Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data - Mailing list pgsql-bugs

From Sergei Kornilov
Subject Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data
Date
Msg-id 430591679487667@lma6oifqwmuo4pt7.myt.yp-c.yandex.net
Whole thread Raw
In response to Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data  (Julien Rouhaud <rjuju123@gmail.com>)
Responses Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data  (Tomas Vondra <tomas.vondra@enterprisedb.com>)
List pgsql-bugs
Hello

I have a similar problem with exactly the same reason. Queries are counted as top level, although they are not called
atthe top level. Another small example:
 

set pg_stat_statements.track_utility to off;
set pg_stat_statements.track to 'top';
do $$ declare i int; begin select 1 as n into i; end $$ language plpgsql;
select toplevel, query from pg_stat_statements order by query;
 toplevel |               query               
----------+-----------------------------------
 t        | select $1 as n
 t        | select pg_stat_statements_reset()
(2 rows)

But "select $1 as n" was not a top-level query.

In the first patch, a testcase showing the behavior now. The second patch adds a nesting level increment if
track_utilityis disabled. I need to duplicate the PGSS_HANDLED_UTILITY check here because it's documented above:
 

> If it's an EXECUTE statement, we don't track it and don't increment the nesting level.

regards, Sergei
Attachment

pgsql-bugs by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: BUG #17858: ExecEvalArrayExpr() leaves uninitialised memory for multidim array with nulls
Next
From: PG Bug reporting form
Date:
Subject: BUG #17860: Possible Bugs in PL/pgSQL Functions' Return Values