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 1w7KUw-005BrR-1B for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 21:50:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7KUu-006fHJ-2a for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 21:50:13 +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.96) (envelope-from ) id 1w7KUu-006fH9-1h for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 21:50:12 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7KUs-000000024AC-0aas for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 21:50:12 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-b97c44417ffso531619766b.2 for ; Mon, 30 Mar 2026 14:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774907409; cv=none; d=google.com; s=arc-20240605; b=dtf+1gWqeGp/NJJAz7c0BilJEkJcvu7aZMEIg/TqvMj/vQe8bOWhv/hi4/0IPJGx0F RkPVViWIjI58Mkg11kNdh08niQgtVablfgFmx7VA59+AWJEuRUa5dtL8FZGmAdg/csba Dqz9U8RFcLpd93io5UwI7y5YfddER0A4suLBmLck9I0IY8iRPj/fadO52a8l96TedgWo /DWW5beNR9qKJ1VKW79xIQlRU3AC9qorihK6ckhjSJW9QyAvf1xS77zWGOeF+3Xq8bu7 6EpzrggF/hxwk+IPk04bxFDDy1a5c6XJDcVuUlUbam4yslbpITYtvtnSFygLqXnwsBeK XWFw== 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=cs24gqAZiiZWWoGuQm3x7Cp3X/MrTCV1/vbhoKaG0AI=; fh=6Vzfs6ebSfhvThPwAluAAlCYTFI145d8EWxcrPHkkLc=; b=kG1epPDtm+taJX9OAOnmCJFDRZFiQLEkbd3kxK1czauqdr+Rffj4gOEHTxAeM++7Vu ttjjX2yD8EELcnFq9aePoBjNwBFIPl8jdXT5Hm7vBZSkwBbKVL8ioZo3JxosdIf6PFGz ebg/tpIfvC7ErsS6PZXP5U8Cw7bf1BCBwA/pQ8dirIuatZ/Gg3yowLBLkvqRaVeHK9jz CbCLxCnJ+FC1VuXcDpmdsWeF7avRxUUmmwC0413oo6dP5dRDJGrqG2Swt1lUYeiZXz33 mJkzvaaC3apgH39TdieDTXPgYcS0YMS+2U/TK5Hs7xnXtvWytujB0/sO7aTItfBSBH5g qNMw==; 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=20251104; t=1774907409; x=1775512209; 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=cs24gqAZiiZWWoGuQm3x7Cp3X/MrTCV1/vbhoKaG0AI=; b=Aouda2Ll5I//YKxuESa9sJhJ/GFVomLwYqeRmh6ezlVhzLZ5Pk/Txt0qpZ8AxUSbPw zIgo3lljq8pfiTXNRPKfv3pjvxM4c6HyJ3dbXECD8WJbOHwJeVLUw1LdVag/OmBMR1Uj /5Tz2zbNtRIqL1lPH9j1oB2LiOCpSozw9R6ch1DGuUdBZyELJdVZp4YbqU6BMKjKXk1F wAgl9RkMTd7zyst4zTZ1ieNyhg6wZmKp3kaLxeZ6jGRGEwdkLezA9oxVK+Pt3nUqHSnM Z0n79oxYJaqFiG0W7L0RR6mkzadnrQpEDOhMd+xB03z9w970BuB02kMHNTSomVq81mGW l4hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774907409; x=1775512209; 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=cs24gqAZiiZWWoGuQm3x7Cp3X/MrTCV1/vbhoKaG0AI=; b=V+a467i5y9SCUeXdVtcv/HZhJuYZAbTMXgzzKpvKv6L51UgEnrZz0I5I1V9TKu4Ghq 1ONbhqe62LRUjWkmeKpd9vDs1vOhCyi1RW4M+6ViI4JyCcHIGULviIjiJJwTHnvQGfyH 4DKDJv670YelVs967aPJASV4qUnlN+wYsvOFeWOw5eN0TNZnqJmQxx8qz6X0NZUXUame de4rbY0//l3R6AViKVWJlUAPOqhBqIOcq3qK5KnnffsFr2ZCwDMTaGhdD6soaD2REZQO u+Bv+kyngpTI4AWEHh4neN+e2lwV47HTBq+JeeRas14fwIM0c88Xl4OnVOUlwb0ym0NN m4lg== X-Gm-Message-State: AOJu0YxMV+rdhcmiEPc2AoGE44E5BFBq3bVhkzQfS1Zpi6Sr4exy/XCK v7506WGPkxA9pDmiGmrBxaUyBM3adb5621O2cV4ucinw0+ysfDUgYb+zkw/sWnyAWZL5aVQ3/KK IqjLtO9WkuqFIQRm7zpWpY2eTK08wmExLLTu6 X-Gm-Gg: ATEYQzy0fWH5e/62gCOmvZzFPc2+IHzgnVq5THlFXX7QdS8pJ6+is+YYIKQhh+eo4Nr L8VSIXYqU42nEg8fcNnmzN/qDq6JiYmnCRofizcdV0Py9TXWC8euYJAP3AxQlfaJXa0WTEloemt 0xhaC8QqlCDYtyweFBTt+sCTGf99IW/SaKl5JG1EVEbvW6zhBW0qkpP2ioLy740T6fiWPEVYBQe 7tEqiDmzCmQnn2WcLj0w+s2VCrgfWIR/mUgcHVC2DRqn6BzMxkWott5/gXfnNnCiY5vFTYCmKmJ DADsecR+VyNrPec9JOUkdLX9DvewCynq/yRa3Ci3cZpmbfINxQ== X-Received: by 2002:a17:907:6d09:b0:b93:5385:327e with SMTP id a640c23a62f3a-b9b5035b09emr979454366b.21.1774907409035; Mon, 30 Mar 2026 14:50:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Mon, 30 Mar 2026 17:49:55 -0400 X-Gm-Features: AQROBzARaLX4Tn6tthiRZ63qHcB6NwnmW2RgWluVAO3AyZGkACCJb7Dw5VO4e5w Message-ID: Subject: Re: Add custom EXPLAIN options support to auto_explain To: Matheus Alcantara Cc: pgsql-hackers@lists.postgresql.org 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 Thu, Mar 26, 2026 at 3:18=E2=80=AFPM Matheus Alcantara wrote: > Attached patch add a new GUC parameter auto_explain.log_options that > accepts a comma-separated list of custom EXPLAIN options registered by > extensions. This allows auto_explain to pass extension specific options > (like from pg_plan_advice) when logging query plans. I like this idea a lot, but I don't think the details work. It seems to me that fabricating an ExplainState to pass down as this patch does is probably not very safe. I see why you're doing that: the built-in options can be signaled via instrument_options flags, but custom EXPLAIN options can only be requested via an ExplainState, which won't exist here unless the user happens to be running EXPLAIN, so you have to create one. But I think that might cause problems for other extensions that are expecting the ExplainState to exist only when the command being run is actually EXPLAIN, and it also makes the behavior dependent on the module load order. > That being said, this patch creates a new planner_setup_hook for case > 1 and changes explain_ExecutorEnd() to call explain_per_plan_hook() > for case 2. Note that even for case 1, we still need to call > explain_per_plan_hook() so the extra information from the custom > explain option is included in the explain output. I think that adding a call here to explain_per_plan_hook() makes a lot of sense. Doing some refactoring so that auto_explain can reuse some core function instead of rolling its own might make sense, too. In terms of making things work with pg_plan_advice, it seems to me that all we really need here is (1) add a call to explain_per_plan_hook() as you've done, or possibly with some refactoring, and (2) provide a way to set custom options in the ExplainState that is explain_ExecutorEnd is already creating. If had that much, then the user could set pg_plan_advice.always_store_advice_details=3Dtrue to close the remaining gap. Any module other than pg_plan_advice that needs to behave differently at plan time depending on EXPLAIN options should provide a similar option, because the issue is fundamental. Modules that don't, like pg_overexplain, just work with no further changes. But, while (1) is simple, it seems that (2) is not. When you actually run EXPLAIN (options go here), any problems with those options will result in throwing an ERROR. But auto_explain does not want to have foreground queries start erroring out because of problems with its configuration. For built-in options, it can and does avoid that by validating those options at the time you set auto_explain.log_WHATEVER, and then it also just kind of makes an end-run around the cross-checks between different options. For custom options, that doesn't work, because RegisterExtensionExplainOption() registers a single handler that *both* throws errors if the option value isn't OK *and also* feeds required information into the ExplainState. I'm currently poking at some ideas for fixing this... more soon. --=20 Robert Haas EDB: http://www.enterprisedb.com