Skip to content

[Compatibility]: TO_BASE64 materializes bounded VARBINARY input as TEXT and prevents indexing #28902

Description

@Ariznawlll

Problem

TO_BASE64 exposes every bounded string/binary input as unbounded TEXT. For a small VARBINARY input, this changes the View/CTAS schema and prevents ordinary secondary indexing even though the encoded result has a small deterministic maximum size.

Reproduction

drop database if exists to_base64_type_repro;
create database to_base64_type_repro;
use to_base64_type_repro;

create table src(id int primary key, raw varbinary(128));
insert into src values (1,unhex('4100FF7A')),(2,unhex('612C622C2C63')),(3,null);

create view v as select id,to_base64(raw) b64 from src;
create table ctas as select * from v;

select table_name,column_name,data_type,column_type,character_maximum_length
from information_schema.columns
where table_schema=database() and table_name in ('v','ctas')
order by table_name,ordinal_position;

create index idx_b64 on ctas(b64);

MatrixOne result

  • b64 is declared as TEXT, with character_maximum_length=65535, in both the View and CTAS table.
  • CREATE INDEX returns not supported: TEXT column 'b64' cannot be in index.
  • Scalar values themselves are correct (QQD/eg==, YSxiLCxj, and NULL).

MySQL 8.0.45 result

  • The same expression over VARBINARY(128) is declared as VARCHAR(174) in both the View and CTAS table.
  • The secondary index is created and an indexed equality lookup returns the expected row.

Controls and scope

NULL and embedded 0x00/0xff bytes are included. Direct selection, View, CTAS, index creation, forced-index lookup, and prepared TO_BASE64/FROM_BASE64 round trips are covered. Three independent executions produced identical results on each database.

The functional impact is not only metadata: bounded encoded values lose index eligibility after materialization.

Code location

The scalar string overload in pkg/sql/plan/function/list_builtIn.go returns types.T_text.ToType() unconditionally. Its return bound can instead be derived from the declared input byte bound and Base64 expansion/line-wrap rules; large inputs may still require a LOB type.

Environment

  • MatrixOne: official main commit 0c3a04f390adaf6281fd592a49778ea5b1155e67
  • MySQL control: 8.0.45
  • Local single-node MatrixOne deployment

Activity

  1. added this to the MO-202609 milestone on Sep 15, 2026
  2. added theissue type on Sep 15, 2026
  3. self-assigned this
    on Sep 15, 2026
  4. added a commit that references this issue on Sep 17, 2026
    f6f8c0c
  5. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    当前 main 复测未通过,转回 @XuPeng-SH 继续处理。

    验证环境:本地单机 MatrixOne,由远端 main 0370bb4d6b118da29e164c54aa34ee010ed897bc 全新构建;二进制 build info 已核对为该 SHA。声明修复本 issue 的 PR #28941(f6f8c0c885f999cbde3b0d394194b0a4a74176ae)已包含在该提交中。以下场景独立执行 3/3,结果一致。

    复现:VARBINARY(128) 输入经 TO_BASE64 进入 View 和 CTAS。两处 b64 仍为 TEXT(0),character_maximum_length=65535;CREATE INDEX idx_b64 ON ctas(b64) 稳定报 ERROR 20105: not supported: TEXT column 'b64' cannot be in index。包含 0x00、非 UTF-8 字节和 NULL 的标量值本身正确,因此问题仍是有实际影响的元数据/索引资格回归。

    期望是有界输入推导有界结果(MySQL 为 VARCHAR(174)),并允许 CTAS 列建立普通二级索引。当前验收未通过,issue 保持 Open。

  6. added 2 commits that reference this issue on Sep 17, 2026
    385154b
    fe9c331
  7. added a commit that references this issue on Sep 19, 2026
    aeee7db
  8. Ariznawlll commented on Sep 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:d8ddce92b1c5c172111b50aefe6b6b200b2589cb
    • 日期:2026-09-20

    原问题验证

    验证 TO_BASE64(VARBINARY(128)) 经 View 和 CTAS 后的元数据。结果列为 VARCHAR(174),不再退化为无界 TEXT/BLOB;在 CTAS 结果列上创建索引成功。连续执行 3 次通过。

    覆盖范围

    1. View 和 CTAS 元数据推导。
    2. 有界二进制输入的 BASE64 编码结果。
    3. CTAS 结果列索引创建。

    边界与异常路径

    1. 二进制字节 X'00FF10' 编码为预期 AP8Q。
    2. NULL 输入保持 NULL。

    自动化回归

    • motr#193 新增 issue_28902_to_base64_metadata.test。
    • MOTR 目标集连续运行 3 轮,共 33/33 成功。

    测试结论

    测试通过。

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