Consolidate 'unique array values' logic into a reusable function? - Mailing list pgsql-hackers

From Thomas Munro
Subject Consolidate 'unique array values' logic into a reusable function?
Date
Msg-id CAEepm=2vmFTNpAmwbGGD2WaryM6T3hSDVKQPfUwjdD_5XY6vAA@mail.gmail.com
Whole thread Raw
Responses Re: Consolidate 'unique array values' logic into a reusable function?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

Looking at commits f10eab73d and c50d192c, I wondered why we don't
have a reusable in-place unique function.  It may be trivial, but we
seem to have a lot of copies and variations in the tree.

Here's a sketch patch that creates a function array_unique which takes
the same arguments as qsort or qsort_arg and returns the new length.
The patch replaces all the specialised unique functions and open coded
versions that I could find with simple greps, but there are probably
more.

My compiler seems to inline the comparator function and memcpy well,
so I can't measure any speed difference between array_unique(array,
size, sizeof(int), compare_int) and a hand-crafted loop using == for
comparison and = for assignment, for a billion items.

If no one objects I'll post a version of this to a commitfest, along
with some other trivial code duplication refactoring work I posted a
while back that consolidates popcount and ffs/fls implementations.  I
don't like code duplication :-)

--
Thomas Munro
http://www.enterprisedb.com

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Draft release notes for next week's back-branch releases
Next
From: Dean Rasheed
Date:
Subject: Re: Bogus ANALYZE results for an otherwise-unique column with many nulls