[Commits] db844d2c6e6: TVC fix
revision-id: db844d2c6e6f8e0d7b45631f9335759f41f5a6bf (mariadb-10.4.4-101-gdb844d2c6e6) parent(s): bcb5ba8f3c3b955f0b83590c7098df5d98c1c01f author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-05-18 09:11:47 +0200 message: TVC fix --- mysql-test/main/table_value_constr.result | 20 ++++++++++---------- .../suite/compat/oracle/r/table_value_constr.result | 20 ++++++++++---------- sql/sql_lex.cc | 10 ++++++++++ sql/sql_union.cc | 19 ++++++++++++++++++- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result index 318d0a76663..51198ea47d6 100644 --- a/mysql-test/main/table_value_constr.result +++ b/mysql-test/main/table_value_constr.result @@ -2337,8 +2337,8 @@ Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union /* select#2 */ select 2 A 2 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2) union select 2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Warnings: @@ -2350,8 +2350,8 @@ Note 1003 (/* select#1 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3) 2 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2 offset 1) union select 2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Warnings: @@ -2398,8 +2398,8 @@ Note 1003 /* select#1 */ select 3 AS `3` union all (/* select#3 */ select `tvc_0 3 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2) union all select 3; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Warnings: @@ -2459,8 +2459,8 @@ Note 1003 (values (5),(7),(1),(3),(4) limit 3,2) union all /* select#2 */ select 5 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: @@ -2473,8 +2473,8 @@ order by 1 limit 2 offset 1; explain extended (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1 limit 2 offset 1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: diff --git a/mysql-test/suite/compat/oracle/r/table_value_constr.result b/mysql-test/suite/compat/oracle/r/table_value_constr.result index f0c7c4eebe1..3e72167d43d 100644 --- a/mysql-test/suite/compat/oracle/r/table_value_constr.result +++ b/mysql-test/suite/compat/oracle/r/table_value_constr.result @@ -2331,8 +2331,8 @@ Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union /* select#2 */ select 2 A 2 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2) union select 2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Warnings: @@ -2344,8 +2344,8 @@ Note 1003 (/* select#1 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3) 2 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2 offset 1) union select 2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Warnings: @@ -2392,8 +2392,8 @@ Note 1003 /* select#1 */ select 3 AS "3" union all (/* select#3 */ select "tvc_0 3 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2) union all select 3; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Warnings: @@ -2453,8 +2453,8 @@ Note 1003 (values (5),(7),(1),(3),(4) limit 3,2) union all /* select#2 */ select 5 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: @@ -2467,8 +2467,8 @@ order by 1 limit 2 offset 1; explain extended (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1 limit 2 offset 1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SUBQUERY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort -3 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 Using filesort +3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index c02263a1ce7..fecf6d1d723 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -9283,6 +9283,16 @@ SELECT_LEX_UNIT *LEX::parsed_body_select(SELECT_LEX *sel, return NULL; SELECT_LEX_UNIT *res= create_unit(sel); + if (res && sel->tvc && sel->order_list.elements) + { + if (res->add_fake_select_lex(thd)) + return NULL; + SELECT_LEX *fake= res->fake_select_lex; + fake->order_list= sel->order_list; + fake->explicit_limit= sel->explicit_limit; + fake->select_limit= sel->select_limit; + fake->offset_limit= sel->offset_limit; + } return res; } diff --git a/sql/sql_union.cc b/sql/sql_union.cc index c9c260548c1..c40e0cf84f8 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -982,7 +982,24 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, types= first_sl->item_list; goto cont; } - + + if (sl->tvc && sl->order_list.elements && + !sl->tvc->to_be_wrapped_as_with_tail()) + { + if (thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW) + { + sl->master_unit()->fake_select_lex= 0; + sl->master_unit()->saved_fake_select_lex= 0; + } + else + { + sl->order_list.empty(); + sl->explicit_limit= 0; + sl->select_limit= 0; + sl->offset_limit= 0; + } + } + for (;sl; sl= sl->next_select(), union_part_count++) { if (sl->tvc)
participants (1)
-
Oleksandr Byelkin