Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit763ff8a

Browse files
committed
Remove Query->qry_aggs and qry_numaggs and replace with Query->hasAggs.
Pass List* of Aggregs into executor, and create needed array there.No longer need to double-processs Aggregs with second copy in Query.Fix crash when doing:select sum(x+1) from test where 1 > 0;
1 parentf22d8e6 commit763ff8a

File tree

20 files changed

+173
-272
lines changed

20 files changed

+173
-272
lines changed

‎src/backend/executor/nodeAgg.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ExecAgg(Agg *node)
105105
ProjectionInfo*projInfo;
106106
TupleTableSlot*resultSlot;
107107
HeapTupleoneTuple;
108+
List*alist;
108109
char*nulls;
109110
boolisDone;
110111
boolisNull= FALSE,
@@ -121,8 +122,17 @@ ExecAgg(Agg *node)
121122

122123
estate=node->plan.state;
123124
econtext=aggstate->csstate.cstate.cs_ExprContext;
124-
aggregates=node->aggs;
125-
nagg=node->numAgg;
125+
nagg=length(node->aggs);
126+
127+
aggregates= (Aggreg**)palloc(sizeof(Aggreg*)*nagg);
128+
129+
/* take List* and make it an array that can be quickly indexed */
130+
alist=node->aggs;
131+
for (i=0;i<nagg;i++)
132+
{
133+
aggregates[i]=lfirst(alist);
134+
alist=lnext(alist);
135+
}
126136

127137
value1=node->aggstate->csstate.cstate.cs_ExprContext->ecxt_values;
128138
nulls=node->aggstate->csstate.cstate.cs_ExprContext->ecxt_nulls;
@@ -540,10 +550,10 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
540550

541551
econtext=aggstate->csstate.cstate.cs_ExprContext;
542552
econtext->ecxt_values=
543-
(Datum*)palloc(sizeof(Datum)*node->numAgg);
544-
MemSet(econtext->ecxt_values,0,sizeof(Datum)*node->numAgg);
545-
econtext->ecxt_nulls= (char*)palloc(node->numAgg);
546-
MemSet(econtext->ecxt_nulls,0,node->numAgg);
553+
(Datum*)palloc(sizeof(Datum)*length(node->aggs));
554+
MemSet(econtext->ecxt_values,0,sizeof(Datum)*length(node->aggs));
555+
econtext->ecxt_nulls= (char*)palloc(length(node->aggs));
556+
MemSet(econtext->ecxt_nulls,0,length(node->aggs));
547557

548558
/*
549559
* initializes child nodes

‎src/backend/nodes/copyfuncs.c‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.29 1998/01/11 20:01:53 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.30 1998/01/15 18:59:20 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -493,15 +493,10 @@ static Agg *
493493
_copyAgg(Agg*from)
494494
{
495495
Agg*newnode=makeNode(Agg);
496-
inti;
497496

498497
CopyPlanFields((Plan*)from, (Plan*)newnode);
499498

500-
newnode->numAgg=from->numAgg;
501-
newnode->aggs=palloc(sizeof(Aggreg*));
502-
for (i=0;i<from->numAgg;i++)
503-
newnode->aggs[i]=copyObject(from->aggs[i]);
504-
499+
Node_Copy(from,newnode,aggs);
505500
Node_Copy(from,newnode,aggstate);
506501

507502
returnnewnode;
@@ -1495,7 +1490,6 @@ static Query *
14951490
_copyQuery(Query*from)
14961491
{
14971492
Query*newnode=makeNode(Query);
1498-
inti;
14991493

15001494
newnode->commandType=from->commandType;
15011495
if (from->utilityStmt&&nodeTag(from->utilityStmt)==T_NotifyStmt)
@@ -1522,14 +1516,7 @@ _copyQuery(Query *from)
15221516
Node_Copy(from,newnode,groupClause);
15231517
Node_Copy(from,newnode,havingQual);
15241518

1525-
newnode->qry_numAgg=from->qry_numAgg;
1526-
if (from->qry_numAgg>0)
1527-
{
1528-
newnode->qry_aggs=
1529-
(Aggreg**)palloc(sizeof(Aggreg*)*from->qry_numAgg);
1530-
for (i=0;i<from->qry_numAgg;i++)
1531-
newnode->qry_aggs[i]=_copyAggreg(from->qry_aggs[i]);
1532-
}
1519+
newnode->hasAggs=from->hasAggs;
15331520

15341521
if (from->unionClause)
15351522
{

‎src/backend/nodes/list.c‎

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.10 1998/01/07 21:03:29 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.11 1998/01/15 18:59:23 momjian Exp $
1111
*
1212
* NOTES
1313
* XXX a few of the following functions are duplicated to handle
@@ -89,6 +89,48 @@ lappendi(List *list, int datum)
8989
returnnconc(list,lconsi(datum,NIL));
9090
}
9191

92+
List*
93+
nconc(List*l1,List*l2)
94+
{
95+
List*temp;
96+
97+
if (l1==NIL)
98+
returnl2;
99+
if (l2==NIL)
100+
returnl1;
101+
if (l1==l2)
102+
elog(ERROR,"tryout to nconc a list to itself");
103+
104+
for (temp=l1;lnext(temp)!=NULL;temp=lnext(temp))
105+
;
106+
107+
lnext(temp)=l2;
108+
return (l1);/* list1 is now list1[]list2 */
109+
}
110+
111+
112+
List*
113+
nreverse(List*list)
114+
{
115+
List*rlist=NIL;
116+
List*p=NIL;
117+
118+
if (list==NULL)
119+
return (NIL);
120+
121+
if (length(list)==1)
122+
return (list);
123+
124+
for (p=list;p!=NULL;p=lnext(p))
125+
{
126+
rlist=lcons(lfirst(p),rlist);
127+
}
128+
129+
lfirst(list)=lfirst(rlist);
130+
lnext(list)=lnext(rlist);
131+
return (list);
132+
}
133+
92134
Value*
93135
makeInteger(longi)
94136
{
@@ -227,48 +269,6 @@ intAppend(List *l1, List *l2)
227269
returnnewlist;
228270
}
229271

230-
List*
231-
nconc(List*l1,List*l2)
232-
{
233-
List*temp;
234-
235-
if (l1==NIL)
236-
returnl2;
237-
if (l2==NIL)
238-
returnl1;
239-
if (l1==l2)
240-
elog(ERROR,"tryout to nconc a list to itself");
241-
242-
for (temp=l1;lnext(temp)!=NULL;temp=lnext(temp))
243-
;
244-
245-
lnext(temp)=l2;
246-
return (l1);/* list1 is now list1[]list2 */
247-
}
248-
249-
250-
List*
251-
nreverse(List*list)
252-
{
253-
List*rlist=NIL;
254-
List*p=NIL;
255-
256-
if (list==NULL)
257-
return (NIL);
258-
259-
if (length(list)==1)
260-
return (list);
261-
262-
for (p=list;p!=NULL;p=lnext(p))
263-
{
264-
rlist=lcons(lfirst(p),rlist);
265-
}
266-
267-
lfirst(list)=lfirst(rlist);
268-
lnext(list)=lnext(rlist);
269-
return (list);
270-
}
271-
272272
/*
273273
*same
274274
*

‎src/backend/nodes/outfuncs.c‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.20 1998/01/07 15:32:25 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.21 1998/01/15 18:59:26 momjian Exp $
1111
*
1212
* NOTES
1313
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -163,7 +163,6 @@ static void
163163
_outQuery(StringInfostr,Query*node)
164164
{
165165
charbuf[500];
166-
inti;
167166

168167
appendStringInfo(str,"QUERY");
169168

@@ -229,12 +228,8 @@ _outQuery(StringInfo str, Query *node)
229228
_outNode(str,node->groupClause);
230229
appendStringInfo(str," :havingQual ");
231230
_outNode(str,node->havingQual);
232-
appendStringInfo(str," :qry_numAgg ");
233-
sprintf(buf," %d ",node->qry_numAgg);
234-
appendStringInfo(str,buf);
235-
appendStringInfo(str," :qry_aggs ");
236-
for (i=0;i<node->qry_numAgg;i++)
237-
_outNode(str,node->qry_aggs[i]);
231+
appendStringInfo(str," :hasAggs ");
232+
appendStringInfo(str, (node->hasAggs ?"true" :"false"));
238233
appendStringInfo(str," :unionClause ");
239234
_outNode(str,node->unionClause);
240235
}
@@ -505,14 +500,12 @@ _outSort(StringInfo str, Sort *node)
505500
staticvoid
506501
_outAgg(StringInfostr,Agg*node)
507502
{
508-
charbuf[500];
509503

510504
appendStringInfo(str,"AGG");
511505
_outPlanInfo(str, (Plan*)node);
512506

513-
/* the actual Agg fields */
514-
sprintf(buf," :numagg %d ",node->numAgg);
515-
appendStringInfo(str,buf);
507+
appendStringInfo(str," :aggs ");
508+
_outNode(str,node->aggs);
516509
}
517510

518511
staticvoid

‎src/backend/nodes/readfuncs.c‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.17 1998/01/07 21:03:37 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.18 1998/01/15 18:59:31 momjian Exp $
1111
*
1212
* NOTES
1313
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -76,7 +76,6 @@ _readQuery()
7676
Query*local_node;
7777
char*token;
7878
intlength;
79-
inti;
8079

8180
local_node=makeNode(Query);
8281

@@ -153,19 +152,9 @@ _readQuery()
153152
token=lsptok(NULL,&length);/* skip :havingQual */
154153
local_node->havingQual=nodeRead(true);
155154

156-
token=lsptok(NULL,&length);/* skip the :qry_numAgg */
157-
token=lsptok(NULL,&length);/* get qry_numAgg */
158-
local_node->qry_numAgg=atoi(token);
159-
160-
token=lsptok(NULL,&length);/* skip the :qry_Aggs */
161-
if (local_node->qry_numAgg==0)
162-
local_node->qry_aggs=NULL;
163-
else
164-
{
165-
local_node->qry_aggs=palloc(sizeof(Aggreg*)*local_node->qry_numAgg);
166-
for (i=0;i<local_node->qry_numAgg;i++)
167-
local_node->qry_aggs[i]=nodeRead(true);
168-
}
155+
token=lsptok(NULL,&length);/* skip the :hasAggs */
156+
token=lsptok(NULL,&length);/* get hasAggs */
157+
local_node->hasAggs= (token[0]=='t') ? true : false;
169158

170159
token=lsptok(NULL,&length);/* skip :unionClause */
171160
local_node->unionClause=nodeRead(true);
@@ -618,9 +607,8 @@ _readAgg()
618607
local_node=makeNode(Agg);
619608
_getPlan((Plan*)local_node);
620609

621-
token=lsptok(NULL,&length);/* eat :numagg */
622-
token=lsptok(NULL,&length);/* get numagg */
623-
local_node->numAgg=atoi(token);
610+
token=lsptok(NULL,&length);/* eat :agg */
611+
local_node->aggs=nodeRead(true);/* now read it */
624612

625613
return (local_node);
626614
}

‎src/backend/optimizer/plan/createplan.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.22 1998/01/07 21:04:01 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.23 1998/01/15 18:59:37 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1106,7 +1106,7 @@ make_material(List *tlist,
11061106
}
11071107

11081108
Agg*
1109-
make_agg(List*tlist,intnagg,Aggreg**aggs,Plan*lefttree)
1109+
make_agg(List*tlist,Plan*lefttree)
11101110
{
11111111
Agg*node=makeNode(Agg);
11121112

@@ -1116,8 +1116,7 @@ make_agg(List *tlist, int nagg, Aggreg **aggs, Plan *lefttree)
11161116
node->plan.targetlist=tlist;
11171117
node->plan.lefttree=lefttree;
11181118
node->plan.righttree= (Plan*)NULL;
1119-
node->numAgg=nagg;
1120-
node->aggs=aggs;
1119+
node->aggs=NIL;
11211120

11221121
return (node);
11231122
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp