summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin Kumar <sachin.setiya@mariadb.com>2021-06-11 14:26:19 +0100
committerSachin Kumar <sachin.setiya@mariadb.com>2021-06-11 14:26:19 +0100
commitb1881e07797e2ea1ef258e384791368940b4e4c6 (patch)
treec4d3041450f19d8e86cc1cf8c6af72a68f44e0dd
parent8a2b4d531dc661ee605eeecdfc901bc833f86564 (diff)
downloadmariadb-git-bb-10.4-20131.tar.gz
MDEV-20131 Assertion `!pk->has_virtual ()' failed in instant_alter_column_possiblebb-10.4-20131
Problem:- Primary key on long unique columns is not allowed but when `CREATE TABLE t2 (a TEXT, PRIMARY KEY(a(1871))) ENGINE=InnoDB;` is executed with innodb_page_size=8k or 4k, primary key on DB_ROW_HASH_1 column is created. Reason of this is in mysql_prepare_create_table we check against max_key_part_length() to see whether key_part length is more then engine supported key_part length , and if it is true error is thrown for primary key and long unique index is created for unique key. But in this case max_key_part_length() returns 3072 which is more the max_key_length() , which later in code triggers creating of long unique index. Solution:- max_supported_key_part_length() should return according to innodb page size.
-rw-r--r--mysql-test/main/long_unique_bugs.opt1
-rw-r--r--mysql-test/main/long_unique_bugs.result4
-rw-r--r--mysql-test/main/long_unique_bugs.test6
-rw-r--r--storage/innobase/handler/ha_innodb.cc23
4 files changed, 25 insertions, 9 deletions
diff --git a/mysql-test/main/long_unique_bugs.opt b/mysql-test/main/long_unique_bugs.opt
new file mode 100644
index 00000000000..058a129cdc2
--- /dev/null
+++ b/mysql-test/main/long_unique_bugs.opt
@@ -0,0 +1 @@
+--innodb-page-size=8K
diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result
index 5d6c0562c8a..e1c5738e2aa 100644
--- a/mysql-test/main/long_unique_bugs.result
+++ b/mysql-test/main/long_unique_bugs.result
@@ -148,7 +148,7 @@ ALTER TABLE t1 DROP KEY f, ADD INDEX idx1(f), ALGORITHM=INSTANT;
ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY
ALTER TABLE t1 ADD KEY idx2(f);
Warnings:
-Note 1071 Specified key was too long; max key length is 3072 bytes
+Note 1071 Specified key was too long; max key length is 1536 bytes
DROP TABLE t1;
CREATE TABLE t1(a blob , b blob , unique(a,b));
alter table t1 drop column b;
@@ -288,3 +288,5 @@ Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_par
t2 0 a 1 a A NULL NULL NULL YES HASH
t2 0 a 2 b A NULL NULL NULL YES HASH
DROP TABLE t1,t2;
+CREATE TABLE t2 (a TEXT, PRIMARY KEY(a(1871))) ENGINE=InnoDB;
+ERROR 42000: Specified key was too long; max key length is 1536 bytes
diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test
index 34d02b1c8f4..b38ce881802 100644
--- a/mysql-test/main/long_unique_bugs.test
+++ b/mysql-test/main/long_unique_bugs.test
@@ -368,3 +368,9 @@ show index from t2;
# Cleanup
DROP TABLE t1,t2;
+
+#
+# MDEV-20131 Assertion `!pk->has_virtual ()' failed in instant_alter_column_possible
+# (.opt file is created which will make innodb_page_size=8k)
+--error ER_TOO_LONG_KEY
+CREATE TABLE t2 (a TEXT, PRIMARY KEY(a(1871))) ENGINE=InnoDB;
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index ce2e4b6990f..e5e864bffc5 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -6537,14 +6537,21 @@ ha_innobase::clone(
DBUG_RETURN(new_handler);
}
-
-uint
-ha_innobase::max_supported_key_part_length() const
-/*==============================================*/
-{
- /* A table format specific index column length check will be performed
- at ha_innobase::add_index() and row_create_index_for_mysql() */
- return(REC_VERSION_56_MAX_INDEX_COL_LEN);
+uint ha_innobase::max_supported_key_part_length() const
+{
+ /* A table format specific index column length check will be performed
+ at ha_innobase::add_index() and row_create_index_for_mysql() */
+ /* FIXME: rewrite this as well as ha_innobase::max_supported_key_length()
+ using an API that considers the PRIMARY KEY as well as secondary index
+ metadata and the ROW_FORMAT and KEY_BLOCK_SIZE */
+ switch (srv_page_size) {
+ case 4096:
+ return 1173;
+ case 8192:
+ return 1536;
+ default:
+ return REC_VERSION_56_MAX_INDEX_COL_LEN;
+ }
}
/******************************************************************//**