Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDhfR-0004ht-JA for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 07:29:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDhfQ-0003mV-GO for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 07:29:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDhfQ-0003jL-5m for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 07:29:16 +0000 Received: from mout-b-206.mailbox.org ([2001:67c:2050:102:465::206]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDhfN-0006Gx-7a for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 07:29:15 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-206.mailbox.org (Postfix) with ESMTPS id 4Ln9SK1q6mz9sc3; Tue, 19 Jul 2022 09:29:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aboutsource.net; s=MBO0001; t=1658215745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A+ASxGV7zGU1+e0iuGPzdm2DUWxWn0uv41g95FUHY3c=; b=RVldvr2NIwfBz7UqcN1C9ZzA5Jwf1uL+Lw8FHkq314oooIPlxzezRHNp7bfMv5G8GFIGBy eHq7zqmqsbK+QsMDcMI4NWDy97GVt+QyA4YQh0JURmK08PMGxp+wN+pgWVl9CUHFYY7q93 kzmyIVor3Y5nuwIXX+NRhGP/QvNjFjcf3IdalNrg0uqKOArhBoNdo0axeBRmhBYUTm65Mu Fhso7ZowUgzlq8wRnpOthxQwy8+cr50pSGSDf21MaGbAURa60QY7Y7mqiO95dSd9Y9Ethm e+w7Lin6jh48TqVcprkOEgP2r10MPA7dSWTl5fZiAtAXRfR//UjaXrK6gBXebQ== Message-ID: <8617d454-0cd6-93bb-b18d-23a97ba40cb4@aboutsource.net> Date: Tue, 19 Jul 2022 09:29:03 +0200 MIME-Version: 1.0 Content-Language: de-DE From: Martin Kalcher To: Tom Lane Cc: Robert Haas , John Naylor , Thomas Munro , PostgreSQL Hackers References: <9d160a44-7675-51e8-60cf-6d64b76db831@aboutsource.net> <4073858.1658027909@sss.pgh.pa.us> <4077925.1658029046@sss.pgh.pa.us> <5ef15c6f-e108-53af-3d82-587fac394f1a@aboutsource.net> <463181.1658097987@sss.pgh.pa.us> <5b7a1ee9-f942-2502-3a0c-e9fc12511139@aboutsource.net> <469954.1658100033@sss.pgh.pa.us> <687490.1658152096@sss.pgh.pa.us> <1708d95a-629e-5ac5-deab-d20a8d0b2b0e@aboutsource.net> <809171.1658176490@sss.pgh.pa.us> <817328.1658178181@sss.pgh.pa.us> <0b5dea2b-37fa-6c81-ea9d-0341ab6f87d6@aboutsource.net> <840271.1658182720@sss.pgh.pa.us> Subject: Re: [PATCH] Introduce array_shuffle() and array_sample() In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4Ln9SK1q6mz9sc3 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Am 19.07.22 um 00:52 schrieb Martin Kalcher: > > On the contrary! I am pretty sure there are people out there wanting > sampling-without-shuffling. I will think about that. I gave it some thought. Even though there might be use cases, where a stable order is desired, i would consider them edge cases, not worth the additional complexity. I personally would not expect array_sample() to return elements in any specific order. I looked up some sample() implementations. None of them makes guarantees about the order of the resulting array or explicitly states that the resulting array is in random or selection order. - Python random.sample [0] - Ruby Array#sample [1] - Rust rand::seq::SliceRandom::choose_multiple [2] - Julia StatsBase.sample [3] stable order needs explicit request [0] https://docs.python.org/3/library/random.html#random.sample [1] https://ruby-doc.org/core-3.0.0/Array.html#method-i-sample [2] https://docs.rs/rand/0.6.5/rand/seq/trait.SliceRandom.html#tymethod.choose_multiple [3] https://juliastats.org/StatsBase.jl/stable/sampling/#StatsBase.sample