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

Commit4557c84

Browse files
committed
Cleanup of sort nodes and use of strtoul .
1 parentf439eb3 commit4557c84

File tree

2 files changed

+114
-76
lines changed

2 files changed

+114
-76
lines changed

‎src/backend/nodes/outfuncs.c

Lines changed: 61 additions & 25 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.15 1998/01/0618:52:15 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.16 1998/01/0623:19:47 momjian Exp $
1111
*
1212
* NOTES
1313
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -80,7 +80,7 @@ _outCreateStmt(StringInfo str, CreateStmt *node)
8080
_outNode(str,node->inhRelnames);
8181
appendStringInfo(str," :constraints");
8282
_outNode(str,node->constraints);
83-
}/* _outCreateStmt() */
83+
}
8484

8585
staticvoid
8686
_outIndexStmt(StringInfostr,IndexStmt*node)
@@ -102,10 +102,10 @@ _outIndexStmt(StringInfo str, IndexStmt *node)
102102
appendStringInfo(str," :rangetable ");
103103
_outNode(str,node->rangetable);
104104
appendStringInfo(str," :lossy ");
105-
appendStringInfo(str, (*node->lossy ?"y":"n"));
105+
appendStringInfo(str, (*node->lossy ?"true":"false"));
106106
appendStringInfo(str," :unique ");
107-
appendStringInfo(str, (node->unique ?"y":"n"));
108-
}/* _outIndexStmt() */
107+
appendStringInfo(str, (node->unique ?"true":"false"));
108+
}
109109

110110
staticvoid
111111
_outColumnDef(StringInfostr,ColumnDef*node)
@@ -117,12 +117,32 @@ _outColumnDef(StringInfo str, ColumnDef *node)
117117
appendStringInfo(str," :typename ");
118118
_outNode(str,node->typename);
119119
appendStringInfo(str," :is_not_null ");
120-
appendStringInfo(str, (node->is_not_null ?"y":"n"));
120+
appendStringInfo(str, (node->is_not_null ?"true":"false"));
121121
appendStringInfo(str," :defval ");
122122
appendStringInfo(str,node->defval);
123123
appendStringInfo(str," :constraints");
124124
_outNode(str,node->constraints);
125-
}/* _outColumnDef() */
125+
}
126+
127+
staticvoid
128+
_outTypeName(StringInfostr,TypeName*node)
129+
{
130+
charbuf[500];
131+
132+
appendStringInfo(str,"TYPENAME");
133+
134+
appendStringInfo(str," :name ");
135+
appendStringInfo(str,node->name);
136+
appendStringInfo(str," :timezone ");
137+
appendStringInfo(str, (node->timezone ?"true" :"false"));
138+
appendStringInfo(str," :setof ");
139+
appendStringInfo(str, (node->setof ?"true" :"false"));
140+
appendStringInfo(str," :arrayBounds ");
141+
_outNode(str,node->arrayBounds);
142+
appendStringInfo(str," :typlen ");
143+
sprintf(buf," %d ",node->typlen);
144+
appendStringInfo(str,buf);
145+
}
126146

127147
staticvoid
128148
_outIndexElem(StringInfostr,IndexElem*node)
@@ -137,7 +157,7 @@ _outIndexElem(StringInfo str, IndexElem *node)
137157
appendStringInfo(str,node->class);
138158
appendStringInfo(str," :tname");
139159
_outNode(str,node->tname);
140-
}/* _outIndexElem() */
160+
}
141161

142162
staticvoid
143163
_outQuery(StringInfostr,Query*node)
@@ -190,11 +210,11 @@ _outQuery(StringInfo str, Query *node)
190210
appendStringInfo(str," :into ");
191211
appendStringInfo(str,node->into);
192212
appendStringInfo(str," :isPortal ");
193-
appendStringInfo(str, (node->isPortal ?"y":"n"));
213+
appendStringInfo(str, (node->isPortal ?"true":"false"));
194214
appendStringInfo(str," :isBinary ");
195-
appendStringInfo(str, (node->isBinary ?"y":"n"));
215+
appendStringInfo(str, (node->isBinary ?"true":"false"));
196216
appendStringInfo(str," :unionall ");
197-
appendStringInfo(str, (node->unionall ?"y":"n"));
217+
appendStringInfo(str, (node->unionall ?"true":"false"));
198218
appendStringInfo(str," :unique ");
199219
appendStringInfo(str,node->uniqueFlag);
200220
appendStringInfo(str," :sortClause ");
@@ -220,21 +240,31 @@ _outQuery(StringInfo str, Query *node)
220240
}
221241

222242
staticvoid
223-
_outSortGroupBy(StringInfostr,SortGroupBy*node)
243+
_outSortClause(StringInfostr,SortClause*node)
224244
{
225245
charbuf[500];
226-
inti;
227246

228-
appendStringInfo(str,"SORTGROUPBY");
247+
appendStringInfo(str,"SORTCLAUSE");
229248

230-
appendStringInfo(str," :resno ");
231-
sprintf(buf," %d ",node->resno);
232-
appendStringInfo(str," :range ");
233-
appendStringInfo(str,node->range);
234-
appendStringInfo(str," :name ");
235-
appendStringInfo(str,node->name);
236-
appendStringInfo(str," :useOp ");
237-
appendStringInfo(str,node->useOp);
249+
appendStringInfo(str," :resdom ");
250+
_outNode(str,node->resdom);
251+
appendStringInfo(str," :opoid ");
252+
sprintf(buf," %u ",node->opoid);
253+
appendStringInfo(str,buf);
254+
}
255+
256+
staticvoid
257+
_outGroupClause(StringInfostr,GroupClause*node)
258+
{
259+
charbuf[500];
260+
261+
appendStringInfo(str,"GROUPCLAUSE");
262+
263+
appendStringInfo(str," :entry ");
264+
_outNode(str,node->entry);
265+
appendStringInfo(str," :grpOpoid ");
266+
sprintf(buf," %u ",node->grpOpoid);
267+
appendStringInfo(str,buf);
238268
}
239269

240270
/*
@@ -252,7 +282,7 @@ _outPlanInfo(StringInfo str, Plan *node)
252282
sprintf(buf," :width %d",node->plan_width);
253283
appendStringInfo(str,buf);
254284
appendStringInfo(str," :state ");
255-
appendStringInfo(str,(node->state== (EState*)NULL?"nil" :"non-NIL"));
285+
appendStringInfo(str,node->state ?"not-NULL" :"\"\"");
256286
appendStringInfo(str," :qptargetlist ");
257287
_outNode(str,node->targetlist);
258288
appendStringInfo(str," :qpqual ");
@@ -1544,15 +1574,21 @@ _outNode(StringInfo str, void *obj)
15441574
caseT_ColumnDef:
15451575
_outColumnDef(str,obj);
15461576
break;
1577+
caseT_TypeName:
1578+
_outTypeName(str,obj);
1579+
break;
15471580
caseT_IndexElem:
15481581
_outIndexElem(str,obj);
15491582
break;
15501583

15511584
caseT_Query:
15521585
_outQuery(str,obj);
15531586
break;
1554-
caseT_SortGroupBy:
1555-
_outSortGroupBy(str,obj);
1587+
caseT_SortClause:
1588+
_outSortClause(str,obj);
1589+
break;
1590+
caseT_GroupClause:
1591+
_outGroupClause(str,obj);
15561592
break;
15571593
caseT_Plan:
15581594
_outPlan(str,obj);

‎src/backend/nodes/readfuncs.c

Lines changed: 53 additions & 51 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.14 1998/01/0618:52:22 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.15 1998/01/0623:19:49 momjian Exp $
1111
*
1212
* NOTES
1313
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -174,51 +174,49 @@ _readQuery()
174174
}
175175

176176
/* ----------------
177-
*_readSortGroupBy
177+
*_readSortClause
178178
* ----------------
179179
*/
180-
staticSortGroupBy*
181-
_readSortGroupBy()
180+
staticSortClause*
181+
_readSortClause()
182182
{
183-
SortGroupBy*local_node;
183+
SortClause*local_node;
184184
char*token;
185185
intlength;
186186

187-
local_node=makeNode(SortGroupBy);
187+
local_node=makeNode(SortClause);
188188

189-
token=lsptok(NULL,&length);/* skip the :resno */
190-
token=lsptok(NULL,&length);/* getresno */
191-
local_node->resno=atoi(token);
189+
token=lsptok(NULL,&length);/* skip the :resdom */
190+
token=lsptok(NULL,&length);/* getresdom */
191+
local_node->resdom=nodeRead(true);
192192

193-
token=lsptok(NULL,&length);/* skip :range */
194-
token=lsptok(NULL,&length);/* get range */
195-
if (length==0)
196-
local_node->range=NULL;
197-
else
198-
{
199-
local_node->range=palloc(length+1);
200-
StrNCpy(local_node->range,token,length+1);
201-
}
193+
token=lsptok(NULL,&length);/* skip :opoid */
194+
token=lsptok(NULL,&length);/* get opoid */
195+
local_node->opoid=strtoul(token,NULL,10);
202196

203-
token=lsptok(NULL,&length);/* skip :name */
204-
token=lsptok(NULL,&length);/* get name */
205-
if (length==0)
206-
local_node->name=NULL;
207-
else
208-
{
209-
local_node->name=palloc(length+1);
210-
StrNCpy(local_node->name,token,length+1);
211-
}
197+
return (local_node);
198+
}
212199

213-
token=lsptok(NULL,&length);/* skip :useOp */
214-
token=lsptok(NULL,&length);/* get useOp */
215-
if (length==0)
216-
local_node->useOp=NULL;
217-
else
218-
{
219-
local_node->useOp=palloc(length+1);
220-
StrNCpy(local_node->useOp,token,length+1);
221-
}
200+
/* ----------------
201+
*_readGroupClause
202+
* ----------------
203+
*/
204+
staticGroupClause*
205+
_readGroupClause()
206+
{
207+
GroupClause*local_node;
208+
char*token;
209+
intlength;
210+
211+
local_node=makeNode(GroupClause);
212+
213+
token=lsptok(NULL,&length);/* skip the :entry */
214+
token=lsptok(NULL,&length);/* get entry */
215+
local_node->entry=nodeRead(true);
216+
217+
token=lsptok(NULL,&length);/* skip :grpOpoid */
218+
token=lsptok(NULL,&length);/* get grpOpoid */
219+
local_node->grpOpoid=strtoul(token,NULL,10);
222220

223221
return (local_node);
224222
}
@@ -248,7 +246,7 @@ _getPlan(Plan *node)
248246
token=lsptok(NULL,&length);/* eat the :state stuff */
249247
token=lsptok(NULL,&length);/* now get the state */
250248

251-
if (!strncmp(token,"nil",3))
249+
if (length==0)
252250
{
253251
node->state= (EState*)NULL;
254252
}
@@ -343,7 +341,7 @@ _readAppend()
343341

344342
token=lsptok(NULL,&length);/* eat :unionrelid */
345343
token=lsptok(NULL,&length);/* get unionrelid */
346-
local_node->unionrelid=atoi(token);
344+
local_node->unionrelid=strtoul(token,NULL,10);
347345

348346
token=lsptok(NULL,&length);/* eat :unionrtentries */
349347
local_node->unionrtentries=nodeRead(true);/* now read it */
@@ -449,7 +447,7 @@ _readHashJoin()
449447

450448
token=lsptok(NULL,&length);/* eat :hashjoinop */
451449
token=lsptok(NULL,&length);/* get hashjoinop */
452-
local_node->hashjoinop=atoi(token);
450+
local_node->hashjoinop=strtoul(token,NULL,10);
453451

454452
token=lsptok(NULL,&length);/* eat :hashjointable */
455453
token=lsptok(NULL,&length);/* eat hashjointable */
@@ -490,7 +488,7 @@ _getScan(Scan *node)
490488

491489
token=lsptok(NULL,&length);/* eat :scanrelid */
492490
token=lsptok(NULL,&length);/* get scanrelid */
493-
node->scanrelid=atoi(token);
491+
node->scanrelid=strtoul(token,NULL,10);
494492
}
495493

496494
/* ----------------
@@ -735,7 +733,7 @@ _readResdom()
735733

736734
token=lsptok(NULL,&length);/* eat :reskey */
737735
token=lsptok(NULL,&length);/* get reskey */
738-
local_node->reskey=atoi(token);
736+
local_node->reskey=strtoul(token,NULL,10);
739737

740738
token=lsptok(NULL,&length);/* eat :reskeyop */
741739
token=lsptok(NULL,&length);/* get reskeyop */
@@ -816,7 +814,7 @@ _readVar()
816814

817815
token=lsptok(NULL,&length);/* eat :varno */
818816
token=lsptok(NULL,&length);/* get varno */
819-
local_node->varno=atoi(token);
817+
local_node->varno=strtoul(token,NULL,10);
820818

821819
token=lsptok(NULL,&length);/* eat :varattno */
822820
token=lsptok(NULL,&length);/* get varattno */
@@ -854,7 +852,7 @@ _readArray()
854852

855853
token=lsptok(NULL,&length);/* eat :arrayelemtype */
856854
token=lsptok(NULL,&length);/* get arrayelemtype */
857-
local_node->arrayelemtype=(Oid)atoi(token);
855+
local_node->arrayelemtype=strtoul(token,NULL,10);
858856

859857
token=lsptok(NULL,&length);/* eat :arrayelemlength */
860858
token=lsptok(NULL,&length);/* get arrayelemlength */
@@ -896,7 +894,7 @@ _readArrayRef()
896894

897895
token=lsptok(NULL,&length);/* eat :refelemtype */
898896
token=lsptok(NULL,&length);/* get refelemtype */
899-
local_node->refelemtype=(Oid)atoi(token);
897+
local_node->refelemtype=strtoul(token,NULL,10);
900898

901899
token=lsptok(NULL,&length);/* eat :refattrlength */
902900
token=lsptok(NULL,&length);/* get refattrlength */
@@ -947,7 +945,7 @@ _readConst()
947945

948946
token=lsptok(NULL,&length);/* get :constlen */
949947
token=lsptok(NULL,&length);/* now read it */
950-
local_node->constlen=atoi(token);
948+
local_node->constlen=strtoul(token,NULL,10);
951949

952950
token=lsptok(NULL,&length);/* get :constisnull */
953951
token=lsptok(NULL,&length);/* now read it */
@@ -1337,7 +1335,7 @@ _readRangeTblEntry()
13371335

13381336
token=lsptok(NULL,&length);/* eat :inh */
13391337
token=lsptok(NULL,&length);/* get :inh */
1340-
local_node->inh=atoi(token);
1338+
local_node->inh= (token[0]=='t') ? true : false;
13411339

13421340
token=lsptok(NULL,&length);/* eat :refname */
13431341
token=lsptok(NULL,&length);/* get :refname */
@@ -1351,7 +1349,7 @@ _readRangeTblEntry()
13511349

13521350
token=lsptok(NULL,&length);/* eat :relid */
13531351
token=lsptok(NULL,&length);/* get :relid */
1354-
local_node->relid=atoi(token);
1352+
local_node->relid=strtoul(token,NULL,10);
13551353

13561354
return (local_node);
13571355
}
@@ -1676,7 +1674,7 @@ _readOrderKey()
16761674
token=lsptok(NULL,&length);/* get :array_index */
16771675
token=lsptok(NULL,&length);/* now read it */
16781676

1679-
local_node->array_index=atoi(token);
1677+
local_node->array_index=strtoul(token,NULL,10);
16801678

16811679
return (local_node);
16821680
}
@@ -1838,7 +1836,7 @@ _readHInfo()
18381836
token=lsptok(NULL,&length);/* get :hashop */
18391837
token=lsptok(NULL,&length);/* now read it */
18401838

1841-
local_node->hashop=atoi(token);
1839+
local_node->hashop=strtoul(token,NULL,10);
18421840

18431841
token=lsptok(NULL,&length);/* get :jmkeys */
18441842
local_node->jmethod.jmkeys=nodeRead(true);/* now read it */
@@ -2108,9 +2106,13 @@ parsePlanString(void)
21082106
{
21092107
return_value=_readQuery();
21102108
}
2111-
elseif (!strncmp(token,"SORTGROUPBY",11))
2109+
elseif (!strncmp(token,"SORTCLAUSE",10))
2110+
{
2111+
return_value=_readSortClause();
2112+
}
2113+
elseif (!strncmp(token,"GROUPCLAUSE",10))
21122114
{
2113-
return_value=_readSortGroupBy();
2115+
return_value=_readGroupClause();
21142116
}
21152117
else
21162118
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp