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

Commit779fdcd

Browse files
committed
Improve new caching logic in tbm_add_tuples().
For no significant extra complexity, we can cache knowledge that thetarget page is lossy, and save a hash_search per iteration in thatcase as well. This probably makes little difference, since the extrarechecks that must occur when pages are lossy are way more expensivethan anything we can save here ... but we might as well do it if we'regoing to cache anything.
1 parentf5ae3ba commit779fdcd

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

‎src/backend/nodes/tidbitmap.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ void
268268
tbm_add_tuples(TIDBitmap*tbm,constItemPointertids,intntids,
269269
boolrecheck)
270270
{
271-
inti;
272-
PagetableEntry*page=NULL;
271+
BlockNumbercurrblk=InvalidBlockNumber;
272+
PagetableEntry*page=NULL;/* only valid when currblk is valid */
273+
inti;
273274

274275
Assert(!tbm->iterating);
275276
for (i=0;i<ntids;i++)
@@ -283,19 +284,23 @@ tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids,
283284
if (off<1||off>MAX_TUPLES_PER_PAGE)
284285
elog(ERROR,"tuple offset out of range: %u",off);
285286

286-
if (page==NULL||page->blockno!=blk)
287+
/*
288+
* Look up target page unless we already did. This saves cycles when
289+
* the input includes consecutive tuples on the same page, which is
290+
* common enough to justify an extra test here.
291+
*/
292+
if (blk!=currblk)
287293
{
288294
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);
295+
page=NULL;/* remember page is lossy */
296+
else
297+
page=tbm_get_pageentry(tbm,blk);
298+
currblk=blk;
297299
}
298300

301+
if (page==NULL)
302+
continue;/* whole page is already marked */
303+
299304
if (page->ischunk)
300305
{
301306
/* The page is a lossy chunk header, set bit for itself */
@@ -313,8 +318,8 @@ tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids,
313318
if (tbm->nentries>tbm->maxentries)
314319
{
315320
tbm_lossify(tbm);
316-
/*Cached pagecouldbecomelossy or freed */
317-
page=NULL;
321+
/*Pagecouldhave been converted tolossy, so force new lookup */
322+
currblk=InvalidBlockNumber;
318323
}
319324
}
320325
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp