planner: warn for incremental analyze in version 3 stats (#24689)
This commit is contained in:
@ -3637,6 +3637,31 @@ func (s *testIntegrationSuite) TestIssue24281(c *C) {
|
||||
"UNION select 1 as v1, 2 as v2")
|
||||
}
|
||||
|
||||
func (s *testIntegrationSuite) TestIncrementalAnalyzeStatsVer3(c *C) {
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
tk.MustExec("use test")
|
||||
tk.MustExec("drop table if exists t")
|
||||
tk.MustExec("create table t(a int primary key, b int, index idx_b(b))")
|
||||
tk.MustExec("insert into t values(1,1),(2,2),(3,3)")
|
||||
tk.MustExec("set @@session.tidb_analyze_version = 3")
|
||||
tk.MustExec("analyze table t")
|
||||
is := tk.Se.GetInfoSchema().(infoschema.InfoSchema)
|
||||
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
|
||||
c.Assert(err, IsNil)
|
||||
tblID := tbl.Meta().ID
|
||||
rows := tk.MustQuery(fmt.Sprintf("select distinct_count from mysql.stats_histograms where table_id = %d and is_index = 1", tblID)).Rows()
|
||||
c.Assert(len(rows), Equals, 1)
|
||||
c.Assert(rows[0][0], Equals, "3")
|
||||
tk.MustExec("insert into t values(4,4),(5,5),(6,6)")
|
||||
tk.MustExec("analyze incremental table t index idx_b")
|
||||
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings(), HasLen, 2)
|
||||
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings()[0].Err.Error(), Equals, "The version 3 would collect all statistics not only the selected indexes")
|
||||
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings()[1].Err.Error(), Equals, "The version 3 stats would ignore the INCREMENTAL keyword and do full sampling")
|
||||
rows = tk.MustQuery(fmt.Sprintf("select distinct_count from mysql.stats_histograms where table_id = %d and is_index = 1", tblID)).Rows()
|
||||
c.Assert(len(rows), Equals, 1)
|
||||
c.Assert(rows[0][0], Equals, "6")
|
||||
}
|
||||
|
||||
func (s *testIntegrationSuite) TestConflictReadFromStorage(c *C) {
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
tk.MustExec("use test")
|
||||
|
||||
@ -1683,6 +1683,9 @@ func (b *PlanBuilder) buildAnalyzeFullSamplingTask(
|
||||
}
|
||||
idxInfos = append(idxInfos, idx)
|
||||
}
|
||||
if as.Incremental {
|
||||
b.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("The version 3 stats would ignore the INCREMENTAL keyword and do full sampling"))
|
||||
}
|
||||
for i, id := range physicalIDs {
|
||||
if id == tbl.TableInfo.ID {
|
||||
id = -1
|
||||
@ -1692,7 +1695,7 @@ func (b *PlanBuilder) buildAnalyzeFullSamplingTask(
|
||||
TableName: tbl.Name.O,
|
||||
PartitionName: names[i],
|
||||
TableID: AnalyzeTableID{TableID: tbl.TableInfo.ID, PartitionID: id},
|
||||
Incremental: as.Incremental,
|
||||
Incremental: false,
|
||||
StatsVersion: version,
|
||||
}
|
||||
newTask := AnalyzeColumnsTask{
|
||||
|
||||
Reference in New Issue
Block a user