mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
4b20ccafaa
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.
205 lines
8.5 KiB
C++
205 lines
8.5 KiB
C++
/* Copyright 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
#ifndef SQL_PARSE_INCLUDED
|
|
#define SQL_PARSE_INCLUDED
|
|
|
|
#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
|
|
#include "sql_acl.h" /* GLOBAL_ACLS */
|
|
|
|
class Comp_creator;
|
|
class Item;
|
|
class Object_creation_ctx;
|
|
class Parser_state;
|
|
struct TABLE_LIST;
|
|
class THD;
|
|
class Table_ident;
|
|
struct LEX;
|
|
|
|
enum enum_mysql_completiontype {
|
|
ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7,
|
|
COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6
|
|
};
|
|
|
|
extern "C" int test_if_data_home_dir(const char *dir);
|
|
|
|
bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
|
|
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
|
|
int mysql_multi_update_prepare(THD *thd);
|
|
int mysql_multi_delete_prepare(THD *thd);
|
|
bool mysql_insert_select_prepare(THD *thd);
|
|
bool update_precheck(THD *thd, TABLE_LIST *tables);
|
|
bool delete_precheck(THD *thd, TABLE_LIST *tables);
|
|
bool insert_precheck(THD *thd, TABLE_LIST *tables);
|
|
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
|
|
TABLE_LIST *create_table);
|
|
|
|
bool parse_sql(THD *thd,
|
|
Parser_state *parser_state,
|
|
Object_creation_ctx *creation_ctx);
|
|
|
|
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
|
|
|
|
void free_items(Item *item);
|
|
void cleanup_items(Item *item);
|
|
|
|
Comp_creator *comp_eq_creator(bool invert);
|
|
Comp_creator *comp_ge_creator(bool invert);
|
|
Comp_creator *comp_gt_creator(bool invert);
|
|
Comp_creator *comp_le_creator(bool invert);
|
|
Comp_creator *comp_lt_creator(bool invert);
|
|
Comp_creator *comp_ne_creator(bool invert);
|
|
|
|
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
|
|
enum enum_schema_tables schema_table_idx);
|
|
void get_default_definer(THD *thd, LEX_USER *definer);
|
|
LEX_USER *create_default_definer(THD *thd);
|
|
LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name);
|
|
LEX_USER *get_current_user(THD *thd, LEX_USER *user);
|
|
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
|
|
uint max_byte_length);
|
|
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
|
|
uint max_char_length, CHARSET_INFO *cs,
|
|
bool no_error);
|
|
CHARSET_INFO* merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl);
|
|
bool check_host_name(LEX_STRING *str);
|
|
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
|
|
uint err_code, const char *param_for_err_msg);
|
|
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
|
|
bool sqlcom_can_generate_row_events(const THD *thd);
|
|
bool is_update_query(enum enum_sql_command command);
|
|
bool is_log_table_write_query(enum enum_sql_command command);
|
|
bool alloc_query(THD *thd, const char *packet, uint packet_length);
|
|
void mysql_init_select(LEX *lex);
|
|
void mysql_parse(THD *thd, char *rawbuf, uint length,
|
|
Parser_state *parser_state);
|
|
void mysql_reset_thd_for_next_command(THD *thd);
|
|
bool mysql_new_select(LEX *lex, bool move_down);
|
|
void create_select_for_variable(const char *var_name);
|
|
void create_table_set_open_action_and_adjust_tables(LEX *lex);
|
|
void mysql_init_multi_delete(LEX *lex);
|
|
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
|
|
void create_table_set_open_action_and_adjust_tables(LEX *lex);
|
|
pthread_handler_t handle_bootstrap(void *arg);
|
|
bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
|
|
bool *write_to_binlog);
|
|
int mysql_execute_command(THD *thd);
|
|
bool do_command(THD *thd);
|
|
void do_handle_bootstrap(THD *thd);
|
|
bool dispatch_command(enum enum_server_command command, THD *thd,
|
|
char* packet, uint packet_length);
|
|
void log_slow_statement(THD *thd);
|
|
bool append_file_to_dir(THD *thd, const char **filename_ptr,
|
|
const char *table_name);
|
|
bool append_file_to_dir(THD *thd, const char **filename_ptr,
|
|
const char *table_name);
|
|
void execute_init_command(THD *thd, LEX_STRING *init_command,
|
|
mysql_rwlock_t *var_lock);
|
|
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
|
|
char *length, char *decimal,
|
|
uint type_modifier,
|
|
Item *default_value, Item *on_update_value,
|
|
LEX_STRING *comment,
|
|
char *change, List<String> *interval_list,
|
|
CHARSET_INFO *cs,
|
|
uint uint_geom_type);
|
|
bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group, bool asc);
|
|
void add_join_on(TABLE_LIST *b,Item *expr);
|
|
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
|
|
SELECT_LEX *lex);
|
|
bool add_proc_to_list(THD *thd, Item *item);
|
|
bool push_new_name_resolution_context(THD *thd,
|
|
TABLE_LIST *left_op,
|
|
TABLE_LIST *right_op);
|
|
void store_position_for_column(const char *name);
|
|
void init_update_queries(void);
|
|
bool check_simple_select();
|
|
Item *negate_expression(THD *thd, Item *expr);
|
|
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
|
|
|
|
/* Variables */
|
|
|
|
extern const char* any_db;
|
|
extern uint sql_command_flags[];
|
|
extern uint server_command_flags[];
|
|
extern const LEX_STRING command_name[];
|
|
extern uint server_command_flags[];
|
|
|
|
/* Inline functions */
|
|
inline bool check_identifier_name(LEX_STRING *str, uint err_code)
|
|
{
|
|
return check_identifier_name(str, NAME_CHAR_LEN, err_code, "");
|
|
}
|
|
|
|
inline bool check_identifier_name(LEX_STRING *str)
|
|
{
|
|
return check_identifier_name(str, NAME_CHAR_LEN, 0, "");
|
|
}
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
|
|
bool check_single_table_access(THD *thd, ulong privilege,
|
|
TABLE_LIST *tables, bool no_errors);
|
|
bool check_routine_access(THD *thd,ulong want_access,char *db,char *name,
|
|
bool is_proc, bool no_errors);
|
|
bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
|
|
bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list);
|
|
bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc);
|
|
bool check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
|
|
GRANT_INTERNAL_INFO *grant_internal_info,
|
|
bool dont_check_global_grants, bool no_errors);
|
|
bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
|
|
bool any_combination_of_privileges_will_do,
|
|
uint number,
|
|
bool no_errors);
|
|
#else
|
|
inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables)
|
|
{ return false; }
|
|
inline bool check_single_table_access(THD *thd, ulong privilege,
|
|
TABLE_LIST *tables, bool no_errors)
|
|
{ return false; }
|
|
inline bool check_routine_access(THD *thd,ulong want_access,char *db,
|
|
char *name, bool is_proc, bool no_errors)
|
|
{ return false; }
|
|
inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table)
|
|
{
|
|
table->grant.privilege= want_access;
|
|
return false;
|
|
}
|
|
inline bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list)
|
|
{ return false; }
|
|
inline bool check_some_routine_access(THD *thd, const char *db,
|
|
const char *name, bool is_proc)
|
|
{ return false; }
|
|
inline bool check_access(THD *, ulong, const char *, ulong *save_priv,
|
|
GRANT_INTERNAL_INFO *, bool, bool)
|
|
{
|
|
if (save_priv)
|
|
*save_priv= GLOBAL_ACLS;
|
|
return false;
|
|
}
|
|
inline bool
|
|
check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
|
|
bool any_combination_of_privileges_will_do,
|
|
uint number,
|
|
bool no_errors)
|
|
{ return false; }
|
|
#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
|
|
|
|
/* These were under the INNODB_COMPATIBILITY_HOOKS */
|
|
|
|
bool check_global_access(THD *thd, ulong want_access);
|
|
|
|
#endif /* SQL_PARSE_INCLUDED */
|