pgsql: Redesign the API for list sorting (list_qsort becomeslist_sort) - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Redesign the API for list sorting (list_qsort becomeslist_sort)
Date
Msg-id E1hnPw8-0003V4-BW@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Redesign the API for list sorting (list_qsort becomes list_sort).

In the wake of commit 1cff1b95a, the obvious way to sort a List
is to apply qsort() directly to the array of ListCells.  list_qsort
was building an intermediate array of pointers-to-ListCells, which
we no longer need, but getting rid of it forces an API change:
the comparator functions need to do one less level of indirection.

Since we're having to touch the callers anyway, let's do two additional
changes: sort the given list in-place rather than making a copy (as
none of the existing callers have any use for the copying behavior),
and rename list_qsort to list_sort.  It was argued that the old name
exposes more about the implementation than it should, which I find
pretty questionable, but a better reason to rename it is to be sure
we get the attention of any external callers about the need to fix
their comparator functions.

While we're at it, change four existing callers of qsort() to use
list_sort instead; previously, they all had local reinventions
of list_qsort, ie build-an-array-from-a-List-and-qsort-it.
(There are some other places where changing to list_sort perhaps
would be worthwhile, but they're less obviously wins.)

Discussion: https://postgr.es/m/29361.1563220190@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/569ed7f48312c70ed4a79daec1d7688fda4e74ac

Modified Files
--------------
src/backend/nodes/list.c                        | 53 +++++++++----------------
src/backend/optimizer/util/pathnode.c           | 31 ++++++++-------
src/backend/parser/parse_agg.c                  | 30 +++-----------
src/backend/replication/basebackup.c            | 51 ++++++++++--------------
src/backend/replication/logical/reorderbuffer.c | 27 ++++---------
src/backend/rewrite/rowsecurity.c               | 43 +++++---------------
src/include/nodes/pg_list.h                     |  4 +-
7 files changed, 82 insertions(+), 157 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pgsql: Represent Lists as expansible arrays, not chains of cons-cells.
Next
From: Andrew Dunstan
Date:
Subject: Re: pgsql: Represent Lists as expansible arrays, not chains ofcons-cells.