pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Honor enable_sort and enable_seqscan in CLUSTER and REPACK
Date: Tue, 24 Nov 2026 02:36:25 +0000
Message-ID: <E1xVgOO-000000005iD-39mT@gemulon.postgresql.org> (raw)

Honor enable_sort and enable_seqscan in CLUSTER and REPACK

CLUSTER and REPACK USING INDEX could choose a sequential scan and sort
even when enable_sort or enable_seqscan was off and an enabled index
scan was available. This could also cause unexpected temporary disk
usage for sorting.

The cause was that plan_cluster_use_sort() compared only total costs,
ignoring the disabled-node counts used to enforce these settings.
In v19 and later, it also left default_pgs_mask at zero, marking both
scan paths as disabled regardless of enable_seqscan.

Fix this by using compare_path_costs() to compare disabled-node counts
before costs, and initializing the strategy mask for the scan paths.
An enabled index scan is now preferred when either enable_sort or
enable_seqscan is off, regardless of the estimated costs.

Backpatch to v18, where the cost comparison regression was introduced.

Reported-by: Noah <imchifan8@gmail.com>
Author: Raja Sai Pranav <rajasaipranav0@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/19881-cc00ace224a1fa3e@postgresql.org
Backpatch-through: 18

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d51990fdba1f3afb267eb6051b32283a20de6387

Modified Files
--------------
src/backend/optimizer/plan/planner.c  | 12 +++++++++++-
src/test/regress/expected/cluster.out | 22 ++++++++++++++++++++++
src/test/regress/sql/cluster.sql      | 17 +++++++++++++++++
3 files changed, 50 insertions(+), 1 deletion(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1xVgOO-000000005iD-39mT@gemulon.postgresql.org>
Permalink:  ../E1xVgOO-000000005iD-39mT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xVgOO-000000005iD-39mT@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org
  Subject: Re: pgsql: Honor enable_sort and enable_seqscan in CLUSTER and REPACK
  In-Reply-To: <E1xVgOO-000000005iD-39mT@gemulon.postgresql.org>
  References: <E1xVgOO-000000005iD-39mT@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox