Re: [PATCH] Add last_executed timestamp to pg_stat_statements - Mailing list pgsql-hackers

From Pavlo Golub
Subject Re: [PATCH] Add last_executed timestamp to pg_stat_statements
Date
Msg-id CAK7ymc+M_=890L6EA28QAN8AxadJTzUjvqEHT2ojw3ivdD1HSQ@mail.gmail.com
Whole thread
In response to Re: [PATCH] Add last_executed timestamp to pg_stat_statements  (Christoph Berg <myon@debian.org>)
List 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

pgsql-hackers by date:

Previous
From: Jim Jones
Date:
Subject: Re: Add CREATE SCHEMA ... LIKE support
Next
From: "David G. Johnston"
Date:
Subject: Add CREATE SCHEMA ... LIKE support