Re: Proposal to introduce a shuffle function to intarray extension
Martin Kalcher <martin.kalcher@aboutsource.net>
From: Martin Kalcher <martin.kalcher@aboutsource.net>
To: Thomas Munro <thomas.munro@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-17T16:15:51Z
Lists: pgsql-hackers, pgsql-general
Attachments
- 0001-introduce-array_shuffle.patch (text/x-patch) patch 0001
Am 17.07.22 um 08:00 schrieb Thomas Munro: >> Actually ... is there a reason to bother with an intarray version >> at all, rather than going straight for an in-core anyarray function? >> It's not obvious to me that an int4-only version would have >> major performance advantages. > > Yeah, that seems like a good direction. If there is a performance > advantage to specialising, then perhaps we only have to specialise on > size, not type. Perhaps there could be a general function that > internally looks out for typbyval && typlen == 4, and dispatches to a > specialised 4-byte, and likewise for 8, if it can, and that'd already > be enough to cover int, bigint, float etc, without needing > specialisations for each type. I played around with the idea of an anyarray shuffle(). The hard part was to deal with arrays with variable length elements, as they can not be swapped easily in place. I solved it by creating an intermediate array of references to the elements. I'll attach a patch with the proof of concept. Unfortunatly it is already about 5 times slower than the specialised version and i am not sure if it is worth going down that road. Martin
Commits
-
Add array_sample() and array_shuffle() functions.
- 888f2ea0a81f 16.0 landed
-
Use a separate random seed for SQL random()/setseed() functions.
- 6645ad6bdd81 12.0 cited