Commit 249a10c7 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #825035.

The value of maybe_null flag should be saved for the second execution
of a prepared statement from SELECT that uses an outer join.
parent 923dc9ea
...@@ -1593,3 +1593,25 @@ FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1; ...@@ -1593,3 +1593,25 @@ FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
b b
NULL NULL
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#
# LP bug #825035: second execution of PS with outer join
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4);
CREATE TABLE t2 (a int);
PREPARE stmt FROM
"SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a";
EXECUTE stmt;
a a
1 NULL
2 NULL
3 NULL
4 NULL
EXECUTE stmt;
a a
1 NULL
2 NULL
3 NULL
4 NULL
DEALLOCATE PREPARE stmt;
DROP TABLE t1,t2;
...@@ -1602,6 +1602,28 @@ FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1; ...@@ -1602,6 +1602,28 @@ FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
b b
NULL NULL
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#
# LP bug #825035: second execution of PS with outer join
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4);
CREATE TABLE t2 (a int);
PREPARE stmt FROM
"SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a";
EXECUTE stmt;
a a
1 NULL
2 NULL
3 NULL
4 NULL
EXECUTE stmt;
a a
1 NULL
2 NULL
3 NULL
4 NULL
DEALLOCATE PREPARE stmt;
DROP TABLE t1,t2;
set join_cache_level=default; set join_cache_level=default;
show variables like 'join_cache_level'; show variables like 'join_cache_level';
Variable_name Value Variable_name Value
......
...@@ -1154,3 +1154,22 @@ SELECT t2.b ...@@ -1154,3 +1154,22 @@ SELECT t2.b
FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1; FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
--echo #
--echo # LP bug #825035: second execution of PS with outer join
--echo #
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4);
CREATE TABLE t2 (a int);
PREPARE stmt FROM
"SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1,t2;
...@@ -7847,6 +7847,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context, ...@@ -7847,6 +7847,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
{ {
table_list->table->tablenr= table_list->tablenr_exec; table_list->table->tablenr= table_list->tablenr_exec;
table_list->table->map= table_list->map_exec; table_list->table->map= table_list->map_exec;
table_list->table->maybe_null= table_list->maybe_null_exec;
table_list->table->pos_in_table_list= table_list; table_list->table->pos_in_table_list= table_list;
} }
select_lex->leaf_tables.push_back(table_list); select_lex->leaf_tables.push_back(table_list);
......
...@@ -3015,6 +3015,7 @@ bool mysql_insert_select_prepare(THD *thd) ...@@ -3015,6 +3015,7 @@ bool mysql_insert_select_prepare(THD *thd)
select_lex->leaf_tables_exec.push_back(table); select_lex->leaf_tables_exec.push_back(table);
table->tablenr_exec= table->table->tablenr; table->tablenr_exec= table->table->tablenr;
table->map_exec= table->table->map; table->map_exec= table->table->map;
table->maybe_null_exec= table->table->maybe_null;
} }
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
......
...@@ -3588,6 +3588,10 @@ bool st_select_lex::save_leaf_tables(THD *thd) ...@@ -3588,6 +3588,10 @@ bool st_select_lex::save_leaf_tables(THD *thd)
return 1; return 1;
table->tablenr_exec= table->table->tablenr; table->tablenr_exec= table->table->tablenr;
table->map_exec= table->table->map; table->map_exec= table->table->map;
if (join && (join->select_options & SELECT_DESCRIBE))
table->maybe_null_exec= 0;
else
table->maybe_null_exec= table->table->maybe_null;
} }
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
......
...@@ -371,6 +371,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, ...@@ -371,6 +371,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
ulonglong create_options; ulonglong create_options;
uint save_tablenr= 0; uint save_tablenr= 0;
table_map save_map= 0; table_map save_map= 0;
uint save_maybe_null= 0;
while ((type= tp++)) while ((type= tp++))
{ {
...@@ -429,6 +430,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, ...@@ -429,6 +430,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{ {
save_tablenr= result_table_list.tablenr_exec; save_tablenr= result_table_list.tablenr_exec;
save_map= result_table_list.map_exec; save_map= result_table_list.map_exec;
save_maybe_null= result_table_list.maybe_null_exec;
} }
bzero((char*) &result_table_list, sizeof(result_table_list)); bzero((char*) &result_table_list, sizeof(result_table_list));
result_table_list.db= (char*) ""; result_table_list.db= (char*) "";
...@@ -438,6 +440,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, ...@@ -438,6 +440,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{ {
result_table_list.tablenr_exec= save_tablenr; result_table_list.tablenr_exec= save_tablenr;
result_table_list.map_exec= save_map; result_table_list.map_exec= save_map;
result_table_list.maybe_null_exec= save_maybe_null;
} }
thd_arg->lex->current_select= lex_select_save; thd_arg->lex->current_select= lex_select_save;
......
...@@ -1448,6 +1448,7 @@ struct TABLE_LIST ...@@ -1448,6 +1448,7 @@ struct TABLE_LIST
table_map map_exec; table_map map_exec;
/* TODO: check if this can be joined with jtbm_table_no */ /* TODO: check if this can be joined with jtbm_table_no */
uint tablenr_exec; uint tablenr_exec;
uint maybe_null_exec;
/* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */ /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
TABLE_LIST *parent_l; TABLE_LIST *parent_l;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment