Re: [PATCH] Introduce array_shuffle() and array_sample()

Поиск
Список
Период
Сортировка
От Salek Talangi
Тема Re: [PATCH] Introduce array_shuffle() and array_sample()
Дата
Msg-id CACX8wBfgatVYMkaQ6we8sSVrFQ0P=uvLkGAhhB5gv692=VkKJA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [PATCH] Introduce array_shuffle() and array_sample()  (Daniel Gustafsson <daniel@yesql.se>)
Список pgsql-hackers
Hi all,


To me the description
   /*
    * Shuffle array using Fisher-Yates algorithm.  Scan the array and swap
    * current item (nelm datums starting at ielms) with a randomly chosen
    * later item (nelm datums starting at jelms) in each iteration.  We can
    * stop once we've done n iterations; then first n items are the result.
    */

seems wrong. For n = 1 the returned item could never be the 1st item of the array (see "randomly chosen later item").
If this really is the case then the result is not really random. But to me it seems j later can be 0 (making it not really "later"), so this might only be a documentation issue.

Best regards
Salek Talangi

Am Mi., 19. Apr. 2023 um 13:48 Uhr schrieb Daniel Gustafsson <daniel@yesql.se>:
> On 7 Apr 2023, at 17:47, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Daniel Gustafsson <daniel@yesql.se> writes:
>> Ah, ok, now I see what you mean, thanks!  I'll try to fix up the patch like
>> this tomorrow.
>
> Since we're running out of time, I took the liberty of fixing and
> pushing this.

Great, thanks!

--
Daniel Gustafsson

В списке pgsql-hackers по дате отправления:

Предыдущее
От: shaurya jain
Дата:
Сообщение: Re: Logical replication failed with SSL SYSCALL error
Следующее
От: Thom Brown
Дата:
Сообщение: Remove references to pre-11 versions