Skip to content

[Bug]: PAD SPACE CHAR set operations return wrong UNION/INTERSECT/MINUS results #28952

Closed

Description

@XuPeng-SH

CI evidence

The same failure family appears on unrelated PRs:

Reproduction

The failing fixture is test/distributed/cases/dtype/pad_char_to_full_length.sql:

CREATE TABLE pad_char_set8 (c CHAR(8));
CREATE TABLE pad_char_set4 (c CHAR(4));
INSERT INTO pad_char_set8 VALUES ('MO');
INSERT INTO pad_char_set4 VALUES ('MO');

SELECT COUNT(*) FROM
  (SELECT c FROM pad_char_set8 UNION SELECT c FROM pad_char_set4) u;
SELECT COUNT(*) FROM
  (SELECT c FROM pad_char_set8 INTERSECT SELECT c FROM pad_char_set4) i;
SELECT COUNT(*) FROM
  (SELECT c FROM pad_char_set8 MINUS SELECT c FROM pad_char_set4) m;

Expected results:

UNION      1
INTERSECT  1
MINUS      0

Observed results:

UNION      2
INTERSECT  0
MINUS      1

The reverse-order UNION cases also return both an unpadded length-4 value and a padded length-8 value, instead of one PAD SPACE-equivalent result.

Expected behavior

CHAR values that differ only by trailing PAD SPACE should use one consistent equality/key normalization across UNION, INTERSECT, and MINUS. Mixed CHAR widths must not create distinct set keys solely because the physical padded lengths differ.

Attribution

The failing PRs do not modify this CHAR set-operation path. This is a base/shared PAD SPACE semantics regression.

Related #28024 covers PAD SPACE loss for COALESCE/IFNULL expression keys, and #27525 covered parallel INTERSECT duplicate keys; this issue is the direct mixed-width CHAR set-key failure.

Activity

  1. self-assigned this
    on Sep 15, 2026
  2. added
    kind/bug
    on Sep 15, 2026
  3. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:8e8e1998ef02b1f6233ddb1c2d3208f3b70d2d83
    • 部署:隔离的单 CN / 单 TN / 单 LogService 本地集群,通过 MySQL 协议执行。
    • 日期:2026-09-17

    原问题验证

    使用 CHAR(8) 与 CHAR(4) 的相同文本值 MO 复现集合运算。UNION、INTERSECT、MINUS 均返回正确基数(1、1、0),交换左右输入后结果保持一致,未再发生 PAD SPACE 语义丢失或误判为不相等。

    Happy Path 覆盖

    覆盖 UNION、INTERSECT、MINUS 及两种 operand 顺序。

    Unhappy Path 覆盖

    不适用:该问题是等值语义错误,不存在独立的失败输入;双向 MINUS 为非匹配结果的反向控制。

    白盒验证

    不适用:以 SQL 结果和交换操作数后的语义不变性作为黑盒验收。

    回归测试

    已加入 MOTR PR #181:issue_28952_28897_character_coercion.test。本地连续 3 轮通过。

    测试证据

    motr --repeat 3 14_issue_regression.issue_28952_28897_character_coercion:3/3 通过,21 条 SQL/轮均成功。

    测试结论

    测试通过。

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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions