Skip to content

[Bug]: prepared HLL and bitmap state consumers bind parameters as TEXT #29311

Closed

Description

@Ariznawlll

Summary

Prepared statements reject untyped parameter markers passed to HLL_CARDINALITY, HLL_MERGE_AGG, and BITMAP_OR_AGG because the markers are resolved as TEXT. These functions consume opaque VARBINARY aggregate states, but that input domain is not propagated to ?.

The same stored HLL or bitmap state works through a table column and through an explicit CAST(? AS VARBINARY). BITMAP_COUNT(?) is an important control: its fixed scalar signature correctly binds the same untyped marker to VARBINARY.

Version

MatrixOne main: 95b1d2bfd9d756d08320569858080cb16f230fff
Build date: 2026-09-24
Deployment: fresh local launch cluster

Reproduction

CREATE DATABASE repro_hll_prepare;
USE repro_hll_prepare;
CREATE TABLE src(v INT);
INSERT INTO src VALUES (1),(2),(2);
CREATE TABLE states(sketch BLOB);
INSERT INTO states SELECT HLL_ADD_AGG(v) FROM src;
SELECT sketch INTO @sk FROM states;

CREATE TABLE bitmap_states AS
SELECT BITMAP_CONSTRUCT_AGG(BITMAP_BIT_POSITION(v)) AS bitmap FROM src;
SELECT bitmap INTO @bitmap FROM bitmap_states;

-- controls: both return 2
SELECT HLL_CARDINALITY(sketch) FROM states;
PREPARE pc_ok FROM 'SELECT HLL_CARDINALITY(CAST(? AS VARBINARY))';
EXECUTE pc_ok USING @sk;

-- rejected during PREPARE
PREPARE pc FROM 'SELECT HLL_CARDINALITY(?)';

-- explicit-cast merge control returns 2
PREPARE pm_ok FROM
  'SELECT HLL_CARDINALITY(HLL_MERGE_AGG(CAST(? AS VARBINARY))) FROM src';
EXECUTE pm_ok USING @sk;

-- rejected during PREPARE
PREPARE pm FROM
  'SELECT HLL_CARDINALITY(HLL_MERGE_AGG(?)) FROM src';

-- bitmap scalar control succeeds and returns 2
PREPARE bc FROM 'SELECT BITMAP_COUNT(?)';
EXECUTE bc USING @bitmap;

-- bitmap aggregate state consumer is rejected during PREPARE
PREPARE bo FROM
  'SELECT BITMAP_COUNT(BITMAP_OR_AGG(?)) FROM src';

Each failing PREPARE statement reproduces in three consecutive attempts.

Actual behavior

invalid argument function hll_cardinality, bad value [TEXT]
invalid argument aggregate function hll_merge_agg, bad value [TEXT]
invalid argument aggregate function bitmap_or_agg, bad value [TEXT]

Expected behavior

The parameter marker should bind to the VARBINARY input domain, matching the explicit-cast and BITMAP_COUNT(?) controls. Persisted HLL and bitmap states should be reusable through prepared aggregate consumers without requiring callers to add a MatrixOne-specific cast.

Code analysis

The function registry handles T_any as follows:

  • HLL_CARDINALITY: cast unknown input to VARBINARY;
  • HLL_MERGE_AGG: cast unknown input to VARBINARY.
  • BITMAP_OR_AGG: fixed unary aggregate input is VARBINARY, while the scalar BITMAP_COUNT(?) fixed signature successfully supplies that domain.

The observed [TEXT] diagnostic shows that prepared-parameter inference assigns a text type before the aggregate/function domain rules can supply the binary type.

Duplicate / compatibility-contract check

  • No matching open or closed MatrixOne issue or fix PR was found for prepared HLL_CARDINALITY, HLL_MERGE_AGG, or BITMAP_OR_AGG parameters.
  • mysql-compatibility-contract/README.md contains no HLL, HyperLogLog, bitmap, or opaque-state known limitation and no exemption for this prepared binary binding path.

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. changed the title [-][Bug]: prepared HLL_CARDINALITY and HLL_MERGE_AGG parameters are bound as TEXT[/-] [+][Bug]: prepared HLL and bitmap state consumers bind parameters as TEXT[/+] on Sep 24, 2026
  5. self-assigned this
    on Sep 24, 2026
  6. added a commit that references this issue on Sep 24, 2026
    5d80e0b
  7. 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 已包含修复提交 5d80e0bc0348c31325c9a54488561c567076abb0。

    Happy Path 覆盖

    1. HLL 与 bitmap 二进制状态通过 prepared 参数传入后可正确消费,基数均为 2。

    Unhappy Path 覆盖

    1. 非法 00 HLL payload 返回 20301;错误后重新绑定合法状态仍成功。

    白盒验证

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

    回归测试

    已加入 MOTR PR #204 的 issue_29311_29313_29314_29320_prepared_domains.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