Skip to content

Commit

Permalink
plan: disable plan cache for query containing SubqueryExpr (#8395)
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored and zz-jason committed Nov 22, 2018
1 parent 2953616 commit 4dd328b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ func (s *testSuite) TestPrepared(c *C) {
c.Assert(err, IsNil)
tk.ResultSetToResult(rs, Commentf("%v", rs)).Check(testkit.Rows("3"))

tk.MustExec("delete from prepare_test")
query = "select c1 from prepare_test where c1 = (select c1 from prepare_test where c1 = ?)"
stmtId, _, _, err = tk.Se.PrepareStmt(query)
_, err = tk.Se.ExecutePreparedStmt(ctx, stmtId, 3)
c.Assert(err, IsNil)
tk1.MustExec("insert prepare_test (c1) values (3)")
rs, err = tk.Se.ExecutePreparedStmt(ctx, stmtId, 3)
c.Assert(err, IsNil)
tk.ResultSetToResult(rs, Commentf("%v", rs)).Check(testkit.Rows("3"))

tk.MustExec("delete from prepare_test")
query = "select c1 from prepare_test where c1 in (select c1 from prepare_test where c1 = ?)"
stmtId, _, _, err = tk.Se.PrepareStmt(query)
_, err = tk.Se.ExecutePreparedStmt(ctx, stmtId, 3)
c.Assert(err, IsNil)
tk1.MustExec("insert prepare_test (c1) values (3)")
rs, err = tk.Se.ExecutePreparedStmt(ctx, stmtId, 3)
c.Assert(err, IsNil)
tk.ResultSetToResult(rs, Commentf("%v", rs)).Check(testkit.Rows("3"))

tk.MustExec("begin")
tk.MustExec("insert prepare_test (c1) values (4)")
query = "select c1, c2 from prepare_test where c1 = ?"
Expand Down
2 changes: 1 addition & 1 deletion plan/cacheable_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type cacheableChecker struct {
// Enter implements Visitor interface.
func (checker *cacheableChecker) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
switch node := in.(type) {
case *ast.VariableExpr, *ast.ExistsSubqueryExpr:
case *ast.VariableExpr, *ast.ExistsSubqueryExpr, *ast.SubqueryExpr:
checker.cacheable = false
return in, true
case *ast.FuncCallExpr:
Expand Down

0 comments on commit 4dd328b

Please sign in to comment.