You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MDEV-36486 Forbid placing optimizer hints at the INSERT part of INSERT..SELECT
Due to complications while parsing of INSERT..SELECT statements,
optimizer hints placed at the INSERT part are ignored.
At the same time, hints placed at the SELECT part of
INSERT..SELECT statements are fully supported.
Copy file name to clipboardExpand all lines: mysql-test/main/opt_hints.result
+18-24
Original file line number
Diff line number
Diff line change
@@ -490,17 +490,17 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
490
490
Warnings:
491
491
Note 1003 (insert into `test`.`t3`(f1,f2,f3) select /*+ NO_ICP(`t5`@`select#2`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
492
492
# Turn off ICP for a particular table
493
-
EXPLAIN EXTENDED INSERT /*+ NO_ICP(t5@QB1) */ INTO t3(f1, f2, f3)
id select_type table type possible_keys key key_len ref rows filtered Extra
497
497
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
498
498
1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
499
499
Warnings:
500
-
Note 1003 (insert into `test`.`t3`(f1,f2,f3) select /*+ QB_NAME(`qb1`) NO_ICP(`t5`@`qb1`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
500
+
Note 1003 (insert into `test`.`t3`(f1,f2,f3) select /*+ NO_ICP(`t5`@`select#2`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
id select_type table type possible_keys key key_len ref rows filtered Extra
506
506
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
@@ -525,23 +525,23 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
525
525
Warnings:
526
526
Note 1003 (replace into `test`.`t3`(f1,f2,f3) select /*+ NO_ICP(`t5`@`select#2`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
527
527
# Turn off ICP for a particular table
528
-
EXPLAIN EXTENDED REPLACE /*+ NO_ICP(t5@QB1) */ INTO t3(f1, f2, f3)
id select_type table type possible_keys key key_len ref rows filtered Extra
532
532
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
533
533
1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
534
534
Warnings:
535
535
Note 1003 (replace into `test`.`t3`(f1,f2,f3) select /*+ QB_NAME(`qb1`) NO_ICP(`t5`@`qb1`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
id select_type table type possible_keys key key_len ref rows filtered Extra
541
541
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
542
542
1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
543
543
Warnings:
544
-
Note 1003 (replace into `test`.`t3`(f1,f2,f3) select /*+ QB_NAME(`qb1`) NO_ICP(`t5`@`qb1` `x_idx`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
544
+
Note 1003 (replace into `test`.`t3`(f1,f2,f3) select /*+ NO_ICP(`t5`@`select#2` `x_idx`) */ `test`.`t4`.`x` AS `x`,`test`.`t5`.`y` AS `y`,'filler' AS `filler` from `test`.`t4` join `test`.`t4` `t5` where `test`.`t4`.`y` = 8 and `test`.`t5`.`x` between 7 and <cache>(8 + 0))
@@ -1400,21 +1400,23 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1400
1400
1 SIMPLE t1 index a a 5 NULL 3 100.00 Using where; Using index; Using temporary
1401
1401
Warnings:
1402
1402
Note 1003 insert into `test`.`t1`(a) select /*+ NO_RANGE_OPTIMIZATION(`t1`@`select#2` `a`) */ sql_buffer_result `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1 and `test`.`t1`.`a` <= 3
1403
-
# Alternatively, a hint may be placed next to INSERT keyword:
1403
+
# Hints at the INSERT part of a INSERT..SELECT are not supported:
1404
1404
EXPLAIN EXTENDED
1405
1405
INSERT /*+ no_range_optimization (t1)*/ INTO t1 (a) SELECT a FROM t1 WHERE a>1 AND a<=3;
1406
1406
id select_type table type possible_keys key key_len ref rows filtered Extra
1407
-
1 SIMPLE t1 index a a 5 NULL 3 100.00 Using where; Using index; Using temporary
1407
+
1 SIMPLE t1 range a a 5 NULL 2 100.00 Using where; Using index; Using temporary
1408
1408
Warnings:
1409
-
Note 1003 insert into `test`.`t1`(a) select /*+ NO_RANGE_OPTIMIZATION(`t1`@`select#1`) */ sql_buffer_result `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1 and `test`.`t1`.`a` <= 3
1410
-
# But if hints are present at both INSERT and SELECT parts,
1411
-
# those at the INSERT part are ignored:
1409
+
Warning 4223 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
1410
+
Note 1003 insert into `test`.`t1`(a) select sql_buffer_result `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1 and `test`.`t1`.`a` <= 3
1411
+
# If hints are present at both INSERT and SELECT parts,
1412
+
# those at the INSERT part are ignored
1412
1413
EXPLAIN EXTENDED
1413
1414
INSERT /*+ no_range_optimization (t1)*/ INTO t1 (a) SELECT /*+ mrr(t1)*/ a
1414
1415
FROM t1 WHERE a>1 AND a<=3;
1415
1416
id select_type table type possible_keys key key_len ref rows filtered Extra
1416
1417
1 SIMPLE t1 range a a 5 NULL 2 100.00 Using where; Using index; Using temporary
1417
1418
Warnings:
1419
+
Warning 4223 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
1418
1420
Note 1003 insert into `test`.`t1`(a) select /*+ MRR(`t1`@`select#2`) */ sql_buffer_result `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1 and `test`.`t1`.`a` <= 3
1419
1421
# Table `t2` cannot be resolved since it is not present in the SELECT part
1420
1422
# (a warning expected):
@@ -1423,15 +1425,7 @@ INSERT INTO t2 (a) SELECT /*+ no_range_optimization (t2)*/ a FROM t1 WHERE a>1 A
1423
1425
id select_type table type possible_keys key key_len ref rows filtered Extra
1424
1426
1 SIMPLE t1 range a a 5 NULL 2 100.00 Using where; Using index
1425
1427
Warnings:
1426
-
Warning 4212 Unresolved table name `t2`@`select#2` for NO_RANGE_OPTIMIZATION hint
1427
-
Note 1003 insert into `test`.`t2`(a) select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1 and `test`.`t1`.`a` <= 3
1428
-
# Alternative placement of the hint:
1429
-
EXPLAIN EXTENDED
1430
-
INSERT /*+ no_range_optimization (t2 ix1)*/ INTO t2 (a) SELECT a FROM t1 WHERE a>1 AND a<=3;
1431
-
id select_type table type possible_keys key key_len ref rows filtered Extra
1432
-
1 SIMPLE t1 range a a 5 NULL 2 100.00 Using where; Using index
1433
-
Warnings:
1434
-
Warning 4213 Unresolved index name `t2`@`select#1` `ix1` for NO_RANGE_OPTIMIZATION hint
1428
+
Warning 4219 Unresolved table name `t2`@`select#2` for NO_RANGE_OPTIMIZATION hint
1435
1429
Note 1003 insert into `test`.`t2`(a) select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1 and `test`.`t1`.`a` <= 3
0 commit comments