Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ae1f1b

Browse files
authored
Merge pull request #229 from postgrespro/pgpro-5306
[PGPRO-5306] more correct checking of b-tree search strategies
2 parents 2e174ba + 4b0252a commit 4ae1f1b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/pg_pathman.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,14 @@ handle_array(ArrayType *array,
11591159
bool elem_byval;
11601160
char elem_align;
11611161

1162-
/* Check if we can work with this strategy */
1163-
if (strategy == 0)
1162+
/*
1163+
* Check if we can work with this strategy
1164+
* We can work only with BTLessStrategyNumber, BTLessEqualStrategyNumber,
1165+
* BTEqualStrategyNumber, BTGreaterEqualStrategyNumber and BTGreaterStrategyNumber.
1166+
* If new search strategies appear in the future, then access optimizations from
1167+
* this function will not work, and the default behavior (handle_array_return:) will work.
1168+
*/
1169+
if (strategy == InvalidStrategy || strategy > BTGreaterStrategyNumber)
11641170
goto handle_array_return;
11651171

11661172
/* Get element's properties */
@@ -1177,8 +1183,12 @@ handle_array(ArrayType *array,
11771183
List *ranges;
11781184
int i;
11791185

1180-
/* This is only for paranoia's sake */
1181-
Assert(BTMaxStrategyNumber == 5 && BTEqualStrategyNumber == 3);
1186+
/* This is only for paranoia's sake (checking correctness of following take_min calculation) */
1187+
Assert(BTEqualStrategyNumber == 3
1188+
&& BTLessStrategyNumber < BTEqualStrategyNumber
1189+
&& BTLessEqualStrategyNumber < BTEqualStrategyNumber
1190+
&& BTGreaterEqualStrategyNumber > BTEqualStrategyNumber
1191+
&& BTGreaterStrategyNumber > BTEqualStrategyNumber);
11821192

11831193
/* Optimizations for <, <=, >=, > */
11841194
if (strategy != BTEqualStrategyNumber)

0 commit comments

Comments
 (0)