Skip to content

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

Closed

Description

@Ariznawlll

MatrixOne version

Latest main at f72ca9efbeb3a7c673701e4a135cc6670c33cfde. MySQL control: 8.3.0.

What is different

MatrixOne exposes the bounded results of INET_NTOA, INET6_ATON, and INET6_NTOA as maximum-width VARCHAR(65535)/VARBINARY(65535). MySQL exposes the actual maximum widths. The difference becomes persistent schema when the functions are used in CTAS.

Reproduction

CREATE TABLE t AS
SELECT
  INET_NTOA(16909060) AS v4_text,
  INET6_ATON('2001:db8::1') AS network_bytes,
  INET6_NTOA(UNHEX('20010DB8000000000000000000000001')) AS v6_text;

SHOW CREATE TABLE t;

MatrixOne derives:

`v4_text`     varchar(65535) NOT NULL,
`network_bytes` varbinary(65535) DEFAULT NULL,
`v6_text`     varchar(65535) DEFAULT NULL

MySQL 8.3 derives:

`v4_text`       varchar(31) DEFAULT NULL,
`network_bytes` varbinary(16) DEFAULT NULL,
`v6_text`       varchar(39) DEFAULT NULL

INFORMATION_SCHEMA.COLUMNS.CHARACTER_MAXIMUM_LENGTH reports the same widths. This was reproduced in three independent databases per engine.

Controls

  • The stored values themselves are correct: 1.2.3.4, 20010DB8000000000000000000000001, and 2001:db8::1.
  • Ordinary secondary indexes can be created on all three derived columns in both engines, so this is a result metadata/schema derivation problem rather than a value or index-build failure.
  • INET_ATON correctly derives BIGINT UNSIGNED in both engines and is not included in the affected string/binary width set.

Compatibility contract and root cause

MySQL's network-function reference specifies VARBINARY(16) for IPv6 output, VARBINARY(4) for IPv4 output, and a maximum INET6_NTOA text length of 39; its CTAS example derives VARCHAR(39).

MatrixOne's function registry returns bare T_varbinary/T_varchar without setting a width for INET6_ATON and INET6_NTOA or INET_NTOA. CTAS consequently materializes MatrixOne's default maximum width.

Expected behavior

These functions should expose their bounded result widths so CTAS and client result metadata do not inflate them to 65535. At minimum, INET6_ATON should be VARBINARY(16), INET6_NTOA should be VARCHAR(39), and INET_NTOA should match MySQL's declared result width.

Activity

  1. added this to the MO-202609 milestone on Sep 8, 2026
  2. added theissue type on Sep 8, 2026
  3. changed the title [-][Compatibility]: network functions derive VARCHAR/VARBINARY(65535) in CTAS[/-] [+][Compatibility]: bounded conversion functions derive maximum-width types in CTAS[/+] on Sep 8, 2026
  4. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    同一结果类型宽度根因继续扩展到基本进制/二进制转换函数;为避免重复 issue,建议由本 issue 一并覆盖:

    CREATE TABLE t_bin   AS SELECT BIN(1) AS v;
    CREATE TABLE t_conv  AS SELECT CONV('10',10,2) AS v;
    CREATE TABLE t_hex   AS SELECT HEX(1) AS v;
    CREATE TABLE t_unhex AS SELECT UNHEX('41') AS v;

    SHOW CREATE TABLE 的类型对照:

    function       MatrixOne             MySQL 8.3
    BIN            VARCHAR(65535)        VARCHAR(65)
    CONV           VARCHAR(65535)        VARCHAR(65)
    HEX(integer)   VARCHAR(65535)        VARCHAR(16)
    UNHEX          BLOB                  VARBINARY(4)
    

    LOWER('ABC') 和 UPPER('abc') 的控制表在 MatrixOne 与 MySQL 都能正确派生 VARCHAR(3),说明 CTAS 能保留函数返回宽度;差异来自这些转换函数注册的返回类型没有设置宽度,而不是 CTAS 无条件放大字符串列。

    网络函数与上述转换函数的值计算、NULL 传播和普通索引创建仍正常。问题是函数结果元数据会直接固化成过宽或不同类别的持久列类型。

  5. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    Latest main (f72ca9efbeb3a7c673701e4a135cc6670c33cfde) shows that the same return-type derivation also affects bounded encryption, compression, and hash functions.

    Source table:

    CREATE TABLE source(s VARCHAR(12), b VARBINARY(12));
    CREATE TABLE derived AS
    SELECT COMPRESS(s) c,
           UNCOMPRESS(COMPRESS(s)) u,
           UNCOMPRESSED_LENGTH(COMPRESS(s)) n,
           AES_ENCRYPT(b,'key') a,
           MD5(s) m,
           SHA1(s) h1,
           SHA2(s,512) h2,
           CRC32(s) crc
    FROM source;
    SHOW CREATE TABLE derived;

    MatrixOne derives:

    c   BLOB
    u   BLOB
    n   BIGINT
    a   BLOB
    m   VARCHAR(65535)
    h1  VARCHAR(65535)
    h2  VARCHAR(65535)
    crc INT UNSIGNED
    

    MySQL 8.3 derives:

    c   VARBINARY(66)
    u   LONGBLOB
    n   INT
    a   VARBINARY(16)
    m   VARCHAR(32)
    h1  VARCHAR(40)
    h2  VARCHAR(128)
    crc INT UNSIGNED
    

    The hash widths are fixed by their algorithms, and the maximum AES_ENCRYPT()/COMPRESS() output sizes are calculable from the input width. MatrixOne instead uses the generic maximum VARCHAR/BLOB return types. CRC32() is a control whose CTAS type already agrees with MySQL.

    Value behavior was checked separately: normal hashes match MySQL; current COMPRESS() values are mutually readable by MatrixOne and MySQL; default ECB AES ciphertext is byte-identical and mutually decryptable. The issue here is the schema inferred for persisted expressions rather than the computed value.

  6. self-assigned this
    on Sep 8, 2026
  7. XuPeng-SH commented on Sep 8, 2026

    @XuPeng-SH
    Contributor

    Implemented and submitted as PR #28420: #28420

    Root cause confirmed: the affected built-ins returned bare wide planner types. CTAS persists that expression metadata, so bounded values were materialized as VARCHAR(65535), VARBINARY(65535), or BLOB even though the scalar values were correct.

    The fix derives bounded metadata through checked, fail-closed planner arithmetic and preserves text/binary domains:

    • INET_NTOA: VARCHAR(31)
    • INET6_NTOA: VARCHAR(39)
    • BIN/CONV: VARCHAR(65)
    • HEX numeric: VARCHAR(16)
    • HEX(string): 2x declared input byte bound
    • UNHEX: ceil(input byte bound / 2), binary
    • MD5/SHA1/SHA2: VARCHAR(32/40/128)
    • AES_ENCRYPT: PKCS#7 padded binary bound
    • UNCOMPRESSED_LENGTH: INT with int32 executor storage
    • UNCOMPRESS remains BLOB because output length is not statically bounded
    • array HEX remains TEXT as a lossless fallback

    One important implementation-specific correction came from adversarial validation: MySQL's C-zlib formula gives 66/30 for VARCHAR(12)/VARBINARY(12), but MatrixOne's current Go zlib stream can produce 68/32 for incompressible input. The PR therefore uses the codec-aware 68/32 bounds; a real 48-byte high-entropy valid UTF-8 value produced 68 bytes and CTAS materialized VARBINARY(68) without overflow.

    Validation completed:

    • Targeted function tests passed, including overflow/unknown fallback, NULL propagation, compression bounds, AES, and existing compression behavior.
    • New distributed BVT func_bounded_result_metadata.test: 15/15 passed.
    • Rebuilt local server and verified real CTAS values plus information_schema metadata.
    • Full package execution only hit unrelated environment prerequisites: missing ONNX testdata and the existing WASM test's /test write path.

    Please review #28420 for the intentional scope boundaries and the codec-specific compression rationale.

  8. added a commit that references this issue on Sep 8, 2026
    c2d03b5
  9. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:a9d3b8b857c44f1249e682c91d4d62a914eb7d20
    • 环境:本地单机 MatrixOne,2026-09-09。

    原问题验证

    验证网络相关返回值参与 CTAS 时的推导宽度正确,并可建立索引。

    Happy Path 覆盖

    • 三类函数 CTAS 后的列宽分别为 31、16、39;
    • 创建索引成功,查询结果与原函数输出一致;连续 3 轮通过。

    Unhappy Path 覆盖

    本 issue 的风险为类型宽度推导,非非法网络文本解析;以三种不同最大宽度输出交叉验证,确认不会采用过窄的公共宽度而导致截断。

    白盒验证

    不适用:以 SHOW COLUMNS、索引创建与查询结果验证外部类型契约。

    回归测试

    • 已加入 MOTR PR #152:suites/14_issue_regression/t/issue_28389_28387_network_return_types.test。
    • --record --repeat 3 和非 record --repeat 3 均通过;PR 共 21/21 用例、321/321 条语句成功。

    测试证据

    各宽度场景、索引和输出均重复 3 次。

    测试结论

    测试通过。

  10. added 3 commits that reference this issue on Sep 17, 2026
    c37584d
    d6c6527
    1b3789f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions