pgsql: Optimize sort and deduplication in ginExtractEntries()

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Optimize sort and deduplication in ginExtractEntries()
Date: 2026-04-07 10:27:27
Message-ID: E1wA3eY-003NWf-1Z@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Optimize sort and deduplication in ginExtractEntries()

Remove NULLs from the array first, and use qsort to deduplicate only
the non-NULL items. This simplifies the comparison function. Also
replace qsort_arg() with a templated version so that the comparison
function can be inlined. These changes make ginExtractEntries() a
little faster especially for simple datatypes like integers.

Author: David Geier <geidav(dot)pg(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/6d16b6bd-a1ff-4469-aefb-a1c8274e561a@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6f5ad00ab763f9e029ec591f7f650bd09c1e933f

Modified Files
--------------
src/backend/access/gin/ginutil.c | 151 +++++++++++++++++----------------------
src/include/access/gin_private.h | 2 +-
2 files changed, 68 insertions(+), 85 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-04-07 10:28:37 pgsql: Avoid different-size pointer-to-integer cast
Previous Message Bertrand Drouvot 2026-04-07 09:41:58 Re: pgsql: Fix valgrind failure