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 1vEobi-00177K-0q for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2025 12:51:53 +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 1vEobf-00EbIm-P8 for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2025 12:51:50 +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.94.2) (envelope-from ) id 1vEobf-00EbIe-Fe for pgsql-hackers@lists.postgresql.org; Fri, 31 Oct 2025 12:51:50 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vEobc-005FVt-0A for pgsql-hackers@lists.postgresql.org; Fri, 31 Oct 2025 12:51:50 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-b6d2f5c0e8eso476504066b.3 for ; Fri, 31 Oct 2025 05:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761915107; x=1762519907; 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=jZAsE7W6jQo/KJWLJi86mrCEQuA9mUBOAbzQsI6zFTo=; b=PJ/r5XT/+JlfH0g4MUpXm6+JWjqg+I7ExIAOaYhQxEJg0A2UYS0MpuaiVmSWUJ9Cbe imHiylETqvG5J6Qc3uL6tgKAo3YSU7cFm8N1g3AifcOXbWx+5fmEc6iT7L0gWRdC4wL8 bbkMrNyErfBXWd5w43QgYt272XgZm6QCGAIrN9Wz45cuZKY6X7TjS9/Qt7KHW4n12zaa BA/qRZKTypTgxW06guzQGnWUYAEmAymmQ4aKGPIGKFrGhTV+V3lSjwYQX4l2A+7Rx9JZ GnAnd2Va+OkQibwQ7hR7t/KO5BgaODGkSI8ezfhIPCaiPnr/NI4wy3lYeEO420PxBzQg RftQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761915107; x=1762519907; 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=jZAsE7W6jQo/KJWLJi86mrCEQuA9mUBOAbzQsI6zFTo=; b=Iuh6Tc7w9QKooLGgCRQh+Ndume9F2Wd+J1i9Z43GYbSjIvSm/4yiv8MT0YADjvWd4w KAliGfgW9yn58pt6z9fYAdHit0RtznevBcJmiOaa4S3klzntEE66jmkRRX/lU+gfKmDg bAEik0IXQkOFqevHNcgRbifldtGlZbgnAMb6MuTRvpyqk3LU2AMnlUt05pP2n7pZDf60 KtIhZnFDJnA0ItXNkiAPzDQUARiiCTIcU4lP6WPB8c7APWe8Vn9JfLLyMdqX9TJVCCyZ cWefZaVUOlvkna5Gp+hVQcHgurRFF3cfxfCSkze0MAOFyJkXFsrK/5cDExYUbtkreZmw 2vrw== X-Gm-Message-State: AOJu0Yy59NGoEnBJNw5wNmza7Kc7whCdT2uc8KpgzL3pnTt9LlpKrZmy f1Su4K2ShuPPLMqhNoWJSz/3CwATsTeudPRUlYqwqVHfJvH0hKngYetH/8hs/YAS+aK+zJMhuA7 YrLMKITnrl3oW6ubk19glCFg7xA1JCCc= X-Gm-Gg: ASbGncvVjRwS69iTJhFMeB52CS37OrshBcJQN27kvv0gceYH0DXY9A10dsub+0XFdpG rjUAbNJ5d1UhaajggwLy57EGozIPn1RKDiBr50Jbe223vAaoY3GWahxh6B9DUb3rEDvBTGGtMAP 8gRNThFfCaULzd9bTxEJkVpPVgwTcJAfNC1jTGBnB7k4barYyobgxNWEM7viZwsLyK+Fk9clXrO 38l8PhrxQ5mSc/7tO1i2M02zwE9HQxbhuTBbdkKzZO4N66rIb7vH+80wGaD X-Google-Smtp-Source: AGHT+IHxQflSuyw7kWqrRawBWCkMHWpYiec7C+fr/IFkU3rgpjZItpd2TG8adQgyuAU6RgAnF5ZVE8c+oSZ3C7ZmL/k= X-Received: by 2002:a17:907:1c0c:b0:b43:b7ec:b8a1 with SMTP id a640c23a62f3a-b707019eb52mr374866166b.24.1761915106594; Fri, 31 Oct 2025 05:51:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Fri, 31 Oct 2025 08:51:34 -0400 X-Gm-Features: AWmQ_bnzorjABO6O0wvVNRI2P-lZ758XKOCejYszcxAwuE50XWWNQQ8rhSwIeY4 Message-ID: Subject: Re: pg_plan_advice To: Jakub Wartak Cc: 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:59=E2=80=AFAM Jakub Wartak wrote: > > First, any form of user control over the planner tends to be a lightnin= g rod for criticism around here. > > I do not know where this is coming from, but everybody I've talked to > was saying this is needed to handle real enterprise databases and > applications. I just really love it, how one could precisely adjust > the plan with this even with the presence of heavy aliasing: Thanks for the kind words. I'll respond to the points about compiler warnings later. > To attract a little attention to the $thread, the only bigger design > (usability) question that keeps ringing in my head is how we are going > to bind it to specific queries without even issuing any SETs(or ALTER > USER) in the far future in the grand scheme of things. The discussed > query id (hash), full query text comparison, maybe even strstr(query , > "partial hit") or regex all seem to be kind too limited in terms of > what crazy ORMs can come up with (each query will be potentially > slightly different, but if optimizer reference points are stable that > should nail it good enough, but just enabling it for the very specific > set of queries and not the others [with same aliases] is some major > challenge). Yeah, I haven't really dealt with this problem yet. > Due to this, at some point I was even thinking about some hashes for > every plan node (including hashes of subplans), [...] > > and then having a way to use `somehashval3` (let's say it's SHA1) as a > way to activate the necessary advice. Something like having a way to This doesn't make sense to me, because it seems circular. We can't use anything in the plan to choose which advice string to use, because the purpose of the advice string is to influence the choice of plan. In other words, our choice of what advice string to use has to be based on the properties of the query, not the plan. We can implement anything we want to do in terms of exactly how that works: we can use the query ID, or the query text, or the query node tree. Hypothetically, we could call out to a user-defined function and pass the query text or the query node tree as an argument and let it do whatever it wants to decide on an advice string. The practical problem here is computational cost -- any computation that gets performed for every single query is going to have to be pretty cheap to avoid creating a performance problem. That's why I thought matching on query ID or exact matching on query text would likely be the most practical approaches, aside from the obvious alternative of setting and resetting pg_plan_advice.advice manually. But I haven't really explored this area too much yet, because I need to get all the basics working first. --=20 Robert Haas EDB: http://www.enterprisedb.com