Re: Recursive optimization of IN subqueries

From: Dennis Haney <davh(at)diku(dot)dk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Recursive optimization of IN subqueries
Date: 2004-01-23 17:09:06
Message-ID: 40115532.7030206@diku.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Tom Lane wrote:

>Dennis Haney <davh(at)diku(dot)dk> writes:
>
>
>>As far as I can tell, the pull_up_IN_clauses does not optimize
>>recursively. Am I totally misguided here?
>>
>>
>
>Yes. The subquery is not being physically folded into the outer query
>(so the comment about "pulling up" may be a poor choice of words).
>It will still get planned separately by a recursive call to
>subquery_planner, and any internal INs will get fixed at that time.
>
>It is possible and even rather likely that the subsequent run of
>pull_up_subqueries will flatten the subquery into the outer query,
>and if so its internal INs are fixed during pull_up_subqueries.
>But doing it here would be redundant.
>
>
I think I figured it out now, after looking at it for hours...

I saw it as though convert_IN_to_join rewrote the query from

select a.* from tenk1 a where a.unique1 in
(select c.thousand from tenk1 c where c.hundred = 99);

to

select a.* from tenk1 a, tenk1 c where a.unique1 = c.thousand AND
c.hundred = 99;

But after looking at it, I've reached the conclusion that the rewrite is
to this instead:

select a.* from tenk1 a, (select d.thousand from tenk1 d where
d.hundred = 99) as c where a.unique1 = c.thousand;

except the subselect is added as a range table entry instead of a
subselect in the from-list (not that I understand this particular part,
do you mind explaining?).

Or am I still totally lost?

--
Dennis

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-01-23 17:52:29 Re: Recursive optimization of IN subqueries
Previous Message Joshua D. Drake 2004-01-23 16:32:53 Re: sequence in schema -- broken default

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2004-01-23 17:25:26 Re: [HACKERS] PostgreSQL installation CD based on
Previous Message Tom Lane 2004-01-23 15:13:06 7.5 change documentation (was Re: cache control?)