Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: Sergei Kornilov <sk@zsrv.org>, Julien Rouhaud <rjuju123@gmail.com>,
maxim.boguk@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2023-11-01T17:15:27Z
Lists: pgsql-bugs
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix some issues with tracking nesting level in pg_stat_statements.
- 76db9cb6368e 17.0 landed
Attachments
- v2-0001-increment-nest-level-more-often.patch (text/x-diff) patch v2-0001
Tomas Vondra <tomas.vondra@enterprisedb.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