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

Commitcefcbbf

Browse files
committed
Push the responsibility for handling ignore_killed_tuples down into
_bt_checkkeys(), instead of checking it in the top-level nbtree.c routinesas formerly. This saves a little bit of loop overhead, but more importantlyit lets us skip performing the index key comparisons for dead tuples.
1 parentf1b059a commitcefcbbf

File tree

4 files changed

+72
-72
lines changed

4 files changed

+72
-72
lines changed

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

Lines changed: 3 additions & 38 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.134 2005/11/22 18:17:06 momjian Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.135 2005/12/07 19:37:53 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -288,21 +288,6 @@ btgettuple(PG_FUNCTION_ARGS)
288288
else
289289
res=_bt_first(scan,dir);
290290

291-
/*
292-
* Skip killed tuples if asked to.
293-
*/
294-
if (scan->ignore_killed_tuples)
295-
{
296-
while (res)
297-
{
298-
offnum=ItemPointerGetOffsetNumber(&(scan->currentItemData));
299-
page=BufferGetPage(so->btso_curbuf);
300-
if (!ItemIdDeleted(PageGetItemId(page,offnum)))
301-
break;
302-
res=_bt_next(scan,dir);
303-
}
304-
}
305-
306291
/*
307292
* Save heap TID to use it in _bt_restscan. Then release the read lock on
308293
* the buffer so that we aren't blocking other backends.
@@ -353,25 +338,6 @@ btgetmulti(PG_FUNCTION_ARGS)
353338
res=_bt_next(scan,ForwardScanDirection);
354339
else
355340
res=_bt_first(scan,ForwardScanDirection);
356-
357-
/*
358-
* Skip killed tuples if asked to.
359-
*/
360-
if (scan->ignore_killed_tuples)
361-
{
362-
while (res)
363-
{
364-
Pagepage;
365-
OffsetNumberoffnum;
366-
367-
offnum=ItemPointerGetOffsetNumber(&(scan->currentItemData));
368-
page=BufferGetPage(so->btso_curbuf);
369-
if (!ItemIdDeleted(PageGetItemId(page,offnum)))
370-
break;
371-
res=_bt_next(scan,ForwardScanDirection);
372-
}
373-
}
374-
375341
if (!res)
376342
break;
377343
/* Save tuple ID, and continue scanning */
@@ -385,9 +351,8 @@ btgetmulti(PG_FUNCTION_ARGS)
385351
*/
386352
if (res)
387353
{
388-
((BTScanOpaque)scan->opaque)->curHeapIptr=scan->xs_ctup.t_self;
389-
LockBuffer(((BTScanOpaque)scan->opaque)->btso_curbuf,
390-
BUFFER_LOCK_UNLOCK);
354+
so->curHeapIptr=scan->xs_ctup.t_self;
355+
LockBuffer(so->btso_curbuf,BUFFER_LOCK_UNLOCK);
391356
}
392357

393358
*returned_tids=ntids;

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.98 2005/12/0718:03:48 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.99 2005/12/0719:37:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -423,8 +423,6 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
423423
Pagepage;
424424
OffsetNumberoffnum;
425425
ItemPointercurrent;
426-
BTItembtitem;
427-
IndexTupleitup;
428426
BTScanOpaqueso;
429427
boolcontinuescan;
430428

@@ -445,13 +443,10 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
445443
/* current is the next candidate tuple to return */
446444
offnum=ItemPointerGetOffsetNumber(current);
447445
page=BufferGetPage(buf);
448-
btitem= (BTItem)PageGetItem(page,PageGetItemId(page,offnum));
449-
itup=&btitem->bti_itup;
450446

451-
if (_bt_checkkeys(scan,itup,dir,&continuescan))
447+
if (_bt_checkkeys(scan,page,offnum,dir,&continuescan))
452448
{
453449
/* tuple passes all scan key conditions, so return it */
454-
scan->xs_ctup.t_self=itup->t_tid;
455450
return true;
456451
}
457452

@@ -485,8 +480,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
485480
Pagepage;
486481
BTStackstack;
487482
OffsetNumberoffnum;
488-
BTItembtitem;
489-
IndexTupleitup;
490483
ItemPointercurrent;
491484
BlockNumberblkno;
492485
StrategyNumberstrat;
@@ -848,14 +841,11 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
848841
/* okay, current item pointer for the scan is right */
849842
offnum=ItemPointerGetOffsetNumber(current);
850843
page=BufferGetPage(buf);
851-
btitem= (BTItem)PageGetItem(page,PageGetItemId(page,offnum));
852-
itup=&btitem->bti_itup;
853844

854845
/* is the first item actually acceptable? */
855-
if (_bt_checkkeys(scan,itup,dir,&continuescan))
846+
if (_bt_checkkeys(scan,page,offnum,dir,&continuescan))
856847
{
857848
/* yes, return it */
858-
scan->xs_ctup.t_self=itup->t_tid;
859849
res= true;
860850
}
861851
elseif (continuescan)
@@ -1215,8 +1205,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
12151205
OffsetNumbermaxoff;
12161206
OffsetNumberstart;
12171207
BlockNumberblkno;
1218-
BTItembtitem;
1219-
IndexTupleitup;
12201208
BTScanOpaqueso;
12211209
boolres;
12221210
boolcontinuescan;
@@ -1284,16 +1272,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
12841272
page=BufferGetPage(buf);
12851273
}
12861274

1287-
btitem= (BTItem)PageGetItem(page,PageGetItemId(page,start));
1288-
itup=&(btitem->bti_itup);
1289-
12901275
/*
12911276
* Okay, we are on the first or last tuple. Does it pass all the quals?
12921277
*/
1293-
if (_bt_checkkeys(scan,itup,dir,&continuescan))
1278+
if (_bt_checkkeys(scan,page,start,dir,&continuescan))
12941279
{
12951280
/* yes, return it */
1296-
scan->xs_ctup.t_self=itup->t_tid;
12971281
res= true;
12981282
}
12991283
elseif (continuescan)

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

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.66 2005/11/22 18:17:06 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.67 2005/12/07 19:37:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -477,30 +477,77 @@ _bt_preprocess_keys(IndexScanDesc scan)
477477
/*
478478
* Test whether an indextuple satisfies all the scankey conditions.
479479
*
480+
* If so, copy its TID into scan->xs_ctup.t_self, and return TRUE.
481+
* If not, return FALSE (xs_ctup is not changed).
482+
*
480483
* If the tuple fails to pass the qual, we also determine whether there's
481484
* any need to continue the scan beyond this tuple, and set *continuescan
482485
* accordingly. See comments for _bt_preprocess_keys(), above, about how
483486
* this is done.
487+
*
488+
* scan: index scan descriptor
489+
* page: buffer page containing index tuple
490+
* offnum: offset number of index tuple (must be a valid item!)
491+
* dir: direction we are scanning in
492+
* continuescan: output parameter (will be set correctly in all cases)
484493
*/
485494
bool
486-
_bt_checkkeys(IndexScanDescscan,IndexTupletuple,
495+
_bt_checkkeys(IndexScanDescscan,
496+
Pagepage,OffsetNumberoffnum,
487497
ScanDirectiondir,bool*continuescan)
488498
{
489-
BTScanOpaqueso= (BTScanOpaque)scan->opaque;
490-
intkeysz=so->numberOfKeys;
491-
intikey;
499+
ItemIdiid=PageGetItemId(page,offnum);
500+
booltuple_valid;
501+
BTItembtitem;
502+
IndexTupletuple;
492503
TupleDesctupdesc;
504+
BTScanOpaqueso;
505+
intkeysz;
506+
intikey;
493507
ScanKeykey;
494508

495-
*continuescan= true;
509+
*continuescan= true;/* default assumption */
510+
511+
/*
512+
* If the scan specifies not to return killed tuples, then we treat
513+
* a killed tuple as not passing the qual. Most of the time, it's a
514+
* win to not bother examining the tuple's index keys, but just return
515+
* immediately with continuescan = true to proceed to the next tuple.
516+
* However, if this is the last tuple on the page, we should check
517+
* the index keys to prevent uselessly advancing to the next page.
518+
*/
519+
if (scan->ignore_killed_tuples&&ItemIdDeleted(iid))
520+
{
521+
/* return immediately if there are more tuples on the page */
522+
if (ScanDirectionIsForward(dir))
523+
{
524+
if (offnum<PageGetMaxOffsetNumber(page))
525+
return false;
526+
}
527+
else
528+
{
529+
BTPageOpaqueopaque= (BTPageOpaque)PageGetSpecialPointer(page);
530+
531+
if (offnum>P_FIRSTDATAKEY(opaque))
532+
return false;
533+
}
534+
/*
535+
* OK, we want to check the keys, but we'll return FALSE even
536+
* if the tuple passes the key tests.
537+
*/
538+
tuple_valid= false;
539+
}
540+
else
541+
tuple_valid= true;
496542

497-
/* If no keys, always scan the whole index */
498-
if (keysz==0)
499-
return true;
543+
btitem= (BTItem)PageGetItem(page,iid);
544+
tuple=&btitem->bti_itup;
500545

501546
IncrIndexProcessed();
502547

503548
tupdesc=RelationGetDescr(scan->indexRelation);
549+
so= (BTScanOpaque)scan->opaque;
550+
keysz=so->numberOfKeys;
504551

505552
for (key=so->keyData,ikey=0;ikey<keysz;key++,ikey++)
506553
{
@@ -592,6 +639,9 @@ _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple,
592639
}
593640
}
594641

595-
/* If we get here, the tuple passes all quals. */
596-
return true;
642+
/* If we get here, the tuple passes all index quals. */
643+
if (tuple_valid)
644+
scan->xs_ctup.t_self=tuple->t_tid;
645+
646+
returntuple_valid;
597647
}

‎src/include/access/nbtree.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.88 2005/11/06 19:29:01 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.89 2005/12/07 19:37:53 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -467,8 +467,9 @@ extern ScanKey _bt_mkscankey_nodata(Relation rel);
467467
externvoid_bt_freeskey(ScanKeyskey);
468468
externvoid_bt_freestack(BTStackstack);
469469
externvoid_bt_preprocess_keys(IndexScanDescscan);
470-
externbool_bt_checkkeys(IndexScanDescscan,IndexTupletuple,
471-
ScanDirectiondir,bool*continuescan);
470+
externbool_bt_checkkeys(IndexScanDescscan,
471+
Pagepage,OffsetNumberoffnum,
472+
ScanDirectiondir,bool*continuescan);
472473
externBTItem_bt_formitem(IndexTupleitup);
473474

474475
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp