diff options
Diffstat (limited to 'sql')
252 files changed, 7061 insertions, 3987 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 913eb3464e2..396c8b1fd27 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -41,7 +41,7 @@ ENDIF() SET (SQL_SOURCE ../sql-common/client.c derror.cc des_key_file.cc discover.cc ../libmysql/errmsg.c field.cc field_conv.cc - filesort.cc gstream.cc + filesort.cc gstream.cc sha2.cc ha_partition.cc handler.cc hash_filo.cc hash_filo.h sql_plugin_services.h hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc @@ -66,7 +66,7 @@ SET (SQL_SOURCE sql_repl.cc sql_select.cc sql_show.cc sql_state.c sql_string.cc sql_table.cc sql_test.cc sql_trigger.cc sql_udf.cc sql_union.cc sql_update.cc sql_view.cc strfunc.cc table.cc thr_malloc.cc - time.cc tztime.cc uniques.cc unireg.cc item_xmlfunc.cc + sql_time.cc tztime.cc uniques.cc unireg.cc item_xmlfunc.cc rpl_tblmap.cc sql_binlog.cc event_scheduler.cc event_data_objects.cc event_queue.cc event_db_repository.cc sql_tablespace.cc events.cc ../sql-common/my_user.c diff --git a/sql/Makefile.am b/sql/Makefile.am index 9a60cbcbf66..93595a964eb 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -84,22 +84,29 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ item_strfunc.h item_timefunc.h \ item_xmlfunc.h sql_plugin_services.h \ item_create.h item_subselect.h item_row.h \ - mysql_priv.h item_geofunc.h sql_bitmap.h \ + sql_priv.h item_geofunc.h sql_bitmap.h \ procedure.h sql_class.h sql_lex.h sql_list.h \ sql_map.h sql_string.h unireg.h \ sql_error.h field.h handler.h mysqld_suffix.h \ - sql_profile.h \ + sql_profile.h mysqld.h sql_help.h frm_crypt.h \ ha_ndbcluster.h ha_ndbcluster_cond.h \ ha_ndbcluster_binlog.h ha_ndbcluster_tables.h \ ha_partition.h rpl_constants.h \ debug_sync.h \ opt_range.h protocol.h rpl_tblmap.h rpl_utility.h \ - rpl_reporting.h \ + rpl_reporting.h sql_locale.h sql_parse.h \ log.h sql_show.h rpl_rli.h rpl_mi.h \ sql_select.h structs.h table.h sql_udf.h hash_filo.h \ - lex.h lex_symbol.h sql_acl.h sql_crypt.h \ + lex.h lex_symbol.h sql_acl.h sql_crypt.h sql_base.h \ + sql_table.h key.h lock.h thr_malloc.h strfunc.h \ + sql_delete.h sql_insert.h sql_update.h sql_db.h \ + sql_connect.h sql_rename.h sql_time.h sql_tablespace.h \ + hostname.h sql_test.h records.h filesort.h \ + sql_derived.h sql_load.h sql_handler.h init.h \ + derror.h sql_union.h des_key_file.h sql_binlog.h \ + discover.h sql_manager.h sql_do.h \ sql_repl.h slave.h rpl_filter.h rpl_injector.h \ - log_event.h rpl_record.h \ + log_event.h rpl_record.h sql_const.h \ log_event_old.h rpl_record_old.h \ sql_sort.h sql_cache.h set_var.h sys_vars_shared.h \ spatial.h gstream.h client_settings.h tzfile.h \ @@ -137,7 +144,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ unireg.cc des_key_file.cc \ log_event.cc rpl_record.cc \ log_event_old.cc rpl_record_old.cc \ - discover.cc time.cc opt_range.cc opt_sum.cc \ + discover.cc sql_time.cc opt_range.cc opt_sum.cc \ records.cc filesort.cc handler.cc \ ha_partition.cc \ debug_sync.cc \ @@ -160,7 +167,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ sql_plugin.cc sql_binlog.cc \ sql_builtin.cc sql_tablespace.cc partition_info.cc \ sql_servers.cc event_parse_data.cc sql_signal.cc \ - rpl_handler.cc mdl.cc transaction.cc sql_audit.cc + rpl_handler.cc mdl.cc transaction.cc sql_audit.cc \ + sha2.cc nodist_mysqld_SOURCES = mini_client_errors.c pack.c client.c my_time.c my_user.c diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 517aab93707..d16fa4b2468 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -321,12 +321,13 @@ /* Due to weaknesses in our include files, we need to include - mysql_priv.h here. To have THD declared, we need to include + sql_priv.h here. To have THD declared, we need to include sql_class.h. This includes log_event.h, which in turn requires - declarations from mysql_priv.h (e.g. OPTION_AUTO_IS_NULL). - mysql_priv.h includes almost everything, so is sufficient here. + declarations from sql_priv.h (e.g. OPTION_AUTO_IS_NULL). + sql_priv.h includes almost everything, so is sufficient here. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_parse.h" /* Action to perform at a synchronization point. @@ -394,7 +395,7 @@ extern "C" void (*debug_sync_C_callback_ptr)(const char *, size_t); We cannot place a sync point directly in C files (like those in mysys or certain storage engines written mostly in C like MyISAM or Maria). Because - they are C code and do not include mysql_priv.h. So they do not know the + they are C code and do not include sql_priv.h. So they do not know the macro DEBUG_SYNC(thd, sync_point_name). The macro needs a 'thd' argument. Hence it cannot be used in files outside of the sql/ directory. @@ -1867,4 +1868,42 @@ void debug_sync(THD *thd, const char *sync_point_name, size_t name_len) DBUG_VOID_RETURN; } +/** + Define debug sync action. + + @param[in] thd thread handle + @param[in] action_str action string + + @return status + @retval FALSE ok + @retval TRUE error + + @description + The function is similar to @c debug_sync_eval_action but is + to be called immediately from the server code rather than + to be triggered by setting a value to DEBUG_SYNC system variable. + + @note + The input string is copied prior to be fed to + @c debug_sync_eval_action to let the latter modify it. + + Caution. + The function allocates in THD::mem_root and therefore + is not recommended to be deployed inside big loops. +*/ + +bool debug_sync_set_action(THD *thd, const char *action_str, size_t len) +{ + bool rc; + char *value; + DBUG_ENTER("debug_sync_set_action"); + DBUG_ASSERT(thd); + DBUG_ASSERT(action_str); + + value= strmake_root(thd->mem_root, action_str, len); + rc= debug_sync_eval_action(thd, value); + DBUG_RETURN(rc); +} + + #endif /* defined(ENABLED_DEBUG_SYNC) */ diff --git a/sql/debug_sync.h b/sql/debug_sync.h index f4cd0b364cf..9ac7da39d4d 100644 --- a/sql/debug_sync.h +++ b/sql/debug_sync.h @@ -50,6 +50,7 @@ extern void debug_sync_end(void); extern void debug_sync_init_thread(THD *thd); extern void debug_sync_end_thread(THD *thd); extern void debug_sync(THD *thd, const char *sync_point_name, size_t name_len); +extern bool debug_sync_set_action(THD *thd, const char *action_str, size_t len); #else /* defined(ENABLED_DEBUG_SYNC) */ diff --git a/sql/derror.cc b/sql/derror.cc index 8e47dda7bbe..04a82860d45 100644 --- a/sql/derror.cc +++ b/sql/derror.cc @@ -21,8 +21,13 @@ Read language depeneded messagefile */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "derror.h" #include "mysys_err.h" +#include "mysqld.h" // lc_messages_dir +#include "derror.h" // read_texts +#include "sql_class.h" // THD static void init_myfunc_errs(void); diff --git a/sql/derror.h b/sql/derror.h new file mode 100644 index 00000000000..cb8ae91acbc --- /dev/null +++ b/sql/derror.h @@ -0,0 +1,25 @@ +/* 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 DERROR_INCLUDED +#define DERROR_INCLUDED + +#include "my_global.h" /* uint */ + +bool init_errmessage(void); +bool read_texts(const char *file_name, const char *language, + const char ***point, uint error_messages); + +#endif /* DERROR_INCLUDED */ diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index c2b632e521b..d2bf2ebdaa7 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -13,7 +13,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "my_global.h" // HAVE_* +#include "sql_priv.h" +#include "des_key_file.h" // st_des_keyschedule, st_des_keyblock +#include "log.h" // sql_print_error #include <m_ctype.h> #ifdef HAVE_OPENSSL diff --git a/sql/des_key_file.h b/sql/des_key_file.h new file mode 100644 index 00000000000..d817ff93949 --- /dev/null +++ b/sql/des_key_file.h @@ -0,0 +1,40 @@ +/* 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 DES_KEY_FILE_INCLUDED +#define DES_KEY_FILE_INCLUDED + +#ifdef HAVE_OPENSSL +#include <openssl/des.h> + +#include "violite.h" /* DES_cblock, DES_key_schedule */ + +struct st_des_keyblock +{ + DES_cblock key1, key2, key3; +}; + +struct st_des_keyschedule +{ + DES_key_schedule ks1, ks2, ks3; +}; + +extern struct st_des_keyschedule des_keyschedule[10]; +extern uint des_default_key; + +bool load_des_key_file(const char *file_name); +#endif /* HAVE_OPENSSL */ + +#endif /* DES_KEY_FILE_INCLUDED */ diff --git a/sql/discover.cc b/sql/discover.cc index fcc26042fe2..f50f7deed99 100644 --- a/sql/discover.cc +++ b/sql/discover.cc @@ -21,7 +21,9 @@ Functions for discover of frm file from handler */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "discover.h" #include <my_dir.h> /** diff --git a/sql/discover.h b/sql/discover.h new file mode 100644 index 00000000000..54fb78ddd2f --- /dev/null +++ b/sql/discover.h @@ -0,0 +1,24 @@ +/* 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 DISCOVER_INCLUDED +#define DISCOVER_INCLUDED + +#include "my_global.h" /* uchar */ + +int readfrm(const char *name, uchar **data, size_t *length); +int writefrm(const char* name, const uchar* data, size_t len); + +#endif /* DISCOVER_INCLUDED */ diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 7f4104f4a77..28fd1e240a2 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -14,11 +14,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include "sql_parse.h" // parse_sql +#include "strfunc.h" // find_string_in_array +#include "sql_db.h" // get_default_db_collation +#include "sql_time.h" // interval_type_to_name, + // date_add_interval, + // calc_time_diff +#include "tztime.h" // my_tz_find, my_tz_OFFSET0, struct Time_zone +#include "sql_acl.h" // EVENT_ACL, SUPER_ACL +#include "sp.h" // load_charset, load_collation #include "events.h" #include "event_data_objects.h" #include "event_db_repository.h" #include "sp_head.h" +#include "sql_show.h" // append_definer, append_identifier /** @addtogroup Event_Scheduler diff --git a/sql/event_data_objects.h b/sql/event_data_objects.h index e32077b9c97..9d17213bcb8 100644 --- a/sql/event_data_objects.h +++ b/sql/event_data_objects.h @@ -23,6 +23,12 @@ */ #include "event_parse_data.h" +#include "thr_lock.h" /* thr_lock_type */ + +class Field; +class THD; +class Time_zone; +struct TABLE; class Event_queue_element_for_exec { diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 0696652deb1..b7c01f10066 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -13,12 +13,21 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_base.h" // close_thread_tables #include "event_db_repository.h" +#include "key.h" // key_copy +#include "sql_db.h" // get_default_db_collation +#include "sql_time.h" // interval_type_to_name +#include "tztime.h" // struct Time_zone +#include "sql_acl.h" // SUPER_ACL, MYSQL_DB_FIELD_COUNT, mysql_db_table_fields +#include "records.h" // init_read_record, end_read_record #include "sp_head.h" #include "event_data_objects.h" #include "events.h" #include "sql_show.h" +#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT /** @addtogroup Event_Scheduler diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc index 86905b38627..c36567fc8e1 100644 --- a/sql/event_parse_data.cc +++ b/sql/event_parse_data.cc @@ -13,9 +13,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sp_head.h" #include "event_parse_data.h" +#include "sql_time.h" // TIME_to_timestamp /* Returns a new instance diff --git a/sql/event_parse_data.h b/sql/event_parse_data.h index 8b42eb23937..4ca46b40d3f 100644 --- a/sql/event_parse_data.h +++ b/sql/event_parse_data.h @@ -16,6 +16,12 @@ #ifndef _EVENT_PARSE_DATA_H_ #define _EVENT_PARSE_DATA_H_ +#include "sql_list.h" /* Sql_alloc */ + +class Item; +class THD; +class sp_name; + #define EVEX_GET_FIELD_FAILED -2 #define EVEX_BAD_PARAMS -5 #define EVEX_MICROSECOND_UNSUP -6 diff --git a/sql/event_queue.cc b/sql/event_queue.cc index 225029040b0..f0310c676d1 100644 --- a/sql/event_queue.cc +++ b/sql/event_queue.cc @@ -13,10 +13,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "event_queue.h" #include "event_data_objects.h" #include "sql_audit.h" +#include "tztime.h" // my_tz_find, my_tz_OFFSET0, struct Time_zone +#include "log.h" // sql_print_error +#include "sql_class.h" // struct THD /** @addtogroup Event_Scheduler diff --git a/sql/event_queue.h b/sql/event_queue.h index aac9eb04e98..93af03ba901 100644 --- a/sql/event_queue.h +++ b/sql/event_queue.h @@ -30,6 +30,10 @@ extern PSI_mutex_key key_LOCK_event_queue; extern PSI_cond_key key_COND_queue_state; #endif /* HAVE_PSI_INTERFACE */ +#include "queues.h" // QUEUE +#include "sql_string.h" /* LEX_STRING */ +#include "my_time.h" /* my_time_t, interval_type */ + class Event_basic; class Event_queue_element; class Event_queue_element_for_exec; diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 3ceb1597a41..c3cfd5c0fda 100755 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -13,12 +13,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "event_scheduler.h" #include "events.h" #include "event_data_objects.h" -#include "event_scheduler.h" #include "event_queue.h" #include "event_db_repository.h" +#include "sql_connect.h" // init_new_connection_handler_thread +#include "sql_acl.h" // SUPER_ACL /** @addtogroup Event_Scheduler diff --git a/sql/event_scheduler.h b/sql/event_scheduler.h index 2988f354f63..ecd7031f546 100644 --- a/sql/event_scheduler.h +++ b/sql/event_scheduler.h @@ -34,7 +34,9 @@ class Event_queue; class Event_job_data; class Event_db_repository; +class Event_queue_element_for_exec; class Events; +class THD; void pre_init_event_thread(THD* thd); diff --git a/sql/events.cc b/sql/events.cc index d8bf549321e..96b86e6798f 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc +/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -11,10 +11,19 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_parse.h" // check_access +#include "sql_base.h" // close_thread_tables +#include "sql_show.h" // append_definer #include "events.h" +#include "sql_db.h" // check_db_dir_existence +#include "sql_table.h" // write_bin_log +#include "tztime.h" // struct Time_zone +#include "sql_acl.h" // EVENT_ACL +#include "records.h" // init_read_record, end_read_record #include "event_data_objects.h" #include "event_db_repository.h" #include "event_queue.h" @@ -367,15 +376,14 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, { sql_print_error("Event Error: An error occurred while creating query string, " "before writing it into binary log."); - /* Restore the state of binlog format */ - DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row()); - if (save_binlog_row_based) - thd->set_current_stmt_binlog_format_row(); - DBUG_RETURN(TRUE); + ret= TRUE; + } + else + { + /* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER + will be written into the binary log as the definer for the SQL thread. */ + ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length()); } - /* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER - will be written into the binary log as the definer for the SQL thread. */ - ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length()); } } mysql_mutex_unlock(&LOCK_event_metadata); @@ -1017,7 +1025,11 @@ Events::dump_internal_status() puts("LLA = Last Locked At LUA = Last Unlocked At"); puts("WOC = Waiting On Condition DL = Data Locked"); - mysql_mutex_lock(&LOCK_event_metadata); + /* + opt_event_scheduler should only be accessed while + holding LOCK_global_system_variables. + */ + mysql_mutex_lock(&LOCK_global_system_variables); if (opt_event_scheduler == EVENTS_DISABLED) puts("The Event Scheduler is disabled"); else @@ -1026,7 +1038,7 @@ Events::dump_internal_status() event_queue->dump_internal_status(); } - mysql_mutex_unlock(&LOCK_event_metadata); + mysql_mutex_unlock(&LOCK_global_system_variables); DBUG_VOID_RETURN; } diff --git a/sql/events.h b/sql/events.h index 881ade37cbf..c84c37b881d 100644 --- a/sql/events.h +++ b/sql/events.h @@ -1,6 +1,6 @@ #ifndef _EVENT_H_ #define _EVENT_H_ -/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc +/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -13,7 +13,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** @defgroup Event_Scheduler Event Scheduler @@ -32,10 +32,17 @@ extern PSI_cond_key key_event_scheduler_COND_state; extern PSI_thread_key key_thread_event_scheduler, key_thread_event_worker; #endif /* HAVE_PSI_INTERFACE */ -class Event_parse_data; +#include "sql_string.h" /* LEX_STRING */ +#include "my_time.h" /* interval_type */ + class Event_db_repository; +class Event_parse_data; class Event_queue; class Event_scheduler; +struct TABLE_LIST; +class THD; +typedef class Item COND; +typedef struct charset_info_st CHARSET_INFO; /* Return codes */ enum enum_events_error_code @@ -83,6 +90,7 @@ public: See sys_var.cc */ enum enum_opt_event_scheduler { EVENTS_OFF, EVENTS_ON, EVENTS_DISABLED }; + /* Protected using LOCK_global_system_variables only. */ static uint opt_event_scheduler; static mysql_mutex_t LOCK_event_metadata; static bool check_if_system_tables_error(); @@ -107,9 +115,6 @@ public: destroy_mutexes(); static bool - switch_event_scheduler_state(enum enum_opt_event_scheduler new_state); - - static bool create_event(THD *thd, Event_parse_data *parse_data, bool if_exists); static bool diff --git a/sql/field.cc b/sql/field.cc index 51235d9f0e8..bd091f7eb57 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -25,10 +25,19 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" #include "sql_select.h" #include "rpl_rli.h" // Pull in Relay_log_info #include "slave.h" // Pull in rpl_master_has_bug() +#include "strfunc.h" // find_type2, find_set +#include "sql_time.h" // str_to_datetime_with_warn, + // str_to_time_with_warn, + // TIME_to_timestamp, + // make_time, make_date, + // make_truncated_value_warning +#include "tztime.h" // struct Time_zone +#include "filesort.h" // change_double_for_sort +#include "log_event.h" // class Table_map_log_event #include <m_ctype.h> #include <errno.h> @@ -2981,16 +2990,16 @@ Field_new_decimal::unpack(uchar* to, a decimal and write that to the raw data buffer. */ decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION]; - decimal_t dec; - dec.len= from_precision; - dec.buf= dec_buf; + decimal_t dec_val; + dec_val.len= from_precision; + dec_val.buf= dec_buf; /* Note: bin2decimal does not change the length of the field. So it is just the first step the resizing operation. The second step does the resizing using the precision and decimals from the slave. */ - bin2decimal((uchar *)from, &dec, from_precision, from_decimal); - decimal2bin(&dec, to, precision, decimals()); + bin2decimal((uchar *)from, &dec_val, from_precision, from_decimal); + decimal2bin(&dec_val, to, precision, decimals()); } else memcpy(to, from, len); // Sizes are the same, just copy the data. @@ -6287,7 +6296,7 @@ check_string_copy_error(Field_str *field, SYNOPSIS Field_longstr::report_if_important_data() - ptr - Truncated rest of string + pstr - Truncated rest of string end - End of truncated string count_spaces - Treat traling spaces as important data @@ -6303,12 +6312,12 @@ check_string_copy_error(Field_str *field, */ int -Field_longstr::report_if_important_data(const char *ptr, const char *end, +Field_longstr::report_if_important_data(const char *pstr, const char *end, bool count_spaces) { - if ((ptr < end) && table->in_use->count_cuted_fields) + if ((pstr < end) && table->in_use->count_cuted_fields) { - if (test_if_important_data(field_charset, ptr, end)) + if (test_if_important_data(field_charset, pstr, end)) { if (table->in_use->abort_on_warning) set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1); @@ -6613,8 +6622,20 @@ uchar *Field_string::pack(uchar *to, const uchar *from, local_char_length= my_charpos(field_charset, from, from+length, local_char_length); set_if_smaller(length, local_char_length); - while (length && from[length-1] == field_charset->pad_char) - length--; + + /* + TODO: change charset interface to add a new function that does + the following or add a flag to lengthsp to do it itself + (this is for not packing padding adding bytes in BINARY + fields). + */ + if (field_charset->mbmaxlen == 1) + { + while (length && from[length-1] == field_charset->pad_char) + length --; + } + else + length= field_charset->cset->lengthsp(field_charset, (const char*) from, length); // Length always stored little-endian *to++= (uchar) length; @@ -6680,7 +6701,7 @@ Field_string::unpack(uchar *to, memcpy(to, from, length); // Pad the string with the pad character of the fields charset - bfill(to + length, field_length - length, field_charset->pad_char); + field_charset->cset->fill(field_charset, (char*) to + length, field_length - length, field_charset->pad_char); return from+length; } @@ -6812,9 +6833,8 @@ const uint Field_varstring::MAX_SIZE= UINT_MAX16; */ int Field_varstring::do_save_field_metadata(uchar *metadata_ptr) { - char *ptr= (char *)metadata_ptr; DBUG_ASSERT(field_length <= 65535); - int2store(ptr, field_length); + int2store((char*)metadata_ptr, field_length); return 2; } diff --git a/sql/field.h b/sql/field.h index fb985ab9930..d1fcc40ff5d 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1,7 +1,7 @@ #ifndef FIELD_INCLUDED #define FIELD_INCLUDED -/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -14,7 +14,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Because of the function new_field() all field classes that have static @@ -25,6 +25,12 @@ #pragma interface /* gcc class implementation */ #endif +#include "mysqld.h" /* system_charset_info */ +#include "table.h" /* TABLE */ +#include "sql_string.h" /* String */ +#include "my_decimal.h" /* my_decimal */ +#include "sql_error.h" /* MYSQL_ERROR */ + #define DATETIME_DEC 6 const uint32 max_field_size= (uint32) 4294967295U; @@ -32,6 +38,33 @@ class Send_field; class Protocol; class Create_field; class Relay_log_info; +class Field; + +enum enum_check_fields +{ + CHECK_FIELD_IGNORE, + CHECK_FIELD_WARN, + CHECK_FIELD_ERROR_FOR_NULL +}; + + +enum Derivation +{ + DERIVATION_IGNORABLE= 6, + DERIVATION_NUMERIC= 5, + DERIVATION_COERCIBLE= 4, + DERIVATION_SYSCONST= 3, + DERIVATION_IMPLICIT= 2, + DERIVATION_NONE= 1, + DERIVATION_EXPLICIT= 0 +}; + +#define STORAGE_TYPE_MASK 7 +#define COLUMN_FORMAT_MASK 7 +#define COLUMN_FORMAT_SHIFT 3 + +#define my_charset_numeric my_charset_latin1 +#define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII struct st_cache_field; int field_conv(Field *to,Field *from); @@ -57,7 +90,11 @@ public: static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); } uchar *ptr; // Position to field in record - uchar *null_ptr; // Byte where null_bit is + /** + Byte where the @c NULL bit is stored inside a record. If this Field is a + @c NOT @c NULL field, this member is @c NULL. + */ + uchar *null_ptr; /* Note that you can use table->in_use as replacement for current_thd member only inside of val_*() and store() members (e.g. you can't use it in cons) @@ -254,6 +291,9 @@ public: inline void set_notnull(my_ptrdiff_t row_offset= 0) { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; } inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; } + /** + Signals that this field is NULL-able. + */ inline bool real_maybe_null(void) { return null_ptr != 0; } enum { diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 3574534722e..e3be33c0f3c 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -24,7 +24,8 @@ gives much more speed. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_class.h" // THD #include <m_ctype.h> static void do_field_eq(Copy_field *copy) diff --git a/sql/filesort.cc b/sql/filesort.cc index 79887577f8f..3f3dc4e1e3e 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -21,13 +21,17 @@ Sorts a database */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "filesort.h" +#include "unireg.h" // REQUIRED by other includes #ifdef HAVE_STDDEF_H #include <stddef.h> /* for macro offsetof */ #endif #include <m_ctype.h> #include "sql_sort.h" #include "probes_mysql.h" +#include "sql_test.h" // TEST_filesort +#include "opt_range.h" // SQL_SELECT #ifndef THREAD #define SKIP_DBUG_IN_FILESORT diff --git a/sql/filesort.h b/sql/filesort.h new file mode 100644 index 00000000000..c1a101cc1e8 --- /dev/null +++ b/sql/filesort.h @@ -0,0 +1,36 @@ +/* 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 FILESORT_INCLUDED +#define FILESORT_INCLUDED + +class SQL_SELECT; + +#include "my_global.h" /* uint, uchar */ +#include "my_base.h" /* ha_rows */ + +class SQL_SELECT; +class THD; +struct TABLE; +typedef struct st_sort_field SORT_FIELD; + +ha_rows filesort(THD *thd, TABLE *table, st_sort_field *sortorder, + uint s_length, SQL_SELECT *select, + ha_rows max_rows, bool sort_positions, + ha_rows *examined_rows); +void filesort_free_buffers(TABLE *table, bool full); +void change_double_for_sort(double nr,uchar *to); + +#endif /* FILESORT_INCLUDED */ diff --git a/sql/frm_crypt.cc b/sql/frm_crypt.cc index 590205e83ab..821e61c5247 100644 --- a/sql/frm_crypt.cc +++ b/sql/frm_crypt.cc @@ -21,7 +21,8 @@ ** mysql binary. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "frm_crypt.h" #ifdef HAVE_CRYPTED_FRM diff --git a/sql/frm_crypt.h b/sql/frm_crypt.h new file mode 100644 index 00000000000..e119dceae35 --- /dev/null +++ b/sql/frm_crypt.h @@ -0,0 +1,23 @@ +/* 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 FRM_CRYPT_INCLUDED +#define FRM_CRYPT_INCLUDED + +class SQL_CRYPT; + +SQL_CRYPT *get_crypt_for_frm(void); + +#endif /* FRM_CRYPT_INCLUDED */ diff --git a/sql/gstream.cc b/sql/gstream.cc index e2bb41b8541..fcb9a91ac50 100644 --- a/sql/gstream.cc +++ b/sql/gstream.cc @@ -18,7 +18,9 @@ NOTE: These functions assumes that the string is end \0 terminated! */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "gstream.h" +#include "m_string.h" // LEX_STRING enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type() { diff --git a/sql/gstream.h b/sql/gstream.h index ea7158ee1a3..65acc2ff193 100644 --- a/sql/gstream.h +++ b/sql/gstream.h @@ -17,6 +17,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "my_global.h" /* NULL, NullS */ +#include "my_sys.h" /* MY_ALLOW_ZERO_PTR */ +#include "m_ctype.h" /* my_charset_latin1, my_charset_bin */ + +typedef struct charset_info_st CHARSET_INFO; +typedef struct st_mysql_lex_string LEX_STRING; + class Gis_read_stream { public: diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 05a42220caf..38324f3cf19 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -26,7 +26,15 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_table.h" // build_table_filename, + // tablename_to_filename, + // filename_to_tablename +#include "sql_partition.h" // HA_CAN_*, partition_info, part_id_range +#include "sql_base.h" // close_cached_tables +#include "discover.h" // readfrm +#include "sql_acl.h" // wild_case_compare #include "rpl_mi.h" /* @@ -48,8 +56,11 @@ int ha_ndb_dummy; #include "ha_ndbcluster_binlog.h" #include "ha_ndbcluster_tables.h" -#include <mysql/plugin.h> +#include "sql_plugin.h" #include "probes_mysql.h" +#include "sql_show.h" // init_fill_schema_files_row, + // schema_table_store_record +#include "sql_test.h" // print_where #ifdef ndb_dynamite #undef assert diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 63da24e8dda..17ba7451538 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -51,6 +51,8 @@ class NdbIndexStat; class NdbEventOperation; class ha_ndbcluster_cond; +#include "sql_partition.h" /* part_id_range */ + // connectstring to cluster if given by mysqld extern const char *ndbcluster_connectstring; diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index 279d5b4c242..edb6aeebb5c 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -14,7 +14,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes #include "sql_show.h" #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE #include "ha_ndbcluster.h" @@ -28,6 +29,14 @@ #include "ndb_cluster_connection.hpp" #include <util/NdbAutoPtr.hpp> +#include "sql_base.h" // close_thread_tables +#include "sql_table.h" // build_table_filename +#include "table.h" // open_table_from_share +#include "discover.h" // readfrm, writefrm +#include "lock.h" // MYSQL_LOCK_IGNORE_FLUSH, + // mysql_unlock_tables +#include "sql_parse.h" // mysql_parse + #ifdef ndb_dynamite #undef assert #define assert(x) do { if(x) break; ::printf("%s %d: assert failed: %s\n", __FILE__, __LINE__, #x); ::fflush(stdout); ::signal(SIGABRT,SIG_DFL); ::abort(); ::kill(::getpid(),6); ::kill(::getpid(),9); } while (0) @@ -2346,7 +2355,6 @@ static int open_ndb_binlog_index(THD *thd, TABLE **ndb_binlog_index) thd->proc_info= "Opening " NDB_REP_DB "." NDB_REP_TABLE; tables->required_type= FRMTYPE_TABLE; - uint counter; thd->clear_error(); if (open_and_lock_tables(thd, tables, FALSE, 0)) { @@ -2374,7 +2382,6 @@ int ndb_add_ndb_binlog_index(THD *thd, void *_row) { ndb_binlog_index_row &row= *(ndb_binlog_index_row *) _row; int error= 0; - bool need_reopen; /* Turn of binlogging to prevent the table changes to be written to the binary log. diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h index 32dac553ee8..4d2a49588b4 100644 --- a/sql/ha_ndbcluster_binlog.h +++ b/sql/ha_ndbcluster_binlog.h @@ -17,6 +17,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "sql_class.h" /* THD */ + // Typedefs for long names typedef NdbDictionary::Object NDBOBJ; typedef NdbDictionary::Column NDBCOL; diff --git a/sql/ha_ndbcluster_cond.cc b/sql/ha_ndbcluster_cond.cc index bb35211944b..6df1f4881c3 100644 --- a/sql/ha_ndbcluster_cond.cc +++ b/sql/ha_ndbcluster_cond.cc @@ -22,7 +22,10 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_class.h" // set_var.h: THD +#include "my_global.h" // WITH_* +#include "log.h" // sql_print_error #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE #include <ndbapi/NdbApi.hpp> diff --git a/sql/ha_ndbcluster_cond.h b/sql/ha_ndbcluster_cond.h index 4ccc7e062ec..442eac2fafd 100644 --- a/sql/ha_ndbcluster_cond.h +++ b/sql/ha_ndbcluster_cond.h @@ -25,6 +25,13 @@ #pragma interface /* gcc class implementation */ #endif +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "set_var.h" /* Item, Item_field */ + typedef enum ndb_item_type { NDB_VALUE = 0, // Qualified more with Item::Type NDB_FIELD = 1, // Qualified from table definition diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index e0118d55d7b..b8831127e3f 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -51,12 +51,14 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_parse.h" // append_file_to_dir #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" - -#include <mysql/plugin.h> +#include "sql_table.h" // tablename_to_filename +#include "key.h" +#include "sql_plugin.h" static const char *ha_par_ext= ".par"; #ifdef NOT_USED @@ -5241,6 +5243,7 @@ int ha_partition::info(uint flag) file= m_file[handler_instance]; file->info(HA_STATUS_CONST); + stats.block_size= file->stats.block_size; stats.create_time= file->stats.create_time; ref_length= m_ref_length; } @@ -6625,9 +6628,22 @@ void ha_partition::release_auto_increment() ulonglong next_auto_inc_val; lock_auto_increment(); next_auto_inc_val= ha_data->next_auto_inc_val; + /* + If the current auto_increment values is lower than the reserved + value, and the reserved value was reserved by this thread, + we can lower the reserved value. + */ if (next_insert_id < next_auto_inc_val && auto_inc_interval_for_cur_row.maximum() >= next_auto_inc_val) - ha_data->next_auto_inc_val= next_insert_id; + { + THD *thd= ha_thd(); + /* + Check that we do not lower the value because of a failed insert + with SET INSERT_ID, i.e. forced/non generated values. + */ + if (thd->auto_inc_intervals_forced.maximum() < next_insert_id) + ha_data->next_auto_inc_val= next_insert_id; + } DBUG_PRINT("info", ("ha_data->next_auto_inc_val: %lu", (ulong) ha_data->next_auto_inc_val)); diff --git a/sql/ha_partition.h b/sql/ha_partition.h index b3a347612f3..9f499e7b4a9 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -20,6 +20,9 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_partition.h" /* part_id_range, partition_element */ +#include "queues.h" /* QUEUE */ + enum partition_keywords { PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR, diff --git a/sql/handler.cc b/sql/handler.cc index 69ac4e72555..ad3ba908173 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -23,8 +23,19 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "rpl_handler.h" +#include "sql_cache.h" // query_cache, query_cache_* +#include "key.h" // key_copy, key_unpack, key_cmp_if_same, key_cmp +#include "sql_table.h" // build_table_filename +#include "lock.h" // wait_if_global_read_lock, + // start_waiting_global_read_lock +#include "sql_parse.h" // check_stack_overrun +#include "sql_acl.h" // SUPER_ACL +#include "sql_base.h" // free_io_cache +#include "discover.h" // writefrm +#include "log_event.h" // *_rows_log_event #include "rpl_filter.h" #include <myisampack.h> #include "transaction.h" diff --git a/sql/handler.h b/sql/handler.h index 1734e5727dc..9f21cb0f25d 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -22,6 +22,13 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_const.h" +#include "mysqld.h" /* server_id */ +#include "sql_plugin.h" /* plugin_ref, st_plugin_int, plugin */ +#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA */ +#include "sql_cache.h" +#include "structs.h" /* SHOW_COMP_OPTION */ + #include <my_handler.h> #include <ft_global.h> #include <keycache.h> @@ -2173,4 +2180,15 @@ int ha_binlog_end(THD *thd); #define ha_binlog_wait(a) do {} while (0) #define ha_binlog_end(a) do {} while (0) #endif + +const char *get_canonical_filename(handler *file, const char *path, + char *tmp_path); +bool mysql_xa_recover(THD *thd); + + +inline const char *table_case_name(HA_CREATE_INFO *info, const char *name) +{ + return ((lower_case_table_names == 2 && info->alias) ? info->alias : name); +} + #endif /* HANDLER_INCLUDED */ diff --git a/sql/hash_filo.cc b/sql/hash_filo.cc index 9303120e18a..d10b7fa4907 100644 --- a/sql/hash_filo.cc +++ b/sql/hash_filo.cc @@ -23,5 +23,5 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" #include "hash_filo.h" diff --git a/sql/hash_filo.h b/sql/hash_filo.h index 805e1262020..859b4713940 100644 --- a/sql/hash_filo.h +++ b/sql/hash_filo.h @@ -26,6 +26,10 @@ #pragma interface /* gcc class interface */ #endif +#include "hash.h" /* my_hash_get_key, my_hash_free_key, HASH */ +#include "m_string.h" /* bzero */ +#include "mysqld.h" /* key_hash_filo_lock */ + class hash_filo_element { hash_filo_element *next_used,*prev_used; diff --git a/sql/hostname.cc b/sql/hostname.cc index 5517d85527c..d309efc4196 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -24,9 +24,18 @@ doesn't resemble an IP address. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "hostname.h" +#include "my_global.h" +#ifndef __WIN__ +#include <netdb.h> // getservbyname, servent +#endif #include "hash_filo.h" #include <m_ctype.h> +#include "log.h" // sql_print_warning, + // sql_print_information +#include "violite.h" // vio_getnameinfo, + // vio_get_normalized_ip_string #ifdef __cplusplus extern "C" { // Because of SCO 3.2V4.2 #endif diff --git a/sql/hostname.h b/sql/hostname.h new file mode 100644 index 00000000000..03611bb5813 --- /dev/null +++ b/sql/hostname.h @@ -0,0 +1,30 @@ +/* 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 HOSTNAME_INCLUDED +#define HOSTNAME_INCLUDED + +#include "my_global.h" /* uint */ + +bool ip_to_hostname(struct sockaddr_storage *ip_storage, + const char *ip_string, + char **hostname, uint *connect_errors); +void inc_host_errors(const char *ip_string); +void reset_host_errors(const char *ip_string); +bool hostname_cache_init(); +void hostname_cache_free(); +void hostname_cache_refresh(void); + +#endif /* HOSTNAME_INCLUDED */ diff --git a/sql/init.cc b/sql/init.cc index cada907b013..c72787300b7 100644 --- a/sql/init.cc +++ b/sql/init.cc @@ -21,7 +21,12 @@ Init and dummy functions for interface with unireg */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "init.h" +#include "my_sys.h" +#include "mysqld.h" // abort_loop, ... +#include "my_time.h" // my_init_time +#include "unireg.h" // SPECIAL_SAME_DB_NAME #include <m_ctype.h> void unireg_init(ulong options) diff --git a/sql/init.h b/sql/init.h new file mode 100644 index 00000000000..2c160879223 --- /dev/null +++ b/sql/init.h @@ -0,0 +1,24 @@ +/* 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 INIT_INCLUDED +#define INIT_INCLUDED + +#include "my_global.h" /* ulong */ + +void unireg_init(ulong options); +void unireg_end(void) __attribute__((noreturn)); + +#endif /* INIT_INCLUDED */ diff --git a/sql/item.cc b/sql/item.cc index e269f6399e9..4199f8a409a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -17,7 +17,9 @@ #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes #include <mysql.h> #include <m_ctype.h> #include "my_dir.h" @@ -25,6 +27,19 @@ #include "sp_head.h" #include "sql_trigger.h" #include "sql_select.h" +#include "sql_show.h" // append_identifier +#include "sql_view.h" // VIEW_ANY_SQL +#include "sql_time.h" // str_to_datetime_with_warn, + // make_truncated_value_warning +#include "sql_acl.h" // get_column_grant, + // SELECT_ACL, UPDATE_ACL, + // INSERT_ACL, + // check_grant_column +#include "sql_base.h" // enum_resolution_type, + // REPORT_EXCEPT_NOT_FOUND, + // find_item_in_list, + // RESOLVED_AGAINST_ALIAS, ... +#include "log_event.h" // append_query_string const String my_null_string("NULL", 4, default_charset_info); @@ -589,6 +604,18 @@ Item_ident::Item_ident(Name_resolution_context *context_arg, } +Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg) + :orig_db_name(NullS), orig_table_name(view_arg->table_name), + orig_field_name(field_name_arg), context(&view_arg->view->select_lex.context), + db_name(NullS), table_name(view_arg->alias), + field_name(field_name_arg), + alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX), + cached_table(NULL), depended_from(NULL) +{ + name = (char*) field_name_arg; +} + + /** Constructor used by Item_field & Item_*_ref (see Item comment) */ @@ -1159,7 +1186,9 @@ Item_splocal::Item_splocal(const LEX_STRING &sp_var_name, enum_field_types sp_var_type, uint pos_in_q, uint len_in_q) :Item_sp_variable(sp_var_name.str, sp_var_name.length), - m_var_idx(sp_var_idx), pos_in_query(pos_in_q), len_in_query(len_in_q) + m_var_idx(sp_var_idx), + limit_clause_param(FALSE), + pos_in_query(pos_in_q), len_in_query(len_in_q) { maybe_null= TRUE; @@ -4710,6 +4739,7 @@ void Item_field::cleanup() I.e. we can drop 'field'. */ field= result_field= 0; + item_equal= NULL; null_value= FALSE; DBUG_VOID_RETURN; } @@ -5990,9 +6020,14 @@ void Item_field::print(String *str, enum_query_type query_type) char buff[MAX_FIELD_WIDTH]; String tmp(buff,sizeof(buff),str->charset()); field->val_str(&tmp); - str->append('\''); - str->append(tmp); - str->append('\''); + if (field->is_null()) + str->append("NULL"); + else + { + str->append('\''); + str->append(tmp); + str->append('\''); + } return; } Item_ident::print(str, query_type); @@ -6015,6 +6050,20 @@ Item_ref::Item_ref(Name_resolution_context *context_arg, } +Item_ref::Item_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg, bool alias_name_used_arg) + :Item_ident(view_arg, field_name_arg), + result_field(NULL), ref(item) +{ + alias_name_used= alias_name_used_arg; + /* + This constructor is used to create some internal references over fixed items + */ + if (ref && *ref && (*ref)->fixed) + set_properties(); +} + + /** Resolve the name of a reference to a column reference. @@ -7504,7 +7553,7 @@ double Item_cache_decimal::val_real() DBUG_ASSERT(fixed); double res; if (!value_cached && !cache_value()) - return NULL; + return 0.0; my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res); return res; } diff --git a/sql/item.h b/sql/item.h index 9f64c0110ec..11b4199da2c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1,7 +1,7 @@ #ifndef ITEM_INCLUDED #define ITEM_INCLUDED -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -21,10 +21,18 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_priv.h" /* STRING_BUFFER_USUAL_SIZE */ +#include "unireg.h" +#include "sql_const.h" /* RAND_TABLE_BIT, MAX_FIELD_NAME */ +#include "unireg.h" // REQUIRED: for other includes +#include "thr_malloc.h" /* sql_calloc */ +#include "field.h" /* Derivation */ + class Protocol; struct TABLE_LIST; void item_init(void); /* Init item functions */ class Item_field; +class user_var_entry; /* "Declared Type Collation" @@ -1294,6 +1302,13 @@ class Item_splocal :public Item_sp_variable, Item_result m_result_type; enum_field_types m_field_type; public: + /* + Is this variable a parameter in LIMIT clause. + Used only during NAME_CONST substitution, to not append + NAME_CONST to the resulting query and thus not break + the slave. + */ + bool limit_clause_param; /* Position of this reference to SP variable in the statement (the statement itself is in sp_instr_stmt::m_query). @@ -1543,6 +1558,7 @@ public: const char *db_name_arg, const char *table_name_arg, const char *field_name_arg); Item_ident(THD *thd, Item_ident *item); + Item_ident(TABLE_LIST *view_arg, const char *field_name_arg); const char *full_name() const; void cleanup(); bool remove_dependence_processor(uchar * arg); @@ -2386,6 +2402,8 @@ public: Item_ref(Name_resolution_context *context_arg, Item **item, const char *table_name_arg, const char *field_name_arg, bool alias_name_used_arg= FALSE); + Item_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg, bool alias_name_used_arg= FALSE); /* Constructor need to process subselect with temporary tables (see Item) */ Item_ref(THD *thd, Item_ref *item) @@ -2481,6 +2499,11 @@ public: if (ref && result_type() == ROW_RESULT) (*ref)->bring_value(); } + bool get_time(MYSQL_TIME *ltime) + { + DBUG_ASSERT(fixed); + return (*ref)->get_time(ltime); + } bool basic_const_item() { return (*ref)->basic_const_item(); } }; @@ -2502,6 +2525,12 @@ public: {} /* Constructor need to process subselect with temporary tables (see Item) */ Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} + Item_direct_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg, + bool alias_name_used_arg= FALSE) + :Item_ref(view_arg, item, field_name_arg, + alias_name_used_arg) + {} double val_real(); longlong val_int(); @@ -2527,6 +2556,10 @@ public: /* Constructor need to process subselect with temporary tables (see Item) */ Item_direct_view_ref(THD *thd, Item_direct_ref *item) :Item_direct_ref(thd, item) {} + Item_direct_view_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg) + :Item_direct_ref(view_arg, item, field_name_arg) + {} bool fix_fields(THD *, Item **); bool eq(const Item *item, bool binary_cmp) const; @@ -2671,6 +2704,7 @@ public: #include "item_timefunc.h" #include "item_subselect.h" #include "item_xmlfunc.h" +#include "item_create.h" #endif /** @@ -3003,18 +3037,6 @@ public: }; -/* - We need this two enums here instead of sql_lex.h because - at least one of them is used by Item_trigger_field interface. - - Time when trigger is invoked (i.e. before or after row actually - inserted/updated/deleted). -*/ -enum trg_action_time_type -{ - TRG_ACTION_BEFORE= 0, TRG_ACTION_AFTER= 1, TRG_ACTION_MAX -}; - class Table_triggers_list; /* @@ -3122,14 +3144,16 @@ protected: bool value_cached; public: Item_cache(): - example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING), + example(0), used_table_map(0), cached_field(0), + cached_field_type(MYSQL_TYPE_STRING), value_cached(0) { fixed= 1; null_value= 1; } Item_cache(enum_field_types field_type_arg): - example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg), + example(0), used_table_map(0), cached_field(0), + cached_field_type(field_type_arg), value_cached(0) { fixed= 1; @@ -3182,6 +3206,7 @@ public: Item_cache_int(enum_field_types field_type_arg): Item_cache(field_type_arg), value(0) {} + virtual void store(Item *item){ Item_cache::store(item); } void store(Item *item, longlong val_arg); double val_real(); longlong val_int(); @@ -3233,10 +3258,9 @@ class Item_cache_str: public Item_cache public: Item_cache_str(const Item *item) : - Item_cache(), value(0), + Item_cache(item->field_type()), value(0), is_varbinary(item->type() == FIELD_ITEM && - ((const Item_field *) item)->field->type() == - MYSQL_TYPE_VARCHAR && + cached_field_type == MYSQL_TYPE_VARCHAR && !((const Item_field *) item)->field->has_charset()) {} double val_real(); @@ -3398,4 +3422,7 @@ extern Cached_item *new_Cached_item(THD *thd, Item *item); extern Item_result item_cmp_type(Item_result a,Item_result b); extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item); extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item); + +extern const String my_null_string; + #endif /* ITEM_INCLUDED */ diff --git a/sql/item_buff.cc b/sql/item_buff.cc index 2f45d0a17c2..a1bbd95c2c6 100644 --- a/sql/item_buff.cc +++ b/sql/item_buff.cc @@ -21,7 +21,14 @@ Buffers to save and compare item values */ -#include "mysql_priv.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // THD +#include "set_var.h" // Cached_item, Cached_item_field, ... /** Create right type of Cached_item for an item. diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 08383325580..19e8385539f 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -25,9 +25,11 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" #include <m_ctype.h> #include "sql_select.h" +#include "sql_parse.h" // check_stack_overrun +#include "sql_time.h" // make_truncated_value_warning static bool convert_constant_item(THD *, Item_field *, Item **); static longlong @@ -1024,12 +1026,12 @@ bool Arg_comparator::try_year_cmp_func(Item_result type) @return cache item or original value. */ -Item** Arg_comparator::cache_converted_constant(THD *thd, Item **value, +Item** Arg_comparator::cache_converted_constant(THD *thd_arg, Item **value, Item **cache_item, Item_result type) { /* Don't need cache if doing context analysis only. */ - if (!thd->is_context_analysis_only() && + if (!thd_arg->is_context_analysis_only() && (*value)->const_item() && type != (*value)->result_type()) { Item_cache *cache= Item_cache::get_cache(*value, type); @@ -1192,12 +1194,21 @@ get_year_value(THD *thd, Item ***item_arg, Item **cache_arg, /* Coerce value to the 19XX form in order to correctly compare YEAR(2) & YEAR(4) types. + Here we are converting all item values but YEAR(4) fields since + 1) YEAR(4) already has a regular YYYY form and + 2) we don't want to convert zero/bad YEAR(4) values to the + value of 2000. */ - if (value < 70) - value+= 100; - if (value <= 1900) - value+= 1900; - + Item *real_item= item->real_item(); + if (!(real_item->type() == Item::FIELD_ITEM && + ((Item_field *)real_item)->field->type() == MYSQL_TYPE_YEAR && + ((Item_field *)real_item)->field->field_length == 4)) + { + if (value < 70) + value+= 100; + if (value <= 1900) + value+= 1900; + } /* Convert year to DATETIME of form YYYY-00-00 00:00:00 (YYYY0000000000). */ value*= 10000000000LL; @@ -1370,12 +1381,12 @@ int Arg_comparator::compare_real() int Arg_comparator::compare_decimal() { - my_decimal value1; - my_decimal *val1= (*a)->val_decimal(&value1); + my_decimal decimal1; + my_decimal *val1= (*a)->val_decimal(&decimal1); if (!(*a)->null_value) { - my_decimal value2; - my_decimal *val2= (*b)->val_decimal(&value2); + my_decimal decimal2; + my_decimal *val2= (*b)->val_decimal(&decimal2); if (!(*b)->null_value) { if (set_null) @@ -1399,9 +1410,9 @@ int Arg_comparator::compare_e_real() int Arg_comparator::compare_e_decimal() { - my_decimal value1, value2; - my_decimal *val1= (*a)->val_decimal(&value1); - my_decimal *val2= (*b)->val_decimal(&value2); + my_decimal decimal1, decimal2; + my_decimal *val1= (*a)->val_decimal(&decimal1); + my_decimal *val2= (*b)->val_decimal(&decimal2); if ((*a)->null_value || (*b)->null_value) return test((*a)->null_value && (*b)->null_value); return test(my_decimal_cmp(val1, val2) == 0); @@ -5403,11 +5414,11 @@ void Item_equal::merge(Item_equal *item) members follow in a wrong order they are swapped. This is performed again and again until we get all members in a right order. - @param cmp function to compare field item + @param compare function to compare field item @param arg context extra parameter for the cmp function */ -void Item_equal::sort(Item_field_cmpfunc cmp, void *arg) +void Item_equal::sort(Item_field_cmpfunc compare, void *arg) { bool swap; List_iterator<Item_field> it(fields); @@ -5421,7 +5432,7 @@ void Item_equal::sort(Item_field_cmpfunc cmp, void *arg) while ((item2= it++)) { Item_field **ref2= it.ref(); - if (cmp(item1, item2, arg) < 0) + if (compare(item1, item2, arg) < 0) { Item_field *item= *ref1; *ref1= *ref2; diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 3232a77ac3e..afd25688e79 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1,7 +1,7 @@ #ifndef ITEM_CMPFUNC_INCLUDED #define ITEM_CMPFUNC_INCLUDED -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -23,6 +23,9 @@ #pragma interface /* gcc class implementation */ #endif +#include "thr_malloc.h" /* sql_calloc */ +#include "item_func.h" /* Item_int_func, Item_bool_func */ + extern Item_result item_cmp_type(Item_result a,Item_result b); class Item_bool_func2; class Arg_comparator; @@ -1624,7 +1627,7 @@ public: longlong val_int(); const char *func_name() const { return "multiple equal"; } optimize_type select_optimize() const { return OPTIMIZE_EQUAL; } - void sort(Item_field_cmpfunc cmp, void *arg); + void sort(Item_field_cmpfunc compare, void *arg); friend class Item_equal_iterator; void fix_length_and_dec(); bool fix_fields(THD *thd, Item **ref); @@ -1760,8 +1763,26 @@ inline Item *and_conds(Item *a, Item *b) return new Item_cond_and(a, b); } + Item *and_expressions(Item *a, Item *b, Item **org_item); +longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, + Item *warn_item, bool *is_null); + + bool get_mysql_time_from_str(THD *thd, String *str, timestamp_type warn_type, const char *warn_name, MYSQL_TIME *l_time); + +/* + These need definitions from this file but the variables are defined + in mysqld.h. The variables really belong in this component, but for + the time being we leave them in mysqld.cc to avoid merge problems. +*/ +extern Eq_creator eq_creator; +extern Ne_creator ne_creator; +extern Gt_creator gt_creator; +extern Lt_creator lt_creator; +extern Ge_creator ge_creator; +extern Le_creator le_creator; + #endif /* ITEM_CMPFUNC_INCLUDED */ diff --git a/sql/item_create.cc b/sql/item_create.cc index a393c886483..5f30a10d1e0 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -20,8 +20,14 @@ Functions to create an item. Used by sql_yac.yy */ -#include "mysql_priv.h" -#include "item_create.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" #include "sp_head.h" #include "sp.h" @@ -42,7 +48,7 @@ class Create_native_func : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** Builder method, with no arguments. @@ -69,7 +75,7 @@ protected: class Create_func_arg0 : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** Builder method, with no arguments. @@ -93,7 +99,7 @@ protected: class Create_func_arg1 : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** Builder method, with one argument. @@ -118,7 +124,7 @@ protected: class Create_func_arg2 : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** Builder method, with two arguments. @@ -144,7 +150,7 @@ protected: class Create_func_arg3 : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** Builder method, with three arguments. @@ -194,7 +200,7 @@ protected: class Create_func_no_geom : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** Singleton. */ static Create_func_no_geom s_singleton; @@ -1828,6 +1834,19 @@ protected: }; +class Create_func_sha2 : public Create_func_arg2 +{ +public: + virtual Item* create(THD *thd, Item *arg1, Item *arg2); + + static Create_func_sha2 s_singleton; + +protected: + Create_func_sha2() {} + virtual ~Create_func_sha2() {} +}; + + class Create_func_sign : public Create_func_arg1 { public: @@ -2327,7 +2346,7 @@ static bool has_named_parameters(List<Item> *params) Create_func_no_geom Create_func_no_geom::s_singleton; Item* -Create_func_no_geom::create(THD * /* unused */, +Create_func_no_geom::create_func(THD * /* unused */, LEX_STRING /* unused */, List<Item> * /* unused */) { @@ -2340,7 +2359,7 @@ Create_func_no_geom::create(THD * /* unused */, Item* -Create_qfunc::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_qfunc::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { LEX_STRING db; @@ -2373,7 +2392,7 @@ Create_qfunc::create(THD *thd, LEX_STRING name, List<Item> *item_list) Create_udf_func Create_udf_func::s_singleton; Item* -Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_udf_func::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { udf_func *udf= find_udf(name.str, name.length); DBUG_ASSERT(udf); @@ -2525,7 +2544,7 @@ Create_sp_func::create(THD *thd, LEX_STRING db, LEX_STRING name, Item* -Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_native_func::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { if (has_named_parameters(item_list)) { @@ -2538,7 +2557,7 @@ Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list) Item* -Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_func_arg0::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { int arg_count= 0; @@ -2556,7 +2575,7 @@ Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list) Item* -Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_func_arg1::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { int arg_count= 0; @@ -2582,7 +2601,7 @@ Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list) Item* -Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_func_arg2::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { int arg_count= 0; @@ -2610,7 +2629,7 @@ Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list) Item* -Create_func_arg3::create(THD *thd, LEX_STRING name, List<Item> *item_list) +Create_func_arg3::create_func(THD *thd, LEX_STRING name, List<Item> *item_list) { int arg_count= 0; @@ -2946,9 +2965,7 @@ Create_func_cot Create_func_cot::s_singleton; Item* Create_func_cot::create(THD *thd, Item *arg1) { - Item *i1= new (thd->mem_root) Item_int((char*) "1", 1, 1); - Item *i2= new (thd->mem_root) Item_func_tan(arg1); - return new (thd->mem_root) Item_func_div(i1, i2); + return new (thd->mem_root) Item_func_cot(arg1); } @@ -4359,6 +4376,15 @@ Create_func_sha::create(THD *thd, Item *arg1) } +Create_func_sha2 Create_func_sha2::s_singleton; + +Item* +Create_func_sha2::create(THD *thd, Item *arg1, Item *arg2) +{ + return new (thd->mem_root) Item_func_sha2(arg1, arg2); +} + + Create_func_sign Create_func_sign::s_singleton; Item* @@ -4969,6 +4995,7 @@ static Native_func_registry func_array[] = { { C_STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)}, { { C_STRING_WITH_LEN("SHA") }, BUILDER(Create_func_sha)}, { { C_STRING_WITH_LEN("SHA1") }, BUILDER(Create_func_sha)}, + { { C_STRING_WITH_LEN("SHA2") }, BUILDER(Create_func_sha2)}, { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)}, { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)}, { { C_STRING_WITH_LEN("SLEEP") }, BUILDER(Create_func_sleep)}, diff --git a/sql/item_create.h b/sql/item_create.h index a3ba6bd26a6..fc21e0a4d33 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -18,6 +18,8 @@ #ifndef ITEM_CREATE_H #define ITEM_CREATE_H +typedef struct st_udf_func udf_func; + /** Public function builder interface. The parser (sql/sql_yacc.yy) uses a factory / builder pattern to @@ -53,7 +55,7 @@ public: @param item_list The list of arguments to the function, can be NULL @return An item representing the parsed function call, or NULL */ - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list) = 0; + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list) = 0; protected: /** Constructor */ @@ -80,7 +82,7 @@ public: @param item_list The list of arguments to the function, can be NULL @return An item representing the parsed function call */ - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** The builder create method, for qualified functions. @@ -127,7 +129,7 @@ extern Create_qfunc * find_qualified_function_builder(THD *thd); class Create_udf_func : public Create_func { public: - virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list); + virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list); /** The builder create method, for User Defined Functions. @@ -163,5 +165,9 @@ Item * create_func_cast(THD *thd, Item *a, Cast_target cast_type, const char *len, const char *dec, CHARSET_INFO *cs); + +int item_create_init(); +void item_create_cleanup(); + #endif diff --git a/sql/item_func.cc b/sql/item_func.cc index ca8f5d00bb1..4d0dec25e64 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -25,8 +25,21 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" #include "slave.h" // for wait_for_master_pos +#include "sql_show.h" // append_identifier +#include "strfunc.h" // find_type +#include "sql_parse.h" // is_update_query +#include "sql_acl.h" // EXECUTE_ACL +#include "mysqld.h" // LOCK_uuid_generator #include "rpl_mi.h" #include <m_ctype.h> #include <hash.h> @@ -65,6 +78,14 @@ eval_const_cond(COND *cond) } +/** + Test if the sum of arguments overflows the ulonglong range. +*/ +static inline bool test_if_sum_overflows_ull(ulonglong arg1, ulonglong arg2) +{ + return ULONGLONG_MAX - arg1 < arg2; +} + void Item_func::set_arguments(List<Item> &list) { allowed_arg_cols= 1; @@ -1094,16 +1115,68 @@ double Item_func_plus::real_op() double value= args[0]->val_real() + args[1]->val_real(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; - return fix_result(value); + return check_float_overflow(value); } longlong Item_func_plus::int_op() { - longlong value=args[0]->val_int()+args[1]->val_int(); - if ((null_value=args[0]->null_value || args[1]->null_value)) + longlong val0= args[0]->val_int(); + longlong val1= args[1]->val_int(); + longlong res= val0 + val1; + bool res_unsigned= FALSE; + + if ((null_value= args[0]->null_value || args[1]->null_value)) return 0; - return value; + + /* + First check whether the result can be represented as a + (bool unsigned_flag, longlong value) pair, then check if it is compatible + with this Item's unsigned_flag by calling check_integer_overflow(). + */ + if (args[0]->unsigned_flag) + { + if (args[1]->unsigned_flag || val1 >= 0) + { + if (test_if_sum_overflows_ull((ulonglong) val0, (ulonglong) val1)) + goto err; + res_unsigned= TRUE; + } + else + { + /* val1 is negative */ + if ((ulonglong) val0 > (ulonglong) LONGLONG_MAX) + res_unsigned= TRUE; + } + } + else + { + if (args[1]->unsigned_flag) + { + if (val0 >= 0) + { + if (test_if_sum_overflows_ull((ulonglong) val0, (ulonglong) val1)) + goto err; + res_unsigned= TRUE; + } + else + { + if ((ulonglong) val1 > (ulonglong) LONGLONG_MAX) + res_unsigned= TRUE; + } + } + else + { + if (val0 >=0 && val1 >= 0) + res_unsigned= TRUE; + else if (val0 < 0 && val1 < 0 && res >= 0) + goto err; + } + } + return check_integer_overflow(res, res_unsigned); + +err: + return raise_integer_overflow(); } @@ -1127,8 +1200,10 @@ my_decimal *Item_func_plus::decimal_op(my_decimal *decimal_value) return 0; val2= args[1]->val_decimal(&value2); if (!(null_value= (args[1]->null_value || - (my_decimal_add(E_DEC_FATAL_ERROR, decimal_value, val1, - val2) > 3)))) + check_decimal_overflow(my_decimal_add(E_DEC_FATAL_ERROR & + ~E_DEC_OVERFLOW, + decimal_value, + val1, val2)) > 3))) return decimal_value; return 0; } @@ -1172,16 +1247,71 @@ double Item_func_minus::real_op() double value= args[0]->val_real() - args[1]->val_real(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; - return fix_result(value); + return check_float_overflow(value); } longlong Item_func_minus::int_op() { - longlong value=args[0]->val_int() - args[1]->val_int(); - if ((null_value=args[0]->null_value || args[1]->null_value)) + longlong val0= args[0]->val_int(); + longlong val1= args[1]->val_int(); + longlong res= val0 - val1; + bool res_unsigned= FALSE; + + if ((null_value= args[0]->null_value || args[1]->null_value)) return 0; - return value; + + /* + First check whether the result can be represented as a + (bool unsigned_flag, longlong value) pair, then check if it is compatible + with this Item's unsigned_flag by calling check_integer_overflow(). + */ + if (args[0]->unsigned_flag) + { + if (args[1]->unsigned_flag) + { + if ((ulonglong) val0 < (ulonglong) val1) + { + if (res >= 0) + goto err; + } + else + res_unsigned= TRUE; + } + else + { + if (val1 >= 0) + { + if ((ulonglong) val0 > (ulonglong) val1) + res_unsigned= TRUE; + } + else + { + if (test_if_sum_overflows_ull((ulonglong) val0, (ulonglong) -val1)) + goto err; + res_unsigned= TRUE; + } + } + } + else + { + if (args[1]->unsigned_flag) + { + if ((ulonglong) (val0 - LONGLONG_MIN) < (ulonglong) val1) + goto err; + } + else + { + if (val0 > 0 && val1 < 0) + res_unsigned= TRUE; + else if (val0 < 0 && val1 > 0 && res >= 0) + goto err; + } + } + return check_integer_overflow(res, res_unsigned); + +err: + return raise_integer_overflow(); } @@ -1199,8 +1329,10 @@ my_decimal *Item_func_minus::decimal_op(my_decimal *decimal_value) return 0; val2= args[1]->val_decimal(&value2); if (!(null_value= (args[1]->null_value || - (my_decimal_sub(E_DEC_FATAL_ERROR, decimal_value, val1, - val2) > 3)))) + (check_decimal_overflow(my_decimal_sub(E_DEC_FATAL_ERROR & + ~E_DEC_OVERFLOW, + decimal_value, val1, + val2)) > 3)))) return decimal_value; return 0; } @@ -1212,17 +1344,86 @@ double Item_func_mul::real_op() double value= args[0]->val_real() * args[1]->val_real(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; - return fix_result(value); + return check_float_overflow(value); } longlong Item_func_mul::int_op() { DBUG_ASSERT(fixed == 1); - longlong value=args[0]->val_int()*args[1]->val_int(); - if ((null_value=args[0]->null_value || args[1]->null_value)) + longlong a= args[0]->val_int(); + longlong b= args[1]->val_int(); + longlong res; + ulonglong res0, res1; + ulong a0, a1, b0, b1; + bool res_unsigned= FALSE; + bool a_negative= FALSE, b_negative= FALSE; + + if ((null_value= args[0]->null_value || args[1]->null_value)) return 0; - return value; + + /* + First check whether the result can be represented as a + (bool unsigned_flag, longlong value) pair, then check if it is compatible + with this Item's unsigned_flag by calling check_integer_overflow(). + + Let a = a1 * 2^32 + a0 and b = b1 * 2^32 + b0. Then + a * b = (a1 * 2^32 + a0) * (b1 * 2^32 + b0) = a1 * b1 * 2^64 + + + (a1 * b0 + a0 * b1) * 2^32 + a0 * b0; + We can determine if the above sum overflows the ulonglong range by + sequentially checking the following conditions: + 1. If both a1 and b1 are non-zero. + 2. Otherwise, if (a1 * b0 + a0 * b1) is greater than ULONG_MAX. + 3. Otherwise, if (a1 * b0 + a0 * b1) * 2^32 + a0 * b0 is greater than + ULONGLONG_MAX. + + Since we also have to take the unsigned_flag for a and b into account, + it is easier to first work with absolute values and set the + correct sign later. + */ + if (!args[0]->unsigned_flag && a < 0) + { + a_negative= TRUE; + a= -a; + } + if (!args[1]->unsigned_flag && b < 0) + { + b_negative= TRUE; + b= -b; + } + + a0= 0xFFFFFFFFUL & a; + a1= ((ulonglong) a) >> 32; + b0= 0xFFFFFFFFUL & b; + b1= ((ulonglong) b) >> 32; + + if (a1 && b1) + goto err; + + res1= (ulonglong) a1 * b0 + (ulonglong) a0 * b1; + if (res1 > 0xFFFFFFFFUL) + goto err; + + res1= res1 << 32; + res0= (ulonglong) a0 * b0; + + if (test_if_sum_overflows_ull(res1, res0)) + goto err; + res= res1 + res0; + + if (a_negative != b_negative) + { + if ((ulonglong) res > (ulonglong) LONGLONG_MIN + 1) + goto err; + res= -res; + } + else + res_unsigned= TRUE; + + return check_integer_overflow(res, res_unsigned); + +err: + return raise_integer_overflow(); } @@ -1237,8 +1438,10 @@ my_decimal *Item_func_mul::decimal_op(my_decimal *decimal_value) return 0; val2= args[1]->val_decimal(&value2); if (!(null_value= (args[1]->null_value || - (my_decimal_mul(E_DEC_FATAL_ERROR, decimal_value, val1, - val2) > 3)))) + (check_decimal_overflow(my_decimal_mul(E_DEC_FATAL_ERROR & + ~E_DEC_OVERFLOW, + decimal_value, val1, + val2)) > 3)))) return decimal_value; return 0; } @@ -1271,7 +1474,7 @@ double Item_func_div::real_op() signal_divide_by_null(); return 0.0; } - return fix_result(value/val2); + return check_float_overflow(value/val2); } @@ -1287,8 +1490,12 @@ my_decimal *Item_func_div::decimal_op(my_decimal *decimal_value) val2= args[1]->val_decimal(&value2); if ((null_value= args[1]->null_value)) return 0; - if ((err= my_decimal_div(E_DEC_FATAL_ERROR & ~E_DEC_DIV_ZERO, decimal_value, - val1, val2, prec_increment)) > 3) + if ((err= check_decimal_overflow(my_decimal_div(E_DEC_FATAL_ERROR & + ~E_DEC_OVERFLOW & + ~E_DEC_DIV_ZERO, + decimal_value, + val1, val2, + prec_increment))) > 3) { if (err == E_DEC_DIV_ZERO) signal_divide_by_null(); @@ -1379,22 +1586,35 @@ longlong Item_func_int_div::val_int() if (my_decimal2int(E_DEC_FATAL_ERROR, &tmp, unsigned_flag, &res) & E_DEC_OVERFLOW) - my_error(ER_WARN_DATA_OUT_OF_RANGE, MYF(0), name, 1); + raise_integer_overflow(); return res; } - longlong value=args[0]->val_int(); - longlong val2=args[1]->val_int(); + longlong val0=args[0]->val_int(); + longlong val1=args[1]->val_int(); + bool val0_negative, val1_negative, res_negative; + ulonglong uval0, uval1, res; if ((null_value= (args[0]->null_value || args[1]->null_value))) return 0; - if (val2 == 0) + if (val1 == 0) { signal_divide_by_null(); return 0; } - return (unsigned_flag ? - (ulonglong) value / (ulonglong) val2 : - value / val2); + + val0_negative= !args[0]->unsigned_flag && val0 < 0; + val1_negative= !args[1]->unsigned_flag && val1 < 0; + res_negative= val0_negative != val1_negative; + uval0= (ulonglong) (val0_negative ? -val0 : val0); + uval1= (ulonglong) (val1_negative ? -val1 : val1); + res= uval0 / uval1; + if (res_negative) + { + if (res > (ulonglong) LONGLONG_MAX) + return raise_integer_overflow(); + res= (ulonglong) (-(longlong) res); + } + return check_integer_overflow(res, !res_negative); } @@ -1413,26 +1633,32 @@ void Item_func_int_div::fix_length_and_dec() longlong Item_func_mod::int_op() { DBUG_ASSERT(fixed == 1); - longlong value= args[0]->val_int(); - longlong val2= args[1]->val_int(); - longlong result; + longlong val0= args[0]->val_int(); + longlong val1= args[1]->val_int(); + bool val0_negative, val1_negative; + ulonglong uval0, uval1; + ulonglong res; if ((null_value= args[0]->null_value || args[1]->null_value)) return 0; /* purecov: inspected */ - if (val2 == 0) + if (val1 == 0) { signal_divide_by_null(); return 0; } - if (args[0]->unsigned_flag) - result= args[1]->unsigned_flag ? - ((ulonglong) value) % ((ulonglong) val2) : ((ulonglong) value) % val2; - else - result= args[1]->unsigned_flag ? - value % ((ulonglong) val2) : value % val2; - - return result; + /* + '%' is calculated by integer division internally. Since dividing + LONGLONG_MIN by -1 generates SIGFPE, we calculate using unsigned values and + then adjust the sign appropriately. + */ + val0_negative= !args[0]->unsigned_flag && val0 < 0; + val1_negative= !args[1]->unsigned_flag && val1 < 0; + uval0= (ulonglong) (val0_negative ? -val0 : val0); + uval1= (ulonglong) (val1_negative ? -val1 : val1); + res= uval0 % uval1; + return check_integer_overflow(val0_negative ? -(longlong) res : res, + !val0_negative); } double Item_func_mod::real_op() @@ -1502,8 +1728,12 @@ double Item_func_neg::real_op() longlong Item_func_neg::int_op() { longlong value= args[0]->val_int(); - null_value= args[0]->null_value; - return -value; + if ((null_value= args[0]->null_value)) + return 0; + if (args[0]->unsigned_flag && + (ulonglong) value > (ulonglong) LONGLONG_MAX + 1) + return raise_integer_overflow(); + return check_integer_overflow(-value, !args[0]->unsigned_flag && value < 0); } @@ -1572,7 +1802,12 @@ longlong Item_func_abs::int_op() longlong value= args[0]->val_int(); if ((null_value= args[0]->null_value)) return 0; - return (value >= 0) || unsigned_flag ? value : -value; + if (unsigned_flag) + return value; + /* -LONGLONG_MIN = LONGLONG_MAX + 1 => outside of signed longlong range */ + if (value == LONGLONG_MIN) + return raise_integer_overflow(); + return (value >= 0) ? value : -value; } @@ -1679,7 +1914,7 @@ double Item_func_exp::val_real() double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; /* purecov: inspected */ - return fix_result(exp(value)); + return check_float_overflow(exp(value)); } double Item_func_sqrt::val_real() @@ -1698,7 +1933,7 @@ double Item_func_pow::val_real() double val2= args[1]->val_real(); if ((null_value=(args[0]->null_value || args[1]->null_value))) return 0.0; /* purecov: inspected */ - return fix_result(pow(value,val2)); + return check_float_overflow(pow(value,val2)); } // Trigonometric functions @@ -1734,7 +1969,7 @@ double Item_func_atan::val_real() double val2= args[1]->val_real(); if ((null_value=args[1]->null_value)) return 0.0; - return fix_result(atan2(value,val2)); + return check_float_overflow(atan2(value,val2)); } return atan(value); } @@ -1763,7 +1998,17 @@ double Item_func_tan::val_real() double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; - return fix_result(tan(value)); + return check_float_overflow(tan(value)); +} + + +double Item_func_cot::val_real() +{ + DBUG_ASSERT(fixed == 1); + double value= args[0]->val_real(); + if ((null_value=args[0]->null_value)) + return 0.0; + return check_float_overflow(1.0 / tan(value)); } @@ -2238,7 +2483,7 @@ double Item_func_units::val_real() double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0; - return value*mul+add; + return check_float_overflow(value * mul + add); } @@ -3424,80 +3669,6 @@ longlong Item_master_pos_wait::val_int() return event_count; } -#ifdef EXTRA_DEBUG -void debug_sync_point(const char* lock_name, uint lock_timeout) -{ - THD* thd=current_thd; - User_level_lock* ull; - struct timespec abstime; - size_t lock_name_len; - lock_name_len= strlen(lock_name); - mysql_mutex_lock(&LOCK_user_locks); - - if (thd->ull) - { - item_user_lock_release(thd->ull); - thd->ull=0; - } - - /* - If the lock has not been aquired by some client, we do not want to - create an entry for it, since we immediately release the lock. In - this case, we will not be waiting, but rather, just waste CPU and - memory on the whole deal - */ - if (!(ull= ((User_level_lock*) my_hash_search(&hash_user_locks, - (uchar*) lock_name, - lock_name_len)))) - { - mysql_mutex_unlock(&LOCK_user_locks); - return; - } - ull->count++; - - /* - Structure is now initialized. Try to get the lock. - Set up control struct to allow others to abort locks - */ - thd_proc_info(thd, "User lock"); - thd->mysys_var->current_mutex= &LOCK_user_locks; - thd->mysys_var->current_cond= &ull->cond; - - set_timespec(abstime,lock_timeout); - while (ull->locked && !thd->killed) - { - int error= mysql_cond_timedwait(&ull->cond, &LOCK_user_locks, &abstime); - if (error == ETIMEDOUT || error == ETIME) - break; - } - - if (ull->locked) - { - if (!--ull->count) - delete ull; // Should never happen - } - else - { - ull->locked=1; - ull->set_thread(thd); - thd->ull=ull; - } - mysql_mutex_unlock(&LOCK_user_locks); - mysql_mutex_lock(&thd->mysys_var->mutex); - thd_proc_info(thd, 0); - thd->mysys_var->current_mutex= 0; - thd->mysys_var->current_cond= 0; - mysql_mutex_unlock(&thd->mysys_var->mutex); - mysql_mutex_lock(&LOCK_user_locks); - if (thd->ull) - { - item_user_lock_release(thd->ull); - thd->ull=0; - } - mysql_mutex_unlock(&LOCK_user_locks); -} - -#endif /** @@ -4766,6 +4937,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command, user_var_event->user_var_event= var_entry; user_var_event->type= var_entry->type; user_var_event->charset_number= var_entry->collation.collation->number; + user_var_event->unsigned_flag= var_entry->unsigned_flag; if (!var_entry->value) { /* NULL value*/ diff --git a/sql/item_func.h b/sql/item_func.h index fc7f8708a45..c3f8b254f28 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -187,13 +187,56 @@ public: void * arg, traverse_order order); bool is_expensive_processor(uchar *arg); virtual bool is_expensive() { return 0; } - inline double fix_result(double value) + inline void raise_numeric_overflow(const char *type_name) { - if (isfinite(value)) - return value; - null_value=1; + char buf[256]; + String str(buf, sizeof(buf), system_charset_info); + str.length(0); + print(&str, QT_ORDINARY); + my_error(ER_DATA_OUT_OF_RANGE, MYF(0), type_name, str.c_ptr_safe()); + } + inline double raise_float_overflow() + { + raise_numeric_overflow("DOUBLE"); return 0.0; } + inline longlong raise_integer_overflow() + { + raise_numeric_overflow(unsigned_flag ? "BIGINT UNSIGNED": "BIGINT"); + return 0; + } + inline int raise_decimal_overflow() + { + raise_numeric_overflow("DECIMAL"); + return E_DEC_OVERFLOW; + } + /** + Throw an error if the input double number is not finite, i.e. is either + +/-INF or NAN. + */ + inline double check_float_overflow(double value) + { + return isfinite(value) ? value : raise_float_overflow(); + } + /** + Throw an error if the input BIGINT value represented by the + (longlong value, bool unsigned flag) pair cannot be returned by the + function, i.e. is not compatible with this Item's unsigned_flag. + */ + inline longlong check_integer_overflow(longlong value, bool val_unsigned) + { + if ((unsigned_flag && !val_unsigned && value < 0) || + (!unsigned_flag && val_unsigned && (ulonglong) value > LONGLONG_MAX)) + return raise_integer_overflow(); + return value; + } + /** + Throw an error if the error code of a DECIMAL operation is E_DEC_OVERFLOW. + */ + inline int check_decimal_overflow(int error) + { + return (error == E_DEC_OVERFLOW) ? raise_decimal_overflow() : error; + } bool has_timestamp_args() { DBUG_ASSERT(fixed == TRUE); @@ -667,6 +710,14 @@ public: const char *func_name() const { return "tan"; } }; +class Item_func_cot :public Item_dec_func +{ +public: + Item_func_cot(Item *a) :Item_dec_func(a) {} + double val_real(); + const char *func_name() const { return "cot"; } +}; + class Item_func_integer :public Item_int_func { public: @@ -1746,4 +1797,14 @@ public: bool check_partition_func_processor(uchar *int_arg) {return FALSE;} }; +Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, + LEX_STRING component); +extern bool check_reserved_words(LEX_STRING *name); +extern enum_field_types agg_field_type(Item **items, uint nitems); +double my_double_round(double value, longlong dec, bool dec_unsigned, + bool truncate); +bool eval_const_cond(COND *cond); + +extern bool volatile mqh_used; + #endif /* ITEM_FUNC_INCLUDED */ diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index c5554265fbe..e046087b16a 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -25,7 +25,14 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // THD, set_var.h: THD +#include "set_var.h" #ifdef HAVE_SPATIAL #include <m_ctype.h> diff --git a/sql/item_row.cc b/sql/item_row.cc index 29b37eb2bc0..2fbf0c12499 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -13,7 +13,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // THD, set_var.h: THD +#include "set_var.h" /** Row items used for comparing rows and IN operations on rows: @@ -30,7 +37,8 @@ */ Item_row::Item_row(List<Item> &arg): - Item(), used_tables_cache(0), const_item_cache(1), with_null(0) + Item(), used_tables_cache(0), not_null_tables_cache(0), + const_item_cache(1), with_null(0) { //TODO: think placing 2-3 component items in item (as it done for function) @@ -71,6 +79,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref) Item *item= *arg; used_tables_cache |= item->used_tables(); const_item_cache&= item->const_item() && !with_null; + not_null_tables_cache|= item->not_null_tables(); /* Some subqueries transformations aren't done in the view_prepare_mode thus is_null() will fail. So we skip is_null() calculation for CREATE VIEW as diff --git a/sql/item_row.h b/sql/item_row.h index 7c08c5888e0..87988e718ca 100644 --- a/sql/item_row.h +++ b/sql/item_row.h @@ -19,7 +19,7 @@ class Item_row: public Item { Item **items; - table_map used_tables_cache; + table_map used_tables_cache, not_null_tables_cache; uint arg_count; bool const_item_cache; bool with_null; @@ -29,6 +29,7 @@ public: Item(), items(item->items), used_tables_cache(item->used_tables_cache), + not_null_tables_cache(0), arg_count(item->arg_count), const_item_cache(item->const_item_cache), with_null(0) @@ -68,6 +69,7 @@ public: bool const_item() const { return const_item_cache; }; enum Item_result result_type() const { return ROW_RESULT; } void update_used_tables(); + table_map not_null_tables() const { return not_null_tables_cache; } virtual void print(String *str, enum_query_type query_type); bool walk(Item_processor processor, bool walk_subquery, uchar *arg); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index dab29bb58c4..32baae87c50 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -29,7 +29,24 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +/* May include caustic 3rd-party defs. Use early, so it can override nothing. */ +#include "sha2.h" +#include "my_global.h" // HAVE_* + + +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" +#include "mysqld.h" // LOCK_uuid_generator +#include "sql_acl.h" // SUPER_ACL +#include "des_key_file.h" // st_des_keyschedule, st_des_keyblock +#include "password.h" // my_make_scrambled_password, + // my_make_scrambled_password_323 #include <m_ctype.h> #include "my_md5.h" #include "sha1.h" @@ -79,9 +96,9 @@ String *Item_str_ascii_func::val_str(String *str) Used to generate a hexadecimal representation of a message digest. */ -static void array_to_hex(char *to, const char *str, uint len) +static void array_to_hex(char *to, const unsigned char *str, uint len) { - const char *str_end= str + len; + const unsigned char *str_end= str + len; for (; str != str_end; ++str) { *to++= _dig_vec_lower[((uchar) *str) >> 4]; @@ -160,7 +177,7 @@ String *Item_func_md5::val_str_ascii(String *str) null_value=1; return 0; } - array_to_hex((char *) str->ptr(), (const char*) digest, 16); + array_to_hex((char *) str->ptr(), digest, 16); str->length((uint) 32); return str; } @@ -201,7 +218,7 @@ String *Item_func_sha::val_str_ascii(String *str) if (!( str->alloc(SHA1_HASH_SIZE*2) || (mysql_sha1_result(&context,digest)))) { - array_to_hex((char *) str->ptr(), (const char*) digest, SHA1_HASH_SIZE); + array_to_hex((char *) str->ptr(), digest, SHA1_HASH_SIZE); str->length((uint) SHA1_HASH_SIZE*2); null_value=0; return str; @@ -225,6 +242,144 @@ void Item_func_sha::fix_length_and_dec() fix_length_and_charset(SHA1_HASH_SIZE * 2, default_charset()); } +String *Item_func_sha2::val_str(String *str) +{ + DBUG_ASSERT(fixed == 1); +#ifdef HAVE_OPENSSL + unsigned char digest_buf[SHA512_DIGEST_LENGTH]; + String *input_string; + unsigned char *input_ptr; + size_t input_len; + uint digest_length= 0; + + str->set_charset(&my_charset_bin); + + input_string= args[0]->val_str(str); + if (input_string == NULL) + { + null_value= TRUE; + return (String *) NULL; + } + + null_value= args[0]->null_value; + if (null_value) + return (String *) NULL; + + input_ptr= (unsigned char *) input_string->ptr(); + input_len= input_string->length(); + + switch ((uint) args[1]->val_int()) { +#ifndef OPENSSL_NO_SHA512 + case 512: + digest_length= SHA512_DIGEST_LENGTH; + (void) SHA512(input_ptr, input_len, digest_buf); + break; + case 384: + digest_length= SHA384_DIGEST_LENGTH; + (void) SHA384(input_ptr, input_len, digest_buf); + break; +#endif +#ifndef OPENSSL_NO_SHA256 + case 224: + digest_length= SHA224_DIGEST_LENGTH; + (void) SHA224(input_ptr, input_len, digest_buf); + break; + case 256: + case 0: // SHA-256 is the default + digest_length= SHA256_DIGEST_LENGTH; + (void) SHA256(input_ptr, input_len, digest_buf); + break; +#endif + default: + if (!args[1]->const_item()) + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WRONG_PARAMETERS_TO_NATIVE_FCT, + ER(ER_WRONG_PARAMETERS_TO_NATIVE_FCT), "sha2"); + null_value= TRUE; + return NULL; + } + + /* + Since we're subverting the usual String methods, we must make sure that + the destination has space for the bytes we're about to write. + */ + str->realloc((uint) digest_length*2 + 1); /* Each byte as two nybbles */ + + /* Convert the large number to a string-hex representation. */ + array_to_hex((char *) str->ptr(), digest_buf, digest_length); + + /* We poked raw bytes in. We must inform the the String of its length. */ + str->length((uint) digest_length*2); /* Each byte as two nybbles */ + + null_value= FALSE; + return str; + +#else + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), + "sha2", "--with-ssl"); + null_value= TRUE; + return (String *) NULL; +#endif +} + + +void Item_func_sha2::fix_length_and_dec() +{ + maybe_null = 1; + max_length = 0; + +#if defined(HAVE_OPENSSL) + int sha_variant= args[1]->const_item() ? args[1]->val_int() : 512; + + switch (sha_variant) { +#ifndef OPENSSL_NO_SHA512 + case 512: + max_length= SHA512_DIGEST_LENGTH*2; + break; + case 384: + max_length= SHA384_DIGEST_LENGTH*2; + break; +#endif +#ifndef OPENSSL_NO_SHA256 + case 256: + case 0: // SHA-256 is the default + max_length= SHA256_DIGEST_LENGTH*2; + break; + case 224: + max_length= SHA224_DIGEST_LENGTH*2; + break; +#endif + default: + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WRONG_PARAMETERS_TO_NATIVE_FCT, + ER(ER_WRONG_PARAMETERS_TO_NATIVE_FCT), "sha2"); + } + + /* + The SHA2() function treats its parameter as being a case sensitive. + Thus we set binary collation on it so different instances of SHA2() + will be compared properly. + */ + + args[0]->collation.set( + get_charset_by_csname( + args[0]->collation.collation->csname, + MY_CS_BINSORT, + MYF(0)), + DERIVATION_COERCIBLE); +#else + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), + "sha2", "--with-ssl"); +#endif +} /* Implementation of AES encryption routines */ @@ -495,7 +650,6 @@ String *Item_func_des_encrypt::val_str(String *str) return 0; // ENCRYPT(NULL) == NULL if ((res_length=res->length()) == 0) return &my_empty_string; - if (arg_count == 1) { /* Protect against someone doing FLUSH DES_KEY_FILE */ @@ -568,7 +722,7 @@ error: #else push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_encrypt","--with-openssl"); + "des_encrypt", "--with-ssl"); #endif /* HAVE_OPENSSL */ null_value=1; return 0; @@ -646,7 +800,7 @@ wrong_key: #else push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_decrypt","--with-openssl"); + "des_decrypt", "--with-ssl"); #endif /* HAVE_OPENSSL */ null_value=1; return 0; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index c9d62ac1052..7b7f8d3308a 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -23,6 +23,8 @@ #pragma interface /* gcc class implementation */ #endif +class MY_LOCALE; + class Item_str_func :public Item_func { public: @@ -80,6 +82,18 @@ public: const char *func_name() const { return "sha"; } }; +class Item_func_sha2 :public Item_str_func +{ +public: + Item_func_sha2(Item *a, Item *b) :Item_str_func(a, b) + { + collation.set(&my_charset_bin); + } + String *val_str(String *); + void fix_length_and_dec(); + const char *func_name() const { return "sha2"; } +}; + class Item_func_aes_encrypt :public Item_str_func { public: @@ -877,4 +891,6 @@ public: String *val_str(String *); }; +extern String my_empty_string; + #endif /* ITEM_STRFUNC_INCLUDED */ diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 267a4b38450..c341dd97460 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -28,8 +28,16 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" #include "sql_select.h" +#include "sql_parse.h" // check_stack_overrun inline Item * and_items(Item* cond, Item *item) { @@ -249,9 +257,13 @@ bool Item_subselect::exec() { int res; - if (thd->is_error()) - /* Do not execute subselect in case of a fatal error */ + /* + Do not execute subselect in case of a fatal error + or if the query has been killed. + */ + if (thd->is_error() || thd->killed) return 1; + /* Simulate a failure in sub-query execution. Used to test e.g. out of memory or query being killed conditions. diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 3503d42edc0..04daab19adc 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -28,6 +28,15 @@ class JOIN; class select_subselect; class subselect_engine; class Item_bool_func2; +class Comp_creator; + +typedef class st_select_lex SELECT_LEX; + +/** + Convenience typedef used in this file, and further used by any files + including this file. +*/ +typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); /* base class for subselects */ @@ -572,6 +581,15 @@ public: virtual void print (String *str, enum_query_type query_type); }; +/* + This function is actually defined in sql_parse.cc, but it depends on + chooser_compare_func_creator defined in this file. + */ +Item * all_any_subquery_creator(Item *left_expr, + chooser_compare_func_creator cmp, + bool all, + SELECT_LEX *select_lex); + inline bool Item_subselect::is_evaluated() const { diff --git a/sql/item_sum.cc b/sql/item_sum.cc index cb0fd82bd54..4746a6057c6 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -25,7 +25,7 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" #include "sql_select.h" /** @@ -1176,7 +1176,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) default: DBUG_ASSERT(0); }; - setup(args[0], NULL); + setup_hybrid(args[0], NULL); /* MIN/MAX can return NULL for empty set indepedent of the used column */ maybe_null= 1; unsigned_flag=item->unsigned_flag; @@ -1210,7 +1210,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) of the original MIN/MAX object and it is saved in this object's cache. */ -void Item_sum_hybrid::setup(Item *item, Item *value_arg) +void Item_sum_hybrid::setup_hybrid(Item *item, Item *value_arg) { value= Item_cache::get_cache(item); value->setup(item); @@ -1972,7 +1972,7 @@ void Item_sum_hybrid::no_rows_in_result() Item *Item_sum_min::copy_or_same(THD* thd) { Item_sum_min *item= new (thd->mem_root) Item_sum_min(thd, this); - item->setup(args[0], value); + item->setup_hybrid(args[0], value); return item; } @@ -1995,7 +1995,7 @@ bool Item_sum_min::add() Item *Item_sum_max::copy_or_same(THD* thd) { Item_sum_max *item= new (thd->mem_root) Item_sum_max(thd, this); - item->setup(args[0], value); + item->setup_hybrid(args[0], value); return item; } diff --git a/sql/item_sum.h b/sql/item_sum.h index 26f0a08096e..5f2c4f166e6 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1,7 +1,7 @@ #ifndef ITEM_SUM_INCLUDED #define ITEM_SUM_INCLUDED -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -24,6 +24,7 @@ #endif #include <my_tree.h> +#include "sql_udf.h" /* udf_handler */ class Item_sum; class Aggregator_distinct; @@ -987,7 +988,7 @@ protected: was_values(item->was_values) { } bool fix_fields(THD *, Item **); - void setup(Item *item, Item *value_arg); + void setup_hybrid(Item *item, Item *value_arg); void clear(); double val_real(); longlong val_int(); diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 49d31bf1252..feff03e704a 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -28,7 +28,28 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" +#include "sql_locale.h" // MY_LOCALE my_locale_en_US +#include "strfunc.h" // check_word +#include "sql_time.h" // make_truncated_value_warning, + // make_time, get_date_from_daynr, + // calc_weekday, calc_week, + // convert_month_to_period, + // convert_period_to_month, + // TIME_to_timestamp, make_date, + // calc_time_diff, + // calc_time_from_sec, + // known_date_time_format, + // get_date_time_format_str +#include "tztime.h" // struct Time_zone +#include "sql_class.h" // THD #include <m_ctype.h> #include <time.h> diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 20e4d6488d6..2c08853fda4 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -23,6 +23,8 @@ #pragma interface /* gcc class implementation */ #endif +class MY_LOCALE; + enum date_time_format_types { TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND @@ -1066,4 +1068,10 @@ public: } }; + +/* Function prototypes */ + +bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, + timestamp_type type, String *str); + #endif /* ITEM_TIMEFUNC_INCLUDED */ diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index 3621733f456..f124c37f0eb 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -17,9 +17,17 @@ #pragma implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" #include "my_xml.h" #include "sp_pcontext.h" +#include "sql_class.h" // THD /* TODO: future development directions: diff --git a/sql/key.cc b/sql/key.cc index 93197ec4ff5..d593850ca10 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -16,7 +16,10 @@ /* Functions to handle keys and fields in forms */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: by includes later +#include "key.h" // key_rec_cmp +#include "field.h" // Field /* Search after a key that starts with 'field' diff --git a/sql/key.h b/sql/key.h new file mode 100644 index 00000000000..8b416da5846 --- /dev/null +++ b/sql/key.h @@ -0,0 +1,39 @@ +/* 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 KEY_INCLUDED +#define KEY_INCLUDED + +#include "my_global.h" /* uchar */ + +class Field; +class String; +struct TABLE; +typedef struct st_bitmap MY_BITMAP; +typedef struct st_key KEY; +typedef struct st_key_part_info KEY_PART_INFO; + +int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field, + uint *key_length, uint *keypart); +void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length); +void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, + uint key_length); +bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length); +void key_unpack(String *to,TABLE *form,uint index); +bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields); +int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length); +extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b); + +#endif /* KEY_INCLUDED */ diff --git a/sql/keycaches.h b/sql/keycaches.h index 542a4d14c3d..66d24b59465 100644 --- a/sql/keycaches.h +++ b/sql/keycaches.h @@ -1,3 +1,6 @@ +#ifndef KEYCACHES_INCLUDED +#define KEYCACHES_INCLUDED + /* Copyright (C) 2002-2006 MySQL AB, 2009 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify @@ -39,3 +42,4 @@ KEY_CACHE *get_or_create_key_cache(const char *name, uint length); void free_key_cache(const char *name, KEY_CACHE *key_cache); bool process_key_caches(process_key_cache_t func); +#endif /* KEYCACHES_INCLUDED */ diff --git a/sql/lock.cc b/sql/lock.cc index 3ff131bb828..758ea6cf914 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -73,8 +73,13 @@ we are forced to use mysql_lock_merge. */ -#include "mysql_priv.h" +#include "sql_priv.h" #include "debug_sync.h" +#include "unireg.h" // REQUIRED: for other includes +#include "lock.h" +#include "sql_base.h" // close_tables_for_reopen +#include "sql_parse.h" // is_log_table_write_query +#include "sql_acl.h" // SUPER_ACL #include <hash.h> #include <assert.h> @@ -89,15 +94,15 @@ extern HASH open_cache; #define GET_LOCK_UNLOCK 1 #define GET_LOCK_STORE_LOCKS 2 -static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table,uint count, - uint flags, TABLE **write_locked); +static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, + uint flags); static int lock_external(THD *thd, TABLE **table,uint count); static int unlock_external(THD *thd, TABLE **table,uint count); static void print_lock_error(int error, const char *); /* Map the return value of thr_lock to an error from errmsg.txt */ static int thr_lock_errno_to_mysql[]= -{ 0, 1, ER_LOCK_WAIT_TIMEOUT, ER_LOCK_DEADLOCK }; +{ 0, ER_LOCK_ABORTED, ER_LOCK_WAIT_TIMEOUT, ER_LOCK_DEADLOCK }; /** Perform semantic checks for mysql_lock_tables. @@ -107,17 +112,18 @@ static int thr_lock_errno_to_mysql[]= @param flags Lock flags @return 0 if all the check passed, non zero if a check failed. */ -int mysql_lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) +static int +lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) { - bool log_table_write_query; - uint system_count; - uint i; + uint system_count, i; + bool is_superuser, log_table_write_query; - DBUG_ENTER("mysql_lock_tables_check"); + DBUG_ENTER("lock_tables_check"); system_count= 0; + is_superuser= thd->security_ctx->master_access & SUPER_ACL; log_table_write_query= (is_log_table_write_query(thd->lex->sql_command) - || ((flags & MYSQL_LOCK_PERF_SCHEMA) != 0)); + || ((flags & MYSQL_LOCK_LOG_TABLE) != 0)); for (i=0 ; i<count; i++) { @@ -148,10 +154,16 @@ int mysql_lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) } } - if ((t->s->table_category == TABLE_CATEGORY_SYSTEM) && - (t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE)) + if (t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE) { - system_count++; + if (t->s->table_category == TABLE_CATEGORY_SYSTEM) + system_count++; + + if (t->db_stat & HA_READ_ONLY) + { + my_error(ER_OPEN_AS_READONLY, MYF(0), t->alias); + DBUG_RETURN(1); + } } /* @@ -172,6 +184,20 @@ int mysql_lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) thd->mdl_context.is_lock_owner(MDL_key::TABLE, t->s->db.str, t->s->table_name.str, MDL_SHARED))); + + /* + Prevent modifications to base tables if READ_ONLY is activated. + In any case, read only does not apply to temporary tables. + */ + if (!(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY) && !t->s->tmp_table) + { + if (t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE && + !is_superuser && opt_readonly && !thd->slave_thread) + { + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); + DBUG_RETURN(1); + } + } } /* @@ -248,157 +274,69 @@ static void reset_lock_data_and_free(MYSQL_LOCK **mysql_lock) @param tables An array of pointers to the tables to lock. @param count The number of tables to lock. @param flags Options: - MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK Ignore a global read lock MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY Ignore SET GLOBAL READ_ONLY - MYSQL_LOCK_IGNORE_FLUSH Ignore a flush tables. MYSQL_LOCK_IGNORE_TIMEOUT Use maximum timeout value. - @param need_reopen Out parameter, TRUE if some tables were altered - or deleted and should be reopened by caller. - - @note Caller of this function should always be ready to handle request to - reopen table unless there are external invariants which guarantee - that such thing won't be needed (for example we are obtaining lock - on table on which we already have exclusive metadata lock). @retval A lock structure pointer on success. - @retval NULL on error or if some tables should be reopen. + @retval NULL if an error or if wait on a lock was killed. */ -MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, - uint flags, bool *need_reopen) +MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags) { - MYSQL_LOCK *sql_lock; - TABLE *write_lock_used; int rc; - - DBUG_ENTER("mysql_lock_tables"); - - *need_reopen= FALSE; - - if (mysql_lock_tables_check(thd, tables, count, flags)) - DBUG_RETURN (NULL); - + MYSQL_LOCK *sql_lock; ulong timeout= (flags & MYSQL_LOCK_IGNORE_TIMEOUT) ? LONG_TIMEOUT : thd->variables.lock_wait_timeout; - for (;;) - { - if (! (sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS, - &write_lock_used))) - break; + DBUG_ENTER("mysql_lock_tables"); - if (global_read_lock && write_lock_used && - ! (flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)) - { - /* - Someone has issued LOCK ALL TABLES FOR READ and we want a write lock - Wait until the lock is gone - */ - if (thd->global_read_lock.wait_if_global_read_lock(thd, 1, 1)) - { - /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data_and_free(&sql_lock); - break; - } - if (thd->version != refresh_version) - { - /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data_and_free(&sql_lock); - goto retry; - } - } + if (lock_tables_check(thd, tables, count, flags)) + DBUG_RETURN(NULL); - if (!(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY) && - write_lock_used && - opt_readonly && - !(thd->security_ctx->master_access & SUPER_ACL) && - !thd->slave_thread) - { - /* - Someone has issued SET GLOBAL READ_ONLY=1 and we want a write lock. - We do not wait for READ_ONLY=0, and fail. - */ - reset_lock_data_and_free(&sql_lock); - my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); - break; - } + if (! (sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS))) + DBUG_RETURN(NULL); - thd_proc_info(thd, "System lock"); - DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info)); - if (sql_lock->table_count && lock_external(thd, sql_lock->table, - sql_lock->table_count)) - { - /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data_and_free(&sql_lock); - break; - } - DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info)); - /* Copy the lock data array. thr_multi_lock() reorders its contens. */ - memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, - sql_lock->lock_count * sizeof(*sql_lock->locks)); - /* Lock on the copied half of the lock data array. */ - rc= thr_lock_errno_to_mysql[(int) thr_multi_lock(sql_lock->locks + - sql_lock->lock_count, - sql_lock->lock_count, - thd->lock_id, timeout)]; - if (rc > 1) /* a timeout or a deadlock */ - { - if (sql_lock->table_count) - (void) unlock_external(thd, sql_lock->table, sql_lock->table_count); - reset_lock_data_and_free(&sql_lock); - my_error(rc, MYF(0)); - break; - } - else if (rc == 1) /* aborted or killed */ - { - /* - reset_lock_data is required here. If thr_multi_lock fails it - resets lock type for tables, which were locked before (and - including) one that caused error. Lock type for other tables - preserved. - */ - reset_lock_data(sql_lock); - sql_lock->lock_count= 0; // Locks are already freed - // Fall through: unlock, reset lock data, free and retry - } - else - { - /* Success */ - break; - } - thd_proc_info(thd, 0); - - /* going to retry, unlock all tables */ - if (sql_lock->lock_count) - thr_multi_unlock(sql_lock->locks, sql_lock->lock_count); + thd_proc_info(thd, "System lock"); + DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info)); + if (sql_lock->table_count && lock_external(thd, sql_lock->table, + sql_lock->table_count)) + { + /* Clear the lock type of all lock data to avoid reusage. */ + reset_lock_data_and_free(&sql_lock); + goto end; + } + /* Copy the lock data array. thr_multi_lock() reorders its contents. */ + memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, + sql_lock->lock_count * sizeof(*sql_lock->locks)); + /* Lock on the copied half of the lock data array. */ + rc= thr_lock_errno_to_mysql[(int) thr_multi_lock(sql_lock->locks + + sql_lock->lock_count, + sql_lock->lock_count, + thd->lock_id, timeout)]; + if (rc) + { if (sql_lock->table_count) (void) unlock_external(thd, sql_lock->table, sql_lock->table_count); - - /* - If thr_multi_lock fails it resets lock type for tables, which - were locked before (and including) one that caused error. Lock - type for other tables preserved. - */ reset_lock_data_and_free(&sql_lock); -retry: - /* Let upper level close all used tables and retry or give error. */ - *need_reopen= TRUE; - break; + if (! thd->killed) + my_error(rc, MYF(0)); } +end: thd_proc_info(thd, 0); + if (thd->killed) { thd->send_kill_message(); if (sql_lock) { - mysql_unlock_tables(thd,sql_lock); - sql_lock=0; + mysql_unlock_tables(thd, sql_lock); + sql_lock= 0; } } thd->set_time_after_lock(); - DBUG_RETURN (sql_lock); + DBUG_RETURN(sql_lock); } @@ -459,9 +397,7 @@ void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock) void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count) { MYSQL_LOCK *sql_lock; - TABLE *write_lock_used; - if ((sql_lock= get_lock_data(thd, table, count, GET_LOCK_UNLOCK, - &write_lock_used))) + if ((sql_lock= get_lock_data(thd, table, count, GET_LOCK_UNLOCK))) mysql_unlock_tables(thd, sql_lock); } @@ -603,9 +539,7 @@ void mysql_lock_downgrade_write(THD *thd, TABLE *table, thr_lock_type new_lock_type) { MYSQL_LOCK *locked; - TABLE *write_lock_used; - if ((locked = get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK, - &write_lock_used))) + if ((locked = get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK))) { for (uint i=0; i < locked->lock_count; i++) thr_downgrade_write_lock(locked->locks[i], new_lock_type); @@ -619,11 +553,9 @@ void mysql_lock_downgrade_write(THD *thd, TABLE *table, void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock) { MYSQL_LOCK *locked; - TABLE *write_lock_used; DBUG_ENTER("mysql_lock_abort"); - if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK, - &write_lock_used))) + if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK))) { for (uint i=0; i < locked->lock_count; i++) thr_abort_locks(locked->locks[i]->lock, upgrade_lock); @@ -648,12 +580,10 @@ void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock) bool mysql_lock_abort_for_thread(THD *thd, TABLE *table) { MYSQL_LOCK *locked; - TABLE *write_lock_used; bool result= FALSE; DBUG_ENTER("mysql_lock_abort_for_thread"); - if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK, - &write_lock_used))) + if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK))) { for (uint i=0; i < locked->lock_count; i++) { @@ -848,11 +778,10 @@ static int unlock_external(THD *thd, TABLE **table,uint count) @param flags One of: - GET_LOCK_UNLOCK : If we should send TL_IGNORE to store lock - GET_LOCK_STORE_LOCKS : Store lock info in TABLE - @param write_lock_used Store pointer to last table with WRITE_ALLOW_WRITE */ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, - uint flags, TABLE **write_lock_used) + uint flags) { uint i,tables,lock_count; MYSQL_LOCK *sql_lock; @@ -861,9 +790,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, DBUG_ENTER("get_lock_data"); DBUG_ASSERT((flags == GET_LOCK_UNLOCK) || (flags == GET_LOCK_STORE_LOCKS)); - DBUG_PRINT("info", ("count %d", count)); - *write_lock_used=0; + for (i=tables=lock_count=0 ; i < count ; i++) { TABLE *t= table_ptr[i]; @@ -895,24 +823,12 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, { TABLE *table; enum thr_lock_type lock_type; + THR_LOCK_DATA **org_locks = locks; if ((table=table_ptr[i])->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE) continue; lock_type= table->reginfo.lock_type; DBUG_ASSERT(lock_type != TL_WRITE_DEFAULT && lock_type != TL_READ_DEFAULT); - if (lock_type >= TL_WRITE_ALLOW_WRITE) - { - *write_lock_used=table; - if (table->db_stat & HA_READ_ONLY) - { - my_error(ER_OPEN_AS_READONLY,MYF(0),table->alias); - /* Clear the lock type of the lock data that are stored already. */ - sql_lock->lock_count= (uint) (locks - sql_lock->locks); - reset_lock_data_and_free(&sql_lock); - DBUG_RETURN(0); - } - } - THR_LOCK_DATA **org_locks = locks; locks_start= locks; locks= table->file->store_lock(thd, locks, (flags & GET_LOCK_UNLOCK) ? TL_IGNORE : diff --git a/sql/lock.h b/sql/lock.h new file mode 100644 index 00000000000..19b23f1f42b --- /dev/null +++ b/sql/lock.h @@ -0,0 +1,104 @@ +#ifndef LOCK_INCLUDED +#define LOCK_INCLUDED + +#include "thr_lock.h" /* thr_lock_type */ + +// Forward declarations +struct TABLE; +struct TABLE_LIST; +class THD; +typedef struct st_mysql_lock MYSQL_LOCK; + +/* mysql_lock_tables() and open_table() flags bits */ +#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001 +#define MYSQL_OPEN_IGNORE_FLUSH 0x0002 +#define MYSQL_OPEN_TEMPORARY_ONLY 0x0004 +#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008 +#define MYSQL_LOCK_LOG_TABLE 0x0010 +#define MYSQL_OPEN_TAKE_UPGRADABLE_MDL 0x0020 +/** + Do not try to acquire a metadata lock on the table: we + already have one. +*/ +#define MYSQL_OPEN_HAS_MDL_LOCK 0x0040 +/** + If in locked tables mode, ignore the locked tables and get + a new instance of the table. +*/ +#define MYSQL_OPEN_GET_NEW_TABLE 0x0080 +/** Don't look up the table in the list of temporary tables. */ +#define MYSQL_OPEN_SKIP_TEMPORARY 0x0100 +/** Fail instead of waiting when conficting metadata lock is discovered. */ +#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0200 +/** Open tables using MDL_SHARED lock instead of one specified in parser. */ +#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0400 +/** + Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified + in parser. +*/ +#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0800 +/** + When opening or locking the table, use the maximum timeout + (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value. +*/ +#define MYSQL_LOCK_IGNORE_TIMEOUT 0x1000 + +/** Please refer to the internals manual. */ +#define MYSQL_OPEN_REOPEN (MYSQL_OPEN_IGNORE_FLUSH |\ + MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK |\ + MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |\ + MYSQL_LOCK_IGNORE_TIMEOUT |\ + MYSQL_OPEN_GET_NEW_TABLE |\ + MYSQL_OPEN_SKIP_TEMPORARY |\ + MYSQL_OPEN_HAS_MDL_LOCK) + + +#include "thr_lock.h" /* thr_lock_type */ + +struct TABLE_LIST; +class THD; +struct TABLE; +typedef struct st_mysql_lock MYSQL_LOCK; + +MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, uint flags); +void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock); +void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock); +void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count); +void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table); +void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock); +void mysql_lock_downgrade_write(THD *thd, TABLE *table, + thr_lock_type new_lock_type); +bool mysql_lock_abort_for_thread(THD *thd, TABLE *table); +MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b); +TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle, + TABLE_LIST *haystack); +bool lock_global_read_lock(THD *thd); +void unlock_global_read_lock(THD *thd); +bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, + bool is_not_commit); +void start_waiting_global_read_lock(THD *thd); +bool make_global_read_lock_block_commit(THD *thd); +bool set_protect_against_global_read_lock(void); +void unset_protect_against_global_read_lock(void); +/* Lock based on stored routine name */ +bool lock_routine_name(THD *thd, bool is_function, const char *db, + const char *name); +void broadcast_refresh(void); + +/* Lock based on name */ +int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list); +int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use); +void unlock_table_name(THD *thd, TABLE_LIST *table_list); +bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list); +bool lock_table_names(THD *thd, TABLE_LIST *table_list); +void unlock_table_names(THD *thd); +bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list); +bool is_table_name_exclusively_locked_by_this_thread(THD *thd, + TABLE_LIST *table_list); +bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key, + int key_length); +void broadcast_refresh(void); + + + +#endif /* LOCK_INCLUDED */ diff --git a/sql/log.cc b/sql/log.cc index ce9d75089d1..551072d2d47 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -24,8 +24,17 @@ Abort logging when we get an error in reading or writing log files */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "log.h" +#include "sql_base.h" // close_thread_tables #include "sql_repl.h" +#include "sql_delete.h" // mysql_truncate +#include "sql_parse.h" // command_name +#include "sql_time.h" // calc_time_from_sec, my_time_compare +#include "tztime.h" // my_tz_OFFSET0, struct Time_zone +#include "sql_acl.h" // SUPER_ACL +#include "log_event.h" // Query_log_event #include "rpl_filter.h" #include "rpl_rli.h" #include "sql_audit.h" @@ -38,7 +47,7 @@ #include "message.h" #endif -#include <mysql/plugin.h> +#include "sql_plugin.h" #include "rpl_handler.h" /* max size of the log message */ @@ -4671,7 +4680,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) /* setting flags for user var log event */ uchar flags= User_var_log_event::UNDEF_F; - if (user_var_event->user_var_event->unsigned_flag) + if (user_var_event->unsigned_flag) flags|= User_var_log_event::UNSIGNED_F; User_var_log_event e(thd, user_var_event->user_var_event->name.str, @@ -4993,7 +5002,7 @@ int query_error_code(THD *thd, bool not_killed) { int error; - if (not_killed) + if (not_killed || (thd->killed == THD::KILL_BAD_DATA)) { error= thd->is_error() ? thd->stmt_da->sql_errno() : 0; diff --git a/sql/log.h b/sql/log.h index e9429067a34..71c27f50f78 100644 --- a/sql/log.h +++ b/sql/log.h @@ -16,6 +16,9 @@ #ifndef LOG_H #define LOG_H +#include "unireg.h" // REQUIRED: for other includes +#include "handler.h" /* my_xid */ + class Relay_log_info; class Format_description_log_event; @@ -644,4 +647,36 @@ extern TYPELIB binlog_format_typelib; int query_error_code(THD *thd, bool not_killed); uint purge_log_get_error_code(int res); +int vprint_msg_to_log(enum loglevel level, const char *format, va_list args); +void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2); +void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2); +void sql_print_information(const char *format, ...) + ATTRIBUTE_FORMAT(printf, 1, 2); +typedef void (*sql_print_message_func)(const char *format, ...) + ATTRIBUTE_FORMAT(printf, 1, 2); +extern sql_print_message_func sql_print_message_handlers[]; + +int error_log_print(enum loglevel level, const char *format, + va_list args); + +bool slow_log_print(THD *thd, const char *query, uint query_length, + ulonglong current_utime); + +bool general_log_print(THD *thd, enum enum_server_command command, + const char *format,...); + +bool general_log_write(THD *thd, enum enum_server_command command, + const char *query, uint query_length); + +void sql_perror(const char *message); +bool flush_error_log(); + +File open_binlog(IO_CACHE *log, const char *log_file_name, + const char **errmsg); + +char *make_log_name(char *buff, const char *name, const char* log_ext); + +extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log; +extern LOGGER logger; + #endif /* LOG_H */ diff --git a/sql/log_event.cc b/sql/log_event.cc index 6412f0047d1..a1f8a791c49 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -16,7 +16,7 @@ #ifdef MYSQL_CLIENT -#include "mysql_priv.h" +#include "sql_priv.h" #else @@ -24,7 +24,19 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "my_global.h" // REQUIRED by log_event.h > m_string.h > my_bitmap.h +#include "log_event.h" +#include "sql_base.h" // close_thread_tables +#include "sql_cache.h" // QUERY_CACHE_FLAGS_SIZE +#include "sql_locale.h" // MY_LOCALE, my_locale_by_number, my_locale_en_US +#include "key.h" // key_copy +#include "lock.h" // mysql_unlock_tables +#include "sql_parse.h" // mysql_test_parse_for_slave +#include "tztime.h" // struct Time_zone +#include "sql_load.h" // mysql_load +#include "sql_db.h" // load_db_opt_by_name #include "slave.h" #include "rpl_rli.h" #include "rpl_mi.h" @@ -9638,7 +9650,7 @@ Incident_log_event::write_data_body(IO_CACHE *file) they will always be printed for the first event. */ st_print_event_info::st_print_event_info() - :flags2_inited(0), sql_mode_inited(0), + :flags2_inited(0), sql_mode_inited(0), sql_mode(0), auto_increment_increment(0),auto_increment_offset(0), charset_inited(0), lc_time_names_number(~0), charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER), diff --git a/sql/log_event.h b/sql/log_event.h index 81669e24708..36397c427e5 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -28,7 +28,7 @@ #ifndef _log_event_h #define _log_event_h -#if defined(USE_PRAGMA_INTERFACE) && !defined(MYSQL_CLIENT) +#if defined(USE_PRAGMA_INTERFACE) && defined(MYSQL_SERVER) #pragma interface /* gcc class implementation */ #endif @@ -36,17 +36,22 @@ #include "rpl_constants.h" #ifdef MYSQL_CLIENT +#include "sql_const.h" #include "rpl_utility.h" #include "hash.h" #include "rpl_tblmap.h" #include "rpl_tblmap.cc" #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER #include "rpl_record.h" #include "rpl_reporting.h" +#include "sql_class.h" /* THD */ #endif +/* Forward declarations */ +class String; + #define PREFIX_SQL_LOAD "SQL_LOAD-" /** @@ -607,7 +612,7 @@ enum Int_event_type }; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER class String; class MYSQL_BIN_LOG; class THD; @@ -685,11 +690,9 @@ typedef struct st_print_event_info uint8 common_header_len; char delimiter[16]; -#ifdef MYSQL_CLIENT uint verbose; table_mapping m_table_map; table_mapping m_table_map_ignored; -#endif /* These two caches are used by the row-based replication events to @@ -963,7 +966,7 @@ public: */ ulong slave_exec_mode; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER THD* thd; Log_event(); @@ -1035,7 +1038,7 @@ public: static void *operator new(size_t, void* ptr) { return ptr; } static void operator delete(void*, void*) { } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write_header(IO_CACHE* file, ulong data_length); virtual bool write(IO_CACHE* file) { @@ -1109,7 +1112,7 @@ public: /* Return start of query time or current time */ -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) public: /** @@ -1413,7 +1416,7 @@ protected: <td>Q_SQL_MODE_CODE == 1</td> <td>8 byte bitfield</td> <td>The @c sql_mode variable. See the section "SQL Modes" in the - MySQL manual, and see mysql_priv.h for a list of the possible + MySQL manual, and see sql_priv.h for a list of the possible flags. Currently (2007-10-04), the following flags are available: <pre> MODE_REAL_AS_FLOAT==0x1 @@ -1697,7 +1700,7 @@ public: */ uint32 master_data_written; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length, bool using_trans, bool direct, bool suppress_use, int error); @@ -1720,7 +1723,7 @@ public: my_free((uchar*) data_buf, MYF(0)); } Log_event_type get_type_code() { return QUERY_EVENT; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); virtual bool write_post_header_for_derived(IO_CACHE* file) { return FALSE; } #endif @@ -1734,7 +1737,7 @@ public: /* Writes derived event-specific part of post header. */ public: /* !!! Public in this patch to allow old usage */ -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); @@ -1809,7 +1812,7 @@ public: int master_log_len; uint16 master_port; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Slave_log_event(THD* thd_arg, Relay_log_info* rli); void pack_info(Protocol* protocol); #else @@ -1821,12 +1824,12 @@ public: int get_data_size(); bool is_valid() const { return master_host != 0; } Log_event_type get_type_code() { return SLAVE_EVENT; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const* rli); #endif }; @@ -2080,7 +2083,7 @@ public: return local_fname; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER String field_lens_buf; String fields_buf; @@ -2113,7 +2116,7 @@ public: { return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write_data_header(IO_CACHE* file); bool write_data_body(IO_CACHE* file); #endif @@ -2126,7 +2129,7 @@ public: } public: /* !!! Public in this patch to allow old usage */ -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const* rli) { return do_apply_event(thd->slave_net,rli,0); @@ -2188,7 +2191,7 @@ public: */ bool dont_set_created; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Start_log_event_v3(); #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); @@ -2202,7 +2205,7 @@ public: const Format_description_log_event* description_event); ~Start_log_event_v3() {} Log_event_type get_type_code() { return START_EVENT_V3;} -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif bool is_valid() const { return 1; } @@ -2212,7 +2215,7 @@ public: } protected: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info*) { @@ -2264,7 +2267,7 @@ public: my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR)); } Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;} -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif bool is_valid() const @@ -2286,7 +2289,7 @@ public: void calc_server_version_split(); protected: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); @@ -2338,7 +2341,7 @@ public: ulonglong val; uchar type; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg) :Log_event(thd_arg,0,0),val(val_arg),type(type_arg) {} @@ -2355,13 +2358,13 @@ public: Log_event_type get_type_code() { return INTVAR_EVENT;} const char* get_var_type_name(); int get_data_size() { return 9; /* sizeof(type) + sizeof(val) */;} -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif bool is_valid() const { return 1; } private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); @@ -2414,7 +2417,7 @@ class Rand_log_event: public Log_event ulonglong seed1; ulonglong seed2; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg) :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg) {} @@ -2430,13 +2433,13 @@ class Rand_log_event: public Log_event ~Rand_log_event() {} Log_event_type get_type_code() { return RAND_EVENT;} int get_data_size() { return 16; /* sizeof(ulonglong) * 2*/ } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif bool is_valid() const { return 1; } private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); @@ -2460,7 +2463,7 @@ class Xid_log_event: public Log_event public: my_xid xid; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {} #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); @@ -2474,13 +2477,13 @@ class Xid_log_event: public Log_event ~Xid_log_event() {} Log_event_type get_type_code() { return XID_EVENT;} int get_data_size() { return sizeof(xid); } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif bool is_valid() const { return 1; } private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); enum_skip_reason do_shall_skip(Relay_log_info *rli); #endif @@ -2510,7 +2513,7 @@ public: uint charset_number; bool is_null; uchar flags; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg, char *val_arg, ulong val_len_arg, Item_result type_arg, uint charset_number_arg, uchar flags_arg) @@ -2527,13 +2530,13 @@ public: const Format_description_log_event *description_event); ~User_var_log_event() {} Log_event_type get_type_code() { return USER_VAR_EVENT;} -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif bool is_valid() const { return 1; } private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); @@ -2552,7 +2555,7 @@ private: class Stop_log_event: public Log_event { public: -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Stop_log_event() :Log_event() {} #else @@ -2568,7 +2571,7 @@ public: bool is_valid() const { return 1; } private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) { @@ -2644,7 +2647,7 @@ public: ulonglong pos; uint ident_len; uint flags; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Rotate_log_event(const char* new_log_ident_arg, uint ident_len_arg, ulonglong pos_arg, uint flags); @@ -2665,12 +2668,12 @@ public: Log_event_type get_type_code() { return ROTATE_EVENT;} int get_data_size() { return ident_len + ROTATE_HEADER_LEN;} bool is_valid() const { return new_log_ident != 0; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); #endif @@ -2701,7 +2704,7 @@ public: uint file_id; bool inited_from_old; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg, const char* table_name_arg, List<Item>& fields_arg, @@ -2735,7 +2738,7 @@ public: 4 + 1 + block_len); } bool is_valid() const { return inited_from_old || block != 0; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write_data_header(IO_CACHE* file); bool write_data_body(IO_CACHE* file); /* @@ -2746,7 +2749,7 @@ public: #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); #endif }; @@ -2777,7 +2780,7 @@ public: */ const char* db; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg, uint block_len_arg, bool using_trans); #ifdef HAVE_REPLICATION @@ -2795,13 +2798,13 @@ public: Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;} int get_data_size() { return block_len + APPEND_BLOCK_HEADER_LEN ;} bool is_valid() const { return block != 0; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); const char* get_db() { return db; } #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); #endif }; @@ -2819,7 +2822,7 @@ public: uint file_id; const char* db; /* see comment in Append_block_log_event */ -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans); #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); @@ -2836,13 +2839,13 @@ public: Log_event_type get_type_code() { return DELETE_FILE_EVENT;} int get_data_size() { return DELETE_FILE_HEADER_LEN ;} bool is_valid() const { return file_id != 0; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); const char* get_db() { return db; } #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); #endif }; @@ -2860,7 +2863,7 @@ public: uint file_id; const char* db; /* see comment in Append_block_log_event */ -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans); #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); @@ -2876,13 +2879,13 @@ public: Log_event_type get_type_code() { return EXEC_LOAD_EVENT;} int get_data_size() { return EXEC_LOAD_HEADER_LEN ;} bool is_valid() const { return file_id != 0; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write(IO_CACHE* file); const char* get_db() { return db; } #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); #endif }; @@ -2900,7 +2903,7 @@ private: class Begin_load_query_log_event: public Append_block_log_event { public: -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Begin_load_query_log_event(THD* thd_arg, const char *db_arg, uchar* block_arg, uint block_len_arg, bool using_trans); @@ -2915,7 +2918,7 @@ public: ~Begin_load_query_log_event() {} Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; } private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); #endif }; @@ -2951,7 +2954,7 @@ public: */ enum_load_dup_handling dup_handling; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Execute_load_query_log_event(THD* thd, const char* query_arg, ulong query_length, uint fn_pos_start_arg, uint fn_pos_end_arg, @@ -2976,12 +2979,12 @@ public: bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; } ulong get_post_header_size_for_derived(); -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER bool write_post_header_for_derived(IO_CACHE* file); #endif private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); #endif }; @@ -3371,7 +3374,7 @@ public: flag_set get_flags(flag_set flag) const { return m_flags & flag; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, bool is_transactional); #endif #ifdef HAVE_REPLICATION @@ -3396,14 +3399,14 @@ public: virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ } virtual int get_data_size() { return (uint) m_data_size; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER virtual int save_field_metadata(); virtual bool write_data_header(IO_CACHE *file); virtual bool write_data_body(IO_CACHE *file); virtual const char *get_db() { return m_dbnam; } #endif -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual void pack_info(Protocol *protocol); #endif @@ -3413,13 +3416,13 @@ public: private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER TABLE *m_table; #endif char const *m_dbnam; @@ -3515,7 +3518,7 @@ public: void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; } flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; } -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual void pack_info(Protocol *protocol); #endif @@ -3530,7 +3533,7 @@ public: const uchar *ptr, const uchar *prefix); #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER int add_row_data(uchar *data, size_t length) { return do_add_row_data(data,length); @@ -3544,7 +3547,7 @@ public: size_t get_width() const { return m_width; } ulong get_table_id() const { return m_table_id; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER virtual bool write_data_header(IO_CACHE *file); virtual bool write_data_body(IO_CACHE *file); virtual const char *get_db() { return m_table->s->db.str; } @@ -3567,7 +3570,7 @@ protected: The constructors are protected since you're supposed to inherit this class, not create instances of this class. */ -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Rows_log_event(THD*, TABLE*, ulong table_id, MY_BITMAP const *cols, bool is_transactional); #endif @@ -3579,11 +3582,11 @@ protected: void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name); #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER virtual int do_add_row_data(uchar *data, size_t length); #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER TABLE *m_table; /* The table the rows belong to */ #endif ulong m_table_id; /* Table ID */ @@ -3612,7 +3615,7 @@ protected: /* helper functions */ -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) const uchar *m_curr_row; /* Start of the row being processed */ const uchar *m_curr_row_end; /* One-after the end of the current row */ uchar *m_key; /* Buffer to keep key value during searches */ @@ -3640,7 +3643,7 @@ protected: private: -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); virtual int do_update_pos(Relay_log_info *rli); virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); @@ -3695,7 +3698,7 @@ private: */ virtual int do_exec_row(const Relay_log_info *const rli) = 0; -#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */ +#endif /* defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) */ friend class Old_rows_log_event; }; @@ -3718,7 +3721,7 @@ public: TYPE_CODE = WRITE_ROWS_EVENT }; -#if !defined(MYSQL_CLIENT) +#if defined(MYSQL_SERVER) Write_rows_log_event(THD*, TABLE*, ulong table_id, MY_BITMAP const *cols, bool is_transactional); #endif @@ -3726,7 +3729,7 @@ public: Write_rows_log_event(const char *buf, uint event_len, const Format_description_log_event *description_event); #endif -#if !defined(MYSQL_CLIENT) +#if defined(MYSQL_SERVER) static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, MY_BITMAP *cols, @@ -3747,7 +3750,7 @@ private: void print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_before_row_operations(const Slave_reporting_capability *const); virtual int do_after_row_operations(const Slave_reporting_capability *const,int); virtual int do_exec_row(const Relay_log_info *const); @@ -3776,7 +3779,7 @@ public: TYPE_CODE = UPDATE_ROWS_EVENT }; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Update_rows_log_event(THD*, TABLE*, ulong table_id, MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai, @@ -3796,7 +3799,7 @@ public: const Format_description_log_event *description_event); #endif -#if !defined(MYSQL_CLIENT) +#ifdef MYSQL_SERVER static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, MY_BITMAP *cols, @@ -3821,11 +3824,11 @@ protected: void print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_before_row_operations(const Slave_reporting_capability *const); virtual int do_after_row_operations(const Slave_reporting_capability *const,int); virtual int do_exec_row(const Relay_log_info *const); -#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */ +#endif /* defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) */ }; /** @@ -3857,7 +3860,7 @@ public: TYPE_CODE = DELETE_ROWS_EVENT }; -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Delete_rows_log_event(THD*, TABLE*, ulong, MY_BITMAP const *cols, bool is_transactional); #endif @@ -3865,7 +3868,7 @@ public: Delete_rows_log_event(const char *buf, uint event_len, const Format_description_log_event *description_event); #endif -#if !defined(MYSQL_CLIENT) +#ifdef MYSQL_SERVER static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, MY_BITMAP *cols, @@ -3886,7 +3889,7 @@ protected: void print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_before_row_operations(const Slave_reporting_capability *const); virtual int do_after_row_operations(const Slave_reporting_capability *const,int); virtual int do_exec_row(const Relay_log_info *const); @@ -3934,7 +3937,7 @@ protected: */ class Incident_log_event : public Log_event { public: -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Incident_log_event(THD *thd_arg, Incident incident) : Log_event(thd_arg, 0, FALSE), m_incident(incident) { @@ -3957,7 +3960,7 @@ public: } #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER void pack_info(Protocol*); #endif @@ -3970,7 +3973,7 @@ public: virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info); #endif -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) virtual int do_apply_event(Relay_log_info const *rli); #endif @@ -4002,7 +4005,7 @@ static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER /***************************************************************************** Heartbeat Log Event class @@ -4038,6 +4041,9 @@ private: }; #endif +int append_query_string(CHARSET_INFO *csinfo, + String const *from, String *to); + /** @} (end of group Replication) */ diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index 9b46ad83b14..a80e8f4b1a2 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -1,6 +1,16 @@ -#include "mysql_priv.h" +#include "sql_priv.h" #ifndef MYSQL_CLIENT +#include "unireg.h" +#endif +#include "my_global.h" // REQUIRED by log_event.h > m_string.h > my_bitmap.h +#include "log_event.h" +#ifndef MYSQL_CLIENT +#include "sql_cache.h" // QUERY_CACHE_FLAGS_SIZE +#include "sql_base.h" // close_tables_for_reopen +#include "key.h" // key_copy +#include "lock.h" // mysql_unlock_tables +#include "sql_parse.h" // mysql_reset_thd_for_next_command #include "rpl_rli.h" #include "rpl_utility.h" #endif @@ -16,7 +26,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info { DBUG_ENTER("Old_rows_log_event::do_apply_event(st_relay_log_info*)"); int error= 0; - THD *thd= ev->thd; + THD *ev_thd= ev->thd; uchar const *row_start= ev->m_rows_buf; /* @@ -33,17 +43,17 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info */ DBUG_ASSERT(ev->get_flags(Old_rows_log_event::STMT_END_F)); - const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd); - thd->clear_error(); + const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(ev_thd); + ev_thd->clear_error(); DBUG_RETURN(0); } /* - 'thd' has been set by exec_relay_log_event(), just before calling + 'ev_thd' has been set by exec_relay_log_event(), just before calling do_apply_event(). We still check here to prevent future coding errors. */ - DBUG_ASSERT(rli->sql_thd == thd); + DBUG_ASSERT(rli->sql_thd == ev_thd); /* If there is no locks taken, this is the first binrow event seen @@ -51,10 +61,10 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info used in the transaction and proceed with execution of the actual event. */ - if (!thd->lock) + if (!ev_thd->lock) { /* - Lock_tables() reads the contents of thd->lex, so they must be + Lock_tables() reads the contents of ev_thd->lex, so they must be initialized. We also call the mysql_reset_thd_for_next_command(), since this @@ -62,8 +72,8 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info call might reset the value of current_stmt_binlog_format, so we need to do any changes to that value after this function. */ - lex_start(thd); - mysql_reset_thd_for_next_command(thd); + lex_start(ev_thd); + mysql_reset_thd_for_next_command(ev_thd); /* This is a row injection, so we flag the "statement" as @@ -71,12 +81,12 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info injections and when the BINLOG statement is used to do row injections. */ - thd->lex->set_stmt_row_injection(); + ev_thd->lex->set_stmt_row_injection(); - if (open_and_lock_tables(thd, rli->tables_to_lock, FALSE, 0)) + if (open_and_lock_tables(ev_thd, rli->tables_to_lock, FALSE, 0)) { - uint actual_error= thd->stmt_da->sql_errno(); - if (thd->is_slave_error || thd->is_fatal_error) + uint actual_error= ev_thd->stmt_da->sql_errno(); + if (ev_thd->is_slave_error || ev_thd->is_fatal_error) { /* Error reporting borrowed from Query_log_event with many excessive @@ -84,9 +94,9 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info */ rli->report(ERROR_LEVEL, actual_error, "Error '%s' on opening tables", - (actual_error ? thd->stmt_da->message() : + (actual_error ? ev_thd->stmt_da->message() : "unexpected success or fatal error")); - thd->is_slave_error= 1; + ev_thd->is_slave_error= 1; } const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd); DBUG_RETURN(actual_error); @@ -108,8 +118,8 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli), ptr->table, &conv_table)) { - thd->is_slave_error= 1; - const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd); + ev_thd->is_slave_error= 1; + const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(ev_thd); DBUG_RETURN(Old_rows_log_event::ERR_BAD_TABLE_DEF); } DBUG_PRINT("debug", ("Table: %s.%s is compatible with master" @@ -161,23 +171,23 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info TIMESTAMP column to a table with one. So we call set_time(), like in SBR. Presently it changes nothing. */ - thd->set_time((time_t)ev->when); + ev_thd->set_time((time_t)ev->when); /* There are a few flags that are replicated with each row event. Make sure to set/clear them before executing the main body of the event. */ if (ev->get_flags(Old_rows_log_event::NO_FOREIGN_KEY_CHECKS_F)) - thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS; + ev_thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS; else - thd->variables.option_bits&= ~OPTION_NO_FOREIGN_KEY_CHECKS; + ev_thd->variables.option_bits&= ~OPTION_NO_FOREIGN_KEY_CHECKS; if (ev->get_flags(Old_rows_log_event::RELAXED_UNIQUE_CHECKS_F)) - thd->variables.option_bits|= OPTION_RELAXED_UNIQUE_CHECKS; + ev_thd->variables.option_bits|= OPTION_RELAXED_UNIQUE_CHECKS; else - thd->variables.option_bits&= ~OPTION_RELAXED_UNIQUE_CHECKS; + ev_thd->variables.option_bits&= ~OPTION_RELAXED_UNIQUE_CHECKS; /* A small test to verify that objects have consistent types */ - DBUG_ASSERT(sizeof(thd->variables.option_bits) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS)); + DBUG_ASSERT(sizeof(ev_thd->variables.option_bits) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS)); /* Now we are in a statement and will stay in a statement until we @@ -194,7 +204,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info while (error == 0 && row_start < ev->m_rows_end) { uchar const *row_end= NULL; - if ((error= do_prepare_row(thd, rli, table, row_start, &row_end))) + if ((error= do_prepare_row(ev_thd, rli, table, row_start, &row_end))) break; // We should perform the after-row operation even in // the case of error @@ -204,7 +214,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info /* in_use can have been set to NULL in close_tables_for_reopen */ THD* old_thd= table->in_use; if (!table->in_use) - table->in_use= thd; + table->in_use= ev_thd; error= do_exec_row(table); table->in_use = old_thd; switch (error) @@ -218,10 +228,10 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info break; default: - rli->report(ERROR_LEVEL, thd->stmt_da->sql_errno(), + rli->report(ERROR_LEVEL, ev_thd->stmt_da->sql_errno(), "Error in %s event: row application failed. %s", ev->get_type_str(), - thd->is_error() ? thd->stmt_da->message() : ""); + ev_thd->is_error() ? ev_thd->stmt_da->message() : ""); thd->is_slave_error= 1; break; } @@ -234,18 +244,18 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info if (!ev->use_trans_cache()) { DBUG_PRINT("info", ("Marked that we need to keep log")); - thd->variables.option_bits|= OPTION_KEEP_LOG; + ev_thd->variables.option_bits|= OPTION_KEEP_LOG; } } if (error) { /* error has occured during the transaction */ - rli->report(ERROR_LEVEL, thd->stmt_da->sql_errno(), + rli->report(ERROR_LEVEL, ev_thd->stmt_da->sql_errno(), "Error in %s event: error during transaction execution " "on table %s.%s. %s", ev->get_type_str(), table->s->db.str, table->s->table_name.str, - thd->is_error() ? thd->stmt_da->message() : ""); + ev_thd->is_error() ? ev_thd->stmt_da->message() : ""); /* If one day we honour --skip-slave-errors in row-based replication, and @@ -258,9 +268,9 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info thread is certainly going to stop. rollback at the caller along with sbr. */ - thd->reset_current_stmt_binlog_format_row(); - const_cast<Relay_log_info*>(rli)->cleanup_context(thd, error); - thd->is_slave_error= 1; + ev_thd->reset_current_stmt_binlog_format_row(); + const_cast<Relay_log_info*>(rli)->cleanup_context(ev_thd, error); + ev_thd->is_slave_error= 1; DBUG_RETURN(error); } @@ -1455,8 +1465,6 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli) */ if (!thd->lock) { - bool need_reopen= 1; /* To execute the first lap of the loop below */ - /* lock_tables() reads the contents of thd->lex, so they must be initialized. Contrary to in @@ -1465,80 +1473,31 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli) */ lex_start(thd); - while ((error= lock_tables(thd, rli->tables_to_lock, - rli->tables_to_lock_count, 0, - &need_reopen))) + if ((error= lock_tables(thd, rli->tables_to_lock, + rli->tables_to_lock_count, 0))) { - if (!need_reopen) - { - if (thd->is_slave_error || thd->is_fatal_error) - { - /* - Error reporting borrowed from Query_log_event with many excessive - simplifications (we don't honour --slave-skip-errors) - */ - uint actual_error= thd->net.last_errno; - rli->report(ERROR_LEVEL, actual_error, - "Error '%s' in %s event: when locking tables", - (actual_error ? thd->net.last_error : - "unexpected success or fatal error"), - get_type_str()); - thd->is_fatal_error= 1; - } - else - { - rli->report(ERROR_LEVEL, error, - "Error in %s event: when locking tables", - get_type_str()); - } - const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd); - DBUG_RETURN(error); - } - - /* - So we need to reopen the tables. - - We need to flush the pending RBR event, since it keeps a - pointer to an open table. - - ALTERNATIVE SOLUTION (not implemented): Extract a pointer to - the pending RBR event and reset the table pointer after the - tables has been reopened. - - NOTE: For this new scheme there should be no pending event: - need to add code to assert that is the case. - */ - error= thd->binlog_flush_pending_rows_event(FALSE); - if (error) + if (thd->is_slave_error || thd->is_fatal_error) { - rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, - ER(ER_SLAVE_FATAL_ERROR), - "call to binlog_flush_pending_rows_event() failed"); - thd->is_slave_error= 1; - DBUG_RETURN(error); + /* + Error reporting borrowed from Query_log_event with many excessive + simplifications (we don't honour --slave-skip-errors) + */ + uint actual_error= thd->net.last_errno; + rli->report(ERROR_LEVEL, actual_error, + "Error '%s' in %s event: when locking tables", + (actual_error ? thd->net.last_error : + "unexpected success or fatal error"), + get_type_str()); + thd->is_fatal_error= 1; } - TABLE_LIST *tables= rli->tables_to_lock; - close_tables_for_reopen(thd, &tables, NULL); - - uint tables_count= rli->tables_to_lock_count; - if ((error= open_tables(thd, &tables, &tables_count, 0))) + else { - if (thd->is_slave_error || thd->is_fatal_error) - { - /* - Error reporting borrowed from Query_log_event with many excessive - simplifications (we don't honour --slave-skip-errors) - */ - uint actual_error= thd->net.last_errno; - rli->report(ERROR_LEVEL, actual_error, - "Error '%s' on reopening tables", - (actual_error ? thd->net.last_error : - "unexpected success or fatal error")); - thd->is_slave_error= 1; - } - const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd); - DBUG_RETURN(error); + rli->report(ERROR_LEVEL, error, + "Error in %s event: when locking tables", + get_type_str()); } + const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd); + DBUG_RETURN(error); } /* diff --git a/sql/mdl.cc b/sql/mdl.cc index f9a4e10aade..ddf518fbb1c 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -19,6 +19,54 @@ #include <hash.h> #include <mysqld_error.h> +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key key_MDL_map_mutex; +static PSI_mutex_key key_MDL_context_signal_mutex; + +static PSI_mutex_info all_mdl_mutexes[]= +{ + { &key_MDL_map_mutex, "MDL_map::mutex", PSI_FLAG_GLOBAL}, + { &key_MDL_context_signal_mutex, "MDL_context::signal", 0} +}; + +static PSI_rwlock_key key_MDL_lock_rwlock; +static PSI_rwlock_key key_MDL_context_waiting_for_rwlock; + +static PSI_rwlock_info all_mdl_rwlocks[]= +{ + { &key_MDL_lock_rwlock, "MDL_lock::rwlock", 0}, + { &key_MDL_context_waiting_for_rwlock, "MDL_context::waiting_for_lock", 0} +}; + +static PSI_cond_key key_MDL_context_signal_cond; + +static PSI_cond_info all_mdl_conds[]= +{ + { &key_MDL_context_signal_cond, "MDL_context::signal", 0} +}; + +/** + Initialise all the performance schema instrumentation points + used by the MDL subsystem. +*/ +static void init_mdl_psi_keys(void) +{ + const char *category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_mdl_mutexes); + PSI_server->register_mutex(category, all_mdl_mutexes, count); + + count= array_elements(all_mdl_rwlocks); + PSI_server->register_rwlock(category, all_mdl_rwlocks, count); + + count= array_elements(all_mdl_conds); + PSI_server->register_cond(category, all_mdl_conds, count); +} +#endif /* HAVE_PSI_INTERFACE */ void notify_shared_lock(THD *thd, MDL_ticket *conflicting_ticket); @@ -178,7 +226,7 @@ public: If m_wrlock prefers readers (actually ignoring pending writers is enough) ctxA and ctxB will continue and no deadlock will occur. */ - rw_pr_lock_t m_rwlock; + mysql_prlock_t m_rwlock; bool is_empty() const { @@ -240,12 +288,12 @@ public: m_ref_release(0), m_is_destroyed(FALSE) { - rw_pr_init(&m_rwlock); + mysql_prlock_init(key_MDL_lock_rwlock, &m_rwlock); } virtual ~MDL_lock() { - rw_pr_destroy(&m_rwlock); + mysql_prlock_destroy(&m_rwlock); } inline static void destroy(MDL_lock *lock); public: @@ -368,6 +416,11 @@ void mdl_init() { DBUG_ASSERT(! mdl_initialized); mdl_initialized= TRUE; + +#ifdef HAVE_PSI_INTERFACE + init_mdl_psi_keys(); +#endif + mdl_locks.init(); } @@ -393,7 +446,7 @@ void mdl_destroy() void MDL_map::init() { - mysql_mutex_init(NULL /* pfs key */,&m_mutex, NULL); + mysql_mutex_init(key_MDL_map_mutex, &m_mutex, NULL); my_hash_init(&m_locks, &my_charset_bin, 16 /* FIXME */, 0, 0, mdl_locks_key, 0, 0); } @@ -507,7 +560,7 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock) lock->m_ref_usage++; mysql_mutex_unlock(&m_mutex); - rw_pr_wrlock(&lock->m_rwlock); + mysql_prlock_wrlock(&lock->m_rwlock); lock->m_ref_release++; if (unlikely(lock->m_is_destroyed)) { @@ -522,7 +575,7 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock) */ uint ref_usage= lock->m_ref_usage; uint ref_release= lock->m_ref_release; - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); if (ref_usage == ref_release) MDL_lock::destroy(lock); return TRUE; @@ -565,7 +618,7 @@ void MDL_map::remove(MDL_lock *lock) lock->m_is_destroyed= TRUE; ref_usage= lock->m_ref_usage; ref_release= lock->m_ref_release; - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); mysql_mutex_unlock(&m_mutex); if (ref_usage == ref_release) MDL_lock::destroy(lock); @@ -586,9 +639,9 @@ MDL_context::MDL_context() m_deadlock_weight(0), m_signal(NO_WAKE_UP) { - rw_pr_init(&m_waiting_for_lock); - mysql_mutex_init(NULL /* pfs key */, &m_signal_lock, NULL); - mysql_cond_init(NULL /* pfs key */, &m_signal_cond, NULL); + mysql_prlock_init(key_MDL_context_waiting_for_rwlock, &m_waiting_for_lock); + mysql_mutex_init(key_MDL_context_signal_mutex, &m_signal_lock, NULL); + mysql_cond_init(key_MDL_context_signal_mutex, &m_signal_cond, NULL); } @@ -608,7 +661,7 @@ void MDL_context::destroy() { DBUG_ASSERT(m_tickets.is_empty()); - rw_pr_destroy(&m_waiting_for_lock); + mysql_prlock_destroy(&m_waiting_for_lock); mysql_mutex_destroy(&m_signal_lock); mysql_cond_destroy(&m_signal_cond); } @@ -1098,7 +1151,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg, void MDL_lock::remove_ticket(Ticket_list MDL_lock::*list, MDL_ticket *ticket) { - rw_pr_wrlock(&m_rwlock); + mysql_prlock_wrlock(&m_rwlock); (this->*list).remove_ticket(ticket); if (is_empty()) mdl_locks.remove(this); @@ -1109,7 +1162,7 @@ void MDL_lock::remove_ticket(Ticket_list MDL_lock::*list, MDL_ticket *ticket) which now might be able to do it. Wake them up! */ wake_up_waiters(); - rw_pr_unlock(&m_rwlock); + mysql_prlock_unlock(&m_rwlock); } } @@ -1129,9 +1182,9 @@ bool MDL_lock::has_pending_conflicting_lock(enum_mdl_type type) mysql_mutex_assert_not_owner(&LOCK_open); - rw_pr_rdlock(&m_rwlock); + mysql_prlock_rdlock(&m_rwlock); result= (m_waiting.bitmap() & incompatible_granted_types_bitmap()[type]); - rw_pr_unlock(&m_rwlock); + mysql_prlock_unlock(&m_rwlock); return result; } @@ -1325,7 +1378,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request) { ticket->m_lock= lock; lock->m_granted.add_ticket(ticket); - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); m_tickets.push_front(ticket); @@ -1335,7 +1388,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request) { /* We can't get here if we allocated a new lock. */ DBUG_ASSERT(! lock->is_empty()); - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); MDL_ticket::destroy(ticket); } @@ -1376,9 +1429,9 @@ MDL_context::clone_ticket(MDL_request *mdl_request) ticket->m_lock= mdl_request->ticket->m_lock; mdl_request->ticket= ticket; - rw_pr_wrlock(&ticket->m_lock->m_rwlock); + mysql_prlock_wrlock(&ticket->m_lock->m_rwlock); ticket->m_lock->m_granted.add_ticket(ticket); - rw_pr_unlock(&ticket->m_lock->m_rwlock); + mysql_prlock_unlock(&ticket->m_lock->m_rwlock); m_tickets.push_front(ticket); @@ -1484,7 +1537,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request, if (ticket->is_upgradable_or_exclusive()) lock->notify_shared_locks(this); - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); set_deadlock_weight(mdl_request->get_deadlock_weight()); will_wait_for(ticket); @@ -1519,7 +1572,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request, my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0)); return TRUE; } - rw_pr_wrlock(&lock->m_rwlock); + mysql_prlock_wrlock(&lock->m_rwlock); } lock->m_waiting.remove_ticket(ticket); @@ -1529,7 +1582,7 @@ bool MDL_context::acquire_lock_impl(MDL_request *mdl_request, (*lock->cached_object_release_hook)(lock->cached_object); lock->cached_object= NULL; - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); m_tickets.push_front(ticket); @@ -1674,7 +1727,7 @@ MDL_context::upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket, is_new_ticket= ! has_lock(mdl_svp, mdl_xlock_request.ticket); /* Merge the acquired and the original lock. @todo: move to a method. */ - rw_pr_wrlock(&mdl_ticket->m_lock->m_rwlock); + mysql_prlock_wrlock(&mdl_ticket->m_lock->m_rwlock); if (is_new_ticket) mdl_ticket->m_lock->m_granted.remove_ticket(mdl_xlock_request.ticket); /* @@ -1686,7 +1739,7 @@ MDL_context::upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket, mdl_ticket->m_type= MDL_EXCLUSIVE; mdl_ticket->m_lock->m_granted.add_ticket(mdl_ticket); - rw_pr_unlock(&mdl_ticket->m_lock->m_rwlock); + mysql_prlock_unlock(&mdl_ticket->m_lock->m_rwlock); if (is_new_ticket) { @@ -1704,7 +1757,7 @@ bool MDL_lock::find_deadlock(MDL_ticket *waiting_ticket, MDL_ticket *ticket; bool result= FALSE; - rw_pr_rdlock(&m_rwlock); + mysql_prlock_rdlock(&m_rwlock); Ticket_iterator granted_it(m_granted); Ticket_iterator waiting_it(m_waiting); @@ -1756,7 +1809,7 @@ bool MDL_lock::find_deadlock(MDL_ticket *waiting_ticket, } end: - rw_pr_unlock(&m_rwlock); + mysql_prlock_unlock(&m_rwlock); return result; } @@ -1765,7 +1818,7 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx) { bool result= FALSE; - rw_pr_rdlock(&m_waiting_for_lock); + mysql_prlock_rdlock(&m_waiting_for_lock); if (m_waiting_for) { @@ -1794,14 +1847,14 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx) deadlock_ctx->victim= this; else if (deadlock_ctx->victim->m_deadlock_weight >= m_deadlock_weight) { - rw_pr_unlock(&deadlock_ctx->victim->m_waiting_for_lock); + mysql_prlock_unlock(&deadlock_ctx->victim->m_waiting_for_lock); deadlock_ctx->victim= this; } else - rw_pr_unlock(&m_waiting_for_lock); + mysql_prlock_unlock(&m_waiting_for_lock); } else - rw_pr_unlock(&m_waiting_for_lock); + mysql_prlock_unlock(&m_waiting_for_lock); return result; } @@ -1827,7 +1880,7 @@ bool MDL_context::find_deadlock() if (deadlock_ctx.victim != this) { deadlock_ctx.victim->awake(VICTIM_WAKE_UP); - rw_pr_unlock(&deadlock_ctx.victim->m_waiting_for_lock); + mysql_prlock_unlock(&deadlock_ctx.victim->m_waiting_for_lock); /* After adding new arc to waiting graph we found that it participates in some loop (i.e. there is a deadlock). We decided to destroy this @@ -1840,7 +1893,7 @@ bool MDL_context::find_deadlock() else { DBUG_ASSERT(&deadlock_ctx.victim->m_waiting_for_lock == &m_waiting_for_lock); - rw_pr_unlock(&deadlock_ctx.victim->m_waiting_for_lock); + mysql_prlock_unlock(&deadlock_ctx.victim->m_waiting_for_lock); return TRUE; } } @@ -1897,14 +1950,14 @@ MDL_context::wait_for_lock(MDL_request *mdl_request, ulong lock_wait_timeout) if (lock->can_grant_lock(mdl_request->type, this)) { - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); return FALSE; } MDL_ticket *pending_ticket; if (! (pending_ticket= MDL_ticket::create(this, mdl_request->type))) { - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); return TRUE; } @@ -1913,7 +1966,7 @@ MDL_context::wait_for_lock(MDL_request *mdl_request, ulong lock_wait_timeout) lock->m_waiting.add_ticket(pending_ticket); wait_reset(); - rw_pr_unlock(&lock->m_rwlock); + mysql_prlock_unlock(&lock->m_rwlock); set_deadlock_weight(MDL_DEADLOCK_WEIGHT_DML); will_wait_for(pending_ticket); @@ -2064,7 +2117,7 @@ void MDL_ticket::downgrade_exclusive_lock(enum_mdl_type type) if (m_type != MDL_EXCLUSIVE) return; - rw_pr_wrlock(&m_lock->m_rwlock); + mysql_prlock_wrlock(&m_lock->m_rwlock); /* To update state of MDL_lock object correctly we need to temporarily exclude ticket from the granted queue and then include it back. @@ -2073,7 +2126,7 @@ void MDL_ticket::downgrade_exclusive_lock(enum_mdl_type type) m_type= type; m_lock->m_granted.add_ticket(this); m_lock->wake_up_waiters(); - rw_pr_unlock(&m_lock->m_rwlock); + mysql_prlock_unlock(&m_lock->m_rwlock); } diff --git a/sql/mdl.h b/sql/mdl.h index 42461f6ac2f..124151798ae 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -628,7 +628,7 @@ private: important as deadlock detector won't work correctly otherwise. @sa Comment for MDL_lock::m_rwlock. */ - rw_pr_lock_t m_waiting_for_lock; + mysql_prlock_t m_waiting_for_lock; MDL_ticket *m_waiting_for; uint m_deadlock_weight; /** @@ -652,9 +652,9 @@ private: void will_wait_for(MDL_ticket *pending_ticket) { - rw_pr_wrlock(&m_waiting_for_lock); + mysql_prlock_wrlock(&m_waiting_for_lock); m_waiting_for= pending_ticket; - rw_pr_unlock(&m_waiting_for_lock); + mysql_prlock_unlock(&m_waiting_for_lock); } void set_deadlock_weight(uint weight) @@ -670,9 +670,9 @@ private: void stop_waiting() { - rw_pr_wrlock(&m_waiting_for_lock); + mysql_prlock_wrlock(&m_waiting_for_lock); m_waiting_for= NULL; - rw_pr_unlock(&m_waiting_for_lock); + mysql_prlock_unlock(&m_waiting_for_lock); } void wait_reset() diff --git a/sql/mf_iocache.cc b/sql/mf_iocache.cc index 8c2d16c40b0..d20d93ff0b9 100644 --- a/sql/mf_iocache.cc +++ b/sql/mf_iocache.cc @@ -32,7 +32,8 @@ flush_io_cache(). */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_class.h" // THD #ifdef HAVE_REPLICATION extern "C" { diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc index 234a0a98782..68f9b582dd2 100644 --- a/sql/my_decimal.cc +++ b/sql/my_decimal.cc @@ -13,9 +13,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" #include <time.h> +#ifndef MYSQL_CLIENT +#include "sql_class.h" // THD +#endif #ifndef MYSQL_CLIENT /** diff --git a/sql/my_decimal.h b/sql/my_decimal.h index 21669e82c44..abf4b178422 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -28,10 +28,17 @@ #ifndef my_decimal_h #define my_decimal_h +#if defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY) +#include "sql_string.h" /* String */ +#endif + C_MODE_START #include <decimal.h> C_MODE_END +class String; +typedef struct st_mysql_time MYSQL_TIME; + #define DECIMAL_LONGLONG_DIGITS 22 #define DECIMAL_LONG_DIGITS 10 #define DECIMAL_LONG3_DIGITS 8 @@ -133,6 +140,12 @@ const char *dbug_decimal_as_string(char *buff, const my_decimal *val); #define dbug_decimal_as_string(A) NULL #endif +bool str_set_decimal(uint mask, const my_decimal *val, uint fixed_prec, + uint fixed_dec, char filler, String *str, + CHARSET_INFO *cs); + +extern my_decimal decimal_zero; + #ifndef MYSQL_CLIENT int decimal_operation_results(int result); #else @@ -289,7 +302,14 @@ int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to) } +inline bool str_set_decimal(const my_decimal *val, String *str, + CHARSET_INFO *cs) +{ + return str_set_decimal(E_DEC_FATAL_ERROR, val, 0, 0, 0, str, cs); +} + #ifndef MYSQL_CLIENT +class String; int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, char filler, String *str); #endif diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h deleted file mode 100644 index 4e672f1d6c7..00000000000 --- a/sql/mysql_priv.h +++ /dev/null @@ -1,2766 +0,0 @@ -/* Copyright 2000-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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/** - @file - - @details - Mostly this file is used in the server. But a little part of it is used in - mysqlbinlog too (definition of SELECT_DISTINCT and others). - The consequence is that 90% of the file is wrapped in \#ifndef MYSQL_CLIENT, - except the part which must be in the server and in the client. -*/ - -#ifndef MYSQL_PRIV_H -#define MYSQL_PRIV_H - -#ifndef MYSQL_CLIENT - -/* - the following #define adds server-only members to enum_mysql_show_type, - that is defined in mysql/plugin.h - it has to be before mysql/plugin.h is included. -*/ -#define SHOW_always_last SHOW_KEY_CACHE_LONG, \ - SHOW_KEY_CACHE_LONGLONG, SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \ - SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \ - SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS, SHOW_LEX_STRING - -#include <my_global.h> -#include <mysql_version.h> -#include <mysql_embed.h> -#include <my_sys.h> -#include <my_time.h> -#include <m_string.h> -#include <hash.h> -#include <signal.h> -#include <thr_lock.h> -#include <my_base.h> /* Needed by field.h */ -#include <queues.h> -#include "sql_bitmap.h" -#include "sql_array.h" -#include "sql_plugin.h" -#include "scheduler.h" -#include <my_atomic.h> -#include <mysql/psi/mysql_file.h> -#ifndef __WIN__ -#include <netdb.h> -#endif - -class Parser_state; - -/** - Query type constants. - - QT_ORDINARY -- ordinary SQL query. - QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without - character set introducers). -*/ -enum enum_query_type -{ - QT_ORDINARY, - QT_IS -}; - -/* TODO convert all these three maps to Bitmap classes */ -typedef ulonglong table_map; /* Used for table bits in join */ -#if MAX_INDEXES <= 64 -typedef Bitmap<64> key_map; /* Used for finding keys */ -#else -typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */ -#endif -typedef ulong nesting_map; /* Used for flags of nesting constructs */ -/* - Used to identify NESTED_JOIN structures within a join (applicable only to - structures that have not been simplified away and embed more the one - element) -*/ -typedef ulonglong nested_join_map; - -/* query_id */ -typedef int64 query_id_t; -extern query_id_t global_query_id; -extern int32 thread_running; -extern my_atomic_rwlock_t global_query_id_lock; -extern my_atomic_rwlock_t thread_running_lock; - -/* increment query_id and return it. */ -inline query_id_t next_query_id() -{ - query_id_t id; - my_atomic_rwlock_wrlock(&global_query_id_lock); - id= my_atomic_add64(&global_query_id, 1); - my_atomic_rwlock_wrunlock(&global_query_id_lock); - return (id+1); -} - -inline query_id_t get_query_id() -{ - query_id_t id; - my_atomic_rwlock_wrlock(&global_query_id_lock); - id= my_atomic_load64(&global_query_id); - my_atomic_rwlock_wrunlock(&global_query_id_lock); - return id; -} - -inline int32 -inc_thread_running() -{ - int32 num_thread_running; - my_atomic_rwlock_wrlock(&thread_running_lock); - num_thread_running= my_atomic_add32(&thread_running, 1); - my_atomic_rwlock_wrunlock(&thread_running_lock); - return (num_thread_running+1); -} - -inline int32 -dec_thread_running() -{ - int32 num_thread_running; - my_atomic_rwlock_wrlock(&thread_running_lock); - num_thread_running= my_atomic_add32(&thread_running, -1); - my_atomic_rwlock_wrunlock(&thread_running_lock); - return (num_thread_running-1); -} - -inline int32 -get_thread_running() -{ - int32 num_thread_running; - my_atomic_rwlock_wrlock(&thread_running_lock); - num_thread_running= my_atomic_load32(&thread_running); - my_atomic_rwlock_wrunlock(&thread_running_lock); - return num_thread_running; -} - -/* useful constants */ -extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty; -extern MYSQL_PLUGIN_IMPORT key_map key_map_full; /* Should be threaded as const */ -extern MYSQL_PLUGIN_IMPORT const char *primary_key_name; - -#include "mysql_com.h" -#include <violite.h> -#include "unireg.h" - -void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size); -void *sql_alloc(size_t); -void *sql_calloc(size_t); -char *sql_strdup(const char *str); -char *sql_strmake(const char *str, size_t len); -void *sql_memdup(const void * ptr, size_t size); -void sql_element_free(void *ptr); -char *sql_strmake_with_convert(const char *str, size_t arg_length, - CHARSET_INFO *from_cs, - size_t max_res_length, - CHARSET_INFO *to_cs, size_t *result_length); -uint kill_one_thread(THD *thd, ulong id, bool only_kill_query); -void sql_kill(THD *thd, ulong id, bool only_kill_query); -bool net_request_file(NET* net, const char* fname); -char* query_table_status(THD *thd,const char *db,const char *table_name); - -#define x_free(A) { my_free((uchar*) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); } -#define safeFree(x) { if(x) { my_free((uchar*) x,MYF(0)); x = NULL; } } -#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1)) -#define all_bits_set(A,B) ((A) & (B) != (B)) - -/* - Generates a warning that a feature is deprecated. After a specified - version asserts that the feature is removed. - - Using it as - - WARN_DEPRECATED(thd, 6,2, "BAD", "'GOOD'"); - - Will result in a warning - - "The syntax 'BAD' is deprecated and will be removed in MySQL 6.2. Please - use 'GOOD' instead" - - Note that in macro arguments BAD is not quoted, while 'GOOD' is. - Note that the version is TWO numbers, separated with a comma - (two macro arguments, that is) -*/ -#define WARN_DEPRECATED(Thd,VerHi,VerLo,Old,New) \ - do { \ - compile_time_assert(MYSQL_VERSION_ID < VerHi * 10000 + VerLo * 100); \ - if (((THD *) Thd) != NULL) \ - push_warning_printf(((THD *) Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \ - ER_WARN_DEPRECATED_SYNTAX, \ - ER(ER_WARN_DEPRECATED_SYNTAX), \ - (Old), (New)); \ - else \ - sql_print_warning("The syntax '%s' is deprecated and will be removed " \ - "in a future release. Please use %s instead.", \ - (Old), (New)); \ - } while(0) - -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info; -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ; -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *national_charset_info; -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *table_alias_charset; - -/** - Character set of the buildin error messages loaded from errmsg.sys. -*/ -extern CHARSET_INFO *error_message_charset_info; - -enum Derivation -{ - DERIVATION_IGNORABLE= 6, - DERIVATION_NUMERIC= 5, - DERIVATION_COERCIBLE= 4, - DERIVATION_SYSCONST= 3, - DERIVATION_IMPLICIT= 2, - DERIVATION_NONE= 1, - DERIVATION_EXPLICIT= 0 -}; - -#define my_charset_numeric my_charset_latin1 -#define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII - -typedef struct my_locale_errmsgs -{ - const char *language; - const char **errmsgs; -} MY_LOCALE_ERRMSGS; - -extern char err_shared_dir[]; - -/** @note Keep this a POD-type because we use offsetof() on it */ -typedef struct my_locale_st -{ - uint number; - const char *name; - const char *description; - const bool is_ascii; - TYPELIB *month_names; - TYPELIB *ab_month_names; - TYPELIB *day_names; - TYPELIB *ab_day_names; - uint max_month_name_length; - uint max_day_name_length; - uint decimal_point; - uint thousand_sep; - const char *grouping; - MY_LOCALE_ERRMSGS *errmsgs; -#ifdef __cplusplus - my_locale_st(uint number_par, - const char *name_par, const char *descr_par, bool is_ascii_par, - TYPELIB *month_names_par, TYPELIB *ab_month_names_par, - TYPELIB *day_names_par, TYPELIB *ab_day_names_par, - uint max_month_name_length_par, uint max_day_name_length_par, - uint decimal_point_par, uint thousand_sep_par, - const char *grouping_par, MY_LOCALE_ERRMSGS *errmsgs_par) : - number(number_par), - name(name_par), description(descr_par), is_ascii(is_ascii_par), - month_names(month_names_par), ab_month_names(ab_month_names_par), - day_names(day_names_par), ab_day_names(ab_day_names_par), - max_month_name_length(max_month_name_length_par), - max_day_name_length(max_day_name_length_par), - decimal_point(decimal_point_par), - thousand_sep(thousand_sep_par), - grouping(grouping_par), - errmsgs(errmsgs_par) - {} -#endif -} MY_LOCALE; - -extern MY_LOCALE my_locale_en_US; -extern MY_LOCALE *my_locales[]; -extern MY_LOCALE *my_default_lc_messages; -extern MY_LOCALE *my_default_lc_time_names; - -MY_LOCALE *my_locale_by_name(const char *name); -MY_LOCALE *my_locale_by_number(uint number); - -void cleanup_errmsgs(void); - -/*************************************************************************/ - -/** - Object_creation_ctx -- interface for creation context of database objects - (views, stored routines, events, triggers). Creation context -- is a set - of attributes, that should be fixed at the creation time and then be used - each time the object is parsed or executed. -*/ - -class Object_creation_ctx -{ -public: - Object_creation_ctx *set_n_backup(THD *thd); - - void restore_env(THD *thd, Object_creation_ctx *backup_ctx); - -protected: - Object_creation_ctx() {} - virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0; - - virtual void change_env(THD *thd) const = 0; - -public: - virtual ~Object_creation_ctx() - { } -}; - -/*************************************************************************/ - -/** - Default_object_creation_ctx -- default implementation of - Object_creation_ctx. -*/ - -class Default_object_creation_ctx : public Object_creation_ctx -{ -public: - CHARSET_INFO *get_client_cs() - { - return m_client_cs; - } - - CHARSET_INFO *get_connection_cl() - { - return m_connection_cl; - } - -protected: - Default_object_creation_ctx(THD *thd); - - Default_object_creation_ctx(CHARSET_INFO *client_cs, - CHARSET_INFO *connection_cl); - -protected: - virtual Object_creation_ctx *create_backup_ctx(THD *thd) const; - - virtual void change_env(THD *thd) const; - -protected: - /** - client_cs stores the value of character_set_client session variable. - The only character set attribute is used. - - Client character set is included into query context, because we save - query in the original character set, which is client character set. So, - in order to parse the query properly we have to switch client character - set on parsing. - */ - CHARSET_INFO *m_client_cs; - - /** - connection_cl stores the value of collation_connection session - variable. Both character set and collation attributes are used. - - Connection collation is included into query context, becase it defines - the character set and collation of text literals in internal - representation of query (item-objects). - */ - CHARSET_INFO *m_connection_cl; -}; - -/*************************************************************************** - Configuration parameters -****************************************************************************/ - -#define ACL_CACHE_SIZE 256 -#define MAX_PASSWORD_LENGTH 32 -#define HOST_CACHE_SIZE 128 -#define MAX_ACCEPT_RETRY 10 // Test accept this many times -#define MAX_FIELDS_BEFORE_HASH 32 -#define USER_VARS_HASH_SIZE 16 -#define TABLE_OPEN_CACHE_MIN 400 -#define TABLE_OPEN_CACHE_DEFAULT 400 -#define TABLE_DEF_CACHE_DEFAULT 400 -/** - We must have room for at least 400 table definitions in the table - cache, since otherwise there is no chance prepared - statements that use these many tables can work. - Prepared statements use table definition cache ids (table_map_id) - as table version identifiers. If the table definition - cache size is less than the number of tables used in a statement, - the contents of the table definition cache is guaranteed to rotate - between a prepare and execute. This leads to stable validation - errors. In future we shall use more stable version identifiers, - for now the only solution is to ensure that the table definition - cache can contain at least all tables of a given statement. -*/ -#define TABLE_DEF_CACHE_MIN 400 - -/* - Stack reservation. - Feel free to raise this by the smallest amount you can to get the - "execution_constants" test to pass. -*/ -#define STACK_MIN_SIZE 16000 // Abort if less stack during eval. - -#define STACK_MIN_SIZE_FOR_OPEN 1024*80 -#define STACK_BUFF_ALLOC 352 ///< For stack overrun checks -#ifndef MYSQLD_NET_RETRY_COUNT -#define MYSQLD_NET_RETRY_COUNT 10 ///< Abort read after this many int. -#endif -#define TEMP_POOL_SIZE 128 - -#define QUERY_ALLOC_BLOCK_SIZE 8192 -#define QUERY_ALLOC_PREALLOC_SIZE 8192 -#define TRANS_ALLOC_BLOCK_SIZE 4096 -#define TRANS_ALLOC_PREALLOC_SIZE 4096 -#define RANGE_ALLOC_BLOCK_SIZE 4096 -#define ACL_ALLOC_BLOCK_SIZE 1024 -#define UDF_ALLOC_BLOCK_SIZE 1024 -#define TABLE_ALLOC_BLOCK_SIZE 1024 -#define BDB_LOG_ALLOC_BLOCK_SIZE 1024 -#define WARN_ALLOC_BLOCK_SIZE 2048 -#define WARN_ALLOC_PREALLOC_SIZE 1024 -#define PROFILE_ALLOC_BLOCK_SIZE 2048 -#define PROFILE_ALLOC_PREALLOC_SIZE 1024 - -/* - The following parameters is to decide when to use an extra cache to - optimise seeks when reading a big table in sorted order -*/ -#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024) -#define MIN_ROWS_TO_USE_TABLE_CACHE 100 -#define MIN_ROWS_TO_USE_BULK_INSERT 100 - -/** - The following is used to decide if MySQL should use table scanning - instead of reading with keys. The number says how many evaluation of the - WHERE clause is comparable to reading one extra row from a table. -*/ -#define TIME_FOR_COMPARE 5 // 5 compares == one read - -/** - Number of comparisons of table rowids equivalent to reading one row from a - table. -*/ -#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2) - -/* - For sequential disk seeks the cost formula is: - DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip - - The cost of average seek - DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0. -*/ -#define DISK_SEEK_BASE_COST ((double)0.5) - -#define BLOCKS_IN_AVG_SEEK 128 - -#define DISK_SEEK_PROP_COST ((double)0.5/BLOCKS_IN_AVG_SEEK) - - -/** - Number of rows in a reference table when refereed through a not unique key. - This value is only used when we don't know anything about the key - distribution. -*/ -#define MATCHING_ROWS_IN_OTHER_TABLE 10 - -/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */ -#define KEY_DEFAULT_PACK_LENGTH 8 - -/** Characters shown for the command in 'show processlist'. */ -#define PROCESS_LIST_WIDTH 100 -/* Characters shown for the command in 'information_schema.processlist' */ -#define PROCESS_LIST_INFO_WIDTH 65535 - -#define PRECISION_FOR_DOUBLE 53 -#define PRECISION_FOR_FLOAT 24 - -/* -[digits].E+## */ -#define MAX_FLOAT_STR_LENGTH (FLT_DIG + 6) -/* -[digits].E+### */ -#define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7) - -/* - Default time to wait before aborting a new client connection - that does not respond to "initial server greeting" timely -*/ -#define CONNECT_TIMEOUT 10 - -/* The following can also be changed from the command line */ -#define DEFAULT_CONCURRENCY 10 -#define DELAYED_LIMIT 100 /**< pause after xxx inserts */ -#define DELAYED_QUEUE_SIZE 1000 -#define DELAYED_WAIT_TIMEOUT 5*60 /**< Wait for delayed insert */ -#define FLUSH_TIME 0 /**< Don't flush tables */ -#define MAX_CONNECT_ERRORS 10 ///< errors before disabling host - -#if defined(__WIN__) -#undef FLUSH_TIME -#define FLUSH_TIME 1800 /**< Flush every half hour */ -#endif /* __WIN__ */ - - /* Bits from testflag */ -#define TEST_PRINT_CACHED_TABLES 1 -#define TEST_NO_KEY_GROUP 2 -#define TEST_MIT_THREAD 4 -#define TEST_BLOCKING 8 -#define TEST_KEEP_TMP_TABLES 16 -#define TEST_READCHECK 64 /**< Force use of readcheck */ -#define TEST_NO_EXTRA 128 -#define TEST_CORE_ON_SIGNAL 256 /**< Give core if signal */ -#define TEST_NO_STACKTRACE 512 -#define TEST_SIGINT 1024 /**< Allow sigint on threads */ -#define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in - some places */ -#endif - -/* - This is included in the server and in the client. - Options for select set by the yacc parser (stored in lex->options). - - NOTE - log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD - options list are written into binlog. These options can NOT change their - values, or it will break replication between version. - - context is encoded as following: - SELECT - SELECT_LEX_NODE::options - THD - THD::options - intern - neither. used only as - func(..., select_node->options | thd->options | OPTION_XXX, ...) - - TODO: separate three contexts above, move them to separate bitfields. -*/ - -#define SELECT_DISTINCT (1ULL << 0) // SELECT, user -#define SELECT_STRAIGHT_JOIN (1ULL << 1) // SELECT, user -#define SELECT_DESCRIBE (1ULL << 2) // SELECT, user -#define SELECT_SMALL_RESULT (1ULL << 3) // SELECT, user -#define SELECT_BIG_RESULT (1ULL << 4) // SELECT, user -#define OPTION_FOUND_ROWS (1ULL << 5) // SELECT, user -#define OPTION_TO_QUERY_CACHE (1ULL << 6) // SELECT, user -#define SELECT_NO_JOIN_CACHE (1ULL << 7) // intern -/** always the opposite of OPTION_NOT_AUTOCOMMIT except when in fix_autocommit() */ -#define OPTION_AUTOCOMMIT (1ULL << 8) // THD, user -#define OPTION_BIG_SELECTS (1ULL << 9) // THD, user -#define OPTION_LOG_OFF (1ULL << 10) // THD, user -#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user, unused -#define TMP_TABLE_ALL_COLUMNS (1ULL << 12) // SELECT, intern -#define OPTION_WARNINGS (1ULL << 13) // THD, user -#define OPTION_AUTO_IS_NULL (1ULL << 14) // THD, user, binlog -#define OPTION_FOUND_COMMENT (1ULL << 15) // SELECT, intern, parser -#define OPTION_SAFE_UPDATES (1ULL << 16) // THD, user -#define OPTION_BUFFER_RESULT (1ULL << 17) // SELECT, user -#define OPTION_BIN_LOG (1ULL << 18) // THD, user -#define OPTION_NOT_AUTOCOMMIT (1ULL << 19) // THD, user -#define OPTION_BEGIN (1ULL << 20) // THD, intern -#define OPTION_TABLE_LOCK (1ULL << 21) // THD, intern -#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE) -#define OPTION_KEEP_LOG (1ULL << 23) // THD, user - -/* The following is used to detect a conflict with DISTINCT */ -#define SELECT_ALL (1ULL << 24) // SELECT, user, parser -/** The following can be set when importing tables in a 'wrong order' - to suppress foreign key checks */ -#define OPTION_NO_FOREIGN_KEY_CHECKS (1ULL << 26) // THD, user, binlog -/** The following speeds up inserts to InnoDB tables by suppressing unique - key checks in some cases */ -#define OPTION_RELAXED_UNIQUE_CHECKS (1ULL << 27) // THD, user, binlog -#define SELECT_NO_UNLOCK (1ULL << 28) // SELECT, intern -#define OPTION_SCHEMA_TABLE (1ULL << 29) // SELECT, intern -/** Flag set if setup_tables already done */ -#define OPTION_SETUP_TABLES_DONE (1ULL << 30) // intern -/** If not set then the thread will ignore all warnings with level notes. */ -#define OPTION_SQL_NOTES (1ULL << 31) // THD, user -/** - Force the used temporary table to be a MyISAM table (because we will use - fulltext functions when reading from it. -*/ -#define TMP_TABLE_FORCE_MYISAM (1ULL << 32) -#define OPTION_PROFILING (1ULL << 33) - - -/** - Maximum length of time zone name that we support - (Time zone name is char(64) in db). mysqlbinlog needs it. -*/ -#define MAX_TIME_ZONE_NAME_LENGTH (NAME_LEN + 1) - -/* The rest of the file is included in the server only */ -#ifndef MYSQL_CLIENT - -/* Bits for different SQL modes modes (including ANSI mode) */ -#define MODE_REAL_AS_FLOAT 1 -#define MODE_PIPES_AS_CONCAT 2 -#define MODE_ANSI_QUOTES 4 -#define MODE_IGNORE_SPACE 8 -#define MODE_NOT_USED 16 -#define MODE_ONLY_FULL_GROUP_BY 32 -#define MODE_NO_UNSIGNED_SUBTRACTION 64 -#define MODE_NO_DIR_IN_CREATE 128 -#define MODE_POSTGRESQL 256 -#define MODE_ORACLE 512 -#define MODE_MSSQL 1024 -#define MODE_DB2 2048 -#define MODE_MAXDB 4096 -#define MODE_NO_KEY_OPTIONS 8192 -#define MODE_NO_TABLE_OPTIONS 16384 -#define MODE_NO_FIELD_OPTIONS 32768 -#define MODE_MYSQL323 65536L -#define MODE_MYSQL40 (MODE_MYSQL323*2) -#define MODE_ANSI (MODE_MYSQL40*2) -#define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2) -#define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2) -#define MODE_STRICT_TRANS_TABLES (MODE_NO_BACKSLASH_ESCAPES*2) -#define MODE_STRICT_ALL_TABLES (MODE_STRICT_TRANS_TABLES*2) -#define MODE_NO_ZERO_IN_DATE (MODE_STRICT_ALL_TABLES*2) -#define MODE_NO_ZERO_DATE (MODE_NO_ZERO_IN_DATE*2) -#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2) -#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2) -#define MODE_TRADITIONAL (MODE_ERROR_FOR_DIVISION_BY_ZERO*2) -#define MODE_NO_AUTO_CREATE_USER (MODE_TRADITIONAL*2) -#define MODE_HIGH_NOT_PRECEDENCE (MODE_NO_AUTO_CREATE_USER*2) -#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2) -#define MODE_PAD_CHAR_TO_FULL_LENGTH (ULL(1) << 31) - -/* @@optimizer_switch flags. These must be in sync with optimizer_switch_typelib */ -#define OPTIMIZER_SWITCH_INDEX_MERGE (1ULL << 0) -#define OPTIMIZER_SWITCH_INDEX_MERGE_UNION (1ULL << 1) -#define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION (1ULL << 2) -#define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT (1ULL << 3) -#define OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN (1ULL << 4) -#define OPTIMIZER_SWITCH_LAST (1ULL << 5) - -/* The following must be kept in sync with optimizer_switch_str in mysqld.cc */ -#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \ - OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \ - OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \ - OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \ - OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) - - -/* - Replication uses 8 bytes to store SQL_MODE in the binary log. The day you - use strictly more than 64 bits by adding one more define above, you should - contact the replication team because the replication code should then be - updated (to store more bytes on disk). - - NOTE: When adding new SQL_MODE types, make sure to also add them to - the scripts used for creating the MySQL system tables - in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql - -*/ - -#define RAID_BLOCK_SIZE 1024 - -#define MY_CHARSET_BIN_MB_MAXLEN 1 - -// uncachable cause -#define UNCACHEABLE_DEPENDENT 1 -#define UNCACHEABLE_RAND 2 -#define UNCACHEABLE_SIDEEFFECT 4 -/// forcing to save JOIN for explain -#define UNCACHEABLE_EXPLAIN 8 -/** Don't evaluate subqueries in prepare even if they're not correlated */ -#define UNCACHEABLE_PREPARE 16 -/* For uncorrelated SELECT in an UNION with some correlated SELECTs */ -#define UNCACHEABLE_UNITED 32 -#define UNCACHEABLE_CHECKOPTION 64 - -/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */ -#define UNDEF_POS (-1) -#ifdef EXTRA_DEBUG -/** - Sync points allow us to force the server to reach a certain line of code - and block there until the client tells the server it is ok to go on. - The client tells the server to block with SELECT GET_LOCK() - and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult - concurrency problems -*/ -#define DBUG_SYNC_POINT(lock_name,lock_timeout) \ - debug_sync_point(lock_name,lock_timeout) -void debug_sync_point(const char* lock_name, uint lock_timeout); -#else -#define DBUG_SYNC_POINT(lock_name,lock_timeout) -#endif /* EXTRA_DEBUG */ - -/* BINLOG_DUMP options */ - -#define BINLOG_DUMP_NON_BLOCK 1 - -/* sql_show.cc:show_log_files() */ -#define SHOW_LOG_STATUS_FREE "FREE" -#define SHOW_LOG_STATUS_INUSE "IN USE" - -struct TABLE_LIST; -class String; -void view_store_options(THD *thd, TABLE_LIST *table, String *buff); - -/* Options to add_table_to_list() */ -#define TL_OPTION_UPDATING 1 -#define TL_OPTION_FORCE_INDEX 2 -#define TL_OPTION_IGNORE_LEAVES 4 -#define TL_OPTION_ALIAS 8 - -/* Some portable defines */ - -#define portable_sizeof_char_ptr 8 - -#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */ -#define tmp_file_prefix_length 4 - -/* Flags for calc_week() function. */ -#define WEEK_MONDAY_FIRST 1 -#define WEEK_YEAR 2 -#define WEEK_FIRST_WEEKDAY 4 - -#define STRING_BUFFER_USUAL_SIZE 80 - -/* - Some defines for exit codes for ::is_equal class functions. -*/ -#define IS_EQUAL_NO 0 -#define IS_EQUAL_YES 1 -#define IS_EQUAL_PACK_LENGTH 2 - -enum enum_parsing_place -{ - NO_MATTER, - IN_HAVING, - SELECT_LIST, - IN_WHERE, - IN_ON -}; - - -#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__) -class THD; - -enum enum_check_fields -{ - CHECK_FIELD_IGNORE, - CHECK_FIELD_WARN, - CHECK_FIELD_ERROR_FOR_NULL -}; - - -/** Struct to handle simple linked lists. */ -typedef struct st_sql_list { - uint elements; - uchar *first; - uchar **next; - - st_sql_list() {} /* Remove gcc warning */ - inline void empty() - { - elements=0; - first=0; - next= &first; - } - inline void link_in_list(uchar *element,uchar **next_ptr) - { - elements++; - (*next)=element; - next= next_ptr; - *next=0; - } - inline void save_and_clear(struct st_sql_list *save) - { - *save= *this; - empty(); - } - inline void push_front(struct st_sql_list *save) - { - *save->next= first; /* link current list last */ - first= save->first; - elements+= save->elements; - } - inline void push_back(struct st_sql_list *save) - { - if (save->first) - { - *next= save->first; - next= save->next; - elements+= save->elements; - } - } -} SQL_LIST; - -#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32) -extern "C" THD *_current_thd_noinline(); -#define _current_thd() _current_thd_noinline() -#else -extern pthread_key(THD*, THR_THD); -inline THD *_current_thd(void) -{ - return my_pthread_getspecific_ptr(THD*,THR_THD); -} -#endif -#define current_thd _current_thd() - - -/** - The meat of thd_proc_info(THD*, char*), a macro that packs the last - three calling-info parameters. -*/ -extern "C" -const char *set_thd_proc_info(THD *thd, const char *info, - const char *calling_func, - const char *calling_file, - const unsigned int calling_line); - -/** - Enumerate possible types of a table from re-execution - standpoint. - TABLE_LIST class has a member of this type. - At prepared statement prepare, this member is assigned a value - as of the current state of the database. Before (re-)execution - of a prepared statement, we check that the value recorded at - prepare matches the type of the object we obtained from the - table definition cache. - - @sa check_and_update_table_version() - @sa Execute_observer - @sa Prepared_statement::reprepare() -*/ - -enum enum_table_ref_type -{ - /** Initial value set by the parser */ - TABLE_REF_NULL= 0, - TABLE_REF_VIEW, - TABLE_REF_BASE_TABLE, - TABLE_REF_I_S_TABLE, - TABLE_REF_TMP_TABLE -}; - -/* - External variables -*/ -extern ulong server_id, concurrency; - - -typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key, - uint key_length, - ulonglong *engine_data); -#include "sql_string.h" -#include "sql_list.h" -#include "sql_map.h" -#include "my_decimal.h" -#include "handler.h" -#include "parse_file.h" -#include "table.h" -#include "sql_error.h" -#include "field.h" /* Field definitions */ -#include "protocol.h" -#include "sql_udf.h" -#include "sql_profile.h" -#include "sql_partition.h" - -class user_var_entry; -class Security_context; -enum enum_var_type -{ - OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL -}; -class sys_var; -#ifdef MYSQL_SERVER -class Comp_creator; -typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); -#endif -#include "item.h" -extern my_decimal decimal_zero; - -/* my_decimal.cc */ -bool str_set_decimal(uint mask, const my_decimal *val, uint fixed_prec, - uint fixed_dec, char filler, String *str, - CHARSET_INFO *cs); -inline bool str_set_decimal(const my_decimal *val, String *str, - CHARSET_INFO *cs) -{ - return str_set_decimal(E_DEC_FATAL_ERROR, val, 0, 0, 0, str, cs); -} - -/* sql_parse.cc */ -void free_items(Item *item); -void cleanup_items(Item *item); -class THD; -void close_thread_tables(THD *thd); - -#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_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc); -#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; } -#endif /*NO_EMBEDDED_ACCESS_CHECKS*/ - -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); -int append_query_string(CHARSET_INFO *csinfo, - String const *from, String *to); - -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); -bool check_host_name(LEX_STRING *str); - -CHARSET_INFO *merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl); - -bool parse_sql(THD *thd, - Parser_state *parser_state, - Object_creation_ctx *creation_ctx); - -Item *negate_expression(THD *thd, Item *expr); - -/* log.cc */ -int vprint_msg_to_log(enum loglevel level, const char *format, va_list args); -void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2); -void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2); -void sql_print_information(const char *format, ...) - ATTRIBUTE_FORMAT(printf, 1, 2); -typedef void (*sql_print_message_func)(const char *format, ...) - ATTRIBUTE_FORMAT(printf, 1, 2); -extern sql_print_message_func sql_print_message_handlers[]; - -int error_log_print(enum loglevel level, const char *format, - va_list args); - -bool slow_log_print(THD *thd, const char *query, uint query_length, - ulonglong current_utime); - -bool general_log_print(THD *thd, enum enum_server_command command, - const char *format,...); - -bool general_log_write(THD *thd, enum enum_server_command command, - const char *query, uint query_length); - -#include "sql_class.h" -#include "sql_acl.h" -#include "tztime.h" -#ifdef MYSQL_SERVER -#include "sql_servers.h" -#include "records.h" -#include "opt_range.h" - -#ifdef HAVE_QUERY_CACHE -struct Query_cache_query_flags -{ - unsigned int client_long_flag:1; - unsigned int client_protocol_41:1; - unsigned int protocol_type:2; - unsigned int more_results_exists:1; - unsigned int in_trans:1; - unsigned int autocommit:1; - unsigned int pkt_nr; - uint character_set_client_num; - uint character_set_results_num; - uint collation_connection_num; - ha_rows limit; - Time_zone *time_zone; - ulong sql_mode; - ulong max_sort_length; - ulong group_concat_max_len; - ulong default_week_format; - ulong div_precision_increment; - MY_LOCALE *lc_time_names; -}; -#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags) -#include "sql_cache.h" -#define query_cache_abort(A) query_cache.abort(A) -#define query_cache_end_of_result(A) query_cache.end_of_result(A) -#define query_cache_store_query(A, B) query_cache.store_query(A, B) -#define query_cache_destroy() query_cache.destroy() -#define query_cache_result_size_limit(A) query_cache.result_size_limit(A) -#define query_cache_init() query_cache.init() -#define query_cache_resize(A) query_cache.resize(A) -#define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A) -#define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C) -#define query_cache_invalidate1(A) query_cache.invalidate(A) -#define query_cache_send_result_to_client(A, B, C) \ - query_cache.send_result_to_client(A, B, C) -#define query_cache_invalidate_by_MyISAM_filename_ref \ - &query_cache_invalidate_by_MyISAM_filename -/* note the "maybe": it's a read without mutex */ -#define query_cache_maybe_disabled(T) \ - (T->variables.query_cache_type == 0 || query_cache.query_cache_size == 0) -#define query_cache_is_cacheable_query(L) \ - (((L)->sql_command == SQLCOM_SELECT) && (L)->safe_to_cache_query) -#else -#define QUERY_CACHE_FLAGS_SIZE 0 -#define query_cache_store_query(A, B) -#define query_cache_destroy() -#define query_cache_result_size_limit(A) -#define query_cache_init() -#define query_cache_resize(A) -#define query_cache_set_min_res_unit(A) -#define query_cache_invalidate3(A, B, C) -#define query_cache_invalidate1(A) -#define query_cache_send_result_to_client(A, B, C) 0 -#define query_cache_invalidate_by_MyISAM_filename_ref NULL - -#define query_cache_abort(A) -#define query_cache_end_of_result(A) -#define query_cache_invalidate_by_MyISAM_filename_ref NULL -#define query_cache_maybe_disabled(T) 1 -#define query_cache_is_cacheable_query(L) 0 -#endif /*HAVE_QUERY_CACHE*/ - -int write_bin_log(THD *thd, bool clear_error, - char const *query, ulong query_length, - bool is_trans= FALSE); - -/* sql_connect.cc */ -int check_user(THD *thd, enum enum_server_command command, - const char *passwd, uint passwd_len, const char *db, - bool check_count); -pthread_handler_t handle_one_connection(void *arg); -void do_handle_one_connection(THD *thd_arg); -bool init_new_connection_handler_thread(); -void reset_mqh(LEX_USER *lu, bool get_them); -bool check_mqh(THD *thd, uint check_command); -void time_out_user_resource_limits(THD *thd, USER_CONN *uc); -void decrease_user_connections(USER_CONN *uc); -void thd_init_client_charset(THD *thd, uint cs_number); -bool setup_connection_thread_globals(THD *thd); - -int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); -bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); -bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); -bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db); -void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags); -void mysql_client_binlog_statement(THD *thd); -bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, - my_bool drop_temporary); -int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, - bool drop_temporary, bool drop_view, bool log_query); -bool quick_rm_table(handlerton *base,const char *db, - const char *table_name, uint flags); -bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent); -bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, - char *new_table_name, char *new_table_alias, - bool skip_error); - -bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, - bool force_switch); - -bool mysql_opt_change_db(THD *thd, - const LEX_STRING *new_db_name, - LEX_STRING *saved_db_name, - bool force_switch, - bool *cur_db_changed); - -void mysql_parse(THD *thd, const char *inBuf, uint length, - const char ** semicolon); - -bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length); -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_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 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); -void init_max_user_conn(void); -void init_update_queries(void); -void free_max_user_conn(void); -pthread_handler_t handle_bootstrap(void *arg); -void do_handle_bootstrap(THD *thd); -int mysql_execute_command(THD *thd); -bool do_command(THD *thd); -bool dispatch_command(enum enum_server_command command, THD *thd, - char* packet, uint packet_length); -void log_slow_statement(THD *thd); -bool check_dup(const char *db, const char *name, TABLE_LIST *tables); -bool compare_record(TABLE *table); -bool append_file_to_dir(THD *thd, const char **filename_ptr, - const char *table_name); -bool table_def_init(void); -void table_def_start_shutdown(void); -void table_def_free(void); -void assign_new_table_id(TABLE_SHARE *share); -uint cached_open_tables(void); -uint cached_table_definitions(void); -void kill_mysql(void); -void close_connection(THD *thd, uint errcode, bool lock); -bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, - bool *write_to_binlog); -#ifndef NO_EMBEDDED_ACCESS_CHECKS -bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv, - GRANT_INTERNAL_INFO *grant_internal_info, - bool no_grant, 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_access(THD *thd, ulong access, const char *db, - ulong *save_priv, - GRANT_INTERNAL_INFO *grant_internal_info, - bool no_grant, bool no_errors) -{ - 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*/ - -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -bool check_global_access(THD *thd, ulong want_access); -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER - -/* - Support routine for SQL parser on partitioning syntax -*/ -my_bool is_partition_management(LEX *lex); -/* - General routine to change field->ptr of a NULL-terminated array of Field - objects. Useful when needed to call val_int, val_str or similar and the - field data is not in table->record[0] but in some other structure. - set_key_field_ptr changes all fields of an index using a key_info object. - All methods presume that there is at least one field to change. -*/ - -void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf); -void set_key_field_ptr(KEY *key_info, const uchar *new_buf, - const uchar *old_buf); - -bool mysql_backup_table(THD* thd, TABLE_LIST* table_list); -bool mysql_restore_table(THD* thd, TABLE_LIST* table_list); - -bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -bool mysql_check_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -bool mysql_repair_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list, - LEX_STRING *key_cache_name); -bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list); -int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache, - KEY_CACHE *dst_cache); -TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list); - -bool mysql_xa_recover(THD *thd); - -bool check_simple_select(); -int mysql_alter_tablespace(THD* thd, st_alter_tablespace *ts_info); - -SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length, - SORT_FIELD *sortorder); -int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, - List<Item> &fields, List <Item> &all_fields, ORDER *order); -int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, - List<Item> &fields, List<Item> &all_fields, ORDER *order, - bool *hidden_group_fields); -bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select, - Item **ref_pointer_array, ORDER *group_list= NULL); - -bool handle_select(THD *thd, LEX *lex, select_result *result, - ulong setup_tables_done_option); -bool mysql_select(THD *thd, Item ***rref_pointer_array, - TABLE_LIST *tables, uint wild_num, List<Item> &list, - COND *conds, uint og_num, ORDER *order, ORDER *group, - Item *having, ORDER *proc_param, ulonglong select_type, - select_result *result, SELECT_LEX_UNIT *unit, - SELECT_LEX *select_lex); -void free_underlaid_joins(THD *thd, SELECT_LEX *select); -bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, - select_result *result); -int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type, - select_result *result); -bool mysql_union(THD *thd, LEX *lex, select_result *result, - SELECT_LEX_UNIT *unit, ulong setup_tables_done_option); -bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd, - LEX *lex, - TABLE_LIST *table)); -bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t); -bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t); -Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, - Item ***copy_func, Field **from_field, - Field **def_field, - bool group, bool modify_item, - bool table_cant_handle_bit_fields, - bool make_copy_field, - uint convert_blob_length); -void sp_prepare_create_field(THD *thd, Create_field *sql_field); -int prepare_create_field(Create_field *sql_field, - uint *blob_columns, - int *timestamps, int *timestamps_with_niladic, - longlong table_flags); -CHARSET_INFO* get_sql_field_charset(Create_field *sql_field, - HA_CREATE_INFO *create_info); -bool mysql_create_table(THD *thd, TABLE_LIST *create_table, - HA_CREATE_INFO *create_info, - Alter_info *alter_info); -bool mysql_create_table_no_lock(THD *thd, const char *db, - const char *table_name, - HA_CREATE_INFO *create_info, - Alter_info *alter_info, - bool tmp_table, uint select_field_count); - -bool mysql_alter_table(THD *thd, char *new_db, char *new_name, - HA_CREATE_INFO *create_info, - TABLE_LIST *table_list, - Alter_info *alter_info, - uint order_num, ORDER *order, bool ignore); -bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list); -bool mysql_create_like_table(THD *thd, TABLE_LIST *table, - TABLE_LIST *src_table, - HA_CREATE_INFO *create_info); -bool mysql_rename_table(handlerton *base, const char *old_db, - const char * old_name, const char *new_db, - const char * new_name, uint flags); -bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, - Item **conds, uint order_num, ORDER *order); -int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields, - List<Item> &values,COND *conds, - uint order_num, ORDER *order, ha_rows limit, - enum enum_duplicates handle_duplicates, bool ignore, - ha_rows *found_return, ha_rows *updated_return); -bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, - List<Item> *fields, List<Item> *values, - COND *conds, ulonglong options, - enum enum_duplicates handle_duplicates, bool ignore, - SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex, - multi_update **result); -bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, - List<Item> &fields, List_item *values, - List<Item> &update_fields, - List<Item> &update_values, enum_duplicates duplic, - COND **where, bool select_insert, - bool check_fields, bool abort_on_warning); -bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields, - List<List_item> &values, List<Item> &update_fields, - List<Item> &update_values, enum_duplicates flag, - bool ignore); -int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, - TABLE_LIST *table_list); -void prepare_triggers_for_insert_stmt(TABLE *table); -int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); -bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, - SQL_LIST *order, ha_rows rows, ulonglong options, - bool reset_auto_increment); -bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok); -bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create); -uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list, - bool tmp_table); -TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key, - uint key_length, uint db_flags, int *error, - my_hash_value_type hash_value); -void release_table_share(TABLE_SHARE *share); -TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name); -TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update, - uint lock_flags); -bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem, - Open_table_context *backoff, uint flags); -bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias, - char *cache_key, uint cache_key_length, - MEM_ROOT *mem_root, uint flags); -TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name); -TABLE *find_table_for_mdl_upgrade(TABLE *list, const char *db, - const char *table_name, - bool no_error); -thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table); -bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias, - uint db_stat, uint prgflag, - uint ha_open_flags, TABLE *outparam, - TABLE_LIST *table_desc, MEM_ROOT *mem_root); -void execute_init_command(THD *thd, LEX_STRING *init_command, - mysql_rwlock_t *var_mutex); -extern Field *not_found_field; -extern Field *view_ref_found; - -enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND, - IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE, - IGNORE_EXCEPT_NON_UNIQUE}; -Field * -find_field_in_tables(THD *thd, Item_ident *item, - TABLE_LIST *first_table, TABLE_LIST *last_table, - Item **ref, find_item_error_report_type report_error, - bool check_privileges, bool register_tree_change); -Field * -find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, - const char *name, uint length, - const char *item_name, const char *db_name, - const char *table_name, Item **ref, - bool check_privileges, bool allow_rowid, - uint *cached_field_index_ptr, - bool register_tree_change, TABLE_LIST **actual_table); -Field * -find_field_in_table(THD *thd, TABLE *table, const char *name, uint length, - bool allow_rowid, uint *cached_field_index_ptr); -Field * -find_field_in_table_sef(TABLE *table, const char *name); - -#endif /* MYSQL_SERVER */ - -#ifdef HAVE_OPENSSL -#include <openssl/des.h> -struct st_des_keyblock -{ - DES_cblock key1, key2, key3; -}; -struct st_des_keyschedule -{ - DES_key_schedule ks1, ks2, ks3; -}; -extern char *des_key_file; -extern struct st_des_keyschedule des_keyschedule[10]; -extern uint des_default_key; -extern mysql_mutex_t LOCK_des_key_file; -bool load_des_key_file(const char *file_name); -#endif /* HAVE_OPENSSL */ - -#ifdef MYSQL_SERVER -/* sql_do.cc */ -bool mysql_do(THD *thd, List<Item> &values); - -/* sql_analyse.h */ -bool append_escaped(String *to_str, String *from_str); - -/* sql_show.cc */ -bool mysqld_show_open_tables(THD *thd,const char *wild); -bool mysqld_show_logs(THD *thd); -void append_identifier(THD *thd, String *packet, const char *name, - uint length); -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -int get_quote_char_for_identifier(THD *thd, const char *name, uint length); -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild); -int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd); -bool mysqld_show_create(THD *thd, TABLE_LIST *table_list); -bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create); - -void mysqld_list_processes(THD *thd,const char *user,bool verbose); -int mysqld_show_status(THD *thd); -int mysqld_show_variables(THD *thd,const char *wild); -bool mysqld_show_storage_engines(THD *thd); -bool mysqld_show_authors(THD *thd); -bool mysqld_show_contributors(THD *thd); -bool mysqld_show_privileges(THD *thd); -bool mysqld_show_column_types(THD *thd); -bool mysqld_help (THD *thd, const char *text); -void calc_sum_of_all_status(STATUS_VAR *to); - -void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user, - const LEX_STRING *definer_host); - -int add_status_vars(SHOW_VAR *list); -void remove_status_vars(SHOW_VAR *list); -void init_status_vars(); -void free_status_vars(); -void reset_status_vars(); -/* information schema */ -extern LEX_STRING INFORMATION_SCHEMA_NAME; -/* performance schema */ -extern LEX_STRING PERFORMANCE_SCHEMA_DB_NAME; -/* log tables */ -extern LEX_STRING MYSQL_SCHEMA_NAME; -extern LEX_STRING GENERAL_LOG_NAME; -extern LEX_STRING SLOW_LOG_NAME; - -extern const LEX_STRING partition_keywords[]; -ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name); -ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx); -int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, - enum enum_schema_tables schema_table_idx); -int make_schema_select(THD *thd, SELECT_LEX *sel, - enum enum_schema_tables schema_table_idx); -int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list); -int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond); -int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond); -int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond); -int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond); -bool get_schema_tables_result(JOIN *join, - enum enum_schema_table_state executed_place); -enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table); - -inline bool is_infoschema_db(const char *name, size_t len) -{ - return (INFORMATION_SCHEMA_NAME.length == len && - !my_strcasecmp(system_charset_info, - INFORMATION_SCHEMA_NAME.str, name)); -} - -inline bool is_infoschema_db(const char *name) -{ - return !my_strcasecmp(system_charset_info, - INFORMATION_SCHEMA_NAME.str, name); -} - -void initialize_information_schema_acl(); - -/* sql_handler.cc */ -bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen); -bool mysql_ha_close(THD *thd, TABLE_LIST *tables); -bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, - List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows); -void mysql_ha_flush(THD *thd); -void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables); -void mysql_ha_cleanup(THD *thd); -void mysql_ha_move_tickets_after_trans_sentinel(THD *thd); - -/* sql_base.cc */ -#define TMP_TABLE_KEY_EXTRA 8 -void set_item_name(Item *item,char *pos,uint length); -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); -Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type, - char *length, char *decimals, - 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); -void store_position_for_column(const char *name); -bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc); -bool push_new_name_resolution_context(THD *thd, - TABLE_LIST *left_op, - TABLE_LIST *right_op); -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 wait_while_table_is_used(THD *thd, TABLE *table, - enum ha_extra_function function); -void drop_open_table(THD *thd, TABLE *table, const char *db_name, - const char *table_name); -void close_all_tables_for_name(THD *thd, TABLE_SHARE *share, - bool remove_from_locked_tables); -void update_non_unique_table_error(TABLE_LIST *update, - const char *operation, - TABLE_LIST *duplicate); - -SQL_SELECT *make_select(TABLE *head, table_map const_tables, - table_map read_tables, COND *conds, - bool allow_null_cond, int *error); -extern Item **not_found_item; - -/* - A set of constants used for checking non aggregated fields and sum - functions mixture in the ONLY_FULL_GROUP_BY_MODE. -*/ -#define NON_AGG_FIELD_USED 1 -#define SUM_FUNC_USED 2 - -/* - This enumeration type is used only by the function find_item_in_list - to return the info on how an item has been resolved against a list - of possibly aliased items. - The item can be resolved: - - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS) - - against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS) - - against an aliased field name of the list (RESOLVED_BEHIND_ALIAS) - - ignoring the alias name in cases when SQL requires to ignore aliases - (e.g. when the resolved field reference contains a table name or - when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS) -*/ -enum enum_resolution_type { - NOT_RESOLVED=0, - RESOLVED_IGNORING_ALIAS, - RESOLVED_BEHIND_ALIAS, - RESOLVED_WITH_NO_ALIAS, - RESOLVED_AGAINST_ALIAS -}; -Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter, - find_item_error_report_type report_error, - enum_resolution_type *resolution); -bool get_key_map_from_key_list(key_map *map, TABLE *table, - List<String> *index_list); -bool insert_fields(THD *thd, Name_resolution_context *context, - const char *db_name, const char *table_name, - List_iterator<Item> *it, bool any_privileges); -bool setup_tables(THD *thd, Name_resolution_context *context, - List<TABLE_LIST> *from_clause, TABLE_LIST *tables, - TABLE_LIST **leaves, bool select_insert); -bool setup_tables_and_check_access(THD *thd, - Name_resolution_context *context, - List<TABLE_LIST> *from_clause, - TABLE_LIST *tables, - TABLE_LIST **leaves, - bool select_insert, - ulong want_access_first, - ulong want_access); -int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, - List<Item> *sum_func_list, uint wild_num); -bool setup_fields(THD *thd, Item** ref_pointer_array, - List<Item> &item, enum_mark_columns mark_used_columns, - List<Item> *sum_func_list, bool allow_sum_func); -inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array, - List<Item> &item, - enum_mark_columns mark_used_columns, - List<Item> *sum_func_list, - bool allow_sum_func) -{ - bool res; - thd->lex->select_lex.no_wrap_view_item= TRUE; - res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list, - allow_sum_func); - thd->lex->select_lex.no_wrap_view_item= FALSE; - return res; -} -int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, - COND **conds); -int setup_ftfuncs(SELECT_LEX* select); -int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order); -void wait_for_condition(THD *thd, mysql_mutex_t *mutex, - mysql_cond_t *cond); -bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags, - Prelocking_strategy *prelocking_strategy); -inline bool -open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags) -{ - DML_prelocking_strategy prelocking_strategy; - - return open_tables(thd, tables, counter, flags, &prelocking_strategy); -} -/* open_and_lock_tables with optional derived handling */ -bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, - bool derived, uint flags, - Prelocking_strategy *prelocking_strategy); -inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, - bool derived, uint flags) -{ - DML_prelocking_strategy prelocking_strategy; - - return open_and_lock_tables(thd, tables, derived, flags, - &prelocking_strategy); -} -/* simple open_and_lock_tables without derived handling for single table */ -TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l, - thr_lock_type lock_type, uint flags); -bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags); -bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags, - bool *need_reopen); -TABLE *open_temporary_table(THD *thd, const char *path, const char *db, - const char *table_name, bool link_in_list); -bool rm_temporary_table(handlerton *base, char *path); -void free_io_cache(TABLE *entry); -void intern_close_table(TABLE *entry); -bool close_thread_table(THD *thd, TABLE **table_ptr); -void close_temporary_tables(THD *thd); -void close_tables_for_reopen(THD *thd, TABLE_LIST **tables, - MDL_ticket *mdl_savepoint); -TABLE_LIST *find_table_in_list(TABLE_LIST *table, - TABLE_LIST *TABLE_LIST::*link, - const char *db_name, - const char *table_name); -TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, - bool check_alias); -TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name); -TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list); -int drop_temporary_table(THD *thd, TABLE_LIST *table_list); -void close_temporary_table(THD *thd, TABLE *table, bool free_share, - bool delete_table); -void mark_tmp_table_for_reuse(TABLE *table); -void close_temporary(TABLE *table, bool free_share, bool delete_table); -bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db, - const char *table_name); -void flush_tables(); -bool is_equal(const LEX_STRING *a, const LEX_STRING *b); -char *make_log_name(char *buff, const char *name, const char* log_ext); -extern char default_logfile_name[FN_REFLEN]; - -#ifdef WITH_PARTITION_STORAGE_ENGINE -uint fast_alter_partition_table(THD *thd, TABLE *table, - Alter_info *alter_info, - HA_CREATE_INFO *create_info, - TABLE_LIST *table_list, - char *db, - const char *table_name, - uint fast_alter_partition); -uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info, - enum partition_state part_state); -uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, - HA_CREATE_INFO *create_info, - handlerton *old_db_type, - bool *partition_changed, - uint *fast_alter_partition); -char *generate_partition_syntax(partition_info *part_info, - uint *buf_length, bool use_sql_alloc, - bool show_partition_options, - HA_CREATE_INFO *create_info, - Alter_info *alter_info); -#endif - -enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN, - TDC_RT_REMOVE_UNUSED}; -void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, - const char *db, const char *table_name); - -#define NORMAL_PART_NAME 0 -#define TEMP_PART_NAME 1 -#define RENAMED_PART_NAME 2 -void create_partition_name(char *out, const char *in1, - const char *in2, uint name_variant, - bool translate); -void create_subpartition_name(char *out, const char *in1, - const char *in2, const char *in3, - uint name_variant); - -typedef struct st_lock_param_type -{ - TABLE_LIST *table_list; - ulonglong copied; - ulonglong deleted; - THD *thd; - HA_CREATE_INFO *create_info; - Alter_info *alter_info; - TABLE *table; - KEY *key_info_buffer; - const char *db; - const char *table_name; - uchar *pack_frm_data; - uint key_count; - uint db_options; - size_t pack_frm_len; - partition_info *part_info; -} ALTER_PARTITION_PARAM_TYPE; - -void mem_alloc_error(size_t size); - -enum ddl_log_entry_code -{ - /* - DDL_LOG_EXECUTE_CODE: - This is a code that indicates that this is a log entry to - be executed, from this entry a linked list of log entries - can be found and executed. - DDL_LOG_ENTRY_CODE: - An entry to be executed in a linked list from an execute log - entry. - DDL_IGNORE_LOG_ENTRY_CODE: - An entry that is to be ignored - */ - DDL_LOG_EXECUTE_CODE = 'e', - DDL_LOG_ENTRY_CODE = 'l', - DDL_IGNORE_LOG_ENTRY_CODE = 'i' -}; - -enum ddl_log_action_code -{ - /* - The type of action that a DDL_LOG_ENTRY_CODE entry is to - perform. - DDL_LOG_DELETE_ACTION: - Delete an entity - DDL_LOG_RENAME_ACTION: - Rename an entity - DDL_LOG_REPLACE_ACTION: - Rename an entity after removing the previous entry with the - new name, that is replace this entry. - */ - DDL_LOG_DELETE_ACTION = 'd', - DDL_LOG_RENAME_ACTION = 'r', - DDL_LOG_REPLACE_ACTION = 's' -}; - - -typedef struct st_ddl_log_entry -{ - const char *name; - const char *from_name; - const char *handler_name; - uint next_entry; - uint entry_pos; - enum ddl_log_entry_code entry_type; - enum ddl_log_action_code action_type; - /* - Most actions have only one phase. REPLACE does however have two - phases. The first phase removes the file with the new name if - there was one there before and the second phase renames the - old name to the new name. - */ - char phase; -} DDL_LOG_ENTRY; - -typedef struct st_ddl_log_memory_entry -{ - uint entry_pos; - struct st_ddl_log_memory_entry *next_log_entry; - struct st_ddl_log_memory_entry *prev_log_entry; - struct st_ddl_log_memory_entry *next_active_log_entry; -} DDL_LOG_MEMORY_ENTRY; - - -bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry, - DDL_LOG_MEMORY_ENTRY **active_entry); -bool write_execute_ddl_log_entry(uint first_entry, - bool complete, - DDL_LOG_MEMORY_ENTRY **active_entry); -bool deactivate_ddl_log_entry(uint entry_no); -void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry); -bool sync_ddl_log(); -void release_ddl_log(); -void execute_ddl_log_recovery(); -bool execute_ddl_log_entry(THD *thd, uint first_entry); - -extern mysql_mutex_t LOCK_gdl; - -#define WFRM_WRITE_SHADOW 1 -#define WFRM_INSTALL_SHADOW 2 -#define WFRM_PACK_FRM 4 -#define WFRM_KEEP_SHARE 8 -bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags); -int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt); -void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt); - -/* Functions to work with system tables. */ -bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list, - Open_tables_backup *backup); -void close_system_tables(THD *thd, Open_tables_backup *backup); -TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table); - -TABLE *open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup); -void close_log_table(THD *thd, Open_tables_backup *backup); - -bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, - bool wait_for_refresh); -bool close_cached_connection_tables(THD *thd, bool wait_for_refresh, - LEX_STRING *connect_string, - bool have_lock = FALSE); -void copy_field_from_tmp_record(Field *field,int offset); -bool fill_record(THD *thd, Field **field, List<Item> &values, - bool ignore_errors); -bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields, - List<Item> &values, - bool ignore_errors, - Table_triggers_list *triggers, - enum trg_event_type event); -bool fill_record_n_invoke_before_triggers(THD *thd, Field **field, - List<Item> &values, - bool ignore_errors, - Table_triggers_list *triggers, - enum trg_event_type event); -OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild); - -inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table, - const char *db_name, - const char *table_name) -{ - return find_table_in_list(table, &TABLE_LIST::next_global, - db_name, table_name); -} - -inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table, - const char *db_name, - const char *table_name) -{ - return find_table_in_list(table, &TABLE_LIST::next_local, - db_name, table_name); -} - - -/* sql_calc.cc */ -bool eval_const_cond(COND *cond); - -/* sql_load.cc */ -int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, - List<Item> &fields_vars, List<Item> &set_fields, - List<Item> &set_values_list, - enum enum_duplicates handle_duplicates, bool ignore, - bool local_file); -int write_record(THD *thd, TABLE *table, COPY_INFO *info); - -/* sql_manager.cc */ -extern bool volatile mqh_used; -void start_handle_manager(); -void stop_handle_manager(); -bool mysql_manager_submit(void (*action)()); - - -/* sql_test.cc */ -#ifndef DBUG_OFF -void print_where(COND *cond,const char *info, enum_query_type query_type); -void print_cached_tables(void); -void TEST_filesort(SORT_FIELD *sortorder,uint s_length); -void print_plan(JOIN* join,uint idx, double record_count, double read_time, - double current_read_time, const char *info); -#endif -void mysql_print_status(); -/* key.cc */ -int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field, - uint *key_length, uint *keypart); -void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length); -void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, - uint key_length); -bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length); -void key_unpack(String *to,TABLE *form,uint index); -bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields); -int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length); -extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b); - -bool init_errmessage(void); -#endif /* MYSQL_SERVER */ -void sql_perror(const char *message); -bool read_texts(const char *file_name, const char *language, - const char ***point, uint error_messages); - -bool fn_format_relative_to_data_home(char * to, const char *name, - const char *dir, const char *extension); -#ifdef MYSQL_SERVER -File open_binlog(IO_CACHE *log, const char *log_file_name, - const char **errmsg); - -/* mysqld.cc */ -extern void MYSQLerror(const char*); -void refresh_status(THD *thd); -my_bool mysql_rm_tmp_tables(void); -void handle_connection_in_main_thread(THD *thd); -void create_thread_to_handle_connection(THD *thd); -void unlink_thd(THD *thd); -bool one_thread_per_connection_end(THD *thd, bool put_in_cache); -void flush_thread_cache(); - -/* item_func.cc */ -extern bool check_reserved_words(LEX_STRING *name); -extern enum_field_types agg_field_type(Item **items, uint nitems); - -/* strfunc.cc */ -ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs, - char **err_pos, uint *err_len, bool *set_warning); -uint find_type(const TYPELIB *lib, const char *find, uint length, - bool part_match); -uint find_type2(const TYPELIB *lib, const char *find, uint length, - CHARSET_INFO *cs); -void unhex_type2(TYPELIB *lib); -uint check_word(TYPELIB *lib, const char *val, const char *end, - const char **end_of_word); -int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle, - CHARSET_INFO * const cs); -char *set_to_string(THD *thd, LEX_STRING *result, ulonglong set, - const char *lib[]); -char *flagset_to_string(THD *thd, LEX_STRING *result, ulonglong set, - const char *lib[]); - - -bool is_keyword(const char *name, uint len); - -#define MY_DB_OPT_FILE "db.opt" -bool my_database_names_init(void); -void my_database_names_free(void); -bool check_db_dir_existence(const char *db_name); -bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create); -bool load_db_opt_by_name(THD *thd, const char *db_name, - HA_CREATE_INFO *db_create_info); -CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name); -bool my_dbopt_init(void); -void my_dbopt_cleanup(void); -extern int creating_database; // How many database locks are made -extern int creating_table; // How many mysql_create_table() are running - -/* - External variables -*/ - -extern time_t server_start_time, flush_status_time; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern uint mysql_data_home_len, mysql_real_data_home_len; -extern const char *mysql_real_data_home_ptr; -extern uint thread_handling; - -extern MYSQL_PLUGIN_IMPORT char *mysql_data_home; -extern char server_version[SERVER_VERSION_LENGTH]; -extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[]; -extern char mysql_unpacked_real_data_home[]; - -extern CHARSET_INFO *character_set_filesystem; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern char *opt_mysql_tmpdir, mysql_charsets_dir[]; -extern int mysql_unpacked_real_data_home_len; -#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list)) -extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list; -extern const LEX_STRING command_name[]; - -extern LEX_STRING opt_init_connect, opt_init_slave; - -extern const char *first_keyword, *delayed_user, *binary_keyword; -extern MYSQL_PLUGIN_IMPORT const char *my_localhost; -extern MYSQL_PLUGIN_IMPORT const char **errmesg; /* Error messages */ - -extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond; -extern const char * const TRG_EXT; -extern const char * const TRN_EXT; -extern Eq_creator eq_creator; -extern Ne_creator ne_creator; -extern Gt_creator gt_creator; -extern Lt_creator lt_creator; -extern Ge_creator ge_creator; -extern Le_creator le_creator; -extern char lc_messages_dir[FN_REFLEN]; -extern char *lc_messages_dir_ptr, *log_error_file_ptr; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN]; -extern MYSQL_PLUGIN_IMPORT uint reg_ext_length; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern char *mysql_home_ptr, *pidfile_name_ptr; -extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; -extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; -extern char log_error_file[FN_REFLEN], *opt_tc_log_file; -extern const double log_10[309]; -extern ulonglong log_10_int[20]; -extern ulonglong keybuff_size; -extern ulonglong thd_startup_options; -extern ulong thread_id; -extern ulong binlog_cache_use, binlog_cache_disk_use; -extern ulong aborted_threads,aborted_connects; -extern ulong delayed_insert_timeout; -extern ulong delayed_insert_limit, delayed_queue_size; -extern ulong delayed_insert_threads, delayed_insert_writes; -extern ulong delayed_rows_in_use,delayed_insert_errors; -extern ulong slave_open_temp_tables; -extern ulong query_cache_size, query_cache_min_res_unit; -extern ulong slow_launch_threads, slow_launch_time; -extern ulong table_cache_size, table_def_size; -extern MYSQL_PLUGIN_IMPORT ulong max_connections; -extern ulong max_connect_errors, connect_timeout; -extern ulong slave_trans_retries; -extern uint slave_net_timeout; -extern ulong what_to_log,flush_time; -extern ulong query_buff_size; -extern ulong max_prepared_stmt_count, prepared_stmt_count; -extern ulong binlog_cache_size, open_files_limit; -extern ulonglong max_binlog_cache_size; -extern ulong max_binlog_size, max_relay_log_size; -extern ulong opt_binlog_rows_event_max_size; -extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size; -extern ulong back_log; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern ulong MYSQL_PLUGIN_IMPORT specialflag; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern ulong current_pid; -extern ulong expire_logs_days; -extern uint sync_binlog_period, sync_relaylog_period, - sync_relayloginfo_period, sync_masterinfo_period; -extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size; -extern ulong tc_log_page_waits; -extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb; -extern my_bool relay_log_recovery; -extern uint test_flags,select_errors,ha_open_options; -extern uint protocol_version, mysqld_port, dropping_tables; -extern uint delay_key_write_options; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern bool opt_endinfo, using_udf_functions; -extern my_bool locked_in_memory; -extern bool opt_using_transactions; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern bool opt_large_files, server_id_supplied; -extern bool opt_bin_log, opt_error_log; -extern my_bool opt_log, opt_slow_log; -extern ulonglong log_output_options; -extern my_bool opt_log_queries_not_using_indexes; -extern bool opt_disable_networking, opt_skip_show_db; -extern bool opt_ignore_builtin_innodb; -extern my_bool opt_character_set_client_handshake; -extern bool volatile abort_loop, shutdown_in_progress; -extern bool in_bootstrap; -extern uint volatile thread_count, global_read_lock; -extern uint connection_count; -extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types; -extern my_bool opt_local_infile, opt_myisam_use_mmap; -extern my_bool opt_slave_compressed_protocol, use_temp_pool; -extern uint slave_exec_mode_options; -extern ulonglong slave_type_conversions_options; -extern my_bool opt_readonly, lower_case_file_system; -extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs; -extern my_bool opt_secure_auth; -extern char* opt_secure_file_priv; -extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements; -extern my_bool sp_automatic_privileges, opt_noacl, disable_slaves; -extern my_bool opt_old_style_user_limits, trust_function_creators; -extern uint opt_crash_binlog_innodb; -extern char *shared_memory_base_name, *mysqld_unix_port; -extern my_bool opt_enable_shared_memory; -extern char *default_tz_name; -extern Time_zone *default_tz; -extern char *default_storage_engine; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern my_bool opt_large_pages; -extern uint opt_large_page_size; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern char *opt_logname, *opt_slow_logname; -extern const char *log_output_str; -extern my_bool old_mode; - -extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log; -extern LOGGER logger; -extern TABLE_LIST general_log, slow_log; -extern MYSQL_FILE *bootstrap_file; -extern int bootstrap_error; -extern FILE *stderror_file; -extern pthread_key(MEM_ROOT**,THR_MALLOC); -extern mysql_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_lock_db, - LOCK_mapped_file, LOCK_user_locks, LOCK_status, - LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator, - LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, - LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock, - LOCK_global_system_variables, LOCK_user_conn, - LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count; -extern MYSQL_PLUGIN_IMPORT mysql_mutex_t LOCK_thread_count; -#ifdef HAVE_OPENSSL -extern mysql_mutex_t LOCK_des_key_file; -#endif -extern mysql_mutex_t LOCK_server_started; -extern mysql_cond_t COND_server_started; -extern int mysqld_server_started; -extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; -extern mysql_rwlock_t LOCK_system_variables_hash; -extern mysql_cond_t COND_thread_count; -extern mysql_cond_t COND_refresh, COND_manager; -extern mysql_cond_t COND_global_read_lock; -extern pthread_attr_t connection_attrib; -extern I_List<THD> threads; -extern MY_BITMAP temp_pool; -extern String my_empty_string; -extern const String my_null_string; -extern SHOW_VAR status_vars[]; -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables; -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -extern struct system_variables max_system_variables; -extern struct system_status_var global_status_var; -extern struct rand_struct sql_rand; - -extern DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format; -extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[]; - -extern String null_string; -extern HASH table_def_cache, lock_db_cache; -extern TABLE *unused_tables; -extern uint table_cache_count; -extern const char* any_db; -extern const LEX_STRING view_type; -extern scheduler_functions thread_scheduler; -extern TYPELIB thread_handling_typelib; -extern uint sql_command_flags[]; -extern uint server_command_flags[]; -extern TYPELIB log_output_typelib; -extern const char *log_output_names[]; - -/* optional things, have_* variables */ -extern SHOW_COMP_OPTION have_csv, have_innodb; -extern SHOW_COMP_OPTION have_ndbcluster, have_partitioning; -extern SHOW_COMP_OPTION have_profiling; - -extern handlerton *partition_hton; -extern handlerton *myisam_hton; -extern handlerton *heap_hton; - -extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen; -extern SHOW_COMP_OPTION have_query_cache; -extern SHOW_COMP_OPTION have_geometry, have_rtree_keys; -extern SHOW_COMP_OPTION have_crypt; -extern SHOW_COMP_OPTION have_compress; - -extern int orig_argc; -extern char **orig_argv; -extern const char *load_default_groups[]; - -#ifndef __WIN__ -extern pthread_t signal_thread; -#endif - -extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher, - *opt_ssl_key; - -#ifdef HAVE_OPENSSL -extern struct st_VioSSLFd * ssl_acceptor_fd; -#endif /* HAVE_OPENSSL */ - -MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, - uint flags, bool *need_reopen); -/* mysql_lock_tables() and open_table() flags bits */ -#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001 -#define MYSQL_LOCK_IGNORE_FLUSH 0x0002 -#define MYSQL_OPEN_TEMPORARY_ONLY 0x0004 -#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008 -#define MYSQL_LOCK_PERF_SCHEMA 0x0010 -#define MYSQL_OPEN_TAKE_UPGRADABLE_MDL 0x0020 -/** - Do not try to acquire a metadata lock on the table: we - already have one. -*/ -#define MYSQL_OPEN_HAS_MDL_LOCK 0x0040 -/** - If in locked tables mode, ignore the locked tables and get - a new instance of the table. -*/ -#define MYSQL_OPEN_GET_NEW_TABLE 0x0080 -/** Don't look up the table in the list of temporary tables. */ -#define MYSQL_OPEN_SKIP_TEMPORARY 0x0100 -/** Fail instead of waiting when conficting metadata lock is discovered. */ -#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0200 -/** Open tables using MDL_SHARED lock instead of one specified in parser. */ -#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0400 -/** - Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified - in parser. -*/ -#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0800 -/** - When opening or locking the table, use the maximum timeout - (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value. -*/ -#define MYSQL_LOCK_IGNORE_TIMEOUT 0x1000 - -/** Please refer to the internals manual. */ -#define MYSQL_OPEN_REOPEN (MYSQL_LOCK_IGNORE_FLUSH |\ - MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK |\ - MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |\ - MYSQL_LOCK_IGNORE_TIMEOUT |\ - MYSQL_OPEN_GET_NEW_TABLE |\ - MYSQL_OPEN_SKIP_TEMPORARY |\ - MYSQL_OPEN_HAS_MDL_LOCK) - -void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock); -void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock); -void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count); -void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table); -void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock); -void mysql_lock_downgrade_write(THD *thd, TABLE *table, - thr_lock_type new_lock_type); -bool mysql_lock_abort_for_thread(THD *thd, TABLE *table); -MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b); -TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle, - TABLE_LIST *haystack); -void broadcast_refresh(void); - -/* Lock based on name */ -bool lock_table_names(THD *thd, TABLE_LIST *table_list); -void unlock_table_names(THD *thd); - -/* Lock based on stored routine name */ -bool lock_routine_name(THD *thd, bool is_function, const char *db, - const char *name); - -/* old unireg functions */ - -void unireg_init(ulong options); -void unireg_end(void) __attribute__((noreturn)); -bool mysql_create_frm(THD *thd, const char *file_name, - const char *db, const char *table, - HA_CREATE_INFO *create_info, - List<Create_field> &create_field, - uint key_count,KEY *key_info,handler *db_type); -int rea_create_table(THD *thd, const char *path, - const char *db, const char *table_name, - HA_CREATE_INFO *create_info, - List<Create_field> &create_field, - uint key_count,KEY *key_info, - handler *file); -int format_number(uint inputflag,uint max_length,char * pos,uint length, - char * *errpos); - -/* table.cc */ -TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, - uint key_length); -void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, - uint key_length, - const char *table_name, const char *path); -void free_table_share(TABLE_SHARE *share); -int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags); -void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg); -int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, - uint db_stat, uint prgflag, uint ha_open_flags, - TABLE *outparam, bool is_create_table); -int readfrm(const char *name, uchar **data, size_t *length); -int writefrm(const char* name, const uchar* data, size_t len); -int closefrm(TABLE *table, bool free_share); -int read_string(File file, uchar* *to, size_t length); -void free_blobs(TABLE *table); -void free_field_buffers_larger_than(TABLE *table, uint32 size); -int set_zone(int nr,int min_zone,int max_zone); -ulong convert_period_to_month(ulong period); -ulong convert_month_to_period(ulong month); -void get_date_from_daynr(long daynr,uint *year, uint *month, - uint *day); -my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist); -/* Character set-aware version of str_to_time() */ -bool str_to_time(CHARSET_INFO *cs, const char *str,uint length, - MYSQL_TIME *l_time, int *warning); -/* Character set-aware version of str_to_datetime() */ -timestamp_type str_to_datetime(CHARSET_INFO *cs, - const char *str, uint length, - MYSQL_TIME *l_time, uint flags, int *was_cut); -bool str_to_time_with_warn(CHARSET_INFO *cs, const char *str,uint length, - MYSQL_TIME *l_time); -timestamp_type str_to_datetime_with_warn(CHARSET_INFO *cs, - const char *str, uint length, - MYSQL_TIME *l_time, uint flags); -void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); -void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds); - -void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, - const char *str_val, - uint str_length, timestamp_type time_type, - const char *field_name); - -bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval); -bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, - longlong *seconds_out, long *microseconds_out); - -extern LEX_STRING interval_type_to_name[]; - - -bool parse_date_time_format(timestamp_type format_type, - const char *format, uint format_length, - DATE_TIME_FORMAT *date_time_format); -/* convenience wrapper */ -inline bool parse_date_time_format(timestamp_type format_type, - DATE_TIME_FORMAT *date_time_format) -{ - return parse_date_time_format(format_type, - date_time_format->format.str, - date_time_format->format.length, - date_time_format); -} - -extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type, - const char *format_str, - uint format_length); -extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd, - DATE_TIME_FORMAT *format); -const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format, - timestamp_type type); -extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, - timestamp_type type, String *str); -void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time, - String *str); -void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time, - String *str); -void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time, - String *str); -int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b); -longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, - Item *warn_item, bool *is_null); - -int test_if_number(char *str,int *res,bool allow_wildcards); -void change_byte(uchar *,uint,char,char); -ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder, - uint s_length, SQL_SELECT *select, - ha_rows max_rows, bool sort_positions, - ha_rows *examined_rows); -void filesort_free_buffers(TABLE *table, bool full); -void change_double_for_sort(double nr,uchar *to); -double my_double_round(double value, longlong dec, bool dec_unsigned, - bool truncate); -int get_quick_record(SQL_SELECT *select); - -int calc_weekday(long daynr,bool sunday_first_day_of_week); -uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year); -void find_date(char *pos,uint *vek,uint flag); -TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end); -TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings); -ulong get_form_pos(File file, uchar *head, TYPELIB *save_names); -ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames, - const char *newname); -ulong next_io_size(ulong pos); -void append_unescaped(String *res, const char *pos, uint length); -int create_frm(THD *thd, const char *name, const char *db, const char *table, - uint reclength, uchar *fileinfo, - HA_CREATE_INFO *create_info, uint keys, KEY *key_info); -void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form); -int rename_file_ext(const char * from,const char * to,const char * ext); -bool check_db_name(LEX_STRING *db); -bool check_column_name(const char *name); -bool check_table_name(const char *name, uint length); -char *get_field(MEM_ROOT *mem, Field *field); -bool get_field(MEM_ROOT *mem, Field *field, class String *res); -int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr); -char *fn_rext(char *name); -bool check_duplicate_warning(THD *thd, char *msg, ulong length); - -/* Conversion functions */ -#endif /* MYSQL_SERVER */ -#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -uint strconvert(CHARSET_INFO *from_cs, const char *from, - CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors); -/* depends on errmsg.txt Database `db`, Table `t` ... */ -#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63 -enum enum_explain_filename_mode -{ - EXPLAIN_ALL_VERBOSE= 0, - EXPLAIN_PARTITIONS_VERBOSE, - EXPLAIN_PARTITIONS_AS_COMMENT -}; -uint explain_filename(THD* thd, const char *from, char *to, uint to_length, - enum_explain_filename_mode explain_mode); -uint filename_to_tablename(const char *from, char *to, uint to_length); -uint tablename_to_filename(const char *from, char *to, uint to_length); -uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length); -#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ -#ifdef MYSQL_SERVER -uint build_table_filename(char *buff, size_t bufflen, const char *db, - const char *table, const char *ext, uint flags); -const char *get_canonical_filename(handler *file, const char *path, - char *tmp_path); - -#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#" -#define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9 - -uint build_table_shadow_filename(char *buff, size_t bufflen, - ALTER_PARTITION_PARAM_TYPE *lpt); -/* Flags for conversion functions. */ -#define FN_FROM_IS_TMP (1 << 0) -#define FN_TO_IS_TMP (1 << 1) -#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP) -#define NO_FRM_RENAME (1 << 2) -#define FRM_ONLY (1 << 3) - -/* from hostname.cc */ -bool ip_to_hostname(struct sockaddr_storage *ip_storage, - const char *ip_string, - char **hostname, uint *connect_errors); -void inc_host_errors(const char *ip_string); -void reset_host_errors(const char *ip_string); -bool hostname_cache_init(); -void hostname_cache_free(); -void hostname_cache_refresh(void); - -/* sql_cache.cc */ -extern bool sql_cache_init(); -extern void sql_cache_free(); -extern int sql_cache_hit(THD *thd, char *inBuf, uint length); - -/* item_func.cc */ -Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, - LEX_STRING component); -int get_var_with_binlog(THD *thd, enum_sql_command sql_command, - LEX_STRING &name, user_var_entry **out_entry); -/* log.cc */ -bool flush_error_log(void); - -/* sql_list.cc */ -void free_list(I_List <i_string_pair> *list); -void free_list(I_List <i_string> *list); - -/* sql_yacc.cc */ -#ifndef DBUG_OFF -extern void turn_parser_debug_on(); -#endif - -/* frm_crypt.cc */ -#ifdef HAVE_CRYPTED_FRM -SQL_CRYPT *get_crypt_for_frm(void); -#endif - -/* password.c */ -extern "C" void my_make_scrambled_password_323(char *to, const char *password, - size_t pass_len); -extern "C" void my_make_scrambled_password(char *to, const char *password, - size_t pass_len); - -#include "sql_view.h" - -/* Some inline functions for more speed */ - -inline bool add_item_to_list(THD *thd, Item *item) -{ - return thd->lex->current_select->add_item_to_list(thd, item); -} - -inline bool add_value_to_list(THD *thd, Item *value) -{ - return thd->lex->value_list.push_back(value); -} - -inline bool add_order_to_list(THD *thd, Item *item, bool asc) -{ - return thd->lex->current_select->add_order_to_list(thd, item, asc); -} - -inline bool add_group_to_list(THD *thd, Item *item, bool asc) -{ - return thd->lex->current_select->add_group_to_list(thd, item, asc); -} - -inline void mark_as_null_row(TABLE *table) -{ - table->null_row=1; - table->status|=STATUS_NULL_ROW; - bfill(table->null_flags,table->s->null_bytes,255); -} - -inline void table_case_convert(char * name, uint length) -{ - if (lower_case_table_names) - files_charset_info->cset->casedn(files_charset_info, - name, length, name, length); -} - -inline const char *table_case_name(HA_CREATE_INFO *info, const char *name) -{ - return ((lower_case_table_names == 2 && info->alias) ? info->alias : name); -} - -inline ulong sql_rnd_with_mutex() -{ - mysql_mutex_lock(&LOCK_thread_count); - ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */ - mysql_mutex_unlock(&LOCK_thread_count); - return tmp; -} - -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); - -Item * all_any_subquery_creator(Item *left_expr, - chooser_compare_func_creator cmp, - bool all, - SELECT_LEX *select_lex); - -/** - clean/setup table fields and map. - - @param table TABLE structure pointer (which should be setup) - @param table_list TABLE_LIST structure pointer (owner of TABLE) - @param tablenr table number -*/ - - -inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr) -{ - table->used_fields= 0; - table->const_table= 0; - table->null_row= 0; - table->status= STATUS_NO_RECORD; - table->maybe_null= table_list->outer_join; - TABLE_LIST *embedding= table_list->embedding; - while (!table->maybe_null && embedding) - { - table->maybe_null= embedding->outer_join; - embedding= embedding->embedding; - } - table->tablenr= tablenr; - table->map= (table_map) 1 << tablenr; - table->force_index= table_list->force_index; - table->force_index_order= table->force_index_group= 0; - table->covering_keys= table->s->keys_for_keyread; - table->merge_keys.clear_all(); -} - - -/** - convert a hex digit into number. -*/ - -inline int hexchar_to_int(char c) -{ - if (c <= '9' && c >= '0') - return c-'0'; - c|=32; - if (c <= 'f' && c >= 'a') - return c-'a'+10; - return -1; -} - -/** - return true if the table was created explicitly. -*/ -inline bool is_user_table(TABLE * table) -{ - const char *name= table->s->table_name.str; - return strncmp(name, tmp_file_prefix, tmp_file_prefix_length); -} - -/* - Some functions that are different in the embedded library and the normal - server -*/ - -#ifndef EMBEDDED_LIBRARY -extern "C" void unireg_abort(int exit_code) __attribute__((noreturn)); -void kill_delayed_threads(void); -#else -extern "C" void unireg_clear(int exit_code); -#define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0) -inline void kill_delayed_threads(void) {} -#endif - -bool check_stack_overrun(THD *thd, long margin, uchar *dummy); - -/* This must match the path length limit in the ER_NOT_RW_DIR error msg. */ -#define ER_NOT_RW_DIR_PATHSIZE 200 -bool is_usable_directory(THD *thd, const char *varname, - const char *path, const char *prefix); - -/* Used by handlers to store things in schema tables */ -#define IS_FILES_FILE_ID 0 -#define IS_FILES_FILE_NAME 1 -#define IS_FILES_FILE_TYPE 2 -#define IS_FILES_TABLESPACE_NAME 3 -#define IS_FILES_TABLE_CATALOG 4 -#define IS_FILES_TABLE_SCHEMA 5 -#define IS_FILES_TABLE_NAME 6 -#define IS_FILES_LOGFILE_GROUP_NAME 7 -#define IS_FILES_LOGFILE_GROUP_NUMBER 8 -#define IS_FILES_ENGINE 9 -#define IS_FILES_FULLTEXT_KEYS 10 -#define IS_FILES_DELETED_ROWS 11 -#define IS_FILES_UPDATE_COUNT 12 -#define IS_FILES_FREE_EXTENTS 13 -#define IS_FILES_TOTAL_EXTENTS 14 -#define IS_FILES_EXTENT_SIZE 15 -#define IS_FILES_INITIAL_SIZE 16 -#define IS_FILES_MAXIMUM_SIZE 17 -#define IS_FILES_AUTOEXTEND_SIZE 18 -#define IS_FILES_CREATION_TIME 19 -#define IS_FILES_LAST_UPDATE_TIME 20 -#define IS_FILES_LAST_ACCESS_TIME 21 -#define IS_FILES_RECOVER_TIME 22 -#define IS_FILES_TRANSACTION_COUNTER 23 -#define IS_FILES_VERSION 24 -#define IS_FILES_ROW_FORMAT 25 -#define IS_FILES_TABLE_ROWS 26 -#define IS_FILES_AVG_ROW_LENGTH 27 -#define IS_FILES_DATA_LENGTH 28 -#define IS_FILES_MAX_DATA_LENGTH 29 -#define IS_FILES_INDEX_LENGTH 30 -#define IS_FILES_DATA_FREE 31 -#define IS_FILES_CREATE_TIME 32 -#define IS_FILES_UPDATE_TIME 33 -#define IS_FILES_CHECK_TIME 34 -#define IS_FILES_CHECKSUM 35 -#define IS_FILES_STATUS 36 -#define IS_FILES_EXTRA 37 - -#define IS_TABLESPACES_TABLESPACE_NAME 0 -#define IS_TABLESPACES_ENGINE 1 -#define IS_TABLESPACES_TABLESPACE_TYPE 2 -#define IS_TABLESPACES_LOGFILE_GROUP_NAME 3 -#define IS_TABLESPACES_EXTENT_SIZE 4 -#define IS_TABLESPACES_AUTOEXTEND_SIZE 5 -#define IS_TABLESPACES_MAXIMUM_SIZE 6 -#define IS_TABLESPACES_NODEGROUP_ID 7 -#define IS_TABLESPACES_TABLESPACE_COMMENT 8 - -void init_fill_schema_files_row(TABLE* table); -bool schema_table_store_record(THD *thd, TABLE *table); - -/* sql/item_create.cc */ -int item_create_init(); -void item_create_cleanup(); - -bool show_create_trigger(THD *thd, const sp_name *trg_name); - -inline void lex_string_set(LEX_STRING *lex_str, const char *c_str) -{ - lex_str->str= (char *) c_str; - lex_str->length= strlen(c_str); -} - -bool load_charset(MEM_ROOT *mem_root, - Field *field, - CHARSET_INFO *dflt_cs, - CHARSET_INFO **cs); - -bool load_collation(MEM_ROOT *mem_root, - Field *field, - CHARSET_INFO *dflt_cl, - CHARSET_INFO **cl); - -#define LONG_TIMEOUT ((ulong) 3600L*24L*365L) - -/** - only options that need special treatment in get_one_option() deserve - to be listed below -*/ -enum options_mysqld -{ - OPT_to_set_the_start_number=256, - OPT_BIND_ADDRESS, - OPT_BINLOG_DO_DB, - OPT_BINLOG_FORMAT, - OPT_BINLOG_IGNORE_DB, - OPT_BIN_LOG, - OPT_BOOTSTRAP, - OPT_CONSOLE, - OPT_DEBUG_SYNC_TIMEOUT, - OPT_ISAM_LOG, - OPT_KEY_BUFFER_SIZE, - OPT_KEY_CACHE_AGE_THRESHOLD, - OPT_KEY_CACHE_BLOCK_SIZE, - OPT_KEY_CACHE_DIVISION_LIMIT, - OPT_LOWER_CASE_TABLE_NAMES, - OPT_ONE_THREAD, - OPT_POOL_OF_THREADS, - OPT_REPLICATE_DO_DB, - OPT_REPLICATE_DO_TABLE, - OPT_REPLICATE_IGNORE_DB, - OPT_REPLICATE_IGNORE_TABLE, - OPT_REPLICATE_REWRITE_DB, - OPT_REPLICATE_WILD_DO_TABLE, - OPT_REPLICATE_WILD_IGNORE_TABLE, - OPT_SAFE, - OPT_SERVER_ID, - OPT_SKIP_HOST_CACHE, - OPT_SKIP_NEW, - OPT_SKIP_PRIOR, - OPT_SKIP_RESOLVE, - OPT_SKIP_STACK_TRACE, - OPT_SLOW_QUERY_LOG, - OPT_SSL_CA, - OPT_SSL_CAPATH, - OPT_SSL_CERT, - OPT_SSL_CIPHER, - OPT_SSL_KEY, - OPT_WANT_CORE, - OPT_ENGINE_CONDITION_PUSHDOWN, - OPT_LOG_ERROR -}; - -#endif /* MYSQL_SERVER */ -extern "C" int test_if_data_home_dir(const char *dir); - -#endif /* MYSQL_CLIENT */ - -#ifdef MYSQL_SERVER -#ifdef HAVE_PSI_INTERFACE -#ifdef HAVE_MMAP -extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active, - key_LOCK_pool; -#endif /* HAVE_MMAP */ - -#ifdef HAVE_OPENSSL -extern PSI_mutex_key key_LOCK_des_key_file; -#endif - -extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_prep_xids, - key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, - key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, - key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, - key_LOCK_gdl, key_LOCK_global_read_lock, key_LOCK_global_system_variables, - key_LOCK_lock_db, key_LOCK_logger, key_LOCK_manager, key_LOCK_mapped_file, - key_LOCK_mysql_create_db, key_LOCK_open, key_LOCK_prepared_stmt_count, - key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, - key_LOCK_table_share, key_LOCK_thd_data, - key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, - key_master_info_data_lock, key_master_info_run_lock, - key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock, - key_relay_log_info_log_space_lock, key_relay_log_info_run_lock, - key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data, key_LOCK_error_messages, - key_LOCK_thread_count; - -extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, - key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave, - key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock; - -#ifdef HAVE_MMAP -extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; -#endif /* HAVE_MMAP */ - -extern PSI_cond_key key_BINLOG_COND_prep_xids, key_BINLOG_update_cond, - key_COND_cache_status_changed, key_COND_global_read_lock, key_COND_manager, - key_COND_refresh, key_COND_rpl_status, key_COND_server_started, - key_delayed_insert_cond, key_delayed_insert_cond_client, - key_item_func_sleep_cond, key_master_info_data_cond, - key_master_info_start_cond, key_master_info_stop_cond, - key_relay_log_info_data_cond, key_relay_log_info_log_space_cond, - key_relay_log_info_start_cond, key_relay_log_info_stop_cond, - key_TABLE_SHARE_cond, key_user_level_lock_cond, - key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; - -extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, - key_thread_handle_manager, key_thread_kill_server, key_thread_main, - key_thread_one_connection, key_thread_signal_hand; - -#ifdef HAVE_MMAP -extern PSI_file_key key_file_map; -#endif /* HAVE_MMAP */ - -extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, - key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, - key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, - key_file_loadfile, key_file_log_event_data, key_file_log_event_info, - key_file_master_info, key_file_misc, key_file_MYSQL_LOG, key_file_partition, - key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, - key_file_trg, key_file_trn, key_file_init; - -void init_server_psi_keys(); -#endif /* HAVE_PSI_INTERFACE */ -#endif /* MYSQL_SERVER */ - - -#endif /* MYSQL_PRIV_H */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 37713992a90..b35e2545a18 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -13,7 +13,43 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include <signal.h> +#ifndef __WIN__ +#include <netdb.h> // getservbyname, servent +#endif +#include "sql_parse.h" // test_if_data_home_dir +#include "sql_cache.h" // query_cache, query_cache_* +#include "sql_locale.h" // MY_LOCALES, my_locales, my_locale_by_name +#include "sql_show.h" // free_status_vars, add_status_vars, + // reset_status_vars +#include "strfunc.h" // find_set_from_flags +#include "parse_file.h" // File_parser_dummy_hook +#include "sql_db.h" // my_database_names_free, + // my_database_names_init +#include "sql_table.h" // release_ddl_log, execute_ddl_log_recovery +#include "sql_connect.h" // free_max_user_conn, init_max_user_conn, + // handle_one_connection +#include "sql_time.h" // known_date_time_formats, + // get_date_time_format_str, + // date_time_format_make +#include "tztime.h" // my_tz_free, my_tz_init, my_tz_SYSTEM +#include "hostname.h" // hostname_cache_free, hostname_cache_init +#include "sql_acl.h" // acl_free, grant_free, acl_init, + // grant_init +#include "sql_base.h" // table_def_free, table_def_init, + // cached_open_tables, + // cached_table_definitions +#include "sql_test.h" // mysql_print_status +#include "item_create.h" // item_create_cleanup, item_create_init +#include "sql_servers.h" // servers_free, servers_init +#include "init.h" // unireg_init +#include "derror.h" // init_errmessage +#include "derror.h" // init_errmessage +#include "des_key_file.h" // load_des_key_file +#include "sql_manager.h" // stop_handle_manager, start_handle_manager #include <m_ctype.h> #include <my_dir.h> #include <my_bit.h> @@ -921,7 +957,9 @@ static void openssl_lock(int, openssl_lock_t *, const char *, int); static unsigned long openssl_id_function(); #endif char *des_key_file; +#ifndef EMBEDDED_LIBRARY struct st_VioSSLFd *ssl_acceptor_fd; +#endif #endif /* HAVE_OPENSSL */ /** @@ -967,8 +1005,8 @@ static void clean_up_mutexes(void); static void wait_for_signal_thread_to_end(void); static void create_pid_file(); static void mysqld_exit(int exit_code) __attribute__((noreturn)); -static void end_ssl(); #endif +static void end_ssl(); #ifndef EMBEDDED_LIBRARY @@ -1456,6 +1494,7 @@ void clean_up(bool print_message) item_user_lock_free(); lex_free(); /* Free some memory */ item_create_cleanup(); + free_charsets(); if (!opt_noacl) { #ifdef HAVE_DLOPEN @@ -1487,9 +1526,7 @@ void clean_up(bool print_message) #endif delete binlog_filter; delete rpl_filter; -#ifndef EMBEDDED_LIBRARY end_ssl(); -#endif vio_end(); #ifdef USE_REGEX my_regex_end(); @@ -3879,11 +3916,10 @@ static void openssl_lock(int mode, openssl_lock_t *lock, const char *file, #endif /* HAVE_OPENSSL */ -#ifndef EMBEDDED_LIBRARY - static void init_ssl() { #ifdef HAVE_OPENSSL +#ifndef EMBEDDED_LIBRARY if (opt_use_ssl) { enum enum_ssl_init_error error= SSL_INITERR_NOERROR; @@ -3905,6 +3941,9 @@ static void init_ssl() { have_ssl= SHOW_OPTION_DISABLED; } +#else + have_ssl= SHOW_OPTION_DISABLED; +#endif /* ! EMBEDDED_LIBRARY */ if (des_key_file) load_des_key_file(des_key_file); #endif /* HAVE_OPENSSL */ @@ -3914,16 +3953,16 @@ static void init_ssl() static void end_ssl() { #ifdef HAVE_OPENSSL +#ifndef EMBEDDED_LIBRARY if (ssl_acceptor_fd) { free_vio_ssl_acceptor_fd(ssl_acceptor_fd); ssl_acceptor_fd= 0; } +#endif /* ! EMBEDDED_LIBRARY */ #endif /* HAVE_OPENSSL */ } -#endif /* EMBEDDED_LIBRARY */ - static int init_server_components() { @@ -6123,7 +6162,10 @@ thread is in the master's binlogs.", "Tells the slave thread to not replicate to the specified database. To specify more than one database to ignore, use the directive multiple times, once for each database. This option will not work if you use cross database updates. If you need cross database updates to work, make sure you have 3.23.28 or later, and use replicate-wild-ignore-table=db_name.%. ", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE, - "Tells the slave thread to not replicate to the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. This will work for cross-datbase updates, in contrast to replicate-ignore-db.", + "Tells the slave thread to not replicate to the specified table. To specify " + "more than one table to ignore, use the directive multiple times, once for " + "each table. This will work for cross-database updates, in contrast to " + "replicate-ignore-db.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB, "Updates to a database with a different name than the original. Example: replicate-rewrite-db=master_db_name->slave_db_name.", @@ -6394,7 +6436,7 @@ static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) return 0; } -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* Functions relying on CTX */ static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff) { @@ -6650,7 +6692,7 @@ static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) return 0; } -#endif /* HAVE_OPENSSL */ +#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ /* @@ -6741,6 +6783,7 @@ SHOW_VAR status_vars[]= { {"Sort_rows", (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS}, {"Sort_scan", (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS}, #ifdef HAVE_OPENSSL +#ifndef EMBEDDED_LIBRARY {"Ssl_accept_renegotiates", (char*) &show_ssl_ctx_sess_accept_renegotiate, SHOW_FUNC}, {"Ssl_accepts", (char*) &show_ssl_ctx_sess_accept, SHOW_FUNC}, {"Ssl_callback_cache_hits", (char*) &show_ssl_ctx_sess_cb_hits, SHOW_FUNC}, @@ -6764,6 +6807,7 @@ SHOW_VAR status_vars[]= { {"Ssl_verify_depth", (char*) &show_ssl_get_verify_depth, SHOW_FUNC}, {"Ssl_verify_mode", (char*) &show_ssl_get_verify_mode, SHOW_FUNC}, {"Ssl_version", (char*) &show_ssl_get_version, SHOW_FUNC}, +#endif #endif /* HAVE_OPENSSL */ {"Table_locks_immediate", (char*) &locks_immediate, SHOW_LONG}, {"Table_locks_waited", (char*) &locks_waited, SHOW_LONG}, @@ -7063,8 +7107,10 @@ static int mysql_init_variables(void) #endif #ifdef HAVE_OPENSSL des_key_file = 0; +#ifndef EMBEDDED_LIBRARY ssl_acceptor_fd= 0; -#endif +#endif /* ! EMBEDDED_LIBRARY */ +#endif /* HAVE_OPENSSL */ #ifdef HAVE_SMEM shared_memory_base_name= default_shared_memory_base_name; #endif diff --git a/sql/mysqld.h b/sql/mysqld.h new file mode 100644 index 00000000000..2547100d8ff --- /dev/null +++ b/sql/mysqld.h @@ -0,0 +1,510 @@ +/* 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 MYSQLD_INCLUDED +#define MYSQLD_INCLUDED + +#include "my_global.h" /* MYSQL_PLUGIN_IMPORT, FN_REFLEN, FN_EXTLEN */ +#include "sql_bitmap.h" /* Bitmap */ +#include "my_decimal.h" /* my_decimal */ +#include "mysql_com.h" /* SERVER_VERSION_LENGTH */ +#include "my_atomic.h" /* my_atomic_rwlock_t */ +#include "mysql/psi/mysql_file.h" /* MYSQL_FILE */ +#include "sql_list.h" /* I_List */ + +class THD; +struct handlerton; +class Time_zone; + +class scheduler_functions; + +typedef struct st_mysql_const_lex_string LEX_CSTRING; +typedef struct st_mysql_show_var SHOW_VAR; + +/* + This forward declaration is used from C files where the real + definition is included before. Since C does not allow repeated + typedef declarations, even when identical, the definition may not be + repeated. +*/ +#ifndef CHARSET_INFO_DEFINED +typedef struct charset_info_st CHARSET_INFO; +#endif /* CHARSET_INFO_DEFINED */ + +#if MAX_INDEXES <= 64 +typedef Bitmap<64> key_map; /* Used for finding keys */ +#else +typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */ +#endif + + /* Bits from testflag */ +#define TEST_PRINT_CACHED_TABLES 1 +#define TEST_NO_KEY_GROUP 2 +#define TEST_MIT_THREAD 4 +#define TEST_BLOCKING 8 +#define TEST_KEEP_TMP_TABLES 16 +#define TEST_READCHECK 64 /**< Force use of readcheck */ +#define TEST_NO_EXTRA 128 +#define TEST_CORE_ON_SIGNAL 256 /**< Give core if signal */ +#define TEST_NO_STACKTRACE 512 +#define TEST_SIGINT 1024 /**< Allow sigint on threads */ +#define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in + some places */ +/* Function prototypes */ +void kill_mysql(void); +void close_connection(THD *thd, uint errcode, bool lock); +void handle_connection_in_main_thread(THD *thd); +void create_thread_to_handle_connection(THD *thd); +void unlink_thd(THD *thd); +bool one_thread_per_connection_end(THD *thd, bool put_in_cache); +void flush_thread_cache(); +void refresh_status(THD *thd); + +extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info; +extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ; +extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *national_charset_info; +extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *table_alias_charset; + +extern TYPELIB log_output_typelib; +extern const char *log_output_names[]; + +/** + Character set of the buildin error messages loaded from errmsg.sys. +*/ +extern CHARSET_INFO *error_message_charset_info; + +extern CHARSET_INFO *character_set_filesystem; + +extern MY_BITMAP temp_pool; +extern bool opt_large_files, server_id_supplied; +extern bool opt_update_log, opt_bin_log, opt_error_log; +extern my_bool opt_log, opt_slow_log; +extern my_bool opt_backup_history_log; +extern my_bool opt_backup_progress_log; +extern ulonglong log_output_options; +extern ulong log_backup_output_options; +extern my_bool opt_log_queries_not_using_indexes; +extern bool opt_disable_networking, opt_skip_show_db; +extern bool opt_ignore_builtin_innodb; +extern my_bool opt_character_set_client_handshake; +extern bool volatile abort_loop; +extern bool in_bootstrap; +extern uint volatile thread_count, global_read_lock; +extern uint connection_count; +extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types; +extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap; +extern my_bool opt_slave_compressed_protocol, use_temp_pool; +extern uint slave_exec_mode_options; +extern ulonglong slave_type_conversions_options; +extern my_bool opt_readonly, lower_case_file_system; +extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs; +extern my_bool opt_secure_auth; +extern char* opt_secure_file_priv; +extern char* opt_secure_backup_file_priv; +extern size_t opt_secure_backup_file_priv_len; +extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements; +extern my_bool sp_automatic_privileges, opt_noacl; +extern my_bool opt_old_style_user_limits, trust_function_creators; +extern uint opt_crash_binlog_innodb; +extern char *shared_memory_base_name, *mysqld_unix_port; +extern my_bool opt_enable_shared_memory; +extern char *default_tz_name; +extern Time_zone *default_tz; +extern char *default_storage_engine; +extern bool opt_endinfo, using_udf_functions; +extern my_bool locked_in_memory; +extern bool opt_using_transactions; +extern ulong current_pid; +extern ulong expire_logs_days; +extern my_bool relay_log_recovery; +extern uint sync_binlog_period, sync_relaylog_period, + sync_relayloginfo_period, sync_masterinfo_period; +extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size; +extern ulong tc_log_page_waits; +extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb; +extern my_bool relay_log_recovery; +extern uint test_flags,select_errors,ha_open_options; +extern uint protocol_version, mysqld_port, dropping_tables; +extern uint delay_key_write_options; +extern char *opt_logname, *opt_slow_logname; +extern char *opt_backup_history_logname, *opt_backup_progress_logname, + *opt_backup_settings_name; +extern const char *log_output_str; +extern const char *log_backup_output_str; +extern char *mysql_home_ptr, *pidfile_name_ptr; +extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; +extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; +extern char default_logfile_name[FN_REFLEN]; +extern char log_error_file[FN_REFLEN], *opt_tc_log_file; +extern const double log_10[309]; +extern ulonglong keybuff_size; +extern ulonglong thd_startup_options; +extern ulong thread_id; +extern ulong binlog_cache_use, binlog_cache_disk_use; +extern ulong aborted_threads,aborted_connects; +extern ulong delayed_insert_timeout; +extern ulong delayed_insert_limit, delayed_queue_size; +extern ulong delayed_insert_threads, delayed_insert_writes; +extern ulong delayed_rows_in_use,delayed_insert_errors; +extern ulong slave_open_temp_tables; +extern ulong query_cache_size, query_cache_min_res_unit; +extern ulong slow_launch_threads, slow_launch_time; +extern ulong table_cache_size, table_def_size; +extern MYSQL_PLUGIN_IMPORT ulong max_connections; +extern ulong max_connect_errors, connect_timeout; +extern my_bool slave_allow_batching; +extern my_bool allow_slave_start; +extern LEX_CSTRING reason_slave_blocked; +extern ulong slave_trans_retries; +extern uint slave_net_timeout; +extern uint max_user_connections; +extern ulong what_to_log,flush_time; +extern ulong query_buff_size; +extern ulong max_prepared_stmt_count, prepared_stmt_count; +extern ulong binlog_cache_size, open_files_limit; +extern ulonglong max_binlog_cache_size; +extern ulong max_binlog_size, max_relay_log_size; +extern ulong opt_binlog_rows_event_max_size; +extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size; +extern ulong back_log; +extern char language[FN_REFLEN]; +extern ulong server_id, concurrency; +extern time_t server_start_time, flush_status_time; +extern char *opt_mysql_tmpdir, mysql_charsets_dir[]; +extern int mysql_unpacked_real_data_home_len; +extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list; +extern const char *first_keyword, *delayed_user, *binary_keyword; +extern MYSQL_PLUGIN_IMPORT const char *my_localhost; +extern MYSQL_PLUGIN_IMPORT const char **errmesg; /* Error messages */ +extern const char *myisam_recover_options_str; +extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond; +extern SHOW_VAR status_vars[]; +extern struct system_variables max_system_variables; +extern struct system_status_var global_status_var; +extern struct rand_struct sql_rand; +extern const char *opt_date_time_formats[]; +extern handlerton *partition_hton; +extern handlerton *myisam_hton; +extern handlerton *heap_hton; +extern const char *load_default_groups[]; +extern struct my_option my_long_options[]; +extern int mysqld_server_started; +extern int orig_argc; +extern char **orig_argv; +extern pthread_attr_t connection_attrib; +extern MYSQL_FILE *bootstrap_file; +extern my_bool old_mode; +extern LEX_STRING opt_init_connect, opt_init_slave; +extern int bootstrap_error; +extern FILE *stderror_file; +extern I_List<THD> threads; +extern char err_shared_dir[]; +extern scheduler_functions thread_scheduler; +extern TYPELIB thread_handling_typelib; +extern my_decimal decimal_zero; + +extern pthread_key(MEM_ROOT**,THR_MALLOC); + +#ifdef HAVE_PSI_INTERFACE +#ifdef HAVE_MMAP +extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active, + key_LOCK_pool; +#endif /* HAVE_MMAP */ + +#ifdef HAVE_OPENSSL +extern PSI_mutex_key key_LOCK_des_key_file; +#endif + +extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_prep_xids, + key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, + key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, + key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, + key_LOCK_gdl, key_LOCK_global_read_lock, key_LOCK_global_system_variables, + key_LOCK_lock_db, key_LOCK_logger, key_LOCK_manager, key_LOCK_mapped_file, + key_LOCK_mysql_create_db, key_LOCK_open, key_LOCK_prepared_stmt_count, + key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, + key_LOCK_table_share, key_LOCK_thd_data, + key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, + key_master_info_data_lock, key_master_info_run_lock, + key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock, + key_relay_log_info_log_space_lock, key_relay_log_info_run_lock, + key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data, key_LOCK_error_messages, + key_LOCK_thread_count; + +extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, + key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave, + key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock; + +#ifdef HAVE_MMAP +extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; +#endif /* HAVE_MMAP */ + +extern PSI_cond_key key_BINLOG_COND_prep_xids, key_BINLOG_update_cond, + key_COND_cache_status_changed, key_COND_global_read_lock, key_COND_manager, + key_COND_refresh, key_COND_rpl_status, key_COND_server_started, + key_delayed_insert_cond, key_delayed_insert_cond_client, + key_item_func_sleep_cond, key_master_info_data_cond, + key_master_info_start_cond, key_master_info_stop_cond, + key_relay_log_info_data_cond, key_relay_log_info_log_space_cond, + key_relay_log_info_start_cond, key_relay_log_info_stop_cond, + key_TABLE_SHARE_cond, key_user_level_lock_cond, + key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; + +extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, + key_thread_handle_manager, key_thread_kill_server, key_thread_main, + key_thread_one_connection, key_thread_signal_hand; + +#ifdef HAVE_MMAP +extern PSI_file_key key_file_map; +#endif /* HAVE_MMAP */ + +extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, + key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, + key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, + key_file_loadfile, key_file_log_event_data, key_file_log_event_info, + key_file_master_info, key_file_misc, key_file_MYSQL_LOG, key_file_partition, + key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, + key_file_trg, key_file_trn, key_file_init; + +void init_server_psi_keys(); +#endif /* HAVE_PSI_INTERFACE */ + +#ifndef __WIN__ +extern pthread_t signal_thread; +#endif + +#ifdef HAVE_OPENSSL +extern struct st_VioSSLFd * ssl_acceptor_fd; +#endif /* HAVE_OPENSSL */ + +/* + The following variables were under INNODB_COMPABILITY_HOOKS + */ +extern my_bool opt_large_pages; +extern uint opt_large_page_size; +extern char lc_messages_dir[FN_REFLEN]; +extern char *lc_messages_dir_ptr, *log_error_file_ptr; +extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN]; +extern MYSQL_PLUGIN_IMPORT uint reg_ext_length; +extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names; +extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded; +extern ulong specialflag; +extern uint mysql_data_home_len; +extern uint mysql_real_data_home_len; +extern const char *mysql_real_data_home_ptr; +extern uint thread_handling; +extern MYSQL_PLUGIN_IMPORT char *mysql_data_home; +extern char server_version[SERVER_VERSION_LENGTH]; +extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[]; +extern char mysql_unpacked_real_data_home[]; +extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables; +extern char default_logfile_name[FN_REFLEN]; +extern char err_shared_dir[]; + +#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list)) + +extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty; +extern MYSQL_PLUGIN_IMPORT key_map key_map_full; /* Should be threaded as const */ + +/* + Server mutex locks and condition variables. + */ +extern mysql_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_lock_db, + LOCK_mapped_file, LOCK_user_locks, LOCK_status, + LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator, + LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, + LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock, + LOCK_global_system_variables, LOCK_user_conn, + LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count; +extern MYSQL_PLUGIN_IMPORT mysql_mutex_t LOCK_thread_count; +#ifdef HAVE_OPENSSL +extern mysql_mutex_t LOCK_des_key_file; +#endif +extern mysql_mutex_t LOCK_server_started; +extern mysql_cond_t COND_server_started; +extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; +extern mysql_rwlock_t LOCK_system_variables_hash; +extern mysql_cond_t COND_thread_count; +extern mysql_cond_t COND_refresh, COND_manager; +extern mysql_cond_t COND_global_read_lock; +extern int32 thread_running; +extern my_atomic_rwlock_t thread_running_lock; + +extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher, + *opt_ssl_key; + +extern MYSQL_PLUGIN_IMPORT pthread_key(THD*, THR_THD); + +/** + only options that need special treatment in get_one_option() deserve + to be listed below +*/ +enum options_mysqld +{ + OPT_to_set_the_start_number=256, + OPT_BIND_ADDRESS, + OPT_BINLOG_DO_DB, + OPT_BINLOG_FORMAT, + OPT_BINLOG_IGNORE_DB, + OPT_BIN_LOG, + OPT_BOOTSTRAP, + OPT_CONSOLE, + OPT_DEBUG_SYNC_TIMEOUT, + OPT_DELAY_KEY_WRITE_ALL, + OPT_ISAM_LOG, + OPT_KEY_BUFFER_SIZE, + OPT_KEY_CACHE_AGE_THRESHOLD, + OPT_KEY_CACHE_BLOCK_SIZE, + OPT_KEY_CACHE_DIVISION_LIMIT, + OPT_LOWER_CASE_TABLE_NAMES, + OPT_ONE_THREAD, + OPT_POOL_OF_THREADS, + OPT_REPLICATE_DO_DB, + OPT_REPLICATE_DO_TABLE, + OPT_REPLICATE_IGNORE_DB, + OPT_REPLICATE_IGNORE_TABLE, + OPT_REPLICATE_REWRITE_DB, + OPT_REPLICATE_WILD_DO_TABLE, + OPT_REPLICATE_WILD_IGNORE_TABLE, + OPT_SAFE, + OPT_SERVER_ID, + OPT_SKIP_HOST_CACHE, + OPT_SKIP_LOCK, + OPT_SKIP_NEW, + OPT_SKIP_PRIOR, + OPT_SKIP_RESOLVE, + OPT_SKIP_STACK_TRACE, + OPT_SKIP_SYMLINKS, + OPT_SLOW_QUERY_LOG, + OPT_SSL_CA, + OPT_SSL_CAPATH, + OPT_SSL_CERT, + OPT_SSL_CIPHER, + OPT_SSL_KEY, + OPT_UPDATE_LOG, + OPT_WANT_CORE, + OPT_ENGINE_CONDITION_PUSHDOWN, + OPT_LOG_ERROR +}; + + +/** + Query type constants. + + QT_ORDINARY -- ordinary SQL query. + QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without + character set introducers). +*/ +enum enum_query_type +{ + QT_ORDINARY, + QT_IS +}; + +/* query_id */ +typedef int64 query_id_t; +extern query_id_t global_query_id; +extern my_atomic_rwlock_t global_query_id_lock; + +void unireg_end(void) __attribute__((noreturn)); + +/* increment query_id and return it. */ +inline query_id_t next_query_id() +{ + query_id_t id; + my_atomic_rwlock_wrlock(&global_query_id_lock); + id= my_atomic_add64(&global_query_id, 1); + my_atomic_rwlock_wrunlock(&global_query_id_lock); + return (id+1); +} + +inline query_id_t get_query_id() +{ + query_id_t id; + my_atomic_rwlock_wrlock(&global_query_id_lock); + id= my_atomic_load64(&global_query_id); + my_atomic_rwlock_wrunlock(&global_query_id_lock); + return id; +} + + +/* + TODO: Replace this with an inline function. + */ +#ifndef EMBEDDED_LIBRARY +extern "C" void unireg_abort(int exit_code) __attribute__((noreturn)); +#else +extern "C" void unireg_clear(int exit_code); +#define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0) +#endif + +inline void table_case_convert(char * name, uint length) +{ + if (lower_case_table_names) + files_charset_info->cset->casedn(files_charset_info, + name, length, name, length); +} + +inline ulong sql_rnd_with_mutex() +{ + mysql_mutex_lock(&LOCK_thread_count); + ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */ + mysql_mutex_unlock(&LOCK_thread_count); + return tmp; +} + +inline int32 +inc_thread_running() +{ + int32 num_thread_running; + my_atomic_rwlock_wrlock(&thread_running_lock); + num_thread_running= my_atomic_add32(&thread_running, 1); + my_atomic_rwlock_wrunlock(&thread_running_lock); + return (num_thread_running+1); +} + +inline int32 +dec_thread_running() +{ + int32 num_thread_running; + my_atomic_rwlock_wrlock(&thread_running_lock); + num_thread_running= my_atomic_add32(&thread_running, -1); + my_atomic_rwlock_wrunlock(&thread_running_lock); + return (num_thread_running-1); +} + +inline int32 +get_thread_running() +{ + int32 num_thread_running; + my_atomic_rwlock_wrlock(&thread_running_lock); + num_thread_running= my_atomic_load32(&thread_running); + my_atomic_rwlock_wrunlock(&thread_running_lock); + return num_thread_running; +} + +#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32) +extern "C" THD *_current_thd_noinline(); +#define _current_thd() _current_thd_noinline() +#else +extern pthread_key(THD*, THR_THD); +inline THD *_current_thd(void) +{ + return my_pthread_getspecific_ptr(THD*,THR_THD); +} +#endif +#define current_thd _current_thd() + +#endif /* MYSQLD_INCLUDED */ diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 12cb1224064..fc8655ea2e7 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -39,7 +39,6 @@ */ #include <my_global.h> #include <mysql.h> -#include <mysql_embed.h> #include <mysql_com.h> #include <mysqld_error.h> #include <my_sys.h> @@ -88,7 +87,7 @@ void sql_print_error(const char *format,...); #ifdef MYSQL_SERVER /* The following variables/functions should really not be declared - extern, but as it's hard to include mysql_priv.h here, we have to + extern, but as it's hard to include sql_priv.h here, we have to live with this for a while. */ extern uint test_flags; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 5483ed237db..a46bfcf2d0e 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -65,7 +65,13 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "key.h" // is_key_used, key_copy, key_cmp, key_restore +#include "sql_parse.h" // check_stack_overrun +#include "sql_partition.h" // get_part_id_func, PARTITION_ITERATOR, + // struct partition_info +#include "sql_base.h" // free_io_cache +#include "records.h" // init_read_record, end_read_record #include <m_ctype.h> #include "sql_select.h" diff --git a/sql/opt_range.h b/sql/opt_range.h index 0bb2243080a..3b3b36f7689 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -23,6 +23,20 @@ #pragma interface /* gcc class implementation */ #endif +#include "thr_malloc.h" /* sql_memdup */ +#include "records.h" /* READ_RECORD */ +#include "queues.h" /* QUEUE */ +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" // set_var.h: THD +#include "set_var.h" /* Item */ + +class JOIN; +class Item_sum; + typedef struct st_key_part { uint16 key,part; /* See KEY_PART_INFO for meaning of the next two: */ @@ -742,10 +756,15 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, struct st_table_ref *ref, ha_rows records); uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit); +SQL_SELECT *make_select(TABLE *head, table_map const_tables, + table_map read_tables, COND *conds, + bool allow_null_cond, int *error); #ifdef WITH_PARTITION_STORAGE_ENGINE bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond); void store_key_image_to_rec(Field *field, uchar *ptr, uint len); #endif +extern String null_string; + #endif diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index ae54a462c67..fd2040a4979 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -47,7 +47,8 @@ (assuming a index for column d of table t2 is defined) */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "key.h" // key_cmp_if_same #include "sql_select.h" static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, Field* field, @@ -96,7 +97,7 @@ static ulonglong get_exact_record_count(TABLE_LIST *tables) @param conds WHERE clause @note - This function is only called for queries with sum functions and no + This function is only called for queries with aggregate functions and no GROUP BY part. This means that the result set shall contain a single row only @@ -563,31 +564,57 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order) /** Check whether a condition matches a key to get {MAX|MIN}(field):. - For the index specified by the keyinfo parameter, index that - contains field as its component (field_part), the function - checks whether the condition cond is a conjunction and all its - conjuncts referring to the columns of the same table as column - field are one of the following forms: - - f_i= const_i or const_i= f_i or f_i is null, - where f_i is part of the index - - field {<|<=|>=|>|=} const or const {<|<=|>=|>|=} field - - field between const1 and const2 - - @param[in] max_fl Set to 1 if we are optimising MAX() - @param[in,out] ref Reference to the structure we store the key - value - @param[in] keyinfo Reference to the key info - @param[in] field_part Pointer to the key part for the field - @param[in] cond WHERE condition - @param[in,out] key_part_used Map of matchings parts - @param[in,out] range_fl Says whether including key will be used - @param[out] prefix_len Length of common key part for the range - where MAX/MIN is searched for + For the index specified by the keyinfo parameter and an index that + contains the field as its component (field_part), the function + checks whether + + - the condition cond is a conjunction, + - all of its conjuncts refer to columns of the same table, and + - each conjunct is on one of the following forms: + - f_i = const_i or const_i = f_i or f_i IS NULL, + where f_i is part of the index + - field {<|<=|>=|>|=} const + - const {<|<=|>=|>|=} field + - field BETWEEN const_1 AND const_2 + + As a side-effect, the key value to be used for looking up the MIN/MAX value + is actually stored inside the Field object. An interesting feature is that + the function will find the most restrictive endpoint by over-eager + evaluation of the @c WHERE condition. It continually stores the current + endpoint inside the Field object. For a query such as + + @code + SELECT MIN(a) FROM t1 WHERE a > 3 AND a > 5; + @endcode + + the algorithm will recurse over the conjuction, storing first a 3 in the + field. In the next recursive invocation the expression a > 5 is evaluated + as 3 > 5 (Due to the dual nature of Field objects as value carriers and + field identifiers), which will obviously fail, leading to 5 being stored in + the Field object. + + @param[in] max_fl Set to true if we are optimizing MAX(), + false means we are optimizing %MIN() + @param[in, out] ref Reference to the structure where the function + stores the key value + @param[in] keyinfo Reference to the key info + @param[in] field_part Pointer to the key part for the field + @param[in] cond WHERE condition + @param[in,out] key_part_used Map of matchings parts. The function will output + the set of key parts actually being matched in + this set, yet it relies on the caller to + initialize the value to zero. This is due + to the fact that this value is passed + recursively. + @param[in,out] range_fl Says whether endpoints use strict greater/less + than. + @param[out] prefix_len Length of common key part for the range + where MAX/MIN is searched for @retval - 0 Index can't be used. + false Index can't be used. @retval - 1 We can use index to get MIN/MAX value + true We can use the index to get MIN/MAX value */ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, @@ -624,17 +651,20 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, return 0; // Not operator, can't optimize bool eq_type= 0; // =, <=> or IS NULL + bool is_null_safe_eq= FALSE; // The operator is NULL safe, e.g. <=> bool noeq_type= 0; // < or > bool less_fl= 0; // < or <= - bool is_null= 0; - bool between= 0; + bool is_null= 0; // IS NULL + bool between= 0; // BETWEEN ... AND ... switch (((Item_func*) cond)->functype()) { case Item_func::ISNULL_FUNC: is_null= 1; /* fall through */ case Item_func::EQ_FUNC: + eq_type= TRUE; + break; case Item_func::EQUAL_FUNC: - eq_type= 1; + eq_type= is_null_safe_eq= TRUE; break; case Item_func::LT_FUNC: noeq_type= 1; /* fall through */ @@ -662,6 +692,10 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, if (!simple_pred((Item_func*) cond, args, &inv)) return 0; + if (!is_null_safe_eq && !is_null && + (args[1]->is_null() || (between && args[2]->is_null()))) + return FALSE; + if (inv && !eq_type) less_fl= 1-less_fl; // Convert '<' -> '>' (etc) @@ -712,15 +746,16 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, - field {>|>=} const, when searching for MIN */ - if (is_null) + if (is_null || (is_null_safe_eq && args[1]->is_null())) { part->field->set_null(); *key_ptr= (uchar) 1; } else { - store_val_in_field(part->field, args[between && max_fl ? 2 : 1], - CHECK_FIELD_IGNORE); + /* Update endpoints for MAX/MIN, see function comment. */ + Item *value= args[between && max_fl ? 2 : 1]; + store_val_in_field(part->field, value, CHECK_FIELD_IGNORE); if (part->null_bit) *key_ptr++= (uchar) test(part->field->is_null()); part->field->get_key_image(key_ptr, part->length, Field::itRAW); diff --git a/sql/parse_file.cc b/sql/parse_file.cc index d94ab3d940d..cce0bb262e7 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -20,7 +20,10 @@ Text .frm files management routines */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "parse_file.h" +#include "unireg.h" // CREATE_MODE +#include "sql_table.h" // build_table_filename #include <errno.h> #include <m_ctype.h> #include <my_sys.h> diff --git a/sql/parse_file.h b/sql/parse_file.h index 84647e45927..1833e90cadd 100644 --- a/sql/parse_file.h +++ b/sql/parse_file.h @@ -17,6 +17,14 @@ #ifndef _PARSE_FILE_H_ #define _PARSE_FILE_H_ +#include "my_global.h" // uchar +#include "sql_string.h" // LEX_STRING +#include "sql_list.h" // Sql_alloc + +class THD; + +typedef struct st_mem_root MEM_ROOT; + #define PARSE_FILE_TIMESTAMPLENGTH 19 enum file_opt_type { diff --git a/sql/partition_element.h b/sql/partition_element.h index 73f85ac275f..cefc32ecac4 100644 --- a/sql/partition_element.h +++ b/sql/partition_element.h @@ -16,6 +16,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "my_base.h" /* ha_rows */ +#include "handler.h" /* UNDEF_NODEGROUP */ + /** * An enum and a struct to handle partitioning and subpartitioning. */ diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 65029a817de..f42a8ee2312 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -19,7 +19,13 @@ #pragma implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +// Required to get server definitions for mysql/plugin.h right +#include "sql_plugin.h" +#include "sql_partition.h" /* partition_info.h: LIST_PART_ENTRY */ +#include "partition_info.h" +#include "sql_parse.h" // test_if_data_home_dir +#include "sql_acl.h" // *_ACL #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" diff --git a/sql/password.c b/sql/password.c index 9204c660b77..b77cb618a46 100644 --- a/sql/password.c +++ b/sql/password.c @@ -58,6 +58,7 @@ *****************************************************************************/ +#include <password.h> #include <my_global.h> #include <my_sys.h> #include <m_string.h> diff --git a/sql/procedure.cc b/sql/procedure.cc index c993ba976ac..66e09a42cb4 100644 --- a/sql/procedure.cc +++ b/sql/procedure.cc @@ -20,7 +20,7 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" #include "procedure.h" #include "sql_analyse.h" // Includes procedure #ifdef USE_PROC_RANGE diff --git a/sql/procedure.h b/sql/procedure.h index 25b30ac593d..f34eb228f28 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -23,6 +23,14 @@ #pragma interface /* gcc class implementation */ #endif +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "sql_class.h" /* select_result, set_var.h: THD */ +#include "set_var.h" /* Item */ + #define PROC_NO_SORT 1 /**< Bits in flags */ #define PROC_GROUP 2 /**< proc must have group */ diff --git a/sql/protocol.cc b/sql/protocol.cc index fd943c98bd6..e036f255960 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -24,7 +24,10 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "protocol.h" +#include "sql_class.h" // THD #include <stdarg.h> static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024; @@ -648,8 +651,7 @@ void Protocol::init(THD *thd_arg) void Protocol::end_partial_result_set(THD *thd_arg) { - net_send_eof(thd_arg, thd_arg->server_status, - 0 /* no warnings, we're inside SP */); + net_send_eof(thd_arg, thd_arg->server_status, 0 /* no warnings, we're inside SP */); } diff --git a/sql/protocol.h b/sql/protocol.h index 142f7919d6f..f661c7663e5 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -21,8 +21,10 @@ #endif #include "sql_error.h" +#include "my_decimal.h" /* my_decimal */ class i_string; +class Field; class THD; class Item_param; typedef struct st_mysql_field MYSQL_FIELD; diff --git a/sql/records.cc b/sql/records.cc index c97ffa152dc..d85cb49e013 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -25,7 +25,11 @@ */ #include "records.h" -#include "mysql_priv.h" +#include "sql_priv.h" +#include "records.h" +#include "filesort.h" // filesort_free_buffers +#include "opt_range.h" // SQL_SELECT +#include "sql_class.h" // THD static int rr_quick(READ_RECORD *info); diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 29443eb6e65..cddf798aac0 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -23,15 +23,18 @@ functions like register_slave()) are working. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_parse.h" // check_access #ifdef HAVE_REPLICATION #include "repl_failsafe.h" +#include "sql_acl.h" // REPL_SLAVE_ACL #include "sql_repl.h" #include "slave.h" #include "rpl_mi.h" #include "rpl_filter.h" #include "log_event.h" +#include "sql_db.h" // mysql_create_db #include <mysql.h> #define SLAVE_LIST_CHUNK 128 diff --git a/sql/replication.h b/sql/replication.h index 5e9c09adf31..1c83025e1d6 100644 --- a/sql/replication.h +++ b/sql/replication.h @@ -16,6 +16,8 @@ #ifndef REPLICATION_H #define REPLICATION_H +#include <mysql.h> + typedef struct st_mysql MYSQL; #ifdef __cplusplus diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index 392d8baf50e..63521c0398f 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -13,8 +13,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED by other includes #include "rpl_filter.h" +#include "hash.h" // my_hash_free +#include "table.h" // TABLE_LIST #define TABLE_RULE_HASH_SIZE 16 #define TABLE_RULE_ARR_SIZE 16 diff --git a/sql/rpl_filter.h b/sql/rpl_filter.h index ff7e4081bb1..20f5ce8efc4 100644 --- a/sql/rpl_filter.h +++ b/sql/rpl_filter.h @@ -17,6 +17,12 @@ #define RPL_FILTER_H #include "mysql.h" +#include "sql_list.h" /* I_List */ +#include "hash.h" /* HASH */ + +class String; +struct TABLE_LIST; +typedef struct st_dynamic_array DYNAMIC_ARRAY; typedef struct st_table_rule_ent { diff --git a/sql/rpl_handler.cc b/sql/rpl_handler.cc index 5a406866513..9cb5391075d 100644 --- a/sql/rpl_handler.cc +++ b/sql/rpl_handler.cc @@ -13,7 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "rpl_mi.h" #include "sql_repl.h" diff --git a/sql/rpl_handler.h b/sql/rpl_handler.h index 4fb7b4e035b..bf207e53e2d 100644 --- a/sql/rpl_handler.h +++ b/sql/rpl_handler.h @@ -16,7 +16,7 @@ #ifndef RPL_HANDLER_H #define RPL_HANDLER_H -#include "mysql_priv.h" +#include "sql_priv.h" #include "rpl_mi.h" #include "rpl_rli.h" #include "sql_plugin.h" diff --git a/sql/rpl_injector.cc b/sql/rpl_injector.cc index 08d81e10d59..0f636f5b2ab 100644 --- a/sql/rpl_injector.cc +++ b/sql/rpl_injector.cc @@ -13,9 +13,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED by later includes #include "rpl_injector.h" #include "transaction.h" +#include "sql_parse.h" // begin_trans, end_trans, COMMIT +#include "sql_base.h" // close_thread_tables +#include "log_event.h" // Incident_log_event /* injector::transaction - member definitions diff --git a/sql/rpl_injector.h b/sql/rpl_injector.h index a0c71fee099..36cb6aaa184 100644 --- a/sql/rpl_injector.h +++ b/sql/rpl_injector.h @@ -21,6 +21,7 @@ #include <my_bitmap.h> #include "rpl_constants.h" +#include "table.h" /* TABLE */ /* Forward declarations */ class handler; diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 7dad340cfa6..10bf752e140 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -14,10 +14,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <my_global.h> // For HAVE_REPLICATION -#include "mysql_priv.h" +#include "sql_priv.h" #include <my_dir.h> - +#include "unireg.h" // REQUIRED by other includes #include "rpl_mi.h" +#include "slave.h" // SLAVE_MAX_HEARTBEAT_PERIOD #ifdef HAVE_REPLICATION diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index c4ca5714306..c3734fdf59e 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -22,9 +22,9 @@ #include "rpl_reporting.h" #include "my_sys.h" +typedef struct st_mysql MYSQL; /***************************************************************************** - Replication IO Thread Master_info contains: diff --git a/sql/rpl_record.cc b/sql/rpl_record.cc index 9e1413d726d..ced5c0943dd 100644 --- a/sql/rpl_record.cc +++ b/sql/rpl_record.cc @@ -13,7 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "rpl_rli.h" #include "rpl_record.h" #include "slave.h" // Need to pull in slave_print_msg diff --git a/sql/rpl_record.h b/sql/rpl_record.h index 6e8838f82b3..9b3829a435e 100644 --- a/sql/rpl_record.h +++ b/sql/rpl_record.h @@ -17,6 +17,11 @@ #define RPL_RECORD_H #include <rpl_reporting.h> +#include "my_global.h" /* uchar */ + +class Relay_log_info; +struct TABLE; +typedef struct st_bitmap MY_BITMAP; #if !defined(MYSQL_CLIENT) size_t pack_row(TABLE* table, MY_BITMAP const* cols, diff --git a/sql/rpl_record_old.cc b/sql/rpl_record_old.cc index ab4e993ce41..09d5bcacd62 100644 --- a/sql/rpl_record_old.cc +++ b/sql/rpl_record_old.cc @@ -1,7 +1,9 @@ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED by other includes #include "rpl_rli.h" #include "rpl_record_old.h" +#include "log_event.h" // Log_event_type size_t pack_row_old(TABLE *table, MY_BITMAP const* cols, diff --git a/sql/rpl_record_old.h b/sql/rpl_record_old.h index bdaedd56741..71c0ccc17b9 100644 --- a/sql/rpl_record_old.h +++ b/sql/rpl_record_old.h @@ -16,6 +16,8 @@ #ifndef RPL_RECORD_OLD_H #define RPL_RECORD_OLD_H +#include "log_event.h" /* Log_event_type */ + #ifndef MYSQL_CLIENT size_t pack_row_old(TABLE *table, MY_BITMAP const* cols, uchar *row_data, const uchar *record); diff --git a/sql/rpl_reporting.cc b/sql/rpl_reporting.cc index ae9d100eeb4..051a3609019 100644 --- a/sql/rpl_reporting.cc +++ b/sql/rpl_reporting.cc @@ -14,8 +14,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" #include "rpl_reporting.h" +#include "log.h" // sql_print_error, sql_print_warning, + // sql_print_information Slave_reporting_capability::Slave_reporting_capability(char const *thread_name) : m_thread_name(thread_name) diff --git a/sql/rpl_reporting.h b/sql/rpl_reporting.h index b8d9c049653..495c74170d2 100644 --- a/sql/rpl_reporting.h +++ b/sql/rpl_reporting.h @@ -1,7 +1,4 @@ -#ifndef RPL_REPORTING_H -#define RPL_REPORTING_H - -/* Copyright (C) 2008-2009 Sun Microsystems, Inc +/* 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 @@ -14,7 +11,12 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef RPL_REPORTING_H +#define RPL_REPORTING_H + +#include "my_sys.h" /* loglevel */ /** Maximum size of an error message from a slave thread. diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index e1c43771b32..8f070c51410 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -13,14 +13,19 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" - +#include "sql_priv.h" +#include "unireg.h" // HAVE_* #include "rpl_mi.h" #include "rpl_rli.h" +#include "sql_base.h" // close_thread_tables #include <my_dir.h> // For MY_STAT #include "sql_repl.h" // For check_binlog_magic +#include "log_event.h" // Format_description_log_event, Log_event, + // FORMAT_DESCRIPTION_LOG_EVENT, ROTATE_EVENT, + // PREFIX_SQL_LOAD #include "rpl_utility.h" #include "transaction.h" +#include "sql_parse.h" // end_trans, ROLLBACK static int count_relay_log_space(Relay_log_info* rli); diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index b1ed75146a0..bf8381933c0 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -19,6 +19,8 @@ #include "rpl_tblmap.h" #include "rpl_reporting.h" #include "rpl_utility.h" +#include "log.h" /* LOG_INFO, MYSQL_BIN_LOG */ +#include "sql_class.h" /* THD */ struct RPL_TABLE_LIST; class Master_info; diff --git a/sql/rpl_tblmap.cc b/sql/rpl_tblmap.cc index b04a3120a86..5a178ffde83 100644 --- a/sql/rpl_tblmap.cc +++ b/sql/rpl_tblmap.cc @@ -13,11 +13,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "my_global.h" // HAVE_REPLICATION #ifdef HAVE_REPLICATION #include "rpl_tblmap.h" +#ifndef MYSQL_CLIENT +#include "table.h" +#endif #ifdef MYSQL_CLIENT #define MAYBE_TABLE_NAME(T) ("") diff --git a/sql/rpl_tblmap.h b/sql/rpl_tblmap.h index a6ec8bcbc9b..3d24a47d9ae 100644 --- a/sql/rpl_tblmap.h +++ b/sql/rpl_tblmap.h @@ -52,6 +52,8 @@ void free_table_map_log_event(TABLE *table); A dedicated MEM_ROOT needs to be used, see below. */ +#include "hash.h" /* HASH */ + class table_mapping { private: diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index feb35527b62..0675e9b51ad 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -16,7 +16,9 @@ #include "rpl_utility.h" #ifndef MYSQL_CLIENT +#include "unireg.h" // REQUIRED by later includes #include "rpl_rli.h" +#include "sql_select.h" /** Function to compare two size_t integers for their relative @@ -340,7 +342,7 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const /** */ -void show_sql_type(enum_field_types type, uint16 metadata, String *str) +void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_INFO *field_cs) { DBUG_ENTER("show_sql_type"); DBUG_PRINT("enter", ("type: %d, metadata: 0x%x", type, metadata)); @@ -489,7 +491,7 @@ void show_sql_type(enum_field_types type, uint16 metadata, String *str) uint bytes= (((metadata >> 4) & 0x300) ^ 0x300) + (metadata & 0x00ff); uint32 length= cs->cset->snprintf(cs, (char*) str->ptr(), str->alloced_length(), - "char(%d)", bytes / cs->mbmaxlen); + "char(%d)", bytes / field_cs->mbmaxlen); str->length(length); } break; @@ -579,7 +581,7 @@ can_convert_field_to(Field *field, DBUG_ENTER("can_convert_field_to"); #ifndef DBUG_OFF char field_type_buf[MAX_FIELD_WIDTH]; - String field_type(field_type_buf, sizeof(field_type_buf), field->charset()); + String field_type(field_type_buf, sizeof(field_type_buf), &my_charset_latin1); field->sql_type(field_type); DBUG_PRINT("enter", ("field_type: %s, target_type: %d, source_type: %d, source_metadata: 0x%x", field_type.c_ptr_safe(), field->real_type(), source_type, metadata)); @@ -822,9 +824,9 @@ table_def::compatible_with(THD *thd, Relay_log_info *rli, const char *tbl_name= table->s->table_name.str; char source_buf[MAX_FIELD_WIDTH]; char target_buf[MAX_FIELD_WIDTH]; - String source_type(source_buf, sizeof(source_buf), field->charset()); - String target_type(target_buf, sizeof(target_buf), field->charset()); - show_sql_type(type(col), field_metadata(col), &source_type); + String source_type(source_buf, sizeof(source_buf), &my_charset_latin1); + String target_type(target_buf, sizeof(target_buf), &my_charset_latin1); + show_sql_type(type(col), field_metadata(col), &source_type, field->charset()); field->sql_type(target_type); rli->report(ERROR_LEVEL, ER_SLAVE_CONVERSION_FAILED, ER(ER_SLAVE_CONVERSION_FAILED), @@ -842,8 +844,8 @@ table_def::compatible_with(THD *thd, Relay_log_info *rli, { char source_buf[MAX_FIELD_WIDTH]; char target_buf[MAX_FIELD_WIDTH]; - String source_type(source_buf, sizeof(source_buf), table->field[col]->charset()); - String target_type(target_buf, sizeof(target_buf), table->field[col]->charset()); + String source_type(source_buf, sizeof(source_buf), &my_charset_latin1); + String target_type(target_buf, sizeof(target_buf), &my_charset_latin1); tmp_table->field[col]->sql_type(source_type); table->field[col]->sql_type(target_type); DBUG_PRINT("debug", ("Field %s - conversion required." diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h index 4b9bf3be93f..cf28d2c8e29 100644 --- a/sql/rpl_utility.h +++ b/sql/rpl_utility.h @@ -20,7 +20,11 @@ #error "Don't include this C++ header file from a non-C++ file!" #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "m_string.h" /* bzero, memcpy */ +#ifdef MYSQL_SERVER +#include "table.h" /* TABLE_LIST */ +#endif #include "mysql_com.h" class Relay_log_info; diff --git a/sql/scheduler.cc b/sql/scheduler.cc index b308b84eb19..10009246428 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -21,7 +21,10 @@ #pragma implementation #endif -#include <mysql_priv.h> +#include <sql_priv.h> +#include "unireg.h" // REQUIRED: for other includes +#include "scheduler.h" +#include "sql_connect.h" // init_new_connection_handler_thread /* 'Dummy' functions to be used when we don't need any handling for a scheduler diff --git a/sql/set_var.cc b/sql/set_var.cc index a30fbdc1edd..ec9c09f02a3 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -19,9 +19,31 @@ /* variable declarations are in sys_vars.cc now !!! */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_class.h" // set_var.h: session_var_ptr +#include "set_var.h" +#include "sql_priv.h" +#include "unireg.h" +#include "mysqld.h" // lc_messages_dir #include "sys_vars_shared.h" #include "transaction.h" +#include "sql_base.h" // close_thread_tables +#include "sql_locale.h" // my_locale_by_number, + // my_locale_by_name +#include "strfunc.h" // find_set_from_flags, find_set +#include "sql_parse.h" // check_global_access +#include "sql_table.h" // reassign_keycache_tables +#include "sql_time.h" // date_time_format_copy, + // date_time_format_make +#include "derror.h" +#include "tztime.h" // my_tz_find, my_tz_SYSTEM, struct Time_zone +#include "sql_acl.h" // SUPER_ACL +#include "sql_select.h" // free_underlaid_joins +#include "sql_show.h" // make_default_log_name +#include "sql_view.h" // updatable_views_with_limit_typelib +#include "lock.h" // lock_global_read_lock, + // make_global_read_lock_block_commit, + // unlock_global_read_lock static HASH system_variable_hash; static PolyLock_mutex PLock_global_system_variables(&LOCK_global_system_variables); diff --git a/sql/set_var.h b/sql/set_var.h index 4a212d3b685..1b415567659 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -30,6 +30,10 @@ class sys_var; class set_var; class sys_var_pluginvar; class PolyLock; +class Item_func_set_user_var; + +// This include needs to be here since item.h requires enum_var_type :-P +#include "item.h" /* Item */ extern TYPELIB bool_typelib; @@ -165,6 +169,9 @@ protected: { return ((uchar*)&global_system_variables) + offset; } }; +#include "log.h" /* binlog_format_typelib */ +#include "sql_plugin.h" /* SHOW_HA_ROWS, SHOW_MY_BOOL */ + /**************************************************************************** Classes for parsing of the SET command ****************************************************************************/ @@ -277,6 +284,18 @@ public: int update(THD *thd); }; + +/* optional things, have_* variables */ +extern SHOW_COMP_OPTION have_csv, have_innodb; +extern SHOW_COMP_OPTION have_ndbcluster, have_partitioning; +extern SHOW_COMP_OPTION have_profiling; + +extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen; +extern SHOW_COMP_OPTION have_query_cache; +extern SHOW_COMP_OPTION have_geometry, have_rtree_keys; +extern SHOW_COMP_OPTION have_crypt; +extern SHOW_COMP_OPTION have_compress; + /* Prototypes for helper functions */ diff --git a/sql/sha2.cc b/sql/sha2.cc new file mode 100644 index 00000000000..1a9de86f2e0 --- /dev/null +++ b/sql/sha2.cc @@ -0,0 +1,68 @@ +/* Copyright (C) 2007 MySQL AB + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +/** + @file + A compatibility layer to our built-in SSL implementation, to mimic the + oft-used external library, OpenSSL. +*/ + +#include <my_global.h> +#include <sha2.h> + +#ifdef HAVE_YASSL + +/* + If TaoCrypt::SHA512 or ::SHA384 are not defined (but ::SHA256 is), it's + probably that neither of config.h's SIZEOF_LONG or SIZEOF_LONG_LONG are + 64 bits long. At present, both OpenSSL and YaSSL require 64-bit integers + for SHA-512. (The SIZEOF_* definitions come from autoconf's config.h .) +*/ + +# define GEN_YASSL_SHA2_BRIDGE(size) \ +unsigned char* SHA##size(const unsigned char *input_ptr, size_t input_length, \ + char unsigned *output_ptr) { \ + TaoCrypt::SHA##size hasher; \ + \ + hasher.Update(input_ptr, input_length); \ + hasher.Final(output_ptr); \ + return(output_ptr); \ +} + + +/** + @fn SHA512 + @fn SHA384 + @fn SHA256 + @fn SHA224 + + Instantiate an hash object, fill in the cleartext value, compute the digest, + and extract the result from the object. + + (Generate the functions. See similar .h code for the prototypes.) +*/ +# ifndef OPENSSL_NO_SHA512 +GEN_YASSL_SHA2_BRIDGE(512); +GEN_YASSL_SHA2_BRIDGE(384); +# else +# warning Some SHA2 functionality is missing. See OPENSSL_NO_SHA512. +# endif +GEN_YASSL_SHA2_BRIDGE(256); +GEN_YASSL_SHA2_BRIDGE(224); + +# undef GEN_YASSL_SHA2_BRIDGE + +#endif /* HAVE_YASSL */ diff --git a/sql/share/Makefile.am b/sql/share/Makefile.am index cd4f7a83279..03f9a1652b7 100644 --- a/sql/share/Makefile.am +++ b/sql/share/Makefile.am @@ -17,13 +17,13 @@ EXTRA_DIST= errmsg-utf8.txt \ CMakeLists.txt - + dist-hook: for dir in charsets @AVAILABLE_LANGUAGES@; do \ test -d $(distdir)/$$dir || mkdir $(distdir)/$$dir; \ $(INSTALL_DATA) $(srcdir)/$$dir/*.* $(distdir)/$$dir; \ done; \ - sleep 1 ; touch $(builddir)/*/errmsg.sys + sleep 1 ; touch $(srcdir)/*/errmsg.sys $(INSTALL_DATA) $(srcdir)/charsets/README $(distdir)/charsets $(INSTALL_DATA) $(srcdir)/charsets/Index.xml $(distdir)/charsets @@ -40,12 +40,12 @@ install-data-local: for lang in @AVAILABLE_LANGUAGES@; \ do \ $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/$$lang; \ - $(INSTALL_DATA) $(builddir)/$$lang/errmsg.sys \ + $(INSTALL_DATA) $(srcdir)/$$lang/errmsg.sys \ $(DESTDIR)$(pkgdatadir)/$$lang/errmsg.sys; \ done $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/charsets - $(INSTALL_DATA) $(builddir)/errmsg-utf8.txt \ - $(DESTDIR)$(pkgdatadir)/errmsg-utf8.txt; \ + $(INSTALL_DATA) $(srcdir)/errmsg-utf8.txt \ + $(DESTDIR)$(pkgdatadir)/errmsg-utf8.txt; \ $(INSTALL_DATA) $(srcdir)/charsets/README $(DESTDIR)$(pkgdatadir)/charsets/README $(INSTALL_DATA) $(srcdir)/charsets/*.xml $(DESTDIR)$(pkgdatadir)/charsets @@ -54,7 +54,7 @@ uninstall-local: @RM@ -f -r $(DESTDIR)$(pkgdatadir) distclean-local: - @RM@ -f $(builddir)/*/errmsg.sys + @RM@ -f */errmsg.sys # Do nothing link_sources: diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 9861c03137f..3acf990e00d 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6321,3 +6321,12 @@ ER_SPATIAL_MUST_HAVE_GEOM_COL 42000 ER_TOO_LONG_INDEX_COMMENT eng "Comment for index '%-.64s' is too long (max = %lu)" + +ER_LOCK_ABORTED + eng "Wait on a lock was aborted due to a pending exclusive lock" + +ER_DATA_OUT_OF_RANGE 22003 + eng "%s value is out of range in '%s'" + +ER_WRONG_SPVAR_TYPE_IN_LIMIT + eng "A variable of a non-integer type in LIMIT clause" diff --git a/sql/slave.cc b/sql/slave.cc index 2f06d468d64..e23763696df 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -24,11 +24,11 @@ replication slave. */ -#include "mysql_priv.h" - -#include <mysql.h> -#include <myisam.h> +#include "sql_priv.h" +#include "my_global.h" #include "slave.h" +#include "sql_parse.h" // execute_init_command +#include "sql_table.h" // mysql_rm_table #include "rpl_mi.h" #include "rpl_rli.h" #include "sql_repl.h" @@ -42,10 +42,20 @@ #include <mysqld_error.h> #include <mysys_err.h> #include "rpl_handler.h" +#include <signal.h> +#include <mysql.h> +#include <myisam.h> + +#include "sql_base.h" // close_thread_tables +#include "tztime.h" // struct Time_zone +#include "log_event.h" // Rotate_log_event, + // Create_file_log_event, + // Format_description_log_event #ifdef HAVE_REPLICATION #include "rpl_tblmap.h" +#include "debug_sync.h" #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") @@ -1269,7 +1279,16 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) unavailable (very old master not supporting UNIX_TIMESTAMP()?). */ - DBUG_SYNC_POINT("debug_lock.before_get_UNIX_TIMESTAMP", 10); + DBUG_EXECUTE_IF("dbug.before_get_UNIX_TIMESTAMP", + { + const char act[]= + "now " + "wait_for signal.get_unix_timestamp"; + DBUG_ASSERT(opt_debug_sync_timeout > 0); + DBUG_ASSERT(!debug_sync_set_action(current_thd, + STRING_WITH_LEN(act))); + };); + master_res= NULL; if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) && (master_res= mysql_store_result(mysql)) && @@ -1310,7 +1329,15 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) Note: we could have put a @@SERVER_ID in the previous SELECT UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters. */ - DBUG_SYNC_POINT("debug_lock.before_get_SERVER_ID", 10); + DBUG_EXECUTE_IF("dbug.before_get_SERVER_ID", + { + const char act[]= + "now " + "wait_for signal.get_server_id"; + DBUG_ASSERT(opt_debug_sync_timeout > 0); + DBUG_ASSERT(!debug_sync_set_action(current_thd, + STRING_WITH_LEN(act))); + };); master_res= NULL; master_row= NULL; if (!mysql_real_query(mysql, @@ -2763,6 +2790,16 @@ pthread_handler_t handle_slave_io(void *arg) connected: + DBUG_EXECUTE_IF("dbug.before_get_running_status_yes", + { + const char act[]= + "now " + "wait_for signal.io_thread_let_running"; + DBUG_ASSERT(opt_debug_sync_timeout > 0); + DBUG_ASSERT(!debug_sync_set_action(thd, + STRING_WITH_LEN(act))); + };); + // TODO: the assignment below should be under mutex (5.0) mi->slave_running= MYSQL_SLAVE_RUN_CONNECT; thd->slave_net = &mysql->net; diff --git a/sql/slave.h b/sql/slave.h index f01eccf09f4..4073c90b612 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -210,6 +210,8 @@ int apply_event_and_update_pos(Log_event* ev, THD* thd, Relay_log_info* rli); pthread_handler_t handle_slave_io(void *arg); pthread_handler_t handle_slave_sql(void *arg); +bool net_request_file(NET* net, const char* fname); + extern bool volatile abort_loop; extern Master_info main_mi, *active_mi; /* active_mi for multi-master */ extern LIST master_list; diff --git a/sql/sp.cc b/sql/sp.cc index 39a8b6a009f..6aaddb69e05 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -13,10 +13,21 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sp.h" +#include "sql_base.h" // close_thread_tables +#include "sql_parse.h" // parse_sql +#include "key.h" // key_copy +#include "sql_show.h" // append_definer, append_identifier +#include "sql_db.h" // get_default_db_collation, mysql_opt_change_db, + // mysql_change_db, check_db_dir_existence, + // load_db_opt_by_name +#include "sql_table.h" // write_bin_log +#include "sql_acl.h" // SUPER_ACL #include "sp_head.h" #include "sp_cache.h" +#include "lock.h" // lock_routine_name #include <my_user.h> @@ -17,6 +17,25 @@ #ifndef _SP_H_ #define _SP_H_ +#include "sql_string.h" // LEX_STRING + +class Field; +class Open_tables_backup; +class Open_tables_state; +class Query_arena; +class Query_tables_list; +class Sroutine_hash_entry; +class THD; +class sp_cache; +class sp_head; +class sp_name; +struct st_sp_chistics; +struct LEX; +struct TABLE; +struct TABLE_LIST; +typedef struct st_hash HASH; +typedef struct st_sql_list SQL_LIST; + /* Tells what SP_DEFAULT_ACCESS should be mapped to */ #define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL @@ -162,4 +181,14 @@ sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db, const char *returns, const char *params, bool *free_sp_head); +bool load_charset(MEM_ROOT *mem_root, + Field *field, + CHARSET_INFO *dflt_cs, + CHARSET_INFO **cs); + +bool load_collation(MEM_ROOT *mem_root, + Field *field, + CHARSET_INFO *dflt_cl, + CHARSET_INFO **cl); + #endif /* _SP_H_ */ diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index 09d347bf951..f062276a9de 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -13,7 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation #endif diff --git a/sql/sp_cache.h b/sql/sp_cache.h index 7dbb0d5429c..c75e29474bc 100644 --- a/sql/sp_cache.h +++ b/sql/sp_cache.h @@ -21,6 +21,8 @@ #pragma interface /* gcc class implementation */ #endif +#include "my_global.h" /* ulong */ + /* Stored procedures/functions cache. This is used as follows: * Each thread has its own cache. @@ -30,6 +32,7 @@ class sp_head; class sp_cache; +class sp_name; /* Cache usage scenarios: diff --git a/sql/sp_head.cc b/sql/sp_head.cc index c6bf0e381fb..c91ba2a68b4 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -13,9 +13,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" #include "sql_prepare.h" +#include "sql_cache.h" // query_cache_* #include "probes_mysql.h" +#include "sql_show.h" // append_identifier +#include "sql_db.h" // mysql_opt_change_db, mysql_change_db +#include "sql_table.h" // sp_prepare_create_field, + // prepare_create_field +#include "sql_acl.h" // *_ACL +#include "sql_array.h" // Dynamic_array +#include "log_event.h" // append_query_string, Query_log_event + #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation #endif @@ -25,6 +36,8 @@ #include "sp_rcontext.h" #include "sp_cache.h" #include "set_var.h" +#include "sql_parse.h" // cleanup_items +#include "sql_base.h" // close_thread_tables /* Sufficient max length of printed destinations and frame offsets (all uints). @@ -965,11 +978,20 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) res|= qbuf.append(cur + prev_pos, (*splocal)->pos_in_query - prev_pos); prev_pos= (*splocal)->pos_in_query + (*splocal)->len_in_query; + res|= (*splocal)->fix_fields(thd, (Item **) splocal); + if (res) + break; + + if ((*splocal)->limit_clause_param) + { + res|= qbuf.append_ulonglong((*splocal)->val_uint()); + continue; + } + /* append the spvar substitute */ res|= qbuf.append(STRING_WITH_LEN(" NAME_CONST('")); res|= qbuf.append((*splocal)->m_name.str, (*splocal)->m_name.length); res|= qbuf.append(STRING_WITH_LEN("',")); - res|= (*splocal)->fix_fields(thd, (Item **) splocal); if (res) break; diff --git a/sql/sp_head.h b/sql/sp_head.h index d1e152765f2..165f88321a9 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -21,6 +21,15 @@ #pragma interface /* gcc class implementation */ #endif +/* + It is necessary to include set_var.h instead of item.h because there + are dependencies on include order for set_var.h and item.h. This + will be resolved later. +*/ +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_class.h" // THD, set_var.h: THD +#include "set_var.h" // Item + #include <stddef.h> /** diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc index 48ceb1371ca..74dda9f456b 100644 --- a/sql/sp_pcontext.cc +++ b/sql/sp_pcontext.cc @@ -13,7 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation #endif diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h index 75e55880e60..b12d5362c6b 100644 --- a/sql/sp_pcontext.h +++ b/sql/sp_pcontext.h @@ -21,6 +21,12 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_string.h" // LEX_STRING +#include "mysql_com.h" // enum_field_types +#include "field.h" // Create_field + +class sp_pcontext; + typedef enum { sp_param_in, diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index d966de03b4e..e3cdf328659 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -13,7 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation #endif @@ -27,7 +28,7 @@ #include "sql_cursor.h" #include "sp_rcontext.h" #include "sp_pcontext.h" - +#include "sql_select.h" // create_virtual_tmp_table sp_rcontext::sp_rcontext(sp_pcontext *root_parsing_ctx, Field *return_value_fld, diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index 2af96cf64dd..fad253706cb 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -21,11 +21,19 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_class.h" // select_result_interceptor + struct sp_cond_type; class sp_cursor; struct sp_variable; class sp_lex_keeper; class sp_instr_cpush; +class Query_arena; +class sp_head; +class sp_pcontext; +class Item_cache; +typedef class st_select_lex_unit SELECT_LEX_UNIT; +class Server_side_cursor; #define SP_HANDLER_NONE 0 #define SP_HANDLER_EXIT 1 diff --git a/sql/spatial.cc b/sql/spatial.cc index 9a31b099e92..34b1f3d1f0c 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -13,7 +13,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "my_global.h" // REQUIRED for HAVE_* below +#include "spatial.h" +#include "gstream.h" // Gis_read_stream +#include "sql_string.h" // String #ifdef HAVE_SPATIAL diff --git a/sql/spatial.h b/sql/spatial.h index 86c2ed8c197..a4bce47d0e5 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -16,8 +16,12 @@ #ifndef _spatial_h #define _spatial_h +#include "sql_string.h" /* String, LEX_STRING */ + #ifdef HAVE_SPATIAL +class Gis_read_stream; + const uint SRID_SIZE= 4; const uint SIZEOF_STORED_DOUBLE= 8; const uint POINT_DATA_SIZE= SIZEOF_STORED_DOUBLE*2; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 86f62d9bf72..f8be3ff6d4a 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -24,13 +24,26 @@ in the relevant fields. Empty strings comes last. */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "sql_acl.h" // MYSQL_DB_FIELD_COUNT, ACL_ACCESS +#include "sql_base.h" // close_thread_tables +#include "key.h" // key_copy, key_cmp_if_same, key_restore +#include "sql_show.h" // append_identifier +#include "sql_table.h" // build_table_filename #include "hash_filo.h" +#include "sql_parse.h" // check_access +#include "sql_view.h" // VIEW_ANY_ACL +#include "records.h" // READ_RECORD, read_record_info, + // init_read_record, end_read_record +#include "rpl_filter.h" // rpl_filter #include <m_ctype.h> #include <stdarg.h> #include "sp_head.h" #include "sp.h" #include "transaction.h" +#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT +#include "records.h" // init_read_record, end_read_record bool mysql_user_table_is_in_short_password_format= false; @@ -916,7 +929,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, if (acl_user) { /* OK. User found and password checked continue validation */ -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) Vio *vio=thd->net.vio; SSL *ssl= (SSL*) vio->ssl_arg; X509 *cert; @@ -933,7 +946,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, case SSL_TYPE_NONE: // SSL is not required user_access= acl_user->access; break; -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) case SSL_TYPE_ANY: // Any kind of SSL is ok if (vio_type(vio) == VIO_TYPE_SSL) user_access= acl_user->access; diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 8d521be2bc4..c0b536b7740 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -16,7 +16,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "slave.h" // for tables_ok(), rpl_filter +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "violite.h" /* SSL_type */ +#include "sql_class.h" /* LEX_COLUMN */ #define SELECT_ACL (1L << 0) #define INSERT_ACL (1L << 1) @@ -278,6 +280,11 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool check_routine_level_acl(THD *thd, const char *db, const char *name, bool is_proc); bool is_acl_user(const char *host, const char *user); +int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr); #ifdef NO_EMBEDDED_ACCESS_CHECKS #define check_grant(A,B,C,D,E,F) 0 diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index d273b3319ee..0b3e5117c97 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -28,7 +28,7 @@ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "sql_priv.h" #include "procedure.h" #include "sql_analyse.h" #include <m_ctype.h> diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h index 8f52b90c874..a1461247894 100644 --- a/sql/sql_analyse.h +++ b/sql/sql_analyse.h @@ -23,6 +23,8 @@ #pragma interface /* gcc class implementation */ #endif +#include "procedure.h" /* Procedure */ + #define my_thd_charset default_charset_info #define DEC_IN_AVG 4 @@ -359,4 +361,6 @@ public: List<Item> &field_list); }; +bool append_escaped(String *to_str, String *from_str); + #endif /* SQL_ANALYSE_INCLUDED */ diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 412de9225e8..7d269d455a9 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" #include "sql_audit.h" extern int initialize_audit_plugin(st_plugin_int *plugin); diff --git a/sql/sql_audit.h b/sql/sql_audit.h index c25011d0d59..5b6962b9ecb 100644 --- a/sql/sql_audit.h +++ b/sql/sql_audit.h @@ -18,6 +18,7 @@ #include <mysql/plugin_audit.h> +#include "sql_class.h" extern unsigned long mysql_global_audit_mask[]; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b4c9aa576d0..3daaa71141a 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -16,8 +16,30 @@ /* Basic functions needed by many modules */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" #include "debug_sync.h" +#include "sql_base.h" // setup_table_map +#include "lock.h" // broadcast_refresh, mysql_lock_remove, + // mysql_unlock_tables, + // mysql_lock_have_duplicate +#include "sql_show.h" // append_identifier +#include "strfunc.h" // find_type +#include "parse_file.h" // sql_parse_prepare, File_parser +#include "sql_view.h" // mysql_frm_type, mysql_make_view, VIEW_ANY_ACL +#include "sql_parse.h" // check_table_access +#include "sql_insert.h" // kill_delayed_threads +#include "sql_acl.h" // *_ACL, check_grant_all_columns, + // check_column_grant_in_table_ref, + // get_column_grant +#include "sql_partition.h" // ALTER_PARTITION_PARAM_TYPE +#include "sql_derived.h" // mysql_derived_prepare, + // mysql_handle_derived, + // mysql_derived_filling +#include "sql_handler.h" // mysql_ha_flush +#include "sql_partition.h" // ALTER_PARTITION_PARAM_TYPE +#include "log_event.h" // Query_log_event #include "sql_select.h" #include "sp_head.h" #include "sp.h" @@ -29,6 +51,7 @@ #include <my_dir.h> #include <hash.h> #include "rpl_filter.h" +#include "sql_table.h" // build_table_filename #ifdef __WIN__ #include <io.h> #endif @@ -1675,6 +1698,7 @@ void close_temporary_tables(THD *thd) { if (is_user_table(table)) { + bool save_thread_specific_used= thd->thread_specific_used; my_thread_id save_pseudo_thread_id= thd->variables.pseudo_thread_id; /* Set pseudo_thread_id to be that of the processed table */ thd->variables.pseudo_thread_id= tmpkeyval(thd, table); @@ -1704,6 +1728,7 @@ void close_temporary_tables(THD *thd) thd->clear_error(); CHARSET_INFO *cs_save= thd->variables.character_set_client; thd->variables.character_set_client= system_charset_info; + thd->thread_specific_used= TRUE; Query_log_event qinfo(thd, s_query.ptr(), s_query.length() - 1 /* to remove trailing ',' */, FALSE, TRUE, FALSE, 0); @@ -1716,6 +1741,7 @@ void close_temporary_tables(THD *thd) "Failed to write the DROP statement for temporary tables to binary log"); } thd->variables.pseudo_thread_id= save_pseudo_thread_id; + thd->thread_specific_used= save_thread_specific_used; } else { @@ -2421,7 +2447,7 @@ open_table_get_mdl_lock(THD *thd, TABLE_LIST *table_list, required to remedy problem appeared during attempt to open table. flags Bitmap of flags to modify how open works: - MYSQL_LOCK_IGNORE_FLUSH - Open table even if + MYSQL_OPEN_IGNORE_FLUSH - Open table even if someone has done a flush or there is a pending exclusive metadata lock requests against it (i.e. request high priority metadata lock). @@ -2480,6 +2506,31 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, TMP_TABLE_KEY_EXTRA); /* + We need this to work for all tables, including temporary + tables, for backwards compatibility. But not under LOCK + TABLES, since under LOCK TABLES one can't use a non-prelocked + table. This code only works for updates done inside DO/SELECT + f1() statements, normal DML is handled by means of + sql_command_flags. + */ + if (global_read_lock && table_list->lock_type >= TL_WRITE_ALLOW_WRITE && + ! (flags & MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK) && + ! thd->locked_tables_mode) + { + /* + Someone has issued FLUSH TABLES WITH READ LOCK and we want + a write lock. Wait until the lock is gone. + */ + if (thd->global_read_lock.wait_if_global_read_lock(thd, 1, 1)) + DBUG_RETURN(TRUE); + + if (thd->version != refresh_version) + { + (void) ot_ctx->request_backoff_action(Open_table_context::OT_WAIT_TDC); + DBUG_RETURN(TRUE); + } + } + /* Unless requested otherwise, try to resolve this table in the list of temporary tables of this thread. In MySQL temporary tables are always thread-local and "shadow" possible base tables with the @@ -2680,7 +2731,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, if (!thd->open_tables) thd->version=refresh_version; else if ((thd->version != refresh_version) && - ! (flags & MYSQL_LOCK_IGNORE_FLUSH)) + ! (flags & MYSQL_OPEN_IGNORE_FLUSH)) { /* Someone did a refresh while thread was opening tables */ mysql_mutex_unlock(&LOCK_open); @@ -2811,7 +2862,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, if (share->version != refresh_version) { - if (!(flags & MYSQL_LOCK_IGNORE_FLUSH)) + if (!(flags & MYSQL_OPEN_IGNORE_FLUSH)) { /* We already have an MDL lock. But we have encountered an old @@ -3293,7 +3344,6 @@ bool Locked_tables_list::reopen_tables(THD *thd) { Open_table_context ot_ctx_unused(thd, LONG_TIMEOUT); - bool lt_refresh_unused; size_t reopen_count= 0; MYSQL_LOCK *lock; MYSQL_LOCK *merged_lock; @@ -3333,7 +3383,7 @@ Locked_tables_list::reopen_tables(THD *thd) break something else. */ lock= mysql_lock_tables(thd, m_reopen_array, reopen_count, - MYSQL_OPEN_REOPEN, <_refresh_unused); + MYSQL_OPEN_REOPEN); thd->in_lock_tables= 0; if (lock == NULL || (merged_lock= mysql_lock_merge(thd->lock, lock)) == NULL) @@ -5061,7 +5111,6 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type, TABLE *table; Open_table_context ot_ctx(thd, (lock_flags & MYSQL_LOCK_IGNORE_TIMEOUT) ? LONG_TIMEOUT : thd->variables.lock_wait_timeout); - bool refresh; bool error; DBUG_ENTER("open_ltable"); @@ -5073,8 +5122,7 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type, /* open_ltable can be used only for BASIC TABLEs */ table_list->required_type= FRMTYPE_TABLE; -retry: - while ((error= open_table(thd, table_list, thd->mem_root, &ot_ctx, 0)) && + while ((error= open_table(thd, table_list, thd->mem_root, &ot_ctx, lock_flags)) && ot_ctx.can_recover_from_failed_open()) { /* @@ -5120,18 +5168,9 @@ retry: DBUG_ASSERT(thd->lock == 0); // You must lock everything at once if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK) if (! (thd->lock= mysql_lock_tables(thd, &table_list->table, 1, - lock_flags, &refresh))) + lock_flags))) { - if (refresh) - { - close_thread_tables(thd); - table_list->table= NULL; - table_list->mdl_request.ticket= NULL; - thd->mdl_context.rollback_to_savepoint(ot_ctx.start_of_statement_svp()); - goto retry; - } - else - table= 0; + table= 0; } } } @@ -5168,42 +5207,27 @@ bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, Prelocking_strategy *prelocking_strategy) { uint counter; - bool need_reopen; - /* - Remember the set of metadata locks which this connection - managed to acquire before the start of the current statement. - It can be either transaction-scope locks, or HANDLER locks, - or LOCK TABLES locks. If mysql_lock_tables() fails with - need_reopen request, we'll use it to instruct - close_tables_for_reopen() to release all locks of this - statement. - */ - MDL_ticket *start_of_statement_svp= thd->mdl_context.mdl_savepoint(); DBUG_ENTER("open_and_lock_tables"); DBUG_PRINT("enter", ("derived handling: %d", derived)); - for ( ; ; ) - { - if (open_tables(thd, &tables, &counter, flags, prelocking_strategy)) - DBUG_RETURN(TRUE); - DBUG_EXECUTE_IF("sleep_open_and_lock_after_open", { - const char *old_proc_info= thd->proc_info; - thd->proc_info= "DBUG sleep"; - my_sleep(6000000); - thd->proc_info= old_proc_info;}); - - if (!lock_tables(thd, tables, counter, flags, - &need_reopen)) - break; - if (!need_reopen) - DBUG_RETURN(TRUE); - close_tables_for_reopen(thd, &tables, start_of_statement_svp); - } + if (open_tables(thd, &tables, &counter, flags, prelocking_strategy)) + DBUG_RETURN(TRUE); + + DBUG_EXECUTE_IF("sleep_open_and_lock_after_open", { + const char *old_proc_info= thd->proc_info; + thd->proc_info= "DBUG sleep"; + my_sleep(6000000); + thd->proc_info= old_proc_info;}); + + if (lock_tables(thd, tables, counter, flags)) + DBUG_RETURN(TRUE); + if (derived && (mysql_handle_derived(thd->lex, &mysql_derived_prepare) || (thd->fill_derived_tables() && mysql_handle_derived(thd->lex, &mysql_derived_filling)))) DBUG_RETURN(TRUE); /* purecov: inspected */ + DBUG_RETURN(FALSE); } @@ -5216,7 +5240,7 @@ bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, thd - thread handler tables - list of tables for open flags - bitmap of flags to modify how the tables will be open: - MYSQL_LOCK_IGNORE_FLUSH - open table even if someone has + MYSQL_OPEN_IGNORE_FLUSH - open table even if someone has done a flush or namelock on it. RETURN @@ -5261,37 +5285,28 @@ static void mark_real_tables_as_free_for_reuse(TABLE_LIST *table) } -/* - Lock all tables in list +/** + Lock all tables in a list. - SYNOPSIS - lock_tables() - thd Thread handler - tables Tables to lock - count Number of opened tables - flags Options (see mysql_lock_tables() for details) - need_reopen Out parameter which if TRUE indicates that some - tables were dropped or altered during this call - and therefore invoker should reopen tables and - try to lock them once again (in this case - lock_tables() will also return error). + @param thd Thread handler + @param tables Tables to lock + @param count Number of opened tables + @param flags Options (see mysql_lock_tables() for details) - NOTES - You can't call lock_tables twice, as this would break the dead-lock-free - handling thr_lock gives us. You most always get all needed locks at - once. + You can't call lock_tables() while holding thr_lock locks, as + this would break the dead-lock-free handling thr_lock gives us. + You must always get all needed locks at once. - If query for which we are calling this function marked as requiring - prelocking, this function will change locked_tables_mode to - LTM_PRELOCKED. + If the query for which we are calling this function is marked as + requiring prelocking, this function will change + locked_tables_mode to LTM_PRELOCKED. - RETURN VALUES - 0 ok - -1 Error + @retval FALSE Success. + @retval TRUE A lock wait timeout, deadlock or out of memory. */ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, - uint flags, bool *need_reopen) + uint flags) { TABLE_LIST *table; @@ -5302,7 +5317,6 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, */ DBUG_ASSERT(thd->locked_tables_mode <= LTM_LOCK_TABLES || !thd->lex->requires_prelocking()); - *need_reopen= FALSE; if (!tables && !thd->lex->requires_prelocking()) DBUG_RETURN(thd->decide_logging_format(tables)); @@ -5347,7 +5361,7 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, DEBUG_SYNC(thd, "before_lock_tables_takes_lock"); if (! (thd->lock= mysql_lock_tables(thd, start, (uint) (ptr - start), - flags, need_reopen))) + flags))) DBUG_RETURN(TRUE); DEBUG_SYNC(thd, "after_lock_tables_takes_lock"); @@ -8869,7 +8883,7 @@ open_system_tables_for_read(THD *thd, TABLE_LIST *table_list, thd->reset_n_backup_open_tables_state(backup); if (open_and_lock_tables(thd, table_list, FALSE, - MYSQL_LOCK_IGNORE_FLUSH | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT)) { lex->restore_backup_query_tables_list(&query_tables_list_backup); @@ -8957,11 +8971,11 @@ open_system_table_for_update(THD *thd, TABLE_LIST *one_table) TABLE * open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup) { - uint flags= ( MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK | + uint flags= ( MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | - MYSQL_LOCK_IGNORE_FLUSH | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | - MYSQL_LOCK_PERF_SCHEMA); + MYSQL_LOCK_LOG_TABLE); TABLE *table; /* Save value that is changed in mysql_lock_tables() */ ulonglong save_utime_after_lock= thd->utime_after_lock; @@ -8989,8 +9003,7 @@ open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup) open tables cannot be accepted when restoring the open tables state. */ - if (thd->killed) - close_thread_tables(thd); + close_thread_tables(thd); thd->restore_backup_open_tables_state(backup); } diff --git a/sql/sql_base.h b/sql/sql_base.h new file mode 100644 index 00000000000..a57666afe49 --- /dev/null +++ b/sql/sql_base.h @@ -0,0 +1,359 @@ +/* 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_BASE_INCLUDED +#define SQL_BASE_INCLUDED + +#include "unireg.h" // REQUIRED: for other includes +#include "table.h" /* open_table_mode */ +#include "sql_trigger.h" /* trg_event_type */ +#include "sql_class.h" /* enum_mark_columns */ +#include "mysqld.h" /* key_map */ + +class Item_ident; +struct Name_resolution_context; +class Open_table_context; +class Open_tables_state; +class Prelocking_strategy; +struct TABLE_LIST; +class THD; +struct handlerton; +struct TABLE; + +typedef class st_select_lex SELECT_LEX; + +typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE; + +/* + This enumeration type is used only by the function find_item_in_list + to return the info on how an item has been resolved against a list + of possibly aliased items. + The item can be resolved: + - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS) + - against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS) + - against an aliased field name of the list (RESOLVED_BEHIND_ALIAS) + - ignoring the alias name in cases when SQL requires to ignore aliases + (e.g. when the resolved field reference contains a table name or + when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS) +*/ +enum enum_resolution_type { + NOT_RESOLVED=0, + RESOLVED_IGNORING_ALIAS, + RESOLVED_BEHIND_ALIAS, + RESOLVED_WITH_NO_ALIAS, + RESOLVED_AGAINST_ALIAS +}; + +enum enum_open_table_action {OT_NO_ACTION= 0, OT_BACK_OFF_AND_RETRY, + OT_DISCOVER, OT_REPAIR}; + +enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND, + IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE, + IGNORE_EXCEPT_NON_UNIQUE}; + +enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN, + TDC_RT_REMOVE_UNUSED}; + +/* bits for last argument to remove_table_from_cache() */ +#define RTFC_NO_FLAG 0x0000 +#define RTFC_OWNED_BY_THD_FLAG 0x0001 +#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002 +#define RTFC_CHECK_KILLED_FLAG 0x0004 + +bool check_dup(const char *db, const char *name, TABLE_LIST *tables); +bool table_cache_init(void); +void table_cache_free(void); +bool table_def_init(void); +void table_def_free(void); +void table_def_start_shutdown(void); +void assign_new_table_id(TABLE_SHARE *share); +uint cached_open_tables(void); +uint cached_table_definitions(void); +uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list, + bool tmp_table); +TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key, + uint key_length, uint db_flags, int *error, + my_hash_value_type hash_value); +void release_table_share(TABLE_SHARE *share); +TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name); + +TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update, + uint lock_flags); +bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, + Open_table_context *ot_ctx, uint flags); +bool name_lock_locked_table(THD *thd, TABLE_LIST *tables); +bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in); +TABLE *table_cache_insert_placeholder(THD *thd, const char *key, + uint key_length); +bool lock_table_name_if_not_cached(THD *thd, const char *db, + const char *table_name, TABLE **table); +void detach_merge_children(TABLE *table, bool clear_refs); +bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last, + TABLE_LIST *new_child_list, TABLE_LIST **new_last); +bool reopen_table(TABLE *table); +bool reopen_tables(THD *thd,bool get_locks,bool in_refresh); +void close_data_files_and_morph_locks(THD *thd, const char *db, + const char *table_name); +void close_handle_and_leave_table_as_lock(TABLE *table); +bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias, + uint db_stat, uint prgflag, + uint ha_open_flags, TABLE *outparam, TABLE_LIST *table_desc, + MEM_ROOT *mem_root); +bool wait_for_tables(THD *thd); +bool table_is_used(TABLE *table, bool wait_for_name_lock); +TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name); +void abort_locked_tables(THD *thd,const char *db, const char *table_name); + +bool get_key_map_from_key_list(key_map *map, TABLE *table, + List<String> *index_list); +TABLE *open_temporary_table(THD *thd, const char *path, const char *db, + const char *table_name, bool link_in_list); +TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name); +TABLE *find_write_locked_table(TABLE *list, const char *db, + const char *table_name); +thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table); + +my_bool mysql_rm_tmp_tables(void); +bool rm_temporary_table(handlerton *base, char *path); +void close_tables_for_reopen(THD *thd, TABLE_LIST **tables, + MDL_ticket *start_of_statement_svp); +TABLE_LIST *find_table_in_list(TABLE_LIST *table, + TABLE_LIST *TABLE_LIST::*link, + const char *db_name, + const char *table_name); +TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name); +TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list); +void close_thread_tables(THD *thd); +bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields, + List<Item> &values, + bool ignore_errors, + Table_triggers_list *triggers, + enum trg_event_type event); +bool fill_record_n_invoke_before_triggers(THD *thd, Field **field, + List<Item> &values, + bool ignore_errors, + Table_triggers_list *triggers, + enum trg_event_type event); +bool insert_fields(THD *thd, Name_resolution_context *context, + const char *db_name, const char *table_name, + List_iterator<Item> *it, bool any_privileges); +int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, + List<Item> *sum_func_list, uint wild_num); +bool setup_fields(THD *thd, Item** ref_pointer_array, + List<Item> &item, enum_mark_columns mark_used_columns, + List<Item> *sum_func_list, bool allow_sum_func); +bool fill_record(THD *thd, Field **field, List<Item> &values, + bool ignore_errors); + +Field * +find_field_in_tables(THD *thd, Item_ident *item, + TABLE_LIST *first_table, TABLE_LIST *last_table, + Item **ref, find_item_error_report_type report_error, + bool check_privileges, bool register_tree_change); +Field * +find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, + const char *name, uint length, + const char *item_name, const char *db_name, + const char *table_name, Item **ref, + bool check_privileges, bool allow_rowid, + uint *cached_field_index_ptr, + bool register_tree_change, TABLE_LIST **actual_table); +Field * +find_field_in_table(THD *thd, TABLE *table, const char *name, uint length, + bool allow_rowid, uint *cached_field_index_ptr); +Field * +find_field_in_table_sef(TABLE *table, const char *name); +Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter, + find_item_error_report_type report_error, + enum_resolution_type *resolution); +bool setup_tables(THD *thd, Name_resolution_context *context, + List<TABLE_LIST> *from_clause, TABLE_LIST *tables, + TABLE_LIST **leaves, bool select_insert); +bool setup_tables_and_check_access(THD *thd, + Name_resolution_context *context, + List<TABLE_LIST> *from_clause, + TABLE_LIST *tables, + TABLE_LIST **leaves, + bool select_insert, + ulong want_access_first, + ulong want_access); +bool wait_while_table_is_used(THD *thd, TABLE *table, + enum ha_extra_function function); +void unlink_open_table(THD *thd, TABLE *find, bool unlock); + +void drop_open_table(THD *thd, TABLE *table, const char *db_name, + const char *table_name); +void close_all_tables_for_name(THD *thd, TABLE_SHARE *share, + bool remove_from_locked_tables); +void update_non_unique_table_error(TABLE_LIST *update, + const char *operation, + TABLE_LIST *duplicate); +int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, + COND **conds); +int setup_ftfuncs(SELECT_LEX* select); +int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order); +void wait_for_condition(THD *thd, mysql_mutex_t *mutex, + mysql_cond_t *cond); +bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags, + Prelocking_strategy *prelocking_strategy); +/* open_and_lock_tables with optional derived handling */ +bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, + bool derived, uint flags, + Prelocking_strategy *prelocking_strategy); +int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived); +/* simple open_and_lock_tables without derived handling for single table */ +TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l, + thr_lock_type lock_type, uint flags); +bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags); +bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags); +int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt); +int decide_logging_format(THD *thd, TABLE_LIST *tables); +void free_io_cache(TABLE *entry); +void intern_close_table(TABLE *entry); +bool close_thread_table(THD *thd, TABLE **table_ptr); +void close_temporary_tables(THD *thd); +TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, + bool check_alias); +int drop_temporary_table(THD *thd, TABLE_LIST *table_list); +void close_temporary_table(THD *thd, TABLE *table, bool free_share, + bool delete_table); +void close_temporary(TABLE *table, bool free_share, bool delete_table); +bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db, + const char *table_name); +void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table); +void remove_db_from_cache(const char *db); +void flush_tables(); +bool is_equal(const LEX_STRING *a, const LEX_STRING *b); + +/* Functions to work with system tables. */ +bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list, + Open_tables_backup *backup); +void close_system_tables(THD *thd, Open_tables_backup *backup); +TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table); +TABLE *open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup); +void close_log_table(THD *thd, Open_tables_backup *backup); + +TABLE *open_performance_schema_table(THD *thd, TABLE_LIST *one_table, + Open_tables_state *backup); +void close_performance_schema_table(THD *thd, Open_tables_state *backup); + +bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, + bool wait_for_refresh); +bool close_cached_connection_tables(THD *thd, bool wait_for_refresh, + LEX_STRING *connect_string, + bool have_lock = FALSE); +void close_all_tables_for_name(THD *thd, TABLE_SHARE *share, + bool remove_from_locked_tables); +OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild); +bool remove_table_from_cache(THD *thd, const char *db, const char *table, + uint flags); +void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, + const char *db, const char *table_name); +bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias, + char *cache_key, uint cache_key_length, + MEM_ROOT *mem_root, uint flags); +TABLE *find_table_for_mdl_upgrade(TABLE *list, const char *db, + const char *table_name, + bool no_error); +void mark_tmp_table_for_reuse(TABLE *table); + +extern uint table_cache_count; +extern TABLE *unused_tables; +extern Item **not_found_item; +extern Field *not_found_field; +extern Field *view_ref_found; +extern HASH open_cache; +extern HASH table_def_cache; + +/** + clean/setup table fields and map. + + @param table TABLE structure pointer (which should be setup) + @param table_list TABLE_LIST structure pointer (owner of TABLE) + @param tablenr table number +*/ + + +inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr) +{ + table->used_fields= 0; + table->const_table= 0; + table->null_row= 0; + table->status= STATUS_NO_RECORD; + table->maybe_null= table_list->outer_join; + TABLE_LIST *embedding= table_list->embedding; + while (!table->maybe_null && embedding) + { + table->maybe_null= embedding->outer_join; + embedding= embedding->embedding; + } + table->tablenr= tablenr; + table->map= (table_map) 1 << tablenr; + table->force_index= table_list->force_index; + table->force_index_order= table->force_index_group= 0; + table->covering_keys= table->s->keys_for_keyread; + table->merge_keys.clear_all(); +} + +inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table, + const char *db_name, + const char *table_name) +{ + return find_table_in_list(table, &TABLE_LIST::next_global, + db_name, table_name); +} + +inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table, + const char *db_name, + const char *table_name) +{ + return find_table_in_list(table, &TABLE_LIST::next_local, + db_name, table_name); +} + +inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array, + List<Item> &item, + enum_mark_columns mark_used_columns, + List<Item> *sum_func_list, + bool allow_sum_func) +{ + bool res; + thd->lex->select_lex.no_wrap_view_item= TRUE; + res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, + sum_func_list, allow_sum_func); + thd->lex->select_lex.no_wrap_view_item= FALSE; + return res; +} + +inline bool +open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags) +{ + DML_prelocking_strategy prelocking_strategy; + + return open_tables(thd, tables, counter, flags, &prelocking_strategy); +} + + +/* open_and_lock_tables with derived handling */ +inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, + bool derived, uint flags) +{ + DML_prelocking_strategy prelocking_strategy; + + return open_and_lock_tables(thd, tables, derived, flags, + &prelocking_strategy); +} + +#endif /* SQL_BASE_INCLUDED */ diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc index 31d4430cbe6..0730f7df00c 100644 --- a/sql/sql_binlog.cc +++ b/sql/sql_binlog.cc @@ -13,10 +13,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_binlog.h" +#include "sql_parse.h" // check_global_access +#include "sql_acl.h" // *_ACL #include "rpl_rli.h" #include "base64.h" - +#include "slave.h" // apply_event_and_update_pos +#include "log_event.h" // Format_description_log_event, + // EVENT_LEN_OFFSET, + // EVENT_TYPE_OFFSET, + // FORMAT_DESCRIPTION_LOG_EVENT, + // START_EVENT_V3, + // Log_event_type, + // Log_event /** Execute a BINLOG statement. diff --git a/sql/sql_binlog.h b/sql/sql_binlog.h new file mode 100644 index 00000000000..50251eaac50 --- /dev/null +++ b/sql/sql_binlog.h @@ -0,0 +1,23 @@ +/* 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_BINLOG_INCLUDED +#define SQL_BINLOG_INCLUDED + +class THD; + +void mysql_client_binlog_statement(THD *thd); + +#endif /* SQL_BINLOG_INCLUDED */ diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h index 97accefe8aa..80a4712dd69 100644 --- a/sql/sql_bitmap.h +++ b/sql/sql_bitmap.h @@ -19,6 +19,9 @@ also be able to use 32 or 64 bits bitmaps very efficiently */ +#ifndef SQL_BITMAP_INCLUDED +#define SQL_BITMAP_INCLUDED + #include <my_bitmap.h> template <uint default_width> class Bitmap @@ -138,3 +141,5 @@ public: ulonglong to_ulonglong() const { return map; } }; + +#endif /* SQL_BITMAP_INCLUDED */ diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index f812ef862b0..1e4161dfa1c 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -327,7 +327,13 @@ TODO list: (This could be done with almost no speed penalty) */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "sql_cache.h" +#include "sql_parse.h" // check_table_access +#include "tztime.h" // struct Time_zone +#include "sql_acl.h" // SELECT_ACL +#include "sql_base.h" // TMP_TABLE_KEY_EXTRA #ifdef HAVE_QUERY_CACHE #include <m_ctype.h> #include <my_dir.h> diff --git a/sql/sql_cache.h b/sql/sql_cache.h index 9d1f32d6ef1..792ae6ba960 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -16,6 +16,16 @@ #ifndef _SQL_CACHE_H #define _SQL_CACHE_H +#include "hash.h" +#include "my_base.h" /* ha_rows */ + +class MY_LOCALE; +struct TABLE_LIST; +class Time_zone; +struct LEX; +struct TABLE; +typedef struct st_changed_table_list CHANGED_TABLE_LIST; + /* Query cache */ /* @@ -66,6 +76,11 @@ struct Query_cache_result; class Query_cache; struct Query_cache_tls; struct LEX; +class THD; + +typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key, + uint key_length, + ulonglong *engine_data); /** This class represents a node in the linked chain of queries @@ -502,5 +517,68 @@ protected: void unlock(void); }; +#ifdef HAVE_QUERY_CACHE +struct Query_cache_query_flags +{ + unsigned int client_long_flag:1; + unsigned int client_protocol_41:1; + unsigned int protocol_type:2; + unsigned int more_results_exists:1; + unsigned int in_trans:1; + unsigned int autocommit:1; + unsigned int pkt_nr; + uint character_set_client_num; + uint character_set_results_num; + uint collation_connection_num; + ha_rows limit; + Time_zone *time_zone; + ulong sql_mode; + ulong max_sort_length; + ulong group_concat_max_len; + ulong default_week_format; + ulong div_precision_increment; + MY_LOCALE *lc_time_names; +}; +#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags) +#include "sql_cache.h" +#define query_cache_abort(A) query_cache.abort(A) +#define query_cache_end_of_result(A) query_cache.end_of_result(A) +#define query_cache_store_query(A, B) query_cache.store_query(A, B) +#define query_cache_destroy() query_cache.destroy() +#define query_cache_result_size_limit(A) query_cache.result_size_limit(A) +#define query_cache_init() query_cache.init() +#define query_cache_resize(A) query_cache.resize(A) +#define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A) +#define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C) +#define query_cache_invalidate1(A) query_cache.invalidate(A) +#define query_cache_send_result_to_client(A, B, C) \ + query_cache.send_result_to_client(A, B, C) +#define query_cache_invalidate_by_MyISAM_filename_ref \ + &query_cache_invalidate_by_MyISAM_filename +/* note the "maybe": it's a read without mutex */ +#define query_cache_maybe_disabled(T) \ + (T->variables.query_cache_type == 0 || query_cache.query_cache_size == 0) +#define query_cache_is_cacheable_query(L) \ + (((L)->sql_command == SQLCOM_SELECT) && (L)->safe_to_cache_query) +#else +#define QUERY_CACHE_FLAGS_SIZE 0 +#define query_cache_store_query(A, B) +#define query_cache_destroy() +#define query_cache_result_size_limit(A) +#define query_cache_init() +#define query_cache_resize(A) +#define query_cache_set_min_res_unit(A) +#define query_cache_invalidate3(A, B, C) +#define query_cache_invalidate1(A) +#define query_cache_send_result_to_client(A, B, C) 0 +#define query_cache_invalidate_by_MyISAM_filename_ref NULL + +#define query_cache_abort(A) +#define query_cache_end_of_result(A) +#define query_cache_invalidate_by_MyISAM_filename_ref NULL +#define query_cache_maybe_disabled(T) 1 +#define query_cache_is_cacheable_query(L) 0 +#endif /*HAVE_QUERY_CACHE*/ + extern Query_cache query_cache; #endif diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 4b21bc283e2..256f2fa730a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -25,7 +25,18 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_class.h" +#include "lock.h" // unlock_global_read_lock, mysql_unlock_tables +#include "sql_cache.h" // query_cache_abort +#include "sql_base.h" // close_thread_tables +#include "sql_time.h" // date_time_format_copy +#include "sql_acl.h" // NO_ACCESS, + // acl_getroot_no_password +#include "sql_base.h" // close_temporary_tables +#include "sql_handler.h" // mysql_ha_cleanup #include "rpl_rli.h" #include "rpl_filter.h" #include "rpl_record.h" @@ -46,6 +57,7 @@ #include "sp_cache.h" #include "transaction.h" #include "debug_sync.h" +#include "sql_parse.h" // is_update_query /* The following is used to initialise Table_ident with a internal diff --git a/sql/sql_class.h b/sql/sql_class.h index 8ce3cee3c36..950db01d1cd 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -23,10 +23,22 @@ #pragma interface /* gcc class implementation */ #endif +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#ifdef MYSQL_SERVER +#include "unireg.h" // REQUIRED: for other includes +#endif +#include "sql_const.h" #include <mysql/plugin_audit.h> #include "log.h" #include "rpl_tblmap.h" #include "mdl.h" +#include "sql_locale.h" /* my_locale_st */ +#include "sql_profile.h" /* PROFILING */ +#include "scheduler.h" /* thd_scheduler */ +#include "protocol.h" /* Protocol_text, Protocol_binary */ +#include "violite.h" /* vio_is_connected */ +#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA, + THR_LOCK_INFO, THR_LOCK_OWNER */ class Reprepare_observer; @@ -40,6 +52,8 @@ class sp_cache; class Parser_state; class Rows_log_event; class Sroutine_hash_entry; +class User_level_lock; +class user_var_entry; enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE }; enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME }; @@ -55,6 +69,40 @@ enum enum_mark_columns { MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE}; enum enum_filetype { FILETYPE_CSV, FILETYPE_XML }; +/* Bits for different SQL modes modes (including ANSI mode) */ +#define MODE_REAL_AS_FLOAT 1 +#define MODE_PIPES_AS_CONCAT 2 +#define MODE_ANSI_QUOTES 4 +#define MODE_IGNORE_SPACE 8 +#define MODE_NOT_USED 16 +#define MODE_ONLY_FULL_GROUP_BY 32 +#define MODE_NO_UNSIGNED_SUBTRACTION 64 +#define MODE_NO_DIR_IN_CREATE 128 +#define MODE_POSTGRESQL 256 +#define MODE_ORACLE 512 +#define MODE_MSSQL 1024 +#define MODE_DB2 2048 +#define MODE_MAXDB 4096 +#define MODE_NO_KEY_OPTIONS 8192 +#define MODE_NO_TABLE_OPTIONS 16384 +#define MODE_NO_FIELD_OPTIONS 32768 +#define MODE_MYSQL323 65536L +#define MODE_MYSQL40 (MODE_MYSQL323*2) +#define MODE_ANSI (MODE_MYSQL40*2) +#define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2) +#define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2) +#define MODE_STRICT_TRANS_TABLES (MODE_NO_BACKSLASH_ESCAPES*2) +#define MODE_STRICT_ALL_TABLES (MODE_STRICT_TRANS_TABLES*2) +#define MODE_NO_ZERO_IN_DATE (MODE_STRICT_ALL_TABLES*2) +#define MODE_NO_ZERO_DATE (MODE_NO_ZERO_IN_DATE*2) +#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2) +#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2) +#define MODE_TRADITIONAL (MODE_ERROR_FOR_DIVISION_BY_ZERO*2) +#define MODE_NO_AUTO_CREATE_USER (MODE_TRADITIONAL*2) +#define MODE_HIGH_NOT_PRECEDENCE (MODE_NO_AUTO_CREATE_USER*2) +#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2) +#define MODE_PAD_CHAR_TO_FULL_LENGTH (ULL(1) << 31) + extern char internal_table_name[2]; extern char empty_c_string[1]; extern MYSQL_PLUGIN_IMPORT const char **errmesg; @@ -75,6 +123,7 @@ typedef struct st_user_var_events ulong length; Item_result type; uint charset_number; + bool unsigned_flag; } BINLOG_USER_VAR_EVENT; #define RP_LOCK_LOG_IS_ALREADY_LOCKED 1 @@ -247,6 +296,8 @@ public: LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {} }; +class MY_LOCALE; + /** Query_cache_tls -- query cache thread local data. */ @@ -1161,9 +1212,7 @@ public: class Drop_table_error_handler : public Internal_error_handler { public: - Drop_table_error_handler(Internal_error_handler *err_handler) - :m_err_handler(err_handler) - { } + Drop_table_error_handler() {} public: bool handle_condition(THD *thd, @@ -1174,7 +1223,6 @@ public: MYSQL_ERROR ** cond_hdl); private: - Internal_error_handler *m_err_handler; }; @@ -2768,8 +2816,6 @@ public: bool escaped_given(void); }; -#include "log_event.h" - /* This is used to get result from a select */ @@ -3486,13 +3532,55 @@ public: */ #define CF_SKIP_QUESTIONS (1U << 1) -/* Functions in sql_class.cc */ - void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var); void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, STATUS_VAR *dec_var); void mark_transaction_to_rollback(THD *thd, bool all); +/* + This prototype is placed here instead of in item_func.h because it + depends on the definition of enum_sql_command, which is in this + file. + */ +int get_var_with_binlog(THD *thd, enum_sql_command sql_command, + LEX_STRING &name, user_var_entry **out_entry); + +/* Inline functions */ + +inline bool add_item_to_list(THD *thd, Item *item) +{ + return thd->lex->current_select->add_item_to_list(thd, item); +} + +inline bool add_value_to_list(THD *thd, Item *value) +{ + return thd->lex->value_list.push_back(value); +} + +inline bool add_order_to_list(THD *thd, Item *item, bool asc) +{ + return thd->lex->current_select->add_order_to_list(thd, item, asc); +} + +inline bool add_group_to_list(THD *thd, Item *item, bool asc) +{ + return thd->lex->current_select->add_group_to_list(thd, item, asc); +} + #endif /* MYSQL_SERVER */ + +/** + The meat of thd_proc_info(THD*, char*), a macro that packs the last + three calling-info parameters. +*/ +extern "C" +const char *set_thd_proc_info(THD *thd, const char *info, + const char *calling_func, + const char *calling_file, + const unsigned int calling_line); + +#define thd_proc_info(thd, msg) \ + set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__) + #endif /* SQL_CLASS_INCLUDED */ diff --git a/sql/sql_client.cc b/sql/sql_client.cc index 032a2e26e3a..0c16449276a 100644 --- a/sql/sql_client.cc +++ b/sql/sql_client.cc @@ -17,7 +17,8 @@ This files defines some MySQL C API functions that are server specific */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_class.h" // system_variables /* Function called by my_net_init() to set some check variables diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 90b255b0843..e2d0977def7 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -18,11 +18,25 @@ Functions to autenticate and handle reqests for a connection */ -#include "mysql_priv.h" +#include "my_global.h" +#include "sql_priv.h" +#ifndef __WIN__ +#include <netdb.h> // getservbyname, servent +#endif #include "sql_audit.h" +#include "sql_connect.h" +#include "my_global.h" #include "probes_mysql.h" - -#ifdef HAVE_OPENSSL +#include "unireg.h" // REQUIRED: for other includes +#include "sql_parse.h" // sql_command_flags, + // execute_init_command, + // do_command +#include "sql_db.h" // mysql_change_db +#include "hostname.h" // inc_host_errors, ip_to_hostname, + // reset_host_errors +#include "sql_acl.h" // acl_getroot, NO_ACCESS, SUPER_ACL + +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* Without SSL the handshake consists of one packet. This packet has both client capabilites and scrambled password. @@ -38,7 +52,7 @@ #define MIN_HANDSHAKE_SIZE 2 #else #define MIN_HANDSHAKE_SIZE 6 -#endif /* HAVE_OPENSSL */ +#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ /* Get structure for logging connection data for the current user @@ -640,6 +654,7 @@ bool init_new_connection_handler_thread() return 0; } +#ifndef EMBEDDED_LIBRARY /* Perform handshake, authorize client and update thd ACL variables. @@ -653,7 +668,6 @@ bool init_new_connection_handler_thread() > 0 error code (not sent to user) */ -#ifndef EMBEDDED_LIBRARY static int check_connection(THD *thd) { uint connect_errors= 0; @@ -735,7 +749,7 @@ static int check_connection(THD *thd) #ifdef HAVE_COMPRESS server_capabilites|= CLIENT_COMPRESS; #endif /* HAVE_COMPRESS */ -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) if (ssl_acceptor_fd) { server_capabilites |= CLIENT_SSL; /* Wow, SSL is available! */ @@ -813,7 +827,7 @@ static int check_connection(THD *thd) if (thd->client_capabilities & CLIENT_IGNORE_SPACE) thd->variables.sql_mode|= MODE_IGNORE_SPACE; -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) DBUG_PRINT("info", ("client capabilities: %lu", thd->client_capabilities)); if (thd->client_capabilities & CLIENT_SSL) { diff --git a/sql/sql_connect.h b/sql/sql_connect.h new file mode 100644 index 00000000000..2334b7303be --- /dev/null +++ b/sql/sql_connect.h @@ -0,0 +1,43 @@ +/* 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_CONNECT_INCLUDED +#define SQL_CONNECT_INCLUDED + +#include "my_sys.h" /* pthread_handler_t */ +#include "mysql_com.h" /* enum_server_command */ + +class THD; +typedef struct st_lex_user LEX_USER; +typedef struct user_conn USER_CONN; + +void init_max_user_conn(void); +void free_max_user_conn(void); + +pthread_handler_t handle_one_connection(void *arg); +void do_handle_one_connection(THD *thd_arg); +bool init_new_connection_handler_thread(); +void reset_mqh(LEX_USER *lu, bool get_them); +bool check_mqh(THD *thd, uint check_command); +void time_out_user_resource_limits(THD *thd, USER_CONN *uc); +void decrease_user_connections(USER_CONN *uc); +void thd_init_client_charset(THD *thd, uint cs_number); +bool setup_connection_thread_globals(THD *thd); + +int check_user(THD *thd, enum enum_server_command command, + const char *passwd, uint passwd_len, const char *db, + bool check_count); + +#endif /* SQL_CONNECT_INCLUDED */ diff --git a/sql/sql_const.h b/sql/sql_const.h new file mode 100644 index 00000000000..72f34ed6be8 --- /dev/null +++ b/sql/sql_const.h @@ -0,0 +1,254 @@ +/* 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 */ + +/** + @file + File containing constants that can be used throughout the server. + + @note This file shall not contain any includes of any kinds. +*/ + +#ifndef SQL_CONST_INCLUDED +#define SQL_CONST_INCLUDED + +#define LIBLEN FN_REFLEN-FN_LEN /* Max l{ngd p} dev */ +/* extra 4+4 bytes for slave tmp tables */ +#define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4) +#define MAX_ALIAS_NAME 256 +#define MAX_FIELD_NAME 34 /* Max colum name length +2 */ +#define MAX_SYS_VAR_LENGTH 32 +#define MAX_KEY MAX_INDEXES /* Max used keys */ +#define MAX_REF_PARTS 16 /* Max parts used as ref */ +#define MAX_KEY_LENGTH 3072 /* max possible key */ +#if SIZEOF_OFF_T > 4 +#define MAX_REFLENGTH 8 /* Max length for record ref */ +#else +#define MAX_REFLENGTH 4 /* Max length for record ref */ +#endif +#define MAX_HOSTNAME 61 /* len+1 in mysql.user */ + +#define MAX_MBWIDTH 3 /* Max multibyte sequence */ +#define MAX_FIELD_CHARLENGTH 255 +#define MAX_FIELD_VARCHARLENGTH 65535 +#define MAX_FIELD_BLOBLENGTH UINT_MAX32 /* cf field_blob::get_length() */ +#define CONVERT_IF_BIGGER_TO_BLOB 512 /* Used for CREATE ... SELECT */ + +/* Max column width +1 */ +#define MAX_FIELD_WIDTH (MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1) + +#define MAX_BIT_FIELD_LENGTH 64 /* Max length in bits for bit fields */ + +#define MAX_DATE_WIDTH 10 /* YYYY-MM-DD */ +#define MAX_TIME_WIDTH 23 /* -DDDDDD HH:MM:SS.###### */ +#define MAX_DATETIME_FULL_WIDTH 29 /* YYYY-MM-DD HH:MM:SS.###### AM */ +#define MAX_DATETIME_WIDTH 19 /* YYYY-MM-DD HH:MM:SS */ +#define MAX_DATETIME_COMPRESSED_WIDTH 14 /* YYYYMMDDHHMMSS */ + +#define MAX_TABLES (sizeof(table_map)*8-3) /* Max tables in join */ +#define PARAM_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-3)) +#define OUTER_REF_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-2)) +#define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1)) +#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \ + RAND_TABLE_BIT) +#define MAX_FIELDS 4096 /* Limit in the .frm file */ +#define MAX_PARTITIONS 1024 + +#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1) + +#define MAX_SORT_MEMORY 2048*1024 +#define MIN_SORT_MEMORY 32*1024 + +/* Some portable defines */ + +#define portable_sizeof_char_ptr 8 +#define STRING_BUFFER_USUAL_SIZE 80 + +/* Memory allocated when parsing a statement / saving a statement */ +#define MEM_ROOT_BLOCK_SIZE 8192 +#define MEM_ROOT_PREALLOC 8192 +#define TRANS_MEM_ROOT_BLOCK_SIZE 4096 +#define TRANS_MEM_ROOT_PREALLOC 4096 + +#define DEFAULT_ERROR_COUNT 64 +#define EXTRA_RECORDS 10 /* Extra records in sort */ +#define SCROLL_EXTRA 5 /* Extra scroll-rows. */ +#define FIELD_NAME_USED ((uint) 32768) /* Bit set if fieldname used */ +#define FORM_NAME_USED ((uint) 16384) /* Bit set if formname used */ +#define FIELD_NR_MASK 16383 /* To get fieldnumber */ +#define FERR -1 /* Error from my_functions */ +#define CREATE_MODE 0 /* Default mode on new files */ +#define NAMES_SEP_CHAR '\377' /* Char to sep. names */ + +#define READ_RECORD_BUFFER (uint) (IO_SIZE*8) /* Pointer_buffer_size */ +#define DISK_BUFFER_SIZE (uint) (IO_SIZE*16) /* Size of diskbuffer */ + +#define FRM_VER_TRUE_VARCHAR (FRM_VER+4) /* 10 */ + +/*************************************************************************** + Configuration parameters +****************************************************************************/ + +#define ACL_CACHE_SIZE 256 +#define MAX_PASSWORD_LENGTH 32 +#define HOST_CACHE_SIZE 128 +#define MAX_ACCEPT_RETRY 10 // Test accept this many times +#define MAX_FIELDS_BEFORE_HASH 32 +#define USER_VARS_HASH_SIZE 16 +#define TABLE_OPEN_CACHE_MIN 400 +#define TABLE_OPEN_CACHE_DEFAULT 400 +#define TABLE_DEF_CACHE_DEFAULT 400 +/** + We must have room for at least 400 table definitions in the table + cache, since otherwise there is no chance prepared + statements that use these many tables can work. + Prepared statements use table definition cache ids (table_map_id) + as table version identifiers. If the table definition + cache size is less than the number of tables used in a statement, + the contents of the table definition cache is guaranteed to rotate + between a prepare and execute. This leads to stable validation + errors. In future we shall use more stable version identifiers, + for now the only solution is to ensure that the table definition + cache can contain at least all tables of a given statement. +*/ +#define TABLE_DEF_CACHE_MIN 400 + +/* + Stack reservation. + Feel free to raise this by the smallest amount you can to get the + "execution_constants" test to pass. +*/ +#define STACK_MIN_SIZE 16000 // Abort if less stack during eval. + +#define STACK_MIN_SIZE_FOR_OPEN 1024*80 +#define STACK_BUFF_ALLOC 352 ///< For stack overrun checks +#ifndef MYSQLD_NET_RETRY_COUNT +#define MYSQLD_NET_RETRY_COUNT 10 ///< Abort read after this many int. +#endif +#define TEMP_POOL_SIZE 128 + +#define QUERY_ALLOC_BLOCK_SIZE 8192 +#define QUERY_ALLOC_PREALLOC_SIZE 8192 +#define TRANS_ALLOC_BLOCK_SIZE 4096 +#define TRANS_ALLOC_PREALLOC_SIZE 4096 +#define RANGE_ALLOC_BLOCK_SIZE 4096 +#define ACL_ALLOC_BLOCK_SIZE 1024 +#define UDF_ALLOC_BLOCK_SIZE 1024 +#define TABLE_ALLOC_BLOCK_SIZE 1024 +#define BDB_LOG_ALLOC_BLOCK_SIZE 1024 +#define WARN_ALLOC_BLOCK_SIZE 2048 +#define WARN_ALLOC_PREALLOC_SIZE 1024 +#define PROFILE_ALLOC_BLOCK_SIZE 2048 +#define PROFILE_ALLOC_PREALLOC_SIZE 1024 + +/* + The following parameters is to decide when to use an extra cache to + optimise seeks when reading a big table in sorted order +*/ +#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024) +#define MIN_ROWS_TO_USE_TABLE_CACHE 100 +#define MIN_ROWS_TO_USE_BULK_INSERT 100 + +/** + The following is used to decide if MySQL should use table scanning + instead of reading with keys. The number says how many evaluation of the + WHERE clause is comparable to reading one extra row from a table. +*/ +#define TIME_FOR_COMPARE 5 // 5 compares == one read + +/** + Number of comparisons of table rowids equivalent to reading one row from a + table. +*/ +#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2) + +/* + For sequential disk seeks the cost formula is: + DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip + + The cost of average seek + DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0. +*/ +#define DISK_SEEK_BASE_COST ((double)0.5) + +#define BLOCKS_IN_AVG_SEEK 128 + +#define DISK_SEEK_PROP_COST ((double)0.5/BLOCKS_IN_AVG_SEEK) + + +/** + Number of rows in a reference table when refereed through a not unique key. + This value is only used when we don't know anything about the key + distribution. +*/ +#define MATCHING_ROWS_IN_OTHER_TABLE 10 + +#define RAID_BLOCK_SIZE 1024 + +#define MY_CHARSET_BIN_MB_MAXLEN 1 + +/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */ +#define KEY_DEFAULT_PACK_LENGTH 8 + +/** Characters shown for the command in 'show processlist'. */ +#define PROCESS_LIST_WIDTH 100 +/* Characters shown for the command in 'information_schema.processlist' */ +#define PROCESS_LIST_INFO_WIDTH 65535 + +#define PRECISION_FOR_DOUBLE 53 +#define PRECISION_FOR_FLOAT 24 + +/* -[digits].E+## */ +#define MAX_FLOAT_STR_LENGTH (FLT_DIG + 6) +/* -[digits].E+### */ +#define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7) + +/* + Default time to wait before aborting a new client connection + that does not respond to "initial server greeting" timely +*/ +#define CONNECT_TIMEOUT 10 + +/* The following can also be changed from the command line */ +#define DEFAULT_CONCURRENCY 10 +#define DELAYED_LIMIT 100 /**< pause after xxx inserts */ +#define DELAYED_QUEUE_SIZE 1000 +#define DELAYED_WAIT_TIMEOUT 5*60 /**< Wait for delayed insert */ +#define FLUSH_TIME 0 /**< Don't flush tables */ +#define MAX_CONNECT_ERRORS 10 ///< errors before disabling host + +#define LONG_TIMEOUT ((ulong) 3600L*24L*365L) + +/** + Maximum length of time zone name that we support (Time zone name is + char(64) in db). mysqlbinlog needs it. +*/ +#define MAX_TIME_ZONE_NAME_LENGTH (NAME_LEN + 1) + +#if defined(__WIN__) +#undef FLUSH_TIME +#define FLUSH_TIME 1800 /**< Flush every half hour */ + +#define INTERRUPT_PRIOR -2 +#define CONNECT_PRIOR -1 +#define WAIT_PRIOR 0 +#define QUERY_PRIOR 2 +#else +#define INTERRUPT_PRIOR 10 +#define CONNECT_PRIOR 9 +#define WAIT_PRIOR 8 +#define QUERY_PRIOR 6 +#endif /* __WIN92__ */ + +#endif /* SQL_CONST_INCLUDED */ diff --git a/sql/sql_crypt.cc b/sql/sql_crypt.cc index 3d7d248782b..455e7dc1e7b 100644 --- a/sql/sql_crypt.cc +++ b/sql/sql_crypt.cc @@ -26,7 +26,9 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_crypt.h" +#include "password.h" void SQL_CRYPT::init(ulong *rand_nr) { diff --git a/sql/sql_crypt.h b/sql/sql_crypt.h index dd1cba9ee0c..15cc495858b 100644 --- a/sql/sql_crypt.h +++ b/sql/sql_crypt.h @@ -21,6 +21,9 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_list.h" /* Sql_alloc */ +#include "mysql_com.h" /* rand_struct */ + class SQL_CRYPT :public Sql_alloc { struct rand_struct rand,org_rand; diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc index 0391ce6dc72..59bf0764ada 100644 --- a/sql/sql_cursor.cc +++ b/sql/sql_cursor.cc @@ -16,10 +16,12 @@ #pragma implementation /* gcc class implementation */ #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sql_cursor.h" #include "sql_select.h" #include "probes_mysql.h" +#include "sql_parse.h" // mysql_execute_command /**************************************************************************** Declarations. diff --git a/sql/sql_cursor.h b/sql/sql_cursor.h index 1f19cbfdbcf..2a394e281b4 100644 --- a/sql/sql_cursor.h +++ b/sql/sql_cursor.h @@ -20,6 +20,10 @@ #pragma interface /* gcc class interface */ #endif +#include "sql_class.h" /* Query_arena */ + +class JOIN; + /** @file diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 75855020127..15fdd842e34 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -16,7 +16,20 @@ /* create and drop of databases */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include "sql_db.h" +#include "sql_cache.h" // query_cache_* +#include "lock.h" // wait_if_global_read_lock, + // start_waiting_global_read_lock +#include "sql_table.h" // build_table_filename, + // filename_to_tablename +#include "sql_rename.h" // mysql_rename_tables +#include "sql_acl.h" // SELECT_ACL, DB_ACLS, + // acl_get, check_grant_db +#include "sql_base.h" // wait_for_condition +#include "log_event.h" // Query_log_event #include <mysys_err.h> #include "sp.h" #include "events.h" @@ -934,7 +947,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) } else { - Drop_table_error_handler err_handler(thd->get_internal_handler()); + Drop_table_error_handler err_handler; thd->push_internal_handler(&err_handler); error= -1; diff --git a/sql/sql_db.h b/sql/sql_db.h new file mode 100644 index 00000000000..96b3de80d3a --- /dev/null +++ b/sql/sql_db.h @@ -0,0 +1,53 @@ +/* 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_DB_INCLUDED +#define SQL_DB_INCLUDED + +#include "hash.h" /* HASH */ + +class THD; +typedef struct charset_info_st CHARSET_INFO; +typedef struct st_ha_create_information HA_CREATE_INFO; +typedef struct st_mysql_lex_string LEX_STRING; + +int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); +bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); +bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); +bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db); +bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, + bool force_switch); + +bool mysql_opt_change_db(THD *thd, + const LEX_STRING *new_db_name, + LEX_STRING *saved_db_name, + bool force_switch, + bool *cur_db_changed); +bool my_database_names_init(void); +void my_database_names_free(void); +bool check_db_dir_existence(const char *db_name); +bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create); +bool load_db_opt_by_name(THD *thd, const char *db_name, + HA_CREATE_INFO *db_create_info); +CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name); +bool my_dbopt_init(void); +void my_dbopt_cleanup(void); + +extern int creating_database; // How many database locks are made +extern HASH lock_db_cache; + +#define MY_DB_OPT_FILE "db.opt" + +#endif /* SQL_DB_INCLUDED */ diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 2c3242c10cd..2a8503077aa 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -19,11 +19,25 @@ Multi-table deletes were introduced by Monty and Sinisa */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_delete.h" +#include "sql_cache.h" // query_cache_* +#include "sql_base.h" // open_temprary_table +#include "sql_table.h" // build_table_filename +#include "lock.h" // lock_and_wait_for_table_name, + // unlock_table_name +#include "sql_view.h" // check_key_in_view, mysql_frm_type +#include "sql_parse.h" // mysql_init_select +#include "sql_acl.h" // *_ACL +#include "filesort.h" // filesort +#include "sql_handler.h" // mysql_ha_rm_tables #include "sql_select.h" #include "sp_head.h" #include "sql_trigger.h" #include "transaction.h" +#include "records.h" // init_read_record, + // end_read_record /** Implement DELETE SQL word. @@ -51,6 +65,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SELECT_LEX *select_lex= &thd->lex->select_lex; THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_delete"); + bool save_binlog_row_based; THD::enum_binlog_query_type query_type= thd->lex->sql_command == SQLCOM_TRUNCATE ? @@ -148,12 +163,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, query_type= THD::STMT_QUERY_TYPE; error= -1; // ok deleted= maybe_deleted; + save_binlog_row_based= thd->is_current_stmt_binlog_format_row(); goto cleanup; } if (error != HA_ERR_WRONG_COMMAND) { table->file->print_error(error,MYF(0)); error=0; + save_binlog_row_based= thd->is_current_stmt_binlog_format_row(); goto cleanup; } /* Handler didn't support fast delete; Delete rows one by one */ @@ -294,6 +311,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, table->mark_columns_needed_for_delete(); + save_binlog_row_based= thd->is_current_stmt_binlog_format_row(); + if (thd->lex->sql_command == SQLCOM_TRUNCATE && + thd->is_current_stmt_binlog_format_row()) + thd->clear_current_stmt_binlog_format_row(); + while (!(error=info.read_record(&info)) && !thd->killed && ! thd->is_error()) { @@ -392,7 +414,10 @@ cleanup: /* See similar binlogging code in sql_update.cc, for comments */ if ((error < 0) || thd->transaction.stmt.modified_non_trans_table) { - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open() && + !(thd->lex->sql_command == SQLCOM_TRUNCATE && + thd->is_current_stmt_binlog_format_row() && + find_temporary_table(thd, table_list))) { bool const is_trans= thd->lex->sql_command == SQLCOM_TRUNCATE ? @@ -424,6 +449,8 @@ cleanup: } } } + if (save_binlog_row_based) + thd->set_current_stmt_binlog_format_row(); DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table); free_underlaid_joins(thd, select_lex); if (error < 0 || @@ -1049,12 +1076,11 @@ bool multi_delete::send_eof() static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list) { - bool error, save_binlog_row_based= thd->is_current_stmt_binlog_format_row(); + bool error; DBUG_ENTER("mysql_truncate_by_delete"); table_list->lock_type= TL_WRITE; table_list->mdl_request.set_type(MDL_SHARED_WRITE); mysql_init_select(thd->lex); - thd->clear_current_stmt_binlog_format_row(); /* Delete all rows from table */ error= mysql_delete(thd, table_list, NULL, NULL, HA_POS_ERROR, LL(0), TRUE); /* @@ -1067,8 +1093,6 @@ static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list) trans_rollback_stmt(thd); trans_rollback(thd); } - if (save_binlog_row_based) - thd->set_current_stmt_binlog_format_row(); DBUG_RETURN(error); } diff --git a/sql/sql_delete.h b/sql/sql_delete.h new file mode 100644 index 00000000000..d1c1b363abd --- /dev/null +++ b/sql/sql_delete.h @@ -0,0 +1,34 @@ +/* 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_DELETE_INCLUDED +#define SQL_DELETE_INCLUDED + +#include "my_base.h" /* ha_rows */ + +class THD; +struct TABLE_LIST; +class Item; + +typedef class Item COND; +typedef struct st_sql_list SQL_LIST; + +int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); +bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, + SQL_LIST *order, ha_rows rows, ulonglong options, + bool reset_auto_increment); +bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok); + +#endif /* SQL_DELETE_INCLUDED */ diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 24088872471..e86ae52e501 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -20,9 +20,13 @@ */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include "sql_derived.h" #include "sql_select.h" - +#include "sql_view.h" // check_duplicate_names +#include "sql_acl.h" // SELECT_ACL /* diff --git a/sql/sql_derived.h b/sql/sql_derived.h new file mode 100644 index 00000000000..0d4eddedf22 --- /dev/null +++ b/sql/sql_derived.h @@ -0,0 +1,29 @@ +/* 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_DERIVED_INCLUDED +#define SQL_DERIVED_INCLUDED + +struct TABLE_LIST; +class THD; +struct LEX; + +bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd, + LEX *lex, + TABLE_LIST *table)); +bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t); +bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t); + +#endif /* SQL_DERIVED_INCLUDED */ diff --git a/sql/sql_do.cc b/sql/sql_do.cc index 0f3a7e1ecef..79e488ac2a5 100644 --- a/sql/sql_do.cc +++ b/sql/sql_do.cc @@ -16,8 +16,12 @@ /* Execute DO statement */ -#include "mysql_priv.h" +#include "sql_priv.h" #include "transaction.h" +#include "unireg.h" +#include "sql_do.h" +#include "sql_base.h" // setup_fields +#include "sql_select.h" // free_underlaid_joins bool mysql_do(THD *thd, List<Item> &values) { diff --git a/sql/sql_do.h b/sql/sql_do.h new file mode 100644 index 00000000000..56479f8f88e --- /dev/null +++ b/sql/sql_do.h @@ -0,0 +1,26 @@ +/* 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_DO_INCLUDED +#define SQL_DO_INCLUDED + +#include "sql_list.h" /* List */ + +class THD; +class Item; + +bool mysql_do(THD *thd, List<Item> &values); + +#endif /* SQL_DO_INCLUDED */ diff --git a/sql/sql_error.cc b/sql/sql_error.cc index eeefdb99eed..cc6529f7b10 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -42,7 +42,8 @@ This file contains the implementation of error and warnings related ***********************************************************************/ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sql_error.h" #include "sp_rcontext.h" diff --git a/sql/sql_error.h b/sql/sql_error.h index ac86ca4770c..9e649a004df 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -19,6 +19,7 @@ #include "sql_list.h" /* Sql_alloc, MEM_ROOT */ #include "m_string.h" /* LEX_STRING */ +#include "sql_string.h" /* String */ #include "mysql_com.h" /* MYSQL_ERRMSG_SIZE */ class THD; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 3afeb4164bd..23177b8f51a 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -51,7 +51,13 @@ cursor points at the first record). */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_handler.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_base.h" // close_thread_tables +#include "lock.h" // broadcast_refresh, mysql_unlock_tables +#include "key.h" // key_copy +#include "sql_base.h" // insert_fields #include "sql_select.h" #include <assert.h> @@ -405,6 +411,56 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) } +/** + A helper class to process an error from mysql_lock_tables(). + HANDLER READ statement's attempt to lock the subject table + may get aborted if there is a pending DDL. In that case + we close the table, reopen it, and try to read again. + This is implicit and obscure, since HANDLER position + is lost in the process, but it's the legacy server + behaviour we should preserve. +*/ + +class Sql_handler_lock_error_handler: public Internal_error_handler +{ +public: + virtual + bool handle_condition(THD *thd, + uint sql_errno, + const char *sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg, + MYSQL_ERROR **cond_hdl); + + bool need_reopen() const { return m_need_reopen; }; + void init() { m_need_reopen= FALSE; }; +private: + bool m_need_reopen; +}; + + +/** + Handle an error from mysql_lock_tables(). + Ignore ER_LOCK_ABORTED errors. +*/ + +bool +Sql_handler_lock_error_handler:: +handle_condition(THD *thd, + uint sql_errno, + const char *sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg, + MYSQL_ERROR **cond_hdl) +{ + *cond_hdl= NULL; + if (sql_errno == ER_LOCK_ABORTED) + m_need_reopen= TRUE; + + return m_need_reopen; +} + + /* Read from a HANDLER table. @@ -442,7 +498,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, uint num_rows; uchar *UNINIT_VAR(key); uint UNINIT_VAR(key_len); - bool need_reopen; + Sql_handler_lock_error_handler sql_handler_lock_error; DBUG_ENTER("mysql_ha_read"); DBUG_PRINT("enter",("'%s'.'%s' as '%s'", tables->db, tables->table_name, tables->alias)); @@ -506,8 +562,12 @@ retry: thd->open_tables= hash_tables->table; - lock= mysql_lock_tables(thd, &thd->open_tables, 1, 0, &need_reopen); + sql_handler_lock_error.init(); + thd->push_internal_handler(&sql_handler_lock_error); + + lock= mysql_lock_tables(thd, &thd->open_tables, 1, 0); + thd->pop_internal_handler(); /* In 5.1 and earlier, mysql_lock_tables() could replace the TABLE object with another one (reopen it). This is no longer the case @@ -517,8 +577,9 @@ retry: /* Restore previous context. */ thd->open_tables= backup_open_tables; - if (need_reopen) + if (sql_handler_lock_error.need_reopen()) { + DBUG_ASSERT(!lock && !thd->is_error()); mysql_ha_close_table(thd, hash_tables); goto retry; } diff --git a/sql/sql_handler.h b/sql/sql_handler.h new file mode 100644 index 00000000000..8666d5a8d7b --- /dev/null +++ b/sql/sql_handler.h @@ -0,0 +1,35 @@ +/* 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_HANDLER_INCLUDED +#define SQL_HANDLER_INCLUDED + +#include "sql_class.h" /* enum_ha_read_mode */ +#include "my_base.h" /* ha_rkey_function, ha_rows */ +#include "sql_list.h" /* List */ + +class THD; +struct TABLE_LIST; + +bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen); +bool mysql_ha_close(THD *thd, TABLE_LIST *tables); +bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, + List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows); +void mysql_ha_flush(THD *thd); +void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables); +void mysql_ha_cleanup(THD *thd); +void mysql_ha_move_tickets_after_trans_sentinel(THD *thd); + +#endif /* SQL_HANDLER_INCLUDED */ diff --git a/sql/sql_help.cc b/sql/sql_help.cc index e9b15e07e9d..7bea236269a 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -13,7 +13,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_help.h" +#include "sql_table.h" // primary_key_name +#include "sql_base.h" // REPORT_ALL_ERRORS, setup_tables +#include "opt_range.h" // SQL_SELECT +#include "records.h" // init_read_record, end_read_record struct st_find_field { diff --git a/sql/sql_help.h b/sql/sql_help.h new file mode 100644 index 00000000000..74cff691730 --- /dev/null +++ b/sql/sql_help.h @@ -0,0 +1,28 @@ +/* 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_HELP_INCLUDED +#define SQL_HELP_INCLUDED + +class THD; + + +/* + Function prototypes +*/ + +bool mysqld_help (THD *thd, const char *text); + +#endif /* SQL_HELP_INCLUDED */ diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 26fb4e4e4e4..103be4c851f 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -54,12 +54,24 @@ */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_insert.h" +#include "sql_update.h" // compare_record +#include "sql_base.h" // close_thread_tables +#include "sql_cache.h" // query_cache_* +#include "key.h" // key_copy +#include "lock.h" // mysql_unlock_tables #include "sp_head.h" +#include "sql_view.h" // check_key_in_view, insert_view_fields +#include "sql_table.h" // mysql_create_table_no_lock +#include "sql_acl.h" // *_ACL, check_grant_all_columns #include "sql_trigger.h" #include "sql_select.h" #include "sql_show.h" #include "slave.h" +#include "sql_parse.h" // end_active_trans #include "rpl_mi.h" #include "transaction.h" #include "sql_audit.h" @@ -2396,7 +2408,8 @@ void kill_delayed_threads(void) bool Delayed_insert::open_and_lock_table() { if (!(table= open_n_lock_single_table(&thd, &table_list, - TL_WRITE_DELAYED, 0))) + TL_WRITE_DELAYED, + MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK))) { thd.fatal_error(); // Abort waiting inserts return TRUE; @@ -2557,7 +2570,6 @@ pthread_handler_t handle_delayed_insert(void *arg) if (di->tables_in_use && ! thd->lock && !thd->killed) { - bool need_reopen; /* Request for new delayed insert. Lock the table, but avoid to be blocked by a global read lock. @@ -2568,30 +2580,10 @@ pthread_handler_t handle_delayed_insert(void *arg) handler will close the table and finish when the outstanding inserts are done. */ - if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, - MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK, - &need_reopen))) + if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, 0))) { - if (need_reopen && !thd->killed) - { - /* - We were waiting to obtain TL_WRITE_DELAYED (probably due to - someone having or requesting TL_WRITE_ALLOW_READ) and got - aborted. Try to reopen table and if it fails die. - */ - TABLE_LIST *tl_ptr = &di->table_list; - close_tables_for_reopen(thd, &tl_ptr, NULL); - di->table= 0; - if (di->open_and_lock_table()) - { - thd->killed= THD::KILL_CONNECTION; - } - } - else - { - /* Fatal error */ - thd->killed= THD::KILL_CONNECTION; - } + /* Fatal error */ + thd->killed= THD::KILL_CONNECTION; } mysql_cond_broadcast(&di->cond_client); } @@ -3542,7 +3534,6 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, List_iterator_fast<Item> it(*items); Item *item; Field *tmp_field; - bool not_used; DBUG_ENTER("create_table_from_items"); tmp_table.alias= 0; @@ -3666,8 +3657,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, since it won't wait for the table lock (we have exclusive metadata lock on the table) and thus can't get aborted. */ - if (! ((*lock)= mysql_lock_tables(thd, &table, 1, - MYSQL_LOCK_IGNORE_FLUSH, ¬_used)) || + if (! ((*lock)= mysql_lock_tables(thd, &table, 1, 0)) || hooks->postlock(&table, 1)) { if (*lock) diff --git a/sql/sql_insert.h b/sql/sql_insert.h new file mode 100644 index 00000000000..9511cee8526 --- /dev/null +++ b/sql/sql_insert.h @@ -0,0 +1,49 @@ +/* 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_INSERT_INCLUDED +#define SQL_INSERT_INCLUDED + +#include "sql_class.h" /* enum_duplicates */ +#include "sql_list.h" + +/* Instead of including sql_lex.h we add this typedef here */ +typedef List<Item> List_item; +typedef struct st_copy_info COPY_INFO; + +bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, + List<Item> &fields, List_item *values, + List<Item> &update_fields, + List<Item> &update_values, enum_duplicates duplic, + COND **where, bool select_insert, + bool check_fields, bool abort_on_warning); +bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields, + List<List_item> &values, List<Item> &update_fields, + List<Item> &update_values, enum_duplicates flag, + bool ignore); +void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type, + enum_duplicates duplic, + bool is_multi_insert); +int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, + TABLE_LIST *table_list); +void prepare_triggers_for_insert_stmt(TABLE *table); +int write_record(THD *thd, TABLE *table, COPY_INFO *info); +void kill_delayed_threads(void); + +#ifdef EMBEDDED_LIBRARY +inline void kill_delayed_threads(void) {} +#endif + +#endif /* SQL_INSERT_INCLUDED */ diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 14b5e160629..6384aa575fe 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -17,7 +17,11 @@ /* A lexical scanner on a temporary buffer with a yacc interface */ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_class.h" // sql_lex.h: SQLCOM_END +#include "sql_lex.h" +#include "sql_parse.h" // add_to_list #include "item_create.h" #include <m_ctype.h> #include <hash.h> diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 0b27f73e763..cb8a96ad2ed 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -20,6 +20,11 @@ #ifndef SQL_LEX_INCLUDED #define SQL_LEX_INCLUDED +#include "violite.h" /* SSL_type */ +#include "sql_trigger.h" +#include "item.h" /* From item_subselect.h: subselect_union_engine */ +#include "thr_lock.h" /* thr_lock_type, TL_UNLOCK */ + /* YACC and LEX Definitions */ /* These may not be declared yet */ @@ -35,6 +40,12 @@ class partition_info; class Event_parse_data; class set_var_base; class sys_var; +class Item_func_match; +class Alter_drop; +class Alter_column; +class Key; +class File_parser; +class Key_part_spec; /** used by the parser to store internal variable name @@ -55,6 +66,7 @@ struct sys_var_with_base #else #include "lex_symbol.h" #if MYSQL_LEX +#include "item_func.h" /* Cast_target used in sql_yacc.h */ #include "sql_yacc.h" #define LEX_YYSTYPE YYSTYPE * #else @@ -192,6 +204,12 @@ enum enum_drop_mode DROP_RESTRICT // RESTRICT option }; +/* Options to add_table_to_list() */ +#define TL_OPTION_UPDATING 1 +#define TL_OPTION_FORCE_INDEX 2 +#define TL_OPTION_IGNORE_LEAVES 4 +#define TL_OPTION_ALIAS 8 + typedef List<Item> List_item; /* SERVERS CACHE CHANGES */ @@ -2287,6 +2305,7 @@ extern bool is_lex_native_function(const LEX_STRING *name); */ void my_missing_function_error(const LEX_STRING &token, const char *name); +bool is_keyword(const char *name, uint len); #endif /* MYSQL_SERVER */ #endif /* SQL_LEX_INCLUDED */ diff --git a/sql/sql_list.cc b/sql/sql_list.cc index a256212471d..31f0ba28b85 100644 --- a/sql/sql_list.cc +++ b/sql/sql_list.cc @@ -18,6 +18,7 @@ #pragma implementation // gcc: Class implementation #endif +#include "unireg.h" #include "sql_list.h" list_node end_of_list; diff --git a/sql/sql_list.h b/sql/sql_list.h index fdc80b116a7..60d9697a606 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -26,6 +26,11 @@ void *sql_alloc(size_t); +#include "my_sys.h" /* alloc_root, TRASH, MY_WME, + MY_FAE, MY_ALLOW_ZERO_PTR */ +#include "m_string.h" /* bfill */ +#include "thr_malloc.h" /* sql_alloc */ + /* mysql standard class memory allocator */ class Sql_alloc @@ -61,6 +66,57 @@ public: }; +/** + Struct to handle simple linked lists. + + @todo What is the relation between this class and list_node, below? + /Matz + + @see list_node, base_list, List + +*/ +typedef struct st_sql_list { + uint elements; + uchar *first; + uchar **next; + + st_sql_list() {} /* Remove gcc warning */ + inline void empty() + { + elements=0; + first=0; + next= &first; + } + inline void link_in_list(uchar *element,uchar **next_ptr) + { + elements++; + (*next)=element; + next= next_ptr; + *next=0; + } + inline void save_and_clear(struct st_sql_list *save) + { + *save= *this; + empty(); + } + inline void push_front(struct st_sql_list *save) + { + *save->next= first; /* link current list last */ + first= save->first; + elements+= save->elements; + } + inline void push_back(struct st_sql_list *save) + { + if (save->first) + { + *next= save->first; + next= save->next; + elements+= save->elements; + } + } +} SQL_LIST; + + /* Basic single linked list Used for item and item_buffs. @@ -637,4 +693,7 @@ list_copy_and_replace_each_value(List<T> &list, MEM_ROOT *mem_root) it.replace(el->clone(mem_root)); } +void free_list(I_List <i_string_pair> *list); +void free_list(I_List <i_string> *list); + #endif // INCLUDES_MYSQL_SQL_LIST_H diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 3f49543c69d..87a347b9f98 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -17,8 +17,21 @@ /* Copy data from a textfile to table */ /* 2006-12 Erik Wetterberg : LOAD XML added */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_load.h" +#include "sql_load.h" +#include "sql_cache.h" // query_cache_* +#include "sql_base.h" // fill_record_n_invoke_before_triggers #include <my_dir.h> +#include "sql_view.h" // check_key_in_view +#include "sql_insert.h" // check_that_all_fields_are_given_values, + // prepare_triggers_for_insert_stmt, + // write_record +#include "sql_acl.h" // INSERT_ACL, UPDATE_ACL +#include "log_event.h" // Delete_file_log_event, + // Execute_load_query_log_event, + // LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F #include <m_ctype.h> #include "rpl_mi.h" #include "sql_repl.h" diff --git a/sql/sql_load.h b/sql/sql_load.h new file mode 100644 index 00000000000..344b869854a --- /dev/null +++ b/sql/sql_load.h @@ -0,0 +1,34 @@ +/* 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_LOAD_INCLUDED +#define SQL_LOAD_INCLUDED + +#include "sql_list.h" /* List */ + +class Item; + +#include "sql_class.h" /* enum_duplicates */ + +class sql_exchange; + +int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, + List<Item> &fields_vars, List<Item> &set_fields, + List<Item> &set_values_list, + enum enum_duplicates handle_duplicates, bool ignore, + bool local_file); + + +#endif /* SQL_LOAD_INCLUDED */ diff --git a/sql/sql_locale.cc b/sql/sql_locale.cc index 9b1bb67ca06..abd9c395083 100644 --- a/sql/sql_locale.cc +++ b/sql/sql_locale.cc @@ -20,7 +20,11 @@ !! This file is built from my_locale.pl !! */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_locale.h" +#include "sql_class.h" // THD +#include "my_sys.h" // MY_*, NullS, NULL enum err_msgs_index diff --git a/sql/sql_locale.h b/sql/sql_locale.h new file mode 100644 index 00000000000..e62660aaa47 --- /dev/null +++ b/sql/sql_locale.h @@ -0,0 +1,78 @@ +/* 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_LOCALE_INCLUDED +#define SQL_LOCALE_INCLUDED + +typedef struct my_locale_errmsgs +{ + const char *language; + const char **errmsgs; +} MY_LOCALE_ERRMSGS; + +#include "my_global.h" /* uint */ + +typedef struct st_typelib TYPELIB; + +class MY_LOCALE +{ +public: + uint number; + const char *name; + const char *description; + const bool is_ascii; + TYPELIB *month_names; + TYPELIB *ab_month_names; + TYPELIB *day_names; + TYPELIB *ab_day_names; + uint max_month_name_length; + uint max_day_name_length; + uint decimal_point; + uint thousand_sep; + const char *grouping; + MY_LOCALE_ERRMSGS *errmsgs; + MY_LOCALE(uint number_par, + const char *name_par, const char *descr_par, bool is_ascii_par, + TYPELIB *month_names_par, TYPELIB *ab_month_names_par, + TYPELIB *day_names_par, TYPELIB *ab_day_names_par, + uint max_month_name_length_par, uint max_day_name_length_par, + uint decimal_point_par, uint thousand_sep_par, + const char *grouping_par, MY_LOCALE_ERRMSGS *errmsgs_par) : + number(number_par), + name(name_par), description(descr_par), is_ascii(is_ascii_par), + month_names(month_names_par), ab_month_names(ab_month_names_par), + day_names(day_names_par), ab_day_names(ab_day_names_par), + max_month_name_length(max_month_name_length_par), + max_day_name_length(max_day_name_length_par), + decimal_point(decimal_point_par), + thousand_sep(thousand_sep_par), + grouping(grouping_par), + errmsgs(errmsgs_par) + {} +}; +/* Exported variables */ + +extern MY_LOCALE my_locale_en_US; +extern MY_LOCALE *my_locales[]; +extern MY_LOCALE *my_default_lc_messages; +extern MY_LOCALE *my_default_lc_time_names; + +/* Exported functions */ + +MY_LOCALE *my_locale_by_name(const char *name); +MY_LOCALE *my_locale_by_number(uint number); +void cleanup_errmsgs(void); + +#endif /* SQL_LOCALE_INCLUDED */ diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index 4f3e4e1c6d1..e9c9402a89a 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -21,8 +21,10 @@ * o Berkeley DB: removing unneeded log files. */ -#include "mysql_priv.h" - +#include "sql_priv.h" +#include "sql_manager.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_base.h" // flush_tables static bool volatile manager_thread_in_use; static bool abort_manager; diff --git a/sql/sql_manager.h b/sql/sql_manager.h new file mode 100644 index 00000000000..a0ef8080aa7 --- /dev/null +++ b/sql/sql_manager.h @@ -0,0 +1,23 @@ +/* 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_MANAGER_INCLUDED +#define SQL_MANAGER_INCLUDED + +void start_handle_manager(); +void stop_handle_manager(); +bool mysql_manager_submit(void (*action)()); + +#endif /* SQL_MANAGER_INCLUDED */ diff --git a/sql/sql_map.cc b/sql/sql_map.cc index e4e85c51d17..35a248e5465 100644 --- a/sql/sql_map.cc +++ b/sql/sql_map.cc @@ -18,7 +18,11 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_map.h" // mapped_files +#include "sql_class.h" // THD + #include <sys/stat.h> #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> diff --git a/sql/sql_map.h b/sql/sql_map.h index 5ae260841e0..be1c145df3f 100644 --- a/sql/sql_map.h +++ b/sql/sql_map.h @@ -23,6 +23,9 @@ #pragma interface /* gcc class implementation */ #endif +#include "my_base.h" /* ha_rows */ +#include "sql_list.h" /* ilink */ + class mapped_files; mapped_files *map_file(const char * name,uchar *magic,uint magic_length); void unmap_file(mapped_files *map); diff --git a/sql/sql_olap.cc b/sql/sql_olap.cc index dccfcbaf8ac..cdfa5e3f496 100644 --- a/sql/sql_olap.cc +++ b/sql/sql_olap.cc @@ -31,7 +31,8 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sql_select.h" diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 6403ad99282..8dc5f4a8c56 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -14,7 +14,68 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "my_global.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_parse.h" // sql_kill, *_precheck, *_prepare +#include "lock.h" // wait_if_global_read_lock, + // unlock_global_read_lock, + // try_transactional_lock, + // check_transactional_lock, + // set_handler_table_locks, + // start_waiting_global_read_lock, + // lock_global_read_lock, + // make_global_read_lock_block_commit +#include "sql_base.h" // find_temporary_tablesx +#include "sql_cache.h" // QUERY_CACHE_FLAGS_SIZE, query_cache_* +#include "sql_show.h" // mysqld_list_*, mysqld_show_*, + // calc_sum_of_all_status +#include "mysqld.h" +#include "sql_locale.h" // my_locale_en_US +#include "log.h" // flush_error_log +#include "sql_view.h" // mysql_create_view, mysql_drop_view +#include "sql_delete.h" // mysql_truncate, mysql_delete +#include "sql_insert.h" // mysql_insert +#include "sql_update.h" // mysql_update, mysql_multi_update +#include "sql_partition.h" // struct partition_info +#include "sql_db.h" // mysql_change_db, mysql_create_db, + // mysql_rm_db, mysql_upgrade_db, + // mysql_alter_db, + // check_db_dir_existence, + // my_dbopt_cleanup +#include "sql_table.h" // mysql_create_like_table, + // mysql_create_table, + // mysql_alter_table, + // mysql_recreate_table, + // mysql_backup_table, + // mysql_restore_table +#include "sql_connect.h" // check_user, + // decrease_user_connections, + // thd_init_client_charset, check_mqh, + // reset_mqh +#include "sql_rename.h" // mysql_rename_table +#include "sql_tablespace.h" // mysql_alter_tablespace +#include "hostname.h" // hostname_cache_refresh +#include "sql_acl.h" // *_ACL, check_grant, is_acl_user, + // has_any_table_level_privileges, + // mysql_drop_user, mysql_rename_user, + // check_grant_routine, + // mysql_routine_grant, + // mysql_show_grants, + // sp_grant_privileges, ... +#include "sql_test.h" // mysql_print_status +#include "sql_select.h" // handle_select, mysql_select, + // mysql_explain_union +#include "sql_load.h" // mysql_load +#include "sql_servers.h" // create_servers, alter_servers, + // drop_servers, servers_reload +#include "sql_handler.h" // mysql_ha_open, mysql_ha_close, + // mysql_ha_read +#include "sql_binlog.h" // mysql_client_binlog_statement +#include "sql_do.h" // mysql_do +#include "sql_help.h" // mysqld_help +#include "rpl_constants.h" // Incident, INCIDENT_LOST_EVENTS +#include "log_event.h" #include "sql_repl.h" #include "rpl_filter.h" #include "repl_failsafe.h" @@ -34,6 +95,8 @@ #include "probes_mysql.h" #include "set_var.h" +#define FLAGSTR(V,F) ((V)&(F)?#F" ":"") + /** @defgroup Runtime_Environment Runtime Environment @{ @@ -1631,6 +1694,14 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, - you can't flush WITH READ LOCK a non-existent table - you can't flush WITH READ LOCK under LOCK TABLES - currently incompatible with the GRL (@todo: fix) + + Effect on views and temporary tables. + ------------------------------------ + You can only apply this command to existing base tables. + If a view with such name exists, ER_WRONG_OBJECT is returned. + If a temporary table with such name exists, it's ignored: + if there is a base table, it's used, otherwise ER_NO_SUCH_TABLE + is returned. */ static bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) @@ -1665,6 +1736,21 @@ static bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) if (lock_table_names(thd, all_tables)) goto error; + for (table_list= all_tables; table_list; + table_list= table_list->next_global) + { + /* Remove the table from cache. */ + mysql_mutex_lock(&LOCK_open); + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, + table_list->db, + table_list->table_name); + mysql_mutex_unlock(&LOCK_open); + + /* Skip views and temporary tables. */ + table_list->required_type= FRMTYPE_TABLE; /* Don't try to flush views. */ + table_list->open_type= OT_BASE_ONLY; /* Ignore temporary tables. */ + } + if (open_and_lock_tables(thd, all_tables, FALSE, MYSQL_OPEN_HAS_MDL_LOCK, &lock_tables_prelocking_strategy) || @@ -2825,15 +2911,20 @@ end_with_restore_list: NOTE: SHOW_VIEW ACL is checked when the view is created. */ + DBUG_PRINT("debug", ("lex->only_view: %d, table: %s.%s", + lex->only_view, + first_table->db, first_table->table_name)); if (lex->only_view) { if (check_table_access(thd, SELECT_ACL, first_table, FALSE, 1, FALSE)) { + DBUG_PRINT("debug", ("check_table_access failed")); my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), "SHOW", thd->security_ctx->priv_user, thd->security_ctx->host_or_ip, first_table->alias); goto error; } + DBUG_PRINT("debug", ("check_table_access succeeded")); /* Ignore temporary tables if this is "SHOW CREATE VIEW" */ first_table->open_type= OT_BASE_ONLY; @@ -2846,6 +2937,8 @@ end_with_restore_list: access is granted. We need to check if first_table->grant.privilege contains any table-specific privilege. */ + DBUG_PRINT("debug", ("first_table->grant.privilege: %x", + first_table->grant.privilege)); if (check_some_access(thd, SHOW_CREATE_TABLE_ACLS, first_table) || (first_table->grant.privilege & SHOW_CREATE_TABLE_ACLS) == 0) { diff --git a/sql/sql_parse.h b/sql/sql_parse.h new file mode 100644 index 00000000000..3c34b063d91 --- /dev/null +++ b/sql/sql_parse.h @@ -0,0 +1,210 @@ +/* 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 sql_kill(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 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, const char *inBuf, uint length, + const char ** semicolon); +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_LIST &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); + +bool begin_trans(THD *thd); +bool end_active_trans(THD *thd); +int end_trans(THD *thd, enum enum_mysql_completiontype completion); + + +/* 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_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 *thd, ulong access, const char *db, + ulong *save_priv, bool no_grant, bool no_errors, + bool schema_db) +{ + 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 */ diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index d400e96ce7e..0eb92dc23a9 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -46,12 +46,26 @@ /* Some general useful functions */ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_partition.h" +#include "key.h" // key_restore +#include "sql_parse.h" // parse_sql +#include "sql_cache.h" // query_cache_invalidate3 +#include "lock.h" // mysql_lock_remove +#include "sql_show.h" // append_identifier #include <errno.h> #include <m_ctype.h> #include "my_md5.h" #include "transaction.h" +#include "sql_base.h" // close_thread_tables +#include "sql_table.h" // build_table_filename, + // build_table_shadow_filename, + // table_to_filename +#include "opt_range.h" // store_key_image_to_rec +#include "sql_analyse.h" // append_escaped + #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" @@ -2128,8 +2142,6 @@ static int check_part_field(enum_field_types sql_type, } switch (sql_type) { - case MYSQL_TYPE_NEWDECIMAL: - case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: @@ -2151,6 +2163,8 @@ static int check_part_field(enum_field_types sql_type, *result_type= STRING_RESULT; *need_cs_check= TRUE; return FALSE; + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_NULL: case MYSQL_TYPE_FLOAT: @@ -3359,6 +3373,7 @@ int get_partition_id_range(partition_info *part_info, *func_value= part_func_value; if (unsigned_flag) part_func_value-= 0x8000000000000000ULL; + /* Search for the partition containing part_func_value */ while (max_part_id > min_part_id) { loc_part_id= (max_part_id + min_part_id) / 2; @@ -3498,11 +3513,17 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info, part_end_val= range_array[loc_part_id]; if (left_endpoint) { + DBUG_ASSERT(part_func_value > part_end_val ? + (loc_part_id == max_partition && + !part_info->defined_max_value) : + 1); /* In case of PARTITION p VALUES LESS THAN MAXVALUE - the maximum value is in the current partition. + the maximum value is in the current (last) partition. + If value is equal or greater than the endpoint, + the range starts from the next partition. */ - if (part_func_value == part_end_val && + if (part_func_value >= part_end_val && (loc_part_id < max_partition || !part_info->defined_max_value)) loc_part_id++; } @@ -4536,6 +4557,12 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, { DBUG_ENTER("prep_alter_part_table"); + /* Foreign keys on partitioned tables are not supported, waits for WL#148 */ + if (table->part_info && (alter_info->flags & ALTER_FOREIGN_KEY)) + { + my_error(ER_FOREIGN_KEY_ON_PARTITIONED, MYF(0)); + DBUG_RETURN(TRUE); + } /* We are going to manipulate the partition info on the table object so we need to ensure that the table instance is removed from the diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 7ac1415c158..8542074e718 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -20,12 +20,51 @@ #pragma interface /* gcc class implementation */ #endif +#include "sql_list.h" /* List */ +#include "table.h" /* TABLE_LIST */ + +class Alter_info; +class Field; +class String; +class handler; +class partition_info; +struct TABLE; +struct TABLE_LIST; +typedef struct st_bitmap MY_BITMAP; +typedef struct st_ha_create_information HA_CREATE_INFO; +typedef struct st_key KEY; +typedef struct st_key_range key_range; + /* Flags for partition handlers */ #define HA_CAN_PARTITION (1 << 0) /* Partition support */ #define HA_CAN_UPDATE_PARTITION_KEY (1 << 1) #define HA_CAN_PARTITION_UNIQUE (1 << 2) #define HA_USE_AUTO_PARTITION (1 << 3) +#define NORMAL_PART_NAME 0 +#define TEMP_PART_NAME 1 +#define RENAMED_PART_NAME 2 + +typedef struct st_lock_param_type +{ + TABLE_LIST *table_list; + ulonglong copied; + ulonglong deleted; + THD *thd; + HA_CREATE_INFO *create_info; + Alter_info *alter_info; + TABLE *table; + KEY *key_info_buffer; + const char *db; + const char *table_name; + uchar *pack_frm_data; + uint key_count; + uint db_options; + size_t pack_frm_len; + partition_info *part_info; +} ALTER_PARTITION_PARAM_TYPE; + + /*typedef struct { ulonglong data_file_length; ulonglong max_data_file_length; @@ -101,6 +140,7 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info, bool check_part_func_fields(Field **ptr, bool ok_with_charsets); bool field_is_partition_charset(Field *field); Item* convert_charset_partition_constant(Item *item, CHARSET_INFO *cs); +void mem_alloc_error(size_t size); /* A "Get next" function for partition iterator. @@ -220,4 +260,39 @@ typedef int (*get_partitions_in_range_iter)(partition_info *part_info, #include "partition_info.h" +#ifdef WITH_PARTITION_STORAGE_ENGINE +uint fast_alter_partition_table(THD *thd, TABLE *table, + Alter_info *alter_info, + HA_CREATE_INFO *create_info, + TABLE_LIST *table_list, + char *db, + const char *table_name, + uint fast_alter_partition); +uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info, + enum partition_state part_state); +uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, + HA_CREATE_INFO *create_info, + handlerton *old_db_type, + bool *partition_changed, + uint *fast_alter_partition); +char *generate_partition_syntax(partition_info *part_info, + uint *buf_length, bool use_sql_alloc, + bool show_partition_options, + HA_CREATE_INFO *create_info, + Alter_info *alter_info); +#endif + +void create_partition_name(char *out, const char *in1, + const char *in2, uint name_variant, + bool translate); +void create_subpartition_name(char *out, const char *in1, + const char *in2, const char *in3, + uint name_variant); + +void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf); +void set_key_field_ptr(KEY *key_info, const uchar *new_buf, + const uchar *old_buf); + +extern const LEX_STRING partition_keywords[]; + #endif /* SQL_PARTITION_INCLUDED */ diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 3d1380d46f3..31e0cced207 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -13,10 +13,24 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "sql_priv.h" // SHOW_MY_BOOL +#include "unireg.h" +#include "my_global.h" // REQUIRED by m_string.h +#include "sql_class.h" // set_var.h: THD #include "sys_vars_shared.h" +#include "sql_locale.h" +#include "sql_plugin.h" +#include "sql_parse.h" // check_table_access +#include "sql_base.h" // close_thread_tables +#include "key.h" // key_copy +#include "sql_show.h" // remove_status_vars, add_status_vars +#include "strfunc.h" // find_set +#include "sql_acl.h" // *_ACL +#include "records.h" // init_read_record, end_read_record #include <my_pthread.h> #include <my_getopt.h> #include <mysql/plugin_audit.h> +#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT #define REPORT_TO_LOG 1 #define REPORT_TO_USER 2 @@ -1817,6 +1831,9 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE); + if (check_table_access(thd, DELETE_ACL, &tables, FALSE, 1, FALSE)) + DBUG_RETURN(TRUE); + /* need to open before acquiring LOCK_plugin or it will deadlock */ if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT))) DBUG_RETURN(TRUE); diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 1a870ec260e..e7ecca029b9 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -16,6 +16,22 @@ #ifndef _sql_plugin_h #define _sql_plugin_h +/* + the following #define adds server-only members to enum_mysql_show_type, + that is defined in plugin.h +*/ +#define SHOW_always_last SHOW_KEY_CACHE_LONG, \ + SHOW_KEY_CACHE_LONGLONG, SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \ + SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \ + SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS, SHOW_LEX_STRING +#include <mysql/plugin.h> +#undef SHOW_always_last + +#include "m_string.h" /* LEX_STRING */ +#include "my_alloc.h" /* MEM_ROOT */ + +#include "my_sys.h" /* CALLER_INFO_PROTO */ + class sys_var; enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED}; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 31e3baca764..739b6576a99 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -83,10 +83,24 @@ When one supplies long data for a placeholder: at statement execute. */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include "sql_class.h" // set_var.h: THD #include "set_var.h" #include "sql_prepare.h" +#include "sql_parse.h" // insert_precheck, update_precheck, delete_precheck +#include "sql_base.h" // close_thread_tables +#include "sql_cache.h" // query_cache_* +#include "sql_view.h" // create_view_precheck +#include "sql_delete.h" // mysql_prepare_delete #include "sql_select.h" // for JOIN +#include "sql_insert.h" // upgrade_lock_type_for_insert, mysql_prepare_insert +#include "sql_update.h" // mysql_prepare_update +#include "sql_db.h" // mysql_opt_change_db, mysql_change_db +#include "sql_acl.h" // *_ACL +#include "sql_derived.h" // mysql_derived_prepare, + // mysql_handle_derived #include "sql_cursor.h" #include "sp_head.h" #include "sp.h" @@ -98,6 +112,7 @@ When one supplies long data for a placeholder: #else #include <mysql_com.h> #endif +#include "lock.h" // MYSQL_OPEN_FORCE_SHARED_MDL /** A result class used to send cursor rows using the binary protocol. @@ -3769,7 +3784,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) if (state == Query_arena::PREPARED) state= Query_arena::EXECUTED; - if (this->lex->sql_command == SQLCOM_CALL) + if (error == 0 && this->lex->sql_command == SQLCOM_CALL) { if (is_sql_prepare()) thd->protocol_text.send_out_parameters(&this->lex->param_list); @@ -3777,7 +3792,6 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) thd->protocol->send_out_parameters(&this->lex->param_list); } - /* Log COM_EXECUTE to the general log. Note, that in case of SQL prepared statements this causes two records to be output: diff --git a/sql/sql_priv.h b/sql/sql_priv.h new file mode 100644 index 00000000000..cc67fa9c010 --- /dev/null +++ b/sql/sql_priv.h @@ -0,0 +1,265 @@ +/* Copyright 2000-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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** + @file + + @details + Mostly this file is used in the server. But a little part of it is used in + mysqlbinlog too (definition of SELECT_DISTINCT and others). + The consequence is that 90% of the file is wrapped in \#ifndef MYSQL_CLIENT, + except the part which must be in the server and in the client. +*/ + +#ifndef MYSQL_PRIV_H +#define MYSQL_PRIV_H + +#ifndef MYSQL_CLIENT + +/* + Generates a warning that a feature is deprecated. After a specified + version asserts that the feature is removed. + + Using it as + + WARN_DEPRECATED(thd, 6,2, "BAD", "'GOOD'"); + + Will result in a warning + + "The syntax 'BAD' is deprecated and will be removed in MySQL 6.2. Please + use 'GOOD' instead" + + Note that in macro arguments BAD is not quoted, while 'GOOD' is. + Note that the version is TWO numbers, separated with a comma + (two macro arguments, that is) +*/ +#define WARN_DEPRECATED(Thd,VerHi,VerLo,Old,New) \ + do { \ + compile_time_assert(MYSQL_VERSION_ID < VerHi * 10000 + VerLo * 100); \ + if (((THD *) Thd) != NULL) \ + push_warning_printf(((THD *) Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \ + ER_WARN_DEPRECATED_SYNTAX, \ + ER(ER_WARN_DEPRECATED_SYNTAX), \ + (Old), (New)); \ + else \ + sql_print_warning("The syntax '%s' is deprecated and will be removed " \ + "in a future release. Please use %s instead.", \ + (Old), (New)); \ + } while(0) + +extern char err_shared_dir[]; + +/*************************************************************************/ + +#endif + +/* + This is included in the server and in the client. + Options for select set by the yacc parser (stored in lex->options). + + NOTE + log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD + options list are written into binlog. These options can NOT change their + values, or it will break replication between version. + + context is encoded as following: + SELECT - SELECT_LEX_NODE::options + THD - THD::options + intern - neither. used only as + func(..., select_node->options | thd->options | OPTION_XXX, ...) + + TODO: separate three contexts above, move them to separate bitfields. +*/ + +#define SELECT_DISTINCT (1ULL << 0) // SELECT, user +#define SELECT_STRAIGHT_JOIN (1ULL << 1) // SELECT, user +#define SELECT_DESCRIBE (1ULL << 2) // SELECT, user +#define SELECT_SMALL_RESULT (1ULL << 3) // SELECT, user +#define SELECT_BIG_RESULT (1ULL << 4) // SELECT, user +#define OPTION_FOUND_ROWS (1ULL << 5) // SELECT, user +#define OPTION_TO_QUERY_CACHE (1ULL << 6) // SELECT, user +#define SELECT_NO_JOIN_CACHE (1ULL << 7) // intern +/** always the opposite of OPTION_NOT_AUTOCOMMIT except when in fix_autocommit() */ +#define OPTION_AUTOCOMMIT (1ULL << 8) // THD, user +#define OPTION_BIG_SELECTS (1ULL << 9) // THD, user +#define OPTION_LOG_OFF (1ULL << 10) // THD, user +#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user, unused +#define TMP_TABLE_ALL_COLUMNS (1ULL << 12) // SELECT, intern +#define OPTION_WARNINGS (1ULL << 13) // THD, user +#define OPTION_AUTO_IS_NULL (1ULL << 14) // THD, user, binlog +#define OPTION_FOUND_COMMENT (1ULL << 15) // SELECT, intern, parser +#define OPTION_SAFE_UPDATES (1ULL << 16) // THD, user +#define OPTION_BUFFER_RESULT (1ULL << 17) // SELECT, user +#define OPTION_BIN_LOG (1ULL << 18) // THD, user +#define OPTION_NOT_AUTOCOMMIT (1ULL << 19) // THD, user +#define OPTION_BEGIN (1ULL << 20) // THD, intern +#define OPTION_TABLE_LOCK (1ULL << 21) // THD, intern +#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE) +#define OPTION_KEEP_LOG (1ULL << 23) // THD, user + +/* The following is used to detect a conflict with DISTINCT */ +#define SELECT_ALL (1ULL << 24) // SELECT, user, parser +/** The following can be set when importing tables in a 'wrong order' + to suppress foreign key checks */ +#define OPTION_NO_FOREIGN_KEY_CHECKS (1ULL << 26) // THD, user, binlog +/** The following speeds up inserts to InnoDB tables by suppressing unique + key checks in some cases */ +#define OPTION_RELAXED_UNIQUE_CHECKS (1ULL << 27) // THD, user, binlog +#define SELECT_NO_UNLOCK (1ULL << 28) // SELECT, intern +#define OPTION_SCHEMA_TABLE (1ULL << 29) // SELECT, intern +/** Flag set if setup_tables already done */ +#define OPTION_SETUP_TABLES_DONE (1ULL << 30) // intern +/** If not set then the thread will ignore all warnings with level notes. */ +#define OPTION_SQL_NOTES (1ULL << 31) // THD, user +/** + Force the used temporary table to be a MyISAM table (because we will use + fulltext functions when reading from it. +*/ +#define TMP_TABLE_FORCE_MYISAM (1ULL << 32) +#define OPTION_PROFILING (1ULL << 33) + + +/* The rest of the file is included in the server only */ +#ifndef MYSQL_CLIENT + +/* @@optimizer_switch flags. These must be in sync with optimizer_switch_typelib */ +#define OPTIMIZER_SWITCH_INDEX_MERGE (1ULL << 0) +#define OPTIMIZER_SWITCH_INDEX_MERGE_UNION (1ULL << 1) +#define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION (1ULL << 2) +#define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT (1ULL << 3) +#define OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN (1ULL << 4) +#define OPTIMIZER_SWITCH_LAST (1ULL << 5) + +/* The following must be kept in sync with optimizer_switch_str in mysqld.cc */ +#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \ + OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \ + OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \ + OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \ + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) + + +/* + Replication uses 8 bytes to store SQL_MODE in the binary log. The day you + use strictly more than 64 bits by adding one more define above, you should + contact the replication team because the replication code should then be + updated (to store more bytes on disk). + + NOTE: When adding new SQL_MODE types, make sure to also add them to + the scripts used for creating the MySQL system tables + in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql + +*/ + +// uncachable cause +#define UNCACHEABLE_DEPENDENT 1 +#define UNCACHEABLE_RAND 2 +#define UNCACHEABLE_SIDEEFFECT 4 +/// forcing to save JOIN for explain +#define UNCACHEABLE_EXPLAIN 8 +/** Don't evaluate subqueries in prepare even if they're not correlated */ +#define UNCACHEABLE_PREPARE 16 +/* For uncorrelated SELECT in an UNION with some correlated SELECTs */ +#define UNCACHEABLE_UNITED 32 +#define UNCACHEABLE_CHECKOPTION 64 + +/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */ +#define UNDEF_POS (-1) + +/* BINLOG_DUMP options */ + +#define BINLOG_DUMP_NON_BLOCK 1 + +/* sql_show.cc:show_log_files() */ +#define SHOW_LOG_STATUS_FREE "FREE" +#define SHOW_LOG_STATUS_INUSE "IN USE" + +/* + Some defines for exit codes for ::is_equal class functions. +*/ +#define IS_EQUAL_NO 0 +#define IS_EQUAL_YES 1 +#define IS_EQUAL_PACK_LENGTH 2 + +enum enum_parsing_place +{ + NO_MATTER, + IN_HAVING, + SELECT_LIST, + IN_WHERE, + IN_ON +}; + + +enum enum_var_type +{ + OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL +}; + +class sys_var; + +#ifdef MYSQL_SERVER + +#endif /* MYSQL_SERVER */ + +#ifdef MYSQL_SERVER +/* + A set of constants used for checking non aggregated fields and sum + functions mixture in the ONLY_FULL_GROUP_BY_MODE. +*/ +#define NON_AGG_FIELD_USED 1 +#define SUM_FUNC_USED 2 + +/* + External variables +*/ + +/* sql_yacc.cc */ +#ifndef DBUG_OFF +extern void turn_parser_debug_on(); + +#endif + +/** + convert a hex digit into number. +*/ + +inline int hexchar_to_int(char c) +{ + if (c <= '9' && c >= '0') + return c-'0'; + c|=32; + if (c <= 'f' && c >= 'a') + return c-'a'+10; + return -1; +} + +/* This must match the path length limit in the ER_NOT_RW_DIR error msg. */ +#define ER_NOT_RW_DIR_PATHSIZE 200 + +#define IS_TABLESPACES_TABLESPACE_NAME 0 +#define IS_TABLESPACES_ENGINE 1 +#define IS_TABLESPACES_TABLESPACE_TYPE 2 +#define IS_TABLESPACES_LOGFILE_GROUP_NAME 3 +#define IS_TABLESPACES_EXTENT_SIZE 4 +#define IS_TABLESPACES_AUTOEXTEND_SIZE 5 +#define IS_TABLESPACES_MAXIMUM_SIZE 6 +#define IS_TABLESPACES_NODEGROUP_ID 7 +#define IS_TABLESPACES_TABLESPACE_COMMENT 8 + +#endif /* MYSQL_SERVER */ + +#endif /* MYSQL_CLIENT */ + +#endif /* MYSQL_PRIV_H */ diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc index 74d7beede47..4a0d3d944ad 100644 --- a/sql/sql_profile.cc +++ b/sql/sql_profile.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2007 MySQL AB +/* Copyright (c) 2007, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -29,8 +29,12 @@ */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_profile.h" #include "my_sys.h" +#include "sql_show.h" // schema_table_store_record +#include "sql_class.h" // THD #define TIME_FLOAT_DIGITS 9 /** two vals encoded: (dec*100)+len */ @@ -508,7 +512,7 @@ void PROFILING::set_query_source(char *query_source_arg, uint query_length_arg) There are two ways to get to this function: Selecting from the information schema, and a SHOW command. */ -int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond) +int PROFILING::fill_statistics_info(THD *thd_arg, TABLE_LIST *tables, Item *cond) { DBUG_ENTER("PROFILING::fill_statistics_info"); TABLE *table= tables->table; @@ -543,7 +547,7 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond) /* Skip the first. We count spans of fence, not fence-posts. */ if (previous == NULL) continue; - if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE) + if (thd_arg->lex->sql_command == SQLCOM_SHOW_PROFILE) { /* We got here via a SHOW command. That means that we stored @@ -556,14 +560,14 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond) struct where and having conditions at the SQL layer, then this condition should be ripped out. */ - if (thd->lex->profile_query_id == 0) /* 0 == show final query */ + if (thd_arg->lex->profile_query_id == 0) /* 0 == show final query */ { if (query != last) continue; } else { - if (thd->lex->profile_query_id != query->profiling_query_id) + if (thd_arg->lex->profile_query_id != query->profiling_query_id) continue; } } @@ -701,7 +705,7 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond) table->field[17]->set_notnull(); } - if (schema_table_store_record(thd, table)) + if (schema_table_store_record(thd_arg, table)) DBUG_RETURN(1); } diff --git a/sql/sql_profile.h b/sql/sql_profile.h index 33597ca337e..ff16a2da19b 100644 --- a/sql/sql_profile.h +++ b/sql/sql_profile.h @@ -16,6 +16,12 @@ #ifndef _SQL_PROFILE_H #define _SQL_PROFILE_H +class Item; +struct TABLE_LIST; +class THD; +typedef struct st_field_info ST_FIELD_INFO; +typedef struct st_schema_table ST_SCHEMA_TABLE; + extern ST_FIELD_INFO query_profile_statistics_info[]; int fill_query_profile_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond); int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table); @@ -34,7 +40,8 @@ int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table); #if defined(ENABLED_PROFILING) -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 009563319cd..d387010141c 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -17,9 +17,18 @@ Atomic rename of table; RENAME TABLE t1 to t2, tmp to t1 [,...] */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_rename.h" +#include "sql_cache.h" // query_cache_* +#include "sql_table.h" // build_table_filename +#include "sql_view.h" // mysql_frm_type, mysql_rename_view #include "sql_trigger.h" - +#include "lock.h" // wait_if_global_read_lock, lock_table_names, + // unlock_table_names, + // start_waiting_global_read_lock +#include "sql_base.h" // tdc_remove_table +#include "sql_handler.h" // mysql_ha_rm_tables static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error); diff --git a/sql/sql_rename.h b/sql/sql_rename.h new file mode 100644 index 00000000000..7fbf9f1e5cd --- /dev/null +++ b/sql/sql_rename.h @@ -0,0 +1,27 @@ +/* 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_RENAME_INCLUDED +#define SQL_RENAME_INCLUDED + +class THD; +struct TABLE_LIST; + +bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent); +bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, + char *new_table_name, char *new_table_alias, + bool skip_error); + +#endif /* SQL_RENAME_INCLUDED */ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 510f9d8dc01..1ee770f70ef 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -13,11 +13,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_parse.h" // check_access #ifdef HAVE_REPLICATION #include "rpl_mi.h" #include "sql_repl.h" +#include "sql_acl.h" // SUPER_ACL #include "log_event.h" #include "rpl_filter.h" #include <my_dir.h> @@ -1994,7 +1997,6 @@ int log_loaded_block(IO_CACHE* file) if (mysql_bin_log.write(&b)) DBUG_RETURN(1); lf_info->wrote_create_file= 1; - DBUG_SYNC_POINT("debug_lock.created_file_event",10); } } DBUG_RETURN(0); diff --git a/sql/sql_repl.h b/sql/sql_repl.h index aa71ac96ff8..4d3b0b8d62c 100644 --- a/sql/sql_repl.h +++ b/sql/sql_repl.h @@ -65,6 +65,7 @@ typedef struct st_load_file_info int log_loaded_block(IO_CACHE* file); int init_replication_sys_vars(); +void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags); #endif /* HAVE_REPLICATION */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 099d1a87bfd..62a51a32ca2 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -28,16 +28,33 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sql_select.h" +#include "sql_cache.h" // query_cache_* +#include "sql_table.h" // primary_key_name #include "sql_cursor.h" #include "probes_mysql.h" - +#include "key.h" // key_copy, key_cmp, key_cmp_if_same +#include "lock.h" // mysql_unlock_some_tables, + // mysql_unlock_read_tables +#include "sql_show.h" // append_identifier +#include "sql_base.h" // setup_wild, setup_fields, fill_record +#include "sql_parse.h" // check_stack_overrun +#include "sql_partition.h" // make_used_partitions_str +#include "sql_acl.h" // *_ACL +#include "sql_test.h" // print_where, print_keyuse_array, + // print_sjm, print_plan +#include "records.h" // init_read_record, end_read_record +#include "filesort.h" // filesort_free_buffers +#include "sql_union.h" // mysql_union #include <m_ctype.h> #include <my_bit.h> #include <hash.h> #include <ft_global.h> +#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1)) + const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref", "MAYBE_REF","ALL","range","index","fulltext", "ref_or_null","unique_subquery","index_subquery", @@ -1116,6 +1133,31 @@ JOIN::optimize() conds=new Item_int((longlong) 0,1); // Always false } + /* + It's necessary to check const part of HAVING cond as + there is a chance that some cond parts may become + const items after make_join_statisctics(for example + when Item is a reference to cost table field from + outer join). + This check is performed only for those conditions + which do not use aggregate functions. In such case + temporary table may not be used and const condition + elements may be lost during further having + condition transformation in JOIN::exec. + */ + if (having && !having->with_sum_func) + { + COND *const_cond= make_cond_for_table(having, const_table_map, 0); + DBUG_EXECUTE("where", print_where(const_cond, "const_having_cond", + QT_ORDINARY);); + if (const_cond && !const_cond->val_int()) + { + zero_result_cause= "Impossible HAVING noticed after reading const tables"; + error= 0; + DBUG_RETURN(0); + } + } + /* Cache constant expressions in WHERE, HAVING, ON clauses. */ cache_const_exprs(); @@ -2964,7 +3006,8 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds, s->quick=select->quick; s->needed_reg=select->needed_reg; select->quick=0; - if (records == 0 && s->table->reginfo.impossible_range) + if (records == 0 && s->table->reginfo.impossible_range && + (s->table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT)) { /* Impossible WHERE or ON expression @@ -4114,7 +4157,7 @@ is_indexed_agg_distinct(JOIN *join, List<Item_field> *out_args) optimization is applicable */ if (out_args) - out_args->push_back((Item_field *) expr); + out_args->push_back((Item_field *) expr->real_item()); result= true; } } @@ -5946,7 +5989,7 @@ store_val_in_field(Field *field, Item *item, enum_check_fields check_flag) @retval TRUE error occurred */ bool -JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table) +JOIN::make_simple_join(JOIN *parent, TABLE *temp_table) { DBUG_ENTER("JOIN::make_simple_join"); @@ -5959,7 +6002,7 @@ JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table) DBUG_RETURN(TRUE); /* purecov: inspected */ join_tab= parent->join_tab_reexec; - parent->table_reexec[0]= tmp_table; + parent->table_reexec[0]= temp_table; tables= 1; const_tables= 0; const_table_map= 0; @@ -5979,7 +6022,7 @@ JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table) do_send_rows= row_limit ? 1 : 0; join_tab->cache.buff=0; /* No caching */ - join_tab->table=tmp_table; + join_tab->table=temp_table; join_tab->select=0; join_tab->select_cond=0; join_tab->quick=0; @@ -5996,8 +6039,8 @@ JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table) join_tab->join= this; join_tab->ref.key_parts= 0; bzero((char*) &join_tab->read_record,sizeof(join_tab->read_record)); - tmp_table->status=0; - tmp_table->null_row=0; + temp_table->status=0; + temp_table->null_row=0; DBUG_RETURN(FALSE); } @@ -13098,12 +13141,35 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, uint find_shortest_key(TABLE *table, const key_map *usable_keys) { - uint min_length= (uint) ~0; uint best= MAX_KEY; + uint usable_clustered_pk= (table->file->primary_key_is_clustered() && + table->s->primary_key != MAX_KEY && + usable_keys->is_set(table->s->primary_key)) ? + table->s->primary_key : MAX_KEY; if (!usable_keys->is_clear_all()) { + uint min_length= (uint) ~0; for (uint nr=0; nr < table->s->keys ; nr++) { + /* + As far as + 1) clustered primary key entry data set is a set of all record + fields (key fields and not key fields) and + 2) secondary index entry data is a union of its key fields and + primary key fields (at least InnoDB and its derivatives don't + duplicate primary key fields there, even if the primary and + the secondary keys have a common subset of key fields), + then secondary index entry data is always a subset of primary key + entry, and the PK is always longer. + Unfortunately, key_info[nr].key_length doesn't show the length + of key/pointer pair but a sum of key field lengths only, thus + we can't estimate index IO volume comparing only this key_length + value of seconday keys and clustered PK. + So, try secondary keys first, and choose PK only if there are no + usable secondary covering keys: + */ + if (nr == usable_clustered_pk) + continue; if (usable_keys->is_set(nr)) { if (table->key_info[nr].key_length < min_length) @@ -13114,7 +13180,7 @@ uint find_shortest_key(TABLE *table, const key_map *usable_keys) } } } - return best; + return best != MAX_KEY ? best : usable_clustered_pk; } /** @@ -17150,7 +17216,17 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) first= 0; else str->append(','); - item->print_item_w_name(str, query_type); + + if (master_unit()->item && item->is_autogenerated_name) + { + /* + Do not print auto-generated aliases in subqueries. It has no purpose + in a view definition or other contexts where the query is printed. + */ + item->print(str, query_type); + } + else + item->print_item_w_name(str, query_type); } /* diff --git a/sql/sql_select.h b/sql/sql_select.h index 3cec00a84c8..ccf88c2cc5c 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -30,6 +30,10 @@ #include "procedure.h" #include <myisam.h> +#include "sql_array.h" /* Array */ +#include "records.h" /* READ_RECORD */ +#include "opt_range.h" /* SQL_SELECT, QUICK_SELECT_I */ + typedef struct keyuse_t { TABLE *table; @@ -798,6 +802,46 @@ bool error_if_full_join(JOIN *join); int report_error(TABLE *table, int error); int safe_index_read(JOIN_TAB *tab); COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value); +int get_quick_record(SQL_SELECT *select); +SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length, + SORT_FIELD *sortorder); +int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, + List<Item> &fields, List <Item> &all_fields, ORDER *order); +int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, + List<Item> &fields, List<Item> &all_fields, ORDER *order, + bool *hidden_group_fields); +bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select, + Item **ref_pointer_array, ORDER *group_list= NULL); + +bool handle_select(THD *thd, LEX *lex, select_result *result, + ulong setup_tables_done_option); +bool mysql_select(THD *thd, Item ***rref_pointer_array, + TABLE_LIST *tables, uint wild_num, List<Item> &list, + COND *conds, uint og_num, ORDER *order, ORDER *group, + Item *having, ORDER *proc_param, ulonglong select_type, + select_result *result, SELECT_LEX_UNIT *unit, + SELECT_LEX *select_lex); +void free_underlaid_joins(THD *thd, SELECT_LEX *select); +bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, + select_result *result); +Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, + Item ***copy_func, Field **from_field, + Field **def_field, + bool group, bool modify_item, + bool table_cant_handle_bit_fields, + bool make_copy_field, + uint convert_blob_length); + +/* + General routine to change field->ptr of a NULL-terminated array of Field + objects. Useful when needed to call val_int, val_str or similar and the + field data is not in table->record[0] but in some other structure. + set_key_field_ptr changes all fields of an index using a key_info object. + All methods presume that there is at least one field to change. +*/ + +TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list); + inline bool optimizer_flag(THD *thd, uint flag) { diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 0bf38639ff7..c7f9cf0b132 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -33,13 +33,18 @@ currently running transactions etc will not be disrupted. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_servers.h" +#include "unireg.h" +#include "sql_base.h" // close_thread_tables +#include "records.h" // init_read_record, end_read_record #include "hash_filo.h" #include <m_ctype.h> #include <stdarg.h> #include "sp_head.h" #include "sp.h" #include "transaction.h" +#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT /* We only use 1 mutex to guard the data structures - THR_LOCK_servers. diff --git a/sql/sql_servers.h b/sql/sql_servers.h index 12855f8473c..3c338bbe3f9 100644 --- a/sql/sql_servers.h +++ b/sql/sql_servers.h @@ -16,8 +16,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "my_global.h" /* uint */ #include "slave.h" // for tables_ok(), rpl_filter +class THD; +typedef struct st_lex_server_options LEX_SERVER_OPTIONS; +typedef struct st_mem_root MEM_ROOT; + /* structs */ typedef struct st_federated_server { diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8b8e223ad02..1b77e20cc02 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -16,10 +16,26 @@ /* Function with list databases, tables or fields */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include "sql_acl.h" // fill_schema_*_privileges #include "sql_select.h" // For select_describe +#include "sql_base.h" // close_tables_for_reopen #include "sql_show.h" +#include "sql_table.h" // filename_to_tablename, + // primary_key_name, + // build_table_filename #include "repl_failsafe.h" +#include "sql_view.h" // mysql_frm_type +#include "sql_parse.h" // check_access, check_table_access +#include "sql_partition.h" // partition_element +#include "sql_db.h" // check_db_dir_existence, load_db_opt_by_name +#include "sql_time.h" // interval_type_to_name +#include "tztime.h" // struct Time_zone +#include "sql_acl.h" // TABLE_ACLS, check_grant, DB_ACLS, acl_get, + // check_grant_db +#include "filesort.h" // filesort_free_buffers #include "sp.h" #include "sp_head.h" #include "sp_pcontext.h" @@ -33,6 +49,7 @@ #include "event_data_objects.h" #endif #include <my_dir.h> +#include "lock.h" // MYSQL_LOCK_IGNORE_FLUSH #define STR_OR_NIL(S) ((S) ? (S) : "<nil>") @@ -2934,7 +2951,7 @@ fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables, */ lex->sql_command= SQLCOM_SHOW_FIELDS; res= open_normal_and_derived_tables(thd, show_table_list, - (MYSQL_LOCK_IGNORE_FLUSH | + (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL | (can_deadlock ? MYSQL_OPEN_FAIL_ON_MDL_CONFLICT : 0))); @@ -3516,7 +3533,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) show_table_list->i_s_requested_object= schema_table->i_s_requested_object; res= open_normal_and_derived_tables(thd, show_table_list, - (MYSQL_LOCK_IGNORE_FLUSH | + (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL | (can_deadlock ? MYSQL_OPEN_FAIL_ON_MDL_CONFLICT : 0))); lex->sql_command= save_sql_command; diff --git a/sql/sql_show.h b/sql/sql_show.h index fa067a46033..d1323ede8c1 100644 --- a/sql/sql_show.h +++ b/sql/sql_show.h @@ -16,12 +16,24 @@ #ifndef SQL_SHOW_H #define SQL_SHOW_H +#include "sql_list.h" /* List */ +#include "handler.h" /* enum_schema_tables */ +#include "table.h" /* enum_schema_table_state */ + /* Forward declarations */ +class JOIN; class String; class THD; +class sp_name; +struct TABLE_LIST; struct st_ha_create_information; +typedef class st_select_lex SELECT_LEX; typedef st_ha_create_information HA_CREATE_INFO; -struct TABLE_LIST; +struct LEX; +typedef struct st_mysql_show_var SHOW_VAR; +typedef struct st_schema_table ST_SCHEMA_TABLE; +struct TABLE; +typedef struct system_status_var STATUS_VAR; enum find_files_result { FIND_FILES_OK, @@ -29,6 +41,46 @@ enum find_files_result { FIND_FILES_DIR }; +/* Used by handlers to store things in schema tables */ +#define IS_FILES_FILE_ID 0 +#define IS_FILES_FILE_NAME 1 +#define IS_FILES_FILE_TYPE 2 +#define IS_FILES_TABLESPACE_NAME 3 +#define IS_FILES_TABLE_CATALOG 4 +#define IS_FILES_TABLE_SCHEMA 5 +#define IS_FILES_TABLE_NAME 6 +#define IS_FILES_LOGFILE_GROUP_NAME 7 +#define IS_FILES_LOGFILE_GROUP_NUMBER 8 +#define IS_FILES_ENGINE 9 +#define IS_FILES_FULLTEXT_KEYS 10 +#define IS_FILES_DELETED_ROWS 11 +#define IS_FILES_UPDATE_COUNT 12 +#define IS_FILES_FREE_EXTENTS 13 +#define IS_FILES_TOTAL_EXTENTS 14 +#define IS_FILES_EXTENT_SIZE 15 +#define IS_FILES_INITIAL_SIZE 16 +#define IS_FILES_MAXIMUM_SIZE 17 +#define IS_FILES_AUTOEXTEND_SIZE 18 +#define IS_FILES_CREATION_TIME 19 +#define IS_FILES_LAST_UPDATE_TIME 20 +#define IS_FILES_LAST_ACCESS_TIME 21 +#define IS_FILES_RECOVER_TIME 22 +#define IS_FILES_TRANSACTION_COUNTER 23 +#define IS_FILES_VERSION 24 +#define IS_FILES_ROW_FORMAT 25 +#define IS_FILES_TABLE_ROWS 26 +#define IS_FILES_AVG_ROW_LENGTH 27 +#define IS_FILES_DATA_LENGTH 28 +#define IS_FILES_MAX_DATA_LENGTH 29 +#define IS_FILES_INDEX_LENGTH 30 +#define IS_FILES_DATA_FREE 31 +#define IS_FILES_CREATE_TIME 32 +#define IS_FILES_UPDATE_TIME 33 +#define IS_FILES_CHECK_TIME 34 +#define IS_FILES_CHECKSUM 35 +#define IS_FILES_STATUS 36 +#define IS_FILES_EXTRA 37 + find_files_result find_files(THD *thd, List<LEX_STRING> *files, const char *db, const char *path, const char *wild, bool dir); @@ -38,4 +90,47 @@ int view_store_create_info(THD *thd, TABLE_LIST *table, String *buff); int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table); +void append_identifier(THD *thd, String *packet, const char *name, + uint length); +void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild); +int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd); +bool mysqld_show_create(THD *thd, TABLE_LIST *table_list); +bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create); + +void mysqld_list_processes(THD *thd,const char *user,bool verbose); +int mysqld_show_status(THD *thd); +int mysqld_show_variables(THD *thd,const char *wild); +bool mysqld_show_storage_engines(THD *thd); +bool mysqld_show_authors(THD *thd); +bool mysqld_show_contributors(THD *thd); +bool mysqld_show_privileges(THD *thd); +bool mysqld_show_column_types(THD *thd); +char *make_backup_log_name(char *buff, const char *name, const char* log_ext); +void calc_sum_of_all_status(STATUS_VAR *to); +void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user, + const LEX_STRING *definer_host); +int add_status_vars(SHOW_VAR *list); +void remove_status_vars(SHOW_VAR *list); +void init_status_vars(); +void free_status_vars(); +void reset_status_vars(); +bool show_create_trigger(THD *thd, const sp_name *trg_name); +void view_store_options(THD *thd, TABLE_LIST *table, String *buff); + +void init_fill_schema_files_row(TABLE* table); +bool schema_table_store_record(THD *thd, TABLE *table); +void initialize_information_schema_acl(); + +ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name); +ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx); +int make_schema_select(THD *thd, SELECT_LEX *sel, + enum enum_schema_tables schema_table_idx); +int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list); +bool get_schema_tables_result(JOIN *join, + enum enum_schema_table_state executed_place); +enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table); + +/* These functions were under INNODB_COMPATIBILITY_HOOKS */ +int get_quote_char_for_identifier(THD *thd, const char *name, uint length); + #endif /* SQL_SHOW_H */ diff --git a/sql/sql_signal.cc b/sql/sql_signal.cc index c9ab37272b8..8ae77f3645b 100644 --- a/sql/sql_signal.cc +++ b/sql/sql_signal.cc @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mysql_priv.h" +#include "sql_priv.h" #include "sp_head.h" #include "sp_pcontext.h" #include "sp_rcontext.h" diff --git a/sql/sql_sort.h b/sql/sql_sort.h index 102b3ef0a11..45ef14c1319 100644 --- a/sql/sql_sort.h +++ b/sql/sql_sort.h @@ -16,6 +16,18 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "my_global.h" /* uchar */ +#include "my_base.h" /* ha_rows */ +#include "my_sys.h" /* qsort2_cmp */ + +typedef struct st_buffpek BUFFPEK; +typedef struct st_queue QUEUE; +typedef struct st_sort_field SORT_FIELD; + +class Field; +struct TABLE; + + /* Defines used by filesort and uniques */ #define MERGEBUFF 7 diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 75e8ca30cf0..9fbc06b7529 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -405,6 +405,16 @@ bool String::append(const char *s) } + +bool String::append_ulonglong(ulonglong val) +{ + if (realloc(str_length+MAX_BIGINT_WIDTH+2)) + return TRUE; + char *end= (char*) longlong10_to_str(val, (char*) Ptr + str_length, 10); + str_length= end - Ptr; + return FALSE; +} + /* Append a string in the given charset to the string with character set recoding diff --git a/sql/sql_string.h b/sql/sql_string.h index 38f843e7e8f..debfb7aa9c6 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -22,7 +22,15 @@ #pragma interface /* gcc class implementation */ #endif +#include "m_ctype.h" /* my_charset_bin */ +#include "my_sys.h" /* alloc_root, my_free, my_realloc */ +#include "m_string.h" /* TRASH */ + class String; +typedef struct charset_info_st CHARSET_INFO; +typedef struct st_io_cache IO_CACHE; +typedef struct st_mem_root MEM_ROOT; + int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, @@ -259,6 +267,7 @@ public: bool append(const char *s); bool append(const char *s,uint32 arg_length); bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs); + bool append_ulonglong(ulonglong val); bool append(IO_CACHE* file, uint32 arg_length); bool append_with_prefill(const char *s, uint32 arg_length, uint32 full_length, char fill_char); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 8ba8c50b01e..c3a39354ff1 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -15,14 +15,40 @@ /* drop and alter of tables */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "debug_sync.h" +#include "sql_table.h" +#include "sql_rename.h" // do_rename +#include "sql_parse.h" // test_if_data_home_dir +#include "sql_cache.h" // query_cache_* +#include "sql_base.h" // open_temporary_table +#include "lock.h" // wait_if_global_read_lock, lock_table_names, + // start_waiting_global_read_lock, + // unlock_table_names, mysql_unlock_tables +#include "strfunc.h" // find_type2, find_set +#include "sql_view.h" // mysql_frm_type, view_checksum, mysql_frm_type +#include "sql_delete.h" // mysql_truncate +#include "sql_partition.h" // mem_alloc_error, + // generate_partition_syntax, + // partition_info +#include "sql_db.h" // load_db_opt_by_name, lock_db_cache, creating_database +#include "sql_time.h" // make_truncated_value_warning +#include "records.h" // init_read_record, end_read_record +#include "filesort.h" // filesort_free_buffers +#include "sql_select.h" // setup_order, + // make_unireg_sortorder +#include "sql_handler.h" // mysql_ha_rm_tables +#include "discover.h" // readfrm +#include "my_pthread.h" // pthread_mutex_t +#include "log_event.h" // Query_log_event #include <hash.h> #include <myisam.h> #include <my_dir.h> #include "sp_head.h" #include "sp.h" #include "sql_trigger.h" +#include "sql_parse.h" #include "sql_show.h" #include "transaction.h" #include "keycaches.h" @@ -1811,7 +1837,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, my_bool drop_temporary) { bool error; - Drop_table_error_handler err_handler(thd->get_internal_handler()); + Drop_table_error_handler err_handler; DBUG_ENTER("mysql_rm_table"); @@ -4426,7 +4452,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, MY_STAT stat_info; Open_table_context ot_ctx_unused(thd, LONG_TIMEOUT); DBUG_ENTER("prepare_for_repair"); - uint reopen_for_repair_flags= (MYSQL_LOCK_IGNORE_FLUSH | + uint reopen_for_repair_flags= (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_HAS_MDL_LOCK); if (!(check_opt->sql_flags & TT_USEFRM)) @@ -5490,6 +5516,45 @@ err: DBUG_RETURN(-1); } +/** + @brief Check if both DROP and CREATE are present for an index in ALTER TABLE + + @details Checks if any index is being modified (present as both DROP INDEX + and ADD INDEX) in the current ALTER TABLE statement. Needed for disabling + online ALTER TABLE. + + @param table The table being altered + @param alter_info The ALTER TABLE structure + @return presence of index being altered + @retval FALSE No such index + @retval TRUE Have at least 1 index modified +*/ + +static bool +is_index_maintenance_unique (TABLE *table, Alter_info *alter_info) +{ + List_iterator<Key> key_it(alter_info->key_list); + List_iterator<Alter_drop> drop_it(alter_info->drop_list); + Key *key; + + while ((key= key_it++)) + { + if (key->name.str) + { + Alter_drop *drop; + + drop_it.rewind(); + while ((drop= drop_it++)) + { + if (drop->type == Alter_drop::KEY && + !my_strcasecmp(system_charset_info, key->name.str, drop->name)) + return TRUE; + } + } + } + return FALSE; +} + /* SYNOPSIS @@ -5578,6 +5643,7 @@ compare_tables(TABLE *table, */ Alter_info tmp_alter_info(*alter_info, thd->mem_root); uint db_options= 0; /* not used */ + /* Create the prepared information. */ if (mysql_prepare_create_table(thd, create_info, &tmp_alter_info, @@ -6858,10 +6924,14 @@ view_err: */ new_db_type= create_info->db_type; + if (is_index_maintenance_unique (table, alter_info)) + need_copy_table= ALTER_TABLE_DATA_CHANGED; + if (mysql_prepare_alter_table(thd, table, create_info, alter_info)) goto err; - - need_copy_table= alter_info->change_level; + + if (need_copy_table == ALTER_TABLE_METADATA_ONLY) + need_copy_table= alter_info->change_level; set_table_default_charset(thd, create_info, db); @@ -7155,7 +7225,7 @@ view_err: tbl.table_name= tbl.alias= tmp_name; /* Table is in thd->temporary_tables */ (void) open_table(thd, &tbl, thd->mem_root, &ot_ctx_unused, - MYSQL_LOCK_IGNORE_FLUSH); + MYSQL_OPEN_IGNORE_FLUSH); new_table= tbl.table; } else @@ -7950,22 +8020,28 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, for (uint i= 0; i < t->s->fields; i++ ) { Field *f= t->field[i]; - enum_field_types field_type= f->type(); - /* - BLOB and VARCHAR have pointers in their field, we must convert - to string; GEOMETRY is implemented on top of BLOB. - */ - if ((field_type == MYSQL_TYPE_BLOB) || - (field_type == MYSQL_TYPE_VARCHAR) || - (field_type == MYSQL_TYPE_GEOMETRY)) - { - String tmp; - f->val_str(&tmp); - row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(), tmp.length()); + + /* + BLOB and VARCHAR have pointers in their field, we must convert + to string; GEOMETRY is implemented on top of BLOB. + BIT may store its data among NULL bits, convert as well. + */ + switch (f->type()) { + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_GEOMETRY: + case MYSQL_TYPE_BIT: + { + String tmp; + f->val_str(&tmp); + row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(), + tmp.length()); + break; + } + default: + row_crc= my_checksum(row_crc, f->ptr, f->pack_length()); + break; } - else - row_crc= my_checksum(row_crc, f->ptr, - f->pack_length()); } crc+= row_crc; diff --git a/sql/sql_table.h b/sql/sql_table.h new file mode 100644 index 00000000000..3114876f5ed --- /dev/null +++ b/sql/sql_table.h @@ -0,0 +1,215 @@ +/* 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_TABLE_INCLUDED +#define SQL_TABLE_INCLUDED + +#include "my_global.h" /* my_bool */ +#include "my_sys.h" // pthread_mutex_t + +class Alter_info; +class Alter_info; +class Create_field; +struct TABLE_LIST; +class THD; +struct TABLE; +struct handlerton; +typedef struct st_ha_check_opt HA_CHECK_OPT; +typedef struct st_ha_create_information HA_CREATE_INFO; +typedef struct st_key_cache KEY_CACHE; +typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE; +typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE; +typedef struct st_mysql_lex_string LEX_STRING; +typedef struct st_order ORDER; + +enum ddl_log_entry_code +{ + /* + DDL_LOG_EXECUTE_CODE: + This is a code that indicates that this is a log entry to + be executed, from this entry a linked list of log entries + can be found and executed. + DDL_LOG_ENTRY_CODE: + An entry to be executed in a linked list from an execute log + entry. + DDL_IGNORE_LOG_ENTRY_CODE: + An entry that is to be ignored + */ + DDL_LOG_EXECUTE_CODE = 'e', + DDL_LOG_ENTRY_CODE = 'l', + DDL_IGNORE_LOG_ENTRY_CODE = 'i' +}; + +enum ddl_log_action_code +{ + /* + The type of action that a DDL_LOG_ENTRY_CODE entry is to + perform. + DDL_LOG_DELETE_ACTION: + Delete an entity + DDL_LOG_RENAME_ACTION: + Rename an entity + DDL_LOG_REPLACE_ACTION: + Rename an entity after removing the previous entry with the + new name, that is replace this entry. + */ + DDL_LOG_DELETE_ACTION = 'd', + DDL_LOG_RENAME_ACTION = 'r', + DDL_LOG_REPLACE_ACTION = 's' +}; + + +typedef struct st_ddl_log_entry +{ + const char *name; + const char *from_name; + const char *handler_name; + uint next_entry; + uint entry_pos; + enum ddl_log_entry_code entry_type; + enum ddl_log_action_code action_type; + /* + Most actions have only one phase. REPLACE does however have two + phases. The first phase removes the file with the new name if + there was one there before and the second phase renames the + old name to the new name. + */ + char phase; +} DDL_LOG_ENTRY; + +typedef struct st_ddl_log_memory_entry +{ + uint entry_pos; + struct st_ddl_log_memory_entry *next_log_entry; + struct st_ddl_log_memory_entry *prev_log_entry; + struct st_ddl_log_memory_entry *next_active_log_entry; +} DDL_LOG_MEMORY_ENTRY; + + +enum enum_explain_filename_mode +{ + EXPLAIN_ALL_VERBOSE= 0, + EXPLAIN_PARTITIONS_VERBOSE, + EXPLAIN_PARTITIONS_AS_COMMENT +}; + +/* depends on errmsg.txt Database `db`, Table `t` ... */ +#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63 + +#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#" +#define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9 + +#define WFRM_WRITE_SHADOW 1 +#define WFRM_INSTALL_SHADOW 2 +#define WFRM_PACK_FRM 4 +#define WFRM_KEEP_SHARE 8 + +/* Flags for conversion functions. */ +#define FN_FROM_IS_TMP (1 << 0) +#define FN_TO_IS_TMP (1 << 1) +#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP) +#define NO_FRM_RENAME (1 << 2) +#define FRM_ONLY (1 << 3) + +uint filename_to_tablename(const char *from, char *to, uint to_length); +uint tablename_to_filename(const char *from, char *to, uint to_length); +uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length); +uint build_table_filename(char *buff, size_t bufflen, const char *db, + const char *table, const char *ext, uint flags); +uint build_table_shadow_filename(char *buff, size_t bufflen, + ALTER_PARTITION_PARAM_TYPE *lpt); +bool mysql_create_table(THD *thd, TABLE_LIST *create_table, + HA_CREATE_INFO *create_info, + Alter_info *alter_info); +bool mysql_create_table_no_lock(THD *thd, const char *db, + const char *table_name, + HA_CREATE_INFO *create_info, + Alter_info *alter_info, + bool tmp_table, uint select_field_count); + +bool mysql_alter_table(THD *thd, char *new_db, char *new_name, + HA_CREATE_INFO *create_info, + TABLE_LIST *table_list, + Alter_info *alter_info, + uint order_num, ORDER *order, bool ignore); +bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list); +bool mysql_create_like_table(THD *thd, TABLE_LIST *table, + TABLE_LIST *src_table, + HA_CREATE_INFO *create_info); +bool mysql_rename_table(handlerton *base, const char *old_db, + const char * old_name, const char *new_db, + const char * new_name, uint flags); + +bool mysql_backup_table(THD* thd, TABLE_LIST* table_list); +bool mysql_restore_table(THD* thd, TABLE_LIST* table_list); + +bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_check_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_repair_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list, + LEX_STRING *key_cache_name); +bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list); +int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache, + KEY_CACHE *dst_cache); +bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, + my_bool drop_temporary); +int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, + bool drop_temporary, bool drop_view, bool log_query); +bool quick_rm_table(handlerton *base,const char *db, + const char *table_name, uint flags); +void close_cached_table(THD *thd, TABLE *table); +void sp_prepare_create_field(THD *thd, Create_field *sql_field); +int prepare_create_field(Create_field *sql_field, + uint *blob_columns, + int *timestamps, int *timestamps_with_niladic, + longlong table_flags); +CHARSET_INFO* get_sql_field_charset(Create_field *sql_field, + HA_CREATE_INFO *create_info); +bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags); +int write_bin_log(THD *thd, bool clear_error, + char const *query, ulong query_length, + bool is_trans= FALSE); +bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry, + DDL_LOG_MEMORY_ENTRY **active_entry); +bool write_execute_ddl_log_entry(uint first_entry, + bool complete, + DDL_LOG_MEMORY_ENTRY **active_entry); +bool deactivate_ddl_log_entry(uint entry_no); +void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry); +bool sync_ddl_log(); +void release_ddl_log(); +void execute_ddl_log_recovery(); +bool execute_ddl_log_entry(THD *thd, uint first_entry); +bool check_duplicate_warning(THD *thd, char *msg, ulong length); + +/* + These prototypes where under INNODB_COMPATIBILITY_HOOKS. +*/ +uint explain_filename(THD* thd, const char *from, char *to, uint to_length, + enum_explain_filename_mode explain_mode); + + +extern MYSQL_PLUGIN_IMPORT const char *primary_key_name; +extern int creating_table; // How many mysql_create_table() are running +extern mysql_mutex_t LOCK_gdl; + +#endif /* SQL_TABLE_INCLUDED */ diff --git a/sql/sql_tablespace.cc b/sql/sql_tablespace.cc index 4db3083eb04..18650c11c09 100644 --- a/sql/sql_tablespace.cc +++ b/sql/sql_tablespace.cc @@ -15,7 +15,11 @@ /* drop and alter of tablespaces */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_tablespace.h" +#include "sql_table.h" // write_bin_log +#include "sql_class.h" // THD int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info) { diff --git a/sql/sql_tablespace.h b/sql/sql_tablespace.h new file mode 100644 index 00000000000..93544dea4af --- /dev/null +++ b/sql/sql_tablespace.h @@ -0,0 +1,24 @@ +/* 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_TABLESPACE_INCLUDED +#define SQL_TABLESPACE_INCLUDED + +class THD; +class st_alter_tablespace; + +int mysql_alter_tablespace(THD* thd, st_alter_tablespace *ts_info); + +#endif /* SQL_TABLESPACE_INCLUDED */ diff --git a/sql/sql_test.cc b/sql/sql_test.cc index bfd053d3333..d34aee854d0 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -17,7 +17,11 @@ /* Write some debug info */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_test.h" +#include "sql_base.h" // table_def_cache, table_cache_count, unused_tables +#include "sql_show.h" // calc_sum_of_all_status #include "sql_select.h" #include "keycaches.h" #include <hash.h> diff --git a/sql/sql_test.h b/sql/sql_test.h new file mode 100644 index 00000000000..539e89ec949 --- /dev/null +++ b/sql/sql_test.h @@ -0,0 +1,37 @@ +/* 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_TEST_INCLUDED +#define SQL_TEST_INCLUDED + +#include "mysqld.h" + +class JOIN; +struct TABLE_LIST; +typedef class Item COND; +typedef class st_select_lex SELECT_LEX; +typedef struct st_sort_field SORT_FIELD; + +#ifndef DBUG_OFF +void print_where(COND *cond,const char *info, enum_query_type query_type); +void print_cached_tables(void); +void TEST_filesort(SORT_FIELD *sortorder,uint s_length); +void print_plan(JOIN* join,uint idx, double record_count, double read_time, + double current_read_time, const char *info); +void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl); +#endif +void mysql_print_status(); + +#endif /* SQL_TEST_INCLUDED */ diff --git a/sql/time.cc b/sql/sql_time.cc index 2db7812b9ef..9606304ea16 100644 --- a/sql/time.cc +++ b/sql/sql_time.cc @@ -16,7 +16,11 @@ /* Functions to handle date and time */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED by other includes +#include "sql_time.h" +#include "tztime.h" // struct Time_zone +#include "sql_class.h" // THD, MODE_INVALID_DATES, MODE_NO_ZERO_DATE #include <m_ctype.h> diff --git a/sql/sql_time.h b/sql/sql_time.h new file mode 100644 index 00000000000..47e1a2b4843 --- /dev/null +++ b/sql/sql_time.h @@ -0,0 +1,101 @@ +/* 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_TIME_INCLUDED +#define SQL_TIME_INCLUDED + +#include "my_global.h" /* ulong */ +#include "my_time.h" +#include "mysql_time.h" /* timestamp_type */ +#include "sql_error.h" /* MYSQL_ERROR */ +#include "structs.h" /* INTERVAL */ + +typedef enum enum_mysql_timestamp_type timestamp_type; +typedef struct st_date_time_format DATE_TIME_FORMAT; +typedef struct st_known_date_time_format KNOWN_DATE_TIME_FORMAT; + +/* Flags for calc_week() function. */ +#define WEEK_MONDAY_FIRST 1 +#define WEEK_YEAR 2 +#define WEEK_FIRST_WEEKDAY 4 + +ulong convert_period_to_month(ulong period); +ulong convert_month_to_period(ulong month); +void get_date_from_daynr(long daynr,uint *year, uint *month, uint *day); +my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist); +bool str_to_time_with_warn(CHARSET_INFO *cs, const char *str, uint length, + MYSQL_TIME *l_time); +timestamp_type str_to_datetime_with_warn(CHARSET_INFO *cs, const char *str, + uint length, MYSQL_TIME *l_time, + uint flags); +void make_truncated_value_warning(THD *thd, + MYSQL_ERROR::enum_warning_level level, + const char *str_val, uint str_length, + timestamp_type time_type, + const char *field_name); +extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type, + const char *format_str, + uint format_length); +extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd, + DATE_TIME_FORMAT *format); +const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format, + timestamp_type type); +void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time, + String *str); +void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time, + String *str); +void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time, + String *str); + +/* MYSQL_TIME operations */ +bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, + INTERVAL interval); +bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, + longlong *seconds_out, long *microseconds_out); +int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b); +void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); +void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds); +uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year); + +int calc_weekday(long daynr,bool sunday_first_day_of_week); +bool parse_date_time_format(timestamp_type format_type, + const char *format, uint format_length, + DATE_TIME_FORMAT *date_time_format); +/* Character set-aware version of str_to_time() */ +bool str_to_time(CHARSET_INFO *cs, const char *str,uint length, + MYSQL_TIME *l_time, int *warning); +/* Character set-aware version of str_to_datetime() */ +timestamp_type str_to_datetime(CHARSET_INFO *cs, + const char *str, uint length, + MYSQL_TIME *l_time, uint flags, int *was_cut); + +/* convenience wrapper */ +inline bool parse_date_time_format(timestamp_type format_type, + DATE_TIME_FORMAT *date_time_format) +{ + return parse_date_time_format(format_type, + date_time_format->format.str, + date_time_format->format.length, + date_time_format); +} + + +extern DATE_TIME_FORMAT global_date_format; +extern DATE_TIME_FORMAT global_datetime_format; +extern DATE_TIME_FORMAT global_time_format; +extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[]; +extern LEX_STRING interval_type_to_name[]; + +#endif /* SQL_TIME_INCLUDED */ diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index b1367a61b37..701a2ec93c2 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -15,11 +15,23 @@ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" #include "sp_head.h" #include "sql_trigger.h" +#include "sql_parse.h" // parse_sql #include "parse_file.h" #include "sp.h" +#include "sql_base.h" // find_temporary_table +#include "lock.h" // wait_if_global_read_lock, + // start_waiting_global_read_lock +#include "sql_show.h" // append_definer, append_identifier +#include "sql_table.h" // build_table_filename, + // check_n_cut_mysql50_prefix +#include "sql_db.h" // get_default_db_collation +#include "sql_acl.h" // *_ACL, is_acl_user +#include "sql_handler.h" // mysql_ha_rm_tables /*************************************************************************/ diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 85b2dbe5f21..28bf0a60877 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -16,6 +16,38 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* Forward declarations */ + +class Item_trigger_field; +class sp_head; +class sp_name; +class Query_tables_list; +struct TABLE_LIST; +class Query_tables_list; + +/** Event on which trigger is invoked. */ +enum trg_event_type +{ + TRG_EVENT_INSERT= 0, + TRG_EVENT_UPDATE= 1, + TRG_EVENT_DELETE= 2, + TRG_EVENT_MAX +}; + +#include "table.h" /* GRANT_INFO */ + +/* + We need this two enums here instead of sql_lex.h because + at least one of them is used by Item_trigger_field interface. + + Time when trigger is invoked (i.e. before or after row actually + inserted/updated/deleted). +*/ +enum trg_action_time_type +{ + TRG_ACTION_BEFORE= 0, TRG_ACTION_AFTER= 1, TRG_ACTION_MAX +}; + /** This class holds all information about triggers of table. @@ -178,5 +210,9 @@ bool load_table_name_for_trigger(THD *thd, const sp_name *trg_name, const LEX_STRING *trn_path, LEX_STRING *tbl_name); +bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create); + +extern const char * const TRG_EXT; +extern const char * const TRN_EXT; #endif /* SQL_TRIGGER_INCLUDED */ diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 7dfcf9f6b2e..9ec17a67533 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -31,8 +31,14 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_base.h" // close_thread_tables +#include "sql_parse.h" // check_identifier_name +#include "sql_table.h" // write_bin_log +#include "records.h" // init_read_record, end_read_record #include <my_pthread.h> +#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT #ifdef HAVE_DLOPEN extern "C" diff --git a/sql/sql_union.cc b/sql/sql_union.cc index ad14d2e4ecd..a4d3f61f0e3 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -20,9 +20,13 @@ */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_union.h" #include "sql_select.h" #include "sql_cursor.h" +#include "sql_base.h" // fill_record +#include "filesort.h" // filesort_free_buffers bool mysql_union(THD *thd, LEX *lex, select_result *result, SELECT_LEX_UNIT *unit, ulong setup_tables_done_option) diff --git a/sql/sql_union.h b/sql/sql_union.h new file mode 100644 index 00000000000..43e1b7a6910 --- /dev/null +++ b/sql/sql_union.h @@ -0,0 +1,31 @@ +/* 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_UNION_INCLUDED +#define SQL_UNION_INCLUDED + +#include "my_global.h" /* ulong */ + +class THD; +class select_result; +struct LEX; + +typedef class st_select_lex_unit SELECT_LEX_UNIT; + +bool mysql_union(THD *thd, LEX *lex, select_result *result, + SELECT_LEX_UNIT *unit, ulong setup_tables_done_option); + + +#endif /* SQL_UNION_INCLUDED */ diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 1643bce8ddd..3d9a2f74451 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -19,12 +19,28 @@ Multi-table updates were introduced by Sinisa & Monty */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_update.h" +#include "sql_cache.h" // query_cache_* +#include "sql_base.h" // close_tables_for_reopen +#include "sql_parse.h" // cleanup_items +#include "sql_partition.h" // partition_key_modified #include "sql_select.h" +#include "sql_view.h" // check_key_in_view #include "sp_head.h" #include "sql_trigger.h" #include "probes_mysql.h" #include "debug_sync.h" +#include "key.h" // is_key_used +#include "sql_acl.h" // *_ACL, check_grant +#include "records.h" // init_read_record, + // end_read_record +#include "filesort.h" // filesort +#include "sql_derived.h" // mysql_derived_prepare, + // mysql_handle_derived, + // mysql_derived_filling /* Return 0 if row hasn't changed */ @@ -203,33 +219,26 @@ int mysql_update(THD *thd, SQL_SELECT *select; READ_RECORD info; SELECT_LEX *select_lex= &thd->lex->select_lex; - bool need_reopen; ulonglong id; List<Item> all_fields; THD::killed_state killed_status= THD::NOT_KILLED; MDL_ticket *start_of_statement_svp= thd->mdl_context.mdl_savepoint(); DBUG_ENTER("mysql_update"); - for ( ; ; ) - { - if (open_tables(thd, &table_list, &table_count, 0)) - DBUG_RETURN(1); + if (open_tables(thd, &table_list, &table_count, 0)) + DBUG_RETURN(1); - if (table_list->multitable_view) - { - DBUG_ASSERT(table_list->view != 0); - DBUG_PRINT("info", ("Switch to multi-update")); - /* pass counter value */ - thd->lex->table_count= table_count; - /* convert to multiupdate */ - DBUG_RETURN(2); - } - if (!lock_tables(thd, table_list, table_count, 0, &need_reopen)) - break; - if (!need_reopen) - DBUG_RETURN(1); - close_tables_for_reopen(thd, &table_list, start_of_statement_svp); + if (table_list->multitable_view) + { + DBUG_ASSERT(table_list->view != 0); + DBUG_PRINT("info", ("Switch to multi-update")); + /* pass counter value */ + thd->lex->table_count= table_count; + /* convert to multiupdate */ + DBUG_RETURN(2); } + if (lock_tables(thd, table_list, table_count, 0)) + DBUG_RETURN(1); if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) || (thd->fill_derived_tables() && @@ -963,17 +972,14 @@ int mysql_multi_update_prepare(THD *thd) uint table_count= lex->table_count; const bool using_lock_tables= thd->locked_tables_mode != LTM_NONE; bool original_multiupdate= (thd->lex->sql_command == SQLCOM_UPDATE_MULTI); - bool need_reopen= FALSE; MDL_ticket *start_of_statement_svp= thd->mdl_context.mdl_savepoint(); DBUG_ENTER("mysql_multi_update_prepare"); /* following need for prepared statements, to run next time multi-update */ thd->lex->sql_command= SQLCOM_UPDATE_MULTI; -reopen_tables: - /* open tables and create derived ones, but do not lock and fill them */ - if (((original_multiupdate || need_reopen) && + if ((original_multiupdate && open_tables(thd, &table_list, &table_count, 0)) || mysql_handle_derived(lex, &mysql_derived_prepare)) DBUG_RETURN(TRUE); @@ -1089,58 +1095,11 @@ reopen_tables: /* now lock and fill tables */ if (!thd->stmt_arena->is_stmt_prepare() && - lock_tables(thd, table_list, table_count, 0, &need_reopen)) + lock_tables(thd, table_list, table_count, 0)) { - if (!need_reopen) - DBUG_RETURN(TRUE); - - DBUG_PRINT("info", ("lock_tables failed, reopening")); - - /* - We have to reopen tables since some of them were altered or dropped - during lock_tables() or something was done with their triggers. - Let us do some cleanups to be able do setup_table() and setup_fields() - once again. - */ - List_iterator_fast<Item> it(*fields); - Item *item; - while ((item= it++)) - item->cleanup(); - - /* - To not to hog memory (as a result of the - unit->reinit_exec_mechanism() call below): - */ - lex->unit.cleanup(); - - for (SELECT_LEX *sl= lex->all_selects_list; - sl; - sl= sl->next_select_in_list()) - { - SELECT_LEX_UNIT *unit= sl->master_unit(); - unit->reinit_exec_mechanism(); // reset unit->prepared flags - /* - Reset 'clean' flag back to force normal execution of - unit->cleanup() in Prepared_statement::cleanup_stmt() - (call to lex->unit.cleanup() above sets this flag to TRUE). - */ - unit->unclean(); - } - - /* - Also we need to cleanup Natural_join_column::table_field items. - To not to traverse a join tree we will cleanup whole - thd->free_list (in PS execution mode that list may not contain - items from 'fields' list, so the cleanup above is necessary to. - */ - cleanup_items(thd->free_list); - cleanup_items(thd->stmt_arena->free_list); - close_tables_for_reopen(thd, &table_list, start_of_statement_svp); - - DEBUG_SYNC(thd, "multi_update_reopen_tables"); - - goto reopen_tables; + DBUG_RETURN(TRUE); } + /* @todo: downgrade the metadata locks here. */ /* Check that we are not using table that we are updating, but we should diff --git a/sql/sql_update.h b/sql/sql_update.h new file mode 100644 index 00000000000..6bf022a171c --- /dev/null +++ b/sql/sql_update.h @@ -0,0 +1,43 @@ +/* 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_UPDATE_INCLUDED +#define SQL_UPDATE_INCLUDED + +#include "sql_class.h" /* enum_duplicates */ + +class Item; +struct TABLE_LIST; +class THD; + +typedef class st_select_lex SELECT_LEX; +typedef class st_select_lex_unit SELECT_LEX_UNIT; + +bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, + Item **conds, uint order_num, ORDER *order); +int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields, + List<Item> &values,COND *conds, + uint order_num, ORDER *order, ha_rows limit, + enum enum_duplicates handle_duplicates, bool ignore, + ha_rows *found_return, ha_rows *updated_return); +bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, + List<Item> *fields, List<Item> *values, + COND *conds, ulonglong options, + enum enum_duplicates handle_duplicates, bool ignore, + SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex, + multi_update **result); +bool compare_record(TABLE *table); + +#endif /* SQL_UPDATE_INCLUDED */ diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 4438f1c37b5..3a6866f4a7e 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -15,7 +15,18 @@ */ #define MYSQL_LEX 1 -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" +#include "sql_view.h" +#include "sql_base.h" // find_table_in_global_list +#include "sql_parse.h" // sql_parse +#include "sql_cache.h" // query_cache_* +#include "lock.h" // wait_if_global_read_lock, lock_table_names +#include "sql_show.h" // append_identifier +#include "sql_table.h" // build_table_filename +#include "sql_db.h" // mysql_opt_change_db, mysql_change_db +#include "sql_acl.h" // *_ACL, check_grant #include "sql_select.h" #include "parse_file.h" #include "sp.h" @@ -146,6 +157,35 @@ err: DBUG_RETURN(TRUE); } + +/** + Check if auto generated column names are conforming and + possibly generate a conforming name for them if not. + + @param item_list List of Items which should be checked +*/ + +static void make_valid_column_names(List<Item> &item_list) +{ + Item *item; + uint name_len; + List_iterator_fast<Item> it(item_list); + char buff[NAME_LEN]; + DBUG_ENTER("make_valid_column_names"); + + for (uint column_no= 1; (item= it++); column_no++) + { + if (!item->is_autogenerated_name || !check_column_name(item->name)) + continue; + name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no); + item->orig_name= item->name; + item->set_name(buff, name_len, system_charset_info); + } + + DBUG_VOID_RETURN; +} + + /* Fill defined view parts @@ -543,6 +583,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, } } + /* Check if the auto generated column names are conforming. */ + make_valid_column_names(select_lex->item_list); + if (check_duplicate_names(select_lex->item_list, 1)) { res= TRUE; diff --git a/sql/sql_view.h b/sql/sql_view.h index 3de51c3264e..7d06abb9068 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -18,6 +18,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "sql_class.h" /* Required by sql_lex.h */ +#include "sql_lex.h" /* enum_view_create_mode, enum_drop_mode */ + +/* Forward declarations */ + +class File_parser; + + +/* Function declarations */ + bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, enum_view_create_mode mode); @@ -45,4 +55,6 @@ bool mysql_rename_view(THD *thd, const char *new_db, const char *new_name, #define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL) +extern const LEX_STRING view_type; + #endif /* SQL_VIEW_INCLUDED */ diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 5648e3cbdb5..a0d64e6a378 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -35,7 +35,14 @@ #define YYMAXDEPTH 3200 /* Because of 64K stack */ #define Lex (YYTHD->lex) #define Select Lex->current_select -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "sql_parse.h" /* comp_*_creator */ +#include "sql_table.h" /* primary_key_name */ +#include "sql_partition.h" /* mem_alloc_error, partition_info, HASH_PARTITION */ +#include "sql_acl.h" /* *_ACL */ +#include "password.h" /* my_make_scrambled_password_323, my_make_scrambled_password */ +#include "sql_class.h" /* Key_part_spec, enum_filetype, Diag_condition_item_name */ #include "slave.h" #include "lex_symbol.h" #include "item_create.h" @@ -8562,7 +8569,7 @@ function_call_generic: builder= find_native_function_builder(thd, $1); if (builder) { - item= builder->create(thd, $1, $4); + item= builder->create_func(thd, $1, $4); } else { @@ -8584,7 +8591,7 @@ function_call_generic: { builder= find_qualified_function_builder(thd); DBUG_ASSERT(builder); - item= builder->create(thd, $1, $4); + item= builder->create_func(thd, $1, $4); } } @@ -9823,7 +9830,40 @@ limit_options: ; limit_option: - param_marker + ident + { + Item_splocal *splocal; + THD *thd= YYTHD; + LEX *lex= thd->lex; + Lex_input_stream *lip= & thd->m_parser_state->m_lip; + sp_variable_t *spv; + sp_pcontext *spc = lex->spcont; + if (spc && (spv = spc->find_variable(&$1))) + { + splocal= new (thd->mem_root) + Item_splocal($1, spv->offset, spv->type, + lip->get_tok_start() - lex->sphead->m_tmp_query, + lip->get_ptr() - lip->get_tok_start()); + if (splocal == NULL) + MYSQL_YYABORT; +#ifndef DBUG_OFF + splocal->m_sp= lex->sphead; +#endif + lex->safe_to_cache_query=0; + } + else + { + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); + MYSQL_YYABORT; + } + if (splocal->type() != Item::INT_ITEM) + { + my_error(ER_WRONG_SPVAR_TYPE_IN_LIMIT, MYF(0)); + MYSQL_YYABORT; + } + splocal->limit_clause_param= TRUE; + $$= splocal; + } | param_marker { ((Item_param *) $1)->limit_clause_param= TRUE; } diff --git a/sql/strfunc.cc b/sql/strfunc.cc index d7ab102b225..a0e2f39f8dc 100644 --- a/sql/strfunc.cc +++ b/sql/strfunc.cc @@ -15,7 +15,13 @@ /* Some useful string utility functions used by the MySQL server */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "strfunc.h" +#include "sql_class.h" +#include "typelib.h" // TYPELIB +#include "m_ctype.h" // my_charset_latin1 +#include "mysqld.h" // system_charset_info /* Return bitmap for strings used in a set diff --git a/sql/strfunc.h b/sql/strfunc.h new file mode 100644 index 00000000000..f1eb83ff0de --- /dev/null +++ b/sql/strfunc.h @@ -0,0 +1,51 @@ +/* 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 STRFUNC_INCLUDED +#define STRFUNC_INCLUDED + +#include "my_global.h" /* ulonglong, uint */ + +typedef struct charset_info_st CHARSET_INFO; +typedef struct st_mysql_lex_string LEX_STRING; +typedef struct st_typelib TYPELIB; + +ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs, + char **err_pos, uint *err_len, bool *set_warning); +ulonglong find_set_from_flags(TYPELIB *lib, uint default_name, + ulonglong cur_set, ulonglong default_set, + const char *str, uint length, CHARSET_INFO *cs, + char **err_pos, uint *err_len, bool *set_warning); +uint find_type(const TYPELIB *lib, const char *find, uint length, + bool part_match); +uint find_type2(const TYPELIB *lib, const char *find, uint length, + CHARSET_INFO *cs); +void unhex_type2(TYPELIB *lib); +uint check_word(TYPELIB *lib, const char *val, const char *end, + const char **end_of_word); +int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle, + CHARSET_INFO * const cs); +char *flagset_to_string(THD *thd, LEX_STRING *result, ulonglong set, + const char *lib[]); +char *set_to_string(THD *thd, LEX_STRING *result, ulonglong set, + const char *lib[]); + +/* + These functions were protected by INNODB_COMPATIBILITY_HOOKS + */ +uint strconvert(CHARSET_INFO *from_cs, const char *from, + CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors); + +#endif /* STRFUNC_INCLUDED */ diff --git a/sql/structs.h b/sql/structs.h index 6d2cf54d693..5ffcc4dc62e 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -17,10 +17,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + /* The old structures from unireg */ +#include "sql_plugin.h" /* plugin_ref */ +#include "sql_const.h" /* MAX_REFLENGTH */ +#include "my_time.h" /* enum_mysql_timestamp_type */ +#include "thr_lock.h" /* thr_lock_type */ +#include "my_base.h" /* ha_rows, ha_key_alg */ + struct TABLE; class Field; + class THD; typedef struct st_date_time_format { diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 2e239a9161c..ea86bcc227f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2006 MySQL AB, 2009-2010 Sun Microsystems, Inc. +/* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* How to add new variables: @@ -27,6 +27,9 @@ (for example in storage/myisam/ha_myisam.cc) ! */ +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "sql_class.h" // set_var.h: THD #include "sys_vars.h" #include "events.h" @@ -34,12 +37,26 @@ #include "slave.h" #include "rpl_mi.h" #include "transaction.h" +#include "mysqld.h" +#include "lock.h" +#include "sql_time.h" // known_date_time_formats +#include "sql_acl.h" // SUPER_ACL, + // mysql_user_table_is_in_short_password_format +#include "derror.h" // read_texts +#include "sql_base.h" // close_cached_tables #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE #include "../storage/perfschema/pfs_server.h" #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ /* + This forward declaration is needed because including sql_base.h + causes further includes. [TODO] Eliminate this forward declaration + and include a file with the prototype instead. +*/ +extern void close_thread_tables(THD *thd); + +/* The rule for this file: everything should be 'static'. When a sys_var variable or a function from this file is - in very rare cases - needed elsewhere it should be explicitly declared 'export' here to show that it's @@ -647,32 +664,40 @@ static bool event_scheduler_check(sys_var *self, THD *thd, set_var *var) } static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type) { + uint opt_event_scheduler_value= Events::opt_event_scheduler; mysql_mutex_unlock(&LOCK_global_system_variables); /* Events::start() is heavyweight. In particular it creates a new THD, which takes LOCK_global_system_variables internally. Thus we have to release it here. We need to re-take it before returning, though. - And we need to take it *without* holding Events::LOCK_event_metadata. + + Note that since we release LOCK_global_system_variables before calling + start/stop, there is a possibility that the server variable + can become out of sync with the real event scheduler state. + + This can happen with two concurrent statments if the first gets + interrupted after start/stop but before retaking + LOCK_global_system_variables. However, this problem should be quite + rare and it's difficult to avoid it without opening up possibilities + for deadlocks. See bug#51160. */ - bool ret= Events::opt_event_scheduler == Events::EVENTS_ON + bool ret= opt_event_scheduler_value == Events::EVENTS_ON ? Events::start() : Events::stop(); - mysql_mutex_unlock(&Events::LOCK_event_metadata); mysql_mutex_lock(&LOCK_global_system_variables); - mysql_mutex_lock(&Events::LOCK_event_metadata); if (ret) my_error(ER_EVENT_SET_VAR_ERROR, MYF(0)); return ret; } -static PolyLock_mutex PLock_event_metadata(&Events::LOCK_event_metadata); + static Sys_var_enum Sys_event_scheduler( "event_scheduler", "Enable the event scheduler. Possible values are " "ON, OFF, and DISABLED (keep the event scheduler completely " "deactivated, it cannot be activated run-time)", GLOBAL_VAR(Events::opt_event_scheduler), CMD_LINE(OPT_ARG), event_scheduler_names, DEFAULT(Events::EVENTS_OFF), - &PLock_event_metadata, NOT_IN_BINLOG, + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(event_scheduler_check), ON_UPDATE(event_scheduler_update)); #endif @@ -1898,7 +1923,7 @@ static Sys_var_set Sys_sql_mode( sql_mode_names, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_sql_mode), ON_UPDATE(fix_sql_mode)); -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) #define SSL_OPT(X) CMD_LINE(REQUIRED_ARG,X) #else #define SSL_OPT(X) NO_CMD_LINE diff --git a/sql/sys_vars.h b/sql/sys_vars.h index ccc36c72786..c4855ef4fd3 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -26,6 +26,8 @@ #include <my_bit.h> #include <my_dir.h> #include "keycaches.h" +#include "strfunc.h" +#include "tztime.h" // my_tz_find, my_tz_SYSTEM, struct Time_zone /* a set of mostly trivial (as in f(X)=X) defines below to make system variable diff --git a/sql/sys_vars_shared.h b/sql/sys_vars_shared.h index a8ef9034715..644cc10c853 100644 --- a/sql/sys_vars_shared.h +++ b/sql/sys_vars_shared.h @@ -1,3 +1,6 @@ +#ifndef SYS_VARS_SHARED_INCLUDED +#define SYS_VARS_SHARED_INCLUDED + /* Copyright (C) 2002-2006 MySQL AB, 2009-2010 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify @@ -22,7 +25,7 @@ classes in the sys_var hierarchy (sql_plugin.cc) */ -#include <mysql_priv.h> +#include <sql_priv.h> #include "set_var.h" extern bool throw_bounds_warning(THD *thd, const char *name, @@ -79,3 +82,5 @@ public: ~AutoRLock() { if (lock) lock->unlock(); } }; + +#endif /* SYS_VARS_SHARED_INCLUDED */ diff --git a/sql/table.cc b/sql/table.cc index fa1186c2a45..65918dd58f9 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -16,8 +16,21 @@ /* Some general useful functions */ -#include "mysql_priv.h" +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_priv.h" +#include "unireg.h" // REQUIRED: for other includes +#include "table.h" +#include "frm_crypt.h" // get_crypt_for_frm +#include "key.h" // find_ref_key +#include "sql_table.h" // build_table_filename, + // primary_key_name #include "sql_trigger.h" +#include "sql_parse.h" // free_items +#include "strfunc.h" // unhex_type2 +#include "sql_partition.h" // mysql_unpack_partition, + // fix_partition_func, partition_info +#include "sql_acl.h" // *_ACL, acl_getroot_no_password +#include "sql_base.h" // release_table_share #include <m_ctype.h> #include "my_md5.h" @@ -4069,9 +4082,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, { DBUG_RETURN(field); } - Item *item= new Item_direct_view_ref(&view->view->select_lex.context, - field_ref, view->alias, - name); + Item *item= new Item_direct_view_ref(view, field_ref, name); DBUG_RETURN(item); } diff --git a/sql/table.h b/sql/table.h index 3832e7c9555..fcff0cfb0d5 100644 --- a/sql/table.h +++ b/sql/table.h @@ -16,9 +16,18 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ #include "sql_plist.h" +#include "sql_list.h" /* Sql_alloc */ #include "mdl.h" +#ifndef MYSQL_CLIENT + +#include "hash.h" /* HASH */ +#include "handler.h" /* row_type, ha_choice, handler */ +#include "mysql_com.h" /* enum_field_types */ +#include "thr_lock.h" /* thr_lock_type */ + /* Structs that defines the TABLE */ class Item; /* Needed by ORDER */ @@ -30,12 +39,145 @@ class st_select_lex; class partition_info; class COND_EQUAL; class Security_context; +struct TABLE_LIST; class ACL_internal_schema_access; class ACL_internal_table_access; +struct TABLE_LIST; +class Field; + +/* + Used to identify NESTED_JOIN structures within a join (applicable only to + structures that have not been simplified away and embed more the one + element) +*/ +typedef ulonglong nested_join_map; + + +#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */ +#define tmp_file_prefix_length 4 +#define TMP_TABLE_KEY_EXTRA 8 + +/** + Enumerate possible types of a table from re-execution + standpoint. + TABLE_LIST class has a member of this type. + At prepared statement prepare, this member is assigned a value + as of the current state of the database. Before (re-)execution + of a prepared statement, we check that the value recorded at + prepare matches the type of the object we obtained from the + table definition cache. + + @sa check_and_update_table_version() + @sa Execute_observer + @sa Prepared_statement::reprepare() +*/ + +enum enum_table_ref_type +{ + /** Initial value set by the parser */ + TABLE_REF_NULL= 0, + TABLE_REF_VIEW, + TABLE_REF_BASE_TABLE, + TABLE_REF_I_S_TABLE, + TABLE_REF_TMP_TABLE +}; + + +/** + Opening modes for open_temporary_table and open_table_from_share +*/ + +enum open_table_mode +{ + OTM_OPEN= 0, + OTM_CREATE= 1, + OTM_ALTER= 2 +}; + /*************************************************************************/ /** + Object_creation_ctx -- interface for creation context of database objects + (views, stored routines, events, triggers). Creation context -- is a set + of attributes, that should be fixed at the creation time and then be used + each time the object is parsed or executed. +*/ + +class Object_creation_ctx +{ +public: + Object_creation_ctx *set_n_backup(THD *thd); + + void restore_env(THD *thd, Object_creation_ctx *backup_ctx); + +protected: + Object_creation_ctx() {} + virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0; + + virtual void change_env(THD *thd) const = 0; + +public: + virtual ~Object_creation_ctx() + { } +}; + +/*************************************************************************/ + +/** + Default_object_creation_ctx -- default implementation of + Object_creation_ctx. +*/ + +class Default_object_creation_ctx : public Object_creation_ctx +{ +public: + CHARSET_INFO *get_client_cs() + { + return m_client_cs; + } + + CHARSET_INFO *get_connection_cl() + { + return m_connection_cl; + } + +protected: + Default_object_creation_ctx(THD *thd); + + Default_object_creation_ctx(CHARSET_INFO *client_cs, + CHARSET_INFO *connection_cl); + +protected: + virtual Object_creation_ctx *create_backup_ctx(THD *thd) const; + + virtual void change_env(THD *thd) const; + +protected: + /** + client_cs stores the value of character_set_client session variable. + The only character set attribute is used. + + Client character set is included into query context, because we save + query in the original character set, which is client character set. So, + in order to parse the query properly we have to switch client character + set on parsing. + */ + CHARSET_INFO *m_client_cs; + + /** + connection_cl stores the value of collation_connection session + variable. Both character set and collation attributes are used. + + Connection collation is included into query context, becase it defines + the character set and collation of text literals in internal + representation of query (item-objects). + */ + CHARSET_INFO *m_connection_cl; +}; + + +/** View_creation_ctx -- creation context of view objects. */ @@ -164,15 +306,6 @@ enum tmp_table_type INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE }; -/** Event on which trigger is invoked. */ -enum trg_event_type -{ - TRG_EVENT_INSERT= 0, - TRG_EVENT_UPDATE= 1, - TRG_EVENT_DELETE= 2, - TRG_EVENT_MAX -}; - enum frm_type_enum { FRMTYPE_ERROR= 0, @@ -1859,4 +1992,82 @@ size_t max_row_length(TABLE *table, const uchar *data); void init_mdl_requests(TABLE_LIST *table_list); +int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, + uint db_stat, uint prgflag, uint ha_open_flags, + TABLE *outparam, bool is_create_table); +TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, + uint key_length); +void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, + uint key_length, + const char *table_name, const char *path); +void free_table_share(TABLE_SHARE *share); +int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags); +void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg); +void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form); +bool check_and_convert_db_name(LEX_STRING *db, bool preserve_lettercase); +bool check_db_name(LEX_STRING *db); +bool check_column_name(const char *name); +bool check_table_name(const char *name, uint length); +int rename_file_ext(const char * from,const char * to,const char * ext); +char *get_field(MEM_ROOT *mem, Field *field); +bool get_field(MEM_ROOT *mem, Field *field, class String *res); + +int closefrm(TABLE *table, bool free_share); +int read_string(File file, uchar* *to, size_t length); +void free_blobs(TABLE *table); +void free_field_buffers_larger_than(TABLE *table, uint32 size); +int set_zone(int nr,int min_zone,int max_zone); +ulong get_form_pos(File file, uchar *head, TYPELIB *save_names); +ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames, + const char *newname); +ulong next_io_size(ulong pos); +void append_unescaped(String *res, const char *pos, uint length); +File create_frm(THD *thd, const char *name, const char *db, + const char *table, uint reclength, uchar *fileinfo, + HA_CREATE_INFO *create_info, uint keys, KEY *key_info); +char *fn_rext(char *name); + +/* performance schema */ +extern LEX_STRING PERFORMANCE_SCHEMA_DB_NAME; + +extern LEX_STRING GENERAL_LOG_NAME; +extern LEX_STRING SLOW_LOG_NAME; + +/* information schema */ +extern LEX_STRING INFORMATION_SCHEMA_NAME; +extern LEX_STRING MYSQL_SCHEMA_NAME; + +inline bool is_infoschema_db(const char *name, size_t len) +{ + return (INFORMATION_SCHEMA_NAME.length == len && + !my_strcasecmp(system_charset_info, + INFORMATION_SCHEMA_NAME.str, name)); +} + +inline bool is_infoschema_db(const char *name) +{ + return !my_strcasecmp(system_charset_info, + INFORMATION_SCHEMA_NAME.str, name); +} + +TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings); + +/** + return true if the table was created explicitly. +*/ +inline bool is_user_table(TABLE * table) +{ + const char *name= table->s->table_name.str; + return strncmp(name, tmp_file_prefix, tmp_file_prefix_length); +} + +inline void mark_as_null_row(TABLE *table) +{ + table->null_row=1; + table->status|=STATUS_NULL_ROW; + bfill(table->null_flags,table->s->null_bytes,255); +} + +#endif /* MYSQL_CLIENT */ + #endif /* TABLE_INCLUDED */ diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index ed17f7968c0..638f3bbb9f1 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -16,7 +16,10 @@ /* Mallocs for used in threads */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "thr_malloc.h" +#include "sql_class.h" extern "C" { void sql_alloc_error_handler(void) diff --git a/sql/thr_malloc.h b/sql/thr_malloc.h new file mode 100644 index 00000000000..a655884b8b4 --- /dev/null +++ b/sql/thr_malloc.h @@ -0,0 +1,36 @@ +/* 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 THR_MALLOC_INCLUDED +#define THR_MALLOC_INCLUDED + +#include "my_global.h" // uint, size_t + +typedef struct charset_info_st CHARSET_INFO; +typedef struct st_mem_root MEM_ROOT; + +void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size); +void *sql_alloc(size_t); +void *sql_calloc(size_t); +char *sql_strdup(const char *str); +char *sql_strmake(const char *str, size_t len); +void *sql_memdup(const void * ptr, size_t size); +void sql_element_free(void *ptr); +char *sql_strmake_with_convert(const char *str, size_t arg_length, + CHARSET_INFO *from_cs, + size_t max_res_length, + CHARSET_INFO *to_cs, size_t *result_length); + +#endif /* THR_MALLOC_INCLUDED */ diff --git a/sql/transaction.cc b/sql/transaction.cc index 8d9b4943404..ff4eabc2b0f 100644 --- a/sql/transaction.cc +++ b/sql/transaction.cc @@ -18,7 +18,7 @@ #pragma implementation // gcc: Class implementation #endif -#include "mysql_priv.h" +#include "sql_priv.h" #include "transaction.h" #include "rpl_handler.h" diff --git a/sql/tztime.cc b/sql/tztime.cc index 632dca1ce44..b23456b5465 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -20,7 +20,7 @@ */ /* - We should not include mysql_priv.h in mysql_tzinfo_to_sql utility since + We should not include sql_priv.h in mysql_tzinfo_to_sql utility since it creates unsolved link dependencies on some platforms. */ @@ -30,7 +30,12 @@ #include <my_global.h> #if !defined(TZINFO2SQL) && !defined(TESTTIME) -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "tztime.h" +#include "sql_time.h" // localtime_to_TIME +#include "sql_base.h" // open_system_tables_for_read, + // close_system_tables #else #include <my_time.h> #include "tztime.h" @@ -41,6 +46,15 @@ #include <m_string.h> #include <my_dir.h> #include <mysql/psi/mysql_file.h> +#include "lock.h" // MYSQL_LOCK_IGNORE_FLUSH, + // MYSQL_LOCK_IGNORE_TIMEOUT + +/* + This forward declaration is needed because including sql_base.h + causes further includes. [TODO] Eliminate this forward declaration + and include a file with the prototype instead. +*/ +extern void close_thread_tables(THD *thd); /* Now we don't use abbreviations in server but we will do this in future. @@ -1668,7 +1682,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) open all time zone tables to see if they exist. */ if (open_and_lock_tables(thd, tz_tables, FALSE, - MYSQL_LOCK_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT)) + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT)) { sql_print_warning("Can't open and lock time zone table: %s " "trying to live without them", thd->stmt_da->message()); diff --git a/sql/tztime.h b/sql/tztime.h index 9990e91f17b..f3fea485152 100644 --- a/sql/tztime.h +++ b/sql/tztime.h @@ -21,8 +21,17 @@ #pragma interface /* gcc class interface */ #endif +#include "my_time.h" /* my_time_t */ +#include "mysql_time.h" /* MYSQL_TIME */ +#include "sql_list.h" /* Sql_alloc */ +#include "sql_string.h" /* String */ + +class THD; + #if !defined(TESTTIME) && !defined(TZINFO2SQL) +class THD; + /** This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t conversion. diff --git a/sql/udf_example.c b/sql/udf_example.c index 73256bb5529..fa1b44178ac 100644 --- a/sql/udf_example.c +++ b/sql/udf_example.c @@ -107,7 +107,7 @@ ** option. ** ** If you can't get AGGREGATES to work, check that you have the column -** 'type' in the mysql.func table. If not, run 'mysql_fix_privilege_tables'. +** 'type' in the mysql.func table. If not, run 'mysql_upgrade'. ** */ diff --git a/sql/uniques.cc b/sql/uniques.cc index f7c290ae61d..7b5a6d1ce4f 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -30,9 +30,12 @@ deletes in disk order. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "sql_sort.h" - +#include "queues.h" // QUEUE +#include "my_tree.h" // element_count +#include "sql_class.h" // Unique int unique_write_to_file(uchar* key, element_count count, Unique *unique) { diff --git a/sql/unireg.cc b/sql/unireg.cc index c7d2f2f5b5b..dbe4e8712ea 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -23,7 +23,11 @@ str is a (long) to record position where 0 is the first position. */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" +#include "sql_partition.h" // struct partition_info +#include "sql_table.h" // check_duplicate_warning +#include "sql_class.h" // THD, Internal_error_handler #include <m_ctype.h> #include <assert.h> diff --git a/sql/unireg.h b/sql/unireg.h index 9932be7ae74..dbbeea077a9 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -17,8 +17,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "my_global.h" /* ulonglong */ +#include "mysql_version.h" /* FRM_VER */ + /* Extra functions used by unireg library */ +typedef struct st_ha_create_information HA_CREATE_INFO; + #ifndef NO_ALARM_LOOP #define NO_ALARM_LOOP /* lib5 and popen can't use alarm */ #endif @@ -52,71 +57,6 @@ #define ERRMAPP 1 /* Errormap f|r my_error */ -#define LIBLEN FN_REFLEN-FN_LEN /* Max l{ngd p} dev */ -/* extra 4+4 bytes for slave tmp tables */ -#define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4) -#define MAX_ALIAS_NAME 256 -#define MAX_FIELD_NAME 34 /* Max colum name length +2 */ -#define MAX_SYS_VAR_LENGTH 32 -#define MAX_KEY MAX_INDEXES /* Max used keys */ -#define MAX_REF_PARTS 16 /* Max parts used as ref */ -#define MAX_KEY_LENGTH 3072 /* max possible key */ -#if SIZEOF_OFF_T > 4 -#define MAX_REFLENGTH 8 /* Max length for record ref */ -#else -#define MAX_REFLENGTH 4 /* Max length for record ref */ -#endif -#define MAX_HOSTNAME 61 /* len+1 in mysql.user */ - -#define MAX_MBWIDTH 3 /* Max multibyte sequence */ -#define MAX_FIELD_CHARLENGTH 255 -#define MAX_FIELD_VARCHARLENGTH 65535 -#define MAX_FIELD_BLOBLENGTH UINT_MAX32 /* cf field_blob::get_length() */ -#define CONVERT_IF_BIGGER_TO_BLOB 512 /* Used for CREATE ... SELECT */ - -/* Max column width +1 */ -#define MAX_FIELD_WIDTH (MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1) - -#define MAX_BIT_FIELD_LENGTH 64 /* Max length in bits for bit fields */ - -#define MAX_DATE_WIDTH 10 /* YYYY-MM-DD */ -#define MAX_TIME_WIDTH 23 /* -DDDDDD HH:MM:SS.###### */ -#define MAX_DATETIME_FULL_WIDTH 29 /* YYYY-MM-DD HH:MM:SS.###### AM */ -#define MAX_DATETIME_WIDTH 19 /* YYYY-MM-DD HH:MM:SS */ -#define MAX_DATETIME_COMPRESSED_WIDTH 14 /* YYYYMMDDHHMMSS */ - -#define MAX_TABLES (sizeof(table_map)*8-3) /* Max tables in join */ -#define PARAM_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-3)) -#define OUTER_REF_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-2)) -#define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1)) -#define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \ - RAND_TABLE_BIT) -#define MAX_FIELDS 4096 /* Limit in the .frm file */ -#define MAX_PARTITIONS 1024 - -#define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1) - -#define MAX_SORT_MEMORY 2048*1024 -#define MIN_SORT_MEMORY 32*1024 - -/* Memory allocated when parsing a statement / saving a statement */ -#define MEM_ROOT_BLOCK_SIZE 8192 -#define MEM_ROOT_PREALLOC 8192 -#define TRANS_MEM_ROOT_BLOCK_SIZE 4096 -#define TRANS_MEM_ROOT_PREALLOC 4096 - -#define DEFAULT_ERROR_COUNT 64 -#define EXTRA_RECORDS 10 /* Extra records in sort */ -#define SCROLL_EXTRA 5 /* Extra scroll-rows. */ -#define FIELD_NAME_USED ((uint) 32768) /* Bit set if fieldname used */ -#define FORM_NAME_USED ((uint) 16384) /* Bit set if formname used */ -#define FIELD_NR_MASK 16383 /* To get fieldnumber */ -#define FERR -1 /* Error from my_functions */ -#define CREATE_MODE 0 /* Default mode on new files */ -#define NAMES_SEP_CHAR '\377' /* Char to sep. names */ - -#define READ_RECORD_BUFFER (uint) (IO_SIZE*8) /* Pointer_buffer_size */ -#define DISK_BUFFER_SIZE (uint) (IO_SIZE*16) /* Size of diskbuffer */ #define ME_INFO (ME_HOLDTANG+ME_OLDWIN+ME_NOREFRESH) #define ME_ERROR (ME_BELL+ME_OLDWIN+ME_NOREFRESH) @@ -206,7 +146,6 @@ #define TE_INFO_LENGTH 3 #define MTYP_NOEMPTY_BIT 128 -#define FRM_VER_TRUE_VARCHAR (FRM_VER+4) /* 10 */ /* Minimum length pattern before Turbo Boyer-Moore is used for SELECT "text" LIKE "%pattern%", excluding the two @@ -228,5 +167,18 @@ #include "mysqld_error.h" #include "structs.h" /* All structs we need */ - +#include "sql_list.h" /* List<> */ +#include "field.h" /* Create_field */ + +bool mysql_create_frm(THD *thd, const char *file_name, + const char *db, const char *table, + HA_CREATE_INFO *create_info, + List<Create_field> &create_field, + uint key_count,KEY *key_info,handler *db_type); +int rea_create_table(THD *thd, const char *path, + const char *db, const char *table_name, + HA_CREATE_INFO *create_info, + List<Create_field> &create_field, + uint key_count,KEY *key_info, + handler *file); #endif |