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 1xR8rW-00000000idO-2q19 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 13:59:42 +0000 Received: from localhost ([127.0.0.1]:46710 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR8rV-0000000BMB8-1Fu0 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 13:59:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:49328) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR8eN-0000000BCGx-42HB for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 13:46:08 +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 1xR8eL-00000000Ndq-0TQ0 for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 13:46:07 +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=kIIb3AHA3WfxrtL6uYQ/xA9s9WhIPG8nZmWD9O+YNrw=; b=cMAhSCBPbm3n+hjYkjWz6G93Uv 1QCbWkWBol8F+9J3v/fqtatTnNuPzQoa4oR0FbEpm37nD+abKQTwxWW38y9X5mI0V8+HK1jcNm0Sc 7Na0eUinwR/Tr+ZDJU2VwOgp47aEVmJCR+BHoqvEYEe2s+mqnSuwg3PuTJRkDRFGCJAz56pTmH9ay IQVahdE3c+js8W6V+IXc0acG7VskZ8RyRXtEKeaiPt+vM7pD016OL55UwDAzsMszRM1/2TGI22ZNu VVpoiC+xNYJpZILXA9xFVhKrLontddwBF6vAy7uA16kv6wQMx4GYvWlpIkpe4ZvcJJEEoO3Y1Oks/ +jamiuYg==; 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 1xR8eK-0000000133J-11lI for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 13:46: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 1xR8eJ-00000002jEV-0Nnl for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 13:46:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan8@gmail.com Reply-To: imchifan8@gmail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Nov 2026 13:45:48 +0000 Message-ID: <19881-cc00ace224a1fa3e@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: 19881 Logged by: Noah Email address: imchifan8@gmail.com PostgreSQL version: 18.6 Operating system: Linux/amd64 Description: =20 CLUSTER can choose a sequential scan plus explicit sort even when enable_sort is off and an enabled index-scan alternative exists. In the case below, high random_page_cost makes the sort route numerically cheaper, but its additional disabled-node count should take precedence over total cost and cause the index route to be selected. With enable_sort on, trace_sort reports "begin tuple sort", as expected. With enable_sort off, the same message still appears, showing that CLUSTER selected the disabled explicit-sort route. How to repeat: Save the following as setup.sql: ``` DROP TABLE IF EXISTS cluster_control; DROP TABLE IF EXISTS cluster_test; CREATE TABLE cluster_control (a integer, filler text); CREATE TABLE cluster_test (a integer, filler text); INSERT INTO cluster_control SELECT g, repeat('x', 80) FROM generate_series(1, 50000) AS g; INSERT INTO cluster_test SELECT * FROM cluster_control; CREATE INDEX cluster_control_idx ON cluster_control (a); CREATE INDEX cluster_test_idx ON cluster_test (a); ANALYZE cluster_control; ANALYZE cluster_test; ``` Save the control as control.sql: ``` SET client_min_messages =3D log; SET trace_sort =3D on; SET random_page_cost =3D 100000; SET seq_page_cost =3D 0.01; SET enable_sort =3D on; CLUSTER cluster_control USING cluster_control_idx; ``` Save the test as test.sql: ``` SET client_min_messages =3D log; SET trace_sort =3D on; SET random_page_cost =3D 100000; SET seq_page_cost =3D 0.01; SET enable_sort =3D off; CLUSTER cluster_test USING cluster_test_idx; ``` Run the files in order, with the control and test in separate sessions: ``` psql -X -d postgres -f setup.sql psql -X -d postgres -f control.sql psql -X -d postgres -f test.sql ``` Both CLUSTER commands complete. The decisive recorded output for the control includes: ``` SET SET SET SET SET CLUSTER LOG: begin tuple sort: nkeys =3D 1, workMem =3D 65536, randomAccess =3D f ``` The test produces the same strategy discriminator despite enable_sort being off: ``` SET SET SET SET SET CLUSTER LOG: begin tuple sort: nkeys =3D 1, workMem =3D 65536, randomAccess =3D f ``` Other trace_sort messages report index sorts used while rebuilding indexes; the "begin tuple sort" message identifies the explicit sort used to implement CLUSTER itself. This was reproduced on PostgreSQL 18.6 on Linux/amd64. The behavior suggests that CLUSTER's manual comparison of its alternatives uses numeric cost without first honoring the disabled-node count. This occurs when CLUSTER chooses between an index scan and a numerically cheaper sequential scan plus sort while explicit sorts are disabled.