mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Fix initialization of pg_stat_get_lastscan()
A NULL result should be reported when a stats timestamp is set to 0, but
c037471
missed that, leading to a confusing timestamp value after for
example a DML on a freshly-created relation with no scans done on it
yet.
This impacted the following attributes for two system views:
- pg_stat_all_tables.last_idx_scan
- pg_stat_all_tables.last_seq_scan
- pg_stat_all_indexes.last_idx_scan
Reported-by: Robert Treat
Analyzed-by: Peter Eisentraut
Author: Dave Page
Discussion: https://postgr.es/m/CABV9wwPzMfSaz3EfKXXDxKmMprbxwF5r6WPuxqA=5mzRUqfTGg@mail.gmail.com
This commit is contained in:
@ -56,12 +56,18 @@ Datum
|
||||
pg_stat_get_lastscan(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid relid = PG_GETARG_OID(0);
|
||||
TimestampTz result;
|
||||
PgStat_StatTabEntry *tabentry;
|
||||
|
||||
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
|
||||
result = 0;
|
||||
else
|
||||
result = tabentry->lastscan;
|
||||
|
||||
if (result == 0)
|
||||
PG_RETURN_NULL();
|
||||
else
|
||||
PG_RETURN_TIMESTAMPTZ(tabentry->lastscan);
|
||||
PG_RETURN_TIMESTAMPTZ(result);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user