summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-06-29 16:57:22 +0200
committerNikita Malyavin <nikitamalyavin@gmail.com>2022-08-23 16:36:26 +0300
commitd79721b32d0b2c3cf5492935d986295e564a2e36 (patch)
treea65276cc8642235f3c2d92be58c43cf8e833ed3d
parent76650f30cb6ff88560880470df61c325e743f77b (diff)
downloadmariadb-git-d79721b32d0b2c3cf5492935d986295e564a2e36.tar.gz
MDEV-28771 Assertion `table->in_use&&tdc->flushed' failed after ALTER
don't simply set tdc->flushed, use flush_unused(1) that removes opened but unused TABLE instances (that would otherwise prevent TABLE_SHARE from being closed by keeping the ref_count>0).
-rw-r--r--mysql-test/main/alter_table_online.result56
-rw-r--r--mysql-test/main/alter_table_online.test35
-rw-r--r--sql/sql_table.cc2
3 files changed, 92 insertions, 1 deletions
diff --git a/mysql-test/main/alter_table_online.result b/mysql-test/main/alter_table_online.result
new file mode 100644
index 00000000000..5015b4cb5b7
--- /dev/null
+++ b/mysql-test/main/alter_table_online.result
@@ -0,0 +1,56 @@
+#
+# MDEV-28771 Assertion `table->in_use&&tdc->flushed' failed after ALTER
+#
+create table t (a char(1));
+insert into t values ('a'),('b');
+select * from t join t as t2 join t as t3;
+a a a
+a a a
+b a a
+a b a
+b b a
+a a b
+b a b
+a b b
+b b b
+alter table t modify a int;
+ERROR 22007: Truncated incorrect INTEGER value: 'a'
+select * from t;
+a
+a
+b
+drop table t;
+create table t (c double precision key,c2 char,c3 year);
+insert into t values (7,3,1);
+select a from t where a=all (select a from t where b=2 union select a from t where b=2);
+ERROR 42S22: Unknown column 'a' in 'field list'
+insert into t values (3,1,1);
+alter table t change c c date,add key(c);
+ERROR 22007: Incorrect date value: '7' for column `test`.`t`.`c` at row 1
+select * from t;
+c c2 c3
+7 3 2001
+3 1 2001
+drop table t;
+set sql_mode='';
+create table t (c char unique,c2 int,stamp timestamp);
+insert into t values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5);
+Warnings:
+Warning 1265 Data truncated for column 'stamp' at row 1
+Warning 1265 Data truncated for column 'stamp' at row 2
+Warning 1265 Data truncated for column 'stamp' at row 3
+Warning 1265 Data truncated for column 'stamp' at row 4
+Warning 1265 Data truncated for column 'stamp' at row 5
+update t set c=(select * from t) where c in (select * from t);
+ERROR 21000: Operand should contain 1 column(s)
+alter table t modify c date;
+ERROR 23000: Duplicate entry '0000-00-00' for key 'c'
+select * from t;
+c c2 stamp
+1 1 0000-00-00 00:00:00
+2 2 0000-00-00 00:00:00
+3 3 0000-00-00 00:00:00
+4 4 0000-00-00 00:00:00
+5 5 0000-00-00 00:00:00
+drop table t;
+set sql_mode=default;
diff --git a/mysql-test/main/alter_table_online.test b/mysql-test/main/alter_table_online.test
new file mode 100644
index 00000000000..a9e20fa05f6
--- /dev/null
+++ b/mysql-test/main/alter_table_online.test
@@ -0,0 +1,35 @@
+--source include/binlog_combinations.inc
+--source include/have_innodb.inc
+
+--echo #
+--echo # MDEV-28771 Assertion `table->in_use&&tdc->flushed' failed after ALTER
+--echo #
+
+create table t (a char(1));
+insert into t values ('a'),('b');
+select * from t join t as t2 join t as t3;
+--error ER_TRUNCATED_WRONG_VALUE
+alter table t modify a int;
+select * from t;
+drop table t;
+
+create table t (c double precision key,c2 char,c3 year);
+insert into t values (7,3,1);
+--error ER_BAD_FIELD_ERROR
+select a from t where a=all (select a from t where b=2 union select a from t where b=2);
+insert into t values (3,1,1);
+--error ER_TRUNCATED_WRONG_VALUE
+alter table t change c c date,add key(c);
+select * from t;
+drop table t;
+
+set sql_mode='';
+create table t (c char unique,c2 int,stamp timestamp);
+insert into t values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5);
+--error ER_OPERAND_COLUMNS
+update t set c=(select * from t) where c in (select * from t);
+--error ER_DUP_ENTRY
+alter table t modify c date;
+select * from t;
+drop table t;
+set sql_mode=default;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 98c75457163..ddee9010136 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -11870,7 +11870,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
}
else if (online) // error was on copy stage
{
- from->s->tdc->flushed= 1; // to free the binlog
+ from->s->tdc->flush_unused(1); // to free the binlog
}
#endif