diff --git a/executor/prepared_test.go b/executor/prepared_test.go index 1e56b37ee94e9..57d2a2a791a55 100644 --- a/executor/prepared_test.go +++ b/executor/prepared_test.go @@ -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" @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -706,7 +707,9 @@ func (s *testSuite) TestPreparedIssue8153(c *C) { plannercore.SetPreparedPlanCache(flag) plannercore.PreparedPlanCacheCapacity = 100 plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1 - plannercore.PreparedPlanCacheMaxMemory, err = memory.MemTotal() + // 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") diff --git a/planner/core/point_get_plan_test.go b/planner/core/point_get_plan_test.go index be81fff292802..a485bd488aac8 100644 --- a/planner/core/point_get_plan_test.go +++ b/planner/core/point_get_plan_test.go @@ -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" @@ -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))") diff --git a/planner/core/prepare_test.go b/planner/core/prepare_test.go index 38f914870fe6b..795b563bfd5aa 100644 --- a/planner/core/prepare_test.go +++ b/planner/core/prepare_test.go @@ -14,6 +14,7 @@ package core_test import ( + "math" "strconv" "time" @@ -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" @@ -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))") @@ -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))") @@ -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)() @@ -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.