diff options
author | Mattias Jonsson <mattias.jonsson@oracle.com> | 2010-08-16 14:53:30 +0200 |
---|---|---|
committer | Mattias Jonsson <mattias.jonsson@oracle.com> | 2010-08-16 14:53:30 +0200 |
commit | 4b20ccafaa3bacfd11c5fcc61e1647dbbefe7bad (patch) | |
tree | c70fa0c8e6b1e40f9c93c89eed5cb4337b1b681c /sql/sql_parse.cc | |
parent | 0058f16d933d6de41e670348080ce625d8109b47 (diff) | |
download | mariadb-git-4b20ccafaa3bacfd11c5fcc61e1647dbbefe7bad.tar.gz |
Bug#49907: ALTER TABLE ... TRUNCATE PARTITION does not wait for
locks on the table
Fixing the partitioning specifics after TRUNCATE TABLE in
bug-42643 was fixed.
Reorganize of code to decrease the size of the giant switch
in mysql_execute_command, and to prepare for future parser
reengineering. Moved code into Sql_statement objects.
Updated patch according to davi's review comments.
libmysqld/CMakeLists.txt:
Added new files.
libmysqld/Makefile.am:
Added new files.
mysql-test/r/not_partition.result:
now returning error on partitioning commands
if partitioning is not enabled.
mysql-test/r/partition_disabled.result:
There is no partition handlerton, so it cannot
find the specified engine in the .frm file.
mysql-test/r/partition_truncate.result:
Updated test results.
mysql-test/suite/parts/inc/partition_mgm.inc:
Added check that TRUNCATE PARTITION does not delete on failure.
mysql-test/suite/parts/r/partition_debug_sync_innodb.result:
updated results.
mysql-test/suite/parts/r/partition_mgm_lc0_archive.result:
updated results.
mysql-test/suite/parts/r/partition_mgm_lc1_archive.result:
updated results.
mysql-test/suite/parts/r/partition_mgm_lc2_archive.result:
updated results.
mysql-test/suite/parts/t/partition_debug_sync_innodb.test:
Test case for this bug.
mysql-test/t/not_partition.test:
Added check for TRUNCATE PARTITION without partitioning.
mysql-test/t/partition_truncate.test:
Added test of TRUNCATE PARTITION on non partitioned table.
sql/CMakeLists.txt:
Added new files.
sql/Makefile.am:
Added new files.
sql/datadict.cc:
Moved out the storage engine check into an own
function, including assert for lock.
sql/datadict.h:
added dd_frm_storage_engine.
sql/sql_alter_table.cc:
moved the code for SQLCOM_ALTER_TABLE in mysql_execute_command
into its own file, and using the Sql_statement object to
prepare for future parser reengineering.
sql/sql_alter_table.h:
Created Sql_statement object for ALTER TABLE.
sql/sql_lex.cc:
resetting m_stmt.
sql/sql_lex.h:
Temporary hack for forward declaration of enum_alter_table_change_level.
sql/sql_parse.cc:
Moved out ALTER/ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE
from the giant switch into their own Sql_statement
objects.
sql/sql_parse.h:
Exporting check_merge_table_access.
sql/sql_partition_admin.cc:
created Sql_statement for
ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR/TRUNCATE
PARTITION. To be able to reuse the TABLE equivalents.
sql/sql_partition_admin.h:
Added Sql_statement of partition admin statements.
sql/sql_table.cc:
Moved table maintenance code into sql_table_maintenance.cc
sql/sql_table.h:
Moved table maintenance code into sql_table_maintenance.h
exporting functions used by sql_table_maintenance.
sql/sql_table_maintenance.cc:
Moved table maintenance code from sql_table.cc
sql/sql_table_maintenance.h:
Sql_statement objects for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
Also declaring the keycache functions.
sql/sql_truncate.cc:
Moved code from SQLCOM_TRUNCATE in mysql_execute_command into
Truncate_statement::execute.
Added check for partitioned table on TRUNCATE PARTITION.
Moved locking fix for partitioned table into
Alter_table_truncate_partition::execute.
sql/sql_truncate.h:
Truncate_statement declaration (sub class of Sql_statement).
sql/sql_yacc.yy:
Using the new Sql_statment objects.
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r-- | sql/sql_parse.cc | 176 |
1 files changed, 11 insertions, 165 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fbcfb3f49c2..2f02188d122 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -50,6 +50,7 @@ // mysql_backup_table, // mysql_restore_table #include "sql_truncate.h" // mysql_truncate_table +#include "sql_table_maintenance.h" // mysql_assign_to_keycache #include "sql_connect.h" // check_user, // decrease_user_connections, // thd_init_client_charset, check_mqh, @@ -659,8 +660,7 @@ end: every child. Set 'db' for every child if not present. */ #ifndef NO_EMBEDDED_ACCESS_CHECKS -static bool check_merge_table_access(THD *thd, char *db, - TABLE_LIST *table_list) +bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list) { int error= 0; @@ -2831,77 +2831,6 @@ end_with_restore_list: } #endif /* HAVE_REPLICATION */ - case SQLCOM_ALTER_TABLE: - DBUG_ASSERT(first_table == all_tables && first_table != 0); - { - ulong priv=0; - ulong priv_needed= ALTER_ACL; - /* - Code in mysql_alter_table() may modify its HA_CREATE_INFO argument, - so we have to use a copy of this structure to make execution - prepared statement- safe. A shallow copy is enough as no memory - referenced from this structure will be modified. - */ - HA_CREATE_INFO create_info(lex->create_info); - Alter_info alter_info(lex->alter_info, thd->mem_root); - - if (thd->is_fatal_error) /* out of memory creating a copy of alter_info */ - goto error; - /* - We also require DROP priv for ALTER TABLE ... DROP PARTITION, as well - as for RENAME TO, as being done by SQLCOM_RENAME_TABLE - */ - if (alter_info.flags & (ALTER_DROP_PARTITION | ALTER_RENAME)) - priv_needed|= DROP_ACL; - - /* Must be set in the parser */ - DBUG_ASSERT(select_lex->db); - if (check_access(thd, priv_needed, first_table->db, - &first_table->grant.privilege, - &first_table->grant.m_internal, - 0, 0) || - check_access(thd, INSERT_ACL | CREATE_ACL, select_lex->db, - &priv, - NULL, /* Do not use first_table->grant with select_lex->db */ - 0, 0) || - check_merge_table_access(thd, first_table->db, - create_info.merge_list.first)) - goto error; /* purecov: inspected */ - if (check_grant(thd, priv_needed, all_tables, FALSE, UINT_MAX, FALSE)) - goto error; - if (lex->name.str && !test_all_bits(priv,INSERT_ACL | CREATE_ACL)) - { // Rename of table - TABLE_LIST tmp_table; - bzero((char*) &tmp_table,sizeof(tmp_table)); - tmp_table.table_name= lex->name.str; - tmp_table.db=select_lex->db; - tmp_table.grant.privilege=priv; - if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, FALSE, - UINT_MAX, FALSE)) - goto error; - } - - /* Don't yet allow changing of symlinks with ALTER TABLE */ - if (create_info.data_file_name) - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), - "DATA DIRECTORY"); - if (create_info.index_file_name) - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), - "INDEX DIRECTORY"); - create_info.data_file_name= create_info.index_file_name= NULL; - - thd->enable_slow_log= opt_log_slow_admin_statements; - res= mysql_alter_table(thd, select_lex->db, lex->name.str, - &create_info, - first_table, - &alter_info, - select_lex->order_list.elements, - select_lex->order_list.first, - lex->ignore); - break; - } case SQLCOM_RENAME_TABLE: { DBUG_ASSERT(first_table == all_tables && first_table != 0); @@ -3021,81 +2950,6 @@ end_with_restore_list: res = mysql_checksum_table(thd, first_table, &lex->check_opt); break; } - case SQLCOM_REPAIR: - { - DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, - FALSE, UINT_MAX, FALSE)) - goto error; /* purecov: inspected */ - thd->enable_slow_log= opt_log_slow_admin_statements; - res= mysql_repair_table(thd, first_table, &lex->check_opt); - /* ! we write after unlocking the table */ - if (!res && !lex->no_write_to_binlog) - { - /* - Presumably, REPAIR and binlog writing doesn't require synchronization - */ - res= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); - } - select_lex->table_list.first= first_table; - lex->query_tables=all_tables; - break; - } - case SQLCOM_CHECK: - { - DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_table_access(thd, SELECT_ACL, all_tables, - TRUE, UINT_MAX, FALSE)) - goto error; /* purecov: inspected */ - thd->enable_slow_log= opt_log_slow_admin_statements; - res = mysql_check_table(thd, first_table, &lex->check_opt); - select_lex->table_list.first= first_table; - lex->query_tables=all_tables; - break; - } - case SQLCOM_ANALYZE: - { - DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, - FALSE, UINT_MAX, FALSE)) - goto error; /* purecov: inspected */ - thd->enable_slow_log= opt_log_slow_admin_statements; - res= mysql_analyze_table(thd, first_table, &lex->check_opt); - /* ! we write after unlocking the table */ - if (!res && !lex->no_write_to_binlog) - { - /* - Presumably, ANALYZE and binlog writing doesn't require synchronization - */ - res= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); - } - select_lex->table_list.first= first_table; - lex->query_tables=all_tables; - break; - } - - case SQLCOM_OPTIMIZE: - { - DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, - FALSE, UINT_MAX, FALSE)) - goto error; /* purecov: inspected */ - thd->enable_slow_log= opt_log_slow_admin_statements; - res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ? - mysql_recreate_table(thd, first_table) : - mysql_optimize_table(thd, first_table, &lex->check_opt); - /* ! we write after unlocking the table */ - if (!res && !lex->no_write_to_binlog) - { - /* - Presumably, OPTIMIZE and binlog writing doesn't require synchronization - */ - res= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); - } - select_lex->table_list.first= first_table; - lex->query_tables=all_tables; - break; - } case SQLCOM_UPDATE: { ha_rows found= 0, updated= 0; @@ -3316,23 +3170,6 @@ end_with_restore_list: break; } - case SQLCOM_TRUNCATE: - DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_one_table_access(thd, DROP_ACL, all_tables)) - goto error; - /* - Don't allow this within a transaction because we want to use - re-generate table - */ - if (thd->in_active_multi_stmt_transaction()) - { - my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); - goto error; - } - if (! (res= mysql_truncate_table(thd, first_table))) - my_ok(thd); - break; case SQLCOM_DELETE: { DBUG_ASSERT(first_table == all_tables && first_table != 0); @@ -4718,6 +4555,14 @@ create_sp_error: my_ok(thd, 1); break; } + case SQLCOM_ANALYZE: + case SQLCOM_CHECK: + case SQLCOM_OPTIMIZE: + case SQLCOM_REPAIR: + case SQLCOM_TRUNCATE: + case SQLCOM_ALTER_TABLE: + DBUG_ASSERT(first_table == all_tables && first_table != 0); + /* fall through */ case SQLCOM_SIGNAL: case SQLCOM_RESIGNAL: DBUG_ASSERT(lex->m_stmt != NULL); @@ -7853,6 +7698,7 @@ bool parse_sql(THD *thd, { bool ret_value; DBUG_ASSERT(thd->m_parser_state == NULL); + DBUG_ASSERT(thd->lex->m_stmt == NULL); MYSQL_QUERY_PARSE_START(thd->query()); /* Backup creation context. */ |