Skip to content

Commit f49375f

Browse files
committed
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.
1 parent b70cd26 commit f49375f

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

mysql-test/r/derived.result

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,4 +988,27 @@ David Yes 210
988988
Edward Yes 150
989989
DROP TABLE example1463;
990990
set sql_mode= @save_sql_mode;
991+
#
992+
# MDEV-9028: SELECT DISTINCT constant column of derived table
993+
# used as the second operand of LEFT JOIN
994+
#
995+
create table t1 (id int, data varchar(255));
996+
insert into t1 values (1,'yes'),(2,'yes');
997+
select distinct t1.id, tt.id, tt.data
998+
from t1
999+
left join
1000+
(select t1.id, 'yes' as data from t1) as tt
1001+
on t1.id = tt.id;
1002+
id id data
1003+
1 1 yes
1004+
2 2 yes
1005+
select distinct t1.id, tt.id, tt.data
1006+
from t1
1007+
left join
1008+
(select t1.id, 'yes' as data from t1 where id > 1) as tt
1009+
on t1.id = tt.id;
1010+
id id data
1011+
2 2 yes
1012+
1 NULL NULL
1013+
drop table t1;
9911014
# end of 5.5

mysql-test/t/derived.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,27 @@ SELECT Customer, Success, SUM(OrderSize)
842842
DROP TABLE example1463;
843843
set sql_mode= @save_sql_mode;
844844

845+
--echo #
846+
--echo # MDEV-9028: SELECT DISTINCT constant column of derived table
847+
--echo # used as the second operand of LEFT JOIN
848+
--echo #
849+
850+
create table t1 (id int, data varchar(255));
851+
insert into t1 values (1,'yes'),(2,'yes');
852+
853+
select distinct t1.id, tt.id, tt.data
854+
from t1
855+
left join
856+
(select t1.id, 'yes' as data from t1) as tt
857+
on t1.id = tt.id;
858+
859+
select distinct t1.id, tt.id, tt.data
860+
from t1
861+
left join
862+
(select t1.id, 'yes' as data from t1 where id > 1) as tt
863+
on t1.id = tt.id;
864+
865+
drop table t1;
866+
867+
845868
--echo # end of 5.5

sql/sql_select.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14627,7 +14627,9 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
1462714627
if (new_field)
1462814628
new_field->init(table);
1462914629

14630-
if (copy_func && item->real_item()->is_result_field())
14630+
if (copy_func &&
14631+
(item->is_result_field() ||
14632+
(item->real_item()->is_result_field())))
1463114633
*((*copy_func)++) = item; // Save for copy_funcs
1463214634
if (modify_item)
1463314635
item->set_result_field(new_field);

0 commit comments

Comments
 (0)