diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-08-12 11:20:18 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-08-12 11:20:18 -0400 |
commit | 5ee190f8ec37c1bbfb3061e18304e155d600bc8e (patch) | |
tree | 5767a0de205205f91373bd5645f9c09bd046b0cf /src/backend/parser/parse_clause.c | |
parent | 251c8e39bc6b0a3ff1620d9ac10888a7660e6b88 (diff) | |
download | postgresql-5ee190f8ec37c1bbfb3061e18304e155d600bc8e.tar.gz postgresql-5ee190f8ec37c1bbfb3061e18304e155d600bc8e.zip |
Rationalize use of list_concat + list_copy combinations.
In the wake of commit 1cff1b95a, the result of list_concat no longer
shares the ListCells of the second input. Therefore, we can replace
"list_concat(x, list_copy(y))" with just "list_concat(x, y)".
To improve call sites that were list_copy'ing the first argument,
or both arguments, invent "list_concat_copy()" which produces a new
list sharing no ListCells with either input. (This is a bit faster
than "list_concat(list_copy(x), y)" because it makes the result list
the right size to start with.)
In call sites that were not list_copy'ing the second argument, the new
semantics mean that we are usually leaking the second List's storage,
since typically there is no remaining pointer to it. We considered
inventing another list_copy variant that would list_free the second
input, but concluded that for most call sites it isn't worth worrying
about, given the relative compactness of the new List representation.
(Note that in cases where such leakage would happen, the old code
already leaked the second List's header; so we're only discussing
the size of the leak not whether there is one. I did adjust two or
three places that had been troubling to free that header so that
they manually free the whole second List.)
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/parser/parse_clause.c')
-rw-r--r-- | src/backend/parser/parse_clause.c | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 2a6b2ff153b..260ccd4d7fa 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -1214,9 +1214,6 @@ transformFromClauseItem(ParseState *pstate, Node *n, * * Notice that we don't require the merged namespace list to be * conflict-free. See the comments for scanNameSpaceForRefname(). - * - * NB: this coding relies on the fact that list_concat is not - * destructive to its second argument. */ lateral_ok = (j->jointype == JOIN_INNER || j->jointype == JOIN_LEFT); setNamespaceLateralState(l_namespace, true, lateral_ok); @@ -2116,9 +2113,7 @@ flatten_grouping_sets(Node *expr, bool toplevel, bool *hasGroupingSets) if (IsA(n1, GroupingSet) && ((GroupingSet *) n1)->kind == GROUPING_SET_SETS) - { result_set = list_concat(result_set, (List *) n2); - } else result_set = lappend(result_set, n2); } |