-
Notifications
You must be signed in to change notification settings - Fork 4.1k
opt: type NullExprs in binary operators #85135
Copy link
Copy link
Open
Labels
C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)E-quick-winLikely to be a quick win for someone experienced.Likely to be a quick win for someone experienced.T-sql-queriesSQL Queries TeamSQL Queries Team
Description
Notice this comment in optbuilder:
cockroach/pkg/sql/opt/optbuilder/scalar.go
Lines 211 to 224 in 4df883b
| case *tree.BinaryExpr: | |
| // It's possible for an overload to be selected that expects different | |
| // types than the TypedExpr arguments return: | |
| // | |
| // ARRAY[1, 2] || NULL | |
| // | |
| // This is a tricky case, because the type checker selects []int as the | |
| // type of the right argument, but then types it as unknown. This causes | |
| // issues for the execbuilder, which doesn't have enough information to | |
| // select the right overload. The solution is to wrap any mismatched | |
| // arguments with a CastExpr that preserves the static type. | |
| left := reType(t.TypedLeft(), t.ResolvedBinOp().LeftType) | |
| right := reType(t.TypedRight(), t.ResolvedBinOp().RightType) |
It sounds like we could avoid these casts entirely if we attached t.ResolvedBinOp().[Left|Right]Type to the possible NullExprs constructed in b.buildScalar below this comment. If the Null was typed, then execbuilder should be able to determine the correct overload.
Jira issue: CRDB-18056
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)E-quick-winLikely to be a quick win for someone experienced.Likely to be a quick win for someone experienced.T-sql-queriesSQL Queries TeamSQL Queries Team
Type
Projects
Status
Backlog