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

Commitbbaf315

Browse files
committed
Add bound check before bsearch() for performance
In the current lazy vacuum implementation, some index AMs such asbtree indexes call lazy_tid_reaped() for each index tuple duringambulkdelete to check if the index tuple points to the (collected)garbage tuple. In that function, we simply call bsearch(), but weshould be able to know the result without bsearch() if the index tuplepoints to the heap tuple that is out of range of the collected garbagetuples. Therefore, add a simple bound check before resorting tobsearch(). Testing has shown that this can give significantperformance benefits.Author: Masahiko Sawada <masahiko.sawada@2ndquadrant.com>Discussion:https://www.postgresql.org/message-id/flat/CA+fd4k76j8jKzJzcx8UqEugvayaMSnQz0iLUt_XgBp-_-bd22A@mail.gmail.com
1 parentc427de4 commitbbaf315

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include"access/visibilitymap.h"
6262
#include"access/xact.h"
6363
#include"access/xlog.h"
64+
#include"catalog/index.h"
6465
#include"catalog/storage.h"
6566
#include"commands/dbcommands.h"
6667
#include"commands/progress.h"
@@ -2923,8 +2924,24 @@ static bool
29232924
lazy_tid_reaped(ItemPointeritemptr,void*state)
29242925
{
29252926
LVDeadTuples*dead_tuples= (LVDeadTuples*)state;
2927+
int64litem,
2928+
ritem,
2929+
item;
29262930
ItemPointerres;
29272931

2932+
litem=itemptr_encode(&dead_tuples->itemptrs[0]);
2933+
ritem=itemptr_encode(&dead_tuples->itemptrs[dead_tuples->num_tuples-1]);
2934+
item=itemptr_encode(itemptr);
2935+
2936+
/*
2937+
* Doing a simple bound check before bsearch() is useful to avoid the
2938+
* extra cost of bsearch(), especially if dead tuples on the heap are
2939+
* concentrated in a certain range. Since this function is called for
2940+
* every index tuple, it pays to be really fast.
2941+
*/
2942+
if (item<litem||item>ritem)
2943+
return false;
2944+
29282945
res= (ItemPointer)bsearch((void*)itemptr,
29292946
(void*)dead_tuples->itemptrs,
29302947
dead_tuples->num_tuples,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp