pgsql: Rationalize use of list_concat + list_copy combinations.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

pgsql: Rationalize use of list_concat + list_copy combinations.

Tom Lane-2
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@...

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5ee190f8ec37c1bbfb3061e18304e155d600bc8e

Modified Files
--------------
contrib/postgres_fdw/deparse.c            |  2 +-
contrib/postgres_fdw/postgres_fdw.c       | 14 ++++----
src/backend/commands/indexcmds.c          |  4 +--
src/backend/executor/functions.c          |  3 +-
src/backend/nodes/list.c                  | 50 ++++++++++++++++++++++++----
src/backend/optimizer/path/allpaths.c     | 13 +++-----
src/backend/optimizer/path/costsize.c     |  3 +-
src/backend/optimizer/path/indxpath.c     | 18 ++++-------
src/backend/optimizer/plan/createplan.c   |  4 +--
src/backend/optimizer/plan/initsplan.c    |  1 -
src/backend/optimizer/plan/planner.c      | 13 +++-----
src/backend/optimizer/plan/setrefs.c      |  2 +-
src/backend/optimizer/prep/prepjointree.c |  1 -
src/backend/optimizer/prep/prepqual.c     | 12 -------
src/backend/optimizer/util/clauses.c      | 54 ++++++++++++-------------------
src/backend/optimizer/util/orclauses.c    |  2 +-
src/backend/optimizer/util/relnode.c      | 34 +++++++++----------
src/backend/optimizer/util/tlist.c        |  5 ++-
src/backend/parser/parse_agg.c            | 12 +++----
src/backend/parser/parse_clause.c         |  5 ---
src/backend/partitioning/partprune.c      |  8 ++---
src/backend/replication/syncrep.c         |  5 +--
src/backend/rewrite/rewriteHandler.c      |  8 ++---
src/backend/utils/adt/ruleutils.c         |  2 +-
src/backend/utils/adt/selfuncs.c          |  1 -
src/include/nodes/pg_list.h               |  2 ++
26 files changed, 130 insertions(+), 148 deletions(-)