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:00:07
Message-ID: nh-8a23e327-61fa-40b1-b814-4d8997269fef@google.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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
v2-0001-Honor-enable_sort-and-enable_seqscan-in-CLUSTER-s.patch text/x-patch 4.8 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Raja Sai pranav 2026-11-21 06:24:20 Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off
Previous Message Fujii Masao 2026-11-21 02:28:31 Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off