diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 556f0b339a3de..daf12ba5f2ab5 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -926,3 +926,19 @@ func (s *testSerialSuite2) TestIssue20874(c *C) { "test t idxb 1 1 3 2 \x00C \x00C 0", )) } + +func (s *testSuite1) TestAnalyzeClusteredIndexPrimary(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t0") + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t0(a varchar(20), primary key(a) clustered)") + tk.MustExec("create table t1(a varchar(20), primary key(a))") + tk.MustExec("insert into t0 values('1111')") + tk.MustExec("insert into t1 values('1111')") + tk.MustExec("analyze table t0 index primary") + tk.MustExec("analyze table t1 index primary") + tk.MustQuery("show stats_buckets").Check(testkit.Rows( + "test t0 PRIMARY 1 0 1 1 1111 1111 0", + "test t1 PRIMARY 1 0 1 1 1111 1111 0")) +} diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index fc1a7bea8813b..5b9d61d0a64ea 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1735,7 +1735,8 @@ func (b *PlanBuilder) buildAnalyzeIndex(as *ast.AnalyzeTableStmt, opts map[ast.A for _, idxName := range as.IndexNames { if isPrimaryIndex(idxName) { handleCols := BuildHandleColsForAnalyze(b.ctx, tblInfo) - if handleCols != nil { + // Fast analyze use analyze column to solve int handle. + if handleCols != nil && handleCols.IsInt() && b.ctx.GetSessionVars().EnableFastAnalyze { for i, id := range physicalIDs { if id == tblInfo.ID { id = -1