Re: pg_stat_statements: Fix nested tracking for implicitly closed cursors - Mailing list pgsql-hackers

From Sami Imseih
Subject Re: pg_stat_statements: Fix nested tracking for implicitly closed cursors
Date
Msg-id CAA5RZ0tDxGO-O+n+HomO9cmHkq34v7WgT0Q+HsED-cuqW+JUWA@mail.gmail.com
Whole thread Raw
In response to Re: pg_stat_statements: Fix nested tracking for implicitly closed cursors  (Martin Huang <jjja5555@gmail.com>)
List 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

pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: ALTER TABLE: warn when actions do not recurse to partitions
Next
From: Andreas Karlsson
Date:
Subject: Re: [PATCH] check kernel version for io_method