-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner: add privilege check for lock/unlock stats #46742
planner: add privilege check for lock/unlock stats #46742
Conversation
create table t(a int, b int);
insert into t values (1,2), (3,4), (5,6), (7,8);
analyze table t;
show warnings;
mysql> lock stats t;
ERROR 1142 (42000): INSERT command denied to user 'dd'@'localhost' for table 't'
mysql> unlock stats t;
ERROR 1142 (42000): INSERT command denied to user 'dd'@'localhost' for table 't'
mysql> lock stats t;
ERROR 1142 (42000): SELECT command denied to user 'dd'@'localhost' for table 't'
mysql> unlock stats t;
ERROR 1142 (42000): SELECT command denied to user 'dd'@'localhost' for table 't'
mysql> show warnings;
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Note | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "use min(1, 110000/4) as the sample-rate=1" |
| Warning | 1105 | skip analyze locked table: t |
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> lock stats t;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show warnings;
+---------+------+-----------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------+
| Warning | 1105 | skip locking locked table: test.t |
+---------+------+-----------------------------------+
1 row in set (0.00 sec)
mysql> show stats_locked;
ERROR 1142 (42000): SHOW command denied to user 'dd'@'localhost' for table 'stats_table_locked'
mysql> show stats_locked;
+---------+------------+----------------+--------+
| Db_name | Table_name | Partition_name | Status |
+---------+------------+----------------+--------+
| test | t | | locked |
+---------+------------+----------------+--------+
1 row in set (0.00 sec)
mysql> select * from mysql.stats_table_locked;
Empty set (0.00 sec)
mysql> show stats_locked;
Empty set (0.00 sec)
mysql> unlock stats t;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+---------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------+
| Warning | 1105 | skip unlocking unlocked table: test.t |
+---------+------+---------------------------------------+
1 row in set (0.00 sec) |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #46742 +/- ##
================================================
- Coverage 73.2873% 72.6758% -0.6115%
================================================
Files 1319 1342 +23
Lines 395898 402476 +6578
================================================
+ Hits 290143 292503 +2360
- Misses 87268 91409 +4141
- Partials 18487 18564 +77
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔢 self-check
/retest |
LGTM, but could you transform this to a unit test like |
Good point. I will add it. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hawkingrei, qw4990 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
What problem does this PR solve?
Issue Number: ref #46351
Problem Summary:
What is changed and how it works?
Added privilege check for lock/unlock stats. They require the
SELECT
andINSERT
privileges.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.