diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-21 03:49:17 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-21 03:49:17 +0000 |
commit | db436adf761bd5cb7990745ceba2959ac4bfca7c (patch) | |
tree | 8878ce970fd9b3ac480f3c5ef953fbc85827e685 /src/backend/nodes/copyfuncs.c | |
parent | 5588c559e6e21fae6ba1f162616f4fb4f680fb31 (diff) | |
download | postgresql-db436adf761bd5cb7990745ceba2959ac4bfca7c.tar.gz postgresql-db436adf761bd5cb7990745ceba2959ac4bfca7c.zip |
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.
Diffstat (limited to 'src/backend/nodes/copyfuncs.c')
-rw-r--r-- | src/backend/nodes/copyfuncs.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 99b1c39c7e6..4895be72379 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.91 1999/08/16 02:17:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.92 1999/08/21 03:48:57 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -456,12 +456,6 @@ _copyAgg(Agg *from) CopyPlanFields((Plan *) from, (Plan *) newnode); - /* - * Cannot copy agg list; it must be rebuilt to point to subnodes of - * new node. - */ - set_agg_tlist_references(newnode); - return newnode; } @@ -474,8 +468,8 @@ _copyGroupClause(GroupClause *from) { GroupClause *newnode = makeNode(GroupClause); - newnode->grpOpoid = from->grpOpoid; - newnode->tleGroupref = from->tleGroupref; + newnode->tleSortGroupRef = from->tleSortGroupRef; + newnode->sortop = from->sortop; return newnode; } @@ -567,12 +561,11 @@ _copyResdom(Resdom *from) newnode->resno = from->resno; newnode->restype = from->restype; newnode->restypmod = from->restypmod; - if (from->resname != NULL) newnode->resname = pstrdup(from->resname); + newnode->ressortgroupref = from->ressortgroupref; newnode->reskey = from->reskey; newnode->reskeyop = from->reskeyop; - newnode->resgroupref = from->resgroupref; newnode->resjunk = from->resjunk; return newnode; @@ -862,8 +855,8 @@ _copyAggref(Aggref *from) newnode->basetype = from->basetype; newnode->aggtype = from->aggtype; Node_Copy(from, newnode, target); - newnode->aggno = from->aggno; newnode->usenulls = from->usenulls; + newnode->aggno = from->aggno; /* probably not needed */ return newnode; } @@ -1345,8 +1338,8 @@ _copySortClause(SortClause *from) { SortClause *newnode = makeNode(SortClause); - Node_Copy(from, newnode, resdom); - newnode->opoid = from->opoid; + newnode->tleSortGroupRef = from->tleSortGroupRef; + newnode->sortop = from->sortop; return newnode; } @@ -1398,33 +1391,29 @@ _copyQuery(Query *from) newnode->isBinary = from->isBinary; newnode->isTemp = from->isTemp; newnode->unionall = from->unionall; - if (from->uniqueFlag) - newnode->uniqueFlag = pstrdup(from->uniqueFlag); - Node_Copy(from, newnode, sortClause); + newnode->hasAggs = from->hasAggs; + newnode->hasSubLinks = from->hasSubLinks; + Node_Copy(from, newnode, rtable); Node_Copy(from, newnode, targetList); Node_Copy(from, newnode, qual); + Node_Copy(from, newnode, rowMark); + if (from->uniqueFlag) + newnode->uniqueFlag = pstrdup(from->uniqueFlag); + Node_Copy(from, newnode, sortClause); Node_Copy(from, newnode, groupClause); Node_Copy(from, newnode, havingQual); - newnode->hasAggs = from->hasAggs; - newnode->hasSubLinks = from->hasSubLinks; - - if (from->unionClause) - { - List *ulist, - *temp_list = NIL; - - foreach(ulist, from->unionClause) - temp_list = lappend(temp_list, copyObject(lfirst(ulist))); - newnode->unionClause = temp_list; - } + /* why is intersectClause missing? */ + Node_Copy(from, newnode, unionClause); Node_Copy(from, newnode, limitOffset); Node_Copy(from, newnode, limitCount); - Node_Copy(from, newnode, rowMark); + /* we do not copy the planner internal fields: base_rel_list, + * join_rel_list, query_pathkeys. Not entirely clear if this is right? + */ return newnode; } |