more cleanups...of note, appendStringInfo now performs like sprintf(),
authorMarc G. Fournier
Mon, 14 Dec 1998 08:11:17 +0000 (08:11 +0000)
committerMarc G. Fournier
Mon, 14 Dec 1998 08:11:17 +0000 (08:11 +0000)
where you state a format and arguments.  the old behavior required
each appendStringInfo to have to have a sprintf() before it if any
formatting was required.

Also shortened several instances where there were multiple appendStringInfo()
calls in a row, doing nothing more then adding one more word to the String,
instead of doing them all in one call.

12 files changed:
src/backend/commands/explain.c
src/backend/commands/user.c
src/backend/commands/view.c
src/backend/executor/execAmi.c
src/backend/executor/nodeHash.c
src/backend/lib/stringinfo.c
src/backend/libpq/portal.c
src/backend/libpq/util.c
src/backend/nodes/outfuncs.c
src/backend/utils/adt/nabstime.c
src/backend/utils/sort/psort.c
src/include/lib/stringinfo.h

index 1a61c684240dfab7489625fa86f413578bf55a2f..5b547adb2f3244052b0a194d0c4d5ca21be074ed 100644 (file)
@@ -1,15 +1,11 @@
-/*-------------------------------------------------------------------------
- *
+/*
  * explain.c--
  *   Explain the query execution plan
  *
  * Copyright (c) 1994-5, Regents of the University of California
  *
+ *   $Id: explain.c,v 1.29 1998/12/14 08:11:00 scrappy Exp $
  *
- * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.28 1998/12/14 05:18:43 scrappy Exp $
- *
- *-------------------------------------------------------------------------
  */
 #include 
 #include 
@@ -217,7 +213,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
            {
                relation = RelationIdCacheGetRelation((int) lfirst(l));
                if (++i > 1)
+               {
                    appendStringInfo(str, ", ");
+               }
                appendStringInfo(str, (RelationGetRelationName(relation))->data);
            }
        case T_SeqScan:
@@ -239,9 +237,8 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
    }
    if (es->printCost)
    {
-       snprintf(buf, 1000, "  (cost=%.2f size=%d width=%d)",
+       appendStringInfo(str, "  (cost=%.2f size=%d width=%d)",
                plan->cost, plan->plan_size, plan->plan_width);
-       appendStringInfo(str, buf);
    }
    appendStringInfo(str, "\n");
 
@@ -251,14 +248,18 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
        List       *saved_rtable = es->rtable;
        List       *lst;
 
-       for (i = 0; i < indent; i++)
+       for (i = 0; i < indent; i++) 
+       {
            appendStringInfo(str, "  ");
+       }
        appendStringInfo(str, "  InitPlan\n");
        foreach(lst, plan->initPlan)
        {
            es->rtable = ((SubPlan *) lfirst(lst))->rtable;
            for (i = 0; i < indent; i++)
+           {
                appendStringInfo(str, "  ");
+           }
            appendStringInfo(str, "    ->  ");
            explain_outNode(str, ((SubPlan *) lfirst(lst))->plan, indent + 2, es);
        }
@@ -269,7 +270,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
    if (outerPlan(plan))
    {
        for (i = 0; i < indent; i++)
+       {
            appendStringInfo(str, "  ");
+       }
        appendStringInfo(str, "  ->  ");
        explain_outNode(str, outerPlan(plan), indent + 3, es);
    }
@@ -278,7 +281,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
    if (innerPlan(plan))
    {
        for (i = 0; i < indent; i++)
+       {
            appendStringInfo(str, "  ");
+       }
        appendStringInfo(str, "  ->  ");
        explain_outNode(str, innerPlan(plan), indent + 3, es);
    }
@@ -290,13 +295,17 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
        List       *lst;
 
        for (i = 0; i < indent; i++)
+       {
            appendStringInfo(str, "  ");
+       }
        appendStringInfo(str, "  SubPlan\n");
        foreach(lst, plan->subPlan)
        {
            es->rtable = ((SubPlan *) lfirst(lst))->rtable;
            for (i = 0; i < indent; i++)
+           {
                appendStringInfo(str, "  ");
+           }
            appendStringInfo(str, "    ->  ");
            explain_outNode(str, ((SubPlan *) lfirst(lst))->plan, indent + 4, es);
        }
@@ -327,7 +336,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
                es->rtable = nth(whichplan, appendplan->unionrtables);
 
            for (i = 0; i < indent; i++)
+           {
                appendStringInfo(str, "  ");
+           }
            appendStringInfo(str, "    ->  ");
 
            explain_outNode(str, subnode, indent + 4, es);
index a547156ed738a8d9c4e8dd7de06b3d90749830f7..e0c0e51ea13a3e6276c50847fa4a02fbe06f405e 100644 (file)
@@ -5,11 +5,11 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: user.c,v 1.21 1998/12/14 06:50:18 scrappy Exp $
+ * $Id: user.c,v 1.22 1998/12/14 08:11:00 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
-#include              /* for sprintf() */
+#include              
 #include 
 #include 
 #include 
@@ -68,7 +68,7 @@ UpdatePgPwdFile(char *sql)
     * SEPCHAR character as the delimiter between fields.  Then rename the
     * file to its final name.
     */
-   snprintf(sql, QRY_LENGTH, 
+   snprintf(sql, SQL_LENGTH, 
            "copy %s to '%s' using delimiters %s", 
            ShadowRelationName, tempname, CRYPT_PWD_FILE_SEPCHAR);
    pg_exec_query(sql);
@@ -173,7 +173,7 @@ DefineUser(CreateUserStmt *stmt)
            (stmt->createdb && *stmt->createdb) ? ",'t','t'" : ",'f','t'",
            (stmt->createuser && *stmt->createuser) ? ",'t','t'" : ",'f','t'",
            stmt->password ? stmt->password : "''",
-           stmt->validUntil ? stmt->valudUntil : "");
+           stmt->validUntil ? stmt->validUntil : "");
 
    pg_exec_query(sql);
 
@@ -262,20 +262,20 @@ AlterUser(AlterUserStmt *stmt)
    if (stmt->createdb)
    {
        snprintf(sql, SQL_LENGTH, "%s %susecreatedb='%s'",
-               stmt->password ? "," : "",
-               *stmt->createdb ? "t" : "f");
+               sql, stmt->password ? "," : "", *stmt->createdb ? "t" : "f");
    }
 
    if (stmt->createuser)
    {
        snprintf(sql, SQL_LENGTH, "%s %susesuper='%s'",
-               (stmt->password || stmt->createdb) ? "," : "",
+               sql, (stmt->password || stmt->createdb) ? "," : "",
                *stmt->createuser ? "t" : "f");
    }
 
    if (stmt->validUntil)
    {
        snprintf(sql, SQL_LENGTH, "%s %svaluntil='%s'",
+               sql,
                (stmt->password || stmt->createdb || stmt->createuser) ? "," : "",
                stmt->validUntil);
    }
index 1132b1f02e2cf77b6f96232b09b6d3fedc7b54e4..b37acb6d25eef739042c78ec807ce8711fe499a2 100644 (file)
@@ -5,11 +5,11 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: view.c,v 1.28 1998/12/14 06:50:18 scrappy Exp $
+ *  $Id: view.c,v 1.29 1998/12/14 08:11:01 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
-#include              /* for sprintf() */
+#include          
 #include 
 
 #include 
index 17936d75d05ba561d2098cd2b3351b47a9649923..a1f26d9fc1ddb97e97097e1646625a621484a061 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: execAmi.c,v 1.27 1998/12/14 06:50:20 scrappy Exp $
+ *  $Id: execAmi.c,v 1.28 1998/12/14 08:11:02 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -24,7 +24,7 @@
  *     ExecCreatR      function to create temporary relations
  *
  */
-#include              /* for sprintf() */
+#include          
 
 #include "postgres.h"
 
index 1f900bdb17234b0219cb0eb4c8d305e186c4f51a..5f528850ffac17b0ecd45c025abb28bd7a5b7d92 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 1994, Regents of the University of California
  *
  *
- *  $Id: nodeHash.c,v 1.26 1998/12/14 06:50:21 scrappy Exp $
+ *  $Id: nodeHash.c,v 1.27 1998/12/14 08:11:02 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,7 +19,7 @@
  */
 
 #include 
-#include              /* for sprintf() */
+#include      
 #include 
 #include 
 #include 
index 1c5a0f4f578ff43db4983cfd19bc0c811e3751c5..ed891c5f841689d360a3716ae1a54a4f79568ad9 100644 (file)
@@ -1,5 +1,4 @@
-/*-------------------------------------------------------------------------
- *
+/*
  * stringinfo.c--
  *   These are routines that can be used to write informations to a string,
  *   without having to worry about string lengths, space allocation etc.
@@ -7,25 +6,24 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *
- * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/lib/stringinfo.c,v 1.12 1998/11/08 19:22:24 tgl Exp $
- *
- *-------------------------------------------------------------------------
+ *   $Id: stringinfo.c,v 1.13 1998/12/14 08:11:04 scrappy Exp $
  */
+
+#include 
 #include 
 
+#include 
+
 #include 
 
 #include 
 #include 
 
-/*---------------------------------------------------------------------
+/*
  * makeStringInfo
  *
  * Create a StringInfoData & return a pointer to it.
  *
- *---------------------------------------------------------------------
  */
 StringInfo
 makeStringInfo()
@@ -52,7 +50,7 @@ makeStringInfo()
    return res;
 }
 
-/*---------------------------------------------------------------------
+/*
  * appendStringInfo
  *
  * append to the current 'StringInfo' a new string.
@@ -60,26 +58,31 @@ makeStringInfo()
  * some more...
  *
  * NOTE: if we reallocate space, we pfree the old one!
- *---------------------------------------------------------------------
+ *
  */
 void
-appendStringInfo(StringInfo str, char *buffer)
+appendStringInfo(StringInfo str, const char *fmt,...)
 {
-   int         buflen,
+   int     buflen,
                newlen,
                needed;
-   char       *s;
+   char    *s,
+               buffer[512];
+
+  va_list args;
+   va_start(args, fmt);
+  buflen = vsnprintf(buffer, 512, fmt, args);
+  va_end(args);
 
    Assert(str != NULL);
-   if (buffer == NULL)
-       buffer = "<>";
+   if (buflen == 0)
+       strcpy(buffer, "<>");
 
    /*
     * do we have enough space to append the new string? (don't forget to
     * count the null string terminating char!) If no, then reallocate
     * some more.
     */
-   buflen = strlen(buffer);
    needed = str->len + buflen + 1;
    if (needed > str->maxlen)
    {
@@ -99,8 +102,7 @@ appendStringInfo(StringInfo str, char *buffer)
        if (s == NULL)
        {
            elog(ERROR,
-                "appendStringInfo: Out of memory (%d bytes requested)",
-                newlen);
+                "appendStringInfo: Out of memory (%d bytes requested)", newlen);
        }
        /*
         * transfer the data.  strcpy() would work, but is probably a tad
index d116a3c12cc336ecaa5e08e6c25f7ed6176f74b4..0dd744bbd1870cfc1292b9abe951028647c202fe 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: portal.c,v 1.18 1998/12/14 06:50:26 scrappy Exp $
+ *  $Id: portal.c,v 1.19 1998/12/14 08:11:06 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,7 +53,7 @@
  *     see utils/mmgr/portalmem.c for why. -cim 2/22/91
  *
  */
-#include              /* for sprintf() */
+#include          
 #include 
 
 #include 
index c9cd23641eb802e2a3d184548bd304f1041ede71..94ff9169e4815aaae220a1a571fb5d29fef09210 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: util.c,v 1.6 1998/12/14 06:50:27 scrappy Exp $
+ *  $Id: util.c,v 1.7 1998/12/14 08:11:07 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
  *     PQuntrace       - turn off pqdebug() tracing
  */
 
-#include              /* for sprintf() */
+#include          
 #include 
 
 #include 
index 8115957e7a332d71135f582a88b13f152ff015f5..c79c43421c139cdd7fcf23d1ef694c91eefa399f 100644 (file)
@@ -1,11 +1,11 @@
-/*-------------------------------------------------------------------------
+/*
  *
  * outfuncs.c--
  *   routines to convert a node to ascii representation
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: outfuncs.c,v 1.51 1998/12/14 06:50:28 scrappy Exp $
+ *  $Id: outfuncs.c,v 1.52 1998/12/14 08:11:09 scrappy Exp $
  *
  * NOTES
  *   Every (plan) node in POSTGRES has an associated "out" routine which
@@ -18,7 +18,6 @@
  *   passed to them. This argument contains the string holding the ASCII
  *   representation plus some other information (string length, etc.)
  *
- *-------------------------------------------------------------------------
  */
 #include 
 #include "postgres.h"
@@ -57,14 +56,12 @@ static void _outNode(StringInfo str, void *obj);
 static void
 _outIntList(StringInfo str, List *list)
 {
-   List       *l;
-   char        buf[500];
+   List    *l;
 
    appendStringInfo(str, "(");
    foreach(l, list)
    {
-       sprintf(buf, " %d ", (int) lfirst(l));
-       appendStringInfo(str, buf);
+       appendStringInfo(str, " %d ", (int) lfirst(l));
    }
    appendStringInfo(str, ")");
 }
@@ -72,11 +69,8 @@ _outIntList(StringInfo str, List *list)
 static void
 _outCreateStmt(StringInfo str, CreateStmt *node)
 {
-   appendStringInfo(str, " CREATE ");
+   appendStringInfo(str, " CREATE :relname %s :columns ", node->relname);
 
-   appendStringInfo(str, " :relname ");
-   appendStringInfo(str, node->relname);
-   appendStringInfo(str, " :columns ");
    _outNode(str, node->tableElts);
    appendStringInfo(str, " :inhRelnames ");
    _outNode(str, node->inhRelnames);
@@ -87,15 +81,10 @@ _outCreateStmt(StringInfo str, CreateStmt *node)
 static void
 _outIndexStmt(StringInfo str, IndexStmt *node)
 {
-   appendStringInfo(str, " INDEX ");
+   appendStringInfo(str, 
+           " INDEX :idxname %s :relname %s :accessMethod %s :indexParams ",
+           node->idxname, node->relname, node->accessMethod);
 
-   appendStringInfo(str, " :idxname ");
-   appendStringInfo(str, node->idxname);
-   appendStringInfo(str, " :relname ");
-   appendStringInfo(str, node->relname);
-   appendStringInfo(str, " :accessMethod ");
-   appendStringInfo(str, node->accessMethod);
-   appendStringInfo(str, " :indexParams ");
    _outNode(str, node->indexParams);
    appendStringInfo(str, " :withClause ");
    _outNode(str, node->withClause);
@@ -103,28 +92,24 @@ _outIndexStmt(StringInfo str, IndexStmt *node)
    _outNode(str, node->whereClause);
    appendStringInfo(str, " :rangetable ");
    _outNode(str, node->rangetable);
-   appendStringInfo(str, " :lossy ");
-   appendStringInfo(str, (node->lossy ? "true" : "false"));
-   appendStringInfo(str, " :unique ");
-   appendStringInfo(str, (node->unique ? "true" : "false"));
+
+   appendStringInfo(str, " :lossy %s :unique %s ",
+           node->lossy ? "true" : "false",
+           node->unique ? "true" : "false");
 }
 
 #ifdef PARSEDEBUG
 static void
 _outSelectStmt(StringInfo str, SelectStmt *node)
 {
-   appendStringInfo(str, "SELECT");
-
-   appendStringInfo(str, " :where ");
+   appendStringInfo(str, "SELECT :where ");
    _outNode(str, node->whereClause);
 }
 
 static void
 _outFuncCall(StringInfo str, FuncCall *node)
 {
-   appendStringInfo(str, "FUNCTION ");
-   appendStringInfo(str, node->funcname);
-   appendStringInfo(str, " :args ");
+   appendStringInfo(str, "FUNCTION %s :args ", node->funcname);
    _outNode(str, node->args);
 }
 
@@ -133,24 +118,18 @@ _outFuncCall(StringInfo str, FuncCall *node)
 static void
 _outColumnDef(StringInfo str, ColumnDef *node)
 {
-   appendStringInfo(str, " COLUMNDEF ");
-
-   appendStringInfo(str, " :colname ");
-   appendStringInfo(str, node->colname);
-   appendStringInfo(str, " :typename ");
+   appendStringInfo(str, " COLUMNDEF :colname %s :typename ", node->colname);
    _outNode(str, node->typename);
-   appendStringInfo(str, " :is_not_null ");
-   appendStringInfo(str, (node->is_not_null ? "true" : "false"));
-   appendStringInfo(str, " :defval ");
-   appendStringInfo(str, node->defval);
-   appendStringInfo(str, " :constraints ");
+
+   appendStringInfo(str, " :is_not_null %s :defval %s :constraints ",
+           node->is_not_null ? "true" : "false", node->defval);
    _outNode(str, node->constraints);
 }
 
 static void
 _outTypeName(StringInfo str, TypeName *node)
 {
-   char        buf[500];
+   char    buf[500];
 
    appendStringInfo(str, " TYPENAME ");
 
@@ -161,7 +140,7 @@ _outTypeName(StringInfo str, TypeName *node)
    appendStringInfo(str, " :setof ");
    appendStringInfo(str, (node->setof ? "true" : "false"));
    appendStringInfo(str, " :typmod ");
-   sprintf(buf, " %d ", node->typmod);
+   snprintf(buf, 500, " %d ", node->typmod);
    appendStringInfo(str, buf);
    appendStringInfo(str, " :arrayBounds ");
    _outNode(str, node->arrayBounds);
@@ -185,12 +164,12 @@ _outIndexElem(StringInfo str, IndexElem *node)
 static void
 _outQuery(StringInfo str, Query *node)
 {
-   char        buf[500];
+   char    buf[500];
 
    appendStringInfo(str, " QUERY ");
 
    appendStringInfo(str, " :command ");
-   sprintf(buf, " %d ", node->commandType);
+   snprintf(buf, 500, " %d ", node->commandType);
    appendStringInfo(str, buf);
 
    if (node->utilityStmt)
@@ -227,7 +206,7 @@ _outQuery(StringInfo str, Query *node)
    }
 
    appendStringInfo(str, " :resultRelation ");
-   sprintf(buf, " %d ", node->resultRelation);
+   snprintf(buf, 500, " %d ", node->resultRelation);
    appendStringInfo(str, buf);
    appendStringInfo(str, " :into ");
    appendStringInfo(str, node->into);
@@ -266,28 +245,28 @@ _outQuery(StringInfo str, Query *node)
 static void
 _outSortClause(StringInfo str, SortClause *node)
 {
-   char        buf[500];
+   char    buf[500];
 
    appendStringInfo(str, " SORTCLAUSE ");
 
    appendStringInfo(str, " :resdom ");
    _outNode(str, node->resdom);
    appendStringInfo(str, " :opoid ");
-   sprintf(buf, " %u ", node->opoid);
+   snprintf(buf, 500, " %u ", node->opoid);
    appendStringInfo(str, buf);
 }
 
 static void
 _outGroupClause(StringInfo str, GroupClause *node)
 {
-   char        buf[500];
+   char    buf[500];
 
    appendStringInfo(str, " GROUPCLAUSE ");
 
    appendStringInfo(str, " :entry ");
    _outNode(str, node->entry);
    appendStringInfo(str, " :grpOpoid ");
-   sprintf(buf, " %u ", node->grpOpoid);
+   snprintf(buf, 500, " %u ", node->grpOpoid);
    appendStringInfo(str, buf);
 }
 
@@ -297,13 +276,13 @@ _outGroupClause(StringInfo str, GroupClause *node)
 static void
 _outPlanInfo(StringInfo str, Plan *node)
 {
-   char        buf[500];
+   char    buf[500];
 
-   sprintf(buf, " :cost %g ", node->cost);
+   snprintf(buf, 500, " :cost %g ", node->cost);
    appendStringInfo(str, buf);
-   sprintf(buf, " :size %d ", node->plan_size);
+   snprintf(buf, 500, " :size %d ", node->plan_size);
    appendStringInfo(str, buf);
-   sprintf(buf, " :width %d ", node->plan_width);
+   snprintf(buf, 500, " :width %d ", node->plan_width);
    appendStringInfo(str, buf);
    appendStringInfo(str, " :state ");
    appendStringInfo(str, node->state ? "not-NULL" : "<>");
@@ -321,7 +300,7 @@ _outPlanInfo(StringInfo str, Plan *node)
    _outIntList(str, node->locParam);
    appendStringInfo(str, " :initplan ");
    _outNode(str, node->initPlan);
-   sprintf(buf, " :nprm %d ", node->nParamExec);
+   snprintf(buf, 500, " :nprm %d ", node->nParamExec);
    appendStringInfo(str, buf);
 }
 
@@ -363,7 +342,7 @@ _outAppend(StringInfo str, Append *node)
    appendStringInfo(str, " :unionrtables ");
    _outNode(str, node->unionrtables);
 
-   sprintf(buf, " :inheritrelid %d ", node->inheritrelid);
+   snprintf(buf, 500, " :inheritrelid %d ", node->inheritrelid);
    appendStringInfo(str, buf);
 
    appendStringInfo(str, " :inheritrtable ");
@@ -406,13 +385,13 @@ _outMergeJoin(StringInfo str, MergeJoin *node)
    appendStringInfo(str, " :mergeclauses ");
    _outNode(str, node->mergeclauses);
 
-   sprintf(buf, " :mergejoinop %u ", node->mergejoinop);
+   snprintf(buf, 500, " :mergejoinop %u ", node->mergejoinop);
    appendStringInfo(str, buf);
 
-   sprintf(buf, " :mergerightorder %u ", node->mergerightorder[0]);
+   snprintf(buf, 500, " :mergerightorder %u ", node->mergerightorder[0]);
    appendStringInfo(str, buf);
 
-   sprintf(buf, " :mergeleftorder %u ", node->mergeleftorder[0]);
+   snprintf(buf, 500, " :mergeleftorder %u ", node->mergeleftorder[0]);
    appendStringInfo(str, buf);
 }
 
index e05352d39d6c8b781bbe58e1b44448232bd03c69..af30131630a4a632cb56da3a2b8debe77e7d9bd4 100644 (file)
@@ -1,15 +1,11 @@
-/*-------------------------------------------------------------------------
- *
+/*
  * nabstime.c--
  *   parse almost any absolute date getdate(3) can (& some it can't)
  *
  * Copyright (c) 1994, Regents of the University of California
  *
+ *   $Id: nabstime.c,v 1.48 1998/12/14 08:11:12 scrappy Exp $
  *
- * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.47 1998/12/13 23:34:17 thomas Exp $
- *
- *-------------------------------------------------------------------------
  */
 #include 
 #include 
index 5a8695c8c1392380fd09ab06d3f5e1b1123a2c4b..d73be1210b0335324df38c5a29606c40c406a93e 100644 (file)
@@ -1,13 +1,10 @@
-/*-------------------------------------------------------------------------
- *
+/*
  * psort.c--
  *   Polyphase merge sort.
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *
- * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.44 1998/12/14 05:19:13 scrappy Exp $
+ *   $Id: psort.c,v 1.45 1998/12/14 08:11:14 scrappy Exp $
  *
  * NOTES
  *     Sorts the first relation into the second relation.
@@ -31,7 +28,7 @@
  *
  *     Arguments? Variables?
  *             MAXMERGE, MAXTAPES
- *-------------------------------------------------------------------------
+ *
  */
 #include 
 #include 
@@ -323,26 +320,34 @@ initialrun(Sort *node)
        tp->tp_dummy--;
        PS(node)->TotalDummy--;
        if (tp->tp_dummy < (tp + 1)->tp_dummy)
+       {
            tp++;
-       else if (tp->tp_dummy != 0)
-           tp = PS(node)->Tape;
-       else
+       }
+       else 
        {
-           PS(node)->Level++;
-           baseruns = PS(node)->Tape[0].tp_fib;
-           for (tp = PS(node)->Tape;
-                tp - PS(node)->Tape < PS(node)->TapeRange; tp++)
+           if (tp->tp_dummy != 0)
            {
-               PS(node)->TotalDummy +=
-                   (tp->tp_dummy = baseruns
-                    + (tp + 1)->tp_fib
-                    - tp->tp_fib);
-               tp->tp_fib = baseruns
-                   + (tp + 1)->tp_fib;
+               tp = PS(node)->Tape;
            }
-           tp = PS(node)->Tape;/* D4 */
-       }                       /* D3 */
+           else
+           {
+               PS(node)->Level++;
+               baseruns = PS(node)->Tape[0].tp_fib;
+               for (tp = PS(node)->Tape;
+                    tp - PS(node)->Tape < PS(node)->TapeRange; tp++)
+               {
+                   PS(node)->TotalDummy +=
+                       (tp->tp_dummy = baseruns
+                        + (tp + 1)->tp_fib
+                        - tp->tp_fib);
+                   tp->tp_fib = baseruns
+                       + (tp + 1)->tp_fib;
+               }
+               tp = PS(node)->Tape;/* D4 */
+           }                       /* D3 */
+       }
        if (extrapasses)
+       {
            if (--extrapasses)
            {
                dumptuples(tp->tp_file, node);
@@ -353,7 +358,7 @@ initialrun(Sort *node)
            {
                break;
            }
-
+       }
        if ((bool) createrun(node, tp->tp_file) == false)
            extrapasses = 1 + (PS(node)->Tuples != NULL);
        /* D2 */
@@ -550,7 +555,9 @@ createrun(Sort *node, FILE *file)
            memtuples[t_last] = tup;
        }
        else
+       {
            puttuple(&PS(node)->Tuples, tup, 0, &PS(node)->treeContext);
+       }
    }
    if (lasttuple != NULL)
    {
@@ -639,9 +646,10 @@ merge(Sort *node, struct tape * dest)
    tp->tp_fib += times;
    /* Tape[].tp_fib (A[]) is set to proper exit values */
 
-   if (PS(node)->TotalDummy < PS(node)->TapeRange)     /* no complete dummy
-                                                        * runs */
+   if (PS(node)->TotalDummy < PS(node)->TapeRange) /* no complete dummy runs */
+   {
        outdummy = 0;
+   }
    else
    {
        outdummy = PS(node)->TotalDummy;        /* a large positive number */
index 2c32fb4e92d5be7f785f7e6348f209d4291925cf..269342c84e026898e445a826f607e0bfd8bd75be 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: stringinfo.h,v 1.7 1998/09/01 04:36:21 momjian Exp $
+ * $Id: stringinfo.h,v 1.8 1998/12/14 08:11:17 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,6 +42,6 @@ extern StringInfo makeStringInfo(void);
  * appendStringInfo
  * similar to 'strcat' but reallocates more space if necessary...
  */
-extern void appendStringInfo(StringInfo str, char *buffer);
+extern void appendStringInfo(StringInfo str, const char *fmt,...);
 
 #endif  /* STRINGINFO_H */