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 1wfhGZ-005bG1-1W for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Jul 2026 17:01:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfhGX-008bdk-16 for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Jul 2026 17:01:25 +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 1wfhGX-008bdc-0K for pgsql-bugs@lists.postgresql.org; Fri, 03 Jul 2026 17:01:25 +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 1wfhGV-00000001L39-0lO4 for pgsql-bugs@postgresql.org; Fri, 03 Jul 2026 17:01:24 +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 663H1JBw3879868; Fri, 3 Jul 2026 13:01:19 -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: <3854290.1783086630@sss.pgh.pa.us> References: <3748108.1783003096@sss.pgh.pa.us> <3756776.1783011257@sss.pgh.pa.us> <3793780.1783033337@sss.pgh.pa.us> <3854290.1783086630@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 03 Jul 2026 09:50:30 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3879600.1783097914.0@sss.pgh.pa.us> Date: Fri, 03 Jul 2026 13:01:19 -0400 Message-ID: <3879867.1783098079@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3879600.1783097914.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable For the archives' sake: I tested the 0003 patch (sort with bitcmp not byteacmp) with the attached script. I get this with HEAD: -> Index Only Scan using varbitidx on varbittmp (cost=3D0.28..219.00 = rows=3D3584 width=3D0) (actual time=3D0.146..1.895 rows=3D3200.00 loops=3D= 1) Index Cond: (a > '11111'::bit varying) Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=3D1 read=3D110 and this with the bitcmp patch: -> Index Only Scan using varbitidx on varbittmp (cost=3D0.28..267.00 = rows=3D3584 width=3D0) (actual time=3D0.081..0.955 rows=3D3200.00 loops=3D= 1) Index Cond: (a > '11111'::bit varying) Heap Fetches: 0 Index Searches: 1 Buffers: shared hit=3D1 read=3D47 You might get different hit-vs-read splits depending on your shared_buffers setting, but the totals should be pretty stable. So that's a clear win, and indeed running the same script on v17 shows 50-some buffer accesses, so we did lose performance from this mistake. I don't see any win however for a bit(N) column where all the entries are the same width. This is unsurprising, since the bit_len prefix is the same for all and so the bytea sort gives the same ordering as bitcmp. Possibly this explains our failure to notice this problem earlier. Anyway, 0003 seems quite solid so I'll go push that part. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="btree-gist-bit-index-build.sql"; charset="us-ascii" Content-ID: <3879600.1783097914.2@sss.pgh.pa.us> Content-Description: btree-gist-bit-index-build.sql create extension if not exists btree_gist; drop table if exists varbittmp; CREATE TABLE varbittmp (a varbit); insert into varbittmp select repeat(i::bit(8)::text, j)::varbit from generate_series(0,255) i, generate_series(1,100) j; insert into varbittmp select * from varbittmp; insert into varbittmp select * from varbittmp; vacuum analyze varbittmp; select count(*) from varbittmp; SELECT count(*) FROM varbittmp WHERE a > '11111'; CREATE INDEX varbitidx ON varbittmp USING GIST ( a ); select pg_size_pretty(pg_relation_size('varbittmp')) as table_size, pg_size_pretty(pg_indexes_size('varbittmp')) as index_size, pg_indexes_size('varbittmp') / 8192 as index_blocks; explain (analyze, buffers) SELECT count(*) FROM varbittmp WHERE a > '11111'; ------- =_aaaaaaaaaa0--