summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2020-06-10 11:55:00 +0300
committerMonty <monty@mariadb.org>2020-06-14 19:39:43 +0300
commit56045ef94a1393849e034d187e2ca5d9fd31ad32 (patch)
tree344994c5388dd97a15c6f9ccb89842246fd38ff2
parentab7eedc1858dc92ab10b96bc3df007775f1d6bb5 (diff)
downloadmariadb-git-56045ef94a1393849e034d187e2ca5d9fd31ad32.tar.gz
Fix for crash in Aria LOCK TABLES + CREATE TRIGGER
MDEV-22829 SIGSEGV in _ma_reset_history on LOCK
-rw-r--r--mysql-test/suite/maria/lock.result11
-rw-r--r--mysql-test/suite/maria/lock.test13
-rw-r--r--sql/sql_trigger.cc6
3 files changed, 29 insertions, 1 deletions
diff --git a/mysql-test/suite/maria/lock.result b/mysql-test/suite/maria/lock.result
index 9c7c7bedbb2..0891e8ad249 100644
--- a/mysql-test/suite/maria/lock.result
+++ b/mysql-test/suite/maria/lock.result
@@ -166,3 +166,14 @@ test.t1 optimize status Table is already up to date
disconnect con1;
connection default;
DROP TABLE t1, t2;
+#
+# MDEV-22829 SIGSEGV in _ma_reset_history on LOCK
+#
+CREATE TABLE t1 (f1 INT) ENGINE=Aria;
+CREATE TABLE t2 (f2 INT) ENGINE=Aria;
+LOCK TABLES t2 WRITE, t1 WRITE;
+INSERT INTO t1 VALUES (1);
+CREATE TRIGGER ai AFTER INSERT ON t1 FOR EACH ROW UPDATE t1 SET v=1 WHERE b=new.a;
+ERROR 42S22: Unknown column 'a' in 'NEW'
+UNLOCK TABLES;
+DROP TABLE t1, t2;
diff --git a/mysql-test/suite/maria/lock.test b/mysql-test/suite/maria/lock.test
index bb709f8a69c..017bd025ac1 100644
--- a/mysql-test/suite/maria/lock.test
+++ b/mysql-test/suite/maria/lock.test
@@ -185,3 +185,16 @@ OPTIMIZE TABLE t1;
--disconnect con1
--connection default
DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-22829 SIGSEGV in _ma_reset_history on LOCK
+--echo #
+
+CREATE TABLE t1 (f1 INT) ENGINE=Aria;
+CREATE TABLE t2 (f2 INT) ENGINE=Aria;
+LOCK TABLES t2 WRITE, t1 WRITE;
+INSERT INTO t1 VALUES (1);
+--error ER_BAD_FIELD_ERROR
+CREATE TRIGGER ai AFTER INSERT ON t1 FOR EACH ROW UPDATE t1 SET v=1 WHERE b=new.a;
+UNLOCK TABLES;
+DROP TABLE t1, t2;
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 779faa96f82..677e6cfa510 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -558,7 +558,11 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
/* Later on we will need it to downgrade the lock */
mdl_ticket= table->mdl_ticket;
- if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
+ /*
+ RENAME ensures that table is flushed properly and locked tables will
+ be removed from the active transaction
+ */
+ if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
goto end;
lock_upgrade_done= TRUE;