Skip to content
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

Merged
merged 6 commits into from
Mar 18, 2020

Conversation

Deardrops
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Mar 12, 2020

Codecov Report

Merging #15338 into master will decrease coverage by 0.2816%.
The diff coverage is n/a.

@@               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.
Copy link
Member

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 ?

Copy link
Contributor Author

@Deardrops Deardrops Mar 13, 2020

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:

不可见的索引可以测试移除索引对查询性能的影响,而不会做出破坏性的更改,如果(移除后)发现索引是必需的,则必须撤销这些更改。

docs/design/2020-03-12-invisible-index.md Outdated Show resolved Hide resolved
docs/design/2020-03-12-invisible-index.md Outdated Show resolved Hide resolved
Copy link
Member

@wjhuang2016 wjhuang2016 left a comment

Choose a reason for hiding this comment

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

LGTM

@sre-bot
Copy link
Contributor

sre-bot commented Mar 15, 2020

@wjhuang2016, PTAL.

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@sre-bot
Copy link
Contributor

sre-bot commented Mar 18, 2020

@wjhuang2016, @AilinKid, PTAL.

@Deardrops Deardrops added status/LGT2 Indicates that a PR has LGTM 2. and removed status/PTAL labels Mar 18, 2020
@Deardrops
Copy link
Contributor Author

@bb7133 This PR is ready for merge, PTAL

@Deardrops Deardrops requested a review from bb7133 March 18, 2020 06:36
@wjhuang2016 wjhuang2016 added status/can-merge Indicates a PR has been approved by a committer. and removed status/can-merge Indicates a PR has been approved by a committer. labels Mar 18, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 18, 2020

/run-all-tests

@ngaut ngaut merged commit 7a51ca5 into pingcap:master Mar 18, 2020

## 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Port All mysql test related to invisible index
- Learn from MySQL test cases related to invisible indexes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/docs proposal status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants