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 1xD78E-00000000K6D-20hm for pgsql-bugs@arkaria.postgresql.org; Sat, 03 Oct 2026 21:18:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xD78D-00000003FFB-1TVU for pgsql-bugs@arkaria.postgresql.org; Sat, 03 Oct 2026 21:18:57 +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.98.2) (envelope-from ) id 1xD2R5-00000002M17-2emn for pgsql-bugs@lists.postgresql.org; Sat, 03 Oct 2026 16:18: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 1xD2R3-00000000BDM-0jb5 for pgsql-bugs@lists.postgresql.org; Sat, 03 Oct 2026 16:18:06 +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=M5LTQRo9SKz6vX2vOkpI6RAoqezhPvzAiT4K2F854QY=; b=lX5Fxy93Gh5TgECBBDW5qj6ALZ 0HZi/hvU38R6oB+jnhHFUJkB6BBLndYijVzupMezB+Lx2ymM+kmIPdvZEuWxUyo7NIn0ohzZSdQbm 4Zz81S6jJl2SI6c8HzjqI1mleDqp3tw2lTAXQpjglFoV7+aNa7UB8VIM/xy7ufJTY3FeJQekmiitb FsgDCZ330c+mIn4HxZlbZotosLtFfzc2jhn/ofRJyZZCtgXrC/JdCCVDvNxynqhYO4wR9uBaRDw16 CPGjdBOqji9OEZmQlyszPL9+Uj1cURyYeDDuZLjwoJtDtc4HAqyw0KygN3R+8E+b/SqTOBSmFOvqG 1qjYXdsQ==; 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 1xD2R2-00000000eh4-2Exi for pgsql-bugs@lists.postgresql.org; Sat, 03 Oct 2026 16:18: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 1xD2R1-00000001nNA-11ri for pgsql-bugs@lists.postgresql.org; Sat, 03 Oct 2026 16:18:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t" To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: feasiblechart@gmail.com Reply-To: feasiblechart@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sat, 03 Oct 2026 16:17:03 +0000 Message-ID: <19742-dc403ca277cad1d3@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: 19742 Logged by: Junwen AN Email address: feasiblechart@gmail.com PostgreSQL version: 19beta4 Operating system: Linux Description: =20 Please see the repro. Seems like a regression; 19beta4 and the current main branch both have this error raised, but 18.6 works fine. I ran it with psql CREATE TABLE d (a int); INSERT INTO d VALUES (1), (1), (2), (NULL), (3); SELECT * FROM (SELECT a FROM d INTERSECT ALL SELECT a FROM d UNION ALL SELECT a FROM d WHERE false) s WHERE a =3D 1; -- ERROR: XX000: could not find pathkey item to sort (prepare_sort_from_pathkeys, createplan.c) -- 18.6: a =3D 1, 1 -- 19beta4 / main: ERROR: could not find pathkey item to sort -- EXPLAIN (without ANALYZE) fails the same way: the error is raised while planning. Did some more digging with LLM, and it seems this works fine -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D workaround: the same query without = a sorted SetOp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D SET enable_sort =3D off; -- or enable_hashagg =3D on with statis= tics that favour hashing SELECT * FROM (SELECT a FROM d INTERSECT ALL SELECT a FROM d UNION ALL SELECT a FROM d WHERE false) s WHERE a =3D 1; -- 1, 1 (HashSetOp Intersect All) RESET enable_sort;