Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
Cc: Sergei Kornilov <sk(at)zsrv(dot)org>, Julien Rouhaud <rjuju123(at)gmail(dot)com>, maxim(dot)boguk(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data
Date: 2023-11-01 17:15:27
Message-ID: 2831679.1698858927@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com> writes:
> I took a look, and the patch seems correct to me. It'll need better
> comments explaining the change, but I'll take care of that. Barring
> objections, I'll get this committed and backpatched.

Since Tomas hadn't done anything with this, I picked it up with
intent to commit, and got as far as revising the comments and
eliminating some duplicative condition checks (see attached).

However, I then started to wonder whether it's really a good idea
that the code treats PREPARE and EXECUTE alike for this purpose.
In the case of EXECUTE, the idea is that we'll still be at top
level when we reach the executor hooks, and they will do the right
thing and then increment exec_nested_level before any lower-level
statement can be reached. But how does that concept apply to
PREPARE, which won't reach the executor? ISTM the net result
is that if any subsidiary statements are reached during PREPARE
(perhaps via const-simplification of some SQL or PL function),
we will erroneously treat them as top-level.

It's worth noting that the comments here explicitly mention that
suppressing the nesting level bump is desired for EXECUTE, while
*not* saying that for PREPARE. I've not dug in the commit history,
but I wonder if this isn't a bug somebody introduced during
careless refactoring to invent the PGSS_HANDLED_UTILITY macro.
It's not clear to me that that macro is anything but an
invitation to sloppy thinking.

In short, I think we probably want to bump the nest level
for everything except EXECUTE, and I'm not sure that
PGSS_HANDLED_UTILITY is worth keeping.

Thoughts?

BTW, I'm inclined not to back-patch this. While it seems like
a bug fix, it's also a behavioral change that might break
someone's expectations.

regards, tom lane

Attachment Content-Type Size
v2-0001-increment-nest-level-more-often.patch text/x-diff 7.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-11-01 21:20:21 Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data
Previous Message Alexander Korotkov 2023-11-01 10:29:12 Re: BUG #18170: Unexpected error: no relation entry for relid 3