diff --git a/executor/tiflash_test.go b/executor/tiflash_test.go index e41e7f81f9eb7..94d5c4726a3a3 100644 --- a/executor/tiflash_test.go +++ b/executor/tiflash_test.go @@ -959,3 +959,20 @@ func (s *tiflashTestSuite) TestForbidTiflashDuringStaleRead(c *C) { c.Assert(strings.Contains(res, "tiflash"), IsFalse) c.Assert(strings.Contains(res, "tikv"), IsTrue) } + +func (s *tiflashTestSuite) TestIssue29154(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a char(20))") + tk.MustExec("alter table t set tiflash replica 1") + tb := testGetTableByName(c, tk.Se, "test", "t") + err := domain.GetDomain(tk.Se).DDL().UpdateTableReplicaInfo(tk.Se, tb.Meta().ID, true) + c.Assert(err, IsNil) + time.Sleep(2 * time.Second) + tk.MustExec("set session tidb_isolation_read_engines=\"tiflash\";") + tk.MustQuery("explain select * from t where trim('x' from a)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Scalar function 'trim'(signature: Trim2Args, return type: var_string(5)) can not be pushed to storage layer")) + tk.MustQuery("explain select * from t where trim(trailing 'x' from a)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Scalar function 'trim'(signature: Trim3Args, return type: var_string(20)) can not be pushed to storage layer")) +} diff --git a/expression/expression.go b/expression/expression.go index 3a1df326ce809..b79aea6e9502a 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -1032,8 +1032,13 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool { ast.Radians, ast.Degrees, ast.Conv, ast.CRC32, ast.JSONLength, ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton, - ast.Coalesce, ast.ASCII, ast.Length, ast.Trim, ast.Position: + ast.Coalesce, ast.ASCII, ast.Length, ast.Position: return true + case ast.Trim: + switch function.Function.PbCode() { + case tipb.ScalarFuncSig_Trim1Arg: + return true + } case ast.Substr, ast.Substring, ast.Left, ast.Right, ast.CharLength: switch function.Function.PbCode() { case