Commit 622d21e2 authored by Marko Mäkelä's avatar Marko Mäkelä

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).
parent b9227410
......@@ -3638,48 +3638,46 @@ row_drop_table_for_mysql(
pars_info_add_str_literal(info, "table_name", name);
std::basic_string<char, std::char_traits<char>,
ut_allocator<char> > sql;
sql.reserve(2000);
sql = "PROCEDURE DROP_TABLE_PROC () IS\n"
err = que_eval_sql(
info,
"PROCEDURE DROP_TABLE_PROC () IS\n"
"sys_foreign_id CHAR;\n"
"table_id CHAR;\n"
"index_id CHAR;\n"
"foreign_id CHAR;\n"
"space_id INT;\n"
"found INT;\n";
"found INT;\n"
sql += "DECLARE CURSOR cur_fk IS\n"
"DECLARE CURSOR cur_fk IS\n"
"SELECT ID FROM SYS_FOREIGN\n"
"WHERE FOR_NAME = :table_name\n"
"AND TO_BINARY(FOR_NAME)\n"
" = TO_BINARY(:table_name)\n"
"LOCK IN SHARE MODE;\n";
"LOCK IN SHARE MODE;\n"
sql += "DECLARE CURSOR cur_idx IS\n"
"DECLARE CURSOR cur_idx IS\n"
"SELECT ID FROM SYS_INDEXES\n"
"WHERE TABLE_ID = table_id\n"
"LOCK IN SHARE MODE;\n";
"LOCK IN SHARE MODE;\n"
sql += "BEGIN\n";
"BEGIN\n"
sql += "SELECT ID INTO table_id\n"
"SELECT ID INTO table_id\n"
"FROM SYS_TABLES\n"
"WHERE NAME = :table_name\n"
"LOCK IN SHARE MODE;\n"
"IF (SQL % NOTFOUND) THEN\n"
" RETURN;\n"
"END IF;\n";
"END IF;\n"
sql += "SELECT SPACE INTO space_id\n"
"SELECT SPACE INTO space_id\n"
"FROM SYS_TABLES\n"
"WHERE NAME = :table_name;\n"
"IF (SQL % NOTFOUND) THEN\n"
" RETURN;\n"
"END IF;\n";
"END IF;\n"
sql += "found := 1;\n"
"found := 1;\n"
"SELECT ID INTO sys_foreign_id\n"
"FROM SYS_TABLES\n"
"WHERE NAME = 'SYS_FOREIGN'\n"
......@@ -3693,9 +3691,9 @@ row_drop_table_for_mysql(
"IF (:table_name = 'SYS_FOREIGN_COLS') \n"
"THEN\n"
" found := 0;\n"
"END IF;\n";
"END IF;\n"
sql += "OPEN cur_fk;\n"
"OPEN cur_fk;\n"
"WHILE found = 1 LOOP\n"
" FETCH cur_fk INTO foreign_id;\n"
" IF (SQL % NOTFOUND) THEN\n"
......@@ -3708,9 +3706,9 @@ row_drop_table_for_mysql(
" WHERE ID = foreign_id;\n"
" END IF;\n"
"END LOOP;\n"
"CLOSE cur_fk;\n";
"CLOSE cur_fk;\n"
sql += "found := 1;\n"
"found := 1;\n"
"OPEN cur_idx;\n"
"WHILE found = 1 LOOP\n"
" FETCH cur_idx INTO index_id;\n"
......@@ -3724,26 +3722,22 @@ row_drop_table_for_mysql(
" AND TABLE_ID = table_id;\n"
" END IF;\n"
"END LOOP;\n"
"CLOSE cur_idx;\n";
"CLOSE cur_idx;\n"
sql += "DELETE FROM SYS_COLUMNS\n"
"DELETE FROM SYS_COLUMNS\n"
"WHERE TABLE_ID = table_id;\n"
"DELETE FROM SYS_TABLES\n"
"WHERE NAME = :table_name;\n";
"WHERE NAME = :table_name;\n"
if (dict_table_is_file_per_table(table)) {
sql += "DELETE FROM SYS_TABLESPACES\n"
"DELETE FROM SYS_TABLESPACES\n"
"WHERE SPACE = space_id;\n"
"DELETE FROM SYS_DATAFILES\n"
"WHERE SPACE = space_id;\n";
}
sql += "DELETE FROM SYS_VIRTUAL\n"
"WHERE TABLE_ID = table_id;\n";
sql += "END;\n";
"WHERE SPACE = space_id;\n"
err = que_eval_sql(info, sql.c_str(), FALSE, trx);
"DELETE FROM SYS_VIRTUAL\n"
"WHERE TABLE_ID = table_id;\n"
"END;\n",
FALSE, trx);
} else {
page_no = page_nos;
for (dict_index_t* index = dict_table_get_first_index(table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment