Skip to content

Commit e8bb94c

Browse files
committed
MDEV-16499 [10.1] ER_NO_SUCH_TABLE_IN_ENGINE followed by "Please drop the table and recreate" upon adding FULLTEXT key to table with virtual column
There was an incorrect check for MariaDB and InnoDB tables fields count. Corruption was reported when there was no corruption. Also, a warning message had incorrect field numbers for both MariaDB and InnoDB tables. ha_innobase::open(): fixed check and message
1 parent 14f6b0c commit e8bb94c

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

mysql-test/suite/innodb/r/innodb-virtual-columns.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,18 @@ term uw_id plan wdraw_rsn admit_term
320320
1035 2 CSM ACAD 1009
321321
drop table grad_degree;
322322
drop table gso_grad_supr;
323+
CREATE TABLE t1 (a INT, b CHAR(12), c INT AS (a) VIRTUAL, FULLTEXT KEY(b)) ENGINE=InnoDB;
324+
INSERT INTO t1 (a,b) VALUES (1,'foo');
325+
SELECT * FROM t1;
326+
a b c
327+
1 foo 1
328+
DROP TABLE t1;
329+
CREATE TABLE t1 (a INT, b CHAR(12), c INT AS (a) VIRTUAL) ENGINE=InnoDB;
330+
INSERT INTO t1 (a,b) VALUES (1,'foo');
331+
ALTER TABLE t1 ADD FULLTEXT KEY(b);
332+
Warnings:
333+
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
334+
SELECT * FROM t1;
335+
a b c
336+
1 foo 1
337+
DROP TABLE t1;

mysql-test/suite/innodb/t/innodb-virtual-columns.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,14 @@ select * from gso_grad_supr;
300300

301301
drop table grad_degree;
302302
drop table gso_grad_supr;
303+
304+
CREATE TABLE t1 (a INT, b CHAR(12), c INT AS (a) VIRTUAL, FULLTEXT KEY(b)) ENGINE=InnoDB;
305+
INSERT INTO t1 (a,b) VALUES (1,'foo');
306+
SELECT * FROM t1;
307+
DROP TABLE t1;
308+
309+
CREATE TABLE t1 (a INT, b CHAR(12), c INT AS (a) VIRTUAL) ENGINE=InnoDB;
310+
INSERT INTO t1 (a,b) VALUES (1,'foo');
311+
ALTER TABLE t1 ADD FULLTEXT KEY(b);
312+
SELECT * FROM t1;
313+
DROP TABLE t1;

storage/innobase/handler/ha_innodb.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,19 +5312,21 @@ ha_innobase::open(
53125312
ib_table = dict_table_open_on_name(norm_name, FALSE, TRUE, ignore_err);
53135313

53145314
if (ib_table
5315-
&& ((!DICT_TF2_FLAG_IS_SET(ib_table, DICT_TF2_FTS_HAS_DOC_ID)
5316-
&& table->s->stored_fields != dict_table_get_n_user_cols(ib_table))
5317-
|| (DICT_TF2_FLAG_IS_SET(ib_table, DICT_TF2_FTS_HAS_DOC_ID)
5318-
&& (table->s->fields
5319-
!= dict_table_get_n_user_cols(ib_table) - 1)))) {
5315+
&& (table->s->stored_fields != dict_table_get_n_user_cols(ib_table)
5316+
- (DICT_TF2_FLAG_IS_SET(ib_table, DICT_TF2_FTS_HAS_DOC_ID)
5317+
? 1 : 0))) {
53205318
ib_logf(IB_LOG_LEVEL_WARN,
53215319
"table %s contains %lu user defined columns "
53225320
"in InnoDB, but %lu columns in MySQL. Please "
53235321
"check INFORMATION_SCHEMA.INNODB_SYS_COLUMNS and "
53245322
REFMAN "innodb-troubleshooting.html "
53255323
"for how to resolve it",
5326-
norm_name, (ulong) dict_table_get_n_user_cols(ib_table),
5327-
(ulong) table->s->fields);
5324+
norm_name,
5325+
(ulong) (dict_table_get_n_user_cols(ib_table)
5326+
- DICT_TF2_FLAG_IS_SET(ib_table,
5327+
DICT_TF2_FTS_HAS_DOC_ID)
5328+
? 1 : 0),
5329+
(ulong) table->s->stored_fields);
53285330

53295331
/* Mark this table as corrupted, so the drop table
53305332
or force recovery can still use it, but not others. */

storage/xtradb/handler/ha_innodb.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5984,19 +5984,21 @@ ha_innobase::open(
59845984
ib_table = dict_table_open_on_name(norm_name, FALSE, TRUE, ignore_err);
59855985

59865986
if (ib_table
5987-
&& ((!DICT_TF2_FLAG_IS_SET(ib_table, DICT_TF2_FTS_HAS_DOC_ID)
5988-
&& table->s->stored_fields != dict_table_get_n_user_cols(ib_table))
5989-
|| (DICT_TF2_FLAG_IS_SET(ib_table, DICT_TF2_FTS_HAS_DOC_ID)
5990-
&& (table->s->fields
5991-
!= dict_table_get_n_user_cols(ib_table) - 1)))) {
5987+
&& (table->s->stored_fields != dict_table_get_n_user_cols(ib_table)
5988+
- (DICT_TF2_FLAG_IS_SET(ib_table, DICT_TF2_FTS_HAS_DOC_ID)
5989+
? 1 : 0))) {
59925990
ib_logf(IB_LOG_LEVEL_WARN,
59935991
"table %s contains %lu user defined columns "
59945992
"in InnoDB, but %lu columns in MySQL. Please "
59955993
"check INFORMATION_SCHEMA.INNODB_SYS_COLUMNS and "
59965994
REFMAN "innodb-troubleshooting.html "
59975995
"for how to resolve it",
5998-
norm_name, (ulong) dict_table_get_n_user_cols(ib_table),
5999-
(ulong) table->s->fields);
5996+
norm_name,
5997+
(ulong) (dict_table_get_n_user_cols(ib_table)
5998+
- DICT_TF2_FLAG_IS_SET(ib_table,
5999+
DICT_TF2_FTS_HAS_DOC_ID)
6000+
? 1 : 0),
6001+
(ulong) table->s->stored_fields);
60006002

60016003
/* Mark this table as corrupted, so the drop table
60026004
or force recovery can still use it, but not others. */

0 commit comments

Comments
 (0)