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 1p2Out-00054S-VR for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Dec 2022 03:46:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p2Our-0003jI-L5 for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Dec 2022 03:46:45 +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 1p2Our-0003j9-A9 for pgsql-hackers@lists.postgresql.org; Tue, 06 Dec 2022 03:46:45 +0000 Received: from relay10.mail.gandi.net ([217.70.178.230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p2Ouo-0000vS-3H for pgsql-hackers@lists.postgresql.org; Tue, 06 Dec 2022 03:46:44 +0000 Received: (Authenticated sender: vik@postgresfriends.org) by mail.gandi.net (Postfix) with ESMTPSA id 1A67D240002; Tue, 6 Dec 2022 03:46:37 +0000 (UTC) Message-ID: Date: Tue, 6 Dec 2022 04:46:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: ANY_VALUE aggregate Content-Language: en-US To: "David G. Johnston" Cc: PostgreSQL Hackers References: <5cff866c-10a8-d2df-32cb-e9072e6b04a2@postgresfriends.org> From: Vik Fearing In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/5/22 18:56, David G. Johnston wrote: > Also, maybe we should have any_value do something like compute a 50/50 > chance that any new value seen replaces the existing chosen value, instead > of simply returning the first value all the time. Maybe even prohibit the > first value from being chosen so long as a second value appears. The spec says the result is implementation-dependent meaning we don't even need to document how it is obtained, but surely behavior like this would preclude future optimizations like the ones I mentioned? I once wrote a random_agg() for a training course that used reservoir sampling to get an evenly distributed value from the inputs. Something like that seems to be what you are looking for here. I don't see the use case for adding it to core, though. The use case for ANY_VALUE is compliance with the standard. -- Vik Fearing