diff --git a/contrib/pgstattuple/expected/pgstattuple.out b/contrib/pgstattuple/expected/pgstattuple.out index 86a7c78fbb..c7c1732827 100644 --- a/contrib/pgstattuple/expected/pgstattuple.out +++ b/contrib/pgstattuple/expected/pgstattuple.out @@ -132,9 +132,9 @@ select * from pgstatginindex('test_ginidx'); create index test_hashidx on test using hash (b); select * from pgstathashindex('test_hashidx'); - version | bucket_pages | overflow_pages | bitmap_pages | zero_pages | live_items | dead_items | free_percent ----------+--------------+----------------+--------------+------------+------------+------------+-------------- - 3 | 4 | 0 | 1 | 0 | 0 | 0 | 100 + version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent +---------+--------------+----------------+--------------+--------------+------------+------------+-------------- + 3 | 4 | 0 | 1 | 0 | 0 | 0 | 100 (1 row) -- these should error with the wrong type diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c index d448e9ede6..15aedec1bf 100644 --- a/contrib/pgstattuple/pgstatindex.c +++ b/contrib/pgstattuple/pgstatindex.c @@ -119,7 +119,7 @@ typedef struct HashIndexStat BlockNumber bucket_pages; BlockNumber overflow_pages; BlockNumber bitmap_pages; - BlockNumber zero_pages; + BlockNumber unused_pages; int64 live_items; int64 dead_items; @@ -634,7 +634,6 @@ pgstathashindex(PG_FUNCTION_ARGS) { Buffer buf; Page page; - HashPageOpaque opaque; CHECK_FOR_INTERRUPTS(); @@ -644,7 +643,7 @@ pgstathashindex(PG_FUNCTION_ARGS) page = (Page) BufferGetPage(buf); if (PageIsNew(page)) - stats.zero_pages++; + stats.unused_pages++; else if (PageGetSpecialSize(page) != MAXALIGN(sizeof(HashPageOpaqueData))) ereport(ERROR, @@ -654,19 +653,26 @@ pgstathashindex(PG_FUNCTION_ARGS) BufferGetBlockNumber(buf)))); else { + HashPageOpaque opaque; + int pagetype; + opaque = (HashPageOpaque) PageGetSpecialPointer(page); - if (opaque->hasho_flag & LH_BUCKET_PAGE) + pagetype = opaque->hasho_flag & LH_PAGE_TYPE; + + if (pagetype == LH_BUCKET_PAGE) { stats.bucket_pages++; GetHashPageStats(page, &stats); } - else if (opaque->hasho_flag & LH_OVERFLOW_PAGE) + else if (pagetype == LH_OVERFLOW_PAGE) { stats.overflow_pages++; GetHashPageStats(page, &stats); } - else if (opaque->hasho_flag & LH_BITMAP_PAGE) + else if (pagetype == LH_BITMAP_PAGE) stats.bitmap_pages++; + else if (pagetype == LH_UNUSED_PAGE) + stats.unused_pages++; else ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), @@ -680,8 +686,8 @@ pgstathashindex(PG_FUNCTION_ARGS) /* Done accessing the index */ index_close(rel, AccessShareLock); - /* Count zero pages as free space. */ - stats.free_space += stats.zero_pages * stats.space_per_page; + /* Count unused pages as free space. */ + stats.free_space += stats.unused_pages * stats.space_per_page; /* * Total space available for tuples excludes the metapage and the bitmap @@ -710,7 +716,7 @@ pgstathashindex(PG_FUNCTION_ARGS) values[1] = Int64GetDatum((int64) stats.bucket_pages); values[2] = Int64GetDatum((int64) stats.overflow_pages); values[3] = Int64GetDatum((int64) stats.bitmap_pages); - values[4] = Int64GetDatum((int64) stats.zero_pages); + values[4] = Int64GetDatum((int64) stats.unused_pages); values[5] = Int64GetDatum(stats.live_items); values[6] = Int64GetDatum(stats.dead_items); values[7] = Float8GetDatum(free_percent); diff --git a/contrib/pgstattuple/pgstattuple--1.4--1.5.sql b/contrib/pgstattuple/pgstattuple--1.4--1.5.sql index 05ae51fa4b..5d03544a21 100644 --- a/contrib/pgstattuple/pgstattuple--1.4--1.5.sql +++ b/contrib/pgstattuple/pgstattuple--1.4--1.5.sql @@ -125,7 +125,7 @@ CREATE OR REPLACE FUNCTION pgstathashindex(IN relname regclass, OUT bucket_pages BIGINT, OUT overflow_pages BIGINT, OUT bitmap_pages BIGINT, - OUT zero_pages BIGINT, + OUT unused_pages BIGINT, OUT live_items BIGINT, OUT dead_items BIGINT, OUT free_percent FLOAT8) diff --git a/doc/src/sgml/pgstattuple.sgml b/doc/src/sgml/pgstattuple.sgml index 141d8e225f..b6a5f19e70 100644 --- a/doc/src/sgml/pgstattuple.sgml +++ b/doc/src/sgml/pgstattuple.sgml @@ -372,7 +372,7 @@ version | 2 bucket_pages | 33081 overflow_pages | 0 bitmap_pages | 1 -zero_pages | 32455 +unused_pages | 32455 live_items | 10204006 dead_items | 0 free_percent | 61.8005949100872 @@ -418,9 +418,9 @@ free_percent | 61.8005949100872 - zero_pages + unused_pages bigint - Number of new or zero pages + Number of unused pages