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-00000000K4I-2agy 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-0xjm for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Nov 2026 09:50:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:37796) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQOus-000000013LZ-0jxo for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:56:06 +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 1xQOur-000000001qi-1WPC for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:56:05 +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=qWjdUCO3ZrWIqe1O3PCgb96tblRVfgrO7skh2xIw1Rc=; b=PCu3nlEBuMq/LPEQN2qZKfF991 2Tv4J9SISSG53Nfs8hOcaJmxu9lxqU8D35W8Fts4oaDrYJibie7tO5zAuozF8nISJnsc50ZNcsqwJ 3eZY5/6NDlRsAD1BwtfrD2R/REUw0u3xul6SV13J9TLK7rRSuTLBTcANQskKWo+gPZOMPnbTsL+w0 lRefeJs2IR+W4b3b/kM3cm+6UqKYDTEZ9pubnNrCmbM4BC42JAkM7KbqIQhmUHz3v+x2bOQ+6JGAN k/9r7u5gkrEFVuhFL6lzz1dKPMeIh7cMLfUzFYsITHeGUrAeQSuRM/yWLv3HLjGbhCEK4zrchzy5J Tf9KfmHw==; 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 1xQOuq-000000004Yp-21Ih for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:56: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 1xQOup-00000000IYi-30nn for pgsql-bugs@lists.postgresql.org; Mon, 09 Nov 2026 12:56:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19855: GiST index on multirange misses rows for <@ with a multirange query 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:55:21 +0000 Message-ID: <19855-58321b0115af92ba@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: 19855 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 multirange column returns too few rows for "column <@ multirange" when the stored value has a gap. No error is raised. CREATE TABLE m(c int4multirange); INSERT INTO m VALUES ('{[1,2),[5,9)}'); SELECT count(*) FROM m WHERE c <@ '{[1,2),[5,9)}'; -- 1 SELECT count(*) FROM m WHERE c <@ '{[0,3),[4,10)}'; -- 1 CREATE INDEX ON m USING gist (c); SET enable_seqscan =3D off; SELECT count(*) FROM m WHERE c <@ '{[1,2),[5,9)}'; -- 0, expected 1 SELECT count(*) FROM m WHERE c <@ '{[0,3),[4,10)}'; -- 0, expected 1 The first query asks whether a value is contained by itself. An index scan and a bitmap scan both give the wrong answer. Cause: multirange_gist_compress() stores the union range with the gaps filled in, so the key here is [1,9), and multirange_gist_consistent() sets recheck =3D tr= ue because the key is lossy. At leaf level, RANGESTRAT_CONTAINED_BY with a multirange query calls range_gist_consistent_leaf_multirange(), which calls multirange_contains_range_internal(query, key). [1,9) is not contained by the query because of the query's gap, so the entry is rejected before the recheck can run. That helper is written for exact keys and is also used by range_gist_consistent(), where the check is right. Range columns are not affected. A possible patch is attached (0001-fix-multirange-gist-contained-by.patch). In the multirange path only, it rejects an entry only if the key falls outside the union of the query. An empty key stands for an empty multirange, so it is kept. With it, index and sequential scans agreed on all 120 operator and query pairs I compared on a 5,000-row table, range columns still gave correct results, and all 239 core regression tests pass on master. It adds no new test. Existing indexes do not need a rebuild for this fix, since only the search changes. Found by comparing index and sequential scans across the operator classes listed in the catalog. I reproduced and checked the result myself.