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 1vTIbs-00GNzy-0t for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Dec 2025 11:43:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vTIbq-00B281-2q for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Dec 2025 11:43:55 +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 1vTIbq-00B27s-1p for pgsql-hackers@lists.postgresql.org; Wed, 10 Dec 2025 11:43:54 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vTIbo-0047lM-1X for pgsql-hackers@lists.postgresql.org; Wed, 10 Dec 2025 11:43:53 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-59581e32163so8414134e87.1 for ; Wed, 10 Dec 2025 03:43:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1765367030; x=1765971830; 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=8LjYRl75ZHnR1muTrDzdkGDcMnOIfswvLjifzFPupRw=; b=EFzWH3EYXWLqxV81IFp3nqUlxENmIeaU1AwXvrbldOsSe4KrvMxHaHBxSFdQwS2Q2v hyboUSQO7ca2HZ9nPsmK3fHA30q4wdorqrg3BNa5wurhEVt27w/H9EIjbncLtbI3VHV7 MdLrdvO9LwoRoOtD+SUFH/BMtuGsdBd1oo2RYwZrt6mBVNncKspUm7wJSlXOCQKZs3XT TueHLkJgfooBMmsFGE1MxSTPg9HM4ags+69EgO+o9h6cZeRteEnoX7S+LTWe4CnzNOZR BtO0QBBhTmRqK2umWVWBupsLtaGrPMYpkEPk1LlAM1BL9euNuTvDAwU4wdnk5VWrav53 khzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765367030; x=1765971830; 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=8LjYRl75ZHnR1muTrDzdkGDcMnOIfswvLjifzFPupRw=; b=AgtzT0EpC1ReHKE9DBJBGg/CK2NYEOwW2uP1ujYXIX32d5q3NiI2a4qgjkO4GvaDYR mWqe5azwd/bAM3tBjGuAcKurPoIXhqEkUJgNDo7kV4/jYzldt4acYS5azIPuNZKHOejl omkfoGLjhcKYO7auowugGOG9WuH+NyZq+8Z9Ey/txQmH513B8+kqi5Sb2N5CY+EikZIs rvLTB7q6zm0RC0EiiCcQ7xMlQJ+MFl+Av27ckrqDcezWdbJ7bZXKJMpsfPvEaesyktjH 7XR2O6CfrgbECcfcxFnSGb6J/+xC2UwC4QrHUAGp4J8R4ikaEr41dT1zjwRBaY2+WOoK Dp4A== X-Forwarded-Encrypted: i=1; AJvYcCV3/CIKmF92mX7hPflu4JLghUQwBOfAgwDtexOTzgVFKMEPbxH3cSMHTMrlQd0xZB675EKSLEw230ooN1gO@lists.postgresql.org X-Gm-Message-State: AOJu0Yw7kg1DZuag6sXMmDPtCAh0iYK9UZgzkvWXj/U+CfS5+FUXwtRz FMKDilOzW2Ml96ooVsDe6UoyIwiysAOnw4MN9NMOhBucbZPoveYDXooLcwpr03dOdTyyXKpb5hd 4cjmrcYE25J0hvMr3BOKnT74j1nsjFKp2+1NZ3iu+ X-Gm-Gg: AY/fxX6gfxOiJHXvYXmWcAQvAaN0mrYCvg1PyPbPnkuEJ752KYzIdYXkH4aaZMz5AO5 9TCda8tSpWrXEU2D+my+L5gOjiAlEqqWN77d/+zRbTIVdDwLbhOGLcs4A9RTg3j/a9sFuslMGKA YjgB0bRUAkGsQbAs4uTdmglvwRZNLhnHhQ7zEYvuJYdM7jv+0E92rbExRMgejzmFkyJ4ilYLsDz zVs97h0OSTQBct0fPEnT3afdPJAlxBhlhlbD13YBvEDkGE++d5SsFCBNB7Pw/Txkuadf4A= X-Google-Smtp-Source: AGHT+IH3CSe4I1R9zkijCInMx25Olk8bMsgY6pUqQcVJF6WopO8DCLULNowEkhwR8NHKr7nkrqo0L9Iqsc0PheXGkks= X-Received: by 2002:a05:6512:b8b:b0:597:cf1d:bc77 with SMTP id 2adb3069b0e04-598ee5278c2mr833603e87.29.1765367030477; Wed, 10 Dec 2025 03:43:50 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jakub Wartak Date: Wed, 10 Dec 2025 12:43:39 +0100 X-Gm-Features: AQt7F2pqa242NwKcovL8bCuAEPh9Ya3uxFbJ_KOMhXZnkxOdDb2uq5tb0DV3jy8 Message-ID: Subject: Re: pg_plan_advice To: Robert Haas Cc: 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 Fri, Dec 5, 2025 at 8:57=E2=80=AFPM Robert Haas = wrote: [..] > 014f9a831a320666bf2195949f41710f970c54ad removes the need for what was > previously 0004, so here is a new patch series with that dropped, to > avoid confusing cfbot or human reviewers. Quick-question regarding cross-interactions of the extensions: would it be possible for auto_explain to have something like auto_explain.log_custom_options=3D'PLAN_ADVICES' so that it could be dumping the advice of the queries involved . I can see there is ApplyExtensionExplainOption() and that would have to probably be used by auto_explain(?) Or is there any other better way or perhaps it somehow is against some design or it's just outside of initial scope? This would solve two problems: a) sometimes explaining manually (psql) is simply not realistic as it is being run by app only b) auto_explain could log nested queries and could print plan advices along the way, which can be very painful process otherwise (reverse-engineering how the optimizer would name things in more complex queries run from inside PLPGSQL functions) BTW, some feedback: the plan advices (plan fixing) seems to work fine for nested queries inside PLPGSQL, and also I've discovered (?) that one can do even today with patchset the following: alter function blah(bigint) set pg_plan_advice.advice =3D 'NESTED_LOOP_MATERIALIZE(b)'; which seems to be pretty cool, because it allows more targeted fixes without even having capability of fixing plans for specific query_id (as discussed earlier). For the generation part, the only remaining thing is how it integrates with partitions (especially the ones being dynamically created/dropped over time). Right now one needs to keep the advice(s) in sync after altering the partitions, but it could be expected that some form of regexp/partition-templating would be built into pg_plan_advices instead. Anyway, I think this one should go into documentation just as known-limitations for now. While scratching my head on how to prove that this is not crashing I've also checked below ones (TLDR all ok): 1. PG_TEST_INITDB_EXTRA_OPTS=3D"-c shared_preload_libraries=3D'pg_plan_advice'" meson test # It was clean 2. PG_TEST_INITDB_EXTRA_OPTS=3D"-c shared_preload_libraries=3D'pg_plan_advice'" PGOPTIONS=3D"-c pg_plan_advice.advice=3DNESTED_LOOP_MATERIALIZE(certainlynotused)" meson test # This had several failures, but all is OK: it's just some of them had to additional (expected) text inside regression.diffs: NESTED_LOOP_MATERIALIZE(certainlynotused) /* not matched */ 3. PG_TEST_INITDB_EXTRA_OPTS=3D"-c shared_preload_libraries=3D'pg_plan_advice' -c pg_plan_advice.shared_collection_limit=3D42" meson test # It was clean too -J.