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 1woQa8-0013Iw-0U for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Jul 2026 19:01:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1woQa7-00ETpV-0X for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Jul 2026 19:01:43 +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 1woO2l-00E155-0S for pgsql-bugs@lists.postgresql.org; Mon, 27 Jul 2026 16:19:07 +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 1woO2i-00000000bbi-4AcZ for pgsql-bugs@lists.postgresql.org; Mon, 27 Jul 2026 16:19: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=nBeZkRy9D/sqNVUUmp+UcrzeCbKCMejUEpZf1FjqEds=; b=x0RhdZjBWZKrWSbGmwotuUH2s3 iWyiJPrFI6vXKmETXqesmPhBLWD0M/7DFTERm1J1wwpq++Nm1zIsTYWYTwrNm8UVDpVxVrO7iOF40 r6HAMkN+YfAia4+9jNpY3Kj1U6+pO1OkUMZoc0/RtaQdY/CEyu+7E1EvYBLOie4bM4Ov/j/f1iTeJ 26rqiZUP0KlxHjaKTKGqHoar68zSg15Im4FgGbAoaR9r+UCYpEgMYbHgw8TvPab3tvW0+yvx+BOxo RNQQdWuGGFjF9LiNExdf778tRCMDE4PFECmCrCXgrJ0iSU+oJVnNBk8H5EKbyDt4XyYRpkWHKqDUh ti312Q7Q==; 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.96) (envelope-from ) id 1woO2i-001x8g-2W for pgsql-bugs@lists.postgresql.org; Mon, 27 Jul 2026 16:19: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 1woO2h-00000004h3g-1Sbp for pgsql-bugs@lists.postgresql.org; Mon, 27 Jul 2026 16:19:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19582: Query fails on mixed IPv4 IPv6 data when index added To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: gsaviane@gmail.com Reply-To: gsaviane@gmail.com, pgsql-bugs@lists.postgresql.org Date: Mon, 27 Jul 2026 16:18:59 +0000 Message-ID: <19582-b9e0113754eb1d62@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: 19582 Logged by: Giorgio Saviane Email address: gsaviane@gmail.com PostgreSQL version: 17.10 Operating system: Ubuntu 22.04 Description: =20 The attached SQL code snippet shows how to reproduce the problem. A table with generated mixed IPv4 and IPv6 data, when queried filtering by IP family fails when a conditional index is being added to the table. I suspect the planner pre-executes the query on some samples, applying the index condition only partially. This is the output I get when executing the SQL: BEGIN CREATE TABLE INSERT 0 20000000 count --------- 8355840 (1 row) CREATE INDEX QUERY PLAN ---------------------------------------------------------------------------= -------------------- Aggregate (cost=3D1913.76..1913.77 rows=3D1 width=3D8) -> Bitmap Heap Scan on test_inet (cost=3D8.31..1912.51 rows=3D500 widt= h=3D0) Recheck Cond: (((addr & '255.0.0.0'::inet) =3D '1.0.0.0'::inet) AND (family(addr) =3D 4)) -> Bitmap Index Scan on test_inet_expr_idx (cost=3D0.00..8.18 rows=3D500 width=3D0) Index Cond: ((addr & '255.0.0.0'::inet) =3D '1.0.0.0'::inet) (5 rows) ERROR: cannot AND inet values of different sizes ROLLBACK =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CODE HERE =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D begin; -- Create a table to host inet addresses create table test_inet ( addr inet not null ); -- Generate mixed IPv4 and IPv6 data. -- The amout of data makes the difference. -- Experimentally, lower than 13M it does not reproduce. -- It might depend on server configuration insert into test_inet(addr) select (case mod(s,2) when 0 then 'fe80:1::'::inet + s else '1.1.0.0'::inet + s end) from generate_series(1, 20000000) s; -- Count filtered by IPv4 family and subnet. -- Suceeds without an index select count(*) from test_inet where family(addr) =3D 4 and addr & '255.0.0.0'::inet =3D '1.0.0.0'; -- Now create an index filtered only on IPv4 family create index on test_inet((addr & '255.0.0.0'::inet)) where family(addr) =3D 4; -- The plan should show how subnet and family -- conditions are split due to rechecking explain select count(*) from test_inet where family(addr) =3D 4 and addr & '255.0.0.0'::inet =3D '1.0.0.0'; -- Same count filtered by IPv4 family and subnet fails with: -- ERROR: cannot AND inet values of different sizes select count(*) from test_inet where family(addr) =3D 4 and addr & '255.0.0.0'::inet =3D '1.0.0.0'; rollback; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D END CODE =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D