avoiding nested loops when joining on partitioned tables

From: Peter Neal <doabackflip(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: avoiding nested loops when joining on partitioned tables
Date: 2010-10-31 22:35:36
Message-ID: AANLkTim-A4UY1WnfA+iWBKmuiAsu+pSW9ApSUqB04KR4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have two tables (A and B), which are partitioned (A1, A2... B1, B2...) for
easy deletion of old records. They are linked by a bigint column "id", which
is defined as a foreign key in each B partition referencing the
corresponding A partition. Many rows in B1 can reference a single row in A1.
The "id" column is indexed in both tables. Each partition could have
>1million rows.

The id column in each A partition gets its nextval from a (common) counter,
and the inserts always use the default value for this column - I know that
B1 references rows in A1 only, B2 -> A2 only etc.

Is there any way I can explain this to postgres? When I query the parent
table of the partitions, "SELECT * from A, B where a.id=b.id;", the planner
does a sequential scan on A, A1, A2, ... an index scan on B, B1, B2, ...
then a nested loop, which generally takes a while.

As I say, I presume this is because the planner does not know that there is
no overlap in 'id' values between the different partitions - is there any
way to express this?

Thanks,

Pete

ps please copy me on replies as I am not subscribed.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-10-31 23:22:00 Re: How to determine server version inside select statement
Previous Message Osvaldo Kussama 2010-10-31 22:21:29 Re: How to determine server version inside select statement