Skip to content

Commit 5ab153c

Browse files
MDEV-37389 Hint NO_MERGE(@qb_name) is accepted but has no effect
Allows [NO_]MERGE(@qb_name) and [NO_]MERGE() to apply to all tables in a target named query block and all tables in the current query block, respectively. Repairs a bug when fixing hints for derived tables that prevented derived tables from being linked with a query block's hints in the case that no derived tables were explicitly specified in the query.
1 parent 0316c6e commit 5ab153c

File tree

3 files changed

+302
-19
lines changed

3 files changed

+302
-19
lines changed

mysql-test/main/opt_hints_merge.result

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,180 @@ Warning 4221 Unresolved table name `bar`@`select#1` for NO_MERGE hint
467467
Warning 4221 Unresolved table name `foo`@`select#1` for NO_MERGE hint
468468
drop table t1, t2;
469469
drop view v1, v2;
470+
set session optimizer_switch='derived_merge=on';
471+
#
472+
# MDEV-37389 Hint NO_MERGE(@qb_name) is accepted but has no effect
473+
#
474+
CREATE TABLE employees (
475+
emp_id INT PRIMARY KEY,
476+
emp_name VARCHAR(100),
477+
department VARCHAR(50)
478+
);
479+
CREATE TABLE salaries (
480+
emp_id INT,
481+
salary DECIMAL(10, 2),
482+
FOREIGN KEY (emp_id) REFERENCES employees(emp_id)
483+
);
484+
INSERT INTO employees (emp_id, emp_name, department) VALUES
485+
(101, 'Alice', 'Engineering'),
486+
(102, 'Bob', 'Engineering');
487+
INSERT INTO salaries (emp_id, salary) VALUES
488+
(101, 120000.00),
489+
(102, 95000.00);
490+
EXPLAIN EXTENDED SELECT /*+ NO_MERGE() */ e.emp_name, s.salary FROM (
491+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
492+
id select_type table type possible_keys key key_len ref rows filtered Extra
493+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
494+
1 PRIMARY <derived3> ref key0 key0 5 e.emp_id 1 100.00
495+
3 DERIVED salaries ALL NULL NULL NULL NULL 2 100.00
496+
2 DERIVED employees ALL NULL NULL NULL NULL 2 100.00
497+
Warnings:
498+
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`select#1`) */ `e`.`emp_name` AS `emp_name`,`s`.`salary` AS `salary` from (/* select#2 */ select `test`.`employees`.`emp_id` AS `emp_id`,`test`.`employees`.`emp_name` AS `emp_name`,`test`.`employees`.`department` AS `department` from `test`.`employees`) `e` join (/* select#3 */ select `test`.`salaries`.`emp_id` AS `emp_id`,`test`.`salaries`.`salary` AS `salary` from `test`.`salaries`) `s` where `s`.`emp_id` = `e`.`emp_id`
499+
EXPLAIN EXTENDED SELECT /*+ QB_NAME(foo) NO_MERGE(@`foo`) */ e.emp_name, s.salary FROM (
500+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
501+
id select_type table type possible_keys key key_len ref rows filtered Extra
502+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
503+
1 PRIMARY <derived3> ref key0 key0 5 e.emp_id 1 100.00
504+
3 DERIVED salaries ALL NULL NULL NULL NULL 2 100.00
505+
2 DERIVED employees ALL NULL NULL NULL NULL 2 100.00
506+
Warnings:
507+
Note 1003 /* select#1 */ select /*+ QB_NAME(`foo`) NO_MERGE(@`foo`) */ `e`.`emp_name` AS `emp_name`,`s`.`salary` AS `salary` from (/* select#2 */ select `test`.`employees`.`emp_id` AS `emp_id`,`test`.`employees`.`emp_name` AS `emp_name`,`test`.`employees`.`department` AS `department` from `test`.`employees`) `e` join (/* select#3 */ select `test`.`salaries`.`emp_id` AS `emp_id`,`test`.`salaries`.`salary` AS `salary` from `test`.`salaries`) `s` where `s`.`emp_id` = `e`.`emp_id`
508+
EXPLAIN EXTENDED
509+
select /*+ NO_MERGE() */ emp_id from (
510+
select /*+ NO_MERGE() */ emp_id from (
511+
select /*+ NO_MERGE() */ emp_id from (
512+
select /*+ NO_MERGE() */ emp_id from (
513+
select emp_id from employees) dt) du) dv) dw;
514+
id select_type table type possible_keys key key_len ref rows filtered Extra
515+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
516+
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00
517+
3 DERIVED <derived4> ALL NULL NULL NULL NULL 2 100.00
518+
4 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00
519+
5 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
520+
Warnings:
521+
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`select#4`) NO_MERGE(@`select#3`) NO_MERGE(@`select#2`) NO_MERGE(@`select#1`) */ `dw`.`emp_id` AS `emp_id` from (/* select#2 */ select `dv`.`emp_id` AS `emp_id` from (/* select#3 */ select `du`.`emp_id` AS `emp_id` from (/* select#4 */ select `dt`.`emp_id` AS `emp_id` from (/* select#5 */ select `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `dt`) `du`) `dv`) `dw`
522+
EXPLAIN EXTENDED
523+
select /*+ NO_MERGE(@qb4) */ emp_id from (
524+
select /*+ QB_NAME(qb2) */ emp_id from (
525+
select /*+ QB_NAME(qb3) */ emp_id from (
526+
select /*+ QB_NAME(qb4) */ emp_id from (
527+
select emp_id from employees) dt) du) dv) dw;
528+
id select_type table type possible_keys key key_len ref rows filtered Extra
529+
1 PRIMARY <derived5> ALL NULL NULL NULL NULL 2 100.00
530+
5 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
531+
Warnings:
532+
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`qb4`) */ `dt`.`emp_id` AS `emp_id` from (/* select#5 */ select `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `dt`
533+
EXPLAIN EXTENDED
534+
select /*+ NO_MERGE(@qb3) */ emp_id from (
535+
select /*+ QB_NAME(qb2) */ emp_id from (
536+
select /*+ QB_NAME(qb3) */ emp_id from (
537+
select /*+ QB_NAME(qb4) */ emp_id from (
538+
select emp_id from employees) dt) du) dv) dw;
539+
id select_type table type possible_keys key key_len ref rows filtered Extra
540+
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 2 100.00
541+
4 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
542+
Warnings:
543+
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`qb3`) */ `du`.`emp_id` AS `emp_id` from (/* select#4 */ select /*+ QB_NAME(`qb4`) */ `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `du`
544+
EXPLAIN EXTENDED
545+
select /*+ NO_MERGE(@qb2) */ emp_id from (
546+
select /*+ QB_NAME(qb2) */ emp_id from (
547+
select /*+ QB_NAME(qb3) */ emp_id from (
548+
select /*+ QB_NAME(qb4) */ emp_id from (
549+
select emp_id from employees) dt) du) dv) dw;
550+
id select_type table type possible_keys key key_len ref rows filtered Extra
551+
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00
552+
3 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
553+
Warnings:
554+
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`qb2`) */ `dv`.`emp_id` AS `emp_id` from (/* select#3 */ select /*+ QB_NAME(`qb3`) */ `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `dv`
555+
EXPLAIN EXTENDED
556+
select /*+ NO_MERGE(@qb2) NO_MERGE(@qb4) */ emp_id from (
557+
select /*+ QB_NAME(qb2) */ emp_id from (
558+
select /*+ QB_NAME(qb3) */ emp_id from (
559+
select /*+ QB_NAME(qb4) */ emp_id from (
560+
select emp_id from employees) dt) du) dv) dw;
561+
id select_type table type possible_keys key key_len ref rows filtered Extra
562+
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00
563+
3 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00
564+
5 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
565+
Warnings:
566+
Note 1003 /* select#1 */ select /*+ NO_MERGE(@`qb4`) NO_MERGE(@`qb2`) */ `dv`.`emp_id` AS `emp_id` from (/* select#3 */ select /*+ QB_NAME(`qb3`) */ `dt`.`emp_id` AS `emp_id` from (/* select#5 */ select `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `dt`) `dv`
567+
# Test the MERGE hint variant
568+
set session optimizer_switch='derived_merge=off';
569+
EXPLAIN EXTENDED SELECT /*+ MERGE() */ e.emp_name, s.salary FROM (
570+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
571+
id select_type table type possible_keys key key_len ref rows filtered Extra
572+
1 SIMPLE salaries ALL emp_id NULL NULL NULL 2 100.00 Using where
573+
1 SIMPLE employees eq_ref PRIMARY PRIMARY 4 test.salaries.emp_id 1 100.00
574+
Warnings:
575+
Note 1003 select /*+ MERGE(@`select#1`) */ `test`.`employees`.`emp_name` AS `emp_name`,`test`.`salaries`.`salary` AS `salary` from `test`.`employees` join `test`.`salaries` where `test`.`employees`.`emp_id` = `test`.`salaries`.`emp_id`
576+
EXPLAIN EXTENDED SELECT /*+ QB_NAME(foo) MERGE(@`foo`) */ e.emp_name, s.salary FROM (
577+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
578+
id select_type table type possible_keys key key_len ref rows filtered Extra
579+
1 SIMPLE salaries ALL emp_id NULL NULL NULL 2 100.00 Using where
580+
1 SIMPLE employees eq_ref PRIMARY PRIMARY 4 test.salaries.emp_id 1 100.00
581+
Warnings:
582+
Note 1003 select /*+ QB_NAME(`foo`) MERGE(@`foo`) */ `test`.`employees`.`emp_name` AS `emp_name`,`test`.`salaries`.`salary` AS `salary` from `test`.`employees` join `test`.`salaries` where `test`.`employees`.`emp_id` = `test`.`salaries`.`emp_id`
583+
EXPLAIN EXTENDED
584+
select /*+ MERGE() */ emp_id from (
585+
select /*+ MERGE() */ emp_id from (
586+
select /*+ MERGE() */ emp_id from (
587+
select /*+ MERGE() */ emp_id from (
588+
select emp_id from employees) dt) du) dv) dw;
589+
id select_type table type possible_keys key key_len ref rows filtered Extra
590+
1 SIMPLE employees index NULL PRIMARY 4 NULL 2 100.00 Using index
591+
Warnings:
592+
Note 1003 select /*+ MERGE(@`select#4`) MERGE(@`select#3`) MERGE(@`select#2`) MERGE(@`select#1`) */ `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`
593+
EXPLAIN EXTENDED
594+
select /*+ MERGE(@qb4) */ emp_id from (
595+
select /*+ QB_NAME(qb2) */ emp_id from (
596+
select /*+ QB_NAME(qb3) */ emp_id from (
597+
select /*+ QB_NAME(qb4) */ emp_id from (
598+
select emp_id from employees) dt) du) dv) dw;
599+
id select_type table type possible_keys key key_len ref rows filtered Extra
600+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
601+
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00
602+
3 DERIVED <derived4> ALL NULL NULL NULL NULL 2 100.00
603+
4 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
604+
Warnings:
605+
Note 1003 /* select#1 */ select /*+ MERGE(@`qb4`) */ `dw`.`emp_id` AS `emp_id` from (/* select#2 */ select /*+ QB_NAME(`qb2`) */ `dv`.`emp_id` AS `emp_id` from (/* select#3 */ select /*+ QB_NAME(`qb3`) */ `du`.`emp_id` AS `emp_id` from (/* select#4 */ select /*+ QB_NAME(`qb4`) */ `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `du`) `dv`) `dw`
606+
EXPLAIN EXTENDED
607+
select /*+ MERGE(@qb3) */ emp_id from (
608+
select /*+ QB_NAME(qb2) */ emp_id from (
609+
select /*+ QB_NAME(qb3) */ emp_id from (
610+
select /*+ QB_NAME(qb4) */ emp_id from (
611+
select emp_id from employees) dt) du) dv) dw;
612+
id select_type table type possible_keys key key_len ref rows filtered Extra
613+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
614+
2 DERIVED <derived3> ALL NULL NULL NULL NULL 2 100.00
615+
3 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00
616+
5 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
617+
Warnings:
618+
Note 1003 /* select#1 */ select /*+ MERGE(@`qb3`) */ `dw`.`emp_id` AS `emp_id` from (/* select#2 */ select /*+ QB_NAME(`qb2`) */ `dv`.`emp_id` AS `emp_id` from (/* select#3 */ select /*+ QB_NAME(`qb3`) */ `dt`.`emp_id` AS `emp_id` from (/* select#5 */ select `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `dt`) `dv`) `dw`
619+
EXPLAIN EXTENDED
620+
select /*+ MERGE(@qb2) */ emp_id from (
621+
select /*+ QB_NAME(qb2) */ emp_id from (
622+
select /*+ QB_NAME(qb3) */ emp_id from (
623+
select /*+ QB_NAME(qb4) */ emp_id from (
624+
select emp_id from employees) dt) du) dv) dw;
625+
id select_type table type possible_keys key key_len ref rows filtered Extra
626+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
627+
2 DERIVED <derived4> ALL NULL NULL NULL NULL 2 100.00
628+
4 DERIVED <derived5> ALL NULL NULL NULL NULL 2 100.00
629+
5 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
630+
Warnings:
631+
Note 1003 /* select#1 */ select /*+ MERGE(@`qb2`) */ `dw`.`emp_id` AS `emp_id` from (/* select#2 */ select /*+ QB_NAME(`qb2`) */ `du`.`emp_id` AS `emp_id` from (/* select#4 */ select /*+ QB_NAME(`qb4`) */ `dt`.`emp_id` AS `emp_id` from (/* select#5 */ select `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `dt`) `du`) `dw`
632+
EXPLAIN EXTENDED
633+
select /*+ MERGE(@qb2) MERGE(@qb4) */ emp_id from (
634+
select /*+ QB_NAME(qb2) */ emp_id from (
635+
select /*+ QB_NAME(qb3) */ emp_id from (
636+
select /*+ QB_NAME(qb4) */ emp_id from (
637+
select emp_id from employees) dt) du) dv) dw;
638+
id select_type table type possible_keys key key_len ref rows filtered Extra
639+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
640+
2 DERIVED <derived4> ALL NULL NULL NULL NULL 2 100.00
641+
4 DERIVED employees index NULL PRIMARY 4 NULL 2 100.00 Using index
642+
Warnings:
643+
Note 1003 /* select#1 */ select /*+ MERGE(@`qb4`) MERGE(@`qb2`) */ `dw`.`emp_id` AS `emp_id` from (/* select#2 */ select /*+ QB_NAME(`qb2`) */ `du`.`emp_id` AS `emp_id` from (/* select#4 */ select /*+ QB_NAME(`qb4`) */ `test`.`employees`.`emp_id` AS `emp_id` from `test`.`employees`) `du`) `dw`
644+
set session optimizer_switch='derived_merge=on';
645+
DROP TABLE employees, salaries;
646+
# End of 12.1 tests

mysql-test/main/opt_hints_merge.test

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,117 @@ SELECT /*+ NO_MERGE(bar) NO_MERGE(foo) */ a, b FROM (SELECT i as a, j as b FROM
9292

9393
drop table t1, t2;
9494
drop view v1, v2;
95+
set session optimizer_switch='derived_merge=on';
9596
--enable_view_protocol
97+
98+
--echo #
99+
--echo # MDEV-37389 Hint NO_MERGE(@qb_name) is accepted but has no effect
100+
--echo #
101+
CREATE TABLE employees (
102+
emp_id INT PRIMARY KEY,
103+
emp_name VARCHAR(100),
104+
department VARCHAR(50)
105+
);
106+
107+
CREATE TABLE salaries (
108+
emp_id INT,
109+
salary DECIMAL(10, 2),
110+
FOREIGN KEY (emp_id) REFERENCES employees(emp_id)
111+
);
112+
113+
INSERT INTO employees (emp_id, emp_name, department) VALUES
114+
(101, 'Alice', 'Engineering'),
115+
(102, 'Bob', 'Engineering');
116+
INSERT INTO salaries (emp_id, salary) VALUES
117+
(101, 120000.00),
118+
(102, 95000.00);
119+
120+
EXPLAIN EXTENDED SELECT /*+ NO_MERGE() */ e.emp_name, s.salary FROM (
121+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
122+
123+
EXPLAIN EXTENDED SELECT /*+ QB_NAME(foo) NO_MERGE(@`foo`) */ e.emp_name, s.salary FROM (
124+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
125+
126+
EXPLAIN EXTENDED
127+
select /*+ NO_MERGE() */ emp_id from (
128+
select /*+ NO_MERGE() */ emp_id from (
129+
select /*+ NO_MERGE() */ emp_id from (
130+
select /*+ NO_MERGE() */ emp_id from (
131+
select emp_id from employees) dt) du) dv) dw;
132+
133+
EXPLAIN EXTENDED
134+
select /*+ NO_MERGE(@qb4) */ emp_id from (
135+
select /*+ QB_NAME(qb2) */ emp_id from (
136+
select /*+ QB_NAME(qb3) */ emp_id from (
137+
select /*+ QB_NAME(qb4) */ emp_id from (
138+
select emp_id from employees) dt) du) dv) dw;
139+
140+
EXPLAIN EXTENDED
141+
select /*+ NO_MERGE(@qb3) */ emp_id from (
142+
select /*+ QB_NAME(qb2) */ emp_id from (
143+
select /*+ QB_NAME(qb3) */ emp_id from (
144+
select /*+ QB_NAME(qb4) */ emp_id from (
145+
select emp_id from employees) dt) du) dv) dw;
146+
147+
EXPLAIN EXTENDED
148+
select /*+ NO_MERGE(@qb2) */ emp_id from (
149+
select /*+ QB_NAME(qb2) */ emp_id from (
150+
select /*+ QB_NAME(qb3) */ emp_id from (
151+
select /*+ QB_NAME(qb4) */ emp_id from (
152+
select emp_id from employees) dt) du) dv) dw;
153+
154+
EXPLAIN EXTENDED
155+
select /*+ NO_MERGE(@qb2) NO_MERGE(@qb4) */ emp_id from (
156+
select /*+ QB_NAME(qb2) */ emp_id from (
157+
select /*+ QB_NAME(qb3) */ emp_id from (
158+
select /*+ QB_NAME(qb4) */ emp_id from (
159+
select emp_id from employees) dt) du) dv) dw;
160+
161+
--echo # Test the MERGE hint variant
162+
set session optimizer_switch='derived_merge=off';
163+
164+
EXPLAIN EXTENDED SELECT /*+ MERGE() */ e.emp_name, s.salary FROM (
165+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
166+
167+
EXPLAIN EXTENDED SELECT /*+ QB_NAME(foo) MERGE(@`foo`) */ e.emp_name, s.salary FROM (
168+
select * from employees) e JOIN (select * from salaries) s ON e.emp_id = s.emp_id;
169+
170+
EXPLAIN EXTENDED
171+
select /*+ MERGE() */ emp_id from (
172+
select /*+ MERGE() */ emp_id from (
173+
select /*+ MERGE() */ emp_id from (
174+
select /*+ MERGE() */ emp_id from (
175+
select emp_id from employees) dt) du) dv) dw;
176+
177+
EXPLAIN EXTENDED
178+
select /*+ MERGE(@qb4) */ emp_id from (
179+
select /*+ QB_NAME(qb2) */ emp_id from (
180+
select /*+ QB_NAME(qb3) */ emp_id from (
181+
select /*+ QB_NAME(qb4) */ emp_id from (
182+
select emp_id from employees) dt) du) dv) dw;
183+
184+
EXPLAIN EXTENDED
185+
select /*+ MERGE(@qb3) */ emp_id from (
186+
select /*+ QB_NAME(qb2) */ emp_id from (
187+
select /*+ QB_NAME(qb3) */ emp_id from (
188+
select /*+ QB_NAME(qb4) */ emp_id from (
189+
select emp_id from employees) dt) du) dv) dw;
190+
191+
EXPLAIN EXTENDED
192+
select /*+ MERGE(@qb2) */ emp_id from (
193+
select /*+ QB_NAME(qb2) */ emp_id from (
194+
select /*+ QB_NAME(qb3) */ emp_id from (
195+
select /*+ QB_NAME(qb4) */ emp_id from (
196+
select emp_id from employees) dt) du) dv) dw;
197+
198+
EXPLAIN EXTENDED
199+
select /*+ MERGE(@qb2) MERGE(@qb4) */ emp_id from (
200+
select /*+ QB_NAME(qb2) */ emp_id from (
201+
select /*+ QB_NAME(qb3) */ emp_id from (
202+
select /*+ QB_NAME(qb4) */ emp_id from (
203+
select emp_id from employees) dt) du) dv) dw;
204+
205+
set session optimizer_switch='derived_merge=on';
206+
DROP TABLE employees, salaries;
207+
208+
--echo # End of 12.1 tests

sql/opt_hints.cc

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct st_opt_hint_info opt_hint_info[]=
4646
{{STRING_WITH_LEN("JOIN_ORDER")}, false, true, true},
4747
{{STRING_WITH_LEN("JOIN_FIXED_ORDER")}, false, true, false},
4848
{{STRING_WITH_LEN("DERIVED_CONDITION_PUSHDOWN")}, false, false, false},
49-
{{STRING_WITH_LEN("MERGE")}, false, false, false},
49+
{{STRING_WITH_LEN("MERGE")}, true, false, false},
5050
{{STRING_WITH_LEN("SPLIT_MATERIALIZED")}, false, false, false},
5151
{{STRING_WITH_LEN("INDEX")}, false, true, false},
5252
{{STRING_WITH_LEN("JOIN_INDEX")}, false, true, false},
@@ -432,34 +432,27 @@ Opt_hints_qb::Opt_hints_qb(Opt_hints *opt_hints_arg,
432432

433433
void Opt_hints_qb::fix_hints_for_derived_table(TABLE_LIST *table_list)
434434
{
435-
Opt_hints_table *tab=
436-
static_cast<Opt_hints_table *>(find_by_name(table_list->alias));
437-
438-
/*
439-
If this is fixed and the corresponding Opt_hints_table doesn't exist (or it
440-
exists and is fixed) then there's nothing to do, so return early.
441-
*/
442-
if (are_all_fixed() && (!tab || tab->are_all_fixed()))
443-
return;
435+
DBUG_ASSERT(table_list->is_view_or_derived());
436+
DBUG_ASSERT(!table_list->opt_hints_qb ||
437+
(table_list->opt_hints_qb == this));
438+
table_list->opt_hints_qb= this;
444439

445440
/*
446441
This instance will have been marked as fixed on the basis of its
447-
attachment to a SELECT_LEX (during get_qb_hints) but that is
448-
insufficient to consider it fixed for the case where a TABLE
449-
instance is required but not yet available. If the associated
450-
table isn't yet fixed, then fix this hint as though it were unfixed.
442+
attachment to a SELECT_LEX (during get_qb_hints).
451443
452-
We mark the Opt_hints_table as 'fixed' here and this means we
444+
We mark the opt_hints_table as 'fixed' here and this means we
453445
won't try to fix the child hints again later. They will remain
454446
unfixed and will eventually produce "Unresolved index name" error
455447
in opt_hints_qb->check_unfixed(). This is acceptable because
456448
no child hints apply to derived tables.
457449
*/
458450
DBUG_ASSERT(!table_list->opt_hints_table);
459-
DBUG_ASSERT(tab);
460-
table_list->opt_hints_qb= this;
461-
table_list->opt_hints_table= tab;
462-
tab->set_fixed();
451+
table_list->opt_hints_table=
452+
static_cast<Opt_hints_table *>(find_by_name(table_list->alias));
453+
if (!table_list->opt_hints_table)
454+
return;
455+
table_list->opt_hints_table->set_fixed();
463456
}
464457

465458

0 commit comments

Comments
 (0)