Repository navigation
fix(plan): only rewrite integer literals 0/1 to BOOL in comparisons - #31299
Conversation
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: 916906d18c767f0d827ec7ba1bb437dc0350077d
Assessment: approve
Reviewed the complete four-file delta and surrounding comparison, IN and cast paths. The guard restores numeric comparison semantics through the existing coercion owner while preserving 0/1 predicates and logical truth conversion. Tests cover public SQL behavior, NULLs and compatibility. No actionable findings or substantive discussion disputes remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
Validation:
-
Reused frozen-head evidence reporting successful Ubuntu UT, UT coverage, PROXY BVT and COMPOSE PESSIMISTIC BVT.
-
Source identity, patch consistency, formatting and discussion-accounting audit passed: checks/1793034271672807432-2.json matches source-evidence-audit-v2.log and the assessed head. Artifacts are under /home/xupeng/.local/state/mo-bot/jobs/adcb6328844264062b50b7c2/attempt-1.
-
Saved discussion-assessment.json covering both informational comments exactly once, and review-evidence.json recording design, caller, boundary and performance analysis.
Limitations:
-
No local Go/SQL tests were repeated. Supplied CI evidence contains job outcomes, not per-case logs; author-reported execution counts were not independently verified.
-
Corrected comparisons can incur the existing BOOL-to-BIGINT cast cost; performance was not benchmarked. Ordinary 0/1 and logical paths retain existing behavior.
-
Issue #31295 was assessed through the frozen PR's problem statement; its separate issue body was not supplied.
|
Queued — the merge queue status continues in this comment ↓. |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed the comparison rewrite and its SQL/plan controls at this commit. Restricting BOOL literal normalization to 0/1 preserves the intended comparisons; I found no blocking issues. I reused the passing CI results and did not run local tests.
🚫 Left the queue56 min in the queue, with no time running CI. So far
Reason Pull request #31299 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.
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. Merge conditions: 2 of 3 metThis pull request
The batch, tested in place
Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #31295
What this PR does / why we need it:
Comparing a
BOOLwith an integer literal other than 0/1 silently gave wrong results.b = 2was planned asb = true(EXPLAIN:Filter Cond: (t.b = true)), soWHERE b = 2returned the TRUE rows. Also2 = truereturned 1,b < 2returned 0 for TRUE, and2 in (true)returned 1. In MySQL, TRUE/FALSE are 1/0, so all of these are the other way round.Root cause: for
=,<=>,<,<=,>,>=,<>with a BOOL side,convertValueIntoBoolrewrote every integer literal tovalue != 0. That truth conversion is right for AND/OR/NOT/XOR, but in a comparison only 0 and 1 have the same value as a BOOL.Fix:
build_util.go+7. In the comparison case only literals 0/1 are rewritten, which keepsb = 1/b = 0as a plain BOOL filter. Other literals stay BIGINT and take the existingCAST(b AS BIGINT) <op> literalpath, which column-vs-column comparisons already use. AND/OR/NOT/XOR are unchanged.Evidence
bool_compare_int_literal_test.go:b = 2/-1/100keeps the literal. RED on main (the literal became BOOL), GREEN with the fix. 0/1 are still rewritten, and logic operators still truth-convert.go test ./pkg/sql/plan ./pkg/sql/plan/functionpass.operator/bool_compare_int_literal.sql: main 9/15, PR 15/15.2 = true, true = 2, -1 = true, 2 <> true, 2 > true, true < 2, 2 <=> true2 in (true), true in (2, 3)b = 2, b <> 2, b < 2, b >= 2, b > -1for b=trueselect id from t where b = 2... where b < 2 and b > -1b = 1, b = 0, b and 2git merge-treeagainst each is clean. I merged all of them locally (main + fix(function): allow BIT operands in AND/OR/XOR/NOT #31192 + fix(function): treat BOOL as 1/0 next to DECIMAL in arithmetic and comparison #31193 + fix(function): CASE/IF/IFNULL/COALESCE keep numeric type when a branch is BOOL #31201 + all 4 PRs of this batch) and ran every new BVT on that build: all green. With this PR merged,nullif(2, true)also returns 2 instead of NULL.Merge Danger
Medium-low. Results change only for comparisons between BOOL and an integer literal other than 0/1. Those were wrong before, and queries relying on
flag = 2matching TRUE rows would now match nothing, like MySQL. Such filters on a BOOL column now evaluateCAST(b AS BIGINT), the same asb = int_colalready does.