Skip to content

Commit e13181f

Browse files
authored
planner: fix stack overflow caused by folding constant (#10174)
1 parent 2a6c8d6 commit e13181f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

expression/constant_fold.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ func foldConstant(expr Expression) (Expression, bool) {
117117
constArgs[i] = One
118118
}
119119
}
120-
dummyScalarFunc := NewFunctionInternal(x.GetCtx(), x.FuncName.L, x.GetType(), constArgs...)
120+
dummyScalarFunc, err := NewFunctionBase(x.GetCtx(), x.FuncName.L, x.GetType(), constArgs...)
121+
if err != nil {
122+
return expr, isDeferredConst
123+
}
121124
value, err := dummyScalarFunc.Eval(chunk.Row{})
122125
if err != nil {
123126
return expr, isDeferredConst

expression/integration_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,3 +4213,25 @@ func (s *testIntegrationSuite) TestDaynameArithmetic(c *C) {
42134213
tk.MustQuery(c.sql).Check(testkit.Rows(c.result))
42144214
}
42154215
}
4216+
4217+
func (s *testIntegrationSuite) TestIssue10156(c *C) {
4218+
tk := testkit.NewTestKit(c, s.store)
4219+
defer s.cleanEnv(c)
4220+
4221+
tk.MustExec("use test")
4222+
tk.MustExec("CREATE TABLE `t1` (`period_name` varchar(24) DEFAULT NULL ,`period_id` bigint(20) DEFAULT NULL ,`starttime` bigint(20) DEFAULT NULL)")
4223+
tk.MustExec("CREATE TABLE `t2` (`bussid` bigint(20) DEFAULT NULL,`ct` bigint(20) DEFAULT NULL)")
4224+
q := `
4225+
select
4226+
a.period_name,
4227+
b.date8
4228+
from
4229+
(select * from t1) a
4230+
left join
4231+
(select bussid,date(from_unixtime(ct)) date8 from t2) b
4232+
on
4233+
a.period_id = b.bussid
4234+
where
4235+
datediff(b.date8, date(from_unixtime(a.starttime))) >= 0`
4236+
tk.MustQuery(q)
4237+
}

0 commit comments

Comments
 (0)