Skip to content

[Bug]: GROUP_CONCAT rejects a single string-like value above an internal uint16 limit #28653

Closed

Description

@Ariznawlll

Description

GROUP_CONCAT returns an internal error when one non-NULL LONGTEXT or LONGBLOB input value is 65,536 bytes or larger, even when group_concat_max_len is large enough for the result.

The failure is tied to the size of one input row, not to the aggregate result size: a 65,535-byte value succeeds, and three 40,000-byte values concatenate to a 120,000-byte result.

Environment

  • Branch: main
  • Commit: e7d46d6dfb27696211ca828c55e245d3bd1b634d
  • Deployment: local standalone (1 CN / 1 TN / 1 LogService)
  • Oracle: MySQL 8.3.0, isolated local instance

Steps to reproduce

drop database if exists gc_single_value_boundary;
create database gc_single_value_boundary;
use gc_single_value_boundary;

create table src (id int primary key, txt longtext, bin longblob);
insert into src values
  (1, repeat('x', 65535), unhex(repeat('61', 65535))),
  (2, repeat('y', 65536), unhex(repeat('62', 65536))),
  (3, repeat('z', 70000), unhex(repeat('63', 70000)));

set session group_concat_max_len = 300000;

select id, length(txt), length(bin) from src order by id;
select length(group_concat(txt order by id separator '')) from src where id = 1;
select length(group_concat(txt order by id separator '')) from src where id = 2;
select length(group_concat(txt order by id separator '')) from src where id = 3;
select length(group_concat(bin order by id separator '')) from src where id = 2;

Actual behavior

The source values are stored at the requested lengths, and the 65,535-byte aggregate succeeds. Each 65,536-byte or 70,000-byte text/binary probe returns:

ERROR 20101 (HY000): internal error: group_concat: the length of the value is too long

Expected behavior

With group_concat_max_len = 300000, these one-row aggregates should return lengths 65,536 and 70,000. MySQL 8.3.0 returns the full values for the same SQL.

Stability and controls

  • Reproducer: 3/3 for both LONGTEXT and LONGBLOB at 65,536 and 70,000 bytes.
  • Lower-bound control: a 65,535-byte single value returns length 65,535.
  • Aggregate-size control: three 40,000-byte values return one 120,000-byte result.
  • Source-data control: direct LENGTH(txt) and LENGTH(bin) return 65,535, 65,536, and 70,000.
  • MySQL 8.3.0 oracle: all text and binary probes return the requested lengths in 3/3 runs.
  • Failure atomicity: read-only aggregate failures do not modify the source rows.

Evidence

MatrixOne (same output in runs 1-3):
control_plain_lengths  1  65535  65535
control_plain_lengths  2  65536  65536
control_plain_lengths  3  70000  70000
text_65535             65535
text_65536             ERROR 20101 ... length of the value is too long
text_70000             ERROR 20101 ... length of the value is too long
binary_65535           65535
binary_65536           ERROR 20101 ... length of the value is too long
binary_70000           ERROR 20101 ... length of the value is too long
many_small_values      120000

MySQL 8.3.0 (same output in runs 1-3):
text_65535             65535
text_65536             65536
text_70000             70000
binary_65535           65535
binary_65536           65536
binary_70000           70000
many_small_values      120000

Code analysis

pkg/sql/colexec/aggexec/agg_payload.go calls isValidGroupConcatUnit for string, binary, array, and JSON payload fields. pkg/sql/colexec/aggexec/concat2.go rejects any such field whose encoded byte length exceeds math.MaxUint16.

That guard is inconsistent with the current payload format: appendPayloadField stores field lengths as uint32, and the aggregate already supports results larger than 65,535 bytes. Removing or widening the obsolete per-field guard should be evaluated together with spill serialization and memory accounting.

Regression coverage

After the fix, add focused aggregate-executor coverage at 65,535/65,536 bytes and SQL regression coverage for LONGTEXT/LONGBLOB, ordered aggregation, and a forced-spill run with a value larger than 64 KiB.

Related

Activity

  1. added this to the MO-202609 milestone on Sep 11, 2026
  2. added
    kind/bug
    on Sep 11, 2026
  3. added theissue type on Sep 11, 2026
  4. changed the title [-][Bug]: GROUP_CONCAT rejects a single LONGTEXT or LONGBLOB value above 65,535 bytes[/-] [+][Bug]: GROUP_CONCAT rejects a single string-like value above an internal uint16 limit[/+] on Sep 11, 2026
  5. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充影响范围:该 65,535-byte 限制并非只影响表中的 LONGTEXT/LONGBLOB,由表达式生成的长字符串、二进制值和 JSON 也会触发同一个内部错误。

    当前 main e7d46d6dfb27696211ca828c55e245d3bd1b634d:

    set group_concat_max_len = 1000000;
    
    select length(group_concat(repeat('x', 70000)));
    select length(group_concat(cast(repeat('x', 70000) as binary)));
    select length(group_concat(json_object('k', repeat('x', 70000))));

    三个语句都直接报:

    ERROR 20101 (HY000): internal error: group_concat: the length of the value is too long
    

    MySQL 8.3.0 分别返回 70000、70000 和 70009。

    JSON 还有额外问题:限制施加在 MatrixOne 的内部二进制 JSON 编码,而不是最终输出字节数。repeat 长度为 65511 时,JSON 的最终文本为 65520 bytes,可以聚合;只增加一个字符到 65512,最终文本仅 65521 bytes,却因内部编码超过 uint16 上限而失败。因此,即使最终文本尚未达到 65,535 bytes,也可能报错。

    字符串、二进制和 JSON 三种表达式均连续 3 次复现;小于内部边界的 JSON 作为对照可正常返回。实现中的 isValidGroupConcatUnit 对 VARCHAR/TEXT/BLOB/VARBINARY/BINARY/JSON/ARRAY 共用 math.MaxUint16 检查,说明这些类型都在同一问题范围内。

  6. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 065a67528608c475d0219e0be6b7d454a58f7b1a 复核:group_concat(repeat('x',70000)) 连续 3 次均报 group_concat: the length of the value is too long;同一 group_concat_max_len=1000000 下 MySQL 8.3.0 返回 70000 bytes。内部 uint16 单值限制仍存在。

  7. aunjgr commented on Sep 13, 2026

    @aunjgr
    Contributor

    Verified fixed by merged PR #28702 on main 4d18bee954400592c8b96546febcc7b987d448a3.

    The SQL regression passes for text and binary expressions of 65,535, 65,536, and 70,000 bytes with a sufficient group_concat_max_len. The large JSON expression also succeeds and returns 70,009 output bytes. Existing payload and ordered-spill regressions pass, including large text, JSON, and float32-vector cases.

    The obsolete uint16 per-field restriction is removed; the existing payload format and output-length limit remain intact. Closing this issue as completed. The separate result-metadata issue #28663 and temporal/strict-write issues #28657/#28664 are not covered by this closure.

  8. assigned and unassigned on Sep 14, 2026
  9. reopened this on Sep 14, 2026
  10. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:bb358ea76aeb44a6eed5079616e7e75ba35e75b9
    • 部署方式:macOS arm64 本地 standalone,1 CN / 1 TN / 1 LogService
    • 测试日期:2026-09-14

    原问题验证

    在 group_concat_max_len=100000 下分别聚合 65,535、65,536、70,000 bytes 的单个文本值,以及含 70,000 bytes 字段的 JSON 值。连续 3 轮结果分别为 65535/65536/70000/70009,不再触发原 uint16 单字段限制。

    Happy Path 覆盖

    1. 覆盖原阈值两侧 65,535 与 65,536 bytes,以及 70,000 bytes。
    2. 覆盖普通字符串和 JSON 表达式,返回长度与输入契约一致。

    Unhappy Path 覆盖

    1. 将 group_concat_max_len 降至 10 后,70,000 bytes 输入返回长度 10 并产生 Warning 1260;这是配置输出上限的预期截断,不是单字段大小限制。

    白盒验证

    修复 PR matrixone#28702 已合入当前 main;本轮从 SQL 聚合入口覆盖实际 payload 与输出上限路径。

    回归测试

    已加入 motr#169:suites/14_issue_regression/t/issue_28579_28593_28595_28653_28657_28669_compatibility.test。定向用例连续 3/3 通过,共 150/150 statements。

    测试证据

    • 本地输出 SHA-256:6817c73d112d012ae784cbb9c0fc9b515a313e4fd1b1057f0abd7ea15125b9f6(3 轮一致)。
    • 回归 PR:motr#169。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions