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 1vxd2F-00GzGV-3C for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 03:36:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxd2D-009xJR-0K for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 03:36:29 +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 1vxd2C-009xJB-1e for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 03:36:29 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vxd2A-00000000J30-3sB8 for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 03:36:28 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-b8f8d80faebso1118728166b.1 for ; Tue, 03 Mar 2026 19:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772595385; cv=none; d=google.com; s=arc-20240605; b=V7kzWuLmd2eUcV+mrTAddlTtb9NL1dEKUXqoA2+TTtWpcWa/hMVsc8i1WzAvS55HaR I0LXzdEHmJfNloRpolReAnqdvruLDcyq6SyFdUtb4BVz2DQm2+lVHJKUCcH6DQFfmAGu PR97xY0Ur3JyxMf7nTcDNbxrbb0o1TLKMHcigjyHNXpLgPc1EKLRSTtJsr4+a4GpSmUV 0HkeNz2d29oFjj7v8DJXUAiEZinMQjZ/34vz7/Hi1VwQSkpCvlWtDlodZdRXJQ5LHjCF jHvYGDXbWTmnd5CrVhsooPVc9kmsMW/bJi2q1BVzepHpotXrn3sLUFok2lMn5BoNeSfs fUNg== 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=mHHfTixpoLRfjMgIrcBmiqf2BrL38o4spXkoSqfm7S8=; fh=EUd+2+OeBr7OaKJ+wsh2RCsQ+W2OJN/OYWenNgOjg3w=; b=CzyR3d2QJCaVstqJfklwx1GPzr5EDCXGagtLp4Zg1pbMJ3PfP0Zj0OFfu7sevdTIld SOdb38U6cwEHcsxed0+syH96yM3OSxUar/uAw9nDsV+XeImWtmAolugMDxWaGaf0g+4B ekq9W15QsMHu43cpt4wMDx+RJToO1ySlLjXpEBP9z0Kt2Zyf0Wy56po+TZymDnxq9Nmm im9aSNXsP5JfFvK1f7GhWHAYXaGroPNOkaXo0N23LV4n97IsYV0SNVjnMttifNk9meuT zRlMb/G4LBnbprjNOot6Uf837L592lVNvHd5UpsxmIXcwiXUo5y6bdtDQ56xf+CZ5Nrh CGdA==; 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=1772595385; x=1773200185; 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=mHHfTixpoLRfjMgIrcBmiqf2BrL38o4spXkoSqfm7S8=; b=WuGf4tennjmG17ZRya54Jqj1mLZRnUue7NyL9s+3Vg84Pc0qlpKVP1wb+k1DNpbwVn lwnJm0fFW0gC/74O+/B/PP4at8j2XcwaJKP6rf1wMayho4nGNsnMjdkdcGS2oby95fi8 H0Do7AnyJQDn/m7QpxlVGB2YDJ2vmzMptpjSxLiVQ6dmwWdq5bPlNUPR2PcwCaRoVGUd 23n0kW8iMgwJV1GMTovpWHSbGit6+P2nfpTmFMFC+Hx8+UxQmX2oBws1dJdo5RKGsV+R rhq3gyQ+/1U7UcIbG5Iqu0GiMPpr4IpefRjxI4m581mRU8SS7AiIBuof2XULQ5urvmhJ rChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772595385; x=1773200185; 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=mHHfTixpoLRfjMgIrcBmiqf2BrL38o4spXkoSqfm7S8=; b=YsRsQXDT7c17fPL16snQXzMZ2wkTX6sw1oe1PsFRNrhs4rk+7JIT0u3+lxcd2edO7s o2WhOKtB8i+3jc+uukc69zDLCjzwIXrE+KZBSxpvYc/nMbtRuAMVNPlSZtVERW4K40Zd rFiDY5f6Zwj4MEzCDkESp+uXevdJjvxAqDhlqM7f1SM/Tq6LvsoLkovyJjk+0vFpSLmB iDkOlBDnssRuriwm+Nxd7YzBHECrSvu6YTxj3QxLX2UhaMQ1cl8TlOfavDJhrgwUpSvx 9Mrweq7NPaWHwSJU3oCT0vQZRinnN61hHJ+Gxlo+2xr143nDkYg7XBisOf+e9jSSZp/z U5sA== X-Forwarded-Encrypted: i=1; AJvYcCU/d3OvxbQa+oLxUngvsW52gfJiMWx1LAibIQJJ1qSB0xgxPBTWzCYjlLtU1SsKeFDtOi7xqxTxeCSf0NNm@lists.postgresql.org X-Gm-Message-State: AOJu0YxRj6U01VEqoYbg9do9plEh7Fl1W+fZZ7OHpRXlkG+ZR1tfr+cB I52qo1+qyP1H54ASpMcOnPw8xgtjp8J5QMam6Dh4dctvaasdN1I7AAV4QUvVwKZfrnHkOJdtvaD knhJhD5pGVjj0+Ula9vwd+eUlmn5+NQk= X-Gm-Gg: ATEYQzxatu/Jp4WIyHBYcp9ZlLgrZAkf6UCb+neV7VapTEXbmffB/AYDdSi8R5Ul4w3 +o/0bAkX8TbVO5/nioaB2yVy5QQKmbXnwLfufHap8jLhVO3emK5i4oGoMcEqBMpwuZMFqdXy03B 5qGKAEerZmbASC8TDE54k1TSL4abb1B13TTekuhcOE+e0pvYUS2M50c5L9zlV76Mm4tbQuvEyq7 Ig3PQEwkmEADEWlA2S97WQU6UmBRuPFnlJlA2z+h8GEIoT91y/sqiDePX0JflZbzS+1nWWtxYhc nSvIH1hTcgprOA2eeZj1uTqS6VWh6FUnVxDIlrM= X-Received: by 2002:a17:907:96a6:b0:b88:58e5:86ff with SMTP id a640c23a62f3a-b93eeee7984mr39615066b.0.1772595385144; Tue, 03 Mar 2026 19:36:25 -0800 (PST) MIME-Version: 1.0 References: <1136161.1769654478@sss.pgh.pa.us> In-Reply-To: From: Robert Haas Date: Tue, 3 Mar 2026 22:36:13 -0500 X-Gm-Features: AaiRm517sO4Vjn7N762qQ3kj6WVQyhd2JqcMyjoqNlmoVlYdLfxsYg1xlDeynng 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 2:28=E2=80=AFPM David G. Johnston wrote: > I mostly get why specifying an index that doesn't exist as part of advice= , alongside a target relation, produces "matched" along with "inapplicable"= and "failed". > > INDEX_SCAN(f no_such_index) /* matched, inapplicable, failed */ > > But less understandable is why a failure to match a subplan-qualified tar= get produces "matched" when the subplan doesn't appear. > > SEQ_SCAN(t1@minmax_1) /* matched, failed */ Because there's not a way to control aggregation behavior at present, you can't directly conrol whether t1 or t1@minmax_1 appears in the winning plan. This case is "matched" because we saw t1@minmax_1 get planned, but it's "failed" because the non-minmax strategy then won on cost. Aside: This is actually an instance of a very common problem into which I have already invested an enormous amount of time and energy. Suppose that for some operation X (which might be a scan or a join or any other kind of thing) you tell the planner that you want it to use strategy S. If strategy S is not what was going to be chosen anyway, you've just increased the cost of X. Unsurprisingly, the planner's response to that is very often to choose not to perform X at all. Otherwise, it ends up looking like the planner has just made an end-run around the advice. For example, HASH_JOIN(X) says "put X on the inner side of a hash join". Obviously, this means that when we see a join with X as the inner rel, we should disallow all join strategies other than hash join. Less obviously, it also means that when we see a join with X as the outer rel, we shouldn't allow *any* join strategies. If you don't do that, you get a problem very similar to what you're complaining about here. The difference is that join control is supported by the patch set, and so I have put in the work to avoid instances of this problem that occur in that case, and aggregate control is not, so I haven't. > Maybe we need to do something like: > > relname - matches anywhere in the plan tree > relname@somewhere - only looks at "somewhere" for matches; absence of som= ewhere results in "not matched" (the expected feedback for the advice/query= combination above). This would not work in general; "anywhere in the plan tree" is too broad a scope, and it would be easy to construct an example where it falsely matches an unrelated part of the query. I think that the solution here probably looks more like letting the user write AGGREGATE_PLAIN(something) or AGGREGATE_MINMAX(something), but to make it really work, we would need to figure out what the "something" should be, and also remember to account for partitionwise aggregation, eager aggregation, partial aggregation, hashed aggregation, sorted aggregation, plain aggregation, and mixed aggregation, some of which can be combined with some of the others but not all of the others, and then we would need to add design and implement hooks in core to allow that advice to be enforced, and then we would need to get pg_plan_advice to properly accept the syntax and enforce it and also be able to generate the syntax from a finished plan tree, and then document all that and add tests. I think that work is worth doing, but, again, I think it would be a much better idea to spend the next few weeks trying to figure out whether it makes sense to commit what I've got, and perform any necessarily stabilization of that functionality, than to keep saying "hey, maybe you should radically expand the scope." It's probably a six-month project to get all that working, and we don't have that time for v19. > If keeping the status quo the existing behavior should be documented. The= existing wording for not matched; "or it may occur if the relevant portion= of the query was not planned," seems to be the one that covers this case. That's definitely relevant here, although these specific examples seem to have more to do with "failed" than "not matched". --=20 Robert Haas EDB: http://www.enterprisedb.com