Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: masao(dot)fujii(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, imchifan8(at)gmail(dot)com
Subject: Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off
Date: 2026-11-21 06:24:20
Message-ID: nh-9e691925-bd01-4cfa-9249-764736897349@google.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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(at)gmail(dot)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(dot)fujii(at)gmail(dot)com> wrote:
>
>> On Sat, Nov 21, 2026 at 2:12 AM Raja Sai pranav
>> <rajasaipranav0(at)gmail(dot)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
>>
>

Attachment Content-Type Size
v1-0001-doc-Mention-enable_indexscan-and-enable_seqscan-i.patch text/x-patch 1.5 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Raja Sai pranav 2026-11-21 06:31:25 Re: BUG #19890: pg_receivewal advances past a truncated LZ4 WAL segment
Previous Message Raja Sai pranav 2026-11-21 06:00:07 Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off