Skip to content

Commit 61dd5f6

Browse files
committed
Use recheck only when it's needed.
1 parent 2aeacb9 commit 61dd5f6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

jsonb_vodka_ops.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -466,19 +466,18 @@ vodkajsonbconsistent(PG_FUNCTION_ARGS)
466466
int32 nkeys = PG_GETARG_INT32(3);
467467
bool *recheck = (bool *) PG_GETARG_POINTER(4);
468468
VodkaKey *queryKeys = (VodkaKey *) PG_GETARG_POINTER(5);
469+
ExtractedNode *root;
469470
bool res;
470471
int32 i;
471472

472473
switch (strategy)
473474
{
474475
case JsonbContainsStrategyNumber:
475-
/* result is not lossy */
476-
*recheck = false;
477-
/* must have all elements in check[] true, and no nulls */
476+
*recheck = true;
478477
res = true;
479478
for (i = 0; i < nkeys; i++)
480479
{
481-
if (!check[i] || queryKeys[i].isnull)
480+
if (!check[i])
482481
{
483482
res = false;
484483
break;
@@ -487,10 +486,12 @@ vodkajsonbconsistent(PG_FUNCTION_ARGS)
487486
break;
488487

489488
case JsQueryMatchStrategyNumber:
489+
root = (ExtractedNode *)queryKeys[0].extra;
490+
*recheck = root->indirect;
490491
if (nkeys == 0)
491492
res = true;
492493
else
493-
res = execRecursive((ExtractedNode *)queryKeys[0].extra, check);
494+
res = execRecursive(root, check);
494495
break;
495496

496497
default:
@@ -516,6 +517,7 @@ vodkajsonbtriconsistent(PG_FUNCTION_ARGS)
516517

517518
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
518519
VodkaKey *queryKeys = (VodkaKey *) PG_GETARG_POINTER(4);
520+
ExtractedNode *root;
519521
VodkaTernaryValue res;
520522
int32 i;
521523

@@ -539,12 +541,13 @@ vodkajsonbtriconsistent(PG_FUNCTION_ARGS)
539541
break;
540542

541543
case JsQueryMatchStrategyNumber:
544+
root = (ExtractedNode *)queryKeys[0].extra;
542545
if (nkeys == 0)
543546
res = GIN_MAYBE;
544547
else
545-
res = execRecursiveTristate((ExtractedNode *)queryKeys[0].extra, check);
548+
res = execRecursiveTristate(root, check);
546549

547-
if (res == GIN_TRUE)
550+
if (root->indirect && res == GIN_TRUE)
548551
res = GIN_MAYBE;
549552

550553
break;

0 commit comments

Comments
 (0)