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:
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/name.c,v 1.50 2003/11/29 19:51:59 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/name.c,v 1.51 2004/05/26 04:41:37 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -342,7 +342,8 @@ current_schema(PG_FUNCTION_ARGS)
|
||||
|
||||
if (search_path == NIL)
|
||||
PG_RETURN_NULL();
|
||||
nspname = get_namespace_name(lfirsto(search_path));
|
||||
nspname = get_namespace_name(linitial_oid(search_path));
|
||||
list_free(search_path);
|
||||
if (!nspname)
|
||||
PG_RETURN_NULL(); /* recently-deleted namespace? */
|
||||
PG_RETURN_DATUM(DirectFunctionCall1(namein, CStringGetDatum(nspname)));
|
||||
@@ -352,25 +353,27 @@ Datum
|
||||
current_schemas(PG_FUNCTION_ARGS)
|
||||
{
|
||||
List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
|
||||
ListCell *l;
|
||||
Datum *names;
|
||||
int i;
|
||||
ArrayType *array;
|
||||
|
||||
/* +1 here is just to avoid palloc(0) error */
|
||||
|
||||
names = (Datum *) palloc((length(search_path) + 1) * sizeof(Datum));
|
||||
i = 0;
|
||||
while (search_path)
|
||||
foreach(l, search_path)
|
||||
{
|
||||
char *nspname;
|
||||
|
||||
nspname = get_namespace_name(lfirsto(search_path));
|
||||
nspname = get_namespace_name(lfirst_oid(l));
|
||||
if (nspname) /* watch out for deleted namespace */
|
||||
{
|
||||
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
|
||||
i++;
|
||||
}
|
||||
search_path = lnext(search_path);
|
||||
}
|
||||
list_free(search_path);
|
||||
|
||||
array = construct_array(names, i,
|
||||
NAMEOID,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.87 2004/05/07 00:24:58 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.88 2004/05/26 04:41:37 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1099,7 +1099,7 @@ stringToQualifiedNameList(const char *string, const char *caller)
|
||||
char *rawname;
|
||||
List *result = NIL;
|
||||
List *namelist;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
|
||||
/* We need a modifiable copy of the input string. */
|
||||
rawname = pstrdup(string);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.67 2004/02/03 17:34:03 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.68 2004/05/26 04:41:38 neilc Exp $
|
||||
*
|
||||
* ----------
|
||||
*/
|
||||
@@ -2571,8 +2571,8 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel)
|
||||
char attname[MAX_QUOTED_NAME_LEN];
|
||||
char fkattname[MAX_QUOTED_NAME_LEN];
|
||||
const char *sep;
|
||||
List *list;
|
||||
List *list2;
|
||||
ListCell *l;
|
||||
ListCell *l2;
|
||||
int old_work_mem;
|
||||
char workmembuf[32];
|
||||
int spi_result;
|
||||
@@ -2605,9 +2605,9 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel)
|
||||
|
||||
sprintf(querystr, "SELECT ");
|
||||
sep="";
|
||||
foreach(list, fkconstraint->fk_attrs)
|
||||
foreach(l, fkconstraint->fk_attrs)
|
||||
{
|
||||
quoteOneName(attname, strVal(lfirst(list)));
|
||||
quoteOneName(attname, strVal(lfirst(l)));
|
||||
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr),
|
||||
"%sfk.%s", sep, attname);
|
||||
sep = ", ";
|
||||
@@ -2620,12 +2620,10 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel)
|
||||
relname, pkrelname);
|
||||
|
||||
sep="";
|
||||
for (list=fkconstraint->pk_attrs, list2=fkconstraint->fk_attrs;
|
||||
list != NIL && list2 != NIL;
|
||||
list=lnext(list), list2=lnext(list2))
|
||||
forboth(l, fkconstraint->pk_attrs, l2, fkconstraint->fk_attrs)
|
||||
{
|
||||
quoteOneName(attname, strVal(lfirst(list)));
|
||||
quoteOneName(fkattname, strVal(lfirst(list2)));
|
||||
quoteOneName(attname, strVal(lfirst(l)));
|
||||
quoteOneName(fkattname, strVal(lfirst(l2)));
|
||||
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr),
|
||||
"%spk.%s=fk.%s",
|
||||
sep, attname, fkattname);
|
||||
@@ -2635,14 +2633,14 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel)
|
||||
* It's sufficient to test any one pk attribute for null to detect a
|
||||
* join failure.
|
||||
*/
|
||||
quoteOneName(attname, strVal(lfirst(fkconstraint->pk_attrs)));
|
||||
quoteOneName(attname, strVal(linitial(fkconstraint->pk_attrs)));
|
||||
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr),
|
||||
") WHERE pk.%s IS NULL AND (", attname);
|
||||
|
||||
sep="";
|
||||
foreach(list, fkconstraint->fk_attrs)
|
||||
foreach(l, fkconstraint->fk_attrs)
|
||||
{
|
||||
quoteOneName(attname, strVal(lfirst(list)));
|
||||
quoteOneName(attname, strVal(lfirst(l)));
|
||||
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr),
|
||||
"%sfk.%s IS NOT NULL",
|
||||
sep, attname);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* back to source text
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.166 2004/05/10 22:44:46 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.167 2004/05/26 04:41:38 neilc Exp $
|
||||
*
|
||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||
*
|
||||
@@ -627,6 +627,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, int prettyFlags)
|
||||
Form_pg_class idxrelrec;
|
||||
Form_pg_am amrec;
|
||||
List *indexprs;
|
||||
ListCell *indexpr_item;
|
||||
List *context;
|
||||
Oid indrelid;
|
||||
int keyno;
|
||||
@@ -691,6 +692,8 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, int prettyFlags)
|
||||
else
|
||||
indexprs = NIL;
|
||||
|
||||
indexpr_item = list_head(indexprs);
|
||||
|
||||
context = deparse_context_for(get_rel_name(indrelid), indrelid);
|
||||
|
||||
/*
|
||||
@@ -733,10 +736,10 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, int prettyFlags)
|
||||
/* expressional index */
|
||||
Node *indexkey;
|
||||
|
||||
if (indexprs == NIL)
|
||||
if (indexpr_item == NULL)
|
||||
elog(ERROR, "too few entries in indexprs list");
|
||||
indexkey = (Node *) lfirst(indexprs);
|
||||
indexprs = lnext(indexprs);
|
||||
indexkey = (Node *) lfirst(indexpr_item);
|
||||
indexpr_item = lnext(indexpr_item);
|
||||
/* Deparse */
|
||||
str = deparse_expression_pretty(indexkey, context, false, false,
|
||||
prettyFlags, 0);
|
||||
@@ -1358,7 +1361,7 @@ deparse_context_for_subplan(const char *name, List *tlist,
|
||||
List *attrs = NIL;
|
||||
int nattrs = 0;
|
||||
int rtablelength = length(rtable);
|
||||
List *tl;
|
||||
ListCell *tl;
|
||||
char buf[32];
|
||||
|
||||
foreach(tl, tlist)
|
||||
@@ -1526,7 +1529,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
|
||||
* (which can only be references to OLD and NEW). Use the rtable
|
||||
* of the first query in the action list for this purpose.
|
||||
*/
|
||||
query = (Query *) lfirst(actions);
|
||||
query = (Query *) linitial(actions);
|
||||
|
||||
/*
|
||||
* If the action is INSERT...SELECT, OLD/NEW have been pushed down
|
||||
@@ -1556,7 +1559,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
|
||||
/* Finally the rules actions */
|
||||
if (length(actions) > 1)
|
||||
{
|
||||
List *action;
|
||||
ListCell *action;
|
||||
Query *query;
|
||||
|
||||
appendStringInfo(buf, "(");
|
||||
@@ -1579,7 +1582,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
|
||||
{
|
||||
Query *query;
|
||||
|
||||
query = (Query *) lfirst(actions);
|
||||
query = (Query *) linitial(actions);
|
||||
get_query_def(query, buf, NIL, NULL, prettyFlags, 0);
|
||||
appendStringInfo(buf, ";");
|
||||
}
|
||||
@@ -1636,7 +1639,7 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
|
||||
return;
|
||||
}
|
||||
|
||||
query = (Query *) lfirst(actions);
|
||||
query = (Query *) linitial(actions);
|
||||
|
||||
if (ev_type != '1' || ev_attr >= 0 || !is_instead ||
|
||||
strcmp(ev_qual, "<>") != 0 || query->commandType != CMD_SELECT)
|
||||
@@ -1670,7 +1673,7 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
|
||||
deparse_namespace dpns;
|
||||
|
||||
context.buf = buf;
|
||||
context.namespaces = lcons(&dpns, parentnamespace);
|
||||
context.namespaces = lcons(&dpns, list_copy(parentnamespace));
|
||||
context.varprefix = (parentnamespace != NIL ||
|
||||
length(query->rtable) != 1);
|
||||
context.prettyFlags = prettyFlags;
|
||||
@@ -1725,7 +1728,7 @@ get_select_query_def(Query *query, deparse_context *context,
|
||||
StringInfo buf = context->buf;
|
||||
bool force_colno;
|
||||
char *sep;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
|
||||
/*
|
||||
* If the Query node has a setOperations tree, then it's the top level
|
||||
@@ -1802,7 +1805,7 @@ get_basic_select_query(Query *query, deparse_context *context,
|
||||
{
|
||||
StringInfo buf = context->buf;
|
||||
char *sep;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
int colno;
|
||||
|
||||
/*
|
||||
@@ -2057,7 +2060,7 @@ get_insert_query_def(Query *query, deparse_context *context)
|
||||
RangeTblEntry *select_rte = NULL;
|
||||
RangeTblEntry *rte;
|
||||
char *sep;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
|
||||
/*
|
||||
* If it's an INSERT ... SELECT there will be a single subquery RTE
|
||||
@@ -2136,10 +2139,10 @@ get_insert_query_def(Query *query, deparse_context *context)
|
||||
static void
|
||||
get_update_query_def(Query *query, deparse_context *context)
|
||||
{
|
||||
StringInfo buf = context->buf;
|
||||
char *sep;
|
||||
RangeTblEntry *rte;
|
||||
List *l;
|
||||
StringInfo buf = context->buf;
|
||||
char *sep;
|
||||
RangeTblEntry *rte;
|
||||
ListCell *l;
|
||||
|
||||
/*
|
||||
* Start the query with UPDATE relname SET
|
||||
@@ -2271,17 +2274,17 @@ static void
|
||||
get_names_for_var(Var *var, deparse_context *context,
|
||||
char **schemaname, char **refname, char **attname)
|
||||
{
|
||||
List *nslist = context->namespaces;
|
||||
ListCell *nslist_item = list_head(context->namespaces);
|
||||
int sup = var->varlevelsup;
|
||||
deparse_namespace *dpns;
|
||||
RangeTblEntry *rte;
|
||||
|
||||
/* Find appropriate nesting depth */
|
||||
while (sup-- > 0 && nslist != NIL)
|
||||
nslist = lnext(nslist);
|
||||
if (nslist == NIL)
|
||||
while (sup-- > 0 && nslist_item != NULL)
|
||||
nslist_item = lnext(nslist_item);
|
||||
if (nslist_item == NULL)
|
||||
elog(ERROR, "bogus varlevelsup: %d", var->varlevelsup);
|
||||
dpns = (deparse_namespace *) lfirst(nslist);
|
||||
dpns = (deparse_namespace *) lfirst(nslist_item);
|
||||
|
||||
/* Find the relevant RTE */
|
||||
if (var->varno >= 1 && var->varno <= length(dpns->rtable))
|
||||
@@ -2342,13 +2345,13 @@ get_names_for_var(Var *var, deparse_context *context,
|
||||
static RangeTblEntry *
|
||||
find_rte_by_refname(const char *refname, deparse_context *context)
|
||||
{
|
||||
RangeTblEntry *result = NULL;
|
||||
List *nslist;
|
||||
RangeTblEntry *result = NULL;
|
||||
ListCell *nslist;
|
||||
|
||||
foreach(nslist, context->namespaces)
|
||||
{
|
||||
deparse_namespace *dpns = (deparse_namespace *) lfirst(nslist);
|
||||
List *rtlist;
|
||||
ListCell *rtlist;
|
||||
|
||||
foreach(rtlist, dpns->rtable)
|
||||
{
|
||||
@@ -2396,7 +2399,7 @@ get_simple_binary_op_name(OpExpr *expr)
|
||||
if (length(args) == 2)
|
||||
{
|
||||
/* binary operator */
|
||||
Node *arg1 = (Node *) lfirst(args);
|
||||
Node *arg1 = (Node *) linitial(args);
|
||||
Node *arg2 = (Node *) lsecond(args);
|
||||
const char *op;
|
||||
|
||||
@@ -2501,7 +2504,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
|
||||
* Operators are same priority --- can skip parens
|
||||
* only if we have (a - b) - c, not a - (b - c).
|
||||
*/
|
||||
if (node == (Node *) lfirst(((OpExpr *) parentNode)->args))
|
||||
if (node == (Node *) linitial(((OpExpr *) parentNode)->args))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -2759,8 +2762,8 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
ArrayRef *aref = (ArrayRef *) node;
|
||||
bool savevarprefix = context->varprefix;
|
||||
bool need_parens;
|
||||
List *lowlist;
|
||||
List *uplist;
|
||||
ListCell *lowlist_item;
|
||||
ListCell *uplist_item;
|
||||
|
||||
/*
|
||||
* If we are doing UPDATE array[n] = expr, we need to
|
||||
@@ -2783,18 +2786,19 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
if (need_parens)
|
||||
appendStringInfoChar(buf, ')');
|
||||
context->varprefix = savevarprefix;
|
||||
lowlist = aref->reflowerindexpr;
|
||||
foreach(uplist, aref->refupperindexpr)
|
||||
lowlist_item = list_head(aref->reflowerindexpr);
|
||||
foreach(uplist_item, aref->refupperindexpr)
|
||||
{
|
||||
appendStringInfo(buf, "[");
|
||||
if (lowlist)
|
||||
if (lowlist_item)
|
||||
{
|
||||
get_rule_expr((Node *) lfirst(lowlist), context,
|
||||
get_rule_expr((Node *) lfirst(lowlist_item), context,
|
||||
false);
|
||||
appendStringInfo(buf, ":");
|
||||
lowlist = lnext(lowlist);
|
||||
lowlist_item = lnext(lowlist_item);
|
||||
}
|
||||
get_rule_expr((Node *) lfirst(uplist), context, false);
|
||||
get_rule_expr((Node *) lfirst(uplist_item),
|
||||
context, false);
|
||||
appendStringInfo(buf, "]");
|
||||
}
|
||||
if (aref->refassgnexpr)
|
||||
@@ -2818,7 +2822,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
{
|
||||
DistinctExpr *expr = (DistinctExpr *) node;
|
||||
List *args = expr->args;
|
||||
Node *arg1 = (Node *) lfirst(args);
|
||||
Node *arg1 = (Node *) linitial(args);
|
||||
Node *arg2 = (Node *) lsecond(args);
|
||||
|
||||
if (!PRETTY_PAREN(context))
|
||||
@@ -2835,7 +2839,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
{
|
||||
ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
|
||||
List *args = expr->args;
|
||||
Node *arg1 = (Node *) lfirst(args);
|
||||
Node *arg1 = (Node *) linitial(args);
|
||||
Node *arg2 = (Node *) lsecond(args);
|
||||
|
||||
if (!PRETTY_PAREN(context))
|
||||
@@ -2856,20 +2860,22 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case T_BoolExpr:
|
||||
{
|
||||
BoolExpr *expr = (BoolExpr *) node;
|
||||
List *args = expr->args;
|
||||
Node *first_arg = linitial(expr->args);
|
||||
ListCell *arg = lnext(list_head(expr->args));
|
||||
|
||||
switch (expr->boolop)
|
||||
{
|
||||
case AND_EXPR:
|
||||
if (!PRETTY_PAREN(context))
|
||||
appendStringInfoChar(buf, '(');
|
||||
get_rule_expr_paren((Node *) lfirst(args), context,
|
||||
get_rule_expr_paren(first_arg, context,
|
||||
false, node);
|
||||
while ((args = lnext(args)) != NIL)
|
||||
while (arg)
|
||||
{
|
||||
appendStringInfo(buf, " AND ");
|
||||
get_rule_expr_paren((Node *) lfirst(args), context,
|
||||
get_rule_expr_paren((Node *) lfirst(arg), context,
|
||||
false, node);
|
||||
arg = lnext(arg);
|
||||
}
|
||||
if (!PRETTY_PAREN(context))
|
||||
appendStringInfoChar(buf, ')');
|
||||
@@ -2878,13 +2884,14 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case OR_EXPR:
|
||||
if (!PRETTY_PAREN(context))
|
||||
appendStringInfoChar(buf, '(');
|
||||
get_rule_expr_paren((Node *) lfirst(args), context,
|
||||
get_rule_expr_paren(first_arg, context,
|
||||
false, node);
|
||||
while ((args = lnext(args)) != NIL)
|
||||
while (arg)
|
||||
{
|
||||
appendStringInfo(buf, " OR ");
|
||||
get_rule_expr_paren((Node *) lfirst(args), context,
|
||||
get_rule_expr_paren((Node *) lfirst(arg), context,
|
||||
false, node);
|
||||
arg = lnext(arg);
|
||||
}
|
||||
if (!PRETTY_PAREN(context))
|
||||
appendStringInfoChar(buf, ')');
|
||||
@@ -2894,7 +2901,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
if (!PRETTY_PAREN(context))
|
||||
appendStringInfoChar(buf, '(');
|
||||
appendStringInfo(buf, "NOT ");
|
||||
get_rule_expr_paren((Node *) lfirst(args), context,
|
||||
get_rule_expr_paren(first_arg, context,
|
||||
false, node);
|
||||
if (!PRETTY_PAREN(context))
|
||||
appendStringInfoChar(buf, ')');
|
||||
@@ -2989,7 +2996,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case T_CaseExpr:
|
||||
{
|
||||
CaseExpr *caseexpr = (CaseExpr *) node;
|
||||
List *temp;
|
||||
ListCell *temp;
|
||||
|
||||
appendContextKeyword(context, "CASE",
|
||||
0, PRETTYINDENT_VAR, 0);
|
||||
@@ -3035,7 +3042,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case T_ArrayExpr:
|
||||
{
|
||||
ArrayExpr *arrayexpr = (ArrayExpr *) node;
|
||||
List *element;
|
||||
ListCell *element;
|
||||
char *sep;
|
||||
|
||||
appendStringInfo(buf, "ARRAY[");
|
||||
@@ -3055,7 +3062,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case T_RowExpr:
|
||||
{
|
||||
RowExpr *rowexpr = (RowExpr *) node;
|
||||
List *arg;
|
||||
ListCell *arg;
|
||||
char *sep;
|
||||
|
||||
/*
|
||||
@@ -3082,7 +3089,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case T_CoalesceExpr:
|
||||
{
|
||||
CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
|
||||
List *arg;
|
||||
ListCell *arg;
|
||||
char *sep;
|
||||
|
||||
appendStringInfo(buf, "COALESCE(");
|
||||
@@ -3102,7 +3109,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
||||
case T_NullIfExpr:
|
||||
{
|
||||
NullIfExpr *nullifexpr = (NullIfExpr *) node;
|
||||
List *arg;
|
||||
ListCell *arg;
|
||||
char *sep;
|
||||
|
||||
appendStringInfo(buf, "NULLIF(");
|
||||
@@ -3239,7 +3246,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
|
||||
if (length(args) == 2)
|
||||
{
|
||||
/* binary operator */
|
||||
Node *arg1 = (Node *) lfirst(args);
|
||||
Node *arg1 = (Node *) linitial(args);
|
||||
Node *arg2 = (Node *) lsecond(args);
|
||||
|
||||
get_rule_expr_paren(arg1, context, true, (Node *) expr);
|
||||
@@ -3252,7 +3259,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
|
||||
else
|
||||
{
|
||||
/* unary operator --- but which side? */
|
||||
Node *arg = (Node *) lfirst(args);
|
||||
Node *arg = (Node *) linitial(args);
|
||||
HeapTuple tp;
|
||||
Form_pg_operator optup;
|
||||
|
||||
@@ -3298,7 +3305,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
|
||||
Oid funcoid = expr->funcid;
|
||||
Oid argtypes[FUNC_MAX_ARGS];
|
||||
int nargs;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
char *sep;
|
||||
|
||||
/*
|
||||
@@ -3308,7 +3315,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
|
||||
*/
|
||||
if (expr->funcformat == COERCE_IMPLICIT_CAST && !showimplicit)
|
||||
{
|
||||
get_rule_expr_paren((Node *) lfirst(expr->args), context,
|
||||
get_rule_expr_paren((Node *) linitial(expr->args), context,
|
||||
showimplicit, (Node *) expr);
|
||||
return;
|
||||
}
|
||||
@@ -3320,7 +3327,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
|
||||
if (expr->funcformat == COERCE_EXPLICIT_CAST ||
|
||||
expr->funcformat == COERCE_IMPLICIT_CAST)
|
||||
{
|
||||
Node *arg = lfirst(expr->args);
|
||||
Node *arg = linitial(expr->args);
|
||||
Oid rettype = expr->funcresulttype;
|
||||
int32 coercedTypmod;
|
||||
|
||||
@@ -3424,7 +3431,7 @@ strip_type_coercion(Node *expr, Oid resultType)
|
||||
if (exprIsLengthCoercion(expr, NULL))
|
||||
return expr;
|
||||
|
||||
return (Node *) lfirst(func->args);
|
||||
return (Node *) linitial(func->args);
|
||||
}
|
||||
|
||||
return expr;
|
||||
@@ -3580,7 +3587,7 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
|
||||
{
|
||||
StringInfo buf = context->buf;
|
||||
Query *query = (Query *) (sublink->subselect);
|
||||
List *l;
|
||||
ListCell *l;
|
||||
char *sep;
|
||||
bool need_paren;
|
||||
|
||||
@@ -3625,7 +3632,7 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
|
||||
|
||||
case ANY_SUBLINK:
|
||||
if (length(sublink->operName) == 1 &&
|
||||
strcmp(strVal(lfirst(sublink->operName)), "=") == 0)
|
||||
strcmp(strVal(linitial(sublink->operName)), "=") == 0)
|
||||
{
|
||||
/* Represent = ANY as IN */
|
||||
appendStringInfo(buf, "IN ");
|
||||
@@ -3680,7 +3687,7 @@ get_from_clause(Query *query, deparse_context *context)
|
||||
{
|
||||
StringInfo buf = context->buf;
|
||||
bool first = true;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
|
||||
/*
|
||||
* We use the query's jointree as a guide to what to print. However,
|
||||
@@ -3763,12 +3770,12 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
|
||||
gavealias = true;
|
||||
if (rte->alias->colnames != NIL && coldeflist == NIL)
|
||||
{
|
||||
List *col;
|
||||
ListCell *col;
|
||||
|
||||
appendStringInfoChar(buf, '(');
|
||||
foreach(col, rte->alias->colnames)
|
||||
{
|
||||
if (col != rte->alias->colnames)
|
||||
if (col != list_head(rte->alias->colnames))
|
||||
appendStringInfo(buf, ", ");
|
||||
appendStringInfoString(buf,
|
||||
quote_identifier(strVal(lfirst(col))));
|
||||
@@ -3897,12 +3904,12 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
|
||||
{
|
||||
if (j->using)
|
||||
{
|
||||
List *col;
|
||||
ListCell *col;
|
||||
|
||||
appendStringInfo(buf, " USING (");
|
||||
foreach(col, j->using)
|
||||
{
|
||||
if (col != j->using)
|
||||
if (col != list_head(j->using))
|
||||
appendStringInfo(buf, ", ");
|
||||
appendStringInfoString(buf,
|
||||
quote_identifier(strVal(lfirst(col))));
|
||||
@@ -3929,12 +3936,12 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
|
||||
quote_identifier(j->alias->aliasname));
|
||||
if (j->alias->colnames != NIL)
|
||||
{
|
||||
List *col;
|
||||
ListCell *col;
|
||||
|
||||
appendStringInfoChar(buf, '(');
|
||||
foreach(col, j->alias->colnames)
|
||||
{
|
||||
if (col != j->alias->colnames)
|
||||
if (col != list_head(j->alias->colnames))
|
||||
appendStringInfo(buf, ", ");
|
||||
appendStringInfoString(buf,
|
||||
quote_identifier(strVal(lfirst(col))));
|
||||
@@ -3958,7 +3965,7 @@ static void
|
||||
get_from_clause_coldeflist(List *coldeflist, deparse_context *context)
|
||||
{
|
||||
StringInfo buf = context->buf;
|
||||
List *col;
|
||||
ListCell *col;
|
||||
int i = 0;
|
||||
|
||||
appendStringInfoChar(buf, '(');
|
||||
@@ -4337,20 +4344,21 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2)
|
||||
static void
|
||||
print_operator_name(StringInfo buf, List *opname)
|
||||
{
|
||||
int nnames = length(opname);
|
||||
ListCell *op = list_head(opname);
|
||||
int nnames = length(opname);
|
||||
|
||||
if (nnames == 1)
|
||||
appendStringInfoString(buf, strVal(lfirst(opname)));
|
||||
appendStringInfoString(buf, strVal(lfirst(op)));
|
||||
else
|
||||
{
|
||||
appendStringInfo(buf, "OPERATOR(");
|
||||
while (nnames-- > 1)
|
||||
{
|
||||
appendStringInfo(buf, "%s.",
|
||||
quote_identifier(strVal(lfirst(opname))));
|
||||
opname = lnext(opname);
|
||||
quote_identifier(strVal(lfirst(op))));
|
||||
op = lnext(op);
|
||||
}
|
||||
appendStringInfo(buf, "%s)", strVal(lfirst(opname)));
|
||||
appendStringInfo(buf, "%s)", strVal(lfirst(op)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.158 2004/02/27 21:44:34 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.159 2004/05/26 04:41:39 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1936,7 +1936,7 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows)
|
||||
List *allvars = NIL;
|
||||
List *varinfos = NIL;
|
||||
double numdistinct;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
typedef struct
|
||||
{ /* varinfos is a List of these */
|
||||
Var *var;
|
||||
@@ -1987,14 +1987,14 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows)
|
||||
VariableStatData vardata;
|
||||
double ndistinct;
|
||||
bool keep = true;
|
||||
List *l2;
|
||||
ListCell *l2;
|
||||
|
||||
examine_variable(root, (Node *) var, 0, &vardata);
|
||||
ndistinct = get_variable_numdistinct(&vardata);
|
||||
ReleaseVariableStats(vardata);
|
||||
|
||||
/* cannot use foreach here because of possible lremove */
|
||||
l2 = varinfos;
|
||||
l2 = list_head(varinfos);
|
||||
while (l2)
|
||||
{
|
||||
MyVarInfo *varinfo = (MyVarInfo *) lfirst(l2);
|
||||
@@ -2043,7 +2043,7 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows)
|
||||
|
||||
do
|
||||
{
|
||||
MyVarInfo *varinfo1 = (MyVarInfo *) lfirst(varinfos);
|
||||
MyVarInfo *varinfo1 = (MyVarInfo *) linitial(varinfos);
|
||||
RelOptInfo *rel = find_base_rel(root, varinfo1->var->varno);
|
||||
double reldistinct = varinfo1->ndistinct;
|
||||
List *newvarinfos = NIL;
|
||||
@@ -2052,7 +2052,7 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows)
|
||||
* Get the largest numdistinct estimate of the Vars for this rel.
|
||||
* Also, construct new varinfos list of remaining Vars.
|
||||
*/
|
||||
foreach(l, lnext(varinfos))
|
||||
for_each_cell(l, lnext(list_head(varinfos)))
|
||||
{
|
||||
MyVarInfo *varinfo2 = (MyVarInfo *) lfirst(l);
|
||||
|
||||
@@ -2844,7 +2844,7 @@ get_restriction_variable(Query *root, List *args, int varRelid,
|
||||
if (length(args) != 2)
|
||||
return false;
|
||||
|
||||
left = (Node *) lfirst(args);
|
||||
left = (Node *) linitial(args);
|
||||
right = (Node *) lsecond(args);
|
||||
|
||||
/*
|
||||
@@ -2895,7 +2895,7 @@ get_join_variables(Query *root, List *args,
|
||||
if (length(args) != 2)
|
||||
elog(ERROR, "join operator should take two arguments");
|
||||
|
||||
left = (Node *) lfirst(args);
|
||||
left = (Node *) linitial(args);
|
||||
right = (Node *) lsecond(args);
|
||||
|
||||
examine_variable(root, left, 0, vardata1);
|
||||
@@ -3033,16 +3033,16 @@ examine_variable(Query *root, Node *node, int varRelid,
|
||||
* different index opclasses; if so, we need to pick one that
|
||||
* matches the operator we are estimating for. FIXME later.
|
||||
*/
|
||||
List *ilist;
|
||||
ListCell *ilist;
|
||||
|
||||
foreach(ilist, onerel->indexlist)
|
||||
{
|
||||
IndexOptInfo *index = (IndexOptInfo *) lfirst(ilist);
|
||||
List *indexprs;
|
||||
ListCell *indexpr_item;
|
||||
int pos;
|
||||
|
||||
indexprs = index->indexprs;
|
||||
if (indexprs == NIL)
|
||||
indexpr_item = list_head(index->indexprs);
|
||||
if (indexpr_item == NULL)
|
||||
continue; /* no expressions here... */
|
||||
|
||||
/*
|
||||
@@ -3058,9 +3058,9 @@ examine_variable(Query *root, Node *node, int varRelid,
|
||||
{
|
||||
Node *indexkey;
|
||||
|
||||
if (indexprs == NIL)
|
||||
if (indexpr_item == NULL)
|
||||
elog(ERROR, "too few entries in indexprs list");
|
||||
indexkey = (Node *) lfirst(indexprs);
|
||||
indexkey = (Node *) lfirst(indexpr_item);
|
||||
if (indexkey && IsA(indexkey, RelabelType))
|
||||
indexkey = (Node *) ((RelabelType *) indexkey)->arg;
|
||||
if (equal(node, indexkey))
|
||||
@@ -3081,7 +3081,7 @@ examine_variable(Query *root, Node *node, int varRelid,
|
||||
if (vardata->statsTuple)
|
||||
break;
|
||||
}
|
||||
indexprs = lnext(indexprs);
|
||||
indexpr_item = lnext(indexpr_item);
|
||||
}
|
||||
}
|
||||
if (vardata->statsTuple)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tid.c,v 1.43 2004/05/07 00:24:58 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tid.c,v 1.44 2004/05/26 04:41:39 neilc Exp $
|
||||
*
|
||||
* NOTES
|
||||
* input routine largely stolen from boxin().
|
||||
@@ -241,7 +241,7 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
|
||||
|
||||
if (length(rewrite->actions) != 1)
|
||||
elog(ERROR, "only one select rule is allowed in views");
|
||||
query = (Query *) lfirst(rewrite->actions);
|
||||
query = (Query *) linitial(rewrite->actions);
|
||||
tle = get_tle_by_resno(query->targetList, tididx+1);
|
||||
if (tle && tle->expr && IsA(tle->expr, Var))
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.112 2004/02/21 00:34:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.113 2004/05/26 04:41:39 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1623,7 +1623,7 @@ textToQualifiedNameList(text *textval, const char *caller)
|
||||
char *rawname;
|
||||
List *result = NIL;
|
||||
List *namelist;
|
||||
List *l;
|
||||
ListCell *l;
|
||||
|
||||
/* Convert to C string (handles possible detoasting). */
|
||||
/* Note we rely on being able to modify rawname below. */
|
||||
|
||||
Reference in New Issue
Block a user