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.94.2) (envelope-from ) id 1vFxGF-004HSu-6X for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 16:18:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFxGE-005f3h-1k for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 16:18:25 +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.94.2) (envelope-from ) id 1vFxGD-005f1p-Ni for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 16:18:24 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vFxGA-005F2C-1x for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 16:18:23 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b70fb7b531cso166187166b.2 for ; Mon, 03 Nov 2025 08:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762186701; x=1762791501; 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=iimye/GX1nn3uLDYXwORQpf1V+ixGaViL/eaPyG+Kvo=; b=c8heiQgHNgi83YkQz+uzcevhvy9TXnhXJblii3HoTDYmWuW3ey6sBuQrUPS5eWHclC AvzSpMI7x0wS3/Xu7V/SmCbHUzyKvX+k/HXEJMicbCYFS61QwxGVTfIrR5WITfYcPdGy EvXC2DiJfu93yV23DMA97VgXZ19eeeoG7aqXuEyv1wsGKDtzzwS2XBN1V+QTHy3XOWh+ Wf12R9WfFISQaAePyjlSYoMtkPthWnLYdyVI0vGB87FoLLwYFJvi07rsj+19cENvWrEj eoYt5nL7I1nhEp3elQwYnNbgbDZIk6xazi0oM31SSx/wnC4eHcFWSdIhUVQN9JoIRFJp 8kvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762186701; x=1762791501; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iimye/GX1nn3uLDYXwORQpf1V+ixGaViL/eaPyG+Kvo=; b=WYGITty9I6cTVOKUU5zhhIDdRhnpDfQ+ufgYTEosscJBda+7KcPC6q+srmQn4ikewP +GOTCIwHcK5D15aNQdzyMs0GxpkKCq62H1LhkscMewqt18wrtvI3UAo1pOwpQkJy7I/V ZqXIMZs5MhUWeEBofdM5EEh+AVfO4hlvGrSyS6QFhqZp0YGlmeOJCAR5RpoMWSqhQbHI JWTmi0OgBPdJe5hV2FkOQ3Q00FfIlTeX9uN4nNhZF3LnvguFVtKbMlhM8CXvtZsFLAGn 5ho7EhoB8CfaRvkWwpJZxH0ABoIOxI0l1rhmPn2DWBnUDhpoObvBA5lz7BmhU6vCQKwM 4yJA== X-Forwarded-Encrypted: i=1; AJvYcCUOvneaIQs//MJc+4QDDQKAFsfEtIsQHGypucbNRIKGUBUukTkwPkw33LrorqZvoGH6WWRJGz5/M6gdi4nh@lists.postgresql.org X-Gm-Message-State: AOJu0YyhjF+qPh8rxiG9V0H0wdfCSMfnOMEcyNmWicUrYB0aBnrTGO+c AA2SPV7/RUwT4HiBCJtHQzSJQ5MRaZC7tjvPK1p33m6Uo5OUAR4q/jJyrpqUVgRm1tuP7wSCBM1 AhogZnI5ZXLVhTbZK/CyFnszE4GtEbOQ= X-Gm-Gg: ASbGncsGnHCeG9lTbNgHpBiffwxWvihbaaZV8h06RzwdlPy8XZXnwxn1OV/64ogXBBy eY1HHA35PGPKe+r6UxD+JvnM7Jak11poLJphyAi273nVThNumaOUTYVv9w6rUqKic9liQTXgso4 LocoN8Fh3aGSROr+FQj2OVpHmc18ftAj2gmVq5hVS3kAlhnhL3ND8A9FAK26vP/xYuQttN9Te6n fWkoxZIIvjAxKYGtTGAQmjHDgGne2ek3I23e1KfhbDqP78xQOajTxi+U9Er7g== X-Google-Smtp-Source: AGHT+IHG9EAlAfLJBh1whyexZCb5Qlh10BimH7VOSy9TEqwo/LoqktBZxho4GbeipZ8RLTc6QFFGL7zcS6AyDhNAkCM= X-Received: by 2002:a17:907:7210:b0:aff:c306:de51 with SMTP id a640c23a62f3a-b70700d1e3bmr1442027066b.4.1762186700525; Mon, 03 Nov 2025 08:18:20 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Mon, 3 Nov 2025 11:18:08 -0500 X-Gm-Features: AWmQ_bmMcgZsg6JdBOr5vxo1TRsCziNNMHwsMBEiwNwH95ekfcXpGf-kmzmT3wI Message-ID: Subject: Re: pg_plan_advice To: Alastair Turner Cc: Jakub Wartak , 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 Fri, Oct 31, 2025 at 5:17=E2=80=AFPM Alastair Turner wrote: > I really like the functionality of the current patch as well, even though= I am suspicious of user control over the planner. By giving concise, preci= se control over a plan, this allows people who believe they can out-plan th= e planner to test their alternative, and possibly fail. Indeed. The downside of letting people control anything is that they may leverage that control to do something bad. However, I think it is unlikely that very many people would prefer to write an entire query plan by hand. If you wanted to do that, why would you being using PostgreSQL in the first place? Furthermore, if somebody does try to do that, I expect that they will find it frustrating and difficult: the planner considers a large number of options even for simple queries and an absolutely vast number of options for more difficult queries, and a human being trying possibilities one by one is only ever going to consider a tiny fraction of those possibilities. The ideal possibility often won't be in that small subset of the search space, and the user will be wasting their time. If that were the design goal of this feature, I don't think it would be worth having. But it isn't. As I say in the README, what I consider the principal use case is reproducing plans that you know to have worked well in the past. Sometimes, the planner is correct for a while and then it's wrong later. We don't need to accept the proposition that users can out-plan the planner. We only need to accept that they can tell good plans from bad plans better than the planner. That is a low bar to clear. The planner never finds out what happens when the plans that it generates are actually executed, but users do. If they are sufficiently experienced, they can make reasonable judgements about whether the plan they're currently getting is one they'd like to continue getting. Of course, they may make wrong judgements even then, because they lack knowledge or experience or just make a mistake, but it's not a farcically unreasonable thing to do. I've basically never wanted to write my own query plan from scratch, but I've certainly looked at many plans over the years and judged them to be great, or terrible, or good for now but risky in the long-term; and I'm probably not the only human being on the planet capable of making such judgements with some degree of competence. > Whatever other UIs and integrations you build as you develop this towards= you goal, please keep what's currently there user accessible. Not only for= testing code, but also for testing users' belief that they know better. And this is also a good point. Knowledgeable and experienced users can look at a plan that the planner generated, feel like it's bad, and wonder why the planner picked it. You can try to figure that out by, for example, setting enable_SOMETHING =3D false and re-running EXPLAIN, but since there aren't that many such knobs relevant to any given query, and since changing any of those knobs can affect large swathes of the query and not just the part you're trying to understand better, it can actually be really difficult to understand why the planner thought that something was the best option. Sometimes you can't even tell whether the planner thinks that the plan you expected to be chosen is *impossible* or just *more expensive*, which is always one of the things that I'm keen to find out when something weird is happening. This can make answering that question a great deal easier. If some important index is not getting used, you can say "no, really, I want to see what happens with this query when you plan it with that index" -- and then it either gives you a plan that does use that index, and you can see how much more expensive it is and why, or it still doesn't give you a plan using that index, and you know that the index is inapplicable to the query or unusable in general for some reason. You don't necessarily have it as a goal to coerce the planner in production; your goal may very well be to find out why your belief that you know better is incorrect. --=20 Robert Haas EDB: http://www.enterprisedb.com