Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Dec 5, 2024
1 parent 2831cb6 commit 6d80f37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
25 changes: 9 additions & 16 deletions pkg/statistics/handle/handletest/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/planner/cardinality"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/sessiontxn"
"github.com/pingcap/tidb/pkg/statistics"
"github.com/pingcap/tidb/pkg/statistics/handle"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
Expand Down Expand Up @@ -1490,30 +1491,22 @@ func TestSkipMissingPartitionStats(t *testing.T) {
})
}

func TestStatsCacheUpdateTimeout(t *testing.T) {
func TestReadStatsWithoutAnalyzeAndHandleEvent(t *testing.T) {
// it means it only has stats_meta without stats_hist
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'")
tk.MustExec("set @@tidb_skip_missing_partition_stats = 1")
tk.MustExec("create table t (a int, b int, c int, index idx_b(b)) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200), partition p2 values less than (300))")
tk.MustExec("insert into t values (1,1,1), (2,2,2), (101,101,101), (102,102,102), (201,201,201), (202,202,202)")
analyzehelper.TriggerPredicateColumnsCollection(t, tk, store, "t", "a", "b", "c")
h := dom.StatsHandle()
require.NoError(t, h.DumpStatsDeltaToKV(true))
tk.MustExec("analyze table t partition p0, p1")
tbl, err := dom.InfoSchema().TableByName(context.Background(), model.NewCIStr("test"), model.NewCIStr("t"))
is := sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema()
table, err := is.TableByName(context.Background(), model.NewCIStr("test"), model.NewCIStr("t"))
require.NoError(t, err)
tblInfo := tbl.Meta()
globalStats := h.GetTableStats(tblInfo)
require.Equal(t, 6, int(globalStats.RealtimeCount))
require.Equal(t, 2, int(globalStats.ModifyCount))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/statistics/handle/util/ExecRowsTimeout", "return()"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/util/ExecRowsTimeout"))
}()
require.Error(t, h.Update(context.Background(), dom.InfoSchema()))
globalStats2 := h.GetTableStats(tblInfo)
require.Equal(t, 6, int(globalStats2.RealtimeCount))
require.Equal(t, 2, int(globalStats2.ModifyCount))
tableInfo := table.Meta()
tblStats, err := h.TableStatsFromStorage(tableInfo, tableInfo.ID, true, 0)
require.NoError(t, err)
require.NotNil(t, tblStats)
}
2 changes: 1 addition & 1 deletion pkg/statistics/handle/storage/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func TableStatsFromStorage(sctx sessionctx.Context, snapshot uint64, tableInfo *
}
// Check deleted table.
if len(rows) == 0 {
return nil, nil
return table, nil
}
for _, row := range rows {
if err := sctx.GetSessionVars().SQLKiller.HandleSignal(); err != nil {
Expand Down

0 comments on commit 6d80f37

Please sign in to comment.