expression: fix incorrect short path in truncate function (#58656)

close pingcap/tidb#57608
This commit is contained in:
xzhangxian1008
2025-01-03 18:01:34 +08:00
committed by GitHub
parent d9e197f3be
commit 1a455d0ff3
2 changed files with 20 additions and 3 deletions

View File

@ -2157,15 +2157,16 @@ func (b *builtinTruncateIntSig) evalInt(ctx EvalContext, row chunk.Row) (int64,
if isNull || err != nil {
return 0, isNull, err
}
if mysql.HasUnsignedFlag(b.args[1].GetType(ctx).GetFlag()) {
return x, false, nil
}
d, isNull, err := b.args[1].EvalInt(ctx, row)
if isNull || err != nil {
return 0, isNull, err
}
if mysql.HasUnsignedFlag(b.args[1].GetType(ctx).GetFlag()) {
return x, false, nil
}
if d >= 0 {
return x, false, nil
}

View File

@ -4158,3 +4158,19 @@ func TestIssue55886(t *testing.T) {
" (t1 as ref_4 right outer join t2 as ref_5 on ref_5.c_g7eofzlxn != 1)), cte_4 as (select 1 as c1 from t2) select ref_34.c1 as c5 from" +
" cte_0 as ref_34 where exists (select 1 from cte_4 as ref_35 where ref_34.c1 <= case when ref_34.c5 then cast(1 as char) else ref_34.c5 end);")
}
func TestIssue57608(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 ( c1 int primary key);")
tk.MustExec("insert into t1 (c1) values (1), (2), (3), (4), (5), (6), (7), (11), (12), (13), (14), (15), (16), (17), (21), (22), (23), (24), (25), (26), (27), (116), (127), (121), (122), (113), (214), (251), (261), (217), (91), (92), (39), (94), (95), (69), (79), (191), (129);")
tk.MustExec("create view v2 as select 0 as q2 from t1;")
for i := 0; i < 10; i++ {
tk.MustQuery("select distinct 1 between NULL and 1 as w0, truncate(1, (cast(ref_1.q2 as unsigned) % 0)) as w1, (1 between truncate(1, (cast(ref_1.q2 as unsigned) % 0)) and 1) as w2 from (v2 as ref_0 inner join v2 as ref_1 on (1=1));").Check(testkit.Rows(
"<nil> <nil> <nil>",
))
}
}