Skip to content

Commit

Permalink
Merge #84622
Browse files Browse the repository at this point in the history
84622: rowenc: fix recent bugs with DOidWrappers and inverted indexes r=yuzefovich a=yuzefovich

Previously, we were using the passed-in datum asserting that it is
a `DString` whereas it could be a `DOidWrapper`, and this is now fixed.

Fixes: #84569.

Release note: None (no stable release with the bugs)

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Jul 19, 2022
2 parents 6b61196 + f3c7866 commit 5e53f01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/inverted_index
Original file line number Diff line number Diff line change
Expand Up @@ -1686,3 +1686,8 @@ SELECT primes FROM cb WHERE primes && numbers ORDER BY primes
{2,3}
{2,3}
{2,3,5}

# Regression test for incorrectly unwrapping a DOidWrapper (#84569).
statement ok
CREATE TABLE t84569 (name_col NAME NOT NULL, INVERTED INDEX (name_col gin_trgm_ops DESC));
INSERT INTO t84569 (name_col) VALUES ('X'::NAME)
8 changes: 6 additions & 2 deletions pkg/sql/rowenc/index_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ func EncodeInvertedIndexTableKeys(
// need to pass in the inverted index column kind to this function.
// We pad the keys when writing them to the index.
// TODO(jordan): why are we doing this padding at all? Postgres does it.
return encodeTrigramInvertedIndexTableKeys(string(*val.(*tree.DString)), inKey, version, true /* pad */)
// val could be a DOidWrapper, so we need to use the unwrapped datum
// here.
return encodeTrigramInvertedIndexTableKeys(string(*datum.(*tree.DString)), inKey, version, true /* pad */)
}
return nil, errors.AssertionFailedf("trying to apply inverted index to unsupported type %s", datum.ResolvedType())
}
Expand Down Expand Up @@ -672,7 +674,9 @@ func EncodeExistsInvertedIndexSpans(
datum := eval.UnwrapDatum(evalCtx, val)
switch val.ResolvedType().Family() {
case types.StringFamily:
s := string(*val.(*tree.DString))
// val could be a DOidWrapper, so we need to use the unwrapped datum
// here.
s := string(*datum.(*tree.DString))
return json.EncodeExistsInvertedIndexSpans(nil /* inKey */, s)
case types.ArrayFamily:
if val.ResolvedType().ArrayContents().Family() != types.StringFamily {
Expand Down

0 comments on commit 5e53f01

Please sign in to comment.