From 5fb4e4ab3939402ff6864e14ddbc9dd564a9d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 17 Jan 2019 14:16:59 +0200 Subject: [PATCH] MDEV-18149 Crash after DROP COLUMN of AUTO_INCREMENT column on nonempty table commit_cache_norebuild(): Restore the MDEV-17901 fix that was reverted as part of the MDEV-18076/MDEV-18077 fix. It was not redundant after all. --- .../suite/innodb/r/instant_alter.result | 29 ++++++++++++++++++- mysql-test/suite/innodb/t/instant_alter.test | 8 +++++ storage/innobase/handler/handler0alter.cc | 6 +++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index 98000d0120c..0c0b81da6e3 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -578,6 +578,15 @@ id f 1 NULL 2 NULL DROP TABLE t1; +CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT, f INT, KEY(id)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT; +INSERT INTO t1 SET f=NULL; +ALTER TABLE t1 DROP COLUMN id; +INSERT INTO t1 SET f=NULL; +SELECT * FROM t1; +f +NULL +NULL +DROP TABLE t1; CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT; ALTER TABLE t1 DROP COLUMN f; INSERT INTO t1 VALUES (1); @@ -1239,6 +1248,15 @@ id f 1 NULL 2 NULL DROP TABLE t1; +CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT, f INT, KEY(id)) ENGINE=InnoDB ROW_FORMAT=COMPACT; +INSERT INTO t1 SET f=NULL; +ALTER TABLE t1 DROP COLUMN id; +INSERT INTO t1 SET f=NULL; +SELECT * FROM t1; +f +NULL +NULL +DROP TABLE t1; CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) ENGINE=InnoDB ROW_FORMAT=COMPACT; ALTER TABLE t1 DROP COLUMN f; INSERT INTO t1 VALUES (1); @@ -1900,6 +1918,15 @@ id f 1 NULL 2 NULL DROP TABLE t1; +CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT, f INT, KEY(id)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; +INSERT INTO t1 SET f=NULL; +ALTER TABLE t1 DROP COLUMN id; +INSERT INTO t1 SET f=NULL; +SELECT * FROM t1; +f +NULL +NULL +DROP TABLE t1; CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; ALTER TABLE t1 DROP COLUMN f; INSERT INTO t1 VALUES (1); @@ -2042,5 +2069,5 @@ SELECT variable_value-@old_instant instants FROM information_schema.global_status WHERE variable_name = 'innodb_instant_alter_column'; instants -155 +158 SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test index 688b26c4388..65dde13808c 100644 --- a/mysql-test/suite/innodb/t/instant_alter.test +++ b/mysql-test/suite/innodb/t/instant_alter.test @@ -447,6 +447,14 @@ ALTER TABLE t1 ADD COLUMN id INT NOT NULL AUTO_INCREMENT FIRST, ADD KEY(id); SELECT * FROM t1; DROP TABLE t1; +# MDEV-18149 Crash after DROP COLUMN of AUTO_INCREMENT column on nonempty table +eval CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT, f INT, KEY(id)) $engine; +INSERT INTO t1 SET f=NULL; +ALTER TABLE t1 DROP COLUMN id; +INSERT INTO t1 SET f=NULL; +SELECT * FROM t1; +DROP TABLE t1; + # MDEV-18076/MDEV-18077 Crash on AUTO_INCREMENT column after instant DROP eval CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) $engine; ALTER TABLE t1 DROP COLUMN f; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 77a582a7139..e58eaca4cee 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2005, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2013, 2018, MariaDB Corporation. +Copyright (c) 2013, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -10359,6 +10359,10 @@ commit_cache_norebuild( } } } + + if (!ctx->instant_table->persistent_autoinc) { + ctx->new_table->persistent_autoinc = 0; + } } if (ha_alter_info->handler_flags & ALTER_COLUMN_UNVERSIONED) {