[MDEV-15937] Assertion failure 'key->flags & 1' on ALTER TABLE Created: 2018-04-20  Updated: 2018-04-23  Resolved: 2018-04-23

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.2.2, 10.3.0
Fix Version/s: 10.0.35, 10.1.33, 10.2.15, 10.3.7

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: online-ddl, upstream


 Description   

This was originally reported by Roel as MySQL Bug #89087 Assertion `key->flags & 1' failed.

CREATE TABLE t1(c1 INT) ENGINE=InnoDB;
ALTER TABLE t1 ADD CONSTRAINT UNIQUE KEY i1(c1);
ALTER TABLE t1 CHANGE c1 c1 INT NOT NULL,ADD KEY(c1);
DROP TABLE t1;

There is a fix for this in MySQL 8.0.11, but I think that we should fix this differently in MariaDB, and starting from the first potentially affected version (10.0). I was not able to repeat a failure on 10.0 even after adding a debug assertion.

For 10.2, the minimal fix should be as follows:

diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 02a8428cdc9..20bac687ccf 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -2597,10 +2597,8 @@ innobase_create_key_defs(
 				DBUG_ASSERT(got_default_clust);
 				DBUG_ASSERT(altered_table->s->primary_key
 					    == 0);
-				primary_key_number = 0;
-			} else {
-				primary_key_number = *add;
 			}
+			primary_key_number = altered_table->s->primary_key;
 		} else if (got_default_clust) {
 			/* Create the GEN_CLUST_INDEX */
 			index_def_t*	index = indexdef++;


Generated at Thu Feb 08 08:25:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.