mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-25080 Fix incorrect view names in printed queries
When printing Item_direct_view_ref the printed 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`. But if the view was merged then the initial `q` does not make sense any more so field `a` must be printed as `t1`.`a`
This commit is contained in:
committed by
Sergei Golubchik
parent
b5507c738f
commit
47e29a2ff4
@@ -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
|
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
|
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
|
||||||
Warnings:
|
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
|
# Status of EXPLAIN EXTENDED query
|
||||||
Variable_name Value
|
Variable_name Value
|
||||||
Handler_read_key 3
|
Handler_read_key 3
|
||||||
|
@@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -381,6 +381,7 @@ connection slave;
|
|||||||
DROP TABLES federated.t1, federated.t2, federated.t3, federated.t10,
|
DROP TABLES federated.t1, federated.t2, federated.t3, federated.t10,
|
||||||
federated.t11;
|
federated.t11;
|
||||||
|
|
||||||
|
|
||||||
--echo # MDEV-25080: Allow pushdown of queries involving UNIONs
|
--echo # MDEV-25080: Allow pushdown of queries involving UNIONs
|
||||||
--echo # in outer select to foreign engines
|
--echo # in outer select to foreign engines
|
||||||
--echo #
|
--echo #
|
||||||
|
19
sql/item.cc
19
sql/item.cc
@@ -10866,6 +10866,25 @@ table_map Item_direct_view_ref::not_null_tables() const
|
|||||||
return get_null_ref_table()->map;
|
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
|
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
|
||||||
*/
|
*/
|
||||||
|
@@ -6238,6 +6238,7 @@ public:
|
|||||||
Item *field_transformer_for_having_pushdown(THD *, uchar *) override
|
Item *field_transformer_for_having_pushdown(THD *, uchar *) override
|
||||||
{ return this; }
|
{ return this; }
|
||||||
Item *remove_item_direct_ref() override { return this; }
|
Item *remove_item_direct_ref() override { return this; }
|
||||||
|
void print(String *str, enum_query_type query_type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user