Skip to content

Commit

Permalink
config: disable prepare plan cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka committed Mar 9, 2021
1 parent f6a61bc commit 42d7a14
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ var defaultConf = Config{
HeaderTimeout: 5,
},
PreparedPlanCache: PreparedPlanCache{
Enabled: true,
Enabled: false,
Capacity: 100,
MemoryGuardRatio: 0.1,
},
Expand Down
2 changes: 1 addition & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ networks = ""
header-timeout = 5

[prepared-plan-cache]
enabled = true
enabled = false
capacity = 100
memory-guard-ratio = 0.1

Expand Down
14 changes: 12 additions & 2 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5893,9 +5893,19 @@ func (s *testIntegrationSuite) TestCastStrToInt(c *C) {
func (s *testIntegrationSerialSuite) TestPreparePlanCache(c *C) {
tk := testkit.NewTestKit(c, s.store)

// Plan cache should now be on by default
c.Assert(plannercore.PreparedPlanCacheEnabled(), Equals, true)
// Plan cache should now be off by default
c.Assert(plannercore.PreparedPlanCacheEnabled(), Equals, false)

orgEnable := plannercore.PreparedPlanCacheEnabled()
defer func() {
plannercore.SetPreparedPlanCache(orgEnable)
}()
plannercore.SetPreparedPlanCache(true)
var err error
tk.Se, err = session.CreateSession4TestWithOpt(s.store, &session.Opt{
PreparedPlanCache: kvcache.NewSimpleLRUCache(100, 0.1, math.MaxUint64),
})
c.Assert(err, IsNil)
// Use the example from the docs https://docs.pingcap.com/tidb/stable/sql-prepare-plan-cache
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
Expand Down
4 changes: 2 additions & 2 deletions planner/core/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (

var (
// preparedPlanCacheEnabledValue stores the global config "prepared-plan-cache-enabled".
// The value is true unless "prepared-plan-cache-enabled" is FALSE in configuration.
preparedPlanCacheEnabledValue int32 = 1
// The value is false unless "prepared-plan-cache-enabled" is true in configuration.
preparedPlanCacheEnabledValue int32 = 0
// PreparedPlanCacheCapacity stores the global config "prepared-plan-cache-capacity".
PreparedPlanCacheCapacity uint = 100
// PreparedPlanCacheMemoryGuardRatio stores the global config "prepared-plan-cache-memory-guard-ratio".
Expand Down

0 comments on commit 42d7a14

Please sign in to comment.