Commit 9396802f authored by Marc G. Fournier's avatar Marc G. Fournier

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