diff --git a/executor/simple.go b/executor/simple.go index efdb3a7912061..48f4b5264c79d 100644 --- a/executor/simple.go +++ b/executor/simple.go @@ -1324,7 +1324,7 @@ func asyncDelayShutdown(p *os.Process, delay time.Duration) { func (e *SimpleExec) executeAdminReloadStatistics(s *ast.AdminStmt) error { if s.Tp != ast.AdminReloadStatistics { - return errors.New("This AdminStmt is not ADMIN RELOAD TIDB_STATS") + return errors.New("This AdminStmt is not ADMIN RELOAD STATS_EXTENDED") } if !e.ctx.GetSessionVars().EnableExtendedStats { return errors.New("Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") diff --git a/executor/simple_test.go b/executor/simple_test.go index bc35d3432bce3..7c141e45d159c 100644 --- a/executor/simple_test.go +++ b/executor/simple_test.go @@ -774,28 +774,28 @@ func (s *testSuite3) TestExtendedStatsPrivileges(c *C) { ctx := context.Background() _, err = se.Execute(ctx, "set session tidb_enable_extended_stats = on") c.Assert(err, IsNil) - _, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)") + _, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)") c.Assert(err, NotNil) c.Assert(err.Error(), Equals, "[planner:1142]ALTER command denied to user 'u1'@'%' for table 't'") tk.MustExec("grant alter on test.* to 'u1'@'%'") - _, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)") + _, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)") c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, "[planner:1142]ADD TIDB_STATS command denied to user 'u1'@'%' for table 't'") + c.Assert(err.Error(), Equals, "[planner:1142]ADD STATS_EXTENDED command denied to user 'u1'@'%' for table 't'") tk.MustExec("grant select on test.* to 'u1'@'%'") - _, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)") + _, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)") c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, "[planner:1142]ADD TIDB_STATS command denied to user 'u1'@'%' for table 'stats_extended'") + c.Assert(err.Error(), Equals, "[planner:1142]ADD STATS_EXTENDED command denied to user 'u1'@'%' for table 'stats_extended'") tk.MustExec("grant insert on mysql.stats_extended to 'u1'@'%'") - _, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)") + _, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)") c.Assert(err, IsNil) _, err = se.Execute(ctx, "use test") c.Assert(err, IsNil) - _, err = se.Execute(ctx, "alter table t drop tidb_stats s1") + _, err = se.Execute(ctx, "alter table t drop stats_extended s1") c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, "[planner:1142]DROP TIDB_STATS command denied to user 'u1'@'%' for table 'stats_extended'") + c.Assert(err.Error(), Equals, "[planner:1142]DROP STATS_EXTENDED command denied to user 'u1'@'%' for table 'stats_extended'") tk.MustExec("grant update on mysql.stats_extended to 'u1'@'%'") - _, err = se.Execute(ctx, "alter table t drop tidb_stats s1") + _, err = se.Execute(ctx, "alter table t drop stats_extended s1") c.Assert(err, IsNil) tk.MustExec("drop user 'u1'@'%'") } diff --git a/go.mod b/go.mod index 63a7da37d93ff..49db0b780b613 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 github.com/pingcap/kvproto v0.0.0-20201215060142-f3dafca4c7fd github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 - github.com/pingcap/parser v0.0.0-20210108074737-814a888e05e2 + github.com/pingcap/parser v0.0.0-20210125075924-ffe0fda947cb github.com/pingcap/sysutil v0.0.0-20201130064824-f0c8aa6a6966 github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible github.com/pingcap/tipb v0.0.0-20201229060814-148bc717ce4c diff --git a/go.sum b/go.sum index 533849047442b..58f7ce09913a9 100644 --- a/go.sum +++ b/go.sum @@ -653,8 +653,8 @@ github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 h1:M+DNpOu/I3uDmwee6vc github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/parser v0.0.0-20200422082501-7329d80eaf2c/go.mod h1:9v0Edh8IbgjGYW2ArJr19E+bvL8zKahsFp+ixWeId+4= -github.com/pingcap/parser v0.0.0-20210108074737-814a888e05e2 h1:8ESOr7xSfwM3jdWlklug0Mz8tjpb/KzDh+YSJx2SI8w= -github.com/pingcap/parser v0.0.0-20210108074737-814a888e05e2/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE= +github.com/pingcap/parser v0.0.0-20210125075924-ffe0fda947cb h1:16lZkJzsAOIY781DmUgSU0El+GpV8fl3BohzVmHO1rE= +github.com/pingcap/parser v0.0.0-20210125075924-ffe0fda947cb/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE= github.com/pingcap/pd v2.1.5+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E= github.com/pingcap/pd/v4 v4.0.0-rc.1.0.20200422143320-428acd53eba2/go.mod h1:s+utZtXDznOiL24VK0qGmtoHjjXNsscJx3m1n8cC56s= github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI= diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 90d5b9e822c24..70c0b792e25f3 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -3213,9 +3213,9 @@ func (b *PlanBuilder) buildDDL(ctx context.Context, node ast.DDLNode) (Plan, err var selectErr, insertErr error user := b.ctx.GetSessionVars().User if user != nil { - selectErr = ErrTableaccessDenied.GenWithStackByArgs("ADD TIDB_STATS", user.AuthUsername, + selectErr = ErrTableaccessDenied.GenWithStackByArgs("ADD STATS_EXTENDED", user.AuthUsername, user.AuthHostname, v.Table.Name.L) - insertErr = ErrTableaccessDenied.GenWithStackByArgs("ADD TIDB_STATS", user.AuthUsername, + insertErr = ErrTableaccessDenied.GenWithStackByArgs("ADD STATS_EXTENDED", user.AuthUsername, user.AuthHostname, "stats_extended") } b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SelectPriv, v.Table.Schema.L, @@ -3225,7 +3225,7 @@ func (b *PlanBuilder) buildDDL(ctx context.Context, node ast.DDLNode) (Plan, err } else if spec.Tp == ast.AlterTableDropStatistics { user := b.ctx.GetSessionVars().User if user != nil { - authErr = ErrTableaccessDenied.GenWithStackByArgs("DROP TIDB_STATS", user.AuthUsername, + authErr = ErrTableaccessDenied.GenWithStackByArgs("DROP STATS_EXTENDED", user.AuthUsername, user.AuthHostname, "stats_extended") } b.visitInfo = appendVisitInfo(b.visitInfo, mysql.UpdatePriv, mysql.SystemDB, diff --git a/statistics/handle/dump_test.go b/statistics/handle/dump_test.go index 30d5ab8c16f9a..f718c85e91447 100644 --- a/statistics/handle/dump_test.go +++ b/statistics/handle/dump_test.go @@ -195,7 +195,7 @@ func (s *testStatsSuite) TestDumpExtendedStats(c *C) { tk.MustExec("insert into t values(1,5),(2,4),(3,3),(4,2),(5,1)") h := s.do.StatsHandle() c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) - tk.MustExec("alter table t add tidb_stats s1 correlation(a,b)") + tk.MustExec("alter table t add stats_extended s1 correlation(a,b)") tk.MustExec("analyze table t") is := s.do.InfoSchema() diff --git a/statistics/handle/gc_test.go b/statistics/handle/gc_test.go index f754804d6e6fb..ffbeb71003059 100644 --- a/statistics/handle/gc_test.go +++ b/statistics/handle/gc_test.go @@ -100,8 +100,8 @@ func (s *testStatsSuite) TestGCExtendedStats(c *C) { testKit.MustExec("use test") testKit.MustExec("create table t(a int, b int, c int)") testKit.MustExec("insert into t values (1,1,1),(2,2,2),(3,3,3)") - testKit.MustExec("alter table t add tidb_stats s1 correlation(a,b)") - testKit.MustExec("alter table t add tidb_stats s2 correlation(b,c)") + testKit.MustExec("alter table t add stats_extended s1 correlation(a,b)") + testKit.MustExec("alter table t add stats_extended s2 correlation(b,c)") testKit.MustExec("analyze table t") testKit.MustQuery("select name, type, column_ids, stats, status from mysql.stats_extended").Sort().Check(testkit.Rows( diff --git a/statistics/handle/handle_test.go b/statistics/handle/handle_test.go index 97e1bbbf26d2f..c72d0a84e2ae8 100644 --- a/statistics/handle/handle_test.go +++ b/statistics/handle/handle_test.go @@ -648,11 +648,11 @@ func (s *testStatsSuite) TestExtendedStatsDefaultSwitch(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table t(a int primary key, b int, c int, d int)") - err := tk.ExecToErr("alter table t add tidb_stats s1 correlation(b,c)") + err := tk.ExecToErr("alter table t add stats_extended s1 correlation(b,c)") c.Assert(err.Error(), Equals, "Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") - err = tk.ExecToErr("alter table t drop tidb_stats s1") + err = tk.ExecToErr("alter table t drop stats_extended s1") c.Assert(err.Error(), Equals, "Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") - err = tk.ExecToErr("admin reload tidb_stats") + err = tk.ExecToErr("admin reload stats_extended") c.Assert(err.Error(), Equals, "Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") } @@ -664,22 +664,22 @@ func (s *testStatsSuite) TestExtendedStatsOps(c *C) { tk.MustExec("create table t(a int primary key, b int, c int, d int)") tk.MustExec("insert into t values(1,1,5,1),(2,2,4,2),(3,3,3,3),(4,4,2,4),(5,5,1,5)") tk.MustExec("analyze table t") - err := tk.ExecToErr("alter table not_exist_db.t add tidb_stats s1 correlation(b,c)") + err := tk.ExecToErr("alter table not_exist_db.t add stats_extended s1 correlation(b,c)") c.Assert(err.Error(), Equals, "[schema:1146]Table 'not_exist_db.t' doesn't exist") - err = tk.ExecToErr("alter table not_exist_tbl add tidb_stats s1 correlation(b,c)") + err = tk.ExecToErr("alter table not_exist_tbl add stats_extended s1 correlation(b,c)") c.Assert(err.Error(), Equals, "[schema:1146]Table 'test.not_exist_tbl' doesn't exist") - err = tk.ExecToErr("alter table t add tidb_stats s1 correlation(b,e)") + err = tk.ExecToErr("alter table t add stats_extended s1 correlation(b,e)") c.Assert(err.Error(), Equals, "[schema:1054]Unknown column 'e' in 't'") - tk.MustExec("alter table t add tidb_stats s1 correlation(a,b)") + tk.MustExec("alter table t add stats_extended s1 correlation(a,b)") tk.MustQuery("show warnings").Check(testkit.Rows( "Warning 1105 No need to create correlation statistics on the integer primary key column", )) tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows()) - err = tk.ExecToErr("alter table t add tidb_stats s1 correlation(b,c,d)") + err = tk.ExecToErr("alter table t add stats_extended s1 correlation(b,c,d)") c.Assert(err.Error(), Equals, "Only support Correlation and Dependency statistics types on 2 columns") tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows()) - tk.MustExec("alter table t add tidb_stats s1 correlation(b,c)") + tk.MustExec("alter table t add stats_extended s1 correlation(b,c)") tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows( "2 [2,3] 0", )) @@ -702,7 +702,7 @@ func (s *testStatsSuite) TestExtendedStatsOps(c *C) { c.Assert(statsTbl.ExtendedStats, NotNil) c.Assert(len(statsTbl.ExtendedStats.Stats), Equals, 1) - tk.MustExec("alter table t drop tidb_stats s1") + tk.MustExec("alter table t drop stats_extended s1") tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows( "2 [2,3] 2", )) @@ -720,7 +720,7 @@ func (s *testStatsSuite) TestAdminReloadStatistics(c *C) { tk.MustExec("create table t(a int primary key, b int, c int, d int)") tk.MustExec("insert into t values(1,1,5,1),(2,2,4,2),(3,3,3,3),(4,4,2,4),(5,5,1,5)") tk.MustExec("analyze table t") - tk.MustExec("alter table t add tidb_stats s1 correlation(b,c)") + tk.MustExec("alter table t add stats_extended s1 correlation(b,c)") tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows( "2 [2,3] 0", )) @@ -749,7 +749,7 @@ func (s *testStatsSuite) TestAdminReloadStatistics(c *C) { c.Assert(statsTbl.ExtendedStats, NotNil) c.Assert(len(statsTbl.ExtendedStats.Stats), Equals, 1) - tk.MustExec("admin reload tidb_stats") + tk.MustExec("admin reload stats_extended") statsTbl = do.StatsHandle().GetTableStats(tableInfo) c.Assert(statsTbl.ExtendedStats, NotNil) c.Assert(len(statsTbl.ExtendedStats.Stats), Equals, 0) @@ -764,8 +764,8 @@ func (s *testStatsSuite) TestCorrelationStatsCompute(c *C) { tk.MustExec("insert into t values(1,1,5),(2,2,4),(3,3,3),(4,4,2),(5,5,1)") tk.MustExec("analyze table t") tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended").Check(testkit.Rows()) - tk.MustExec("alter table t add tidb_stats s1 correlation(a,b)") - tk.MustExec("alter table t add tidb_stats s2 correlation(a,c)") + tk.MustExec("alter table t add stats_extended s1 correlation(a,b)") + tk.MustExec("alter table t add stats_extended s2 correlation(a,c)") tk.MustQuery("select type, column_ids, stats, status from mysql.stats_extended").Sort().Check(testkit.Rows( "2 [1,2] 0", "2 [1,3] 0", @@ -821,7 +821,7 @@ func (s *statsSerialSuite) TestIndexUsageInformation(c *C) { tk.MustExec("create unique index idx_a on t_idx(a)") tk.MustExec("create unique index idx_b on t_idx(b)") tk.MustQuery("select a from t_idx where a=1") - querySQL := `select idx.table_schema, idx.table_name, idx.key_name, stats.query_count, stats.rows_selected + querySQL := `select idx.table_schema, idx.table_name, idx.key_name, stats.query_count, stats.rows_selected from mysql.schema_index_usage as stats, information_schema.tidb_indexes as idx, information_schema.tables as tables where tables.table_schema = idx.table_schema AND tables.table_name = idx.table_name @@ -862,7 +862,7 @@ func (s *statsSerialSuite) TestGCIndexUsageInformation(c *C) { do := s.do err := do.StatsHandle().DumpIndexUsageToKV() c.Assert(err, IsNil) - querySQL := `select count(distinct idx.table_schema, idx.table_name, idx.key_name, stats.query_count, stats.rows_selected) + querySQL := `select count(distinct idx.table_schema, idx.table_name, idx.key_name, stats.query_count, stats.rows_selected) from mysql.schema_index_usage as stats, information_schema.tidb_indexes as idx, information_schema.tables as tables where tables.table_schema = idx.table_schema AND tables.table_name = idx.table_name