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 1qIYoM-0003Ke-1M for pgsql-hackers@arkaria.postgresql.org; Sun, 09 Jul 2023 18:07:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qIYnM-000347-2k for pgsql-hackers@arkaria.postgresql.org; Sun, 09 Jul 2023 18:06:04 +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 1qIYnL-00033x-Ke for pgsql-hackers@lists.postgresql.org; Sun, 09 Jul 2023 18:06:03 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qIYnF-0038Qh-02 for pgsql-hackers@lists.postgresql.org; Sun, 09 Jul 2023 18:06:01 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4QzZnF5Wq8z49Q0Z; Sun, 9 Jul 2023 21:05:53 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1688925954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AA+dPuwgkD+4thTr0tiCsKOrwergHpmogBiec9wRDrA=; b=nMRggkFwYWulqFty8kbPI0q5ZFCvj4SAdnTt/nU3mpPvczwEH0EitMec2yXxqUFBEJtoUJ xngHYVyAG+xYbHbSdIMl0TImuu65JQwP4aBP+oDaSBYxG7J/DMjBvpOlj25M2o2yWtcAqh 1M9IeVR9wC9sxkjviLtcxOTUVGVy4DezEjx0Ys+O3FhtlBI6KyTaaBwB2hMW5G6OCCbSZC LBDLTtUx8RzqopcM1mgX2fbTvfxfonpAQcMN2T3EymdM9DJatjOyW5tyxt8SwZX59S07od r00KPWosLQZxsWZ1G6jZrS+6Sy+XFo1MqFPaei3OBg5cHEbI+jKjm9nUszo+8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1688925954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AA+dPuwgkD+4thTr0tiCsKOrwergHpmogBiec9wRDrA=; b=H0x+aEIH72Z3zvNnzClP+GmovcOYoIUjcH5DRJOcwhrwY24W/oA7qgB28mSCL5BPoVZIkb K049wgSaKmIFWMrbWd0ik4Gtu6ll46DYH6vNThqGBJ/Zq+zn1RKgmUBhR6pSBHe0ZWMt7/ VH/iVlp7YFcehtx/VF+YfIu9nyKi2OzoSenQ1faHTYrqatCLaO75fJRL0nY2gD/utMAAQa GsavnJ53HhHY0aeUWy92Q4L/YrshTL9c8EjMTOEyGWvnv4E/Ed9FQjdht/7c1KYwadx94m 4jqNEukhdMDMU7KquMVmQ8wztPDNVZxjmaZdDG450L8QTxScfPHM8nzJY8TpuA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1688925954; a=rsa-sha256; cv=none; b=JvCRgDVWu1W02s7ykSMZq2mc0ql0TQjTrY31HQTcix2S+GJ84UeVouPXRVS7dO4ZtClqyL DprHt9sCKkaJb21K6B+x8kfcQmDpKI60vczbmmPx08LtqxSZOGNEQY+Mk1wBS+UHU0c9oV IJT8/PZrm5a7r0VBu/I3KvYmpAs3UCC/c2SsPpZLXzEbTpk+pu2IrFr/hoIol7usmIA9d0 qz7zgUiiYh7N3rAKJWhiy1lPmxHoFOGc2QQdSr5z/ppkTf/y3r9+2Wd8g1gHU85KAjoawr Tt8ej1BrIe4XyA24UdXcgqKRzDMGBQ+Ze2Xu/bpecpySuZUbp+O0oRtULosR9g== Message-ID: <6a220195-52f8-303c-d154-3f29ac2f078d@iki.fi> Date: Sun, 9 Jul 2023 21:05:53 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: BRIN indexes vs. SK_SEARCHARRAY (and preprocessing scan keys) Content-Language: en-US To: Tomas Vondra , PostgreSQL Hackers References: <0e1f3350-c9cf-ab62-43a5-5dae314de89c@enterprisedb.com> <57020b2e-d9c9-9bc7-4892-b36d9bb07563@enterprisedb.com> <327064f1-276e-cb45-88c2-1ff498037cf5@enterprisedb.com> <4fa33caf-b5d1-6887-65a9-82ce9d92765c@enterprisedb.com> <1701e986-fa32-f3fa-0ac8-39fae8e5db35@enterprisedb.com> <856edf2c-8e95-0a8f-5a37-c8564a770a82@enterprisedb.com> <2484032b-3e6d-ae6a-61e5-732e2136ad18@iki.fi> <677c95ad-513f-6702-3c59-0afa2790a149@enterprisedb.com> From: Heikki Linnakangas In-Reply-To: <677c95ad-513f-6702-3c59-0afa2790a149@enterprisedb.com> 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 09/07/2023 19:16, Tomas Vondra wrote: > On 7/8/23 23:57, Heikki Linnakangas wrote: >> The new preprocess support function feels a bit too inflexible to me. >> True, you can store whatever you want in the ScanKey that it returns, >> but since that's the case, why not just make it void * ? It seems that >> the constraint here was that you need to pass a ScanKey to the >> consistent function, because the consistent function's signature is what >> it is. But we can change the signature, if we introduce a new support >> amproc number for it. > > Now sure I follow - what should be made (void *)? Oh, you mean not > passing the preprocessed array as a scan key at all, and instead passing > it as a new (void*) parameter to the (new) consistent function? Right. >> It would be unpleasant to force all BRIN opclasses to immediately >> implement the searcharray-logic. If we don't want to do that, we need to >> implement generic SK_SEARCHARRAY handling in BRIN AM itself. That would >> be pretty easy, right? Just call the regular consistent function for >> every element in the array. > > True, although the question is how many out-of-core opclasses are there. > My impression is the number is pretty close to 0, in which case we're > making ourselves to jump through all kinds of hoops, making the code > more complex, with almost no benefit in the end. Perhaps. How many of the opclasses can do something smart with SEARCHARRAY? If the answer is "all" or "almost all", then it seems reasonable to just require them all to handle it. If the answer is "some", then it would still be nice to provide a naive default implementation in the AM itself. Otherwise all the opclasses need to include a bunch of boilerplate to support SEARCHARRAY. >> If an opclass wants to provide a faster/better implementation, it can >> provide a new consistent support procedure that supports that. Let's >> assign a new amproc number for new-style consistent function, which must >> support SK_SEARCHARRAY, and pass it some scratch space where it can >> cache whatever per-scankey data. Because it gets a new amproc number, we >> can define the arguments as we wish. We can pass a pointer to the >> per-scankey scratch space as a new argument, for example. >> >> We did this backwards-compatibility dance with the 3/4-argument variants >> of the current consistent functions. But I think assigning a whole new >> procedure number is better than looking at the number of arguments. > > I actually somewhat hate the 3/4-argument dance, and I'm opposed to > doing that sort of thing again. First, I'm not quite convinced it's > worth the effort to jump through this hoop (I recall this being one of > the headaches when fixing the BRIN NULL handling). Second, it can only > be done once - imagine we now need to add a new optional parameter. > Presumably, we'd need to keep the existing 3/4 variants, and add new 4/5 > variants. At which point 4 is ambiguous. My point is that we should assign a new amproc number to distinguish the new variant, instead of looking at the number of arguments. That way it's not ambiguous, and you can define whatever arguments you want for the new variant. Yet another idea is to introduce a new amproc for a consistent function that *only* handles the SEARCHARRAY case, and keep the old consistent function as it is for the scalars. So every opclass would need to implement the current consistent function, just like today. But if an opclass wants to support SEARCHARRAY, it could optionally also provide an "consistent_array" function. > Yes, my previous message was mostly about backwards compatibility, and > this may seem a bit like an argument against it. But that message was > more a question "If we do this, is it actually backwards compatible the > way we want/need?") > > Anyway, I think the BrinDesc scratch space is a neat idea, I'll try > doing it that way and report back in a couple days. Cool. In 0005-Support-SK_SEARCHARRAY-in-BRIN-bloom-20230702.patch, you used the preprocess function to pre-calculate the scankey's hash, even for scalars. You could use the scratch space in BrinDesc for that, before doing anything with SEARCHARRAYs. -- Heikki Linnakangas Neon (https://neon.tech)