pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raja Sai pranav <rajasaipranav0@gmail.com>
To: masao.fujii@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Cc: imchifan8@gmail.com
Subject: Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off
Date: Fri, 20 Nov 2026 22:24:20 -0800
Message-ID: <nh-9e691925-bd01-4cfa-9249-764736897349@google.com> (raw)
In-Reply-To: <nh-8a23e327-61fa-40b1-b814-4d8997269fef@google.com>
References: <nh-8a23e327-61fa-40b1-b814-4d8997269fef@google.com>

Hi,

Here is the separate docs patch. The only place that mentions this is
"Notes on Resources" in repack.sgml, which the CLUSTER page points to. It
adds one sentence: with enable_indexscan off, a sequential scan and sort is
always used, and with enable_seqscan off, the index scan is preferred. Both
match what I saw in the 8-combination tests. The enable_seqscan part is
only true with the v2 code fix applied, so this goes on top of it.

I couldn't build the full docs locally because the DocBook DTD isn't
installed. I checked that the paragraph is well-formed and that the three
link targets exist in config.sgml.

Regards,
Sai Pranav

On Sat, Nov 21, 2026 11:30 AM, Raja Sai pranav <rajasaipranav0@gmail.com>
wrote:

> Hi Fujii-san,
>
> Thanks for looking. You are right: with default_pgs_mask at zero, both
> scans count as disabled, so they tie and enable_seqscan does nothing. v2
> attached adds your mask initialization as you wrote it. I first tried
> making PGS_INDEXSCAN depend on enable_indexscan, but the function already
> returns early when enable_indexscan is off, so your version is enough.
>
> I ran all 8 combinations of enable_sort, enable_seqscan and
> enable_indexscan on master, once with seqscan + sort cheaper
> (random_page_cost = 100000) and once with the index scan cheaper
> (seq_page_cost = 1000). Compared with v1, the only change is enable_seqscan
> = off with sort cheaper: it now uses the index scan.
>
> The test in cluster.sql now also checks enable_seqscan = off. It fails if
> either part of the fix is removed, and the regression tests pass. v2
> applies cleanly to REL_19_STABLE. REL_18_STABLE has no default_pgs_mask, so
> it would need only the compare_path_costs() part; I can send a separate
> version for 18 if that helps.
>
> I agree about the docs. I'll send that as a separate patch.
>
> Regards,
> Sai Pranav
>
> On Sat, Nov 21, 2026 07:58 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
>
>> On Sat, Nov 21, 2026 at 2:12 AM Raja Sai pranav
>> <rajasaipranav0@gmail.com> wrote:
>> > The patch uses compare_path_costs(), which looks at disabled nodes
>> first, like the rest of the planner.
>>
>> Thanks for the patch!
>>
>> There seems another related issue: enable_seqscan = off still has no
>> effect,
>> even with this patch. The cause seems to be that plan_cluster_use_sort()
>> leaves glob->default_pgs_mask at zero, effectively disabling both scan
>> types.
>>
>> We should initialize the default_pgs_mask before calling
>> build_simple_rel()?
>> For example:
>>
>> -------------------------------
>>   glob = makeNode(PlannerGlobal);
>>
>> + glob->default_pgs_mask = PGS_CONSIDER_NONPARTIAL | PGS_INDEXSCAN;
>> + if (enable_seqscan)
>> + glob->default_pgs_mask |= PGS_SEQSCAN;
>> -------------------------------
>>
>> This fix seems necessary for both v19 and master.
>>
>> BTW, separately, I found that the CLUSTER/REPACK docs mention only
>> enable_sort, although enable_seqscan and enable_indexscan also affect
>> the choice. Perhaps we could document those in a separate patch.
>>
>> Regards,
>>
>> --
>> Fujii Masao
>>
>

Attachments:

v1-0001-doc-Mention-enable_indexscan-and-enable_seqscan-i.patch (text/x-patch, 1.5K) download From 08b4dc8bf7aa2d91dbb7b9ee6123133a2bbbeba5 Mon Sep 17 00:00:00 2001 From: Sai Pranav <rajasaipranav0@gmail.com> Date: Sat, 21 Nov 2026 06:23:54 +0000 Subject: [PATCH v1] doc: Mention enable_indexscan and enable_seqscan in REPACK resource notes The notes said only that enable_sort can stop REPACK USING INDEX (and so CLUSTER) from choosing a sequential scan and sort. enable_indexscan and enable_seqscan also affect that choice, so say how. Suggested by Fujii Masao. Discussion: https://postgr.es/m/19881-cc00ace224a1fa3e@postgresql.org --- doc/src/sgml/ref/repack.sgml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/ref/repack.sgml b/doc/src/sgml/ref/repack.sgml index 4cd3cfa0b1..58ab8ac391 100644 --- a/doc/src/sgml/ref/repack.sgml +++ b/doc/src/sgml/ref/repack.sgml @@ -294,7 +294,11 @@ REPACK [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] USING requirement is intolerable, you can disable this choice by temporarily setting <xref linkend="guc-enable-sort"/> to <literal>off</literal>; or omitting <literal>USING INDEX</literal> if the table doesn't need to be - reordered. + reordered. The choice also follows <xref linkend="guc-enable-indexscan"/> + and <xref linkend="guc-enable-seqscan"/>: with + <varname>enable_indexscan</varname> off, a sequential scan and sort is + always used, and with <varname>enable_seqscan</varname> off, the index + scan is preferred. </para> <para> -- 2.50.1 (Apple Git-155)

view thread (11+ messages)  latest in thread

Message-ID: <nh-9e691925-bd01-4cfa-9249-764736897349@google.com>
Permalink:  ../nh-9e691925-bd01-4cfa-9249-764736897349@google.com/
Also on:    postgresql.org/message-id/nh-9e691925-bd01-4cfa-9249-764736897349@google.com

 ·  · 

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-bugs@postgresql.org
  Cc: rajasaipranav0@gmail.com, masao.fujii@gmail.com, imchifan8@gmail.com
  Subject: Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off
  In-Reply-To: <nh-9e691925-bd01-4cfa-9249-764736897349@google.com>
  References: <nh-8a23e327-61fa-40b1-b814-4d8997269fef@google.com> <nh-9e691925-bd01-4cfa-9249-764736897349@google.com>

* 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