Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7744d5

Browse files
committed
Fix initialization of pg_stat_get_lastscan()
A NULL result should be reported when a stats timestamp is set to 0, butc037471 missed that, leading to a confusing timestamp value after forexample a DML on a freshly-created relation with no scans done on ityet.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_scanReported-by: Robert TreatAnalyzed-by: Peter EisentrautAuthor: Dave PageDiscussion:https://postgr.es/m/CABV9wwPzMfSaz3EfKXXDxKmMprbxwF5r6WPuxqA=5mzRUqfTGg@mail.gmail.com
1 parent1613de8 commitd7744d5

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ Datum
5656
pg_stat_get_lastscan(PG_FUNCTION_ARGS)
5757
{
5858
Oidrelid=PG_GETARG_OID(0);
59+
TimestampTzresult;
5960
PgStat_StatTabEntry*tabentry;
6061

6162
if ((tabentry=pgstat_fetch_stat_tabentry(relid))==NULL)
63+
result=0;
64+
else
65+
result=tabentry->lastscan;
66+
67+
if (result==0)
6268
PG_RETURN_NULL();
6369
else
64-
PG_RETURN_TIMESTAMPTZ(tabentry->lastscan);
70+
PG_RETURN_TIMESTAMPTZ(result);
6571
}
6672

6773

‎src/test/regress/expected/stats.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,12 @@ SELECT pg_stat_force_next_flush();
573573

574574
(1 row)
575575

576+
SELECT last_seq_scan, last_idx_scan FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
577+
last_seq_scan | last_idx_scan
578+
---------------+---------------
579+
|
580+
(1 row)
581+
576582
COMMIT;
577583
SELECT pg_stat_reset_single_table_counters('test_last_scan'::regclass);
578584
pg_stat_reset_single_table_counters

‎src/test/regress/sql/stats.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ BEGIN;
303303
CREATE TEMPORARY TABLE test_last_scan(idx_colintprimary key, noidx_colint);
304304
INSERT INTO test_last_scan(idx_col, noidx_col)VALUES(1,1);
305305
SELECT pg_stat_force_next_flush();
306+
SELECT last_seq_scan, last_idx_scanFROM pg_stat_all_tablesWHERE relid='test_last_scan'::regclass;
306307
COMMIT;
307308

308309
SELECT pg_stat_reset_single_table_counters('test_last_scan'::regclass);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp