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 1xU08r-00000000fH3-0pmj for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Nov 2026 11:17:25 +0000 Received: from localhost ([127.0.0.1]:54782 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xU08q-00000000ZlE-2kLc for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Nov 2026 11:17:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:48310) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTo5V-0000000EDtv-1Ytl for pgsql-bugs@lists.postgresql.org; Wed, 18 Nov 2026 22:25:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTo5S-00000000QDP-3ftf for pgsql-bugs@lists.postgresql.org; Wed, 18 Nov 2026 22:25:09 +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=xxB2C9ivLMeHjndfiEUjNo5TeQoLG3LkCY70CV7wsc0=; b=Up0nxqbOLVEPTchd2dJf3oFf/o Gg6fBO28uI/LTSJ7J3ljls5eKw6vNrVR7PMs/nO0Gw1XtVL8+uW8n3p0/2P3tmH9V+PV6i17KXK28 MAJh8ahxbD6LE9aQZIPz9Dkp0FsFs8PnZuDMAsgksHtgvxltY06MXQR9wXTdfKXemi5LsxRzqG1rc A7ZRLYCoZHATvbdcxy9JSChj9NE1mStAt3lwbvmgcVGAZvChXGa3sApmqWdyS9CotqrssYUxNk/+U YXffCMVyOjJqkZlWSu8YTe7rgWj4C1f83vBKuOm6mQV0aA/U1DoWjwT9qKtbdrxFA9yXPprz20DRV q9TVLg8A==; 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 1xTo5Q-000000016ei-3Cea for pgsql-bugs@lists.postgresql.org; Wed, 18 Nov 2026 22:25:05 +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 1xTo5P-00000002mwt-1NZI for pgsql-bugs@lists.postgresql.org; Wed, 18 Nov 2026 22:25:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19916: UNION over hash-only and sort-only columns: could not devise a query plan To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: tharakan@gmail.com Reply-To: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 18 Nov 2026 22:24:14 +0000 Message-ID: <19916-8097ca71b8aa4085@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: 19916 Logged by: Robins Tharakan Email address: tharakan@gmail.com PostgreSQL version: Unsupported/Unknown Operating system: Debian 13 (x86_64) Description: =20 A UNION whose columns can't all be sorted and can't all be hashed fails with an internal error: ERROR: XX000: could not devise a query plan for the given query LOCATION: set_cheapest, pathnode.c:279 tsvector has a btree opclass but no hash opclass, and aclitem has a hash opclass but no btree one, so neither strategy works for the query below. Up to 16 this was reported properly, and INTERSECT and EXCEPT over the same columns still are, on every branch: ERROR: 0A000: could not implement UNION with the DETAIL "Some of the datatypes only support hashing, while others only support sorting." generate_union_paths() adds a hashed path only when every column can be hashed, and a sorted one only when every column can be sorted, so for these columns it adds no path at all, and set_cheapest() raises the error. Up to 16, make_union_unique() called choose_hashed_setop(), which raised "could not implement UNION" for this case. 12933dc6048 replaced make_union_unique() and dropped that check, while generate_nonunion_paths() still makes it for INTERSECT and EXCEPT. At 12933dc6048 itself the query returns a row with no error; it fails from c37267162e8, which made generate_union_paths() set groupList even when the columns can't be sorted. It reproduces on master through REL_17_STABLE. REL_16_STABLE raises the 0A000 error. It's an elog(ERROR), not an assertion: a release build (no cassert, -O2) fails the same way. SQL =3D=3D=3D SELECT NULL::tsvector, NULL::aclitem[] UNION SELECT NULL, NULL; -- the same with xid (hash only) and tsvector (btree only): SELECT '123'::xid, ''::tsvector UNION SELECT '123'::xid, ''::tsvector; Commit =3D=3D=3D=3D=3D=3D Started: c37267162e8 (2024-05-21) Affects: REL_17_STABLE 162cf60d925 (2026-11-18) REL_18_STABLE 7c19a14bbef (2026-11-18) REL_19_STABLE 19aa5713be2 (2026-11-18) Master: 8c15c2cb5c4 (2026-11-18), the newest commit tested Built with --enable-cassert --enable-debug (gcc 14.2.0, Debian 13, x86_64). Error Log =3D=3D=3D=3D=3D=3D=3D=3D=3D ERROR: XX000: could not devise a query plan for the given query LOCATION: set_cheapest, pathnode.c:279 STATEMENT: SELECT NULL::tsvector, NULL::aclitem[] UNION SELECT NULL, NULL Found using SQLsmith, SQLReduce and Claude. - Robins Tharakan Databricks