Odd warnings when QB_NAME tries to address a CTE
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
```sql
create table ten(a int);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table one_k(a int);
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
create table t1 (
a int,
b int,
c int,
index idx1(a)
);
insert into t1 select A.a, A.a, A.a from one_k A, ten B, ten C;
analyze table t1;
```
An attempt to have hint outside the CTE control behavior inside the CTE:
```sql
explain
with cte1 as (
select * from t1 where a=2 limit 100
)
select /*+ qb_name(my_select, tt@sel_1 ) ignore_index(t1@my_select idx1) */ *
from cte1 as tt;
```
gives
```
+--------------------------------+---------+-----------+-------------------------+---------------------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------------+---------+-----------+-------------------------+---------------------------------------------+
| IndexLookUp_23 | 10.00 | root | | limit embedded(offset:0, count:100) |
| ├─Limit_22(Build) | 10.00 | cop[tikv] | | offset:?, count:? |
| │ └─IndexRangeScan_20 | 10.00 | cop[tikv] | table:t1, index:idx1(a) | range:[?,?], keep order:false, stats:pseudo |
| └─TableRowIDScan_21(Probe) | 10.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo |
+--------------------------------+---------+-----------+-------------------------+---------------------------------------------+
4 rows in set, 1 warning (0.035 sec)
Warning (Code 1105): The qb_name hint my_select is unused, please check whether the table list in the qb_name hint my_select is correct
```
Ok, So it says `qb_name(my_select )` is not used by the IGNORE_INDEX hint. Ok let's rename it to `my_select_i_am_unused`:
```sql
explain
with cte1 as (
select * from t1 where a=2 limit 100
)
select /*+ qb_name(my_select_i_am_unused, tt@sel_1 ) ignore_index(t1@my_select idx1) */ *
from cte1 as tt;
```
gives
```
+--------------------------------+---------+-----------+-------------------------+---------------------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------------+---------+-----------+-------------------------+---------------------------------------------+
| IndexLookUp_23 | 10.00 | root | | limit embedded(offset:0, count:100) |
| ├─Limit_22(Build) | 10.00 | cop[tikv] | | offset:?, count:? |
| │ └─IndexRangeScan_20 | 10.00 | cop[tikv] | table:t1, index:idx1(a) | range:[?,?], keep order:false, stats:pseudo |
| └─TableRowIDScan_21(Probe) | 10.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo |
+--------------------------------+---------+-----------+-------------------------+---------------------------------------------+
4 rows in set, 2 warnings (0.034 sec)
Warning (Code 1105): Hint ignore_index(`t1`@`my_select` `idx1`) is ignored due to unknown query block name
Warning (Code 1105): The qb_name hint my_select_i_am_unused is unused, please check whether the table list in the qb_name hint my_select_i_am_unused is correct
```
and now we've got two warnings.
The `IGNORE_INDEX` hint is complaining that it cannot find my_select. But didn't the previous query say the hint was not used? So, it was used...
### 2. What did you expect to see? (Required)
I would have expected consistent behavior. If I get "The qb_name hint $NAME is unused", then renaming/removing it should not cause new warning about being unable to find $NAME.
### 3. What did you see instead (Required)
(see above)
### 4. What is your TiDB version? (Required)
```
| 8.0.11-TiDB-v7.5.6-serverless |
```
Contributor guide
Assessment
This issue has not been assessed yet.