aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-02-28 14:25:01 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-02-28 14:25:01 -0500
commitc94fb8e8acc05c4b5f9f5b2a595ce7930827c2be (patch)
treeaafacc4fb6291f41aeb9eeb15234fbac83c83e90 /src/backend/utils/adt/ruleutils.c
parent0a271df705c98c1cc617078ebd069cf080fa5a16 (diff)
downloadpostgresql-c94fb8e8acc05c4b5f9f5b2a595ce7930827c2be.tar.gz
postgresql-c94fb8e8acc05c4b5f9f5b2a595ce7930827c2be.zip
Standardize some more loops that chase down parallel lists.
We have forboth() and forthree() macros that simplify iterating through several parallel lists, but not everyplace that could reasonably use those was doing so. Also invent forfour() and forfive() macros to do the same for four or five parallel lists, and use those where applicable. The immediate motivation for doing this is to reduce the number of ad-hoc lnext() calls, to reduce the footprint of a WIP patch. However, it seems like good cleanup and error-proofing anyway; the places that were combining forthree() with a manually iterated loop seem particularly illegible and bug-prone. There was some speculation about restructuring related parsetree representations to reduce the need for parallel list chasing of this sort. Perhaps that's a win, or perhaps not, but in any case it would be considerably more invasive than this patch; and it's not particularly related to my immediate goal of improving the List infrastructure. So I'll leave that question for another day. Patch by me; thanks to David Rowley for review. Discussion: https://postgr.es/m/11587.1550975080@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 1258092dc8c..85055bbb95a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9811,31 +9811,18 @@ get_tablefunc(TableFunc *tf, deparse_context *context, bool showimplicit)
ListCell *l5;
int colnum = 0;
- l2 = list_head(tf->coltypes);
- l3 = list_head(tf->coltypmods);
- l4 = list_head(tf->colexprs);
- l5 = list_head(tf->coldefexprs);
-
appendStringInfoString(buf, " COLUMNS ");
- foreach(l1, tf->colnames)
+ forfive(l1, tf->colnames, l2, tf->coltypes, l3, tf->coltypmods,
+ l4, tf->colexprs, l5, tf->coldefexprs)
{
char *colname = strVal(lfirst(l1));
- Oid typid;
- int32 typmod;
- Node *colexpr;
- Node *coldefexpr;
- bool ordinality = tf->ordinalitycol == colnum;
+ Oid typid = lfirst_oid(l2);
+ int32 typmod = lfirst_int(l3);
+ Node *colexpr = (Node *) lfirst(l4);
+ Node *coldefexpr = (Node *) lfirst(l5);
+ bool ordinality = (tf->ordinalitycol == colnum);
bool notnull = bms_is_member(colnum, tf->notnulls);
- typid = lfirst_oid(l2);
- l2 = lnext(l2);
- typmod = lfirst_int(l3);
- l3 = lnext(l3);
- colexpr = (Node *) lfirst(l4);
- l4 = lnext(l4);
- coldefexpr = (Node *) lfirst(l5);
- l5 = lnext(l5);
-
if (colnum > 0)
appendStringInfoString(buf, ", ");
colnum++;
@@ -10349,12 +10336,11 @@ get_from_clause_coldeflist(RangeTblFunction *rtfunc,
appendStringInfoChar(buf, '(');
- /* there's no forfour(), so must chase one list the hard way */
i = 0;
- l4 = list_head(rtfunc->funccolnames);
- forthree(l1, rtfunc->funccoltypes,
- l2, rtfunc->funccoltypmods,
- l3, rtfunc->funccolcollations)
+ forfour(l1, rtfunc->funccoltypes,
+ l2, rtfunc->funccoltypmods,
+ l3, rtfunc->funccolcollations,
+ l4, rtfunc->funccolnames)
{
Oid atttypid = lfirst_oid(l1);
int32 atttypmod = lfirst_int(l2);
@@ -10378,7 +10364,6 @@ get_from_clause_coldeflist(RangeTblFunction *rtfunc,
appendStringInfo(buf, " COLLATE %s",
generate_collation_name(attcollation));
- l4 = lnext(l4);
i++;
}