git.postgresql.org Git - postgresql.git/commit

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: 8875a16) | patch
Arrange to convert EXISTS subqueries that are equivalent to hashable IN
2008年8月22日 00:16:04 +0000 (00:16 +0000)
2008年8月22日 00:16:04 +0000 (00:16 +0000)
commit bd3daddaf232d95b0c9ba6f99b0170a0147dd8af
Arrange to convert EXISTS subqueries that are equivalent to hashable IN
subqueries into the same thing you'd have gotten from IN (except always with
unknownEqFalse = true, so as to get the proper semantics for an EXISTS).
I believe this fixes the last case within CVS HEAD in which an EXISTS could
give worse performance than an equivalent IN subquery.

The tricky part of this is that if the upper query probes the EXISTS for only
a few rows, the hashing implementation can actually be worse than the default,
and therefore we need to make a cost-based decision about which way to use.
But at the time when the planner generates plans for subqueries, it doesn't
really know how many times the subquery will be executed. The least invasive
solution seems to be to generate both plans and postpone the choice until
execution. Therefore, in a query that has been optimized this way, EXPLAIN
will show two subplans for the EXISTS, of which only one will actually get
executed.

There is a lot more that could be done based on this infrastructure: in
particular it's interesting to consider switching to the hash plan if we start
out using the non-hashed plan but find a lot more upper rows going by than we
expected. I have therefore left some minor inefficiencies in place, such as
initializing both subplans even though we will currently only use one.
21 files changed:
src/backend/catalog/dependency.c diff | blob | blame | history
src/backend/executor/execQual.c diff | blob | blame | history
src/backend/executor/nodeSubplan.c diff | blob | blame | history
src/backend/nodes/copyfuncs.c diff | blob | blame | history
src/backend/nodes/equalfuncs.c diff | blob | blame | history
src/backend/nodes/outfuncs.c diff | blob | blame | history
src/backend/optimizer/path/clausesel.c diff | blob | blame | history
src/backend/optimizer/path/costsize.c diff | blob | blame | history
src/backend/optimizer/plan/subselect.c diff | blob | blame | history
src/backend/optimizer/util/clauses.c diff | blob | blame | history
src/backend/optimizer/util/var.c diff | blob | blame | history
src/backend/parser/parse_expr.c diff | blob | blame | history
src/backend/rewrite/rewriteManip.c diff | blob | blame | history
src/backend/utils/adt/ruleutils.c diff | blob | blame | history
src/include/executor/nodeSubplan.h diff | blob | blame | history
src/include/nodes/execnodes.h diff | blob | blame | history
src/include/nodes/nodes.h diff | blob | blame | history
src/include/nodes/primnodes.h diff | blob | blame | history
src/include/optimizer/clauses.h diff | blob | blame | history
src/include/optimizer/cost.h diff | blob | blame | history
src/include/rewrite/rewriteManip.h diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /