Repository navigation
Description
Problem
PreparedStatement execution of ELT truncates fractional DECIMAL/string indexes toward zero, while the same literal or DECIMAL column is rounded to the nearest integer. The chosen array element therefore depends on the execution path.
Reproduction
drop database if exists elt_prepared_repro;
create database elt_prepared_repro;
use elt_prepared_repro;
select elt(1.4,'a','b','c'), elt(1.5,'a','b','c'), elt(1.6,'a','b','c'),
elt(2.4,'a','b','c'), elt(2.5,'a','b','c'), elt(2.6,'a','b','c');
create table src(id int primary key,idx decimal(4,2));
insert into src values (1,1.40),(2,1.50),(3,1.60),(4,2.40),(5,2.50),(6,2.60);
select id,idx,elt(idx,'a','b','c') from src order by id;
prepare p from 'select elt(?,''a'',''b'',''c'')';
set @i=1.5; execute p using @i;
set @i=1.6; execute p using @i;
set @i=2.5; execute p using @i;
set @i=2.6; execute p using @i;
set @i=cast(1.5 as decimal(4,2)); execute p using @i;
set @i='1.5'; execute p using @i;MatrixOne result
- Direct literals and DECIMAL columns choose
b,b,c, andcfor indexes 1.5, 1.6, 2.5, and 2.6. - The prepared executions choose
a,a,b, andbfor the same values. - Explicit DECIMAL parameter 1.5 and string parameter
'1.5'also choosea.
Thus values from [1.0,2.0) select item 1 and values from [2.0,3.0) select item 2 only on the prepared path.
MySQL 8.0.45 result
DECIMAL literals, DECIMAL columns, ordinary DECIMAL user variables, explicit DECIMAL parameters, and numeric strings use the same nearest-integer conversion: 1.5/1.6 choose b; 2.5/2.6 choose c.
An explicit DOUBLE parameter is a type-sensitive control and follows MySQL's DOUBLE-to-integer behavior; it is not used as the expected result for the DECIMAL cases above.
Stability and scope
- 1.4, 1.5, 1.6, 2.4, 2.5, 2.6, NULL, explicit DECIMAL, explicit DOUBLE, numeric string, and integer string are covered.
- A second prepared statement executes the types in reverse order; the MatrixOne result remains the same, so this is not first-execution cache poisoning.
- Three independent executions produced identical output on each database.
Code location
eltCheck in pkg/sql/plan/function/func_binary.go resolves noninteger indexes by inserting an INT64 cast. The prepared-parameter conversion does not preserve the DECIMAL/string integer-conversion semantics used by literals and columns. This is the focused code-path hypothesis; the externally visible bug is the result difference above.
Environment
- MatrixOne: official
maincommit0c3a04f390adaf6281fd592a49778ea5b1155e67 - MySQL control: 8.0.45
- Local single-node MatrixOne deployment
Activity
fix compatibility for concat, prepared elt, and string numeric results (
Ariznawlll commentedon Sep 16, 2026
测试版本
main8a4c84f4516d5098de9eef50b8afecc7524f37a2原问题验证
验证字面量、DECIMAL 列和 Prepared
ELT的小数索引语义。1.5/1.6均选择第 2 个元素,2.5/2.6均选择第 3 个元素;Prepared 与非 Prepared 结果一致。Happy Path 覆盖
ELT(1.5/2.5, ...)结果为b/c。b/c。Unhappy Path 覆盖
不适用;本 issue 验证的是合法 DECIMAL/Prepared 参数的兼容性,没有引入非法索引作为替代预期。
白盒验证
不适用;以公开 SQL 结果一致性为准。
回归测试
已加入 motr PR #181 的
issue_28908_28904_compat.test/.result。测试证据
最新 main 集群版本为
commit-8a4c84f;3/3 次 Prepared 与字面量结果一致。测试结论
测试通过。
fix compatibility for concat, prepared elt, and string numeric results (
fix compatibility for concat, prepared elt, and string numeric results (