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 15, 2023
1 parent 0d24af2 commit c4e4562
Show file tree
Hide file tree
Showing 2 changed files with 75 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
68 changes: 68 additions & 0 deletions storage/innobase/xtrabackup/test/t/xb_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,71 @@ vlog "Checksums are OK"
stop_server

rm -rf $backup_dir
rm -rf $mysql_datadir
rm -rf $topdir/backup/

vlog "#PXB-2797: Schema mismatch when importing table with full-text index from backup"

start_server

mysql test <<EOF
CREATE TABLE test.t1 (
c1 int NOT NULL AUTO_INCREMENT,
c2 varchar(50) NOT NULL,
PRIMARY KEY (c1),
FULLTEXT KEY idx (c2)
) ENGINE=InnoDB;
INSERT INTO test.t1 (c2) values ("text1");
INSERT INTO test.t1 (c2) values ("text2");
CREATE TABLE test.t2 (
c1 int NOT NULL AUTO_INCREMENT,
c2 int NOT NULL,
c3 int NOT NULL,
PRIMARY KEY (c1),
INDEX idx1 (c2 ASC),
UNIQUE INDEX idx2 (c2 DESC),
INDEX idx3 (c2 ASC, c3 DESC)
) ENGINE=InnoDB;
INSERT INTO test.t2 (c2, c3) values (1000, 2000);
INSERT INTO test.t2 (c2, c3) values (2000, 3000);
INSERT INTO test.t2 (c2, c3) values (3000, 4000);
CREATE TABLE test.t3 (
c1 int NOT NULL AUTO_INCREMENT,
c2 GEOMETRY NOT NULL,
PRIMARY KEY (c1),
SPATIAL INDEX idx (c2)
) ENGINE=InnoDB;
INSERT INTO test.t3 (c2) values (ST_GeomFromText('POINT(1 1)'));
INSERT INTO test.t3 (c2) values (ST_GeomFromText('LINESTRING(15 5,15 25)'));
INSERT INTO test.t3 (c2) values (ST_GeomFromText('POLYGON((65 0,75 25,85 0,75 5,65 0))'));
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;"

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

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

verify_db_state test
rm -rf $topdir/backup/

0 comments on commit c4e4562

Please sign in to comment.