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

Commit81b9b5c

Browse files
committed
Make gistvacuumcleanup() count the actual number of index tuples.
Previously, it just returned the heap tuple count, which might be only anestimate, and would be completely the wrong thing if the index is partial.Since this function scans every index page anyway to find free pages,it's practically free to count the surviving index tuples. Let's do thatand return an accurate count.This is easily visible as a wrong reltuples value for a partial GiSTindex following VACUUM, so back-patch to all supported branches.Andrey Borodin, reviewed by Michail NikolaevDiscussion:https://postgr.es/m/151956654251.6915.675951950408204404.pgcf@coridan.postgresql.org
1 parent7240962 commit81b9b5c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

‎src/backend/access/gist/gistvacuum.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ gistvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
3232
BlockNumbernpages,
3333
blkno;
3434
BlockNumbertotFreePages;
35+
doubletuplesCount;
3536
boolneedLock;
3637

3738
/* No-op in ANALYZE ONLY mode */
@@ -40,17 +41,7 @@ gistvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
4041

4142
/* Set up all-zero stats if gistbulkdelete wasn't called */
4243
if (stats==NULL)
43-
{
4444
stats= (IndexBulkDeleteResult*)palloc0(sizeof(IndexBulkDeleteResult));
45-
/* use heap's tuple count */
46-
stats->num_index_tuples=info->num_heap_tuples;
47-
stats->estimated_count=info->estimated_count;
48-
49-
/*
50-
* XXX the above is wrong if index is partial. Would it be OK to just
51-
* return NULL, or is there work we must do below?
52-
*/
53-
}
5445

5546
/*
5647
* Need lock unless it's local to this backend.
@@ -65,6 +56,7 @@ gistvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
6556
UnlockRelationForExtension(rel,ExclusiveLock);
6657

6758
totFreePages=0;
59+
tuplesCount=0;
6860
for (blkno=GIST_ROOT_BLKNO+1;blkno<npages;blkno++)
6961
{
7062
Bufferbuffer;
@@ -82,6 +74,11 @@ gistvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
8274
totFreePages++;
8375
RecordFreeIndexPage(rel,blkno);
8476
}
77+
elseif (GistPageIsLeaf(page))
78+
{
79+
/* count tuples in index (considering only leaf tuples) */
80+
tuplesCount+=PageGetMaxOffsetNumber(page);
81+
}
8582
UnlockReleaseBuffer(buffer);
8683
}
8784

@@ -95,6 +92,8 @@ gistvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
9592
stats->num_pages=RelationGetNumberOfBlocks(rel);
9693
if (needLock)
9794
UnlockRelationForExtension(rel,ExclusiveLock);
95+
stats->num_index_tuples=tuplesCount;
96+
stats->estimated_count= false;
9897

9998
returnstats;
10099
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp