Cleanup of sort nodes and use of strtoul .
authorBruce Momjian
Tue, 6 Jan 1998 23:19:49 +0000 (23:19 +0000)
committerBruce Momjian
Tue, 6 Jan 1998 23:19:49 +0000 (23:19 +0000)
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c

index 7232d5a026aa573fb20ccb4a3f6a4dab7f21eb21..2a8602852c1459363caa26d6de328a37c7dec2cf 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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
  *   Every (plan) node in POSTGRES has an associated "out" routine which
@@ -80,7 +80,7 @@ _outCreateStmt(StringInfo str, CreateStmt *node)
    _outNode(str, node->inhRelnames);
    appendStringInfo(str, " :constraints");
    _outNode(str, node->constraints);
-} /* _outCreateStmt() */
+}
 
 static void
 _outIndexStmt(StringInfo str, IndexStmt *node)
@@ -102,10 +102,10 @@ _outIndexStmt(StringInfo str, IndexStmt *node)
    appendStringInfo(str, " :rangetable ");
    _outNode(str, node->rangetable);
    appendStringInfo(str, " :lossy ");
-   appendStringInfo(str, (*node->lossy ? "y": "n"));
+   appendStringInfo(str, (*node->lossy ? "true": "false"));
    appendStringInfo(str, " :unique ");
-   appendStringInfo(str, (node->unique ? "y": "n"));
-} /* _outIndexStmt() */
+   appendStringInfo(str, (node->unique ? "true": "false"));
+}
 
 static void
 _outColumnDef(StringInfo str, ColumnDef *node)
@@ -117,12 +117,32 @@ _outColumnDef(StringInfo str, ColumnDef *node)
    appendStringInfo(str, " :typename ");
    _outNode(str, node->typename);
    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, node->defval);
    appendStringInfo(str, " :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
 _outIndexElem(StringInfo str, IndexElem *node)
@@ -137,7 +157,7 @@ _outIndexElem(StringInfo str, IndexElem *node)
    appendStringInfo(str, node->class);
    appendStringInfo(str, " :tname");
    _outNode(str, node->tname);
-} /* _outIndexElem() */
+}
 
 static void
 _outQuery(StringInfo str, Query *node)
@@ -190,11 +210,11 @@ _outQuery(StringInfo str, Query *node)
    appendStringInfo(str, " :into ");
    appendStringInfo(str, node->into);
    appendStringInfo(str, " :isPortal ");
-   appendStringInfo(str, (node->isPortal ? "y": "n"));
+   appendStringInfo(str, (node->isPortal ? "true" : "false"));
    appendStringInfo(str, " :isBinary ");
-   appendStringInfo(str, (node->isBinary ? "y": "n"));
+   appendStringInfo(str, (node->isBinary ? "true" : "false"));
    appendStringInfo(str, " :unionall ");
-   appendStringInfo(str, (node->unionall ? "y": "n"));
+   appendStringInfo(str, (node->unionall ? "true" : "false"));
    appendStringInfo(str, " :unique ");
    appendStringInfo(str, node->uniqueFlag);
    appendStringInfo(str, " :sortClause ");
@@ -220,21 +240,31 @@ _outQuery(StringInfo str, Query *node)
 }
 
 static void
-_outSortGroupBy(StringInfo str, SortGroupBy *node)
+_outSortClause(StringInfo str, SortClause *node)
 {
    char        buf[500];
-   int i;
    
-   appendStringInfo(str, "SORTGROUPBY");
+   appendStringInfo(str, "SORTCLAUSE");
 
-   appendStringInfo(str, " :resno ");
-   sprintf(buf," %d ", node->resno);
-   appendStringInfo(str, " :range ");
-   appendStringInfo(str, node->range);
-   appendStringInfo(str, " :name ");
-   appendStringInfo(str, node->name);
-   appendStringInfo(str, " :useOp ");
-   appendStringInfo(str, node->useOp);
+   appendStringInfo(str, " :resdom ");
+   _outNode(str, node->resdom);
+   appendStringInfo(str, " :opoid ");
+   sprintf(buf," %u ", node->opoid);
+   appendStringInfo(str, buf);
+}
+
+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)
    sprintf(buf, " :width %d", node->plan_width);
    appendStringInfo(str, buf);
    appendStringInfo(str, " :state ");
-   appendStringInfo(str,  (node->state == (EState *) NULL? "nil" : "non-NIL"));
+   appendStringInfo(str,  node->state ? "not-NULL" : "\"\"");
    appendStringInfo(str, " :qptargetlist ");
    _outNode(str, node->targetlist);
    appendStringInfo(str, " :qpqual ");
@@ -1544,6 +1574,9 @@ _outNode(StringInfo str, void *obj)
            case T_ColumnDef:
                _outColumnDef(str, obj);
                break;
+           case T_TypeName:
+               _outTypeName(str, obj);
+               break;
            case T_IndexElem:
                _outIndexElem(str, obj);
                break;
@@ -1551,8 +1584,11 @@ _outNode(StringInfo str, void *obj)
            case T_Query:
                _outQuery(str, obj);
                break;
-           case T_SortGroupBy:
-               _outSortGroupBy(str, obj);
+           case T_SortClause:
+               _outSortClause(str, obj);
+               break;
+           case T_GroupClause:
+               _outGroupClause(str, obj);
                break;
            case T_Plan:
                _outPlan(str, obj);
index d43646c92d6e12258fb12475344ee002ec9db545..6a7a15280ac1a14345815c2c4ff9970e841848b2 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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
  *   Most of the read functions for plan nodes are tested. (In fact, they
@@ -174,51 +174,49 @@ _readQuery()
 }
 
 /* ----------------
- *     _readSortGroupBy
+ *     _readSortClause
  * ----------------
  */
-static SortGroupBy *
-_readSortGroupBy()
+static SortClause *
+_readSortClause()
 {
-   SortGroupBy *local_node;
+   SortClause *local_node;
    char       *token;
    int         length;
 
-   local_node = makeNode(SortGroupBy);
+   local_node = makeNode(SortClause);
 
-   token = lsptok(NULL, &length);      /* skip the :resno */
-   token = lsptok(NULL, &length);      /* get resno */
-   local_node->resno = atoi(token);
+   token = lsptok(NULL, &length);      /* skip the :resdom */
+   token = lsptok(NULL, &length);      /* get resdom */
+   local_node->resdom = nodeRead(true);
 
-   token = lsptok(NULL, &length);      /* skip :range */
-   token = lsptok(NULL, &length);      /* get range */
-   if (length == 0)
-       local_node->range = NULL;
-   else
-   {
-       local_node->range = palloc(length + 1);
-       StrNCpy(local_node->range, token, length+1);
-   }
+   token = lsptok(NULL, &length);      /* skip :opoid */
+   token = lsptok(NULL, &length);      /* get opoid */
+   local_node->opoid = strtoul(token,NULL,10);
 
-   token = lsptok(NULL, &length);      /* skip :name */
-   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);
-   }
+   return (local_node);
+}
 
-   token = lsptok(NULL, &length);      /* skip :useOp */
-   token = lsptok(NULL, &length);      /* get useOp */
-   if (length == 0)
-       local_node->useOp = NULL;
-   else
-   {
-       local_node->useOp = palloc(length + 1);
-       StrNCpy(local_node->useOp, token, length+1);
-   }
+/* ----------------
+ *     _readGroupClause
+ * ----------------
+ */
+static GroupClause *
+_readGroupClause()
+{
+   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);
 }
@@ -248,7 +246,7 @@ _getPlan(Plan *node)
    token = lsptok(NULL, &length);      /* eat the :state stuff */
    token = lsptok(NULL, &length);      /* now get the state */
 
-   if (!strncmp(token, "nil", 3))
+   if (length == 0)
    {
        node->state = (EState *) NULL;
    }
@@ -343,7 +341,7 @@ _readAppend()
 
    token = lsptok(NULL, &length);      /* eat :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 */
    local_node->unionrtentries = nodeRead(true);        /* now read it */
@@ -449,7 +447,7 @@ _readHashJoin()
 
    token = lsptok(NULL, &length);      /* eat :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 */
@@ -490,7 +488,7 @@ _getScan(Scan *node)
 
    token = lsptok(NULL, &length);      /* eat :scanrelid */
    token = lsptok(NULL, &length);      /* get scanrelid */
-   node->scanrelid = atoi(token);
+   node->scanrelid = strtoul(token,NULL,10);
 }
 
 /* ----------------
@@ -735,7 +733,7 @@ _readResdom()
 
    token = lsptok(NULL, &length);      /* eat :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);      /* get reskeyop */
@@ -816,7 +814,7 @@ _readVar()
 
    token = lsptok(NULL, &length);      /* eat :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);      /* get varattno */
@@ -854,7 +852,7 @@ _readArray()
 
    token = lsptok(NULL, &length);      /* eat :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);      /* get arrayelemlength */
@@ -896,7 +894,7 @@ _readArrayRef()
 
    token = lsptok(NULL, &length);      /* eat :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);      /* get refattrlength */
@@ -947,7 +945,7 @@ _readConst()
 
    token = lsptok(NULL, &length);      /* get :constlen */
    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);      /* now read it */
@@ -1337,7 +1335,7 @@ _readRangeTblEntry()
 
    token = lsptok(NULL, &length);      /* eat :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);      /* get :refname */
@@ -1351,7 +1349,7 @@ _readRangeTblEntry()
 
    token = lsptok(NULL, &length);      /* eat :relid */
    token = lsptok(NULL, &length);      /* get :relid */
-   local_node->relid = atoi(token);
+   local_node->relid = strtoul(token,NULL,10);
 
    return (local_node);
 }
@@ -1676,7 +1674,7 @@ _readOrderKey()
    token = lsptok(NULL, &length);      /* get :array_index */
    token = lsptok(NULL, &length);      /* now read it */
 
-   local_node->array_index = atoi(token);
+   local_node->array_index = strtoul(token,NULL,10);
 
    return (local_node);
 }
@@ -1838,7 +1836,7 @@ _readHInfo()
    token = lsptok(NULL, &length);      /* get :hashop */
    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 */
    local_node->jmethod.jmkeys = nodeRead(true);        /* now read it */
@@ -2108,9 +2106,13 @@ parsePlanString(void)
    {
        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
    {