Commit 78f5e714 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 4ccb5107
......@@ -1593,3 +1593,25 @@ FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
b
NULL
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;
b
NULL
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;
show variables like 'join_cache_level';
Variable_name Value
......
......@@ -1154,3 +1154,22 @@ SELECT t2.b
FROM t1 LEFT JOIN t2 ON (t2.b) IN (SELECT c2 from t3) AND t2.a = 1;
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,
{
table_list->table->tablenr= table_list->tablenr_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;
}
select_lex->leaf_tables.push_back(table_list);
......
......@@ -3015,6 +3015,7 @@ bool mysql_insert_select_prepare(THD *thd)
select_lex->leaf_tables_exec.push_back(table);
table->tablenr_exec= table->table->tablenr;
table->map_exec= table->table->map;
table->maybe_null_exec= table->table->maybe_null;
}
if (arena)
thd->restore_active_arena(arena, &backup);
......
......@@ -3588,6 +3588,10 @@ bool st_select_lex::save_leaf_tables(THD *thd)
return 1;
table->tablenr_exec= table->table->tablenr;
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)
thd->restore_active_arena(arena, &backup);
......
......@@ -371,6 +371,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
ulonglong create_options;
uint save_tablenr= 0;
table_map save_map= 0;
uint save_maybe_null= 0;
while ((type= tp++))
{
......@@ -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_map= result_table_list.map_exec;
save_maybe_null= result_table_list.maybe_null_exec;
}
bzero((char*) &result_table_list, sizeof(result_table_list));
result_table_list.db= (char*) "";
......@@ -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.map_exec= save_map;
result_table_list.maybe_null_exec= save_maybe_null;
}
thd_arg->lex->current_select= lex_select_save;
......
......@@ -1448,6 +1448,7 @@ struct TABLE_LIST
table_map map_exec;
/* TODO: check if this can be joined with jtbm_table_no */
uint tablenr_exec;
uint maybe_null_exec;
/* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
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