Re: Define hash partition for certain column values

From: Голубева Яна <ishsha(at)yandex(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Define hash partition for certain column values
Date: 2021-01-12 08:20:59
Message-ID: 987221610348608@mail.yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<div><div>Thank you for the answer!</div><div> </div><div>List or range partitioning isn't suitable for my case.</div><div>I am using a column of numeric(20) type as a base for partitioning. The values of the column are generated randomly. </div><div>So there will be too many partitions if I use list partitioning as is.</div><div> </div><div>I've tried to use an expression with this column for list partitioning in order to restrict the number of partitions. But in that case I can't create an index because of</div><div>ERROR: unsupported UNIQUE constraint with partition key definition</div><div>DETAIL: UNIQUE constraints cannot be used when partition keys include expressions.</div><div> </div><div>So that the only option I see is to use hash partitioning by this column.</div><div> </div><div>I do not need to control which partition any particular row goes to. But I would like to have an opportunity to prepare pieces of data related to the certain partition. satisfies_hash_partition function is pretty good for this purpose but not for my case.</div><div> </div><div>My partitioning table is filling by insert with a query. The query is pretty complicated and contains several joins of different tables. Data replication into partitioning table occurs regularly.</div><div> </div><div>So, I'd like to create an index which allows me to align data in a basic table with data in the partitioning table based on partitions the data will be placed in. This way I'll be able to manipulate data in different partitions independently. Also I suppose that it could help to improve performance since data refill occurs regularly.</div><div> </div><div>For now I've created a custom C-function define_hash_partition for test and it seems to be working well for my case although I haven't finished my tests yet.</div><div> </div><div>Thank you!</div><div>Iana Golubeva</div></div><div> </div><div><br /></div><div><br /></div><div>11.01.2021, 09:36, "Tom Lane" &lt;tgl(at)sss(dot)pgh(dot)pa(dot)us&gt;:</div><blockquote><p>=?utf-8?B?0JPQvtC70YPQsdC10LLQsCDQr9C90LA=?= &lt;<a href="mailto:ishsha(at)yandex(dot)ru">ishsha(at)yandex(dot)ru</a>&gt; writes:<br /></p><blockquote class="210e7a848e8fcb45wmi-quote"> Hello, I've found in source code that there is a function satisfies_hash_partition(oid, modulus, remainder, column_values[]) which allows to check if the certain column value will be placed in the certain partition. I' d like to know if there is an opportunity not to check the certain partition but to define which partition will be the certain column value placed in.<br /></blockquote><p><br />If you want to control what goes where, use list partitioning (or,<br />perhaps, range partitioning). Hash is only suitable if you do not<br />care which partition any particular row goes to.<br /><br />Personally, I think hash partitioning is mostly academic, precisely<br />because of that. If the partitioning doesn't line up with application<br />requirements, you give up too much of the benefit of using partitions.<br /><br />                        regards, tom lane<br /></p></blockquote>

Attachment Content-Type Size
unknown_filename text/html 3.0 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-01-12 14:45:12 Re: CASE WHEN idiomatic for functions with side-effect?
Previous Message Joel Jacobson 2021-01-12 08:13:47 CASE WHEN idiomatic for functions with side-effect?