Consolidate 'unique array values' logic into a reusable function?

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Consolidate 'unique array values' logic into a reusable function?
Date: 2016-08-07 04:45:39
Message-ID: CAEepm=2vmFTNpAmwbGGD2WaryM6T3hSDVKQPfUwjdD_5XY6vAA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
array-unique.patch application/octet-stream 16.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2016-08-07 07:01:40 Re: Bogus ANALYZE results for an otherwise-unique column with many nulls
Previous Message Tom Lane 2016-08-07 02:13:16 Draft release notes for next week's back-branch releases