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 1qIcEO-00059K-Fl for pgsql-hackers@arkaria.postgresql.org; Sun, 09 Jul 2023 21:46:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qIcDP-0002yD-7B for pgsql-hackers@arkaria.postgresql.org; Sun, 09 Jul 2023 21:45:11 +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 1qIcDO-0002wo-Ov for pgsql-hackers@lists.postgresql.org; Sun, 09 Jul 2023 21:45:10 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qIcDH-002xEH-5V for pgsql-hackers@lists.postgresql.org; Sun, 09 Jul 2023 21:45:08 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-51e278e344bso4539323a12.0 for ; Sun, 09 Jul 2023 14:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1688939100; x=1691531100; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=n+S9Qp6BAFg5jpvmNwuJrfij/52zNpeXhiKsjFFgV/E=; b=UV6+6lIvoU2Xs7cRSXfCIPupru3+j3qlt5I6xN0Hr1VxAjGPb+SCLYyxtCmd3ttdzF Zs5m9g+bGrxzjfYtHecShHAUQxo9vGKO/pFx+/sU2uJQoeLG8tVVdKRSk4EBS7jg34Lb OmrvlVCS6R0EOkdXYyMOMXWNEMystik6Yp9996wSVldEkkcBgjw4hiyz/swI6wS+Fk4J lMyYUdlYvinoMpNwM2DgO2Hjs4O2xlW2xTsE9GV4c4uNJTMWWrR02ICobb37ZlixI9oR dyDgTDidKn0/35VnI4ZqECcz/sZCnarkGmQe3CAodShDRVm1Fg77+f39O5kyw7FBuhYG aXIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688939100; x=1691531100; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n+S9Qp6BAFg5jpvmNwuJrfij/52zNpeXhiKsjFFgV/E=; b=TgtGEY/8WUO7uGBEdrS0dN0if/B0Twkpy0kiM3hhV2qBhgOhX+pFp2A6R7esYvoH/Q smdOYNq728GrnjvzTKxuNG9czQQEYM5rxueTBZSrgGTsXBi4HreU4KwVStn/7SQDouuW rZQTdmG+Aaow+7sT/41dxObceoRRk8Ky7BAwoU0TEA4fIfve+YGmPrjy7Q6HPxHFAbly GTLy/qMW5Nv35OCzivsGD2yMaOvEybTFMR2nJnBM79TTrCAeD5MaCN2cZgLAUvh8sCXl F6N8wcFreHFwoYoBsMhlTVOCWYqM3dHM3tf4YvAkHmg4YtjDs6OHI0BAou9oxMCwhUIM jHqw== X-Gm-Message-State: ABy/qLZPLGSwPOufLB6TaRLrq7HytH01aeO5PaoBywzYnrfmivDKOHUf Hku4WGqjFr7EZOv1z1au8ibvbQ== X-Google-Smtp-Source: APBJJlGpx/FUHUERDAlk062r8LtSbxKUE4SPAaPUgNNm8As+TriK6o172/j9SNqGqj/jPArb+WYRdA== X-Received: by 2002:a17:906:2207:b0:991:b613:9b65 with SMTP id s7-20020a170906220700b00991b6139b65mr8929210ejs.37.1688939100132; Sun, 09 Jul 2023 14:45:00 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-228-220.bb.vodafone.cz. [86.49.228.220]) by smtp.gmail.com with ESMTPSA id rn6-20020a170906d92600b00993470682e5sm5215634ejb.32.2023.07.09.14.44.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Jul 2023 14:44:59 -0700 (PDT) Message-ID: <4c512f2b-1f08-aa43-4087-78434f94ffeb@enterprisedb.com> Date: Sun, 9 Jul 2023 23:44:57 +0200 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) To: Heikki Linnakangas , 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> <6a220195-52f8-303c-d154-3f29ac2f078d@iki.fi> Content-Language: en-US From: Tomas Vondra In-Reply-To: <6a220195-52f8-303c-d154-3f29ac2f078d@iki.fi> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/9/23 20:05, Heikki Linnakangas wrote: > 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. > For the built-in, I think all can do something smart. For external, hard to say - my guess is they could do something interesting too. >>> 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. > Right, I agree. > 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. > Hmm, we probably need to do something like this anyway. Because even with the scratch space in BrinDesc, we still need to track whether the opclass can process arrays or not. And if it can't we need to emulate it in brin.c. >> 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. > Yeah, that's a good idea. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company