Skip to content

Commit 9a4c874

Browse files
committed
planner: fix stack overflow caused by folding constant (#10174)
1 parent 8bbcdd8 commit 9a4c874

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
@@ -3875,3 +3875,25 @@ func (s *testIntegrationSuite) TestIssue9325(c *C) {
38753875
result = tk.MustQuery("select * from t where a < timestamp'2019-02-16 14:21:00'")
38763876
result.Check(testkit.Rows("2019-02-16 14:19:59", "2019-02-16 14:20:01"))
38773877
}
3878+
3879+
func (s *testIntegrationSuite) TestIssue10156(c *C) {
3880+
tk := testkit.NewTestKit(c, s.store)
3881+
defer s.cleanEnv(c)
3882+
3883+
tk.MustExec("use test")
3884+
tk.MustExec("CREATE TABLE `t1` (`period_name` varchar(24) DEFAULT NULL ,`period_id` bigint(20) DEFAULT NULL ,`starttime` bigint(20) DEFAULT NULL)")
3885+
tk.MustExec("CREATE TABLE `t2` (`bussid` bigint(20) DEFAULT NULL,`ct` bigint(20) DEFAULT NULL)")
3886+
q := `
3887+
select
3888+
a.period_name,
3889+
b.date8
3890+
from
3891+
(select * from t1) a
3892+
left join
3893+
(select bussid,date(from_unixtime(ct)) date8 from t2) b
3894+
on
3895+
a.period_id = b.bussid
3896+
where
3897+
datediff(b.date8, date(from_unixtime(a.starttime))) >= 0`
3898+
tk.MustQuery(q)
3899+
}

0 commit comments

Comments
 (0)