1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Fixed bug mdev-9028.

This patch is actually a complement for the fix of bug mdev-6892.
The procedure create_tmp_table() now must take into account
Item_direct_refs that wrap up constant fields of derived tables/views
that are used as inner tables in outer join operations.
This commit is contained in:
Igor Babaev
2017-02-16 23:44:54 -08:00
parent b70cd26d73
commit f49375fddf
3 changed files with 49 additions and 1 deletions

View File

@@ -988,4 +988,27 @@ David Yes 210
Edward Yes 150 Edward Yes 150
DROP TABLE example1463; DROP TABLE example1463;
set sql_mode= @save_sql_mode; set sql_mode= @save_sql_mode;
#
# MDEV-9028: SELECT DISTINCT constant column of derived table
# used as the second operand of LEFT JOIN
#
create table t1 (id int, data varchar(255));
insert into t1 values (1,'yes'),(2,'yes');
select distinct t1.id, tt.id, tt.data
from t1
left join
(select t1.id, 'yes' as data from t1) as tt
on t1.id = tt.id;
id id data
1 1 yes
2 2 yes
select distinct t1.id, tt.id, tt.data
from t1
left join
(select t1.id, 'yes' as data from t1 where id > 1) as tt
on t1.id = tt.id;
id id data
2 2 yes
1 NULL NULL
drop table t1;
# end of 5.5 # end of 5.5

View File

@@ -842,4 +842,27 @@ SELECT Customer, Success, SUM(OrderSize)
DROP TABLE example1463; DROP TABLE example1463;
set sql_mode= @save_sql_mode; set sql_mode= @save_sql_mode;
--echo #
--echo # MDEV-9028: SELECT DISTINCT constant column of derived table
--echo # used as the second operand of LEFT JOIN
--echo #
create table t1 (id int, data varchar(255));
insert into t1 values (1,'yes'),(2,'yes');
select distinct t1.id, tt.id, tt.data
from t1
left join
(select t1.id, 'yes' as data from t1) as tt
on t1.id = tt.id;
select distinct t1.id, tt.id, tt.data
from t1
left join
(select t1.id, 'yes' as data from t1 where id > 1) as tt
on t1.id = tt.id;
drop table t1;
--echo # end of 5.5 --echo # end of 5.5

View File

@@ -14627,7 +14627,9 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
if (new_field) if (new_field)
new_field->init(table); new_field->init(table);
if (copy_func && item->real_item()->is_result_field()) if (copy_func &&
(item->is_result_field() ||
(item->real_item()->is_result_field())))
*((*copy_func)++) = item; // Save for copy_funcs *((*copy_func)++) = item; // Save for copy_funcs
if (modify_item) if (modify_item)
item->set_result_field(new_field); item->set_result_field(new_field);