Quelle opt_hints_impl_qb_name.result
Sprache: Lisp
set Warnings:
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 Note1003withcte as /
test.t1 Table todate
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
# Table-level hint
explain extended extendedextended
(select t1.* fromwith as(elect(*fromt1, ( a< ) )
id select_typeselect /*+ no_bnl(@cte)*/ * from cte;
NULL NULL 10010000
<> NULL NULL200 .java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
Warnings:
Note 1003 select /*+ NO_BNL(`t2`@`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`
# MoreNote1003 cte(*#2 *select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_BNL(@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
explain extended select /*+ no_bnl(t2@dt) no_index(t1@dt)*/ * from
(select t1.* from t1, t2 where t1.a > t2.a) as dt;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 100100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note 1003 select /*+ NO_BNL(`t2`@`dt`) NO_INDEX(`t1`@`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`
# QBselect /*+ no_index(t1@cte)*/ * from cte;*from ;
explain extended select /*+ no_bnl(@dt)*/ * from<> NULL.
(select t1.* from t1, t2 where t1.a > t2.a) as dt;
id select_type table type possible_keys2DERIVEDt1rangeidx_aidx_a 2 100 where
t1ALLiNULLNULL100 . 1 SIMPLE t2 ALL NULL NULL NULL NULL 100100.:
Warnings: /*+ NO_BNL(@`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`
#levelhints
# Without theselectjava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
explain extended select /*+ no_index(t1@`T`)*/ * from
(select * from t1 where a < 3) t;
typepossible_keys key_lenref filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10022 DERIVED ALL NULLNULL NULL 100400 Using where
Warnings:
Note 1003 select
# N as/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`cte`) NO_INDEX(`t1`@`dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
explain extended select /*+ no_range_optimization(t1@t1)*/ * from
(select * from t1 where a > 100and a < 120) as t1;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL idx_a,idx_ab NULL NULL NULL 1001.00 Using where
Warnings:
Note 1003 select /*+ NO_RANGE_OPTIMIZATION(`t1`@`t1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 100 and `test`.`t1`.`a` < 120
hint is applied correctly
explain extended select /*+ index(t1@t1 idx_ab)*/ * from
(electfrom where<3)ast1
id select_type tableidselect_typetable keyrefrows 1 SIMPLE t11PRIMARY derived2> NULL NULL 300.
Warnings:
Note 1003 select /*+ INDEX(`t1`@`t1` `idx_ab`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 3
explain extended select /*+ no_index(t1@t2 idx_a) index(t1@t1 idx_ab)*/ * from
(select * from t1 where a < 3) as t1, (select * from t1 where a 2t1 idx_a5100100 index
id typepossible_keysref filtered 1 SIMPLE t1 range idx_ab idx_ab 5 NULL java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 63 1 where
Warnings:
Note table possible_keys ref filteredExtra
explain extended select /*+ no_index(t1@t1 idx_a, idx_ab)*/ * from< NULL NULL10000
* ) t1 (elect*from wherea 5 t2
id select_type table type possible_keys key key_len 2 indexidx_a .indexUsingjava.lang.StringIndexOutOfBoundsException: Range [79, 78) out of bounds for length 95 1 SIMPLE t1 ALL NULL NULL idx_abidx_a2.java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
idx_aidx_abidx_a5200Usingconditionjava.lang.StringIndexOutOfBoundsException: Index 123 out of bounds for length 123
Warnings: /*+ NO_INDEX(`t1`@`t1` `idx_a`,`idx_ab`) */ `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` < 5 and `test`.`t1`.`a` < 3NO_BNLjava.lang.StringIndexOutOfBoundsException: Range [64, 65) out of bounds for length 64
# Nested derived tables
However java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 77
(select count(*) from t1, explain extended
id select_type table type possible_keys key withcteas(select count*)as from t1,(select from t1where a 5 dt1) 1 java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 5 2 DERIVED t1 range select_type possible_keyskey_len 2 t1 index 5 NULL .Using
Warnings:
Note 1003/* select#1 */ select /*+ NO_BNL(`t1`@`dt2`) */ `dt2`.`count(*)` AS `count(*)` from (/* select#2 */ select /*+ QB_NAME(`dt2`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5) `dt2`
explain extended select /*+ no_index(t1@DT2)*/ * from
s* select * t1 a<5 )asjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200100.00 2DERIVED java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 78 2 DERIVED t1 ALL NULL NULL NULL NULL 100100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003/* select#1 */ select /*+ NO_INDEX(`t1`@`DT2`) */ `dt2`.`count(*)` AS `count(*)` from (/* select#2 */ select /*+ QB_NAME(`DT2`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5) `dt2`
name the
explain extended 1 SIMPLE t1 range idx_ab 2100 java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
(select count(*) Warningsjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
id select_type table type possible_keys key key_len rowsjava.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 75 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 400100.00
DERIVED ALLNULL NULL1004. 2 DERIVED t1 viewv2asselect a 300;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 /* select#1 */ select /*+ NO_INDEX(`t1`@`dt2`) */ `dt2`.`count(*)` AS `count(*)` from (/* select#2 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5) `dt2`
# Both hints are applied1 t1ALL ,idx_ab NULL NULL1009400Using where
Note`.t1.` a```1.b `b``.t1``` `c` from`est.t1`where`est```.a 300andt`.`t1.` 100
( ()fromt1,(electfrom a )dt1as ;
id select_type table type possible_keys key extended /*+ index(t1@`v1` idx_ab)*/ * from v2;
PRIMARY<> 400 . 2 DERIVED t1 ALL NULL NULL NULL NULL 1004.00 Using where 2 DERIVED t1 index NULL idx_a1 SIMPLEt1rangeidx_ab idx_ab 5 NULL 99100.00 Using index condition
WarningsNote1003select
Note 1003/* select#1 */ select /*+ NO_INDEX(`t1`@`dt1`) NO_BNL(`t1`@`dt2`) */ `dt2`.`count(*)` AS `count(*)` from (/* select#2 */ select /*+ QB_NAME(`dt2`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5) `dt2`
# Nested derived tables with ambiguous names, hint isselect/*+ no_index(t1@v3) */ * from v3;
explainextended /*+ no_index(t1@t1)*/* from
(select count(*) from 1 derived2>ALLNULLNULL 20010000java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 75 1 PRIMARY <derived2Warning4260queryblocknamev3 supportedfor tables withEXCEPT and ignored
t1rangeidx_a, idx_a5NULL210000Using 2 DERIVED t1 index NULL # ` hint
Warnings:
Warning 4259 Query(electfrom > 5)dt
# *select```(* () /java.lang.StringIndexOutOfBoundsException: Index 178 out of bounds for length 178
# The hint cannot be applied to a derived 1SIMPLE idx_aidx_abidx_ab 5 NULL 9990.20 Using where; Using index
explain extended select /*+ no_index(t2@t1)*/* from
(select * from t1 where a < 3 union select *arnings:
type keykey_len rowsfilteredExtra 1 PRIMARY <derived2> ALL NULL NULL NULL Note1003select````` a`t1`` b,`.t1.` c,test```` from test.``join`test``1``est.t1`b and java.lang.StringIndexOutOfBoundsException: Range [179, 178) out of bounds for length 220
rangeidx_a 110000Usingcondition 3 UNION t2 ALL NULL NULL NULL NULL 1008.00 Using where
UNION <nion2> NULL NULLNULL NULL
Warnings:
Warning 4260 Implicit query block name `t1` is notselect.*from t1,t2 where .a >t2.) as dtjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
(/* 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` < 3 union /* select#3 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where `test`.`t2`.`a` < 9) `t1` createview java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 20
explain select /*+ no_index(t1@t1)*/* from
(select * from t1 where a < 3 union select * from t2 where a < 9) as t1;
id select_type table type create view v5 as select dt.a 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9100.00
index condition 3 UNION t2 ALL NULL NULL NULL NULL 1008.00 Using where
NULL UNIONexplain extended select /*+ no_bnl(t2@dt) */* from v5;
Warnings:
Warning 4260 Implicit typepossible_keys key_len Extra 1SIMPLEindexidx_a,idx_ab idx_a 5 NULL 100100.00 Using where; Using index
# Test INSERT..SELECT
explain extended insert into t2 select /*+ no_bnl(t2@dt)*/ * from
(select t1.* from t1, t2 where t1.a > t2.a) as dt;
id select_type table typepossible_keyskeykey_lenreffiltered java.lang.StringIndexOutOfBoundsException: Range [75, 76) out of bounds for length 75 1 SIMPLE t1 ALL idx_a,idx_ab NULL# Addressing whole derived table 1 SIMPLE t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
id s tabletypepossible_keyskey_len rows Extra
# Test 1 SIMPLE t1idx_ab 00java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 47
(select * from (1 SIMPLE t2 ALL NULL N 100100.0
id select_type Note @``/test`. a test```join ``` `.java.lang.StringIndexOutOfBoundsException: Range [118, 117) out of bounds for length 189 1 SIMPLE t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00 1 SIMPLE t2 ALL NULLexplain /*+ no_bnl(t2@dt) */ * from v4;
Warnings:
Note 1003 selectselect_typetabletype java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 75
extended /*+ no_merge(@dt)*/ * from
(select * from (select t1.1 ALLNULL NULL 100100
No1003select 1 PRIMARY <derived3> ALL NULL NULL 1000010000 3 DERIVED t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00 3 DERIVED t2 ALL NULL NULL#=================java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
Warnings: /* select#1 */ select /*+ NO_MERGE(@`dt`) */ `dt1`.`a` AS `a`,`dt1`.`b` AS `b`,`dt1`.`c` AS `c` from (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt1`
# Multiple levels of nested derived tables, allidselect_type type key_len rows Extra
extended
select /*+ no_merge(dv) no_bnl(t2@dt) */ * from (
select (
select /*+ no_merge(dt) */ * from (
select *from java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 41
)
) du
) dv;
tabletype key_len rowsfilteredjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 1 PRIMARY <derived2> ALL deletejava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
DERIVED<>NULL1000010000
(* java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 67 4 DERIVED t1 ALL idx_a,idx_ab id table keyjava.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 75 4 DERIVED t2 ALL NULL1ALL NULLNULL 1009000
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
1003java.lang.StringIndexOutOfBoundsException: Index 544 out of bounds for length 544
# ======================================
# Test CTEs
# By default BNL and index access to t1 used
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 200100.00
2 DERIVED t1 index Note java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 144
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`
explain extended
with cte as (select count(*) from t1, (select * from t1 where java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 35
java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
select_typetypepossible_keyskey java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 75 1 PRIMARY <derived2> ALL NULL NULL NULL java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 39 2 DERIVED t1 range idx_a,idx_ab idx_a end| 2 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_BNL(`t1`@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte` NULL NULL Impossiblenoticed after reading const tables
explain extended
with cte as (select count(#Storedfunction with tableinside
select /*+ no_bnl(@cte)*/ * from cte;functionget_max(p_aint)returns
select_type tabletype possible_keyskeykey_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200100.00 2# 2 DERIVED t1 index explain select no_indext1)* a a fromt1
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_BNL(@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte` indexNULL idx_a 100100.0Using
explain extended
cte ((* (*from wherea<5
select /*+ no_index(t1@cte)*/ * from cte;
id select_type table type possible_keyssetoptimizer_switch ='off'
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 75 2 DERIVED t1 insert t1 select,,'java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 59 2 DERIVED t1 ALL NULL NULL NULL NULL 100analyze t1, persistentfor all;
Warnings:
as/ select# * /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ no_index(t1@cte) no_index(t1@dt1)*/ * from cte;
id select_type table type possible_keys#Table-evel 1 sjava.lang.StringIndexOutOfBoundsException: Range [33, 30) out of bounds for length 50 2 DERIVED t1 ALL NULL1PRIMARYd> NULL 10000. 2 DERIVED t1 ALL2DERIVED ALLidx_a, NULL 100100
Warnings: 1003withcte as(/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`cte`) NO_INDEX(`t1`@`dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
explain extended
cteas (count* t1,s* 5)java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
id select_type table type possible_keys java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 75 1 1 PRIMARY< ALL NULL 10000 . 2 DERIVED t1 range idx_ab idx_ab 5 NULL 3100.00 Using where; Using index 2 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5)/* select#1 */ select /*+ NO_INDEX(`t1`@`dt1` `idx_a`) NO_BNL(@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Ambiguity: multiple occurencies explain select/*+ no_bnl(@dt)*/ * from
explain extended
ith cte as select count(*) as cnt from t1, (select * from t1 where a < 5) dt1)
selectselect_type type keykey_len Extra
union
select * 1 PRIMARY <de> NULLNULL 10000100.
id select_type Lidx_ai NULL NULL NULL100100.00 1PRIMARY derived2> ALL NULL NULL NULL NULL 200100.00 Using where 2 DERIVED t1 range idx_a,idx_ab idx_a Note1003/* select#1 */ select /*+ NO_BNL(@`dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`
NULLidx_a 100100. Using index Usingjoin fjava.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95 4 UNION <derived5> ALL NULL NULL NULL NULL 200100.00 Using Warnings: 5 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2 where 5 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index; Using join buffer (flat, BNL join)
NULL UNION # Without the 'ange'index access be
Warnings:
Warning 4259 Query block name `cte(elect*from t1 wherea > 100and a < 120) as t1;
Note id table possible_keyskey ref filtered
# 1 PRIMARYderived2>ALL NULL2100.
explain extended
as( *)ast1 select* where 5)dt1)
select /*+ no_index(t1@cte1)*/ * from cte as cte1 where cnt > 10
union
select * from cte where cnt < 100;
id select_type table type possible_keys key key_len ref rows filtered 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200100.00 Using where
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 78 2 DERIVED t1 ALL NULL NULL java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 56 4 UNION <derived5> ALL NULL NULL NULL NULL 200100.00 Using where 5 DERIVED t1 range idx_a,idx_ab idx_a1PRIMARY <erived2> >ALLNULLNULL NULL . 5 DERIVEDt1index idx_a 510010000Using
Warnings:
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte1`) */ count(0) AS `cnt` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` < 5 having `cnt` > 10)/* select#1 */ select /*+ NO_INDEX(`t1`@`cte1`) */ `cte1`.`cnt` AS `cnt` from `cte` `cte1` where `cte1`.`cnt` > 10 union /* select#4 */ select `cte`.`cnt` AS `cnt` from `cte` where `cte`.`cnt` < 100
# ======================================
# views
create view v1 as select * from t1 1<>ALL NULL NULL310000 (, )
# Default execution plan
explain select*
from v1, v1 as v2 where v1.a = v2.a and v1.a < 3;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 t1 idx_a, idx_a 1100. Using condition 1 SIMPLE /* select#1 */ select /*+ NO_INDEX(`t1`@`t2` `idx_a`) INDEX(`t1`@`t1` `idx_ab`) */ `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c`,`t2`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`t1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 3) `t1` join (/* select#3 */ select /*+ QB_NAME(`t2`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 5) `t2`
Warnings:
Note 1003 select `test`.`t1`Note1003java.lang.StringIndexOutOfBoundsException: Index 484 out of bounds for length 484
explain extended
select /*+ index(t1@v1 idx_ab) no_index(t1@`v2`)*/ *
from v1, v1 as v2 where v1.a = v2.a and v1.a < 3;
id table possible_keys ref Extra 1 SIMPLE t1 range idx_ab idx_ab 5 NULL 2100.00 Using index condition 1 SIMPLE t1 ALL NULL NULL NULL NULL 10099.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select /*+ INDEX(`t1`@`v1` `idx_ab`) NO_INDEX(`t1`@`v2`) */ `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` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 and `test`.`t1`.`a` < 100 and `test`.`t1`.`a` < 100 java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 75
# Nested views
create
# Default execution plan java.lang.StringIndexOutOfBoundsException: Index 332 out of bounds for length 332
explain extended select * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1explain select /*+ no_index(t1@DT2)*/ * from
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
` a,`java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 156
# ana view
explain extended select /*+ index(t1@`v1` idx_ab)*/ * from v2;
id 1PRIMARY derived2>NULL NULL 200100. 1 SIMPLE t1 range idx_ab idx_ab 5 NULL derived3ALL NULL 210000
Warnings:
Note 1003 select /*+ INDEX(`t1`@`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` < 300 and `test`.`t1`.`a` < 100t1 ,idx_abidx_a 00Usingindex
java.lang.StringIndexOutOfBoundsException: Range [49, 6) out of bounds for length 58
# Unable to apply the hint to a view with UNION
explain extended select /*+ no_index(t1@v3) */ * from v3;
id select_type table # Explicit QB name overri one 1 < java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 56
DERIVED NULLNULL NULL NULL 100 .java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 3 UNION t2 ALL NULL 1 derived2 ALLNULLNULL 40010000java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
NULL 2 DERIVED 100 java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
Warnings:
Warning 4260 Implicit query block name `java.lang.StringIndexOutOfBoundsException: Range [0, 42) out of bounds for length 9
Note 1003/* select#1 */ select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# Ambiguity: view `v1` appears two times - should warn and ignore hint
explain select
(select a from v1 where b > 5 * wherea)
key rows Extra 1 SIMPLE t1 range idx_a,idx_ab idx_ab 5 NULL PRIMARYderived2 NULL NULL 400100. 1 SIMPLE t1 ALL idx_a,idx_ab NULL 2 idx_a 100 index
Warnings:
Warning 4259 Query 3DERIVEDt1NULL NULL400
Note 1003 select `test`.`t1`.`a`Note1003java.lang.StringIndexOutOfBoundsException: Index 375 out of bounds for length 375
# Implicit QB names are not supported inside views
create view v4 as select /*+ no_bnl(t2@dt)*/ * from
(select t1.* from t1, t2 where t1.a > t2.a) as dt;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
Warning 4242 explain extended select /*+ no_index(t1@t1)*/* from
show create view v4;
View Viewcharacter_set_clientcollation_connection
v4 CREATE ALGORITHM keykey_lenref filteredExtra
# However java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 56
create view v5 as select dt.a from
t1, (2 DERIVED NULL 510010000 ;joinbuffer(, java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
# Addressing a single table
explain extended select /*+ no_bnl(t2@dt) */* from v5;
id select_type Warning 4259 Query blockt1isambiguous 1 Note /* select#1 */ select `t1`.`count(*)` AS `count(*)` from (/* 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) `t1`) `t1` to derivedwith
t1,idx_ab test.a 10000Using index 1 SIMPLE t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note 1003 select /*+ NO_BNL(`t2`@`dt`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` > `test`.`t2`.`a`8
# Addressing:
explain extended select /*+ no_bnl(@dt) */* from v5;4260java.lang.StringIndexOutOfBoundsException: Index 150 out of bounds for length 150
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_a,idx_ab idx_a 5 NULL 100100.00 Using where; Using index 1 SIMPLE t1 ref idx_a,idx_ab idx_a 5 test.t1.a 1100.00 Using index 1 SIMPLE t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
`AS` `1``. `t2 .t1.=`````` `est.t.`> ``.t```
# Derived tables inside views can be addressed by their aliases
explain extended select /*+ no_bnl(t2@dt) */ * from v4;
_type java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 75
t1 i10010000 1 SIMPLE t2 3 UNION t2 ALL java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 55
Warnings:
Note 1003 select /*+ NO_BNL(`t2`@`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`t1is forderived views UNIONINTERSECTisfor hint
drop view v1, v2, v3, v4 v5;
# ======================================
# Not supported for DML, check presence of warnings
explain extended
update /*+ no_range_optimization(t1@dt)*/ t2,
s a where>10) set b=1 where t2.a = dt.a;
id select_type table type possible_keys key key_len ref(t1. .a t2 dt;
t2NULL 1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 9100.00 2 DERIVED 2DERIVEDt1idx_aidx_ab NULL 10010000
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
Warning 4220 Query block 1003java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 326
Note 1003java.lang.StringIndexOutOfBoundsException: Index 201 out of bounds for length 201
explain extended
delete /*+ no_index(t1@dt)*/ from t2
where t2.a in
(select * from (select a from t1 where a > 10) dt where dt.a > 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
hints 1 PRIMARY t1explain select/*+ merge(@dt)*/ * from
Warnings
Warning 4220 Query id select_type table type ref Extra 1003 from```` t`t` t`t1`` ``.t2`a `.```` > andtest`t2`` 10
# ======================================
unctions must java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 72
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 31
# Trigger with derived java.lang.StringIndexOutOfBoundsException: Index 297 out of bounds for length 297
create trigger tr1 before insert on t3
for each row
begin set new.b = (select (select * from (select t1 where>)dt1as dt;
(select a from t1 where a < new.a) dt);
end|
# Warning expected java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 58 /*+ no_index(t1@dt) */ max(a) from t3 where a<2;
id select_type table type possible_keys key key_len ref rows DERIVED t2 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join 1 Notejava.lang.StringIndexOutOfBoundsException: Index 386 out of bounds for length 386
Warnings:
Warning 4220 Query block name `dt` is not found for NO_INDEX hint
1003max)max(java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 63
# Stored function with select /*+ no_merge(dv) no_bnldt * (
create function get_max(p_a int) returns int returnselect /*+ no_merge(du) */ * from (
safromwhere <p_a))
# from where.a>a
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 69
id select_type table ); 1id key key_lenjava.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 75
:
Warning 4220 Query block name `dt` is 2 NULL10000
Note 1003 select `test3<>
drop function get_max;
table,t3java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
='=java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
create table t1 N * select#1 */ select /*+ NO_MERGE(`dt`@`select#3`) NO_MERGE(`du`@`select#2`) NO_MERGE(`dv`@`select#1`) NO_BNL(`t2`@`dt`) */ `dv`.`a` AS `a`,`dv`.`b` AS `b`,`dv`.`c` AS `c` from (/* select#2 */ select `du`.`a` AS `a`,`du`.`b` AS `b`,`du`.`c` AS `c` from (/* select#3 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#4 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`) `du`) `dv`explain
insert into t1 select seq, seq, 'filler' from seq_1_to_100;
create tablet2 select from t1;
analyze table t1,t2 persistent for all;
Warningsjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
.t1- collected
test.t1 analyze status Table is already up to java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 16
test.t2 analyze status Engine-independent (elect ()from ,(elect t1where 5 )
testt2 OK
# Table-level hint
explain extended select /*+ no_bnl(t2@dt)*/ * from
(select java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 56
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 75 1 PRIMARY <derived2> ALL NULL NULL2DERIVEDt1indexNULL5 100.0
t1 idx_ai NULLNULL100. 2 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings: /* select#1 */ select /*+ NO_BNL(`t2`@`dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`
# More than one reference to a single QB
explain extended select /*+ no_bnl(t2@dt) no_index(t1@dt)*/ * from
(select t1.* from t1, t2 where t1.a > t2.a) as dt;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 10000100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 100100.00 2 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note1PRIMARY <>ALL NULL NULL 200100.00
# QB-level hint
explain extended select /*+ no_bnl(@dt)*/ * from
(select t1.* from t12 DERIVEDt1 index NULL 5 NULL 10000 index
table type possible_keys ref filteredExtra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 10000100.00 2 t1 idx_aidx_ab NULL 100100. 2 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note1003/* select#1 */ select /*+ NO_BNL(@`dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`
# Index-level hints
# select_type table type possible_keys key key_len ref rows filtered Extra
explain extended select /*+ no_index(t1@`T`)*/ * from
( fromt1where a<3)t;
id select_type table type possible_keys key key_len ref rows filtered Extra
derived2 ALL NULL 2100.java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 2 DERIVED t1 ALL NULL NULL NULL NULL 1002.00 Using where
Warnings: 1003java.lang.StringIndexOutOfBoundsException: Index 267 out of bounds for length 267
# Without the hint 'range' index access would be chosen
explain extended select /*+ no_range_optimization(t1@t1)*/ * from
(select * from t1 where a > 100and a < 120) as t1;
id select_type table type possible_keys explain 1 PRIMARY <derived2> ALLwithcte (elect()from t1 ( * a<5 dt1java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 2 DERIVED t1 ALL idx_a,idx_ab 1PRIMARYd>ALL NULLNULL40010000java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
Warnings:
1003 1/ *+ NO_RANGE_OPTIMIZATION(`t1`@`t1`) */ `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`t1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` > 100 and `test`.`t1`.`a` < 120) `t1`
# Regular and derived tables sharesame butthe isapplied correctly
explain extended select /*+ index(t1@t1 idx_ab)*/ * from
(select * from t1 where a < 3) as t1;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2100.00 2 DERIVED t1 range idx_ab idx_ab 5 NULL 2100.00 Usingselect /*+ no_index(t1@dt1 idx_a) no_bnl(@cte)*/ * from cte;
Warnings:
Note 1003/* select#1 */ select /*+ INDEX(`t1`@`t1` `idx_ab`) */ `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`t1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 3) `t1` .
explain extended select + no_index(1t2idx_a index(t1@1 idx_ab* *from
(select * from t1 where a < 3) as t1, (select * from java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
id select_type table type possible_keys key key_len ref rows filtered 3 idx_ab 3100.indexcondition 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2100.00 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 3100.00 Using buffer flat,BNLjoinjava.lang.StringIndexOutOfBoundsException: Index 88 out of bounds for length 88 3 DERIVED t1 range idx_ab idx_ab 5 NULL 3100.00 Using index condition 2 DERIVED t1 range s() ,s* where
Warnings:
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
java.lang.StringIndexOutOfBoundsException: Range [16, 7) out of bounds for length 66
(select * from t1 where a < 3) as t1, (select * from t1 where a < 5) as t2;
id 1 derived2 NULL NULL20000Using 1 PRIMARY2DERIVED derived3> ALL NULL NULL NULL NULL 2100.00 1 PRIMARY <derived3> ALL NULL NULL NULL 2 DERIVED t1 NULL idx_a NULL . index; Using join buffer (flat, BNL join) 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 65 2 DERIVED t1 ALL NULL NULL NULL NULL 1002.00 Using where
Warnings:
Note 1003/* select#1 */ select /*+ NO_INDEX(`t1`@`t1` `idx_a`,`idx_ab`) */ `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c`,`t2`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`t1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 3) `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) `t2`:
# Nested derived tables
explain extended select /*+ no_bnl(t1@dt2)*/ * from
(select count(*) from t1, (select * from t1 where a < 5) dt1) as dt2;
# However, CTE occurencies ,thebe applied 1 PRIMARY <derived2> ALL NULL 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00
t1 index idx_a5100. 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition
Warnings:
Note 1003/* select#1 */ select /*+ NO_BNL(`t1`@`dt2`) */ `dt2`.`count(*)` AS `count(*)` from (/* select#2 */ select /*+ QB_NAME(`dt2`) */ 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`) `dt2`
explain extended select /*+ no_index(t1@DT2)*/ * from
(select count)from select * from t1 where a < 5) dt1) as dt2;
id select_type table type 3 DERIVED t1 range idx_a,idx_ab idx_a100.00Usingindex 1 PRIMARY <4 <>ALLNULL java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 65 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 100100.00 Using join buffer (flat, BNL join) 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition
Warnings:
Note 1003/* select#1 */ select /*+ NO_INDEX(`t1`@`DT2`) */ `dt2`.`count(*)` AS `count(*)` from (/* select#2 */ select /*+ QB_NAME(`DT2`) */ 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`) `dt2`
# Explicit QB name overrides the implicit one
explain extended select /*+ no_index(t1@dt2)*/ * from
select* t1(/*+ qb_name(dt2)*/ * from t1 where a < 5) dt1) as dt2;
id select_type table type# 1 PRIMARY <derived2 * t1 where <100; 2 DERIVED <derived3> ALL NULL NULL NULL NULL 4100.00
NULL5NULL100. ;Using (,BNLjoinjava.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
ULL 1004.0
Warnings:
Note 10031 SIMPLE refidx_a,idx_ab 5 test.1. 1100.00
# Both hints are applied
explainselect/
(select count(*) from t1, (select * from t1 where a < 5) explainextended
id select_type table type possible_keys key key_len ref rows filtered select *+ index(t1@v1 idx_ab) no_index(t1@`v2`)*/ * 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 400100.00
ved3 ALL NULL NULLNULL 4100.00 2 DERIVED t1 index NULL idx_a java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 69 3 DERIVED t1 ALL 1 SIMPLE t1 ALL NULLNULL 100 99.where; Using join buffer (flat, BNL join)
Warnings:
Note1003
# Nested derived tables with ambiguous names, hintisignored
explain extended select /*+ no_index(t1@t1)*/* from
(select count(*) from t1, (select * from t1 where a < 5) t1) as t1;
id select_type # views 1 PRIMARY <derived2> ALL NULLcreate view as * where <300; 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00 2DERIVEDt1NULL 5 NULL100 . index; Using join buffer (flat, BNL join) 3 DERIVED t1 range idx_a,idx_ab idx_a 5 1 SIMPLE t1 ALL idx_a,idx_ab NULL NULL NULL where
Warnings:
Warnings:
Note 1003/* select#1 */ select `t1`.`count(*)` AS `count(*)` from (/* 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) `t1`) `t1`c test`1wheretest.t1`a`< ``.`
# The hint cannot be applied to a derived table with UNION
explain extended select /*+ no_index(t2@t1)*/* from
(select * from t1 wherejava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
id select_type tabletype possible_keys key refrowsExtra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9100.00 2 DERIVEDt1 idx_a, idx_a NULL1 . index 3 UNION t2 ALL NULL NULL NULL NULL 1008.00 Using where
java.lang.StringIndexOutOfBoundsException: Range [57, 23) out of bounds for length 57
Warnings: 1derived2 NULLNULLNULL20010000
Note NULL 100100.00java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
explain extended select /*+ no_index(t1@t1)*/* from
(elect*fromwherea< select t2where )as ;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9100.00
condition 3 UNION t2 ALL NULL NULL NULL NULL 1008.00 Using where
NULL UNION RESULT <union2,3>Note1003/* select#1 */ select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
:
Warning 4260 Implicitextended select
Note 1003/* select#1 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`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` < 3 union /* select#3 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where `test`.`t2`.`a` < 9) `t1`
# Test INSERT..SELECT
explain extended insert into t2 2 DERIVED t1 range idx_a,idx_ab idx_ab 9990Usingwhere
(select t1.* from t1, t2Warnings
id select_type table type Warning4259Query v1 ambiguousfor hint 1 Note 1003 2DERIVEDt1ALLidx_a,NULLNULL100100. 2DERIVEDt2ALLNULLNULLNULLNULL100100.00Usingwhere Warnings:
Note 1003 insert into `test`.`t2` /* select#1 */ select /*+ NO_BNL(`t2`@`dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt` View character_set_client collation_connection
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 31
explain extended select /*+ merge(@dt)*/ * from
( from(java.lang.StringIndexOutOfBoundsException: Range [37, 22) out of bounds for length 73
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL,. t1 .a d.; 2 DERIVED t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00
id table key_lenref filtered Extra
Warnings:
Note /* select#1 */ select /*+ MERGE(@`dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#2 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`
explain extended select /*+ no_merge(@dt)*/ * from3 t1 idx_ai NULL 100100.00java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
( *( t1.*t1,t2 t1.>t2a )asdt
id select_type table type possible_keys key key_len refNote1003/ 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 10000100.00 2 DERIVED <derived3> ALL NULL NULL NULL NULL 10000100.00 3 DERIVED t1 java.lang.StringIndexOutOfBoundsException: Range [23, 16) out of bounds for length 52 3 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
RGE@dt)* dt```ASa,```AS```t.cAS`` /java.lang.StringIndexOutOfBoundsException: Index 386 out of bounds for length 386
# Multiple levels of nested derived tables, all hints are applied
explain extended
select /*+ no_merge(dv) no_bnl(t2@dt) */ * from (
select /*+ no_merge(du) */ * from (
select /*+ no_merge(dt) */ * from (
select t1.* from t1, t2 where t1.a > t2.a
) dt
) du
) dv;
id Note 1003 /* s1* /*+ NO_BNL(@`dt`) */ `dt`.`a` AS `a` 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` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt` where `dt`.`a` = `test`.`t1`.`a` 1 <>ALLNULL NULL java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 58 2 DERIVED1PRIMARYderived3 ALLNULLNULL10000100. 3 DERIVED <derived4> ALL NULL NULL NULL NULL 10000100.00 4 DERIVED t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00 4 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
WarningsWarnings
Note 1003/* select#1 */ select /*+ NO_MERGE(`dt`@`select#3`) NO_MERGE(`du`@`select#2`) NO_MERGE(`dv`@`select#1`) NO_BNL(`t2`@`dt`) */ `dv`.`a` AS `a`,`dv`.`b` AS `b`,`dv`.`c` AS `c` from (/* select#2 */ select `du`.`a` AS `a`,`du`.`b` AS `b`,`du`.`c` AS `c` from (/* select#3 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#4 */ select /*+ QB_NAME(`dt`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`) `du`) `dv`DML of
# ===================rangeidx_abidx_ab5 . where
# Test CTEs
# By default BNL and index access to t1 are used.
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 explain 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200100.00 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.(select * from (select a from t1 where a > 10) dt where dt.a > 20);
java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 95 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition
Warnings:
DERIVED range,idx_ab 84.Using where
explain extended
with cte as (select count(*) from t1, (select * from t1 where Warning 4220 Query block name `dt` is not found for NO_INDEX hint /*+ no_bnl(t1@cte)*/ * from cte;
select_type java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 75 1 PRIMARY <derived2 storedfunctions hints 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00 2 DERIVED#Trigger 3 DERIVED t1 range idx_a,createtrigger insert t3
Warnings:
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
with cte as (select count(*) from t1, (select * from t1 (electfromt1 a < new dt)
select /*+ no_bnl(@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 200100.00 2DERIVED<erived3> NULL 2100. 2 1 SIMPLENULLNULLNULLNULL java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 100 3 DERIVED t1 rangeWarningsjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`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_BNL(@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
with cte as (select count expected
select /*+ no_index(t1@cte)*/ * from cte;/*+ no_index(t1@dt) */ a, get_max(a) from t1;
id select_type table type possible_keys .Using 1 PRIMARY <derived2> ALL java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 9 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00
) 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`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`@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ no_index(t1@cte) no_index(t1@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 400100.00 2 DERIVED <derived3> ALL NULL NULL NULL NULL 4100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 100100.00 Using join buffer (flat, BNL join) 3 DERIVED t1 ALL NULL NULL NULL NULL 1004.00 Using where
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select /*+ QB_NAME(`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`@`cte`) NO_INDEX(`t1`@`dt1`) */ `cte`.`count(*)` AS `count(*)` from `cte`
explain extended
with cte as (select count(*) from t1, (select * from t1 where a < 5) dt1)
select /*+ no_index(t1@dt1 idx_a) no_bnl(@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 300100.00 2 DERIVED <derived3> ALL NULL NULL NULL NULL 3100.00 2 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index 3 DERIVED t1 range idx_ab idx_ab 5 NULL 3100.00 Using index condition
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte`) */ count(0) AS `count(*)` from `test`.`t1` join (/* select#3 */ select /*+ QB_NAME(`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`@`dt1` `idx_a`) NO_BNL(@`cte`) */ `cte`.`count(*)` AS `count(*)` from `cte`
# Ambiguity: multiple occurencies of `cte`, the hint is ignored
explain extended
with cte as (select count(*) as cnt from t1, (select * from t1 where a < 5) dt1)
select /*+ no_bnl(@cte)*/ * from cte where cnt > 10
union
select * from cte where cnt < 100;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200100.00 Using where 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00 2 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index; Using join buffer (flat, BNL join) 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition 4 UNION <derived5> ALL NULL NULL NULL NULL 200100.00 Using where 5 DERIVED <derived6> ALL NULL NULL NULL NULL 2100.00 5 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index; Using join buffer (flat, BNL join) 6 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition
NULL UNION RESULT <union1,4> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Warning 4259 Query block name `cte` is ambiguous for NO_BNL hint
Note 1003 with cte as (/* select#2 */ select count(0) AS `cnt` 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` having `cnt` > 10)/* select#1 */ select `cte`.`cnt` AS `cnt` from `cte` where `cte`.`cnt` > 10 union /* select#4 */ select `cte`.`cnt` AS `cnt` from `cte` where `cte`.`cnt` < 100
# However, if CTE occurencies have different aliases, the hint can be applied
explain extended
with cte as (select count(*) as cnt from t1, (select * from t1 where a < 5) dt1)
select /*+ no_index(t1@cte1)*/ * from cte as cte1 where cnt > 10
union
select * from cte where cnt < 100;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 200100.00 Using where 2 DERIVED <derived3> ALL NULL NULL NULL NULL 2100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 100100.00 Using join buffer (flat, BNL join) 3 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition 4 UNION <derived5> ALL NULL NULL NULL NULL 200100.00 Using where 5 DERIVED <derived6> ALL NULL NULL NULL NULL 2100.00 5 DERIVED t1 index NULL idx_a 5 NULL 100100.00 Using index; Using join buffer (flat, BNL join) 6 DERIVED t1 range idx_a,idx_ab idx_a 5 NULL 2100.00 Using index condition
NULL UNION RESULT <union1,4> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Note 1003 with cte as (/* select#2 */ select /*+ QB_NAME(`cte1`) */ count(0) AS `cnt` 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` having `cnt` > 10)/* select#1 */ select /*+ NO_INDEX(`t1`@`cte1`) */ `cte1`.`cnt` AS `cnt` from `cte` `cte1` where `cte1`.`cnt` > 10 union /* select#4 */ select `cte`.`cnt` AS `cnt` from `cte` where `cte`.`cnt` < 100
# ======================================
# Test views
create view v1 as select * from t1 where a < 100;
# Default execution plan
explain extended select *
from v1, v1 as v2 where v1.a = v2.a and v1.a < 3;
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 1100.00 Using index condition 1 SIMPLE t1 ref idx_a,idx_ab idx_a 5 test.t1.a 1100.00
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` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3and `test`.`t1`.`a` < 100and `test`.`t1`.`a` < 100
explain extended
select /*+ index(t1@v1 idx_ab) no_index(t1@`v2`)*/ *
from v1, v1 as v2 where v1.a = v2.a and v1.a < 3;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range idx_ab idx_ab 5 NULL 2100.00 Using index condition 1 SIMPLE t1 ALL NULL NULL NULL NULL 10099.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select /*+ INDEX(`t1`@`v1` `idx_ab`) NO_INDEX(`t1`@`v2`) */ `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` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 and `test`.`t1`.`a` < 100 and `test`.`t1`.`a` < 100
# Nested views
create view v2 as select * from v1 where a < 300;
# Default execution plan
explain extended select * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL idx_a,idx_ab NULL NULL NULL 10094.00 Using where
Warnings:
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` < 300and `test`.`t1`.`a` < 100
# Addressing an object inside a nested view
explain extended select /*+ index(t1@`v1` idx_ab)*/ * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range idx_ab idx_ab 5 NULL 99100.00 Using index condition
Warnings:
Note 1003 select /*+ INDEX(`t1`@`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` < 300 and `test`.`t1`.`a` < 100
create view v3 as select * from t1 union select * from t2;
# Unable to apply the hint to a view with UNION
explain extended select /*+ no_index(t1@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 200100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 100100.00 3 UNION t2 ALL NULL NULL NULL NULL 100100.00
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Warning 4260 Implicit query block name `v3` is not supported for derived tables and views with UNION/EXCEPT/INTERSECT and is ignored for NO_INDEX hint
Note 1003/* select#1 */ select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
# Ambiguity: view `v1` appears two times - should warn and ignore hint
explain extended select /*+ index(t2@v1) */ * from v1,
(select a from v1 where b > 5) dt;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL idx_a,idx_ab NULL NULL NULL 10094.00 Using where 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 99100.00 Using join buffer (flat, BNL join) 2 DERIVED t1 range idx_a,idx_ab idx_ab 5 NULL 9990.20 Using where; Using index
Warnings:
Warning 4259 Query block name `v1` is ambiguous for INDEX hint
Note 1003/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`dt`.`a` AS `a` from `test`.`t1` join (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` > 5 and `test`.`t1`.`a` < 100) `dt` where `test`.`t1`.`a` < 100
# Implicit QB names are not supported inside views
create view v4 as select /*+ no_bnl(t2@dt)*/ * from
(select t1.* from t1, t2 where t1.a > t2.a) as dt;
Warnings:
Warning 4242 Implicit query block names are ignored for hints specified within VIEWs
show create view v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from (`t1` join `t2`) where `t1`.`a` > `t2`.`a`) `dt` latin1 latin1_swedish_ci
# However, a derived table inside a view can be addressed from outer query
create view v5 as select dt.a from
t1, (select t1.* from t1, t2 where t1.a > t2.a) as dt where t1.a=dt.a;
# Addressing a single table
explain extended select /*+ no_bnl(t2@dt) */* from v5;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index idx_a,idx_ab idx_a 5 NULL 100100.00 Using where; Using index 1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 100100.00 3 DERIVED t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00 3 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note 1003/* select#1 */ select /*+ NO_BNL(`t2`@`dt`) */ `dt`.`a` AS `a` 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` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt` where `dt`.`a` = `test`.`t1`.`a`
# Addressing the whole derived table
explain extended select /*+ no_bnl(@dt) */* from v5;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index idx_a,idx_ab idx_a 5 NULL 100100.00 Using where; Using index 1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 100100.00 3 DERIVED t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00 3 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note 1003/* select#1 */ select /*+ NO_BNL(@`dt`) */ `dt`.`a` AS `a` 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` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt` where `dt`.`a` = `test`.`t1`.`a`
# Derived tables inside views can be addressed by their aliases
explain extended select /*+ no_bnl(t2@dt) */ * from v4;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 10000100.00 3 DERIVED t1 ALL idx_a,idx_ab NULL NULL NULL 100100.00 3 DERIVED t2 ALL NULL NULL NULL NULL 100100.00 Using where
Warnings:
Note 1003/* select#1 */ select /*+ NO_BNL(`t2`@`dt`) */ `dt`.`a` AS `a`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` > `test`.`t2`.`a`) `dt`
drop view v1, v2, v3, v4, v5;
# ======================================
# Not supported for DML, check presence of warnings
explain extended
update /*+ no_range_optimization(t1@dt)*/ t2,
(select a from t1 where a > 10) dt set b=1 where t2.a = dt.a;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 100100.00 Using where 1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 9100.00 2 DERIVED t1 range idx_a,idx_ab idx_ab 5 NULL 92100.00 Using where; Using index
Warnings:
Warning 4220 Query block name `dt` is not found for NO_RANGE_OPTIMIZATION hint
Note 1003/* select#1 */ update `test`.`t2` join (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 10) `dt` set `test`.`t2`.`b` = 1 where `dt`.`a` = `test`.`t2`.`a`
explain extended
delete /*+ no_index(t1@dt)*/ from t2
where t2.a in
(select * from (select a from t1 where a > 10) dt where dt.a > 20);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 10080.00 Using where 1 PRIMARY <derived3> eq_ref distinct_key distinct_key 5 test.t2.a 1100.00 3 DERIVED t1 range idx_a,idx_ab idx_ab 5 NULL 84100.00 Using where; Using index
Warnings:
Warning 4220 Query block name `dt` is not found for NO_INDEX hint
Note 1003/* select#1 */ delete from `test`.`t2` using (/* select#3 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 10 and `test`.`t1`.`a` > 20) `dt` where `dt`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` > 20
# ======================================
# Objects in triggers and stored functions must not be visible for hints
create table t3 (a int, b int);
# Trigger with derived table inside
create trigger tr1 before insert on t3
for each row
begin set new.b = (select max(a) from
(select a from t1 where a < new.a) dt);
end|
# Warning expected
explain extended select /*+ no_index(t1@dt) */ max(a) from t3 where a<2;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Warning 4220 Query block name `dt` is not found for NO_INDEX hint
Note 1003 select max(NULL) AS `max(a)` from `test`.`t3` where 0
# Stored function with derived table inside
create function get_max(p_a int) returns int return (select max(a) from
(select a from t1 where a < p_a) dt);
# Warning expected
explain extended select /*+ no_index(t1@dt) */ a, get_max(a) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL idx_a 5 NULL 100100.00 Using index
Warnings:
Warning 4220 Query block name `dt` is not found for NO_INDEX hint
Note 1003 select `test`.`t1`.`a` AS `a`,`get_max`(`test`.`t1`.`a`) AS `get_max(a)` from `test`.`t1`
drop function get_max;
drop table t1, t2, t3; set optimizer_switch = default;
Messung V0.5 in Prozent
¤ 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.0.30Bemerkung:
¤
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.