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

Optimizer hints is not worked for views #37887

Closed
jackysp opened this issue Sep 16, 2022 · 2 comments · Fixed by #38653
Closed

Optimizer hints is not worked for views #37887

jackysp opened this issue Sep 16, 2022 · 2 comments · Fixed by #38653
Assignees
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@jackysp
Copy link
Member

jackysp commented Sep 16, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql --connect-timeout 15 -u '3sDg3oSF1k7eu15.root' -h [gateway01.ap-northeast-1.prod.aws.tidbcloud.com](http://gateway01.ap-northeast-1.prod.aws.tidbcloud.com/) -P 4000 -D test -p

You can use your own tidb-cloud dev_tier.

use gharchive_dev;
create view v1 as select * from github_events;
explain select /*+ use_index(github_events, index_github_events_on_actor_id) */ * from v1 where id = 1;

2. What did you expect to see? (Required)

The plan should use index index_github_events_on_actor_id.

3. What did you see instead (Required)

mysql> explain select /*+ use_index(github_events, index_github_events_on_actor_id) */ * from v1 where id = 1;
+--------------------------------+---------+-----------+----------------------------------------------------------+-------------------------------+
| id                             | estRows | task      | access object                                            | operator info                 |
+--------------------------------+---------+-----------+----------------------------------------------------------+-------------------------------+
| IndexLookUp_15                 | 0.00    | root      |                                                          |                               |
| ├─IndexRangeScan_13(Build)     | 0.00    | cop[tikv] | table:github_events, index:index_github_events_on_id(id) | range:[1,1], keep order:false |
| └─TableRowIDScan_14(Probe)     | 0.00    | cop[tikv] | table:github_events                                      | keep order:false              |
+--------------------------------+---------+-----------+----------------------------------------------------------+-------------------------------+
3 rows in set, 1 warning (0.18 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                              |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1815 | use_index(gharchive_dev.github_events, index_github_events_on_actor_id) is inapplicable, check whether the table(gharchive_dev.github_events) exists |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.12 sec)

4. What is your TiDB version? (Required)

796fb1f

@jackysp jackysp added the type/bug The issue is confirmed as a bug. label Sep 16, 2022
@jackysp jackysp changed the title The hintUSE_INDEX not work for views The hint USE_INDEX not work for views Sep 16, 2022
@winoros
Copy link
Member

winoros commented Sep 16, 2022

https://docs.oracle.com/cd/E18283_01/server.112/e16638/hintsref.htm#i27644

We can impl the same grammar mentioned in this chapter. It's a reasonable solution that is not hard to impl. But we need to extend our parser to support the grammar.

The current

// HintTable is table in the hint. It may have query block info.
type HintTable struct {
        DBName        model.CIStr
        TableName     model.CIStr
        QBName        model.CIStr
        PartitionList []model.CIStr
}

should become

// HintTable is table in the hint. It may have query block info.
type HintTable struct {
        DBName        model.CIStr
        TableName     model.CIStr
        QBNameList   []model.CIStr
        PartitionList []model.CIStr
}

@winoros winoros added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner and removed type/bug The issue is confirmed as a bug. labels Sep 16, 2022
@winoros winoros changed the title The hint USE_INDEX not work for views Optimizer hints is not worked for views Sep 16, 2022
@winoros
Copy link
Member

winoros commented Sep 16, 2022

Not only the index hint, we will fail if we want to use hint to choose the physical algorithm of join/agg.
Thus, modify the title of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants