From: | Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | james(dot)sewell(at)lisasoft(dot)com |
Cc: | pierce(at)hogranch(dot)com, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Partitioning |
Date: | 2015-01-19 06:09:52 |
Message-ID: | 20150119.150952.127015115.horiguchi.kyotaro@lab.ntt.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
an 2015 14:13:37 +1100, James Sewell <james(dot)sewell(at)lisasoft(dot)com> wrote in <CANkGpBs8GypQ3TQGKdjTD+n-w1rkq5uO97h3tuhg5eWaKR6RbA(at)mail(dot)gmail(dot)com>
> Sadly not ... I still hit all the tables.
| 5.9.4. Partitioning and Constraint Exclusion
http://www.postgresql.org/docs/9.4/static/ddl-partitioning.html
Constraint exclusion is a mechanism to omit tables that are known
to have no hit by the query *beforehand* execution. So the
criteria cannot rely on out of the query itself (and CHECK
constraints, of course).
Your query uses the result of the WITH-clause-query in the WHERE
clause which is unknown to the planner so constraint exclusion
does not work. JOINs don't change the situation.
> On Mon, Jan 19, 2015 at 1:54 PM, John R Pierce <pierce(at)hogranch(dot)com> wrote:
>
> > On 1/18/2015 5:58 PM, James Sewell wrote:
> >
> > WITH idlist as (SELECT id from othertable)
> > SELECT id from mastertable WHERE id = idlist.id);
> >
> >
> >
> > select mt.id, ... from mastertable mt join othertable ot on mt.id=
> > ot.id;
> >
> > might optimize better.
As the result, the query inevitably scans all the tables, but not
necessariry in sequqntial scans or simple index scans. The
suggestion above seeems showing the notation which the planner
can find the better plans on that premise.
For example, if you have an index on id of one of the two tables,
(and some other conditions match, of course) index only scan will
be selected for it and the suggested query will give you a
seemingly better plan than your query.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
From | Date | Subject | |
---|---|---|---|
Next Message | Roxanne Reid-Bennett | 2015-01-19 06:33:23 | Re: Simple Atomic Relationship Insert |
Previous Message | James Sewell | 2015-01-19 03:13:37 | Re: Partitioning |