Skip to content

Commit 8041255

Browse files
committed
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.
1 parent 2cb6171 commit 8041255

10 files changed

+92
-52
lines changed

mysql-test/main/opt_hint_timeout.result

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ Warning 1912 Incorrect value '4294967296' for option 'MAX_EXECUTION_TIME'
7272
CREATE TABLE t2 (i INT);
7373
INSERT /*+ MAX_EXECUTION_TIME(10) */ INTO t2 SELECT 1;
7474
Warnings:
75+
Warning 4223 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
76+
INSERT INTO t2 SELECT /*+ MAX_EXECUTION_TIME(10) */ 1;
77+
Warnings:
7578
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
7679
REPLACE /*+ MAX_EXECUTION_TIME(15) */ INTO t2 SELECT 1;
7780
Warnings:
78-
Warning 4172 'MAX_EXECUTION_TIME(15)' is not allowed in this context
81+
Warning 4223 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
82+
REPLACE INTO t2 SELECT /*+ MAX_EXECUTION_TIME(10) */ 1;
83+
Warnings:
84+
Warning 4172 'MAX_EXECUTION_TIME(10)' is not allowed in this context
7985
UPDATE /*+ MAX_EXECUTION_TIME(23) */ t2 SET i = 1;
8086
Warnings:
8187
Warning 4172 'MAX_EXECUTION_TIME(23)' is not allowed in this context

mysql-test/main/opt_hint_timeout.test

+2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ SELECT /*+ MAX_EXECUTION_TIME(4294967296) */ count(*) FROM t1;
7878
--echo
7979
CREATE TABLE t2 (i INT);
8080
INSERT /*+ MAX_EXECUTION_TIME(10) */ INTO t2 SELECT 1;
81+
INSERT INTO t2 SELECT /*+ MAX_EXECUTION_TIME(10) */ 1;
8182
REPLACE /*+ MAX_EXECUTION_TIME(15) */ INTO t2 SELECT 1;
83+
REPLACE INTO t2 SELECT /*+ MAX_EXECUTION_TIME(10) */ 1;
8284
UPDATE /*+ MAX_EXECUTION_TIME(23) */ t2 SET i = 1;
8385
DELETE /*+ MAX_EXECUTION_TIME(5000) */ FROM t2 WHERE i = 1;
8486

mysql-test/main/opt_hints.result

+18-24
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,17 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
490490
Warnings:
491491
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))
492492
# Turn off ICP for a particular table
493-
EXPLAIN EXTENDED INSERT /*+ NO_ICP(t5@QB1) */ INTO t3(f1, f2, f3)
494-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
493+
EXPLAIN EXTENDED INSERT INTO t3(f1, f2, f3)
494+
(SELECT /*+ NO_ICP(t5) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
495495
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
496496
id select_type table type possible_keys key key_len ref rows filtered Extra
497497
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
498498
1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
499499
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))
501501
# Turn off ICP for a particular table and a key
502-
EXPLAIN EXTENDED INSERT /*+ NO_ICP(t5@QB1 x_idx) */ INTO t3(f1, f2, f3)
503-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
502+
EXPLAIN EXTENDED INSERT INTO t3(f1, f2, f3)
503+
(SELECT /*+ QB_NAME(qb1) NO_ICP(t5@QB1 x_idx)*/ t4.x, t5.y, 'filler' FROM t4, t4 t5
504504
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
505505
id select_type table type possible_keys key key_len ref rows filtered Extra
506506
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
525525
Warnings:
526526
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))
527527
# Turn off ICP for a particular table
528-
EXPLAIN EXTENDED REPLACE /*+ NO_ICP(t5@QB1) */ INTO t3(f1, f2, f3)
529-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
528+
EXPLAIN EXTENDED REPLACE INTO t3(f1, f2, f3)
529+
(SELECT /*+ QB_NAME(qb1) NO_ICP(t5@QB1)*/ t4.x, t5.y, 'filler' FROM t4, t4 t5
530530
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
531531
id select_type table type possible_keys key key_len ref rows filtered Extra
532532
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
533533
1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
534534
Warnings:
535535
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))
536536
# Turn off ICP for a particular table and a key
537-
EXPLAIN EXTENDED REPLACE /*+ NO_ICP(t5@QB1 x_idx) */ INTO t3(f1, f2, f3)
538-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
537+
EXPLAIN EXTENDED REPLACE INTO t3(f1, f2, f3)
538+
(SELECT /*+ NO_ICP(t5 x_idx) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
539539
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
540540
id select_type table type possible_keys key key_len ref rows filtered Extra
541541
1 SIMPLE t4 ref y_idx y_idx 5 const 1 100.00
542542
1 SIMPLE t5 range x_idx x_idx 5 NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
543543
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))
545545
# Misc tests
546546
# Should issue warning
547547
EXPLAIN EXTENDED SELECT /*+ QB_NAME(qb1) QB_NAME(qb1 ) */ * FROM t2;
@@ -1400,21 +1400,23 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
14001400
1 SIMPLE t1 index a a 5 NULL 3 100.00 Using where; Using index; Using temporary
14011401
Warnings:
14021402
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:
14041404
EXPLAIN EXTENDED
14051405
INSERT /*+ no_range_optimization (t1)*/ INTO t1 (a) SELECT a FROM t1 WHERE a>1 AND a<=3;
14061406
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
14081408
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
14121413
EXPLAIN EXTENDED
14131414
INSERT /*+ no_range_optimization (t1)*/ INTO t1 (a) SELECT /*+ mrr(t1)*/ a
14141415
FROM t1 WHERE a>1 AND a<=3;
14151416
id select_type table type possible_keys key key_len ref rows filtered Extra
14161417
1 SIMPLE t1 range a a 5 NULL 2 100.00 Using where; Using index; Using temporary
14171418
Warnings:
1419+
Warning 4223 Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported
14181420
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
14191421
# Table `t2` cannot be resolved since it is not present in the SELECT part
14201422
# (a warning expected):
@@ -1423,15 +1425,7 @@ INSERT INTO t2 (a) SELECT /*+ no_range_optimization (t2)*/ a FROM t1 WHERE a>1 A
14231425
id select_type table type possible_keys key key_len ref rows filtered Extra
14241426
1 SIMPLE t1 range a a 5 NULL 2 100.00 Using where; Using index
14251427
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
14351429
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
14361430
DROP TABLE t1, t2;
14371431
set optimizer_switch = DEFAULT;

mysql-test/main/opt_hints.test

+15-15
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ EXPLAIN EXTENDED INSERT INTO t3(f1, f2, f3)
275275
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
276276

277277
--echo # Turn off ICP for a particular table
278-
EXPLAIN EXTENDED INSERT /*+ NO_ICP(t5@QB1) */ INTO t3(f1, f2, f3)
279-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
278+
EXPLAIN EXTENDED INSERT INTO t3(f1, f2, f3)
279+
(SELECT /*+ NO_ICP(t5) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
280280
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
281281

282282
--echo # Turn off ICP for a particular table and a key
283-
EXPLAIN EXTENDED INSERT /*+ NO_ICP(t5@QB1 x_idx) */ INTO t3(f1, f2, f3)
284-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
283+
EXPLAIN EXTENDED INSERT INTO t3(f1, f2, f3)
284+
(SELECT /*+ QB_NAME(qb1) NO_ICP(t5@QB1 x_idx)*/ t4.x, t5.y, 'filler' FROM t4, t4 t5
285285
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
286286

287287
--echo # Make sure ICP is expected to be used when there are no hints
@@ -294,13 +294,13 @@ EXPLAIN EXTENDED REPLACE INTO t3(f1, f2, f3)
294294
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
295295

296296
--echo # Turn off ICP for a particular table
297-
EXPLAIN EXTENDED REPLACE /*+ NO_ICP(t5@QB1) */ INTO t3(f1, f2, f3)
298-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
297+
EXPLAIN EXTENDED REPLACE INTO t3(f1, f2, f3)
298+
(SELECT /*+ QB_NAME(qb1) NO_ICP(t5@QB1)*/ t4.x, t5.y, 'filler' FROM t4, t4 t5
299299
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
300300

301301
--echo # Turn off ICP for a particular table and a key
302-
EXPLAIN EXTENDED REPLACE /*+ NO_ICP(t5@QB1 x_idx) */ INTO t3(f1, f2, f3)
303-
(SELECT /*+ QB_NAME(qb1) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
302+
EXPLAIN EXTENDED REPLACE INTO t3(f1, f2, f3)
303+
(SELECT /*+ NO_ICP(t5 x_idx) */ t4.x, t5.y, 'filler' FROM t4, t4 t5
304304
WHERE t4.y = 8 AND t5.x BETWEEN 7 AND t4.y+0);
305305

306306
--echo # Misc tests
@@ -723,24 +723,24 @@ INSERT INTO t1 (a) SELECT a FROM t1 WHERE a>1 AND a<=3;
723723
EXPLAIN EXTENDED
724724
INSERT INTO t1 (a) SELECT /*+ no_range_optimization (t1 a)*/ a FROM t1 WHERE a>1 AND a<=3;
725725

726-
--echo # Alternatively, a hint may be placed next to INSERT keyword:
726+
--echo # Hints at the INSERT part of a INSERT..SELECT are not supported:
727727
EXPLAIN EXTENDED
728728
INSERT /*+ no_range_optimization (t1)*/ INTO t1 (a) SELECT a FROM t1 WHERE a>1 AND a<=3;
729729

730-
--echo # But if hints are present at both INSERT and SELECT parts,
731-
--echo # those at the INSERT part are ignored:
730+
--echo # If hints are present at both INSERT and SELECT parts,
731+
--echo # those at the INSERT part are ignored
732732
EXPLAIN EXTENDED
733733
INSERT /*+ no_range_optimization (t1)*/ INTO t1 (a) SELECT /*+ mrr(t1)*/ a
734734
FROM t1 WHERE a>1 AND a<=3;
735735

736736
--echo # Table `t2` cannot be resolved since it is not present in the SELECT part
737737
--echo # (a warning expected):
738+
# Warnings "Unresolved table/index name..." are generated during both prepare
739+
# and execution stages. So disable PS protocol to avoid duplication
740+
--disable_ps_protocol
738741
EXPLAIN EXTENDED
739742
INSERT INTO t2 (a) SELECT /*+ no_range_optimization (t2)*/ a FROM t1 WHERE a>1 AND a<=3;
740-
741-
--echo # Alternative placement of the hint:
742-
EXPLAIN EXTENDED
743-
INSERT /*+ no_range_optimization (t2 ix1)*/ INTO t2 (a) SELECT a FROM t1 WHERE a>1 AND a<=3;
743+
--enable_ps_protocol
744744

745745
DROP TABLE t1, t2;
746746

mysql-test/main/opt_hints_join_cache.test

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
--disable_view_protocol # Since optimizer hints are not supported inside views
2+
13
set @tmp_jcl= @@join_cache_level;
24
set @tmp_opt= @@optimizer_switch;
35

mysql-test/main/opt_hints_join_order.result

+8
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,14 @@ INSERT INTO t2 (id, f2) VALUES
13361336
(4,5),(3,3),(1,0),(1,3),(6,1),(2,0),(4,1),(2,7),(2,1),(1,0),(3,0),(5,8),(5,4),
13371337
(3,9),(2,0),(7,2),(2,0),(1,8),(6,5),(4,1);
13381338
CREATE TABLE tn (fn_1 INT, fn_2 INT);
1339+
ANALYZE TABLE t1, t2, tn;
1340+
Table Op Msg_type Msg_text
1341+
test.t1 analyze status Engine-independent statistics collected
1342+
test.t1 analyze status OK
1343+
test.t2 analyze status Engine-independent statistics collected
1344+
test.t2 analyze status OK
1345+
test.tn analyze status Engine-independent statistics collected
1346+
test.tn analyze status OK
13391347
EXPLAIN EXTENDED
13401348
INSERT INTO tn (fn_1, fn_2)
13411349
SELECT /*+ JOIN_ORDER(t2,t1) JOIN_FIXED_ORDER() */ f1,f2

mysql-test/main/opt_hints_join_order.test

+2
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ INSERT INTO t2 (id, f2) VALUES
807807

808808
CREATE TABLE tn (fn_1 INT, fn_2 INT);
809809

810+
ANALYZE TABLE t1, t2, tn;
811+
810812
EXPLAIN EXTENDED
811813
INSERT INTO tn (fn_1, fn_2)
812814
SELECT /*+ JOIN_ORDER(t2,t1) JOIN_FIXED_ORDER() */ f1,f2

sql/share/errmsg-utf8.txt

+2
Original file line numberDiff line numberDiff line change
@@ -12325,3 +12325,5 @@ ER_HINTS_INSIDE_VIEWS_NOT_SUPPORTED
1232512325
eng "Optimizer hints are not supported inside view definitions"
1232612326
ER_WARN_MALFORMED_HINT
1232712327
eng "Hint %s is ignored as malformed"
12328+
ER_WARN_HINTS_ON_INSERT_PART_OF_INSERT_SELECT
12329+
eng "Optimizer hints at the INSERT part of a INSERT..SELECT statement are not supported"

sql/sql_lex.cc

+34-12
Original file line numberDiff line numberDiff line change
@@ -11185,22 +11185,17 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
1118511185
return true;
1118611186

1118711187
// fix "main" select
11188-
resolve_optimizer_hints_in_last_select();
11188+
if (discard_optimizer_hints_in_last_select())
11189+
{
11190+
// Hints were specified at the INSERT part of an INSERT..SELECT
11191+
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
11192+
ER_WARN_HINTS_ON_INSERT_PART_OF_INSERT_SELECT,
11193+
ER_THD(thd, ER_WARN_HINTS_ON_INSERT_PART_OF_INSERT_SELECT));
11194+
}
1118911195
SELECT_LEX *blt __attribute__((unused))= pop_select();
1119011196
DBUG_ASSERT(blt == &builtin_select);
1119111197
push_select(first_select);
1119211198

11193-
// INSERT..SELECT allows placing hints next to either INSERT or SELECT, i.e.:
11194-
// `INSERT /* hint(t1) */ INTO t2 SELECT a FROM t1` or
11195-
// `INSERT INTO t2 SELECT /* hint(t1) */ a FROM t1`
11196-
// but not at both places at the same time.
11197-
// `first_select` represents the SELECT part here while `builtin_select` -
11198-
// the INSERT part. Future processing will proceed with `first_select`,
11199-
// so transfer the hints from `builtin_select` to `first_select` in case
11200-
// they were not already set. If hints are present for both INSERT and SELECT
11201-
// parts, SELECT part hints are preserved while INSERT part hints are discarded
11202-
if (!first_select->opt_hints_qb && blt->opt_hints_qb)
11203-
first_select->opt_hints_qb= blt->opt_hints_qb;
1120411199
return false;
1120511200
}
1120611201

@@ -13004,3 +12999,30 @@ void LEX::resolve_optimizer_hints_in_last_select()
1300412999
select_lex->parsed_optimizer_hints->resolve(&pc);
1300513000
}
1300613001
}
13002+
13003+
/*
13004+
This method discards previously parsed optimizer hints attached to
13005+
the last select_lex without their resolving, which may be required
13006+
in some scenarios (for example, ignoring hints at the INSERT part of a
13007+
INSERT..SELECT statement).
13008+
13009+
Also see resolve_optimizer_hints_in_last_select().
13010+
13011+
Return value:
13012+
- false optimizer hints were not found
13013+
- true optimizer hints were found and discarded
13014+
*/
13015+
bool LEX::discard_optimizer_hints_in_last_select()
13016+
{
13017+
SELECT_LEX *select_lex;
13018+
if (likely(select_stack_top))
13019+
select_lex= select_stack[select_stack_top - 1];
13020+
else
13021+
select_lex= nullptr;
13022+
if (select_lex && select_lex->parsed_optimizer_hints)
13023+
{
13024+
select_lex->parsed_optimizer_hints= nullptr;
13025+
return true;
13026+
}
13027+
return false;
13028+
}

sql/sql_lex.h

+2
Original file line numberDiff line numberDiff line change
@@ -3758,6 +3758,8 @@ struct LEX: public Query_tables_list
37583758

37593759
void resolve_optimizer_hints_in_last_select();
37603760

3761+
bool discard_optimizer_hints_in_last_select();
3762+
37613763
SELECT_LEX *current_select_or_default()
37623764
{
37633765
return current_select ? current_select : &builtin_select;

0 commit comments

Comments
 (0)