From c4fe794d22d5dfd23fabfcf0bc45d974621e0cc8 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sun, 8 Dec 2024 22:03:01 +0200 Subject: [PATCH] MDEV-33281 Optimizer hints code cleanup: - remove get_args_printer() from hints printing - add append_hint_arguments(THD *thd, opt_hints_enum hint, String *str) - add more comments - rename st_opt_hint_info::hint_name to hint_type - add pptimizer trace support for hints - add dbug_print_hints() - make print_warn() not be a template - introduce Printable_parser_rule interface, make grammar rules that emit warnings implement it and print_warn invokes its function) - remove Parser::Hint::append_args() as it is not used anywhere (it used to be necessary call print_warn(... (Parser::Hint*)NULL); --- mysql-test/main/lowercase_table.result | 2 +- mysql-test/main/opt_hint_timeout.result | 4 +- mysql-test/main/opt_hints.result | 76 ++++++++--------- mysql-test/main/opt_hints_subquery.result | 88 ++++++++++---------- sql/opt_hints.cc | 68 +++++++++++----- sql/opt_hints.h | 99 +++++++++++++---------- sql/opt_hints_parser.cc | 2 +- sql/opt_hints_parser.h | 33 ++++---- sql/sql_lex.h | 9 ++- sql/sql_select.cc | 3 + 10 files changed, 216 insertions(+), 168 deletions(-) diff --git a/mysql-test/main/lowercase_table.result b/mysql-test/main/lowercase_table.result index cff321b4eee..add0fd1f3a6 100644 --- a/mysql-test/main/lowercase_table.result +++ b/mysql-test/main/lowercase_table.result @@ -230,7 +230,7 @@ a 1 2 Warnings: -Warning 4206 Hint BKA("A") is ignored as conflicting/duplicated +Warning 4207 Hint BKA("A") is ignored as conflicting/duplicated DROP TABLE t1; # # End of 11.7 tests diff --git a/mysql-test/main/opt_hint_timeout.result b/mysql-test/main/opt_hint_timeout.result index 52dc74c3518..7bc1d73a3e5 100644 --- a/mysql-test/main/opt_hint_timeout.result +++ b/mysql-test/main/opt_hint_timeout.result @@ -49,7 +49,7 @@ SELECT /*+ MAX_EXECUTION_TIME(10) MAX_EXECUTION_TIME(100) */ count(*) FROM t1; count(*) 512 Warnings: -Warning 4206 Hint MAX_EXECUTION_TIME(100) is ignored as conflicting/duplicated +Warning 4207 Hint MAX_EXECUTION_TIME(100) is ignored as conflicting/duplicated # Wrong values SELECT /*+ MAX_EXECUTION_TIME(0) */ count(*) FROM t1; count(*) @@ -102,7 +102,7 @@ SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1; count(*) 512 Warnings: -Warning 4206 Hint MAX_EXECUTION_TIME(30) is ignored as conflicting/duplicated +Warning 4207 Hint MAX_EXECUTION_TIME(30) is ignored as conflicting/duplicated SELECT count(*) FROM t1 UNION SELECT /*+ MAX_EXECUTION_TIME(30) */ count(*) FROM t1; diff --git a/mysql-test/main/opt_hints.result b/mysql-test/main/opt_hints.result index 28fd0382dab..c5abba7fe04 100644 --- a/mysql-test/main/opt_hints.result +++ b/mysql-test/main/opt_hints.result @@ -15,25 +15,25 @@ a 1 2 Warnings: -Warning 4209 Unresolved index name `t1`@`select#1` `idx_å` for NO_MRR hint +Warning 4210 Unresolved index name `t1`@`select#1` `idx_å` for NO_MRR hint SELECT /*+ NO_MRR(t1 idx_a, idx_å, idx_A) */ a FROM t1; a 1 2 Warnings: -Warning 4206 Hint NO_MRR(`t1` `idx_A`) is ignored as conflicting/duplicated -Warning 4209 Unresolved index name `t1`@`select#1` `idx_å` for NO_MRR hint +Warning 4207 Hint NO_MRR(`t1` `idx_A`) is ignored as conflicting/duplicated +Warning 4210 Unresolved index name `t1`@`select#1` `idx_å` for NO_MRR hint DROP TABLE t1; # Testing that query block names are accent sensitive case insensitive CREATE TABLE t1 (a INT); SELECT /*+ QB_NAME(a) BKA(t1@a) BKA(t1@A) */ * FROM t1; a Warnings: -Warning 4206 Hint BKA(`t1`@`A`) is ignored as conflicting/duplicated +Warning 4207 Hint BKA(`t1`@`A`) is ignored as conflicting/duplicated SELECT /*+ QB_NAME(a) BKA(t1@a) BKA(t1@å) */ * FROM t1; a Warnings: -Warning 4207 Query block name `å` is not found for BKA hint +Warning 4208 Query block name `å` is not found for BKA hint DROP TABLE t1; CREATE TABLE t1(f1 INT, f2 INT); INSERT INTO t1 VALUES @@ -230,7 +230,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00 1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join) Warnings: -Warning 4209 Unresolved index name `t5`@`select#2` `z_idx` for NO_ICP hint +Warning 4210 Unresolved index name `t5`@`select#2` `z_idx` for NO_ICP hint Note 1003 select /*+ NO_ICP(`t5`@`select#2` `y_idx`) NO_ICP(`t5`@`select#2` `x_idx`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and (8 + 0) # ICP should still be used EXPLAIN EXTENDED SELECT * FROM @@ -548,7 +548,7 @@ EXPLAIN EXTENDED SELECT /*+ QB_NAME(qb1) QB_NAME(qb1 ) */ * FROM t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 28 100.00 Warnings: -Warning 4206 Hint QB_NAME(`qb1`) is ignored as conflicting/duplicated +Warning 4207 Hint QB_NAME(`qb1`) is ignored as conflicting/duplicated Note 1003 select /*+ QB_NAME(`qb1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t2` # Should issue warning EXPLAIN EXTENDED SELECT /*+ BKA(@qb1) QB_NAME(qb1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 @@ -557,7 +557,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 1 SIMPLE t2 ALL f1 NULL NULL NULL 28 25.00 Using where; Using join buffer (flat, BNL join) Warnings: -Warning 4207 Query block name `qb1` is not found for BKA hint +Warning 4208 Query block name `qb1` is not found for BKA hint Note 1003 select /*+ QB_NAME(`qb1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`f1` = `test`.`t1`.`f1` and `test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2` and `test`.`t2`.`f2` + 1 >= `test`.`t1`.`f1` + 1 # Should not crash PREPARE stmt1 FROM "SELECT /*+ BKA(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 @@ -601,9 +601,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 1 SIMPLE t2 ALL f1 NULL NULL NULL 28 25.00 Using where; Using join buffer (flat, BNL join) Warnings: -Warning 4208 Unresolved table name `t3`@`select#1` for BKA hint -Warning 4208 Unresolved table name `t3`@`select#1` for NO_RANGE_OPTIMIZATION hint -Warning 4209 Unresolved index name `t3`@`select#1` `idx1` for NO_RANGE_OPTIMIZATION hint +Warning 4209 Unresolved table name `t3`@`select#1` for BKA hint +Warning 4209 Unresolved table name `t3`@`select#1` for NO_RANGE_OPTIMIZATION hint +Warning 4210 Unresolved index name `t3`@`select#1` `idx1` for NO_RANGE_OPTIMIZATION hint Note 1003 select /*+ BKA(`t2`@`select#1`) NO_BNL(`t1`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`f1` = `test`.`t1`.`f1` and `test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2` and `test`.`t2`.`f2` + 1 >= `test`.`t1`.`f1` + 1 # Check illegal syntax EXPLAIN EXTENDED SELECT /*+ BKA(qb1 t3@qb1) */ f2 FROM @@ -640,7 +640,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tbl12 ALL NULL NULL NULL NULL 10 100.00 Using where 1 SIMPLE tbl13 hash_ALL a #hash#a 5 test.tbl12.a 1000 0.10 Using where; Using join buffer (flat, BNLH join) Warnings: -Warning 4208 Unresolved table name `tbl2`@`select#1` for BKA hint +Warning 4209 Unresolved table name `tbl2`@`select#1` for BKA hint Note 1003 select `test`.`tbl12`.`a` AS `a`,`test`.`tbl12`.`b` AS `b`,`test`.`tbl13`.`a` AS `a`,`test`.`tbl13`.`b` AS `b`,`test`.`tbl13`.`c` AS `c`,`test`.`tbl13`.`filler` AS `filler` from `test`.`t12` `tbl12` join `test`.`t13` `tbl13` where `test`.`tbl13`.`a` = `test`.`tbl12`.`a` and `test`.`tbl13`.`b` + 1 <= `test`.`tbl13`.`b` + 1 # Check that PS and conventional statements give the same result. FLUSH STATUS; @@ -1476,19 +1476,19 @@ SELECT /*+ BKA() BKA() */ 1; 1 1 Warnings: -Warning 4206 Hint BKA() is ignored as conflicting/duplicated +Warning 4207 Hint BKA() is ignored as conflicting/duplicated SELECT /*+ BKA(t1) BKA(t1) */ * FROM t1; i Warnings: -Warning 4206 Hint BKA(`t1`) is ignored as conflicting/duplicated +Warning 4207 Hint BKA(`t1`) is ignored as conflicting/duplicated SELECT /*+ QB_NAME(q1) BKA(t1@q1) BKA(t1@q1) */ * FROM t1; i Warnings: -Warning 4206 Hint BKA(`t1`@`q1`) is ignored as conflicting/duplicated +Warning 4207 Hint BKA(`t1`@`q1`) is ignored as conflicting/duplicated SELECT /*+ QB_NAME(q1) NO_ICP(@q1 t1 PRIMARY) NO_ICP(@q1 t1 PRIMARY) */ * FROM t1; i Warnings: -Warning 4206 Hint NO_ICP(`t1`@`q1` `PRIMARY`) is ignored as conflicting/duplicated +Warning 4207 Hint NO_ICP(`t1`@`q1` `PRIMARY`) is ignored as conflicting/duplicated DROP TABLE t1; # # Hints inside views are not supported @@ -1497,7 +1497,7 @@ CREATE TABLE t1 (a INT, INDEX idx_a(a)); INSERT INTO t1 VALUES (1),(2); CREATE VIEW v1 AS SELECT /*+ NO_MRR(t1 idx_a) */ a FROM t1; Warnings: -Warning 4210 Optimizer hints are not supported inside view definitions +Warning 4211 Optimizer hints are not supported inside view definitions SELECT * FROM v1; a 1 @@ -1513,13 +1513,13 @@ Warnings: Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` CREATE OR REPLACE VIEW v1 AS SELECT /*+ NO_MRR(t1 idx_a) BKA(t1)*/ a FROM t1; Warnings: -Warning 4210 Optimizer hints are not supported inside view definitions +Warning 4211 Optimizer hints are not supported inside view definitions SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8mb4 utf8mb4_uca1400_ai_ci ALTER VIEW v1 AS SELECT /*+ QB_NAME(q1)*/ a FROM t1; Warnings: -Warning 4210 Optimizer hints are not supported inside view definitions +Warning 4211 Optimizer hints are not supported inside view definitions SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8mb4 utf8mb4_uca1400_ai_ci @@ -1686,15 +1686,15 @@ Warning 1064 Optimizer hint syntax error near 'b) */ 1 FROM t1 a, t1 b' at lin SELECT /*+ NO_ICP(i1) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `i1`@`select#1` for NO_ICP hint +Warning 4209 Unresolved table name `i1`@`select#1` for NO_ICP hint SELECT /*+ NO_ICP(i1 i2) */ 1 FROM t1; 1 Warnings: -Warning 4209 Unresolved index name `i1`@`select#1` `i2` for NO_ICP hint +Warning 4210 Unresolved index name `i1`@`select#1` `i2` for NO_ICP hint SELECT /*+ NO_ICP(@qb ident) */ 1 FROM t1; 1 Warnings: -Warning 4207 Query block name `qb` is not found for NO_ICP hint +Warning 4208 Query block name `qb` is not found for NO_ICP hint # valid hint sequences, no warnings expected: @@ -1749,49 +1749,49 @@ CREATE INDEX 3rd_index ON t1(i, j); SELECT /*+ NO_ICP(3rd_index) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `3rd_index`@`select#1` for NO_ICP hint +Warning 4209 Unresolved table name `3rd_index`@`select#1` for NO_ICP hint CREATE INDEX $index ON t1(j, i); SELECT /*+ NO_ICP($index) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `$index`@`select#1` for NO_ICP hint +Warning 4209 Unresolved table name `$index`@`select#1` for NO_ICP hint CREATE TABLE ` quoted name test` (i INT); SELECT /*+ BKA(` quoted name test`) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name ` quoted name test`@`select#1` for BKA hint +Warning 4209 Unresolved table name ` quoted name test`@`select#1` for BKA hint SELECT /*+ BKA(` quoted name test`@`select#1`) */ 1 FROM t1; 1 Warnings: -Warning 4207 Query block name `select#1` is not found for BKA hint +Warning 4208 Query block name `select#1` is not found for BKA hint DROP TABLE ` quoted name test`; SET SQL_MODE = 'ANSI_QUOTES'; CREATE TABLE " quoted name test" (i INT); SELECT /*+ BKA(" quoted name test") */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name " quoted name test"@"select#1" for BKA hint +Warning 4209 Unresolved table name " quoted name test"@"select#1" for BKA hint SELECT /*+ BKA(" quoted name test"@"select#1") */ 1 FROM t1; 1 Warnings: -Warning 4207 Query block name "select#1" is not found for BKA hint +Warning 4208 Query block name "select#1" is not found for BKA hint CREATE TABLE `test1``test2``` (i INT); SELECT /*+ BKA(`test1``test2```) */ 1; 1 1 Warnings: -Warning 4208 Unresolved table name "test1`test2`"@"select#1" for BKA hint +Warning 4209 Unresolved table name "test1`test2`"@"select#1" for BKA hint SELECT /*+ BKA("test1""test2""") */ 1; 1 1 Warnings: -Warning 4208 Unresolved table name "test1""test2"""@"select#1" for BKA hint +Warning 4209 Unresolved table name "test1""test2"""@"select#1" for BKA hint SET SQL_MODE = ''; # should warn: SELECT /*+ BKA(" quoted name test") */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name ` quoted name test`@`select#1` for BKA hint +Warning 4209 Unresolved table name ` quoted name test`@`select#1` for BKA hint DROP TABLE ` quoted name test`; DROP TABLE `test1``test2```; # Valid hints, no warning: @@ -1843,29 +1843,29 @@ CREATE TABLE tableТ (i INT); SELECT /*+ BKA(tableТ) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `tableТ`@`select#1` for BKA hint +Warning 4209 Unresolved table name `tableТ`@`select#1` for BKA hint SELECT /*+ BKA(test@tableТ) */ 1 FROM t1; 1 Warnings: -Warning 4207 Query block name `tableТ` is not found for BKA hint +Warning 4208 Query block name `tableТ` is not found for BKA hint DROP TABLE tableТ; CREATE TABLE таблица (i INT); SELECT /*+ BKA(`таблица`) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `таблица`@`select#1` for BKA hint +Warning 4209 Unresolved table name `таблица`@`select#1` for BKA hint SELECT /*+ BKA(таблица) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `таблица`@`select#1` for BKA hint +Warning 4209 Unresolved table name `таблица`@`select#1` for BKA hint SELECT /*+ BKA(test@таблица) */ 1 FROM t1; 1 Warnings: -Warning 4207 Query block name `таблица` is not found for BKA hint +Warning 4208 Query block name `таблица` is not found for BKA hint SELECT /*+ NO_ICP(`\D1`) */ 1 FROM t1; 1 Warnings: -Warning 4208 Unresolved table name `\D1`@`select#1` for NO_ICP hint +Warning 4209 Unresolved table name `\D1`@`select#1` for NO_ICP hint DROP TABLE таблица; # derived tables and other subqueries: @@ -1966,7 +1966,7 @@ NO_ICP(@qb ident) 1 1 Warnings: -Warning 4207 Query block name `qb` is not found for NO_ICP hint +Warning 4208 Query block name `qb` is not found for NO_ICP hint SELECT /*+ ? bad syntax */ 1; diff --git a/mysql-test/main/opt_hints_subquery.result b/mysql-test/main/opt_hints_subquery.result index 72acab8a8d1..ff8ed5afbeb 100644 --- a/mysql-test/main/opt_hints_subquery.result +++ b/mysql-test/main/opt_hints_subquery.result @@ -158,7 +158,7 @@ a 3 4 Warnings: -Warning 4207 Query block name `qb1` is not found for SUBQUERY hint +Warning 4208 Query block name `qb1` is not found for SUBQUERY hint SELECT /*+ SUBQUERY() */ a FROM t1; a 1 @@ -195,15 +195,15 @@ SELECT /*+ SEMIJOIN() SEMIJOIN(dupsweedout) NO_SEMIJOIN(firstmatch)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(DUPSWEEDOUT) is ignored as conflicting/duplicated -Warning 4206 Hint NO_SEMIJOIN(FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(DUPSWEEDOUT) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(FIRSTMATCH) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SEMIJOIN(loosescan,materialization) SEMIJOIN(dupsweedout)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(DUPSWEEDOUT) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(DUPSWEEDOUT) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`select#1` LOOSESCAN, MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ NO_SEMIJOIN(firstmatch,loosescan,materialization) SEMIJOIN() NO_SEMIJOIN()*/ a @@ -211,8 +211,8 @@ FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN() is ignored as conflicting/duplicated -Warning 4206 Hint NO_SEMIJOIN() is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN() is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN() is ignored as conflicting/duplicated Note 1003 select /*+ NO_SEMIJOIN(@`select#1` FIRSTMATCH, LOOSESCAN, MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ QB_NAME(qb1) SEMIJOIN(@qb1) SEMIJOIN(loosescan) NO_SEMIJOIN(@qb1 dupsweedout)*/ a @@ -220,36 +220,36 @@ FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(LOOSESCAN) is ignored as conflicting/duplicated -Warning 4206 Hint NO_SEMIJOIN(@`qb1` DUPSWEEDOUT) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(LOOSESCAN) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(@`qb1` DUPSWEEDOUT) is ignored as conflicting/duplicated Note 1003 select /*+ QB_NAME(`qb1`) SEMIJOIN(@`qb1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SEMIJOIN(firstmatch) NO_SEMIJOIN()*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint NO_SEMIJOIN() is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN() is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`select#1` FIRSTMATCH) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SUBQUERY(materialization) SUBQUERY(intoexists)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 select /*+ SUBQUERY(@`select#1` MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SEMIJOIN() SUBQUERY(materialization) SUBQUERY(intoexists)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SUBQUERY(materialization) SUBQUERY(intoexists)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 select /*+ SUBQUERY(@`select#1` MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SUBQUERY(materialization) SUBQUERY(intoexists) SUBQUERY(materialization)*/ a @@ -257,32 +257,32 @@ FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated -Warning 4206 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated Note 1003 select /*+ SUBQUERY(@`select#1` MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SUBQUERY(materialization) SEMIJOIN(firstmatch) SUBQUERY(intoexists)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(FIRSTMATCH) is ignored as conflicting/duplicated -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 select /*+ SUBQUERY(@`select#1` MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ QB_NAME(qb1) SEMIJOIN(@qb1) SUBQUERY(@qb1 materialization) SUBQUERY(intoexists)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(@`qb1` MATERIALIZATION) is ignored as conflicting/duplicated -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(@`qb1` MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 select /*+ QB_NAME(`qb1`) SEMIJOIN(@`qb1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ QB_NAME(qb1) SUBQUERY(@qb1 materialization) SEMIJOIN(@qb1 firstmatch) SUBQUERY(intoexists)*/ a FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(@`qb1` FIRSTMATCH) is ignored as conflicting/duplicated -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`qb1` FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 select /*+ QB_NAME(`qb1`) SUBQUERY(@`qb1` MATERIALIZATION) */ `test`.`t1`.`a` AS `a` from `test`.`t1` EXPLAIN EXTENDED SELECT /*+ SEMIJOIN(@qb1) SEMIJOIN(loosescan) NO_SEMIJOIN(@qb1 dupsweedout)*/ a @@ -291,7 +291,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY ALL NULL NULL NULL NULL 4 100.00 2 DERIVED t2 index NULL a 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint NO_SEMIJOIN(@`qb1` DUPSWEEDOUT) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(@`qb1` DUPSWEEDOUT) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SEMIJOIN(@`qb1`) SEMIJOIN(@`select#1` LOOSESCAN) */ `tt`.`a` AS `a` from (/* select#2 */ select /*+ QB_NAME(`qb1`) */ `test`.`t2`.`a` AS `a` from `test`.`t2`) `tt` DROP TABLE t1, t2 ,t3; set optimizer_switch=default; @@ -1434,7 +1434,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN() is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN() is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`select#2`) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Try opposite order EXPLAIN EXTENDED @@ -1444,7 +1444,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t2 ref a a 4 test.t1.a 1 100.00 Using index Warnings: -Warning 4206 Hint NO_SEMIJOIN() is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN() is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`select#2`) */ `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` # Specify at different levels, hint inside block has effect EXPLAIN EXTENDED @@ -1454,7 +1454,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t2 ref a a 4 test.t1.a 1 100.00 Using index Warnings: -Warning 4206 Hint NO_SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`subq`) */ `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` # Specify at different levels, opposite order EXPLAIN EXTENDED @@ -1464,7 +1464,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq`) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Duplicate hints also gives warning, but hint has effect EXPLAIN EXTENDED @@ -1474,7 +1474,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t2 ref a a 4 test.t1.a 1 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`subq`) */ `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` EXPLAIN EXTENDED SELECT /*+ NO_SEMIJOIN(@subq) */ * FROM t2 @@ -1483,7 +1483,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint NO_SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(@`subq` ) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq`) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Multiple subqueries with conflicting hints EXPLAIN EXTENDED @@ -1495,8 +1495,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ref a a 4 test.t1.b 1 66.67 Using index; Start temporary; End temporary 2 DEPENDENT SUBQUERY t3 index_subquery a a 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(@`subq1` LOOSESCAN) is ignored as conflicting/duplicated -Warning 4206 Hint SEMIJOIN(@`subq2` FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq1` LOOSESCAN) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq2` FIRSTMATCH) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq1`) SEMIJOIN(@`subq2` LOOSESCAN) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t1`.`b` and <`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in t3 on a)))) EXPLAIN EXTENDED SELECT /*+ SEMIJOIN(@subq1 LOOSESCAN) SEMIJOIN(@subq2 FIRSTMATCH) */ * FROM t1 @@ -1507,8 +1507,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ref a a 4 test.t1.a 1 100.00 Using index; FirstMatch(t1) 1 PRIMARY t2 ref a a 4 test.t1.b 1 66.67 Using index; Start temporary; End temporary Warnings: -Warning 4206 Hint SEMIJOIN(@`subq1` LOOSESCAN) is ignored as conflicting/duplicated -Warning 4206 Hint SEMIJOIN(@`subq2` FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq1` LOOSESCAN) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq2` FIRSTMATCH) is ignored as conflicting/duplicated Note 1003 select /*+ NO_SEMIJOIN(@`subq1` LOOSESCAN) SEMIJOIN(@`subq2` LOOSESCAN) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t3`) semi join (`test`.`t2`) where `test`.`t3`.`a` = `test`.`t1`.`a` and `test`.`t2`.`a` = `test`.`t1`.`b` # Conflicting hints in same hint comment EXPLAIN EXTENDED @@ -1520,7 +1520,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 25.00 Using where 1 PRIMARY t2 ref a a 4 test.t1.b 1 66.67 Using index; FirstMatch(t1) Warnings: -Warning 4206 Hint SEMIJOIN(@`subq1` FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq1` FIRSTMATCH) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`subq1` LOOSESCAN) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t3`) semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t3`.`a` and `test`.`t2`.`a` = `test`.`t1`.`b` EXPLAIN EXTENDED SELECT /*+ SEMIJOIN(@subq1 LOOSESCAN) NO_SEMIJOIN(@subq1 LOOSESCAN) */ * @@ -1532,7 +1532,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 25.00 Using where 1 PRIMARY t2 ref a a 4 test.t1.b 1 66.67 Using index; FirstMatch(t1) Warnings: -Warning 4206 Hint NO_SEMIJOIN(@`subq1` LOOSESCAN) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(@`subq1` LOOSESCAN) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`subq1` LOOSESCAN) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t3`) semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t3`.`a` and `test`.`t2`.`a` = `test`.`t1`.`b` EXPLAIN EXTENDED SELECT /*+ NO_SEMIJOIN(@subq1 LOOSESCAN) NO_SEMIJOIN(@subq1 FIRSTMATCH) */ * @@ -1544,7 +1544,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ref a a 4 test.t1.a 1 100.00 Using index; FirstMatch(t1) 1 PRIMARY t2 ref a a 4 test.t1.b 1 66.67 Using index; FirstMatch(t3) Warnings: -Warning 4206 Hint NO_SEMIJOIN(@`subq1` FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint NO_SEMIJOIN(@`subq1` FIRSTMATCH) is ignored as conflicting/duplicated Note 1003 select /*+ NO_SEMIJOIN(@`subq1` LOOSESCAN) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t3`) semi join (`test`.`t2`) where `test`.`t3`.`a` = `test`.`t1`.`a` and `test`.`t2`.`a` = `test`.`t1`.`b` # Non-supported strategies should give warnings EXPLAIN EXTENDED @@ -1770,7 +1770,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 MATERIALIZED t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(INTOEXISTS) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SUBQUERY(@`select#2` MATERIALIZATION) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,`test`.`t2`.`a` in ( (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` ), (`test`.`t2`.`a` in on distinct_key where `test`.`t2`.`a` = ``.`a`)))) # Try opposite order EXPLAIN EXTENDED @@ -1781,7 +1781,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SUBQUERY(@`select#2` INTOEXISTS) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Specify at different levels, hint inside block has effect EXPLAIN EXTENDED @@ -1791,7 +1791,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(@`subq` MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(@`subq` MATERIALIZATION) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SUBQUERY(@`subq` INTOEXISTS) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Specify at different levels, opposite order EXPLAIN EXTENDED @@ -1801,7 +1801,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 MATERIALIZED t1 index NULL PRIMARY 4 NULL 4 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(@`subq` INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(@`subq` INTOEXISTS) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SUBQUERY(@`subq` MATERIALIZATION) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,`test`.`t2`.`a` in ( (/* select#2 */ select /*+ QB_NAME(`subq`) */ `test`.`t1`.`a` from `test`.`t1` ), (`test`.`t2`.`a` in on distinct_key where `test`.`t2`.`a` = ``.`a`)))) # Specifying combinations of SUBQUERY and SEMIJOIN/NO_SEMIJOIN # for same query block gives warning @@ -1813,7 +1813,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN() is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN() is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SUBQUERY(@`select#2` INTOEXISTS) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Try opposite order EXPLAIN EXTENDED @@ -1823,7 +1823,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(MATERIALIZATION) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`select#2`) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) # Specify at different levels, hint inside block has effect EXPLAIN EXTENDED @@ -1833,7 +1833,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t2 ref a a 4 test.t1.a 1 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(@`subq` MATERIALIZATION) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(@`subq` MATERIALIZATION) is ignored as conflicting/duplicated Note 1003 select /*+ SEMIJOIN(@`subq`) */ `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` EXPLAIN EXTENDED SELECT /*+ SUBQUERY(@subq INTOEXISTS) */ * FROM t2 @@ -1842,7 +1842,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SUBQUERY(@`subq` INTOEXISTS) is ignored as conflicting/duplicated +Warning 4207 Hint SUBQUERY(@`subq` INTOEXISTS) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq`) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) EXPLAIN EXTENDED SELECT /*+ SEMIJOIN(@subq FIRSTMATCH) */ * FROM t2 @@ -1851,6 +1851,6 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL a 4 NULL 6 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index Warnings: -Warning 4206 Hint SEMIJOIN(@`subq` FIRSTMATCH) is ignored as conflicting/duplicated +Warning 4207 Hint SEMIJOIN(@`subq` FIRSTMATCH) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ SUBQUERY(@`subq` INTOEXISTS) */ `test`.`t2`.`a` AS `a` from `test`.`t2` where <`test`.`t2`.`a`>((`test`.`t2`.`a`,(((`test`.`t2`.`a`) in t1 on PRIMARY)))) DROP TABLE t1,t2,t3; diff --git a/sql/opt_hints.cc b/sql/opt_hints.cc index fec57fc1d82..097983feb7b 100644 --- a/sql/opt_hints.cc +++ b/sql/opt_hints.cc @@ -53,21 +53,20 @@ const LEX_CSTRING sys_qb_prefix= {"select#", 7}; static const Lex_ident_sys null_ident_sys; -template static void print_warn(THD *thd, uint err_code, opt_hints_enum hint_type, bool hint_state, const Lex_ident_sys *qb_name_arg, const Lex_ident_sys *table_name_arg, const Lex_ident_sys *key_name_arg, - Hint_type *hint) + const Printable_parser_rule *hint) { String str; /* Append hint name */ if (!hint_state) str.append(STRING_WITH_LEN("NO_")); - str.append(opt_hint_info[hint_type].hint_name); + str.append(opt_hint_info[hint_type].hint_type); /* ER_WARN_UNKNOWN_QB_NAME with two arguments */ if (err_code == ER_WARN_UNKNOWN_QB_NAME) @@ -212,7 +211,7 @@ static Opt_hints_qb *find_qb_hints(Parse_context *pc, if (qb == NULL) { print_warn(pc->thd, ER_WARN_UNKNOWN_QB_NAME, hint_type, hint_state, - &qb_name, NULL, NULL, (Parser::Hint*) NULL); + &qb_name, NULL, NULL, NULL); } return qb; } @@ -274,9 +273,14 @@ Opt_hints* Opt_hints::find_by_name(const LEX_CSTRING &name_arg) const void Opt_hints::print(THD *thd, String *str) { + /* Do not print the hint if we couldn't attach it to its object */ + if (!is_fixed()) + return; + + // Print the hints stored in the bitmap for (uint i= 0; i < MAX_HINT_ENUM; i++) { - if (is_specified(static_cast(i)) && is_fixed()) + if (is_specified(static_cast(i))) { append_hint_type(str, static_cast(i)); str->append(STRING_WITH_LEN("(")); @@ -286,10 +290,7 @@ void Opt_hints::print(THD *thd, String *str) if (len_after_name > len_before_name) str->append(' '); if (opt_hint_info[i].has_arguments) - { - std::function args_printer= get_args_printer(); - args_printer(thd, str); - } + append_hint_arguments(thd, static_cast(i), str); if (str->length() == len_after_name + 1) { // No additional arguments were printed, trim the space added before @@ -304,11 +305,16 @@ void Opt_hints::print(THD *thd, String *str) } +/* + @brief + Append hint "type", for example, "NO_RANGE_OPTIMIZATION" or "BKA" +*/ + void Opt_hints::append_hint_type(String *str, opt_hints_enum type) { if(!hints_map.is_switched_on(type)) str->append(STRING_WITH_LEN("NO_")); - str->append(opt_hint_info[type].hint_name); + str->append(opt_hint_info[type].hint_type); } @@ -605,7 +611,7 @@ bool Parser::Table_level_hint::resolve(Parse_context *pc) const if (qb->set_switch(hint_state, hint_type, false)) { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, - &qb_name_sys, nullptr, nullptr, (Parser::Hint*) nullptr); + &qb_name_sys, nullptr, nullptr, nullptr); } return false; } @@ -623,7 +629,7 @@ bool Parser::Table_level_hint::resolve(Parse_context *pc) const { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, &qb_name_sys, &table_name_sys, nullptr, - (Parser::Hint*) nullptr); + nullptr); } } } @@ -642,7 +648,7 @@ bool Parser::Table_level_hint::resolve(Parse_context *pc) const if (qb->set_switch(hint_state, hint_type, false)) { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, - &null_ident_sys, nullptr, nullptr, (Parser::Hint*) nullptr); + &null_ident_sys, nullptr, nullptr, nullptr); } return false; } @@ -656,8 +662,7 @@ bool Parser::Table_level_hint::resolve(Parse_context *pc) const if (tab->set_switch(hint_state, hint_type, true)) { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, - &null_ident_sys, &table_name_sys, nullptr, - (Parser::Hint*) nullptr); + &null_ident_sys, &table_name_sys, nullptr, nullptr); } } @@ -677,8 +682,7 @@ bool Parser::Table_level_hint::resolve(Parse_context *pc) const if (tab->set_switch(hint_state, hint_type, true)) { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, - &qb_name_sys, &table_name_sys, nullptr, - (Parser::Hint*) nullptr); + &qb_name_sys, &table_name_sys, nullptr, nullptr); } } } @@ -741,8 +745,7 @@ bool Parser::Index_level_hint::resolve(Parse_context *pc) const if (tab->set_switch(hint_state, hint_type, false)) { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, - &qb_name_sys, &table_name_sys, nullptr, - (Parser::Hint*) nullptr); + &qb_name_sys, &table_name_sys, nullptr, nullptr); } return false; } @@ -761,8 +764,7 @@ bool Parser::Index_level_hint::resolve(Parse_context *pc) const if (idx->set_switch(hint_state, hint_type, true)) { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, hint_type, hint_state, - &qb_name_sys, &table_name_sys, &index_name_sys, - (Parser::Hint*) nullptr); + &qb_name_sys, &table_name_sys, &index_name_sys, nullptr); } } return false; @@ -789,7 +791,7 @@ bool Parser::Qb_name_hint::resolve(Parse_context *pc) const qb->get_parent()->find_by_name(qb_name_sys)) // Name is already used { print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, QB_NAME_HINT_ENUM, true, - &qb_name_sys, nullptr, nullptr, (Parser::Hint*) nullptr); + &qb_name_sys, nullptr, nullptr, nullptr); return false; } @@ -1157,6 +1159,28 @@ bool Opt_hints_global::fix_hint(THD *thd) } +#ifndef DBUG_OFF +static char dbug_print_hint_buf[64]; + +const char *dbug_print_hints(Opt_hints_qb *hint) +{ + char *buf= dbug_print_hint_buf; + THD *thd= current_thd; + String str(buf, sizeof(dbug_print_hint_buf), &my_charset_bin); + str.length(0); + if (!hint) + return "(Opt_hints_qb*)NULL"; + + hint->print(thd, &str); + + if (str.c_ptr_safe() == buf) + return buf; + else + return "Couldn't fit into buffer"; +} +#endif + + bool Parser::Hint_list::resolve(Parse_context *pc) const { if (pc->thd->lex->create_view) diff --git a/sql/opt_hints.h b/sql/opt_hints.h index 5737a5e9f5e..d998da0d1a6 100644 --- a/sql/opt_hints.h +++ b/sql/opt_hints.h @@ -84,6 +84,7 @@ #include "sql_show.h" #include "mysqld_error.h" #include "opt_hints_parser.h" +#include "opt_trace.h" struct LEX; @@ -111,7 +112,7 @@ enum opt_hints_enum struct st_opt_hint_info { - LEX_CSTRING hint_name; // Hint name. + LEX_CSTRING hint_type; // Hint "type", like "BKA" or "MRR". bool check_upper_lvl; // true if upper level hint check is needed (for hints // which can be specified on more than one level). bool has_arguments; // true if hint has additional arguments. @@ -324,16 +325,16 @@ public: @param thd Pointer to THD object */ void check_unfixed(THD *thd); + + /* + Append the name of object(table, index, etc) that hints in this collection + are attached to. + */ virtual void append_name(THD *thd, String *str)= 0; - /** - Get the function appending additional hint arguments to the printed string, - if the arguments exist. For example, SEMIJOIN and SUBQUERY hints may have - a list of strategies as additional arguments - */ - virtual std::function get_args_printer() const + virtual void append_hint_arguments(THD *thd, opt_hints_enum hint, String *str) { - return [](THD*, String*) {}; + DBUG_ASSERT(0); } virtual ~Opt_hints() {} @@ -367,7 +368,7 @@ protected: /** - Global level hints. + Global level hints. Currently, it's only MAX_EXECUTION_TIME. */ class Opt_hints_global : public Opt_hints @@ -386,14 +387,21 @@ public: : Opt_hints(Lex_ident_sys(), NULL, mem_root_arg) {} - virtual void append_name(THD *thd, String *str) override {} - - virtual std::function get_args_printer() const override + virtual void append_name(THD *thd, String *str) override { - using std::placeholders::_1; - using std::placeholders::_2; - return std::bind(&Parser::Max_execution_time_hint::append_args, - max_exec_time_hint, _1, _2); + /* + Don't write anything: global hints are not attached to anything named + like a table/query block/etc + */ + } + + void append_hint_arguments(THD *thd, opt_hints_enum hint, + String *str) override + { + if (hint == MAX_EXEC_TIME_HINT_ENUM) + max_exec_time_hint->append_args(thd, str); + else + DBUG_ASSERT(0); } bool fix_hint(THD *thd); @@ -403,7 +411,11 @@ public: class Opt_hints_table; /** - Query block level hints. + Query block level hints. Currently, these can be: + - QB_NAME (this is interpreted in the parser and is not explicitly + present after that) + - [NO_]SEMIJOIN + - SUBQUERY */ class Opt_hints_qb : public Opt_hints @@ -422,12 +434,7 @@ public: return name.str ? name : sys_name; } - /** - Append query block hint. - @param thd pointer to THD object - @param str pointer to String object - */ void append_qb_hint(THD *thd, String *str) { if (name.str) @@ -437,35 +444,25 @@ public: str->append(STRING_WITH_LEN(") ")); } } - /** - Append query block name. - @param thd pointer to THD object - @param str pointer to String object - */ virtual void append_name(THD *thd, String *str) override { + /* Append query block name. */ str->append(STRING_WITH_LEN("@")); const LEX_CSTRING print_name= get_print_name(); append_identifier(thd, str, &print_name); } - std::function get_args_printer() const override + void append_hint_arguments(THD *thd, opt_hints_enum hint, + String *str) override { - using std::placeholders::_1; - using std::placeholders::_2; - if (semijoin_hint) - { - return std::bind(&Parser::Semijoin_hint::append_args, semijoin_hint, - _1, _2); - } - else if (subquery_hint) - { - return std::bind(&Parser::Subquery_hint::append_args, subquery_hint, - _1, _2); - } - return [](THD*, String*) {}; - } + if (hint == SUBQUERY_HINT_ENUM) + subquery_hint->append_args(thd, str); + else if (hint == SEMIJOIN_HINT_ENUM) + semijoin_hint->append_args(thd, str); + else + DBUG_ASSERT(0); + } /** Function finds Opt_hints_table object corresponding to @@ -518,6 +515,19 @@ public: const Parser::Subquery_hint *subquery_hint= nullptr; uint subquery_strategy= SUBS_NOT_TRANSFORMED; + + void trace_hints(THD *thd) + { + if (unlikely(thd->trace_started())) + { + Json_writer_object obj(thd); + String str; + str.length(0); + print(thd, &str); + // Eventually we may want to print them as array. + obj.add("hints", str.c_ptr_safe()); + } + } }; @@ -635,4 +645,9 @@ bool hint_key_state(const THD *thd, const TABLE *table, */ bool hint_table_state(const THD *thd, const TABLE *table, opt_hints_enum type_arg, bool fallback_value); + +#ifndef DBUG_OFF +const char *dbug_print_hints(Opt_hints_qb *hint); +#endif + #endif /* OPT_HINTS_INCLUDED */ diff --git a/sql/opt_hints_parser.cc b/sql/opt_hints_parser.cc index b7a4881301c..31b0d08ac7c 100644 --- a/sql/opt_hints_parser.cc +++ b/sql/opt_hints_parser.cc @@ -245,7 +245,7 @@ Optimizer_hint_parser:: Hint_list_container::add(Optimizer_hint_parser *p, Hint &&elem) { - Hint *pe= (Hint*) p->m_thd->alloc(sizeof(*pe)); + Hint *pe= new (p->m_thd->mem_root) Hint; if (!pe) return true; *pe= std::move(elem); diff --git a/sql/opt_hints_parser.h b/sql/opt_hints_parser.h index 9c409255895..d50f52ef7eb 100644 --- a/sql/opt_hints_parser.h +++ b/sql/opt_hints_parser.h @@ -117,6 +117,14 @@ protected: }; +class Printable_parser_rule +{ +public: + virtual void append_args(THD *thd, String *str) const = 0; + virtual ~Printable_parser_rule() {} +}; + + class Optimizer_hint_parser: public Optimizer_hint_tokenizer, public Parser_templates { @@ -605,13 +613,14 @@ public: Keyword_MAX_EXECUTION_TIME, LParen, Unsigned_Number, - RParen> + RParen>, + public Printable_parser_rule { public: using AND4::AND4; bool resolve(Parse_context *pc) const; - void append_args(THD *thd, String *str) const; + void append_args(THD *thd, String *str) const override; ulonglong get_milliseconds() const; }; @@ -717,13 +726,14 @@ public: Semijoin_hint_type, LParen, Semijoin_hint_body, - RParen> + RParen>, + public Printable_parser_rule { public: using AND4::AND4; bool resolve(Parse_context *pc) const; - void append_args(THD *thd, String *str) const; + void append_args(THD *thd, String *str) const override; private: Opt_hints_qb* resolve_for_qb_name(Parse_context *pc, bool hint_state, @@ -792,13 +802,14 @@ public: Keyword_SUBQUERY, LParen, Subquery_hint_body, - RParen> + RParen>, + public Printable_parser_rule { public: using AND4::AND4; bool resolve(Parse_context *pc) const; - void append_args(THD *thd, String *str) const; + void append_args(THD *thd, String *str) const override; private: void set_subquery_strategy(TokenID token_id, Opt_hints_qb *qb) const; @@ -825,16 +836,6 @@ public: { public: using OR6::OR6; - - /** - Append additional hint arguments to the printed string. - Implement this method in Hint specifications if needed: - Table_level_hint, Semijoin_hint, etc - - @param thd Pointer to THD object - @param str Pointer to String object - */ - void append_args(THD *thd, String *str) const {} }; private: diff --git a/sql/sql_lex.h b/sql/sql_lex.h index df613c415ba..90dfc4da30a 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1260,6 +1260,13 @@ public: */ table_map select_list_tables; + /* + Parse tree of optimizer hints that were specified in this SELECT. Note + that hints specified in one select can prescribe how to execute another. + */ + const Optimizer_hint_parser_output *parsed_optimizer_hints; + + /* Optimizer hints that prescribe how to execute this SELECT */ Opt_hints_qb *opt_hints_qb; /* Set to 1 if any field in field list has ROWNUM() */ @@ -1273,8 +1280,6 @@ public: /* it is for correct printing SELECT options */ thr_lock_type lock_type; - const Optimizer_hint_parser_output *parsed_optimizer_hints; - /** System Versioning */ int vers_setup_conds(THD *thd, TABLE_LIST *tables); /* push new Item_field into item_list */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 65ce83f1b75..97b05bc3223 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2194,6 +2194,9 @@ JOIN::optimize_inner() trace_prepare.add_select_number(select_lex->select_number); Json_writer_array trace_steps(thd, "steps"); + if (select_lex->opt_hints_qb) + select_lex->opt_hints_qb->trace_hints(thd); + /* Needed in case optimizer short-cuts, set properly in make_aggr_tables_info()