Skip to content

[Compatibility]: enforce BLOB/TEXT family byte limits - #29121

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:issue/28694-blob-text-byte-limits
Sep 20, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:issue/28694-blob-text-byte-limits

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Closes #28694

What this PR does / why we need it:

Enforce declared BLOB/TEXT family byte capacities at assignment boundaries. Strict assignments reject overflow; non-strict and IGNORE assignments truncate with warnings, preserving UTF-8 for TEXT. Cover INSERT, UPDATE, generated columns, expression DEFAULT, prepared execution, CTAS, and modern/foreign-key fallback LOAD paths. Persisted DEFAULT assignment wrappers use the current statement policy and destination column width. Parallel CSV conversion preserves original BLOB/TEXT payloads until assignment validation.

Preserve legacy width-zero BLOB capacity across SHOW/recreation and dump/restore, and serialize positive nonstandard capacities to the smallest non-narrowing family. Keep internal transport BLOB metadata generic. Export all binary BLOB protocol families as Parquet BYTE_ARRAY without a STRING annotation; nonbinary text retains STRING. Update affected metadata expectations and add regression coverage.

Validation

Linux amd64, Go 1.26.4; independent native generation built with make -j8 cgo. Current revision: a0d55732b0447ac8d334991f13e59d2b7ed895b8 (production repair 27da441b6f88f6616a28efbafd3bc56982eafdeb), based on b7ea9eba9d61039728ee65d3d2fbe235c0cf34a2.

  • Public pre-fix SQL reproduction: strict expression DEFAULT stored 65,536 bytes in TEXT; FK LOAD stored 256 bytes in TINYBLOB. Repaired execution rejects both with error 1406.
  • Complete owning packages: frontend PASS (21.442s); planner PASS after final production correction (4.895s). Focused final parallel staging/expression execution regression PASS, including strict rejection and IGNORE truncation with warning. Parquet schema/raw FF00/NULL readback PASS.
  • Incremental SCA: golangci-lint 2.6.2, Go 1.26.4, ./pkg/sql/plan ./pkg/frontend: PASS, 0 issues. Custom molint vet: PASS exit 0; diagnostics retained in local evidence.
  • issue_28694_blob_text_limits.test: normal mo-tester comparison PASS twice, 116/116 each, zero failed/ignored/abnormal statements; schema residue count 0 between and after runs. Covers strict/non-strict/IGNORE, expression defaults, prepared execution, both parent RefChildTbls and child Fkeys fallback, and dependent defaults reading assigned values. Results were reviewed before normal comparison; existing assertions/formatting preserved.
  • Additional SQL QA: multibyte DEFAULT/UPDATE IGNORE/REPLACE produce 255 bytes / 85 characters with one warning, and LOAD omitted defaults work.
  • Independent GPT-6 (gpt-6-astra, medium) design and overall review, followed by correction of the parallel TINYTEXT staging finding and delta review: APPROVED, no remaining code blockers. Reviewed diff fingerprint matches the committed repair; the subsequent child-FK BVT delta also passed independent GPT-6 medium review. Local artifacts: ~/.codex/issue-to-pr/matrixone/29121/.

Evidence scope: the BVT runs use a single-CN instance. Their small inline PARALLEL case is admitted as serial; actual parallel conversion is covered by a one-row expression-executor regression. The final parallel-only correction and nil-builder guard do not invalidate the serial SQL results. Historical CI at b7ea9eba9d passed UT, SCA, and multi-CN proxy/pessimistic BVT; those results are not claimed for the new revision. New-revision CI is pending.

Risks and rollback

No catalog format or stored-data rewrite is introduced. Assignment checks add the required per-value validation/copy; no new worker, retry, or retained state. Some explicit DEFAULT paths retain an additional bounded assignment wrapper. No performance benchmark was required for this planner/schema repair.

GPU execution and admitted large-file multi-CN parallel LOAD were not run locally. Reverting removes assignment enforcement and metadata corrections; it does not require data migration.

@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 19, 2026
@XuPeng-SH
XuPeng-SH force-pushed the issue/28694-blob-text-byte-limits branch from ce63b7a to 523c15c Compare September 20, 2026 03:53
@XuPeng-SH
XuPeng-SH force-pushed the issue/28694-blob-text-byte-limits branch from 523c15c to 1d4343c Compare September 20, 2026 04:10
@XuPeng-SH
XuPeng-SH force-pushed the issue/28694-blob-text-byte-limits branch from 1d4343c to 93420d0 Compare September 20, 2026 08:04

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

P2 blocker — exact head 0975d7e5bab05235ef6def4540ca2b66ad68604a,当前不能 PASS。

生成列链路仍可绕过本 PR 新增的 TEXT/BLOB 字节上限:

  1. buildGeneratedExpr 进入 makePlan2AssignmentCastExpr;
  2. makePlan2CastExprWithName 在表达式类型与目标列类型相等时直接返回原表达式;
  3. applyGeneratedColumnAssignmentCast 只补数组 wrapper,对根节点为普通 CAST 的 TEXT 表达式不补 assignment cast;
  4. INSERT 投影到生成列时没有后续 family-width 校验。

最小反例:

SET sql_mode = 'STRICT_TRANS_TABLES';
CREATE TABLE t_generated_text_limit (
  s LONGTEXT,
  g TEXT GENERATED ALWAYS AS (CAST(s AS TEXT)) STORED
);
INSERT INTO t_generated_text_limit(s) VALUES (REPEAT('x', 65536));

按当前代码路径,65536 字节载荷可绕过 assignment cast;严格模式应报数据过长,非严格/IGNORE 应截断并产生告警。该路径尚未被现有 byte-limit BVT 覆盖。

请在生成列构建/运行时补齐路径施加目标列赋值语义,并增加上述反例的 planner/执行测试和 SQL BVT,覆盖 strict、非 strict、IGNORE、无 wrapper 表达式及行状态。当前 CI 绿色不能解除该 blocker。自有 PR 按规则只提交 COMMENT。

XuPeng-SH added a commit that referenced this pull request Sep 20, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Closes #29168
Closes #28765

Follow-up to #28765, #28766, #28771, #28776: the original exact-decimal
work
already landed on main through #28830. This PR now contains only the
remaining
Decimal256 numeric RANGE gap identified in review, rebased onto that
implementation.

## What this PR does / why we need it:

A wide exact literal in ORDER BY promotes numeric RANGE bounds to
Decimal256.
The scalar plan literal has no Decimal256 variant, so folding previously
published
a nil literal and execution reported a missing prepared parameter.
Prepared
execution and RANGE searches also lacked Decimal256 support.

- Preserve exact constant/prepared bounds using the existing singleton
vector
literal encoding; retain decimal protocol provenance through
copying/serialization.
- Validate finite non-negative, non-NULL bounds and use checked 256-bit
arithmetic.
  Overflow maps to an insertion boundary instead of wrapping.
- Handle ASC/DESC, peers, NULL keys, empty frames, and constant-vector
singleton
partitions without indexing physical storage with a logical row number.
- Reuse existing per-execution frame ownership/reset; no new cache,
global state,
  protocol field, persistent data, or optimization path.
- Preserve original PR protocol-floor regression coverage not yet on
main;
existing decimal BVT files already landed unchanged and are not
duplicated.

## Validation

Base `5e1e93ae35efc6eea54ae2935f68154493d6e95c`, Linux amd64, Go 1.26.4.
Final reviewed tree: `b3d42f5fe7441e96a03e1521690a1e2e963c4eb7`.
Native provenance verified against primary worktree artifacts rebuilt
from the
same native inputs. The initial public reproducer failed on the #29121
candidate
with identical main decimal/window sources; not claimed as a clean-main
binary run.

- Owning packages: PASS (window 2.134s, planner 6.115s), including
prepared
error/reuse, physical overflow, constant partitions and zero-allocation
assertion.
- Preserved protocol-floor and copy/serialization test delta: PASS
(0.056s).
- Incremental SCA: PASS, exit 0 (`./pkg/sql/colexec/window
./pkg/sql/plan`),
  golangci-lint 2.6.2 built with Go 1.26.4 and repository .golangci.yml.
- Normal-comparison BVT on an owned, fresh single-CN deployment: PASS
twice on
the same instance, 76/76 each, exit 0, zero failed/ignored/abnormal
statements.
New Decimal256 case 24/24 plus signed integer 15/15, uint64 15/15,
temporal
RANGE 22/22. Hand-calculated oracles; no genrs. Final fixture schema
residue 0.
- Supplemental targeted race: PASS (1.309s), `-race -count=1
-timeout=180s
  -run TestDecimal256Range ./pkg/sql/colexec/window`. No new goroutine,
synchronization, shared mutable state or timing contract; no
whole-repository
race/stress claim. Allocation correctness was also checked in normal
mode.
- GPT-6 (`gpt-6-astra`, medium) design and independent review found and
closed
the constant-vector indexing counterexample; final exact-commit
independent
  source/evidence review: APPROVE.

## Risks and rollback

Shared RANGE wrapper changes are covered by existing non-Decimal256
regressions.
Decoder accepts only the bounded singleton encoding produced by the
current
vector serializer; malformed/type-mismatched payloads return errors.
Rollback is code-only and restores the unsupported behavior; no data
migration.
Single-CN local validation; distributed compose/proxy execution remains
CI coverage.

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

Force review verdict: P2 blocker — exact head 0975d7e5bab05235ef6def4540ca2b66ad68604a。以下问题来自生产路径源码追踪,不依赖 coverage、queue readiness 或 merge state;自有 PR 按规则只提交 COMMENT。

  1. 生成列可绕过 BLOB/TEXT family byte limit

buildGeneratedExpr 进入 makePlan2AssignmentCastExpr,但 makePlan2CastExprWithName 在表达式类型与目标列类型相等时直接返回原表达式。applyGeneratedColumnAssignmentCast 只补数组 wrapper,普通 TEXT/BLOB CAST 根节点不会获得 assignment enforcement。

最小反例:

SET sql_mode = 'STRICT_TRANS_TABLES';
CREATE TABLE t_generated_text_limit (
  s LONGTEXT,
  g TEXT GENERATED ALWAYS AS (CAST(s AS TEXT)) STORED
);
INSERT INTO t_generated_text_limit(s) VALUES (REPEAT('x', 65536));

严格模式应拒绝;非严格/IGNORE 应截断并告警,但当前生成列投影路径可绕过这些语义。相关路径:pkg/sql/plan/make.go:1011、pkg/sql/plan/build_util.go:905,2074、pkg/sql/plan/bind_insert.go:5157。

  1. LOAD DATA 可绕过 BLOB/TEXT assignment enforcement

现代 LOAD binder 将 typed column references 直接送入 appendNodesForInsertStmt,该路径复制表达式但不插入 assignment cast;CSV reader 的 strict/truncation 逻辑只覆盖 CHAR/VARCHAR,最终写入也没有 family-width 校验。

最小反例:创建 t_load_limit(v TINYBLOB),LOAD 一个包含 256 字节字段的 CSV。严格模式应拒绝,非严格模式应截断到 255 字节并告警;当前 serial、非-LOCAL LOAD 路径可直接写入超限值。相关路径:pkg/sql/plan/bind_load.go:45,140、pkg/sql/plan/bind_insert.go:5052、pkg/sql/colexec/external/external.go:1600,1616,1870、pkg/sql/colexec/multi_update/insert.go:193。

请把生成列和 LOAD DATA 都接入统一 family-width assignment policy,并补充 strict/non-strict/IGNORE 的公共路径测试,断言错误/告警和最终存储长度。当前 force review 结论为 REQUEST_CHANGES;未发现 P0/P1。

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Fixed the two remaining assignment-policy bypasses in b7ea9eba9d:

  • stored generated TEXT/BLOB expressions now regain the target-family assignment cast when legacy/catalog expressions lack it; explicit inner casts are preserved and existing assignment wrappers are rebuilt for the current strict/IGNORE protocol policy;
  • LOAD DATA now applies the same TEXT/BLOB assignment boundary to target-typed external-scan columns, with a separate assignment IGNORE policy so duplicate-key and auto-increment planning are unchanged. Explicit IGNORE and LOCAL (except REPLACE) use the permissive assignment path; IGNORE N LINES does not.

Validation:

  • focused planner UT: PASS (TestApplyGeneratedColumnAssignmentCastCompatibility, TestLoadAssignmentIgnorePolicy, TestApplyLoadAssignmentCasts, TestLoadPlanUsesSingleTableLockTarget)
  • full pkg/sql/plan: PASS (-count=1, 4.941s)
  • git diff --check: PASS
  • GPT-6 medium final review: PASS, no P1/P2 blockers
  • public BVT regression coverage added to issue_28694_blob_text_limits.test/result for generated columns and LOAD DATA strict/non-strict/IGNORE paths

A local BVT attempt was deliberately not counted as product evidence: the fresh instance never reached ISCP-Task Start and repeatedly failed system-task user initialization; all pre-existing cases in this PR failed at the same time. The exact case remains for ready-instance/CI validation.

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

Force review verdict: 3 个 P2 blocker,当前不能 PASS;exact head b7ea9eba9d61039728ee65d3d2fbe235c0cf34a2。coverage 不作为门槛;自有 PR 按规则只提交 COMMENT。

上一轮“普通生成列绕过上限”的路径已修复,但仍有以下问题:

  1. 带外键关系的 LOAD DATA 仍绕过 BLOB/TEXT family byte limit

foreign_key_checks=1 且目标表存在 Fkeys/RefChildTbls 时,ResolveTables 返回 ErrUnsupportedDML,bindAndOptimizeLoadQuery 转入旧 buildLoad,不会执行新增的 applyLoadAssignmentCasts。旧路径的 CSV 输入投影直接使用 typed ColRef,后续没有 TEXT/BLOB 长度检查。

最小场景:父表 p(id INT PRIMARY KEY, v TINYBLOB) 被空子表外键引用;向 p 非 LOCAL、串行 LOAD 一行包含 256 字节字段。严格模式应拒绝,非严格/IGNORE 应截断到 255 字节并告警,但旧回退路径可直接写入超限值。

定位:pkg/sql/plan/bind_load.go:159、pkg/sql/plan/build.go:356、pkg/sql/plan/build_load.go:899。

  1. 省略目标列时,表达式 DEFAULT 仍绕过 assignment enforcement
SET sql_mode = 'STRICT_TRANS_TABLES';
CREATE TABLE default_limit (
  s LONGTEXT,
  v TEXT DEFAULT (CAST(s AS TEXT))
);
INSERT INTO default_limit(s) VALUES (REPEAT('x', 65536));

buildDefaultExprWithColumns 的同类型快捷路径省略 assignment wrapper,appendNodesForInsertStmt 对缺省列直接使用 getDefaultExpr。因此该路径可绕过严格拒绝及非严格/IGNORE 截断告警。定位:pkg/sql/plan/build_util.go:731、pkg/sql/plan/make.go:1011、pkg/sql/plan/bind_insert.go:5122。

  1. BLOB family 协议类型变化导致 Parquet 导出错误标注为 STRING

新的 metadata 将 TINYBLOB/MEDIUMBLOB/LONGBLOB 输出为对应协议类型,但 buildParquetNode 仅把 MYSQL_TYPE_BLOB 映射为 BYTE_ARRAY,其余 family 落入 parquet.String();实际值仍是原始 []byte。例如导出包含 X'FF00' 的 TINYBLOB 列,会把二进制字段标成 UTF-8 STRING,造成下游 schema/type 回归。

定位:pkg/frontend/util.go:2039、pkg/frontend/export_parquet.go:109。请覆盖全部 BLOB family,并结合 binary 标志区分同协议类型的 TEXT,补充二进制值和导出 schema 回归。

请将旧 LOAD 回退、DEFAULT 写入和 Parquet schema 都接入正确的 BLOB/TEXT contract,并补充 strict/non-strict/IGNORE、最终存储长度和导出 schema 测试。未发现 P0/P1。

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review of exact head b7ea9eb: REQUEST_CHANGES. I read the complete review history, audited the full PR diff and the latest increment, traced the LOAD/default/metadata consumers, and ran the focused function, planner, and frontend packages successfully. Independent temporary regression tests reproduced the same-type expression-default wrapper loss and the Parquet STRING schema for all three non-generic binary BLOB protocol types. The three P2 blockers are detailed inline; no P0/P1 was found.

Comment thread pkg/sql/plan/bind_load.go

// External scans expose target-typed columns. For BLOB/TEXT, equal type
// metadata does not prove that the runtime payload fits the target family.
if err = builder.applyLoadAssignmentCasts(tableDef, insertColToExpr, assignmentIgnore); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: this enforcement is skipped whenever LOAD takes the legacy fallback. With foreign_key_checks enabled, ResolveTables returns ErrUnsupportedDML for a target having Fkeys or RefChildTbls; bindAndOptimizeLoadQuery then calls buildLoad. That path builds target-typed ColRefs in getProjectNode and never calls applyLoadAssignmentCasts, so the equal type metadata still bypasses the family limit. Repro: make p(id INT PRIMARY KEY, v TINYBLOB), reference p from an empty child table, then serial non-LOCAL LOAD a 256-byte field into p. Strict mode should reject and non-strict/IGNORE should truncate to 255 bytes with a warning, but the fallback can store all 256 bytes. Please apply the same assignment policy in the fallback or prevent this fallback for supported LOAD shapes, and cover both Fkeys and RefChildTbls.

// 这些类型都不能仅根据元数据相等省略赋值检查。
func needsSameTypeAssignmentCast(targetType Type) bool {
return (targetType.Id == int32(types.T_text) && targetType.Width == types.MaxTinyTextLen) ||
return targetType.Id == int32(types.T_blob) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: expanding this helper does not cover column-reference DEFAULT expressions. buildDefaultExprWithColumns calls makePlan2AssignmentCastExpr, whose makePlan2CastExprWithName path still returns early when source and target types match; appendNodesForInsertStmt later inserts getDefaultExpr directly for an omitted column. A temporary unit test confirmed that a same-type TEXT ColRef returns unchanged instead of a cast_strict wrapper. End-to-end trigger: SET sql_mode='STRICT_TRANS_TABLES'; CREATE TABLE default_limit(s LONGTEXT, v TEXT DEFAULT (CAST(s AS TEXT))); INSERT INTO default_limit(s) VALUES (REPEAT('x',65536));. The value can bypass strict rejection and non-strict/IGNORE truncation plus warning. The DEFAULT runtime path needs a forced target-family assignment cast, with strict, non-strict, and IGNORE coverage.

Comment thread pkg/frontend/util.go
case 0, math.MaxUint32:
col.SetColumnType(defines.MYSQL_TYPE_BLOB)
case types.MaxTinyTextLen:
col.SetColumnType(defines.MYSQL_TYPE_TINY_BLOB)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: emitting the differentiated binary BLOB protocol types changes a downstream Parquet schema. buildParquetNode handles only MYSQL_TYPE_BLOB as raw BYTE_ARRAY; TINY_BLOB, MEDIUM_BLOB, and LONG_BLOB fall through to parquet.String, which adds a UTF-8 logical annotation even though setMysqlBinaryBlobColumnMetadata sets BINARY_FLAG and the values remain raw bytes. A temporary test calling buildParquetNode for all three types with BINARY_FLAG got STRING for each instead of BYTE_ARRAY. For example, exporting TINYBLOB X'FF00' now advertises binary data as UTF-8 text. Please update the Parquet consumer for the complete BLOB family and use BINARY_FLAG/charset to retain text-family STRING behavior.

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

PASS — reviewed exact head a0d5573 against the supplied base cd5feff, with merge-base ancestry reconciled.

All changed hunks and relevant assignment, metadata, serialization and export consumers were reviewed. The previous three P2 findings are closed:

  1. FK fallback LOAD now applies TEXT/BLOB assignment validation before dependent defaults.
  2. Restored expression DEFAULTs receive destination-width/current-statement assignment policy, including same-type expressions.
  3. All binary BLOB protocol families export as unannotated Parquet BYTE_ARRAY, with raw FF00/NULL round-trip coverage.

Also checked strict/non-strict/IGNORE behavior, UTF-8 byte boundaries, generated/prepared paths, parallel staging, legacy width-zero BLOB compatibility, SHOW/dump reconstruction and opaque transport metadata. No new blocking regression was found.

Exact-head UT/SCA and Compose BVT are successful. The small inline PARALLEL SQL case is serial-admitted; actual parallel conversion is supported by the focused executor regression, not claimed as large-file multi-CN validation. Base-only LISTAGG/ARRAY_AGG differences are not PR-introduced deletions.

No P0/P1/P2 blockers remain. Coverage was not used as a gate.

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

kind/bug Something isn't working kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compatibility]: BLOB and TEXT columns do not enforce MySQL family byte limits

3 participants