Skip to content

fix(function): preserve bounded conversion result metadata - #28420

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28387-bounded-function-metadata
Sep 8, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28387-bounded-function-metadata

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

Summary

Fix #28387 by deriving bounded result metadata for conversion, network, hash,
hex, compression, and encryption built-ins instead of returning the default
wide VARCHAR/BLOB types.

The problem is metadata, not the scalar values: CTAS persists the planner's
expression result type, so a function that returns a bounded value was
materialized as VARCHAR(65535), VARBINARY(65535), or BLOB. This affects
schema compatibility, information-schema metadata, client buffer planning,
and downstream DDL.

What changed

  • Add checked planner-only byte-bound arithmetic with fail-closed handling for
    unknown types and arithmetic overflow.
  • Derive the MySQL-compatible fixed text widths for INET_NTOA (31),
    INET6_NTOA (39), BIN/CONV (65), numeric HEX (16), MD5 (32),
    SHA1 (40), and the safe maximum SHA2 width (128).
  • Preserve the input domain while deriving HEX, UNHEX, COMPRESS, and
    AES_ENCRYPT metadata. Text results remain text; binary results remain
    binary.
  • Bound HEX(string) by twice the declared input byte length and UNHEX by
    half the input byte length rounded up.
  • Bound AES_ENCRYPT by PKCS#7 block padding and keep AES_DECRYPT as BLOB
    because its plaintext length is not statically recoverable.
  • Bound COMPRESS using the zlib expansion formula plus MatrixOne's current
    Go-zlib stream overhead. The resulting widths are 68 for VARCHAR(12) and
    32 for VARBINARY(12), rather than blindly using MySQL C-zlib's 66/30;
    high-entropy input demonstrated that 66/30 underestimates the actual
    MatrixOne output.
  • Keep unbounded UNCOMPRESS as BLOB and array HEX as TEXT. These are
    lossless fallbacks because MatrixOne has no statically bounded LONGBLOB or
    array serialization domain here.
  • Align UNCOMPRESSED_LENGTH with its INT result contract and use int32
    end-to-end. Its masked value is at most 0x3fffffff, so this does not
    narrow any valid result.
  • Extend nullability inference for functions that can synthesize NULL from
    non-NULL inputs: invalid conversion bases, invalid SHA2 variants, invalid
    network input, AES/compression failures, and decompression failures.

Correctness and unhappy paths

  • Unknown/unbounded input, negative widths, and arithmetic overflow fall back
    to a lossless wide type; no result is deliberately truncated.
  • Tests cover invalid/NULL propagation and the existing legacy compression
    format behavior.
  • A high-entropy compression test verifies that the planner bound can be used
    as the actual encoder limit without a short write.
  • CTAS coverage checks both value preservation and materialized
    information_schema column metadata for text, binary, network, hash,
    compression, AES, and UNCOMPRESSED_LENGTH results.

Performance and scope

  • All new derivation is constant-time planner arithmetic; no runtime scan,
    allocation, or compression is added to type inference.
  • Runtime changes are limited to the already-existing int32 result contract
    for UNCOMPRESSED_LENGTH; function values and compression/decompression
    behavior are otherwise unchanged.
  • INET6_ATON keeps its existing fixed VARBINARY(16) contract.
  • AES_DECRYPT and UNCOMPRESS intentionally remain wide because their
    result length cannot be soundly bounded from the available static metadata.

Validation

  • Targeted MatrixOne function tests: passed, including bounded return types,
    nullability, compression boundaries, AES compatibility, and existing
    compression behavior.
  • Direct compiled test binary was run with the repository's macOS CGo
    library path; this avoids the known go test launcher/DYLD issue.
  • New distributed BVT: func_bounded_result_metadata.test, 15/15 passed.
  • Rebuilt local MatrixOne server and verified real CTAS output, including the
    48-byte high-entropy UTF-8 case (COMPRESS length 68 and materialized
    VARBINARY(68)).
  • git diff --check passed.
  • A full package run also reaches unrelated environment-only failures for
    missing ONNX testdata and the existing WASM test's /test write path; no
    failure was observed in the changed tests.

@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 →

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Sep 8, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Explicitly requested deep re-review of current head 9aa0519 (base 4b43f8c). Self-authored: COMMENT only; CI readiness is bypassed by the explicit review request, not claimed as passed.

Conclusion remains no confirmed source blocker. I reread all current changed hunks across the 10 files, including every changed registry overload and the complete domain/boundary and CTAS tests. Exact old-head/new-head file comparisons show string_result_domain.go, func_unary.go, list_builtIn.go, and function.go are byte-identical to the implementation reviewed at 26dd486; this is verified reuse of the earlier runtime analysis, not an assumption based on the PR title.

Rechecked checked-width arithmetic and overflow/unknown fallback, UTF-8 versus binary byte bounds, rounded-up UNHEX output, AES full-block PKCS#7 padding, fixed digest/network/numeric domains, all four UNCOMPRESSED_LENGTH registry signatures and the int32 executor/masked range, and NULL-producing function metadata. No new lifecycle, synchronization, or per-row allocation change appeared on this head. The prior encoder/runtime proof remains applicable because the executable files above are unchanged.

Independently reran the standard-library Go compression-framing probe: all 1,031 seeded incompressible input sizes stayed within the proposed bound including the four-byte header and optional trailing dot. This is a focused framing check, not a native MatrixOne test or universal compression proof.

Non-blocking acceptance: keep native/BVT CI for this rebased head and the high-entropy compression/CTAS regression. I did not rerun MatrixOne native or distributed suites here. The metadata/UNCOMPRESSED_LENGTH physical-type change should also be represented in any supported rolling-upgrade compatibility testing; no mixed-version cluster execution is claimed by this review.

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

size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compatibility]: bounded conversion functions derive maximum-width types in CTAS

2 participants