Commit 1ebfa44b authored by Vasil Dimov's avatar Vasil Dimov

Use cursors for seeking records in SYS_FOREIGN and SYS_INDEXES from

DROP_TABLE_PROC().

With this change I observe a speedup from 6.2s to 0.1s when executing
DROP_TABLE_PROC() during DROP TABLE with 512 foreign keys, like what
is being done in innodb_bug56143.test

This fixes "Bug#11765460 DROP TABLE USES INEFFICIENT METHODS TO REMOVE
FKS/INDEXES FROM INNODB SYS TABLES"

Reviewed by:	Marko
parent c6b18288
...@@ -3221,6 +3221,19 @@ check_next_foreign: ...@@ -3221,6 +3221,19 @@ check_next_foreign:
"index_id CHAR;\n" "index_id CHAR;\n"
"foreign_id CHAR;\n" "foreign_id CHAR;\n"
"found INT;\n" "found INT;\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"
"DECLARE CURSOR cur_idx IS\n"
"SELECT ID FROM SYS_INDEXES\n"
"WHERE TABLE_ID = table_id\n"
"LOCK IN SHARE MODE;\n"
"BEGIN\n" "BEGIN\n"
"SELECT ID INTO table_id\n" "SELECT ID INTO table_id\n"
"FROM SYS_TABLES\n" "FROM SYS_TABLES\n"
...@@ -3243,13 +3256,9 @@ check_next_foreign: ...@@ -3243,13 +3256,9 @@ check_next_foreign:
"IF (:table_name = 'SYS_FOREIGN_COLS') THEN\n" "IF (:table_name = 'SYS_FOREIGN_COLS') THEN\n"
" found := 0;\n" " found := 0;\n"
"END IF;\n" "END IF;\n"
"OPEN cur_fk;\n"
"WHILE found = 1 LOOP\n" "WHILE found = 1 LOOP\n"
" SELECT ID INTO foreign_id\n" " FETCH cur_fk INTO foreign_id;\n"
" 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"
" IF (SQL % NOTFOUND) THEN\n" " IF (SQL % NOTFOUND) THEN\n"
" found := 0;\n" " found := 0;\n"
" ELSE\n" " ELSE\n"
...@@ -3259,12 +3268,11 @@ check_next_foreign: ...@@ -3259,12 +3268,11 @@ check_next_foreign:
" WHERE ID = foreign_id;\n" " WHERE ID = foreign_id;\n"
" END IF;\n" " END IF;\n"
"END LOOP;\n" "END LOOP;\n"
"CLOSE cur_fk;\n"
"found := 1;\n" "found := 1;\n"
"OPEN cur_idx;\n"
"WHILE found = 1 LOOP\n" "WHILE found = 1 LOOP\n"
" SELECT ID INTO index_id\n" " FETCH cur_idx INTO index_id;\n"
" FROM SYS_INDEXES\n"
" WHERE TABLE_ID = table_id\n"
" LOCK IN SHARE MODE;\n"
" IF (SQL % NOTFOUND) THEN\n" " IF (SQL % NOTFOUND) THEN\n"
" found := 0;\n" " found := 0;\n"
" ELSE\n" " ELSE\n"
...@@ -3275,6 +3283,7 @@ check_next_foreign: ...@@ -3275,6 +3283,7 @@ check_next_foreign:
" AND TABLE_ID = table_id;\n" " AND TABLE_ID = table_id;\n"
" END IF;\n" " END IF;\n"
"END LOOP;\n" "END LOOP;\n"
"CLOSE cur_idx;\n"
"DELETE FROM SYS_COLUMNS\n" "DELETE FROM SYS_COLUMNS\n"
"WHERE TABLE_ID = table_id;\n" "WHERE TABLE_ID = table_id;\n"
"DELETE FROM SYS_TABLES\n" "DELETE FROM SYS_TABLES\n"
......
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