From 7f3e19e0333b01cd67b38466aa50662d6fb540e1 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Thu, 11 Mar 2021 14:35:56 +0800 Subject: [PATCH] fix Signed-off-by: lzmhhh123 --- executor/analyze_test.go | 5 ++++- planner/core/planbuilder.go | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 314410e5ae440..daf12ba5f2ab5 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -929,6 +929,7 @@ func (s *testSerialSuite2) TestIssue20874(c *C) { 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)") @@ -937,5 +938,7 @@ func (s *testSuite1) TestAnalyzeClusteredIndexPrimary(c *C) { 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("")) + 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 e4bb839738ad6..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 @@ -1749,6 +1750,7 @@ func (b *PlanBuilder) buildAnalyzeIndex(as *ast.AnalyzeTableStmt, opts map[ast.A } p.ColTasks = append(p.ColTasks, AnalyzeColumnsTask{HandleCols: handleCols, analyzeInfo: info, TblInfo: tblInfo}) } + continue } } idx := tblInfo.FindIndexByName(idxName.L)