Repository navigation
fix(plan): support LENGTH/OCTET_LENGTH/CHAR_LENGTH on BIT columns - #32103
Conversation
LENGTH and LENGTH_UTF8 were registered with checkFn stringDomainFixedTypeMatch, which never admits T_bit (BIT's implicit cast rule only targets INT64/UINT64), so LENGTH/OCTET_LENGTH/ CHAR_LENGTH/CHARACTER_LENGTH on a BIT column failed binding with ERROR 20203 while BIT literals (binary-string constants) worked. Bind a single BIT argument directly with no implicit cast, preserving the declared width, and evaluate the length family on BIT(M) as ceil(M/8), the fixed storage width MySQL 8.0 defines in Field_bit::pack_length(); the binary charset makes character length equal byte length. NULL stays NULL. Out-of-range width metadata falls back to a per-value minimal byte count. Adds focused UTs (binding for all four names x widths 1/8/9/16/64, fixed-width semantics incl. NULL, fallback, non-BIT preservation) and BVT coverage in func_string_length/func_string_octet_length/ func_string_char_length. Related to matrixorigin#31183
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: 2f5967dc3ee5951e120423b3e781dd6c0e7c8369
Assessment: approve
The native BIT overloads preserve declared width and reuse existing scalar execution for NULLs and selections. Function-local matching preserves existing casts, aliases and overload identities. No actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all ten changed files, both discussion entries and linked issue context; completed discussion-assessment.json.
-
Verified the fixed-width representation against MySQL 8.0.45 field handling and its packed-width definition.
-
Reused reported focused/full-package tests, vet/gofmt and 204/204 statements across the three changed BVT cases.
-
Frozen CI records successful Ubuntu UT, arm64 SCA and proxy/pessimistic multi-CN BVT checks.
-
Local source, overload-preservation, case/result and receipt audits passed. Source remained unchanged.
Limitations:
-
Go, BVT and static-analysis execution results were reused from frozen author/CI evidence; no local rerun is claimed.
-
Reference MySQL semantics were checked in pinned source rather than a fresh MySQL instance.
🚫 Left the queue · pull request dequeued1 h 6 min in the queue, with no time running CI. So far
Reason Pull request #32103 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 #31183
What this PR does / why we need it:
Root cause
LENGTH/OCTET_LENGTHare backed by theLENGTHbuilt-in andCHAR_LENGTH/CHARACTER_LENGTHbyLENGTH_UTF8(pkg/sql/plan/function/function_id.go). Both were registered withcheckFn: stringDomainFixedTypeMatch, which never admitstypes.T_bit(BIT's implicit-cast rule row only targets INT64/UINT64), so every call on a BIT column failed function binding with ERROR 20203invalid argument .... BIT literals worked because they are binary-string constants and never reach that type-match path.Change
pkg/sql/plan/function/type_check.go: newlengthTypeMatch— a single BIT argument binds directly with no implicit cast, so the declared width M is preserved; all other inputs keep the previous string-domain behavior. BIT's global implicit-cast rules are untouched.pkg/sql/plan/function/list_builtIn.go:LENGTHandLENGTH_UTF8uselengthTypeMatchand each gains a BIT overload returning INT64, evaluated by the new executor.pkg/sql/plan/function/func_unary.go: newLengthBitexecutor returns(width+7)/8, i.e. ceil(M/8), for declared widths 1..64. This matches MySQL 8.0 fixed storage width (Field_bit::pack_length()); BIT values stringify with the binary charset, so the character count equals the byte count. NULL stays NULL. Out-of-range width metadata (0, negative, >64 — no supported SQL producer) falls back to a per-value minimal byte count instead of failing.pkg/sql/plan/function/length_bit_type_match_test.go; BIT sections appended to BVT casesfunc_string_length,func_string_octet_length,func_string_char_length.Behavior after the fix
LENGTH,OCTET_LENGTH,CHAR_LENGTHandCHARACTER_LENGTHon aBIT(M)column return ceil(M/8) for every non-NULL value (value-independent fixed width, leading zero bytes preserved) and NULL for NULL, matching MySQL 8.0.45 (verified against mysql-serversql/field.cc,sql/field.h,sql/item_func.cc).Validation
mo-cgo-test -run 'TestLengthFamily' ./pkg/sql/plan/function— new UTs pass: binding for all four function names x widths 1/8/9/16/64 (cast-free INT64 via the BIT overload), fixed-width results for zero/leading-zero/max values, NULL propagation, invalid-width fallback, and unchanged non-BIT binding (varchar/char/text/blob/varbinary, INT64). The same binding test fails on the base commit with the issue's ERROR 20203 (red/green proof).mo-cgo-test ./pkg/sql/plan/function— whole package green.go vet -mod=readonly ./pkg/sql/plan/functionwith the repository CGo environment — clean; gofmt clean.LENGTHon aBIT(8)column holdingb'11111111'), widths 1/8/9/64, zero and leading-zero values, NULL rows,MAX/SUMaggregates, and BIT-literal controls.LENGTH/OCTET_LENGTH/CHAR_LENGTHover BIT(1)/BIT(8)/BIT(16)/BIT(64) columns return 1/1/2/8 for every non-NULL value and NULL for NULL;SUM(LENGTH(b64))= 24 — identical to MySQL 8.0.45.Residual risks / limits
invalid argument %s, bad value %s); MySQL's exact error text is not mirrored.make static-checkand the complete BVT suite are left to CI; the changed-package closure above is green.