1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Major revision of sort-node handling: push knowledge of query

sort order down into planner, instead of handling it only at the very top
level of the planner.  This fixes many things.  An explicit sort is now
avoided if there is a cheaper alternative (typically an indexscan) not
only for ORDER BY, but also for the internal sort of GROUP BY.  It works
even when there is no other reason (such as a WHERE condition) to consider
the indexscan.  It works for indexes on functions.  It works for indexes
on functions, backwards.  It's just so cool...

CAUTION: I have changed the representation of SortClause nodes, therefore
THIS UPDATE BREAKS STORED RULES.  You will need to initdb.
This commit is contained in:
Tom Lane
1999-08-21 03:49:17 +00:00
parent 5588c559e6
commit db436adf76
33 changed files with 967 additions and 1002 deletions

View File

@ -3,7 +3,7 @@
* out of it's tuple
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.21 1999/07/17 20:17:59 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.22 1999/08/21 03:48:53 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@ -41,6 +41,7 @@
#include "postgres.h"
#include "executor/spi.h"
#include "optimizer/clauses.h"
#include "optimizer/tlist.h"
#include "utils/lsyscache.h"
#include "catalog/pg_shadow.h"
#include "catalog/pg_index.h"
@ -1248,23 +1249,11 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
case T_GroupClause:
{
GroupClause *grp = (GroupClause *) node;
List *l;
TargetEntry *tle = NULL;
Node *groupexpr;
foreach(l, qh->query->targetList)
{
if (((TargetEntry *) lfirst(l))->resdom->resgroupref ==
grp->tleGroupref)
{
tle = (TargetEntry *) lfirst(l);
break;
}
}
if (tle == NULL)
elog(ERROR, "GROUP BY expression not found in targetlist");
return get_rule_expr(qh, rt_index, (Node *) tle, varprefix);
groupexpr = get_sortgroupclause_expr(grp,
qh->query->targetList);
return get_rule_expr(qh, rt_index, groupexpr, varprefix);
}
break;