diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index accca3152896f..de524a7de28b0 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -328,3 +328,7 @@ Point_Get_1 1.00 root table:t, handle:1 desc select * from t where a = '1'; id count task operator info Point_Get_1 1.00 root table:t, handle:1 +desc select sysdate(), sleep(1), sysdate(); +id count task operator info +Projection_3 1.00 root sysdate(), sleep(1), sysdate() +└─TableDual_4 1.00 root rows:1 diff --git a/cmd/explaintest/t/select.test b/cmd/explaintest/t/select.test index 783b520e31dd0..d062a7e047a4d 100644 --- a/cmd/explaintest/t/select.test +++ b/cmd/explaintest/t/select.test @@ -163,3 +163,5 @@ drop table if exists t; create table t(a bigint primary key, b bigint); desc select * from t where a = 1; desc select * from t where a = '1'; + +desc select sysdate(), sleep(1), sysdate(); diff --git a/expression/function_traits.go b/expression/function_traits.go index 9aa6952416eb1..ae3f4b05ea888 100644 --- a/expression/function_traits.go +++ b/expression/function_traits.go @@ -40,6 +40,7 @@ var UnCacheableFunctions = map[string]struct{}{ // unFoldableFunctions stores functions which can not be folded duration constant folding stage. var unFoldableFunctions = map[string]struct{}{ + ast.Sysdate: {}, ast.FoundRows: {}, ast.Rand: {}, ast.UUID: {}, diff --git a/expression/function_traits_test.go b/expression/function_traits_test.go new file mode 100644 index 0000000000000..13982d9e85907 --- /dev/null +++ b/expression/function_traits_test.go @@ -0,0 +1,26 @@ +// Copyright 2018 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package expression + +import ( + . "github.com/pingcap/check" + "github.com/pingcap/tidb/ast" + "github.com/pingcap/tidb/util/testleak" +) + +func (s *testEvaluatorSuite) TestUnfoldableFuncs(c *C) { + defer testleak.AfterTest(c)() + _, ok := unFoldableFunctions[ast.Sysdate] + c.Assert(ok, IsTrue) +}