Files
tidb/pkg/statistics/handle/autoanalyze/exec/exec_test.go

54 lines
1.6 KiB
Go

// Copyright 2024 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package exec_test
import (
"context"
"testing"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/statistics/handle/autoanalyze/exec"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
)
func TestExecAutoAnalyzes(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t (a int, b int, index idx(a))")
tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3)")
se := tk.Session()
sctx := se.(sessionctx.Context)
handle := dom.StatsHandle()
exec.AutoAnalyze(
sctx,
handle,
dom.SysProcTracker(),
2, "analyze table %n", "t",
)
// Check the result of analyze.
is := dom.InfoSchema()
tbl, err := is.TableByName(context.Background(), model.NewCIStr("test"), model.NewCIStr("t"))
require.NoError(t, err)
tblStats := handle.GetTableStats(tbl.Meta())
require.Equal(t, int64(3), tblStats.RealtimeCount)
}