mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Reimplement the linked list data structure used throughout the backend.
In the past, we used a 'Lispy' linked list implementation: a "list" was merely a pointer to the head node of the list. The problem with that design is that it makes lappend() and length() linear time. This patch fixes that problem (and others) by maintaining a count of the list length and a pointer to the tail node along with each head node pointer. A "list" is now a pointer to a structure containing some meta-data about the list; the head and tail pointers in that structure refer to ListCell structures that maintain the actual linked list of nodes. The function names of the list API have also been changed to, I hope, be more logically consistent. By default, the old function names are still available; they will be disabled-by-default once the rest of the tree has been updated to use the new API names.
This commit is contained in:
@@ -15,11 +15,13 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.281 2004/05/10 22:44:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.282 2004/05/26 04:41:18 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define DISABLE_LIST_COMPAT
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "nodes/parsenodes.h"
|
||||
@@ -43,14 +45,6 @@
|
||||
#define COPY_NODE_FIELD(fldname) \
|
||||
(newnode->fldname = copyObject(from->fldname))
|
||||
|
||||
/* Copy a field that is a pointer to a list of integers */
|
||||
#define COPY_INTLIST_FIELD(fldname) \
|
||||
(newnode->fldname = listCopy(from->fldname))
|
||||
|
||||
/* Copy a field that is a pointer to a list of Oids */
|
||||
#define COPY_OIDLIST_FIELD(fldname) \
|
||||
(newnode->fldname = listCopy(from->fldname))
|
||||
|
||||
/* Copy a field that is a pointer to a Bitmapset */
|
||||
#define COPY_BITMAPSET_FIELD(fldname) \
|
||||
(newnode->fldname = bms_copy(from->fldname))
|
||||
@@ -68,46 +62,6 @@
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* listCopy
|
||||
* This copy function only copies the "cons-cells" of the list, not the
|
||||
* pointed-to objects. (Use copyObject if you want a "deep" copy.)
|
||||
*
|
||||
* We also use this function for copying lists of integers and Oids,
|
||||
* which is notationally a bit ugly, but perfectly safe.
|
||||
*
|
||||
* Note that copyObject will surely coredump if applied to a list
|
||||
* of integers or Oids!
|
||||
*/
|
||||
List *
|
||||
listCopy(List *list)
|
||||
{
|
||||
List *newlist,
|
||||
*oldl,
|
||||
*newcell,
|
||||
*prev;
|
||||
|
||||
/* rather ugly coding for speed... */
|
||||
if (list == NIL)
|
||||
return NIL;
|
||||
|
||||
newcell = makeNode(List);
|
||||
newcell->elem = list->elem;
|
||||
|
||||
newlist = prev = newcell;
|
||||
|
||||
foreach(oldl, lnext(list))
|
||||
{
|
||||
newcell = makeNode(List);
|
||||
newcell->elem = oldl->elem;
|
||||
prev->next = newcell;
|
||||
prev = newcell;
|
||||
}
|
||||
prev->next = NIL;
|
||||
|
||||
return newlist;
|
||||
}
|
||||
|
||||
/* ****************************************************************
|
||||
* plannodes.h copy functions
|
||||
* ****************************************************************
|
||||
@@ -259,42 +213,12 @@ _copyIndexScan(IndexScan *from)
|
||||
/*
|
||||
* copy remainder of node
|
||||
*/
|
||||
COPY_OIDLIST_FIELD(indxid);
|
||||
COPY_NODE_FIELD(indxid);
|
||||
COPY_NODE_FIELD(indxqual);
|
||||
COPY_NODE_FIELD(indxqualorig);
|
||||
/* this can become COPY_NODE_FIELD when intlists are normal objects: */
|
||||
{
|
||||
List *newstrat = NIL;
|
||||
List *tmp;
|
||||
|
||||
foreach(tmp, from->indxstrategy)
|
||||
{
|
||||
newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
|
||||
}
|
||||
newnode->indxstrategy = newstrat;
|
||||
}
|
||||
/* this can become COPY_NODE_FIELD when OID lists are normal objects: */
|
||||
{
|
||||
List *newsubtype = NIL;
|
||||
List *tmp;
|
||||
|
||||
foreach(tmp, from->indxsubtype)
|
||||
{
|
||||
newsubtype = lappend(newsubtype, listCopy(lfirst(tmp)));
|
||||
}
|
||||
newnode->indxsubtype = newsubtype;
|
||||
}
|
||||
/* this can become COPY_NODE_FIELD when intlists are normal objects: */
|
||||
{
|
||||
List *newstrat = NIL;
|
||||
List *tmp;
|
||||
|
||||
foreach(tmp, from->indxlossy)
|
||||
{
|
||||
newstrat = lappend(newstrat, listCopy(lfirst(tmp)));
|
||||
}
|
||||
newnode->indxlossy = newstrat;
|
||||
}
|
||||
COPY_NODE_FIELD(indxstrategy);
|
||||
COPY_NODE_FIELD(indxsubtype);
|
||||
COPY_NODE_FIELD(indxlossy);
|
||||
COPY_SCALAR_FIELD(indxorderdir);
|
||||
|
||||
return newnode;
|
||||
@@ -876,7 +800,7 @@ _copySubLink(SubLink *from)
|
||||
COPY_SCALAR_FIELD(useOr);
|
||||
COPY_NODE_FIELD(lefthand);
|
||||
COPY_NODE_FIELD(operName);
|
||||
COPY_OIDLIST_FIELD(operOids);
|
||||
COPY_NODE_FIELD(operOids);
|
||||
COPY_NODE_FIELD(subselect);
|
||||
|
||||
return newnode;
|
||||
@@ -893,14 +817,14 @@ _copySubPlan(SubPlan *from)
|
||||
COPY_SCALAR_FIELD(subLinkType);
|
||||
COPY_SCALAR_FIELD(useOr);
|
||||
COPY_NODE_FIELD(exprs);
|
||||
COPY_INTLIST_FIELD(paramIds);
|
||||
COPY_NODE_FIELD(paramIds);
|
||||
COPY_NODE_FIELD(plan);
|
||||
COPY_SCALAR_FIELD(plan_id);
|
||||
COPY_NODE_FIELD(rtable);
|
||||
COPY_SCALAR_FIELD(useHashTable);
|
||||
COPY_SCALAR_FIELD(unknownEqFalse);
|
||||
COPY_INTLIST_FIELD(setParam);
|
||||
COPY_INTLIST_FIELD(parParam);
|
||||
COPY_NODE_FIELD(setParam);
|
||||
COPY_NODE_FIELD(parParam);
|
||||
COPY_NODE_FIELD(args);
|
||||
|
||||
return newnode;
|
||||
@@ -1582,7 +1506,7 @@ _copyQuery(Query *from)
|
||||
COPY_SCALAR_FIELD(hasSubLinks);
|
||||
COPY_NODE_FIELD(rtable);
|
||||
COPY_NODE_FIELD(jointree);
|
||||
COPY_INTLIST_FIELD(rowMarks);
|
||||
COPY_NODE_FIELD(rowMarks);
|
||||
COPY_NODE_FIELD(targetList);
|
||||
COPY_NODE_FIELD(groupClause);
|
||||
COPY_NODE_FIELD(havingQual);
|
||||
@@ -1591,7 +1515,7 @@ _copyQuery(Query *from)
|
||||
COPY_NODE_FIELD(limitOffset);
|
||||
COPY_NODE_FIELD(limitCount);
|
||||
COPY_NODE_FIELD(setOperations);
|
||||
COPY_INTLIST_FIELD(resultRelations);
|
||||
COPY_NODE_FIELD(resultRelations);
|
||||
COPY_NODE_FIELD(in_info_list);
|
||||
COPY_SCALAR_FIELD(hasJoinRTEs);
|
||||
|
||||
@@ -1679,7 +1603,7 @@ _copySetOperationStmt(SetOperationStmt *from)
|
||||
COPY_SCALAR_FIELD(all);
|
||||
COPY_NODE_FIELD(larg);
|
||||
COPY_NODE_FIELD(rarg);
|
||||
COPY_OIDLIST_FIELD(colTypes);
|
||||
COPY_NODE_FIELD(colTypes);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -1731,7 +1655,7 @@ _copyGrantStmt(GrantStmt *from)
|
||||
COPY_SCALAR_FIELD(is_grant);
|
||||
COPY_SCALAR_FIELD(objtype);
|
||||
COPY_NODE_FIELD(objects);
|
||||
COPY_INTLIST_FIELD(privileges);
|
||||
COPY_NODE_FIELD(privileges);
|
||||
COPY_NODE_FIELD(grantees);
|
||||
COPY_SCALAR_FIELD(grant_option);
|
||||
COPY_SCALAR_FIELD(behavior);
|
||||
@@ -2477,7 +2401,7 @@ _copyPrepareStmt(PrepareStmt *from)
|
||||
|
||||
COPY_STRING_FIELD(name);
|
||||
COPY_NODE_FIELD(argtypes);
|
||||
COPY_OIDLIST_FIELD(argtype_oids);
|
||||
COPY_NODE_FIELD(argtype_oids);
|
||||
COPY_NODE_FIELD(query);
|
||||
|
||||
return newnode;
|
||||
@@ -2511,6 +2435,47 @@ _copyDeallocateStmt(DeallocateStmt *from)
|
||||
* ****************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* Perform a deep copy of the specified list, using copyObject(). The
|
||||
* list MUST be of type T_List; T_IntList and T_OidList nodes don't
|
||||
* need deep copies, so they should be copied via list_copy()
|
||||
*/
|
||||
#define COPY_NODE_CELL(new, old) \
|
||||
(new) = (ListCell *) palloc(sizeof(ListCell)); \
|
||||
lfirst(new) = copyObject(lfirst(old));
|
||||
|
||||
static List *
|
||||
_copyList(List *from)
|
||||
{
|
||||
List *new;
|
||||
ListCell *curr_old;
|
||||
ListCell *prev_new;
|
||||
|
||||
Assert(list_length(from) >= 1);
|
||||
|
||||
new = makeNode(List);
|
||||
new->length = from->length;
|
||||
|
||||
COPY_NODE_CELL(new->head, from->head);
|
||||
prev_new = new->head;
|
||||
curr_old = lnext(from->head);
|
||||
|
||||
while (curr_old)
|
||||
{
|
||||
COPY_NODE_CELL(prev_new->next, curr_old);
|
||||
prev_new = prev_new->next;
|
||||
curr_old = curr_old->next;
|
||||
}
|
||||
prev_new->next = NULL;
|
||||
new->tail = prev_new;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/* ****************************************************************
|
||||
* value.h copy functions
|
||||
* ****************************************************************
|
||||
*/
|
||||
static Value *
|
||||
_copyValue(Value *from)
|
||||
{
|
||||
@@ -2752,30 +2717,21 @@ copyObject(void *from)
|
||||
case T_Null:
|
||||
retval = _copyValue(from);
|
||||
break;
|
||||
|
||||
/*
|
||||
* LIST NODES
|
||||
*/
|
||||
case T_List:
|
||||
{
|
||||
List *list = from,
|
||||
*oldl,
|
||||
*newcell,
|
||||
*prev;
|
||||
|
||||
/* rather ugly coding for speed... */
|
||||
/* Note the input list cannot be NIL if we got here. */
|
||||
newcell = makeNode(List);
|
||||
lfirst(newcell) = copyObject(lfirst(list));
|
||||
|
||||
retval = (void *) newcell;
|
||||
prev = newcell;
|
||||
|
||||
foreach(oldl, lnext(list))
|
||||
{
|
||||
newcell = makeNode(List);
|
||||
lfirst(newcell) = copyObject(lfirst(oldl));
|
||||
prev->next = newcell;
|
||||
prev = newcell;
|
||||
}
|
||||
prev->next = NIL;
|
||||
}
|
||||
retval = _copyList(from);
|
||||
break;
|
||||
/*
|
||||
* Lists of integers and OIDs don't need to be
|
||||
* deep-copied, so we perform a shallow copy via
|
||||
* list_copy()
|
||||
*/
|
||||
case T_IntList:
|
||||
case T_OidList:
|
||||
retval = list_copy(from);
|
||||
break;
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.220 2004/05/10 22:44:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.221 2004/05/26 04:41:19 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define DISABLE_LIST_COMPAT
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "nodes/params.h"
|
||||
@@ -52,20 +54,6 @@
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
/* Compare a field that is a pointer to a list of integers */
|
||||
#define COMPARE_INTLIST_FIELD(fldname) \
|
||||
do { \
|
||||
if (!equali(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
/* Compare a field that is a pointer to a list of Oids */
|
||||
#define COMPARE_OIDLIST_FIELD(fldname) \
|
||||
do { \
|
||||
if (!equalo(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
/* Compare a field that is a pointer to a Bitmapset */
|
||||
#define COMPARE_BITMAPSET_FIELD(fldname) \
|
||||
do { \
|
||||
@@ -328,7 +316,7 @@ _equalSubLink(SubLink *a, SubLink *b)
|
||||
COMPARE_SCALAR_FIELD(useOr);
|
||||
COMPARE_NODE_FIELD(lefthand);
|
||||
COMPARE_NODE_FIELD(operName);
|
||||
COMPARE_OIDLIST_FIELD(operOids);
|
||||
COMPARE_NODE_FIELD(operOids);
|
||||
COMPARE_NODE_FIELD(subselect);
|
||||
|
||||
return true;
|
||||
@@ -340,14 +328,14 @@ _equalSubPlan(SubPlan *a, SubPlan *b)
|
||||
COMPARE_SCALAR_FIELD(subLinkType);
|
||||
COMPARE_SCALAR_FIELD(useOr);
|
||||
COMPARE_NODE_FIELD(exprs);
|
||||
COMPARE_INTLIST_FIELD(paramIds);
|
||||
COMPARE_NODE_FIELD(paramIds);
|
||||
/* should compare plans, but have to settle for comparing plan IDs */
|
||||
COMPARE_SCALAR_FIELD(plan_id);
|
||||
COMPARE_NODE_FIELD(rtable);
|
||||
COMPARE_SCALAR_FIELD(useHashTable);
|
||||
COMPARE_SCALAR_FIELD(unknownEqFalse);
|
||||
COMPARE_INTLIST_FIELD(setParam);
|
||||
COMPARE_INTLIST_FIELD(parParam);
|
||||
COMPARE_NODE_FIELD(setParam);
|
||||
COMPARE_NODE_FIELD(parParam);
|
||||
COMPARE_NODE_FIELD(args);
|
||||
|
||||
return true;
|
||||
@@ -636,7 +624,7 @@ _equalQuery(Query *a, Query *b)
|
||||
COMPARE_SCALAR_FIELD(hasSubLinks);
|
||||
COMPARE_NODE_FIELD(rtable);
|
||||
COMPARE_NODE_FIELD(jointree);
|
||||
COMPARE_INTLIST_FIELD(rowMarks);
|
||||
COMPARE_NODE_FIELD(rowMarks);
|
||||
COMPARE_NODE_FIELD(targetList);
|
||||
COMPARE_NODE_FIELD(groupClause);
|
||||
COMPARE_NODE_FIELD(havingQual);
|
||||
@@ -645,7 +633,7 @@ _equalQuery(Query *a, Query *b)
|
||||
COMPARE_NODE_FIELD(limitOffset);
|
||||
COMPARE_NODE_FIELD(limitCount);
|
||||
COMPARE_NODE_FIELD(setOperations);
|
||||
COMPARE_INTLIST_FIELD(resultRelations);
|
||||
COMPARE_NODE_FIELD(resultRelations);
|
||||
COMPARE_NODE_FIELD(in_info_list);
|
||||
COMPARE_SCALAR_FIELD(hasJoinRTEs);
|
||||
|
||||
@@ -720,7 +708,7 @@ _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
|
||||
COMPARE_SCALAR_FIELD(all);
|
||||
COMPARE_NODE_FIELD(larg);
|
||||
COMPARE_NODE_FIELD(rarg);
|
||||
COMPARE_OIDLIST_FIELD(colTypes);
|
||||
COMPARE_NODE_FIELD(colTypes);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -764,7 +752,7 @@ _equalGrantStmt(GrantStmt *a, GrantStmt *b)
|
||||
COMPARE_SCALAR_FIELD(is_grant);
|
||||
COMPARE_SCALAR_FIELD(objtype);
|
||||
COMPARE_NODE_FIELD(objects);
|
||||
COMPARE_INTLIST_FIELD(privileges);
|
||||
COMPARE_NODE_FIELD(privileges);
|
||||
COMPARE_NODE_FIELD(grantees);
|
||||
COMPARE_SCALAR_FIELD(grant_option);
|
||||
COMPARE_SCALAR_FIELD(behavior);
|
||||
@@ -1389,7 +1377,7 @@ _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(name);
|
||||
COMPARE_NODE_FIELD(argtypes);
|
||||
COMPARE_OIDLIST_FIELD(argtype_oids);
|
||||
COMPARE_NODE_FIELD(argtype_oids);
|
||||
COMPARE_NODE_FIELD(query);
|
||||
|
||||
return true;
|
||||
@@ -1648,6 +1636,65 @@ _equalFkConstraint(FkConstraint *a, FkConstraint *b)
|
||||
* Stuff from pg_list.h
|
||||
*/
|
||||
|
||||
static bool
|
||||
_equalList(List *a, List *b)
|
||||
{
|
||||
ListCell *item_a;
|
||||
ListCell *item_b;
|
||||
|
||||
/*
|
||||
* Try to reject by simple scalar checks before grovelling through
|
||||
* all the list elements...
|
||||
*/
|
||||
COMPARE_SCALAR_FIELD(type);
|
||||
COMPARE_SCALAR_FIELD(length);
|
||||
|
||||
/*
|
||||
* We place the switch outside the loop for the sake of
|
||||
* efficiency; this may not be worth doing...
|
||||
*/
|
||||
switch (a->type)
|
||||
{
|
||||
case T_List:
|
||||
forboth(item_a, a, item_b, b)
|
||||
{
|
||||
if (!equal(lfirst(item_a), lfirst(item_b)))
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case T_IntList:
|
||||
forboth(item_a, a, item_b, b)
|
||||
{
|
||||
if (lfirst_int(item_a) != lfirst_int(item_b))
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case T_OidList:
|
||||
forboth(item_a, a, item_b, b)
|
||||
{
|
||||
if (lfirst_oid(item_a) != lfirst_oid(item_b))
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "unrecognized list node type: %d",
|
||||
(int) a->type);
|
||||
return false; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* If we got here, we should have run out of elements of both lists
|
||||
*/
|
||||
Assert(item_a == NULL);
|
||||
Assert(item_b == NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stuff from value.h
|
||||
*/
|
||||
|
||||
static bool
|
||||
_equalValue(Value *a, Value *b)
|
||||
{
|
||||
@@ -1818,30 +1865,10 @@ equal(void *a, void *b)
|
||||
case T_InClauseInfo:
|
||||
retval = _equalInClauseInfo(a, b);
|
||||
break;
|
||||
|
||||
/*
|
||||
* LIST NODES
|
||||
*/
|
||||
case T_List:
|
||||
{
|
||||
List *la = (List *) a;
|
||||
List *lb = (List *) b;
|
||||
List *l;
|
||||
|
||||
/*
|
||||
* Try to reject by length check before we grovel through
|
||||
* all the elements...
|
||||
*/
|
||||
if (length(la) != length(lb))
|
||||
return false;
|
||||
foreach(l, la)
|
||||
{
|
||||
if (!equal(lfirst(l), lfirst(lb)))
|
||||
return false;
|
||||
lb = lnext(lb);
|
||||
}
|
||||
retval = true;
|
||||
}
|
||||
case T_IntList:
|
||||
case T_OidList:
|
||||
retval = _equalList(a, b);
|
||||
break;
|
||||
|
||||
case T_Integer:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.236 2004/05/10 22:44:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.237 2004/05/26 04:41:19 neilc Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@@ -19,6 +19,8 @@
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#define DISABLE_LIST_COMPAT
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@@ -85,16 +87,6 @@
|
||||
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
|
||||
_outNode(str, node->fldname))
|
||||
|
||||
/* Write an integer-list field */
|
||||
#define WRITE_INTLIST_FIELD(fldname) \
|
||||
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
|
||||
_outIntList(str, node->fldname))
|
||||
|
||||
/* Write an OID-list field */
|
||||
#define WRITE_OIDLIST_FIELD(fldname) \
|
||||
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
|
||||
_outOidList(str, node->fldname))
|
||||
|
||||
/* Write a bitmapset field */
|
||||
#define WRITE_BITMAPSET_FIELD(fldname) \
|
||||
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
|
||||
@@ -145,35 +137,40 @@ _outToken(StringInfo str, char *s)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* _outIntList -
|
||||
* converts a List of integers
|
||||
*/
|
||||
static void
|
||||
_outIntList(StringInfo str, List *list)
|
||||
_outList(StringInfo str, List *node)
|
||||
{
|
||||
List *l;
|
||||
ListCell *lc;
|
||||
|
||||
appendStringInfoChar(str, '(');
|
||||
appendStringInfoChar(str, 'i');
|
||||
foreach(l, list)
|
||||
appendStringInfo(str, " %d", lfirsti(l));
|
||||
appendStringInfoChar(str, ')');
|
||||
}
|
||||
|
||||
/*
|
||||
* _outOidList -
|
||||
* converts a List of OIDs
|
||||
*/
|
||||
static void
|
||||
_outOidList(StringInfo str, List *list)
|
||||
{
|
||||
List *l;
|
||||
if (IsA(node, IntList))
|
||||
appendStringInfoChar(str, 'i');
|
||||
else if (IsA(node, OidList))
|
||||
appendStringInfoChar(str, 'o');
|
||||
|
||||
foreach (lc, node)
|
||||
{
|
||||
/*
|
||||
* For the sake of backward compatibility, we emit a slightly
|
||||
* different whitespace format for lists of nodes vs. other
|
||||
* types of lists. XXX: is this necessary?
|
||||
*/
|
||||
if (IsA(node, List))
|
||||
{
|
||||
_outNode(str, lfirst(lc));
|
||||
if (lnext(lc))
|
||||
appendStringInfoChar(str, ' ');
|
||||
}
|
||||
else if (IsA(node, IntList))
|
||||
appendStringInfo(str, " %d", lfirst_int(lc));
|
||||
else if (IsA(node, OidList))
|
||||
appendStringInfo(str, " %u", lfirst_oid(lc));
|
||||
else
|
||||
elog(ERROR, "unrecognized list node type: %d",
|
||||
(int) node->type);
|
||||
}
|
||||
|
||||
appendStringInfoChar(str, '(');
|
||||
appendStringInfoChar(str, 'o');
|
||||
foreach(l, list)
|
||||
appendStringInfo(str, " %u", lfirsto(l));
|
||||
appendStringInfoChar(str, ')');
|
||||
}
|
||||
|
||||
@@ -336,39 +333,12 @@ _outIndexScan(StringInfo str, IndexScan *node)
|
||||
|
||||
_outScanInfo(str, (Scan *) node);
|
||||
|
||||
WRITE_OIDLIST_FIELD(indxid);
|
||||
WRITE_NODE_FIELD(indxid);
|
||||
WRITE_NODE_FIELD(indxqual);
|
||||
WRITE_NODE_FIELD(indxqualorig);
|
||||
/* this can become WRITE_NODE_FIELD when intlists are normal objects: */
|
||||
{
|
||||
List *tmp;
|
||||
|
||||
appendStringInfo(str, " :indxstrategy ");
|
||||
foreach(tmp, node->indxstrategy)
|
||||
{
|
||||
_outIntList(str, lfirst(tmp));
|
||||
}
|
||||
}
|
||||
/* this can become WRITE_NODE_FIELD when OID lists are normal objects: */
|
||||
{
|
||||
List *tmp;
|
||||
|
||||
appendStringInfo(str, " :indxsubtype ");
|
||||
foreach(tmp, node->indxsubtype)
|
||||
{
|
||||
_outOidList(str, lfirst(tmp));
|
||||
}
|
||||
}
|
||||
/* this can become WRITE_NODE_FIELD when intlists are normal objects: */
|
||||
{
|
||||
List *tmp;
|
||||
|
||||
appendStringInfo(str, " :indxlossy ");
|
||||
foreach(tmp, node->indxlossy)
|
||||
{
|
||||
_outIntList(str, lfirst(tmp));
|
||||
}
|
||||
}
|
||||
WRITE_NODE_FIELD(indxstrategy);
|
||||
WRITE_NODE_FIELD(indxsubtype);
|
||||
WRITE_NODE_FIELD(indxlossy);
|
||||
WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
|
||||
}
|
||||
|
||||
@@ -743,7 +713,7 @@ _outSubLink(StringInfo str, SubLink *node)
|
||||
WRITE_BOOL_FIELD(useOr);
|
||||
WRITE_NODE_FIELD(lefthand);
|
||||
WRITE_NODE_FIELD(operName);
|
||||
WRITE_OIDLIST_FIELD(operOids);
|
||||
WRITE_NODE_FIELD(operOids);
|
||||
WRITE_NODE_FIELD(subselect);
|
||||
}
|
||||
|
||||
@@ -755,14 +725,14 @@ _outSubPlan(StringInfo str, SubPlan *node)
|
||||
WRITE_ENUM_FIELD(subLinkType, SubLinkType);
|
||||
WRITE_BOOL_FIELD(useOr);
|
||||
WRITE_NODE_FIELD(exprs);
|
||||
WRITE_INTLIST_FIELD(paramIds);
|
||||
WRITE_NODE_FIELD(paramIds);
|
||||
WRITE_NODE_FIELD(plan);
|
||||
WRITE_INT_FIELD(plan_id);
|
||||
WRITE_NODE_FIELD(rtable);
|
||||
WRITE_BOOL_FIELD(useHashTable);
|
||||
WRITE_BOOL_FIELD(unknownEqFalse);
|
||||
WRITE_INTLIST_FIELD(setParam);
|
||||
WRITE_INTLIST_FIELD(parParam);
|
||||
WRITE_NODE_FIELD(setParam);
|
||||
WRITE_NODE_FIELD(parParam);
|
||||
WRITE_NODE_FIELD(args);
|
||||
}
|
||||
|
||||
@@ -1302,7 +1272,7 @@ _outQuery(StringInfo str, Query *node)
|
||||
WRITE_BOOL_FIELD(hasSubLinks);
|
||||
WRITE_NODE_FIELD(rtable);
|
||||
WRITE_NODE_FIELD(jointree);
|
||||
WRITE_INTLIST_FIELD(rowMarks);
|
||||
WRITE_NODE_FIELD(rowMarks);
|
||||
WRITE_NODE_FIELD(targetList);
|
||||
WRITE_NODE_FIELD(groupClause);
|
||||
WRITE_NODE_FIELD(havingQual);
|
||||
@@ -1311,7 +1281,7 @@ _outQuery(StringInfo str, Query *node)
|
||||
WRITE_NODE_FIELD(limitOffset);
|
||||
WRITE_NODE_FIELD(limitCount);
|
||||
WRITE_NODE_FIELD(setOperations);
|
||||
WRITE_INTLIST_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
|
||||
/* planner-internal fields are not written out */
|
||||
}
|
||||
@@ -1343,7 +1313,7 @@ _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
|
||||
WRITE_BOOL_FIELD(all);
|
||||
WRITE_NODE_FIELD(larg);
|
||||
WRITE_NODE_FIELD(rarg);
|
||||
WRITE_OIDLIST_FIELD(colTypes);
|
||||
WRITE_NODE_FIELD(colTypes);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1444,7 +1414,6 @@ _outValue(StringInfo str, Value *value)
|
||||
appendStringInfo(str, "%ld", value->val.ival);
|
||||
break;
|
||||
case T_Float:
|
||||
|
||||
/*
|
||||
* We assume the value is a valid numeric literal and so does
|
||||
* not need quoting.
|
||||
@@ -1572,24 +1541,9 @@ static void
|
||||
_outNode(StringInfo str, void *obj)
|
||||
{
|
||||
if (obj == NULL)
|
||||
{
|
||||
appendStringInfo(str, "<>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsA(obj, List))
|
||||
{
|
||||
List *l;
|
||||
|
||||
appendStringInfoChar(str, '(');
|
||||
foreach(l, (List *) obj)
|
||||
{
|
||||
_outNode(str, lfirst(l));
|
||||
if (lnext(l))
|
||||
appendStringInfoChar(str, ' ');
|
||||
}
|
||||
appendStringInfoChar(str, ')');
|
||||
}
|
||||
else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList))
|
||||
_outList(str, obj);
|
||||
else if (IsA(obj, Integer) ||
|
||||
IsA(obj, Float) ||
|
||||
IsA(obj, String) ||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/print.c,v 1.66 2004/05/08 21:21:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/print.c,v 1.67 2004/05/26 04:41:19 neilc Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -255,7 +255,7 @@ pretty_format_node_dump(const char *dump)
|
||||
void
|
||||
print_rt(List *rtable)
|
||||
{
|
||||
List *l;
|
||||
ListCell *l;
|
||||
int i = 1;
|
||||
|
||||
printf("resno\trefname \trelid\tinFromCl\n");
|
||||
@@ -395,7 +395,7 @@ print_expr(Node *expr, List *rtable)
|
||||
{
|
||||
FuncExpr *e = (FuncExpr *) expr;
|
||||
char *funcname;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
|
||||
funcname = get_func_name(e->funcid);
|
||||
printf("%s(", ((funcname != NULL) ? funcname : "(invalid function)"));
|
||||
@@ -418,18 +418,18 @@ print_expr(Node *expr, List *rtable)
|
||||
void
|
||||
print_pathkeys(List *pathkeys, List *rtable)
|
||||
{
|
||||
List *i,
|
||||
*k;
|
||||
ListCell *i;
|
||||
|
||||
printf("(");
|
||||
foreach(i, pathkeys)
|
||||
{
|
||||
List *pathkey = lfirst(i);
|
||||
List *pathkey = (List *) lfirst(i);
|
||||
ListCell *k;
|
||||
|
||||
printf("(");
|
||||
foreach(k, pathkey)
|
||||
{
|
||||
PathKeyItem *item = lfirst(k);
|
||||
PathKeyItem *item = (PathKeyItem *) lfirst(k);
|
||||
|
||||
print_expr(item->key, rtable);
|
||||
if (lnext(k))
|
||||
@@ -449,12 +449,12 @@ print_pathkeys(List *pathkeys, List *rtable)
|
||||
void
|
||||
print_tl(List *tlist, List *rtable)
|
||||
{
|
||||
List *tl;
|
||||
ListCell *tl;
|
||||
|
||||
printf("(\n");
|
||||
foreach(tl, tlist)
|
||||
{
|
||||
TargetEntry *tle = lfirst(tl);
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(tl);
|
||||
|
||||
printf("\t%d %s\t", tle->resdom->resno,
|
||||
tle->resdom->resname ? tle->resdom->resname : "<null>");
|
||||
@@ -590,13 +590,13 @@ print_plan_recursive(Plan *p, Query *parsetree, int indentLevel, char *label)
|
||||
|
||||
if (IsA(p, Append))
|
||||
{
|
||||
List *lst;
|
||||
ListCell *l;
|
||||
int whichplan = 0;
|
||||
Append *appendplan = (Append *) p;
|
||||
|
||||
foreach(lst, appendplan->appendplans)
|
||||
foreach(l, appendplan->appendplans)
|
||||
{
|
||||
Plan *subnode = (Plan *) lfirst(lst);
|
||||
Plan *subnode = (Plan *) lfirst(l);
|
||||
|
||||
/*
|
||||
* I don't think we need to fiddle with the range table here,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.41 2004/05/08 21:21:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.42 2004/05/26 04:41:19 neilc Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -384,7 +384,6 @@ nodeRead(char *token, int tok_len)
|
||||
}
|
||||
break;
|
||||
case T_Integer:
|
||||
|
||||
/*
|
||||
* we know that the token terminates on a char atol will stop
|
||||
* at
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.169 2004/05/10 22:44:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.170 2004/05/26 04:41:19 neilc Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@@ -18,6 +18,8 @@
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#define DISABLE_LIST_COMPAT
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <math.h>
|
||||
@@ -33,21 +35,22 @@
|
||||
* routine.
|
||||
*/
|
||||
|
||||
/* Declare appropriate local variables */
|
||||
#define READ_LOCALS(nodeTypeName) \
|
||||
nodeTypeName *local_node = makeNode(nodeTypeName); \
|
||||
char *token; \
|
||||
int length
|
||||
/* Macros for declaring appropriate local variables */
|
||||
|
||||
/* A few guys need only local_node */
|
||||
#define READ_LOCALS_NO_FIELDS(nodeTypeName) \
|
||||
nodeTypeName *local_node = makeNode(nodeTypeName)
|
||||
|
||||
/* And a few guys need only the pg_strtok support fields */
|
||||
#define READ_TEMP_LOCALS() \
|
||||
char *token; \
|
||||
#define READ_TEMP_LOCALS() \
|
||||
char *token; \
|
||||
int length
|
||||
|
||||
/* ... but most need both */
|
||||
#define READ_LOCALS(nodeTypeName) \
|
||||
READ_LOCALS_NO_FIELDS(nodeTypeName); \
|
||||
READ_TEMP_LOCALS()
|
||||
|
||||
/* Read an integer field (anything written as ":fldname %d") */
|
||||
#define READ_INT_FIELD(fldname) \
|
||||
token = pg_strtok(&length); /* skip :fldname */ \
|
||||
@@ -101,16 +104,6 @@
|
||||
token = pg_strtok(&length); /* skip :fldname */ \
|
||||
local_node->fldname = nodeRead(NULL, 0)
|
||||
|
||||
/* Read an integer-list field (XXX combine me with READ_NODE_FIELD) */
|
||||
#define READ_INTLIST_FIELD(fldname) \
|
||||
token = pg_strtok(&length); /* skip :fldname */ \
|
||||
local_node->fldname = nodeRead(NULL, 0)
|
||||
|
||||
/* Read an OID-list field (XXX combine me with READ_NODE_FIELD) */
|
||||
#define READ_OIDLIST_FIELD(fldname) \
|
||||
token = pg_strtok(&length); /* skip :fldname */ \
|
||||
local_node->fldname = nodeRead(NULL, 0)
|
||||
|
||||
/* Routine exit */
|
||||
#define READ_DONE() \
|
||||
return local_node
|
||||
@@ -153,7 +146,7 @@ _readQuery(void)
|
||||
READ_BOOL_FIELD(hasSubLinks);
|
||||
READ_NODE_FIELD(rtable);
|
||||
READ_NODE_FIELD(jointree);
|
||||
READ_INTLIST_FIELD(rowMarks);
|
||||
READ_NODE_FIELD(rowMarks);
|
||||
READ_NODE_FIELD(targetList);
|
||||
READ_NODE_FIELD(groupClause);
|
||||
READ_NODE_FIELD(havingQual);
|
||||
@@ -162,7 +155,7 @@ _readQuery(void)
|
||||
READ_NODE_FIELD(limitOffset);
|
||||
READ_NODE_FIELD(limitCount);
|
||||
READ_NODE_FIELD(setOperations);
|
||||
READ_INTLIST_FIELD(resultRelations);
|
||||
READ_NODE_FIELD(resultRelations);
|
||||
|
||||
/* planner-internal fields are left zero */
|
||||
|
||||
@@ -237,7 +230,7 @@ _readSetOperationStmt(void)
|
||||
READ_BOOL_FIELD(all);
|
||||
READ_NODE_FIELD(larg);
|
||||
READ_NODE_FIELD(rarg);
|
||||
READ_OIDLIST_FIELD(colTypes);
|
||||
READ_NODE_FIELD(colTypes);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
@@ -526,7 +519,7 @@ _readSubLink(void)
|
||||
READ_BOOL_FIELD(useOr);
|
||||
READ_NODE_FIELD(lefthand);
|
||||
READ_NODE_FIELD(operName);
|
||||
READ_OIDLIST_FIELD(operOids);
|
||||
READ_NODE_FIELD(operOids);
|
||||
READ_NODE_FIELD(subselect);
|
||||
|
||||
READ_DONE();
|
||||
|
||||
Reference in New Issue
Block a user