Set query_id for query contained in utility statement

From: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Set query_id for query contained in utility statement
Date: 2024-08-02 08:21:53
Message-ID: CAO6_XqqM6S9bQ2qd=75W+yKATwoazxSNhv5sjW06fjGAtHbTUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

Some utility statements like Explain, CreateTableAs and DeclareCursor
contain a query which will be planned and executed. During post parse,
only the top utility statement is jumbled, leaving the contained query
without a query_id set. Explain does the query jumble in ExplainQuery
but for the contained query but CreateTableAs and DeclareCursor were
left with unset query_id.

This leads to extensions relying on query_id like pg_stat_statements
to not be able to track those nested queries as the query_id was 0.

This patch fixes this by recursively jumbling queries contained in
those utility statements during post_parse, setting the query_id for
those contained queries and removing the need for ExplainQuery to do
it for the Explain statements.

Regards,
Anthonin Bonnefoy

Attachment Content-Type Size
v1-0001-Set-query_id-for-queries-contained-in-utility-sta.patch application/octet-stream 17.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Kirill Reshke 2024-08-02 08:25:25 Small refactoring around vacuum_open_relation
Previous Message Steven Niu 2024-08-02 07:36:33 Re: [Patch] remove duplicated smgrclose