Skip to content

Commit 4c8ad67

Browse files
nbtree: Use only one notnullkey ScanKeyData.
_bt_first need only store one ScanKeyData struct on the stack for the purposes of building an IS NOT NULL key based on an implied NOT NULL constraint. We don't need INDEX_MAX_KEYS-many ScanKeyData structs. This saves us a little over 2KB in stack space. It's possible that this has some performance benefit. It also seems simpler and more direct. It isn't possible for more than a single index attribute to need its own implied IS NOT NULL key: the first such attribute/IS NOT NULL key always makes _bt_first stop adding additional boundary keys to startKeys[]. Using INDEX_MAX_KEYS-many ScanKeyData entries was (at best) misleading. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Mircea Cadariu <cadariu.mircea@gmail.com> Discussion: https://postgr.es/m/CAH2-Wzm=1kJMSZhhTLoM5BPbwQNWxUj-ynOEh=89ptDZAVgauw@mail.gmail.com
1 parent 48c2c7b commit 4c8ad67

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/backend/access/nbtree/nbtsearch.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
892892
OffsetNumber offnum;
893893
BTScanInsertData inskey;
894894
ScanKey startKeys[INDEX_MAX_KEYS];
895-
ScanKeyData notnullkeys[INDEX_MAX_KEYS];
895+
ScanKeyData notnullkey;
896896
int keysz = 0;
897-
StrategyNumber strat_total;
897+
StrategyNumber strat_total = InvalidStrategy;
898898
BlockNumber blkno = InvalidBlockNumber,
899899
lastcurrblkno;
900900

@@ -1034,7 +1034,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
10341034
* need to be kept in sync.
10351035
*----------
10361036
*/
1037-
strat_total = BTEqualStrategyNumber;
10381037
if (so->numberOfKeys > 0)
10391038
{
10401039
AttrNumber curattr;
@@ -1122,16 +1121,15 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
11221121
ScanDirectionIsForward(dir) :
11231122
ScanDirectionIsBackward(dir)))
11241123
{
1125-
/* Yes, so build the key in notnullkeys[keysz] */
1126-
bkey = &notnullkeys[keysz];
1124+
/* Final startKeys[] entry will be deduced NOT NULL key */
1125+
bkey = &notnullkey;
11271126
ScanKeyEntryInitialize(bkey,
11281127
(SK_SEARCHNOTNULL | SK_ISNULL |
11291128
(impliesNN->sk_flags &
11301129
(SK_BT_DESC | SK_BT_NULLS_FIRST))),
11311130
curattr,
1132-
((impliesNN->sk_flags & SK_BT_NULLS_FIRST) ?
1133-
BTGreaterStrategyNumber :
1134-
BTLessStrategyNumber),
1131+
ScanDirectionIsForward(dir) ?
1132+
BTGreaterStrategyNumber : BTLessStrategyNumber,
11351133
InvalidOid,
11361134
InvalidOid,
11371135
InvalidOid,

0 commit comments

Comments
 (0)