summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/derived.result14
-rw-r--r--mysql-test/r/merge.result7
-rw-r--r--mysql-test/r/ps.result23
-rw-r--r--mysql-test/r/union.result15
-rw-r--r--mysql-test/t/derived.test10
-rw-r--r--mysql-test/t/merge.test9
-rw-r--r--mysql-test/t/ps.test22
-rw-r--r--mysql-test/t/union.test16
-rw-r--r--sql/item.h7
-rw-r--r--sql/item_func.h3
-rw-r--r--sql/sql_base.cc4
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_select.cc5
-rw-r--r--sql/sql_union.cc18
-rw-r--r--sql/table.cc6
-rw-r--r--storage/myisammrg/ha_myisammrg.cc43
16 files changed, 169 insertions, 35 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result
index 9d31ceab4d1..699d3279e3e 100644
--- a/mysql-test/r/derived.result
+++ b/mysql-test/r/derived.result
@@ -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,
diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result
index de376dc187d..41ee148cee3 100644
--- a/mysql-test/r/merge.result
+++ b/mysql-test/r/merge.result
@@ -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
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 95217d9716a..cc348e849e3 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -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
diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result
index d1be5e233df..a3ad63c035a 100644
--- a/mysql-test/r/union.result
+++ b/mysql-test/r/union.result
@@ -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,
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index a67a0e6c9d0..559a8b76280 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -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 #
diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test
index 7e198275730..6573c2b09c0 100644
--- a/mysql-test/t/merge.test
+++ b/mysql-test/t/merge.test
@@ -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 #
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index ff28631862c..5f4c815a192 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -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
diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test
index faa35de3ec1..a53427f7fc6 100644
--- a/mysql-test/t/union.test
+++ b/mysql-test/t/union.test
@@ -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 #
diff --git a/sql/item.h b/sql/item.h
index 8074f11da6b..c4fe24bf482 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -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;
diff --git a/sql/item_func.h b/sql/item_func.h
index bbf7643eaa0..f1dbbb09305 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -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() {
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index d54cb54dec6..f689d96b4cf 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -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
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 3c3cb87e9e3..4af06eec658 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -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);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 0f570a491fc..cd475b28783 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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)
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 22b5e5727e8..72f1df2f4ae 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -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)
{
diff --git a/sql/table.cc b/sql/table.cc
index 15fbe867c15..c949112e7ee 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -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 */
diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc
index 2b571675aef..1ee974c1b23 100644
--- a/storage/myisammrg/ha_myisammrg.cc
+++ b/storage/myisammrg/ha_myisammrg.cc
@@ -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);
-
- 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;
-
- create_info->merge_list.elements++;
- (*create_info->merge_list.next) = ptr;
- create_info->merge_list.next= &ptr->next_local;
+ 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;
+
+ 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;
}