Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-8687 Incorrect autoinc in imported tablespace after restart server #5024

Open
wants to merge 1 commit into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions mysql-test/suite/innodb/r/export_autoinc.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
drop table if exists t1;
CREATE TABLE t1(i serial);
INSERT INTO t1 VALUES(null);
CREATE TABLE t2(i int , j serial);
INSERT INTO t2 VALUES(1, null);
FLUSH TABLES test.t1 FOR EXPORT;
UNLOCK TABLES;
ALTER TABLE test.t1 DISCARD TABLESPACE;
ALTER TABLE test.t1 IMPORT TABLESPACE;
CHECK TABLE test.t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SHOW CREATE TABLE test.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` bigint unsigned NOT NULL AUTO_INCREMENT,
UNIQUE KEY `i` (`i`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SELECT * FROM test.t1;
i
1
# Flush the table and put IBD/CFG files aside for later import.
FLUSH TABLE t1 FOR EXPORT;
"copy done"
UNLOCK TABLES;
ALTER TABLE t1 DISCARD TABLESPACE;
ALTER TABLE t1 IMPORT TABLESPACE;
INSERT INTO t1 VALUES(null);
FLUSH TABLE t2 FOR EXPORT;
"copy done"
UNLOCK TABLES;
ALTER TABLE t2 DISCARD TABLESPACE;
ALTER TABLE t2 IMPORT TABLESPACE;
INSERT INTO t2 VALUES(1, null);
# restart
INSERT INTO t1 VALUES(null);
DROP TABLE t1;
INSERT INTO t2 VALUES(3,null);
DROP TABLE t2;
53 changes: 53 additions & 0 deletions mysql-test/suite/innodb/t/export_autoinc.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--disable_warnings
drop table if exists t1;
--enable_warnings

CREATE TABLE t1(i serial);
INSERT INTO t1 VALUES(null);

CREATE TABLE t2(i int , j serial);
INSERT INTO t2 VALUES(1, null);
--source suite/innodb/include/import.inc

--echo # Flush the table and put IBD/CFG files aside for later import.
FLUSH TABLE t1 FOR EXPORT;

--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/t1.ibd_back
--echo "copy done"
--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/t1.cfg_back

UNLOCK TABLES;

ALTER TABLE t1 DISCARD TABLESPACE;

--copy_file $MYSQLD_DATADIR/t1.ibd_back $MYSQLD_DATADIR/test/t1.ibd
--copy_file $MYSQLD_DATADIR/t1.cfg_back $MYSQLD_DATADIR/test/t1.cfg

ALTER TABLE t1 IMPORT TABLESPACE;

INSERT INTO t1 VALUES(null);

FLUSH TABLE t2 FOR EXPORT;

--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/t2.ibd_back
--echo "copy done"
--copy_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_DATADIR/t2.cfg_back

UNLOCK TABLES;

ALTER TABLE t2 DISCARD TABLESPACE;

--copy_file $MYSQLD_DATADIR/t2.ibd_back $MYSQLD_DATADIR/test/t2.ibd
--copy_file $MYSQLD_DATADIR/t2.cfg_back $MYSQLD_DATADIR/test/t2.cfg

ALTER TABLE t2 IMPORT TABLESPACE;

INSERT INTO t2 VALUES(1, null);

--source include/restart_mysqld.inc

INSERT INTO t1 VALUES(null);
DROP TABLE t1;

INSERT INTO t2 VALUES(3,null);
DROP TABLE t2;
2 changes: 2 additions & 0 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15890,6 +15890,8 @@ int ha_innobase::discard_or_import_tablespace(bool discard,
err = row_import_for_mysql(dict_table, table_def, m_prebuilt);

if (err == DB_SUCCESS) {
dict_table_autoinc_set_col_pos(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With normal table, after a restart, can you please how the autoin column position is set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please get stack trace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* frame #0: 0x0000000102e62388 mysqlddict_table_autoinc_set_col_pos(table=0x000000012d737e90, pos=0) at dict0dict.ic:1253:53
frame #1: 0x0000000102e40c20 mysqlddict_table_t* dd_open_table_one<dd::Table>(client=0x000000014f068a70, table=0x000000012f11ec20, norm_name="test/t1", dd_table=0x000000012d74ac30, thd=0x000000014f94ac00, fk_list=size=0) at dict0dd.cc:4934:5 frame #2: 0x0000000102e2b42c mysqlddict_table_t* dd_open_tabledd::Table(client=0x000000014f068a70, table=0x000000012f11ec20, norm_name="test/t1", dd_table=0x000000012d74ac30, thd=0x000000014f94ac00) at dict0dd.cc:5255:13
frame #3: 0x00000001030ae5b0 mysqldha_innobase::open(this=0x000000012f11f630, name="./test/t1", (null)=2, open_flags=2, table_def=0x000000012d74ac30) at ha_innodb.cc:7778:18 frame #4: 0x00000001007cace4 mysqldhandler::ha_open(this=0x000000012f11f630, table_arg=0x000000012f11ec20, name="./test/t1", mode=2, test_if_locked=2, table_def=0x000000012d74ac30) at handler.cc:2892:16
frame #5: 0x00000001011c194c mysqldopen_table_from_share(thd=0x000000014f94ac00, share=0x000000012f183c30, alias="t1", db_stat=39, prgflag=8, ha_open_flags=0, outparam=0x000000012f11ec20, is_create_table=false, table_def_param=0x000000012d74ac30) at table.cc:3257:36 frame #6: 0x0000000100e125fc mysqldopen_table(thd=0x000000014f94ac00, table_list=0x000000014f959718, ot_ctx=0x0000000179eb51f8) at sql_base.cc:3422:13
frame #7: 0x0000000100e18cb8 mysqldopen_and_process_table(thd=0x000000014f94ac00, lex=0x000000014f938c00, tables=0x000000014f959718, counter=0x000000014f938c58, prelocking_strategy=0x0000000179eb5318, has_prelocking_list=false, ot_ctx=0x0000000179eb51f8) at sql_base.cc:5122:15 frame #8: 0x0000000100e17938 mysqldopen_tables(thd=0x000000014f94ac00, start=0x0000000179eb5328, counter=0x000000014f938c58, flags=0, prelocking_strategy=0x0000000179eb5318) at sql_base.cc:5943:15
frame #9: 0x0000000100e1c9c0 mysqldopen_tables_for_query(thd=0x000000014f94ac00, tables=0x000000014f959718, flags=0) at sql_base.cc:6825:7 frame #10: 0x000000010104b3e0 mysqldSql_cmd_dml::prepare(this=0x000000014f959da0, thd=0x000000014f94ac00) at sql_select.cc:360:7
frame #11: 0x000000010104c644 mysqldSql_cmd_dml::execute(this=0x000000014f959da0, thd=0x000000014f94ac00) at sql_select.cc:534:9 frame #12: 0x0000000100f8dc3c mysqldmysql_execute_command(thd=0x000000014f94ac00, first_level=true) at sql_parse.cc:3815:29
frame #13: 0x0000000100f89430 mysqlddispatch_sql_command(thd=0x000000014f94ac00, parser_state=0x0000000179eb9678, update_userstat=false) at sql_parse.cc:5576:19 frame #14: 0x0000000100f84cf0 mysqlddispatch_command(thd=0x000000014f94ac00, com_data=0x0000000179ebae10, command=COM_QUERY) at sql_parse.cc:2125:7
frame #15: 0x0000000100f87428 mysqlddo_command(thd=0x000000014f94ac00) at sql_parse.cc:1497:18 frame #16: 0x00000001012ec21c mysqldhandle_connection(arg=0x00006000031823e0) at connection_handler_per_thread.cc:308:13
frame #17: 0x0000000103731a9c mysqldpfs_spawn_thread(arg=0x000000014f0687c0) at pfs.cc:2987:3 frame #18: 0x000000018cec606c libsystem_pthread.dylib_pthread_start + 148`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulmalik87 before the import, the table would have been opened and the autoin col pos is set. Do we destroy the opened table object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in another way, the question is, why it is unset at the time of import? Before import, table open would have set it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of import we explicit set autoinc col pos to UNDEF inside row0import.cc
/* This should be set later in handler level, where we know the autoinc counter field index */ table->autoinc_field_no = ULINT_UNDEFINED;

dict_table, table->found_next_number_field->field_index());
info(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE |
HA_STATUS_AUTO);
}
Expand Down