nbtree: Remove useless 'strat' local variable.
authorPeter Geoghegan
Mon, 4 Nov 2024 16:04:30 +0000 (11:04 -0500)
committerPeter Geoghegan
Mon, 4 Nov 2024 16:04:30 +0000 (11:04 -0500)
Remove a local variable that was used to avoid overwriting strat_total
with the = operator strategy when a >= operator strategy key was already
included in the initial positioning/insertion scan keys by _bt_first
(for backwards scans it would have to be a <= key that was included).
_bt_first's strat_total local variable now simply tracks the operator
strategy of the final scan key that was included in the scan's insertion
scan key (barring the case where the !used_all_subkeys row compare path
adjusts strat_total in its own way).

_bt_first already treated >= keys (or <= keys) as = keys for initial
positioning purposes.  There is no good reason to remember that that was
what happened; no later _bt_first step cares about the distinction.
Note, in particular, that the insertion scan key's 'nextkey' and
'backward' fields will be initialized the same way regardless.

Author: Peter Geoghegan 
Reviewed-By: Tomas Vondra
Discussion: https://postgr.es/m/CAH2-Wz=PKR6rB7qbx+Vnd7eqeB5VTcrW=iJvAsTsKbdG+kW_UA@mail.gmail.com

src/backend/access/nbtree/nbtsearch.c

index 177bc226aaf7c7532255b8299d101c850a64eed5..d6023732c9bcdc7fa1386d27b1ed24700f1ac2a0 100644 (file)
@@ -883,7 +883,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
    BTScanOpaque so = (BTScanOpaque) scan->opaque;
    BTStack     stack;
    OffsetNumber offnum;
-   StrategyNumber strat;
    BTScanInsertData inskey;
    ScanKey     startKeys[INDEX_MAX_KEYS];
    ScanKeyData notnullkeys[INDEX_MAX_KEYS];
@@ -1090,18 +1089,11 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                    break;
                startKeys[keysz++] = chosen;
 
-               /*
-                * Adjust strat_total, and quit if we have stored a > or <
-                * key.
-                */
-               strat = chosen->sk_strategy;
-               if (strat != BTEqualStrategyNumber)
-               {
-                   strat_total = strat;
-                   if (strat == BTGreaterStrategyNumber ||
-                       strat == BTLessStrategyNumber)
-                       break;
-               }
+               /* Quit if we have stored a > or < key */
+               strat_total = chosen->sk_strategy;
+               if (strat_total == BTGreaterStrategyNumber ||
+                   strat_total == BTLessStrategyNumber)
+                   break;
 
                /*
                 * Done if that was the last attribute, or if next key is not