mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
sql_union.cc, sql_select.cc:
Code clean-up sql_union.cc, union.test, union.result: A fix for a bug #978. This enables that NULL's can be entered into UNION's result set, although first SELECT columns are NOT NULL. This is also a start of fixing UNION's properly regarding type acceptance. sql_select.cc: A commit for my second July SPRINT task mysql-test/r/union.result: A fix for a bug #978. This enables that NULL's can be entered into UNION's result set, although first SELECT columns are NOT NULL. This is also a start of fixing UNION's properly regarding type acceptance. mysql-test/t/union.test: A fix for a bug #978. This enables that NULL's can be entered into UNION's result set, although first SELECT columns are NOT NULL. This is also a start of fixing UNION's properly regarding type acceptance. sql/sql_select.cc: Code clean-up sql/sql_union.cc: Code clean-up
This commit is contained in:
@@ -328,3 +328,16 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||||||
1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
|
1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
|
||||||
2 UNION t1 ref b b 5 const 1 Using where
|
2 UNION t1 ref b b 5 const 1 Using where
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
create table t1 ( id int not null auto_increment, primary key (id) ,user_name text );
|
||||||
|
create table t2 ( id int not null auto_increment, primary key (id) ,group_name text );
|
||||||
|
create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references users(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references groups(id) );
|
||||||
|
insert into t1 (user_name) values ('Tester');
|
||||||
|
insert into t2 (group_name) values ('Group A');
|
||||||
|
insert into t2 (group_name) values ('Group B');
|
||||||
|
insert into t3 (user_id, group_id) values (1,1);
|
||||||
|
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION select 0 'is_in_group', a.user_name, c.group_name, null from t1 a, t2 c;
|
||||||
|
is_in_group user_name group_name id
|
||||||
|
1 Tester Group A 1
|
||||||
|
0 Tester Group A NULL
|
||||||
|
0 Tester Group B NULL
|
||||||
|
drop table t1, t2, t3;
|
||||||
|
@@ -209,3 +209,12 @@ explain (select * from t1 where a=1) union (select * from t2 where a=1);
|
|||||||
explain (select * from t1 where a=1 and b=10) union (select t1.a,t2.a from t1,t2 where t1.a=t2.a);
|
explain (select * from t1 where a=1 and b=10) union (select t1.a,t2.a from t1,t2 where t1.a=t2.a);
|
||||||
explain (select * from t1 where a=1) union (select * from t1 where b=1);
|
explain (select * from t1 where a=1) union (select * from t1 where b=1);
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
create table t1 ( id int not null auto_increment, primary key (id) ,user_name text );
|
||||||
|
create table t2 ( id int not null auto_increment, primary key (id) ,group_name text );
|
||||||
|
create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references users(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references groups(id) );
|
||||||
|
insert into t1 (user_name) values ('Tester');
|
||||||
|
insert into t2 (group_name) values ('Group A');
|
||||||
|
insert into t2 (group_name) values ('Group B');
|
||||||
|
insert into t3 (user_id, group_id) values (1,1);
|
||||||
|
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION select 0 'is_in_group', a.user_name, c.group_name, null from t1 a, t2 c;
|
||||||
|
drop table t1, t2, t3;
|
||||||
|
@@ -154,8 +154,6 @@ int st_select_lex_unit::prepare(THD *thd, select_result *sel_result,
|
|||||||
goto err;
|
goto err;
|
||||||
List_iterator<Item> it(select_cursor->item_list);
|
List_iterator<Item> it(select_cursor->item_list);
|
||||||
Item *item;
|
Item *item;
|
||||||
while((item=it++))
|
|
||||||
item->maybe_null=1;
|
|
||||||
item_list= select_cursor->item_list;
|
item_list= select_cursor->item_list;
|
||||||
select_cursor->with_wild= 0;
|
select_cursor->with_wild= 0;
|
||||||
if (setup_ref_array(thd, &select_cursor->ref_pointer_array,
|
if (setup_ref_array(thd, &select_cursor->ref_pointer_array,
|
||||||
@@ -166,6 +164,12 @@ int st_select_lex_unit::prepare(THD *thd, select_result *sel_result,
|
|||||||
item_list, 0, 0, 1))
|
item_list, 0, 0, 1))
|
||||||
goto err;
|
goto err;
|
||||||
t_and_f= 1;
|
t_and_f= 1;
|
||||||
|
while((item=it++))
|
||||||
|
{
|
||||||
|
item->maybe_null=1;
|
||||||
|
if (item->type() == Item::FIELD_ITEM)
|
||||||
|
((class Item_field *)item)->field->table->maybe_null=1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_table_param.field_count=item_list.elements;
|
tmp_table_param.field_count=item_list.elements;
|
||||||
@@ -249,7 +253,6 @@ err:
|
|||||||
|
|
||||||
int st_select_lex_unit::exec()
|
int st_select_lex_unit::exec()
|
||||||
{
|
{
|
||||||
int do_print_slow= 0;
|
|
||||||
SELECT_LEX_NODE *lex_select_save= thd->lex.current_select;
|
SELECT_LEX_NODE *lex_select_save= thd->lex.current_select;
|
||||||
SELECT_LEX *select_cursor=first_select_in_union();
|
SELECT_LEX *select_cursor=first_select_in_union();
|
||||||
DBUG_ENTER("st_select_lex_unit::exec");
|
DBUG_ENTER("st_select_lex_unit::exec");
|
||||||
@@ -317,7 +320,6 @@ int st_select_lex_unit::exec()
|
|||||||
thd->lex.current_select= lex_select_save;
|
thd->lex.current_select= lex_select_save;
|
||||||
DBUG_RETURN(res);
|
DBUG_RETURN(res);
|
||||||
}
|
}
|
||||||
do_print_slow|= select_cursor->options;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
optimized= 1;
|
optimized= 1;
|
||||||
@@ -360,12 +362,6 @@ int st_select_lex_unit::exec()
|
|||||||
Mark for slow query log if any of the union parts didn't use
|
Mark for slow query log if any of the union parts didn't use
|
||||||
indexes efficiently
|
indexes efficiently
|
||||||
*/
|
*/
|
||||||
select_cursor->options= ((select_cursor->options &
|
|
||||||
~(QUERY_NO_INDEX_USED |
|
|
||||||
QUERY_NO_GOOD_INDEX_USED)) |
|
|
||||||
do_print_slow &
|
|
||||||
(QUERY_NO_INDEX_USED |
|
|
||||||
QUERY_NO_GOOD_INDEX_USED));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thd->lex.current_select= lex_select_save;
|
thd->lex.current_select= lex_select_save;
|
||||||
|
Reference in New Issue
Block a user