Skip to content

Commit

Permalink
sql: fix JSON fetch value operator evaluation
Browse files Browse the repository at this point in the history
This commit fixes incorrect evaluation of the JSON fetch value operator,
`->`. There were two bugs causing incorrect evaluation.

The first issue was a result of optimizer normalization rules that
produced unequivalent scalar expressions when converting `->` to `@>`.
The rules would convert expressions like `j -> '"a"' = 1` to
`j @> '{"a": 1}'`. This is invalid because `->` results in `NULL` when
the LHS does not contain the RHS key, but the resulting `@>` expression
is always either `true` or `false`, never `NULL`. These normalization
rules have been removed.

These two rules existed to provide inverted index-acceleration for
queries with `->`, because the optimizer can only index-accerlate `@>`
operators during exploration. As a result of their removal, queries with
`->` operators are no longer index-accelerated. This will be remedied in
a future commit.

The second issue was a bug in the vectorized overload of the `->`
operator. Previously, when the operator evaluated to `NULL` with two
non-`NULL` inputs, the resulting `NULL` would not be tracked by the
`Nulls` struct.

Fixes cockroachdb#49143

Release note (bug fix): Previously, the JSON fetch value operator, `->`,
would evaluate incorrectly in some cases. This has been fixed.
  • Loading branch information
mgartner committed Oct 9, 2020
1 parent 5784427 commit c176b31
Show file tree
Hide file tree
Showing 12 changed files with 17,781 additions and 2,102 deletions.
5 changes: 4 additions & 1 deletion pkg/sql/colexec/execgen/cmd/execgen/overloads_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,11 @@ func executeBinOpOnDatums(prelude, targetElem, leftColdataExtDatum, rightDatumEl
if err != nil {
colexecerror.ExpectedError(err)
}
if _res == tree.DNull {
_outNulls.SetNull(%s)
}
%s
`, prelude, leftColdataExtDatum, rightDatumElem,
`, prelude, leftColdataExtDatum, rightDatumElem, idxVariable,
set(typeconv.DatumVecCanonicalTypeFamily, vecVariable, idxVariable, "_res"),
)
}
Expand Down
144 changes: 128 additions & 16 deletions pkg/sql/colexec/like_ops.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c176b31

Please sign in to comment.