Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner, executor: set memory size to MAXUint64 for prepare plan cache test #8556

Merged
merged 10 commits into from
Dec 4, 2018
53 changes: 27 additions & 26 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/metrics"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/testkit"
dto "github.com/prometheus/client_model/go"
"golang.org/x/net/context"
Expand All @@ -47,8 +46,9 @@ func (s *testSuite) TestPrepared(c *C) {
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists prepare_test")
Expand Down Expand Up @@ -253,8 +253,9 @@ func (s *testSuite) TestPreparedLimitOffset(c *C) {
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists prepare_test")
Expand Down Expand Up @@ -292,12 +293,12 @@ func (s *testSuite) TestPreparedNullParam(c *C) {
}()
flags := []bool{false, true}
for _, flag := range flags {
var err error
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -364,12 +365,12 @@ func (s *testSuite) TestPrepareWithAggregation(c *C) {
}()
flags := []bool{false, true}
for _, flag := range flags {
var err error
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -409,12 +410,12 @@ func (s *testSuite) TestPreparedIssue7579(c *C) {
}()
flags := []bool{false, true}
for _, flag := range flags {
var err error
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -463,12 +464,12 @@ func (s *testSuite) TestPreparedInsert(c *C) {
pb := &dto.Metric{}
flags := []bool{false, true}
for _, flag := range flags {
var err error
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists prepare_test")
Expand Down Expand Up @@ -545,12 +546,12 @@ func (s *testSuite) TestPreparedUpdate(c *C) {
pb := &dto.Metric{}
flags := []bool{false, true}
for _, flag := range flags {
var err error
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists prepare_test")
Expand Down Expand Up @@ -604,12 +605,12 @@ func (s *testSuite) TestPreparedDelete(c *C) {
pb := &dto.Metric{}
flags := []bool{false, true}
for _, flag := range flags {
var err error
plannercore.SetPreparedPlanCache(flag)
plannercore.PreparedPlanCacheCapacity = 100
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists prepare_test")
Expand Down Expand Up @@ -658,12 +659,12 @@ func (s *testSuite) TestPrepareDealloc(c *C) {
plannercore.PreparedPlanCacheMemoryGuardRatio = orgMemGuardRatio
plannercore.PreparedPlanCacheMaxMemory = orgMaxMemory
}()
var err error
plannercore.SetPreparedPlanCache(true)
plannercore.PreparedPlanCacheCapacity = 3
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
plannercore.PreparedPlanCacheMaxMemory = math.MaxUint64

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
8 changes: 5 additions & 3 deletions planner/core/point_get_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
package core_test

import (
"math"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
dto "github.com/prometheus/client_model/go"
Expand Down Expand Up @@ -48,8 +49,9 @@ func (s *testPointGetSuite) TestPointGetPlanCache(c *C) {
core.SetPreparedPlanCache(true)
core.PreparedPlanCacheCapacity = 100
core.PreparedPlanCacheMemoryGuardRatio = 0.1
core.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
core.PreparedPlanCacheMaxMemory = math.MaxUint64
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int primary key, b int, c int, key idx_bc(b,c))")
Expand Down
22 changes: 13 additions & 9 deletions planner/core/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package core_test

import (
"math"
"strconv"
"time"

Expand All @@ -24,7 +25,6 @@ import (
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -56,8 +56,9 @@ func (s *testPrepareSuite) TestPrepareCache(c *C) {
core.SetPreparedPlanCache(true)
core.PreparedPlanCacheCapacity = 100
core.PreparedPlanCacheMemoryGuardRatio = 0.1
core.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
core.PreparedPlanCacheMaxMemory = math.MaxUint64
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int primary key, b int, c int, index idx1(b, a), index idx2(b))")
Expand Down Expand Up @@ -105,8 +106,9 @@ func (s *testPrepareSuite) TestPrepareCacheIndexScan(c *C) {
core.SetPreparedPlanCache(true)
core.PreparedPlanCacheCapacity = 100
core.PreparedPlanCacheMemoryGuardRatio = 0.1
core.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
core.PreparedPlanCacheMaxMemory = math.MaxUint64
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, c int, primary key (a, b))")
Expand Down Expand Up @@ -138,8 +140,9 @@ func (s *testPlanSuite) TestPrepareCacheDeferredFunction(c *C) {
core.SetPreparedPlanCache(true)
core.PreparedPlanCacheCapacity = 100
core.PreparedPlanCacheMemoryGuardRatio = 0.1
core.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
core.PreparedPlanCacheMaxMemory = math.MaxUint64

defer testleak.AfterTest(c)()

Expand Down Expand Up @@ -198,8 +201,9 @@ func (s *testPrepareSuite) TestPrepareCacheNow(c *C) {
core.SetPreparedPlanCache(true)
core.PreparedPlanCacheCapacity = 100
core.PreparedPlanCacheMemoryGuardRatio = 0.1
core.PreparedPlanCacheMaxMemory, err = memory.MemTotal()
c.Assert(err, IsNil)
// PreparedPlanCacheMaxMemory is set to MAX_UINT64 to make sure the cache
// behavior would not be effected by the uncertain memory utilization.
core.PreparedPlanCacheMaxMemory = math.MaxUint64
tk.MustExec("use test")
tk.MustExec(`prepare stmt1 from "select now(), sleep(1), now()"`)
// When executing one statement at the first time, we don't use cache, so we need to execute it at least twice to test the cache.
Expand Down