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 1viWkv-008qbA-0b for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jan 2026 11:52:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1viWku-006w0G-0A for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jan 2026 11:52:12 +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 1viWkt-006w06-20 for pgsql-hackers@lists.postgresql.org; Wed, 21 Jan 2026 11:52:12 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1viWkr-001aU7-07 for pgsql-hackers@lists.postgresql.org; Wed, 21 Jan 2026 11:52:10 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-34c30f0f12eso3612763a91.1 for ; Wed, 21 Jan 2026 03:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768996329; cv=none; d=google.com; s=arc-20240605; b=kjcE+A6oCl7OA33sipNM3bQV6xLq1UzjiHmdmvsyyITjQkGGh29btTwNuv8X3jOlLl EoEycya4TnBQvBxtLTEcafnMy2hO7MxKg64P/JYn31WwIdBhzbmGPLa8S4l4jaNeEiGX YA9+/9p/8vXUNConUKLJn1TfyDsHS209R1RFc44ulFyAG2rMpZJylfffbAtgLRgqMViU KLa0fKFDoFc6P55vaSlz6RGjJzrPBOyt/cuqkz7zjcEa9vmQwrrmtae4Rv3xbPrN+hgD VY0OXeTpaSbs5PUhtsomK3l1IWEw2U9JOtx7YljhJJ5OmhznRD6um8ToUUQBYX9ho9W7 6S/w== 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=CSux/eLd47pui1lT5ppdpIOkCq5gBa/jxLj65PAUpsI=; fh=QyFSGT0nqwLZV5U94S2XsHVYVkaIIS2gsR8HBRPbCpk=; b=OigfY08TV53eVz3V71NbabWfWKfVTMm0JJgwfwdBSolMo+3xeCwoXTszdp9SpKxiL4 W3HDRGTSjICNnJ1Hg9Qzy6nkLCI7tAnk32oOyEMNMFCcASYXsrrsvTdAtyrbqTE4cUxL En3fCLnRSyHLHPgoCouU6gl7Op71w4ZyDExQscOknrxUiHZTkW5gVb3e8RQdlB+HsEE8 uw4hcHrf5v34b+mpk390LwtV6YE8HKgbRWv+9RWdbJfEratErHziZXgn5dMGdpXTS5Ro gu0JbcL58QCiuJLOdkOOSFPLOChKeiCRz+1zkYtYQJxeqdCJjq8zGKaD70zIkVjdLy0g KfOA==; 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=1768996329; x=1769601129; 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=CSux/eLd47pui1lT5ppdpIOkCq5gBa/jxLj65PAUpsI=; b=gghnUCvzoQstZqsz1bAdix4//p1CvDXFdaIUVkLQFLvjV9w+gQUVy7j4KOwf+6vH0f Vcpnw8CfVTWICv0JPddr2Yofty5pMmc9SPBFYQJENLdo1lhqqOG7d7PQp7eu5iiqLXg7 NgNvBd65h4V2UOSZ0e5Ey8WnP7Jgn0trJ9fNlbu/kApPRU7Mt3MIe381kwEDv+QCaskR ZBdpRDNEHtGooXDQb5csFyAM4+C1Q6AJl9zJZgZStBeRwELQBnV+wziepktCa866SyPT soJd2BlRx1zk8P2WW4SHJA6UumWsJv/XhNVmJTnu4gWKujagw0id3yUpmqc2nXSErRUs N6Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768996329; x=1769601129; 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=CSux/eLd47pui1lT5ppdpIOkCq5gBa/jxLj65PAUpsI=; b=FsG1Thi5xePCR90J+H9dR8OLybNnvAm7gdrUeoifZRFtvnNFGsfcGfVaxF5U83O4PI JSGnCi/4/LgsrFug2iRsS3k60XkwhHDIxzum2bqyiBRHukOlJH6l5utCOeg1N3RH78XI RTFBdj1+SkKFnq2DvonHnZ0M83S65PDL/QLKeQGn3vrETPQjhDyIt0acGGc+jJY6ihoR zTmudlNkXSRWo8o9+CtO2hFxdAbIKG50HNIWud0RfkeohKZSnHsf5e9qRnhdliONVdRU q3Ewun7kGXWvwCHa3MMotXQQvIP77E3CN3kaKcBtTXP8KNBThLCOhPGXijaGHtDH0MKf 7mwA== X-Forwarded-Encrypted: i=1; AJvYcCWZVDs+fm4nJuP+GIbsg3m7/xrZeso1v+vdKbL5iV7tjGsp9ix2jJ8Ma5cAisAVgOWY7kvXxzbuP4MGSfbu@lists.postgresql.org X-Gm-Message-State: AOJu0YykmkowXgj/Hssy4QdLycTobzDAwE4pHy77SD7nLtfh8/0dOQa0 fjja864wogU/pssSnGx8T2FTQgwJa36q1AIk9RkLl0sS23nkAaYAo1RTiVG0ByXa4nUfgUgw0Wl W39a6aPpueSZm1acBmDww/7AKuXGsS58= X-Gm-Gg: AZuq6aKEUsCVWXxHOyKJu3VOn1wiRfg2xDD9nil3aFM+4s6cdM+2Ivs7uOBe7dj2PNO wjeL5D/wTU5CR8c6XxOdxww+KdIJN2lFuBMUvOG7/Ar/RKaZ+e7lqJ4RxfSFINMBsud7YOv73Op EbqKwS4p3LflrxCQ6WKoix5xesSr0EsgcRq45cUmHMIT1KBlj2A9otZ/XU+GiBhwzkQvXqxqqyW S+2pbBQ+YcZWgnqCrO8Er/FL/er83BLk0Vg3eHLoWcoJz4S9U/VW+AydwyUw73H/YQUrS2SryqG lnq+X1Xj X-Received: by 2002:a17:90b:2701:b0:341:8ad7:5f7a with SMTP id 98e67ed59e1d1-352c4009bbfmr4161558a91.18.1768996328484; Wed, 21 Jan 2026 03:52:08 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ajay Pal Date: Wed, 21 Jan 2026 17:21:57 +0530 X-Gm-Features: AZwV_QiBexemcLWoWX11OV__ReD05yKNzkVfMk_9OIxkIXZGNxqg7RFWekPKZYw Message-ID: Subject: Re: pg_plan_advice To: Jakub Wartak Cc: Robert Haas , 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 Subsequent testing revealed that UNION operations involving constants which enforce empty subplans result in the generated partition-wise plan not being recognized by the planner. Below is the query and output for more details. CREATE TABLE a_test (id int, category text) PARTITION BY LIST (category); CREATE TABLE a_active PARTITION OF a_test FOR VALUES IN ('active'); CREATE TABLE a_retired PARTITION OF a_test FOR VALUES IN ('retired'); postgres=3D# set pg_plan_advice.advice=3D'PARTITIONWISE(unnamed_subquery)'; SET postgres=3D# EXPLAIN (PLAN_ADVICE) SELECT * FROM a_active WHERE id =3D 1 UNION ALL SELECT * FROM a_active WHERE id =3D 2 AND 1=3D0; -- Constant false forces QUERY PLAN ---------------------------------------------------------- Seq Scan on a_active (cost=3D0.00..25.88 rows=3D6 width=3D36) Filter: (id =3D 1) Supplied Plan Advice: PARTITIONWISE(unnamed_subquery) /* not matched */ Generated Plan Advice: SEQ_SCAN(a_active@unnamed_subquery) PARTITIONWISE(unnamed_subquery) NO_GATHER(a_active@unnamed_subquery) (8 rows) Thanks Ajay On Tue, Jan 20, 2026 at 2:50=E2=80=AFPM Jakub Wartak wrote: > > On Mon, Jan 19, 2026 at 9:00=E2=80=AFPM Robert Haas wrote: > > > > On Mon, Jan 19, 2026 at 5:53=E2=80=AFAM Jakub Wartak > > wrote: > > > a) v10-0001 - any example producing such a dummy subplan? (whateve= r > > > I've tried I cannot come up with one) > [..] > > EXPLAIN SELECT * FROM random() UNION SELECT * FROM random() WHERE false= ; > > Oh well, that was easy, thanks! Now I see `RTI 3 (function, > in-from-clause): / Subplan: setop_2 (dummy)` > > I don't have any further insights on v10-[124] other than mentioned earli= er. > > > > c) In v10-0004, maybe in pathnodes.h we could use typedef enum rat= her than > > > list of #defines? (see attached) > > > > I personally hate that style and I think Andres loves it. Whee! > > Oh, ok, nvm, but while two of You we are at this, vim or emacs ? ;) > /me ducks & covers > > > > 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 i= t > > > 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, > > Meh... > > > 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, b= ut > > > empty plan_advice: it's more like palloc0() <- newNode() <- > > > create_index_path() > > > <- build_index_paths() > > > with plan_advice set: palloc0() <- newNode() <- create_nestloop_p= ath() .. > > > > 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. > > Yeah, in both it looks like memory allocation and lots of newNode() > called , quite expected. > > > > - so if anything people should not put something there blindly, but j= ust SET > > > and RESET afterwards (unless we get pinning of SQL plan id to advic= es) 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. > > I think we should simply ignore, and maybe later just note the fact this = is > not free with a single sentence in some docs for 0005. I was just curious= of the > impact and this was measured using pure EXPLAIN (so without query executi= on to > measure impact of non-empty pg_plan_advice), I'm assuming that in > properly managed > systems execution part will always dominate the workload anyway and > one should be > using prepared statements anyway. > > -J. > >