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 1xUeWY-000000015Zo-0HIL for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Nov 2026 06:24:34 +0000 Received: from localhost ([127.0.0.1]:37244 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xUeWX-0000000DcWS-1E8r for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Nov 2026 06:24:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:44266) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xUeWW-0000000DcW7-47P7 for pgsql-bugs@lists.postgresql.org; Sat, 21 Nov 2026 06:24:33 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xUeWS-00000000rhK-2EB9 for pgsql-bugs@lists.postgresql.org; Sat, 21 Nov 2026 06:24:30 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-c40e30c26a4so586131066b.0 for ; Fri, 20 Nov 2026 22:24:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795242262; cv=none; d=google.com; s=arc-20260327; b=AQsHv3B7W8buUKB0MGRPYncqBqfuJiXTbtsm5NreOaVhg1vy9f9HcouLwlbWzTxyx/ frQEtb43ltdCNqBwkfU0jl60+MBwGkr1kUCN7LIexRJNg2YP8nwxxYTnhxHyUjjW5eiT RQ9JpO1vV7lQQGh4eijoJfSV3AsuYBVWhiWZAnMnee2aD2RMEyzA1LcjJXFPqNhPM4CZ Oy6rwKJHzwy+6gPBYUOJMgp+8xhQr+r/h6utg8LW2KsPC9OPFA1IAWhmRd41Bdpn1NBS AAiXLRw5tL3OyXUofIxKyW5GZwgOCmK0hErVEY2SJS8SmOsad8kszowsRcTR6Eij8Ezm xL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:dkim-signature; bh=DsGtV+Exo5tQ5cRTNexcGKoILoHW3gBSUexm5bRGPvs=; fh=oKVTxr+tVg2tCvIPCNvWPIZ0kf66Ahi5DBL4kKmfJTI=; b=ktKLuTV86zYZlqqvqNuMcghMIhX8f2J9G+UIJ2Qs5Yfr1cOJT0M1c3hazdBRyteeHd BvQxMTnrRGJAnHXFoWRsQc5H0itvtUteihI1ISSNzgcsEVWYS67e3ht5D7V8L2vhRUHs GXJu7irJRq2haWgLSpAv0SQDt6xLNjaFaebDkr7Wz5gW62Lceov6ZOIvYP8nhnvVOgly H9rpRaqG1ZmEe1sniMstKtd2yhV63qIN63BnOhTX35hDLkfod1hFzSWnvuk5FEOc1SUF 8uN0sCMA+4dnV/e6vts1B92PREsBR1BG3sOfQRhfQmI6d4QBdZJaH/TNTLG/Rsepl0mF g87Q==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795242262; x=1795847062; darn=lists.postgresql.org; h=content-type:cc:to:subject:message-id:date:mime-version:references :in-reply-to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DsGtV+Exo5tQ5cRTNexcGKoILoHW3gBSUexm5bRGPvs=; b=ZgnEaYkhyhVRozHgfC4qM5WgNQRtSUk0ZgMCpBARl/3tpFLg2TWclJkWD4gAq1nFIN 0kt7vTa6D0qPOJcEdGTlYpMF4jwnDALQso+zTbndq5g+d8RpYEYckRLIFjKyXI6P4xyi Q/iDtlzJU5ruuP/3fsZZcJK0nx0o6q4VvoeXvhqB45jReV+CX+7s4M4eqUGRufHh/XEJ RxN9dr5O16Bk1KHi8DSbgEsmY0XgeTfi/HBjnAjTht8oAKzlJrLIDwO3t9VbbfwKs+7s Q1kfDJMjSXNVzvYEnCysFbqSHFfjzc5CJwRO0qWcv+cijfxTu7qpGVA0KzNiZZWKLvgo aF/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795242262; x=1795847062; h=content-type:cc:to:subject:message-id:date:mime-version:references :in-reply-to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DsGtV+Exo5tQ5cRTNexcGKoILoHW3gBSUexm5bRGPvs=; b=WWGPtAPhWY4dmI3AjmBjDmvnecBbUO9c+iUk2n0KAkoQ/n7Fog++e83JI5G71JQ2WU WFpz9qzn085kKdvUNmZlOMpw0cdKeYbSgtgkGVbPcXlKYDBWGxsDyIiYTZ1D8pDGkuaG d9ecMaSwXbmJqF+xsAXJSXXVrc4eATM2R0wjkFifEMVhFWUo+iPG5LKupDMa0NG2HVoK PCCDMrbLVN0JXD2QlY19gWW7CQl6LSEo29TcAo3Xz4ohtxta0zsbemt04rDVGK5BhM/6 55ZeXWHYoDOhHWZ1fhsp25lRIOlcbD4d/YA4Pukjtsq6xloIk5ArltncUML9tbWR5m9O SnCw== X-Gm-Message-State: APuU4Z9znuER4uQhCFb1IHnzLU/Cq6aHOtucA7qAhFSpdtBdU8owDSpe E3xp5ELxKBm+5c2M242ZZSEayV1LvKnGw9GgdQEBY49ZyfoAkX0PdI6svZv6wWYi7P/YNl22ez8 +GRESzeSBrP4K1+FcMtpbm4nYx0lBfKo= X-Gm-Gg: AYBFou0/lxAVjbyuZRQhUNVqAlqJF4SnQ3UYwiMiP+Eh3CKLbN2RkyF16LydBAt2sUw n15dGJ8WUaE30PhwPLmbaiDlMY1dUvksqWoTOHOCo/hlUaYNq2HBEnRr+jsoo2AGzbh6DZFPdUy FyqvWqSpE/MbDSp9jAjWU6CfSM8QXelSbq57o524t9LaVYRAS7A/pktIn9ZJJY5pCc1p9tpc0u9 3WtNrlbr5tzb8KzJfEH9ENfVXCxs0lDdQu840tJy1e8eQ6GjLSxbxxRC/1PSFL8macXSQ/qLyz+ RO7miLbRRXd0EziqGam7vKRPh2PmgxtO+IiV7xr2SS5hCYm+SB1o42Xk/gJuRYKtyBs87tgs1gu cr9wkyuEDuCbGjtNQ8s5gOacYIf76pvv13nD3xr140Y2mnVtb961r2V7MjbVUbM06 X-Received: by 2002:a17:907:3f18:b0:c46:9711:e30e with SMTP id a640c23a62f3a-c5131a1601amr601109866b.29.1795242262323; Fri, 20 Nov 2026 22:24:22 -0800 (PST) Received: from 101988054943 named unknown by gmailapi.google.com with HTTPREST; Fri, 20 Nov 2026 22:24:20 -0800 Received: from 101988054943 named unknown by gmailapi.google.com with HTTPREST; Fri, 20 Nov 2026 22:24:19 -0800 From: Raja Sai pranav In-Reply-To: References: MIME-Version: 1.0 X-Google-Nh-Sender: AW_J_UoGSHMKlw9OlLyKdTtU0Hg1uOlcVhMvzafzJc9mJVLU2reoNUuzJJ3NDy9xBPlDBnGX0MiXD-Gk1L6OT3sR2QD9SzecYUSqP_ZheyyT5X4ECligIl2l3WWGKaOUyx39YSW8zhKxYL2cW9831k0SikKR3P2CDrmprCz_y7mqaPtYlIoAgKWTfChVGZwEniKEWPNKs9RnKlAwMIlXMSw8-estWiG1-ZG2yk8MzL46ukCD67-WzKbOzd30WwJoDnLYuxlFX3Ajq7BgWZ0r79043rY Date: Fri, 20 Nov 2026 22:24:20 -0800 X-Gm-Features: Aa3M54rd-q4xiYBdw0buEY-OMNvNutVVXzNVTz6r30VKpWgi97YvOrl7aii97tQ Message-ID: Subject: Re: BUG #19881: CLUSTER uses a disabled sort path when enable_sort is off To: masao.fujii@gmail.com Cc: pgsql-bugs@lists.postgresql.org, imchifan8@gmail.com Content-Type: multipart/mixed; boundary="0000000000005533360660c3695b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005533360660c3695b Content-Type: multipart/alternative; boundary="0000000000005533340660c36959" --0000000000005533340660c36959 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 =3D 100000) and once with the index scan cheaper > (seq_page_cost =3D 1000). Compared with v1, the only change is enable_seq= scan > =3D off with sort cheaper: it now uses the index scan. > > The test in cluster.sql now also checks enable_seqscan =3D 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 wrote: > >> On Sat, Nov 21, 2026 at 2:12=E2=80=AFAM Raja Sai pranav >> 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 =3D 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 =3D makeNode(PlannerGlobal); >> >> + glob->default_pgs_mask =3D PGS_CONSIDER_NONPARTIAL | PGS_INDEXSCAN; >> + if (enable_seqscan) >> + glob->default_pgs_mask |=3D 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 >> > --0000000000005533340660c36959 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

Here is the separate docs patch. T= he only place that mentions this is "Notes on Resources" in repac= k.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-co= mbination 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 do= cs 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.sg= ml.

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 sc= ans count as disabled, so they tie and enable_seqscan does nothing. v2 atta= ched adds your mask initialization as you wrote it. I first tried making PG= S_INDEXSCAN depend on enable_indexscan, but the function already returns ea= rly when enable_indexscan is off, so your version is enough.

I ran a= ll 8 combinations of enable_sort, enable_seqscan and enable_indexscan on ma= ster, once with seqscan + sort cheaper (random_page_cost =3D 100000) and on= ce with the index scan cheaper (seq_page_cost =3D 1000). Compared with v1, = the only change is enable_seqscan =3D off with sort cheaper: it now uses th= e index scan.

The test in cluster.sql now also checks enable_seqscan= =3D 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 defa= ult_pgs_mask, so it would need only the compare_path_costs() part; I can se= nd 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, Fu= jii Masao <ma= sao.fujii@gmail.com> wrote:
On Sat= , Nov 21, 2026 at 2:12=E2=80=AFAM Raja Sai pranav
<rajasaipr= anav0@gmail.com> wrote:
> The patch uses compare_path_costs(), which looks at disabled nodes fir= st, like the rest of the planner.

Thanks for the patch!

There seems another related issue: enable_seqscan =3D off still has no effe= ct,
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 t= ypes.

We should initialize the default_pgs_mask before calling build_simple_rel()= ?
For example:

-------------------------------
=C2=A0 glob =3D makeNode(PlannerGlobal);

+ glob->default_pgs_mask =3D PGS_CONSIDER_NONPARTIAL | PGS_INDEXSCAN; + if (enable_seqscan)
+ glob->default_pgs_mask |=3D 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
--0000000000005533340660c36959-- --0000000000005533360660c3695b Content-Type: text/x-patch; charset="UTF-8"; name="v1-0001-doc-Mention-enable_indexscan-and-enable_seqscan-i.patch" Content-Disposition: attachment; filename="v1-0001-doc-Mention-enable_indexscan-and-enable_seqscan-i.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: 99fce3fa1d4c8e70_0.1 RnJvbSAwOGI0ZGM4YmY3YWEyZDkxZGJiN2I5ZWU2MTIzMTMzYTJiYmJlYmE1IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBTYWkgUHJhbmF2IDxyYWphc2FpcHJhbmF2MEBnbWFpbC5jb20+ CkRhdGU6IFNhdCwgMjEgTm92IDIwMjYgMDY6MjM6NTQgKzAwMDAKU3ViamVjdDogW1BBVENIIHYx XSBkb2M6IE1lbn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