Skip to content

fix(function): treat BOOL as 1/0 next to FLOAT/DOUBLE in arithmetic and comparison - #31296

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/double-bool-arith
Oct 30, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/double-bool-arith

Conversation

@MatrixAdventurer

@MatrixAdventurer MatrixAdventurer commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #31292

What this PR does / why we need it:

Arithmetic and comparison between FLOAT/DOUBLE and BOOL failed to bind with bad value [DOUBLE BOOL] / [FLOAT BOOL]. Examples: 1e0 + true, d > b, and nullif(1e0, true), which is lowered to =. MySQL treats TRUE/FALSE as 1/0, so these evaluate as DOUBLE.

Root cause: fixedBinaryCastRule1 / fixedBinaryCastRule2 had BOOL × INT*/UINT* rows but no BOOL × FLOAT32/FLOAT64 rows. The BOOL → FLOAT cast already exists (boolToFloat).

Fix: type_check.go +10 adds BOOL × FLOAT32/FLOAT64 → FLOAT64 in both orders to rule tables 1 (+ - * % and comparisons) and 2 (/ DIV). The rows sit next to the T_any rows, away from the BOOL × DECIMAL rows that #31193 adds, so the two PRs don't conflict.

Evidence

  • UT float_bool_arithmetic_test.go: 13 operators × {FLOAT, DOUBLE} × both orders. RED on main (bad value [FLOAT BOOL]), GREEN with the fix. go test ./pkg/sql/plan/function ./pkg/sql/plan pass.
  • New BVT operator/float_bool_arithmetic.sql: main 6/15, PR 15/15.
  • E2E on a local single node:
query main PR (= MySQL)
1e0 + true bad value [DOUBLE BOOL] 2
1e0 - true, 2e0 * true, 3e0 / true, true + 1e0, true - 2.5e0 error 0 2 3 2 -1.5
1e0 = true, 1e0 > false, 2e0 <> true, true < 2e0, true <=> 1e0 error 1 1 1 1 1
5e0 % true, 5e0 div true, true div 2e0 error 0 5 0
f + b, d - b, d * b, f = b, d > b (f=1.5, d=2.5, b=true) bad value [FLOAT BOOL] 2.5 1.5 2.5 0 1
nullif(1e0, true), nullif(2e0, true) error NULL 2

Merge Danger

Low. This only adds rule rows for type pairs that used to fail to bind. No existing pair changes its resolution.

本操作由 LW 授权的 Grok Bot 智能体执行。

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: b159b634f840dc4c5a4e6942bbd9ecdaf80e86f0

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: b159b634f840dc4c5a4e6942bbd9ecdaf80e86f0

Assessment: approve

Reviewed the complete four-file delta and affected callers. The fix correctly extends the existing coercion tables and reuses established DOUBLE casts and operators. Tests cover binding permutations, SQL results, metadata, NULLs and division by zero. No actionable findings or substantive discussion disputes remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Verified checkout, patch and frozen CI snapshot against the assigned head. CI reports successful build, UT, SCA, coverage, PROXY BVT and COMPOSE/PESSIMISTIC BVT; reviewed package and BVT routing.

  • Static audit passed: exactly eight new coercion cells; all 1,263 existing effective cells remain unchanged. Receipt: checks/1793027901945437359-2.json; retained output: source-evidence-audit.log.

  • Reviewed the 52 binding combinations and four-row SQL fixture, including expected values, metadata, predicates, NULLIF/IN and cleanup.

  • Saved discussion-assessment.json accounting for both informational discussion items, and review-notes.json with design, caller, performance and evidence analysis.

Limitations:

  • No local Go or SQL tests were rerun. Reused frozen candidate CI results; raw per-case CI logs and independently verifiable author execution artifacts were unavailable.

  • The standalone text of issue #31292 was absent; reviewed the concrete reproductions and behavioral contract supplied in the PR.

  • No performance benchmark was run. Existing lookup complexity and table sizes are unchanged; newly accepted expressions use existing vector casts.

@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the BOOL/FLOAT arithmetic and comparison coercion and the associated controls at this commit. I found no blocking issues. I reused the passing CI results and did not run local tests.

@mergify mergify Bot added the queued label Oct 30, 2026
@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

53 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Fri 30 Oct, 11:31 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 12:24 · d4cfbb2

Reason

Pull request #31296 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: FLOAT/DOUBLE arithmetic and comparison with a BOOL operand fail with 'bad value [DOUBLE BOOL]'

4 participants