Correctly propagate queryId for utility stmt in function

Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>

From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2024-07-18T11:37:40Z
Lists: pgsql-hackers

Attachments

Hi,

For utility statements defined within a function, the queryTree is
copied to a plannedStmt as utility commands don't require planning.
However, the queryId is not propagated to the plannedStmt. This leads
to plugins relying on queryId like pg_stat_statements to not be able
to track utility statements within function calls.

This patch fixes the issue by correctly propagating queryId from the
cached queryTree to the plannedStmt.

Regards,
Anthonin

Commits

  1. Propagate query IDs of utility statements in functions