Skip to content

[Bug]: grouped CTAS with BIT_AND, BIT_OR, or BIT_XOR fails during materialization #29323

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues and pull requests.

Branch Name

main

Commit ID

95b1d2b

Other Environment Information

- MatrixOne: local single-CN deployment built from the commit above
- Client: mysql CLI
- Verification: 3 independent rounds

Actual Behavior

CREATE TABLE ... AS SELECT can materialize BIT_AND, BIT_OR, and BIT_XOR when the query has no grouping. The same aggregates fail during CTAS materialization as soon as the query has GROUP BY:

ERROR 3819 (HY000): constraint violation: Column 'a' cannot be null
ERROR 3819 (HY000): constraint violation: Column 'o' cannot be null
ERROR 3819 (HY000): constraint violation: Column 'x' cannot be null

The source groups contain non-NULL values, and the grouped SELECT itself returns the correct non-NULL aggregate values. A grouped VIEW over the same expressions also works. The failure therefore occurs specifically while CTAS materializes the grouped aggregate output.

The behavior is the same for numeric, BINARY, and VARBINARY operands. It is not limited to an all-NULL group.

Expected Behavior

Grouped CTAS should materialize the same values returned by the grouped SELECT. BIT_AND, BIT_OR, and BIT_XOR are non-NULL-producing aggregates and already have executable CTAS defaults.

Steps to Reproduce

DROP DATABASE IF EXISTS bitwise_grouped_ctas_repro;
CREATE DATABASE bitwise_grouped_ctas_repro;
USE bitwise_grouped_ctas_repro;

CREATE TABLE src(g INT, i INT);
INSERT INTO src VALUES (1,15),(1,51),(2,NULL);

-- Control: succeeds and returns (1,3,63,60) and the neutral values for group 2.
SELECT g, BIT_AND(i) a, BIT_OR(i) o, BIT_XOR(i) x
FROM src GROUP BY g ORDER BY g;

-- Control: ungrouped CTAS succeeds.
CREATE TABLE ungrouped AS
SELECT BIT_AND(i) a, BIT_OR(i) o, BIT_XOR(i) x FROM src;

-- Each statement below fails with ERROR 3819.
CREATE TABLE grouped_and AS SELECT g, BIT_AND(i) a FROM src GROUP BY g;
CREATE TABLE grouped_or  AS SELECT g, BIT_OR(i)  o FROM src GROUP BY g;
CREATE TABLE grouped_xor AS SELECT g, BIT_XOR(i) x FROM src GROUP BY g;

SELECT 1 AS recovered;
SHOW TABLES;

Stability, controls, and recovery

  • Reproduced 3/3 on the commit above.
  • The same grouped SELECT and grouped VIEW return correct values.
  • Ungrouped CTAS with all three bitwise aggregates succeeds and creates BIGINT UNSIGNED NOT NULL DEFAULT 0 columns.
  • All three grouped CTAS statements fail independently, including with only non-NULL source rows.
  • Numeric, BINARY, and VARBINARY operands reproduce the same failure.
  • Failed CTAS statements leave no partial tables; the same connection remains usable.

Related work

This report is for a value-materialization failure on the grouped execution path, not another metadata-only compatibility difference.

Suggested regression placement

Extend test/distributed/cases/ddl/create_table_as_select.sql with grouped BIT_AND, BIT_OR, and BIT_XOR CTAS cases, including an all-NULL group and binary-string operands.

Activity

  1. added this to the MO-202609 milestone on Sep 24, 2026
  2. added
    kind/bug
    on Sep 24, 2026
  3. added theissue type on Sep 24, 2026
  4. self-assigned this
    on Sep 24, 2026
  5. added a commit that references this issue on Sep 24, 2026
    9875c6c
  6. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 9875c6c4b4fb03421dc5e695fb378972f96eb790。

    Happy Path 覆盖

    1. 分组 CTAS 可物化 BIT_AND/BIT_OR/BIT_XOR 的数值与二进制结果。

    Unhappy Path 覆盖

    1. 覆盖 NULL 组及 binary/varbinary 输入,物化表行数和聚合值稳定。

    白盒验证

    确认修复提交 9875c6c4b4fb03421dc5e695fb378972f96eb790 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_29323_29325_29327_29328_29329_29330_29331_sql_contracts.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

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