diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-03-22 01:49:38 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-03-22 01:49:38 +0000 |
commit | 05f916e6add9726bf4ee046e4060c1b03c9961f2 (patch) | |
tree | d5045cb6bd1b27d4b9af7c05c94e53e6c08736b9 /src/backend/optimizer/util/clauses.c | |
parent | e43094b1249a0e2814d0759d545ccfe786baef3d (diff) |
Adjust subquery qual pushdown rules to be more forgiving: if a qual
refers to a non-DISTINCT output column of a DISTINCT ON subquery, or
if it refers to a function-returning-set, we cannot push it down.
But the old implementation refused to push down *any* quals if the
subquery had any such 'dangerous' outputs. Now we just look at the
output columns actually referenced by each qual expression. More code
than before, but probably no slower since we don't make unnecessary checks.
Diffstat (limited to 'src/backend/optimizer/util/clauses.c')
-rw-r--r-- | src/backend/optimizer/util/clauses.c | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index bdad4d9b811..00ff202df79 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.132 2003/03/14 00:55:17 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.133 2003/03/22 01:49:38 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -29,6 +29,7 @@ #include "optimizer/clauses.h" #include "optimizer/var.h" #include "parser/analyze.h" +#include "parser/parse_clause.h" #include "tcop/tcopprot.h" #include "utils/acl.h" #include "utils/builtins.h" @@ -814,28 +815,6 @@ pull_constant_clauses(List *quals, List **constantQual) *****************************************************************************/ /* - * Test whether a sort/group reference value appears in the given list of - * SortClause (or GroupClause) nodes. - * - * Because GroupClause is typedef'd as SortClause, either kind of - * node list can be passed without casting. - */ -static bool -sortgroupref_is_present(Index sortgroupref, List *clauselist) -{ - List *clause; - - foreach(clause, clauselist) - { - SortClause *scl = (SortClause *) lfirst(clause); - - if (scl->tleSortGroupRef == sortgroupref) - return true; - } - return false; -} - -/* * Test whether a query uses DISTINCT ON, ie, has a distinct-list that is * not the same as the set of output columns. */ @@ -864,15 +843,14 @@ has_distinct_on_clause(Query *query) foreach(targetList, query->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(targetList); - Index ressortgroupref = tle->resdom->ressortgroupref; - if (ressortgroupref == 0) + if (tle->resdom->ressortgroupref == 0) { if (tle->resdom->resjunk) continue; /* we can ignore unsorted junk cols */ return true; /* definitely not in DISTINCT list */ } - if (sortgroupref_is_present(ressortgroupref, query->distinctClause)) + if (targetIsInSortList(tle, query->distinctClause)) { if (tle->resdom->resjunk) return true; /* junk TLE in DISTINCT means DISTINCT ON */ @@ -883,7 +861,7 @@ has_distinct_on_clause(Query *query) /* This TLE is not in DISTINCT list */ if (!tle->resdom->resjunk) return true; /* non-junk, non-DISTINCT, so DISTINCT ON */ - if (sortgroupref_is_present(ressortgroupref, query->sortClause)) + if (targetIsInSortList(tle, query->sortClause)) return true; /* sorted, non-distinct junk */ /* unsorted junk is okay, keep looking */ } |