| From: | Pavlo Golub <pavlo(dot)golub(at)cybertec(dot)at> |
|---|---|
| To: | Christoph Berg <myon(at)debian(dot)org> |
| Cc: | Sami Imseih <samimseih(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH] Add last_executed timestamp to pg_stat_statements |
| Date: | 2026-02-06 15:27:00 |
| Message-ID: | CAK7ymc+M_=890L6EA28QAN8AxadJTzUjvqEHT2ojw3ivdD1HSQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
OK, here is one more try. I discovered the `total_time` argument to
the `pgss_store()` function! So we can calculate the finish time
without calling `GetCurrentTimestamp()`.
This is version 3 of the patch adding a `stats_last_updated` column
(yes, again) to pg_stat_statements. Based on feedback, this version
improves the implementation with better performance and correctness.
The main improvement uses `statement_start + execution_duration` with
`rint(total_time * 1000.0)` to convert milliseconds to microseconds
with proper rounding. The calculation performed BEFORE acquiring
spinlock and assigned within locked scope.
I'm wondering how we all missed this trick from the very beginning and
started to argue if `GetCurrentTimestamp()` is heavy or not. :)
Best regards,
Pavlo
| Attachment | Content-Type | Size |
|---|---|---|
| v3-0001-pg_stat_statements-Add-stats_last_updated-column.patch | application/octet-stream | 17.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G. Johnston | 2026-02-06 15:30:17 | Add CREATE SCHEMA ... LIKE support |
| Previous Message | Jim Jones | 2026-02-06 15:23:45 | Re: Add CREATE SCHEMA ... LIKE support |