Rebased on current master (e18b0cb7344).
Changes from v4:The locking was inconsistent. The read is now inside the spinlock together with the other counters, and the comment no longer hardcodes a field count. Thanks to Zsolt Parragi for catching this.
The `es_exec_start` field is now set unconditionally in `pgss_ExecutorStart`, not just when `pgss_enabled()`. Thanks to Sami Imseih for pointing this out. The planner hook no longer passes a timestamp to `pgss_store`. `pgss_store` now skips the update when exec_start is zero.
`INT64CONST(0)` in the `pgss_ExecutorStart` was replaced with a plain 0 iconst. No idea why this was introduced in the first place.
The deferred-ExecutorEnd regression test is rewritten. The previous version used `pg_sleep` with `\bind \g` inside an implicit transaction. The new test uses an explicit `BEGIN/END` with `\bind \gset`. Thanks to Anthonin Bonnefoy for the correct pattern and to Sami Imseih for confirming it.
A DDL test is added to cover utility-statement paths. Not sure how it is different from a DML statement though.
The redundant "test filtering" count query and the confusing `stats_since` are removed from the basic update test. Extra comments are also removed.
The documentation now includes a sample monitoring query, as it appeared in
the original v1 submission.Regarding Peter Eisentraut's concern (raised at pgconf.dev) about top-level vs nested statement timestamps: for `toplevel = false` rows, `last_execution_start` reflects the start time of the enclosing top-level statement, not the nested one. This is a consequence of how `GetCurrentStatementStartTimestamp()` works and is documented. It means the field is not useful for timing individual nested calls, but it is still useful for the stated purpose of answering "when was this statement last active".
All pg_stat_statements regression tests that pass on master also pass with this patch.
Magic number `PGSS_FILE_HEADER` is bumped to `0x20260610`. v5 patch attached. Best regards, Pavlo Golub
v5-0001-pg_stat_statements-Add-last_execution_start-colum.patch
Description: Binary data
