Skip to content

Commit

Permalink
PXB-2797: Schema mismatch when importing table with full-text index f…
Browse files Browse the repository at this point in the history
…rom xtrabackup backup

https://jira.percona.com/browse/PXB-2797

When importing a single table (IMPORT TABLESPACE) from a backup made using xtrabackup and the table contains a full-text index the import process will error out with:
`ERROR 1808 (HY000) at line 132: Schema mismatch (Index xxxxxx field xxxxxx is ascending which does not match metadata file which is descending)`

The problem occurs because FTS tables are created internally by InnoDB Storage engine and they do not choose any ordering flag. Default is UNDEF.
This patch solves the issue by treating UNDEF order as ASC when creating dict_table_t on `--prepare` step.
  • Loading branch information
aybek committed Dec 11, 2023
1 parent 0d24af2 commit ae44289
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion storage/innobase/dict/dict0dd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ ulint get_innobase_type_from_dd(const dd::Column *col, ulint &unsigned_type) {
return MYSQL_TYPE_LONG;
}

#ifdef XTRABACKUP
dict_table_t *dd_table_create_on_dd_obj(const dd::Table *dd_table,
const dd::Partition *dd_part,
const dd::String_type *schema_name,
Expand Down Expand Up @@ -981,7 +982,11 @@ dict_table_t *dd_table_create_on_dd_obj(const dd::Table *dd_table,
if (c->is_virtual() == dd_col->is_virtual()) col_pos++;
}

bool is_asc = (idx_elem->order() == dd::Index_element::ORDER_ASC);
/* FULLTEXT and HASH indexes can have UNDEF order, we should treat UNDEF
* as ASC */
bool is_asc = (idx_elem->order() == dd::Index_element::ORDER_ASC ||
idx_elem->order() == dd::Index_element::ORDER_UNDEF);

ulint prefix_len = 0;

if (dd_index->type() == dd::Index::IT_SPATIAL) {
Expand Down Expand Up @@ -1211,6 +1216,7 @@ dict_table_t *dd_table_create_on_dd_obj(const dd::Table *dd_table,

return (table);
}
#endif /* XTRABACKUP */

table_id_t dd_table_id_and_part(space_id_t space_id, const dd::Table &dd_table,
const dd::Partition *&dd_part) {
Expand Down
32 changes: 32 additions & 0 deletions storage/innobase/xtrabackup/test/t/pxb-2797.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# PXB-2797: Schema mismatch when importing table with full-text index from backup
#

start_server

mysql test <<EOF
CREATE TABLE test.t1 (
t1_id int NOT NULL AUTO_INCREMENT,
t1_text varchar(50) DEFAULT NULL,
PRIMARY KEY (t1_id),
FULLTEXT KEY t1_textx (t1_text)
) ENGINE=InnoDB;
INSERT INTO test.t1 (t1_text) values ("text1");
EOF

xtrabackup --backup --target-dir=$topdir/backup

record_db_state test

shutdown_server

xtrabackup --prepare --export --target-dir=$topdir/backup

start_server

mysql -e "ALTER TABLE test.t1 DISCARD TABLESPACE;"
cp $topdir/backup/test/t1.ibd $mysql_datadir/test/t1.ibd
cp $topdir/backup/test/t1.cfg $mysql_datadir/test/t1.cfg
mysql -e "ALTER TABLE test.t1 IMPORT TABLESPACE;"

verify_db_state test

0 comments on commit ae44289

Please sign in to comment.