Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/opt/norm: propagate kv errors from cast folding #87614

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/sql/opt/norm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
importpath = "github.com/cockroachdb/cockroach/pkg/sql/opt/norm",
visibility = ["//visibility:public"],
deps = [
"//pkg/roachpb",
"//pkg/sql/catalog/colinfo",
"//pkg/sql/opt",
"//pkg/sql/opt/cat",
Expand Down
19 changes: 19 additions & 0 deletions pkg/sql/opt/norm/fold_constants_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package norm

import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/opt"
"github.com/cockroachdb/cockroach/pkg/sql/opt/cat"
"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
Expand Down Expand Up @@ -369,6 +370,15 @@ func (c *CustomFuncs) FoldCast(input opt.ScalarExpr, typ *types.T) (_ opt.Scalar

result, err := eval.Expr(c.f.evalCtx, texpr)
if err != nil {
// Casts can require KV operations. KV errors are not safe to swallow.
// Check if the error is a KV error, and, if so, propagate it rather
// than swallowing it. See #85677.
// TODO(mgartner): Ideally, casts that can error and cause adverse
// side-effects would be marked as volatile so that they are not folded.
// That would eliminate the need for this special error handling.
if errors.HasInterface(err, (*roachpb.ErrorDetailInterface)(nil)) {
panic(err)
}
return nil, false
}

Expand All @@ -395,6 +405,15 @@ func (c *CustomFuncs) FoldAssignmentCast(
datum := memo.ExtractConstDatum(input)
result, err := eval.PerformAssignmentCast(c.f.evalCtx, datum, typ)
if err != nil {
// Casts can require KV operations. KV errors are not safe to swallow.
// Check if the error is a KV error, and, if so, propagate it rather
// than swallowing it. See #85677.
// TODO(mgartner): Ideally, casts that can error and cause adverse
// side-effects would be marked as volatile so that they are not folded.
// That would eliminate the need for this special error handling.
if errors.HasInterface(err, (*roachpb.ErrorDetailInterface)(nil)) {
panic(err)
}
return nil, false
}

Expand Down