From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | "Campbell, Lance" <lance(at)illinois(dot)edu>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Partitioning Tables |
Date: | 2021-02-06 04:28:14 |
Message-ID: | 0fbb3e14e792b85057441739053a2c608bf74318.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Fri, 2021-02-05 at 18:27 +0000, Campbell, Lance wrote:
> I have a challenge. I have two tables, group and group_member. A group table has a
> type indicator telling me which of three ways the table can be used. The group member
> table is made up of 50 million records that have a foreign key to the group table.
>
> I really need the queries to be fast for one particular type of group. This type has
> less than a million members in it. So my first thought was to create a separate
> group_member table just for members of this type of group. But I have to change a lot of SQL.
>
> The other idea I thought of is there a way to use table partitions? If the query goes
> against a group of type A then it would pull from the small partition but if it is a group
> of some other type it would query against the other partition.
If you want to partition "group_member", the partitioning key cannot be in "group".
So you would have to (redundantly) add "group.type" to "group_member".
You could ensure consistency by including that column in the foreign key.
If you want partition pruning to take effect, you will have to include
a condition on "group_member.type" in the WHERE condition.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Kellerer | 2021-02-06 12:23:53 | pg_upgrade(?) not cleaning up old extensions |
Previous Message | Nikolay Samokhvalov | 2021-02-05 23:44:56 | Re: wal-g (https://github.com/wal-g/wal-g) reliability |