Re: Am I really stupid???

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: karl(at)debisschop(dot)net
Cc: ddd(at)genesis(dot)homeip(dot)net, pgsql-general(at)hub(dot)org
Subject: Re: Am I really stupid???
Date: 2000-05-17 15:18:43
Message-ID: 16926.958576723@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Karl DeBisschop <kdebisschop(at)h00a0cc3b7988(dot)ne(dot)mediaone(dot)net> writes:
> For example, if you look through the archive you will see quite a few
> discussions about slow returns from "SELECT * FROM foo WHERE x in (...)"
> -- this is a fact about the current implementation of PostgreSQL and the
> (only?) solution is to rewrite using "WHERE EXISTS ...." Though I forget
> the exact reason, it turns out that it is not a trivial matter to have the
> optimizer rewrite the first query into the second (and of course the first
> is slow because it cannot use inidces). Your question could be a similar
> case, or it could be a repairable shortcoming in the planner/optimizer.

In fact, IN (subselect), INTERSECT, and EXCEPT are all pretty much the
same thing, and they're all pretty slow in the current code :-(, because
they all work by rescanning the inner query for each outer tuple --- in
other words, they're all implemented like plain nestloop joins. EXISTS
is marginally better because the planner can figure out how to use an
index on the inner table, if there is one.

The right way to fix this is to promote these operations into
full-fledged join types so that the optimizer can consider alternatives
like mergejoin (which is basically the method Dragos is talking about),
hashjoin, index-driven nestloop, etc. That's not a small task. I'm
hoping to see it happen as part of the querytree redesign scheduled for
7.2, which will also give us outer joins. If you think about it, all
of these are variants on the theme of outer join...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Lockhart 2000-05-17 15:27:46 Re: Question about databases in alternate locations...
Previous Message cc21cn 2000-05-17 14:04:43 Does Psql support Chinese?