Commit 9aac5468 authored by Michael Widenius's avatar Michael Widenius Committed by Michael Widenius

MDEV-5930 Server crashes in thd_get_ha_data on CREATE OR REPLACE TABLE

mysql-test/r/create_or_replace.result:
  More tests for create or replace
mysql-test/t/create_or_replace.test:
  More tests for create or replace
sql/log.cc:
  Don't use binlog_hton if binlog is not enabmed
sql/sql_base.cc:
  We have to call restart_trans_for_tables also if tables where not locked with LOCK TABLES.
  If not, we will get a crash in TokuDB
sql/sql_insert.cc:
  Don't call binlog_reset_cache() if we don't have binary log open
sql/sql_table.cc:
  Don't log to binary log if not open
  Better test if we where using create or replace ... select
storage/tokudb/mysql-test/tokudb_mariadb/r/create_or_replace.result:
  More tests for create or replace
storage/tokudb/mysql-test/tokudb_mariadb/t/create_or_replace.test:
  More tests for create or replace
parent 39e6083e
......@@ -231,8 +231,13 @@ drop table t1;
create table t1 (i int) engine=InnoDB;
create table t3 (i int) engine=InnoDB;
insert into t3 values(1),(2),(3);
lock table t1 write, t2 write, t3 write;
create table t4 (i int) engine=InnoDB;
insert into t4 values(1);
lock table t1 write, t2 write, t3 write, t4 write;
create or replace table t1 (a int, i int) engine=innodb select t2.a,t3.i from t2,t3;
select * from t4;
i
1
unlock tables;
select * from t1 order by a,i;
a i
......@@ -245,7 +250,7 @@ a i
3 1
3 2
3 3
drop table t1,t3;
drop table t1,t3,t4;
#
# Test the meta data locks are freed properly
#
......
......@@ -196,11 +196,14 @@ drop table t1;
create table t1 (i int) engine=InnoDB;
create table t3 (i int) engine=InnoDB;
insert into t3 values(1),(2),(3);
lock table t1 write, t2 write, t3 write;
create table t4 (i int) engine=InnoDB;
insert into t4 values(1);
lock table t1 write, t2 write, t3 write, t4 write;
create or replace table t1 (a int, i int) engine=innodb select t2.a,t3.i from t2,t3;
select * from t4;
unlock tables;
select * from t1 order by a,i;
drop table t1,t3;
drop table t1,t3,t4;
--echo #
--echo # Test the meta data locks are freed properly
......
......@@ -2049,8 +2049,8 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
void binlog_reset_cache(THD *thd)
{
binlog_cache_mngr *const cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
binlog_cache_mngr *const cache_mngr= opt_bin_log ?
(binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton) : 0;
DBUG_ENTER("binlog_reset_cache");
if (cache_mngr)
{
......
......@@ -5426,9 +5426,6 @@ bool restart_trans_for_tables(THD *thd, TABLE_LIST *table)
{
DBUG_ENTER("restart_trans_for_tables");
if (!thd->locked_tables_mode)
DBUG_RETURN(FALSE);
for (; table; table= table->next_global)
{
if (table->placeholder())
......
......@@ -4302,7 +4302,7 @@ void select_create::abort_result_set()
table->auto_increment_field_not_null= FALSE;
drop_open_table(thd, table, create_table->db, create_table->table_name);
table=0; // Safety
if (thd->log_current_statement)
if (thd->log_current_statement && mysql_bin_log.is_open())
{
/* Remove logging of drop, create + insert rows */
binlog_reset_cache(thd);
......@@ -4314,4 +4314,3 @@ void select_create::abort_result_set()
}
DBUG_VOID_RETURN;
}
......@@ -2686,6 +2686,9 @@ bool log_drop_table(THD *thd, const char *db_name, size_t db_name_length,
bool error;
DBUG_ENTER("log_drop_table");
if (!mysql_bin_log.is_open())
DBUG_RETURN(0);
query.length(0);
query.append(STRING_WITH_LEN("DROP "));
if (temporary_table)
......@@ -4759,11 +4762,10 @@ int create_table_impl(THD *thd,
DBUG_EXECUTE_IF("send_kill_after_delete", thd->killed= KILL_QUERY; );
/*
The test of query_tables is to ensure we have any tables in the
select part
Restart statement transactions for the case of CREATE ... SELECT.
*/
if (thd->lex->query_tables &&
restart_trans_for_tables(thd, thd->lex->query_tables->next_global))
if (thd->lex->select_lex.item_list.elements &&
restart_trans_for_tables(thd, thd->lex->query_tables))
goto err;
}
else if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
......
drop table if exists t1,t2,t3;
CREATE TABLE t1 (a INT) engine=myisam;
CREATE TABLE t2 (a INT) ENGINE=TokuDB;
CREATE OR REPLACE TABLE t3 AS SELECT * FROM t2;
CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2;
lock table t1 write,t2 read;
CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2;
unlock tables;
drop table t1,t2,t3;
#
# Test's for CREATE OR REPLACE with tokudb
#
--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
#
# MDEV-5930 Server crashes in thd_get_ha_data on CREATE OR REPLACE TABLE
#
CREATE TABLE t1 (a INT) engine=myisam;
CREATE TABLE t2 (a INT) ENGINE=TokuDB;
CREATE OR REPLACE TABLE t3 AS SELECT * FROM t2;
CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2;
lock table t1 write,t2 read;
CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2;
unlock tables;
drop table t1,t2,t3;
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