Skip to content

opt: type NullExprs in binary operators #85135

@mgartner

Description

@mgartner

Notice this comment in optbuilder:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)E-quick-winLikely to be a quick win for someone experienced.T-sql-queriesSQL Queries Team

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions