Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/MariaDB/mysql-test/main/   (MariaDB Server Version 8.1-8.4©)  Datei vom 1.9.2026 mit Größe 85 kB image not shown  

Quelle  opt_hints_qb_name_path.result   Sprache: Lisp

 


================================================================
set optimizer_switch= 'derived_merge=on';
create table t1 (a int, b int, c char(20), key idx_a(a), key idx_ab(a, b));
insert into t1 select seq, seq, 'filler' from seq_1_to_100;
create table t2 as select * from t1;
analyze table t1,t2 persistent for all;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
create view v1 as select * from t1 where a < 10;
create view v2 as
select * from t1 join /* Name of this query block is @SEL_1 */
(
select count(*) from t1 join v1 /* Name of this query block is @SEL_2 */
) tt;
create view v3 as
select * from t1 where a < 10 union select * from t1 where a > 90;
# ======================================
# Views
#
# select /* The name of the current query block is @SEL_1 */ * from v1;
#
# Addressing a view having one query block.
# QB_NAME(qb_v1, v1) means: inner query block of the view `v1`,
# which is present in the same query block as the hint, gets the name `qb_v1`.
# This name can be used in other hints.
explain extended
select /*+ qb_name(qb_v1, v1) no_index(t1@qb_v1)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_v1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Equivalent to the above but specifying @SEL_1 explicitly.
# QB_NAME(qb_v1, v1@sel_1) means: inner query block of view `v1`,
# which is present in SELECT#1 of the current query block, gets the name `qb_v1`.
explain extended
select /*+ qb_name(qb_v1, v1@sel_1) no_index(t1@qb_v1 idx_a)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_ab idx_ab 5 NULL 7 100.00 Using index condition
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_v1` `idx_a`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Equivalent to the above but also specifying @SEL_1 of the view.
# QB_NAME(qb_v1, v1@sel_1 .@sel_1) means: SELECT#1 of view `v1`,
# which is present in SELECT#1 of the current query block, gets the name `qb_v1`.
explain extended
select /*+ qb_name(qb_v1, v1@sel_1 .@sel_1) no_index(t1@qb_v1 idx_ab)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_v1` `idx_ab`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
#
# The case when a particular view is used in more than one query block.
#   select /* Name of current query block is @SEL_1 */ * from v1
#   join
#   (select /* Name of current query block is @SEL_2 */ * from v1) vvv1;
# The first query block of view v1 can be declared as
#   QB_NAME(v1_1, v1@SEL_1 .@SEL_1),
# and the second query block of the view v1 can be declared as
#   QB_NAME(v1_2, v1@SEL_1 .@SEL_2).
#
# By default, range access is used for both `t1`'s in the statement below. 
explain extended
select * from v1 join (select * from v1) vvv1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition; Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
# Disable index access for t1 from the second occurence of view v1:
explain extended
select /*+ qb_name(v1_2, v1@SEL_2 .@SEL_1) no_index(t1@v1_2)*/ *
from v1 join (select * from v1) vvv1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`v1_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
# Disable index access for t1 from both occurences of view v1:
explain extended
select /*+ qb_name(v1_1, v1@SEL_1) qb_name(v1_2, v1@SEL_2 .@SEL_1)
no_index(t1@v1_1) no_index(t1@v1_2)*/
 *
from v1 join (select * from v1) vvv1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`v1_1`) NO_INDEX(`t1`@`v1_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
#
# The case when a particular view has more than one query block.
# create view v2 as
#   select * from t1 join /* Name of this query block is @SEL_1 */
#   (
#     select count(*) from t1 join v1 /* Name of this query block is @SEL_2 */
#   ) tt;
# The first query block of view v2 can be declared as
# QB_NAME(v2_1, v2@SEL_1 .@SEL_1), and the second query block can be
# declared as QB_NAME(v2_2, v2@SEL_1 .@SEL_2).
#
# See the default execution plan:
explain extended select * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
3 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Disable index access for t1 from the second query block of view v2:
explain extended
select /*+ qb_name(v2_2, v2@SEL_1 .@SEL_2) no_index(t1@v2_2)*/* from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Disable index access for `t1` from view `v1` used in
# the first query block of view `v2`:
explain extended
select /*+ qb_name(v2_v1, v2@SEL_1 .v1@SEL_2) no_index(t1@v2_v1)*/* from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 900 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_v1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Equivalent to the above but specifying @SEL_1 explicitly:
explain extended
select /*+ qb_name(v2_v1_sel1, v2@SEL_1 .v1@SEL_2 .@SEL_1)
no_index(t1@v2_v1_sel1)*/
 * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 900 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_v1_sel1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Disable index access for `t1` tables from views `v1` and `v2`
explain extended
select /*+ qb_name(v2_v1, v2@SEL_1 .v1@SEL_2) no_index(t1@v2_v1)
qb_name(v2_2, v2@SEL_1 .@SEL_2) no_index(t1@v2_2) */
 * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 900 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_v1`) NO_INDEX(`t1`@`v2_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# ======================================
# Views with UNION
#
# Default execution plan:
explain extended select * from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 19 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# `v3` in QB path corresponds to @SEL_1:
explain extended select /*+ qb_name(qb_v3, v3) no_index(t1@qb_v3)*/* from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_v3`) */ `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# Addressing @SEL_1 of `v3` explicitly:
explain extended
select /*+ qb_name(qb_v3_sel1, v3.@sel_1) no_index(t1@qb_v3_sel1)*/* from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_v3_sel1`) */ `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# Addressing @SEL_2 of `v3` explicitly:
explain extended
select /*+ qb_name(qb_v3_sel2, v3.@sel_2) no_index(t1@qb_v3_sel2)*/* from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 14 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 ALL NULL NULL NULL NULL 100 10.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_v3_sel2`) */ `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# ======================================
# Derived tables
#
# QB_NAME(qb_dt, dt) means: inner query block of derived table `dt`,
# which is present in the same query block as the hint, gets the name `qb_dt`.
# This name can be used in other hints.
explain extended select /*+ qb_name(qb_dt, dt) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# QB_NAME(qb_dt, dt@sel_1) means: inner query block of derived table `dt`,
# which is present in SELECT#1 of the current query block, gets the name `qb_dt`.
explain extended select /*+ qb_name(qb_dt, dt@sel_1) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# QB_NAME(qb_dt, dt@sel_1 .@sel_1) means: SELECT#1 of derived table `dt`,
# which is present in SELECT#1 of the current query block, gets the name `qb_dt`.
explain extended select /*+ qb_name(qb_dt, dt@sel_1 .@sel_1) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# QB_NAME(qb4, dw .dv .du) addresses the query block `du`, and the hint
# NO_MERGE(@qb4) forbids merging of any derived tables of this block.
# There is one derived table `dt` inside this block, so the hint applies to it.
explain extended
select /*+ QB_NAME(qb4, dw .dv .du)  NO_MERGE(@qb4) */ a from (
select a from (
select a from (
select a from (
select a from t1) dt
)  du
) dv
) dw;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived5> ALL NULL NULL NULL NULL 100 100.00 
5 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`qb4`) */ `dt`.`a` AS `a` from (/* select#5 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt`
# QB_NAME(qb4, dw .dv .du) addresses the query block `du`, and the hint
# MERGE(@qb4) allows merging of any derived tables of this block.
# There is one derived table `dt` inside this block, so the hint applies to it.
explain extended
select /*+ QB_NAME(qb4, dw .dv .du)  MERGE(@qb4) */ a from (
select a from (
select a from (
select a from (
select a from t1) dt
)  du
) dv
) dw;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index NULL idx_a 5 NULL 100 100.00 Using index
Warnings:
Note 1003 select /*+ MERGE(@`qb4`) */ `test`.`t1`.`a` AS `a` from `test`.`t1`
# ======================================
# Derived tables with UNION
#
# Default execution plan:
explain extended
select * from (select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 19 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# `dt` in QB path corresponds to @SEL_1:
explain extended
select /*+ qb_name(qb_dt, dt) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# Addressing @SEL_1 of `dt` explicitly:
explain extended
select /*+ qb_name(qb_dt_sel1, dt.@sel_1) no_index(t1@qb_dt_sel1)*/* from
(select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt_sel1`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt_sel1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# Addressing @SEL_2 of `dt` explicitly:
explain extended
select /*+ qb_name(qb_dt_sel2, dt.@sel_2) no_index(t1@qb_dt_sel2)*/* from
(select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 14 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 ALL NULL NULL NULL NULL 100 10.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt_sel2`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select /*+ QB_NAME(`qb_dt_sel2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# ======================================
# Mix of views and derived tables
#
explain extended
select /*+ qb_name(dt1_v1_1, dt1 .v1 .@SEL_1) no_index(t1@dt1_v1_1)*/ *
from v1 join (select * from v1) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`dt1_v1_1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
# More complicated query. Default execution plan:
explain extended
select v1.* from v1 join (select v1.* from v1 join (select * from v2) dt2) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index; Using join buffer (flat, BNL join)
1 PRIMARY t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (incremental, BNL join)
1 PRIMARY <derived7> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (incremental, BNL join)
7 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
7 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` join `test`.`t1` join (/* select#7 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(dt1_v1_1, dt1 .v1 .@SEL_1) no_index(t1@dt1_v1_1)*/ v1.*
from v1 join (select v1.* from v1 join (select * from v2) dt2) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 9.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (incremental, BNL join)
1 PRIMARY <derived7> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (incremental, BNL join)
7 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
7 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt1_v1_1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` join `test`.`t1` join (/* select#7 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(dt2_dt1_v1_1, dt1 .dt2 .v2 .@SEL_2)
no_index(t1@dt2_dt1_v1_1)*/
 v1.*
from v1 join (select v1.* from v1 join (select * from v2) dt2) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index; Using join buffer (flat, BNL join)
1 PRIMARY t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (incremental, BNL join)
1 PRIMARY <derived7> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (incremental, BNL join)
7 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
7 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt2_dt1_v1_1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` join `test`.`t1` join (/* select#7 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt` where `test`.`t1`.`a` < 10 and `test`.`t1`.`a` < 10
# ======================================
# CTEs
#
# Default execution plan:
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select `cte`.`count(*)` AS `count(*)` from `cte`
# Disable index access for t1 in CTE
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte, cte) no_index(t1@qb_cte)*/ * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`qb_cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Disable index access for t1 in dt1 of CTE
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte_dt1, cte .dt1) no_index(t1@qb_cte_dt1)*/ * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 400 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 4.00 Using where
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte_dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Disable index access for both t1's
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte, cte) no_index(t1@qb_cte)
qb_name(qb_cte_dt1, cte .dt1) no_index(t1@qb_cte_dt1)*/
 * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 400 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 4.00 Using where
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`qb_cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte`) NO_INDEX(`t1`@`qb_cte_dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Multiple references to a CTE in a query.
# Default execution plan:
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select * from cte join cte cte1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 200 100.00 Using join buffer (flat, BNL join)
4 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
4 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select `cte`.`count(*)` AS `count(*)`,`cte1`.`count(*)` AS `count(*)` from `cte` join `cte` `cte1`
# Disable index access for t1 in `cte`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte, cte) no_index(t1@qb_cte)*/ * from cte join cte as cte1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 200 100.00 Using join buffer (flat, BNL join)
4 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
4 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`qb_cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte`) */ `cte`.`count(*)` AS `count(*)`,`cte1`.`count(*)` AS `count(*)` from `cte` join `cte` `cte1`
# Disable index access for t1 in `cte1`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte1, cte1) no_index(t1@qb_cte1)*/ * from cte join cte as cte1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 200 100.00 Using join buffer (flat, BNL join)
4 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
4 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using where; Using index
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte1`) */ `cte`.`count(*)` AS `count(*)`,`cte1`.`count(*)` AS `count(*)` from `cte` join `cte` `cte1`
# ======================================
# Scalar context subquery
explain extended
select /*+ qb_name(inner, @sel_3) no_index(t1@inner) */
(select (select max(a) from t1 where a < 10) + b)
from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL idx_ab 10 NULL 100 100.00 Using index
3 SUBQUERY t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.b' of SELECT #2 was resolved in SELECT #1
Note 1249 Select 2 was reduced during optimization
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`inner`) */ (/* select#3 */ select /*+ QB_NAME(`inner`) */ max(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` < 10) + `test`.`t1`.`b` AS `(select (select max(a) from t1 where a < 10) + b)` from `test`.`t1`
# ======================================
# Wrong paths generate warnings
#
explain extended
select /*+ qb_name(`qb_v1`, `v2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v2`) is ignored. `v2` required at element #1 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Wrong view name `v2`, however `@sel_2` is correct as it addresses
# the inner query block of `v1`
explain extended
select /*+ qb_name(qb_v1, `v2`@`sel_2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v2`@`sel_2`) is ignored. `v2` required at element #1 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(qb_v1, v2@sel_1 .@sel_2)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v2`@`sel_1` .@`sel_2`) is ignored. `v2` required at element #1 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Attempting to reference a regular table as a query block:
explain extended
select /*+ qb_name(qb_v1, dt .t1)*/* from (select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `dt` .`t1`) is ignored. `t1` required at element #2 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10
# Wrong view name inside a derived table:
explain extended
select /*+ qb_name(qb_v1, dt .v2)*/* from (select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `dt` .`v2`) is ignored. `v2` required at element #2 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10
# Wrong select number:
explain extended
select /*+ qb_name(qb_v1, dt .v1@sel_5)*/* from (select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4262 Hint QB_NAME(`qb_v1`, `dt` .`v1`@`sel_5`) is ignored. SEL_5 required at element #2 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(qb_v1, dt .v1@sel_1 .@sel_2)*/* from
(select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4262 Hint QB_NAME(`qb_v1`, `dt` .`v1`@`sel_1` .@`sel_2`) is ignored. SEL_2 required at element #3 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10
# Wrong select number syntax:
explain extended
select /*+ qb_name(qb_v1, `v1`@`lex_2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4261 Hint QB_NAME(`qb_v1`, `v1`@`lex_2`) is ignored. Element #1 of the path contains invalid select number (expected: @SEL_1, @SEL_2, ...).
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(qb_v1, v1 .lex_2)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v1` .`lex_2`) is ignored. `lex_2` required at element #2 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Select number is too large:
explain extended
select /*+ qb_name(qb_v1, `v1`@`SEL_9999999999`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4261 Hint QB_NAME(`qb_v1`, `v1`@`SEL_9999999999`) is ignored. Element #1 of the path contains invalid select number (expected: @SEL_1, @SEL_2, ...).
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Exponential select numbers are not allowed:
explain extended
select /*+ qb_name(qb_v1, `v1`@`SEL_1e2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4261 Hint QB_NAME(`qb_v1`, `v1`@`SEL_1e2`) is ignored. Element #1 of the path contains invalid select number (expected: @SEL_1, @SEL_2, ...).
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# @SEL_N matches a SELECT in a sibling unit (warning expected).
# v1 has only @SEL_1, v3 has @SEL_1 and @SEL_2 (UNION)
# Navigate to v1, ask for @SEL_2 which matches v3's SELECT
explain extended
select /*+ qb_name(qb_wrong, v1 .@SEL_2) */ * from v1 join v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 19 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
4 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Warning 4262 Hint QB_NAME(`qb_wrong`, `v1` .@`SEL_2`) is ignored. SEL_2 required at element #2 of the path is not found in the target query block.
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`t1` join `test`.`v3` where `test`.`t1`.`a` < 10
drop table t1, t2;
drop view v1, v2, v3;
#
# MDEV-39304 QB_Name hint with path is silently ignored inside view definition
#
create table t1 (a int, b int, index(a), index(b));
insert into t1 values (1,2), (3,4);
create view v1 as select /*+ QB_NAME(dt1,dt2) */ * from
(select a from t1) dt1, (select b from t1) dt2;
Warnings:
Warning 4264 Hint QB_NAME(`dt1`, `dt2`) is ignored. QB_NAME hints with path are not supported inside view definitions.
create view v2 as select * from (select a from t1) dt1, (select b from t1) dt2;
alter view v2 as select /*+ QB_NAME(dt1,dt2) */ * from
(select a from t1) dt1, (select b from t1) dt2;
Warnings:
Warning 4264 Hint QB_NAME(`dt1`, `dt2`) is ignored. QB_NAME hints with path are not supported inside view definitions.
# QB_NAME points to SEL#3 (dt2), so `no_index(t1@dt1)` hint correctly addresses t1 from dt2
explain extended select /*+ no_index(t1@dt1) qb_name(dt1, @sel_3) */ * from
(select a from t1) dt1, (select b from t1) dt2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index NULL a 5 NULL 2 100.00 Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`dt1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t1`
# @dt1 addresses dt1 from `v1` definition, hint applied correctly
explain extended select /*+ no_index(t1@dt1) */ * from v1, (select b from t1) dt2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 
1 SIMPLE t1 index NULL b 5 NULL 2 100.00 Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 index NULL b 5 NULL 2 100.00 Using index; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`dt1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t1` join `test`.`t1`
# Ambiguity: there is dt1 both in `v1` definition and in top-level select, hint ignored
explain extended select /*+ no_index(t1@dt1) */ * from v1, (select b from t1) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index NULL a 5 NULL 2 100.00 Using index
1 SIMPLE t1 index NULL b 5 NULL 2 100.00 Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 index NULL b 5 NULL 2 100.00 Using index; Using join buffer (incremental, BNL join)
Warnings:
Warning 4259 Query block name `dt1` is ambiguous for NO_INDEX hint
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t1` join `test`.`t1`
drop view v1, v2;
drop table t1;

================================================================
set optimizer_switch= 'derived_merge=off';
create table t1 (a int, b int, c char(20), key idx_a(a), key idx_ab(a, b));
insert into t1 select seq, seq, 'filler' from seq_1_to_100;
create table t2 as select * from t1;
analyze table t1,t2 persistent for all;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
create view v1 as select * from t1 where a < 10;
create view v2 as
select * from t1 join /* Name of this query block is @SEL_1 */
(
select count(*) from t1 join v1 /* Name of this query block is @SEL_2 */
) tt;
create view v3 as
select * from t1 where a < 10 union select * from t1 where a > 90;
# ======================================
# Views
#
# select /* The name of the current query block is @SEL_1 */ * from v1;
#
# Addressing a view having one query block.
# QB_NAME(qb_v1, v1) means: inner query block of the view `v1`,
# which is present in the same query block as the hint, gets the name `qb_v1`.
# This name can be used in other hints.
explain extended
select /*+ qb_name(qb_v1, v1) no_index(t1@qb_v1)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_v1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Equivalent to the above but specifying @SEL_1 explicitly.
# QB_NAME(qb_v1, v1@sel_1) means: inner query block of view `v1`,
# which is present in SELECT#1 of the current query block, gets the name `qb_v1`.
explain extended
select /*+ qb_name(qb_v1, v1@sel_1) no_index(t1@qb_v1 idx_a)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_ab idx_ab 5 NULL 7 100.00 Using index condition
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_v1` `idx_a`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Equivalent to the above but also specifying @SEL_1 of the view.
# QB_NAME(qb_v1, v1@sel_1 .@sel_1) means: SELECT#1 of view `v1`,
# which is present in SELECT#1 of the current query block, gets the name `qb_v1`.
explain extended
select /*+ qb_name(qb_v1, v1@sel_1 .@sel_1) no_index(t1@qb_v1 idx_ab)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Note 1003 select /*+ NO_INDEX(`t1`@`qb_v1` `idx_ab`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
#
# The case when a particular view is used in more than one query block.
#   select /* Name of current query block is @SEL_1 */ * from v1
#   join
#   (select /* Name of current query block is @SEL_2 */ * from v1) vvv1;
# The first query block of view v1 can be declared as
#   QB_NAME(v1_1, v1@SEL_1 .@SEL_1),
# and the second query block of the view v1 can be declared as
#   QB_NAME(v1_2, v1@SEL_1 .@SEL_2).
#
# By default, range access is used for both `t1`'s in the statement below. 
explain extended
select * from v1 join (select * from v1) vvv1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`vvv1`.`a` AS `a`,`vvv1`.`b` AS `b`,`vvv1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `vvv1` where `test`.`t1`.`a` < 10
# Disable index access for t1 from the second occurence of view v1:
explain extended
select /*+ qb_name(v1_2, v1@SEL_2 .@SEL_1) no_index(t1@v1_2)*/ *
from v1 join (select * from v1) vvv1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v1_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`vvv1`.`a` AS `a`,`vvv1`.`b` AS `b`,`vvv1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `vvv1` where `test`.`t1`.`a` < 10
# Disable index access for t1 from both occurences of view v1:
explain extended
select /*+ qb_name(v1_1, v1@SEL_1) qb_name(v1_2, v1@SEL_2 .@SEL_1)
no_index(t1@v1_1) no_index(t1@v1_2)*/
 *
from v1 join (select * from v1) vvv1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 9.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v1_1`) NO_INDEX(`t1`@`v1_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`vvv1`.`a` AS `a`,`vvv1`.`b` AS `b`,`vvv1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `vvv1` where `test`.`t1`.`a` < 10
#
# The case when a particular view has more than one query block.
# create view v2 as
#   select * from t1 join /* Name of this query block is @SEL_1 */
#   (
#     select count(*) from t1 join v1 /* Name of this query block is @SEL_2 */
#   ) tt;
# The first query block of view v2 can be declared as
# QB_NAME(v2_1, v2@SEL_1 .@SEL_1), and the second query block can be
# declared as QB_NAME(v2_2, v2@SEL_1 .@SEL_2).
#
# See the default execution plan:
explain extended select * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
3 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Disable index access for t1 from the second query block of view v2:
explain extended
select /*+ qb_name(v2_2, v2@SEL_1 .@SEL_2) no_index(t1@v2_2)*/* from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Disable index access for `t1` from view `v1` used in
# the first query block of view `v2`:
explain extended
select /*+ qb_name(v2_v1, v2@SEL_1 .v1@SEL_2) no_index(t1@v2_v1)*/* from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 900 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_v1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Equivalent to the above but specifying @SEL_1 explicitly:
explain extended
select /*+ qb_name(v2_v1_sel1, v2@SEL_1 .v1@SEL_2 .@SEL_1)
no_index(t1@v2_v1_sel1)*/
 * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 900 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_v1_sel1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# Disable index access for `t1` tables from views `v1` and `v2`
explain extended
select /*+ qb_name(v2_v1, v2@SEL_1 .v1@SEL_2) no_index(t1@v2_v1)
qb_name(v2_2, v2@SEL_1 .@SEL_2) no_index(t1@v2_2) */
 * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 900 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`v2_v1`) NO_INDEX(`t1`@`v2_2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#3 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`
# ======================================
# Views with UNION
#
# Default execution plan:
explain extended select * from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 19 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# `v3` in QB path corresponds to @SEL_1:
explain extended select /*+ qb_name(qb_v3, v3) no_index(t1@qb_v3)*/* from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_v3`) */ `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# Addressing @SEL_1 of `v3` explicitly:
explain extended
select /*+ qb_name(qb_v3_sel1, v3.@sel_1) no_index(t1@qb_v3_sel1)*/* from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_v3_sel1`) */ `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# Addressing @SEL_2 of `v3` explicitly:
explain extended
select /*+ qb_name(qb_v3_sel2, v3.@sel_2) no_index(t1@qb_v3_sel2)*/* from v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 14 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 ALL NULL NULL NULL NULL 100 10.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_v3_sel2`) */ `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# ======================================
# Derived tables
#
# QB_NAME(qb_dt, dt) means: inner query block of derived table `dt`,
# which is present in the same query block as the hint, gets the name `qb_dt`.
# This name can be used in other hints.
explain extended select /*+ qb_name(qb_dt, dt) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
# QB_NAME(qb_dt, dt@sel_1) means: inner query block of derived table `dt`,
# which is present in SELECT#1 of the current query block, gets the name `qb_dt`.
explain extended select /*+ qb_name(qb_dt, dt@sel_1) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
# QB_NAME(qb_dt, dt@sel_1 .@sel_1) means: SELECT#1 of derived table `dt`,
# which is present in SELECT#1 of the current query block, gets the name `qb_dt`.
explain extended select /*+ qb_name(qb_dt, dt@sel_1 .@sel_1) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
# QB_NAME(qb4, dw .dv .du) addresses the query block `du`, and the hint
# NO_MERGE(@qb4) forbids merging of any derived tables of this block.
# There is one derived table `dt` inside this block, so the hint applies to it.
explain extended
select /*+ QB_NAME(qb4, dw .dv .du)  NO_MERGE(@qb4) */ a from (
select a from (
select a from (
select a from (
select a from t1) dt
)  du
) dv
) dw;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 100 100.00 
2 DERIVED <derived3> ALL NULL NULL NULL NULL 100 100.00 
3 DERIVED <derived4> ALL NULL NULL NULL NULL 100 100.00 
4 DERIVED <derived5> ALL NULL NULL NULL NULL 100 100.00 
5 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`qb4`) */ `dw`.`a` AS `a` from (/* select#2 */ select `dv`.`a` AS `a` from (/* select#3 */ select `du`.`a` AS `a` from (/* select#4 */ select /*+ QB_NAME(`qb4`) */ `dt`.`a` AS `a` from (/* select#5 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt`) `du`) `dv`) `dw`
# QB_NAME(qb4, dw .dv .du) addresses the query block `du`, and the hint
# MERGE(@qb4) allows merging of any derived tables of this block.
# There is one derived table `dt` inside this block, so the hint applies to it.
explain extended
select /*+ QB_NAME(qb4, dw .dv .du)  MERGE(@qb4) */ a from (
select a from (
select a from (
select a from (
select a from t1) dt
)  du
) dv
) dw;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 100 100.00 
2 DERIVED <derived3> ALL NULL NULL NULL NULL 100 100.00 
3 DERIVED <derived4> ALL NULL NULL NULL NULL 100 100.00 
4 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select /*+ MERGE(@`qb4`) */ `dw`.`a` AS `a` from (/* select#2 */ select `dv`.`a` AS `a` from (/* select#3 */ select `du`.`a` AS `a` from (/* select#4 */ select /*+ QB_NAME(`qb4`) */ `test`.`t1`.`a` AS `a` from `test`.`t1`) `du`) `dv`) `dw`
# ======================================
# Derived tables with UNION
#
# Default execution plan:
explain extended
select * from (select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 19 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# `dt` in QB path corresponds to @SEL_1:
explain extended
select /*+ qb_name(qb_dt, dt) no_index(t1@qb_dt)*/* from
(select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# Addressing @SEL_1 of `dt` explicitly:
explain extended
select /*+ qb_name(qb_dt_sel1, dt.@sel_1) no_index(t1@qb_dt_sel1)*/* from
(select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 23 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
3 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt_sel1`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`qb_dt_sel1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# Addressing @SEL_2 of `dt` explicitly:
explain extended
select /*+ qb_name(qb_dt_sel2, dt.@sel_2) no_index(t1@qb_dt_sel2)*/* from
(select * from t1 where a < 10 union select * from t1 where a > 90) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 14 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
3 UNION t1 ALL NULL NULL NULL NULL 100 10.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`qb_dt_sel2`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10 union /* select#3 */ select /*+ QB_NAME(`qb_dt_sel2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 90) `dt`
# ======================================
# Mix of views and derived tables
#
explain extended
select /*+ qb_name(dt1_v1_1, dt1 .v1 .@SEL_1) no_index(t1@dt1_v1_1)*/ *
from v1 join (select * from v1) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt1_v1_1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`dt1`.`a` AS `a`,`dt1`.`b` AS `b`,`dt1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10) `dt1` where `test`.`t1`.`a` < 10
# More complicated query. Default execution plan:
explain extended
select v1.* from v1 join (select v1.* from v1 join (select * from v2) dt2) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 250000 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
2 DERIVED <derived3> ALL NULL NULL NULL NULL 50000 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 
3 DERIVED <derived7> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
7 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
7 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#7 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`) `dt2` where `test`.`t1`.`a` < 10) `dt1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(dt1_v1_1, dt1 .v1 .@SEL_1) no_index(t1@dt1_v1_1)*/ v1.*
from v1 join (select v1.* from v1 join (select * from v2) dt2) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 450000 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 100 9.00 Using where
2 DERIVED <derived3> ALL NULL NULL NULL NULL 50000 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 
3 DERIVED <derived7> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
7 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
7 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt1_v1_1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#7 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`) `dt2` where `test`.`t1`.`a` < 10) `dt1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(dt2_dt1_v1_1, dt1 .dt2 .v2 .@SEL_2)
no_index(t1@dt2_dt1_v1_1)*/
 v1.*
from v1 join (select v1.* from v1 join (select * from v2) dt2) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 250000 100.00 Using join buffer (flat, BNL join)
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
2 DERIVED <derived3> ALL NULL NULL NULL NULL 50000 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 
3 DERIVED <derived7> ALL NULL NULL NULL NULL 500 100.00 Using join buffer (flat, BNL join)
7 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
7 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt2_dt1_v1_1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`tt`.`count(*)` AS `count(*)` from `test`.`t1` join (/* select#7 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `tt`) `dt2` where `test`.`t1`.`a` < 10) `dt1` where `test`.`t1`.`a` < 10
# ======================================
# CTEs
#
# Default execution plan:
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select `cte`.`count(*)` AS `count(*)` from `cte`
# Disable index access for t1 in CTE
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte, cte) no_index(t1@qb_cte)*/ * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`qb_cte`) */ count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Disable index access for t1 in dt1 of CTE
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte_dt1, cte .dt1) no_index(t1@qb_cte_dt1)*/ * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 400 100.00 
2 DERIVED <derived3> ALL NULL NULL NULL NULL 4 100.00 
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 4.00 Using where
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select /*+ QB_NAME(`qb_cte_dt1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte_dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Disable index access for both t1's
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte, cte) no_index(t1@qb_cte)
qb_name(qb_cte_dt1, cte .dt1) no_index(t1@qb_cte_dt1)*/
 * from cte;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 400 100.00 
2 DERIVED <derived3> ALL NULL NULL NULL NULL 4 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 100 4.00 Using where
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`qb_cte`) */ count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select /*+ QB_NAME(`qb_cte_dt1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte`) NO_INDEX(`t1`@`qb_cte_dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Multiple references to a CTE in a query.
# Default execution plan:
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select * from cte join cte cte1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 200 100.00 Using join buffer (flat, BNL join)
4 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00 
4 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
5 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select `cte`.`count(*)` AS `count(*)`,`cte1`.`count(*)` AS `count(*)` from `cte` join `cte` `cte1`
# Disable index access for t1 in `cte`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte, cte) no_index(t1@qb_cte)*/ * from cte join cte as cte1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 200 100.00 Using join buffer (flat, BNL join)
4 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00 
4 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
5 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`qb_cte`) */ count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte`) */ `cte`.`count(*)` AS `count(*)`,`cte1`.`count(*)` AS `count(*)` from `cte` join `cte` `cte1`
# Disable index access for t1 in `cte1`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ qb_name(qb_cte1, cte1) no_index(t1@qb_cte1)*/ * from cte join cte as cte1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200 100.00 
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 200 100.00 Using join buffer (flat, BNL join)
4 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00 
4 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
5 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 index NULL idx_a 5 NULL 100 100.00 Using index; Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `dt1`)/* select#1 */ select /*+ NO_INDEX(`t1`@`qb_cte1`) */ `cte`.`count(*)` AS `count(*)`,`cte1`.`count(*)` AS `count(*)` from `cte` join `cte` `cte1`
# ======================================
# Scalar context subquery
explain extended
select /*+ qb_name(inner, @sel_3) no_index(t1@inner) */
(select (select max(a) from t1 where a < 10) + b)
from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL idx_ab 10 NULL 100 100.00 Using index
3 SUBQUERY t1 ALL NULL NULL NULL NULL 100 9.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.b' of SELECT #2 was resolved in SELECT #1
Note 1249 Select 2 was reduced during optimization
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`inner`) */ (/* select#3 */ select /*+ QB_NAME(`inner`) */ max(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` < 10) + `test`.`t1`.`b` AS `(select (select max(a) from t1 where a < 10) + b)` from `test`.`t1`
# ======================================
# Wrong paths generate warnings
#
explain extended
select /*+ qb_name(`qb_v1`, `v2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v2`) is ignored. `v2` required at element #1 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Wrong view name `v2`, however `@sel_2` is correct as it addresses
# the inner query block of `v1`
explain extended
select /*+ qb_name(qb_v1, `v2`@`sel_2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v2`@`sel_2`) is ignored. `v2` required at element #1 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(qb_v1, v2@sel_1 .@sel_2)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v2`@`sel_1` .@`sel_2`) is ignored. `v2` required at element #1 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Attempting to reference a regular table as a query block:
explain extended
select /*+ qb_name(qb_v1, dt .t1)*/* from (select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 500 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `dt` .`t1`) is ignored. `t1` required at element #2 of the path is not found in the target query block.
Note 1003 /* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
# Wrong view name inside a derived table:
explain extended
select /*+ qb_name(qb_v1, dt .v2)*/* from (select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 500 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `dt` .`v2`) is ignored. `v2` required at element #2 of the path is not found in the target query block.
Note 1003 /* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
# Wrong select number:
explain extended
select /*+ qb_name(qb_v1, dt .v1@sel_5)*/* from (select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 500 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4262 Hint QB_NAME(`qb_v1`, `dt` .`v1`@`sel_5`) is ignored. SEL_5 required at element #2 of the path is not found in the target query block.
Note 1003 /* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
explain extended
select /*+ qb_name(qb_v1, dt .v1@sel_1 .@sel_2)*/* from
(select t1.* from t1 join v1) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 500 100.00 
2 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using where; Using index
2 DERIVED t1 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings:
Warning 4262 Hint QB_NAME(`qb_v1`, `dt` .`v1`@`sel_1` .@`sel_2`) is ignored. SEL_2 required at element #3 of the path is not found in the target query block.
Note 1003 /* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 10) `dt`
# Wrong select number syntax:
explain extended
select /*+ qb_name(qb_v1, `v1`@`lex_2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4261 Hint QB_NAME(`qb_v1`, `v1`@`lex_2`) is ignored. Element #1 of the path contains invalid select number (expected: @SEL_1, @SEL_2, ...).
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
explain extended
select /*+ qb_name(qb_v1, v1 .lex_2)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4263 Hint QB_NAME(`qb_v1`, `v1` .`lex_2`) is ignored. `lex_2` required at element #2 of the path is not found in the target query block.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Select number is too large:
explain extended
select /*+ qb_name(qb_v1, `v1`@`SEL_9999999999`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4261 Hint QB_NAME(`qb_v1`, `v1`@`SEL_9999999999`) is ignored. Element #1 of the path contains invalid select number (expected: @SEL_1, @SEL_2, ...).
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# Exponential select numbers are not allowed:
explain extended
select /*+ qb_name(qb_v1, `v1`@`SEL_1e2`)*/* from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
Warnings:
Warning 4261 Hint QB_NAME(`qb_v1`, `v1`@`SEL_1e2`) is ignored. Element #1 of the path contains invalid select number (expected: @SEL_1, @SEL_2, ...).
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 10
# @SEL_N matches a SELECT in a sibling unit (warning expected).
# v1 has only @SEL_1, v3 has @SEL_1 and @SEL_2 (UNION)
# Navigate to v1, ask for @SEL_2 which matches v3's SELECT
explain extended
select /*+ qb_name(qb_wrong, v1 .@SEL_2) */ * from v1 join v3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 19 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 5 100.00 Using index condition
4 UNION t1 range idx_a,idx_ab idx_ab 5 NULL 14 100.00 Using index condition
NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL NULL 
Warnings:
Warning 4262 Hint QB_NAME(`qb_wrong`, `v1` .@`SEL_2`) is ignored. SEL_2 required at element #2 of the path is not found in the target query block.
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`t1` join `test`.`v3` where `test`.`t1`.`a` < 10
drop table t1, t2;
drop view v1, v2, v3;
#
# MDEV-39304 QB_Name hint with path is silently ignored inside view definition
#
create table t1 (a int, b int, index(a), index(b));
insert into t1 values (1,2), (3,4);
create view v1 as select /*+ QB_NAME(dt1,dt2) */ * from
(select a from t1) dt1, (select b from t1) dt2;
Warnings:
Warning 4264 Hint QB_NAME(`dt1`, `dt2`) is ignored. QB_NAME hints with path are not supported inside view definitions.
create view v2 as select * from (select a from t1) dt1, (select b from t1) dt2;
alter view v2 as select /*+ QB_NAME(dt1,dt2) */ * from
(select a from t1) dt1, (select b from t1) dt2;
Warnings:
Warning 4264 Hint QB_NAME(`dt1`, `dt2`) is ignored. QB_NAME hints with path are not supported inside view definitions.
# QB_NAME points to SEL#3 (dt2), so `no_index(t1@dt1)` hint correctly addresses t1 from dt2
explain extended select /*+ no_index(t1@dt1) qb_name(dt1, @sel_3) */ * from
(select a from t1) dt1, (select b from t1) dt2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 index NULL a 5 NULL 2 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt1`) */ `dt1`.`a` AS `a`,`dt2`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt1` join (/* select#3 */ select /*+ QB_NAME(`dt1`) */ `test`.`t1`.`b` AS `b` from `test`.`t1`) `dt2`
# @dt1 addresses dt1 from `v1` definition, hint applied correctly
explain extended select /*+ no_index(t1@dt1) */ * from v1, (select b from t1) dt2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 2 100.00 
1 PRIMARY <derived5> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join)
5 DERIVED t1 index NULL b 5 NULL 2 100.00 Using index
4 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 
2 DERIVED t1 index NULL b 5 NULL 2 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt1`) */ `dt1`.`a` AS `a`,`dt2`.`b` AS `b`,`dt2`.`b` AS `b` from (/* select#4 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt1` join (/* select#5 */ select `test`.`t1`.`b` AS `b` from `test`.`t1`) `dt2` join (/* select#2 */ select `test`.`t1`.`b` AS `b` from `test`.`t1`) `dt2`
# Ambiguity: there is dt1 both in `v1` definition and in top-level select, hint ignored
explain extended select /*+ no_index(t1@dt1) */ * from v1, (select b from t1) dt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 2 100.00 
1 PRIMARY <derived5> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join)
5 DERIVED t1 index NULL b 5 NULL 2 100.00 Using index
4 DERIVED t1 index NULL a 5 NULL 2 100.00 Using index
2 DERIVED t1 index NULL b 5 NULL 2 100.00 Using index
Warnings:
Warning 4259 Query block name `dt1` is ambiguous for NO_INDEX hint
Note 1003 /* select#1 */ select `dt1`.`a` AS `a`,`dt2`.`b` AS `b`,`dt1`.`b` AS `b` from (/* select#4 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt1` join (/* select#5 */ select `test`.`t1`.`b` AS `b` from `test`.`t1`) `dt2` join (/* select#2 */ select `test`.`t1`.`b` AS `b` from `test`.`t1`) `dt1`
drop view v1, v2;
drop table t1;
set optimizer_switch= default;

Messung V0.5 in Prozent
C=73 H=100 G=87

¤ Dauer der Verarbeitung: 0.22 Sekunden  (vorverarbeitet am  2026-10-08) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.