| From: | Sami Imseih <samimseih(at)gmail(dot)com> |
|---|---|
| To: | Martin Huang <jjja5555(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: pg_stat_statements: Fix nested tracking for implicitly closed cursors |
| Date: | 2026-01-14 01:01:48 |
| Message-ID: | CAA5RZ0tDxGO-O+n+HomO9cmHkq34v7WgT0Q+HsED-cuqW+JUWA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Thanks for the comment!
> Please add a `PG_TRY` and `PG_FINALLY` to make sure we always reset the nesting_level.
>
> Also this will break the following scenario
> ```
> BEGIN;
> COMMIT;
> SELECT 1; -- This will be stored as inner level because COMMIT sets is_txn_end flag
> ```
>
> Can we reset is_txn_end at executorStart to solve the problem?
Correct.Thanks for spotting this oversight. I think the is_txn_end flag must
be reset in all hook functions that call pgss_store, except in pgss_ExecutorEnd,
where we just have to check is_txn_end and increment the nesting_level. Also,
I added a PG_TRY/FINALLY inside pgss_ExecutorEnd to ensure we reset the
nesting_level is reset.
I added a test case for the query you mentioned above.
--
Sami Imseih
Amazon Web Services (AWS)
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-pg_stat_statements-Fix-nested-tracking-for-implic.patch | application/octet-stream | 15.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andreas Karlsson | 2026-01-14 01:07:43 | Re: [PATCH] check kernel version for io_method |
| Previous Message | Chao Li | 2026-01-14 00:52:18 | Re: ALTER TABLE: warn when actions do not recurse to partitions |