提交 4557c846 编写于 作者: B Bruce Momjian

Cleanup of sort nodes and use of strtoul .

上级 f439eb35
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.15 1998/01/06 18:52:15 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.16 1998/01/06 23:19:47 momjian Exp $
* *
* NOTES * NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which * Every (plan) node in POSTGRES has an associated "out" routine which
...@@ -80,7 +80,7 @@ _outCreateStmt(StringInfo str, CreateStmt *node) ...@@ -80,7 +80,7 @@ _outCreateStmt(StringInfo str, CreateStmt *node)
_outNode(str, node->inhRelnames); _outNode(str, node->inhRelnames);
appendStringInfo(str, " :constraints"); appendStringInfo(str, " :constraints");
_outNode(str, node->constraints); _outNode(str, node->constraints);
} /* _outCreateStmt() */ }
static void static void
_outIndexStmt(StringInfo str, IndexStmt *node) _outIndexStmt(StringInfo str, IndexStmt *node)
...@@ -102,10 +102,10 @@ _outIndexStmt(StringInfo str, IndexStmt *node) ...@@ -102,10 +102,10 @@ _outIndexStmt(StringInfo str, IndexStmt *node)
appendStringInfo(str, " :rangetable "); appendStringInfo(str, " :rangetable ");
_outNode(str, node->rangetable); _outNode(str, node->rangetable);
appendStringInfo(str, " :lossy "); appendStringInfo(str, " :lossy ");
appendStringInfo(str, (*node->lossy ? "y": "n")); appendStringInfo(str, (*node->lossy ? "true": "false"));
appendStringInfo(str, " :unique "); appendStringInfo(str, " :unique ");
appendStringInfo(str, (node->unique ? "y": "n")); appendStringInfo(str, (node->unique ? "true": "false"));
} /* _outIndexStmt() */ }
static void static void
_outColumnDef(StringInfo str, ColumnDef *node) _outColumnDef(StringInfo str, ColumnDef *node)
...@@ -117,12 +117,32 @@ _outColumnDef(StringInfo str, ColumnDef *node) ...@@ -117,12 +117,32 @@ _outColumnDef(StringInfo str, ColumnDef *node)
appendStringInfo(str, " :typename "); appendStringInfo(str, " :typename ");
_outNode(str, node->typename); _outNode(str, node->typename);
appendStringInfo(str, " :is_not_null "); appendStringInfo(str, " :is_not_null ");
appendStringInfo(str, (node->is_not_null ? "y": "n")); appendStringInfo(str, (node->is_not_null ? "true": "false"));
appendStringInfo(str, " :defval "); appendStringInfo(str, " :defval ");
appendStringInfo(str, node->defval); appendStringInfo(str, node->defval);
appendStringInfo(str, " :constraints"); appendStringInfo(str, " :constraints");
_outNode(str, node->constraints); _outNode(str, node->constraints);
} /* _outColumnDef() */ }
static void
_outTypeName(StringInfo str, TypeName *node)
{
char buf[500];
appendStringInfo(str, "TYPENAME");
appendStringInfo(str, " :name ");
appendStringInfo(str, node->name);
appendStringInfo(str, " :timezone ");
appendStringInfo(str, (node->timezone ? "true" : "false"));
appendStringInfo(str, " :setof ");
appendStringInfo(str, (node->setof ? "true" : "false"));
appendStringInfo(str, " :arrayBounds ");
_outNode(str, node->arrayBounds);
appendStringInfo(str, " :typlen ");
sprintf(buf," %d ", node->typlen);
appendStringInfo(str, buf);
}
static void static void
_outIndexElem(StringInfo str, IndexElem *node) _outIndexElem(StringInfo str, IndexElem *node)
...@@ -137,7 +157,7 @@ _outIndexElem(StringInfo str, IndexElem *node) ...@@ -137,7 +157,7 @@ _outIndexElem(StringInfo str, IndexElem *node)
appendStringInfo(str, node->class); appendStringInfo(str, node->class);
appendStringInfo(str, " :tname"); appendStringInfo(str, " :tname");
_outNode(str, node->tname); _outNode(str, node->tname);
} /* _outIndexElem() */ }
static void static void
_outQuery(StringInfo str, Query *node) _outQuery(StringInfo str, Query *node)
...@@ -190,11 +210,11 @@ _outQuery(StringInfo str, Query *node) ...@@ -190,11 +210,11 @@ _outQuery(StringInfo str, Query *node)
appendStringInfo(str, " :into "); appendStringInfo(str, " :into ");
appendStringInfo(str, node->into); appendStringInfo(str, node->into);
appendStringInfo(str, " :isPortal "); appendStringInfo(str, " :isPortal ");
appendStringInfo(str, (node->isPortal ? "y": "n")); appendStringInfo(str, (node->isPortal ? "true" : "false"));
appendStringInfo(str, " :isBinary "); appendStringInfo(str, " :isBinary ");
appendStringInfo(str, (node->isBinary ? "y": "n")); appendStringInfo(str, (node->isBinary ? "true" : "false"));
appendStringInfo(str, " :unionall "); appendStringInfo(str, " :unionall ");
appendStringInfo(str, (node->unionall ? "y": "n")); appendStringInfo(str, (node->unionall ? "true" : "false"));
appendStringInfo(str, " :unique "); appendStringInfo(str, " :unique ");
appendStringInfo(str, node->uniqueFlag); appendStringInfo(str, node->uniqueFlag);
appendStringInfo(str, " :sortClause "); appendStringInfo(str, " :sortClause ");
...@@ -220,21 +240,31 @@ _outQuery(StringInfo str, Query *node) ...@@ -220,21 +240,31 @@ _outQuery(StringInfo str, Query *node)
} }
static void static void
_outSortGroupBy(StringInfo str, SortGroupBy *node) _outSortClause(StringInfo str, SortClause *node)
{ {
char buf[500]; char buf[500];
int i;
appendStringInfo(str, "SORTGROUPBY"); appendStringInfo(str, "SORTCLAUSE");
appendStringInfo(str, " :resno "); appendStringInfo(str, " :resdom ");
sprintf(buf," %d ", node->resno); _outNode(str, node->resdom);
appendStringInfo(str, " :range "); appendStringInfo(str, " :opoid ");
appendStringInfo(str, node->range); sprintf(buf," %u ", node->opoid);
appendStringInfo(str, " :name "); appendStringInfo(str, buf);
appendStringInfo(str, node->name); }
appendStringInfo(str, " :useOp ");
appendStringInfo(str, node->useOp); static void
_outGroupClause(StringInfo str, GroupClause *node)
{
char buf[500];
appendStringInfo(str, "GROUPCLAUSE");
appendStringInfo(str, " :entry ");
_outNode(str, node->entry);
appendStringInfo(str, " :grpOpoid ");
sprintf(buf," %u ", node->grpOpoid);
appendStringInfo(str, buf);
} }
/* /*
...@@ -252,7 +282,7 @@ _outPlanInfo(StringInfo str, Plan *node) ...@@ -252,7 +282,7 @@ _outPlanInfo(StringInfo str, Plan *node)
sprintf(buf, " :width %d", node->plan_width); sprintf(buf, " :width %d", node->plan_width);
appendStringInfo(str, buf); appendStringInfo(str, buf);
appendStringInfo(str, " :state "); appendStringInfo(str, " :state ");
appendStringInfo(str, (node->state == (EState *) NULL? "nil" : "non-NIL")); appendStringInfo(str, node->state ? "not-NULL" : "\"\"");
appendStringInfo(str, " :qptargetlist "); appendStringInfo(str, " :qptargetlist ");
_outNode(str, node->targetlist); _outNode(str, node->targetlist);
appendStringInfo(str, " :qpqual "); appendStringInfo(str, " :qpqual ");
...@@ -1544,6 +1574,9 @@ _outNode(StringInfo str, void *obj) ...@@ -1544,6 +1574,9 @@ _outNode(StringInfo str, void *obj)
case T_ColumnDef: case T_ColumnDef:
_outColumnDef(str, obj); _outColumnDef(str, obj);
break; break;
case T_TypeName:
_outTypeName(str, obj);
break;
case T_IndexElem: case T_IndexElem:
_outIndexElem(str, obj); _outIndexElem(str, obj);
break; break;
...@@ -1551,8 +1584,11 @@ _outNode(StringInfo str, void *obj) ...@@ -1551,8 +1584,11 @@ _outNode(StringInfo str, void *obj)
case T_Query: case T_Query:
_outQuery(str, obj); _outQuery(str, obj);
break; break;
case T_SortGroupBy: case T_SortClause:
_outSortGroupBy(str, obj); _outSortClause(str, obj);
break;
case T_GroupClause:
_outGroupClause(str, obj);
break; break;
case T_Plan: case T_Plan:
_outPlan(str, obj); _outPlan(str, obj);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.14 1998/01/06 18:52:22 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.15 1998/01/06 23:19:49 momjian Exp $
* *
* NOTES * NOTES
* Most of the read functions for plan nodes are tested. (In fact, they * Most of the read functions for plan nodes are tested. (In fact, they
...@@ -174,51 +174,49 @@ _readQuery() ...@@ -174,51 +174,49 @@ _readQuery()
} }
/* ---------------- /* ----------------
* _readSortGroupBy * _readSortClause
* ---------------- * ----------------
*/ */
static SortGroupBy * static SortClause *
_readSortGroupBy() _readSortClause()
{ {
SortGroupBy *local_node; SortClause *local_node;
char *token; char *token;
int length; int length;
local_node = makeNode(SortGroupBy); local_node = makeNode(SortClause);
token = lsptok(NULL, &length); /* skip the :resno */ token = lsptok(NULL, &length); /* skip the :resdom */
token = lsptok(NULL, &length); /* get resno */ token = lsptok(NULL, &length); /* get resdom */
local_node->resno = atoi(token); local_node->resdom = nodeRead(true);
token = lsptok(NULL, &length); /* skip :range */ token = lsptok(NULL, &length); /* skip :opoid */
token = lsptok(NULL, &length); /* get range */ token = lsptok(NULL, &length); /* get opoid */
if (length == 0) local_node->opoid = strtoul(token,NULL,10);
local_node->range = NULL;
else
{
local_node->range = palloc(length + 1);
StrNCpy(local_node->range, token, length+1);
}
token = lsptok(NULL, &length); /* skip :name */ return (local_node);
token = lsptok(NULL, &length); /* get name */ }
if (length == 0)
local_node->name = NULL;
else
{
local_node->name = palloc(length + 1);
StrNCpy(local_node->name, token, length+1);
}
token = lsptok(NULL, &length); /* skip :useOp */ /* ----------------
token = lsptok(NULL, &length); /* get useOp */ * _readGroupClause
if (length == 0) * ----------------
local_node->useOp = NULL; */
else static GroupClause *
{ _readGroupClause()
local_node->useOp = palloc(length + 1); {
StrNCpy(local_node->useOp, token, length+1); GroupClause *local_node;
} char *token;
int length;
local_node = makeNode(GroupClause);
token = lsptok(NULL, &length); /* skip the :entry */
token = lsptok(NULL, &length); /* get entry */
local_node->entry = nodeRead(true);
token = lsptok(NULL, &length); /* skip :grpOpoid */
token = lsptok(NULL, &length); /* get grpOpoid */
local_node->grpOpoid = strtoul(token,NULL,10);
return (local_node); return (local_node);
} }
...@@ -248,7 +246,7 @@ _getPlan(Plan *node) ...@@ -248,7 +246,7 @@ _getPlan(Plan *node)
token = lsptok(NULL, &length); /* eat the :state stuff */ token = lsptok(NULL, &length); /* eat the :state stuff */
token = lsptok(NULL, &length); /* now get the state */ token = lsptok(NULL, &length); /* now get the state */
if (!strncmp(token, "nil", 3)) if (length == 0)
{ {
node->state = (EState *) NULL; node->state = (EState *) NULL;
} }
...@@ -343,7 +341,7 @@ _readAppend() ...@@ -343,7 +341,7 @@ _readAppend()
token = lsptok(NULL, &length); /* eat :unionrelid */ token = lsptok(NULL, &length); /* eat :unionrelid */
token = lsptok(NULL, &length); /* get unionrelid */ token = lsptok(NULL, &length); /* get unionrelid */
local_node->unionrelid = atoi(token); local_node->unionrelid = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* eat :unionrtentries */ token = lsptok(NULL, &length); /* eat :unionrtentries */
local_node->unionrtentries = nodeRead(true); /* now read it */ local_node->unionrtentries = nodeRead(true); /* now read it */
...@@ -449,7 +447,7 @@ _readHashJoin() ...@@ -449,7 +447,7 @@ _readHashJoin()
token = lsptok(NULL, &length); /* eat :hashjoinop */ token = lsptok(NULL, &length); /* eat :hashjoinop */
token = lsptok(NULL, &length); /* get hashjoinop */ token = lsptok(NULL, &length); /* get hashjoinop */
local_node->hashjoinop = atoi(token); local_node->hashjoinop = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* eat :hashjointable */ token = lsptok(NULL, &length); /* eat :hashjointable */
token = lsptok(NULL, &length); /* eat hashjointable */ token = lsptok(NULL, &length); /* eat hashjointable */
...@@ -490,7 +488,7 @@ _getScan(Scan *node) ...@@ -490,7 +488,7 @@ _getScan(Scan *node)
token = lsptok(NULL, &length); /* eat :scanrelid */ token = lsptok(NULL, &length); /* eat :scanrelid */
token = lsptok(NULL, &length); /* get scanrelid */ token = lsptok(NULL, &length); /* get scanrelid */
node->scanrelid = atoi(token); node->scanrelid = strtoul(token,NULL,10);
} }
/* ---------------- /* ----------------
...@@ -735,7 +733,7 @@ _readResdom() ...@@ -735,7 +733,7 @@ _readResdom()
token = lsptok(NULL, &length); /* eat :reskey */ token = lsptok(NULL, &length); /* eat :reskey */
token = lsptok(NULL, &length); /* get reskey */ token = lsptok(NULL, &length); /* get reskey */
local_node->reskey = atoi(token); local_node->reskey = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* eat :reskeyop */ token = lsptok(NULL, &length); /* eat :reskeyop */
token = lsptok(NULL, &length); /* get reskeyop */ token = lsptok(NULL, &length); /* get reskeyop */
...@@ -816,7 +814,7 @@ _readVar() ...@@ -816,7 +814,7 @@ _readVar()
token = lsptok(NULL, &length); /* eat :varno */ token = lsptok(NULL, &length); /* eat :varno */
token = lsptok(NULL, &length); /* get varno */ token = lsptok(NULL, &length); /* get varno */
local_node->varno = atoi(token); local_node->varno = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* eat :varattno */ token = lsptok(NULL, &length); /* eat :varattno */
token = lsptok(NULL, &length); /* get varattno */ token = lsptok(NULL, &length); /* get varattno */
...@@ -854,7 +852,7 @@ _readArray() ...@@ -854,7 +852,7 @@ _readArray()
token = lsptok(NULL, &length); /* eat :arrayelemtype */ token = lsptok(NULL, &length); /* eat :arrayelemtype */
token = lsptok(NULL, &length); /* get arrayelemtype */ token = lsptok(NULL, &length); /* get arrayelemtype */
local_node->arrayelemtype = (Oid) atoi(token); local_node->arrayelemtype = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* eat :arrayelemlength */ token = lsptok(NULL, &length); /* eat :arrayelemlength */
token = lsptok(NULL, &length); /* get arrayelemlength */ token = lsptok(NULL, &length); /* get arrayelemlength */
...@@ -896,7 +894,7 @@ _readArrayRef() ...@@ -896,7 +894,7 @@ _readArrayRef()
token = lsptok(NULL, &length); /* eat :refelemtype */ token = lsptok(NULL, &length); /* eat :refelemtype */
token = lsptok(NULL, &length); /* get refelemtype */ token = lsptok(NULL, &length); /* get refelemtype */
local_node->refelemtype = (Oid) atoi(token); local_node->refelemtype = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* eat :refattrlength */ token = lsptok(NULL, &length); /* eat :refattrlength */
token = lsptok(NULL, &length); /* get refattrlength */ token = lsptok(NULL, &length); /* get refattrlength */
...@@ -947,7 +945,7 @@ _readConst() ...@@ -947,7 +945,7 @@ _readConst()
token = lsptok(NULL, &length); /* get :constlen */ token = lsptok(NULL, &length); /* get :constlen */
token = lsptok(NULL, &length); /* now read it */ token = lsptok(NULL, &length); /* now read it */
local_node->constlen = atoi(token); local_node->constlen = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* get :constisnull */ token = lsptok(NULL, &length); /* get :constisnull */
token = lsptok(NULL, &length); /* now read it */ token = lsptok(NULL, &length); /* now read it */
...@@ -1337,7 +1335,7 @@ _readRangeTblEntry() ...@@ -1337,7 +1335,7 @@ _readRangeTblEntry()
token = lsptok(NULL, &length); /* eat :inh */ token = lsptok(NULL, &length); /* eat :inh */
token = lsptok(NULL, &length); /* get :inh */ token = lsptok(NULL, &length); /* get :inh */
local_node->inh = atoi(token); local_node->inh = (token[0] == 't') ? true : false;
token = lsptok(NULL, &length); /* eat :refname */ token = lsptok(NULL, &length); /* eat :refname */
token = lsptok(NULL, &length); /* get :refname */ token = lsptok(NULL, &length); /* get :refname */
...@@ -1351,7 +1349,7 @@ _readRangeTblEntry() ...@@ -1351,7 +1349,7 @@ _readRangeTblEntry()
token = lsptok(NULL, &length); /* eat :relid */ token = lsptok(NULL, &length); /* eat :relid */
token = lsptok(NULL, &length); /* get :relid */ token = lsptok(NULL, &length); /* get :relid */
local_node->relid = atoi(token); local_node->relid = strtoul(token,NULL,10);
return (local_node); return (local_node);
} }
...@@ -1676,7 +1674,7 @@ _readOrderKey() ...@@ -1676,7 +1674,7 @@ _readOrderKey()
token = lsptok(NULL, &length); /* get :array_index */ token = lsptok(NULL, &length); /* get :array_index */
token = lsptok(NULL, &length); /* now read it */ token = lsptok(NULL, &length); /* now read it */
local_node->array_index = atoi(token); local_node->array_index = strtoul(token,NULL,10);
return (local_node); return (local_node);
} }
...@@ -1838,7 +1836,7 @@ _readHInfo() ...@@ -1838,7 +1836,7 @@ _readHInfo()
token = lsptok(NULL, &length); /* get :hashop */ token = lsptok(NULL, &length); /* get :hashop */
token = lsptok(NULL, &length); /* now read it */ token = lsptok(NULL, &length); /* now read it */
local_node->hashop = atoi(token); local_node->hashop = strtoul(token,NULL,10);
token = lsptok(NULL, &length); /* get :jmkeys */ token = lsptok(NULL, &length); /* get :jmkeys */
local_node->jmethod.jmkeys = nodeRead(true); /* now read it */ local_node->jmethod.jmkeys = nodeRead(true); /* now read it */
...@@ -2108,9 +2106,13 @@ parsePlanString(void) ...@@ -2108,9 +2106,13 @@ parsePlanString(void)
{ {
return_value = _readQuery(); return_value = _readQuery();
} }
else if (!strncmp(token, "SORTGROUPBY", 11)) else if (!strncmp(token, "SORTCLAUSE", 10))
{
return_value = _readSortClause();
}
else if (!strncmp(token, "GROUPCLAUSE", 10))
{ {
return_value = _readSortGroupBy(); return_value = _readGroupClause();
} }
else else
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册