Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfKgK-005Olh-1c for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Jul 2026 16:54:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfKgJ-002O3z-06 for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Jul 2026 16:54:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfKgI-002O3p-2W for pgsql-bugs@lists.postgresql.org; Thu, 02 Jul 2026 16:54:30 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wfKgG-00000001FAE-43K0 for pgsql-bugs@postgresql.org; Thu, 02 Jul 2026 16:54:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 662GsHuO3756777; Thu, 2 Jul 2026 12:54:17 -0400 From: Tom Lane To: Ayush Tiwari cc: =?UTF-8?B?546L6LeD5p6X?= , pgsql-bugs , 3764353996 <3764353996@qq.com> Subject: Re: Fw:Re: Fw: gbt_var_consistent in contrib/btree_gist/btree_utils_var.c has internal-node type confusion on the <> strategy, bypassing exclusion constraints In-reply-to: References: <3748108.1783003096@sss.pgh.pa.us> Comments: In-reply-to Ayush Tiwari message dated "Thu, 02 Jul 2026 21:13:30 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3756775.1783011257.1@sss.pgh.pa.us> Date: Thu, 02 Jul 2026 12:54:17 -0400 Message-ID: <3756776.1783011257@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ayush Tiwari writes: > On Thu, 2 Jul 2026 at 20:08, Tom Lane wrote: >> None of this passes the smell test for me. If it's unsafe to >> call the type's f_eq function on a truncated key, how is it >> any safer to call the f_cmp function? > I think the difference is that for bit/varbit f_eq and f_cmp aren't the > same kind of function. f_eq is biteq (reads bit_len, does VARSIZE-8), > while f_cmp is byteacmp (plain byte-wise, only needs the varlena > header). Oh! You are right, the internal keys are *not* valid bit/varbit values, just bytea. The level of non-documentation in this code is staggering. So the actual API contract here is that f_eq etc. are to be used only on leaf keys, while f_cmp is to be used only on internal keys. It's not too surprising that whoever added NotEqual support didn't know that, it being documented nowhere. It kind of looks actually like there's an expectation that all internal keys are effectively bytea's; note the naming of gbt_bytea_pf_match, despite the fact that it's applied to all types under the purview of btree_utils_var.c. Anyway, I think part of our work here has got to be to raise the level of documentation of this code. I've had it with having to reverse-engineer details as fundamental as these. regards, tom lane