Skip to content

Commit 622d21e

Browse files
committed
row_drop_table_for_mysql(): Use a constant string
It does not hurt to delete non-existing records from SYS_TABLESPACES and SYS_DATAFILES. Because MariaDB does not support CREATE TABLESPACE, only the system tablespace (space_id=0) can contain multiple tables. But, there are no entries for the system tablespace in these tables (which actually are stored inside the system tablespace).
1 parent b922741 commit 622d21e

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

storage/innobase/row/row0mysql.cc

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,48 +3638,46 @@ row_drop_table_for_mysql(
36383638

36393639
pars_info_add_str_literal(info, "table_name", name);
36403640

3641-
std::basic_string<char, std::char_traits<char>,
3642-
ut_allocator<char> > sql;
3643-
sql.reserve(2000);
3644-
3645-
sql = "PROCEDURE DROP_TABLE_PROC () IS\n"
3641+
err = que_eval_sql(
3642+
info,
3643+
"PROCEDURE DROP_TABLE_PROC () IS\n"
36463644
"sys_foreign_id CHAR;\n"
36473645
"table_id CHAR;\n"
36483646
"index_id CHAR;\n"
36493647
"foreign_id CHAR;\n"
36503648
"space_id INT;\n"
3651-
"found INT;\n";
3649+
"found INT;\n"
36523650

3653-
sql += "DECLARE CURSOR cur_fk IS\n"
3651+
"DECLARE CURSOR cur_fk IS\n"
36543652
"SELECT ID FROM SYS_FOREIGN\n"
36553653
"WHERE FOR_NAME = :table_name\n"
36563654
"AND TO_BINARY(FOR_NAME)\n"
36573655
" = TO_BINARY(:table_name)\n"
3658-
"LOCK IN SHARE MODE;\n";
3656+
"LOCK IN SHARE MODE;\n"
36593657

3660-
sql += "DECLARE CURSOR cur_idx IS\n"
3658+
"DECLARE CURSOR cur_idx IS\n"
36613659
"SELECT ID FROM SYS_INDEXES\n"
36623660
"WHERE TABLE_ID = table_id\n"
3663-
"LOCK IN SHARE MODE;\n";
3661+
"LOCK IN SHARE MODE;\n"
36643662

3665-
sql += "BEGIN\n";
3663+
"BEGIN\n"
36663664

3667-
sql += "SELECT ID INTO table_id\n"
3665+
"SELECT ID INTO table_id\n"
36683666
"FROM SYS_TABLES\n"
36693667
"WHERE NAME = :table_name\n"
36703668
"LOCK IN SHARE MODE;\n"
36713669
"IF (SQL % NOTFOUND) THEN\n"
36723670
" RETURN;\n"
3673-
"END IF;\n";
3671+
"END IF;\n"
36743672

3675-
sql += "SELECT SPACE INTO space_id\n"
3673+
"SELECT SPACE INTO space_id\n"
36763674
"FROM SYS_TABLES\n"
36773675
"WHERE NAME = :table_name;\n"
36783676
"IF (SQL % NOTFOUND) THEN\n"
36793677
" RETURN;\n"
3680-
"END IF;\n";
3678+
"END IF;\n"
36813679

3682-
sql += "found := 1;\n"
3680+
"found := 1;\n"
36833681
"SELECT ID INTO sys_foreign_id\n"
36843682
"FROM SYS_TABLES\n"
36853683
"WHERE NAME = 'SYS_FOREIGN'\n"
@@ -3693,9 +3691,9 @@ row_drop_table_for_mysql(
36933691
"IF (:table_name = 'SYS_FOREIGN_COLS') \n"
36943692
"THEN\n"
36953693
" found := 0;\n"
3696-
"END IF;\n";
3694+
"END IF;\n"
36973695

3698-
sql += "OPEN cur_fk;\n"
3696+
"OPEN cur_fk;\n"
36993697
"WHILE found = 1 LOOP\n"
37003698
" FETCH cur_fk INTO foreign_id;\n"
37013699
" IF (SQL % NOTFOUND) THEN\n"
@@ -3708,9 +3706,9 @@ row_drop_table_for_mysql(
37083706
" WHERE ID = foreign_id;\n"
37093707
" END IF;\n"
37103708
"END LOOP;\n"
3711-
"CLOSE cur_fk;\n";
3709+
"CLOSE cur_fk;\n"
37123710

3713-
sql += "found := 1;\n"
3711+
"found := 1;\n"
37143712
"OPEN cur_idx;\n"
37153713
"WHILE found = 1 LOOP\n"
37163714
" FETCH cur_idx INTO index_id;\n"
@@ -3724,26 +3722,22 @@ row_drop_table_for_mysql(
37243722
" AND TABLE_ID = table_id;\n"
37253723
" END IF;\n"
37263724
"END LOOP;\n"
3727-
"CLOSE cur_idx;\n";
3725+
"CLOSE cur_idx;\n"
37283726

3729-
sql += "DELETE FROM SYS_COLUMNS\n"
3727+
"DELETE FROM SYS_COLUMNS\n"
37303728
"WHERE TABLE_ID = table_id;\n"
37313729
"DELETE FROM SYS_TABLES\n"
3732-
"WHERE NAME = :table_name;\n";
3733-
3734-
if (dict_table_is_file_per_table(table)) {
3735-
sql += "DELETE FROM SYS_TABLESPACES\n"
3736-
"WHERE SPACE = space_id;\n"
3737-
"DELETE FROM SYS_DATAFILES\n"
3738-
"WHERE SPACE = space_id;\n";
3739-
}
3740-
3741-
sql += "DELETE FROM SYS_VIRTUAL\n"
3742-
"WHERE TABLE_ID = table_id;\n";
3730+
"WHERE NAME = :table_name;\n"
37433731

3744-
sql += "END;\n";
3732+
"DELETE FROM SYS_TABLESPACES\n"
3733+
"WHERE SPACE = space_id;\n"
3734+
"DELETE FROM SYS_DATAFILES\n"
3735+
"WHERE SPACE = space_id;\n"
37453736

3746-
err = que_eval_sql(info, sql.c_str(), FALSE, trx);
3737+
"DELETE FROM SYS_VIRTUAL\n"
3738+
"WHERE TABLE_ID = table_id;\n"
3739+
"END;\n",
3740+
FALSE, trx);
37473741
} else {
37483742
page_no = page_nos;
37493743
for (dict_index_t* index = dict_table_get_first_index(table);

0 commit comments

Comments
 (0)