5.3 merge

This commit is contained in:
Sergei Golubchik 2013-12-13 13:00:38 +01:00
commit e68bccc743
16 changed files with 167 additions and 33 deletions

View File

@ -465,6 +465,20 @@ t1.val=t3.val
;
ERROR 42S22: Unknown column 'v.val' in 'field list'
drop table t1, t2;
#
# MDEV-5353: server crash on subselect if WHERE applied to some
# result field
#
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.b;
a b
100 200
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.a;
a b
100 200
# End of 5.3 tests
#
# Bug#58730 Assertion failed: table->key_read == 0 in close_thread_table,

View File

@ -2394,6 +2394,13 @@ REPAIR TABLE m1;
Table Op Msg_type Msg_text
test.m1 repair note The storage engine for the table doesn't support repair
DROP TABLE m1, t1;
create temporary table t1_temp(i int);
create temporary table tm_temp_temp (i int) engine=merge union=(t1_temp) insert_method=last;
alter table tm_temp_temp insert_method=first;
check table tm_temp_temp;
Table Op Msg_type Msg_text
test.tm_temp_temp check status OK
drop temporary table t1_temp, tm_temp_temp;
End of 5.1 tests
#
# MDEV-4277: Crash inside mi_killed_in_mariadb() with myisammrg

View File

@ -3996,4 +3996,27 @@ Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
deallocate prepare st;
drop table t1;
#
# Bug mdev-5410: crash at the execution of PS with subselect
# formed by UNION with global ORDER BY
#
CREATE TABLE t1 (a int DEFAULT NULL);
INSERT INTO t1 VALUES (2), (4);
CREATE TABLE t2 (b int DEFAULT NULL);
INSERT INTO t2 VALUES (1), (3);
PREPARE stmt FROM "
SELECT c1 FROM (SELECT (SELECT a FROM t1 WHERE t1.a <= t2.b
UNION ALL
SELECT a FROM t1 WHERE t1.a+3<= t2.b
ORDER BY a DESC) AS c1 FROM t2) t3;
";
EXECUTE stmt;
c1
NULL
2
EXECUTE stmt;
c1
NULL
2
DROP TABLE t1,t2;
# End of 5.3 tests

View File

@ -1734,6 +1734,21 @@ i
6
DROP VIEW v1;
DROP TABLE t1;
#
# mdev-5382: UNION with ORDER BY in subselect
#
CREATE TABLE t1 (a int DEFAULT NULL);
INSERT INTO t1 VALUES (2), (4);
CREATE TABLE t2 (b int DEFAULT NULL);
INSERT INTO t2 VALUES (1), (3);
SELECT c1 FROM (SELECT (SELECT a FROM t1 WHERE t1.a <= t2.b
UNION ALL
SELECT a FROM t1 WHERE t1.a+3<= t2.b
ORDER BY a DESC) AS c1 FROM t2) t3;
c1
NULL
2
DROP TABLE t1,t2;
End of 5.3 tests
#
# Bug#57986 ORDER BY clause is not used after a UNION,

View File

@ -383,7 +383,17 @@ set
drop table t1, t2;
--echo #
--echo # MDEV-5353: server crash on subselect if WHERE applied to some
--echo # result field
--echo #
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.b;
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.a;
--echo # End of 5.3 tests
--echo #

View File

@ -1830,6 +1830,15 @@ REPAIR TABLE m1;
#
DROP TABLE m1, t1;
#
# MDEV-5266 MySQL:57657 - Temporary MERGE table with temporary underlying is broken by ALTER
#
create temporary table t1_temp(i int);
create temporary table tm_temp_temp (i int) engine=merge union=(t1_temp) insert_method=last;
alter table tm_temp_temp insert_method=first;
check table tm_temp_temp;
drop temporary table t1_temp, tm_temp_temp;
--echo End of 5.1 tests
--echo #

View File

@ -3572,4 +3572,26 @@ show status like '%Handler_read%';
deallocate prepare st;
drop table t1;
--echo #
--echo # Bug mdev-5410: crash at the execution of PS with subselect
--echo # formed by UNION with global ORDER BY
--echo #
CREATE TABLE t1 (a int DEFAULT NULL);
INSERT INTO t1 VALUES (2), (4);
CREATE TABLE t2 (b int DEFAULT NULL);
INSERT INTO t2 VALUES (1), (3);
PREPARE stmt FROM "
SELECT c1 FROM (SELECT (SELECT a FROM t1 WHERE t1.a <= t2.b
UNION ALL
SELECT a FROM t1 WHERE t1.a+3<= t2.b
ORDER BY a DESC) AS c1 FROM t2) t3;
";
EXECUTE stmt;
EXECUTE stmt;
DROP TABLE t1,t2;
--echo # End of 5.3 tests

View File

@ -1188,6 +1188,22 @@ deallocate prepare stmt1;
DROP VIEW v1;
DROP TABLE t1;
--echo #
--echo # mdev-5382: UNION with ORDER BY in subselect
--echo #
CREATE TABLE t1 (a int DEFAULT NULL);
INSERT INTO t1 VALUES (2), (4);
CREATE TABLE t2 (b int DEFAULT NULL);
INSERT INTO t2 VALUES (1), (3);
SELECT c1 FROM (SELECT (SELECT a FROM t1 WHERE t1.a <= t2.b
UNION ALL
SELECT a FROM t1 WHERE t1.a+3<= t2.b
ORDER BY a DESC) AS c1 FROM t2) t3;
DROP TABLE t1,t2;
--echo End of 5.3 tests
--echo #

View File

@ -3269,13 +3269,16 @@ class Item_direct_view_ref :public Item_direct_ref
TABLE_LIST *view;
TABLE *null_ref_table;
#define NO_NULL_TABLE (reinterpret_cast<TABLE *>(0x1))
bool check_null_ref()
{
if (null_ref_table == NULL)
{
null_ref_table= view->get_real_join_table();
if (!(null_ref_table= view->get_real_join_table()))
null_ref_table= NO_NULL_TABLE;
}
if (null_ref_table->null_row)
if (null_ref_table != NO_NULL_TABLE && null_ref_table->null_row)
{
null_value= 1;
return TRUE;

View File

@ -160,7 +160,8 @@ public:
inline bool get_arg0_time(MYSQL_TIME *ltime)
{
null_value= args[0]->get_time(ltime);
DBUG_ASSERT(ltime->time_type != MYSQL_TIMESTAMP_TIME || ltime->day == 0);
DBUG_ASSERT(null_value ||
ltime->time_type != MYSQL_TIMESTAMP_TIME || ltime->day == 0);
return null_value;
}
bool is_null() {

View File

@ -6701,9 +6701,9 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
else
{
if (thd->mark_used_columns == MARK_COLUMNS_READ)
it->walk(&Item::register_field_in_read_map, 1, (uchar *) 0);
it->walk(&Item::register_field_in_read_map, 0, (uchar *) 0);
else
it->walk(&Item::register_field_in_write_map, 1, (uchar *) 0);
it->walk(&Item::register_field_in_write_map, 0, (uchar *) 0);
}
}
else

View File

@ -702,7 +702,7 @@ public:
void print(String *str, enum_query_type query_type);
bool add_fake_select_lex(THD *thd);
void init_prepare_fake_select_lex(THD *thd);
void init_prepare_fake_select_lex(THD *thd, bool first_execution);
inline bool is_prepared() { return prepared; }
bool change_result(select_result_interceptor *result,
select_result_interceptor *old_result);

View File

@ -10813,17 +10813,18 @@ void JOIN::cleanup(bool full)
tabs_kind= WALK_EXECUTION_TABS;
if (table_count)
{
for (tab= first_breadth_first_tab(this, tabs_kind); tab;
for (tab= first_breadth_first_tab(this, tabs_kind); tab;
tab= next_breadth_first_tab(this, tabs_kind, tab))
{
tab->cleanup();
}
}
cleaned= true;
}
else
{
for (tab= first_linear_tab(this, WITH_CONST_TABLES); tab;
for (tab= first_linear_tab(this, WITH_CONST_TABLES); tab;
tab= next_linear_tab(this, tab, WITH_BUSH_ROOTS))
{
if (tab->table)

View File

@ -193,13 +193,15 @@ void select_union::cleanup()
SYNOPSIS
st_select_lex_unit::init_prepare_fake_select_lex()
thd - thread handler
first_execution - TRUE at the first execution of the union
RETURN
options of SELECT
*/
void
st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg)
st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg,
bool first_execution)
{
thd_arg->lex->current_select= fake_select_lex;
fake_select_lex->table_list.link_in_list(&result_table_list,
@ -207,7 +209,13 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg)
fake_select_lex->context.table_list=
fake_select_lex->context.first_name_resolution_table=
fake_select_lex->get_table_list();
if (!fake_select_lex->first_execution)
/*
The flag fake_select_lex->first_execution indicates whether this is
called at the first execution of the statement, while first_execution
shows whether this is called at the first execution of the union that
may form just a subselect.
*/
if (!fake_select_lex->first_execution && first_execution)
{
for (ORDER *order= global_parameters->order_list.first;
order;
@ -481,7 +489,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{
/* Validate the global parameters of this union */
init_prepare_fake_select_lex(thd);
init_prepare_fake_select_lex(thd, TRUE);
/* Should be done only once (the only item_list per statement) */
DBUG_ASSERT(fake_select_lex->join == 0);
if (!(fake_select_lex->join= new JOIN(thd, item_list, thd->variables.option_bits,
@ -622,6 +630,7 @@ bool st_select_lex_unit::exec()
SELECT_LEX *select_cursor=first_select();
ulonglong add_rows=0;
ha_rows examined_rows= 0;
bool first_execution= !executed;
DBUG_ENTER("st_select_lex_unit::exec");
if (executed && !uncacheable && !describe)
@ -638,6 +647,7 @@ bool st_select_lex_unit::exec()
{
ha_rows records_at_start= 0;
thd->lex->current_select= sl;
fake_select_lex->uncacheable|= sl->uncacheable;
{
set_limit(sl);
@ -742,7 +752,7 @@ bool st_select_lex_unit::exec()
if (!thd->is_fatal_error) // Check if EOM
{
set_limit(global_parameters);
init_prepare_fake_select_lex(thd);
init_prepare_fake_select_lex(thd, first_execution);
JOIN *join= fake_select_lex->join;
if (!join)
{

View File

@ -5022,10 +5022,8 @@ TABLE *TABLE_LIST::get_real_join_table()
*/
for (TABLE_LIST *t= ti++; t; t= ti++)
tbl= t;
/*
It is impossible that the list is empty
so tbl can't be NULL after above loop.
*/
if (!tbl)
return NULL; // view/derived with no tables
if (!tbl->nested_join)
break;
/* go deeper if we've found nested join */

View File

@ -1491,31 +1491,36 @@ void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
if (!(create_info->used_fields & HA_CREATE_USED_UNION))
{
MYRG_TABLE *open_table;
TABLE_LIST *child_table;
THD *thd=current_thd;
create_info->merge_list.next= &create_info->merge_list.first;
create_info->merge_list.elements=0;
for (open_table=file->open_tables ;
open_table != file->end_table ;
open_table++)
if (children_l != NULL)
{
TABLE_LIST *ptr;
LEX_STRING db, name;
LINT_INIT(db.str);
for (child_table= children_l;;
child_table= child_table->next_global)
{
TABLE_LIST *ptr;
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
goto err;
split_file_name(open_table->table->filename, &db, &name);
if (!(ptr->table_name= thd->strmake(name.str, name.length)))
goto err;
if (db.length && !(ptr->db= thd->strmake(db.str, db.length)))
goto err;
if (!(ptr= (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
goto err;
create_info->merge_list.elements++;
(*create_info->merge_list.next) = ptr;
create_info->merge_list.next= &ptr->next_local;
if (!(ptr->table_name= thd->strmake(child_table->table_name,
child_table->table_name_length)))
goto err;
if (child_table->db && !(ptr->db= thd->strmake(child_table->db,
child_table->db_length)))
goto err;
create_info->merge_list.elements++;
(*create_info->merge_list.next)= ptr;
create_info->merge_list.next= &ptr->next_local;
if (&child_table->next_global == children_last_l)
break;
}
}
*create_info->merge_list.next=0;
}