Skip to content

Conversation

reafans
Copy link
Contributor

@reafans reafans commented Feb 18, 2020

What problem does this PR solve?

Currently, we can view the history of DDL jobs and DDL jobs by 'admin show DDL jobs', but it is not convenient to use queries such as group by, so we need to add a system table of DDL_JOBS.

What is changed and how it works?

mysql> select * from information_schema.DDL_JOBS limit 10;
+--------+---------------+------------+---------------+--------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| JOB_ID | DB_NAME       | TABLE_NAME | JOB_TYPE      | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME                        | END_TIME                          | STATE  | QUERY                                                                                                                                                  |
+--------+---------------+------------+---------------+--------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|   1718 | test_ddl_jobs |            | create schema | public       |      1717 |        0 |         0 | 2020-02-18 20:35:40.43 +0800 CST  | 2020-02-18 20:35:40.434 +0800 CST | synced | create database if not exists test_ddl_jobs                                                                                                            |
|   1716 | test_ddl_jobs |            | drop schema   | none         |      1714 |        0 |         0 | 2020-02-18 19:50:29.07 +0800 CST  | 2020-02-18 19:50:29.084 +0800 CST | synced | drop database test_ddl_jobs                                                                                                                            |
|   1715 | test_ddl_jobs |            | create schema | public       |      1714 |        0 |         0 | 2020-02-18 19:45:54.182 +0800 CST | 2020-02-18 19:45:54.185 +0800 CST | synced | create database if not exists test_ddl_jobs                                                                                                            |
|   1713 | test          | level0     | create table  | public       |         1 |     1712 |         0 | 2020-02-06 20:32:49.557 +0800 CST | 2020-02-06 20:32:49.563 +0800 CST | synced | CREATE TABLE `level0` (`id` int unsigned AUTO_INCREMENT,`value` varchar(255),`level1_id` int unsigned , PRIMARY KEY (`id`))                            |
|   1711 | test          | level2_1   | create table  | public       |         1 |     1710 |         0 | 2020-02-06 20:32:49.546 +0800 CST | 2020-02-06 20:32:49.552 +0800 CST | synced | CREATE TABLE `level2_1` (`id` int unsigned AUTO_INCREMENT,`level3_id` int unsigned , PRIMARY KEY (`id`))                                               |
|   1709 | test          | level1     | create table  | public       |         1 |     1708 |         0 | 2020-02-06 20:32:49.536 +0800 CST | 2020-02-06 20:32:49.541 +0800 CST | synced | CREATE TABLE `level1` (`id` int unsigned AUTO_INCREMENT,`value` varchar(255),`level2_id` int unsigned,`level2_1_id` int unsigned , PRIMARY KEY (`id`)) |
|   1707 | test          | level2     | create table  | public       |         1 |     1706 |         0 | 2020-02-06 20:32:49.527 +0800 CST | 2020-02-06 20:32:49.532 +0800 CST | synced | CREATE TABLE `level2` (`id` int unsigned AUTO_INCREMENT,`level3_id` int unsigned , PRIMARY KEY (`id`))                                                 |
|   1705 | test          | level3     | create table  | public       |         1 |     1704 |         0 | 2020-02-06 20:32:49.518 +0800 CST | 2020-02-06 20:32:49.523 +0800 CST | synced | CREATE TABLE `level3` (`id` int unsigned AUTO_INCREMENT,`name` varchar(255) , PRIMARY KEY (`id`))                                                      |
|   1703 | test          | level0     | drop table    | none         |         1 |     1554 |         0 | 2020-02-06 20:32:49.5 +0800 CST   | 2020-02-06 20:32:49.513 +0800 CST | synced | DROP TABLE `level0`                                                                                                                                    |
|   1702 | test          | level1     | drop table    | none         |         1 |     1697 |         0 | 2020-02-06 20:32:49.479 +0800 CST | 2020-02-06 20:32:49.493 +0800 CST | synced | DROP TABLE `level1`                                                                                                                                    |
+--------+---------------+------------+---------------+--------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.00 sec)

Group by:

mysql> select db_name,count(*) from DDL_JOBS group by db_name;
+---------------+----------+
| db_name       | count(*) |
+---------------+----------+
| test_ddl_jobs |        3 |
| test          |     1119 |
| mysql         |       23 |
+---------------+----------+
3 rows in set (0.07 sec)

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported variable/fields change

@reafans reafans changed the title infoschema/executor : Add DDLJobs sys table infoschema/executor : add DDLJobs sys table Feb 18, 2020
@reafans
Copy link
Contributor Author

reafans commented Feb 18, 2020

/run-build

@reafans
Copy link
Contributor Author

reafans commented Feb 19, 2020

/rebuild

tk.MustExec("GRANT ALL PRIVILEGES ON mysql.* TO mysql_priv;")
tk.MustExec("GRANT mysql_priv TO DDL_JOBS_tester;")
DDLJobsTester.MustExec("set role mysql_priv")
DDLJobsTester.MustQuery("select DISTINCT DB_NAME from information_schema.DDL_JOBS where DB_NAME = 'mysql';").Check(testkit.Rows("mysql"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should test the table that the user doesn't have the privilege to see it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@wshwsh12 wshwsh12 removed their request for review March 15, 2020 07:40
@@ -16,6 +16,7 @@ package executor_test
import (
"crypto/tls"
"fmt"
"google.golang.org/grpc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format code

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST LGTM

@reafans
Copy link
Contributor Author

reafans commented Mar 19, 2020

/run-unit-test

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added the status/can-merge Indicates a PR has been approved by a committer. label Mar 19, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 19, 2020

/run-all-tests

@sre-bot sre-bot merged commit 86d8e16 into pingcap:master Mar 19, 2020
@reafans reafans deleted the add_ddljobs_sys_table branch March 19, 2020 03:55
@you06 you06 added this to the v4.0.0-rc milestone Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/infoschema sig/execution SIG execution sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants