pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Redesign the API for list sorting (list_qsort becomes list_sort)
Date: Tue, 16 Jul 2019 16:04:16 +0000
Message-ID: <E1hnPw8-0003V4-BW@gemulon.postgresql.org> (raw)

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(-)



Message-ID: <E1hnPw8-0003V4-BW@gemulon.postgresql.org>
Permalink:  ../E1hnPw8-0003V4-BW@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hnPw8-0003V4-BW@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Redesign the API for list sorting (list_qsort becomes list_sort)
  In-Reply-To: <E1hnPw8-0003V4-BW@gemulon.postgresql.org>
  References: <E1hnPw8-0003V4-BW@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox