-
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
*: add sys
schema, sys.SCHEMA_UNUSED_INDEXES
view and sys.SCHEMA_INDEX_USAGE
view
#22126
base: master
Are you sure you want to change the base?
Conversation
/label status/WIP |
I'll add tests for this PR later. |
/label sig/planner |
/label component/statisitic |
These labels are not found |
/label component/statistic |
These labels are not found |
/label component/statistics |
sys
schema and sys.SCHEMA_UNUSED_INDEXES
viewsys
schema and sys.SCHEMA_UNUSED_INDEXES
view, sys.SCHEMA_INDEX_USAGE
view
sys
schema and sys.SCHEMA_UNUSED_INDEXES
view, sys.SCHEMA_INDEX_USAGE
viewsys
schema, sys.SCHEMA_UNUSED_INDEXES
view and sys.SCHEMA_INDEX_USAGE
view
/unlabel status/WIP |
/cc @qw4990 |
infoschema/sysschema/tables.go
Outdated
var pluginTable = make(map[string]func(autoid.Allocators, *model.TableInfo) (table.Table, error)) | ||
|
||
// RegisterTable registers a new table into TiDB. | ||
func RegisterTable(tableName, sql string, |
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.
This function is not used.
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.
updated.
} | ||
|
||
const viewUnusedIndexes = "CREATE VIEW sys." + viewNameUnusedIndexes + | ||
` AS SELECT DISTINCT i.table_schema AS table_schema, i.table_name AS table_name, i.key_name AS index_name |
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.
Why use DISTINCT
in these two SQLs?
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.
Consider a situation, table t
has an index idx_ab(a, b). There will be two rows of data in the table information_schema.tidb_indexes
because this index covers two columns. So there will be two lines of the same (table_schema, t, idx_ab). DISTINCT
is to deal with this situation.
@@ -1923,6 +1923,52 @@ func (d *ddl) RecoverTable(ctx sessionctx.Context, recoverInfo *RecoverInfo) (er | |||
return errors.Trace(err) | |||
} | |||
|
|||
// BuildTableInfoFromCreateViewAST builds model.TableInfo from a CreateViewStmt statement. | |||
func BuildTableInfoFromCreateViewAST(s *ast.CreateViewStmt) (*model.TableInfo, error) { |
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.
How about renaming it to BuildViewInfoFromAST
to correspond to BuildTableInfoFromAST
?
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.
I don’t think this is a good name, because this function does not build ViewInfo
, but TableInfo
.
infoschema/sysschema/const.go
Outdated
@@ -0,0 +1,49 @@ | |||
// Copyright 2016 PingCAP, Inc. |
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.
Please change 2016 to 2021.
infoschema/sysschema/init.go
Outdated
@@ -0,0 +1,76 @@ | |||
// Copyright 2016 PingCAP, Inc. |
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.
ditto
infoschema/sysschema/tables.go
Outdated
@@ -0,0 +1,101 @@ | |||
// Copyright 2017 PingCAP, Inc. |
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.
ditto
infoschema/sysschema/tables_test.go
Outdated
@@ -0,0 +1,63 @@ | |||
// Copyright 2016 PingCAP, Inc. |
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.
ditto
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.
Updated all.
meta/autoid/autoid.go
Outdated
@@ -46,6 +46,7 @@ const ( | |||
PerformanceSchemaDBID int64 = SystemSchemaIDFlag | 10000 | |||
// MetricSchemaDBID is the metrics_schema schema id, it's exported for test. | |||
MetricSchemaDBID int64 = SystemSchemaIDFlag | 20000 | |||
SysSchemaDBID int64 = SystemSchemaIDFlag | 40000 |
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.
Please add some comments. Does the number 40000
is a magic number, just need to be different from others?
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.
OK.
Does the number 40000 is a magic number, just need to be different from others?
Yes.
@@ -193,6 +193,8 @@ var ( | |||
PerformanceSchemaName = model.NewCIStr("PERFORMANCE_SCHEMA") | |||
// MetricSchemaName is the `METRICS_SCHEMA` database name. | |||
MetricSchemaName = model.NewCIStr("METRICS_SCHEMA") | |||
// SysSchemaName is the `sys` database name. | |||
SysSchemaName = model.NewCIStr("sys") |
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.
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.
Good question, I didn’t think about it before. I want to know how the information_schema or MySQL 8.0 was introduced at that time. Do you have any advice? @qw4990
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.
IsMemDB also needs to modify.
@rebelice: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #22126 +/- ##
================================================
- Coverage 77.0764% 77.0736% -0.0029%
================================================
Files 573 575 +2
Lines 145715 145793 +78
================================================
+ Hits 112312 112368 +56
- Misses 23286 23305 +19
- Partials 10117 10120 +3 |
@rebelice: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: #19209
What is changed and how it works?
This is one step of #19209.
Add
sys
schema,sys.SCHEMA_UNUSED_INDEXES
view andsys.SCHEMA_INDEX_USAGE
view.The
sys
schema is referencesys
schema in MySQL.And
sys.SCHEMA_UNUSED_INDEXES
view is also referencesys.SCHEMA_UNUSED_INDEXES
in MySQLThe difference between
sys.SCHEMA_INDEX_USAGE
andmysql.SCHEMA_INDEX_USAGE
is that access tosys.SCHEMA_INDEX_USAGE
does not need to modify any permissions, and the content ofsys.SCHEMA_INDEX_USAGE
has been managed with permissions, only the index information of the table with theSELECT
permission can be obtained. This is the same forsys.SCHEMA_UNUSED_INDEXES
.Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Side effects
Release note
sys
schema,sys.SCHEMA_UNUSED_INDEXES
view andsys.SCHEMA_INDEX_USAGE
view