Thread: pg12 - migrate tables to partitions structure

pg12 - migrate tables to partitions structure

From
Mariel Cherkassky
Date:
Hey,
Thanks to the new partitions features in pg12 (referencing partition table is possible) I was trying to migrate some of my tables into a partitions structure.

Lets assume I have the following non partitions structure : 

Product(id int PK,vendor int references Vendor(id),price int)
ProductPic(int picId PK,product int references product(id) )
Vendor(id int PK,name text)
.... more tables that has references to the Product(id).

I understand that the PK on the  Product table must include also the partition column in order to ensure the uniqueness across all the partitions. However, on the other hand I'll need to add the partition column (Vendor) to all the tables that has a reference to the Product(id) + update that column with the relevant data. This type of maintenance requires a lot of time because I have a lot of references to the Product table. Is there any other option in PG12 to allow references to partition table ?

Re: pg12 - migrate tables to partitions structure

From
Michael Lewis
Date:
How many rows are you dealing with currently? What are your queries like? Have you looked at doing a hash partition on product.id? Is this on a test system or destined for a production environment in the near future? I ask because PG12 is still in beta.

Re: pg12 - migrate tables to partitions structure

From
Mariel Cherkassky
Date:
Hey Michael,
first of all thanks for the quick response.
Right now the production env is on a different version(10). I'm doing all my tests on a test environment. I'm familiar with the hash partitions but my queries doesnt involve the product.id therefore iti isnt relevant. All the queries uses the vendor product and thats why this column is a perfect fit as a partition column.
My main table is big (10M+) (Product), but other tables can also be big(1M+)..

Re: pg12 - migrate tables to partitions structure

From
Michael Lewis
Date:
All the queries uses the vendor product and thats why this column is a perfect fit as a partition column.
My main table is big (10M+) (Product), but other tables can also be big(1M+)..

I assume you have query performance problems and are hoping partitioning will help? Are you read heavy, or write intensive, or both? 10 million rows, especially if they aren't super wide, doesn't seem like a huge number to me. Do you have example queries with explain plans that you think would benefit from the system being partitioned? I just know that as an engineer, sometimes I like to make use of new tools, even when it isn't the best solution for the problem I am actually experiencing. How confident are you that you NEED partitions is my real question.

Re: pg12 - migrate tables to partitions structure

From
Mariel Cherkassky
Date:
Well, if u have 10M rows, and all your queries use the same column in the query and the data can split pretty even between the partitions, any specific reason not to use is ? An index will help u reach a complexity of (logn) while partition + index can be in complexity of (logm) when m = rows in partition , n=total rows

Re: pg12 - migrate tables to partitions structure

From
Michael Lewis
Date:
Is this being done because it can be, or is it solving a real-life pain point? Just wondering what the perspective is here.

Much of partitioning strategy seems to me to revolve around how the system is used, and not just the schema and what is possible. For instance, you can mimic primary and foreign key behavior with triggers as described here, and that would bypass some of the restrictions on what can be done.

This would allow you to change out the primary key for a simple index perhaps, and partition however you want. Just because something can be done, does not mean it should be.