On 2025-11-19 05:19, Akshat Jaimini wrote:
Thanks for your review!
> Hi,
> I have a question:
>
> In src/backend/executor/execMain.c:
>
> ```
> + SetCurrentQueryDesc(oldQueryDesc);
> +
> + /*
> + * Ensure LogQueryPlanPending is initialized in case there was no
> time for
> + * logging the plan. Othewise plan will be logged at the next query
> + * execution on the same session.
> + */
> + LogQueryPlanPending = false;
> ```
>
> It would be really helpful if you could elaborate on any cases where
> this specific situation might arise i.e. where 'there was no time for
> logging the plan'. Are we referencing to something like a sudden
> shutdown of the postmaster process or is this referring to something
> else entirely?
What I have in mind are cases where a query finishes before
LogQueryPlan() is ever invoked.
Since LogQueryPlan() is called from ExecProcNodeFirst(), this generally
means pg_log_query_plan() was called at the moment just before query
execution completes.
Also, very short queries fall into this category:
=# select pg_log_query_plan(pg_backend_pid());
pg_log_query_plan
-------------------
t
(1 row)
=# select 1;
With the current patch, nothing is logged here.
But if I comment out the "LogQueryPlanPending = false" line, the plan
for "SELECT 1" ends up being logged:
LOG: 00000: query and its plan running on backend with PID 33040 are:
Query Text: select 1;
Result (cost=0.00..0.01 rows=1 width=4)
Output: 1
Settings: jit = 'off'
--
Regards,
--
Atsushi Torikoshi
Seconded from NTT DATA Japan Corporation to SRA OSS K.K.