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.96) (envelope-from ) id 1w5Y8b-003Mbi-2d for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 23:59:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5Y8Z-00HaWK-2o for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 23:59:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5Y8Z-00HaWC-1b for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 23:59:47 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5Y8W-00000001AfJ-3BcP for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 23:59:47 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-899a9f445cbso4075596d6.0 for ; Wed, 25 Mar 2026 16:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774483182; cv=none; d=google.com; s=arc-20240605; b=Iam8bl5YSOHR9whVEX5esVq7uDbbfPCBJrE+SGCl8KDB032RONow+ZPFXvM4VRstXV cMuuQ6gRMkGQHOLNhEnRjfaLlWtbEmkr9oo4NsZqwBluz55bIm6tWFT7Zz7XzperpupJ gt7tMytpEV839vGqBrCAlQBM1ax2MnP50kFseghC/RssUfZuHhrfO6naHCWIcAnR8gUT +N6eshEro9dCtlcfG5vtPRtrqe2/ZpywSDQo+aL2ME7EJ9S42tMX9eiBkmFjW4Oio8Ec T8OL+e1Mjkv7N6pZfnmCI6fYU07LIdfT3plA1jmCh6LUupgxEhua4nMYSOC0jPe3sAih T91g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=b7loSWR+4io2q9KCdwdUx64hjzQ23R4TdjTbguQRNT0=; fh=dNjQaCM4Ktrb6bmWZO5LaVBoCO1N7S50hk5FNRf0EhI=; b=I/UB8W+ISzpaeigqjCq3H1ep1NwCEK1aSnXOlCzxC/883uXu8XHji2TGOmZsqhZzLL mI/cwf5sIR+8gg6pqp/6wPirEgzcHd7n+fo0O8mqTDohfPPNmT8oWxRTdRwB3TJ0mm5q Qt1c/4dUDkdT7tF6lDE+VztCZ/rf6DZGFFwPexA4EDMp6vES1KY8CUMCzGrNWOEli569 fUI4UPGQ+cTh7rudjhbld8akUNITFAT2ETMX3SwaVSTzG52RBjp1WfZklIk2Kte9VxUA cc84U8npHtJ/6Gr3/XZjHhLF87xkw0Cfr8Naf8QfyWvqNOu/gq9lIstzLB61puLyHSbZ giPQ==; 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=fittl.com; s=google; t=1774483182; x=1775087982; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b7loSWR+4io2q9KCdwdUx64hjzQ23R4TdjTbguQRNT0=; b=T6i2sDyWxGFkB5LdwrAd8cvwsT3VzZy9vgwXK8de0/3lM8SqNOylZeDNsyo7SdOif4 AwO9yA3c/swC1Cm4ft+RjygoQ6uvkl3EoHT//Bi32a+EboyDyjNHmocl7+afKRIns4ea wBP/oa5JK9aBmgVBabHdfMwkZ2cMxydDN0rj4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774483182; x=1775087982; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=b7loSWR+4io2q9KCdwdUx64hjzQ23R4TdjTbguQRNT0=; b=CJz8sqWePO+3sAjO4zGA7NQFPk6vVEV7BxwS4pnZ91ZQiIzjrJd10GgwXo24yrYrb3 HS0PKPVVsP0YgFv1WZmZ0FOpRvVtcL/e0p6zfE4KtBbNWZ7PTSFQb5XRFEZA/2/FZSiA vSDBgF7wJWgfyn3TTRq4BgWqrLluKCOZ5Y2R1shJnYLkcAV86llqDOtv65nBi22aUhmR grVMyssT76AOYGqJOhPfFjfbw8Gn78N9f4tC+lkQzlLOhE0pDbWqhnseMK/pAlxBTWB0 J447NvDhi/ZTdtCK3Y0IbQdbKmdBS/5jTWiNQvvP2q9kazp4TKaLd2ngrYhrPMl0R8Yt Kytg== X-Forwarded-Encrypted: i=1; AJvYcCUN8USAGRXFakoiwaYUTIUlj0dXyrKmZymPVXX3uL3urbODK5LCbCTZdNUsjYdZUWO5uPiqwuBNooai8rbQ@lists.postgresql.org X-Gm-Message-State: AOJu0Yz2liXLJKRmtFnnL8fKBVn4YuZQFgeh/6LohowUiBdBd6w99j+Y rzTInI7nQec0FfOMGY+pyflrXTlDDVvxOZaqAdOCVRC/XuVMxgRx/SmD+jTWqCZJIuyEuEc4as7 5Ly7zQD6ASaEX5jof3Pj5rg8DrUhP+EhdsQTIJU/NrIlVNS1GmyTZaO3O X-Gm-Gg: ATEYQzzlZXzAvmBzgPxod38sYrxa54Zt9CiWHu+zBF3nTfz/aOSeH7LfSis2ZcG8xrQ Ql15V3NX4iKGK1gYm0p/sDh5v0+NwDo8iFGlKwfWK8WTrAztN0V3jRDUtuXo5xJ1EDsRTM9IKrf 2PhLN2zUg/KnZdfhoz1pe223HCLcEmPvMso7KCIq5YnWidt1rn4xeRAzSKWvRUgw72qCtXTdpcN SMMpCOVqHlC80gKXP948Ejm7Lb9ZN4PnojUOg7LJ2m0zXZWy9d9mmtsnbh9G9CCYCT79oDCk+hH SqnA3aMZJifzQ+UOrOokghpKRO9kDoqnw45pb7VIbdRc052LRg== X-Received: by 2002:a05:6214:dae:b0:89a:2fe7:91d1 with SMTP id 6a1803df08f44-89cc494648emr94064716d6.6.1774483182196; Wed, 25 Mar 2026 16:59:42 -0700 (PDT) MIME-Version: 1.0 References: <1136161.1769654478@sss.pgh.pa.us> <1299934.1773938807@sss.pgh.pa.us> In-Reply-To: From: Lukas Fittl Date: Wed, 25 Mar 2026 16:59:06 -0700 X-Gm-Features: AaiRm51GT8KSv1vvnzObhdYMZcc0avah3AhPRVXes3oZIgJmUgGVrkP1urNEcwE Message-ID: Subject: Re: pg_plan_advice To: Robert Haas Cc: Tom Lane , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Robert, On Tue, Mar 24, 2026 at 2:10=E2=80=AFPM Robert Haas = wrote: > > On Sat, Mar 21, 2026 at 9:13=E2=80=AFAM Robert Haas wrote: > > So I'm left with the idea that to get test_plan_advice to be fully > > stable on these slower machines, it will probably be necessary to make > > it control which AlternativeSubPlan is chosen and whether a > > MinMaxAggPath is chosen or not. I have some ideas about how to > > accomplish that in a reasonably elegant fashion without adding too > > much new machinery, but I need to spend some more time validating > > those ideas before committing to a precise course of action. More > > soon. > > Here is v22. There are four new patches. > > 0001 adds a disabled_nodes fields to SubPlan, to fix the bug that I > identified in the email to which this is a reply. This looks good, and is consistent with how it would have worked before the introduction of disabled nodes (since costs would have just been very high and thus discourage a subplan with many disabled nodes). Only nit is that the commit hash reference in the commit message doesn't seem right, I think you probably meant e22253467942fdb100087787c3e1e3a8620c54b2 > 0002-0004 are an attempt to fix the remaining buildfarm failures not > already addressed (or attempted to be addressed, anyway) by other > commits. The basic idea, implemented by 0004, is to add a > DO_NOT_SCAN() advice tag. This advice is generated when we consider a > MinMaxAggPath or a hashed SubPlan. In either case, all relations which > are part of the non-selected alternative are marked DO_NOT_SCAN(), > which works like scan type advice but disables every possible scan > type rather than still allowing exactly one of them. Unless I've > missed something, this should be sufficient to make pg_plan_advice > stabilize which of two alternative SubPlans we pick and whether or not > a min/max aggregate is chosen. 0002 does some preliminary refactoring > to provide a more centralized way of tracking per-PlannerInfo details > within pg_plan_advice. 0003 makes the necessary change to > src/backend/optimizer, which consists of adding an alternative_root > field to each PlannerInfo and setting it appropriately. 0004 then > updates pg_plan_advice to implement DO_NOT_SCAN(). For 0002: I think that overall looks like a good refactoring, with two minor notes: > diff --git a/contrib/pg_plan_advice/pgpa_planner.c b/contrib/pg_plan_advi= ce/pgpa_planner.c > index fee88904760..70139ff42be 100644 > --- a/contrib/pg_plan_advice/pgpa_planner.c > +++ b/contrib/pg_plan_advice/pgpa_planner.c > ... > @@ -2017,34 +1949,64 @@ pgpa_planner_feedback_warning(List *feedback) > errdetail("%s", detailbuf.data)); > } > > -#ifdef USE_ASSERT_CHECKING > - > /* > - * Fast hash function for a key consisting of an RTI and plan name. > + * Get or create the pgpa_planner_info for the subroot with the given > + * plan_name. > */ > -static uint32 > -pgpa_ri_checker_hash_key(pgpa_ri_checker_key key) > +static pgpa_planner_info * > +pgpa_planner_get_proot(pgpa_planner_state *pps, PlannerInfo *root) > { I'd word that as "Get or create the pgpa_planner_info for the given PlannerInfo and its associated plan_name", since you're not passing a plan_name as the argument. > @@ -2053,19 +2015,34 @@ pgpa_ri_checker_save(pgpa_planner_state *pps, Pla= nnerInfo *root, > RelOptInfo *rel) > { > ... > + if (proot->rid_array_size <=3D rel->relid) > + { > + int new_size =3D Max(proot->rid_array_siz= e, 8); > + > + while (new_size < rel->relid) > + new_size *=3D 2; This could use pg_nextpower2_32 on the rel->relid instead of the manual while loop. --- For 0003: I wonder if "original_root" wouldn't be more correct here as a name (instead of "alternative_root"), since if I follow the implementation correctly, you are adding a pointer on each alternative root, back to the original root that the alternative was copied from. I also wonder if maybe we should be more narrow in what we keep here. It seems 0004 mainly needs the original plan name, so maybe its better if we just keep that for targeting purposes, vs a full pointer to the PlannerInfo. The planner makes an effort to zap unused subplans at the end of set_plan_references, and I think this new field would then be the only pointer to those unused subplans. If we decided to add an early free there at some point (instead of just making them a NULL entry in the list), that'd break pg_plan_advice. --- For 0004: > + /* > + * If the corresponding PlannerInfo has an alternative_root, then th= is is > + * the plan name from that PlannerInfo; otherwise, it is the same as > + * plan_name. > + * > + * is_alternative_plan is set to true for every pgpa_planner_info th= at > + * shares an alternative_plan_name with at least one other, and to f= alse > + * otherwise. > + */ > + char *alternative_plan_name; > + bool is_alternative_plan; Per the earlier note, I think using "original_plan_name" would make more sense here, because it'll be the name the alternatives are based on. I also think "has_alternative_plan" is more clear for the boolean, since it'll be set on the info for the original info as well, if I understand correctly. Otherwise 0004 looks like a reasonable compromise for now. I feel like we can find better ways of doing this over time, and there are parts I'm not excited about (e.g. the targeting feels a bit brittle when it comes to anything that'd cause generated alternative subplan names to change), but I think it works for now. > 0005 is the pg_collect_advice module from previous versions of the > patch set. The main change here is that I completely rewrote the TAP > test, which previously was running the entire regression test suite > yet another time. That's been replaced with something that is much > faster and much better targeted at properly testing the shared advice > collector. Aside from that, I added one more check for > InvalidDsaPointer where the code was previously lacking one.