Re: Query plan question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Maksim Likharev" <mlikharev(at)aurigin(dot)com>
Cc: "GENERAL" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query plan question
Date: 2003-06-26 14:35:34
Message-ID: 24853.1056638134@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Maksim Likharev" <mlikharev(at)aurigin(dot)com> writes:
> basically I complaining that PG does not do what I told to do or
> was hoping to do.

Okay, now I get the point: you want to prevent the "pt" sub-select from
being flattened into the outer query.

7.3.1 through 7.3.3 will actually do what you want (they won't flatten a
sub-select that has any sub-selects in its output list) but we got a lot
of flak for that and 7.4 will go back to the prior behavior. In most
scenarios it's a win for the planner to flatten wherever possible.

Probably the easiest way to handle it is to insert a DISTINCT or LIMIT
clause in the sub-select; that will unconditionally keep the planner
from flattening the sub-select. For example,

...
FROM prod.t_p AS p INNER JOIN t_temp AS t
ON p.did = t.did
LEFT OUTER JOIN prod.t_pinv AS pi
ON p.kid = pi.kid AND pi.orderid = 'S'
-- hack to keep this separate from outer plan:
OFFSET 0
) AS pt

LEFT OUTER JOIN prod.t_dmp AS pdb
ON pt.kid = pdb.kid
...

I don't foresee any future planner changes that would be likely to
bypass a LIMIT/OFFSET clause.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-06-26 14:52:02 Re: [GENERAL] Physical Database Configuration
Previous Message nolan 2003-06-26 14:25:19 Re: [GENERAL] Physical Database Configuration