Repository navigation
sql/plan: support BIT columns in AND/OR/XOR/NOT - #31682
Conversation
BIT columns failed plan binding in logical operators ([BIT BOOL]/[BIT] errors) because AND/OR/XOR/NOT required an implicit BIT->BOOL conversion that the fixed cast table does not provide, even though the execution layer already implements a truthiness-preserving bit->bool cast. Scope BIT acceptance to the operators' boolean argument positions via the new isLogicalBoolOperand matcher: AND/OR resolve through the shared logicalOperatorTypeCheck and NOT/XOR through logicalFixedTypeMatch, both identical to the prior resolution for every non-BIT input. The global implicit-cast table is unchanged, so CASE/IF/COALESCE result typing keeps its base behavior: mixed BIT/BOOL value branches stay plan-time errors instead of collapsing non-zero BIT values to TRUE. Covered by new unit tests (operand acceptance, exact non-BIT parity, cast table scoping, conditional-resolver guards, bit->bool truthiness incl. BIT(64) high bit) and a 34-statement BVT case reproducing the issue SQL. Related to matrixorigin#31180
|
Unresolved unrelated CI blockers tracked for this PR:
|
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: 361fbe63244238fb2ecb2c83e57afc49f05b8481
Assessment: approve
BIT acceptance is correctly scoped to logical operands, preserving global casts and conditional result types. No actionable findings remain. Later successful CI checks supersede the historical blocker notice.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
Preflight and native build from frozen inputs passed.
-
Function and planner package suites passed; all five new tests executed successfully.
-
All 34 SQL-case statements passed twice through a single-CN MySQL frontend, plus mixed-type, multiary and prepared-statement controls. Teardown passed after both runs.
-
Global cast-table identity verified against base. All three discussion keys reconciled. validation-summary.json matches retained logs and receipts; source remains unchanged.
Limitations:
-
The frontend probe did not run mo-tester or verify JDBC-specific width/precision formatting; frozen CI reports successful multi-CN BVT checks.
-
Ten unrelated existing tests/subtests were skipped.
🚫 Left the queue11 min in the queue, with no time running CI. So far
Reason Pull request #31682 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:
Related to #31180
What this PR does / why we need it:
A
BITcolumn used as an operand ofAND/OR/XOR/NOT(and&&/||/!) failed at plan time withERROR 20203 (HY000): invalid argument operator and, bad value [BIT BOOL]/... not, bad value [BIT], even though MatrixOne already evaluates BIT values as numbers in boolean contexts (WHERE b,IF(b,1,0)) and ships a truthiness-preservingbit->boolcast at execution. Root cause: the logical operators demanded an implicitBIT->BOOLconversion, but theT_bitrow of the fixed implicit-cast table lists onlyINT64/UINT64, so plan binding failed before execution.Changes
This PR scopes BIT acceptance to the logical operators' boolean argument positions and leaves the global implicit-cast table byte-identical to base, following the existing operator-local matcher precedent (
binTypeMatch,fixedTypeMatchWithBoolNumericCast,inetNtoaTypeMatch):pkg/sql/plan/function/type_check.go— newisLogicalBoolOperand(accepts BOOL, BIT, or anything the fixed cast table converts to BOOL),logicalOperatorTypeCheck(shared multiary checker for AND/OR with the same cost/cast mechanics as the previous per-operator closures, extended with BIT), andlogicalFixedTypeMatch(NOT/XOR: normalizes BIT arguments to BOOL, resolves through the unchangedfixedTypeMatch, and re-targets BIT arguments' cast types to BOOL so execution runs the existingbit->boolcast; non-BIT inputs resolve exactly as before).pkg/sql/plan/function/list_operator.go— NOT/XORcheckFnswapped tologicalFixedTypeMatch; AND/OR tologicalOperatorTypeCheck. No overload, execution, or cast-table changes.Keeping BIT out of the global cast table matters beyond the operators: CASE/IF/COALESCE result typing consumes that table, and a global
BIT->BOOLrule makes BOOL the only type reachable from both BIT and BOOL, silently collapsing conditional value branches (e.g.coalesce(bit8_col, true)returns 1 instead of 128). With the scoped acceptance, mixed BIT/BOOL value branches stay plan-time errors and BIT-only branches keep their values (if/caseresolve nativeT_bit,coalesceresolves its pre-existing basebit->uint64cast).Tests
pkg/sql/plan/function/bit_logical_operators_test.go(5 tests): BIT acceptance in both operand positions and multiary arities incl.&&/||/!and NULL operands; exact non-BIT resolution parity vs the previous matchers; cast-table scoping guards (nobit->bool, nobit->varchar/float/decimal/date,bit->int64@2/bit->uint64@1retained); conditional-resolver guards (9 mixed BIT/BOOL cases reject; bit-onlyif/caseresolveT_bit,coalesceresolvesT_uint64);bit->boolexecution-cast truthiness incl. 128 and the BIT(64) high bit.Command: mo-cgo-test
-mod=readonly -count=1 -run 'TestLogicalOperatorsAcceptBitOperand|TestLogicalOperatorsNonBitOperandsUnchanged|TestBitImplicitCastRulesRemainScoped|TestConditionalResolversDoNotCollapseBitToBool|TestBitToBoolCastTruthiness' -v ./pkg/sql/plan/function/-> 5/5 PASS; plus full./pkg/sql/plan/function/suite PASS and full./pkg/sql/plan/suite PASS.test/distributed/cases/operator/bit_logical_operators.sql(34 statements): the issue's reproduction onBIT(1)/BIT(8)with 0/1/128/NULL, symbolic aliases, three-valued-logic NULL pins, WHERE variants, boolean-context sharing pins (CASE WHEN w AND true,IF(NOT b, ...)), BIT(64) 2^63 and 2^64-1, numeric+0projections, conditional value branches over COALESCE/IF/CASE in both branch orders preserving 128 and the BIT(64) highs (WHERE coalesce(w,b)=128returns id 3), and six mixed BIT/BOOL plan-time error pins. Result file generated and audited row-by-row against MySQL 8 semantics; validation run 34/34 at 100%.decimal_bool_context24/24 andmysql_compat_logical_expr13/13 at 100% on the fixed binary (DECIMALboolean-context behavior for [Bug]: DECIMAL values in a boolean context (AND/OR/NOT/XOR/CASE WHEN/WHERE) fail with 'bad value [DECIMAL64 BOOL]' #30922 unchanged).Residual risk
coalesce(bit, bit)keeps its pre-existing baseUINT64result typing (no BIT overload exists in COALESCE); this preserves every bit pattern (verified at 2^63 and 2^64-1) and is unchanged by this PR.