diff --git a/pkg/expression/util.go b/pkg/expression/util.go index eaff6d6b1bf68..cd418fb4e618c 100644 --- a/pkg/expression/util.go +++ b/pkg/expression/util.go @@ -519,7 +519,11 @@ func ColumnSubstituteImpl(ctx BuildContext, expr Expression, schema *Schema, new } } if substituted { - return true, hasFail, NewFunctionInternal(ctx, v.FuncName.L, v.RetType, refExprArr.Result()...) + newFunc, err := NewFunction(ctx, v.FuncName.L, v.RetType, refExprArr.Result()...) + if err != nil { + return true, true, v + } + return true, hasFail, newFunc } } return false, false, expr diff --git a/tests/integrationtest/r/planner/core/integration.result b/tests/integrationtest/r/planner/core/integration.result index 56aa43bc98f91..c642d678c258f 100644 --- a/tests/integrationtest/r/planner/core/integration.result +++ b/tests/integrationtest/r/planner/core/integration.result @@ -4305,3 +4305,10 @@ id 2 drop table sys.t; set tidb_isolation_read_engines=DEFAULT; +drop table if exists t; +create table t (col TEXT); +select 1 from (select t.col as c0, 46578369 as c1 from t) as t where +case when ( +t.c0 in (t.c0, cast((cast(1 as unsigned) - cast(t.c1 as signed)) as char)) +) then 1 else 2 end; +1 diff --git a/tests/integrationtest/t/planner/core/integration.test b/tests/integrationtest/t/planner/core/integration.test index 7dbd75208f0ab..6283261333f44 100644 --- a/tests/integrationtest/t/planner/core/integration.test +++ b/tests/integrationtest/t/planner/core/integration.test @@ -2369,3 +2369,11 @@ set tidb_isolation_read_engines='tiflash'; select * from sys.t; drop table sys.t; set tidb_isolation_read_engines=DEFAULT; + +# TestIssue53580 +drop table if exists t; +create table t (col TEXT); +select 1 from (select t.col as c0, 46578369 as c1 from t) as t where + case when ( + t.c0 in (t.c0, cast((cast(1 as unsigned) - cast(t.c1 as signed)) as char)) + ) then 1 else 2 end; \ No newline at end of file