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

Commitd52a57f

Browse files
committed
Actually there's a better way to do this, which is to count tuples
during the vacuumcleanup scan that we're going to do anyway. Shouldsave a few cycles (one calculation per page, not per tuple) as wellas not having to depend on assumptions about heap and index beingin step.I think this could probably be made to work for GIST too, but thatcode looks messy enough that I'm disinclined to try right now.
1 parentfd267c1 commitd52a57f

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

‎src/backend/access/nbtree/nbtree.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.139 2006/02/11 23:31:33 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.140 2006/02/12 00:18:17 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -539,16 +539,12 @@ btbulkdelete(PG_FUNCTION_ARGS)
539539
IndexBulkDeleteCallbackcallback= (IndexBulkDeleteCallback)PG_GETARG_POINTER(1);
540540
void*callback_state= (void*)PG_GETARG_POINTER(2);
541541
IndexBulkDeleteResult*result;
542-
doubletuples_removed;
543-
doublenum_index_tuples;
542+
doubletuples_removed=0;
544543
OffsetNumberdeletable[MaxOffsetNumber];
545544
intndeletable;
546545
Bufferbuf;
547546
BlockNumbernum_pages;
548547

549-
tuples_removed=0;
550-
num_index_tuples=0;
551-
552548
/*
553549
* The outer loop iterates over index leaf pages, the inner over items on
554550
* a leaf page. We issue just one _bt_delitems() call per page, so as to
@@ -566,19 +562,12 @@ btbulkdelete(PG_FUNCTION_ARGS)
566562
* could be stopped on those.
567563
*
568564
* We can skip the scan entirely if there's nothing to delete (indicated
569-
* by callback_state == NULL) and the index isn't partial. For a partial
570-
* index we must scan in order to derive a trustworthy tuple count.
565+
* by callback_state == NULL).
571566
*/
572-
if (callback_state||vac_is_partial_index(rel))
573-
{
567+
if (callback_state)
574568
buf=_bt_get_endpoint(rel,0, false);
575-
}
576569
else
577-
{
578-
/* skip scan and set flag for btvacuumcleanup */
579570
buf=InvalidBuffer;
580-
num_index_tuples=-1;
581-
}
582571

583572
if (BufferIsValid(buf))/* check for empty index */
584573
{
@@ -634,8 +623,6 @@ btbulkdelete(PG_FUNCTION_ARGS)
634623
deletable[ndeletable++]=offnum;
635624
tuples_removed+=1;
636625
}
637-
else
638-
num_index_tuples+=1;
639626
}
640627
}
641628

@@ -663,7 +650,7 @@ btbulkdelete(PG_FUNCTION_ARGS)
663650

664651
result= (IndexBulkDeleteResult*)palloc0(sizeof(IndexBulkDeleteResult));
665652
result->num_pages=num_pages;
666-
result->num_index_tuples=num_index_tuples;
653+
/* btvacuumcleanup will fill innum_index_tuples */
667654
result->tuples_removed=tuples_removed;
668655

669656
PG_RETURN_POINTER(result);
@@ -687,6 +674,7 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
687674
BlockNumber*freePages;
688675
intnFreePages,
689676
maxFreePages;
677+
doublenum_index_tuples=0;
690678
BlockNumberpages_deleted=0;
691679
MemoryContextmycontext;
692680
MemoryContextoldcontext;
@@ -801,6 +789,12 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
801789
MemoryContextSwitchTo(oldcontext);
802790
continue;/* pagedel released buffer */
803791
}
792+
elseif (P_ISLEAF(opaque))
793+
{
794+
/* Count the index entries of live leaf pages */
795+
num_index_tuples+=PageGetMaxOffsetNumber(page)+1-
796+
P_FIRSTDATAKEY(opaque);
797+
}
804798
_bt_relbuf(rel,buf);
805799
}
806800

@@ -847,16 +841,10 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
847841

848842
/* update statistics */
849843
stats->num_pages=num_pages;
844+
stats->num_index_tuples=num_index_tuples;
850845
stats->pages_deleted=pages_deleted;
851846
stats->pages_free=nFreePages;
852847

853-
/* if btbulkdelete skipped the scan, use heap's tuple count */
854-
if (stats->num_index_tuples<0)
855-
{
856-
Assert(info->num_heap_tuples >=0);
857-
stats->num_index_tuples=info->num_heap_tuples;
858-
}
859-
860848
PG_RETURN_POINTER(stats);
861849
}
862850

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp