aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_agg.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-09-28 20:32:53 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-09-28 20:32:53 -0400
commit67b2ceea01576933a1dc881ef6a65403e03483ee (patch)
tree7f56798a0ba8478b18cfabd4fbcab88066c602be /src/backend/parser/parse_agg.c
parent61a78c71a656593bf4121e624348a990ba5b91da (diff)
downloadpostgresql-67b2ceea01576933a1dc881ef6a65403e03483ee.tar.gz
postgresql-67b2ceea01576933a1dc881ef6a65403e03483ee.zip
Add for_each_from, to simplify loops starting from non-first list cells.
We have a dozen or so places that need to iterate over all but the first cell of a List. Prior to v13 this was typically written as for_each_cell(lc, lnext(list_head(list))) Commit 1cff1b95a changed these to for_each_cell(lc, list, list_second_cell(list)) This patch introduces a new macro for_each_from() which expresses the start point as a list index, allowing these to be written as for_each_from(lc, list, 1) This is marginally more efficient, since ForEachState.i can be initialized directly instead of backing into it from a ListCell address. It also seems clearer and less typo-prone. Some of the remaining uses of for_each_cell() look like they could profitably be changed to for_each_from(), but here I confined myself to changing uses of list_second_cell(). Also, fix for_each_cell_setup() and for_both_cell_setup() to const-ify their arguments; that's a simple oversight in 1cff1b95a. Back-patch into v13, on the grounds that (1) the const-ification is a minor bug fix, and (2) it's better for back-patching purposes if we only have two ways to write these loops rather than three. In HEAD, also remove list_third_cell() and list_fourth_cell(), which were also introduced in 1cff1b95a, and are unused as of cc99baa43. It seems unlikely that any third-party code would have started to use them already; anyone who has can be directed to list_nth_cell instead. Discussion: https://postgr.es/m/CAApHDvpo1zj9KhEpU2cCRZfSM3Q6XGdhzuAS2v79PH7WJBkYVA@mail.gmail.com
Diffstat (limited to 'src/backend/parser/parse_agg.c')
-rw-r--r--src/backend/parser/parse_agg.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c
index f813b587f18..783f3fe8f2d 100644
--- a/src/backend/parser/parse_agg.c
+++ b/src/backend/parser/parse_agg.c
@@ -1083,7 +1083,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
if (gset_common)
{
- for_each_cell(l, gsets, list_second_cell(gsets))
+ for_each_from(l, gsets, 1)
{
gset_common = list_intersection_int(gset_common, lfirst(l));
if (!gset_common)
@@ -1774,7 +1774,7 @@ expand_grouping_sets(List *groupingSets, int limit)
result = lappend(result, list_union_int(NIL, (List *) lfirst(lc)));
}
- for_each_cell(lc, expanded_groups, list_second_cell(expanded_groups))
+ for_each_from(lc, expanded_groups, 1)
{
List *p = lfirst(lc);
List *new_result = NIL;