summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-07-31 18:39:13 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-07-31 18:39:13 +0000
commita1e17cd5c5807f905cb324399455eba32d43dd1e (patch)
tree7e799d9204218ef870c9105bb0d840c0de9bc4db /src/backend/utils/adt/ruleutils.c
parentd6b1a407f4c544c438f0bf6067b70e864719bb46 (diff)
Fix optimizer to not try to push WHERE clauses down into a sub-SELECT that
has a DISTINCT ON clause, per bug report from Anthony Wood. While at it, improve the DISTINCT-ON-clause recognizer routine to not be fooled by out- of-order DISTINCT lists. Also, back-patch earlier fix to not push down into sub-SELECT with LIMIT.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c37
1 files changed, 4 insertions, 33 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 5635b90a9fb..47d80954941 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.77 2001/04/18 17:04:24 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.77.2.1 2001/07/31 18:39:12 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -119,7 +119,6 @@ static void get_utility_query_def(Query *query, deparse_context *context);
static void get_basic_select_query(Query *query, deparse_context *context);
static void get_setop_query(Node *setOp, Query *query,
deparse_context *context, bool toplevel);
-static bool simple_distinct(List *distinctClause, List *targetList);
static void get_rule_sortgroupclause(SortClause *srt, List *tlist,
bool force_colno,
deparse_context *context);
@@ -1006,9 +1005,7 @@ get_basic_select_query(Query *query, deparse_context *context)
/* Add the DISTINCT clause if given */
if (query->distinctClause != NIL)
{
- if (simple_distinct(query->distinctClause, query->targetList))
- appendStringInfo(buf, " DISTINCT");
- else
+ if (has_distinct_on_clause(query))
{
appendStringInfo(buf, " DISTINCT ON (");
sep = "";
@@ -1023,6 +1020,8 @@ get_basic_select_query(Query *query, deparse_context *context)
}
appendStringInfo(buf, ")");
}
+ else
+ appendStringInfo(buf, " DISTINCT");
}
/* Then we tell what to select (the targetlist) */
@@ -1150,34 +1149,6 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
}
/*
- * Detect whether a DISTINCT list can be represented as just DISTINCT
- * or needs DISTINCT ON. It's simple if it contains exactly the nonjunk
- * targetlist items.
- */
-static bool
-simple_distinct(List *distinctClause, List *targetList)
-{
- while (targetList)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(targetList);
-
- if (!tle->resdom->resjunk)
- {
- if (distinctClause == NIL)
- return false;
- if (((SortClause *) lfirst(distinctClause))->tleSortGroupRef !=
- tle->resdom->ressortgroupref)
- return false;
- distinctClause = lnext(distinctClause);
- }
- targetList = lnext(targetList);
- }
- if (distinctClause != NIL)
- return false;
- return true;
-}
-
-/*
* Display a sort/group clause.
*/
static void