-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
docs/design: add proposal for invisible index #15338
Conversation
Codecov Report
@@ Coverage Diff @@
## master #15338 +/- ##
================================================
- Coverage 80.6674% 80.3857% -0.2817%
================================================
Files 502 502
Lines 135212 133831 -1381
================================================
- Hits 109072 107581 -1491
- Misses 17723 17808 +85
- Partials 8417 8442 +25 |
|
||
MySQL supports [Invisible indexes](https://dev.mysql.com/doc/refman/8.0/en/invisible-indexes.html); that is, indexes that are not used by the optimizer. | ||
|
||
This is a useful feature when you want to drop an index in a safe way. Invisible indexes make it possible to test the effect of removing an index on query performance, without making a destructive change that must be undone should the index turn out to be required. Dropping and re-adding an index can be expensive for a large table, whereas making it invisible and visible are fast, in-place operations. |
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.
should the index turn out to be required
?
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 statement is copied from mysql docs, translating into Chinese:
不可见的索引可以测试移除索引对查询性能的影响,而不会做出破坏性的更改,如果(移除后)发现索引是必需的,则必须撤销这些更改。
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.
LGTM
@wjhuang2016, PTAL. |
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.
LGTM
@wjhuang2016, @AilinKid, PTAL. |
@bb7133 This PR is ready for merge, PTAL |
/run-all-tests |
|
||
## Abstract | ||
|
||
MySQL supports [Invisible indexes](https://dev.mysql.com/doc/refman/8.0/en/invisible-indexes.html); that is, indexes that are not used by the optimizer. |
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.
MySQL supports [Invisible indexes](https://dev.mysql.com/doc/refman/8.0/en/invisible-indexes.html); that is, indexes that are not used by the optimizer. | |
MySQL supports [invisible indexes](https://dev.mysql.com/doc/refman/8.0/en/invisible-indexes.html); that is, indexes that are not used by the optimizer. |
{VISIBLE | INVISIBLE} | ||
``` | ||
|
||
Also, consider the following: |
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.
Also, consider the following: | |
Also, the following behaviors need to be supported as well: |
|
||
## Proposal | ||
|
||
Adding an option (visible or not) to the index. If it is not visible, it's called **Invisible Index**. Invisible Index cannot be used by the optimizer (with the `use_invisible_indexes` switch on), but the index is maintained during DML operations. For a query statement, invisible index has the same effect as ignoring the index through Index Hint. |
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.
Adding an option (visible or not) to the index. If it is not visible, it's called **Invisible Index**. Invisible Index cannot be used by the optimizer (with the `use_invisible_indexes` switch on), but the index is maintained during DML operations. For a query statement, invisible index has the same effect as ignoring the index through Index Hint. | |
Adding an option (visible or not) to the index. If it is not visible, it's called **Invisible Index**. Invisible indexes cannot be used by the optimizer (with the `use_invisible_indexes` switch on), but the index is maintained during DML operations. For a query statement, invisible indexes have the same effect as ignoring the index through Index Hint. |
ALTER TABLE table_name ALTER INDEX index_name { INVISIBLE | VISIBLE }; | ||
``` | ||
|
||
Or set option `INVISIBLE` when creating an index: |
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.
Or set option `INVISIBLE` when creating an index: | |
Or by setting option `INVISIBLE` when creating an index: |
## Compatibility and Migration Plan | ||
|
||
This the a new feature and it's absolutly compatible with old TiDB versions, also, it's not impact any data migration. | ||
The syntax and functions are basically compatible with MySQL. Expect one: |
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.
The syntax and functions are basically compatible with MySQL. Expect one: | |
The syntax and functions are basically compatible with MySQL expect: |
|
||
## Compatibility and Migration Plan | ||
|
||
This the a new feature and it's absolutly compatible with old TiDB versions, also, it's not impact any data migration. |
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 the a new feature and it's absolutly compatible with old TiDB versions, also, it's not impact any data migration. | |
This the a new feature and it's absolutly compatible with old TiDB versions, also, it does not impact any data migration. |
The syntax and functions are basically compatible with MySQL. Expect one: | ||
|
||
When use invisible index in `SQL Hint`, and set `use_invisible_indexes = false`, MySQL allow use the invisible index. | ||
But in TiDB, It's **not allowed**, and will throw a `Unresolved name` error, Because the behavior is more reasonable. |
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.
But in TiDB, It's **not allowed**, and will throw a `Unresolved name` error, Because the behavior is more reasonable. | |
But in TiDB, It's **not allowed** and an `Unresolved name` error will be thrown. |
## Testing Plan | ||
|
||
- Unit test | ||
- Port All mysql test related to invisible index |
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.
- Port All mysql test related to invisible index | |
- Learn from MySQL test cases related to invisible indexes |
What problem does this PR solve?
This PR adds a proposal for full invisible index support in TiDB.
An issue has been created for the discussions on this proposal:
#9246