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 1vxmQB-00H7uU-1I for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 13:37:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxmQ9-00CrO3-1U for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 13:37:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vxmQ9-00CrNU-08 for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 13:37:49 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vxmQ7-00000000NXA-0ss9 for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 13:37:48 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-65faaa8b807so3161806a12.3 for ; Wed, 04 Mar 2026 05:37:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772631466; cv=none; d=google.com; s=arc-20240605; b=Euk1dzyc6YqaxCLnpsfR39chPcKO/eLD1MlrB0jYTjKZEZuvCaUrQTFNZhdosHVBKE KepOhdl8EyeobNuQAwOxCON8RSO4K+/dAtER0yRF4ABjmXqRPdd6HiCvq+imK7wSwmCD UyaCOh8EbfdWEVDA/bqKlT32oqMquXnfe1c3ys5VbHdkf6YPIfp31N3ekNPN4Sh8cPPP z6gQdzcrClMW9zvIT9TU9tNDqoBE21t7i0MUMfeOvhczG0s0Xe9FarnqT1v0j2TDoQoo vaha0/F7wAJGmqXnDf6OGc3M4EMsYDnjOfQ2HqrpPMb9buqgnWarnsfG9y2ua1RxsDlQ U4bA== 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=bOwuRmPt+VP9rD3w0P9z/Uww6Cp2g3vlgSiPLX0DQvM=; fh=yrduuvKxh6GvS+iQYjBZDOWheBKyaXDXdhE1Ut05J3Q=; b=PG7wTg/jd7AkbP/n5CwBMdIMba/TChJVPq/yFNfAL02MhO+hWu4jVasLEdBZB6wCgO fYlGmAKZwZVAurdPlcXiDGkqdYk4xf2oMKpA1oXNxpXjqSGyb7lS5nNDCpXE7fghYsk/ X6e8p75Yg7mNsE2DIphtsOGwqvXjYFPhfv+sLmomLtML9WP5zxZJeBgcdOyXE9SDtSUU dr9WjEnQyfcAFKEzCYJKvUO351jwRjXYo232pn1Lk2ewLXifjHbV1jvSYaVt0YF15MQB i8xDmXBL0DUAl7IrQbDQO0s7yBCJIyZOE/MAuutaFxVqKEUDRufXytQSH+GlVsfMHl55 6ykQ==; 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=20230601; t=1772631466; x=1773236266; 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=bOwuRmPt+VP9rD3w0P9z/Uww6Cp2g3vlgSiPLX0DQvM=; b=iRU+rdx2GVUsSP06n/6KDNwjnC7m2tUL48ymyxtObq+b9wXSBCKFi3HJp9V9nMcNTN DcNVZUqV+mcZmIuQ1K/rQDxHEcTLCWUNpz2nz4BNBIlSXEj8jPStb91LadWfV0pgj9n/ UsRFYnpDWU+hgcTEE9htDzrmm4w4K6yOjs1g/uKYEfujfmit1QEighVc5SS1Y6nFVX8q 4a14xi4ffYbR25JImUoTU9onP0WUygczkNuAvITjF08DffC5oN/LK51Mea7mPrNxbHqF G5viAwq1M19gA2qaGAT/iMaSDUK3uRh/dCHsEsrxCN+4eVIVJw6ej7ERfTOUJDksn+rO UzZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772631466; x=1773236266; 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=bOwuRmPt+VP9rD3w0P9z/Uww6Cp2g3vlgSiPLX0DQvM=; b=WEbrLp56rsg+03tTdGXZgHH8bComvXMO4ymqYNsStYwgCeuEh4ExPk0txVuvEt5Wso +oZJYUhf+z1nvSWnahjir5AzHUEhr3pVCMgHmRbCAY5gI1S4nUOzKJupFDcTs0d1JuI3 47pl3YIdvdm+SurqIbJs3YuibRVpu3twGFXPBbedvCNss3gGKeE1XR5tbdRJJbLT6IY6 JN69A8gINN56jVB6m0oDBdgIZ3vNGNI5HamenASmoPj5MymDOlBPto0Raxr+z+f0TuwY jLNbsKXr7uVkstWpkWMOTrpFFLAZXNf4VJr2+VHdgsfp3u9VqA9x8yw4jnM4Jj1OzuR+ yrBw== X-Forwarded-Encrypted: i=1; AJvYcCX4kl42waNeScAd/msuZNvQVwUmukc0ofHpwCKplc2P4paC3tanlRx1MzRcKUbPaI9DPD9PcJJEi5mSrOJw@lists.postgresql.org X-Gm-Message-State: AOJu0YzcXI6Sjf/Zn/+HwYmIn7yNq/d6oox5rOHYZKVPii+PMD0ajqnw Sq4F2nNGq4050ch4X4N0pQ0ju4ZJBLXT33YKFLQRLWvRe32fc/hc+arJdIUiOqYIAJBAh071YJ9 QLhoFsHGi8QbUhJYlXqDmaW1jA63CUaw= X-Gm-Gg: ATEYQzxsy9QJlS9R9b2Jq+KiSZsnn+fkaDJvFwCBsG61ZErUyqr9USyQ9l60izVkg8S 411R8PzOvasPJA1SCkntKjt1JpEeaxBM1h4l2i67sLytxWuIMvt4ArbTFQG9rISv4WGk3wtPFDf aQkFSbUc31jyZnwtZ0DU7to030JkxjHbyd7Sa+p92wtl/7oLrlBC4JE9MF5x1VnuwnfVgRlqiTr m4Ytenm4mIlwM+wZMxHEcpz3bV5pQDrGF7nA64aSMAAHqlOSkjq5p1rgKs4ydnAq6SVombWOfqO 5zoleM/2Rn+C1TPGkqZFhTfuwPv1xUXTtS7u/6E= X-Received: by 2002:a17:907:1b28:b0:b87:17df:4d65 with SMTP id a640c23a62f3a-b93f1535dd8mr146724166b.51.1772631465305; Wed, 04 Mar 2026 05:37:45 -0800 (PST) MIME-Version: 1.0 References: <1136161.1769654478@sss.pgh.pa.us> In-Reply-To: From: Robert Haas Date: Wed, 4 Mar 2026 08:37:33 -0500 X-Gm-Features: AaiRm51H6jGpEbUCBxb0QIxJp40t4CqWwzo1SfF6YLV9nojbUwq6TVNnVw9rAOQ Message-ID: Subject: Re: pg_plan_advice (now with transparent SQL plan performance overrides - pg_stash_advice) To: "David G. Johnston" Cc: Jakub Wartak , Alexandra Wang , Richard Guo , Lukas Fittl , Tom Lane , Jacob Champion , Dian Fay , Matheus Alcantara , 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 On Tue, Mar 3, 2026 at 11:11=E2=80=AFPM David G. Johnston wrote: > Ok, that=E2=80=99s what I was missing here, it saw the subplan in its opt= ions but the winning plan didn=E2=80=99t include it. So =E2=80=9Cmatched/f= ailed=E2=80=9D may produce a plan where the target having been matched isn= =E2=80=99t actually visible to the user. > > Maybe add a note like this to pg_plan_advice: > > Generated advice is produced to a high level of specificity without knowi= ng what limitations the advice interpreter has in applying that advice. Th= erefore, generated advice targets may later fail for no other reason than c= ost-based decisions resulted in the originally chosen plan to no longer be = chosen. The planner will still likely see the original target on a now los= ing plan and thus the advice feedback will report matched even when the win= ning plan does not include the specific target. There is doubtless lots of room for improvement in the documentation, but this specific text doesn't seem like a good idea, because it's not true in general. The whole point of test_plan_advice is to ensure that generated advice targets *don't* fail, and with all the patches applied, I get a clean run where every single advice target generated by the main regression test suite can be successfully applied back to the plan that generated it. I think the real issue here is that Jakub has found a case where fiddling with the scan method causes the optimal aggregation method to change, and the resulting weird behavior stems from the fact that aggregation control is not supported. What you want to be able to do is nail down the aggregation behavior first, and then it would be clear whether to provide scan advice for t1 or for t1@minmax_1. But I just don't see what the big deal is here. One thing you can do is provide advice for both t1 and t1@minmax_1 and then the advice will be followed for whichever one appears in the final plan. The other will be marked as failed, but you can decide to just ignore that. Possibly you could even indirectly control whether the minmax path is selected by advising an inefficient strategy for the one you don't want to be be picked and a great strategy for the one you do want to be picked. Also, I've personally never run into a real-world case where the planner made a bad decision about whether to use a minmaxagg or a regular agg, which is why all of my development time and effort went into scans and joins and related topics where I do regularly see things go wrong. So at the risk of repeating myself: It is not in general true that you should expect your advice to randomly not work, but that happens in this case because aggregation control is not supported, which is a documented limitation. --=20 Robert Haas EDB: http://www.enterprisedb.com