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

Commitf5ae3ba

Browse files
committed
Make tbm_add_tuples more efficient by caching the last acccessed page.
When adding a large number of tuples to a TID bitmap usingtbm_add_tuples() sometimes a lot of time was spent looking up a page'sentry in the bitmap's internal hashtable.Improve efficiency by caching the last accessed page, while iteratingover the passed in tuples, hoping consecutive tuples will often be onthe same page. In many cases that's a good bet, and in the rest theadded overhead isn't big.Discussion: 54479A85.8060309@sigaev.ruAuthor: Teodor SigaevReviewed-By: David Rowley
1 parentaa1d2fc commitf5ae3ba

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

‎src/backend/nodes/tidbitmap.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,25 +268,33 @@ void
268268
tbm_add_tuples(TIDBitmap*tbm,constItemPointertids,intntids,
269269
boolrecheck)
270270
{
271-
inti;
271+
inti;
272+
PagetableEntry*page=NULL;
272273

273274
Assert(!tbm->iterating);
274275
for (i=0;i<ntids;i++)
275276
{
276277
BlockNumberblk=ItemPointerGetBlockNumber(tids+i);
277278
OffsetNumberoff=ItemPointerGetOffsetNumber(tids+i);
278-
PagetableEntry*page;
279279
intwordnum,
280280
bitnum;
281281

282282
/* safety check to ensure we don't overrun bit array bounds */
283283
if (off<1||off>MAX_TUPLES_PER_PAGE)
284284
elog(ERROR,"tuple offset out of range: %u",off);
285285

286-
if (tbm_page_is_lossy(tbm,blk))
287-
continue;/* whole page is already marked */
288-
289-
page=tbm_get_pageentry(tbm,blk);
286+
if (page==NULL||page->blockno!=blk)
287+
{
288+
if (tbm_page_is_lossy(tbm,blk))
289+
continue;/* whole page is already marked */
290+
291+
/*
292+
* Cache this page as it's quite likely that we'll see the same
293+
* page again in the next iteration. This will save having to
294+
* lookup the page in the hashtable again.
295+
*/
296+
page=tbm_get_pageentry(tbm,blk);
297+
}
290298

291299
if (page->ischunk)
292300
{
@@ -303,7 +311,11 @@ tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids,
303311
page->recheck |=recheck;
304312

305313
if (tbm->nentries>tbm->maxentries)
314+
{
306315
tbm_lossify(tbm);
316+
/* Cached page could become lossy or freed */
317+
page=NULL;
318+
}
307319
}
308320
}
309321

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp