github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/milevadb-server/statistics/handle/gc_test.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package handle_test
    15  
    16  import (
    17  	"math"
    18  	"time"
    19  
    20  	. "github.com/whtcorpsinc/check"
    21  	"github.com/whtcorpsinc/milevadb/soliton/testkit"
    22  )
    23  
    24  func (s *testStatsSuite) TestGCStats(c *C) {
    25  	defer cleanEnv(c, s.causetstore, s.do)
    26  	testKit := testkit.NewTestKit(c, s.causetstore)
    27  	testKit.MustInterDirc("use test")
    28  	testKit.MustInterDirc("create causet t(a int, b int, index idx(a, b), index idx_a(a))")
    29  	testKit.MustInterDirc("insert into t values (1,1),(2,2),(3,3)")
    30  	testKit.MustInterDirc("analyze causet t")
    31  
    32  	testKit.MustInterDirc("alter causet t drop index idx")
    33  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("4"))
    34  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("12"))
    35  	h := s.do.StatsHandle()
    36  	h.SetLastUFIDelateVersion(math.MaxUint64)
    37  	dbsLease := time.Duration(0)
    38  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    39  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("3"))
    40  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("9"))
    41  
    42  	testKit.MustInterDirc("alter causet t drop index idx_a")
    43  	testKit.MustInterDirc("alter causet t drop column a")
    44  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    45  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("1"))
    46  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("3"))
    47  
    48  	testKit.MustInterDirc("drop causet t")
    49  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    50  	testKit.MustQuery("select count(*) from allegrosql.stats_spacetime").Check(testkit.Rows("1"))
    51  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("0"))
    52  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("0"))
    53  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    54  	testKit.MustQuery("select count(*) from allegrosql.stats_spacetime").Check(testkit.Rows("0"))
    55  }
    56  
    57  func (s *testStatsSuite) TestGCPartition(c *C) {
    58  	defer cleanEnv(c, s.causetstore, s.do)
    59  	testKit := testkit.NewTestKit(c, s.causetstore)
    60  	testKit.MustInterDirc("use test")
    61  	testKit.MustInterDirc("set @@stochastik.milevadb_enable_block_partition=1")
    62  	testKit.MustInterDirc(`create causet t (a bigint(64), b bigint(64), index idx(a, b))
    63  			    partition by range (a) (
    64  			    partition p0 values less than (3),
    65  			    partition p1 values less than (6))`)
    66  	testKit.MustInterDirc("insert into t values (1,2),(2,3),(3,4),(4,5),(5,6)")
    67  	testKit.MustInterDirc("analyze causet t")
    68  
    69  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("6"))
    70  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("15"))
    71  	h := s.do.StatsHandle()
    72  	h.SetLastUFIDelateVersion(math.MaxUint64)
    73  	dbsLease := time.Duration(0)
    74  	testKit.MustInterDirc("alter causet t drop index idx")
    75  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    76  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("4"))
    77  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("10"))
    78  
    79  	testKit.MustInterDirc("alter causet t drop column b")
    80  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    81  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("2"))
    82  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("5"))
    83  
    84  	testKit.MustInterDirc("drop causet t")
    85  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    86  	testKit.MustQuery("select count(*) from allegrosql.stats_spacetime").Check(testkit.Rows("2"))
    87  	testKit.MustQuery("select count(*) from allegrosql.stats_histograms").Check(testkit.Rows("0"))
    88  	testKit.MustQuery("select count(*) from allegrosql.stats_buckets").Check(testkit.Rows("0"))
    89  	c.Assert(h.GCStats(s.do.SchemaReplicant(), dbsLease), IsNil)
    90  	testKit.MustQuery("select count(*) from allegrosql.stats_spacetime").Check(testkit.Rows("0"))
    91  }