diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 3d2af9f80a4..eaeb371d535 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -2723,7 +2723,7 @@ EXPLAIN EXTENDED DELETE FROM v1 WHERE a < 4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where Warnings: -Note 1003 /* select#1 */ delete from `test`.`t1` using dual where `test`.`t1`.`a` < 4 +Note 1003 /* select#1 */ delete from `test`.`t1` using dual where `v1`.`a` < 4 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 1342bc65f17..1d96bfded34 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -59,7 +59,7 @@ select * from v1 { } }, { - "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from v1" + "expanded_query": "/* select#1 */ select v1.a AS a,v1.b AS b from v1" } ] } @@ -230,7 +230,7 @@ select * from (select * from t1 where t1.a=1)q { } }, { - "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from (/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1) q" + "expanded_query": "/* select#1 */ select q.a AS a,q.b AS b from (/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1) q" } ] } @@ -695,7 +695,7 @@ explain select * from v2 { } }, { - "expanded_query": "/* select#1 */ select t2.a AS a from v2" + "expanded_query": "/* select#1 */ select v2.a AS a from v2" } ] } diff --git a/mysql-test/main/opt_trace_security.result b/mysql-test/main/opt_trace_security.result index 9ef6cadec5f..cf5dcf5d886 100644 --- a/mysql-test/main/opt_trace_security.result +++ b/mysql-test/main/opt_trace_security.result @@ -197,7 +197,7 @@ select * from db1.v1 { } }, { - "expanded_query": "/* select#1 */ select db1.t1.a AS a from v1" + "expanded_query": "/* select#1 */ select v1.a AS a from v1" } ] } diff --git a/mysql-test/suite/federated/federatedx_create_handlers.test b/mysql-test/suite/federated/federatedx_create_handlers.test index bb4305da306..d4222087ea7 100644 --- a/mysql-test/suite/federated/federatedx_create_handlers.test +++ b/mysql-test/suite/federated/federatedx_create_handlers.test @@ -381,6 +381,7 @@ connection slave; DROP TABLES federated.t1, federated.t2, federated.t3, federated.t10, federated.t11; + --echo # MDEV-25080: Allow pushdown of queries involving UNIONs --echo # in outer select to foreign engines --echo # diff --git a/sql/item.cc b/sql/item.cc index c55348bcdf3..a07b5532f83 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -10866,6 +10866,25 @@ table_map Item_direct_view_ref::not_null_tables() const return get_null_ref_table()->map; } +void Item_direct_view_ref::print(String *str, enum_query_type query_type) +{ + /* + If the view/derived table was not merged then this field name must + be complemented with the view name/derived table alias. + For example, for "SELECT a FROM (SELECT a FROM t1) q" field `a` in the + select list must be printed as `q`.`a`. + Ancestor class Item_ident contains the correct table_name for that case. + But if the view was merged then the initial `q` does not make sense + any more so print the Item_ref contents. Field `a` will be printed + as `t1`.`a` then + */ + if (!view->merged) + Item_ident::print(str, query_type); + else + Item_ref::print(str, query_type); + +} + /* we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE */ diff --git a/sql/item.h b/sql/item.h index ae503636116..bfc261e204c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -6238,6 +6238,7 @@ public: Item *field_transformer_for_having_pushdown(THD *, uchar *) override { return this; } Item *remove_item_direct_ref() override { return this; } + void print(String *str, enum_query_type query_type) override; };