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

Commit606c012

Browse files
Reduce btree scan overhead for < and > strategies
For <, <=, > and >= strategies, mark the first scan keyas already matched if scanning in an appropriate direction.If index tuple contains no nulls we can skip the firstre-check for each tuple.Author: Rajeev RastogiReviewer: Haribabu KommiRework of the code and comments by Simon Riggs
1 parentdedae6c commit606c012

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,33 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
996996
if (goback)
997997
offnum=OffsetNumberPrev(offnum);
998998

999+
/*
1000+
* By here the scan position is now set for the first key. If all
1001+
* further tuples are expected to match we set the SK_BT_MATCHED flag
1002+
* to avoid re-checking the scan key later. This is a big win for
1003+
* slow key matches though is still significant even for fast datatypes.
1004+
*/
1005+
switch (startKeys[0]->sk_strategy)
1006+
{
1007+
caseBTEqualStrategyNumber:
1008+
break;
1009+
1010+
caseBTGreaterEqualStrategyNumber:
1011+
caseBTGreaterStrategyNumber:
1012+
if (ScanDirectionIsForward(dir))
1013+
startKeys[0]->sk_flags |=SK_BT_MATCHED;
1014+
break;
1015+
1016+
caseBTLessEqualStrategyNumber:
1017+
caseBTLessStrategyNumber:
1018+
if (ScanDirectionIsBackward(dir))
1019+
startKeys[0]->sk_flags |=SK_BT_MATCHED;
1020+
break;
1021+
1022+
default:
1023+
break;
1024+
}
1025+
9991026
/*
10001027
* Now load data from the first page of the scan.
10011028
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,13 @@ _bt_checkkeys(IndexScanDesc scan,
14291429
boolisNull;
14301430
Datumtest;
14311431

1432+
/*
1433+
* If the scan key has already matched we can skip this key, as
1434+
* long as the index tuple does not contain NULL values.
1435+
*/
1436+
if (key->sk_flags&SK_BT_MATCHED&& !IndexTupleHasNulls(tuple))
1437+
continue;
1438+
14321439
/* row-comparison keys need special processing */
14331440
if (key->sk_flags&SK_ROW_HEADER)
14341441
{

‎src/include/access/nbtree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ typedef BTScanOpaqueData *BTScanOpaque;
618618
*/
619619
#defineSK_BT_REQFWD0x00010000/* required to continue forward scan */
620620
#defineSK_BT_REQBKWD0x00020000/* required to continue backward scan */
621+
#defineSK_BT_MATCHED0x00040000/* required to skip further key match */
621622
#defineSK_BT_INDOPTION_SHIFT 24/* must clear the above bits */
622623
#defineSK_BT_DESC(INDOPTION_DESC << SK_BT_INDOPTION_SHIFT)
623624
#defineSK_BT_NULLS_FIRST(INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp