Repository navigation
Description
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 toVARBINARY;HLL_MERGE_AGG: cast unknown input toVARBINARY.BITMAP_OR_AGG: fixed unary aggregate input isVARBINARY, while the scalarBITMAP_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, orBITMAP_OR_AGGparameters. mysql-compatibility-contract/README.mdcontains no HLL, HyperLogLog, bitmap, or opaque-state known limitation and no exemption for this prepared binary binding path.
Activity
[-][Bug]: prepared HLL_CARDINALITY and HLL_MERGE_AGG parameters are bound as TEXT[/-][+][Bug]: prepared HLL and bitmap state consumers bind parameters as TEXT[/+]fix: preserve prepared table-function domains through consumers and C…
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交
5d80e0bc0348c31325c9a54488561c567076abb0。Happy Path 覆盖
Unhappy Path 覆盖
00HLL payload 返回 20301;错误后重新绑定合法状态仍成功。白盒验证
确认修复提交
5d80e0bc0348c31325c9a54488561c567076abb0是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。回归测试
已加入 MOTR PR #204 的
issue_29311_29313_29314_29320_prepared_domains.test,MOTR 提交2b4462f2;本地基线比对连续 3 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。