Repository navigation
fix: keep numeric type for CASE/IF/IFNULL/COALESCE mixing BOOL and numeric branches - #32162
Conversation
2689f32 to
96fe6bc
Compare
…meric branches BOOL has no implicit numeric cast, so the common-type resolution of CASE, IF, IFNULL and COALESCE folded every value branch to BOOL when one branch was BOOL and another was numeric, silently returning 0/1 for numeric values. Normalize BOOL value branches to a numeric domain during result-type resolution (BIGINT, or DECIMAL(1,0) when a DECIMAL branch participates) so the result keeps the numeric type and TRUE/FALSE evaluate as 1/0, matching MySQL. Mixtures the numeric domains cannot resolve now raise a resolution error instead of silently folding to BOOL. Also validate declared precision when assigning BOOL to DECIMAL: TRUE requires one integral digit, so targets with width <= scale (e.g. DECIMAL(1,1)) reject it; FALSE/NULL still convert, and explicit CAST keeps its existing clamp behavior. Related to matrixorigin#31200
96fe6bc to
3a9cb01
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 3a9cb017148412db42f4324e54655e6f922bd1f1
Assessment: approve
The BOOL/numeric fix preserves numeric value branches while retaining condition handling, NULLs and existing nonnumeric behavior. A small shared wrapper reuses the authoritative type resolvers and existing casts; the decimal stand-in preserves the required integral digit without unnecessary precision growth. The changed SQL and dependent-query expectations have independent value/type oracles. No actionable correctness, design or required-validation gap remains.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
Reviewed every hunk in all eight changed files, the complete indexed discussion and linked issue #31200, and the affected type-resolution, cast, IFNULL, UNION and window consumers.
-
Reused the supplied exact-head SUCCESS conclusions for shared build, Ubuntu UT, arm64 SCA, UT coverage and compose BVT. Skipped/neutral lanes were not counted as passes; selections and times are retained in evidence-reuse.json.
-
PR-reported focused seven-root tests, function/plan package checks, dependent-stage regression and SQL BVT results were assessed as attributed evidence, not local executions.
-
Local bounded frozen-source audit passed: exact HEAD, clean checkout, eight-file coverage, matching supplied diff apart from terminal line termination, unchanged baseline cast implementation, git diff --check and complete discussion-key coverage. See frozen-audit.log and the matching checks receipt.
Limitations:
-
No local Go/native build or SQL execution was performed. The supplied CI snapshot provides conclusions rather than raw CI logs; local_validation is empty.
-
The author's reported unrelated JDBC metadata-width differences on both baseline and candidate were not independently reproduced. Source review and changed-path evidence establish no corresponding regression.
|
@Mergifyio queue |
🚫 Left the queue · pull request dequeued2 h 49 min in the queue, with no time running CI. So far
Reason Pull request #32162 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
Related to #31200
What this PR does / why we need it:
Problem
CASE,IF,IFNULLandCOALESCEsilently folded numeric value branches to0/1when another branch wasBOOL:Root cause:
BOOLhas no implicit numeric cast infixedCanImplicitCastRule, so the only common type every value branch could reach incaseCheck/iffCheck/coalesceCheckwasBOOL, and the numeric branches were cast toBOOL.IFNULLis lowered toCASE, so all four constructs shared the defect.Change
pkg/sql/plan/function/operatorSet.go(caseCheck/iffCheck+ shared wrapper): BOOL value branches are normalized to a numeric domain before common-type resolution — BIGINT, or DECIMAL(1,0) when a DECIMAL branch participates (TRUE/FALSE need only one integral digit). The result keeps the numeric type and TRUE/FALSE evaluate as 1/0, matching MySQL. A mixture the numeric domains cannot resolve (e.g. plan-internal DECIMAL(76,76) + BOOL) now returns a resolution error instead of silently folding to BOOL. Non-numeric mixtures (BIT, strings, dates) keep the original resolution path, and BOOL-only branches keep BOOL semantics.pkg/sql/plan/function/func_binary.go(coalesceCheck): delegates to the same wrapper.invalid input: 1 beyond the range, can't be converted to Decimal64(1,1).; FALSE/NULL always convert; explicitCAST(bool AS DECIMAL(M,N))keeps its clamp behavior,CAST(true AS DECIMAL(1,1))= 0.9) is already onmainvia fix(function): support DECIMAL arithmetic and comparison with BOOL operands #31937 and fix(sql): enforce DECIMAL width for integer assignments (#30367) #30639. This PR's diff therefore no longer touchespkg/sql/plan/function/func_cast.go; the UT/BVT below keep covering that contract end to end.Tests
New UT
pkg/sql/plan/function/bool_numeric_branch_test.go: common-type resolution for all four constructs (INT/DOUBLE/DECIMAL × BOOL, both branch orders, BOOL-only and condition-position controls, BIT/VARCHAR/DATE non-numeric controls), high-scale DECIMAL (65,57)/(65,58)/(76,75), unresolvable (76,76) must error, and BOOL→DECIMAL cast/assignment values and range errors. The new tests fail on the pre-fix code (13 subtests) and pass after.New BVT
test/distributed/cases/function/func_bool_numeric_branches.{sql,result}: literals and nullable columns across all four constructs, both branch orders, high-scale DECIMAL up to the publicly reachable precision 65, and assignment/clamp/error coverage (TRUE into DECIMAL(1,1) rejected via INSERT-SELECT and INSERT-VALUES, FALSE/NULL accepted, explicit CAST clamps to 0.9, failed inserts leave the table unchanged). mo-tester: 47/47 100%.Updated goldens
func_coalesce_1.result(BOOL+INT columns now resolve to INT) andunion_and_union_all.result(int-typed rows under the same shared resolution); values unchanged where the old result was already correct. mo-tester: union_and_union_all 234/234 100%; the edited func_coalesce_1 goldens pass.Commands:
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=1800s ./pkg/sql/plan/function ./pkg/sql/plan→okboth packages;GOWORK=off go vet -mod=readonly ./pkg/sql/plan/function→ clean;golangci-lint run -c .golangci.yml --new-from-rev <merge-base> ./pkg/sql/plan/function→ 0 issues; live-node SQL verification of the issue's exact queries.After the 2026-11-04 rebase onto
main(52cbba7): semantic conflict resolution inoperatorSet.go/func_binary.go(the wrapper now composes with the low-precision-float widening from feat: low-precision float types bf16/float16/float8/float4 and vecf8/vecf4 vector columns (#20567) #29554 and the ENUM/JSON condition handling from fix(plan): MySQL implicit boolean semantics for ENUM/SET, BIT literals and JSON conditions #31492);func_cast.goconflicts resolved by takingmain's already-merged BOOL→DECIMAL support, making the file identical tomain; the new UT'sTestBoolToDecimalCastrenamed toTestBoolToDecimalCastAndClamp(name already used by fix(function): support DECIMAL arithmetic and comparison with BOOL operands #31937'sdecimal_bool_operand_test.go). Re-validated:mo-cgo-test -count=1 -v -run 'TestBoolNumericValueBranchesResolveToNumeric|TestBoolDecimalHighScaleValueBranches|TestBoolDecimalUnresolvableDoesNotFoldToBool|TestBoolNonNumericValueBranchesUnchanged|TestBoolToDecimalCastAndClamp|TestBoolToDecimalAssignmentRangeCheck|TestBoolToDecimalAssignmentValues' ./pkg/sql/plan/function→ 7/7 pass; fullpkg/sql/plan/functionpackage suite →ok33s;go vetwith the repository CGo environment → clean;golangci-lint --new-from-rev 52cbba793b→ 0 issues.After CI on the rebased head,
TestDependentNativeStagesinpkg/sql/compile(from fix(plan): support complex non-equality scalar aggregates #31275) failed in UT Coverage: itsrange_row_operand_{skipped,selected_one,uncorrelated,deep_guard}oracles still assumedCASE WHEN <bool> THEN <bool row comparison> ELSE 0 ENDresolves to BOOL. Under this PR's intended semantics the result is numeric, so the expected values are now1/0(matching MySQL). Only the four expectation strings changed;range_row_operand_inner_case/range_row_operand_coalescestay BOOL and keeptrue/false. Local:mo-cgo-test -count=1 -run 'TestDependentNativeStages' ./pkg/sql/compile→ok.Residual risk / notes
func_coalesce_1shows 22 additional failures that are display-width metadata drift only (e.g.[12,-1,0]vs[12,25,0]); the identical failure set occurs with the unmodified base build in that environment, every value row is byte-identical, and the affected statements include pureselect * from t1scans this change cannot influence. CI-generated goldens should not be affected.DECIMAL(M)at M ≤ 65; it is covered by UT only. The public boundary (scales 57/58/65) is covered by BVT.