Repository navigation
fix(function): handle EXPORT_SET typed bit counts - #28731
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed 1300936c03c0f7161333122bba55249ee2dee93e against main@7eb9e0a4cbf20ed9a8e696fc0c0fa2f2795c73d9. COMMENT only for a self-authored PR.
No concrete blocker found. This is a focused correction of the existing binder/executor contract and boundary behavior, not a new architectural feature requiring a design document.
Checked the complete four-file diff, issue reproductions #28210/#28211, binder/registration and physical vector wrappers, shared decimal conversion, output sizing/writing, and the added UT/BVT oracles:
- All eight integer count widths use matching readers. Signed negatives are converted to uint64 before clipping, avoiding uint64 narrowing; zero produces a non-NULL empty result, omitted count remains 64, and supplied NULL stays NULL.
- The same physical-type closure now covers already-accepted BIT and DECIMAL64/128 bits inputs. Decimal conversion preserves scale and exact integer precision via the existing half-away-from-zero/signed-saturation helper; floating-point conversion is intentionally unchanged, not claimed fully MySQL-compatible by this fix.
- Scalar/constant and row-null wrappers are respected. Getter and scale capture are invocation-local, with no retained state across batches or prepared executions. Selection masks are checked before row evaluation; append/allocation errors propagate.
- Count clipping precedes sizing/writing. The zero-count guard avoids negative separator arithmetic, and positive counts retain the overflow-safe byte-size checks. Multibyte tokens/separators are copied intact, not counted as bit positions. Work remains bounded by 64 output positions per row.
- Existing function/overload identity and result metadata are unchanged; no new plan/wire representation or persisted state is introduced. Getter selection stays outside the row loop, with no new synchronization or unbounded buffering.
The count clipping/negative interpretation agrees with the MySQL EXPORT_SET contract; supplied NULL and zero-length handling were also cross-checked against MySQL's implementation.
Evidence/limits: reused author-reported owning function-package test/vet, lint/build, and BVT 46/46 twice on the same CN; I did not independently rerun a native suite or wait for CI. Added tests cover concrete integer constant/vector readers, row NULLs, BIT/decimal precision and boundary sizing. A dedicated prepared multi-execution test and full floating-point/warning compatibility are not claimed; no change-specific failure was established from those limits. Head/base rechecked immediately before submission.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Force re-review completed at unchanged head 1300936c03c0f7161333122bba55249ee2dee93e, base main@7eb9e0a4cbf20ed9a8e696fc0c0fa2f2795c73d9. COMMENT only.
No concrete blocker found; the previous conclusion stands. Reconciled all four changed files and live comments with the prior full change map; there is no implementation/base delta or new contradictory evidence. Reused the valid binder/registration, decimal-helper and test review rather than treating unchanged evidence as stale.
Additional focused recheck covered the native signed/unsigned count readers, clipping before narrowing, 0/negative/UINT64_MAX, constant NULL versus omitted arguments, BIT/DECIMAL bits, invocation-local getter/scale capture, and the final varlena append consumer. Zero count reaches a valid empty inline descriptor without separator underflow; the writer loops over zero positions. Positive result sizing is bounded by 64 positions, counts byte widths, and matches the writing loop. The append consumer rolls back its append checkpoint on allocation/writer error, and ExportSet propagates the error. No new alias retention, synchronization, cross-batch state, overload ID or serialization change was found.
Limits remain explicit: this is not a new native test/BVT/benchmark execution or a claim of comprehensive prepared rebind and floating-point compatibility. Reused the author's reported function-package validation and BVT 46/46 twice, plus the unchanged focused constant/vector/null/decimal tests. Existing approximate bits conversion and noninteger-count binder casts are not expanded by this PR. No CI wait. Live head/base verified again immediately before posting.
## What type of PR is this? - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28210 Fixes matrixorigin#28211 ## What this PR does / why we need it: ### Root cause The binder accepts concrete integer vectors for EXPORT_SET(number_of_bits), but the executor unconditionally requested an int64 physical vector. INT and other narrow/signed/unsigned column vectors therefore reached a physical-type assertion and raised an internal error. The same accepted first-argument contract also had reachable BIT and DECIMAL64/DECIMAL128 column paths that fell through to the int64 reader. The existing boundary normalization changed every number_of_bits below one to one. That made an explicit zero return one output token instead of a non-NULL empty string, and did not preserve MySQL's unsigned treatment of negative values. ### Fix - Select a typed getter once per invocation for every accepted signed/unsigned integer width. - Preserve native BIT and DECIMAL64/DECIMAL128 bits vectors; decimal conversion reuses the existing scale-aware MAKE_SET conversion. - Read number_of_bits without narrowing, then clip its unsigned representation to 64. Omitted means 64, zero means zero, values above 64 and negative signed values become 64. - Distinguish omitted optional arguments from supplied NULL. A supplied NULL separator or count now returns NULL. - Make zero-length result sizing safe so separator-count arithmetic cannot underflow. - Return an ordinary internal error for an unsupported physical type instead of falling through to a mismatched type assertion. ### Correctness and risk boundaries Positive counts, bit order, separators, on/off NULL propagation, negative bit values, and the existing result-size limit are preserved. No retry, concurrency, storage, planner, or unrelated function behavior is changed. Floating-point bits conversion is intentionally unchanged; this PR does not claim to broaden that pre-existing compatibility surface. The count is clipped before result sizing and writing, so user-controlled values cannot create work beyond 64 bit positions. Existing max-result checks still turn oversized output into NULL rather than allocating it. Getter selection is outside the row loop; the common omitted-separator path uses the existing zero-copy comma conversion and no new synchronization or unbounded buffering is introduced. ### Validation - Added focused UT coverage for all eight integer count widths in vector and constant paths; zero, negative, 65, UINT64 max; row-level NULL; BIT; DECIMAL64/DECIMAL128; high-precision decimal; and result-size invalid/zero boundaries. - Added public BVT coverage for an INT count column, all integer count widths, BIT/DECIMAL bits columns, explicit NULL, zero, and negative count behavior. - Exact-main CN black-box validation passed for the reported reproductions and all added SQL cases. - Normal mo-tester comparison passed 46/46 (100%) twice against the same CN instance, including cleanup and rerun. - GOWORK=off go test -mod=readonly ./pkg/sql/plan/function -count=1 passed. - GOWORK=off go vet -mod=readonly ./pkg/sql/plan/function passed. - Incremental golangci-lint reported 0 issues. - make build and git diff --check passed. The change is based on commit 23b20ea (origin/main at task start); no rebase was performed after unrelated main advancement. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28210 Fixes matrixorigin#28211 ## What this PR does / why we need it: ### Root cause The binder accepts concrete integer vectors for EXPORT_SET(number_of_bits), but the executor unconditionally requested an int64 physical vector. INT and other narrow/signed/unsigned column vectors therefore reached a physical-type assertion and raised an internal error. The same accepted first-argument contract also had reachable BIT and DECIMAL64/DECIMAL128 column paths that fell through to the int64 reader. The existing boundary normalization changed every number_of_bits below one to one. That made an explicit zero return one output token instead of a non-NULL empty string, and did not preserve MySQL's unsigned treatment of negative values. ### Fix - Select a typed getter once per invocation for every accepted signed/unsigned integer width. - Preserve native BIT and DECIMAL64/DECIMAL128 bits vectors; decimal conversion reuses the existing scale-aware MAKE_SET conversion. - Read number_of_bits without narrowing, then clip its unsigned representation to 64. Omitted means 64, zero means zero, values above 64 and negative signed values become 64. - Distinguish omitted optional arguments from supplied NULL. A supplied NULL separator or count now returns NULL. - Make zero-length result sizing safe so separator-count arithmetic cannot underflow. - Return an ordinary internal error for an unsupported physical type instead of falling through to a mismatched type assertion. ### Correctness and risk boundaries Positive counts, bit order, separators, on/off NULL propagation, negative bit values, and the existing result-size limit are preserved. No retry, concurrency, storage, planner, or unrelated function behavior is changed. Floating-point bits conversion is intentionally unchanged; this PR does not claim to broaden that pre-existing compatibility surface. The count is clipped before result sizing and writing, so user-controlled values cannot create work beyond 64 bit positions. Existing max-result checks still turn oversized output into NULL rather than allocating it. Getter selection is outside the row loop; the common omitted-separator path uses the existing zero-copy comma conversion and no new synchronization or unbounded buffering is introduced. ### Validation - Added focused UT coverage for all eight integer count widths in vector and constant paths; zero, negative, 65, UINT64 max; row-level NULL; BIT; DECIMAL64/DECIMAL128; high-precision decimal; and result-size invalid/zero boundaries. - Added public BVT coverage for an INT count column, all integer count widths, BIT/DECIMAL bits columns, explicit NULL, zero, and negative count behavior. - Exact-main CN black-box validation passed for the reported reproductions and all added SQL cases. - Normal mo-tester comparison passed 46/46 (100%) twice against the same CN instance, including cleanup and rerun. - GOWORK=off go test -mod=readonly ./pkg/sql/plan/function -count=1 passed. - GOWORK=off go vet -mod=readonly ./pkg/sql/plan/function passed. - Incremental golangci-lint reported 0 issues. - make build and git diff --check passed. The change is based on commit 23b20ea (origin/main at task start); no rebase was performed after unrelated main advancement. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28210 Fixes matrixorigin#28211 ## What this PR does / why we need it: ### Root cause The binder accepts concrete integer vectors for EXPORT_SET(number_of_bits), but the executor unconditionally requested an int64 physical vector. INT and other narrow/signed/unsigned column vectors therefore reached a physical-type assertion and raised an internal error. The same accepted first-argument contract also had reachable BIT and DECIMAL64/DECIMAL128 column paths that fell through to the int64 reader. The existing boundary normalization changed every number_of_bits below one to one. That made an explicit zero return one output token instead of a non-NULL empty string, and did not preserve MySQL's unsigned treatment of negative values. ### Fix - Select a typed getter once per invocation for every accepted signed/unsigned integer width. - Preserve native BIT and DECIMAL64/DECIMAL128 bits vectors; decimal conversion reuses the existing scale-aware MAKE_SET conversion. - Read number_of_bits without narrowing, then clip its unsigned representation to 64. Omitted means 64, zero means zero, values above 64 and negative signed values become 64. - Distinguish omitted optional arguments from supplied NULL. A supplied NULL separator or count now returns NULL. - Make zero-length result sizing safe so separator-count arithmetic cannot underflow. - Return an ordinary internal error for an unsupported physical type instead of falling through to a mismatched type assertion. ### Correctness and risk boundaries Positive counts, bit order, separators, on/off NULL propagation, negative bit values, and the existing result-size limit are preserved. No retry, concurrency, storage, planner, or unrelated function behavior is changed. Floating-point bits conversion is intentionally unchanged; this PR does not claim to broaden that pre-existing compatibility surface. The count is clipped before result sizing and writing, so user-controlled values cannot create work beyond 64 bit positions. Existing max-result checks still turn oversized output into NULL rather than allocating it. Getter selection is outside the row loop; the common omitted-separator path uses the existing zero-copy comma conversion and no new synchronization or unbounded buffering is introduced. ### Validation - Added focused UT coverage for all eight integer count widths in vector and constant paths; zero, negative, 65, UINT64 max; row-level NULL; BIT; DECIMAL64/DECIMAL128; high-precision decimal; and result-size invalid/zero boundaries. - Added public BVT coverage for an INT count column, all integer count widths, BIT/DECIMAL bits columns, explicit NULL, zero, and negative count behavior. - Exact-main CN black-box validation passed for the reported reproductions and all added SQL cases. - Normal mo-tester comparison passed 46/46 (100%) twice against the same CN instance, including cleanup and rerun. - GOWORK=off go test -mod=readonly ./pkg/sql/plan/function -count=1 passed. - GOWORK=off go vet -mod=readonly ./pkg/sql/plan/function passed. - Incremental golangci-lint reported 0 issues. - make build and git diff --check passed. The change is based on commit 23b20ea (origin/main at task start); no rebase was performed after unrelated main advancement. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28210
Fixes #28211
What this PR does / why we need it:
Root cause
The binder accepts concrete integer vectors for EXPORT_SET(number_of_bits), but the executor unconditionally requested an int64 physical vector. INT and other narrow/signed/unsigned column vectors therefore reached a physical-type assertion and raised an internal error. The same accepted first-argument contract also had reachable BIT and DECIMAL64/DECIMAL128 column paths that fell through to the int64 reader.
The existing boundary normalization changed every number_of_bits below one to one. That made an explicit zero return one output token instead of a non-NULL empty string, and did not preserve MySQL's unsigned treatment of negative values.
Fix
Correctness and risk boundaries
Positive counts, bit order, separators, on/off NULL propagation, negative bit values, and the existing result-size limit are preserved. No retry, concurrency, storage, planner, or unrelated function behavior is changed. Floating-point bits conversion is intentionally unchanged; this PR does not claim to broaden that pre-existing compatibility surface.
The count is clipped before result sizing and writing, so user-controlled values cannot create work beyond 64 bit positions. Existing max-result checks still turn oversized output into NULL rather than allocating it. Getter selection is outside the row loop; the common omitted-separator path uses the existing zero-copy comma conversion and no new synchronization or unbounded buffering is introduced.
Validation
The change is based on commit 23b20ea (origin/main at task start); no rebase was performed after unrelated main advancement.