Re: Proposal to introduce a shuffle function to intarray extension
Mladen Gogala <gogala.mladen@gmail.com>
From: Mladen Gogala <gogala.mladen@gmail.com>
To: Martin Kalcher <martin.kalcher@aboutsource.net>,
pgsql-general@lists.postgresql.org
Date: 2022-07-16T21:30:08Z
Lists: pgsql-hackers, pgsql-general
On 7/16/22 16:21, Martin Kalcher wrote:
> Hey Mladen,
>
> thank you for your advice. Unfortunately the performance of shuffling
> with NumPy is about the same as with SQL.
>
> create function numpy_shuffle(arr int[])
> returns int[]
> as $$
> import numpy
> numpy.random.shuffle(arr)
> return arr
> $$ language 'plpython3u';
>
> select arr[1:3]::text || ' ... ' || arr[3999998:4000000]::text
> from (
> select numpy_shuffle(arr) arr from numbers
> ) shuffled;
>
> -------------------------------------------------------
> {674026,3306457,1727170} ... {343875,3825484,1235246}
>
> Time: 2315.431 ms (00:02.315)
>
> Am i doing something wrong?
>
> Martin
Hi Martin,
No, you're doing everything right. I have no solution for you. You may
need to do some C programming or throw a stronger hardware at the
problem. The performance of your processors may be the problem. Good luck!
--
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
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