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 1vhvQ7-00A4fg-1i for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jan 2026 20:00:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vhvQ5-00EVrk-2P for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jan 2026 20:00:14 +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 1vhvQ5-00EVrc-0q for pgsql-hackers@lists.postgresql.org; Mon, 19 Jan 2026 20:00:13 +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 1vhvQ2-001ITM-1l for pgsql-hackers@lists.postgresql.org; Mon, 19 Jan 2026 20:00:12 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b86f3e88d4dso835353166b.0 for ; Mon, 19 Jan 2026 12:00:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768852810; cv=none; d=google.com; s=arc-20240605; b=OM2LVbSYCiVZbamUHHeh0u4chqs8TayZsHjD7Cx/MAVa57U22vhUVbxMsENeXov9O7 DtLzWn/2FhTilPElJ3ITk5fDtlO7QnlwsuSPruZbBVKaSYqezfl7nmyGjLLkMPcndLWX mFRu5p22GWbZ1L1Wmgc5Cnse0CzzKmU5YTtvEC/4qSekCFbi8C7LJzBU898woEfoXyxB xvDhEYhiArVfLP8HCQ2SD+xRXcLoKOcDf0g+Az8oBVj7z/TGiM5X43LbiLrSjVUmkfP9 xjetr1LysRstDQe26P11I8HMIhPKY54EzVI9OAckxBLQ2ae7fcY/yWcrvwTwlHOT1HhQ bCDg== 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=g3tm+PQJHEUZ3cp4Uzbr7KskXCjtSNLVC6KzSfggQyY=; fh=8G3thHYy7bFnJAWODyTQ0BkNB4iAWinVOlU55xei11c=; b=aD1/EUccKm4HA9NQK+xKdFDxH8+5pcxLgKKy3OjlbajR/qG5A3Ub3yVgSFBGqExQ/O 7qdCQJfvH8RLhA4Q+Vz5XlQrFTT7P2V6UsxKRjx2sNsVYTrk54xEpzSYTWok2UXHcUZO 9y626ekx78AuVyaQ/c9HtuwDgw7CK67J+u3VrveLiUVCqZZsbx1HOi8fnxPuDTA0Sdh2 EYloVGNSbba4kwz5bpvTfsCOv6TtPohJg30JSD9MQuiCWT/uUiIGxuT5GYgmbyOCdBgW mkqDGjwXZXu6ZIcWAA1xXw3kjlYG8nM+LRcKQRAh3UeCXJfew0EKjg5QZqpxXuE2SUZ7 Dxwg==; 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=1768852810; x=1769457610; 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=g3tm+PQJHEUZ3cp4Uzbr7KskXCjtSNLVC6KzSfggQyY=; b=a3ow9EmnxwUDpAX/CItAcPSwsO+yB5u8XObvO4eaLgv2vrggk9voeZo0flULo750Cq uEa4wqjFbC5XlOwJB6yEH5N64GKs3HRbL1HUEev3VCUrMRjZ9LBNVHc6cFyCq3x4rgE5 54bGRdGrfsKwmLVcLb55JOZ0qwHhCdWDNK4mHMVf1RjFrF9iVoTTLhhsC/IB634WsMZS pIGWsg5sSdnVFxMCUABtQlOf/v7iSnMObFne1AUjCEKrQguerj3sfgbfwRJ3OZrPxGvH rshVtaKqy85PJk4n9coRJDouva+TK8ZopWZV1ThTH/dI+PRQV+ksvdkNN7v5lDkd3bZA 2Vlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768852810; x=1769457610; 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=g3tm+PQJHEUZ3cp4Uzbr7KskXCjtSNLVC6KzSfggQyY=; b=Yuq3r5PJGJ5Ej6/K12v1GTAtRvAX3aRyLg85Ist2txKiP5+BiUYzaLe/4fNim/MSEj BEmrbeXOWIVroL0BEeOQQf/rhHg8ymW3CijsZUFnFjMQT0DElAPGlzEkEEKFFz9EW1LY RkVOqpL7nVoZty0vHbHN9X2jYONzYDcEmmVPknHbu8FBdxemiYEfNBKD5R/JxMi+G7oe 6zHDmhjTQwMiwis4as1QtEGT0jnZkmCj0BxWphmspjPfLNgFV//qADQzMWlshdeZ5n1G bwosnXJjm9hcOR+4jhneUnJZEPXv2H2zLmnGaSxLQ/kiBlyJOpw8krfYIyOheXlreQx5 H/Hw== X-Forwarded-Encrypted: i=1; AJvYcCX6NNpvI18DOo+Oo9Hg4oXDtNRI3n+RecF77Evutga4foOgfz2sVBmXbWyuxHhfcn+2rB4dmSPQWSejMvUL@lists.postgresql.org X-Gm-Message-State: AOJu0YzxmNOf+/yNVglAEWkcAhOr5n4llXr/FCq8KUQgt4plauXc3lpK g5vep1AinYN9b3KYiHZscoqjzB6vQKQlllyLfOIYF+clX54eMfFoudTWXY1jWAYSVltOnvIv7QR +e8gYCTDfcEJpO6h6MItKLJXLNiob9/Q= X-Gm-Gg: AY/fxX7feB39xYyQpQks1YXagAQ76NpglgACwMgSAtnNY4yxEG1uiwxhFDbpUsPFFz0 NCawpJQM2MvwGTm886v+5BTWK4ODPNoPFEZzoUsnzBBS1UI7dj5Hes14st7oKD9+vf3vcBxz149 65Jf4Yn3yAp5y/IffzrzvaHAK1Vczt4EHzFSwZoPdQGqkOuATp7f+G2MQrKcfTJYMND9qoKZkDw vPi2AHsi00QUUcO2yREQWCCflEwQxFxDH2o1GtnucMXpLoRVJ6bk1G7L6nPXDFxqce29nj/gVe1 nr/KzZo2Pcl7jMhJNzWD5Pbdsv+6tfYKbsiVEg== X-Received: by 2002:a17:906:ee8a:b0:b73:6998:7bcd with SMTP id a640c23a62f3a-b8792d59933mr1116072166b.23.1768852809443; Mon, 19 Jan 2026 12:00:09 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Mon, 19 Jan 2026 14:59:57 -0500 X-Gm-Features: AZwV_QiWd5jTazFG9UJxc9tz8YmYahMG5lDkYOm41DdYtisW_MHZFETlZIXJYb4 Message-ID: Subject: Re: pg_plan_advice To: Jakub Wartak Cc: Lukas Fittl , 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 Mon, Jan 19, 2026 at 5:53=E2=80=AFAM Jakub Wartak wrote: > 2. I couldn't find any glaring issue during code review of v10-000[124]. = But I > have some questions: > a) v10-0001 - any example producing such a dummy subplan? (whatever > I've tried I > cannot come up with one) If you just add something like this, you can see lots of examples from the regression tests: /* When recursing =3D true, it's an unplanned or dummy subquery. *= / rtinfo->dummy =3D recursing; + if (rtinfo->dummy) + elog(WARNING, "hey look i'm a dummy"); Here's a stripped down example that doesn't require the regression database= : EXPLAIN SELECT * FROM random() UNION SELECT * FROM random() WHERE false; > b) v10-0001 - maybe we could add a comment nearby "dummy" struct > member to look > on pgpa_plan_walker() on example how to use it, but that's part of = v5 and > contrib... Maybe. I think people should know how to grep for stuff like that, and I don't want to introduce forward dependencies. > c) In v10-0004, maybe in pathnodes.h we could use typedef enum rather = than > list of #defines? (see attached) I personally hate that style and I think Andres loves it. Whee! > 3. Yes, I could too also repro Jacob's and get the same failure, so it's = real: > TRAP: failed Assert("child_target->ttype =3D=3D PGPA_TARGET_IDENTIFIER= "), > File: "../contrib/pg_plan_advice/pgpa_walker.c", Line: 679, PID: 32344 I have responded to that separately. > 4. Some raw perf numbers on non-assert builds (please ignore +/- 3% > jumps), it just hurts > in one scenario where oq2 drops like 9% of juice (quite expected, it's= not > an issue to be, just posting full results) > > tps oq1 oq2 oq3 oq4 > master 41 14745 439 435 > master+v10-000[1-4] 42 15055 439 432 > master+v10full 41 14734 429 437 > master+v10full+loaded 42 15014 442 438 > master+v10full+loaded+advice 41 13481 424 439 > > (same but in percentages) > %tps_to_master oq1 oq2 oq3 oq4 > master 100 100 100 100 > master+v10-000[1-4] 102 102 100 99 > master+v10full 100 100 98 100 > master+v10full+loaded 102 102 101 101 > master+v10full+loaded+advice 100 91 97 101 I think these numbers look pretty good. I mean, there is obviously room for improvement. We should look at where the CPU cycles are going in the oq2 case and try to optimize. But even without that, it's not terrible, IMHO. > So out of curiosity the oq2 on 1 CPU core behavior looks like below: > - no advices --> ~1000 TPS > - enabled pg_plan_advice.advice to lengthy, but unrelated thing and it > gets ~890TPS I'm not sure exactly where the CPU cycles are going here, but one known problem is that we have to re-parse the advice string for every query. This thread discusses the challenges of creating some infrastructure that would allow us to avoid that: http://postgr.es/m/f87504a6-9dfd-4467-89de-84232cb54f72@gmail.com Maybe I should start thinking about other ways to avoid that overhead, because that thread doesn't seem to be progressing much, but maybe the reparsing isn't even the main problem. > - in both cases (empty and set) the bottleneck seems to in palloc0, but > empty plan_advice: it's more like palloc0() <- newNode() <- > create_index_path() > <- build_index_paths() > with plan_advice set: palloc0() <- newNode() <- create_nestloop_path(= ) .. I've also seen some palloc-related issues with the patch -- it has to build some data structures and that does palloc stuff -- but there shouldn't really be any difference in the code paths you show here. That's just core code, which should be doing the same thing either way if the advice is not relevant. > - so if anything people should not put something there blindly, but just = SET > and RESET afterwards (unless we get pinning of SQL plan id to advices) = as > this might have cost in high-TPS scenarios. Yes, I think that's definitely a potential issue. I'd like the overhead of this module to be as low as possible, but it's bound to have at least some overhead, and people will have to decide whether it's worth it. -- Robert Haas EDB: http://www.enterprisedb.com