Skip to content

Commit

Permalink
cherry pick #19702 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
Lingyu Song committed Sep 7, 2020
1 parent 08323ec commit dec5b93
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,30 @@ func (s *testSuite5) TestShowGrantsPrivilege(c *C) {
tk2.MustQuery("show grants")
}

func (s *testSuite5) TestShowStatsPrivilege(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create user show_stats")
tk1 := testkit.NewTestKit(c, s.store)
se, err := session.CreateSession4Test(s.store)
c.Assert(err, IsNil)
c.Assert(se.Auth(&auth.UserIdentity{Username: "show_stats", Hostname: "%"}, nil, nil), IsTrue)
tk1.Se = se
eqErr := plannercore.ErrDBaccessDenied.GenWithStackByArgs("show_stats", "%", mysql.SystemDB)
_, err = tk1.Exec("show stats_meta")
c.Assert(err.Error(), Equals, eqErr.Error())
_, err = tk1.Exec("SHOW STATS_BUCKETS")
c.Assert(err.Error(), Equals, eqErr.Error())
_, err = tk1.Exec("SHOW STATS_HEALTHY")
c.Assert(err.Error(), Equals, eqErr.Error())
_, err = tk1.Exec("SHOW STATS_HISTOGRAMS")
c.Assert(err.Error(), Equals, eqErr.Error())
tk.MustExec("grant select on mysql.* to show_stats")
tk1.MustExec("show stats_meta")
tk1.MustExec("SHOW STATS_BUCKETS")
tk1.MustExec("SHOW STATS_HEALTHY")
tk1.MustExec("SHOW STATS_HISTOGRAMS")
}

func (s *testSuite5) TestIssue18878(c *C) {
tk := testkit.NewTestKit(c, s.store)
se, err := session.CreateSession4Test(s.store)
Expand Down
7 changes: 7 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,13 @@ func (b *PlanBuilder) buildShow(ctx context.Context, show *ast.ShowStmt) (Plan,
p.setSchemaAndNames(buildShowNextRowID())
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SelectPriv, show.Table.Schema.L, show.Table.Name.L, "", ErrPrivilegeCheckFail)
return p, nil
case ast.ShowStatsBuckets, ast.ShowStatsHistograms, ast.ShowStatsMeta, ast.ShowStatsHealthy:
user := b.ctx.GetSessionVars().User
var err error
if user != nil {
err = ErrDBaccessDenied.GenWithStackByArgs(user.AuthUsername, user.AuthHostname, mysql.SystemDB)
}
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SelectPriv, mysql.SystemDB, "", "", err)
}
schema, names := buildShowSchema(show, isView, isSequence)
p.SetSchema(schema)
Expand Down

0 comments on commit dec5b93

Please sign in to comment.