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.98.2) (envelope-from ) id 1xQiUd-00000000K4J-2bGL for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Nov 2026 09:50:19 +0000 Received: from localhost ([127.0.0.1]:54270 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xQiUc-00000004oAu-10CS for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Nov 2026 09:50:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:54396) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQOvp-000000013Mj-2K5e for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:57:05 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQOvo-000000001rA-2OBH for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:57:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=8cubHBUvaXR2nCIb5XH7mtymGJvCeaz2ZoOYk4FN4dE=; b=mIr7f2iJ++N4A/4TnRcDWNVO0P DewRnXin+cnbBOoDG8Fq9hBoMa15a8QJqajq8GkgYsZDBgAUSibye5qtBXYZxhOm82ldzYDcOUiV9 qgA8iEZhLNLzA2fyoMuSdYQsYA+7iyFN1iTAEiPXCdJVFJxvS8ICOYYdp1JPzyg9C9stIANHIX6wC cJgqHIqegZnt7WhzbT0M/mg+ld0kah74lucJGS1fe+ChZ2NzlZJpMzktMCVltYYqlrba0pUyXnbNA VI05w5w2f4Ckzm1KZ/iAIR66MrCo4ZAZRBKx6iQScTb96+CJmgFnOcAECPUrkMsKS/vXZDOsj8RC6 nVCUJf3g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQOvn-000000004a6-2Xre for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:57:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xQOvm-00000000IbH-3aUC for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:57:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19856: GiST index on tsquery misses empty tsquery rows for <@ To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 125atishprak@gmail.com Reply-To: 125atishprak@gmail.com, pgsql-bugs@lists.postgresql.org Date: Mon, 09 Nov 2026 12:57:00 +0000 Message-ID: <19856-bdfec1ae4a0ffc4c@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19856 Logged by: Atish Prakash Email address: 125atishprak@gmail.com PostgreSQL version: 18.6 Operating system: Linux x86_64 Description: =20 A GiST index on a tsquery column can miss rows holding an empty tsquery for "column <@ query". No error is raised, apart from the usual NOTICE about a query with no lexemes. CREATE TABLE q(c tsquery); INSERT INTO q SELECT (ARRAY['', 'a', 'a & b', 'a | b', '!a', 'b:*']::tsquery[])[1 + i % 6] FROM generate_series(1, 600) i; SELECT count(*) FROM q WHERE c <@ 'zz'; -- 100 SELECT count(*) FROM q WHERE c <@ ''; -- 100 CREATE INDEX ON q USING gist (c); SET enable_seqscan =3D off; SELECT count(*) FROM q WHERE c <@ 'zz'; -- 0, expected 100 SELECT count(*) FROM q WHERE c <@ ''; -- 0, expected 100 Cause: an empty tsquery has an all-zero signature. For RTContainedByStrategyNumber on an internal page, gtsquery_consistent() descends only if (key & sq) !=3D 0.= A subtree can hold empty entries, which are contained by anything, even when its union key does not overlap the query, so that subtree is skipped. This looks like the same mistake as the intarray report "intarray GiST index gets wrong answers for '{}' <@ anything": https://www.postgresql.org/message-id/458.1565114141@sss.pgh.pa.us A possible patch is attached (0001-fix-tsquery-gist-contained-by.patch). It always descends for this strategy on internal pages, as the signature cannot rule out empty entries. That makes <@ scans visit the whole index, a cost a maintainer may want to weigh. With it, the queries above return 100, and all 239 core regression tests pass on master. It adds no new test. Empty tsquery values are probably rare in practice, so this is low severity. Found by comparing index and sequential scans across the operator classes listed in the catalog. I reproduced and checked the result myself.