-
Notifications
You must be signed in to change notification settings - Fork 710
Add index lookup push down content #22196
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -475,6 +475,60 @@ EXPLAIN SELECT /*+ NO_ORDER_INDEX(t, a) */ a FROM t ORDER BY a LIMIT 10; | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The same as the example of `ORDER_INDEX` hint, the optimizer generates two types of plans for this query: `Limit + IndexScan(keep order: true)` and `TopN + IndexScan(keep order: false)`. When the `NO_ORDER_INDEX` hint is used, the optimizer will choose the latter plan to read the index out of order. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### INDEX_LOOKUP_PUSHDOWN(t1_name, idx1_name [, idx2_name ...]) <span class="version-mark">New in v8.5.5 and v9.0.0</span> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The `INDEX_LOOKUP_PUSHDOWN(t1_name, idx1_name [, idx2_name ...])` hint instructs the optimizer to access the specified table using only the specified indexes and to push the `IndexLookUp` operator down to TiKV for execution. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The following example shows the execution plan generated with this hint: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```sql | ||||||||||||||||||||||||||
| CREATE TABLE t1(a INT, b INT, key(a)); | ||||||||||||||||||||||||||
| EXPLAIN SELECT /*+ INDEX_LOOKUP_PUSHDOWN(t1, a) */ a, b FROM t1; | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```sql | ||||||||||||||||||||||||||
| +-----------------------------+----------+-----------+----------------------+--------------------------------+ | ||||||||||||||||||||||||||
| | id | estRows | task | access object | operator info | | ||||||||||||||||||||||||||
| +-----------------------------+----------+-----------+----------------------+--------------------------------+ | ||||||||||||||||||||||||||
| | IndexLookUp_7 | 10000.00 | root | | | | ||||||||||||||||||||||||||
| | ├─LocalIndexLookUp(Build) | 10000.00 | cop[tikv] | | index handle offsets:[1] | | ||||||||||||||||||||||||||
| | │ ├─IndexFullScan_5(Build) | 10000.00 | cop[tikv] | table:t1, index:a(a) | keep order:false, stats:pseudo | | ||||||||||||||||||||||||||
| | │ └─TableRowIDScan_8(Probe) | 10000.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo | | ||||||||||||||||||||||||||
| | └─TableRowIDScan_6(Probe) | 0.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo | | ||||||||||||||||||||||||||
| +-----------------------------+----------+-----------+----------------------+--------------------------------+ | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| When the `INDEX_LOOKUP_PUSHDOWN` hint is enabled, the outermost Build operator that originally runs on the TiDB side in the execution plan is replaced with `LocalIndexLookUp`, which is then pushed down to TiKV for execution. While scanning the index, TiKV attempts to read row data by performing local table lookups. Because the index and row data might be distributed across different Regions, the pushdown request might not cover all target rows. Therefore, TiDB retains the `TableRowIDScan` operator to fetch any rows that are not matched on the TiKV side. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The `INDEX_LOOKUP_PUSHDOWN` hint has the following limitations: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| * Cached tables and temporary tables are not supported. | ||||||||||||||||||||||||||
| * Queries using [global indexes](/global-indexes.md) are not supported. | ||||||||||||||||||||||||||
| * Queries using [multi-valued indexes](/choose-index.md#use-multi-valued-indexes) are not supported. | ||||||||||||||||||||||||||
| * Isolation levels other than `REPEATABLE-READ` are not supported. | ||||||||||||||||||||||||||
| - [Follower Read](/follower-read.md) is not supported. | ||||||||||||||||||||||||||
| - [Stale Read](/stale-read.md) and [reading historical data using `tidb_snapshot`](/read-historical-data.md) are not supported. | ||||||||||||||||||||||||||
| * The pushed-down `LocalIndexLookUp` operator does not support keep order. If the execution plan includes an `ORDER BY` clause on index columns, the query falls back to regular `IndexLookUp`. | ||||||||||||||||||||||||||
| * The pushed-down `LocalIndexLookUp` operator does not support sending Coprocessor requests in pagination mode. | ||||||||||||||||||||||||||
| * The pushed-down `LocalIndexLookUp` operator does not support [Coprocessor Cache](/coprocessor-cache.md). | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| * Isolation levels other than `REPEATABLE-READ` are not supported. | |
| - [Follower Read](/follower-read.md) is not supported. | |
| - [Stale Read](/stale-read.md) and [reading historical data using `tidb_snapshot`](/read-historical-data.md) are not supported. | |
| * The pushed-down `LocalIndexLookUp` operator does not support keep order. If the execution plan includes an `ORDER BY` clause on index columns, the query falls back to regular `IndexLookUp`. | |
| * The pushed-down `LocalIndexLookUp` operator does not support sending Coprocessor requests in pagination mode. | |
| * The pushed-down `LocalIndexLookUp` operator does not support [Coprocessor Cache](/coprocessor-cache.md). | |
| * Isolation levels other than `REPEATABLE-READ` are not supported. | |
| * [Follower Read](/follower-read.md) is not supported. | |
| * [Stale Read](/stale-read.md) and [reading historical data using `tidb_snapshot`](/read-historical-data.md) are not supported. | |
| * The pushed-down `LocalIndexLookUp` operator does not support keep order. If the execution plan includes an `ORDER BY` clause on index columns, the query falls back to regular `IndexLookUp`. | |
| * The pushed-down `LocalIndexLookUp` operator does not support sending `Coprocessor` requests in pagination mode. | |
| * The pushed-down `LocalIndexLookUp` operator does not support [Coprocessor Cache](/coprocessor-cache.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To improve readability and maintain consistency with the style guide, please wrap the hint name and operator names in backticks.
References