From: Голубева Яна <ishsha@yandex.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Define hash partition for certain column values
Date: Tue, 12 Jan 2021 11:20:59 +0300
Message-ID: <987221610348608@mail.yandex.ru> (raw)
In-Reply-To: <820805.1610346968@sss.pgh.pa.us>
References: <2278581610342154@mail.yandex.ru>
<820805.1610346968@sss.pgh.pa.us>
<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" <tgl@sss.pgh.pa.us>:</div><blockquote><p>=?utf-8?B?0JPQvtC70YPQsdC10LLQsCDQr9C90LA=?= <<a href="mailto:ishsha@yandex.ru">ishsha@yandex.ru</a>> 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>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ishsha@yandex.ru, tgl@sss.pgh.pa.us
Subject: Re: Define hash partition for certain column values
In-Reply-To: <987221610348608@mail.yandex.ru>
References: <2278581610342154@mail.yandex.ru> <820805.1610346968@sss.pgh.pa.us> <987221610348608@mail.yandex.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox