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 1oEU9v-0001yJ-4g for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jul 2022 11:15:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEU9t-0002vF-Rz for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jul 2022 11:15:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEU9t-0002pN-Hn for pgsql-hackers@lists.postgresql.org; Thu, 21 Jul 2022 11:15:57 +0000 Received: from mout-b-110.mailbox.org ([195.10.208.55]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEU9q-00086e-EW for pgsql-hackers@lists.postgresql.org; Thu, 21 Jul 2022 11:15:56 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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-110.mailbox.org (Postfix) with ESMTPS id 4LpVNz6ypWz9sTY; Thu, 21 Jul 2022 13:15:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aboutsource.net; s=MBO0001; t=1658402148; 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=GBo9SfvBryxhmZfgaISI/S+OEFe4AfGOJV62Po4GUNg=; b=iKr1tltbwOOvcCypc0ZWSLqIoKph0IsQzOFb4nLgXlrT/bkzXVvk/O17zd1oUrkYtBMiX2 r9Ivn7gqNOW+FqycnhxVzvcc0Kxsg4jNaEv0ReFl1MtHW9XxpzG0lFeMoD2GMC/bzQWOBw OofW4raB0r0+k3fNlgi0msJQByazQ0ty5KDzLIP1KMKEojuZTJ3YrfV0QxCWcyz1HQNpVi YmpUbgYYbhXpIljW4tzFYD/Qj4JbAx95JhGqt+rcI5UeQkBT0pOct+IDZvBUc3qCx9iDhl Tfe/6ZXuHMZnmXPgkn66w6tv15RjwZ5PxBL9sFvo26augL2QzCNM+o3hDI0mYA== Message-ID: Date: Thu, 21 Jul 2022 13:15:43 +0200 MIME-Version: 1.0 Content-Language: de-DE To: Dean Rasheed Cc: Tom Lane , Robert Haas , Andrew Dunstan , John Naylor , Thomas Munro , PostgreSQL Hackers References: <9d160a44-7675-51e8-60cf-6d64b76db831@aboutsource.net> <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> <091a9f69-1e5d-6558-41a7-2607a5fc9ff7@aboutsource.net> <1064800.1658240423@sss.pgh.pa.us> <7e7cf274-09cb-00cf-1715-979f011e40b0@aboutsource.net> From: Martin Kalcher 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: 4LpVNz6ypWz9sTY List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Am 21.07.22 um 10:41 schrieb Dean Rasheed: > > A couple of quick comments on the current patch: Thank you for your feedback! > It's important to mark these new functions as VOLATILE, not IMMUTABLE, > otherwise they won't work as expected in queries. See > https://www.postgresql.org/docs/current/xfunc-volatility.html CREATE FUNCTION marks functions as VOLATILE by default if not explicitly marked otherwise. I assumed function definitions in pg_proc.dat have the same behavior. I will fix that. https://www.postgresql.org/docs/current/sql-createfunction.html > It would be better to use pg_prng_uint64_range() rather than rand() to > pick elements. Partly, that's because it uses a higher quality PRNG, > with a larger internal state, and it ensures that the results are > unbiased across the range. But more importantly, it interoperates with > setseed(), allowing predictable sequences of "random" numbers to be > generated -- something that's useful in writing repeatable regression > tests. I agree that we should use pg_prng_uint64_range(). However, in order to achieve interoperability with setseed() we would have to use drandom_seed (rather than pg_global_prng_state) as rng state, which is declared statically in float.c and exclusively used by random(). Do we want to expose drandom_seed to other functions? > Assuming these new functions are made to interoperate with setseed(), > which I think they should be, then they also need to be marked as > PARALLEL RESTRICTED, rather than PARALLEL SAFE. See > https://www.postgresql.org/docs/current/parallel-safety.html, which > explains why setseed() and random() are parallel restricted. As mentioned above, i assumed the default here is PARALLEL UNSAFE. I'll fix that. > In my experience, the requirement for sampling with replacement is > about as common as the requirement for sampling without replacement, > so it seems odd to provide one but not the other. Of course, we can > always add a with-replacement function later, and give it a different > name. But maybe array_sample() could be used for both, with a > "with_replacement" boolean parameter? We can also add a "with_replacement" boolean parameter which is false by default to array_sample() later. I do not have a strong opinion about that and will implement it, if desired. Any opinions about default/no-default? Martin