diff options
Diffstat (limited to 'sql')
251 files changed, 7272 insertions, 14954 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 913eb3464e2..357575c5b47 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -41,13 +41,13 @@ 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 item_create.cc item_func.cc item_geofunc.cc item_row.cc item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc - key.cc log.cc lock.cc message.rc + key.cc log.cc lock.cc log_event.cc rpl_record.cc rpl_reporting.cc log_event_old.cc rpl_record_old.cc message.h mf_iocache.cc my_decimal.cc ../sql-common/my_time.c @@ -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 @@ -92,7 +92,7 @@ TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} IF(WIN32) - SET(MYSQLD_SOURCE main.cc nt_servc.cc nt_servc.h) + SET(MYSQLD_SOURCE main.cc nt_servc.cc nt_servc.h message.rc) ELSE() SET(MYSQLD_SOURCE main.cc ${DTRACE_PROBES_ALL}) ENDIF() @@ -280,7 +280,8 @@ IF(WIN32 AND MYSQLD_EXECUTABLE) ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/data/mysql/user.frm ) - INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data/mysql DESTINATION data) + INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data DESTINATION . + PATTERN "bootstrap.sql" EXCLUDE) ELSE() # Not windows or cross compiling, just install an empty directory INSTALL(FILES ${DUMMY_FILE} DESTINATION data/mysql) diff --git a/sql/Makefile.am b/sql/Makefile.am index 9a60cbcbf66..f57d1f3bc34 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 @@ -263,6 +271,3 @@ probes_libndb.o: probes_mysql.d libndb_la-ha_ndbcluster.lo fi endif - -# Don't update the files from bitkeeper -%::SCCS/s.% 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..33b9a1cafda 100755 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.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,14 +11,17 @@ 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 "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 @@ -497,8 +500,8 @@ Event_scheduler::run(THD *thd) deinit_event_thread(thd); scheduler_thd= NULL; state= INITIALIZED; - DBUG_PRINT("info", ("Signalling back to the stopper COND_state")); - mysql_cond_signal(&COND_state); + DBUG_PRINT("info", ("Broadcasting COND_state back to the stoppers")); + mysql_cond_broadcast(&COND_state); UNLOCK_DATA(); DBUG_RETURN(res); 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 a2375b1274b..96b86e6798f 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -13,8 +13,17 @@ 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" +#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" diff --git a/sql/events.h b/sql/events.h index 380b0d97f0a..c84c37b881d 100644 --- a/sql/events.h +++ b/sql/events.h @@ -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 diff --git a/sql/field.cc b/sql/field.cc index 8efa765a4bc..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); @@ -6824,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 25869969768..9f003174d2e 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 @@ -4617,7 +4628,7 @@ int ha_ndbcluster::start_statement(THD *thd, trans_register_ha(thd, FALSE, ndbcluster_hton); if (!thd_ndb->trans) { - if (thd->in_multi_stmt_transaction()) + if (thd->in_multi_stmt_transaction_mode()) trans_register_ha(thd, TRUE, ndbcluster_hton); DBUG_PRINT("trans",("Starting transaction")); thd_ndb->trans= ndb->startTransaction(); @@ -4687,7 +4698,7 @@ int ha_ndbcluster::init_handler_for_statement(THD *thd, Thd_ndb *thd_ndb) } #endif - if (thd->in_multi_stmt_transaction()) + if (thd->in_multi_stmt_transaction_mode()) { const void *key= m_table; HASH_SEARCH_STATE state; @@ -4771,7 +4782,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) if (opt_ndb_cache_check_time && m_rows_changed) { DBUG_PRINT("info", ("Rows has changed and util thread is running")); - if (thd->in_multi_stmt_transaction()) + if (thd->in_multi_stmt_transaction_mode()) { DBUG_PRINT("info", ("Add share to list of tables to be invalidated")); /* NOTE push_back allocates memory using transactions mem_root! */ @@ -4790,7 +4801,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) DBUG_PRINT("trans", ("Last external_lock")); PRINT_OPTION_FLAGS(thd); - if (!thd->in_multi_stmt_transaction()) + if (!thd->in_multi_stmt_transaction_mode()) { if (thd_ndb->trans) { @@ -4900,7 +4911,7 @@ static int ndbcluster_commit(handlerton *hton, THD *thd, bool all) PRINT_OPTION_FLAGS(thd); DBUG_PRINT("enter", ("Commit %s", (all ? "all" : "stmt"))); thd_ndb->start_stmt_count= 0; - if (trans == NULL || (!all && thd->in_multi_stmt_transaction())) + if (trans == NULL || (!all && thd->in_multi_stmt_transaction_mode())) { /* An odditity in the handler interface is that commit on handlerton @@ -4970,7 +4981,7 @@ static int ndbcluster_rollback(handlerton *hton, THD *thd, bool all) DBUG_ASSERT(ndb); thd_ndb->start_stmt_count= 0; if (trans == NULL || (!all && - thd->in_multi_stmt_transaction())) + thd->in_multi_stmt_transaction_mode())) { /* Ignore end-of-statement until real rollback or commit is called */ DBUG_PRINT("info", ("Rollback before start or end-of-statement only")); @@ -8260,7 +8271,7 @@ ndbcluster_cache_retrieval_allowed(THD *thd, DBUG_ENTER("ndbcluster_cache_retrieval_allowed"); DBUG_PRINT("enter", ("dbname: %s, tabname: %s", dbname, tabname)); - if (thd->in_multi_stmt_transaction()) + if (thd->in_multi_stmt_transaction_mode()) { DBUG_PRINT("exit", ("No, don't use cache in transaction")); DBUG_RETURN(FALSE); @@ -8328,7 +8339,7 @@ ha_ndbcluster::register_query_cache_table(THD *thd, DBUG_ENTER("ha_ndbcluster::register_query_cache_table"); DBUG_PRINT("enter",("dbname: %s, tabname: %s", m_dbname, m_tabname)); - if (thd->in_multi_stmt_transaction()) + if (thd->in_multi_stmt_transaction_mode()) { DBUG_PRINT("exit", ("Can't register table during transaction")); DBUG_RETURN(FALSE); diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index cbc1875cf6c..de1e36b61d2 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 7097c0a1a46..d38544f9b9f 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) @@ -254,7 +263,6 @@ static void run_query(THD *thd, char *buf, char *end, ulonglong save_thd_options= thd->variables.option_bits; DBUG_ASSERT(sizeof(save_thd_options) == sizeof(thd->variables.option_bits)); NET save_thd_net= thd->net; - const char* found_semicolon= NULL; bzero((char*) &thd->net, sizeof(NET)); thd->set_query(buf, (uint) (end - buf)); @@ -268,7 +276,10 @@ static void run_query(THD *thd, char *buf, char *end, DBUG_ASSERT(!thd->in_sub_stmt); DBUG_ASSERT(!thd->locked_tables_mode); - mysql_parse(thd, thd->query(), thd->query_length(), &found_semicolon); + { + Parser_state parser_state(thd, thd->query(), thd->query_length()); + mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); + } if (no_print_error && thd->is_slave_error) { 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 cb6e578dcf7..f0b77a831a8 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -51,12 +51,15 @@ #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" +#include "table.h" /* HA_DATA_PARTITION */ static const char *ha_par_ext= ".par"; #ifdef NOT_USED @@ -2496,12 +2499,11 @@ err1: A destructor for partition-specific TABLE_SHARE data. */ -void ha_data_partition_destroy(void *ha_part_data) +void ha_data_partition_destroy(HA_DATA_PARTITION* ha_part_data) { if (ha_part_data) { - HA_DATA_PARTITION *ha_data_partition= (HA_DATA_PARTITION*) ha_part_data; - mysql_mutex_destroy(&ha_data_partition->LOCK_auto_inc); + mysql_mutex_destroy(&ha_part_data->LOCK_auto_inc); } } @@ -2648,21 +2650,22 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) mysql_mutex_lock(&table_share->LOCK_ha_data); if (!table_share->ha_part_data) { - HA_DATA_PARTITION *ha_part_data; /* currently only needed for auto_increment */ - table_share->ha_part_data= alloc_root(&table_share->mem_root, - sizeof(HA_DATA_PARTITION)); - ha_part_data= (HA_DATA_PARTITION*) table_share->ha_part_data; - if (!ha_part_data) + table_share->ha_part_data= (HA_DATA_PARTITION*) + alloc_root(&table_share->mem_root, + sizeof(HA_DATA_PARTITION)); + if (!table_share->ha_part_data) { if (is_not_tmp_table) mysql_mutex_unlock(&table_share->LOCK_ha_data); goto err_handler; } - DBUG_PRINT("info", ("table_share->ha_part_data 0x%p", ha_part_data)); - bzero(ha_part_data, sizeof(HA_DATA_PARTITION)); + DBUG_PRINT("info", ("table_share->ha_part_data 0x%p", + table_share->ha_part_data)); + bzero(table_share->ha_part_data, sizeof(HA_DATA_PARTITION)); table_share->ha_part_data_destroy= ha_data_partition_destroy; - mysql_mutex_init(key_PARTITION_LOCK_auto_inc, &ha_part_data->LOCK_auto_inc, + mysql_mutex_init(key_PARTITION_LOCK_auto_inc, + &table_share->ha_part_data->LOCK_auto_inc, MY_MUTEX_INIT_FAST); } if (is_not_tmp_table) @@ -3087,8 +3090,6 @@ int ha_partition::write_row(uchar * buf) longlong func_value; bool have_auto_increment= table->next_number_field && buf == table->record[0]; my_bitmap_map *old_map; - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; THD *thd= ha_thd(); timestamp_auto_set_type orig_timestamp_type= table->timestamp_field_type; #ifdef NOT_NEEDED @@ -3108,8 +3109,8 @@ int ha_partition::write_row(uchar * buf) */ if (have_auto_increment) { - if (!ha_part_data->auto_inc_initialized && - !table->s->next_number_keypart) + if (!table_share->ha_part_data->auto_inc_initialized && + !table_share->next_number_keypart) { /* If auto_increment in table_share is not initialized, start by @@ -3258,9 +3259,7 @@ exit: if (table->found_next_number_field && new_data == table->record[0] && !table->s->next_number_keypart) { - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; - if (!ha_part_data->auto_inc_initialized) + if (!table_share->ha_part_data->auto_inc_initialized) info(HA_STATUS_AUTO); set_auto_increment_if_higher(table->found_next_number_field); } @@ -3352,12 +3351,10 @@ int ha_partition::delete_all_rows() if (thd->lex->sql_command == SQLCOM_TRUNCATE) { Alter_info *alter_info= &thd->lex->alter_info; - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; /* TRUNCATE also means resetting auto_increment */ lock_auto_increment(); - ha_part_data->next_auto_inc_val= 0; - ha_part_data->auto_inc_initialized= FALSE; + table_share->ha_part_data->next_auto_inc_val= 0; + table_share->ha_part_data->auto_inc_initialized= FALSE; unlock_auto_increment(); if (alter_info->flags & ALTER_ADMIN_PARTITION) { @@ -5073,23 +5070,22 @@ int ha_partition::info(uint flag) if (flag & HA_STATUS_AUTO) { bool auto_inc_is_first_in_idx= (table_share->next_number_keypart == 0); - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; DBUG_PRINT("info", ("HA_STATUS_AUTO")); if (!table->found_next_number_field) stats.auto_increment_value= 0; - else if (ha_part_data->auto_inc_initialized) + else if (table_share->ha_part_data->auto_inc_initialized) { lock_auto_increment(); - stats.auto_increment_value= ha_part_data->next_auto_inc_val; + stats.auto_increment_value= table_share->ha_part_data->next_auto_inc_val; unlock_auto_increment(); } else { lock_auto_increment(); /* to avoid two concurrent initializations, check again when locked */ - if (ha_part_data->auto_inc_initialized) - stats.auto_increment_value= ha_part_data->next_auto_inc_val; + if (table_share->ha_part_data->auto_inc_initialized) + stats.auto_increment_value= + table_share->ha_part_data->next_auto_inc_val; else { handler *file, **file_array; @@ -5109,10 +5105,11 @@ int ha_partition::info(uint flag) stats.auto_increment_value= auto_increment_value; if (auto_inc_is_first_in_idx) { - set_if_bigger(ha_part_data->next_auto_inc_val, auto_increment_value); - ha_part_data->auto_inc_initialized= TRUE; + set_if_bigger(table_share->ha_part_data->next_auto_inc_val, + auto_increment_value); + table_share->ha_part_data->auto_inc_initialized= TRUE; DBUG_PRINT("info", ("initializing next_auto_inc_val to %lu", - (ulong) ha_part_data->next_auto_inc_val)); + (ulong) table_share->ha_part_data->next_auto_inc_val)); } } unlock_auto_increment(); @@ -5246,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; } @@ -6501,12 +6499,10 @@ int ha_partition::reset_auto_increment(ulonglong value) { handler **file= m_file; int res; - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; DBUG_ENTER("ha_partition::reset_auto_increment"); lock_auto_increment(); - ha_part_data->auto_inc_initialized= FALSE; - ha_part_data->next_auto_inc_val= 0; + table_share->ha_part_data->auto_inc_initialized= FALSE; + table_share->ha_part_data->next_auto_inc_val= 0; do { if ((res= (*file)->ha_reset_auto_increment(value)) != 0) @@ -6573,12 +6569,10 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, else { THD *thd= ha_thd(); - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; /* This is initialized in the beginning of the first write_row call. */ - DBUG_ASSERT(ha_part_data->auto_inc_initialized); + DBUG_ASSERT(table_share->ha_part_data->auto_inc_initialized); /* Get a lock for handling the auto_increment in table_share->ha_part_data for avoiding two concurrent statements getting the same number. @@ -6607,8 +6601,9 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, } /* this gets corrected (for offset/increment) in update_auto_increment */ - *first_value= ha_part_data->next_auto_inc_val; - ha_part_data->next_auto_inc_val+= nb_desired_values * increment; + *first_value= table_share->ha_part_data->next_auto_inc_val; + table_share->ha_part_data->next_auto_inc_val+= + nb_desired_values * increment; unlock_auto_increment(); DBUG_PRINT("info", ("*first_value: %lu", (ulong) *first_value)); @@ -6628,16 +6623,27 @@ void ha_partition::release_auto_increment() } else if (next_insert_id) { - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; ulonglong next_auto_inc_val; lock_auto_increment(); - next_auto_inc_val= ha_part_data->next_auto_inc_val; + next_auto_inc_val= table_share->ha_part_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_part_data->next_auto_inc_val= next_insert_id; - DBUG_PRINT("info", ("ha_part_data->next_auto_inc_val: %lu", - (ulong) ha_part_data->next_auto_inc_val)); + { + 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) + table_share->ha_part_data->next_auto_inc_val= next_insert_id; + } + DBUG_PRINT("info", ("table_share->ha_part_data->next_auto_inc_val: %lu", + (ulong) table_share->ha_part_data->next_auto_inc_val)); /* Unlock the multi row statement lock taken in get_auto_increment */ if (auto_increment_safe_stmt_log_lock) diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 34aeb7d357b..eec3cb71537 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, @@ -27,16 +30,6 @@ enum partition_keywords }; -/** - Partition specific ha_data struct. -*/ -typedef struct st_ha_data_partition -{ - bool auto_inc_initialized; - mysql_mutex_t LOCK_auto_inc; /**< protecting auto_inc val */ - ulonglong next_auto_inc_val; /**< first non reserved value */ -} HA_DATA_PARTITION; - #define PARTITION_BYTES_IN_POS 2 #define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ) #define PARTITION_DISABLED_TABLE_FLAGS (HA_CAN_GEOMETRY | \ @@ -923,23 +916,19 @@ private: virtual int reset_auto_increment(ulonglong value); virtual void lock_auto_increment() { - HA_DATA_PARTITION *ha_part_data; /* lock already taken */ if (auto_increment_safe_stmt_log_lock) return; - ha_part_data= (HA_DATA_PARTITION*) table_share->ha_part_data; - DBUG_ASSERT(ha_part_data && !auto_increment_lock); + DBUG_ASSERT(table_share->ha_part_data && !auto_increment_lock); if(table_share->tmp_table == NO_TMP_TABLE) { auto_increment_lock= TRUE; - mysql_mutex_lock(&ha_part_data->LOCK_auto_inc); + mysql_mutex_lock(&table_share->ha_part_data->LOCK_auto_inc); } } virtual void unlock_auto_increment() { - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; - DBUG_ASSERT(ha_part_data); + DBUG_ASSERT(table_share->ha_part_data); /* If auto_increment_safe_stmt_log_lock is true, we have to keep the lock. It will be set to false and thus unlocked at the end of the statement by @@ -947,21 +936,19 @@ private: */ if(auto_increment_lock && !auto_increment_safe_stmt_log_lock) { - mysql_mutex_unlock(&ha_part_data->LOCK_auto_inc); + mysql_mutex_unlock(&table_share->ha_part_data->LOCK_auto_inc); auto_increment_lock= FALSE; } } virtual void set_auto_increment_if_higher(Field *field) { - HA_DATA_PARTITION *ha_part_data= (HA_DATA_PARTITION*) - table_share->ha_part_data; ulonglong nr= (((Field_num*) field)->unsigned_flag || field->val_int() > 0) ? field->val_int() : 0; lock_auto_increment(); - DBUG_ASSERT(ha_part_data->auto_inc_initialized == TRUE); + DBUG_ASSERT(table_share->ha_part_data->auto_inc_initialized == TRUE); /* must check when the mutex is taken */ - if (nr >= ha_part_data->next_auto_inc_val) - ha_part_data->next_auto_inc_val= nr + 1; + if (nr >= table_share->ha_part_data->next_auto_inc_val) + table_share->ha_part_data->next_auto_inc_val= nr + 1; unlock_auto_increment(); } diff --git a/sql/handler.cc b/sql/handler.cc index 0bb4e0199d5..8b56921a3a1 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" @@ -46,7 +57,8 @@ static handlerton *installed_htons[128]; #define BITMAP_STACKBUF_SIZE (128/8) -KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NullS,0} }; +KEY_CREATE_INFO default_key_create_info= + { HA_KEY_ALG_UNDEF, 0, {NullS, 0}, {NullS, 0} }; /* number of entries in handlertons[] */ ulong total_ha= 0; @@ -1233,7 +1245,14 @@ end: /** @note This function does not care about global read lock. A caller should. + + @param[in] all Is set in case of explicit commit + (COMMIT statement), or implicit commit + issued by DDL. Is not set when called + at the end of statement, even if + autocommit=1. */ + int ha_commit_one_phase(THD *thd, bool all) { int error=0; @@ -1241,9 +1260,15 @@ int ha_commit_one_phase(THD *thd, bool all) /* "real" is a nick name for a transaction for which a commit will make persistent changes. E.g. a 'stmt' transaction inside a 'all' - transation is not 'real': even though it's possible to commit it, + transaction is not 'real': even though it's possible to commit it, the changes are not durable as they might be rolled back if the enclosing 'all' transaction is rolled back. + We establish the value of 'is_real_trans' by checking + if it's an explicit COMMIT/BEGIN statement, or implicit + commit issued by DDL (all == TRUE), or if we're running + in autocommit mode (it's only in the autocommit mode + ha_commit_one_phase() can be called with an empty + transaction.all.ha_list, see why in trans_register_ha()). */ bool is_real_trans=all || thd->transaction.all.ha_list == 0; Ha_trx_info *ha_info= trans->ha_list, *ha_info_next; @@ -1291,9 +1316,15 @@ int ha_rollback_trans(THD *thd, bool all) /* "real" is a nick name for a transaction for which a commit will make persistent changes. E.g. a 'stmt' transaction inside a 'all' - transation is not 'real': even though it's possible to commit it, + transaction is not 'real': even though it's possible to commit it, the changes are not durable as they might be rolled back if the enclosing 'all' transaction is rolled back. + We establish the value of 'is_real_trans' by checking + if it's an explicit COMMIT or BEGIN statement, or implicit + commit issued by DDL (in these cases all == TRUE), + or if we're running in autocommit mode (it's only in the autocommit mode + ha_commit_one_phase() is called with an empty + transaction.all.ha_list, see why in trans_register_ha()). */ bool is_real_trans=all || thd->transaction.all.ha_list == 0; DBUG_ENTER("ha_rollback_trans"); @@ -1346,7 +1377,7 @@ int ha_rollback_trans(THD *thd, bool all) if (all) thd->variables.tx_isolation=thd->session_tx_isolation; } - /* Always cleanup. Even if there nht==0. There may be savepoints. */ + /* Always cleanup. Even if nht==0. There may be savepoints. */ if (is_real_trans) thd->transaction.cleanup(); if (all) diff --git a/sql/handler.h b/sql/handler.h index 95d7d535d16..1b5d5f8cb1f 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..5fea7b9c075 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; @@ -1767,6 +1796,24 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname, &dummy_offset)) continue; + /* + No needs to add converter if an "arg" is NUMERIC or DATETIME + value (which is pure ASCII) and at the same time target DTCollation + is ASCII-compatible. For example, no needs to rewrite: + SELECT * FROM t1 WHERE datetime_field = '2010-01-01'; + to + SELECT * FROM t1 WHERE CONVERT(datetime_field USING cs) = '2010-01-01'; + + TODO: avoid conversion of any values with + repertoire ASCII and 7bit-ASCII-compatible, + not only numeric/datetime origin. + */ + if ((*arg)->collation.derivation == DERIVATION_NUMERIC && + (*arg)->collation.repertoire == MY_REPERTOIRE_ASCII && + !((*arg)->collation.collation->state & MY_CS_NONASCII) && + !(coll.collation->state & MY_CS_NONASCII)) + continue; + if (!(conv= (*arg)->safe_charset_converter(coll.collation)) && ((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII)) conv= new Item_func_conv_charset(*arg, coll.collation, 1); @@ -4710,6 +4757,7 @@ void Item_field::cleanup() I.e. we can drop 'field'. */ field= result_field= 0; + item_equal= NULL; null_value= FALSE; DBUG_VOID_RETURN; } @@ -5375,7 +5423,7 @@ int Item::save_in_field(Field *field, bool no_conversions) { double nr= val_real(); if (null_value) - return set_field_to_null(field); + return set_field_to_null_with_conversions(field, no_conversions); field->set_notnull(); error=field->store(nr); } @@ -5990,9 +6038,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 +6068,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 +7571,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 a5c664dd159..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; /* @@ -3184,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(); @@ -3399,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 5277e2c7b1d..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; @@ -4357,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* @@ -4967,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 1616acff942..26c802b8057 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> @@ -3656,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 /** @@ -6091,7 +6030,7 @@ longlong Item_func_row_count::val_int() DBUG_ASSERT(fixed == 1); THD *thd= current_thd; - return thd->row_count_func; + return thd->get_row_count_func(); } diff --git a/sql/item_func.h b/sql/item_func.h index 38253a73265..834ecd60e21 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1498,7 +1498,8 @@ class Item_user_var_as_out_param :public Item LEX_STRING name; user_var_entry *entry; public: - Item_user_var_as_out_param(LEX_STRING a) : name(a) {} + Item_user_var_as_out_param(LEX_STRING a) : name(a) + { set_name(a.str, 0, system_charset_info); } /* We should return something different from FIELD_ITEM here */ enum Type type() const { return STRING_ITEM;} double val_real(); @@ -1797,4 +1798,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..f2b34fe59ed 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); +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) + 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 /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ +} + + +void Item_func_sha2::fix_length_and_dec() +{ + maybe_null = 1; + max_length = 0; + +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) + 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 /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ +} /* Implementation of AES encryption routines */ @@ -482,7 +637,7 @@ void Item_func_concat::fix_length_and_dec() String *Item_func_des_encrypt::val_str(String *str) { DBUG_ASSERT(fixed == 1); -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) uint code= ER_WRONG_PARAMETERS_TO_PROCEDURE; DES_cblock ivec; struct st_des_keyblock keyblock; @@ -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,8 +722,8 @@ error: #else push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_encrypt","--with-openssl"); -#endif /* HAVE_OPENSSL */ + "des_encrypt", "--with-ssl"); +#endif /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ null_value=1; return 0; } @@ -578,7 +732,7 @@ error: String *Item_func_des_decrypt::val_str(String *str) { DBUG_ASSERT(fixed == 1); -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) uint code= ER_WRONG_PARAMETERS_TO_PROCEDURE; DES_cblock ivec; struct st_des_keyblock keyblock; @@ -646,8 +800,8 @@ wrong_key: #else push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_decrypt","--with-openssl"); -#endif /* HAVE_OPENSSL */ + "des_decrypt", "--with-ssl"); +#endif /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ 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 7937878073e..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> 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 279782d271b..6c0ab33e87a 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 */ @@ -1567,7 +1576,7 @@ binlog_truncate_trx_cache(THD *thd, binlog_cache_mngr *cache_mngr, bool all) inside a transaction, we reset the transaction cache. */ thd->binlog_remove_pending_rows_event(TRUE, is_transactional); - if (all || !thd->in_multi_stmt_transaction()) + if (ending_trans(thd, all)) { if (cache_mngr->trx_cache.has_incident()) error= mysql_bin_log.write_incident(thd, TRUE); @@ -1631,7 +1640,10 @@ binlog_flush_stmt_cache(THD *thd, binlog_cache_mngr *cache_mngr) */ bool const is_transactional= FALSE; IO_CACHE *cache_log= &cache_mngr->stmt_cache.cache_log; - thd->binlog_flush_pending_rows_event(TRUE, is_transactional); + + if (thd->binlog_flush_pending_rows_event(TRUE, is_transactional)) + DBUG_RETURN(1); + Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE, TRUE, 0); if ((error= mysql_bin_log.write(thd, cache_log, &qev, cache_mngr->stmt_cache.has_incident()))) @@ -1670,12 +1682,11 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) DBUG_ENTER("binlog_commit"); binlog_cache_mngr *const cache_mngr= (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); - bool const in_transaction= thd->in_multi_stmt_transaction(); DBUG_PRINT("debug", ("all: %d, in_transaction: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s", all, - YESNO(in_transaction), + YESNO(thd->in_multi_stmt_transaction_mode()), YESNO(thd->transaction.all.modified_non_trans_table), YESNO(thd->transaction.stmt.modified_non_trans_table))); @@ -1699,7 +1710,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) - We are in a transaction and a full transaction is committed. Otherwise, we accumulate the changes. */ - if (!in_transaction || all) + if (ending_trans(thd, all)) { Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE, TRUE, 0); error= binlog_flush_trx_cache(thd, cache_mngr, &qev); @@ -1777,29 +1788,28 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all) { /* We flush the cache wrapped in a beging/rollback if: - . aborting a transcation that modified a non-transactional table or; - . aborting a statement that modified both transactional and - non-transctional tables but which is not in the boundaries of any - transaction; + . aborting a single or multi-statement transaction and; + . the format is STMT and non-trans engines were updated or; . the OPTION_KEEP_LOG is activate. */ - if (thd->variables.binlog_format == BINLOG_FORMAT_STMT && - ((all && thd->transaction.all.modified_non_trans_table) || - (!all && thd->transaction.stmt.modified_non_trans_table && - !thd->in_multi_stmt_transaction()) || - (thd->variables.option_bits & OPTION_KEEP_LOG))) + if (ending_trans(thd, all) && + ((thd->variables.option_bits & OPTION_KEEP_LOG) || + (trans_has_updated_non_trans_table(thd) && + thd->variables.binlog_format == BINLOG_FORMAT_STMT))) { Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE, TRUE, 0); error= binlog_flush_trx_cache(thd, cache_mngr, &qev); } /* - Otherwise, we simply truncate the cache as there is no change on - non-transactional tables as follows. + Truncate the cache if: + . aborting a single or multi-statement transaction or; + . the OPTION_KEEP_LOG is not activate and; + . the format is not STMT or no non-trans were updated. */ - else if (all || (!all && - (!thd->transaction.stmt.modified_non_trans_table || - !thd->in_multi_stmt_transaction() || - thd->variables.binlog_format != BINLOG_FORMAT_STMT))) + else if (ending_trans(thd, all) || + (!(thd->variables.option_bits & OPTION_KEEP_LOG) && + ((!stmt_has_updated_non_trans_table(thd) || + thd->variables.binlog_format != BINLOG_FORMAT_STMT)))) error= binlog_truncate_trx_cache(thd, cache_mngr, all); } @@ -1897,7 +1907,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) non-transactional table. Otherwise, truncate the binlog cache starting from the SAVEPOINT command. */ - if (unlikely(thd->transaction.all.modified_non_trans_table || + if (unlikely(trans_has_updated_non_trans_table(thd) || (thd->variables.option_bits & OPTION_KEEP_LOG))) { int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); @@ -4180,7 +4190,7 @@ bool MYSQL_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param) } /** - This function checks if a transactional talbe was updated by the + This function checks if a transactional table was updated by the current transaction. @param thd The client thread that executed the current statement. @@ -4193,11 +4203,11 @@ trans_has_updated_trans_table(const THD* thd) binlog_cache_mngr *const cache_mngr= (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); - return (cache_mngr ? my_b_tell (&cache_mngr->trx_cache.cache_log) : 0); + return (cache_mngr ? !cache_mngr->trx_cache.empty() : 0); } /** - This function checks if a transactional talbe was updated by the + This function checks if a transactional table was updated by the current statement. @param thd The client thread that executed the current statement. @@ -4209,7 +4219,8 @@ stmt_has_updated_trans_table(const THD *thd) { Ha_trx_info *ha_info; - for (ha_info= thd->transaction.stmt.ha_list; ha_info; ha_info= ha_info->next()) + for (ha_info= thd->transaction.stmt.ha_list; ha_info; + ha_info= ha_info->next()) { if (ha_info->is_trx_read_write() && ha_info->ht() != binlog_hton) return (TRUE); @@ -4219,11 +4230,14 @@ stmt_has_updated_trans_table(const THD *thd) /** This function checks if either a trx-cache or a non-trx-cache should - be used. If @c bin_log_direct_non_trans_update is active, the cache - to be used depends on the flag @c is_transactional. + be used. If @c bin_log_direct_non_trans_update is active or the format + is either MIXED or ROW, the cache to be used depends on the flag @c + is_transactional. - Otherswise, we use the trx-cache if either the @c is_transactional - is true or the trx-cache is not empty. + On the other hand, if binlog_format is STMT or direct option is + OFF, the trx-cache should be used if and only if the statement is + transactional or the trx-cache is not empty. Otherwise, the + non-trx-cache should be used. @param thd The client thread. @param is_transactional The changes are related to a trx-table. @@ -4236,8 +4250,52 @@ bool use_trans_cache(const THD* thd, bool is_transactional) (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); return - (thd->variables.binlog_direct_non_trans_update ? is_transactional : - (cache_mngr->trx_cache.empty() && !is_transactional ? FALSE : TRUE)); + ((thd->variables.binlog_format != BINLOG_FORMAT_STMT || + thd->variables.binlog_direct_non_trans_update) ? is_transactional : + (is_transactional || !cache_mngr->trx_cache.empty())); +} + +/** + This function checks if a transaction, either a multi-statement + or a single statement transaction is about to commit or not. + + @param thd The client thread that executed the current statement. + @param all Committing a transaction (i.e. TRUE) or a statement + (i.e. FALSE). + @return + @c true if committing a transaction, otherwise @c false. +*/ +bool ending_trans(THD* thd, const bool all) +{ + return (all || (!all && !thd->in_multi_stmt_transaction_mode())); +} + +/** + This function checks if a non-transactional table was updated by + the current transaction. + + @param thd The client thread that executed the current statement. + @return + @c true if a non-transactional table was updated, @c false + otherwise. +*/ +bool trans_has_updated_non_trans_table(const THD* thd) +{ + return (thd->transaction.all.modified_non_trans_table || + thd->transaction.stmt.modified_non_trans_table); +} + +/** + This function checks if a non-transactional table was updated by the + current statement. + + @param thd The client thread that executed the current statement. + @return + @c true if a non-transactional table was updated, @c false otherwise. +*/ +bool stmt_has_updated_non_trans_table(const THD* thd) +{ + return (thd->transaction.stmt.modified_non_trans_table); } /* @@ -4312,7 +4370,7 @@ THD::binlog_start_trans_and_stmt() cache_mngr->trx_cache.get_prev_position() == MY_OFF_T_UNDEF) { this->binlog_set_stmt_begin(); - if (in_multi_stmt_transaction()) + if (in_multi_stmt_transaction_mode()) trans_register_ha(this, TRUE, binlog_hton); trans_register_ha(this, FALSE, binlog_hton); /* @@ -4522,7 +4580,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd, { set_write_error(thd); if (check_write_error(thd) && cache_data && - thd->transaction.stmt.modified_non_trans_table) + stmt_has_updated_non_trans_table(thd)) cache_data->set_incident(); DBUG_RETURN(1); } @@ -4723,7 +4781,7 @@ unlock: { set_write_error(thd); if (check_write_error(thd) && cache_data && - thd->transaction.stmt.modified_non_trans_table) + stmt_has_updated_non_trans_table(thd)) cache_data->set_incident(); } } @@ -4993,7 +5051,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..12e02969485 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; @@ -23,6 +26,9 @@ class Format_description_log_event; bool trans_has_updated_trans_table(const THD* thd); bool stmt_has_updated_trans_table(const THD *thd); bool use_trans_cache(const THD* thd, bool is_transactional); +bool ending_trans(THD* thd, const bool all); +bool trans_has_updated_non_trans_table(const THD* thd); +bool stmt_has_updated_non_trans_table(const THD* thd); /* Transaction Coordinator log - a base abstract class @@ -644,4 +650,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..d5ae1c954ff 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" @@ -667,6 +679,7 @@ Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) server_id= thd->server_id; when= thd->start_time; cache_type= (using_trans || stmt_has_updated_trans_table(thd) + || thd->thread_temporary_used ? Log_event::EVENT_TRANSACTIONAL_CACHE : Log_event::EVENT_STMT_CACHE); } @@ -1717,8 +1730,8 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr, { uint32 tmp= uint3korr(ptr); int part; - char buf[10]; - char *pos= &buf[10]; + char buf[11]; + char *pos= &buf[10]; // start from '\0' to the beginning /* Copied from field.cc */ *pos--=0; // End NULL @@ -2458,6 +2471,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, */ LEX *lex= thd->lex; bool implicit_commit= FALSE; + bool force_trans= FALSE; cache_type= Log_event::EVENT_INVALID_CACHE; switch (lex->sql_command) { @@ -2471,14 +2485,16 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, implicit_commit= TRUE; break; case SQLCOM_DROP_TABLE: - implicit_commit= !(lex->drop_temporary && thd->in_multi_stmt_transaction()); + force_trans= lex->drop_temporary && thd->in_multi_stmt_transaction_mode(); + implicit_commit= !force_trans; break; case SQLCOM_ALTER_TABLE: case SQLCOM_CREATE_TABLE: - implicit_commit= !((lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && - thd->in_multi_stmt_transaction()) && - !(lex->select_lex.item_list.elements && - thd->is_current_stmt_binlog_format_row()); + force_trans= (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && + thd->in_multi_stmt_transaction_mode(); + implicit_commit= !force_trans && + !(lex->select_lex.item_list.elements && + thd->is_current_stmt_binlog_format_row()); break; case SQLCOM_SET_OPTION: implicit_commit= (lex->autocommit ? TRUE : FALSE); @@ -2536,7 +2552,8 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, } else { - cache_type= (using_trans || stmt_has_updated_trans_table(thd) + cache_type= ((using_trans || stmt_has_updated_trans_table(thd) || + force_trans || thd->thread_temporary_used) ? Log_event::EVENT_TRANSACTIONAL_CACHE : Log_event::EVENT_STMT_CACHE); } @@ -3273,8 +3290,8 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, thd->table_map_for_update= (table_map)table_map_for_update; /* Execute the query (note that we bypass dispatch_command()) */ - const char* found_semicolon= NULL; - mysql_parse(thd, thd->query(), thd->query_length(), &found_semicolon); + Parser_state parser_state(thd, thd->query(), thd->query_length()); + mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); log_slow_statement(thd); /* @@ -4209,7 +4226,7 @@ void Load_log_event::print_query(bool need_db, const char *cs, char *buf, pos= strmov(pos, "LOAD DATA "); - if (thd->lex->lock_option == TL_WRITE_CONCURRENT_INSERT) + if (is_concurrent) pos= strmov(pos, "CONCURRENT "); if (fn_start) @@ -4351,6 +4368,7 @@ bool Load_log_event::write_data_body(IO_CACHE* file) Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex, const char *db_arg, const char *table_name_arg, List<Item> &fields_arg, + bool is_concurrent_arg, enum enum_duplicates handle_dup, bool ignore, bool using_trans) :Log_event(thd_arg, @@ -4361,7 +4379,8 @@ Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex, num_fields(0),fields(0), field_lens(0),field_block_len(0), table_name(table_name_arg ? table_name_arg : ""), - db(db_arg), fname(ex->file_name), local_fname(FALSE) + db(db_arg), fname(ex->file_name), local_fname(FALSE), + is_concurrent(is_concurrent_arg) { time_t end_time; time(&end_time); @@ -4442,7 +4461,13 @@ Load_log_event::Load_log_event(const char *buf, uint event_len, const Format_description_log_event *description_event) :Log_event(buf, description_event), num_fields(0), fields(0), field_lens(0),field_block_len(0), - table_name(0), db(0), fname(0), local_fname(FALSE) + table_name(0), db(0), fname(0), local_fname(FALSE), + /* + Load_log_event which comes from the binary log does not contain + information about the type of insert which was used on the master. + Assume that it was an ordinary, non-concurrent LOAD DATA. + */ + is_concurrent(FALSE) { DBUG_ENTER("Load_log_event"); /* @@ -6132,11 +6157,14 @@ int Stop_log_event::do_update_pos(Relay_log_info *rli) Create_file_log_event:: Create_file_log_event(THD* thd_arg, sql_exchange* ex, const char* db_arg, const char* table_name_arg, - List<Item>& fields_arg, enum enum_duplicates handle_dup, + List<Item>& fields_arg, + bool is_concurrent_arg, + enum enum_duplicates handle_dup, bool ignore, uchar* block_arg, uint block_len_arg, bool using_trans) - :Load_log_event(thd_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup, ignore, - using_trans), + :Load_log_event(thd_arg, ex, db_arg, table_name_arg, fields_arg, + is_concurrent_arg, + handle_dup, ignore, using_trans), fake_base(0), block(block_arg), event_buf(0), block_len(block_len_arg), file_id(thd_arg->file_id = mysql_bin_log.next_file_id()) { @@ -7505,7 +7533,7 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) having severe errors which should not be skiped. */ rli->report(ERROR_LEVEL, actual_error, - "Error '%s' on opening tables", + "Error executing row event: '%s'", (actual_error ? thd->stmt_da->message() : "unexpected success or fatal error")); thd->is_slave_error= 1; @@ -7721,12 +7749,6 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); error= 0; } - - if (!use_trans_cache()) - { - DBUG_PRINT("info", ("Marked that we need to keep log")); - thd->variables.option_bits|= OPTION_KEEP_LOG; - } } // if (table) @@ -9638,7 +9660,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..e281fd6e206 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 }; @@ -2066,6 +2069,17 @@ public: uint32 skip_lines; sql_ex_info sql_ex; bool local_fname; + /** + Indicates that this event corresponds to LOAD DATA CONCURRENT, + + @note Since Load_log_event event coming from the binary log + lacks information whether LOAD DATA on master was concurrent + or not, this flag is only set to TRUE for an auxiliary + Load_log_event object which is used in mysql_load() to + re-construct LOAD DATA statement from function parameters, + for logging. + */ + bool is_concurrent; /* fname doesn't point to memory inside Log_event::temp_buf */ void set_fname_outside_temp_buf(const char *afname, uint alen) @@ -2080,13 +2094,15 @@ public: return local_fname; } -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER String field_lens_buf; String fields_buf; Load_log_event(THD* thd, sql_exchange* ex, const char* db_arg, const char* table_name_arg, - List<Item>& fields_arg, enum enum_duplicates handle_dup, bool ignore, + List<Item>& fields_arg, + bool is_concurrent_arg, + enum enum_duplicates handle_dup, bool ignore, bool using_trans); void set_fields(const char* db, List<Item> &fields_arg, Name_resolution_context *context); @@ -2113,7 +2129,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 +2142,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 +2204,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 +2218,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 +2228,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 +2280,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 +2302,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 +2354,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 +2371,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 +2430,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 +2446,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 +2476,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 +2490,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 +2526,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 +2543,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 +2568,7 @@ private: class Stop_log_event: public Log_event { public: -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER Stop_log_event() :Log_event() {} #else @@ -2568,7 +2584,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 +2660,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 +2681,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,10 +2717,11 @@ 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, + bool is_concurrent_arg, enum enum_duplicates handle_dup, bool ignore, uchar* block_arg, uint block_len_arg, bool using_trans); @@ -2735,7 +2752,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 +2763,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 +2794,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 +2812,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 +2836,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 +2853,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 +2877,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 +2893,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 +2917,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 +2932,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 +2968,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 +2993,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 +3388,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 +3413,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 +3430,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 +3532,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 +3547,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 +3561,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 +3584,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 +3596,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 +3629,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 +3657,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 +3712,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 +3735,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 +3743,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 +3764,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 +3793,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 +3813,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 +3838,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 +3874,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 +3882,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 +3903,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 +3951,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 +3974,7 @@ public: } #endif -#ifndef MYSQL_CLIENT +#ifdef MYSQL_SERVER void pack_info(Protocol*); #endif @@ -3970,7 +3987,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 +4019,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 +4055,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 e87c3688cac..f6c5b5d1023 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; } @@ -231,21 +241,16 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info DBUG_EXECUTE_IF("stop_slave_middle_group", const_cast<Relay_log_info*>(rli)->abort_slave= 1;); error= do_after_row_operations(table, error); - if (!ev->use_trans_cache()) - { - DBUG_PRINT("info", ("Marked that we need to keep log")); - 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 +263,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); } @@ -1673,11 +1678,6 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli) DBUG_EXECUTE_IF("stop_slave_middle_group", const_cast<Relay_log_info*>(rli)->abort_slave= 1;); error= do_after_row_operations(rli, error); - if (!use_trans_cache()) - { - DBUG_PRINT("info", ("Marked that we need to keep log")); - thd->variables.option_bits|= OPTION_KEEP_LOG; - } } // if (table) if (error) diff --git a/sql/mdl.h b/sql/mdl.h index 124151798ae..2fb21a5aa18 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -15,6 +15,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if defined(__IBMC__) || defined(__IBMCPP__) +/* Further down, "next_in_lock" and "next_in_context" have the same type, + and in "sql_plist.h" this leads to an identical signature, which causes + problems in function overloading. +*/ +#pragma namemangling(v5) +#endif + #include "sql_plist.h" #include <my_sys.h> 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 e819850448a..00000000000 --- a/sql/mysql_priv.h +++ /dev/null @@ -1,2764 +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); -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); -/* 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) - -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, key_PARTITION_LOCK_auto_inc; - -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/mysql_priv.h.pp b/sql/mysql_priv.h.pp deleted file mode 100644 index ef1cb1fd02e..00000000000 --- a/sql/mysql_priv.h.pp +++ /dev/null @@ -1,10976 +0,0 @@ -#include <my_global.h> -#include <my_config.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <math.h> -#include <limits.h> -#include <float.h> -#include <sys/types.h> -#include <fcntl.h> -#include <sys/timeb.h> -#include <sys/time.h> -#include <time.h> -#include <unistd.h> -#include <alloca.h> -#include <errno.h> -#include <crypt.h> -#include <assert.h> -#include <my_attribute.h> -int __cxa_pure_virtual () __attribute__ ((weak)); -#include <my_dbug.h> -struct _db_code_state_; -extern int _db_keyword_(struct _db_code_state_ *cs, const char *keyword); -extern int _db_strict_keyword_(const char *keyword); -extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len); -extern int _db_explain_init_(char *buf, size_t len); -extern void _db_setjmp_(void); -extern void _db_longjmp_(void); -extern void _db_process_(const char *name); -extern void _db_push_(const char *control); -extern void _db_pop_(void); -extern void _db_set_(struct _db_code_state_ *cs, const char *control); -extern void _db_set_init_(const char *control); -extern void _db_enter_(const char *_func_,const char *_file_,uint _line_, - const char **_sfunc_,const char **_sfile_, - uint *_slevel_, char ***); -extern void _db_return_(uint _line_,const char **_sfunc_,const char **_sfile_, - uint *_slevel_); -extern void _db_pargs_(uint _line_,const char *keyword); -extern void _db_doprnt_ (const char *format,...) - __attribute__((format(printf, 1, 2))); -extern void _db_dump_(uint _line_,const char *keyword, - const unsigned char *memory, size_t length); -extern void _db_end_(void); -extern void _db_lock_file_(void); -extern void _db_unlock_file_(void); -extern FILE *_db_fp_(void); -typedef int File; -typedef int my_socket; -typedef void (*sig_return)(); -typedef char pchar; -typedef char puchar; -typedef char pbool; -typedef short pshort; -typedef float pfloat; -typedef int (*qsort_cmp)(const void *,const void *); -typedef int (*qsort_cmp2)(void*, const void *,const void *); -#include <sys/socket.h> -typedef socklen_t size_socket; -typedef long my_ptrdiff_t; -typedef unsigned char uchar; -typedef signed char int8; -typedef unsigned char uint8; -typedef short int16; -typedef unsigned short uint16; -typedef int int32; -typedef unsigned int uint32; -typedef unsigned long long int ulonglong; -typedef long long int longlong; -typedef longlong int64; -typedef ulonglong uint64; -typedef unsigned long long my_ulonglong; -typedef int intptr; -typedef ulonglong my_off_t; -typedef off_t os_off_t; -typedef uint8 int7; -typedef short int15; -typedef int myf; -typedef char my_bool; -typedef char bool; -typedef union { - double v; - long m[2]; -} doubleget_union; -#include <dlfcn.h> -#include <mysql_version.h> -#include <mysql_embed.h> -#include <my_sys.h> -#include <my_pthread.h> -#include <pthread.h> -#include <sched.h> -extern int my_pthread_getprio(pthread_t thread_id); -typedef void *(* pthread_handler)(void *); -extern void my_pthread_setprio(pthread_t thread_id,int prior); -extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority); -typedef struct st_safe_mutex_t -{ - pthread_mutex_t global,mutex; - const char *file; - uint line,count; - pthread_t thread; -} safe_mutex_t; -int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr, - const char *file, uint line); -int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line); -int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line); -int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line); -int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file, - uint line); -int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, - struct timespec *abstime, const char *file, uint line); -void safe_mutex_global_init(void); -void safe_mutex_end(FILE *file); -typedef ulong my_thread_id; -extern my_bool my_thread_global_init(void); -extern void my_thread_global_end(void); -extern my_bool my_thread_init(void); -extern void my_thread_end(void); -extern const char *my_thread_name(void); -extern my_thread_id my_thread_dbug_id(void); -extern int pthread_no_free(void *); -extern int pthread_dummy(int); -struct st_my_thread_var -{ - int thr_errno; - pthread_cond_t suspend; - pthread_mutex_t mutex; - pthread_mutex_t * volatile current_mutex; - pthread_cond_t * volatile current_cond; - pthread_t pthread_self; - my_thread_id id; - int cmp_length; - int volatile abort; - my_bool init; - struct st_my_thread_var *next,**prev; - void *opt_info; - void *dbug; - char name[10 +1]; -}; -extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); -extern uint my_thread_end_wait_time; -extern uint thd_lib_detected; -#include <m_ctype.h> -#include <my_attribute.h> -typedef struct unicase_info_st -{ - uint16 toupper; - uint16 tolower; - uint16 sort; -} MY_UNICASE_INFO; -extern MY_UNICASE_INFO *my_unicase_default[256]; -extern MY_UNICASE_INFO *my_unicase_turkish[256]; -typedef struct uni_ctype_st -{ - uchar pctype; - uchar *ctype; -} MY_UNI_CTYPE; -extern MY_UNI_CTYPE my_uni_ctype[256]; -typedef struct my_uni_idx_st -{ - uint16 from; - uint16 to; - uchar *tab; -} MY_UNI_IDX; -typedef struct -{ - uint beg; - uint end; - uint mb_len; -} my_match_t; -enum my_lex_states -{ - MY_LEX_START, MY_LEX_CHAR, MY_LEX_IDENT, - MY_LEX_IDENT_SEP, MY_LEX_IDENT_START, - MY_LEX_REAL, MY_LEX_HEX_NUMBER, MY_LEX_BIN_NUMBER, - MY_LEX_CMP_OP, MY_LEX_LONG_CMP_OP, MY_LEX_STRING, MY_LEX_COMMENT, MY_LEX_END, - MY_LEX_OPERATOR_OR_IDENT, MY_LEX_NUMBER_IDENT, MY_LEX_INT_OR_REAL, - MY_LEX_REAL_OR_POINT, MY_LEX_BOOL, MY_LEX_EOL, MY_LEX_ESCAPE, - MY_LEX_LONG_COMMENT, MY_LEX_END_LONG_COMMENT, MY_LEX_SEMICOLON, - MY_LEX_SET_VAR, MY_LEX_USER_END, MY_LEX_HOSTNAME, MY_LEX_SKIP, - MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR, - MY_LEX_IDENT_OR_KEYWORD, - MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN, MY_LEX_IDENT_OR_NCHAR, - MY_LEX_STRING_OR_DELIMITER -}; -struct charset_info_st; -typedef struct my_collation_handler_st -{ - my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t)); - int (*strnncoll)(struct charset_info_st *, - const uchar *, size_t, const uchar *, size_t, my_bool); - int (*strnncollsp)(struct charset_info_st *, - const uchar *, size_t, const uchar *, size_t, - my_bool diff_if_only_endspace_difference); - size_t (*strnxfrm)(struct charset_info_st *, - uchar *, size_t, const uchar *, size_t); - size_t (*strnxfrmlen)(struct charset_info_st *, size_t); - my_bool (*like_range)(struct charset_info_st *, - const char *s, size_t s_length, - pchar w_prefix, pchar w_one, pchar w_many, - size_t res_length, - char *min_str, char *max_str, - size_t *min_len, size_t *max_len); - int (*wildcmp)(struct charset_info_st *, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape,int w_one, int w_many); - int (*strcasecmp)(struct charset_info_st *, const char *, const char *); - uint (*instr)(struct charset_info_st *, - const char *b, size_t b_length, - const char *s, size_t s_length, - my_match_t *match, uint nmatch); - void (*hash_sort)(struct charset_info_st *cs, const uchar *key, size_t len, - ulong *nr1, ulong *nr2); - my_bool (*propagate)(struct charset_info_st *cs, const uchar *str, size_t len); -} MY_COLLATION_HANDLER; -extern MY_COLLATION_HANDLER my_collation_mb_bin_handler; -extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler; -extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler; -extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler; -typedef int (*my_charset_conv_mb_wc)(struct charset_info_st *, ulong *, - const uchar *, const uchar *); -typedef int (*my_charset_conv_wc_mb)(struct charset_info_st *, ulong, - uchar *, uchar *); -typedef size_t (*my_charset_conv_case)(struct charset_info_st *, - char *, size_t, char *, size_t); -typedef struct my_charset_handler_st -{ - my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t)); - uint (*ismbchar)(struct charset_info_st *, const char *, const char *); - uint (*mbcharlen)(struct charset_info_st *, uint c); - size_t (*numchars)(struct charset_info_st *, const char *b, const char *e); - size_t (*charpos)(struct charset_info_st *, const char *b, const char *e, - size_t pos); - size_t (*well_formed_len)(struct charset_info_st *, - const char *b,const char *e, - size_t nchars, int *error); - size_t (*lengthsp)(struct charset_info_st *, const char *ptr, size_t length); - size_t (*numcells)(struct charset_info_st *, const char *b, const char *e); - my_charset_conv_mb_wc mb_wc; - my_charset_conv_wc_mb wc_mb; - int (*ctype)(struct charset_info_st *cs, int *ctype, - const uchar *s, const uchar *e); - size_t (*caseup_str)(struct charset_info_st *, char *); - size_t (*casedn_str)(struct charset_info_st *, char *); - my_charset_conv_case caseup; - my_charset_conv_case casedn; - size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, - const char *fmt, - ...) __attribute__((format(printf, 4, 5))); - size_t (*long10_to_str)(struct charset_info_st *, char *to, size_t n, - int radix, long int val); - size_t (*longlong10_to_str)(struct charset_info_st *, char *to, size_t n, - int radix, longlong val); - void (*fill)(struct charset_info_st *, char *to, size_t len, int fill); - long (*strntol)(struct charset_info_st *, const char *s, size_t l, - int base, char **e, int *err); - ulong (*strntoul)(struct charset_info_st *, const char *s, size_t l, - int base, char **e, int *err); - longlong (*strntoll)(struct charset_info_st *, const char *s, size_t l, - int base, char **e, int *err); - ulonglong (*strntoull)(struct charset_info_st *, const char *s, size_t l, - int base, char **e, int *err); - double (*strntod)(struct charset_info_st *, char *s, size_t l, char **e, - int *err); - longlong (*strtoll10)(struct charset_info_st *cs, - const char *nptr, char **endptr, int *error); - ulonglong (*strntoull10rnd)(struct charset_info_st *cs, - const char *str, size_t length, - int unsigned_fl, - char **endptr, int *error); - size_t (*scan)(struct charset_info_st *, const char *b, const char *e, - int sq); -} MY_CHARSET_HANDLER; -extern MY_CHARSET_HANDLER my_charset_8bit_handler; -extern MY_CHARSET_HANDLER my_charset_ucs2_handler; -typedef struct charset_info_st -{ - uint number; - uint primary_number; - uint binary_number; - uint state; - const char *csname; - const char *name; - const char *comment; - const char *tailoring; - uchar *ctype; - uchar *to_lower; - uchar *to_upper; - uchar *sort_order; - uint16 *contractions; - uint16 **sort_order_big; - uint16 *tab_to_uni; - MY_UNI_IDX *tab_from_uni; - MY_UNICASE_INFO **caseinfo; - uchar *state_map; - uchar *ident_map; - uint strxfrm_multiply; - uchar caseup_multiply; - uchar casedn_multiply; - uint mbminlen; - uint mbmaxlen; - uint16 min_sort_char; - uint16 max_sort_char; - uchar pad_char; - my_bool escape_with_backslash_is_dangerous; - MY_CHARSET_HANDLER *cset; - MY_COLLATION_HANDLER *coll; -} CHARSET_INFO; -extern CHARSET_INFO my_charset_bin; -extern CHARSET_INFO my_charset_big5_chinese_ci; -extern CHARSET_INFO my_charset_big5_bin; -extern CHARSET_INFO my_charset_cp932_japanese_ci; -extern CHARSET_INFO my_charset_cp932_bin; -extern CHARSET_INFO my_charset_eucjpms_japanese_ci; -extern CHARSET_INFO my_charset_eucjpms_bin; -extern CHARSET_INFO my_charset_euckr_korean_ci; -extern CHARSET_INFO my_charset_euckr_bin; -extern CHARSET_INFO my_charset_gb2312_chinese_ci; -extern CHARSET_INFO my_charset_gb2312_bin; -extern CHARSET_INFO my_charset_gbk_chinese_ci; -extern CHARSET_INFO my_charset_gbk_bin; -extern CHARSET_INFO my_charset_latin1; -extern CHARSET_INFO my_charset_latin1_german2_ci; -extern CHARSET_INFO my_charset_latin1_bin; -extern CHARSET_INFO my_charset_latin2_czech_ci; -extern CHARSET_INFO my_charset_sjis_japanese_ci; -extern CHARSET_INFO my_charset_sjis_bin; -extern CHARSET_INFO my_charset_tis620_thai_ci; -extern CHARSET_INFO my_charset_tis620_bin; -extern CHARSET_INFO my_charset_ucs2_general_ci; -extern CHARSET_INFO my_charset_ucs2_bin; -extern CHARSET_INFO my_charset_ucs2_unicode_ci; -extern CHARSET_INFO my_charset_ujis_japanese_ci; -extern CHARSET_INFO my_charset_ujis_bin; -extern CHARSET_INFO my_charset_utf8_general_ci; -extern CHARSET_INFO my_charset_utf8_unicode_ci; -extern CHARSET_INFO my_charset_utf8_bin; -extern CHARSET_INFO my_charset_cp1250_czech_ci; -extern CHARSET_INFO my_charset_filename; -extern size_t my_strnxfrm_simple(CHARSET_INFO *, uchar *, size_t, - const uchar *, size_t); -size_t my_strnxfrmlen_simple(CHARSET_INFO *, size_t); -extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, size_t, - const uchar *, size_t, my_bool); -extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t, - const uchar *, size_t, - my_bool diff_if_only_endspace_difference); -extern void my_hash_sort_simple(CHARSET_INFO *cs, - const uchar *key, size_t len, - ulong *nr1, ulong *nr2); -extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length); -extern uint my_instr_simple(struct charset_info_st *, - const char *b, size_t b_length, - const char *s, size_t s_length, - my_match_t *match, uint nmatch); -extern size_t my_caseup_str_8bit(CHARSET_INFO *, char *); -extern size_t my_casedn_str_8bit(CHARSET_INFO *, char *); -extern size_t my_caseup_8bit(CHARSET_INFO *, char *src, size_t srclen, - char *dst, size_t dstlen); -extern size_t my_casedn_8bit(CHARSET_INFO *, char *src, size_t srclen, - char *dst, size_t dstlen); -extern int my_strcasecmp_8bit(CHARSET_INFO * cs, const char *, const char *); -int my_mb_wc_8bit(CHARSET_INFO *cs,ulong *wc, const uchar *s,const uchar *e); -int my_wc_mb_8bit(CHARSET_INFO *cs,ulong wc, uchar *s, uchar *e); -int my_mb_ctype_8bit(CHARSET_INFO *,int *, const uchar *,const uchar *); -int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *); -size_t my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq); -size_t my_snprintf_8bit(struct charset_info_st *, char *to, size_t n, - const char *fmt, ...) - __attribute__((format(printf, 4, 5))); -long my_strntol_8bit(CHARSET_INFO *, const char *s, size_t l, int base, - char **e, int *err); -ulong my_strntoul_8bit(CHARSET_INFO *, const char *s, size_t l, int base, - char **e, int *err); -longlong my_strntoll_8bit(CHARSET_INFO *, const char *s, size_t l, int base, - char **e, int *err); -ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, size_t l, int base, - char **e, int *err); -double my_strntod_8bit(CHARSET_INFO *, char *s, size_t l,char **e, - int *err); -size_t my_long10_to_str_8bit(CHARSET_INFO *, char *to, size_t l, int radix, - long int val); -size_t my_longlong10_to_str_8bit(CHARSET_INFO *, char *to, size_t l, int radix, - longlong val); -longlong my_strtoll10_8bit(CHARSET_INFO *cs, - const char *nptr, char **endptr, int *error); -longlong my_strtoll10_ucs2(CHARSET_INFO *cs, - const char *nptr, char **endptr, int *error); -ulonglong my_strntoull10rnd_8bit(CHARSET_INFO *cs, - const char *str, size_t length, int - unsigned_fl, char **endptr, int *error); -ulonglong my_strntoull10rnd_ucs2(CHARSET_INFO *cs, - const char *str, size_t length, - int unsigned_fl, char **endptr, int *error); -void my_fill_8bit(CHARSET_INFO *cs, char* to, size_t l, int fill); -my_bool my_like_range_simple(CHARSET_INFO *cs, - const char *ptr, size_t ptr_length, - pbool escape, pbool w_one, pbool w_many, - size_t res_length, - char *min_str, char *max_str, - size_t *min_length, size_t *max_length); -my_bool my_like_range_mb(CHARSET_INFO *cs, - const char *ptr, size_t ptr_length, - pbool escape, pbool w_one, pbool w_many, - size_t res_length, - char *min_str, char *max_str, - size_t *min_length, size_t *max_length); -my_bool my_like_range_ucs2(CHARSET_INFO *cs, - const char *ptr, size_t ptr_length, - pbool escape, pbool w_one, pbool w_many, - size_t res_length, - char *min_str, char *max_str, - size_t *min_length, size_t *max_length); -int my_wildcmp_8bit(CHARSET_INFO *, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many); -int my_wildcmp_bin(CHARSET_INFO *, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many); -size_t my_numchars_8bit(CHARSET_INFO *, const char *b, const char *e); -size_t my_numcells_8bit(CHARSET_INFO *, const char *b, const char *e); -size_t my_charpos_8bit(CHARSET_INFO *, const char *b, const char *e, size_t pos); -size_t my_well_formed_len_8bit(CHARSET_INFO *, const char *b, const char *e, - size_t pos, int *error); -uint my_mbcharlen_8bit(CHARSET_INFO *, uint c); -extern size_t my_caseup_str_mb(CHARSET_INFO *, char *); -extern size_t my_casedn_str_mb(CHARSET_INFO *, char *); -extern size_t my_caseup_mb(CHARSET_INFO *, char *src, size_t srclen, - char *dst, size_t dstlen); -extern size_t my_casedn_mb(CHARSET_INFO *, char *src, size_t srclen, - char *dst, size_t dstlen); -extern int my_strcasecmp_mb(CHARSET_INFO * cs,const char *, const char *); -int my_wildcmp_mb(CHARSET_INFO *, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many); -size_t my_numchars_mb(CHARSET_INFO *, const char *b, const char *e); -size_t my_numcells_mb(CHARSET_INFO *, const char *b, const char *e); -size_t my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, size_t pos); -size_t my_well_formed_len_mb(CHARSET_INFO *, const char *b, const char *e, - size_t pos, int *error); -uint my_instr_mb(struct charset_info_st *, - const char *b, size_t b_length, - const char *s, size_t s_length, - my_match_t *match, uint nmatch); -int my_wildcmp_unicode(CHARSET_INFO *cs, - const char *str, const char *str_end, - const char *wildstr, const char *wildend, - int escape, int w_one, int w_many, - MY_UNICASE_INFO **weights); -extern my_bool my_parse_charset_xml(const char *bug, size_t len, - int (*add)(CHARSET_INFO *cs)); -extern char *my_strchr(CHARSET_INFO *cs, const char *str, const char *end, - pchar c); -my_bool my_propagate_simple(CHARSET_INFO *cs, const uchar *str, size_t len); -my_bool my_propagate_complex(CHARSET_INFO *cs, const uchar *str, size_t len); -uint my_string_repertoire(CHARSET_INFO *cs, const char *str, ulong len); -my_bool my_charset_is_ascii_based(CHARSET_INFO *cs); -my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs); -#include <stdarg.h> -#include <typelib.h> -#include "my_alloc.h" -typedef struct st_used_mem -{ - struct st_used_mem *next; - unsigned int left; - unsigned int size; -} USED_MEM; -typedef struct st_mem_root -{ - USED_MEM *free; - USED_MEM *used; - USED_MEM *pre_alloc; - size_t min_malloc; - size_t block_size; - unsigned int block_num; - unsigned int first_block_usage; - void (*error_handler)(void); -} MEM_ROOT; -typedef struct st_typelib { - unsigned int count; - const char *name; - const char **type_names; - unsigned int *type_lengths; -} TYPELIB; -extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); -extern int find_type_or_exit(const char *x, TYPELIB *typelib, - const char *option); -extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name); -extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); -extern const char *get_type(TYPELIB *typelib,unsigned int nr); -extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); -extern TYPELIB sql_protocol_typelib; -extern void *my_malloc(size_t Size,myf MyFlags); -extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags); -extern void my_no_flags_free(void *ptr); -extern void *my_memdup(const void *from,size_t length,myf MyFlags); -extern char *my_strdup(const char *from,myf MyFlags); -extern char *my_strndup(const char *from, size_t length, - myf MyFlags); -extern uint my_get_large_page_size(void); -extern uchar * my_large_malloc(size_t size, myf my_flags); -extern void my_large_free(uchar * ptr, myf my_flags); -extern int errno; -extern char errbuff[(2)][(256)]; -extern char *home_dir; -extern const char *my_progname; -extern char curr_dir[]; -extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags); -extern int (*fatal_error_handler_hook)(uint my_err, const char *str, - myf MyFlags); -extern uint my_file_limit; -extern ulong my_thread_stack_size; -extern my_bool my_use_large_pages; -extern uint my_large_page_size; -extern CHARSET_INFO *default_charset_info; -extern CHARSET_INFO *all_charsets[256]; -extern CHARSET_INFO compiled_charsets[]; -extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; -extern ulong my_file_total_opened; -extern uint mysys_usage_id; -extern my_bool my_init_done; -extern void (*my_sigtstp_cleanup)(void), - (*my_sigtstp_restart)(void), - (*my_abort_hook)(int); -extern int my_umask, - my_umask_dir, - my_recived_signals, - my_safe_to_handle_signal, - my_dont_interrupt; -extern my_bool mysys_uses_curses, my_use_symdir; -extern ulong sf_malloc_cur_memory, sf_malloc_max_memory; -extern ulong my_default_record_cache_size; -extern my_bool my_disable_locking, my_disable_async_io, - my_disable_flush_key_blocks, my_disable_symlinks; -extern char wild_many,wild_one,wild_prefix; -extern const char *charsets_dir; -extern char *my_defaults_extra_file; -extern const char *my_defaults_group_suffix; -extern const char *my_defaults_file; -extern my_bool timed_mutexes; -typedef struct wild_file_pack -{ - uint wilds; - uint not_pos; - char * *wild; -} WF_PACK; -enum loglevel { - ERROR_LEVEL, - WARNING_LEVEL, - INFORMATION_LEVEL -}; -enum cache_type -{ - TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE, - SEQ_READ_APPEND , - READ_FIFO, READ_NET,WRITE_NET}; -enum flush_type -{ - FLUSH_KEEP, - FLUSH_RELEASE, - FLUSH_IGNORE_CHANGED, - FLUSH_FORCE_WRITE -}; -typedef struct st_record_cache -{ - File file; - int rc_seek,error,inited; - uint rc_length,read_length,reclength; - my_off_t rc_record_pos,end_of_file; - uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos; - enum cache_type type; -} RECORD_CACHE; -enum file_type -{ - UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN, - FILE_BY_MKSTEMP, FILE_BY_DUP -}; -struct st_my_file_info -{ - char * name; - enum file_type type; -}; -extern struct st_my_file_info *my_file_info; -typedef struct st_dynamic_array -{ - uchar *buffer; - uint elements,max_element; - uint alloc_increment; - uint size_of_element; -} DYNAMIC_ARRAY; -typedef struct st_my_tmpdir -{ - DYNAMIC_ARRAY full_list; - char **list; - uint cur, max; - pthread_mutex_t mutex; -} MY_TMPDIR; -typedef struct st_dynamic_string -{ - char *str; - size_t length,max_length,alloc_increment; -} DYNAMIC_STRING; -struct st_io_cache; -typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*); -typedef struct st_io_cache_share -{ - pthread_mutex_t mutex; - pthread_cond_t cond; - pthread_cond_t cond_writer; - my_off_t pos_in_file; - struct st_io_cache *source_cache; - uchar *buffer; - uchar *read_end; - int running_threads; - int total_threads; - int error; -} IO_CACHE_SHARE; -typedef struct st_io_cache -{ - my_off_t pos_in_file; - my_off_t end_of_file; - uchar *read_pos; - uchar *read_end; - uchar *buffer; - uchar *request_pos; - uchar *write_buffer; - uchar *append_read_pos; - uchar *write_pos; - uchar *write_end; - uchar **current_pos, **current_end; - pthread_mutex_t append_buffer_lock; - IO_CACHE_SHARE *share; - int (*read_function)(struct st_io_cache *,uchar *,size_t); - int (*write_function)(struct st_io_cache *,const uchar *,size_t); - enum cache_type type; - IO_CACHE_CALLBACK pre_read; - IO_CACHE_CALLBACK post_read; - IO_CACHE_CALLBACK pre_close; - ulong disk_writes; - void* arg; - char *file_name; - char *dir,*prefix; - File file; - int seek_not_done,error; - size_t buffer_length; - size_t read_length; - myf myflags; - my_bool alloced_buffer; -} IO_CACHE; -typedef int (*qsort2_cmp)(const void *, const void *, const void *); -int my_b_copy_to_file(IO_CACHE *cache, FILE *file); -my_off_t my_b_append_tell(IO_CACHE* info); -my_off_t my_b_safe_tell(IO_CACHE* info); -typedef uint32 ha_checksum; -typedef int (*Process_option_func)(void *ctx, const char *group_name, - const char *option); -#include <my_alloc.h> -extern int my_copy(const char *from,const char *to,myf MyFlags); -extern int my_append(const char *from,const char *to,myf MyFlags); -extern int my_delete(const char *name,myf MyFlags); -extern int my_getwd(char * buf,size_t size,myf MyFlags); -extern int my_setwd(const char *dir,myf MyFlags); -extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags); -extern void *my_once_alloc(size_t Size,myf MyFlags); -extern void my_once_free(void); -extern char *my_once_strdup(const char *src,myf myflags); -extern void *my_once_memdup(const void *src, size_t len, myf myflags); -extern File my_open(const char *FileName,int Flags,myf MyFlags); -extern File my_register_filename(File fd, const char *FileName, - enum file_type type_of_file, - uint error_message_number, myf MyFlags); -extern File my_create(const char *FileName,int CreateFlags, - int AccessFlags, myf MyFlags); -extern int my_close(File Filedes,myf MyFlags); -extern File my_dup(File file, myf MyFlags); -extern int my_mkdir(const char *dir, int Flags, myf MyFlags); -extern int my_readlink(char *to, const char *filename, myf MyFlags); -extern int my_realpath(char *to, const char *filename, myf MyFlags); -extern File my_create_with_symlink(const char *linkname, const char *filename, - int createflags, int access_flags, - myf MyFlags); -extern int my_delete_with_symlink(const char *name, myf MyFlags); -extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); -extern int my_symlink(const char *content, const char *linkname, myf MyFlags); -extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags); -extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset, - myf MyFlags); -extern int my_rename(const char *from,const char *to,myf MyFlags); -extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags); -extern my_off_t my_tell(File fd,myf MyFlags); -extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count, - myf MyFlags); -extern size_t my_pwrite(File Filedes,const uchar *Buffer,size_t Count, - my_off_t offset,myf MyFlags); -extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags); -extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count, - myf MyFlags); -extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags); -extern my_off_t my_ftell(FILE *stream,myf MyFlags); -extern void *_mymalloc(size_t uSize,const char *sFile, - uint uLine, myf MyFlag); -extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile, - uint uLine, myf MyFlag); -extern void * my_multi_malloc (myf MyFlags, ...); -extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag); -extern int _sanity(const char *sFile, uint uLine); -extern void *_my_memdup(const void *from, size_t length, - const char *sFile, uint uLine,myf MyFlag); -extern char * _my_strdup(const char *from, const char *sFile, uint uLine, - myf MyFlag); -extern char *_my_strndup(const char *from, size_t length, - const char *sFile, uint uLine, - myf MyFlag); -extern void *my_memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); -extern int check_if_legal_filename(const char *path); -extern int check_if_legal_tablename(const char *path); -extern void init_glob_errs(void); -extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags); -extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags); -extern int my_fclose(FILE *fd,myf MyFlags); -extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags); -extern int my_sync(File fd, myf my_flags); -extern int my_sync_dir(const char *dir_name, myf my_flags); -extern int my_sync_dir_by_file(const char *file_name, myf my_flags); -extern int my_error (int nr,myf MyFlags, ...); -extern int my_printf_error (uint my_err, const char *format, myf MyFlags, ...) - __attribute__((format(printf, 2, 4))); -extern int my_error_register(const char **errmsgs, int first, int last); -extern const char **my_error_unregister(int first, int last); -extern int my_message(uint my_err, const char *str,myf MyFlags); -extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags); -extern int my_message_curses(uint my_err, const char *str,myf MyFlags); -extern my_bool my_init(void); -extern void my_end(int infoflag); -extern int my_redel(const char *from, const char *to, int MyFlags); -extern int my_copystat(const char *from, const char *to, int MyFlags); -extern char * my_filename(File fd); -extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist); -extern char *my_tmpdir(MY_TMPDIR *tmpdir); -extern void free_tmpdir(MY_TMPDIR *tmpdir); -extern void my_remember_signal(int signal_number,void (*func)(int)); -extern size_t dirname_part(char * to,const char *name, size_t *to_res_length); -extern size_t dirname_length(const char *name); -extern int test_if_hard_path(const char *dir_name); -extern my_bool has_path(const char *name); -extern char *convert_dirname(char *to, const char *from, const char *from_end); -extern void to_unix_path(char * name); -extern char * fn_ext(const char *name); -extern char * fn_same(char * toname,const char *name,int flag); -extern char * fn_format(char * to,const char *name,const char *dir, - const char *form, uint flag); -extern size_t strlength(const char *str); -extern void pack_dirname(char * to,const char *from); -extern size_t unpack_dirname(char * to,const char *from); -extern size_t cleanup_dirname(char * to,const char *from); -extern size_t system_filename(char * to,const char *from); -extern size_t unpack_filename(char * to,const char *from); -extern char * intern_filename(char * to,const char *from); -extern char * directory_file_name(char * dst, const char *src); -extern int pack_filename(char * to, const char *name, size_t max_length); -extern char * my_path(char * to,const char *progname, - const char *own_pathname_part); -extern char * my_load_path(char * to, const char *path, - const char *own_path_prefix); -extern int wild_compare(const char *str,const char *wildstr, - pbool str_is_pattern); -extern WF_PACK *wf_comp(char * str); -extern int wf_test(struct wild_file_pack *wf_pack,const char *name); -extern void wf_end(struct wild_file_pack *buffer); -extern my_bool array_append_string_unique(const char *str, - const char **array, size_t size); -extern void get_date(char * to,int timeflag,time_t use_time); -extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr, - pbool remove_garbage); -extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file, - size_t reclength,enum cache_type type, - pbool use_async_io); -extern int read_cache_record(RECORD_CACHE *info,uchar *to); -extern int end_record_cache(RECORD_CACHE *info); -extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos, - const uchar *record,size_t length); -extern int flush_write_cache(RECORD_CACHE *info); -extern long my_clock(void); -extern void sigtstp_handler(int signal_number); -extern void handle_recived_signals(void); -extern void my_set_alarm_variable(int signo); -extern void my_string_ptr_sort(uchar *base,uint items,size_t size); -extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements, - size_t size_of_element,uchar *buffer[]); -extern void my_qsort(void *base_ptr, size_t total_elems, size_t size, - qsort_cmp cmp); -extern void my_qsort2(void *base_ptr, size_t total_elems, size_t size, - qsort2_cmp cmp, void *cmp_argument); -extern qsort2_cmp get_ptr_compare(size_t); -void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos); -my_off_t my_get_ptr(uchar *ptr, size_t pack_length); -extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize, - enum cache_type type,my_off_t seek_offset, - pbool use_async_io, myf cache_myflags); -extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type, - my_off_t seek_offset,pbool use_async_io, - pbool clear_cache); -extern void setup_io_cache(IO_CACHE* info); -extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count); -extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, - IO_CACHE *write_cache, uint num_threads); -extern void remove_io_thread(IO_CACHE *info); -extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_get(IO_CACHE *info); -extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count); -extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count); -extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count); -extern int my_block_write(IO_CACHE *info, const uchar *Buffer, - size_t Count, my_off_t pos); -extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock); -extern int end_io_cache(IO_CACHE *info); -extern size_t my_b_fill(IO_CACHE *info); -extern void my_b_seek(IO_CACHE *info,my_off_t pos); -extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length); -extern my_off_t my_b_filelength(IO_CACHE *info); -extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...); -extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap); -extern my_bool open_cached_file(IO_CACHE *cache,const char *dir, - const char *prefix, size_t cache_size, - myf cache_myflags); -extern my_bool real_open_cached_file(IO_CACHE *cache); -extern void close_cached_file(IO_CACHE *cache); -File create_temp_file(char *to, const char *dir, const char *pfx, - int mode, myf MyFlags); -extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size, - void *init_buffer, uint init_alloc, - uint alloc_increment - ); -extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, - uint init_alloc,uint alloc_increment - ); -extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element); -extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array); -extern uchar *pop_dynamic(DYNAMIC_ARRAY*); -extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index); -extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements); -extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index); -extern void delete_dynamic(DYNAMIC_ARRAY *array); -extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index); -extern void freeze_size(DYNAMIC_ARRAY *array); -extern int get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element); -extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, - size_t init_alloc,size_t alloc_increment); -extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append); -my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, - size_t length); -extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append, - ...); -extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str); -extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); -extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n); -extern void dynstr_free(DYNAMIC_STRING *str); -extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, - size_t pre_alloc_size); -extern void *alloc_root(MEM_ROOT *mem_root, size_t Size); -extern void *multi_alloc_root(MEM_ROOT *mem_root, ...); -extern void free_root(MEM_ROOT *root, myf MyFLAGS); -extern void set_prealloc_root(MEM_ROOT *root, char *ptr); -extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, - size_t prealloc_size); -extern char *strdup_root(MEM_ROOT *root,const char *str); -extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len); -extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len); -extern int get_defaults_options(int argc, char **argv, - char **defaults, char **extra_defaults, - char **group_suffix); -extern int load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv); -extern int modify_defaults_file(const char *file_location, const char *option, - const char *option_value, - const char *section_name, int remove_option); -extern int my_search_option_files(const char *conf_file, int *argc, - char ***argv, uint *args_used, - Process_option_func func, void *func_ctx); -extern void free_defaults(char **argv); -extern void my_print_default_files(const char *conf_file); -extern void print_defaults(const char *conf_file, const char **groups); -extern my_bool my_compress(uchar *, size_t *, size_t *); -extern my_bool my_uncompress(uchar *, size_t , size_t *); -extern uchar *my_compress_alloc(const uchar *packet, size_t *len, - size_t *complen); -extern int packfrm(uchar *, size_t, uchar **, size_t *); -extern int unpackfrm(uchar **, size_t *, const uchar *); -extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem, - size_t count); -extern void my_sleep(ulong m_seconds); -extern ulong crc32(ulong crc, const uchar *buf, uint len); -extern uint my_set_max_open_files(uint files); -void my_free_open_file_info(void); -extern time_t my_time(myf flags); -extern ulonglong my_getsystime(void); -extern ulonglong my_micro_time(); -extern ulonglong my_micro_time_and_time(time_t *time_arg); -time_t my_time_possible_from_micro(ulonglong microtime); -extern my_bool my_gethwaddr(uchar *to); -extern int my_getncpus(); -#include <sys/mman.h> -int my_msync(int, void *, size_t, int); -extern uint get_charset_number(const char *cs_name, uint cs_flags); -extern uint get_collation_number(const char *name); -extern const char *get_charset_name(uint cs_number); -extern CHARSET_INFO *get_charset(uint cs_number, myf flags); -extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags); -extern CHARSET_INFO *get_charset_by_csname(const char *cs_name, - uint cs_flags, myf my_flags); -extern my_bool resolve_charset(const char *cs_name, - CHARSET_INFO *default_cs, - CHARSET_INFO **cs); -extern my_bool resolve_collation(const char *cl_name, - CHARSET_INFO *default_cl, - CHARSET_INFO **cl); -extern void free_charsets(void); -extern char *get_charsets_dir(char *buf); -extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2); -extern my_bool init_compiled_charsets(myf flags); -extern void add_compiled_collation(CHARSET_INFO *cs); -extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info, - char *to, size_t to_length, - const char *from, size_t length); -extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info, - char *to, size_t to_length, - const char *from, size_t length); -extern void thd_increment_bytes_sent(ulong length); -extern void thd_increment_bytes_received(ulong length); -extern void thd_increment_net_big_packet_count(ulong length); -#include <my_time.h> -#include "my_global.h" -#include "mysql_time.h" -enum enum_mysql_timestamp_type -{ - MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, - MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 -}; -typedef struct st_mysql_time -{ - unsigned int year, month, day, hour, minute, second; - unsigned long second_part; - my_bool neg; - enum enum_mysql_timestamp_type time_type; -} MYSQL_TIME; -extern ulonglong log_10_int[20]; -extern uchar days_in_month[]; -typedef long my_time_t; -my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, - ulong flags, int *was_cut); -enum enum_mysql_timestamp_type -str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, - uint flags, int *was_cut); -longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, - uint flags, int *was_cut); -ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); -ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *); -ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); -ulonglong TIME_to_ulonglong(const MYSQL_TIME *); -my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time, - int *warning); -int check_time_range(struct st_mysql_time *, int *warning); -long calc_daynr(uint year,uint month,uint day); -uint calc_days_in_year(uint year); -uint year_2000_handling(uint year); -void my_init_time(void); -static inline my_bool validate_timestamp_range(const MYSQL_TIME *t) -{ - if ((t->year > 2038 || t->year < (1900 + 70 - 1)) || - (t->year == 2038 && (t->month > 1 || t->day > 19)) || - (t->year == (1900 + 70 - 1) && (t->month < 12 || t->day < 31))) - return (0); - return (1); -} -my_time_t -my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, - my_bool *in_dst_time_gap); -void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); -int my_time_to_str(const MYSQL_TIME *l_time, char *to); -int my_date_to_str(const MYSQL_TIME *l_time, char *to); -int my_datetime_to_str(const MYSQL_TIME *l_time, char *to); -int my_TIME_to_str(const MYSQL_TIME *l_time, char *to); -enum interval_type -{ - INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY, - INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND, - INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, - INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, - INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND, - INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST -}; -#include <m_string.h> -#include <strings.h> -#include <string.h> -#include <stdarg.h> -#include <strings.h> -#include <memory.h> -extern void *(*my_str_malloc)(size_t); -extern void (*my_str_free)(void *); -extern char *stpcpy(char *, const char *); -extern char _dig_vec_upper[]; -extern char _dig_vec_lower[]; -extern const double log_10[309]; -extern void bmove512(uchar *dst,const uchar *src,size_t len); -extern void bmove_upp(uchar *dst,const uchar *src,size_t len); -extern void bchange(uchar *dst,size_t old_len,const uchar *src, - size_t new_len,size_t tot_len); -extern void strappend(char *s,size_t len,pchar fill); -extern char *strend(const char *s); -extern char *strcend(const char *, pchar); -extern char *strfield(char *src,int fields,int chars,int blanks, - int tabch); -extern char *strfill(char * s,size_t len,pchar fill); -extern size_t strinstr(const char *str,const char *search); -extern size_t r_strinstr(const char *str, size_t from, const char *search); -extern char *strkey(char *dst,char *head,char *tail,char *flags); -extern char *strmake(char *dst,const char *src,size_t length); -extern char *strnmov(char *dst,const char *src,size_t n); -extern char *strsuff(const char *src,const char *suffix); -extern char *strcont(const char *src,const char *set); -extern char *strxcat (char *dst,const char *src, ...); -extern char *strxmov (char *dst,const char *src, ...); -extern char *strxcpy (char *dst,const char *src, ...); -extern char *strxncat (char *dst,size_t len, const char *src, ...); -extern char *strxnmov (char *dst,size_t len, const char *src, ...); -extern char *strxncpy (char *dst,size_t len, const char *src, ...); -extern int is_prefix(const char *, const char *); -double my_strtod(const char *str, char **end, int *error); -double my_atof(const char *nptr); -extern char *llstr(longlong value,char *buff); -extern char *ullstr(longlong value,char *buff); -extern char *int2str(long val, char *dst, int radix, int upcase); -extern char *int10_to_str(long val,char *dst,int radix); -extern char *str2int(const char *src,int radix,long lower,long upper, - long *val); -longlong my_strtoll10(const char *nptr, char **endptr, int *error); -extern char *longlong2str(longlong val,char *dst,int radix); -extern char *longlong10_to_str(longlong val,char *dst,int radix); -extern size_t my_vsnprintf(char *str, size_t n, - const char *format, va_list ap); -extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...) - __attribute__((format(printf, 3, 4))); -struct st_mysql_lex_string -{ - char *str; - size_t length; -}; -typedef struct st_mysql_lex_string LEX_STRING; -#include <hash.h> -typedef uchar *(*hash_get_key)(const uchar *,size_t*,my_bool); -typedef void (*hash_free_key)(void *); -typedef struct st_hash { - size_t key_offset,key_length; - size_t blength; - ulong records; - uint flags; - DYNAMIC_ARRAY array; - hash_get_key get_key; - void (*free)(void *); - CHARSET_INFO *charset; -} HASH; -typedef uint HASH_SEARCH_STATE; -my_bool _hash_init(HASH *hash, uint growth_size,CHARSET_INFO *charset, - ulong default_array_elements, size_t key_offset, - size_t key_length, hash_get_key get_key, - void (*free_element)(void*), uint flags ); -void hash_free(HASH *tree); -void my_hash_reset(HASH *hash); -uchar *hash_element(HASH *hash,ulong idx); -uchar *hash_search(const HASH *info, const uchar *key, size_t length); -uchar *hash_first(const HASH *info, const uchar *key, size_t length, - HASH_SEARCH_STATE *state); -uchar *hash_next(const HASH *info, const uchar *key, size_t length, - HASH_SEARCH_STATE *state); -my_bool my_hash_insert(HASH *info,const uchar *data); -my_bool hash_delete(HASH *hash,uchar *record); -my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,size_t old_key_length); -void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, uchar *new_row); -my_bool hash_check(HASH *hash); -#include <signal.h> -#include <thr_lock.h> -#include <my_pthread.h> -#include <my_list.h> -typedef struct st_list { - struct st_list *prev,*next; - void *data; -} LIST; -typedef int (*list_walk_action)(void *,void *); -extern LIST *list_add(LIST *root,LIST *element); -extern LIST *list_delete(LIST *root,LIST *element); -extern LIST *list_cons(void *data,LIST *root); -extern LIST *list_reverse(LIST *root); -extern void list_free(LIST *root,unsigned int free_data); -extern unsigned int list_length(LIST *); -extern int list_walk(LIST *,list_walk_action action,unsigned char * argument); -struct st_thr_lock; -extern ulong locks_immediate,locks_waited ; -enum thr_lock_type { TL_IGNORE=-1, - TL_UNLOCK, - TL_READ, - TL_READ_WITH_SHARED_LOCKS, - TL_READ_HIGH_PRIORITY, - TL_READ_NO_INSERT, - TL_WRITE_ALLOW_WRITE, - TL_WRITE_ALLOW_READ, - TL_WRITE_CONCURRENT_INSERT, - TL_WRITE_DELAYED, - TL_WRITE_DEFAULT, - TL_WRITE_LOW_PRIORITY, - TL_WRITE, - TL_WRITE_ONLY}; -enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1, - THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 }; -extern ulong max_write_lock_count; -extern ulong table_lock_wait_timeout; -extern my_bool thr_lock_inited; -extern enum thr_lock_type thr_upgraded_concurrent_insert_lock; -typedef struct st_thr_lock_info -{ - pthread_t thread; - my_thread_id thread_id; - ulong n_cursors; -} THR_LOCK_INFO; -typedef struct st_thr_lock_owner -{ - THR_LOCK_INFO *info; -} THR_LOCK_OWNER; -typedef struct st_thr_lock_data { - THR_LOCK_OWNER *owner; - struct st_thr_lock_data *next,**prev; - struct st_thr_lock *lock; - pthread_cond_t *cond; - enum thr_lock_type type; - void *status_param; - void *debug_print_param; -} THR_LOCK_DATA; -struct st_lock_list { - THR_LOCK_DATA *data,**last; -}; -typedef struct st_thr_lock { - LIST list; - pthread_mutex_t mutex; - struct st_lock_list read_wait; - struct st_lock_list read; - struct st_lock_list write_wait; - struct st_lock_list write; - ulong write_lock_count; - uint read_no_write_count; - void (*get_status)(void*, int); - void (*copy_status)(void*,void*); - void (*update_status)(void*); - void (*restore_status)(void*); - my_bool (*check_status)(void *); -} THR_LOCK; -extern LIST *thr_lock_thread_list; -extern pthread_mutex_t THR_LOCK_lock; -my_bool init_thr_lock(void); -void thr_lock_info_init(THR_LOCK_INFO *info); -void thr_lock_init(THR_LOCK *lock); -void thr_lock_delete(THR_LOCK *lock); -void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data, - void *status_param); -enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, - THR_LOCK_OWNER *owner, - enum thr_lock_type lock_type); -void thr_unlock(THR_LOCK_DATA *data); -enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, - uint count, THR_LOCK_OWNER *owner); -void thr_multi_unlock(THR_LOCK_DATA **data,uint count); -void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock); -my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread); -void thr_print_locks(void); -my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data); -void thr_downgrade_write_lock(THR_LOCK_DATA *data, - enum thr_lock_type new_lock_type); -my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data); -#include <my_base.h> -#include <my_global.h> -#include <my_dir.h> -#include <sys/stat.h> -typedef struct fileinfo -{ - char *name; - struct stat *mystat; -} FILEINFO; -typedef struct st_my_dir -{ - struct fileinfo *dir_entry; - uint number_off_files; -} MY_DIR; -extern MY_DIR *my_dir(const char *path,myf MyFlags); -extern void my_dirend(MY_DIR *buffer); -extern struct stat *my_stat(const char *path, struct stat *stat_area, myf my_flags); -extern int my_fstat(int filenr, struct stat *stat_area, myf MyFlags); -#include <my_sys.h> -#include <m_string.h> -#include <errno.h> -#include <my_list.h> -enum ha_rkey_function { - HA_READ_KEY_EXACT, - HA_READ_KEY_OR_NEXT, - HA_READ_KEY_OR_PREV, - HA_READ_AFTER_KEY, - HA_READ_BEFORE_KEY, - HA_READ_PREFIX, - HA_READ_PREFIX_LAST, - HA_READ_PREFIX_LAST_OR_PREV, - HA_READ_MBR_CONTAIN, - HA_READ_MBR_INTERSECT, - HA_READ_MBR_WITHIN, - HA_READ_MBR_DISJOINT, - HA_READ_MBR_EQUAL -}; -enum ha_key_alg { - HA_KEY_ALG_UNDEF= 0, - HA_KEY_ALG_BTREE= 1, - HA_KEY_ALG_RTREE= 2, - HA_KEY_ALG_HASH= 3, - HA_KEY_ALG_FULLTEXT= 4 -}; -enum ha_storage_media { - HA_SM_DEFAULT= 0, - HA_SM_DISK= 1, - HA_SM_MEMORY= 2 -}; -enum ha_extra_function { - HA_EXTRA_NORMAL=0, - HA_EXTRA_QUICK=1, - HA_EXTRA_NOT_USED=2, - HA_EXTRA_CACHE=3, - HA_EXTRA_NO_CACHE=4, - HA_EXTRA_NO_READCHECK=5, - HA_EXTRA_READCHECK=6, - HA_EXTRA_KEYREAD=7, - HA_EXTRA_NO_KEYREAD=8, - HA_EXTRA_NO_USER_CHANGE=9, - HA_EXTRA_KEY_CACHE=10, - HA_EXTRA_NO_KEY_CACHE=11, - HA_EXTRA_WAIT_LOCK=12, - HA_EXTRA_NO_WAIT_LOCK=13, - HA_EXTRA_WRITE_CACHE=14, - HA_EXTRA_FLUSH_CACHE=15, - HA_EXTRA_NO_KEYS=16, - HA_EXTRA_KEYREAD_CHANGE_POS=17, - HA_EXTRA_REMEMBER_POS=18, - HA_EXTRA_RESTORE_POS=19, - HA_EXTRA_REINIT_CACHE=20, - HA_EXTRA_FORCE_REOPEN=21, - HA_EXTRA_FLUSH, - HA_EXTRA_NO_ROWS, - HA_EXTRA_RESET_STATE, - HA_EXTRA_IGNORE_DUP_KEY, - HA_EXTRA_NO_IGNORE_DUP_KEY, - HA_EXTRA_PREPARE_FOR_DROP, - HA_EXTRA_PREPARE_FOR_UPDATE, - HA_EXTRA_PRELOAD_BUFFER_SIZE, - HA_EXTRA_CHANGE_KEY_TO_UNIQUE, - HA_EXTRA_CHANGE_KEY_TO_DUP, - HA_EXTRA_KEYREAD_PRESERVE_FIELDS, - HA_EXTRA_MMAP, - HA_EXTRA_IGNORE_NO_KEY, - HA_EXTRA_NO_IGNORE_NO_KEY, - HA_EXTRA_MARK_AS_LOG_TABLE, - HA_EXTRA_WRITE_CAN_REPLACE, - HA_EXTRA_WRITE_CANNOT_REPLACE, - HA_EXTRA_DELETE_CANNOT_BATCH, - HA_EXTRA_UPDATE_CANNOT_BATCH, - HA_EXTRA_INSERT_WITH_UPDATE, - HA_EXTRA_PREPARE_FOR_RENAME, - HA_EXTRA_ATTACH_CHILDREN, - HA_EXTRA_DETACH_CHILDREN -}; -enum ha_panic_function { - HA_PANIC_CLOSE, - HA_PANIC_WRITE, - HA_PANIC_READ -}; -enum ha_base_keytype { - HA_KEYTYPE_END=0, - HA_KEYTYPE_TEXT=1, - HA_KEYTYPE_BINARY=2, - HA_KEYTYPE_SHORT_INT=3, - HA_KEYTYPE_LONG_INT=4, - HA_KEYTYPE_FLOAT=5, - HA_KEYTYPE_DOUBLE=6, - HA_KEYTYPE_NUM=7, - HA_KEYTYPE_USHORT_INT=8, - HA_KEYTYPE_ULONG_INT=9, - HA_KEYTYPE_LONGLONG=10, - HA_KEYTYPE_ULONGLONG=11, - HA_KEYTYPE_INT24=12, - HA_KEYTYPE_UINT24=13, - HA_KEYTYPE_INT8=14, - HA_KEYTYPE_VARTEXT1=15, - HA_KEYTYPE_VARBINARY1=16, - HA_KEYTYPE_VARTEXT2=17, - HA_KEYTYPE_VARBINARY2=18, - HA_KEYTYPE_BIT=19 -}; -typedef ulong key_part_map; -enum en_fieldtype { - FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIP_ENDSPACE,FIELD_SKIP_PRESPACE, - FIELD_SKIP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO, - FIELD_VARCHAR,FIELD_CHECK, - FIELD_enum_val_count -}; -enum data_file_type { - STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD -}; -typedef struct st_key_range -{ - const uchar *key; - uint length; - key_part_map keypart_map; - enum ha_rkey_function flag; -} key_range; -typedef struct st_key_multi_range -{ - key_range start_key; - key_range end_key; - char *ptr; - uint range_flag; -} KEY_MULTI_RANGE; -typedef my_off_t ha_rows; -typedef void (* invalidator_by_filename)(const char * filename); -#include <queues.h> -typedef struct st_queue { - uchar **root; - void *first_cmp_arg; - uint elements; - uint max_elements; - uint offset_to_key; - int max_at_top; - int (*compare)(void *, uchar *,uchar *); - uint auto_extent; -} QUEUE; -typedef int (*queue_compare)(void *,uchar *, uchar *); -int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key, - pbool max_at_top, queue_compare compare, - void *first_cmp_arg); -int init_queue_ex(QUEUE *queue,uint max_elements,uint offset_to_key, - pbool max_at_top, queue_compare compare, - void *first_cmp_arg, uint auto_extent); -int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key, - pbool max_at_top, queue_compare compare, - void *first_cmp_arg); -int resize_queue(QUEUE *queue, uint max_elements); -void delete_queue(QUEUE *queue); -void queue_insert(QUEUE *queue,uchar *element); -int queue_insert_safe(QUEUE *queue, uchar *element); -uchar *queue_remove(QUEUE *queue,uint idx); -void _downheap(QUEUE *queue,uint idx); -void queue_fix(QUEUE *queue); -#include "sql_bitmap.h" -#include <my_bitmap.h> -#include <m_string.h> -typedef uint32 my_bitmap_map; -typedef struct st_bitmap -{ - my_bitmap_map *bitmap; - uint n_bits; - my_bitmap_map last_word_mask; - my_bitmap_map *last_word_ptr; - pthread_mutex_t *mutex; -} MY_BITMAP; -extern void create_last_word_mask(MY_BITMAP *map); -extern my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits, - my_bool thread_safe); -extern my_bool bitmap_is_clear_all(const MY_BITMAP *map); -extern my_bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size); -extern my_bool bitmap_is_set_all(const MY_BITMAP *map); -extern my_bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2); -extern my_bool bitmap_is_overlapping(const MY_BITMAP *map1, - const MY_BITMAP *map2); -extern my_bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit); -extern my_bool bitmap_test_and_clear(MY_BITMAP *map, uint bitmap_bit); -extern my_bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit); -extern uint bitmap_set_next(MY_BITMAP *map); -extern uint bitmap_get_first(const MY_BITMAP *map); -extern uint bitmap_get_first_set(const MY_BITMAP *map); -extern uint bitmap_bits_set(const MY_BITMAP *map); -extern void bitmap_free(MY_BITMAP *map); -extern void bitmap_set_above(MY_BITMAP *map, uint from_byte, uint use_bit); -extern void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size); -extern void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2); -extern void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2); -extern void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2); -extern void bitmap_xor(MY_BITMAP *map, const MY_BITMAP *map2); -extern void bitmap_invert(MY_BITMAP *map); -extern void bitmap_copy(MY_BITMAP *map, const MY_BITMAP *map2); -extern uint bitmap_lock_set_next(MY_BITMAP *map); -extern void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit); -static inline void -bitmap_set_bit(MY_BITMAP *map,uint bit) -{ - assert(bit < (map)->n_bits); - (((uchar*)(map)->bitmap)[(bit) / 8] |= (1 << ((bit) & 7))); -} -static inline void -bitmap_flip_bit(MY_BITMAP *map,uint bit) -{ - assert(bit < (map)->n_bits); - (((uchar*)(map)->bitmap)[(bit) / 8] ^= (1 << ((bit) & 7))); -} -static inline void -bitmap_clear_bit(MY_BITMAP *map,uint bit) -{ - assert(bit < (map)->n_bits); - (((uchar*)(map)->bitmap)[(bit) / 8] &= ~ (1 << ((bit) & 7))); -} -static inline uint -bitmap_is_set(const MY_BITMAP *map,uint bit) -{ - assert(bit < (map)->n_bits); - return (uint) (((uchar*)(map)->bitmap)[(bit) / 8] & (1 << ((bit) & 7))); -} -static inline my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2) -{ - *(map1)->last_word_ptr|= (map1)->last_word_mask; - *(map2)->last_word_ptr|= (map2)->last_word_mask; - return memcmp((map1)->bitmap, (map2)->bitmap, 4*((((map1))->n_bits + 31)/32))==0; -} -template <uint default_width> class Bitmap -{ - MY_BITMAP map; - uint32 buffer[(default_width+31)/32]; -public: - Bitmap() { init(); } - Bitmap(const Bitmap& from) { *this=from; } - explicit Bitmap(uint prefix_to_set) { init(prefix_to_set); } - void init() { bitmap_init(&map, buffer, default_width, 0); } - void init(uint prefix_to_set) { init(); set_prefix(prefix_to_set); } - uint length() const { return default_width; } - Bitmap& operator=(const Bitmap& map2) - { - init(); - memcpy(buffer, map2.buffer, sizeof(buffer)); - return *this; - } - void set_bit(uint n) { bitmap_set_bit(&map, n); } - void clear_bit(uint n) { bitmap_clear_bit(&map, n); } - void set_prefix(uint n) { bitmap_set_prefix(&map, n); } - void set_all() { (memset((&map)->bitmap, 0xFF, 4*((((&map))->n_bits + 31)/32))); } - void clear_all() { { memset((&map)->bitmap, 0, 4*((((&map))->n_bits + 31)/32)); }; } - void intersect(Bitmap& map2) { bitmap_intersect(&map, &map2.map); } - void intersect(ulonglong map2buff) - { - MY_BITMAP map2; - bitmap_init(&map2, (uint32 *)&map2buff, sizeof(ulonglong)*8, 0); - bitmap_intersect(&map, &map2); - } - void intersect_extended(ulonglong map2buff) - { - intersect(map2buff); - if (map.n_bits > sizeof(ulonglong) * 8) - bitmap_set_above(&map, sizeof(ulonglong), - ((map2buff & (1LL << (sizeof(ulonglong) * 8 - 1))) ? 1 : 0)); - } - void subtract(Bitmap& map2) { bitmap_subtract(&map, &map2.map); } - void merge(Bitmap& map2) { bitmap_union(&map, &map2.map); } - my_bool is_set(uint n) const { return bitmap_is_set(&map, n); } - my_bool is_prefix(uint n) const { return bitmap_is_prefix(&map, n); } - my_bool is_clear_all() const { return bitmap_is_clear_all(&map); } - my_bool is_set_all() const { return bitmap_is_set_all(&map); } - my_bool is_subset(const Bitmap& map2) const { return bitmap_is_subset(&map, &map2.map); } - my_bool is_overlapping(const Bitmap& map2) const { return bitmap_is_overlapping(&map, &map2.map); } - my_bool operator==(const Bitmap& map2) const { return bitmap_cmp(&map, &map2.map); } - char *print(char *buf) const - { - char *s=buf; - const uchar *e=(uchar *)buffer, *b=e+sizeof(buffer)-1; - while (!*b && b>e) - b--; - if ((*s=_dig_vec_upper[*b >> 4]) != '0') - s++; - *s++=_dig_vec_upper[*b & 15]; - while (--b>=e) - { - *s++=_dig_vec_upper[*b >> 4]; - *s++=_dig_vec_upper[*b & 15]; - } - *s=0; - return buf; - } - ulonglong to_ulonglong() const - { - if (sizeof(buffer) >= 8) - return (*((ulonglong *) (buffer))); - assert(sizeof(buffer) >= 4); - return (ulonglong) (*((uint32 *) (buffer))); - } -}; -template <> class Bitmap<64> -{ - ulonglong map; -public: - Bitmap<64>() { } - explicit Bitmap<64>(uint prefix_to_set) { set_prefix(prefix_to_set); } - void init() { } - void init(uint prefix_to_set) { set_prefix(prefix_to_set); } - uint length() const { return 64; } - void set_bit(uint n) { map|= ((ulonglong)1) << n; } - void clear_bit(uint n) { map&= ~(((ulonglong)1) << n); } - void set_prefix(uint n) - { - if (n >= length()) - set_all(); - else - map= (((ulonglong)1) << n)-1; - } - void set_all() { map=~(ulonglong)0; } - void clear_all() { map=(ulonglong)0; } - void intersect(Bitmap<64>& map2) { map&= map2.map; } - void intersect(ulonglong map2) { map&= map2; } - void intersect_extended(ulonglong map2) { map&= map2; } - void subtract(Bitmap<64>& map2) { map&= ~map2.map; } - void merge(Bitmap<64>& map2) { map|= map2.map; } - my_bool is_set(uint n) const { return ((map & (((ulonglong)1) << n)) ? 1 : 0); } - my_bool is_prefix(uint n) const { return map == (((ulonglong)1) << n)-1; } - my_bool is_clear_all() const { return map == (ulonglong)0; } - my_bool is_set_all() const { return map == ~(ulonglong)0; } - my_bool is_subset(const Bitmap<64>& map2) const { return !(map & ~map2.map); } - my_bool is_overlapping(const Bitmap<64>& map2) const { return (map & map2.map)!= 0; } - my_bool operator==(const Bitmap<64>& map2) const { return map == map2.map; } - char *print(char *buf) const { longlong2str(map,buf,16); return buf; } - ulonglong to_ulonglong() const { return map; } -}; -#include "sql_array.h" -#include <my_sys.h> -template <class Elem> class Dynamic_array -{ - DYNAMIC_ARRAY array; -public: - Dynamic_array(uint prealloc=16, uint increment=16) - { - init_dynamic_array2(&array,sizeof(Elem),NULL,prealloc,increment ); - } - Elem& at(int idx) - { - return *(((Elem*)array.buffer) + idx); - } - Elem *front() - { - return (Elem*)array.buffer; - } - Elem *back() - { - return ((Elem*)array.buffer) + array.elements; - } - In_C_you_should_use_my_bool_instead() append(Elem &el) - { - return (insert_dynamic(&array, (uchar*)&el)); - } - int elements() - { - return array.elements; - } - ~Dynamic_array() - { - delete_dynamic(&array); - } - typedef int (*CMP_FUNC)(const Elem *el1, const Elem *el2); - void sort(CMP_FUNC cmp_func) - { - my_qsort(array.buffer, array.elements, sizeof(Elem), (qsort_cmp)cmp_func); - } -}; -#include "sql_plugin.h" -class sys_var; -#include <mysql/plugin.h> -typedef struct st_mysql_lex_string MYSQL_LEX_STRING; -struct st_mysql_xid { - long formatID; - long gtrid_length; - long bqual_length; - char data[128]; -}; -typedef struct st_mysql_xid MYSQL_XID; -enum enum_mysql_show_type -{ - SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG, - SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, - SHOW_ARRAY, SHOW_FUNC, 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_DOUBLE -}; -struct st_mysql_show_var { - const char *name; - char *value; - enum enum_mysql_show_type type; -}; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); -struct st_mysql_sys_var; -struct st_mysql_value; -typedef int (*mysql_var_check_func)(void* thd, - struct st_mysql_sys_var *var, - void *save, struct st_mysql_value *value); -typedef void (*mysql_var_update_func)(void* thd, - struct st_mysql_sys_var *var, - void *var_ptr, const void *save); -struct st_mysql_plugin -{ - int type; - void *info; - const char *name; - const char *author; - const char *descr; - int license; - int (*init)(void *); - int (*deinit)(void *); - unsigned int version; - struct st_mysql_show_var *status_vars; - struct st_mysql_sys_var **system_vars; - void * __reserved1; -}; -enum enum_ftparser_mode -{ - MYSQL_FTPARSER_SIMPLE_MODE= 0, - MYSQL_FTPARSER_WITH_STOPWORDS= 1, - MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2 -}; -enum enum_ft_token_type -{ - FT_TOKEN_EOF= 0, - FT_TOKEN_WORD= 1, - FT_TOKEN_LEFT_PAREN= 2, - FT_TOKEN_RIGHT_PAREN= 3, - FT_TOKEN_STOPWORD= 4 -}; -typedef struct st_mysql_ftparser_boolean_info -{ - enum enum_ft_token_type type; - int yesno; - int weight_adjust; - char wasign; - char trunc; - char prev; - char *quot; -} MYSQL_FTPARSER_BOOLEAN_INFO; -typedef struct st_mysql_ftparser_param -{ - int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); - int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, - MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); - void *ftparser_state; - void *mysql_ftparam; - struct charset_info_st *cs; - char *doc; - int length; - int flags; - enum enum_ftparser_mode mode; -} MYSQL_FTPARSER_PARAM; -struct st_mysql_ftparser -{ - int interface_version; - int (*parse)(MYSQL_FTPARSER_PARAM *param); - int (*init)(MYSQL_FTPARSER_PARAM *param); - int (*deinit)(MYSQL_FTPARSER_PARAM *param); -}; -struct st_mysql_storage_engine -{ - int interface_version; -}; -struct handlerton; -struct st_mysql_daemon -{ - int interface_version; -}; -struct st_mysql_information_schema -{ - int interface_version; -}; -struct st_mysql_value -{ - int (*value_type)(struct st_mysql_value *); - const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length); - int (*val_real)(struct st_mysql_value *, double *realbuf); - int (*val_int)(struct st_mysql_value *, long long *intbuf); -}; -int thd_in_lock_tables(const void* thd); -int thd_tablespace_op(const void* thd); -long long thd_test_options(const void* thd, long long test_options); -int thd_sql_command(const void* thd); -const char *thd_proc_info(void* thd, const char *info); -void **thd_ha_data(const void* thd, const struct handlerton *hton); -int thd_tx_isolation(const void* thd); -char *thd_security_context(void* thd, char *buffer, unsigned int length, - unsigned int max_query_len); -void thd_inc_row_count(void* thd); -int mysql_tmpfile(const char *prefix); -int thd_killed(const void* thd); -unsigned long thd_get_thread_id(const void* thd); -void *thd_alloc(void* thd, unsigned int size); -void *thd_calloc(void* thd, unsigned int size); -char *thd_strdup(void* thd, const char *str); -char *thd_strmake(void* thd, const char *str, unsigned int size); -void *thd_memdup(void* thd, const void* str, unsigned int size); -MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, - const char *str, unsigned int size, - int allocate_lex_string); -void thd_get_xid(const void* thd, MYSQL_XID *xid); -void mysql_query_cache_invalidate4(void* thd, - const char *key, unsigned int key_length, - int using_trx); -typedef enum enum_mysql_show_type SHOW_TYPE; -typedef struct st_mysql_show_var SHOW_VAR; -struct st_plugin_dl -{ - LEX_STRING dl; - void *handle; - struct st_mysql_plugin *plugins; - int version; - uint ref_count; -}; -struct st_plugin_int -{ - LEX_STRING name; - struct st_mysql_plugin *plugin; - struct st_plugin_dl *plugin_dl; - uint state; - uint ref_count; - void *data; - MEM_ROOT mem_root; - sys_var *system_vars; -}; -typedef struct st_plugin_int **plugin_ref; -typedef int (*plugin_type_init)(struct st_plugin_int *); -extern char *opt_plugin_load; -extern char *opt_plugin_dir_ptr; -extern char opt_plugin_dir[512]; -extern const LEX_STRING plugin_type_names[]; -extern int plugin_init(int *argc, char **argv, int init_flags); -extern void plugin_shutdown(void); -extern void my_print_help_inc_plugins(struct my_option *options, uint size); -extern In_C_you_should_use_my_bool_instead() plugin_is_ready(const LEX_STRING *name, int type); -extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr ); -extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, - int type ); -extern void plugin_unlock(THD *thd, plugin_ref plugin); -extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count); -extern In_C_you_should_use_my_bool_instead() mysql_install_plugin(THD *thd, const LEX_STRING *name, - const LEX_STRING *dl); -extern In_C_you_should_use_my_bool_instead() mysql_uninstall_plugin(THD *thd, const LEX_STRING *name); -extern In_C_you_should_use_my_bool_instead() plugin_register_builtin(struct st_mysql_plugin *plugin); -extern void plugin_thdvar_init(THD *thd); -extern void plugin_thdvar_cleanup(THD *thd); -typedef my_bool (plugin_foreach_func)(THD *thd, - plugin_ref plugin, - void *arg); -extern In_C_you_should_use_my_bool_instead() plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, - int type, uint state_mask, void *arg); -#include "scheduler.h" -class THD; -class scheduler_functions -{ -public: - uint max_threads; - In_C_you_should_use_my_bool_instead() (*init)(void); - In_C_you_should_use_my_bool_instead() (*init_new_connection_thread)(void); - void (*add_connection)(THD *thd); - void (*post_kill_notification)(THD *thd); - In_C_you_should_use_my_bool_instead() (*end_thread)(THD *thd, In_C_you_should_use_my_bool_instead() cache_thread); - void (*end)(void); - scheduler_functions(); -}; -enum scheduler_types -{ - SCHEDULER_ONE_THREAD_PER_CONNECTION=0, - SCHEDULER_NO_THREADS, - SCHEDULER_POOL_OF_THREADS -}; -void one_thread_per_connection_scheduler(scheduler_functions* func); -void one_thread_scheduler(scheduler_functions* func); -enum pool_command_op -{ - NOT_IN_USE_OP= 0, NORMAL_OP= 1, CONNECT_OP, KILL_OP, DIE_OP -}; -class thd_scheduler -{}; -enum enum_query_type -{ - QT_ORDINARY, - QT_IS -}; -typedef ulonglong table_map; -typedef Bitmap<64> key_map; -typedef ulong nesting_map; -typedef ulonglong nested_join_map; -typedef ulonglong query_id_t; -extern query_id_t global_query_id; -inline query_id_t next_query_id() { return global_query_id++; } -extern const key_map key_map_empty; -extern key_map key_map_full; -extern const char *primary_key_name; -#include "mysql_com.h" -enum enum_server_command -{ - COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST, - COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS, - COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING, - COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP, - COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE, - COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE, - COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON, - COM_END -}; -struct st_vio; -typedef struct st_vio Vio; -typedef struct st_net { - Vio *vio; - unsigned char *buff,*buff_end,*write_pos,*read_pos; - my_socket fd; - unsigned long remain_in_buf,length, buf_length, where_b; - unsigned long max_packet,max_packet_size; - unsigned int pkt_nr,compress_pkt_nr; - unsigned int write_timeout, read_timeout, retry_count; - int fcntl; - unsigned int *return_status; - unsigned char reading_or_writing; - char save_char; - my_bool unused0; - my_bool unused; - my_bool compress; - my_bool unused1; - unsigned char *query_cache_query; - unsigned int last_errno; - unsigned char error; - my_bool unused2; - my_bool return_errno; - char last_error[512]; - char sqlstate[5 +1]; - void *extension; -} NET; -enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, - MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, - MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, - MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, - MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24, - MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, - MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, - MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, - MYSQL_TYPE_BIT, - MYSQL_TYPE_NEWDECIMAL=246, - MYSQL_TYPE_ENUM=247, - MYSQL_TYPE_SET=248, - MYSQL_TYPE_TINY_BLOB=249, - MYSQL_TYPE_MEDIUM_BLOB=250, - MYSQL_TYPE_LONG_BLOB=251, - MYSQL_TYPE_BLOB=252, - MYSQL_TYPE_VAR_STRING=253, - MYSQL_TYPE_STRING=254, - MYSQL_TYPE_GEOMETRY=255 -}; -enum mysql_enum_shutdown_level { - SHUTDOWN_DEFAULT = 0, - SHUTDOWN_WAIT_CONNECTIONS= (unsigned char)(1 << 0), - SHUTDOWN_WAIT_TRANSACTIONS= (unsigned char)(1 << 1), - SHUTDOWN_WAIT_UPDATES= (unsigned char)(1 << 3), - SHUTDOWN_WAIT_ALL_BUFFERS= ((unsigned char)(1 << 3) << 1), - SHUTDOWN_WAIT_CRITICAL_BUFFERS= ((unsigned char)(1 << 3) << 1) + 1, - KILL_QUERY= 254, - KILL_CONNECTION= 255 -}; -enum enum_cursor_type -{ - CURSOR_TYPE_NO_CURSOR= 0, - CURSOR_TYPE_READ_ONLY= 1, - CURSOR_TYPE_FOR_UPDATE= 2, - CURSOR_TYPE_SCROLLABLE= 4 -}; -enum enum_mysql_set_option -{ - MYSQL_OPTION_MULTI_STATEMENTS_ON, - MYSQL_OPTION_MULTI_STATEMENTS_OFF -}; -my_bool my_net_init(NET *net, Vio* vio); -void my_net_local_init(NET *net); -void net_end(NET *net); - void net_clear(NET *net, my_bool clear_buffer); -my_bool net_realloc(NET *net, size_t length); -my_bool net_flush(NET *net); -my_bool my_net_write(NET *net,const unsigned char *packet, size_t len); -my_bool net_write_command(NET *net,unsigned char command, - const unsigned char *header, size_t head_len, - const unsigned char *packet, size_t len); -int net_real_write(NET *net,const unsigned char *packet, size_t len); -unsigned long my_net_read(NET *net); -void my_net_set_write_timeout(NET *net, uint timeout); -void my_net_set_read_timeout(NET *net, uint timeout); -struct sockaddr; -int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen, - unsigned int timeout); -struct rand_struct { - unsigned long seed1,seed2,max_value; - double max_value_dbl; -}; -enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, - DECIMAL_RESULT}; -typedef struct st_udf_args -{ - unsigned int arg_count; - enum Item_result *arg_type; - char **args; - unsigned long *lengths; - char *maybe_null; - char **attributes; - unsigned long *attribute_lengths; - void *extension; -} UDF_ARGS; -typedef struct st_udf_init -{ - my_bool maybe_null; - unsigned int decimals; - unsigned long max_length; - char *ptr; - my_bool const_item; - void *extension; -} UDF_INIT; -void randominit(struct rand_struct *, unsigned long seed1, - unsigned long seed2); -double my_rnd(struct rand_struct *); -void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st); -void hash_password(unsigned long *to, const char *password, unsigned int password_len); -void make_scrambled_password_323(char *to, const char *password); -void scramble_323(char *to, const char *message, const char *password); -my_bool check_scramble_323(const char *, const char *message, - unsigned long *salt); -void get_salt_from_password_323(unsigned long *res, const char *password); -void make_password_from_salt_323(char *to, const unsigned long *salt); -void make_scrambled_password(char *to, const char *password); -void scramble(char *to, const char *message, const char *password); -my_bool check_scramble(const char *reply, const char *message, - const unsigned char *hash_stage2); -void get_salt_from_password(unsigned char *res, const char *password); -void make_password_from_salt(char *to, const unsigned char *hash_stage2); -char *octet2hex(char *to, const char *str, unsigned int len); -char *get_tty_password(const char *opt_message); -const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); -my_bool my_thread_init(void); -void my_thread_end(void); -ulong net_field_length(uchar **packet); -my_ulonglong net_field_length_ll(uchar **packet); -uchar *net_store_length(uchar *pkg, ulonglong length); -#include <violite.h> -#include "my_net.h" -#include <errno.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <sys/poll.h> -#include <sys/ioctl.h> -#include <netinet/in_systm.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#include <netinet/tcp.h> -void my_inet_ntoa(struct in_addr in, char *buf); -struct hostent; -struct hostent *my_gethostbyname_r(const char *name, - struct hostent *result, char *buffer, - int buflen, int *h_errnop); -enum enum_vio_type -{ - VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE, - VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY -}; -Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags); -void vio_delete(Vio* vio); -int vio_close(Vio* vio); -void vio_reset(Vio* vio, enum enum_vio_type type, - my_socket sd, void * hPipe, uint flags); -size_t vio_read(Vio *vio, uchar * buf, size_t size); -size_t vio_read_buff(Vio *vio, uchar * buf, size_t size); -size_t vio_write(Vio *vio, const uchar * buf, size_t size); -int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode); -my_bool vio_is_blocking(Vio *vio); -int vio_fastsend(Vio *vio); -int vio_keepalive(Vio *vio, my_bool onoff); -my_bool vio_should_retry(Vio *vio); -my_bool vio_was_interrupted(Vio *vio); -const char* vio_description(Vio *vio); -enum enum_vio_type vio_type(Vio* vio); -int vio_errno(Vio*vio); -my_socket vio_fd(Vio*vio); -my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); -void vio_in_addr(Vio *vio, struct in_addr *in); -my_bool vio_poll_read(Vio *vio,uint timeout); -void vio_end(void); -enum SSL_type -{ - SSL_TYPE_NOT_SPECIFIED= -1, - SSL_TYPE_NONE, - SSL_TYPE_ANY, - SSL_TYPE_X509, - SSL_TYPE_SPECIFIED -}; -struct st_vio -{ - my_socket sd; - void * hPipe; - my_bool localhost; - int fcntl_mode; - struct sockaddr_in local; - struct sockaddr_in remote; - enum enum_vio_type type; - char desc[30]; - char *read_buffer; - char *read_pos; - char *read_end; - void (*viodelete)(Vio*); - int (*vioerrno)(Vio*); - size_t (*read)(Vio*, uchar *, size_t); - size_t (*write)(Vio*, const uchar *, size_t); - int (*vioblocking)(Vio*, my_bool, my_bool *); - my_bool (*is_blocking)(Vio*); - int (*viokeepalive)(Vio*, my_bool); - int (*fastsend)(Vio*); - my_bool (*peer_addr)(Vio*, char *, uint16*); - void (*in_addr)(Vio*, struct in_addr*); - my_bool (*should_retry)(Vio*); - my_bool (*was_interrupted)(Vio*); - int (*vioclose)(Vio*); - void (*timeout)(Vio*, unsigned int which, unsigned int timeout); -}; -#include "unireg.h" -#include "mysqld_error.h" -#include "structs.h" -struct st_table; -class Field; -typedef struct st_date_time_format { - uchar positions[8]; - char time_separator; - uint flag; - LEX_STRING format; -} DATE_TIME_FORMAT; -typedef struct st_keyfile_info { - uchar ref[8]; - uchar dupp_ref[8]; - uint ref_length; - uint block_size; - File filenr; - ha_rows records; - ha_rows deleted; - ulonglong data_file_length; - ulonglong max_data_file_length; - ulonglong index_file_length; - ulonglong max_index_file_length; - ulonglong delete_length; - ulonglong auto_increment_value; - int errkey,sortkey; - time_t create_time; - time_t check_time; - time_t update_time; - ulong mean_rec_length; -} KEYFILE_INFO; -typedef struct st_key_part_info { - Field *field; - uint offset; - uint null_offset; - uint16 length; - uint16 store_length; - uint16 key_type; - uint16 fieldnr; - uint16 key_part_flag; - uint8 type; - uint8 null_bit; -} KEY_PART_INFO ; -typedef struct st_key { - uint key_length; - ulong flags; - uint key_parts; - uint extra_length; - uint usable_key_parts; - uint block_size; - enum ha_key_alg algorithm; - union - { - plugin_ref parser; - LEX_STRING *parser_name; - }; - KEY_PART_INFO *key_part; - char *name; - ulong *rec_per_key; - union { - int bdb_return_if_eq; - } handler; - struct st_table *table; -} KEY; -struct st_join_table; -typedef struct st_reginfo { - struct st_join_table *join_tab; - enum thr_lock_type lock_type; - In_C_you_should_use_my_bool_instead() not_exists_optimize; - In_C_you_should_use_my_bool_instead() impossible_range; -} REGINFO; -struct st_read_record; -class SQL_SELECT; -class THD; -class handler; -typedef struct st_read_record { - struct st_table *table; - handler *file; - struct st_table **forms; - int (*read_record)(struct st_read_record *); - THD *thd; - SQL_SELECT *select; - uint cache_records; - uint ref_length,struct_length,reclength,rec_cache_size,error_offset; - uint index; - uchar *ref_pos; - uchar *record; - uchar *rec_buf; - uchar *cache,*cache_pos,*cache_end,*read_positions; - IO_CACHE *io_cache; - In_C_you_should_use_my_bool_instead() print_error, ignore_not_found_rows; -} READ_RECORD; -typedef enum enum_mysql_timestamp_type timestamp_type; -typedef struct { - ulong year,month,day,hour; - ulonglong minute,second,second_part; - In_C_you_should_use_my_bool_instead() neg; -} INTERVAL; -typedef struct st_known_date_time_format { - const char *format_name; - const char *date_format; - const char *datetime_format; - const char *time_format; -} KNOWN_DATE_TIME_FORMAT; -enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED}; -extern const char *show_comp_option_name[]; -typedef int *(*update_var)(THD *, struct st_mysql_show_var *); -typedef struct st_lex_user { - LEX_STRING user, host, password; -} LEX_USER; -typedef struct user_resources { - uint questions; - uint updates; - uint conn_per_hour; - uint user_conn; - enum {QUERIES_PER_HOUR= 1, UPDATES_PER_HOUR= 2, CONNECTIONS_PER_HOUR= 4, - USER_CONNECTIONS= 8}; - uint specified_limits; -} USER_RESOURCES; -typedef struct user_conn { - char *user; - char *host; - ulonglong reset_utime; - uint len; - uint connections; - uint conn_per_hour, updates, questions; - USER_RESOURCES user_resources; -} USER_CONN; -class Discrete_interval { -private: - ulonglong interval_min; - ulonglong interval_values; - ulonglong interval_max; -public: - Discrete_interval *next; - void replace(ulonglong start, ulonglong val, ulonglong incr) - { - interval_min= start; - interval_values= val; - interval_max= (val == ((unsigned long long)(~0ULL))) ? val : start + val * incr; - } - Discrete_interval(ulonglong start, ulonglong val, ulonglong incr) : - next(NULL) { replace(start, val, incr); }; - Discrete_interval() : next(NULL) { replace(0, 0, 0); }; - ulonglong minimum() const { return interval_min; }; - ulonglong values() const { return interval_values; }; - ulonglong maximum() const { return interval_max; }; - In_C_you_should_use_my_bool_instead() merge_if_contiguous(ulonglong start, ulonglong val, ulonglong incr) - { - if (interval_max == start) - { - if (val == ((unsigned long long)(~0ULL))) - { - interval_values= interval_max= val; - } - else - { - interval_values+= val; - interval_max= start + val * incr; - } - return 0; - } - return 1; - }; -}; -class Discrete_intervals_list { -private: - Discrete_interval *head; - Discrete_interval *tail; - Discrete_interval *current; - uint elements; - void copy_(const Discrete_intervals_list& from) - { - for (Discrete_interval *i= from.head; i; i= i->next) - { - Discrete_interval j= *i; - append(&j); - } - } -public: - Discrete_intervals_list() : head(NULL), current(NULL), elements(0) {}; - Discrete_intervals_list(const Discrete_intervals_list& from) - { - copy_(from); - } - void operator=(const Discrete_intervals_list& from) - { - empty(); - copy_(from); - } - void empty_no_free() - { - head= current= NULL; - elements= 0; - } - void empty() - { - for (Discrete_interval *i= head; i;) - { - Discrete_interval *next= i->next; - delete i; - i= next; - } - empty_no_free(); - } - const Discrete_interval* get_next() - { - Discrete_interval *tmp= current; - if (current != NULL) - current= current->next; - return tmp; - } - ~Discrete_intervals_list() { empty(); }; - In_C_you_should_use_my_bool_instead() append(ulonglong start, ulonglong val, ulonglong incr); - In_C_you_should_use_my_bool_instead() append(Discrete_interval *interval); - ulonglong minimum() const { return (head ? head->minimum() : 0); }; - ulonglong maximum() const { return (head ? tail->maximum() : 0); }; - uint nb_elements() const { return elements; } -}; -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, In_C_you_should_use_my_bool_instead() only_kill_query); -void sql_kill(THD *thd, ulong id, In_C_you_should_use_my_bool_instead() only_kill_query); -In_C_you_should_use_my_bool_instead() net_request_file(NET* net, const char* fname); -char* query_table_status(THD *thd,const char *db,const char *table_name); -extern CHARSET_INFO *system_charset_info, *files_charset_info ; -extern CHARSET_INFO *national_charset_info, *table_alias_charset; -enum Derivation -{ - DERIVATION_IGNORABLE= 5, - DERIVATION_COERCIBLE= 4, - DERIVATION_SYSCONST= 3, - DERIVATION_IMPLICIT= 2, - DERIVATION_NONE= 1, - DERIVATION_EXPLICIT= 0 -}; -typedef struct my_locale_st -{ - uint number; - const char *name; - const char *description; - const In_C_you_should_use_my_bool_instead() is_ascii; - TYPELIB *month_names; - TYPELIB *ab_month_names; - TYPELIB *day_names; - TYPELIB *ab_day_names; -} MY_LOCALE; -extern MY_LOCALE my_locale_en_US; -extern MY_LOCALE *my_locales[]; -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); -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() - { } -}; -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: - CHARSET_INFO *m_client_cs; - CHARSET_INFO *m_connection_cl; -}; -struct TABLE_LIST; -class String; -void view_store_options(THD *thd, TABLE_LIST *table, String *buff); -enum enum_parsing_place -{ - NO_MATTER, - IN_HAVING, - SELECT_LIST, - IN_WHERE, - IN_ON -}; -struct st_table; -class THD; -enum enum_check_fields -{ - CHECK_FIELD_IGNORE, - CHECK_FIELD_WARN, - CHECK_FIELD_ERROR_FOR_NULL -}; -typedef struct st_sql_list { - uint elements; - uchar *first; - uchar **next; - st_sql_list() {} - 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; - 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; -extern pthread_key_t THR_THD; -inline THD *_current_thd(void) -{ - return ((THD*) pthread_getspecific((THR_THD))); -} -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); -enum enum_table_ref_type -{ - TABLE_REF_NULL= 0, - TABLE_REF_VIEW, - TABLE_REF_BASE_TABLE, - TABLE_REF_I_S_TABLE, - TABLE_REF_TMP_TABLE -}; -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" -class String; -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, - const char *from, uint32 from_length, - CHARSET_INFO *from_cs, uint *errors); -uint32 well_formed_copy_nchars(CHARSET_INFO *to_cs, - char *to, uint to_length, - CHARSET_INFO *from_cs, - const char *from, uint from_length, - uint nchars, - const char **well_formed_error_pos, - const char **cannot_convert_error_pos, - const char **from_end_pos); -size_t my_copy_with_hex_escaping(CHARSET_INFO *cs, - char *dst, size_t dstlen, - const char *src, size_t srclen); -class String -{ - char *Ptr; - uint32 str_length,Alloced_length; - In_C_you_should_use_my_bool_instead() alloced; - CHARSET_INFO *str_charset; -public: - String() - { - Ptr=0; str_length=Alloced_length=0; alloced=0; - str_charset= &my_charset_bin; - } - String(uint32 length_arg) - { - alloced=0; Alloced_length=0; (void) real_alloc(length_arg); - str_charset= &my_charset_bin; - } - String(const char *str, CHARSET_INFO *cs) - { - Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0; - str_charset=cs; - } - String(const char *str,uint32 len, CHARSET_INFO *cs) - { - Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0; - str_charset=cs; - } - String(char *str,uint32 len, CHARSET_INFO *cs) - { - Ptr=(char*) str; Alloced_length=str_length=len; alloced=0; - str_charset=cs; - } - String(const String &str) - { - Ptr=str.Ptr ; str_length=str.str_length ; - Alloced_length=str.Alloced_length; alloced=0; - str_charset=str.str_charset; - } - static void *operator new(size_t size, MEM_ROOT *mem_root) - { return (void*) alloc_root(mem_root, (uint) size); } - static void operator delete(void *ptr_arg,size_t size) - { ; } - static void operator delete(void *ptr_arg, MEM_ROOT *mem_root) - { } - ~String() { free(); } - inline void set_charset(CHARSET_INFO *charset_arg) - { str_charset= charset_arg; } - inline CHARSET_INFO *charset() const { return str_charset; } - inline uint32 length() const { return str_length;} - inline uint32 alloced_length() const { return Alloced_length;} - inline char& operator [] (uint32 i) const { return Ptr[i]; } - inline void length(uint32 len) { str_length=len ; } - inline In_C_you_should_use_my_bool_instead() is_empty() { return (str_length == 0); } - inline void mark_as_const() { Alloced_length= 0;} - inline const char *ptr() const { return Ptr; } - inline char *c_ptr() - { - if (!Ptr || Ptr[str_length]) - (void) realloc(str_length); - return Ptr; - } - inline char *c_ptr_quick() - { - if (Ptr && str_length < Alloced_length) - Ptr[str_length]=0; - return Ptr; - } - inline char *c_ptr_safe() - { - if (Ptr && str_length < Alloced_length) - Ptr[str_length]=0; - else - (void) realloc(str_length); - return Ptr; - } - void set(String &str,uint32 offset,uint32 arg_length) - { - assert(&str != this); - free(); - Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0; - if (str.Alloced_length) - Alloced_length=str.Alloced_length-offset; - else - Alloced_length=0; - str_charset=str.str_charset; - } - inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs) - { - free(); - Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0; - str_charset=cs; - } - inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs) - { - free(); - Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0; - str_charset=cs; - } - In_C_you_should_use_my_bool_instead() set_ascii(const char *str, uint32 arg_length); - inline void set_quick(char *str,uint32 arg_length, CHARSET_INFO *cs) - { - if (!alloced) - { - Ptr=(char*) str; str_length=Alloced_length=arg_length; - } - str_charset=cs; - } - In_C_you_should_use_my_bool_instead() set_int(longlong num, In_C_you_should_use_my_bool_instead() unsigned_flag, CHARSET_INFO *cs); - In_C_you_should_use_my_bool_instead() set(longlong num, CHARSET_INFO *cs) - { return set_int(num, false, cs); } - In_C_you_should_use_my_bool_instead() set(ulonglong num, CHARSET_INFO *cs) - { return set_int((longlong)num, true, cs); } - In_C_you_should_use_my_bool_instead() set_real(double num,uint decimals, CHARSET_INFO *cs); - inline void chop() - { - Ptr[str_length--]= '\0'; - } - inline void free() - { - if (alloced) - { - alloced=0; - Alloced_length=0; - ((void)(myf) (0),my_no_flags_free(Ptr)); - Ptr=0; - str_length=0; - } - } - inline In_C_you_should_use_my_bool_instead() alloc(uint32 arg_length) - { - if (arg_length < Alloced_length) - return 0; - return real_alloc(arg_length); - } - In_C_you_should_use_my_bool_instead() real_alloc(uint32 arg_length); - In_C_you_should_use_my_bool_instead() realloc(uint32 arg_length); - inline void shrink(uint32 arg_length) - { - if (arg_length < Alloced_length) - { - char *new_ptr; - if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,(myf) (0)))) - { - Alloced_length = 0; - real_alloc(arg_length); - } - else - { - Ptr=new_ptr; - Alloced_length=arg_length; - } - } - } - In_C_you_should_use_my_bool_instead() is_alloced() { return alloced; } - inline String& operator = (const String &s) - { - if (&s != this) - { - assert(!s.uses_buffer_owned_by(this)); - free(); - Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length; - alloced=0; - } - return *this; - } - In_C_you_should_use_my_bool_instead() copy(); - In_C_you_should_use_my_bool_instead() copy(const String &s); - In_C_you_should_use_my_bool_instead() copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); - static In_C_you_should_use_my_bool_instead() needs_conversion(uint32 arg_length, - CHARSET_INFO *cs_from, CHARSET_INFO *cs_to, - uint32 *offset); - In_C_you_should_use_my_bool_instead() copy_aligned(const char *s, uint32 arg_length, uint32 offset, - CHARSET_INFO *cs); - In_C_you_should_use_my_bool_instead() set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs); - In_C_you_should_use_my_bool_instead() copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, - CHARSET_INFO *csto, uint *errors); - In_C_you_should_use_my_bool_instead() append(const String &s); - In_C_you_should_use_my_bool_instead() append(const char *s); - In_C_you_should_use_my_bool_instead() append(const char *s,uint32 arg_length); - In_C_you_should_use_my_bool_instead() append(const char *s,uint32 arg_length, CHARSET_INFO *cs); - In_C_you_should_use_my_bool_instead() append(IO_CACHE* file, uint32 arg_length); - In_C_you_should_use_my_bool_instead() append_with_prefill(const char *s, uint32 arg_length, - uint32 full_length, char fill_char); - int strstr(const String &search,uint32 offset=0); - int strrstr(const String &search,uint32 offset=0); - In_C_you_should_use_my_bool_instead() replace(uint32 offset,uint32 arg_length,const char *to,uint32 length); - In_C_you_should_use_my_bool_instead() replace(uint32 offset,uint32 arg_length,const String &to); - inline In_C_you_should_use_my_bool_instead() append(char chr) - { - if (str_length < Alloced_length) - { - Ptr[str_length++]=chr; - } - else - { - if (realloc(str_length+1)) - return 1; - Ptr[str_length++]=chr; - } - return 0; - } - In_C_you_should_use_my_bool_instead() fill(uint32 max_length,char fill); - void strip_sp(); - friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); - friend int stringcmp(const String *a,const String *b); - friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); - uint32 numchars(); - int charpos(int i,uint32 offset=0); - int reserve(uint32 space_needed) - { - return realloc(str_length + space_needed); - } - int reserve(uint32 space_needed, uint32 grow_by); - void q_append(const char c) - { - Ptr[str_length++] = c; - } - void q_append(const uint32 n) - { - *((long *) (Ptr + str_length))= (long) (n); - str_length += 4; - } - void q_append(double d) - { - do { *((long *) (Ptr + str_length)) = ((doubleget_union *)&(d))->m[0]; *(((long *) (Ptr + str_length))+1) = ((doubleget_union *)&(d))->m[1]; } while (0); - str_length += 8; - } - void q_append(double *d) - { - do { *((long *) (Ptr + str_length)) = ((doubleget_union *)&(*d))->m[0]; *(((long *) (Ptr + str_length))+1) = ((doubleget_union *)&(*d))->m[1]; } while (0); - str_length += 8; - } - void q_append(const char *data, uint32 data_len) - { - memcpy(Ptr + str_length, data, data_len); - str_length += data_len; - } - void write_at_position(int position, uint32 value) - { - *((long *) (Ptr + position))= (long) (value); - } - void qs_append(const char *str, uint32 len); - void qs_append(double d); - void qs_append(double *d); - inline void qs_append(const char c) - { - Ptr[str_length]= c; - str_length++; - } - void qs_append(int i); - void qs_append(uint i); - inline char *prep_append(uint32 arg_length, uint32 step_alloc) - { - uint32 new_length= arg_length + str_length; - if (new_length > Alloced_length) - { - if (realloc(new_length + step_alloc)) - return 0; - } - uint32 old_length= str_length; - str_length+= arg_length; - return Ptr+ old_length; - } - inline In_C_you_should_use_my_bool_instead() append(const char *s, uint32 arg_length, uint32 step_alloc) - { - uint32 new_length= arg_length + str_length; - if (new_length > Alloced_length && realloc(new_length + step_alloc)) - return (1); - memcpy(Ptr+str_length, s, arg_length); - str_length+= arg_length; - return (0); - } - void print(String *print); - void swap(String &s); - inline In_C_you_should_use_my_bool_instead() uses_buffer_owned_by(const String *s) const - { - return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length); - } -}; -static inline In_C_you_should_use_my_bool_instead() check_if_only_end_space(CHARSET_INFO *cs, char *str, - char *end) -{ - return str+ cs->cset->scan(cs, str, end, 2) == end; -} -#include "sql_list.h" -class Sql_alloc -{ -public: - static void *operator new(size_t size) throw () - { - return sql_alloc(size); - } - static void *operator new[](size_t size) - { - return sql_alloc(size); - } - static void *operator new[](size_t size, MEM_ROOT *mem_root) throw () - { return alloc_root(mem_root, size); } - static void *operator new(size_t size, MEM_ROOT *mem_root) throw () - { return alloc_root(mem_root, size); } - static void operator delete(void *ptr, size_t size) { ; } - static void operator delete(void *ptr, MEM_ROOT *mem_root) - { } - static void operator delete[](void *ptr, MEM_ROOT *mem_root) - { } - static void operator delete[](void *ptr, size_t size) { ; } - inline Sql_alloc() {} - inline ~Sql_alloc() {} -}; -struct list_node :public Sql_alloc -{ - list_node *next; - void *info; - list_node(void *info_par,list_node *next_par) - :next(next_par),info(info_par) - {} - list_node() - { - info= 0; - next= this; - } -}; -extern list_node end_of_list; -class base_list :public Sql_alloc -{ -protected: - list_node *first,**last; -public: - uint elements; - inline void empty() { elements=0; first= &end_of_list; last=&first;} - inline base_list() { empty(); } - inline base_list(const base_list &tmp) :Sql_alloc() - { - elements= tmp.elements; - first= tmp.first; - last= elements ? tmp.last : &first; - } - base_list(const base_list &rhs, MEM_ROOT *mem_root); - inline base_list(In_C_you_should_use_my_bool_instead() error) { } - inline In_C_you_should_use_my_bool_instead() push_back(void *info) - { - if (((*last)=new list_node(info, &end_of_list))) - { - last= &(*last)->next; - elements++; - return 0; - } - return 1; - } - inline In_C_you_should_use_my_bool_instead() push_back(void *info, MEM_ROOT *mem_root) - { - if (((*last)=new (mem_root) list_node(info, &end_of_list))) - { - last= &(*last)->next; - elements++; - return 0; - } - return 1; - } - inline In_C_you_should_use_my_bool_instead() push_front(void *info) - { - list_node *node=new list_node(info,first); - if (node) - { - if (last == &first) - last= &node->next; - first=node; - elements++; - return 0; - } - return 1; - } - void remove(list_node **prev) - { - list_node *node=(*prev)->next; - if (!--elements) - last= &first; - else if (last == &(*prev)->next) - last= prev; - delete *prev; - *prev=node; - } - inline void concat(base_list *list) - { - if (!list->is_empty()) - { - *last= list->first; - last= list->last; - elements+= list->elements; - } - } - inline void *pop(void) - { - if (first == &end_of_list) return 0; - list_node *tmp=first; - first=first->next; - if (!--elements) - last= &first; - return tmp->info; - } - inline void disjoin(base_list *list) - { - list_node **prev= &first; - list_node *node= first; - list_node *list_first= list->first; - elements=0; - while (node && node != list_first) - { - prev= &node->next; - node= node->next; - elements++; - } - *prev= *last; - last= prev; - } - inline void prepand(base_list *list) - { - if (!list->is_empty()) - { - *list->last= first; - first= list->first; - elements+= list->elements; - } - } - inline void swap(base_list &rhs) - { - { list_node * dummy; dummy= first; first= rhs.first; rhs.first= dummy; }; - { list_node ** dummy; dummy= last; last= rhs.last; rhs.last= dummy; }; - { uint dummy; dummy= elements; elements= rhs.elements; rhs.elements= dummy; }; - } - inline list_node* last_node() { return *last; } - inline list_node* first_node() { return first;} - inline void *head() { return first->info; } - inline void **head_ref() { return first != &end_of_list ? &first->info : 0; } - inline In_C_you_should_use_my_bool_instead() is_empty() { return first == &end_of_list ; } - inline list_node *last_ref() { return &end_of_list; } - friend class base_list_iterator; - friend class error_list; - friend class error_list_iterator; -protected: - void after(void *info,list_node *node) - { - list_node *new_node=new list_node(info,node->next); - node->next=new_node; - elements++; - if (last == &(node->next)) - last= &new_node->next; - } -}; -class base_list_iterator -{ -protected: - base_list *list; - list_node **el,**prev,*current; - void sublist(base_list &ls, uint elm) - { - ls.first= *el; - ls.last= list->last; - ls.elements= elm; - } -public: - base_list_iterator() - :list(0), el(0), prev(0), current(0) - {} - base_list_iterator(base_list &list_par) - { init(list_par); } - inline void init(base_list &list_par) - { - list= &list_par; - el= &list_par.first; - prev= 0; - current= 0; - } - inline void *next(void) - { - prev=el; - current= *el; - el= ¤t->next; - return current->info; - } - inline void *next_fast(void) - { - list_node *tmp; - tmp= *el; - el= &tmp->next; - return tmp->info; - } - inline void rewind(void) - { - el= &list->first; - } - inline void *replace(void *element) - { - void *tmp=current->info; - assert(current->info != 0); - current->info=element; - return tmp; - } - void *replace(base_list &new_list) - { - void *ret_value=current->info; - if (!new_list.is_empty()) - { - *new_list.last=current->next; - current->info=new_list.first->info; - current->next=new_list.first->next; - if ((list->last == ¤t->next) && (new_list.elements > 1)) - list->last= new_list.last; - list->elements+=new_list.elements-1; - } - return ret_value; - } - inline void remove(void) - { - list->remove(prev); - el=prev; - current=0; - } - void after(void *element) - { - list->after(element,current); - current=current->next; - el= ¤t->next; - } - inline void **ref(void) - { - return ¤t->info; - } - inline In_C_you_should_use_my_bool_instead() is_last(void) - { - return el == &list->last_ref()->next; - } - friend class error_list_iterator; -}; -template <class T> class List :public base_list -{ -public: - inline List() :base_list() {} - inline List(const List<T> &tmp) :base_list(tmp) {} - inline List(const List<T> &tmp, MEM_ROOT *mem_root) : - base_list(tmp, mem_root) {} - inline In_C_you_should_use_my_bool_instead() push_back(T *a) { return base_list::push_back(a); } - inline In_C_you_should_use_my_bool_instead() push_back(T *a, MEM_ROOT *mem_root) - { return base_list::push_back(a, mem_root); } - inline In_C_you_should_use_my_bool_instead() push_front(T *a) { return base_list::push_front(a); } - inline T* head() {return (T*) base_list::head(); } - inline T** head_ref() {return (T**) base_list::head_ref(); } - inline T* pop() {return (T*) base_list::pop(); } - inline void concat(List<T> *list) { base_list::concat(list); } - inline void disjoin(List<T> *list) { base_list::disjoin(list); } - inline void prepand(List<T> *list) { base_list::prepand(list); } - void delete_elements(void) - { - list_node *element,*next; - for (element=first; element != &end_of_list; element=next) - { - next=element->next; - delete (T*) element->info; - } - empty(); - } -}; -template <class T> class List_iterator :public base_list_iterator -{ -public: - List_iterator(List<T> &a) : base_list_iterator(a) {} - List_iterator() : base_list_iterator() {} - inline void init(List<T> &a) { base_list_iterator::init(a); } - inline T* operator++(int) { return (T*) base_list_iterator::next(); } - inline T *replace(T *a) { return (T*) base_list_iterator::replace(a); } - inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); } - inline void rewind(void) { base_list_iterator::rewind(); } - inline void remove() { base_list_iterator::remove(); } - inline void after(T *a) { base_list_iterator::after(a); } - inline T** ref(void) { return (T**) base_list_iterator::ref(); } -}; -template <class T> class List_iterator_fast :public base_list_iterator -{ -protected: - inline T *replace(T *a) { return (T*) 0; } - inline T *replace(List<T> &a) { return (T*) 0; } - inline void remove(void) { } - inline void after(T *a) { } - inline T** ref(void) { return (T**) 0; } -public: - inline List_iterator_fast(List<T> &a) : base_list_iterator(a) {} - inline List_iterator_fast() : base_list_iterator() {} - inline void init(List<T> &a) { base_list_iterator::init(a); } - inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); } - inline void rewind(void) { base_list_iterator::rewind(); } - void sublist(List<T> &list_arg, uint el_arg) - { - base_list_iterator::sublist(list_arg, el_arg); - } -}; -struct ilink -{ - struct ilink **prev,*next; - static void *operator new(size_t size) - { - return (void*)my_malloc((uint)size, (myf) (16 | 8)); - } - static void operator delete(void* ptr_arg, size_t size) - { - ((void)(myf) (16|64),my_no_flags_free((uchar*)ptr_arg)); - } - inline ilink() - { - prev=0; next=0; - } - inline void unlink() - { - if (prev) *prev= next; - if (next) next->prev=prev; - prev=0 ; next=0; - } - virtual ~ilink() { unlink(); } -}; -class i_string: public ilink -{ -public: - const char* ptr; - i_string():ptr(0) { } - i_string(const char* s) : ptr(s) {} -}; -class i_string_pair: public ilink -{ -public: - const char* key; - const char* val; - i_string_pair():key(0),val(0) { } - i_string_pair(const char* key_arg, const char* val_arg) : - key(key_arg),val(val_arg) {} -}; -template <class T> class I_List_iterator; -class base_ilist -{ -public: - struct ilink *first,last; - inline void empty() { first= &last; last.prev= &first; } - base_ilist() { empty(); } - inline In_C_you_should_use_my_bool_instead() is_empty() { return first == &last; } - inline void append(ilink *a) - { - first->prev= &a->next; - a->next=first; a->prev= &first; first=a; - } - inline void push_back(ilink *a) - { - *last.prev= a; - a->next= &last; - a->prev= last.prev; - last.prev= &a->next; - } - inline struct ilink *get() - { - struct ilink *first_link=first; - if (first_link == &last) - return 0; - first_link->unlink(); - return first_link; - } - inline struct ilink *head() - { - return (first != &last) ? first : 0; - } - friend class base_list_iterator; -}; -class base_ilist_iterator -{ - base_ilist *list; - struct ilink **el,*current; -public: - base_ilist_iterator(base_ilist &list_par) :list(&list_par), - el(&list_par.first),current(0) {} - void *next(void) - { - current= *el; - if (current == &list->last) return 0; - el= ¤t->next; - return current; - } -}; -template <class T> -class I_List :private base_ilist -{ -public: - I_List() :base_ilist() {} - inline void empty() { base_ilist::empty(); } - inline In_C_you_should_use_my_bool_instead() is_empty() { return base_ilist::is_empty(); } - inline void append(T* a) { base_ilist::append(a); } - inline void push_back(T* a) { base_ilist::push_back(a); } - inline T* get() { return (T*) base_ilist::get(); } - inline T* head() { return (T*) base_ilist::head(); } - friend class I_List_iterator<T>; -}; -template <class T> class I_List_iterator :public base_ilist_iterator -{ -public: - I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {} - inline T* operator++(int) { return (T*) base_ilist_iterator::next(); } -}; -template <typename T> -inline -void -list_copy_and_replace_each_value(List<T> &list, MEM_ROOT *mem_root) -{ - List_iterator<T> it(list); - T *el; - while ((el= it++)) - it.replace(el->clone(mem_root)); -} -#include "sql_map.h" -class mapped_files; -mapped_files *map_file(const char * name,uchar *magic,uint magic_length); -void unmap_file(mapped_files *map); -class mapped_files :public ilink { - uchar *map; - ha_rows size; - char *name; - File file; - int error; - uint use_count; -public: - mapped_files(const char * name,uchar *magic,uint magic_length); - ~mapped_files(); - friend class mapped_file; - friend mapped_files *map_file(const char * name,uchar *magic, - uint magic_length); - friend void unmap_file(mapped_files *map); -}; -class mapped_file -{ - mapped_files *file; -public: - mapped_file(const char * name,uchar *magic,uint magic_length) - { - file=map_file(name,magic,magic_length); - } - ~mapped_file() - { - unmap_file(file); - } - uchar *map() - { - return file->map; - } -}; -#include "my_decimal.h" -#include <decimal.h> -typedef enum -{TRUNCATE=0, HALF_EVEN, HALF_UP, CEILING, FLOOR} - decimal_round_mode; -typedef int32 decimal_digit_t; -typedef struct st_decimal_t { - int intg, frac, len; - my_bool sign; - decimal_digit_t *buf; -} decimal_t; -int internal_str2dec(const char *from, decimal_t *to, char **end, - my_bool fixed); -int decimal2string(decimal_t *from, char *to, int *to_len, - int fixed_precision, int fixed_decimals, - char filler); -int decimal2ulonglong(decimal_t *from, ulonglong *to); -int ulonglong2decimal(ulonglong from, decimal_t *to); -int decimal2longlong(decimal_t *from, longlong *to); -int longlong2decimal(longlong from, decimal_t *to); -int decimal2double(decimal_t *from, double *to); -int double2decimal(double from, decimal_t *to); -int decimal_actual_fraction(decimal_t *from); -int decimal2bin(decimal_t *from, uchar *to, int precision, int scale); -int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale); -int decimal_size(int precision, int scale); -int decimal_bin_size(int precision, int scale); -int decimal_result_size(decimal_t *from1, decimal_t *from2, char op, - int param); -int decimal_intg(decimal_t *from); -int decimal_add(decimal_t *from1, decimal_t *from2, decimal_t *to); -int decimal_sub(decimal_t *from1, decimal_t *from2, decimal_t *to); -int decimal_cmp(decimal_t *from1, decimal_t *from2); -int decimal_mul(decimal_t *from1, decimal_t *from2, decimal_t *to); -int decimal_div(decimal_t *from1, decimal_t *from2, decimal_t *to, - int scale_incr); -int decimal_mod(decimal_t *from1, decimal_t *from2, decimal_t *to); -int decimal_round(decimal_t *from, decimal_t *to, int new_scale, - decimal_round_mode mode); -int decimal_is_zero(decimal_t *from); -void max_decimal(int precision, int frac, decimal_t *to); -inline uint my_decimal_size(uint precision, uint scale) -{ - return decimal_size(precision, scale) + 1; -} -inline int my_decimal_int_part(uint precision, uint decimals) -{ - return precision - ((decimals == 31) ? 0 : decimals); -} -class my_decimal :public decimal_t -{ - decimal_digit_t buffer[9]; -public: - void init() - { - len= 9; - buf= buffer; - for (uint i= 0; i < 9; i++) - buffer[i]= i; - } - my_decimal() - { - init(); - } - void fix_buffer_pointer() { buf= buffer; } - In_C_you_should_use_my_bool_instead() sign() const { return decimal_t::sign; } - void sign(In_C_you_should_use_my_bool_instead() s) { decimal_t::sign= s; } - uint precision() const { return intg + frac; } - void swap(my_decimal &rhs) - { - { my_decimal dummy; dummy= *this; *this= rhs; rhs= dummy; }; - { decimal_digit_t * dummy; dummy= buf; buf= rhs.buf; rhs.buf= dummy; }; - } -}; -void print_decimal(const my_decimal *dec); -void print_decimal_buff(const my_decimal *dec, const uchar* ptr, int length); -const char *dbug_decimal_as_string(char *buff, const my_decimal *val); -int decimal_operation_results(int result); -inline -void max_my_decimal(my_decimal *to, int precision, int frac) -{ - assert((precision <= ((9 * 9) - 8*2))&& (frac <= 30)); - max_decimal(precision, frac, (decimal_t*) to); -} -inline void max_internal_decimal(my_decimal *to) -{ - max_my_decimal(to, ((9 * 9) - 8*2), 0); -} -inline int check_result(uint mask, int result) -{ - if (result & mask) - decimal_operation_results(result); - return result; -} -inline int check_result_and_overflow(uint mask, int result, my_decimal *val) -{ - if (check_result(mask, result) & 2) - { - In_C_you_should_use_my_bool_instead() sign= val->sign(); - val->fix_buffer_pointer(); - max_internal_decimal(val); - val->sign(sign); - } - return result; -} -inline uint my_decimal_length_to_precision(uint length, uint scale, - In_C_you_should_use_my_bool_instead() unsigned_flag) -{ - assert(length || !scale); - return (uint) (length - (scale>0 ? 1:0) - - (unsigned_flag || !length ? 0:1)); -} -inline uint32 my_decimal_precision_to_length(uint precision, uint8 scale, - In_C_you_should_use_my_bool_instead() unsigned_flag) -{ - assert(precision || !scale); - do { if ((precision) > (((9 * 9) - 8*2))) (precision)=(((9 * 9) - 8*2)); } while(0); - return (uint32)(precision + (scale>0 ? 1:0) + - (unsigned_flag || !precision ? 0:1)); -} -inline -int my_decimal_string_length(const my_decimal *d) -{ - return (((d)->intg ? (d)->intg : 1) + (d)->frac + ((d)->frac > 0) + 2); -} -inline -int my_decimal_max_length(const my_decimal *d) -{ - return (((d)->intg ? (d)->intg : 1) + (d)->frac + ((d)->frac > 0) + 2) - 1; -} -inline -int my_decimal_get_binary_size(uint precision, uint scale) -{ - return decimal_bin_size((int)precision, (int)scale); -} -inline -void my_decimal2decimal(const my_decimal *from, my_decimal *to) -{ - *to= *from; - to->fix_buffer_pointer(); -} -int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec, - int scale); -inline -int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d, int prec, - int scale) -{ - return check_result(mask, bin2decimal(bin, (decimal_t*) d, prec, scale)); -} -inline -int my_decimal_set_zero(my_decimal *d) -{ - do { (((decimal_t*) d))->buf[0]=0; (((decimal_t*) d))->intg=1; (((decimal_t*) d))->frac=0; (((decimal_t*) d))->sign=0; } while(0); - return 0; -} -inline -In_C_you_should_use_my_bool_instead() my_decimal_is_zero(const my_decimal *decimal_value) -{ - return decimal_is_zero((decimal_t*) decimal_value); -} -inline -int my_decimal_round(uint mask, const my_decimal *from, int scale, - In_C_you_should_use_my_bool_instead() truncate, my_decimal *to) -{ - return check_result(mask, decimal_round((decimal_t*) from, to, scale, - (truncate ? TRUNCATE : HALF_UP))); -} -inline -int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to) -{ - return check_result(mask, decimal_round((decimal_t*) from, to, 0, FLOOR)); -} -inline -int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to) -{ - return check_result(mask, decimal_round((decimal_t*) from, to, 0, CEILING)); -} -int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec, - uint fixed_dec, char filler, String *str); -inline -int my_decimal2int(uint mask, const my_decimal *d, my_bool unsigned_flag, - longlong *l) -{ - my_decimal rounded; - decimal_round((decimal_t*)d, &rounded, 0, HALF_UP); - return check_result(mask, (unsigned_flag ? - decimal2ulonglong(&rounded, (ulonglong *)l) : - decimal2longlong(&rounded, l))); -} -inline -int my_decimal2double(uint mask, const my_decimal *d, double *result) -{ - return decimal2double((decimal_t*) d, result); -} -inline -int str2my_decimal(uint mask, const char *str, my_decimal *d, char **end) -{ - return check_result_and_overflow(mask, internal_str2dec((str), ((decimal_t*)d), (end), 0), - d); -} -int str2my_decimal(uint mask, const char *from, uint length, - CHARSET_INFO *charset, my_decimal *decimal_value); -inline -int double2my_decimal(uint mask, double val, my_decimal *d) -{ - return check_result_and_overflow(mask, double2decimal(val, (decimal_t*)d), d); -} -inline -int int2my_decimal(uint mask, longlong i, my_bool unsigned_flag, my_decimal *d) -{ - return check_result(mask, (unsigned_flag ? - ulonglong2decimal((ulonglong)i, d) : - longlong2decimal(i, d))); -} -inline -void my_decimal_neg(decimal_t *arg) -{ - if (decimal_is_zero(arg)) - { - arg->sign= 0; - return; - } - do { (arg)->sign^=1; } while(0); -} -inline -int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a, - const my_decimal *b) -{ - return check_result_and_overflow(mask, - decimal_add((decimal_t*)a,(decimal_t*)b,res), - res); -} -inline -int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a, - const my_decimal *b) -{ - return check_result_and_overflow(mask, - decimal_sub((decimal_t*)a,(decimal_t*)b,res), - res); -} -inline -int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a, - const my_decimal *b) -{ - return check_result_and_overflow(mask, - decimal_mul((decimal_t*)a,(decimal_t*)b,res), - res); -} -inline -int my_decimal_div(uint mask, my_decimal *res, const my_decimal *a, - const my_decimal *b, int div_scale_inc) -{ - return check_result_and_overflow(mask, - decimal_div((decimal_t*)a,(decimal_t*)b,res, - div_scale_inc), - res); -} -inline -int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, - const my_decimal *b) -{ - return check_result_and_overflow(mask, - decimal_mod((decimal_t*)a,(decimal_t*)b,res), - res); -} -inline -int my_decimal_cmp(const my_decimal *a, const my_decimal *b) -{ - return decimal_cmp((decimal_t*) a, (decimal_t*) b); -} -inline -int my_decimal_intg(const my_decimal *a) -{ - return decimal_intg((decimal_t*) a); -} -void my_decimal_trim(ulong *precision, uint *scale); -#include "handler.h" -#include <my_handler.h> -#include "myisampack.h" -typedef struct st_HA_KEYSEG -{ - CHARSET_INFO *charset; - uint32 start; - uint32 null_pos; - uint16 bit_pos; - uint16 flag; - uint16 length; - uint8 type; - uint8 language; - uint8 null_bit; - uint8 bit_start,bit_end; - uint8 bit_length; -} HA_KEYSEG; -extern int ha_compare_text(CHARSET_INFO *, uchar *, uint, uchar *, uint , - my_bool, my_bool); -extern int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, - register uchar *b, uint key_length, uint nextflag, - uint *diff_pos); -extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, uchar *a); -extern void my_handler_error_register(void); -extern void my_handler_error_unregister(void); -#include <ft_global.h> -typedef struct st_ft_info FT_INFO; -struct _ft_vft -{ - int (*read_next)(FT_INFO *, char *); - float (*find_relevance)(FT_INFO *, uchar *, uint); - void (*close_search)(FT_INFO *); - float (*get_relevance)(FT_INFO *); - void (*reinit_search)(FT_INFO *); -}; -struct st_ft_info -{ - struct _ft_vft *please; -}; -extern const char *ft_stopword_file; -extern const char *ft_precompiled_stopwords[]; -extern ulong ft_min_word_len; -extern ulong ft_max_word_len; -extern ulong ft_query_expansion_limit; -extern char ft_boolean_syntax[15]; -extern struct st_mysql_ftparser ft_default_parser; -int ft_init_stopwords(void); -void ft_free_stopwords(void); -FT_INFO *ft_init_search(uint,void *, uint, uchar *, uint,CHARSET_INFO *, uchar *); -my_bool ft_boolean_check_syntax_string(const uchar *); -#include <keycache.h> -struct st_block_link; -typedef struct st_block_link BLOCK_LINK; -struct st_keycache_page; -typedef struct st_keycache_page KEYCACHE_PAGE; -struct st_hash_link; -typedef struct st_hash_link HASH_LINK; -typedef struct st_keycache_wqueue -{ - struct st_my_thread_var *last_thread; -} KEYCACHE_WQUEUE; -typedef struct st_key_cache -{ - my_bool key_cache_inited; - my_bool in_resize; - my_bool resize_in_flush; - my_bool can_be_used; - size_t key_cache_mem_size; - uint key_cache_block_size; - ulong min_warm_blocks; - ulong age_threshold; - ulonglong keycache_time; - uint hash_entries; - int hash_links; - int hash_links_used; - int disk_blocks; - ulong blocks_used; - ulong blocks_unused; - ulong blocks_changed; - ulong warm_blocks; - ulong cnt_for_resize_op; - long blocks_available; - HASH_LINK **hash_root; - HASH_LINK *hash_link_root; - HASH_LINK *free_hash_list; - BLOCK_LINK *free_block_list; - BLOCK_LINK *block_root; - uchar *block_mem; - BLOCK_LINK *used_last; - BLOCK_LINK *used_ins; - pthread_mutex_t cache_lock; - KEYCACHE_WQUEUE resize_queue; - KEYCACHE_WQUEUE waiting_for_resize_cnt; - KEYCACHE_WQUEUE waiting_for_hash_link; - KEYCACHE_WQUEUE waiting_for_block; - BLOCK_LINK *changed_blocks[128]; - BLOCK_LINK *file_blocks[128]; - ulonglong param_buff_size; - ulong param_block_size; - ulong param_division_limit; - ulong param_age_threshold; - ulong global_blocks_changed; - ulonglong global_cache_w_requests; - ulonglong global_cache_write; - ulonglong global_cache_r_requests; - ulonglong global_cache_read; - int blocks; - my_bool in_init; -} KEY_CACHE; -extern KEY_CACHE dflt_key_cache_var, *dflt_key_cache; -extern int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, - size_t use_mem, uint division_limit, - uint age_threshold); -extern int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, - size_t use_mem, uint division_limit, - uint age_threshold); -extern void change_key_cache_param(KEY_CACHE *keycache, uint division_limit, - uint age_threshold); -extern uchar *key_cache_read(KEY_CACHE *keycache, - File file, my_off_t filepos, int level, - uchar *buff, uint length, - uint block_length,int return_buffer); -extern int key_cache_insert(KEY_CACHE *keycache, - File file, my_off_t filepos, int level, - uchar *buff, uint length); -extern int key_cache_write(KEY_CACHE *keycache, - File file, my_off_t filepos, int level, - uchar *buff, uint length, - uint block_length,int force_write); -extern int flush_key_blocks(KEY_CACHE *keycache, - int file, enum flush_type type); -extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup); -extern my_bool multi_keycache_init(void); -extern void multi_keycache_free(void); -extern KEY_CACHE *multi_key_cache_search(uchar *key, uint length); -extern my_bool multi_key_cache_set(const uchar *key, uint length, - KEY_CACHE *key_cache); -extern void multi_key_cache_change(KEY_CACHE *old_data, - KEY_CACHE *new_data); -extern int reset_key_cache_counters(const char *name, - KEY_CACHE *key_cache); -enum legacy_db_type -{ - DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1, - DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM, - DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM, - DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM, - DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB, - DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER, - DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB, - DB_TYPE_FEDERATED_DB, - DB_TYPE_BLACKHOLE_DB, - DB_TYPE_PARTITION_DB, - DB_TYPE_BINLOG, - DB_TYPE_SOLID, - DB_TYPE_PBXT, - DB_TYPE_TABLE_FUNCTION, - DB_TYPE_MEMCACHE, - DB_TYPE_FALCON, - DB_TYPE_MARIA, - DB_TYPE_FIRST_DYNAMIC=42, - DB_TYPE_DEFAULT=127 -}; -enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED, - ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED, - ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE }; -enum enum_binlog_func { - BFN_RESET_LOGS= 1, - BFN_RESET_SLAVE= 2, - BFN_BINLOG_WAIT= 3, - BFN_BINLOG_END= 4, - BFN_BINLOG_PURGE_FILE= 5 -}; -enum enum_binlog_command { - LOGCOM_CREATE_TABLE, - LOGCOM_ALTER_TABLE, - LOGCOM_RENAME_TABLE, - LOGCOM_DROP_TABLE, - LOGCOM_CREATE_DB, - LOGCOM_ALTER_DB, - LOGCOM_DROP_DB -}; -typedef ulonglong my_xid; -struct xid_t { - long formatID; - long gtrid_length; - long bqual_length; - char data[128]; - xid_t() {} - In_C_you_should_use_my_bool_instead() eq(struct xid_t *xid) - { return eq(xid->gtrid_length, xid->bqual_length, xid->data); } - In_C_you_should_use_my_bool_instead() eq(long g, long b, const char *d) - { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); } - void set(struct xid_t *xid) - { memcpy(this, xid, xid->length()); } - void set(long f, const char *g, long gl, const char *b, long bl) - { - formatID= f; - memcpy(data, g, gtrid_length= gl); - memcpy(data+gl, b, bqual_length= bl); - } - void set(ulonglong xid) - { - my_xid tmp; - formatID= 1; - set(8, 0, "MySQLXid"); - memcpy(data+8, &server_id, sizeof(server_id)); - tmp= xid; - memcpy(data+(8 +sizeof(server_id)), &tmp, sizeof(tmp)); - gtrid_length=((8 +sizeof(server_id))+sizeof(my_xid)); - } - void set(long g, long b, const char *d) - { - formatID= 1; - gtrid_length= g; - bqual_length= b; - memcpy(data, d, g+b); - } - In_C_you_should_use_my_bool_instead() is_null() { return formatID == -1; } - void null() { formatID= -1; } - my_xid quick_get_my_xid() - { - my_xid tmp; - memcpy(&tmp, data+(8 +sizeof(server_id)), sizeof(tmp)); - return tmp; - } - my_xid get_my_xid() - { - return gtrid_length == ((8 +sizeof(server_id))+sizeof(my_xid)) && bqual_length == 0 && - !memcmp(data+8, &server_id, sizeof(server_id)) && - !memcmp(data, "MySQLXid", 8) ? - quick_get_my_xid() : 0; - } - uint length() - { - return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+ - gtrid_length+bqual_length; - } - uchar *key() - { - return (uchar *)>rid_length; - } - uint key_length() - { - return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length; - } -}; -typedef struct xid_t XID; -enum ts_command_type -{ - TS_CMD_NOT_DEFINED = -1, - CREATE_TABLESPACE = 0, - ALTER_TABLESPACE = 1, - CREATE_LOGFILE_GROUP = 2, - ALTER_LOGFILE_GROUP = 3, - DROP_TABLESPACE = 4, - DROP_LOGFILE_GROUP = 5, - CHANGE_FILE_TABLESPACE = 6, - ALTER_ACCESS_MODE_TABLESPACE = 7 -}; -enum ts_alter_tablespace_type -{ - TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1, - ALTER_TABLESPACE_ADD_FILE = 1, - ALTER_TABLESPACE_DROP_FILE = 2 -}; -enum tablespace_access_mode -{ - TS_NOT_DEFINED= -1, - TS_READ_ONLY = 0, - TS_READ_WRITE = 1, - TS_NOT_ACCESSIBLE = 2 -}; -struct handlerton; -class st_alter_tablespace : public Sql_alloc -{ - public: - const char *tablespace_name; - const char *logfile_group_name; - enum ts_command_type ts_cmd_type; - enum ts_alter_tablespace_type ts_alter_tablespace_type; - const char *data_file_name; - const char *undo_file_name; - const char *redo_file_name; - ulonglong extent_size; - ulonglong undo_buffer_size; - ulonglong redo_buffer_size; - ulonglong initial_size; - ulonglong autoextend_size; - ulonglong max_size; - uint nodegroup_id; - handlerton *storage_engine; - In_C_you_should_use_my_bool_instead() wait_until_completed; - const char *ts_comment; - enum tablespace_access_mode ts_access_mode; - st_alter_tablespace() - { - tablespace_name= NULL; - logfile_group_name= "DEFAULT_LG"; - ts_cmd_type= TS_CMD_NOT_DEFINED; - data_file_name= NULL; - undo_file_name= NULL; - redo_file_name= NULL; - extent_size= 1024*1024; - undo_buffer_size= 8*1024*1024; - redo_buffer_size= 8*1024*1024; - initial_size= 128*1024*1024; - autoextend_size= 0; - max_size= 0; - storage_engine= NULL; - nodegroup_id= 65535; - wait_until_completed= (1); - ts_comment= NULL; - ts_access_mode= TS_NOT_DEFINED; - } -}; -struct st_table; -typedef struct st_table TABLE; -typedef struct st_table_share TABLE_SHARE; -struct st_foreign_key_info; -typedef struct st_foreign_key_info FOREIGN_KEY_INFO; -typedef In_C_you_should_use_my_bool_instead() (stat_print_fn)(THD *thd, const char *type, uint type_len, - const char *file, uint file_len, - const char *status, uint status_len); -enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX }; -extern st_plugin_int *hton2plugin[15]; -enum log_status -{ - HA_LOG_STATUS_FREE= 0, - HA_LOG_STATUS_INUSE= 1, - HA_LOG_STATUS_NOSUCHLOG= 2 -}; -void signal_log_not_needed(struct handlerton, char *log_file); -struct handler_log_file_data { - LEX_STRING filename; - enum log_status status; -}; -enum handler_iterator_type -{ - HA_TRANSACTLOG_ITERATOR= 1 -}; -enum handler_create_iterator_result -{ - HA_ITERATOR_OK, - HA_ITERATOR_UNSUPPORTED, - HA_ITERATOR_ERROR -}; -struct handler_iterator { - int (*next)(struct handler_iterator *, void *iterator_object); - void (*destroy)(struct handler_iterator *); - void *buffer; -}; -struct handlerton -{ - SHOW_COMP_OPTION state; - enum legacy_db_type db_type; - uint slot; - uint savepoint_offset; - int (*close_connection)(handlerton *hton, THD *thd); - int (*savepoint_set)(handlerton *hton, THD *thd, void *sv); - int (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv); - int (*savepoint_release)(handlerton *hton, THD *thd, void *sv); - int (*commit)(handlerton *hton, THD *thd, In_C_you_should_use_my_bool_instead() all); - int (*rollback)(handlerton *hton, THD *thd, In_C_you_should_use_my_bool_instead() all); - int (*prepare)(handlerton *hton, THD *thd, In_C_you_should_use_my_bool_instead() all); - int (*recover)(handlerton *hton, XID *xid_list, uint len); - int (*commit_by_xid)(handlerton *hton, XID *xid); - int (*rollback_by_xid)(handlerton *hton, XID *xid); - void *(*create_cursor_read_view)(handlerton *hton, THD *thd); - void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view); - void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view); - handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root); - void (*drop_database)(handlerton *hton, char* path); - int (*panic)(handlerton *hton, enum ha_panic_function flag); - int (*start_consistent_snapshot)(handlerton *hton, THD *thd); - In_C_you_should_use_my_bool_instead() (*flush_logs)(handlerton *hton); - In_C_you_should_use_my_bool_instead() (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat); - uint (*partition_flags)(); - uint (*alter_table_flags)(uint flags); - int (*alter_tablespace)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info); - int (*fill_files_table)(handlerton *hton, THD *thd, - TABLE_LIST *tables, - class Item *cond); - uint32 flags; - int (*binlog_func)(handlerton *hton, THD *thd, enum_binlog_func fn, void *arg); - void (*binlog_log_query)(handlerton *hton, THD *thd, - enum_binlog_command binlog_command, - const char *query, uint query_length, - const char *db, const char *table_name); - int (*release_temporary_latches)(handlerton *hton, THD *thd); - enum log_status (*get_log_status)(handlerton *hton, char *log); - enum handler_create_iterator_result - (*create_iterator)(handlerton *hton, enum handler_iterator_type type, - struct handler_iterator *fill_this_in); - int (*discover)(handlerton *hton, THD* thd, const char *db, - const char *name, - uchar **frmblob, - size_t *frmlen); - int (*find_files)(handlerton *hton, THD *thd, - const char *db, - const char *path, - const char *wild, In_C_you_should_use_my_bool_instead() dir, List<LEX_STRING> *files); - int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db, - const char *name); - uint32 license; - void *data; -}; -class Ha_trx_info; -struct THD_TRANS -{ - In_C_you_should_use_my_bool_instead() no_2pc; - Ha_trx_info *ha_list; - In_C_you_should_use_my_bool_instead() modified_non_trans_table; - void reset() { no_2pc= (0); modified_non_trans_table= (0); } -}; -class Ha_trx_info -{ -public: - void register_ha(THD_TRANS *trans, handlerton *ht_arg) - { - assert(m_flags == 0); - assert(m_ht == NULL); - assert(m_next == NULL); - m_ht= ht_arg; - m_flags= (int) TRX_READ_ONLY; - m_next= trans->ha_list; - trans->ha_list= this; - } - void reset() - { - m_next= NULL; - m_ht= NULL; - m_flags= 0; - } - Ha_trx_info() { reset(); } - void set_trx_read_write() - { - assert(is_started()); - m_flags|= (int) TRX_READ_WRITE; - } - In_C_you_should_use_my_bool_instead() is_trx_read_write() const - { - assert(is_started()); - return m_flags & (int) TRX_READ_WRITE; - } - In_C_you_should_use_my_bool_instead() is_started() const { return m_ht != NULL; } - void coalesce_trx_with(const Ha_trx_info *stmt_trx) - { - assert(is_started()); - if (stmt_trx->is_trx_read_write()) - set_trx_read_write(); - } - Ha_trx_info *next() const - { - assert(is_started()); - return m_next; - } - handlerton *ht() const - { - assert(is_started()); - return m_ht; - } -private: - enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 }; - Ha_trx_info *m_next; - handlerton *m_ht; - uchar m_flags; -}; -enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED, - ISO_REPEATABLE_READ, ISO_SERIALIZABLE}; -enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 }; -typedef struct { - ulonglong data_file_length; - ulonglong max_data_file_length; - ulonglong index_file_length; - ulonglong delete_length; - ha_rows records; - ulong mean_rec_length; - time_t create_time; - time_t check_time; - time_t update_time; - ulonglong check_sum; -} PARTITION_INFO; -class Item; -struct st_table_log_memory_entry; -class partition_info; -struct st_partition_iter; -enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES }; -typedef struct st_ha_create_information -{ - CHARSET_INFO *table_charset, *default_table_charset; - LEX_STRING connect_string; - const char *password, *tablespace; - LEX_STRING comment; - const char *data_file_name, *index_file_name; - const char *alias; - ulonglong max_rows,min_rows; - ulonglong auto_increment_value; - ulong table_options; - ulong avg_row_length; - ulong used_fields; - ulong key_block_size; - SQL_LIST merge_list; - handlerton *db_type; - enum row_type row_type; - uint null_bits; - uint options; - uint merge_insert_method; - uint extra_size; - enum ha_choice transactional; - In_C_you_should_use_my_bool_instead() table_existed; - In_C_you_should_use_my_bool_instead() frm_only; - In_C_you_should_use_my_bool_instead() varchar; - enum ha_storage_media storage_media; - enum ha_choice page_checksum; -} HA_CREATE_INFO; -typedef struct st_key_create_information -{ - enum ha_key_alg algorithm; - ulong block_size; - LEX_STRING parser_name; -} KEY_CREATE_INFO; -class TABLEOP_HOOKS -{ -public: - TABLEOP_HOOKS() {} - virtual ~TABLEOP_HOOKS() {} - inline void prelock(TABLE **tables, uint count) - { - do_prelock(tables, count); - } - inline int postlock(TABLE **tables, uint count) - { - return do_postlock(tables, count); - } -private: - virtual void do_prelock(TABLE **tables, uint count) - { - } - virtual int do_postlock(TABLE **tables, uint count) - { - return 0; - } -}; -typedef struct st_savepoint SAVEPOINT; -extern ulong savepoint_alloc_size; -extern KEY_CREATE_INFO default_key_create_info; -typedef class Item COND; -typedef struct st_ha_check_opt -{ - st_ha_check_opt() {} - ulong sort_buffer_size; - uint flags; - uint sql_flags; - KEY_CACHE *key_cache; - void init(); -} HA_CHECK_OPT; -typedef struct st_handler_buffer -{ - const uchar *buffer; - const uchar *buffer_end; - uchar *end_of_used_area; -} HANDLER_BUFFER; -typedef struct system_status_var SSV; -class ha_statistics -{ -public: - ulonglong data_file_length; - ulonglong max_data_file_length; - ulonglong index_file_length; - ulonglong max_index_file_length; - ulonglong delete_length; - ulonglong auto_increment_value; - ha_rows records; - ha_rows deleted; - ulong mean_rec_length; - time_t create_time; - time_t check_time; - time_t update_time; - uint block_size; - ha_statistics(): - data_file_length(0), max_data_file_length(0), - index_file_length(0), delete_length(0), auto_increment_value(0), - records(0), deleted(0), mean_rec_length(0), create_time(0), - check_time(0), update_time(0), block_size(0) - {} -}; -uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map); -class handler :public Sql_alloc -{ -public: - typedef ulonglong Table_flags; -protected: - struct st_table_share *table_share; - struct st_table *table; - Table_flags cached_table_flags; - ha_rows estimation_rows_to_insert; -public: - handlerton *ht; - uchar *ref; - uchar *dup_ref; - ha_statistics stats; - In_C_you_should_use_my_bool_instead() multi_range_sorted; - KEY_MULTI_RANGE *multi_range_curr; - KEY_MULTI_RANGE *multi_range_end; - HANDLER_BUFFER *multi_range_buffer; - key_range save_end_range, *end_range; - KEY_PART_INFO *range_key_part; - int key_compare_result_on_equal; - In_C_you_should_use_my_bool_instead() eq_range; - uint errkey; - uint key_used_on_scan; - uint active_index; - uint ref_length; - FT_INFO *ft_handler; - enum {NONE=0, INDEX, RND} inited; - In_C_you_should_use_my_bool_instead() locked; - In_C_you_should_use_my_bool_instead() implicit_emptied; - const COND *pushed_cond; - ulonglong next_insert_id; - ulonglong insert_id_for_cur_row; - Discrete_interval auto_inc_interval_for_cur_row; - handler(handlerton *ht_arg, TABLE_SHARE *share_arg) - :table_share(share_arg), table(0), - estimation_rows_to_insert(0), ht(ht_arg), - ref(0), key_used_on_scan(64), active_index(64), - ref_length(sizeof(my_off_t)), - ft_handler(0), inited(NONE), - locked((0)), implicit_emptied(0), - pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0) - {} - virtual ~handler(void) - { - assert(locked == (0)); - } - virtual handler *clone(MEM_ROOT *mem_root); - void init() - { - cached_table_flags= table_flags(); - } - int ha_open(TABLE *table, const char *name, int mode, int test_if_locked); - int ha_index_init(uint idx, In_C_you_should_use_my_bool_instead() sorted) - { - int result; - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("ha_index_init","./sql/handler.h",1159,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - assert(inited==NONE); - if (!(result= index_init(idx, sorted))) - inited=INDEX; - do {_db_return_ (1163, &_db_func_, &_db_file_, &_db_level_); return(result);} while(0); - } - int ha_index_end() - { - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("ha_index_end","./sql/handler.h",1167,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - assert(inited==INDEX); - inited=NONE; - do {_db_return_ (1170, &_db_func_, &_db_file_, &_db_level_); return(index_end());} while(0); - } - int ha_rnd_init(In_C_you_should_use_my_bool_instead() scan) - { - int result; - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("ha_rnd_init","./sql/handler.h",1175,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - assert(inited==NONE || (inited==RND && scan)); - inited= (result= rnd_init(scan)) ? NONE: RND; - do {_db_return_ (1178, &_db_func_, &_db_file_, &_db_level_); return(result);} while(0); - } - int ha_rnd_end() - { - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("ha_rnd_end","./sql/handler.h",1182,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - assert(inited==RND); - inited=NONE; - do {_db_return_ (1185, &_db_func_, &_db_file_, &_db_level_); return(rnd_end());} while(0); - } - int ha_reset(); - int ha_index_or_rnd_end() - { - return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0; - } - Table_flags ha_table_flags() const { return cached_table_flags; } - int ha_external_lock(THD *thd, int lock_type); - int ha_write_row(uchar * buf); - int ha_update_row(const uchar * old_data, uchar * new_data); - int ha_delete_row(const uchar * buf); - void ha_release_auto_increment(); - int ha_check_for_upgrade(HA_CHECK_OPT *check_opt); - int ha_check(THD *thd, HA_CHECK_OPT *check_opt); - int ha_repair(THD* thd, HA_CHECK_OPT* check_opt); - void ha_start_bulk_insert(ha_rows rows) - { - estimation_rows_to_insert= rows; - start_bulk_insert(rows); - } - int ha_end_bulk_insert() - { - estimation_rows_to_insert= 0; - return end_bulk_insert(); - } - int ha_bulk_update_row(const uchar *old_data, uchar *new_data, - uint *dup_key_found); - int ha_delete_all_rows(); - int ha_reset_auto_increment(ulonglong value); - int ha_backup(THD* thd, HA_CHECK_OPT* check_opt); - int ha_restore(THD* thd, HA_CHECK_OPT* check_opt); - int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt); - int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt); - In_C_you_should_use_my_bool_instead() ha_check_and_repair(THD *thd); - int ha_disable_indexes(uint mode); - int ha_enable_indexes(uint mode); - int ha_discard_or_import_tablespace(my_bool discard); - void ha_prepare_for_alter(); - int ha_rename_table(const char *from, const char *to); - int ha_delete_table(const char *name); - void ha_drop_table(const char *name); - int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info); - int ha_create_handler_files(const char *name, const char *old_name, - int action_flag, HA_CREATE_INFO *info); - int ha_change_partitions(HA_CREATE_INFO *create_info, - const char *path, - ulonglong *copied, - ulonglong *deleted, - const uchar *pack_frm_data, - size_t pack_frm_len); - int ha_drop_partitions(const char *path); - int ha_rename_partitions(const char *path); - int ha_optimize_partitions(THD *thd); - int ha_analyze_partitions(THD *thd); - int ha_check_partitions(THD *thd); - int ha_repair_partitions(THD *thd); - void adjust_next_insert_id_after_explicit_value(ulonglong nr); - int update_auto_increment(); - void print_keydup_error(uint key_nr, const char *msg); - virtual void print_error(int error, myf errflag); - virtual In_C_you_should_use_my_bool_instead() get_error_message(int error, String *buf); - uint get_dup_key(int error); - virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share) - { - table= table_arg; - table_share= share; - } - virtual double scan_time() - { return ((double) (ulonglong) (stats.data_file_length)) / 4096 + 2; } - virtual double read_time(uint index, uint ranges, ha_rows rows) - { return ((double) (ulonglong) (ranges+rows)); } - virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; } - In_C_you_should_use_my_bool_instead() has_transactions() - { return (ha_table_flags() & (1 << 0)) == 0; } - virtual uint extra_rec_buf_length() const { return 0; } - virtual In_C_you_should_use_my_bool_instead() is_fatal_error(int error, uint flags) - { - if (!error || - ((flags & 1) && - (error == 121 || - error == 141))) - return (0); - return (1); - } - virtual ha_rows records() { return stats.records; } - virtual ha_rows estimate_rows_upper_bound() - { return stats.records+10; } - virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; } - virtual const char *index_type(uint key_number) { assert(0); return "";} - virtual void column_bitmaps_signal(); - uint get_index(void) const { return active_index; } - virtual int close(void)=0; - virtual In_C_you_should_use_my_bool_instead() start_bulk_update() { return 1; } - virtual In_C_you_should_use_my_bool_instead() start_bulk_delete() { return 1; } - virtual int exec_bulk_update(uint *dup_key_found) - { - assert((0)); - return 131; - } - virtual void end_bulk_update() { return; } - virtual int end_bulk_delete() - { - assert((0)); - return 131; - } - virtual int index_read_map(uchar * buf, const uchar * key, - key_part_map keypart_map, - enum ha_rkey_function find_flag) - { - uint key_len= calculate_key_len(table, active_index, key, keypart_map); - return index_read(buf, key, key_len, find_flag); - } - virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key, - key_part_map keypart_map, - enum ha_rkey_function find_flag); - virtual int index_next(uchar * buf) - { return 131; } - virtual int index_prev(uchar * buf) - { return 131; } - virtual int index_first(uchar * buf) - { return 131; } - virtual int index_last(uchar * buf) - { return 131; } - virtual int index_next_same(uchar *buf, const uchar *key, uint keylen); - virtual int index_read_last_map(uchar * buf, const uchar * key, - key_part_map keypart_map) - { - uint key_len= calculate_key_len(table, active_index, key, keypart_map); - return index_read_last(buf, key, key_len); - } - virtual int read_multi_range_first(KEY_MULTI_RANGE **found_range_p, - KEY_MULTI_RANGE *ranges, uint range_count, - In_C_you_should_use_my_bool_instead() sorted, HANDLER_BUFFER *buffer); - virtual int read_multi_range_next(KEY_MULTI_RANGE **found_range_p); - virtual int read_range_first(const key_range *start_key, - const key_range *end_key, - In_C_you_should_use_my_bool_instead() eq_range, In_C_you_should_use_my_bool_instead() sorted); - virtual int read_range_next(); - int compare_key(key_range *range); - virtual int ft_init() { return 131; } - void ft_end() { ft_handler=NULL; } - virtual FT_INFO *ft_init_ext(uint flags, uint inx,String *key) - { return NULL; } - virtual int ft_read(uchar *buf) { return 131; } - virtual int rnd_next(uchar *buf)=0; - virtual int rnd_pos(uchar * buf, uchar *pos)=0; - virtual int rnd_pos_by_record(uchar *record) - { - position(record); - return rnd_pos(record, ref); - } - virtual int read_first_row(uchar *buf, uint primary_key); - virtual int restart_rnd_next(uchar *buf, uchar *pos) - { return 131; } - virtual int rnd_same(uchar *buf, uint inx) - { return 131; } - virtual ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key) - { return (ha_rows) 10; } - virtual void position(const uchar *record)=0; - virtual int info(uint)=0; - virtual void get_dynamic_partition_info(PARTITION_INFO *stat_info, - uint part_id); - virtual int extra(enum ha_extra_function operation) - { return 0; } - virtual int extra_opt(enum ha_extra_function operation, ulong cache_size) - { return extra(operation); } - virtual In_C_you_should_use_my_bool_instead() was_semi_consistent_read() { return 0; } - virtual void try_semi_consistent_read(In_C_you_should_use_my_bool_instead()) {} - virtual void unlock_row() {} - virtual int start_stmt(THD *thd, thr_lock_type lock_type) {return 0;} - virtual void get_auto_increment(ulonglong offset, ulonglong increment, - ulonglong nb_desired_values, - ulonglong *first_value, - ulonglong *nb_reserved_values); - void set_next_insert_id(ulonglong id) - { - do {_db_pargs_(1488,"info"); _db_doprnt_ ("auto_increment: next value %lu", (ulong)id);} while(0); - next_insert_id= id; - } - void restore_auto_increment(ulonglong prev_insert_id) - { - next_insert_id= (prev_insert_id > 0) ? prev_insert_id : - insert_id_for_cur_row; - } - virtual void update_create_info(HA_CREATE_INFO *create_info) {} - int check_old_types(); - virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual int dump(THD* thd, int fd = -1) { return 131; } - virtual int indexes_are_disabled(void) {return 0;} - virtual int net_read_dump(NET* net) { return 131; } - virtual char *update_table_comment(const char * comment) - { return (char*) comment;} - virtual void append_create_info(String *packet) {} - virtual In_C_you_should_use_my_bool_instead() is_fk_defined_on_table_or_index(uint index) - { return (0); } - virtual char* get_foreign_key_create_info() - { return(NULL);} - virtual char* get_tablespace_name(THD *thd, char *name, uint name_len) - { return(NULL);} - virtual In_C_you_should_use_my_bool_instead() can_switch_engines() { return 1; } - virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list) - { return 0; } - virtual uint referenced_by_foreign_key() { return 0;} - virtual void init_table_handle_for_HANDLER() - { return; } - virtual void free_foreign_key_create_info(char* str) {} - virtual const char *table_type() const =0; - virtual const char **bas_ext() const =0; - virtual int get_default_no_partitions(HA_CREATE_INFO *info) { return 1;} - virtual void set_auto_partitions(partition_info *part_info) { return; } - virtual In_C_you_should_use_my_bool_instead() get_no_parts(const char *name, - uint *no_parts) - { - *no_parts= 0; - return 0; - } - virtual void set_part_info(partition_info *part_info) {return;} - virtual ulong index_flags(uint idx, uint part, In_C_you_should_use_my_bool_instead() all_parts) const =0; - virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys) - { return (131); } - virtual int prepare_drop_index(TABLE *table_arg, uint *key_num, - uint num_of_keys) - { return (131); } - virtual int final_drop_index(TABLE *table_arg) - { return (131); } - uint max_record_length() const - { return ((65535) < (max_supported_record_length()) ? (65535) : (max_supported_record_length())); } - uint max_keys() const - { return ((64) < (max_supported_keys()) ? (64) : (max_supported_keys())); } - uint max_key_parts() const - { return ((16) < (max_supported_key_parts()) ? (16) : (max_supported_key_parts())); } - uint max_key_length() const - { return ((3072) < (max_supported_key_length()) ? (3072) : (max_supported_key_length())); } - uint max_key_part_length() const - { return ((3072) < (max_supported_key_part_length()) ? (3072) : (max_supported_key_part_length())); } - virtual uint max_supported_record_length() const { return 65535; } - virtual uint max_supported_keys() const { return 0; } - virtual uint max_supported_key_parts() const { return 16; } - virtual uint max_supported_key_length() const { return 3072; } - virtual uint max_supported_key_part_length() const { return 255; } - virtual uint min_record_length(uint options) const { return 1; } - virtual In_C_you_should_use_my_bool_instead() low_byte_first() const { return 1; } - virtual uint checksum() const { return 0; } - virtual In_C_you_should_use_my_bool_instead() is_crashed() const { return 0; } - virtual In_C_you_should_use_my_bool_instead() auto_repair() const { return 0; } - virtual uint lock_count(void) const { return 1; } - virtual THR_LOCK_DATA **store_lock(THD *thd, - THR_LOCK_DATA **to, - enum thr_lock_type lock_type)=0; - virtual uint8 table_cache_type() { return 0; } - virtual my_bool register_query_cache_table(THD *thd, char *table_key, - uint key_length, - qc_engine_callback - *engine_callback, - ulonglong *engine_data) - { - *engine_callback= 0; - return (1); - } - virtual In_C_you_should_use_my_bool_instead() primary_key_is_clustered() { return (0); } - virtual int cmp_ref(const uchar *ref1, const uchar *ref2) - { - return memcmp(ref1, ref2, ref_length); - } - virtual const COND *cond_push(const COND *cond) { return cond; }; - virtual void cond_pop() { return; }; - virtual In_C_you_should_use_my_bool_instead() check_if_incompatible_data(HA_CREATE_INFO *create_info, - uint table_changes) - { return 1; } - virtual void use_hidden_primary_key(); -protected: - void ha_statistic_increment(ulong SSV::*offset) const; - void **ha_data(THD *) const; - THD *ha_thd(void) const; - virtual int rename_table(const char *from, const char *to); - virtual int delete_table(const char *name); -private: - inline void mark_trx_read_write(); -private: - virtual int open(const char *name, int mode, uint test_if_locked)=0; - virtual int index_init(uint idx, In_C_you_should_use_my_bool_instead() sorted) { active_index= idx; return 0; } - virtual int index_end() { active_index= 64; return 0; } - virtual int rnd_init(In_C_you_should_use_my_bool_instead() scan)= 0; - virtual int rnd_end() { return 0; } - virtual int write_row(uchar *buf __attribute__((unused))) - { - return 131; - } - virtual int update_row(const uchar *old_data __attribute__((unused)), - uchar *new_data __attribute__((unused))) - { - return 131; - } - virtual int delete_row(const uchar *buf __attribute__((unused))) - { - return 131; - } - virtual int reset() { return 0; } - virtual Table_flags table_flags(void) const= 0; - virtual int external_lock(THD *thd __attribute__((unused)), - int lock_type __attribute__((unused))) - { - return 0; - } - virtual void release_auto_increment() { return; }; - virtual int check_for_upgrade(HA_CHECK_OPT *check_opt) - { return 0; } - virtual int check(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual int repair(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual void start_bulk_insert(ha_rows rows) {} - virtual int end_bulk_insert() { return 0; } - virtual int index_read(uchar * buf, const uchar * key, uint key_len, - enum ha_rkey_function find_flag) - { return 131; } - virtual int index_read_last(uchar * buf, const uchar * key, uint key_len) - { return ((_my_thread_var())->thr_errno= 131); } - virtual int bulk_update_row(const uchar *old_data, uchar *new_data, - uint *dup_key_found) - { - assert((0)); - return 131; - } - virtual int delete_all_rows() - { return ((_my_thread_var())->thr_errno=131); } - virtual int reset_auto_increment(ulonglong value) - { return 131; } - virtual int backup(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual int restore(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt) - { return -1; } - virtual In_C_you_should_use_my_bool_instead() check_and_repair(THD *thd) { return (1); } - virtual int disable_indexes(uint mode) { return 131; } - virtual int enable_indexes(uint mode) { return 131; } - virtual int discard_or_import_tablespace(my_bool discard) - { return ((_my_thread_var())->thr_errno=131); } - virtual void prepare_for_alter() { return; } - virtual void drop_table(const char *name); - virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0; - virtual int create_handler_files(const char *name, const char *old_name, - int action_flag, HA_CREATE_INFO *info) - { return (0); } - virtual int change_partitions(HA_CREATE_INFO *create_info, - const char *path, - ulonglong *copied, - ulonglong *deleted, - const uchar *pack_frm_data, - size_t pack_frm_len) - { return 131; } - virtual int drop_partitions(const char *path) - { return 131; } - virtual int rename_partitions(const char *path) - { return 131; } - virtual int optimize_partitions(THD *thd) - { return 131; } - virtual int analyze_partitions(THD *thd) - { return 131; } - virtual int check_partitions(THD *thd) - { return 131; } - virtual int repair_partitions(THD *thd) - { return 131; } -}; -extern const char *ha_row_type[]; -extern const char *tx_isolation_names[]; -extern const char *binlog_format_names[]; -extern TYPELIB tx_isolation_typelib; -extern TYPELIB myisam_stats_method_typelib; -extern ulong total_ha, total_ha_2pc; -handlerton *ha_default_handlerton(THD *thd); -plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name); -plugin_ref ha_lock_engine(THD *thd, handlerton *hton); -handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type); -handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc, - handlerton *db_type); -handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type, - In_C_you_should_use_my_bool_instead() no_substitute, In_C_you_should_use_my_bool_instead() report_error); -static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type) -{ - return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type; -} -static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type) -{ - return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str; -} -static inline In_C_you_should_use_my_bool_instead() ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag) -{ - return db_type == NULL ? (0) : ((db_type->flags & flag) ? 1 : 0); -} -static inline In_C_you_should_use_my_bool_instead() ha_storage_engine_is_enabled(const handlerton *db_type) -{ - return (db_type && db_type->create) ? - (db_type->state == SHOW_OPTION_YES) : (0); -} -int ha_init_errors(void); -int ha_init(void); -int ha_end(void); -int ha_initialize_handlerton(st_plugin_int *plugin); -int ha_finalize_handlerton(st_plugin_int *plugin); -TYPELIB *ha_known_exts(void); -int ha_panic(enum ha_panic_function flag); -void ha_close_connection(THD* thd); -In_C_you_should_use_my_bool_instead() ha_flush_logs(handlerton *db_type); -void ha_drop_database(char* path); -int ha_create_table(THD *thd, const char *path, - const char *db, const char *table_name, - HA_CREATE_INFO *create_info, - In_C_you_should_use_my_bool_instead() update_create_info); -int ha_delete_table(THD *thd, handlerton *db_type, const char *path, - const char *db, const char *alias, In_C_you_should_use_my_bool_instead() generate_warning); -In_C_you_should_use_my_bool_instead() ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat); -int ha_create_table_from_engine(THD* thd, const char *db, const char *name); -int ha_discover(THD* thd, const char* dbname, const char* name, - uchar** frmblob, size_t* frmlen); -int ha_find_files(THD *thd,const char *db,const char *path, - const char *wild, In_C_you_should_use_my_bool_instead() dir, List<LEX_STRING>* files); -int ha_table_exists_in_engine(THD* thd, const char* db, const char* name); -extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache); -int ha_resize_key_cache(KEY_CACHE *key_cache); -int ha_change_key_cache_param(KEY_CACHE *key_cache); -int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache); -int ha_end_key_cache(KEY_CACHE *key_cache); -int ha_release_temporary_latches(THD *thd); -int ha_start_consistent_snapshot(THD *thd); -int ha_commit_or_rollback_by_xid(XID *xid, In_C_you_should_use_my_bool_instead() commit); -int ha_commit_one_phase(THD *thd, In_C_you_should_use_my_bool_instead() all); -int ha_rollback_trans(THD *thd, In_C_you_should_use_my_bool_instead() all); -int ha_prepare(THD *thd); -int ha_recover(HASH *commit_list); -int ha_commit_trans(THD *thd, In_C_you_should_use_my_bool_instead() all); -int ha_autocommit_or_rollback(THD *thd, int error); -int ha_enable_transaction(THD *thd, In_C_you_should_use_my_bool_instead() on); -int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv); -int ha_savepoint(THD *thd, SAVEPOINT *sv); -int ha_release_savepoint(THD *thd, SAVEPOINT *sv); -void trans_register_ha(THD *thd, In_C_you_should_use_my_bool_instead() all, handlerton *ht); -#include "parse_file.h" -enum file_opt_type { - FILE_OPTIONS_STRING, - FILE_OPTIONS_ESTRING, - FILE_OPTIONS_ULONGLONG, - FILE_OPTIONS_REV, - FILE_OPTIONS_TIMESTAMP, - FILE_OPTIONS_STRLIST, - FILE_OPTIONS_ULLLIST -}; -struct File_option -{ - LEX_STRING name; - int offset; - file_opt_type type; -}; -class Unknown_key_hook -{ -public: - Unknown_key_hook() {} - virtual ~Unknown_key_hook() {} - virtual In_C_you_should_use_my_bool_instead() process_unknown_string(char *&unknown_key, uchar* base, - MEM_ROOT *mem_root, char *end)= 0; -}; -class File_parser_dummy_hook: public Unknown_key_hook -{ -public: - File_parser_dummy_hook() {} - virtual In_C_you_should_use_my_bool_instead() process_unknown_string(char *&unknown_key, uchar* base, - MEM_ROOT *mem_root, char *end); -}; -extern File_parser_dummy_hook file_parser_dummy_hook; -In_C_you_should_use_my_bool_instead() get_file_options_ulllist(char *&ptr, char *end, char *line, - uchar* base, File_option *parameter, - MEM_ROOT *mem_root); -char * -parse_escaped_string(char *ptr, char *end, MEM_ROOT *mem_root, LEX_STRING *str); -class File_parser; -File_parser *sql_parse_prepare(const LEX_STRING *file_name, - MEM_ROOT *mem_root, In_C_you_should_use_my_bool_instead() bad_format_errors); -my_bool -sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, - const LEX_STRING *type, - uchar* base, File_option *parameters, uint versions); -my_bool rename_in_schema_file(const char *schema, const char *old_name, - const char *new_name, ulonglong revision, - uint num_view_backups); -class File_parser: public Sql_alloc -{ - char *buff, *start, *end; - LEX_STRING file_type; - my_bool content_ok; -public: - File_parser() :buff(0), start(0), end(0), content_ok(0) - { file_type.str= 0; file_type.length= 0; } - my_bool ok() { return content_ok; } - LEX_STRING *type() { return &file_type; } - my_bool parse(uchar* base, MEM_ROOT *mem_root, - struct File_option *parameters, uint required, - Unknown_key_hook *hook); - friend File_parser *sql_parse_prepare(const LEX_STRING *file_name, - MEM_ROOT *mem_root, - In_C_you_should_use_my_bool_instead() bad_format_errors); -}; -#include "table.h" -class Item; -class Item_subselect; -class GRANT_TABLE; -class st_select_lex_unit; -class st_select_lex; -class partition_info; -class COND_EQUAL; -class Security_context; -class View_creation_ctx : public Default_object_creation_ctx, - public Sql_alloc -{ -public: - static View_creation_ctx *create(THD *thd); - static View_creation_ctx *create(THD *thd, - TABLE_LIST *view); -private: - View_creation_ctx(THD *thd) - : Default_object_creation_ctx(thd) - { } -}; -typedef struct st_order { - struct st_order *next; - Item **item; - Item *item_ptr; - Item **item_copy; - int counter; - In_C_you_should_use_my_bool_instead() asc; - In_C_you_should_use_my_bool_instead() free_me; - In_C_you_should_use_my_bool_instead() in_field_list; - In_C_you_should_use_my_bool_instead() counter_used; - Field *field; - char *buff; - table_map used, depend_map; -} ORDER; -typedef struct st_grant_info -{ - GRANT_TABLE *grant_table; - uint version; - ulong privilege; - ulong want_privilege; - ulong orig_want_privilege; -} GRANT_INFO; -enum tmp_table_type -{ - NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE, - INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE -}; -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, - FRMTYPE_TABLE, - FRMTYPE_VIEW -}; -enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP }; -typedef struct st_filesort_info -{ - IO_CACHE *io_cache; - uchar **sort_keys; - uchar *buffpek; - uint buffpek_len; - uchar *addon_buf; - size_t addon_length; - struct st_sort_addon_field *addon_field; - void (*unpack)(struct st_sort_addon_field *, uchar *); - uchar *record_pointers; - ha_rows found_records; -} FILESORT_INFO; -enum timestamp_auto_set_type -{ - TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1, - TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3 -}; -class Field_timestamp; -class Field_blob; -class Table_triggers_list; -enum enum_table_category -{ - TABLE_UNKNOWN_CATEGORY=0, - TABLE_CATEGORY_TEMPORARY=1, - TABLE_CATEGORY_USER=2, - TABLE_CATEGORY_SYSTEM=3, - TABLE_CATEGORY_INFORMATION=4, - TABLE_CATEGORY_PERFORMANCE=5 -}; -typedef enum enum_table_category TABLE_CATEGORY; -TABLE_CATEGORY get_table_category(const LEX_STRING *db, - const LEX_STRING *name); -typedef struct st_table_share -{ - st_table_share() {} - TABLE_CATEGORY table_category; - HASH name_hash; - MEM_ROOT mem_root; - TYPELIB keynames; - TYPELIB fieldnames; - TYPELIB *intervals; - pthread_mutex_t mutex; - pthread_cond_t cond; - struct st_table_share *next, - **prev; - Field **field; - Field **found_next_number_field; - Field *timestamp_field; - KEY *key_info; - uint *blob_field; - uchar *default_values; - LEX_STRING comment; - CHARSET_INFO *table_charset; - MY_BITMAP all_set; - LEX_STRING table_cache_key; - LEX_STRING db; - LEX_STRING table_name; - LEX_STRING path; - LEX_STRING normalized_path; - LEX_STRING connect_string; - key_map keys_in_use; - key_map keys_for_keyread; - ha_rows min_rows, max_rows; - ulong avg_row_length; - ulong raid_chunksize; - ulong version, mysql_version; - ulong timestamp_offset; - ulong reclength; - plugin_ref db_plugin; - inline handlerton *db_type() const - { - return db_plugin ? ((handlerton*)((db_plugin)[0]->data)) : NULL; - } - enum row_type row_type; - enum tmp_table_type tmp_table; - enum ha_choice transactional; - enum ha_choice page_checksum; - uint ref_count; - uint open_count; - uint blob_ptr_size; - uint key_block_size; - uint null_bytes, last_null_bit_pos; - uint fields; - uint rec_buff_length; - uint keys, key_parts; - uint max_key_length, max_unique_length, total_key_length; - uint uniques; - uint null_fields; - uint blob_fields; - uint timestamp_field_offset; - uint varchar_fields; - uint db_create_options; - uint db_options_in_use; - uint db_record_offset; - uint raid_type, raid_chunks; - uint rowid_field_offset; - uint primary_key; - uint next_number_index; - uint next_number_key_offset; - uint next_number_keypart; - uint error, open_errno, errarg; - uint column_bitmap_size; - uchar frm_version; - In_C_you_should_use_my_bool_instead() null_field_first; - In_C_you_should_use_my_bool_instead() system; - In_C_you_should_use_my_bool_instead() crypted; - In_C_you_should_use_my_bool_instead() db_low_byte_first; - In_C_you_should_use_my_bool_instead() crashed; - In_C_you_should_use_my_bool_instead() is_view; - In_C_you_should_use_my_bool_instead() name_lock, replace_with_name_lock; - In_C_you_should_use_my_bool_instead() waiting_on_cond; - ulong table_map_id; - ulonglong table_map_version; - int cached_row_logging_check; - void set_table_cache_key(char *key_buff, uint key_length) - { - table_cache_key.str= key_buff; - table_cache_key.length= key_length; - db.str= table_cache_key.str; - db.length= strlen(db.str); - table_name.str= db.str + db.length + 1; - table_name.length= strlen(table_name.str); - } - void set_table_cache_key(char *key_buff, const char *key, uint key_length) - { - memcpy(key_buff, key, key_length); - set_table_cache_key(key_buff, key_length); - } - inline In_C_you_should_use_my_bool_instead() honor_global_locks() - { - return ((table_category == TABLE_CATEGORY_USER) - || (table_category == TABLE_CATEGORY_SYSTEM)); - } - inline In_C_you_should_use_my_bool_instead() require_write_privileges() - { - return (table_category == TABLE_CATEGORY_PERFORMANCE); - } - inline ulong get_table_def_version() - { - return table_map_id; - } - enum enum_table_ref_type get_table_ref_type() const - { - if (is_view) - return TABLE_REF_VIEW; - switch (tmp_table) { - case NO_TMP_TABLE: - return TABLE_REF_BASE_TABLE; - case SYSTEM_TMP_TABLE: - return TABLE_REF_I_S_TABLE; - default: - return TABLE_REF_TMP_TABLE; - } - } - ulong get_table_ref_version() const - { - return (tmp_table == SYSTEM_TMP_TABLE || is_view) ? 0 : table_map_id; - } -} TABLE_SHARE; -extern ulong refresh_version; -enum index_hint_type -{ - INDEX_HINT_IGNORE, - INDEX_HINT_USE, - INDEX_HINT_FORCE -}; -struct st_table { - st_table() {} - TABLE_SHARE *s; - handler *file; - struct st_table *next, *prev; - struct st_table *parent; - TABLE_LIST *child_l; - TABLE_LIST **child_last_l; - THD *in_use; - Field **field; - uchar *record[2]; - uchar *write_row_record; - uchar *insert_values; - key_map covering_keys; - key_map quick_keys, merge_keys; - key_map keys_in_use_for_query; - key_map keys_in_use_for_group_by; - key_map keys_in_use_for_order_by; - KEY *key_info; - Field *next_number_field; - Field *found_next_number_field; - Field_timestamp *timestamp_field; - Table_triggers_list *triggers; - TABLE_LIST *pos_in_table_list; - ORDER *group; - const char *alias; - uchar *null_flags; - my_bitmap_map *bitmap_init_value; - MY_BITMAP def_read_set, def_write_set, tmp_set; - MY_BITMAP *read_set, *write_set; - query_id_t query_id; - ha_rows quick_rows[64]; - key_part_map const_key_parts[64]; - uint quick_key_parts[64]; - uint quick_n_ranges[64]; - ha_rows quick_condition_rows; - timestamp_auto_set_type timestamp_field_type; - table_map map; - uint lock_position; - uint lock_data_start; - uint lock_count; - uint tablenr,used_fields; - uint temp_pool_slot; - uint status; - uint db_stat; - uint derived_select_number; - int current_lock; - my_bool copy_blobs; - uint maybe_null; - my_bool null_row; - my_bool force_index; - my_bool distinct,const_table,no_rows; - my_bool key_read, no_keyread; - my_bool open_placeholder; - my_bool locked_by_logger; - my_bool no_replicate; - my_bool locked_by_name; - my_bool fulltext_searched; - my_bool no_cache; - my_bool open_by_handler; - my_bool auto_increment_field_not_null; - my_bool insert_or_update; - my_bool alias_name_used; - my_bool get_fields_in_item_tree; - my_bool children_attached; - REGINFO reginfo; - MEM_ROOT mem_root; - GRANT_INFO grant; - FILESORT_INFO sort; - In_C_you_should_use_my_bool_instead() fill_item_list(List<Item> *item_list) const; - void reset_item_list(List<Item> *item_list) const; - void clear_column_bitmaps(void); - void prepare_for_position(void); - void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map); - void mark_columns_used_by_index(uint index); - void restore_column_maps_after_mark_index(); - void mark_auto_increment_column(void); - void mark_columns_needed_for_update(void); - void mark_columns_needed_for_delete(void); - void mark_columns_needed_for_insert(void); - inline void column_bitmaps_set(MY_BITMAP *read_set_arg, - MY_BITMAP *write_set_arg) - { - read_set= read_set_arg; - write_set= write_set_arg; - if (file) - file->column_bitmaps_signal(); - } - inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg, - MY_BITMAP *write_set_arg) - { - read_set= read_set_arg; - write_set= write_set_arg; - } - inline void use_all_columns() - { - column_bitmaps_set(&s->all_set, &s->all_set); - } - inline void default_column_bitmaps() - { - read_set= &def_read_set; - write_set= &def_write_set; - } - inline In_C_you_should_use_my_bool_instead() is_name_opened() { return db_stat || open_placeholder; } - inline In_C_you_should_use_my_bool_instead() needs_reopen_or_name_lock() - { return s->version != refresh_version; } - In_C_you_should_use_my_bool_instead() is_children_attached(void); -}; -enum enum_schema_table_state -{ - NOT_PROCESSED= 0, - PROCESSED_BY_CREATE_SORT_INDEX, - PROCESSED_BY_JOIN_EXEC -}; -typedef struct st_foreign_key_info -{ - LEX_STRING *forein_id; - LEX_STRING *referenced_db; - LEX_STRING *referenced_table; - LEX_STRING *update_method; - LEX_STRING *delete_method; - LEX_STRING *referenced_key_name; - List<LEX_STRING> foreign_fields; - List<LEX_STRING> referenced_fields; -} FOREIGN_KEY_INFO; -enum enum_schema_tables -{ - SCH_CHARSETS= 0, - SCH_COLLATIONS, - SCH_COLLATION_CHARACTER_SET_APPLICABILITY, - SCH_COLUMNS, - SCH_COLUMN_PRIVILEGES, - SCH_ENGINES, - SCH_EVENTS, - SCH_FILES, - SCH_GLOBAL_STATUS, - SCH_GLOBAL_VARIABLES, - SCH_KEY_COLUMN_USAGE, - SCH_OPEN_TABLES, - SCH_PARTITIONS, - SCH_PLUGINS, - SCH_PROCESSLIST, - SCH_PROFILES, - SCH_REFERENTIAL_CONSTRAINTS, - SCH_PROCEDURES, - SCH_SCHEMATA, - SCH_SCHEMA_PRIVILEGES, - SCH_SESSION_STATUS, - SCH_SESSION_VARIABLES, - SCH_STATISTICS, - SCH_STATUS, - SCH_TABLES, - SCH_TABLE_CONSTRAINTS, - SCH_TABLE_NAMES, - SCH_TABLE_PRIVILEGES, - SCH_TRIGGERS, - SCH_USER_PRIVILEGES, - SCH_VARIABLES, - SCH_VIEWS -}; -typedef struct st_field_info -{ - const char* field_name; - uint field_length; - enum enum_field_types field_type; - int value; - uint field_flags; - const char* old_name; - uint open_method; -} ST_FIELD_INFO; -struct TABLE_LIST; -typedef class Item COND; -typedef struct st_schema_table -{ - const char* table_name; - ST_FIELD_INFO *fields_info; - TABLE *(*create_table) (THD *thd, TABLE_LIST *table_list); - int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond); - int (*old_format) (THD *thd, struct st_schema_table *schema_table); - int (*process_table) (THD *thd, TABLE_LIST *tables, TABLE *table, - In_C_you_should_use_my_bool_instead() res, LEX_STRING *db_name, LEX_STRING *table_name); - int idx_field1, idx_field2; - In_C_you_should_use_my_bool_instead() hidden; - uint i_s_requested_object; -} ST_SCHEMA_TABLE; -struct st_lex; -class select_union; -class TMP_TABLE_PARAM; -Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, - const char *name); -struct Field_translator -{ - Item *item; - const char *name; -}; -class Natural_join_column: public Sql_alloc -{ -public: - Field_translator *view_field; - Field *table_field; - TABLE_LIST *table_ref; - In_C_you_should_use_my_bool_instead() is_common; -public: - Natural_join_column(Field_translator *field_param, TABLE_LIST *tab); - Natural_join_column(Field *field_param, TABLE_LIST *tab); - const char *name(); - Item *create_item(THD *thd); - Field *field(); - const char *table_name(); - const char *db_name(); - GRANT_INFO *grant(); -}; -class Index_hint; -struct TABLE_LIST -{ - TABLE_LIST() {} - inline void init_one_table(const char *db_name_arg, - const char *table_name_arg, - enum thr_lock_type lock_type_arg) - { - bzero((char*) this, sizeof(*this)); - db= (char*) db_name_arg; - table_name= alias= (char*) table_name_arg; - lock_type= lock_type_arg; - } - TABLE_LIST *next_local; - TABLE_LIST *next_global, **prev_global; - char *db, *alias, *table_name, *schema_table_name; - char *option; - Item *on_expr; - Item *prep_on_expr; - COND_EQUAL *cond_equal; - TABLE_LIST *natural_join; - In_C_you_should_use_my_bool_instead() is_natural_join; - List<String> *join_using_fields; - List<Natural_join_column> *join_columns; - In_C_you_should_use_my_bool_instead() is_join_columns_complete; - TABLE_LIST *next_name_resolution_table; - List<Index_hint> *index_hints; - TABLE *table; - uint table_id; - select_union *derived_result; - TABLE_LIST *correspondent_table; - st_select_lex_unit *derived; - ST_SCHEMA_TABLE *schema_table; - st_select_lex *schema_select_lex; - In_C_you_should_use_my_bool_instead() schema_table_reformed; - TMP_TABLE_PARAM *schema_table_param; - st_select_lex *select_lex; - st_lex *view; - Field_translator *field_translation; - Field_translator *field_translation_end; - TABLE_LIST *merge_underlying_list; - List<TABLE_LIST> *view_tables; - TABLE_LIST *belong_to_view; - TABLE_LIST *referencing_view; - TABLE_LIST *parent_l; - Security_context *security_ctx; - Security_context *view_sctx; - In_C_you_should_use_my_bool_instead() allowed_show; - TABLE_LIST *next_leaf; - Item *where; - Item *check_option; - LEX_STRING select_stmt; - LEX_STRING md5; - LEX_STRING source; - LEX_STRING view_db; - LEX_STRING view_name; - LEX_STRING timestamp; - st_lex_user definer; - ulonglong file_version; - ulonglong updatable_view; - ulonglong revision; - ulonglong algorithm; - ulonglong view_suid; - ulonglong with_check; - uint8 effective_with_check; - uint8 effective_algorithm; - GRANT_INFO grant; - ulonglong engine_data; - qc_engine_callback callback_func; - thr_lock_type lock_type; - uint outer_join; - uint shared; - size_t db_length; - size_t table_name_length; - In_C_you_should_use_my_bool_instead() updatable; - In_C_you_should_use_my_bool_instead() straight; - In_C_you_should_use_my_bool_instead() updating; - In_C_you_should_use_my_bool_instead() force_index; - In_C_you_should_use_my_bool_instead() ignore_leaves; - table_map dep_tables; - table_map on_expr_dep_tables; - struct st_nested_join *nested_join; - TABLE_LIST *embedding; - List<TABLE_LIST> *join_list; - In_C_you_should_use_my_bool_instead() cacheable_table; - In_C_you_should_use_my_bool_instead() table_in_first_from_clause; - In_C_you_should_use_my_bool_instead() skip_temporary; - In_C_you_should_use_my_bool_instead() contain_auto_increment; - In_C_you_should_use_my_bool_instead() multitable_view; - In_C_you_should_use_my_bool_instead() compact_view_format; - In_C_you_should_use_my_bool_instead() where_processed; - In_C_you_should_use_my_bool_instead() check_option_processed; - enum frm_type_enum required_type; - handlerton *db_type; - char timestamp_buffer[20]; - In_C_you_should_use_my_bool_instead() prelocking_placeholder; - In_C_you_should_use_my_bool_instead() create; - In_C_you_should_use_my_bool_instead() internal_tmp_table; - View_creation_ctx *view_creation_ctx; - LEX_STRING view_client_cs_name; - LEX_STRING view_connection_cl_name; - LEX_STRING view_body_utf8; - uint8 trg_event_map; - uint i_s_requested_object; - In_C_you_should_use_my_bool_instead() has_db_lookup_value; - In_C_you_should_use_my_bool_instead() has_table_lookup_value; - uint table_open_method; - enum enum_schema_table_state schema_table_state; - void calc_md5(char *buffer); - void set_underlying_merge(); - int view_check_option(THD *thd, In_C_you_should_use_my_bool_instead() ignore_failure); - In_C_you_should_use_my_bool_instead() setup_underlying(THD *thd); - void cleanup_items(); - In_C_you_should_use_my_bool_instead() placeholder() - { - return derived || view || schema_table || create && !table->db_stat || - !table; - } - void print(THD *thd, String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() check_single_table(TABLE_LIST **table, table_map map, - TABLE_LIST *view); - In_C_you_should_use_my_bool_instead() set_insert_values(MEM_ROOT *mem_root); - void hide_view_error(THD *thd); - TABLE_LIST *find_underlying_table(TABLE *table); - TABLE_LIST *first_leaf_for_name_resolution(); - TABLE_LIST *last_leaf_for_name_resolution(); - In_C_you_should_use_my_bool_instead() is_leaf_for_name_resolution(); - inline TABLE_LIST *top_table() - { return belong_to_view ? belong_to_view : this; } - inline In_C_you_should_use_my_bool_instead() prepare_check_option(THD *thd) - { - In_C_you_should_use_my_bool_instead() res= (0); - if (effective_with_check) - res= prep_check_option(thd, effective_with_check); - return res; - } - inline In_C_you_should_use_my_bool_instead() prepare_where(THD *thd, Item **conds, - In_C_you_should_use_my_bool_instead() no_where_clause) - { - if (effective_algorithm == 2) - return prep_where(thd, conds, no_where_clause); - return (0); - } - void register_want_access(ulong want_access); - In_C_you_should_use_my_bool_instead() prepare_security(THD *thd); - Security_context *find_view_security_context(THD *thd); - In_C_you_should_use_my_bool_instead() prepare_view_securety_context(THD *thd); - void reinit_before_use(THD *thd); - Item_subselect *containing_subselect(); - In_C_you_should_use_my_bool_instead() process_index_hints(TABLE *table); - inline ulong get_child_def_version() - { - return child_def_version; - } - inline void set_child_def_version(ulong version) - { - child_def_version= version; - } - inline void init_child_def_version() - { - child_def_version= ~0UL; - } - inline - In_C_you_should_use_my_bool_instead() is_table_ref_id_equal(TABLE_SHARE *s) const - { - return (m_table_ref_type == s->get_table_ref_type() && - m_table_ref_version == s->get_table_ref_version()); - } - inline - void set_table_ref_id(TABLE_SHARE *s) - { - m_table_ref_type= s->get_table_ref_type(); - m_table_ref_version= s->get_table_ref_version(); - } -private: - In_C_you_should_use_my_bool_instead() prep_check_option(THD *thd, uint8 check_opt_type); - In_C_you_should_use_my_bool_instead() prep_where(THD *thd, Item **conds, In_C_you_should_use_my_bool_instead() no_where_clause); - ulong child_def_version; - enum enum_table_ref_type m_table_ref_type; - ulong m_table_ref_version; -}; -class Item; -class Field_iterator: public Sql_alloc -{ -public: - Field_iterator() {} - virtual ~Field_iterator() {} - virtual void set(TABLE_LIST *)= 0; - virtual void next()= 0; - virtual In_C_you_should_use_my_bool_instead() end_of_fields()= 0; - virtual const char *name()= 0; - virtual Item *create_item(THD *)= 0; - virtual Field *field()= 0; -}; -class Field_iterator_table: public Field_iterator -{ - Field **ptr; -public: - Field_iterator_table() :ptr(0) {} - void set(TABLE_LIST *table) { ptr= table->table->field; } - void set_table(TABLE *table) { ptr= table->field; } - void next() { ptr++; } - In_C_you_should_use_my_bool_instead() end_of_fields() { return *ptr == 0; } - const char *name(); - Item *create_item(THD *thd); - Field *field() { return *ptr; } -}; -class Field_iterator_view: public Field_iterator -{ - Field_translator *ptr, *array_end; - TABLE_LIST *view; -public: - Field_iterator_view() :ptr(0), array_end(0) {} - void set(TABLE_LIST *table); - void next() { ptr++; } - In_C_you_should_use_my_bool_instead() end_of_fields() { return ptr == array_end; } - const char *name(); - Item *create_item(THD *thd); - Item **item_ptr() {return &ptr->item; } - Field *field() { return 0; } - inline Item *item() { return ptr->item; } - Field_translator *field_translator() { return ptr; } -}; -class Field_iterator_natural_join: public Field_iterator -{ - List_iterator_fast<Natural_join_column> column_ref_it; - Natural_join_column *cur_column_ref; -public: - Field_iterator_natural_join() :cur_column_ref(NULL) {} - ~Field_iterator_natural_join() {} - void set(TABLE_LIST *table); - void next(); - In_C_you_should_use_my_bool_instead() end_of_fields() { return !cur_column_ref; } - const char *name() { return cur_column_ref->name(); } - Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); } - Field *field() { return cur_column_ref->field(); } - Natural_join_column *column_ref() { return cur_column_ref; } -}; -class Field_iterator_table_ref: public Field_iterator -{ - TABLE_LIST *table_ref, *first_leaf, *last_leaf; - Field_iterator_table table_field_it; - Field_iterator_view view_field_it; - Field_iterator_natural_join natural_join_it; - Field_iterator *field_it; - void set_field_iterator(); -public: - Field_iterator_table_ref() :field_it(NULL) {} - void set(TABLE_LIST *table); - void next(); - In_C_you_should_use_my_bool_instead() end_of_fields() - { return (table_ref == last_leaf && field_it->end_of_fields()); } - const char *name() { return field_it->name(); } - const char *table_name(); - const char *db_name(); - GRANT_INFO *grant(); - Item *create_item(THD *thd) { return field_it->create_item(thd); } - Field *field() { return field_it->field(); } - Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref); - Natural_join_column *get_natural_column_ref(); -}; -typedef struct st_nested_join -{ - List<TABLE_LIST> join_list; - table_map used_tables; - table_map not_null_tables; - struct st_join_table *first_nested; - uint counter; - nested_join_map nj_map; -} NESTED_JOIN; -typedef struct st_changed_table_list -{ - struct st_changed_table_list *next; - char *key; - uint32 key_length; -} CHANGED_TABLE_LIST; -typedef struct st_open_table_list{ - struct st_open_table_list *next; - char *db,*table; - uint32 in_use,locked; -} OPEN_TABLE_LIST; -typedef struct st_table_field_w_type -{ - LEX_STRING name; - LEX_STRING type; - LEX_STRING cset; -} TABLE_FIELD_W_TYPE; -my_bool -table_check_intact(TABLE *table, const uint table_f_count, - const TABLE_FIELD_W_TYPE *table_def); -static inline my_bitmap_map *tmp_use_all_columns(TABLE *table, - MY_BITMAP *bitmap) -{ - my_bitmap_map *old= bitmap->bitmap; - bitmap->bitmap= table->s->all_set.bitmap; - return old; -} -static inline void tmp_restore_column_map(MY_BITMAP *bitmap, - my_bitmap_map *old) -{ - bitmap->bitmap= old; -} -static inline my_bitmap_map *dbug_tmp_use_all_columns(TABLE *table, - MY_BITMAP *bitmap) -{ - return tmp_use_all_columns(table, bitmap); -} -static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap, - my_bitmap_map *old) -{ - tmp_restore_column_map(bitmap, old); -} -size_t max_row_length(TABLE *table, const uchar *data); -#include "sql_error.h" -class MYSQL_ERROR: public Sql_alloc -{ -public: - enum enum_warning_level - { WARN_LEVEL_NOTE, WARN_LEVEL_WARN, WARN_LEVEL_ERROR, WARN_LEVEL_END}; - uint code; - enum_warning_level level; - char *msg; - MYSQL_ERROR(THD *thd, uint code_arg, enum_warning_level level_arg, - const char *msg_arg) - :code(code_arg), level(level_arg) - { - if (msg_arg) - set_msg(thd, msg_arg); - } - void set_msg(THD *thd, const char *msg_arg); -}; -MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, - uint code, const char *msg); -void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level, - uint code, const char *format, ...); -void mysql_reset_errors(THD *thd, In_C_you_should_use_my_bool_instead() force); -In_C_you_should_use_my_bool_instead() mysqld_show_warnings(THD *thd, ulong levels_to_show); -extern const LEX_STRING warning_level_names[]; -#include "field.h" -const uint32 max_field_size= (uint32) 4294967295U; -class Send_field; -class Protocol; -class Create_field; -struct st_cache_field; -int field_conv(Field *to,Field *from); -inline uint get_enum_pack_length(int elements) -{ - return elements < 256 ? 1 : 2; -} -inline uint get_set_pack_length(int elements) -{ - uint len= (elements + 7) / 8; - return len > 4 ? 8 : len; -} -class Field -{ - Field(const Item &); - void operator=(Field &); -public: - static void *operator new(size_t size) {return sql_alloc(size); } - static void operator delete(void *ptr_arg, size_t size) { ; } - uchar *ptr; - uchar *null_ptr; - struct st_table *table; - struct st_table *orig_table; - const char **table_name, *field_name; - LEX_STRING comment; - key_map key_start, part_of_key, part_of_key_not_clustered; - key_map part_of_sortkey; - enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL, - CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD, - BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD, - TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD}; - enum geometry_type - { - GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3, - GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6, - GEOM_GEOMETRYCOLLECTION = 7 - }; - enum imagetype { itRAW, itMBR}; - utype unireg_check; - uint32 field_length; - uint32 flags; - uint16 field_index; - uchar null_bit; - In_C_you_should_use_my_bool_instead() is_created_from_null_item; - Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg, - uchar null_bit_arg, utype unireg_check_arg, - const char *field_name_arg); - virtual ~Field() {} - virtual int store(const char *to, uint length,CHARSET_INFO *cs)=0; - virtual int store(double nr)=0; - virtual int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val)=0; - virtual int store_decimal(const my_decimal *d)=0; - virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type); - int store(const char *to, uint length, CHARSET_INFO *cs, - enum_check_fields check_level); - virtual double val_real(void)=0; - virtual longlong val_int(void)=0; - virtual my_decimal *val_decimal(my_decimal *); - inline String *val_str(String *str) { return val_str(str, str); } - virtual String *val_str(String*,String *)=0; - String *val_int_as_str(String *val_buffer, my_bool unsigned_flag); - virtual In_C_you_should_use_my_bool_instead() str_needs_quotes() { return (0); } - virtual Item_result result_type () const=0; - virtual Item_result cmp_type () const { return result_type(); } - virtual Item_result cast_to_int_type () const { return result_type(); } - static In_C_you_should_use_my_bool_instead() type_can_have_key_part(enum_field_types); - static enum_field_types field_type_merge(enum_field_types, enum_field_types); - static Item_result result_merge_type(enum_field_types); - virtual In_C_you_should_use_my_bool_instead() eq(Field *field) - { - return (ptr == field->ptr && null_ptr == field->null_ptr && - null_bit == field->null_bit); - } - virtual In_C_you_should_use_my_bool_instead() eq_def(Field *field); - virtual uint32 pack_length() const { return (uint32) field_length; } - virtual uint32 pack_length_in_rec() const { return pack_length(); } - virtual int compatible_field_size(uint field_metadata); - virtual uint pack_length_from_metadata(uint field_metadata) - { return field_metadata; } - virtual uint row_pack_length() { return 0; } - virtual int save_field_metadata(uchar *first_byte) - { return do_save_field_metadata(first_byte); } - virtual uint32 data_length() { return pack_length(); } - virtual uint32 sort_length() const { return pack_length(); } - virtual uint32 max_data_length() const { - return pack_length(); - }; - virtual int reset(void) { bzero(ptr,pack_length()); return 0; } - virtual void reset_fields() {} - virtual void set_default() - { - my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values - - table->record[0]); - memcpy(ptr, ptr + l_offset, pack_length()); - if (null_ptr) - *null_ptr= ((*null_ptr & (uchar) ~null_bit) | - null_ptr[l_offset] & null_bit); - } - virtual In_C_you_should_use_my_bool_instead() binary() const { return 1; } - virtual In_C_you_should_use_my_bool_instead() zero_pack() const { return 1; } - virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } - virtual uint32 key_length() const { return pack_length(); } - virtual enum_field_types type() const =0; - virtual enum_field_types real_type() const { return type(); } - inline int cmp(const uchar *str) { return cmp(ptr,str); } - virtual int cmp_max(const uchar *a, const uchar *b, uint max_len) - { return cmp(a, b); } - virtual int cmp(const uchar *,const uchar *)=0; - virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L) - { return memcmp(a,b,pack_length()); } - virtual int cmp_offset(uint row_offset) - { return cmp(ptr,ptr+row_offset); } - virtual int cmp_binary_offset(uint row_offset) - { return cmp_binary(ptr, ptr+row_offset); }; - virtual int key_cmp(const uchar *a,const uchar *b) - { return cmp(a, b); } - virtual int key_cmp(const uchar *str, uint length) - { return cmp(ptr,str); } - virtual uint decimals() const { return 0; } - virtual void sql_type(String &str) const =0; - virtual uint size_of() const =0; - inline In_C_you_should_use_my_bool_instead() is_null(my_ptrdiff_t row_offset= 0) - { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; } - inline In_C_you_should_use_my_bool_instead() is_real_null(my_ptrdiff_t row_offset= 0) - { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; } - inline In_C_you_should_use_my_bool_instead() is_null_in_record(const uchar *record) - { - if (!null_ptr) - return 0; - return ((record[(uint) (null_ptr -table->record[0])] & null_bit) ? 1 : 0); - } - inline In_C_you_should_use_my_bool_instead() is_null_in_record_with_offset(my_ptrdiff_t offset) - { - if (!null_ptr) - return 0; - return ((null_ptr[offset] & null_bit) ? 1 : 0); - } - inline void set_null(my_ptrdiff_t row_offset= 0) - { if (null_ptr) null_ptr[row_offset]|= null_bit; } - inline void set_notnull(my_ptrdiff_t row_offset= 0) - { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; } - inline In_C_you_should_use_my_bool_instead() maybe_null(void) { return null_ptr != 0 || table->maybe_null; } - inline In_C_you_should_use_my_bool_instead() real_maybe_null(void) { return null_ptr != 0; } - enum { - LAST_NULL_BYTE_UNDEF= 0 - }; - size_t last_null_byte() const { - size_t bytes= do_last_null_byte(); - do {_db_pargs_(284,"debug"); _db_doprnt_ ("last_null_byte() ==> %ld", (long) bytes);} while(0); - assert(bytes <= table->s->null_bytes); - return bytes; - } - virtual void make_field(Send_field *); - virtual void sort_string(uchar *buff,uint length)=0; - virtual In_C_you_should_use_my_bool_instead() optimize_range(uint idx, uint part); - virtual In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (0); } - virtual void free() {} - virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table, - In_C_you_should_use_my_bool_instead() keep_type); - virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, - uchar *new_ptr, uchar *new_null_ptr, - uint new_null_bit); - Field *clone(MEM_ROOT *mem_root, struct st_table *new_table); - inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg) - { - ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg; - } - inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; } - virtual void move_field_offset(my_ptrdiff_t ptr_diff) - { - ptr=(uchar*) ((uchar*) (ptr)+ptr_diff); - if (null_ptr) - null_ptr=(uchar*) ((uchar*) (null_ptr)+ptr_diff); - } - virtual void get_image(uchar *buff, uint length, CHARSET_INFO *cs) - { memcpy(buff,ptr,length); } - virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) - { memcpy(ptr,buff,length); } - virtual uint get_key_image(uchar *buff, uint length, imagetype type) - { - get_image(buff, length, &my_charset_bin); - return length; - } - virtual void set_key_image(const uchar *buff,uint length) - { set_image(buff,length, &my_charset_bin); } - inline longlong val_int_offset(uint row_offset) - { - ptr+=row_offset; - longlong tmp=val_int(); - ptr-=row_offset; - return tmp; - } - inline longlong val_int(const uchar *new_ptr) - { - uchar *old_ptr= ptr; - longlong return_value; - ptr= (uchar*) new_ptr; - return_value= val_int(); - ptr= old_ptr; - return return_value; - } - inline String *val_str(String *str, const uchar *new_ptr) - { - uchar *old_ptr= ptr; - ptr= (uchar*) new_ptr; - val_str(str); - ptr= old_ptr; - return str; - } - virtual In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - virtual uchar *pack(uchar *to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - uchar *pack(uchar *to, const uchar *from) - { - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("Field::pack","./sql/field.h",390,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first); - do {_db_return_ (392, &_db_func_, &_db_file_, &_db_level_); return(result);} while(0); - } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); - const uchar *unpack(uchar* to, const uchar *from) - { - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("Field::unpack","./sql/field.h",402,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first); - do {_db_return_ (404, &_db_func_, &_db_file_, &_db_level_); return(result);} while(0); - } - virtual uchar *pack_key(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return pack(to, from, max_length, low_byte_first); - } - virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return pack(to, from, max_length, low_byte_first); - } - virtual const uchar *unpack_key(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return unpack(to, from, max_length, low_byte_first); - } - virtual uint packed_col_length(const uchar *to, uint length) - { return length;} - virtual uint max_packed_col_length(uint max_length) - { return max_length;} - virtual int pack_cmp(const uchar *a,const uchar *b, uint key_length_arg, - my_bool insert_or_update) - { return cmp(a,b); } - virtual int pack_cmp(const uchar *b, uint key_length_arg, - my_bool insert_or_update) - { return cmp(ptr,b); } - uint offset(uchar *record) - { - return (uint) (ptr - record); - } - void copy_from_tmp(int offset); - uint fill_cache_field(struct st_cache_field *copy); - virtual In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - virtual In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); - virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } - virtual CHARSET_INFO *sort_charset(void) const { return charset(); } - virtual In_C_you_should_use_my_bool_instead() has_charset(void) const { return (0); } - virtual void set_charset(CHARSET_INFO *charset_arg) { } - virtual enum Derivation derivation(void) const - { return DERIVATION_IMPLICIT; } - virtual void set_derivation(enum Derivation derivation_arg) { } - In_C_you_should_use_my_bool_instead() set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code, - int cuted_increment); - void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, - const char *str, uint str_len, - timestamp_type ts_type, int cuted_increment); - void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, - longlong nr, timestamp_type ts_type, - int cuted_increment); - void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, - double nr, timestamp_type ts_type); - inline In_C_you_should_use_my_bool_instead() check_overflow(int op_result) - { - return (op_result == 2); - } - int warn_if_overflow(int op_result); - void init(TABLE *table_arg) - { - orig_table= table= table_arg; - table_name= &table_arg->alias; - } - virtual uint32 max_display_length()= 0; - virtual uint is_equal(Create_field *new_field); - longlong convert_decimal2longlong(const my_decimal *val, In_C_you_should_use_my_bool_instead() unsigned_flag, - int *err); - inline uint32 char_length() const - { - return field_length / charset()->mbmaxlen; - } - virtual geometry_type get_geometry_type() - { - assert(0); - return GEOM_GEOMETRY; - } - virtual void hash(ulong *nr, ulong *nr2); - friend In_C_you_should_use_my_bool_instead() reopen_table(THD *,struct st_table *,In_C_you_should_use_my_bool_instead()); - friend int cre_myisam(char * name, register TABLE *form, uint options, - ulonglong auto_increment_value); - friend class Copy_field; - friend class Item_avg_field; - friend class Item_std_field; - friend class Item_sum_num; - friend class Item_sum_sum; - friend class Item_sum_str; - friend class Item_sum_count; - friend class Item_sum_avg; - friend class Item_sum_std; - friend class Item_sum_min; - friend class Item_sum_max; - friend class Item_func_group_concat; -private: - virtual size_t do_last_null_byte() const; - virtual int do_save_field_metadata(uchar *metadata_ptr) - { return 0; } -}; -class Field_num :public Field { -public: - const uint8 dec; - In_C_you_should_use_my_bool_instead() zerofill,unsigned_flag; - Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, utype unireg_check_arg, - const char *field_name_arg, - uint8 dec_arg, In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg); - Item_result result_type () const { return REAL_RESULT; } - void prepend_zeros(String *value); - void add_zerofill_and_unsigned(String &res) const; - friend class Create_field; - void make_field(Send_field *); - uint decimals() const { return (uint) dec; } - uint size_of() const { return sizeof(*this); } - In_C_you_should_use_my_bool_instead() eq_def(Field *field); - int store_decimal(const my_decimal *); - my_decimal *val_decimal(my_decimal *); - uint is_equal(Create_field *new_field); - int check_int(CHARSET_INFO *cs, const char *str, int length, - const char *int_end, int error); - In_C_you_should_use_my_bool_instead() get_int(CHARSET_INFO *cs, const char *from, uint len, - longlong *rnd, ulonglong unsigned_max, - longlong signed_min, longlong signed_max); -}; -class Field_str :public Field { -protected: - CHARSET_INFO *field_charset; - enum Derivation field_derivation; -public: - Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, utype unireg_check_arg, - const char *field_name_arg, CHARSET_INFO *charset); - Item_result result_type () const { return STRING_RESULT; } - uint decimals() const { return 31; } - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val)=0; - int store_decimal(const my_decimal *); - int store(const char *to,uint length,CHARSET_INFO *cs)=0; - uint size_of() const { return sizeof(*this); } - CHARSET_INFO *charset(void) const { return field_charset; } - void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; } - enum Derivation derivation(void) const { return field_derivation; } - virtual void set_derivation(enum Derivation derivation_arg) - { field_derivation= derivation_arg; } - In_C_you_should_use_my_bool_instead() binary() const { return field_charset == &my_charset_bin; } - uint32 max_display_length() { return field_length; } - friend class Create_field; - my_decimal *val_decimal(my_decimal *); - virtual In_C_you_should_use_my_bool_instead() str_needs_quotes() { return (1); } - In_C_you_should_use_my_bool_instead() compare_str_field_flags(Create_field *new_field, uint32 flags); - uint is_equal(Create_field *new_field); -}; -class Field_longstr :public Field_str -{ -protected: - int report_if_important_data(const char *ptr, const char *end, - In_C_you_should_use_my_bool_instead() count_spaces); -public: - Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, utype unireg_check_arg, - const char *field_name_arg, CHARSET_INFO *charset_arg) - :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, - field_name_arg, charset_arg) - {} - int store_decimal(const my_decimal *d); - uint32 max_data_length() const; -}; -class Field_real :public Field_num { -public: - my_bool not_fixed; - Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, utype unireg_check_arg, - const char *field_name_arg, - uint8 dec_arg, In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, - field_name_arg, dec_arg, zero_arg, unsigned_arg), - not_fixed(dec_arg >= 31) - {} - int store_decimal(const my_decimal *); - my_decimal *val_decimal(my_decimal *); - int truncate(double *nr, double max_length); - uint32 max_display_length() { return field_length; } - uint size_of() const { return sizeof(*this); } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); -}; -class Field_decimal :public Field_real { -public: - Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint8 dec_arg,In_C_you_should_use_my_bool_instead() zero_arg,In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - dec_arg, zero_arg, unsigned_arg) - {} - enum_field_types type() const { return MYSQL_TYPE_DECIMAL;} - enum ha_base_keytype key_type() const - { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; } - int reset(void); - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - void overflow(In_C_you_should_use_my_bool_instead() negative); - In_C_you_should_use_my_bool_instead() zero_pack() const { return 0; } - void sql_type(String &str) const; - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return Field::unpack(to, from, param_data, low_byte_first); - } - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return Field::pack(to, from, max_length, low_byte_first); - } -}; -class Field_new_decimal :public Field_num { -private: - int do_save_field_metadata(uchar *first_byte); -public: - uint precision; - uint bin_size; - Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint8 dec_arg, In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg); - Field_new_decimal(uint32 len_arg, In_C_you_should_use_my_bool_instead() maybe_null_arg, - const char *field_name_arg, uint8 dec_arg, - In_C_you_should_use_my_bool_instead() unsigned_arg); - enum_field_types type() const { return MYSQL_TYPE_NEWDECIMAL;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } - Item_result result_type () const { return DECIMAL_RESULT; } - int reset(void); - In_C_you_should_use_my_bool_instead() store_value(const my_decimal *decimal_value); - void set_value_on_overflow(my_decimal *decimal_value, In_C_you_should_use_my_bool_instead() sign); - int store(const char *to, uint length, CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store_time(MYSQL_TIME *ltime, timestamp_type t_type); - int store_decimal(const my_decimal *); - double val_real(void); - longlong val_int(void); - my_decimal *val_decimal(my_decimal *); - String *val_str(String*, String *); - int cmp(const uchar *, const uchar *); - void sort_string(uchar *buff, uint length); - In_C_you_should_use_my_bool_instead() zero_pack() const { return 0; } - void sql_type(String &str) const; - uint32 max_display_length() { return field_length; } - uint size_of() const { return sizeof(*this); } - uint32 pack_length() const { return (uint32) bin_size; } - uint pack_length_from_metadata(uint field_metadata); - uint row_pack_length() { return pack_length(); } - int compatible_field_size(uint field_metadata); - uint is_equal(Create_field *new_field); - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); -}; -class Field_tiny :public Field_num { -public: - Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - 0, zero_arg,unsigned_arg) - {} - enum Item_result result_type () const { return INT_RESULT; } - enum_field_types type() const { return MYSQL_TYPE_TINY;} - enum ha_base_keytype key_type() const - { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 1; } - void sql_type(String &str) const; - uint32 max_display_length() { return 4; } - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - *to= *from; - return to + 1; - } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first) - { - *to= *from; - return from + 1; - } -}; -class Field_short :public Field_num { -public: - Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - 0, zero_arg,unsigned_arg) - {} - Field_short(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg, 0, 0, unsigned_arg) - {} - enum Item_result result_type () const { return INT_RESULT; } - enum_field_types type() const { return MYSQL_TYPE_SHORT;} - enum ha_base_keytype key_type() const - { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;} - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=ptr[1]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 2; } - void sql_type(String &str) const; - uint32 max_display_length() { return 6; } - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - int16 val; - do { val = (*((int16 *) (from))); } while(0); - *((uint16*) (to))= (uint16) (val); - return to + sizeof(val); - } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first) - { - int16 val; - do { val = (*((int16 *) (from))); } while(0); - *((uint16*) (to))= (uint16) (val); - return from + sizeof(val); - } -}; -class Field_medium :public Field_num { -public: - Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - 0, zero_arg,unsigned_arg) - {} - enum Item_result result_type () const { return INT_RESULT; } - enum_field_types type() const { return MYSQL_TYPE_INT24;} - enum ha_base_keytype key_type() const - { return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 3; } - void sql_type(String &str) const; - uint32 max_display_length() { return 8; } - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return Field::pack(to, from, max_length, low_byte_first); - } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first) - { - return Field::unpack(to, from, param_data, low_byte_first); - } -}; -class Field_long :public Field_num { -public: - Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - 0, zero_arg,unsigned_arg) - {} - Field_long(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg,0,0,unsigned_arg) - {} - enum Item_result result_type () const { return INT_RESULT; } - enum_field_types type() const { return MYSQL_TYPE_LONG;} - enum ha_base_keytype key_type() const - { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } - double val_real(void); - longlong val_int(void); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - String *val_str(String*,String *); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 4; } - void sql_type(String &str) const; - uint32 max_display_length() { return 11; } - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - int32 val; - do { val = (*((long *) (from))); } while(0); - *((long *) (to))= (long) (val); - return to + sizeof(val); - } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first) - { - int32 val; - do { val = (*((long *) (from))); } while(0); - *((long *) (to))= (long) (val); - return from + sizeof(val); - } -}; -class Field_longlong :public Field_num { -public: - Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() zero_arg, In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - 0, zero_arg,unsigned_arg) - {} - Field_longlong(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, - const char *field_name_arg, - In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg,0,0,unsigned_arg) - {} - enum Item_result result_type () const { return INT_RESULT; } - enum_field_types type() const { return MYSQL_TYPE_LONGLONG;} - enum ha_base_keytype key_type() const - { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) - { - ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; - return 0; - } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 8; } - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } - uint32 max_display_length() { return 20; } - virtual uchar *pack(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first) - { - int64 val; - memcpy(((uchar*) &val),((uchar*) (from)),(sizeof(ulonglong))); - memcpy(((uchar*) (to)),((uchar*) &val),(sizeof(ulonglong))); - return to + sizeof(val); - } - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first) - { - int64 val; - memcpy(((uchar*) &val),((uchar*) (from)),(sizeof(ulonglong))); - memcpy(((uchar*) (to)),((uchar*) &val),(sizeof(ulonglong))); - return from + sizeof(val); - } -}; -class Field_float :public Field_real { -public: - Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint8 dec_arg,In_C_you_should_use_my_bool_instead() zero_arg,In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - dec_arg, zero_arg, unsigned_arg) - {} - Field_float(uint32 len_arg, In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - uint8 dec_arg) - :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0, - NONE, field_name_arg, dec_arg, 0, 0) - {} - enum_field_types type() const { return MYSQL_TYPE_FLOAT;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { bzero(ptr,sizeof(float)); return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return sizeof(float); } - uint row_pack_length() { return pack_length(); } - void sql_type(String &str) const; -private: - int do_save_field_metadata(uchar *first_byte); -}; -class Field_double :public Field_real { -public: - Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint8 dec_arg,In_C_you_should_use_my_bool_instead() zero_arg,In_C_you_should_use_my_bool_instead() unsigned_arg) - :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - dec_arg, zero_arg, unsigned_arg) - {} - Field_double(uint32 len_arg, In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - uint8 dec_arg) - :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, - NONE, field_name_arg, dec_arg, 0, 0) - {} - Field_double(uint32 len_arg, In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - uint8 dec_arg, my_bool not_fixed_arg) - :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, - NONE, field_name_arg, dec_arg, 0, 0) - {not_fixed= not_fixed_arg; } - enum_field_types type() const { return MYSQL_TYPE_DOUBLE;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { bzero(ptr,sizeof(double)); return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return sizeof(double); } - uint row_pack_length() { return pack_length(); } - void sql_type(String &str) const; -private: - int do_save_field_metadata(uchar *first_byte); -}; -class Field_null :public Field_str { - static uchar null[1]; -public: - Field_null(uchar *ptr_arg, uint32 len_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str(ptr_arg, len_arg, null, 1, - unireg_check_arg, field_name_arg, cs) - {} - enum_field_types type() const { return MYSQL_TYPE_NULL;} - int store(const char *to, uint length, CHARSET_INFO *cs) - { null[0]=1; return 0; } - int store(double nr) { null[0]=1; return 0; } - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val) { null[0]=1; return 0; } - int store_decimal(const my_decimal *d) { null[0]=1; return 0; } - int reset(void) { return 0; } - double val_real(void) { return 0.0;} - longlong val_int(void) { return 0;} - my_decimal *val_decimal(my_decimal *) { return 0; } - String *val_str(String *value,String *value2) - { value2->length(0); return value2;} - int cmp(const uchar *a, const uchar *b) { return 0;} - void sort_string(uchar *buff, uint length) {} - uint32 pack_length() const { return 0; } - void sql_type(String &str) const; - uint size_of() const { return sizeof(*this); } - uint32 max_display_length() { return 4; } -}; -class Field_timestamp :public Field_str { -public: - Field_timestamp(uchar *ptr_arg, uint32 len_arg, - uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, CHARSET_INFO *cs); - Field_timestamp(In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs); - enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } - enum Item_result cmp_type () const { return INT_RESULT; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 4; } - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 0; } - void set_time(); - virtual void set_default() - { - if (table->timestamp_field == this && - unireg_check != TIMESTAMP_UN_FIELD) - set_time(); - else - Field::set_default(); - } - inline long get_timestamp(my_bool *null_value) - { - if ((*null_value= is_null())) - return 0; - long tmp; - do { tmp = (*((long *) (ptr))); } while(0); - return tmp; - } - inline void store_timestamp(my_time_t timestamp) - { - *((long *) (ptr))= (long) ((uint32) timestamp); - } - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); - timestamp_auto_set_type get_auto_set_type() const; -}; -class Field_year :public Field_tiny { -public: - Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg) - :Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, 1, 1) - {} - enum_field_types type() const { return MYSQL_TYPE_YEAR;} - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } -}; -class Field_date :public Field_str { -public: - Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) - {} - Field_date(In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg, cs) {} - enum_field_types type() const { return MYSQL_TYPE_DATE;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } - enum Item_result cmp_type () const { return INT_RESULT; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 4; } - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 1; } -}; -class Field_newdate :public Field_str { -public: - Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) - {} - Field_newdate(In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg, cs) {} - enum_field_types type() const { return MYSQL_TYPE_DATE;} - enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; } - enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; } - enum Item_result cmp_type () const { return INT_RESULT; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store_time(MYSQL_TIME *ltime, timestamp_type type); - int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 3; } - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 1; } - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); -}; -class Field_time :public Field_str { -public: - Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) - {} - Field_time(In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str((uchar*) 0,8, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg, cs) {} - enum_field_types type() const { return MYSQL_TYPE_TIME;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } - enum Item_result cmp_type () const { return INT_RESULT; } - int store_time(MYSQL_TIME *ltime, timestamp_type type); - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime, uint fuzzydate); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 3; } - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 1; } -}; -class Field_datetime :public Field_str { -public: - Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) - {} - Field_datetime(In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0, - NONE, field_name_arg, cs) {} - enum_field_types type() const { return MYSQL_TYPE_DATETIME;} - enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } - enum Item_result cmp_type () const { return INT_RESULT; } - uint decimals() const { return 6; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store_time(MYSQL_TIME *ltime, timestamp_type type); - int reset(void) - { - ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; - return 0; - } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - In_C_you_should_use_my_bool_instead() send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return 8; } - void sql_type(String &str) const; - In_C_you_should_use_my_bool_instead() can_be_compared_as_longlong() const { return (1); } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 1; } - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); -}; -class Field_string :public Field_longstr { -public: - In_C_you_should_use_my_bool_instead() can_alter_field_type; - Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs), - can_alter_field_type(1) {}; - Field_string(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, - NONE, field_name_arg, cs), - can_alter_field_type(1) {}; - enum_field_types type() const - { - return ((can_alter_field_type && orig_table && - orig_table->s->db_create_options & 1 && - field_length >= 4) && - orig_table->s->frm_version < (6 +4) ? - MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING); - } - enum ha_base_keytype key_type() const - { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 0; } - int reset(void) - { - charset()->cset->fill(charset(),(char*) ptr, field_length, - (has_charset() ? ' ' : 0)); - return 0; - } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store(double nr) { return Field_str::store(nr); } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - my_decimal *val_decimal(my_decimal *); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - void sql_type(String &str) const; - virtual uchar *pack(uchar *to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); - uint pack_length_from_metadata(uint field_metadata) - { return (field_metadata & 0x00ff); } - uint row_pack_length() { return (field_length + 1); } - int pack_cmp(const uchar *a,const uchar *b,uint key_length, - my_bool insert_or_update); - int pack_cmp(const uchar *b,uint key_length,my_bool insert_or_update); - uint packed_col_length(const uchar *to, uint length); - uint max_packed_col_length(uint max_length); - uint size_of() const { return sizeof(*this); } - enum_field_types real_type() const { return MYSQL_TYPE_STRING; } - In_C_you_should_use_my_bool_instead() has_charset(void) const - { return charset() == &my_charset_bin ? (0) : (1); } - Field *new_field(MEM_ROOT *root, struct st_table *new_table, In_C_you_should_use_my_bool_instead() keep_type); - virtual uint get_key_image(uchar *buff,uint length, imagetype type); -private: - int do_save_field_metadata(uchar *first_byte); -}; -class Field_varstring :public Field_longstr { -public: - static const uint MAX_SIZE; - uint32 length_bytes; - Field_varstring(uchar *ptr_arg, - uint32 len_arg, uint length_bytes_arg, - uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, CHARSET_INFO *cs) - :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs), - length_bytes(length_bytes_arg) - { - share->varchar_fields++; - } - Field_varstring(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, - const char *field_name_arg, - TABLE_SHARE *share, CHARSET_INFO *cs) - :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, - NONE, field_name_arg, cs), - length_bytes(len_arg < 256 ? 1 :2) - { - share->varchar_fields++; - } - enum_field_types type() const { return MYSQL_TYPE_VARCHAR; } - enum ha_base_keytype key_type() const; - uint row_pack_length() { return field_length; } - In_C_you_should_use_my_bool_instead() zero_pack() const { return 0; } - int reset(void) { bzero(ptr,field_length+length_bytes); return 0; } - uint32 pack_length() const { return (uint32) field_length+length_bytes; } - uint32 key_length() const { return (uint32) field_length; } - uint32 sort_length() const - { - return (uint32) field_length + (field_charset == &my_charset_bin ? - length_bytes : 0); - } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store(double nr) { return Field_str::store(nr); } - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - my_decimal *val_decimal(my_decimal *); - int cmp_max(const uchar *, const uchar *, uint max_length); - int cmp(const uchar *a,const uchar *b) - { - return cmp_max(a, b, ~0L); - } - void sort_string(uchar *buff,uint length); - uint get_key_image(uchar *buff,uint length, imagetype type); - void set_key_image(const uchar *buff,uint length); - void sql_type(String &str) const; - virtual uchar *pack(uchar *to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - uchar *pack_key(uchar *to, const uchar *from, uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - uchar *pack_key_from_key_image(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - virtual const uchar *unpack(uchar* to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); - const uchar *unpack_key(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - int pack_cmp(const uchar *a, const uchar *b, uint key_length, - my_bool insert_or_update); - int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update); - int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L); - int key_cmp(const uchar *,const uchar*); - int key_cmp(const uchar *str, uint length); - uint packed_col_length(const uchar *to, uint length); - uint max_packed_col_length(uint max_length); - uint32 data_length(); - uint size_of() const { return sizeof(*this); } - enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; } - In_C_you_should_use_my_bool_instead() has_charset(void) const - { return charset() == &my_charset_bin ? (0) : (1); } - Field *new_field(MEM_ROOT *root, struct st_table *new_table, In_C_you_should_use_my_bool_instead() keep_type); - Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, - uchar *new_ptr, uchar *new_null_ptr, - uint new_null_bit); - uint is_equal(Create_field *new_field); - void hash(ulong *nr, ulong *nr2); -private: - int do_save_field_metadata(uchar *first_byte); -}; -class Field_blob :public Field_longstr { -protected: - uint packlength; - String value; -public: - Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs); - Field_blob(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, - NONE, field_name_arg, cs), - packlength(4) - { - flags|= 16; - } - Field_blob(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs, In_C_you_should_use_my_bool_instead() set_packlength) - :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, - NONE, field_name_arg, cs) - { - flags|= 16; - packlength= 4; - if (set_packlength) - { - uint32 l_char_length= len_arg/cs->mbmaxlen; - packlength= l_char_length <= 255 ? 1 : - l_char_length <= 65535 ? 2 : - l_char_length <= 16777215 ? 3 : 4; - } - } - Field_blob(uint32 packlength_arg) - :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info), - packlength(packlength_arg) {} - enum_field_types type() const { return MYSQL_TYPE_BLOB;} - enum ha_base_keytype key_type() const - { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - my_decimal *val_decimal(my_decimal *); - int cmp_max(const uchar *, const uchar *, uint max_length); - int cmp(const uchar *a,const uchar *b) - { return cmp_max(a, b, ~0L); } - int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length); - int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L); - int key_cmp(const uchar *,const uchar*); - int key_cmp(const uchar *str, uint length); - uint32 key_length() const { return 0; } - void sort_string(uchar *buff,uint length); - uint32 pack_length() const - { return (uint32) (packlength+table->s->blob_ptr_size); } - uint32 pack_length_no_ptr() const - { return (uint32) (packlength); } - uint row_pack_length() { return pack_length_no_ptr(); } - uint32 sort_length() const; - virtual uint32 max_data_length() const - { - return (uint32) (((ulonglong) 1 << (packlength*8)) -1); - } - int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; } - void reset_fields() { bzero((uchar*) &value,sizeof(value)); } - static - void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, In_C_you_should_use_my_bool_instead() low_byte_first); - void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number) - { - store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first); - } - inline void store_length(uint32 number) - { - store_length(ptr, packlength, number); - } - uint32 get_packed_size(const uchar *ptr_arg, In_C_you_should_use_my_bool_instead() low_byte_first) - {return packlength + get_length(ptr_arg, packlength, low_byte_first);} - inline uint32 get_length(uint row_offset= 0) - { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); } - uint32 get_length(const uchar *ptr, uint packlength, In_C_you_should_use_my_bool_instead() low_byte_first); - uint32 get_length(const uchar *ptr_arg) - { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); } - void put_length(uchar *pos, uint32 length); - inline void get_ptr(uchar **str) - { - memcpy(((uchar*) str),(ptr+packlength),(sizeof(uchar*))); - } - inline void get_ptr(uchar **str, uint row_offset) - { - memcpy(((uchar*) str),(ptr+packlength+row_offset),(sizeof(char*))); - } - inline void set_ptr(uchar *length, uchar *data) - { - memcpy(ptr,length,packlength); - memcpy((ptr+packlength),(&data),(sizeof(char*))); - } - void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data) - { - uchar *ptr_ofs= (uchar*) ((uchar*) (ptr)+ptr_diff); - store_length(ptr_ofs, packlength, length); - memcpy((ptr_ofs+packlength),(&data),(sizeof(char*))); - } - inline void set_ptr(uint32 length, uchar *data) - { - set_ptr_offset(0, length, data); - } - uint get_key_image(uchar *buff,uint length, imagetype type); - void set_key_image(const uchar *buff,uint length); - void sql_type(String &str) const; - inline In_C_you_should_use_my_bool_instead() copy() - { - uchar *tmp; - get_ptr(&tmp); - if (value.copy((char*) tmp, get_length(), charset())) - { - Field_blob::reset(); - return 1; - } - tmp=(uchar*) value.ptr(); - memcpy((ptr+packlength),(&tmp),(sizeof(char*))); - return 0; - } - virtual uchar *pack(uchar *to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - uchar *pack_key(uchar *to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - uchar *pack_key_from_key_image(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - virtual const uchar *unpack(uchar *to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); - const uchar *unpack_key(uchar* to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - int pack_cmp(const uchar *a, const uchar *b, uint key_length, - my_bool insert_or_update); - int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update); - uint packed_col_length(const uchar *col_ptr, uint length); - uint max_packed_col_length(uint max_length); - void free() { value.free(); } - inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); } - friend int field_conv(Field *to,Field *from); - uint size_of() const { return sizeof(*this); } - In_C_you_should_use_my_bool_instead() has_charset(void) const - { return charset() == &my_charset_bin ? (0) : (1); } - uint32 max_display_length(); - uint is_equal(Create_field *new_field); - inline In_C_you_should_use_my_bool_instead() in_read_set() { return bitmap_is_set(table->read_set, field_index); } - inline In_C_you_should_use_my_bool_instead() in_write_set() { return bitmap_is_set(table->write_set, field_index); } -private: - int do_save_field_metadata(uchar *first_byte); -}; -class Field_geom :public Field_blob { -public: - enum geometry_type geom_type; - Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, uint blob_pack_length, - enum geometry_type geom_type_arg) - :Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, - field_name_arg, share, blob_pack_length, &my_charset_bin) - { geom_type= geom_type_arg; } - Field_geom(uint32 len_arg,In_C_you_should_use_my_bool_instead() maybe_null_arg, const char *field_name_arg, - TABLE_SHARE *share, enum geometry_type geom_type_arg) - :Field_blob(len_arg, maybe_null_arg, field_name_arg, &my_charset_bin) - { geom_type= geom_type_arg; } - enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; } - enum_field_types type() const { return MYSQL_TYPE_GEOMETRY; } - void sql_type(String &str) const; - int store(const char *to, uint length, CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store_decimal(const my_decimal *); - uint size_of() const { return sizeof(*this); } - int reset(void) { return !maybe_null() || Field_blob::reset(); } - geometry_type get_geometry_type() { return geom_type; }; -}; -class Field_enum :public Field_str { -protected: - uint packlength; -public: - TYPELIB *typelib; - Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint packlength_arg, - TYPELIB *typelib_arg, - CHARSET_INFO *charset_arg) - :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, charset_arg), - packlength(packlength_arg),typelib(typelib_arg) - { - flags|=256; - } - Field *new_field(MEM_ROOT *root, struct st_table *new_table, In_C_you_should_use_my_bool_instead() keep_type); - enum_field_types type() const { return MYSQL_TYPE_STRING; } - enum Item_result cmp_type () const { return INT_RESULT; } - enum Item_result cast_to_int_type () const { return INT_RESULT; } - enum ha_base_keytype key_type() const; - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const { return (uint32) packlength; } - void store_type(ulonglong value); - void sql_type(String &str) const; - uint size_of() const { return sizeof(*this); } - enum_field_types real_type() const { return MYSQL_TYPE_ENUM; } - uint pack_length_from_metadata(uint field_metadata) - { return (field_metadata & 0x00ff); } - uint row_pack_length() { return pack_length(); } - virtual In_C_you_should_use_my_bool_instead() zero_pack() const { return 0; } - In_C_you_should_use_my_bool_instead() optimize_range(uint idx, uint part) { return 0; } - In_C_you_should_use_my_bool_instead() eq_def(Field *field); - In_C_you_should_use_my_bool_instead() has_charset(void) const { return (1); } - CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } -private: - int do_save_field_metadata(uchar *first_byte); -}; -class Field_set :public Field_enum { -public: - Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint32 packlength_arg, - TYPELIB *typelib_arg, CHARSET_INFO *charset_arg) - :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - packlength_arg, - typelib_arg,charset_arg) - { - flags=(flags & ~256) | 2048; - } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr) { return Field_set::store((longlong) nr, (0)); } - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - virtual In_C_you_should_use_my_bool_instead() zero_pack() const { return 1; } - String *val_str(String*,String *); - void sql_type(String &str) const; - enum_field_types real_type() const { return MYSQL_TYPE_SET; } - In_C_you_should_use_my_bool_instead() has_charset(void) const { return (1); } -}; -class Field_bit :public Field { -public: - uchar *bit_ptr; - uchar bit_ofs; - uint bit_len; - uint bytes_in_rec; - Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg, - enum utype unireg_check_arg, const char *field_name_arg); - enum_field_types type() const { return MYSQL_TYPE_BIT; } - enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; } - uint32 key_length() const { return (uint32) (field_length + 7) / 8; } - uint32 max_data_length() const { return (field_length + 7) / 8; } - uint32 max_display_length() { return field_length; } - uint size_of() const { return sizeof(*this); } - Item_result result_type () const { return INT_RESULT; } - int reset(void) { bzero(ptr, bytes_in_rec); return 0; } - int store(const char *to, uint length, CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val); - int store_decimal(const my_decimal *); - double val_real(void); - longlong val_int(void); - String *val_str(String*, String *); - virtual In_C_you_should_use_my_bool_instead() str_needs_quotes() { return (1); } - my_decimal *val_decimal(my_decimal *); - int cmp(const uchar *a, const uchar *b) - { - assert(ptr == a); - return Field_bit::key_cmp(b, bytes_in_rec+((bit_len) ? 1 : 0)); - } - int cmp_binary_offset(uint row_offset) - { return cmp_offset(row_offset); } - int cmp_max(const uchar *a, const uchar *b, uint max_length); - int key_cmp(const uchar *a, const uchar *b) - { return cmp_binary((uchar *) a, (uchar *) b); } - int key_cmp(const uchar *str, uint length); - int cmp_offset(uint row_offset); - void get_image(uchar *buff, uint length, CHARSET_INFO *cs) - { get_key_image(buff, length, itRAW); } - void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) - { Field_bit::store((char *) buff, length, cs); } - uint get_key_image(uchar *buff, uint length, imagetype type); - void set_key_image(const uchar *buff, uint length) - { Field_bit::store((char*) buff, length, &my_charset_bin); } - void sort_string(uchar *buff, uint length) - { get_key_image(buff, length, itRAW); } - uint32 pack_length() const { return (uint32) (field_length + 7) / 8; } - uint32 pack_length_in_rec() const { return bytes_in_rec; } - uint pack_length_from_metadata(uint field_metadata); - uint row_pack_length() - { return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); } - int compatible_field_size(uint field_metadata); - void sql_type(String &str) const; - virtual uchar *pack(uchar *to, const uchar *from, - uint max_length, In_C_you_should_use_my_bool_instead() low_byte_first); - virtual const uchar *unpack(uchar *to, const uchar *from, - uint param_data, In_C_you_should_use_my_bool_instead() low_byte_first); - virtual void set_default(); - Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, - uchar *new_ptr, uchar *new_null_ptr, - uint new_null_bit); - void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg) - { - bit_ptr= bit_ptr_arg; - bit_ofs= bit_ofs_arg; - } - In_C_you_should_use_my_bool_instead() eq(Field *field) - { - return (Field::eq(field) && - field->type() == type() && - bit_ptr == ((Field_bit *)field)->bit_ptr && - bit_ofs == ((Field_bit *)field)->bit_ofs); - } - uint is_equal(Create_field *new_field); - void move_field_offset(my_ptrdiff_t ptr_diff) - { - Field::move_field_offset(ptr_diff); - bit_ptr= (uchar*) ((uchar*) (bit_ptr)+ptr_diff); - } - void hash(ulong *nr, ulong *nr2); -private: - virtual size_t do_last_null_byte() const; - int do_save_field_metadata(uchar *first_byte); -}; -class Field_bit_as_char: public Field_bit { -public: - Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg); - enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } - uint size_of() const { return sizeof(*this); } - int store(const char *to, uint length, CHARSET_INFO *charset); - int store(double nr) { return Field_bit::store(nr); } - int store(longlong nr, In_C_you_should_use_my_bool_instead() unsigned_val) - { return Field_bit::store(nr, unsigned_val); } - void sql_type(String &str) const; -}; -class Create_field :public Sql_alloc -{ -public: - const char *field_name; - const char *change; - const char *after; - LEX_STRING comment; - Item *def; - enum enum_field_types sql_type; - ulong length; - uint32 char_length; - uint decimals, flags, pack_length, key_length; - Field::utype unireg_check; - TYPELIB *interval; - TYPELIB *save_interval; - List<String> interval_list; - CHARSET_INFO *charset; - Field::geometry_type geom_type; - Field *field; - uint8 row,col,sc_length,interval_id; - uint offset,pack_flag; - Create_field() :after(0) {} - Create_field(Field *field, Field *orig_field); - Create_field *clone(MEM_ROOT *mem_root) const - { return new (mem_root) Create_field(*this); } - void create_length_to_internal_length(void); - void init_for_tmp_table(enum_field_types sql_type_arg, - uint32 max_length, uint32 decimals, - In_C_you_should_use_my_bool_instead() maybe_null, In_C_you_should_use_my_bool_instead() is_unsigned); - In_C_you_should_use_my_bool_instead() init(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); -}; -class Send_field { - public: - const char *db_name; - const char *table_name,*org_table_name; - const char *col_name,*org_col_name; - ulong length; - uint charsetnr, flags, decimals; - enum_field_types type; - Send_field() {} -}; -class Copy_field :public Sql_alloc { - typedef void Copy_func(Copy_field*); - Copy_func *get_copy_func(Field *to, Field *from); -public: - uchar *from_ptr,*to_ptr; - uchar *from_null_ptr,*to_null_ptr; - my_bool *null_row; - uint from_bit,to_bit; - uint from_length,to_length; - Field *from_field,*to_field; - String tmp; - Copy_field() {} - ~Copy_field() {} - void set(Field *to,Field *from,In_C_you_should_use_my_bool_instead() save); - void set(uchar *to,Field *from); - void (*do_copy)(Copy_field *); - void (*do_copy2)(Copy_field *); -}; -Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length, - uchar *null_pos, uchar null_bit, - uint pack_flag, enum_field_types field_type, - CHARSET_INFO *cs, - Field::geometry_type geom_type, - Field::utype unireg_check, - TYPELIB *interval, const char *field_name); -uint pack_length_to_packflag(uint type); -enum_field_types get_blob_type_from_length(ulong length); -uint32 calc_pack_length(enum_field_types type,uint32 length); -int set_field_to_null(Field *field); -int set_field_to_null_with_conversions(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); -#include "protocol.h" -class i_string; -class THD; -typedef struct st_mysql_field MYSQL_FIELD; -typedef struct st_mysql_rows MYSQL_ROWS; -class Protocol -{ -protected: - THD *thd; - String *packet; - String *convert; - uint field_pos; - enum enum_field_types *field_types; - uint field_count; - In_C_you_should_use_my_bool_instead() net_store_data(const uchar *from, size_t length); - In_C_you_should_use_my_bool_instead() store_string_aux(const char *from, size_t length, - CHARSET_INFO *fromcs, CHARSET_INFO *tocs); -public: - Protocol() {} - Protocol(THD *thd_arg) { init(thd_arg); } - virtual ~Protocol() {} - void init(THD* thd_arg); - enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 }; - virtual In_C_you_should_use_my_bool_instead() send_fields(List<Item> *list, uint flags); - In_C_you_should_use_my_bool_instead() store(I_List<i_string> *str_list); - In_C_you_should_use_my_bool_instead() store(const char *from, CHARSET_INFO *cs); - String *storage_packet() { return packet; } - inline void free() { packet->free(); } - virtual In_C_you_should_use_my_bool_instead() write(); - inline In_C_you_should_use_my_bool_instead() store(int from) - { return store_long((longlong) from); } - inline In_C_you_should_use_my_bool_instead() store(uint32 from) - { return store_long((longlong) from); } - inline In_C_you_should_use_my_bool_instead() store(longlong from) - { return store_longlong((longlong) from, 0); } - inline In_C_you_should_use_my_bool_instead() store(ulonglong from) - { return store_longlong((longlong) from, 1); } - inline In_C_you_should_use_my_bool_instead() store(String *str) - { return store((char*) str->ptr(), str->length(), str->charset()); } - virtual In_C_you_should_use_my_bool_instead() prepare_for_send(List<Item> *item_list) - { - field_count=item_list->elements; - return 0; - } - virtual In_C_you_should_use_my_bool_instead() flush(); - virtual void end_partial_result_set(THD *thd); - virtual void prepare_for_resend()=0; - virtual In_C_you_should_use_my_bool_instead() store_null()=0; - virtual In_C_you_should_use_my_bool_instead() store_tiny(longlong from)=0; - virtual In_C_you_should_use_my_bool_instead() store_short(longlong from)=0; - virtual In_C_you_should_use_my_bool_instead() store_long(longlong from)=0; - virtual In_C_you_should_use_my_bool_instead() store_longlong(longlong from, In_C_you_should_use_my_bool_instead() unsigned_flag)=0; - virtual In_C_you_should_use_my_bool_instead() store_decimal(const my_decimal *)=0; - virtual In_C_you_should_use_my_bool_instead() store(const char *from, size_t length, CHARSET_INFO *cs)=0; - virtual In_C_you_should_use_my_bool_instead() store(const char *from, size_t length, - CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0; - virtual In_C_you_should_use_my_bool_instead() store(float from, uint32 decimals, String *buffer)=0; - virtual In_C_you_should_use_my_bool_instead() store(double from, uint32 decimals, String *buffer)=0; - virtual In_C_you_should_use_my_bool_instead() store(MYSQL_TIME *time)=0; - virtual In_C_you_should_use_my_bool_instead() store_date(MYSQL_TIME *time)=0; - virtual In_C_you_should_use_my_bool_instead() store_time(MYSQL_TIME *time)=0; - virtual In_C_you_should_use_my_bool_instead() store(Field *field)=0; - void remove_last_row() {} - enum enum_protocol_type - { - PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1 - }; - virtual enum enum_protocol_type type()= 0; -}; -class Protocol_text :public Protocol -{ -public: - Protocol_text() {} - Protocol_text(THD *thd_arg) :Protocol(thd_arg) {} - virtual void prepare_for_resend(); - virtual In_C_you_should_use_my_bool_instead() store_null(); - virtual In_C_you_should_use_my_bool_instead() store_tiny(longlong from); - virtual In_C_you_should_use_my_bool_instead() store_short(longlong from); - virtual In_C_you_should_use_my_bool_instead() store_long(longlong from); - virtual In_C_you_should_use_my_bool_instead() store_longlong(longlong from, In_C_you_should_use_my_bool_instead() unsigned_flag); - virtual In_C_you_should_use_my_bool_instead() store_decimal(const my_decimal *); - virtual In_C_you_should_use_my_bool_instead() store(const char *from, size_t length, CHARSET_INFO *cs); - virtual In_C_you_should_use_my_bool_instead() store(const char *from, size_t length, - CHARSET_INFO *fromcs, CHARSET_INFO *tocs); - virtual In_C_you_should_use_my_bool_instead() store(MYSQL_TIME *time); - virtual In_C_you_should_use_my_bool_instead() store_date(MYSQL_TIME *time); - virtual In_C_you_should_use_my_bool_instead() store_time(MYSQL_TIME *time); - virtual In_C_you_should_use_my_bool_instead() store(float nr, uint32 decimals, String *buffer); - virtual In_C_you_should_use_my_bool_instead() store(double from, uint32 decimals, String *buffer); - virtual In_C_you_should_use_my_bool_instead() store(Field *field); - virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; }; -}; -class Protocol_binary :public Protocol -{ -private: - uint bit_fields; -public: - Protocol_binary() {} - Protocol_binary(THD *thd_arg) :Protocol(thd_arg) {} - virtual In_C_you_should_use_my_bool_instead() prepare_for_send(List<Item> *item_list); - virtual void prepare_for_resend(); - virtual In_C_you_should_use_my_bool_instead() store_null(); - virtual In_C_you_should_use_my_bool_instead() store_tiny(longlong from); - virtual In_C_you_should_use_my_bool_instead() store_short(longlong from); - virtual In_C_you_should_use_my_bool_instead() store_long(longlong from); - virtual In_C_you_should_use_my_bool_instead() store_longlong(longlong from, In_C_you_should_use_my_bool_instead() unsigned_flag); - virtual In_C_you_should_use_my_bool_instead() store_decimal(const my_decimal *); - virtual In_C_you_should_use_my_bool_instead() store(const char *from, size_t length, CHARSET_INFO *cs); - virtual In_C_you_should_use_my_bool_instead() store(const char *from, size_t length, - CHARSET_INFO *fromcs, CHARSET_INFO *tocs); - virtual In_C_you_should_use_my_bool_instead() store(MYSQL_TIME *time); - virtual In_C_you_should_use_my_bool_instead() store_date(MYSQL_TIME *time); - virtual In_C_you_should_use_my_bool_instead() store_time(MYSQL_TIME *time); - virtual In_C_you_should_use_my_bool_instead() store(float nr, uint32 decimals, String *buffer); - virtual In_C_you_should_use_my_bool_instead() store(double from, uint32 decimals, String *buffer); - virtual In_C_you_should_use_my_bool_instead() store(Field *field); - virtual enum enum_protocol_type type() { return PROTOCOL_BINARY; }; -}; -void send_warning(THD *thd, uint sql_errno, const char *err=0); -void net_send_error(THD *thd, uint sql_errno=0, const char *err=0); -void net_end_statement(THD *thd); -In_C_you_should_use_my_bool_instead() send_old_password_request(THD *thd); -uchar *net_store_data(uchar *to,const uchar *from, size_t length); -uchar *net_store_data(uchar *to,int32 from); -uchar *net_store_data(uchar *to,longlong from); -#include "sql_udf.h" -enum Item_udftype {UDFTYPE_FUNCTION=1,UDFTYPE_AGGREGATE}; -typedef void (*Udf_func_clear)(UDF_INIT *, uchar *, uchar *); -typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *); -typedef void (*Udf_func_deinit)(UDF_INIT*); -typedef my_bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *); -typedef void (*Udf_func_any)(); -typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *); -typedef longlong (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, uchar *, - uchar *); -typedef struct st_udf_func -{ - LEX_STRING name; - Item_result returns; - Item_udftype type; - char *dl; - void *dlhandle; - Udf_func_any func; - Udf_func_init func_init; - Udf_func_deinit func_deinit; - Udf_func_clear func_clear; - Udf_func_add func_add; - ulong usage_count; -} udf_func; -class Item_result_field; -class udf_handler :public Sql_alloc -{ - protected: - udf_func *u_d; - String *buffers; - UDF_ARGS f_args; - UDF_INIT initid; - char *num_buffer; - uchar error, is_null; - In_C_you_should_use_my_bool_instead() initialized; - Item **args; - public: - table_map used_tables_cache; - In_C_you_should_use_my_bool_instead() const_item_cache; - In_C_you_should_use_my_bool_instead() not_original; - udf_handler(udf_func *udf_arg) :u_d(udf_arg), buffers(0), error(0), - is_null(0), initialized(0), not_original(0) - {} - ~udf_handler(); - const char *name() const { return u_d ? u_d->name.str : "?"; } - Item_result result_type () const - { return u_d ? u_d->returns : STRING_RESULT;} - In_C_you_should_use_my_bool_instead() get_arguments(); - In_C_you_should_use_my_bool_instead() fix_fields(THD *thd, Item_result_field *item, - uint arg_count, Item **args); - void cleanup(); - double val(my_bool *null_value) - { - is_null= 0; - if (get_arguments()) - { - *null_value=1; - return 0.0; - } - Udf_func_double func= (Udf_func_double) u_d->func; - double tmp=func(&initid, &f_args, &is_null, &error); - if (is_null || error) - { - *null_value=1; - return 0.0; - } - *null_value=0; - return tmp; - } - longlong val_int(my_bool *null_value) - { - is_null= 0; - if (get_arguments()) - { - *null_value=1; - return 0LL; - } - Udf_func_longlong func= (Udf_func_longlong) u_d->func; - longlong tmp=func(&initid, &f_args, &is_null, &error); - if (is_null || error) - { - *null_value=1; - return 0LL; - } - *null_value=0; - return tmp; - } - my_decimal *val_decimal(my_bool *null_value, my_decimal *dec_buf); - void clear() - { - is_null= 0; - Udf_func_clear func= u_d->func_clear; - func(&initid, &is_null, &error); - } - void add(my_bool *null_value) - { - if (get_arguments()) - { - *null_value=1; - return; - } - Udf_func_add func= u_d->func_add; - func(&initid, &f_args, &is_null, &error); - *null_value= (my_bool) (is_null || error); - } - String *val_str(String *str,String *save_str); -}; -void udf_init(void),udf_free(void); -udf_func *find_udf(const char *name, uint len=0,In_C_you_should_use_my_bool_instead() mark_used=0); -void free_udf(udf_func *udf); -int mysql_create_function(THD *thd,udf_func *udf); -int mysql_drop_function(THD *thd,const LEX_STRING *name); -#include "sql_profile.h" -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); -#include "sql_partition.h" -#pragma interface -typedef struct { - longlong list_value; - uint32 partition_id; -} LIST_PART_ENTRY; -typedef struct { - uint32 start_part; - uint32 end_part; -} part_id_range; -struct st_partition_iter; -In_C_you_should_use_my_bool_instead() is_partition_in_list(char *part_name, List<char> list_part_names); -char *are_partitions_in_table(partition_info *new_part_info, - partition_info *old_part_info); -In_C_you_should_use_my_bool_instead() check_reorganise_list(partition_info *new_part_info, - partition_info *old_part_info, - List<char> list_part_names); -handler *get_ha_partition(partition_info *part_info); -int get_parts_for_update(const uchar *old_data, uchar *new_data, - const uchar *rec0, partition_info *part_info, - uint32 *old_part_id, uint32 *new_part_id, - longlong *func_value); -int get_part_for_delete(const uchar *buf, const uchar *rec0, - partition_info *part_info, uint32 *part_id); -void prune_partition_set(const TABLE *table, part_id_range *part_spec); -In_C_you_should_use_my_bool_instead() check_partition_info(partition_info *part_info,handlerton **eng_type, - TABLE *table, handler *file, HA_CREATE_INFO *info); -void set_linear_hash_mask(partition_info *part_info, uint no_parts); -In_C_you_should_use_my_bool_instead() fix_partition_func(THD *thd, TABLE *table, In_C_you_should_use_my_bool_instead() create_table_ind); -char *generate_partition_syntax(partition_info *part_info, - uint *buf_length, In_C_you_should_use_my_bool_instead() use_sql_alloc, - In_C_you_should_use_my_bool_instead() show_partition_options); -In_C_you_should_use_my_bool_instead() partition_key_modified(TABLE *table, const MY_BITMAP *fields); -void get_partition_set(const TABLE *table, uchar *buf, const uint index, - const key_range *key_spec, - part_id_range *part_spec); -void get_full_part_id_from_key(const TABLE *table, uchar *buf, - KEY *key_info, - const key_range *key_spec, - part_id_range *part_spec); -In_C_you_should_use_my_bool_instead() mysql_unpack_partition(THD *thd, const char *part_buf, - uint part_info_len, - const char *part_state, uint part_state_len, - TABLE *table, In_C_you_should_use_my_bool_instead() is_create_table_ind, - handlerton *default_db_type, - In_C_you_should_use_my_bool_instead() *work_part_info_used); -void make_used_partitions_str(partition_info *part_info, String *parts_str); -uint32 get_list_array_idx_for_endpoint(partition_info *part_info, - In_C_you_should_use_my_bool_instead() left_endpoint, - In_C_you_should_use_my_bool_instead() include_endpoint); -uint32 get_partition_id_range_for_endpoint(partition_info *part_info, - In_C_you_should_use_my_bool_instead() left_endpoint, - In_C_you_should_use_my_bool_instead() include_endpoint); -In_C_you_should_use_my_bool_instead() fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, - In_C_you_should_use_my_bool_instead() is_sub_part, In_C_you_should_use_my_bool_instead() is_field_to_be_setup); -In_C_you_should_use_my_bool_instead() check_part_func_fields(Field **ptr, In_C_you_should_use_my_bool_instead() ok_with_charsets); -In_C_you_should_use_my_bool_instead() field_is_partition_charset(Field *field); -typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter); -typedef struct st_partition_iter -{ - partition_iter_func get_next; - In_C_you_should_use_my_bool_instead() ret_null_part, ret_null_part_orig; - struct st_part_num_range - { - uint32 start; - uint32 cur; - uint32 end; - }; - struct st_field_value_range - { - longlong start; - longlong cur; - longlong end; - }; - union - { - struct st_part_num_range part_nums; - struct st_field_value_range field_vals; - }; - partition_info *part_info; -} PARTITION_ITERATOR; -typedef int (*get_partitions_in_range_iter)(partition_info *part_info, - In_C_you_should_use_my_bool_instead() is_subpart, - uchar *min_val, uchar *max_val, - uint flags, - PARTITION_ITERATOR *part_iter); -#include "partition_info.h" -#include "partition_element.h" -enum partition_type { - NOT_A_PARTITION= 0, - RANGE_PARTITION, - HASH_PARTITION, - LIST_PARTITION -}; -enum partition_state { - PART_NORMAL= 0, - PART_IS_DROPPED= 1, - PART_TO_BE_DROPPED= 2, - PART_TO_BE_ADDED= 3, - PART_TO_BE_REORGED= 4, - PART_REORGED_DROPPED= 5, - PART_CHANGED= 6, - PART_IS_CHANGED= 7, - PART_IS_ADDED= 8 -}; -typedef struct p_elem_val -{ - longlong value; - In_C_you_should_use_my_bool_instead() null_value; - In_C_you_should_use_my_bool_instead() unsigned_flag; -} part_elem_value; -struct st_ddl_log_memory_entry; -class partition_element :public Sql_alloc { -public: - List<partition_element> subpartitions; - List<part_elem_value> list_val_list; - ha_rows part_max_rows; - ha_rows part_min_rows; - longlong range_value; - char *partition_name; - char *tablespace_name; - struct st_ddl_log_memory_entry *log_entry; - char* part_comment; - char* data_file_name; - char* index_file_name; - handlerton *engine_type; - enum partition_state part_state; - uint16 nodegroup_id; - In_C_you_should_use_my_bool_instead() has_null_value; - In_C_you_should_use_my_bool_instead() signed_flag; - In_C_you_should_use_my_bool_instead() max_value; - partition_element() - : part_max_rows(0), part_min_rows(0), range_value(0), - partition_name(NULL), tablespace_name(NULL), - log_entry(NULL), part_comment(NULL), - data_file_name(NULL), index_file_name(NULL), - engine_type(NULL), part_state(PART_NORMAL), - nodegroup_id(65535), has_null_value((0)), - signed_flag((0)), max_value((0)) - { - } - partition_element(partition_element *part_elem) - : part_max_rows(part_elem->part_max_rows), - part_min_rows(part_elem->part_min_rows), - range_value(0), partition_name(NULL), - tablespace_name(part_elem->tablespace_name), - part_comment(part_elem->part_comment), - data_file_name(part_elem->data_file_name), - index_file_name(part_elem->index_file_name), - engine_type(part_elem->engine_type), - part_state(part_elem->part_state), - nodegroup_id(part_elem->nodegroup_id), - has_null_value((0)) - { - } - ~partition_element() {} -}; -class partition_info; -typedef int (*get_part_id_func)(partition_info *part_info, - uint32 *part_id, - longlong *func_value); -typedef uint32 (*get_subpart_id_func)(partition_info *part_info); -struct st_ddl_log_memory_entry; -class partition_info : public Sql_alloc -{ -public: - List<partition_element> partitions; - List<partition_element> temp_partitions; - List<char> part_field_list; - List<char> subpart_field_list; - get_part_id_func get_partition_id; - get_part_id_func get_part_partition_id; - get_subpart_id_func get_subpartition_id; - get_part_id_func get_partition_id_charset; - get_part_id_func get_part_partition_id_charset; - get_subpart_id_func get_subpartition_id_charset; - Field **part_field_array; - Field **subpart_field_array; - Field **part_charset_field_array; - Field **subpart_charset_field_array; - Field **full_part_field_array; - Field **full_part_charset_field_array; - MY_BITMAP full_part_field_set; - uchar **part_field_buffers; - uchar **subpart_field_buffers; - uchar **full_part_field_buffers; - uchar **restore_part_field_ptrs; - uchar **restore_subpart_field_ptrs; - uchar **restore_full_part_field_ptrs; - Item *part_expr; - Item *subpart_expr; - Item *item_free_list; - struct st_ddl_log_memory_entry *first_log_entry; - struct st_ddl_log_memory_entry *exec_log_entry; - struct st_ddl_log_memory_entry *frm_log_entry; - MY_BITMAP used_partitions; - union { - longlong *range_int_array; - LIST_PART_ENTRY *list_array; - }; - get_partitions_in_range_iter get_part_iter_for_interval; - get_partitions_in_range_iter get_subpart_iter_for_interval; - longlong err_value; - char* part_info_string; - char *part_func_string; - char *subpart_func_string; - const char *part_state; - partition_element *curr_part_elem; - partition_element *current_partition; - key_map all_fields_in_PF, all_fields_in_PPF, all_fields_in_SPF; - key_map some_fields_in_PF; - handlerton *default_engine_type; - Item_result part_result_type; - partition_type part_type; - partition_type subpart_type; - uint part_info_len; - uint part_state_len; - uint part_func_len; - uint subpart_func_len; - uint no_parts; - uint no_subparts; - uint count_curr_subparts; - uint part_error_code; - uint no_list_values; - uint no_part_fields; - uint no_subpart_fields; - uint no_full_part_fields; - uint has_null_part_id; - uint16 linear_hash_mask; - In_C_you_should_use_my_bool_instead() use_default_partitions; - In_C_you_should_use_my_bool_instead() use_default_no_partitions; - In_C_you_should_use_my_bool_instead() use_default_subpartitions; - In_C_you_should_use_my_bool_instead() use_default_no_subpartitions; - In_C_you_should_use_my_bool_instead() default_partitions_setup; - In_C_you_should_use_my_bool_instead() defined_max_value; - In_C_you_should_use_my_bool_instead() list_of_part_fields; - In_C_you_should_use_my_bool_instead() list_of_subpart_fields; - In_C_you_should_use_my_bool_instead() linear_hash_ind; - In_C_you_should_use_my_bool_instead() fixed; - In_C_you_should_use_my_bool_instead() is_auto_partitioned; - In_C_you_should_use_my_bool_instead() from_openfrm; - In_C_you_should_use_my_bool_instead() has_null_value; - partition_info() - : get_partition_id(NULL), get_part_partition_id(NULL), - get_subpartition_id(NULL), - part_field_array(NULL), subpart_field_array(NULL), - part_charset_field_array(NULL), - subpart_charset_field_array(NULL), - full_part_field_array(NULL), - full_part_charset_field_array(NULL), - part_field_buffers(NULL), subpart_field_buffers(NULL), - full_part_field_buffers(NULL), - restore_part_field_ptrs(NULL), restore_subpart_field_ptrs(NULL), - restore_full_part_field_ptrs(NULL), - part_expr(NULL), subpart_expr(NULL), item_free_list(NULL), - first_log_entry(NULL), exec_log_entry(NULL), frm_log_entry(NULL), - list_array(NULL), err_value(0), - part_info_string(NULL), - part_func_string(NULL), subpart_func_string(NULL), - part_state(NULL), - curr_part_elem(NULL), current_partition(NULL), - default_engine_type(NULL), - part_result_type(INT_RESULT), - part_type(NOT_A_PARTITION), subpart_type(NOT_A_PARTITION), - part_info_len(0), part_state_len(0), - part_func_len(0), subpart_func_len(0), - no_parts(0), no_subparts(0), - count_curr_subparts(0), part_error_code(0), - no_list_values(0), no_part_fields(0), no_subpart_fields(0), - no_full_part_fields(0), has_null_part_id(0), linear_hash_mask(0), - use_default_partitions((1)), use_default_no_partitions((1)), - use_default_subpartitions((1)), use_default_no_subpartitions((1)), - default_partitions_setup((0)), defined_max_value((0)), - list_of_part_fields((0)), list_of_subpart_fields((0)), - linear_hash_ind((0)), fixed((0)), - is_auto_partitioned((0)), from_openfrm((0)), - has_null_value((0)) - { - all_fields_in_PF.clear_all(); - all_fields_in_PPF.clear_all(); - all_fields_in_SPF.clear_all(); - some_fields_in_PF.clear_all(); - partitions.empty(); - temp_partitions.empty(); - part_field_list.empty(); - subpart_field_list.empty(); - } - ~partition_info() {} - partition_info *get_clone(); - In_C_you_should_use_my_bool_instead() is_sub_partitioned() - { - return (subpart_type == NOT_A_PARTITION ? (0) : (1)); - } - uint get_tot_partitions() - { - return no_parts * (is_sub_partitioned() ? no_subparts : 1); - } - In_C_you_should_use_my_bool_instead() set_up_defaults_for_partitioning(handler *file, HA_CREATE_INFO *info, - uint start_no); - char *has_unique_names(); - In_C_you_should_use_my_bool_instead() check_engine_mix(handlerton *engine_type, In_C_you_should_use_my_bool_instead() default_engine); - In_C_you_should_use_my_bool_instead() check_range_constants(); - In_C_you_should_use_my_bool_instead() check_list_constants(); - In_C_you_should_use_my_bool_instead() check_partition_info(THD *thd, handlerton **eng_type, - handler *file, HA_CREATE_INFO *info, - In_C_you_should_use_my_bool_instead() check_partition_function); - void print_no_partition_found(TABLE *table); - In_C_you_should_use_my_bool_instead() set_up_charset_field_preps(); -private: - static int list_part_cmp(const void* a, const void* b); - static int list_part_cmp_unsigned(const void* a, const void* b); - In_C_you_should_use_my_bool_instead() set_up_default_partitions(handler *file, HA_CREATE_INFO *info, - uint start_no); - In_C_you_should_use_my_bool_instead() set_up_default_subpartitions(handler *file, HA_CREATE_INFO *info); - char *create_default_partition_names(uint part_no, uint no_parts, - uint start_no); - char *create_subpartition_name(uint subpart_no, const char *part_name); - In_C_you_should_use_my_bool_instead() has_unique_name(partition_element *element); -}; -uint32 get_next_partition_id_range(struct st_partition_iter* part_iter); -In_C_you_should_use_my_bool_instead() check_partition_dirs(partition_info *part_info); -static inline void init_single_partition_iterator(uint32 part_id, - PARTITION_ITERATOR *part_iter) -{ - part_iter->part_nums.start= part_iter->part_nums.cur= part_id; - part_iter->part_nums.end= part_id+1; - part_iter->get_next= get_next_partition_id_range; -} -static inline -void init_all_partitions_iterator(partition_info *part_info, - PARTITION_ITERATOR *part_iter) -{ - part_iter->part_nums.start= part_iter->part_nums.cur= 0; - part_iter->part_nums.end= part_info->no_parts; - part_iter->get_next= get_next_partition_id_range; -} -class user_var_entry; -class Security_context; -enum enum_var_type -{ - OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL -}; -class sys_var; -#include "item.h" -class Protocol; -struct TABLE_LIST; -void item_init(void); -class Item_field; -class DTCollation { -public: - CHARSET_INFO *collation; - enum Derivation derivation; - uint repertoire; - void set_repertoire_from_charset(CHARSET_INFO *cs) - { - repertoire= cs->state & 4096 ? - 1 : 3; - } - DTCollation() - { - collation= &my_charset_bin; - derivation= DERIVATION_NONE; - repertoire= 3; - } - DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg) - { - collation= collation_arg; - derivation= derivation_arg; - set_repertoire_from_charset(collation_arg); - } - void set(DTCollation &dt) - { - collation= dt.collation; - derivation= dt.derivation; - repertoire= dt.repertoire; - } - void set(CHARSET_INFO *collation_arg, Derivation derivation_arg) - { - collation= collation_arg; - derivation= derivation_arg; - set_repertoire_from_charset(collation_arg); - } - void set(CHARSET_INFO *collation_arg, - Derivation derivation_arg, - uint repertoire_arg) - { - collation= collation_arg; - derivation= derivation_arg; - repertoire= repertoire_arg; - } - void set(CHARSET_INFO *collation_arg) - { - collation= collation_arg; - set_repertoire_from_charset(collation_arg); - } - void set(Derivation derivation_arg) - { derivation= derivation_arg; } - In_C_you_should_use_my_bool_instead() aggregate(DTCollation &dt, uint flags= 0); - In_C_you_should_use_my_bool_instead() set(DTCollation &dt1, DTCollation &dt2, uint flags= 0) - { set(dt1); return aggregate(dt2, flags); } - const char *derivation_name() const - { - switch(derivation) - { - case DERIVATION_IGNORABLE: return "IGNORABLE"; - case DERIVATION_COERCIBLE: return "COERCIBLE"; - case DERIVATION_IMPLICIT: return "IMPLICIT"; - case DERIVATION_SYSCONST: return "SYSCONST"; - case DERIVATION_EXPLICIT: return "EXPLICIT"; - case DERIVATION_NONE: return "NONE"; - default: return "UNKNOWN"; - } - } -}; -struct Hybrid_type_traits; -struct Hybrid_type -{ - longlong integer; - double real; - my_decimal dec_buf[3]; - int used_dec_buf_no; - const Hybrid_type_traits *traits; - Hybrid_type() {} - Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {} -}; -struct Hybrid_type_traits -{ - virtual Item_result type() const { return REAL_RESULT; } - virtual void - fix_length_and_dec(Item *item, Item *arg) const; - virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; } - virtual void add(Hybrid_type *val, Field *f) const - { val->real+= f->val_real(); } - virtual void div(Hybrid_type *val, ulonglong u) const - { val->real/= ((double) (ulonglong) (u)); } - virtual longlong val_int(Hybrid_type *val, In_C_you_should_use_my_bool_instead() unsigned_flag) const - { return (longlong) rint(val->real); } - virtual double val_real(Hybrid_type *val) const { return val->real; } - virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const; - virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; - static const Hybrid_type_traits *instance(); - Hybrid_type_traits() {} - virtual ~Hybrid_type_traits() {} -}; -struct Hybrid_type_traits_decimal: public Hybrid_type_traits -{ - virtual Item_result type() const { return DECIMAL_RESULT; } - virtual void - fix_length_and_dec(Item *arg, Item *item) const; - virtual void set_zero(Hybrid_type *val) const; - virtual void add(Hybrid_type *val, Field *f) const; - virtual void div(Hybrid_type *val, ulonglong u) const; - virtual longlong val_int(Hybrid_type *val, In_C_you_should_use_my_bool_instead() unsigned_flag) const; - virtual double val_real(Hybrid_type *val) const; - virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const - { return &val->dec_buf[val->used_dec_buf_no]; } - virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; - static const Hybrid_type_traits_decimal *instance(); - Hybrid_type_traits_decimal() {}; -}; -struct Hybrid_type_traits_integer: public Hybrid_type_traits -{ - virtual Item_result type() const { return INT_RESULT; } - virtual void - fix_length_and_dec(Item *arg, Item *item) const; - virtual void set_zero(Hybrid_type *val) const - { val->integer= 0; } - virtual void add(Hybrid_type *val, Field *f) const - { val->integer+= f->val_int(); } - virtual void div(Hybrid_type *val, ulonglong u) const - { val->integer/= (longlong) u; } - virtual longlong val_int(Hybrid_type *val, In_C_you_should_use_my_bool_instead() unsigned_flag) const - { return val->integer; } - virtual double val_real(Hybrid_type *val) const - { return (double) val->integer; } - virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const - { - int2my_decimal(30, val->integer, 0, &val->dec_buf[2]); - return &val->dec_buf[2]; - } - virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const - { buf->set(val->integer, &my_charset_bin); return buf;} - static const Hybrid_type_traits_integer *instance(); - Hybrid_type_traits_integer() {}; -}; -void dummy_error_processor(THD *thd, void *data); -void view_error_processor(THD *thd, void *data); -struct Name_resolution_context: Sql_alloc -{ - Name_resolution_context *outer_context; - TABLE_LIST *table_list; - TABLE_LIST *first_name_resolution_table; - TABLE_LIST *last_name_resolution_table; - st_select_lex *select_lex; - void (*error_processor)(THD *, void *); - void *error_processor_data; - In_C_you_should_use_my_bool_instead() resolve_in_select_list; - Security_context *security_ctx; - Name_resolution_context() - :outer_context(0), table_list(0), select_lex(0), - error_processor_data(0), - security_ctx(0) - {} - void init() - { - resolve_in_select_list= (0); - error_processor= &dummy_error_processor; - first_name_resolution_table= NULL; - last_name_resolution_table= NULL; - } - void resolve_in_table_list_only(TABLE_LIST *tables) - { - table_list= first_name_resolution_table= tables; - resolve_in_select_list= (0); - } - void process_error(THD *thd) - { - (*error_processor)(thd, error_processor_data); - } -}; -class Name_resolution_context_state -{ -private: - TABLE_LIST *save_table_list; - TABLE_LIST *save_first_name_resolution_table; - TABLE_LIST *save_next_name_resolution_table; - In_C_you_should_use_my_bool_instead() save_resolve_in_select_list; - TABLE_LIST *save_next_local; -public: - Name_resolution_context_state() {} -public: - void save_state(Name_resolution_context *context, TABLE_LIST *table_list) - { - save_table_list= context->table_list; - save_first_name_resolution_table= context->first_name_resolution_table; - save_resolve_in_select_list= context->resolve_in_select_list; - save_next_local= table_list->next_local; - save_next_name_resolution_table= table_list->next_name_resolution_table; - } - void restore_state(Name_resolution_context *context, TABLE_LIST *table_list) - { - table_list->next_local= save_next_local; - table_list->next_name_resolution_table= save_next_name_resolution_table; - context->table_list= save_table_list; - context->first_name_resolution_table= save_first_name_resolution_table; - context->resolve_in_select_list= save_resolve_in_select_list; - } - TABLE_LIST *get_first_name_resolution_table() - { - return save_first_name_resolution_table; - } -}; -typedef enum monotonicity_info -{ - NON_MONOTONIC, - MONOTONIC_INCREASING, - MONOTONIC_STRICT_INCREASING -} enum_monotonicity_info; -class sp_rcontext; -class Settable_routine_parameter -{ -public: - Settable_routine_parameter() {} - virtual ~Settable_routine_parameter() {} - virtual void set_required_privilege(In_C_you_should_use_my_bool_instead() rw) {}; - virtual In_C_you_should_use_my_bool_instead() set_value(THD *thd, sp_rcontext *ctx, Item **it)= 0; -}; -typedef In_C_you_should_use_my_bool_instead() (Item::*Item_processor) (uchar *arg); -typedef In_C_you_should_use_my_bool_instead() (Item::*Item_analyzer) (uchar **argp); -typedef Item* (Item::*Item_transformer) (uchar *arg); -typedef void (*Cond_traverser) (const Item *item, void *arg); -class Item { - Item(const Item &); - void operator=(Item &); -public: - static void *operator new(size_t size) - { return sql_alloc(size); } - static void *operator new(size_t size, MEM_ROOT *mem_root) - { return alloc_root(mem_root, size); } - static void operator delete(void *ptr,size_t size) { ; } - static void operator delete(void *ptr, MEM_ROOT *mem_root) {} - enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM, - INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM, - COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM, - PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM, - FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, - SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, - PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM, - XPATH_NODESET, XPATH_NODESET_CMP, - VIEW_FIXER_ITEM}; - enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; - enum traverse_order { POSTFIX, PREFIX }; - uint rsize; - String str_value; - char * name; - char * orig_name; - Item *next; - uint32 max_length; - uint name_length; - int8 marker; - uint8 decimals; - my_bool maybe_null; - my_bool null_value; - my_bool unsigned_flag; - my_bool with_sum_func; - my_bool fixed; - my_bool is_autogenerated_name; - DTCollation collation; - my_bool with_subselect; - Item_result cmp_context; - Item(); - Item(THD *thd, Item *item); - virtual ~Item() - { - } - void set_name(const char *str, uint length, CHARSET_INFO *cs); - void rename(char *new_name); - void init_make_field(Send_field *tmp_field,enum enum_field_types type); - virtual void cleanup(); - virtual void make_field(Send_field *field); - Field *make_string_field(TABLE *table); - virtual In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - inline void quick_fix_field() { fixed= 1; } - int save_in_field_no_warnings(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - virtual int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - virtual void save_org_in_field(Field *field) - { (void) save_in_field(field, 1); } - virtual int save_safe_in_field(Field *field) - { return save_in_field(field, 1); } - virtual In_C_you_should_use_my_bool_instead() send(Protocol *protocol, String *str); - virtual In_C_you_should_use_my_bool_instead() eq(const Item *, In_C_you_should_use_my_bool_instead() binary_cmp) const; - virtual Item_result result_type() const { return REAL_RESULT; } - virtual Item_result cast_to_int_type() const { return result_type(); } - virtual enum_field_types string_field_type() const; - virtual enum_field_types field_type() const; - virtual enum Type type() const =0; - virtual enum_monotonicity_info get_monotonicity_info() const - { return NON_MONOTONIC; } - virtual longlong val_int_endpoint(In_C_you_should_use_my_bool_instead() left_endp, In_C_you_should_use_my_bool_instead() *incl_endp) - { assert(0); return 0; } - virtual double val_real()=0; - virtual longlong val_int()=0; - inline ulonglong val_uint() { return (ulonglong) val_int(); } - virtual String *val_str(String *str)=0; - virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0; - virtual In_C_you_should_use_my_bool_instead() val_bool(); - virtual String *val_nodeset(String*) { return 0; } - String *val_string_from_real(String *str); - String *val_string_from_int(String *str); - String *val_string_from_decimal(String *str); - my_decimal *val_decimal_from_real(my_decimal *decimal_value); - my_decimal *val_decimal_from_int(my_decimal *decimal_value); - my_decimal *val_decimal_from_string(my_decimal *decimal_value); - my_decimal *val_decimal_from_date(my_decimal *decimal_value); - my_decimal *val_decimal_from_time(my_decimal *decimal_value); - longlong val_int_from_decimal(); - double val_real_from_decimal(); - int save_time_in_field(Field *field); - int save_date_in_field(Field *field); - int save_str_value_in_field(Field *field, String *result); - virtual Field *get_tmp_table_field() { return 0; } - virtual Field *tmp_table_field(TABLE *t_arg) { return 0; } - virtual const char *full_name() const { return name ? name : "???"; } - virtual double val_result() { return val_real(); } - virtual longlong val_int_result() { return val_int(); } - virtual String *str_result(String* tmp) { return val_str(tmp); } - virtual my_decimal *val_decimal_result(my_decimal *val) - { return val_decimal(val); } - virtual In_C_you_should_use_my_bool_instead() val_bool_result() { return val_bool(); } - virtual table_map used_tables() const { return (table_map) 0L; } - virtual table_map not_null_tables() const { return used_tables(); } - virtual In_C_you_should_use_my_bool_instead() basic_const_item() const { return 0; } - virtual Item *clone_item() { return 0; } - virtual cond_result eq_cmp_result() const { return COND_OK; } - inline uint float_length(uint decimals_par) const - { return decimals != 31 ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;} - virtual uint decimal_precision() const; - inline int decimal_int_part() const - { return my_decimal_int_part(decimal_precision(), decimals); } - virtual In_C_you_should_use_my_bool_instead() const_item() const { return used_tables() == 0; } - virtual In_C_you_should_use_my_bool_instead() const_during_execution() const - { return (used_tables() & ~(((table_map) 1) << (sizeof(table_map)*8-3))) == 0; } - virtual inline void print(String *str, enum_query_type query_type) - { - str->append(full_name()); - } - void print_item_w_name(String *, enum_query_type query_type); - virtual void update_used_tables() {} - virtual void split_sum_func(THD *thd, Item **ref_pointer_array, - List<Item> &fields) {} - void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields, - Item **ref, In_C_you_should_use_my_bool_instead() skip_registered); - virtual In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - virtual In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); - virtual In_C_you_should_use_my_bool_instead() get_date_result(MYSQL_TIME *ltime,uint fuzzydate) - { return get_date(ltime,fuzzydate); } - virtual In_C_you_should_use_my_bool_instead() is_null() { return 0; } - virtual void update_null_value () { (void) val_int(); } - virtual void top_level_item() {} - virtual void set_result_field(Field *field) {} - virtual In_C_you_should_use_my_bool_instead() is_result_field() { return 0; } - virtual In_C_you_should_use_my_bool_instead() is_bool_func() { return 0; } - virtual void save_in_result_field(In_C_you_should_use_my_bool_instead() no_conversions) {} - virtual void no_rows_in_result() {} - virtual Item *copy_or_same(THD *thd) { return this; } - virtual Item *copy_andor_structure(THD *thd) { return this; } - virtual Item *real_item() { return this; } - virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } - static CHARSET_INFO *default_charset(); - virtual CHARSET_INFO *compare_collation() { return NULL; } - virtual In_C_you_should_use_my_bool_instead() walk(Item_processor processor, In_C_you_should_use_my_bool_instead() walk_subquery, uchar *arg) - { - return (this->*processor)(arg); - } - virtual Item* transform(Item_transformer transformer, uchar *arg); - virtual Item* compile(Item_analyzer analyzer, uchar **arg_p, - Item_transformer transformer, uchar *arg_t) - { - if ((this->*analyzer) (arg_p)) - return ((this->*transformer) (arg_t)); - return 0; - } - virtual void traverse_cond(Cond_traverser traverser, - void *arg, traverse_order order) - { - (*traverser)(this, arg); - } - virtual In_C_you_should_use_my_bool_instead() remove_dependence_processor(uchar * arg) { return 0; } - virtual In_C_you_should_use_my_bool_instead() remove_fixed(uchar * arg) { fixed= 0; return 0; } - virtual In_C_you_should_use_my_bool_instead() cleanup_processor(uchar *arg); - virtual In_C_you_should_use_my_bool_instead() collect_item_field_processor(uchar * arg) { return 0; } - virtual In_C_you_should_use_my_bool_instead() find_item_in_field_list_processor(uchar *arg) { return 0; } - virtual In_C_you_should_use_my_bool_instead() change_context_processor(uchar *context) { return 0; } - virtual In_C_you_should_use_my_bool_instead() reset_query_id_processor(uchar *query_id_arg) { return 0; } - virtual In_C_you_should_use_my_bool_instead() is_expensive_processor(uchar *arg) { return 0; } - virtual In_C_you_should_use_my_bool_instead() register_field_in_read_map(uchar *arg) { return 0; } - virtual In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *bool_arg) { return (1);} - virtual In_C_you_should_use_my_bool_instead() subst_argument_checker(uchar **arg) - { - if (*arg) - *arg= NULL; - return (1); - } - virtual Item *equal_fields_propagator(uchar * arg) { return this; } - virtual In_C_you_should_use_my_bool_instead() set_no_const_sub(uchar *arg) { return (0); } - virtual Item *replace_equal_field(uchar * arg) { return this; } - virtual Item *this_item() { return this; } - virtual const Item *this_item() const { return this; } - virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; } - virtual uint cols() { return 1; } - virtual Item* element_index(uint i) { return this; } - virtual Item** addr(uint i) { return 0; } - virtual In_C_you_should_use_my_bool_instead() check_cols(uint c); - virtual In_C_you_should_use_my_bool_instead() null_inside() { return 0; } - virtual void bring_value() {} - Field *tmp_table_field_from_field_type(TABLE *table, In_C_you_should_use_my_bool_instead() fixed_length); - virtual Item_field *filed_for_view_update() { return 0; } - virtual Item *neg_transformer(THD *thd) { return NULL; } - virtual Item *update_value_transformer(uchar *select_arg) { return this; } - virtual Item *safe_charset_converter(CHARSET_INFO *tocs); - void delete_self() - { - cleanup(); - delete this; - } - virtual In_C_you_should_use_my_bool_instead() is_splocal() { return 0; } - virtual Settable_routine_parameter *get_settable_routine_parameter() - { - return 0; - } - virtual In_C_you_should_use_my_bool_instead() result_as_longlong() { return (0); } - In_C_you_should_use_my_bool_instead() is_datetime(); - virtual Field::geometry_type get_geometry_type() const - { return Field::GEOM_GEOMETRY; }; - String *check_well_formed_result(String *str, In_C_you_should_use_my_bool_instead() send_error= 0); - In_C_you_should_use_my_bool_instead() eq_by_collation(Item *item, In_C_you_should_use_my_bool_instead() binary_cmp, CHARSET_INFO *cs); -}; -class sp_head; -class Item_basic_constant :public Item -{ -public: - void cleanup() - { - if (orig_name) - name= orig_name; - } -}; -class Item_sp_variable :public Item -{ -protected: - THD *m_thd; -public: - LEX_STRING m_name; -public: - sp_head *m_sp; -public: - Item_sp_variable(char *sp_var_name_str, uint sp_var_name_length); -public: - In_C_you_should_use_my_bool_instead() fix_fields(THD *thd, Item **); - double val_real(); - longlong val_int(); - String *val_str(String *sp); - my_decimal *val_decimal(my_decimal *decimal_value); - In_C_you_should_use_my_bool_instead() is_null(); -public: - inline void make_field(Send_field *field); - inline In_C_you_should_use_my_bool_instead() const_item() const; - inline int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - inline In_C_you_should_use_my_bool_instead() send(Protocol *protocol, String *str); -}; -inline void Item_sp_variable::make_field(Send_field *field) -{ - Item *it= this_item(); - if (name) - it->set_name(name, (uint) strlen(name), system_charset_info); - else - it->set_name(m_name.str, m_name.length, system_charset_info); - it->make_field(field); -} -inline In_C_you_should_use_my_bool_instead() Item_sp_variable::const_item() const -{ - return (1); -} -inline int Item_sp_variable::save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions) -{ - return this_item()->save_in_field(field, no_conversions); -} -inline In_C_you_should_use_my_bool_instead() Item_sp_variable::send(Protocol *protocol, String *str) -{ - return this_item()->send(protocol, str); -} -class Item_splocal :public Item_sp_variable, - private Settable_routine_parameter -{ - uint m_var_idx; - Type m_type; - Item_result m_result_type; - enum_field_types m_field_type; -public: - uint pos_in_query; - uint len_in_query; - Item_splocal(const LEX_STRING &sp_var_name, uint sp_var_idx, - enum_field_types sp_var_type, - uint pos_in_q= 0, uint len_in_q= 0); - In_C_you_should_use_my_bool_instead() is_splocal() { return 1; } - Item *this_item(); - const Item *this_item() const; - Item **this_item_addr(THD *thd, Item **); - virtual void print(String *str, enum_query_type query_type); -public: - inline const LEX_STRING *my_name() const; - inline uint get_var_idx() const; - inline enum Type type() const; - inline Item_result result_type() const; - inline enum_field_types field_type() const { return m_field_type; } -private: - In_C_you_should_use_my_bool_instead() set_value(THD *thd, sp_rcontext *ctx, Item **it); -public: - Settable_routine_parameter *get_settable_routine_parameter() - { - return this; - } -}; -inline const LEX_STRING *Item_splocal::my_name() const -{ - return &m_name; -} -inline uint Item_splocal::get_var_idx() const -{ - return m_var_idx; -} -inline enum Item::Type Item_splocal::type() const -{ - return m_type; -} -inline Item_result Item_splocal::result_type() const -{ - return m_result_type; -} -class Item_case_expr :public Item_sp_variable -{ -public: - Item_case_expr(uint case_expr_id); -public: - Item *this_item(); - const Item *this_item() const; - Item **this_item_addr(THD *thd, Item **); - inline enum Type type() const; - inline Item_result result_type() const; -public: - virtual void print(String *str, enum_query_type query_type); -private: - uint m_case_expr_id; -}; -inline enum Item::Type Item_case_expr::type() const -{ - return this_item()->type(); -} -inline Item_result Item_case_expr::result_type() const -{ - return this_item()->result_type(); -} -class Item_name_const : public Item -{ - Item *value_item; - Item *name_item; - In_C_you_should_use_my_bool_instead() valid_args; -public: - Item_name_const(Item *name_arg, Item *val); - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - enum Type type() const; - double val_real(); - longlong val_int(); - String *val_str(String *sp); - my_decimal *val_decimal(my_decimal *); - In_C_you_should_use_my_bool_instead() is_null(); - virtual void print(String *str, enum_query_type query_type); - Item_result result_type() const - { - return value_item->result_type(); - } - In_C_you_should_use_my_bool_instead() const_item() const - { - return (1); - } - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions) - { - return value_item->save_in_field(field, no_conversions); - } - In_C_you_should_use_my_bool_instead() send(Protocol *protocol, String *str) - { - return value_item->send(protocol, str); - } -}; -In_C_you_should_use_my_bool_instead() agg_item_collations(DTCollation &c, const char *name, - Item **items, uint nitems, uint flags, int item_sep); -In_C_you_should_use_my_bool_instead() agg_item_collations_for_comparison(DTCollation &c, const char *name, - Item **items, uint nitems, uint flags); -In_C_you_should_use_my_bool_instead() agg_item_charsets(DTCollation &c, const char *name, - Item **items, uint nitems, uint flags, int item_sep); -class Item_num: public Item_basic_constant -{ -public: - Item_num() {} - virtual Item_num *neg()= 0; - Item *safe_charset_converter(CHARSET_INFO *tocs); - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) { return (0);} -}; -class st_select_lex; -class Item_ident :public Item -{ -protected: - const char *orig_db_name; - const char *orig_table_name; - const char *orig_field_name; -public: - Name_resolution_context *context; - const char *db_name; - const char *table_name; - const char *field_name; - In_C_you_should_use_my_bool_instead() alias_name_used; - uint cached_field_index; - TABLE_LIST *cached_table; - st_select_lex *depended_from; - Item_ident(Name_resolution_context *context_arg, - const char *db_name_arg, const char *table_name_arg, - const char *field_name_arg); - Item_ident(THD *thd, Item_ident *item); - const char *full_name() const; - void cleanup(); - In_C_you_should_use_my_bool_instead() remove_dependence_processor(uchar * arg); - virtual void print(String *str, enum_query_type query_type); - virtual In_C_you_should_use_my_bool_instead() change_context_processor(uchar *cntx) - { context= (Name_resolution_context *)cntx; return (0); } - friend In_C_you_should_use_my_bool_instead() insert_fields(THD *thd, Name_resolution_context *context, - const char *db_name, - const char *table_name, List_iterator<Item> *it, - In_C_you_should_use_my_bool_instead() any_privileges); -}; -class Item_ident_for_show :public Item -{ -public: - Field *field; - const char *db_name; - const char *table_name; - Item_ident_for_show(Field *par_field, const char *db_arg, - const char *table_name_arg) - :field(par_field), db_name(db_arg), table_name(table_name_arg) - {} - enum Type type() const { return FIELD_ITEM; } - double val_real() { return field->val_real(); } - longlong val_int() { return field->val_int(); } - String *val_str(String *str) { return field->val_str(str); } - my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); } - void make_field(Send_field *tmp_field); -}; -class Item_equal; -class COND_EQUAL; -class Item_field :public Item_ident -{ -protected: - void set_field(Field *field); -public: - Field *field,*result_field; - Item_equal *item_equal; - In_C_you_should_use_my_bool_instead() no_const_subst; - uint have_privileges; - In_C_you_should_use_my_bool_instead() any_privileges; - Item_field(Name_resolution_context *context_arg, - const char *db_arg,const char *table_name_arg, - const char *field_name_arg); - Item_field(THD *thd, Item_field *item); - Item_field(THD *thd, Name_resolution_context *context_arg, Field *field); - Item_field(Field *field); - enum Type type() const { return FIELD_ITEM; } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - double val_real(); - longlong val_int(); - my_decimal *val_decimal(my_decimal *); - String *val_str(String*); - double val_result(); - longlong val_int_result(); - String *str_result(String* tmp); - my_decimal *val_decimal_result(my_decimal *); - In_C_you_should_use_my_bool_instead() val_bool_result(); - In_C_you_should_use_my_bool_instead() send(Protocol *protocol, String *str_arg); - void reset_field(Field *f); - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - void make_field(Send_field *tmp_field); - int save_in_field(Field *field,In_C_you_should_use_my_bool_instead() no_conversions); - void save_org_in_field(Field *field); - table_map used_tables() const; - enum Item_result result_type () const - { - return field->result_type(); - } - Item_result cast_to_int_type() const - { - return field->cast_to_int_type(); - } - enum_field_types field_type() const - { - return field->type(); - } - enum_monotonicity_info get_monotonicity_info() const - { - return MONOTONIC_STRICT_INCREASING; - } - longlong val_int_endpoint(In_C_you_should_use_my_bool_instead() left_endp, In_C_you_should_use_my_bool_instead() *incl_endp); - Field *get_tmp_table_field() { return result_field; } - Field *tmp_table_field(TABLE *t_arg) { return result_field; } - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - In_C_you_should_use_my_bool_instead() get_date_result(MYSQL_TIME *ltime,uint fuzzydate); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *ltime); - In_C_you_should_use_my_bool_instead() is_null() { return field->is_null(); } - void update_null_value(); - Item *get_tmp_table_item(THD *thd); - In_C_you_should_use_my_bool_instead() collect_item_field_processor(uchar * arg); - In_C_you_should_use_my_bool_instead() find_item_in_field_list_processor(uchar *arg); - In_C_you_should_use_my_bool_instead() register_field_in_read_map(uchar *arg); - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) {return (0);} - void cleanup(); - In_C_you_should_use_my_bool_instead() result_as_longlong() - { - return field->can_be_compared_as_longlong(); - } - Item_equal *find_item_equal(COND_EQUAL *cond_equal); - In_C_you_should_use_my_bool_instead() subst_argument_checker(uchar **arg); - Item *equal_fields_propagator(uchar *arg); - In_C_you_should_use_my_bool_instead() set_no_const_sub(uchar *arg); - Item *replace_equal_field(uchar *arg); - inline uint32 max_disp_length() { return field->max_display_length(); } - Item_field *filed_for_view_update() { return this; } - Item *safe_charset_converter(CHARSET_INFO *tocs); - int fix_outer_field(THD *thd, Field **field, Item **reference); - virtual Item *update_value_transformer(uchar *select_arg); - virtual void print(String *str, enum_query_type query_type); - Field::geometry_type get_geometry_type() const - { - assert(field_type() == MYSQL_TYPE_GEOMETRY); - return field->get_geometry_type(); - } - friend class Item_default_value; - friend class Item_insert_value; - friend class st_select_lex_unit; -}; -class Item_null :public Item_basic_constant -{ -public: - Item_null(char *name_par=0) - { - maybe_null= null_value= (1); - max_length= 0; - name= name_par ? name_par : (char*) "NULL"; - fixed= 1; - collation.set(&my_charset_bin, DERIVATION_IGNORABLE); - } - enum Type type() const { return NULL_ITEM; } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - double val_real(); - longlong val_int(); - String *val_str(String *str); - my_decimal *val_decimal(my_decimal *); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - int save_safe_in_field(Field *field); - In_C_you_should_use_my_bool_instead() send(Protocol *protocol, String *str); - enum Item_result result_type () const { return STRING_RESULT; } - enum_field_types field_type() const { return MYSQL_TYPE_NULL; } - In_C_you_should_use_my_bool_instead() basic_const_item() const { return 1; } - Item *clone_item() { return new Item_null(name); } - In_C_you_should_use_my_bool_instead() is_null() { return 1; } - virtual inline void print(String *str, enum_query_type query_type) - { - str->append(("NULL"), ((size_t) (sizeof("NULL") - 1))); - } - Item *safe_charset_converter(CHARSET_INFO *tocs); - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) {return (0);} -}; -class Item_null_result :public Item_null -{ -public: - Field *result_field; - Item_null_result() : Item_null(), result_field(0) {} - In_C_you_should_use_my_bool_instead() is_result_field() { return result_field != 0; } - void save_in_result_field(In_C_you_should_use_my_bool_instead() no_conversions) - { - save_in_field(result_field, no_conversions); - } - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) {return (1);} -}; -class Item_param :public Item -{ - char cnvbuf[(255*3 +1)]; - String cnvstr; - Item *cnvitem; -public: - enum enum_item_param_state - { - NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE, - STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE, - DECIMAL_VALUE - } state; - String str_value_ptr; - my_decimal decimal_value; - union - { - longlong integer; - double real; - struct CONVERSION_INFO - { - CHARSET_INFO *character_set_client; - CHARSET_INFO *character_set_of_placeholder; - CHARSET_INFO *final_character_set_of_str_value; - } cs_info; - MYSQL_TIME time; - } value; - enum Item_result item_result_type; - enum Type item_type; - enum enum_field_types param_type; - uint pos_in_query; - Item_param(uint pos_in_query_arg); - enum Item_result result_type () const { return item_result_type; } - enum Type type() const { return item_type; } - enum_field_types field_type() const { return param_type; } - double val_real(); - longlong val_int(); - my_decimal *val_decimal(my_decimal*); - String *val_str(String*); - In_C_you_should_use_my_bool_instead() get_time(MYSQL_TIME *tm); - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *tm, uint fuzzydate); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - void set_null(); - void set_int(longlong i, uint32 max_length_arg); - void set_double(double i); - void set_decimal(const char *str, ulong length); - In_C_you_should_use_my_bool_instead() set_str(const char *str, ulong length); - In_C_you_should_use_my_bool_instead() set_longdata(const char *str, ulong length); - void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg); - In_C_you_should_use_my_bool_instead() set_from_user_var(THD *thd, const user_var_entry *entry); - void reset(); - void (*set_param_func)(Item_param *param, uchar **pos, ulong len); - const String *query_val_str(String *str) const; - In_C_you_should_use_my_bool_instead() convert_str_value(THD *thd); - virtual table_map used_tables() const - { return state != NO_VALUE ? (table_map)0 : (((table_map) 1) << (sizeof(table_map)*8-3)); } - virtual void print(String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() is_null() - { assert(state != NO_VALUE); return state == NULL_VALUE; } - In_C_you_should_use_my_bool_instead() basic_const_item() const; - Item *safe_charset_converter(CHARSET_INFO *tocs); - Item *clone_item(); - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - In_C_you_should_use_my_bool_instead() limit_clause_param; - void set_param_type_and_swap_value(Item_param *from); -}; -class Item_int :public Item_num -{ -public: - longlong value; - Item_int(int32 i,uint length= 11) - :value((longlong) i) - { max_length=length; fixed= 1; } - Item_int(longlong i,uint length= 21) - :value(i) - { max_length=length; fixed= 1; } - Item_int(ulonglong i, uint length= 21) - :value((longlong)i) - { max_length=length; fixed= 1; unsigned_flag= 1; } - Item_int(const char *str_arg,longlong i,uint length) :value(i) - { max_length=length; name=(char*) str_arg; fixed= 1; } - Item_int(const char *str_arg, uint length=64); - enum Type type() const { return INT_ITEM; } - enum Item_result result_type () const { return INT_RESULT; } - enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } - longlong val_int() { assert(fixed == 1); return value; } - double val_real() { assert(fixed == 1); return (double) value; } - my_decimal *val_decimal(my_decimal *); - String *val_str(String*); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - In_C_you_should_use_my_bool_instead() basic_const_item() const { return 1; } - Item *clone_item() { return new Item_int(name,value,max_length); } - virtual void print(String *str, enum_query_type query_type); - Item_num *neg() { value= -value; return this; } - uint decimal_precision() const - { return (uint)(max_length - ((value < 0) ? 1 : 0)); } - In_C_you_should_use_my_bool_instead() eq(const Item *, In_C_you_should_use_my_bool_instead() binary_cmp) const; - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *bool_arg) { return (0);} -}; -class Item_uint :public Item_int -{ -public: - Item_uint(const char *str_arg, uint length); - Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {} - Item_uint(const char *str_arg, longlong i, uint length); - double val_real() - { assert(fixed == 1); return ((double) (ulonglong) ((ulonglong)value)); } - String *val_str(String*); - Item *clone_item() { return new Item_uint(name, value, max_length); } - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - virtual void print(String *str, enum_query_type query_type); - Item_num *neg (); - uint decimal_precision() const { return max_length; } - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *bool_arg) { return (0);} -}; -class Item_decimal :public Item_num -{ -protected: - my_decimal decimal_value; -public: - Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset); - Item_decimal(const char *str, const my_decimal *val_arg, - uint decimal_par, uint length); - Item_decimal(my_decimal *value_par); - Item_decimal(longlong val, In_C_you_should_use_my_bool_instead() unsig); - Item_decimal(double val, int precision, int scale); - Item_decimal(const uchar *bin, int precision, int scale); - enum Type type() const { return DECIMAL_ITEM; } - enum Item_result result_type () const { return DECIMAL_RESULT; } - enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } - longlong val_int(); - double val_real(); - String *val_str(String*); - my_decimal *val_decimal(my_decimal *val) { return &decimal_value; } - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - In_C_you_should_use_my_bool_instead() basic_const_item() const { return 1; } - Item *clone_item() - { - return new Item_decimal(name, &decimal_value, decimals, max_length); - } - virtual void print(String *str, enum_query_type query_type); - Item_num *neg() - { - my_decimal_neg(&decimal_value); - unsigned_flag= !decimal_value.sign(); - return this; - } - uint decimal_precision() const { return decimal_value.precision(); } - In_C_you_should_use_my_bool_instead() eq(const Item *, In_C_you_should_use_my_bool_instead() binary_cmp) const; - void set_decimal_value(my_decimal *value_par); - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *bool_arg) { return (0);} -}; -class Item_float :public Item_num -{ - char *presentation; -public: - double value; - Item_float(const char *str_arg, uint length); - Item_float(const char *str,double val_arg,uint decimal_par,uint length) - :value(val_arg) - { - presentation= name=(char*) str; - decimals=(uint8) decimal_par; - max_length=length; - fixed= 1; - } - Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par) - { - decimals= (uint8) decimal_par; - fixed= 1; - } - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - enum Type type() const { return REAL_ITEM; } - enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; } - double val_real() { assert(fixed == 1); return value; } - longlong val_int() - { - assert(fixed == 1); - if (value <= (double) ((long long) 0x8000000000000000LL)) - { - return ((long long) 0x8000000000000000LL); - } - else if (value >= (double) (ulonglong) ((long long) 0x7FFFFFFFFFFFFFFFLL)) - { - return ((long long) 0x7FFFFFFFFFFFFFFFLL); - } - return (longlong) rint(value); - } - String *val_str(String*); - my_decimal *val_decimal(my_decimal *); - In_C_you_should_use_my_bool_instead() basic_const_item() const { return 1; } - Item *clone_item() - { return new Item_float(name, value, decimals, max_length); } - Item_num *neg() { value= -value; return this; } - virtual void print(String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() eq(const Item *, In_C_you_should_use_my_bool_instead() binary_cmp) const; -}; -class Item_static_float_func :public Item_float -{ - const char *func_name; -public: - Item_static_float_func(const char *str, double val_arg, uint decimal_par, - uint length) - :Item_float((char *) 0, val_arg, decimal_par, length), func_name(str) - {} - virtual inline void print(String *str, enum_query_type query_type) - { - str->append(func_name); - } - Item *safe_charset_converter(CHARSET_INFO *tocs); -}; -class Item_string :public Item_basic_constant -{ -public: - Item_string(const char *str,uint length, - CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE, - uint repertoire= 3) - : m_cs_specified((0)) - { - str_value.set_or_copy_aligned(str, length, cs); - collation.set(cs, dv, repertoire); - max_length= str_value.numchars()*cs->mbmaxlen; - set_name(str, length, cs); - decimals=31; - fixed= 1; - } - Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE) - : m_cs_specified((0)) - { - collation.set(cs, dv); - max_length= 0; - set_name(NULL, 0, cs); - decimals= 31; - fixed= 1; - } - Item_string(const char *name_par, const char *str, uint length, - CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE, - uint repertoire= 3) - : m_cs_specified((0)) - { - str_value.set_or_copy_aligned(str, length, cs); - collation.set(cs, dv, repertoire); - max_length= str_value.numchars()*cs->mbmaxlen; - set_name(name_par, 0, cs); - decimals=31; - fixed= 1; - } - void set_str_with_copy(const char *str_arg, uint length_arg) - { - str_value.copy(str_arg, length_arg, collation.collation); - max_length= str_value.numchars() * collation.collation->mbmaxlen; - } - void set_repertoire_from_value() - { - collation.repertoire= my_string_repertoire(str_value.charset(), - str_value.ptr(), - str_value.length()); - } - enum Type type() const { return STRING_ITEM; } - double val_real(); - longlong val_int(); - String *val_str(String*) - { - assert(fixed == 1); - return (String*) &str_value; - } - my_decimal *val_decimal(my_decimal *); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - enum Item_result result_type () const { return STRING_RESULT; } - enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } - In_C_you_should_use_my_bool_instead() basic_const_item() const { return 1; } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - Item *clone_item() - { - return new Item_string(name, str_value.ptr(), - str_value.length(), collation.collation); - } - Item *safe_charset_converter(CHARSET_INFO *tocs); - inline void append(char *str, uint length) - { - str_value.append(str, length); - max_length= str_value.numchars() * collation.collation->mbmaxlen; - } - virtual void print(String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) {return (0);} - inline In_C_you_should_use_my_bool_instead() is_cs_specified() const - { - return m_cs_specified; - } - inline void set_cs_specified(In_C_you_should_use_my_bool_instead() cs_specified) - { - m_cs_specified= cs_specified; - } -private: - In_C_you_should_use_my_bool_instead() m_cs_specified; -}; -class Item_static_string_func :public Item_string -{ - const char *func_name; -public: - Item_static_string_func(const char *name_par, const char *str, uint length, - CHARSET_INFO *cs, - Derivation dv= DERIVATION_COERCIBLE) - :Item_string((char *) 0, str, length, cs, dv), func_name(name_par) - {} - Item *safe_charset_converter(CHARSET_INFO *tocs); - virtual inline void print(String *str, enum_query_type query_type) - { - str->append(func_name); - } - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) {return (1);} -}; -class Item_partition_func_safe_string: public Item_string -{ -public: - Item_partition_func_safe_string(const char *name, uint length, - CHARSET_INFO *cs= NULL): - Item_string(name, length, cs) - {} -}; -class Item_return_date_time :public Item_partition_func_safe_string -{ - enum_field_types date_time_field_type; -public: - Item_return_date_time(const char *name_arg, enum_field_types field_type_arg) - :Item_partition_func_safe_string(name_arg, 0, &my_charset_bin), - date_time_field_type(field_type_arg) - { } - enum_field_types field_type() const { return date_time_field_type; } -}; -class Item_blob :public Item_partition_func_safe_string -{ -public: - Item_blob(const char *name, uint length) : - Item_partition_func_safe_string(name, length, &my_charset_bin) - { max_length= length; } - enum Type type() const { return TYPE_HOLDER; } - enum_field_types field_type() const { return MYSQL_TYPE_BLOB; } -}; -class Item_empty_string :public Item_partition_func_safe_string -{ -public: - Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) : - Item_partition_func_safe_string("",0, cs ? cs : &my_charset_utf8_general_ci) - { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; } - void make_field(Send_field *field); -}; -class Item_return_int :public Item_int -{ - enum_field_types int_field_type; -public: - Item_return_int(const char *name_arg, uint length, - enum_field_types field_type_arg, longlong value= 0) - :Item_int(name_arg, value, length), int_field_type(field_type_arg) - { - unsigned_flag=1; - } - enum_field_types field_type() const { return int_field_type; } -}; -class Item_hex_string: public Item_basic_constant -{ -public: - Item_hex_string() {} - Item_hex_string(const char *str,uint str_length); - enum Type type() const { return VARBIN_ITEM; } - double val_real() - { - assert(fixed == 1); - return (double) (ulonglong) Item_hex_string::val_int(); - } - longlong val_int(); - In_C_you_should_use_my_bool_instead() basic_const_item() const { return 1; } - String *val_str(String*) { assert(fixed == 1); return &str_value; } - my_decimal *val_decimal(my_decimal *); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - enum Item_result result_type () const { return STRING_RESULT; } - enum Item_result cast_to_int_type() const { return INT_RESULT; } - enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } - virtual void print(String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - virtual Item *safe_charset_converter(CHARSET_INFO *tocs); - In_C_you_should_use_my_bool_instead() check_partition_func_processor(uchar *int_arg) {return (0);} -}; -class Item_bin_string: public Item_hex_string -{ -public: - Item_bin_string(const char *str,uint str_length); -}; -class Item_result_field :public Item -{ -public: - Field *result_field; - Item_result_field() :result_field(0) {} - Item_result_field(THD *thd, Item_result_field *item): - Item(thd, item), result_field(item->result_field) - {} - ~Item_result_field() {} - Field *get_tmp_table_field() { return result_field; } - Field *tmp_table_field(TABLE *t_arg) { return result_field; } - table_map used_tables() const { return 1; } - virtual void fix_length_and_dec()=0; - void set_result_field(Field *field) { result_field= field; } - In_C_you_should_use_my_bool_instead() is_result_field() { return 1; } - void save_in_result_field(In_C_you_should_use_my_bool_instead() no_conversions) - { - save_in_field(result_field, no_conversions); - } - void cleanup(); -}; -class Item_ref :public Item_ident -{ -protected: - void set_properties(); -public: - enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF }; - Field *result_field; - Item **ref; - Item_ref(Name_resolution_context *context_arg, - const char *db_arg, const char *table_name_arg, - const char *field_name_arg) - :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg), - result_field(0), ref(0) {} - Item_ref(Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() alias_name_used_arg= (0)); - Item_ref(THD *thd, Item_ref *item) - :Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {} - enum Type type() const { return REF_ITEM; } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const - { - Item *it= ((Item *) item)->real_item(); - return ref && (*ref)->eq(it, binary_cmp); - } - double val_real(); - longlong val_int(); - my_decimal *val_decimal(my_decimal *); - In_C_you_should_use_my_bool_instead() val_bool(); - String *val_str(String* tmp); - In_C_you_should_use_my_bool_instead() is_null(); - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - double val_result(); - longlong val_int_result(); - String *str_result(String* tmp); - my_decimal *val_decimal_result(my_decimal *); - In_C_you_should_use_my_bool_instead() val_bool_result(); - In_C_you_should_use_my_bool_instead() send(Protocol *prot, String *tmp); - void make_field(Send_field *field); - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); - void save_org_in_field(Field *field); - enum Item_result result_type () const { return (*ref)->result_type(); } - enum_field_types field_type() const { return (*ref)->field_type(); } - Field *get_tmp_table_field() - { return result_field ? result_field : (*ref)->get_tmp_table_field(); } - Item *get_tmp_table_item(THD *thd); - table_map used_tables() const - { - return depended_from ? (((table_map) 1) << (sizeof(table_map)*8-2)) : (*ref)->used_tables(); - } - void update_used_tables() - { - if (!depended_from) - (*ref)->update_used_tables(); - } - table_map not_null_tables() const { return (*ref)->not_null_tables(); } - void set_result_field(Field *field) { result_field= field; } - In_C_you_should_use_my_bool_instead() is_result_field() { return 1; } - void save_in_result_field(In_C_you_should_use_my_bool_instead() no_conversions) - { - (*ref)->save_in_field(result_field, no_conversions); - } - Item *real_item() - { - return ref ? (*ref)->real_item() : this; - } - In_C_you_should_use_my_bool_instead() walk(Item_processor processor, In_C_you_should_use_my_bool_instead() walk_subquery, uchar *arg) - { return (*ref)->walk(processor, walk_subquery, arg); } - virtual void print(String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() result_as_longlong() - { - return (*ref)->result_as_longlong(); - } - void cleanup(); - Item_field *filed_for_view_update() - { return (*ref)->filed_for_view_update(); } - virtual Ref_Type ref_type() { return REF; } - uint cols() - { - return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1; - } - Item* element_index(uint i) - { - return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this; - } - Item** addr(uint i) - { - return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0; - } - In_C_you_should_use_my_bool_instead() check_cols(uint c) - { - return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) - : Item::check_cols(c); - } - In_C_you_should_use_my_bool_instead() null_inside() - { - return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0; - } - void bring_value() - { - if (ref && result_type() == ROW_RESULT) - (*ref)->bring_value(); - } -}; -class Item_direct_ref :public Item_ref -{ -public: - Item_direct_ref(Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, - const char *field_name_arg, - In_C_you_should_use_my_bool_instead() alias_name_used_arg= (0)) - :Item_ref(context_arg, item, table_name_arg, - field_name_arg, alias_name_used_arg) - {} - Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} - double val_real(); - longlong val_int(); - String *val_str(String* tmp); - my_decimal *val_decimal(my_decimal *); - In_C_you_should_use_my_bool_instead() val_bool(); - In_C_you_should_use_my_bool_instead() is_null(); - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime,uint fuzzydate); - virtual Ref_Type ref_type() { return DIRECT_REF; } -}; -class Item_direct_view_ref :public Item_direct_ref -{ -public: - Item_direct_view_ref(Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, - const char *field_name_arg) - :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {} - Item_direct_view_ref(THD *thd, Item_direct_ref *item) - :Item_direct_ref(thd, item) {} - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - Item *get_tmp_table_item(THD *thd) - { - Item *item= Item_ref::get_tmp_table_item(thd); - item->name= name; - return item; - } - virtual Ref_Type ref_type() { return VIEW_REF; } -}; -class Item_sum; -class Item_outer_ref :public Item_direct_ref -{ -public: - Item *outer_ref; - Item_sum *in_sum_func; - In_C_you_should_use_my_bool_instead() found_in_select_list; - Item_outer_ref(Name_resolution_context *context_arg, - Item_field *outer_field_arg) - :Item_direct_ref(context_arg, 0, outer_field_arg->table_name, - outer_field_arg->field_name), - outer_ref(outer_field_arg), in_sum_func(0), - found_in_select_list(0) - { - ref= &outer_ref; - set_properties(); - fixed= 0; - } - Item_outer_ref(Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, const char *field_name_arg, - In_C_you_should_use_my_bool_instead() alias_name_used_arg) - :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg, - alias_name_used_arg), - outer_ref(0), in_sum_func(0), found_in_select_list(1) - {} - void save_in_result_field(In_C_you_should_use_my_bool_instead() no_conversions) - { - outer_ref->save_org_in_field(result_field); - } - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - table_map used_tables() const - { - return (*ref)->const_item() ? 0 : (((table_map) 1) << (sizeof(table_map)*8-2)); - } - virtual Ref_Type ref_type() { return OUTER_REF; } -}; -class Item_in_subselect; -class Item_ref_null_helper: public Item_ref -{ -protected: - Item_in_subselect* owner; -public: - Item_ref_null_helper(Name_resolution_context *context_arg, - Item_in_subselect* master, Item **item, - const char *table_name_arg, const char *field_name_arg) - :Item_ref(context_arg, item, table_name_arg, field_name_arg), - owner(master) {} - double val_real(); - longlong val_int(); - String* val_str(String* s); - my_decimal *val_decimal(my_decimal *); - In_C_you_should_use_my_bool_instead() val_bool(); - In_C_you_should_use_my_bool_instead() get_date(MYSQL_TIME *ltime, uint fuzzydate); - virtual void print(String *str, enum_query_type query_type); - table_map used_tables() const - { - return (depended_from ? - (((table_map) 1) << (sizeof(table_map)*8-2)) : - (*ref)->used_tables() | (((table_map) 1) << (sizeof(table_map)*8-1))); - } -}; -class Item_int_with_ref :public Item_int -{ - Item *ref; -public: - Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) : - Item_int(i), ref(ref_arg) - { - unsigned_flag= unsigned_arg; - } - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions) - { - return ref->save_in_field(field, no_conversions); - } - Item *clone_item(); - virtual Item *real_item() { return ref; } -}; -class Item_copy_string :public Item -{ - enum enum_field_types cached_field_type; -public: - Item *item; - Item_copy_string(Item *i) :item(i) - { - null_value=maybe_null=item->maybe_null; - decimals=item->decimals; - max_length=item->max_length; - name=item->name; - cached_field_type= item->field_type(); - } - enum Type type() const { return COPY_STR_ITEM; } - enum Item_result result_type () const { return STRING_RESULT; } - enum_field_types field_type() const { return cached_field_type; } - double val_real() - { - int err_not_used; - char *end_not_used; - return (null_value ? 0.0 : - ((str_value.charset())->cset->strntod((str_value.charset()),((char*) str_value.ptr()),(str_value.length()),(&end_not_used),(&err_not_used)))); - } - longlong val_int() - { - int err; - return null_value ? 0LL : ((str_value.charset())->cset->strntoll((str_value.charset()),(str_value.ptr()),(str_value.length()),(10),((char**) 0),(&err))); - } - String *val_str(String*); - my_decimal *val_decimal(my_decimal *); - void make_field(Send_field *field) { item->make_field(field); } - void copy(); - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions) - { - return save_str_value_in_field(field, &str_value); - } - table_map used_tables() const { return (table_map) 1L; } - In_C_you_should_use_my_bool_instead() const_item() const { return 0; } - In_C_you_should_use_my_bool_instead() is_null() { return null_value; } -}; -class Cached_item :public Sql_alloc -{ -public: - my_bool null_value; - Cached_item() :null_value(0) {} - virtual In_C_you_should_use_my_bool_instead() cmp(void)=0; - virtual ~Cached_item(); -}; -class Cached_item_str :public Cached_item -{ - Item *item; - String value,tmp_value; -public: - Cached_item_str(THD *thd, Item *arg); - In_C_you_should_use_my_bool_instead() cmp(void); - ~Cached_item_str(); -}; -class Cached_item_real :public Cached_item -{ - Item *item; - double value; -public: - Cached_item_real(Item *item_par) :item(item_par),value(0.0) {} - In_C_you_should_use_my_bool_instead() cmp(void); -}; -class Cached_item_int :public Cached_item -{ - Item *item; - longlong value; -public: - Cached_item_int(Item *item_par) :item(item_par),value(0) {} - In_C_you_should_use_my_bool_instead() cmp(void); -}; -class Cached_item_decimal :public Cached_item -{ - Item *item; - my_decimal value; -public: - Cached_item_decimal(Item *item_par); - In_C_you_should_use_my_bool_instead() cmp(void); -}; -class Cached_item_field :public Cached_item -{ - uchar *buff; - Field *field; - uint length; -public: - Cached_item_field(Item_field *item) - { - field= item->field; - buff= (uchar*) sql_calloc(length=field->pack_length()); - } - In_C_you_should_use_my_bool_instead() cmp(void); -}; -class Item_default_value : public Item_field -{ -public: - Item *arg; - Item_default_value(Name_resolution_context *context_arg) - :Item_field(context_arg, (const char *)NULL, (const char *)NULL, - (const char *)NULL), - arg(NULL) {} - Item_default_value(Name_resolution_context *context_arg, Item *a) - :Item_field(context_arg, (const char *)NULL, (const char *)NULL, - (const char *)NULL), - arg(a) {} - enum Type type() const { return DEFAULT_VALUE_ITEM; } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - virtual void print(String *str, enum_query_type query_type); - int save_in_field(Field *field_arg, In_C_you_should_use_my_bool_instead() no_conversions); - table_map used_tables() const { return (table_map)0L; } - In_C_you_should_use_my_bool_instead() walk(Item_processor processor, In_C_you_should_use_my_bool_instead() walk_subquery, uchar *args) - { - return arg->walk(processor, walk_subquery, args) || - (this->*processor)(args); - } - Item *transform(Item_transformer transformer, uchar *args); -}; -class Item_insert_value : public Item_field -{ -public: - Item *arg; - Item_insert_value(Name_resolution_context *context_arg, Item *a) - :Item_field(context_arg, (const char *)NULL, (const char *)NULL, - (const char *)NULL), - arg(a) {} - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - virtual void print(String *str, enum_query_type query_type); - int save_in_field(Field *field_arg, In_C_you_should_use_my_bool_instead() no_conversions) - { - return Item_field::save_in_field(field_arg, no_conversions); - } - table_map used_tables() const { return (((table_map) 1) << (sizeof(table_map)*8-1)); } - In_C_you_should_use_my_bool_instead() walk(Item_processor processor, In_C_you_should_use_my_bool_instead() walk_subquery, uchar *args) - { - return arg->walk(processor, walk_subquery, args) || - (this->*processor)(args); - } -}; -enum trg_action_time_type -{ - TRG_ACTION_BEFORE= 0, TRG_ACTION_AFTER= 1, TRG_ACTION_MAX -}; -class Table_triggers_list; -class Item_trigger_field : public Item_field, - private Settable_routine_parameter -{ -public: - enum row_version_type {OLD_ROW, NEW_ROW}; - row_version_type row_version; - Item_trigger_field *next_trg_field; - uint field_idx; - Table_triggers_list *triggers; - Item_trigger_field(Name_resolution_context *context_arg, - row_version_type row_ver_arg, - const char *field_name_arg, - ulong priv, const In_C_you_should_use_my_bool_instead() ro) - :Item_field(context_arg, - (const char *)NULL, (const char *)NULL, field_name_arg), - row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv), - want_privilege(priv), table_grants(NULL), read_only (ro) - {} - void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info); - enum Type type() const { return TRIGGER_FIELD_ITEM; } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const; - In_C_you_should_use_my_bool_instead() fix_fields(THD *, Item **); - virtual void print(String *str, enum_query_type query_type); - table_map used_tables() const { return (table_map)0L; } - Field *get_tmp_table_field() { return 0; } - Item *copy_or_same(THD *thd) { return this; } - Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } - void cleanup(); -private: - void set_required_privilege(In_C_you_should_use_my_bool_instead() rw); - In_C_you_should_use_my_bool_instead() set_value(THD *thd, sp_rcontext *ctx, Item **it); -public: - Settable_routine_parameter *get_settable_routine_parameter() - { - return (read_only ? 0 : this); - } - In_C_you_should_use_my_bool_instead() set_value(THD *thd, Item **it) - { - return set_value(thd, NULL, it); - } -private: - ulong original_privilege; - ulong want_privilege; - GRANT_INFO *table_grants; - In_C_you_should_use_my_bool_instead() read_only; -}; -class Item_cache: public Item_basic_constant -{ -protected: - Item *example; - table_map used_table_map; - Field *cached_field; - enum enum_field_types cached_field_type; -public: - Item_cache(): - example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING) - { - 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) - { - fixed= 1; - null_value= 1; - } - void set_used_tables(table_map map) { used_table_map= map; } - virtual In_C_you_should_use_my_bool_instead() allocate(uint i) { return 0; } - virtual In_C_you_should_use_my_bool_instead() setup(Item *item) - { - example= item; - max_length= item->max_length; - decimals= item->decimals; - collation.set(item->collation); - unsigned_flag= item->unsigned_flag; - if (item->type() == FIELD_ITEM) - cached_field= ((Item_field *)item)->field; - return 0; - }; - virtual void store(Item *)= 0; - enum Type type() const { return CACHE_ITEM; } - enum_field_types field_type() const { return cached_field_type; } - static Item_cache* get_cache(const Item *item); - table_map used_tables() const { return used_table_map; } - virtual void keep_array() {} - virtual void print(String *str, enum_query_type query_type); - In_C_you_should_use_my_bool_instead() eq_def(Field *field) - { - return cached_field ? cached_field->eq_def (field) : (0); - } - In_C_you_should_use_my_bool_instead() eq(const Item *item, In_C_you_should_use_my_bool_instead() binary_cmp) const - { - return this == item; - } -}; -class Item_cache_int: public Item_cache -{ -protected: - longlong value; -public: - Item_cache_int(): Item_cache(), value(0) {} - Item_cache_int(enum_field_types field_type_arg): - Item_cache(field_type_arg), value(0) {} - void store(Item *item); - void store(Item *item, longlong val_arg); - double val_real() { assert(fixed == 1); return (double) value; } - longlong val_int() { assert(fixed == 1); return value; } - String* val_str(String *str); - my_decimal *val_decimal(my_decimal *); - enum Item_result result_type() const { return INT_RESULT; } - In_C_you_should_use_my_bool_instead() result_as_longlong() { return (1); } -}; -class Item_cache_real: public Item_cache -{ - double value; -public: - Item_cache_real(): Item_cache(), value(0) {} - void store(Item *item); - double val_real() { assert(fixed == 1); return value; } - longlong val_int(); - String* val_str(String *str); - my_decimal *val_decimal(my_decimal *); - enum Item_result result_type() const { return REAL_RESULT; } -}; -class Item_cache_decimal: public Item_cache -{ -protected: - my_decimal decimal_value; -public: - Item_cache_decimal(): Item_cache() {} - void store(Item *item); - double val_real(); - longlong val_int(); - String* val_str(String *str); - my_decimal *val_decimal(my_decimal *); - enum Item_result result_type() const { return DECIMAL_RESULT; } -}; -class Item_cache_str: public Item_cache -{ - char buffer[80]; - String *value, value_buff; - In_C_you_should_use_my_bool_instead() is_varbinary; -public: - Item_cache_str(const Item *item) : - Item_cache(), value(0), - is_varbinary(item->type() == FIELD_ITEM && - ((const Item_field *) item)->field->type() == - MYSQL_TYPE_VARCHAR && - !((const Item_field *) item)->field->has_charset()) - {} - void store(Item *item); - double val_real(); - longlong val_int(); - String* val_str(String *) { assert(fixed == 1); return value; } - my_decimal *val_decimal(my_decimal *); - enum Item_result result_type() const { return STRING_RESULT; } - CHARSET_INFO *charset() const { return value->charset(); }; - int save_in_field(Field *field, In_C_you_should_use_my_bool_instead() no_conversions); -}; -class Item_cache_row: public Item_cache -{ - Item_cache **values; - uint item_count; - In_C_you_should_use_my_bool_instead() save_array; -public: - Item_cache_row() - :Item_cache(), values(0), item_count(2), save_array(0) {} - In_C_you_should_use_my_bool_instead() allocate(uint num); - In_C_you_should_use_my_bool_instead() setup(Item *item); - void store(Item *item); - void illegal_method_call(const char *); - void make_field(Send_field *) - { - illegal_method_call((const char*)"make_field"); - }; - double val_real() - { - illegal_method_call((const char*)"val"); - return 0; - }; - longlong val_int() - { - illegal_method_call((const char*)"val_int"); - return 0; - }; - String *val_str(String *) - { - illegal_method_call((const char*)"val_str"); - return 0; - }; - my_decimal *val_decimal(my_decimal *val) - { - illegal_method_call((const char*)"val_decimal"); - return 0; - }; - enum Item_result result_type() const { return ROW_RESULT; } - uint cols() { return item_count; } - Item *element_index(uint i) { return values[i]; } - Item **addr(uint i) { return (Item **) (values + i); } - In_C_you_should_use_my_bool_instead() check_cols(uint c); - In_C_you_should_use_my_bool_instead() null_inside(); - void bring_value(); - void keep_array() { save_array= 1; } - void cleanup() - { - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("Item_cache_row::cleanup","./sql/item.h",2898,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - Item_cache::cleanup(); - if (save_array) - bzero(values, item_count*sizeof(Item**)); - else - values= 0; - do {_db_return_ (2904, &_db_func_, &_db_file_, &_db_level_); return;} while(0); - } -}; -class Item_type_holder: public Item -{ -protected: - TYPELIB *enum_set_typelib; - enum_field_types fld_type; - Field::geometry_type geometry_type; - void get_full_info(Item *item); - int prev_decimal_int_part; -public: - Item_type_holder(THD*, Item*); - Item_result result_type() const; - enum_field_types field_type() const { return fld_type; }; - enum Type type() const { return TYPE_HOLDER; } - double val_real(); - longlong val_int(); - my_decimal *val_decimal(my_decimal *); - String *val_str(String*); - In_C_you_should_use_my_bool_instead() join_types(THD *thd, Item *); - Field *make_field_by_type(TABLE *table); - static uint32 display_length(Item *item); - static enum_field_types get_real_type(Item *); - Field::geometry_type get_geometry_type() const { return geometry_type; }; -}; -class st_select_lex; -void mark_select_range_as_dependent(THD *thd, - st_select_lex *last_select, - st_select_lex *current_sel, - Field *found_field, Item *found_item, - Item_ident *resolved_item); -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 In_C_you_should_use_my_bool_instead() field_is_equal_to_item(Field *field,Item *item); -extern my_decimal decimal_zero; -void free_items(Item *item); -void cleanup_items(Item *item); -class THD; -void close_thread_tables(THD *thd); -In_C_you_should_use_my_bool_instead() check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables); -In_C_you_should_use_my_bool_instead() check_single_table_access(THD *thd, ulong privilege, - TABLE_LIST *tables, In_C_you_should_use_my_bool_instead() no_errors); -In_C_you_should_use_my_bool_instead() check_routine_access(THD *thd,ulong want_access,char *db,char *name, - In_C_you_should_use_my_bool_instead() is_proc, In_C_you_should_use_my_bool_instead() no_errors); -In_C_you_should_use_my_bool_instead() check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); -In_C_you_should_use_my_bool_instead() check_some_routine_access(THD *thd, const char *db, const char *name, In_C_you_should_use_my_bool_instead() is_proc); -In_C_you_should_use_my_bool_instead() multi_update_precheck(THD *thd, TABLE_LIST *tables); -In_C_you_should_use_my_bool_instead() multi_delete_precheck(THD *thd, TABLE_LIST *tables); -int mysql_multi_update_prepare(THD *thd); -int mysql_multi_delete_prepare(THD *thd); -In_C_you_should_use_my_bool_instead() mysql_insert_select_prepare(THD *thd); -In_C_you_should_use_my_bool_instead() update_precheck(THD *thd, TABLE_LIST *tables); -In_C_you_should_use_my_bool_instead() delete_precheck(THD *thd, TABLE_LIST *tables); -In_C_you_should_use_my_bool_instead() insert_precheck(THD *thd, TABLE_LIST *tables); -In_C_you_should_use_my_bool_instead() 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); -In_C_you_should_use_my_bool_instead() check_string_byte_length(LEX_STRING *str, const char *err_msg, - uint max_byte_length); -In_C_you_should_use_my_bool_instead() check_string_char_length(LEX_STRING *str, const char *err_msg, - uint max_char_length, CHARSET_INFO *cs, - In_C_you_should_use_my_bool_instead() no_error); -In_C_you_should_use_my_bool_instead() test_if_data_home_dir(const char *dir); -In_C_you_should_use_my_bool_instead() parse_sql(THD *thd, - class Lex_input_stream *lip, - class Object_creation_ctx *creation_ctx); -enum enum_mysql_completiontype { - ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7, - COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6 -}; -In_C_you_should_use_my_bool_instead() begin_trans(THD *thd); -In_C_you_should_use_my_bool_instead() end_active_trans(THD *thd); -int end_trans(THD *thd, enum enum_mysql_completiontype completion); -Item *negate_expression(THD *thd, Item *expr); -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); -In_C_you_should_use_my_bool_instead() slow_log_print(THD *thd, const char *query, uint query_length, - ulonglong current_utime); -In_C_you_should_use_my_bool_instead() general_log_print(THD *thd, enum enum_server_command command, - const char *format,...); -In_C_you_should_use_my_bool_instead() general_log_write(THD *thd, enum enum_server_command command, - const char *query, uint query_length); -#include "sql_class.h" -#include "log.h" -class Relay_log_info; -class Format_description_log_event; -class TC_LOG -{ - public: - int using_heuristic_recover(); - TC_LOG() {} - virtual ~TC_LOG() {} - virtual int open(const char *opt_name)=0; - virtual void close()=0; - virtual int log_xid(THD *thd, my_xid xid)=0; - virtual void unlog(ulong cookie, my_xid xid)=0; -}; -class TC_LOG_DUMMY: public TC_LOG -{ -public: - TC_LOG_DUMMY() {} - int open(const char *opt_name) { return 0; } - void close() { } - int log_xid(THD *thd, my_xid xid) { return 1; } - void unlog(ulong cookie, my_xid xid) { } -}; -class TC_LOG_MMAP: public TC_LOG -{ - public: - typedef enum { - POOL, - ERROR, - DIRTY - } PAGE_STATE; - private: - typedef struct st_page { - struct st_page *next; - my_xid *start, *end; - my_xid *ptr; - int size, free; - int waiters; - PAGE_STATE state; - pthread_mutex_t lock; - pthread_cond_t cond; - } PAGE; - char logname[512]; - File fd; - my_off_t file_length; - uint npages, inited; - uchar *data; - struct st_page *pages, *syncing, *active, *pool, *pool_last; - pthread_mutex_t LOCK_active, LOCK_pool, LOCK_sync; - pthread_cond_t COND_pool, COND_active; - public: - TC_LOG_MMAP(): inited(0) {} - int open(const char *opt_name); - void close(); - int log_xid(THD *thd, my_xid xid); - void unlog(ulong cookie, my_xid xid); - int recover(); - private: - void get_active_from_pool(); - int sync(); - int overflow(); -}; -extern TC_LOG *tc_log; -extern TC_LOG_MMAP tc_log_mmap; -extern TC_LOG_DUMMY tc_log_dummy; -class Relay_log_info; -typedef struct st_log_info -{ - char log_file_name[512]; - my_off_t index_file_offset, index_file_start_offset; - my_off_t pos; - In_C_you_should_use_my_bool_instead() fatal; - pthread_mutex_t lock; - st_log_info() - : index_file_offset(0), index_file_start_offset(0), - pos(0), fatal(0) - { - log_file_name[0] = '\0'; - pthread_mutex_init(&lock, NULL); - } - ~st_log_info() { pthread_mutex_destroy(&lock);} -} LOG_INFO; -class Log_event; -class Rows_log_event; -enum enum_log_type { LOG_UNKNOWN, LOG_NORMAL, LOG_BIN }; -enum enum_log_state { LOG_OPENED, LOG_CLOSED, LOG_TO_BE_OPENED }; -class MYSQL_LOG -{ -public: - MYSQL_LOG(); - void init_pthread_objects(); - void cleanup(); - In_C_you_should_use_my_bool_instead() open(const char *log_name, - enum_log_type log_type, - const char *new_name, - enum cache_type io_cache_type_arg); - void init(enum_log_type log_type_arg, - enum cache_type io_cache_type_arg); - void close(uint exiting); - inline In_C_you_should_use_my_bool_instead() is_open() { return log_state != LOG_CLOSED; } - const char *generate_name(const char *log_name, const char *suffix, - In_C_you_should_use_my_bool_instead() strip_ext, char *buff); - int generate_new_name(char *new_name, const char *log_name); - protected: - pthread_mutex_t LOCK_log; - char *name; - char log_file_name[512]; - char time_buff[20], db[(64*3) + 1]; - In_C_you_should_use_my_bool_instead() write_error, inited; - IO_CACHE log_file; - enum_log_type log_type; - volatile enum_log_state log_state; - enum cache_type io_cache_type; - friend class Log_event; -}; -class MYSQL_QUERY_LOG: public MYSQL_LOG -{ -public: - MYSQL_QUERY_LOG() : last_time(0) {} - void reopen_file(); - In_C_you_should_use_my_bool_instead() write(time_t event_time, const char *user_host, - uint user_host_len, int thread_id, - const char *command_type, uint command_type_len, - const char *sql_text, uint sql_text_len); - In_C_you_should_use_my_bool_instead() write(THD *thd, time_t current_time, time_t query_start_arg, - const char *user_host, uint user_host_len, - ulonglong query_utime, ulonglong lock_utime, In_C_you_should_use_my_bool_instead() is_command, - const char *sql_text, uint sql_text_len); - In_C_you_should_use_my_bool_instead() open_slow_log(const char *log_name) - { - char buf[512]; - return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0, - WRITE_CACHE); - } - In_C_you_should_use_my_bool_instead() open_query_log(const char *log_name) - { - char buf[512]; - return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0, - WRITE_CACHE); - } -private: - time_t last_time; -}; -class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG -{ - private: - pthread_mutex_t LOCK_index; - pthread_mutex_t LOCK_prep_xids; - pthread_cond_t COND_prep_xids; - pthread_cond_t update_cond; - ulonglong bytes_written; - IO_CACHE index_file; - char index_file_name[512]; - ulong max_size; - long prepared_xids; - uint file_id; - uint open_count; - int readers_count; - In_C_you_should_use_my_bool_instead() need_start_event; - In_C_you_should_use_my_bool_instead() no_auto_events; - ulonglong m_table_map_version; - int write_to_file(IO_CACHE *cache); - void new_file_without_locking(); - void new_file_impl(In_C_you_should_use_my_bool_instead() need_lock); -public: - MYSQL_LOG::generate_name; - MYSQL_LOG::is_open; - Format_description_log_event *description_event_for_exec, - *description_event_for_queue; - MYSQL_BIN_LOG(); - int open(const char *opt_name); - void close(); - int log_xid(THD *thd, my_xid xid); - void unlog(ulong cookie, my_xid xid); - int recover(IO_CACHE *log, Format_description_log_event *fdle); - In_C_you_should_use_my_bool_instead() is_table_mapped(TABLE *table) const - { - return table->s->table_map_version == table_map_version(); - } - ulonglong table_map_version() const { return m_table_map_version; } - void update_table_map_version() { ++m_table_map_version; } - int flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event); - void reset_bytes_written() - { - bytes_written = 0; - } - void harvest_bytes_written(ulonglong* counter) - { - char buf1[22],buf2[22]; - const char *_db_func_, *_db_file_; uint _db_level_; char **_db_framep_; _db_enter_ ("harvest_bytes_written","./sql/log.h",321,&_db_func_,&_db_file_,&_db_level_, &_db_framep_); - (*counter)+=bytes_written; - do {_db_pargs_(324,"info"); _db_doprnt_ ("counter: %s bytes_written: %s", llstr(*counter,buf1), llstr(bytes_written,buf2));} while(0); - bytes_written=0; - do {_db_return_ (326, &_db_func_, &_db_file_, &_db_level_); return;} while(0); - } - void set_max_size(ulong max_size_arg); - void signal_update(); - void wait_for_update(THD* thd, In_C_you_should_use_my_bool_instead() master_or_slave); - void set_need_start_event() { need_start_event = 1; } - void init(In_C_you_should_use_my_bool_instead() no_auto_events_arg, ulong max_size); - void init_pthread_objects(); - void cleanup(); - In_C_you_should_use_my_bool_instead() open(const char *log_name, - enum_log_type log_type, - const char *new_name, - enum cache_type io_cache_type_arg, - In_C_you_should_use_my_bool_instead() no_auto_events_arg, ulong max_size, - In_C_you_should_use_my_bool_instead() null_created); - In_C_you_should_use_my_bool_instead() open_index_file(const char *index_file_name_arg, - const char *log_name); - void new_file(); - In_C_you_should_use_my_bool_instead() write(Log_event* event_info); - In_C_you_should_use_my_bool_instead() write(THD *thd, IO_CACHE *cache, Log_event *commit_event); - int write_cache(IO_CACHE *cache, In_C_you_should_use_my_bool_instead() lock_log, In_C_you_should_use_my_bool_instead() flush_and_sync); - void start_union_events(THD *thd, query_id_t query_id_param); - void stop_union_events(THD *thd); - In_C_you_should_use_my_bool_instead() is_query_in_union(THD *thd, query_id_t query_id_param); - In_C_you_should_use_my_bool_instead() appendv(const char* buf,uint len,...); - In_C_you_should_use_my_bool_instead() append(Log_event* ev); - void make_log_name(char* buf, const char* log_ident); - In_C_you_should_use_my_bool_instead() is_active(const char* log_file_name); - int update_log_index(LOG_INFO* linfo, In_C_you_should_use_my_bool_instead() need_update_threads); - void rotate_and_purge(uint flags); - In_C_you_should_use_my_bool_instead() flush_and_sync(); - int purge_logs(const char *to_log, In_C_you_should_use_my_bool_instead() included, - In_C_you_should_use_my_bool_instead() need_mutex, In_C_you_should_use_my_bool_instead() need_update_threads, - ulonglong *decrease_log_space); - int purge_logs_before_date(time_t purge_time); - int purge_first_log(Relay_log_info* rli, In_C_you_should_use_my_bool_instead() included); - In_C_you_should_use_my_bool_instead() reset_logs(THD* thd); - void close(uint exiting); - int find_log_pos(LOG_INFO* linfo, const char* log_name, - In_C_you_should_use_my_bool_instead() need_mutex); - int find_next_log(LOG_INFO* linfo, In_C_you_should_use_my_bool_instead() need_mutex); - int get_current_log(LOG_INFO* linfo); - int raw_get_current_log(LOG_INFO* linfo); - uint next_file_id(); - inline char* get_index_fname() { return index_file_name;} - inline char* get_log_fname() { return log_file_name; } - inline char* get_name() { return name; } - inline pthread_mutex_t* get_log_lock() { return &LOCK_log; } - inline IO_CACHE* get_log_file() { return &log_file; } - inline void lock_index() { pthread_mutex_lock(&LOCK_index);} - inline void unlock_index() { pthread_mutex_unlock(&LOCK_index);} - inline IO_CACHE *get_index_file() { return &index_file;} - inline uint32 get_open_count() { return open_count; } -}; -class Log_event_handler -{ -public: - Log_event_handler() {} - virtual In_C_you_should_use_my_bool_instead() init()= 0; - virtual void cleanup()= 0; - virtual In_C_you_should_use_my_bool_instead() log_slow(THD *thd, time_t current_time, - time_t query_start_arg, const char *user_host, - uint user_host_len, ulonglong query_utime, - ulonglong lock_utime, In_C_you_should_use_my_bool_instead() is_command, - const char *sql_text, uint sql_text_len)= 0; - virtual In_C_you_should_use_my_bool_instead() log_error(enum loglevel level, const char *format, - va_list args)= 0; - virtual In_C_you_should_use_my_bool_instead() log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, - const char *command_type, uint command_type_len, - const char *sql_text, uint sql_text_len, - CHARSET_INFO *client_cs)= 0; - virtual ~Log_event_handler() {} -}; -int check_if_log_table(uint db_len, const char *db, uint table_name_len, - const char *table_name, uint check_if_opened); -class Log_to_csv_event_handler: public Log_event_handler -{ - friend class LOGGER; -public: - Log_to_csv_event_handler(); - ~Log_to_csv_event_handler(); - virtual In_C_you_should_use_my_bool_instead() init(); - virtual void cleanup(); - virtual In_C_you_should_use_my_bool_instead() log_slow(THD *thd, time_t current_time, - time_t query_start_arg, const char *user_host, - uint user_host_len, ulonglong query_utime, - ulonglong lock_utime, In_C_you_should_use_my_bool_instead() is_command, - const char *sql_text, uint sql_text_len); - virtual In_C_you_should_use_my_bool_instead() log_error(enum loglevel level, const char *format, - va_list args); - virtual In_C_you_should_use_my_bool_instead() log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, - const char *command_type, uint command_type_len, - const char *sql_text, uint sql_text_len, - CHARSET_INFO *client_cs); - int activate_log(THD *thd, uint log_type); -}; -class Log_to_file_event_handler: public Log_event_handler -{ - MYSQL_QUERY_LOG mysql_log; - MYSQL_QUERY_LOG mysql_slow_log; - In_C_you_should_use_my_bool_instead() is_initialized; -public: - Log_to_file_event_handler(): is_initialized((0)) - {} - virtual In_C_you_should_use_my_bool_instead() init(); - virtual void cleanup(); - virtual In_C_you_should_use_my_bool_instead() log_slow(THD *thd, time_t current_time, - time_t query_start_arg, const char *user_host, - uint user_host_len, ulonglong query_utime, - ulonglong lock_utime, In_C_you_should_use_my_bool_instead() is_command, - const char *sql_text, uint sql_text_len); - virtual In_C_you_should_use_my_bool_instead() log_error(enum loglevel level, const char *format, - va_list args); - virtual In_C_you_should_use_my_bool_instead() log_general(THD *thd, time_t event_time, const char *user_host, - uint user_host_len, int thread_id, - const char *command_type, uint command_type_len, - const char *sql_text, uint sql_text_len, - CHARSET_INFO *client_cs); - void flush(); - void init_pthread_objects(); - MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; } - MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; } -}; -class LOGGER -{ - pthread_rwlock_t LOCK_logger; - uint inited; - Log_to_csv_event_handler *table_log_handler; - Log_to_file_event_handler *file_log_handler; - Log_event_handler *error_log_handler_list[3 + 1]; - Log_event_handler *slow_log_handler_list[3 + 1]; - Log_event_handler *general_log_handler_list[3 + 1]; -public: - In_C_you_should_use_my_bool_instead() is_log_tables_initialized; - LOGGER() : inited(0), table_log_handler(NULL), - file_log_handler(NULL), is_log_tables_initialized((0)) - {} - void lock_shared() { pthread_rwlock_rdlock(&LOCK_logger); } - void lock_exclusive() { pthread_rwlock_wrlock(&LOCK_logger); } - void unlock() { pthread_rwlock_unlock(&LOCK_logger); } - In_C_you_should_use_my_bool_instead() is_log_table_enabled(uint log_table_type); - In_C_you_should_use_my_bool_instead() log_command(THD *thd, enum enum_server_command command); - void init_base(); - void init_log_tables(); - In_C_you_should_use_my_bool_instead() flush_logs(THD *thd); - void cleanup_base(); - void cleanup_end(); - In_C_you_should_use_my_bool_instead() error_log_print(enum loglevel level, const char *format, - va_list args); - In_C_you_should_use_my_bool_instead() slow_log_print(THD *thd, const char *query, uint query_length, - ulonglong current_utime); - In_C_you_should_use_my_bool_instead() general_log_print(THD *thd,enum enum_server_command command, - const char *format, va_list args); - In_C_you_should_use_my_bool_instead() general_log_write(THD *thd, enum enum_server_command command, - const char *query, uint query_length); - int set_handlers(uint error_log_printer, - uint slow_log_printer, - uint general_log_printer); - void init_error_log(uint error_log_printer); - void init_slow_log(uint slow_log_printer); - void init_general_log(uint general_log_printer); - void deactivate_log_handler(THD* thd, uint log_type); - In_C_you_should_use_my_bool_instead() activate_log_handler(THD* thd, uint log_type); - MYSQL_QUERY_LOG *get_slow_log_file_handler() - { - if (file_log_handler) - return file_log_handler->get_mysql_slow_log(); - return NULL; - } - MYSQL_QUERY_LOG *get_log_file_handler() - { - if (file_log_handler) - return file_log_handler->get_mysql_log(); - return NULL; - } -}; -enum enum_binlog_format { - BINLOG_FORMAT_MIXED= 0, - BINLOG_FORMAT_STMT= 1, - BINLOG_FORMAT_ROW= 2, - BINLOG_FORMAT_UNSPEC= 3 -}; -extern TYPELIB binlog_format_typelib; -#include "rpl_tblmap.h" -struct st_table; -typedef st_table TABLE; -class table_mapping { -private: - MEM_ROOT m_mem_root; -public: - enum enum_error { - ERR_NO_ERROR = 0, - ERR_LIMIT_EXCEEDED, - ERR_MEMORY_ALLOCATION - }; - table_mapping(); - ~table_mapping(); - TABLE* get_table(ulong table_id); - int set_table(ulong table_id, TABLE* table); - int remove_table(ulong table_id); - void clear_tables(); - ulong count() const { return m_table_ids.records; } -private: - struct entry { - ulong table_id; - union { - TABLE *table; - entry *next; - }; - }; - entry *find_entry(ulong table_id) - { - return (entry *)hash_search(&m_table_ids, - (uchar*)&table_id, - sizeof(table_id)); - } - int expand(); - entry *m_free; - HASH m_table_ids; -}; -class Reprepare_observer -{ -public: - In_C_you_should_use_my_bool_instead() report_error(THD *thd); - In_C_you_should_use_my_bool_instead() is_invalidated() const { return m_invalidated; } - void reset_reprepare_observer() { m_invalidated= (0); } -private: - In_C_you_should_use_my_bool_instead() m_invalidated; -}; -class Relay_log_info; -class Query_log_event; -class Load_log_event; -class Slave_log_event; -class sp_rcontext; -class sp_cache; -class Lex_input_stream; -class Rows_log_event; -enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE }; -enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME }; -enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE }; -enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON, - DELAY_KEY_WRITE_ALL }; -enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT, - SLAVE_EXEC_MODE_IDEMPOTENT, - SLAVE_EXEC_MODE_LAST_BIT}; -enum enum_mark_columns -{ MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE}; -extern char internal_table_name[2]; -extern char empty_c_string[1]; -extern const char **errmesg; -extern uint tc_heuristic_recover; -typedef struct st_user_var_events -{ - user_var_entry *user_var_event; - char *value; - ulong length; - Item_result type; - uint charset_number; -} BINLOG_USER_VAR_EVENT; -typedef struct st_copy_info { - ha_rows records; - ha_rows deleted; - ha_rows updated; - ha_rows copied; - ha_rows error_count; - ha_rows touched; - enum enum_duplicates handle_duplicates; - int escape_char, last_errno; - In_C_you_should_use_my_bool_instead() ignore; - List<Item> *update_fields; - List<Item> *update_values; - TABLE_LIST *view; -} COPY_INFO; -class Key_part_spec :public Sql_alloc { -public: - const char *field_name; - uint length; - Key_part_spec(const char *name,uint len=0) :field_name(name), length(len) {} - In_C_you_should_use_my_bool_instead() operator==(const Key_part_spec& other) const; - Key_part_spec *clone(MEM_ROOT *mem_root) const - { return new (mem_root) Key_part_spec(*this); } -}; -class Alter_drop :public Sql_alloc { -public: - enum drop_type {KEY, COLUMN }; - const char *name; - enum drop_type type; - Alter_drop(enum drop_type par_type,const char *par_name) - :name(par_name), type(par_type) {} - Alter_drop *clone(MEM_ROOT *mem_root) const - { return new (mem_root) Alter_drop(*this); } -}; -class Alter_column :public Sql_alloc { -public: - const char *name; - Item *def; - Alter_column(const char *par_name,Item *literal) - :name(par_name), def(literal) {} - Alter_column *clone(MEM_ROOT *mem_root) const - { return new (mem_root) Alter_column(*this); } -}; -class Key :public Sql_alloc { -public: - enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY}; - enum Keytype type; - KEY_CREATE_INFO key_create_info; - List<Key_part_spec> columns; - const char *name; - In_C_you_should_use_my_bool_instead() generated; - Key(enum Keytype type_par, const char *name_arg, - KEY_CREATE_INFO *key_info_arg, - In_C_you_should_use_my_bool_instead() generated_arg, List<Key_part_spec> &cols) - :type(type_par), key_create_info(*key_info_arg), columns(cols), - name(name_arg), generated(generated_arg) - {} - Key(const Key &rhs, MEM_ROOT *mem_root); - virtual ~Key() {} - friend In_C_you_should_use_my_bool_instead() foreign_key_prefix(Key *a, Key *b); - virtual Key *clone(MEM_ROOT *mem_root) const - { return new (mem_root) Key(*this, mem_root); } -}; -class Table_ident; -class Foreign_key: public Key { -public: - enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL, - FK_MATCH_PARTIAL, FK_MATCH_SIMPLE}; - enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE, - FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT}; - Table_ident *ref_table; - List<Key_part_spec> ref_columns; - uint delete_opt, update_opt, match_opt; - Foreign_key(const char *name_arg, List<Key_part_spec> &cols, - Table_ident *table, List<Key_part_spec> &ref_cols, - uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg) - :Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols), - ref_table(table), ref_columns(ref_cols), - delete_opt(delete_opt_arg), update_opt(update_opt_arg), - match_opt(match_opt_arg) - {} - Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root); - virtual Key *clone(MEM_ROOT *mem_root) const - { return new (mem_root) Foreign_key(*this, mem_root); } -}; -typedef struct st_mysql_lock -{ - TABLE **table; - uint table_count,lock_count; - THR_LOCK_DATA **locks; -} MYSQL_LOCK; -class LEX_COLUMN : public Sql_alloc -{ -public: - String column; - uint rights; - LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {} -}; -#include "sql_lex.h" -class Table_ident; -class sql_exchange; -class LEX_COLUMN; -class sp_head; -class sp_name; -class sp_instr; -class sp_pcontext; -class st_alter_tablespace; -class partition_info; -class Event_parse_data; -enum enum_sql_command { - SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_ALTER_TABLE, - SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT, - SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX, - SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS, - SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS, - SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX, - SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT, - SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS, - SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS, - SQLCOM_SHOW_TRIGGERS, - SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES, - SQLCOM_GRANT, - SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB, - SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT, - SQLCOM_CREATE_FUNCTION, SQLCOM_DROP_FUNCTION, - SQLCOM_REVOKE,SQLCOM_OPTIMIZE, SQLCOM_CHECK, - SQLCOM_ASSIGN_TO_KEYCACHE, SQLCOM_PRELOAD_KEYS, - SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE, - SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT, - SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT, - SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP, - SQLCOM_BEGIN, SQLCOM_LOAD_MASTER_TABLE, SQLCOM_CHANGE_MASTER, - SQLCOM_RENAME_TABLE, SQLCOM_BACKUP_TABLE, SQLCOM_RESTORE_TABLE, - SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS, - SQLCOM_SHOW_OPEN_TABLES, SQLCOM_LOAD_MASTER_DATA, - SQLCOM_HA_OPEN, SQLCOM_HA_CLOSE, SQLCOM_HA_READ, - SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI, - SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_NEW_MASTER, SQLCOM_DO, - SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS, - SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_STORAGE_ENGINES, SQLCOM_SHOW_PRIVILEGES, - SQLCOM_HELP, SQLCOM_CREATE_USER, SQLCOM_DROP_USER, SQLCOM_RENAME_USER, - SQLCOM_REVOKE_ALL, SQLCOM_CHECKSUM, - SQLCOM_CREATE_PROCEDURE, SQLCOM_CREATE_SPFUNCTION, SQLCOM_CALL, - SQLCOM_DROP_PROCEDURE, SQLCOM_ALTER_PROCEDURE,SQLCOM_ALTER_FUNCTION, - SQLCOM_SHOW_CREATE_PROC, SQLCOM_SHOW_CREATE_FUNC, - SQLCOM_SHOW_STATUS_PROC, SQLCOM_SHOW_STATUS_FUNC, - SQLCOM_PREPARE, SQLCOM_EXECUTE, SQLCOM_DEALLOCATE_PREPARE, - SQLCOM_CREATE_VIEW, SQLCOM_DROP_VIEW, - SQLCOM_CREATE_TRIGGER, SQLCOM_DROP_TRIGGER, - SQLCOM_XA_START, SQLCOM_XA_END, SQLCOM_XA_PREPARE, - SQLCOM_XA_COMMIT, SQLCOM_XA_ROLLBACK, SQLCOM_XA_RECOVER, - SQLCOM_SHOW_PROC_CODE, SQLCOM_SHOW_FUNC_CODE, - SQLCOM_ALTER_TABLESPACE, - SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN, - SQLCOM_SHOW_AUTHORS, SQLCOM_BINLOG_BASE64_EVENT, - SQLCOM_SHOW_PLUGINS, - SQLCOM_SHOW_CONTRIBUTORS, - SQLCOM_CREATE_SERVER, SQLCOM_DROP_SERVER, SQLCOM_ALTER_SERVER, - SQLCOM_CREATE_EVENT, SQLCOM_ALTER_EVENT, SQLCOM_DROP_EVENT, - SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_EVENTS, - SQLCOM_SHOW_CREATE_TRIGGER, - SQLCOM_ALTER_DB_UPGRADE, - SQLCOM_SHOW_PROFILE, SQLCOM_SHOW_PROFILES, - SQLCOM_END -}; -class Delayed_insert; -class select_result; -class Time_zone; -struct system_variables -{ - ulong dynamic_variables_version; - char* dynamic_variables_ptr; - uint dynamic_variables_head; - uint dynamic_variables_size; - ulonglong myisam_max_sort_file_size; - ulonglong max_heap_table_size; - ulonglong tmp_table_size; - ulonglong long_query_time; - ha_rows select_limit; - ha_rows max_join_size; - ulong auto_increment_increment, auto_increment_offset; - ulong bulk_insert_buff_size; - ulong join_buff_size; - ulong max_allowed_packet; - ulong max_error_count; - ulong max_length_for_sort_data; - ulong max_sort_length; - ulong max_tmp_tables; - ulong max_insert_delayed_threads; - ulong min_examined_row_limit; - ulong multi_range_count; - ulong myisam_repair_threads; - ulong myisam_sort_buff_size; - ulong myisam_stats_method; - ulong net_buffer_length; - ulong net_interactive_timeout; - ulong net_read_timeout; - ulong net_retry_count; - ulong net_wait_timeout; - ulong net_write_timeout; - ulong optimizer_prune_level; - ulong optimizer_search_depth; - ulong preload_buff_size; - ulong profiling_history_size; - ulong query_cache_type; - ulong read_buff_size; - ulong read_rnd_buff_size; - ulong div_precincrement; - ulong sortbuff_size; - ulong thread_handling; - ulong tx_isolation; - ulong completion_type; - ulong sql_mode; - ulong max_sp_recursion_depth; - ulong updatable_views_with_limit; - ulong default_week_format; - ulong max_seeks_for_key; - ulong range_alloc_block_size; - ulong query_alloc_block_size; - ulong query_prealloc_size; - ulong trans_alloc_block_size; - ulong trans_prealloc_size; - ulong log_warnings; - ulong group_concat_max_len; - ulong ndb_autoincrement_prefetch_sz; - ulong ndb_index_stat_cache_entries; - ulong ndb_index_stat_update_freq; - ulong binlog_format; - my_thread_id pseudo_thread_id; - my_bool low_priority_updates; - my_bool new_mode; - my_bool old_mode; - my_bool query_cache_wlock_invalidate; - my_bool engine_condition_pushdown; - my_bool keep_files_on_create; - my_bool ndb_force_send; - my_bool ndb_use_copying_alter_table; - my_bool ndb_use_exact_count; - my_bool ndb_use_transactions; - my_bool ndb_index_stat_enable; - my_bool old_alter_table; - my_bool old_passwords; - plugin_ref table_plugin; - CHARSET_INFO *character_set_filesystem; - CHARSET_INFO *character_set_client; - CHARSET_INFO *character_set_results; - CHARSET_INFO *collation_server; - CHARSET_INFO *collation_database; - CHARSET_INFO *collation_connection; - MY_LOCALE *lc_time_names; - Time_zone *time_zone; - DATE_TIME_FORMAT *date_format; - DATE_TIME_FORMAT *datetime_format; - DATE_TIME_FORMAT *time_format; - my_bool sysdate_is_now; -}; -typedef struct system_status_var -{ - ulonglong bytes_received; - ulonglong bytes_sent; - ulong com_other; - ulong com_stat[(uint) SQLCOM_END]; - ulong created_tmp_disk_tables; - ulong created_tmp_tables; - ulong ha_commit_count; - ulong ha_delete_count; - ulong ha_read_first_count; - ulong ha_read_last_count; - ulong ha_read_key_count; - ulong ha_read_next_count; - ulong ha_read_prev_count; - ulong ha_read_rnd_count; - ulong ha_read_rnd_next_count; - ulong ha_rollback_count; - ulong ha_update_count; - ulong ha_write_count; - ulong ha_prepare_count; - ulong ha_discover_count; - ulong ha_savepoint_count; - ulong ha_savepoint_rollback_count; - ulong key_blocks_changed; - ulong key_blocks_used; - ulong key_cache_r_requests; - ulong key_cache_read; - ulong key_cache_w_requests; - ulong key_cache_write; - ulong net_big_packet_count; - ulong opened_tables; - ulong opened_shares; - ulong select_full_join_count; - ulong select_full_range_join_count; - ulong select_range_count; - ulong select_range_check_count; - ulong select_scan_count; - ulong long_query_count; - ulong filesort_merge_passes; - ulong filesort_range_count; - ulong filesort_rows; - ulong filesort_scan_count; - ulong com_stmt_prepare; - ulong com_stmt_reprepare; - ulong com_stmt_execute; - ulong com_stmt_send_long_data; - ulong com_stmt_fetch; - ulong com_stmt_reset; - ulong com_stmt_close; - double last_query_cost; -} STATUS_VAR; -void mark_transaction_to_rollback(THD *thd, In_C_you_should_use_my_bool_instead() all); -#include "sql_acl.h" -#include "slave.h" -#include "log.h" -#include "my_list.h" -#include "rpl_filter.h" -#include "mysql.h" -#include "mysql_version.h" -#include "mysql_com.h" -#include "mysql_time.h" -#include "my_list.h" -extern unsigned int mysql_port; -extern char *mysql_unix_port; -typedef struct st_mysql_field { - char *name; - char *org_name; - char *table; - char *org_table; - char *db; - char *catalog; - char *def; - unsigned long length; - unsigned long max_length; - unsigned int name_length; - unsigned int org_name_length; - unsigned int table_length; - unsigned int org_table_length; - unsigned int db_length; - unsigned int catalog_length; - unsigned int def_length; - unsigned int flags; - unsigned int decimals; - unsigned int charsetnr; - enum enum_field_types type; - void *extension; -} MYSQL_FIELD; -typedef char **MYSQL_ROW; -typedef unsigned int MYSQL_FIELD_OFFSET; -#include "typelib.h" -typedef struct st_mysql_rows { - struct st_mysql_rows *next; - MYSQL_ROW data; - unsigned long length; -} MYSQL_ROWS; -typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; -#include "my_alloc.h" -typedef struct embedded_query_result EMBEDDED_QUERY_RESULT; -typedef struct st_mysql_data { - MYSQL_ROWS *data; - struct embedded_query_result *embedded_info; - MEM_ROOT alloc; - my_ulonglong rows; - unsigned int fields; - void *extension; -} MYSQL_DATA; -enum mysql_option -{ - MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, - MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, - MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, - MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, - MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, - MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, - MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, - MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT -}; -struct st_mysql_options { - unsigned int connect_timeout, read_timeout, write_timeout; - unsigned int port, protocol; - unsigned long client_flag; - char *host,*user,*password,*unix_socket,*db; - struct st_dynamic_array *init_commands; - char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; - char *ssl_key; - char *ssl_cert; - char *ssl_ca; - char *ssl_capath; - char *ssl_cipher; - char *shared_memory_base_name; - unsigned long max_allowed_packet; - my_bool use_ssl; - my_bool compress,named_pipe; - my_bool rpl_probe; - my_bool rpl_parse; - my_bool no_master_reads; - my_bool separate_thread; - enum mysql_option methods_to_use; - char *client_ip; - my_bool secure_auth; - my_bool report_data_truncation; - int (*local_infile_init)(void **, const char *, void *); - int (*local_infile_read)(void *, char *, unsigned int); - void (*local_infile_end)(void *); - int (*local_infile_error)(void *, char *, unsigned int); - void *local_infile_userdata; - void *extension; -}; -enum mysql_status -{ - MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT -}; -enum mysql_protocol_type -{ - MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, - MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY -}; -enum mysql_rpl_type -{ - MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN -}; -typedef struct character_set -{ - unsigned int number; - unsigned int state; - const char *csname; - const char *name; - const char *comment; - const char *dir; - unsigned int mbminlen; - unsigned int mbmaxlen; -} MY_CHARSET_INFO; -struct st_mysql_methods; -struct st_mysql_stmt; -typedef struct st_mysql -{ - NET net; - unsigned char *connector_fd; - char *host,*user,*passwd,*unix_socket,*server_version,*host_info; - char *info, *db; - struct charset_info_st *charset; - MYSQL_FIELD *fields; - MEM_ROOT field_alloc; - my_ulonglong affected_rows; - my_ulonglong insert_id; - my_ulonglong extra_info; - unsigned long thread_id; - unsigned long packet_length; - unsigned int port; - unsigned long client_flag,server_capabilities; - unsigned int protocol_version; - unsigned int field_count; - unsigned int server_status; - unsigned int server_language; - unsigned int warning_count; - struct st_mysql_options options; - enum mysql_status status; - my_bool free_me; - my_bool reconnect; - char scramble[20 +1]; - my_bool rpl_pivot; - struct st_mysql* master, *next_slave; - struct st_mysql* last_used_slave; - struct st_mysql* last_used_con; - LIST *stmts; - const struct st_mysql_methods *methods; - void *thd; - my_bool *unbuffered_fetch_owner; - char *info_buffer; - void *extension; -} MYSQL; -typedef struct st_mysql_res { - my_ulonglong row_count; - MYSQL_FIELD *fields; - MYSQL_DATA *data; - MYSQL_ROWS *data_cursor; - unsigned long *lengths; - MYSQL *handle; - const struct st_mysql_methods *methods; - MYSQL_ROW row; - MYSQL_ROW current_row; - MEM_ROOT field_alloc; - unsigned int field_count, current_field; - my_bool eof; - my_bool unbuffered_fetch_cancelled; - void *extension; -} MYSQL_RES; -typedef struct st_mysql_manager -{ - NET net; - char *host, *user, *passwd; - char *net_buf, *net_buf_pos, *net_data_end; - unsigned int port; - int cmd_status; - int last_errno; - int net_buf_size; - my_bool free_me; - my_bool eof; - char last_error[256]; - void *extension; -} MYSQL_MANAGER; -typedef struct st_mysql_parameters -{ - unsigned long *p_max_allowed_packet; - unsigned long *p_net_buffer_length; - void *extension; -} MYSQL_PARAMETERS; -int mysql_server_init(int argc, char **argv, char **groups); -void mysql_server_end(void); -MYSQL_PARAMETERS * mysql_get_parameters(void); -my_bool mysql_thread_init(void); -void mysql_thread_end(void); -my_ulonglong mysql_num_rows(MYSQL_RES *res); -unsigned int mysql_num_fields(MYSQL_RES *res); -my_bool mysql_eof(MYSQL_RES *res); -MYSQL_FIELD * mysql_fetch_field_direct(MYSQL_RES *res, - unsigned int fieldnr); -MYSQL_FIELD * mysql_fetch_fields(MYSQL_RES *res); -MYSQL_ROW_OFFSET mysql_row_tell(MYSQL_RES *res); -MYSQL_FIELD_OFFSET mysql_field_tell(MYSQL_RES *res); -unsigned int mysql_field_count(MYSQL *mysql); -my_ulonglong mysql_affected_rows(MYSQL *mysql); -my_ulonglong mysql_insert_id(MYSQL *mysql); -unsigned int mysql_errno(MYSQL *mysql); -const char * mysql_error(MYSQL *mysql); -const char * mysql_sqlstate(MYSQL *mysql); -unsigned int mysql_warning_count(MYSQL *mysql); -const char * mysql_info(MYSQL *mysql); -unsigned long mysql_thread_id(MYSQL *mysql); -const char * mysql_character_set_name(MYSQL *mysql); -int mysql_set_character_set(MYSQL *mysql, const char *csname); -MYSQL * mysql_init(MYSQL *mysql); -my_bool mysql_ssl_set(MYSQL *mysql, const char *key, - const char *cert, const char *ca, - const char *capath, const char *cipher); -const char * mysql_get_ssl_cipher(MYSQL *mysql); -my_bool mysql_change_user(MYSQL *mysql, const char *user, - const char *passwd, const char *db); -MYSQL * mysql_real_connect(MYSQL *mysql, const char *host, - const char *user, - const char *passwd, - const char *db, - unsigned int port, - const char *unix_socket, - unsigned long clientflag); -int mysql_select_db(MYSQL *mysql, const char *db); -int mysql_query(MYSQL *mysql, const char *q); -int mysql_send_query(MYSQL *mysql, const char *q, - unsigned long length); -int mysql_real_query(MYSQL *mysql, const char *q, - unsigned long length); -MYSQL_RES * mysql_store_result(MYSQL *mysql); -MYSQL_RES * mysql_use_result(MYSQL *mysql); -my_bool mysql_master_query(MYSQL *mysql, const char *q, - unsigned long length); -my_bool mysql_master_send_query(MYSQL *mysql, const char *q, - unsigned long length); -my_bool mysql_slave_query(MYSQL *mysql, const char *q, - unsigned long length); -my_bool mysql_slave_send_query(MYSQL *mysql, const char *q, - unsigned long length); -void mysql_get_character_set_info(MYSQL *mysql, - MY_CHARSET_INFO *charset); -void -mysql_set_local_infile_handler(MYSQL *mysql, - int (*local_infile_init)(void **, const char *, - void *), - int (*local_infile_read)(void *, char *, - unsigned int), - void (*local_infile_end)(void *), - int (*local_infile_error)(void *, char*, - unsigned int), - void *); -void -mysql_set_local_infile_default(MYSQL *mysql); -void mysql_enable_rpl_parse(MYSQL* mysql); -void mysql_disable_rpl_parse(MYSQL* mysql); -int mysql_rpl_parse_enabled(MYSQL* mysql); -void mysql_enable_reads_from_master(MYSQL* mysql); -void mysql_disable_reads_from_master(MYSQL* mysql); -my_bool mysql_reads_from_master_enabled(MYSQL* mysql); -enum mysql_rpl_type mysql_rpl_query_type(const char* q, int len); -my_bool mysql_rpl_probe(MYSQL* mysql); -int mysql_set_master(MYSQL* mysql, const char* host, - unsigned int port, - const char* user, - const char* passwd); -int mysql_add_slave(MYSQL* mysql, const char* host, - unsigned int port, - const char* user, - const char* passwd); -int mysql_shutdown(MYSQL *mysql, - enum mysql_enum_shutdown_level - shutdown_level); -int mysql_dump_debug_info(MYSQL *mysql); -int mysql_refresh(MYSQL *mysql, - unsigned int refresh_options); -int mysql_kill(MYSQL *mysql,unsigned long pid); -int mysql_set_server_option(MYSQL *mysql, - enum enum_mysql_set_option - option); -int mysql_ping(MYSQL *mysql); -const char * mysql_stat(MYSQL *mysql); -const char * mysql_get_server_info(MYSQL *mysql); -const char * mysql_get_client_info(void); -unsigned long mysql_get_client_version(void); -const char * mysql_get_host_info(MYSQL *mysql); -unsigned long mysql_get_server_version(MYSQL *mysql); -unsigned int mysql_get_proto_info(MYSQL *mysql); -MYSQL_RES * mysql_list_dbs(MYSQL *mysql,const char *wild); -MYSQL_RES * mysql_list_tables(MYSQL *mysql,const char *wild); -MYSQL_RES * mysql_list_processes(MYSQL *mysql); -int mysql_options(MYSQL *mysql,enum mysql_option option, - const void *arg); -void mysql_free_result(MYSQL_RES *result); -void mysql_data_seek(MYSQL_RES *result, - my_ulonglong offset); -MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, - MYSQL_ROW_OFFSET offset); -MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES *result, - MYSQL_FIELD_OFFSET offset); -MYSQL_ROW mysql_fetch_row(MYSQL_RES *result); -unsigned long * mysql_fetch_lengths(MYSQL_RES *result); -MYSQL_FIELD * mysql_fetch_field(MYSQL_RES *result); -MYSQL_RES * mysql_list_fields(MYSQL *mysql, const char *table, - const char *wild); -unsigned long mysql_escape_string(char *to,const char *from, - unsigned long from_length); -unsigned long mysql_hex_string(char *to,const char *from, - unsigned long from_length); -unsigned long mysql_real_escape_string(MYSQL *mysql, - char *to,const char *from, - unsigned long length); -void mysql_debug(const char *debug); -void myodbc_remove_escape(MYSQL *mysql,char *name); -unsigned int mysql_thread_safe(void); -my_bool mysql_embedded(void); -MYSQL_MANAGER* mysql_manager_init(MYSQL_MANAGER* con); -MYSQL_MANAGER* mysql_manager_connect(MYSQL_MANAGER* con, - const char* host, - const char* user, - const char* passwd, - unsigned int port); -void mysql_manager_close(MYSQL_MANAGER* con); -int mysql_manager_command(MYSQL_MANAGER* con, - const char* cmd, int cmd_len); -int mysql_manager_fetch_line(MYSQL_MANAGER* con, - char* res_buf, - int res_buf_size); -my_bool mysql_read_query_result(MYSQL *mysql); -enum enum_mysql_stmt_state -{ - MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, - MYSQL_STMT_FETCH_DONE -}; -typedef struct st_mysql_bind -{ - unsigned long *length; - my_bool *is_null; - void *buffer; - my_bool *error; - unsigned char *row_ptr; - void (*store_param_func)(NET *net, struct st_mysql_bind *param); - void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *, - unsigned char **row); - void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *, - unsigned char **row); - unsigned long buffer_length; - unsigned long offset; - unsigned long length_value; - unsigned int param_number; - unsigned int pack_length; - enum enum_field_types buffer_type; - my_bool error_value; - my_bool is_unsigned; - my_bool long_data_used; - my_bool is_null_value; - void *extension; -} MYSQL_BIND; -typedef struct st_mysql_stmt -{ - MEM_ROOT mem_root; - LIST list; - MYSQL *mysql; - MYSQL_BIND *params; - MYSQL_BIND *bind; - MYSQL_FIELD *fields; - MYSQL_DATA result; - MYSQL_ROWS *data_cursor; - int (*read_row_func)(struct st_mysql_stmt *stmt, - unsigned char **row); - my_ulonglong affected_rows; - my_ulonglong insert_id; - unsigned long stmt_id; - unsigned long flags; - unsigned long prefetch_rows; - unsigned int server_status; - unsigned int last_errno; - unsigned int param_count; - unsigned int field_count; - enum enum_mysql_stmt_state state; - char last_error[512]; - char sqlstate[5 +1]; - my_bool send_types_to_server; - my_bool bind_param_done; - unsigned char bind_result_done; - my_bool unbuffered_fetch_cancelled; - my_bool update_max_length; - void *extension; -} MYSQL_STMT; -enum enum_stmt_attr_type -{ - STMT_ATTR_UPDATE_MAX_LENGTH, - STMT_ATTR_CURSOR_TYPE, - STMT_ATTR_PREFETCH_ROWS -}; -typedef struct st_mysql_methods -{ - my_bool (*read_query_result)(MYSQL *mysql); - my_bool (*advanced_command)(MYSQL *mysql, - enum enum_server_command command, - const unsigned char *header, - unsigned long header_length, - const unsigned char *arg, - unsigned long arg_length, - my_bool skip_check, - MYSQL_STMT *stmt); - MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields, - unsigned int fields); - MYSQL_RES * (*use_result)(MYSQL *mysql); - void (*fetch_lengths)(unsigned long *to, - MYSQL_ROW column, unsigned int field_count); - void (*flush_use_result)(MYSQL *mysql); - MYSQL_FIELD * (*list_fields)(MYSQL *mysql); - my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt); - int (*stmt_execute)(MYSQL_STMT *stmt); - int (*read_binary_rows)(MYSQL_STMT *stmt); - int (*unbuffered_fetch)(MYSQL *mysql, char **row); - void (*free_embedded_thd)(MYSQL *mysql); - const char *(*read_statistics)(MYSQL *mysql); - my_bool (*next_result)(MYSQL *mysql); - int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd); - int (*read_rows_from_cursor)(MYSQL_STMT *stmt); -} MYSQL_METHODS; -MYSQL_STMT * mysql_stmt_init(MYSQL *mysql); -int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, - unsigned long length); -int mysql_stmt_execute(MYSQL_STMT *stmt); -int mysql_stmt_fetch(MYSQL_STMT *stmt); -int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, - unsigned int column, - unsigned long offset); -int mysql_stmt_store_result(MYSQL_STMT *stmt); -unsigned long mysql_stmt_param_count(MYSQL_STMT * stmt); -my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, - enum enum_stmt_attr_type attr_type, - const void *attr); -my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, - enum enum_stmt_attr_type attr_type, - void *attr); -my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); -my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); -my_bool mysql_stmt_close(MYSQL_STMT * stmt); -my_bool mysql_stmt_reset(MYSQL_STMT * stmt); -my_bool mysql_stmt_free_result(MYSQL_STMT *stmt); -my_bool mysql_stmt_send_long_data(MYSQL_STMT *stmt, - unsigned int param_number, - const char *data, - unsigned long length); -MYSQL_RES * mysql_stmt_result_metadata(MYSQL_STMT *stmt); -MYSQL_RES * mysql_stmt_param_metadata(MYSQL_STMT *stmt); -unsigned int mysql_stmt_errno(MYSQL_STMT * stmt); -const char * mysql_stmt_error(MYSQL_STMT * stmt); -const char * mysql_stmt_sqlstate(MYSQL_STMT * stmt); -MYSQL_ROW_OFFSET mysql_stmt_row_seek(MYSQL_STMT *stmt, - MYSQL_ROW_OFFSET offset); -MYSQL_ROW_OFFSET mysql_stmt_row_tell(MYSQL_STMT *stmt); -void mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset); -my_ulonglong mysql_stmt_num_rows(MYSQL_STMT *stmt); -my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT *stmt); -my_ulonglong mysql_stmt_insert_id(MYSQL_STMT *stmt); -unsigned int mysql_stmt_field_count(MYSQL_STMT *stmt); -my_bool mysql_commit(MYSQL * mysql); -my_bool mysql_rollback(MYSQL * mysql); -my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode); -my_bool mysql_more_results(MYSQL *mysql); -int mysql_next_result(MYSQL *mysql); -void mysql_close(MYSQL *sock); -typedef struct st_table_rule_ent -{ - char* db; - char* tbl_name; - uint key_len; -} TABLE_RULE_ENT; -class Rpl_filter -{ -public: - Rpl_filter(); - ~Rpl_filter(); - Rpl_filter(Rpl_filter const&); - Rpl_filter& operator=(Rpl_filter const&); - In_C_you_should_use_my_bool_instead() tables_ok(const char* db, TABLE_LIST* tables); - In_C_you_should_use_my_bool_instead() db_ok(const char* db); - In_C_you_should_use_my_bool_instead() db_ok_with_wild_table(const char *db); - In_C_you_should_use_my_bool_instead() is_on(); - int add_do_table(const char* table_spec); - int add_ignore_table(const char* table_spec); - int add_wild_do_table(const char* table_spec); - int add_wild_ignore_table(const char* table_spec); - void add_do_db(const char* db_spec); - void add_ignore_db(const char* db_spec); - void add_db_rewrite(const char* from_db, const char* to_db); - void get_do_table(String* str); - void get_ignore_table(String* str); - void get_wild_do_table(String* str); - void get_wild_ignore_table(String* str); - const char* get_rewrite_db(const char* db, size_t *new_len); - I_List<i_string>* get_do_db(); - I_List<i_string>* get_ignore_db(); -private: - In_C_you_should_use_my_bool_instead() table_rules_on; - void init_table_rule_hash(HASH* h, In_C_you_should_use_my_bool_instead()* h_inited); - void init_table_rule_array(DYNAMIC_ARRAY* a, In_C_you_should_use_my_bool_instead()* a_inited); - int add_table_rule(HASH* h, const char* table_spec); - int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec); - void free_string_array(DYNAMIC_ARRAY *a); - void table_rule_ent_hash_to_str(String* s, HASH* h, In_C_you_should_use_my_bool_instead() inited); - void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a, - In_C_you_should_use_my_bool_instead() inited); - TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len); - HASH do_table; - HASH ignore_table; - DYNAMIC_ARRAY wild_do_table; - DYNAMIC_ARRAY wild_ignore_table; - In_C_you_should_use_my_bool_instead() do_table_inited; - In_C_you_should_use_my_bool_instead() ignore_table_inited; - In_C_you_should_use_my_bool_instead() wild_do_table_inited; - In_C_you_should_use_my_bool_instead() wild_ignore_table_inited; - I_List<i_string> do_db; - I_List<i_string> ignore_db; - I_List<i_string_pair> rewrite_db; -}; -extern Rpl_filter *rpl_filter; -extern Rpl_filter *binlog_filter; -#include "rpl_tblmap.h" -class Relay_log_info; -class Master_info; -extern ulong master_retry_count; -extern MY_BITMAP slave_error_mask; -extern In_C_you_should_use_my_bool_instead() use_slave_mask; -extern char *slave_load_tmpdir; -extern char *master_info_file, *relay_log_info_file; -extern char *opt_relay_logname, *opt_relaylog_index_name; -extern my_bool opt_skip_slave_start, opt_reckless_slave; -extern my_bool opt_log_slave_updates; -extern ulonglong relay_log_space_limit; -int init_slave(); -void init_slave_skip_errors(const char* arg); -In_C_you_should_use_my_bool_instead() flush_relay_log_info(Relay_log_info* rli); -int register_slave_on_master(MYSQL* mysql); -int terminate_slave_threads(Master_info* mi, int thread_mask, - In_C_you_should_use_my_bool_instead() skip_lock = 0); -int start_slave_threads(In_C_you_should_use_my_bool_instead() need_slave_mutex, In_C_you_should_use_my_bool_instead() wait_for_start, - Master_info* mi, const char* master_info_fname, - const char* slave_info_fname, int thread_mask); -int start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock, - pthread_mutex_t *cond_lock, - pthread_cond_t* start_cond, - volatile uint *slave_running, - volatile ulong *slave_run_id, - Master_info* mi, - In_C_you_should_use_my_bool_instead() high_priority); -int mysql_table_dump(THD* thd, const char* db, - const char* tbl_name, int fd = -1); -int fetch_master_table(THD* thd, const char* db_name, const char* table_name, - Master_info* mi, MYSQL* mysql, In_C_you_should_use_my_bool_instead() overwrite); -In_C_you_should_use_my_bool_instead() show_master_info(THD* thd, Master_info* mi); -In_C_you_should_use_my_bool_instead() show_binlog_info(THD* thd); -In_C_you_should_use_my_bool_instead() rpl_master_has_bug(Relay_log_info *rli, uint bug_id, In_C_you_should_use_my_bool_instead() report=(1)); -In_C_you_should_use_my_bool_instead() rpl_master_erroneous_autoinc(THD* thd); -const char *print_slave_db_safe(const char *db); -int check_expected_error(THD* thd, Relay_log_info const *rli, int error_code); -void skip_load_data_infile(NET* net); -void end_slave(); -void clear_until_condition(Relay_log_info* rli); -void clear_slave_error(Relay_log_info* rli); -void end_relay_log_info(Relay_log_info* rli); -void lock_slave_threads(Master_info* mi); -void unlock_slave_threads(Master_info* mi); -void init_thread_mask(int* mask,Master_info* mi,In_C_you_should_use_my_bool_instead() inverse); -int init_relay_log_pos(Relay_log_info* rli,const char* log,ulonglong pos, - In_C_you_should_use_my_bool_instead() need_data_lock, const char** errmsg, - In_C_you_should_use_my_bool_instead() look_for_description_event); -int purge_relay_logs(Relay_log_info* rli, THD *thd, In_C_you_should_use_my_bool_instead() just_reset, - const char** errmsg); -void set_slave_thread_options(THD* thd); -void set_slave_thread_default_charset(THD *thd, Relay_log_info const *rli); -void rotate_relay_log(Master_info* mi); -int apply_event_and_update_pos(Log_event* ev, THD* thd, Relay_log_info* rli, - In_C_you_should_use_my_bool_instead() skip); - void * handle_slave_io(void *arg); - void * handle_slave_sql(void *arg); -extern In_C_you_should_use_my_bool_instead() volatile abort_loop; -extern Master_info main_mi, *active_mi; -extern LIST master_list; -extern my_bool replicate_same_server_id; -extern int disconnect_slave_event_count, abort_slave_event_count ; -extern uint master_port, master_connect_retry, report_port; -extern char * master_user, *master_password, *master_host; -extern char *master_info_file, *relay_log_info_file, *report_user; -extern char *report_host, *report_password; -extern my_bool master_ssl; -extern char *master_ssl_ca, *master_ssl_capath, *master_ssl_cert; -extern char *master_ssl_cipher, *master_ssl_key; -extern I_List<THD> threads; -enum mysql_db_table_field -{ - MYSQL_DB_FIELD_HOST = 0, - MYSQL_DB_FIELD_DB, - MYSQL_DB_FIELD_USER, - MYSQL_DB_FIELD_SELECT_PRIV, - MYSQL_DB_FIELD_INSERT_PRIV, - MYSQL_DB_FIELD_UPDATE_PRIV, - MYSQL_DB_FIELD_DELETE_PRIV, - MYSQL_DB_FIELD_CREATE_PRIV, - MYSQL_DB_FIELD_DROP_PRIV, - MYSQL_DB_FIELD_GRANT_PRIV, - MYSQL_DB_FIELD_REFERENCES_PRIV, - MYSQL_DB_FIELD_INDEX_PRIV, - MYSQL_DB_FIELD_ALTER_PRIV, - MYSQL_DB_FIELD_CREATE_TMP_TABLE_PRIV, - MYSQL_DB_FIELD_LOCK_TABLES_PRIV, - MYSQL_DB_FIELD_CREATE_VIEW_PRIV, - MYSQL_DB_FIELD_SHOW_VIEW_PRIV, - MYSQL_DB_FIELD_CREATE_ROUTINE_PRIV, - MYSQL_DB_FIELD_ALTER_ROUTINE_PRIV, - MYSQL_DB_FIELD_EXECUTE_PRIV, - MYSQL_DB_FIELD_EVENT_PRIV, - MYSQL_DB_FIELD_TRIGGER_PRIV, - MYSQL_DB_FIELD_COUNT -}; -extern TABLE_FIELD_W_TYPE mysql_db_table_fields[]; -extern time_t mysql_db_table_last_check; -struct acl_host_and_ip -{ - char *hostname; - long ip,ip_mask; -}; -class ACL_ACCESS { -public: - ulong sort; - ulong access; -}; -class ACL_HOST :public ACL_ACCESS -{ -public: - acl_host_and_ip host; - char *db; -}; -class ACL_USER :public ACL_ACCESS -{ -public: - acl_host_and_ip host; - uint hostname_length; - USER_RESOURCES user_resource; - char *user; - uint8 salt[20 +1]; - uint8 salt_len; - enum SSL_type ssl_type; - const char *ssl_cipher, *x509_issuer, *x509_subject; -}; -class ACL_DB :public ACL_ACCESS -{ -public: - acl_host_and_ip host; - char *user,*db; -}; -In_C_you_should_use_my_bool_instead() hostname_requires_resolving(const char *hostname); -my_bool acl_init(In_C_you_should_use_my_bool_instead() dont_read_acl_tables); -my_bool acl_reload(THD *thd); -void acl_free(In_C_you_should_use_my_bool_instead() end=0); -ulong acl_get(const char *host, const char *ip, - const char *user, const char *db, my_bool db_is_pattern); -int acl_getroot(THD *thd, USER_RESOURCES *mqh, const char *passwd, - uint passwd_len); -In_C_you_should_use_my_bool_instead() acl_getroot_no_password(Security_context *sctx, char *user, char *host, - char *ip, char *db); -In_C_you_should_use_my_bool_instead() acl_check_host(const char *host, const char *ip); -int check_change_password(THD *thd, const char *host, const char *user, - char *password, uint password_len); -In_C_you_should_use_my_bool_instead() change_password(THD *thd, const char *host, const char *user, - char *password); -In_C_you_should_use_my_bool_instead() mysql_grant(THD *thd, const char *db, List <LEX_USER> &user_list, - ulong rights, In_C_you_should_use_my_bool_instead() revoke); -int mysql_table_grant(THD *thd, TABLE_LIST *table, List <LEX_USER> &user_list, - List <LEX_COLUMN> &column_list, ulong rights, - In_C_you_should_use_my_bool_instead() revoke); -In_C_you_should_use_my_bool_instead() mysql_routine_grant(THD *thd, TABLE_LIST *table, In_C_you_should_use_my_bool_instead() is_proc, - List <LEX_USER> &user_list, ulong rights, - In_C_you_should_use_my_bool_instead() revoke, In_C_you_should_use_my_bool_instead() no_error); -my_bool grant_init(); -void grant_free(void); -my_bool grant_reload(THD *thd); -In_C_you_should_use_my_bool_instead() check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, - uint show_command, uint number, In_C_you_should_use_my_bool_instead() dont_print_error); -In_C_you_should_use_my_bool_instead() check_grant_column (THD *thd, GRANT_INFO *grant, - const char *db_name, const char *table_name, - const char *name, uint length, Security_context *sctx); -In_C_you_should_use_my_bool_instead() check_column_grant_in_table_ref(THD *thd, TABLE_LIST * table_ref, - const char *name, uint length); -In_C_you_should_use_my_bool_instead() check_grant_all_columns(THD *thd, ulong want_access, - Field_iterator_table_ref *fields); -In_C_you_should_use_my_bool_instead() check_grant_routine(THD *thd, ulong want_access, - TABLE_LIST *procs, In_C_you_should_use_my_bool_instead() is_proc, In_C_you_should_use_my_bool_instead() no_error); -In_C_you_should_use_my_bool_instead() check_grant_db(THD *thd,const char *db); -ulong get_table_grant(THD *thd, TABLE_LIST *table); -ulong get_column_grant(THD *thd, GRANT_INFO *grant, - const char *db_name, const char *table_name, - const char *field_name); -In_C_you_should_use_my_bool_instead() mysql_show_grants(THD *thd, LEX_USER *user); -void get_privilege_desc(char *to, uint max_length, ulong access); -void get_mqh(const char *user, const char *host, USER_CONN *uc); -In_C_you_should_use_my_bool_instead() mysql_create_user(THD *thd, List <LEX_USER> &list); -In_C_you_should_use_my_bool_instead() mysql_drop_user(THD *thd, List <LEX_USER> &list); -In_C_you_should_use_my_bool_instead() mysql_rename_user(THD *thd, List <LEX_USER> &list); -In_C_you_should_use_my_bool_instead() mysql_revoke_all(THD *thd, List <LEX_USER> &list); -void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, - const char *db, const char *table); -In_C_you_should_use_my_bool_instead() sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, - In_C_you_should_use_my_bool_instead() is_proc); -int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, - In_C_you_should_use_my_bool_instead() is_proc); -In_C_you_should_use_my_bool_instead() check_routine_level_acl(THD *thd, const char *db, const char *name, - In_C_you_should_use_my_bool_instead() is_proc); -In_C_you_should_use_my_bool_instead() is_acl_user(const char *host, const char *user); -#include "tztime.h" -class Time_zone: public Sql_alloc -{ -public: - Time_zone() {} - virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t, - my_bool *in_dst_time_gap) const = 0; - virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0; - virtual const String * get_name() const = 0; - virtual ~Time_zone() {}; -}; -extern Time_zone * my_tz_UTC; -extern Time_zone * my_tz_SYSTEM; -extern Time_zone * my_tz_OFFSET0; -extern Time_zone * my_tz_find(THD *thd, const String *name); -extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap); -extern void my_tz_free(); -extern my_time_t sec_since_epoch_TIME(MYSQL_TIME *t); -static const int MY_TZ_TABLES_COUNT= 4; -In_C_you_should_use_my_bool_instead() check_global_access(THD *thd, ulong want_access); -int get_quote_char_for_identifier(THD *thd, const char *name, uint length); -void sql_perror(const char *message); -In_C_you_should_use_my_bool_instead() fn_format_relative_to_data_home(char * to, const char *name, - const char *dir, const char *extension); -extern uint mysql_data_home_len; -extern char *mysql_data_home,server_version[60], - mysql_real_data_home[], mysql_unpacked_real_data_home[]; -extern CHARSET_INFO *character_set_filesystem; -extern char reg_ext[20]; -extern uint reg_ext_length; -extern ulong specialflag; -extern uint lower_case_table_names; -extern In_C_you_should_use_my_bool_instead() mysqld_embedded; -extern my_bool opt_large_pages; -extern uint opt_large_page_size; -extern struct system_variables global_system_variables; -uint strconvert(CHARSET_INFO *from_cs, const char *from, - CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors); -uint filename_to_tablename(const char *from, char *to, uint to_length); -uint tablename_to_filename(const char *from, char *to, uint to_length); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 8a1fa501025..0edb42f5d36 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..842d74d063a --- /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, key_PARTITION_LOCK_auto_inc; + +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..fd01e4a8885 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; @@ -207,7 +210,7 @@ net_send_ok(THD *thd, NET *net= &thd->net; uchar buff[MYSQL_ERRMSG_SIZE+10],*pos; bool error= FALSE; - DBUG_ENTER("my_ok"); + DBUG_ENTER("net_send_ok"); if (! net->vio) // hack for re-parsing queries { @@ -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 8171d028326..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 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..73f2ca13bb6 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,10 +54,7 @@ uninstall-local: @RM@ -f -r $(DESTDIR)$(pkgdatadir) distclean-local: - @RM@ -f $(builddir)/*/errmsg.sys + @RM@ -f */errmsg.sys # Do nothing link_sources: - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 517782cb0b4..598f563ac87 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -5927,7 +5927,7 @@ ER_DROP_INDEX_FK eng "Cannot drop index '%-.192s': needed in a foreign key constraint" ger "Kann Index '%-.192s' nicht löschen: wird für einen Fremdschlüssel benötigt" # When using this error message, use the ER_WARN_DEPRECATED_SYNTAX error -# code. See, for example, code in mysql_priv.h. +# code. ER_WARN_DEPRECATED_SYNTAX_WITH_VER eng "The syntax '%s' is deprecated and will be removed in MySQL %s. Please use %s instead" ger "Die Syntax '%s' ist veraltet und wird in MySQL %s entfernt. Bitte benutzen Sie statt dessen %s" @@ -6068,7 +6068,7 @@ ER_SLAVE_INCIDENT ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT eng "Table has no partition for some existing values" ER_BINLOG_UNSAFE_STATEMENT - eng "Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: %s" + eng "Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. %s" ER_SLAVE_FATAL_ERROR eng "Fatal error: %s" ER_SLAVE_RELAY_LOG_READ_FAILURE @@ -6173,7 +6173,7 @@ ER_FUNC_INEXISTENT_NAME_COLLISION 42000 eng "FUNCTION %s does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual" # When updating these, please update EXPLAIN_FILENAME_MAX_EXTRA_LENGTH in -# mysql_priv.h with the new maximal additional length for explain_filename. +# sql_table.h with the new maximal additional length for explain_filename. ER_DATABASE_NAME eng "Database" swe "Databas" @@ -6258,36 +6258,36 @@ ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD ER_PARTITION_FIELDS_TOO_LONG eng "The total length of the partitioning fields is too large" ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE - eng "Cannot execute statement: binlogging impossible since both row-incapable engines and statement-incapable engines are involved." + eng "Cannot execute statement: impossible to write to binary log since both row-incapable engines and statement-incapable engines are involved." ER_BINLOG_ROW_MODE_AND_STMT_ENGINE - eng "Cannot execute statement: binlogging impossible since BINLOG_FORMAT = ROW and at least one table uses a storage engine limited to statement-logging." + eng "Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = ROW and at least one table uses a storage engine limited to statement-based logging." ER_BINLOG_UNSAFE_AND_STMT_ENGINE - eng "Cannot execute statement: binlogging of unsafe statement is impossible when storage engine is limited to statement-logging and BINLOG_FORMAT = MIXED. Reason for unsafeness: %s" + eng "Cannot execute statement: impossible to write to binary log since statement is unsafe, storage engine is limited to statement-based logging, and BINLOG_FORMAT = MIXED. %s" ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE - eng "Cannot execute row injection: binlogging impossible since at least one table uses a storage engine limited to statement-logging." + eng "Cannot execute statement: impossible to write to binary log since statement is in row format and at least one table uses a storage engine limited to statement-based logging." ER_BINLOG_STMT_MODE_AND_ROW_ENGINE - eng "Cannot execute statement: binlogging impossible since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-logging.%s" + eng "Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging.%s" ER_BINLOG_ROW_INJECTION_AND_STMT_MODE - eng "Cannot execute row injection: binlogging impossible since BINLOG_FORMAT = STATEMENT." + eng "Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT." ER_BINLOG_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE - eng "Cannot execute statement: binlogging impossible since more than one engine is involved and at least one engine is self-logging." + eng "Cannot execute statement: impossible to write to binary log since more than one engine is involved and at least one engine is self-logging." ER_BINLOG_UNSAFE_LIMIT - eng "Statement uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted." + eng "The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted." ER_BINLOG_UNSAFE_INSERT_DELAYED - eng "Statement uses INSERT DELAYED. This is unsafe because the time when rows are inserted cannot be predicted." + eng "The statement is unsafe because it uses INSERT DELAYED. This is unsafe because the times when rows are inserted cannot be predicted." ER_BINLOG_UNSAFE_SYSTEM_TABLE - eng "Statement uses the general_log, slow_log or performance_schema table(s). This is unsafe because system tables may differ on slave." + eng "The statement is unsafe because it uses the general log, slow query log, or performance_schema table(s). This is unsafe because system tables may differ on slaves." ER_BINLOG_UNSAFE_AUTOINC_COLUMNS - eng "Statement invokes a trigger or a stored function that inserts into AUTO_INCREMENT column which is unsafe to binlog in STATEMENT format because slave may execute it non-deterministically." + eng "Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly." ER_BINLOG_UNSAFE_UDF - eng "Statement uses a UDF. It cannot be determined if the UDF will return the same value on slave." + eng "Statement is unsafe because it uses a UDF which may not return the same value on the slave." ER_BINLOG_UNSAFE_SYSTEM_VARIABLE - eng "Statement uses a system variable whose value may differ on slave." + eng "Statement is unsafe because it uses a system variable that may have a different value on the slave." ER_BINLOG_UNSAFE_SYSTEM_FUNCTION - eng "Statement uses a system function whose value may differ on slave." + eng "Statement is unsafe because it uses a system function that may return a different value on the slave." ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS - eng "Non-transactional reads or writes are unsafe if they occur after transactional reads or writes inside a transaction." + eng "Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction." ER_MESSAGE_AND_STATEMENT eng "%s Statement: %s" @@ -6327,3 +6327,12 @@ ER_LOCK_ABORTED 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" + +ER_BINLOG_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE + eng "Mixing self-logging and non-self-logging engines in a statement is unsafe." + +ER_BINLOG_UNSAFE_MIXED_STATEMENT + eng "Statements that read from both transactional (or a temporary table of any engine type) and non-transactional tables and write to any of them are unsafe." 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..e7bf15c56d5 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> @@ -920,6 +931,11 @@ sp_create_routine(THD *thd, int type, sp_head *sp) DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE || type == TYPE_ENUM_FUNCTION); + /* Grab an exclusive MDL lock. */ + if (lock_routine_name(thd, type == TYPE_ENUM_FUNCTION, + sp->m_db.str, sp->m_name.str)) + DBUG_RETURN(SP_OPEN_TABLE_FAILED); + /* Reset sql_mode during data dictionary operations. */ thd->variables.sql_mode= 0; @@ -931,11 +947,6 @@ sp_create_routine(THD *thd, int type, sp_head *sp) if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) thd->clear_current_stmt_binlog_format_row(); - /* Grab an exclusive MDL lock. */ - if (lock_routine_name(thd, type == TYPE_ENUM_FUNCTION, - sp->m_db.str, sp->m_name.str)) - DBUG_RETURN(SP_OPEN_TABLE_FAILED); - saved_count_cuted_fields= thd->count_cuted_fields; thd->count_cuted_fields= CHECK_FIELD_WARN; @@ -1179,6 +1190,14 @@ sp_drop_routine(THD *thd, int type, sp_name *name) DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE || type == TYPE_ENUM_FUNCTION); + /* Grab an exclusive MDL lock. */ + if (lock_routine_name(thd, type == TYPE_ENUM_FUNCTION, + name->m_db.str, name->m_name.str)) + DBUG_RETURN(SP_DELETE_ROW_FAILED); + + if (!(table= open_proc_table_for_update(thd))) + DBUG_RETURN(SP_OPEN_TABLE_FAILED); + /* This statement will be replicated as a statement, even when using row-based replication. The flag will be reset at the end of the @@ -1187,13 +1206,6 @@ sp_drop_routine(THD *thd, int type, sp_name *name) if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) thd->clear_current_stmt_binlog_format_row(); - /* Grab an exclusive MDL lock. */ - if (lock_routine_name(thd, type == TYPE_ENUM_FUNCTION, - name->m_db.str, name->m_name.str)) - DBUG_RETURN(SP_DELETE_ROW_FAILED); - - if (!(table= open_proc_table_for_update(thd))) - DBUG_RETURN(SP_OPEN_TABLE_FAILED); if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK) { if (table->file->ha_delete_row(table->record[0])) @@ -1265,6 +1277,9 @@ sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics) name->m_db.str, name->m_name.str)) DBUG_RETURN(SP_OPEN_TABLE_FAILED); + if (!(table= open_proc_table_for_update(thd))) + DBUG_RETURN(SP_OPEN_TABLE_FAILED); + /* This statement will be replicated as a statement, even when using row-based replication. The flag will be reset at the end of the @@ -1273,8 +1288,6 @@ sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics) if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) thd->clear_current_stmt_binlog_format_row(); - if (!(table= open_proc_table_for_update(thd))) - DBUG_RETURN(SP_OPEN_TABLE_FAILED); if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK) { if (type == TYPE_ENUM_FUNCTION && ! trust_function_creators && @@ -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..2e66aec91e5 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; @@ -2105,6 +2127,9 @@ sp_head::reset_lex(THD *thd) sublex->interval_list.empty(); sublex->type= 0; + /* Reset part of parser state which needs this. */ + thd->m_parser_state->m_yacc.reset_before_substatement(); + DBUG_RETURN(FALSE); } 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..55d83f49245 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; @@ -3146,6 +3159,12 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, */ Query_tables_list backup; thd->lex->reset_n_backup_query_tables_list(&backup); + /* + Restore Query_tables_list::sql_command value, which was reset + above, as the code writing query to the binary log assumes that + this value corresponds to the statement being executed. + */ + thd->lex->sql_command= backup.sql_command; if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { // Should never happen close_thread_tables(thd); /* purecov: deadcode */ 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 5190cba64de..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); @@ -65,6 +65,7 @@ static void general_class_handler(THD *thd, uint event_subtype, va_list ap) { mysql_event_general event; event.event_class= MYSQL_AUDIT_GENERAL_CLASS; + event.event_subclass= event_subtype; event.general_error_code= va_arg(ap, int); event.general_thread_id= thd ? thd->thread_id : 0; event.general_time= va_arg(ap, time_t); 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 a85a863abd9..28633365e28 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 @@ -729,6 +752,7 @@ TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name) } +#ifdef DISABLED_UNTIL_GRL_IS_MADE_PART_OF_MDL /** @brief Mark table share as having one more user (increase its reference count). @@ -746,6 +770,7 @@ static void reference_table_share(TABLE_SHARE *share) (ulong) share, share->ref_count)); DBUG_VOID_RETURN; } +#endif /* @@ -1533,7 +1558,7 @@ void close_thread_tables(THD *thd) - If in autocommit mode, or outside a transactional context, automatically release metadata locks of the current statement. */ - if (! thd->in_multi_stmt_transaction() && + if (! thd->in_multi_stmt_transaction_mode() && ! (thd->state_flags & Open_tables_state::BACKUPS_AVAIL)) { thd->mdl_context.release_transactional_locks(); @@ -1675,6 +1700,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 +1730,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 +1743,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 { @@ -3755,7 +3783,7 @@ end_with_lock_open: Open_table_context::Open_table_context(THD *thd, ulong timeout) :m_action(OT_NO_ACTION), m_start_of_statement_svp(thd->mdl_context.mdl_savepoint()), - m_has_locks((thd->in_multi_stmt_transaction() && + m_has_locks((thd->in_multi_stmt_transaction_mode() && thd->mdl_context.has_locks()) || thd->mdl_context.trans_sentinel()), m_global_mdl_request(NULL), @@ -3935,7 +3963,8 @@ recover_from_failed_open(THD *thd, MDL_request *mdl_request, Return a appropriate read lock type given a table object. @param thd Thread context - @param table TABLE object for table to be locked + @param prelocking_ctx Prelocking context. + @param table_list Table list element for table to be locked. @remark Due to a statement-based replication limitation, statements such as INSERT INTO .. SELECT FROM .. and CREATE TABLE .. SELECT FROM need @@ -3944,20 +3973,44 @@ recover_from_failed_open(THD *thd, MDL_request *mdl_request, source table. If such a statement gets applied on the slave before the INSERT .. SELECT statement finishes, data on the master could differ from data on the slave and end-up with a discrepancy between - the binary log and table state. Furthermore, this does not apply to - I_S and log tables as it's always unsafe to replicate such tables - under statement-based replication as the table on the slave might - contain other data (ie: general_log is enabled on the slave). The - statement will be marked as unsafe for SBR in decide_logging_format(). + the binary log and table state. + This also applies to SELECT/SET/DO statements which use stored + functions. Calls to such functions are going to be logged as a + whole and thus should be serialized against concurrent changes + to tables used by those functions. This can be avoided if functions + only read data but doing so requires more complex analysis than it + is done now. + Furthermore, this does not apply to I_S and log tables as it's + always unsafe to replicate such tables under statement-based + replication as the table on the slave might contain other data + (ie: general_log is enabled on the slave). The statement will + be marked as unsafe for SBR in decide_logging_format(). + @remark Note that even in prelocked mode it is important to correctly + determine lock type value. In this mode lock type is passed to + handler::start_stmt() method and can be used by storage engine, + for example, to determine what kind of row locks it should acquire + when reading data from the table. */ -thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table) +thr_lock_type read_lock_type_for_table(THD *thd, + Query_tables_list *prelocking_ctx, + TABLE_LIST *table_list) { - bool log_on= mysql_bin_log.is_open() && (thd->variables.option_bits & OPTION_BIN_LOG); + /* + In cases when this function is called for a sub-statement executed in + prelocked mode we can't rely on OPTION_BIN_LOG flag in THD::options + bitmap to determine that binary logging is turned on as this bit can + be cleared before executing sub-statement. So instead we have to look + at THD::sql_log_bin_toplevel member. + */ + bool log_on= mysql_bin_log.is_open() && thd->sql_log_bin_toplevel; ulong binlog_format= thd->variables.binlog_format; if ((log_on == FALSE) || (binlog_format == BINLOG_FORMAT_ROW) || - (table->s->table_category == TABLE_CATEGORY_LOG) || - (table->s->table_category == TABLE_CATEGORY_PERFORMANCE)) + (table_list->table->s->table_category == TABLE_CATEGORY_LOG) || + (table_list->table->s->table_category == TABLE_CATEGORY_PERFORMANCE) || + !(is_update_query(prelocking_ctx->sql_command) || + table_list->prelocking_placeholder || + (thd->locked_tables_mode > LTM_LOCK_TABLES))) return TL_READ; else return TL_READ_NO_INSERT; @@ -4308,7 +4361,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, tables->table->reginfo.lock_type= thd->update_lock_default; else if (tables->lock_type == TL_READ_DEFAULT) tables->table->reginfo.lock_type= - read_lock_type_for_table(thd, tables->table); + read_lock_type_for_table(thd, lex, tables); else tables->table->reginfo.lock_type= tables->lock_type; } @@ -4961,35 +5014,49 @@ handle_view(THD *thd, Query_tables_list *prelocking_ctx, } -/* +/** Check that lock is ok for tables; Call start stmt if ok - SYNOPSIS - check_lock_and_start_stmt() - thd Thread handle - table_list Table to check - lock_type Lock used for table + @param thd Thread handle. + @param prelocking_ctx Prelocking context. + @param table_list Table list element for table to be checked. - RETURN VALUES - 0 ok - 1 error + @retval FALSE - Ok. + @retval TRUE - Error. */ -static bool check_lock_and_start_stmt(THD *thd, TABLE *table, - thr_lock_type lock_type) +static bool check_lock_and_start_stmt(THD *thd, + Query_tables_list *prelocking_ctx, + TABLE_LIST *table_list) { int error; + thr_lock_type lock_type; DBUG_ENTER("check_lock_and_start_stmt"); + /* + TL_WRITE_DEFAULT and TL_READ_DEFAULT are supposed to be parser only + types of locks so they should be converted to appropriate other types + to be passed to storage engine. The exact lock type passed to the + engine is important as, for example, InnoDB uses it to determine + what kind of row locks should be acquired when executing statement + in prelocked mode or under LOCK TABLES with @@innodb_table_locks = 0. + */ + if (table_list->lock_type == TL_WRITE_DEFAULT) + lock_type= thd->update_lock_default; + else if (table_list->lock_type == TL_READ_DEFAULT) + lock_type= read_lock_type_for_table(thd, prelocking_ctx, table_list); + else + lock_type= table_list->lock_type; + if ((int) lock_type >= (int) TL_WRITE_ALLOW_READ && - (int) table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ) + (int) table_list->table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ) { - my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias); + my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), table_list->alias); DBUG_RETURN(1); } - if ((error=table->file->start_stmt(thd, lock_type))) + if ((error= table_list->table->file->start_stmt(thd, lock_type))) { - table->file->print_error(error,MYF(0)); + table_list->table->file->print_error(error, MYF(0)); DBUG_RETURN(1); } DBUG_RETURN(0); @@ -5134,7 +5201,7 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type, table->grant= table_list->grant; if (thd->locked_tables_mode) { - if (check_lock_and_start_stmt(thd, table, lock_type)) + if (check_lock_and_start_stmt(thd, thd->lex, table_list)) table= 0; } else @@ -5362,7 +5429,7 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, if (!table->placeholder()) { table->table->query_id= thd->query_id; - if (check_lock_and_start_stmt(thd, table->table, table->lock_type)) + if (check_lock_and_start_stmt(thd, thd->lex, table)) { mysql_unlock_tables(thd, thd->lock); thd->lock= 0; @@ -5416,7 +5483,7 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, } } - if (check_lock_and_start_stmt(thd, table->table, table->lock_type)) + if (check_lock_and_start_stmt(thd, thd->lex, table)) { DBUG_RETURN(TRUE); } diff --git a/sql/sql_base.h b/sql/sql_base.h new file mode 100644 index 00000000000..0c16151e43a --- /dev/null +++ b/sql/sql_base.h @@ -0,0 +1,358 @@ +/* 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 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, + Query_tables_list *prelocking_ctx, + TABLE_LIST *table_list); + +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..92d54c8e71b 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> @@ -1171,7 +1177,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) DBUG_ASSERT(flags.protocol_type != (unsigned int) Protocol::PROTOCOL_LOCAL); flags.more_results_exists= test(thd->server_status & SERVER_MORE_RESULTS_EXISTS); - flags.in_trans= test(thd->server_status & SERVER_STATUS_IN_TRANS); + flags.in_trans= thd->in_active_multi_stmt_transaction(); flags.autocommit= test(thd->server_status & SERVER_STATUS_AUTOCOMMIT); flags.pkt_nr= net->pkt_nr; flags.character_set_client_num= @@ -1464,7 +1470,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) flags.protocol_type= (unsigned int) thd->protocol->type(); flags.more_results_exists= test(thd->server_status & SERVER_MORE_RESULTS_EXISTS); - flags.in_trans= test(thd->server_status & SERVER_STATUS_IN_TRANS); + flags.in_trans= thd->in_active_multi_stmt_transaction(); flags.autocommit= test(thd->server_status & SERVER_STATUS_AUTOCOMMIT); flags.pkt_nr= thd->net.pkt_nr; flags.character_set_client_num= thd->variables.character_set_client->number; @@ -1535,7 +1541,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", } DBUG_PRINT("qcache", ("Query have result 0x%lx", (ulong) query)); - if (thd->in_multi_stmt_transaction() && + if (thd->in_multi_stmt_transaction_mode() && (query->tables_type() & HA_CACHE_TBL_TRANSACT)) { DBUG_PRINT("qcache", @@ -1692,7 +1698,7 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used, if (is_disabled()) DBUG_VOID_RETURN; - using_transactions= using_transactions && thd->in_multi_stmt_transaction(); + using_transactions= using_transactions && thd->in_multi_stmt_transaction_mode(); for (; tables_used; tables_used= tables_used->next_local) { DBUG_ASSERT(!using_transactions || tables_used->table!=0); @@ -1776,7 +1782,7 @@ void Query_cache::invalidate(THD *thd, TABLE *table, if (is_disabled()) DBUG_VOID_RETURN; - using_transactions= using_transactions && thd->in_multi_stmt_transaction(); + using_transactions= using_transactions && thd->in_multi_stmt_transaction_mode(); if (using_transactions && (table->file->table_cache_type() == HA_CACHE_TBL_TRANSACT)) thd->add_changed_table(table); @@ -1794,7 +1800,7 @@ void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length, if (is_disabled()) DBUG_VOID_RETURN; - using_transactions= using_transactions && thd->in_multi_stmt_transaction(); + using_transactions= using_transactions && thd->in_multi_stmt_transaction_mode(); if (using_transactions) // used for innodb => has_transactions() is TRUE thd->add_changed_table(key, key_length); else @@ -3566,7 +3572,7 @@ Query_cache::is_cacheable(THD *thd, size_t query_len, const char *query, tables_type))) DBUG_RETURN(0); - if (thd->in_multi_stmt_transaction() && + if (thd->in_multi_stmt_transaction_mode() && ((*tables_type)&HA_CACHE_TBL_TRANSACT)) { DBUG_PRINT("qcache", ("not in autocommin mode")); 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..789b01443f7 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 @@ -493,14 +505,14 @@ THD::THD() count_cuted_fields= CHECK_FIELD_IGNORE; killed= NOT_KILLED; col_access=0; - is_slave_error= thread_specific_used= FALSE; + is_slave_error= thread_specific_used= thread_temporary_used= FALSE; my_hash_clear(&handler_tables_hash); tmp_table=0; used_tables=0; cuted_fields= 0L; sent_row_count= 0L; limit_found_rows= 0; - row_count_func= -1; + m_row_count_func= -1; statement_id_counter= 0UL; // Must be reset to handle error with THD's created for init of mysqld lex->current_select= 0; @@ -792,7 +804,10 @@ MYSQL_ERROR* THD::raise_condition(uint sql_errno, else { if (! stmt_da->is_error()) + { + set_row_count_func(-1); stmt_da->set_error_status(this, sql_errno, msg, sqlstate); + } } } @@ -1428,7 +1443,7 @@ void THD::add_changed_table(TABLE *table) { DBUG_ENTER("THD::add_changed_table(table)"); - DBUG_ASSERT(in_multi_stmt_transaction() && table->file->has_transactions()); + DBUG_ASSERT(in_multi_stmt_transaction_mode() && table->file->has_transactions()); add_changed_table(table->s->table_cache_key.str, (long) table->s->table_cache_key.length); DBUG_VOID_RETURN; @@ -1793,11 +1808,6 @@ bool select_to_file::send_eof() error= 1; if (!error) { - /* - In order to remember the value of affected rows for ROW_COUNT() - function, SELECT INTO has to have an own SQLCOM. - TODO: split from SQLCOM_SELECT - */ ::my_ok(thd,row_count); } file= -1; @@ -2818,11 +2828,6 @@ bool select_dumpvar::send_eof() if (! row_count) push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA)); - /* - In order to remember the value of affected rows for ROW_COUNT() - function, SELECT INTO has to have an own SQLCOM. - TODO: split from SQLCOM_SELECT - */ ::my_ok(thd,row_count); return 0; } @@ -3589,13 +3594,33 @@ int THD::decide_logging_format(TABLE_LIST *tables) capabilities, and one with the intersection of all the engine capabilities. */ + handler::Table_flags flags_write_some_set= 0; handler::Table_flags flags_some_set= 0; - handler::Table_flags flags_all_set= + handler::Table_flags flags_write_all_set= HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE; - my_bool multi_engine= FALSE; - my_bool mixed_engine= FALSE; - my_bool all_trans_engines= TRUE; + /* + If different types of engines are about to be updated. + For example: Innodb and Falcon; Innodb and MyIsam. + */ + my_bool multi_write_engine= FALSE; + /* + If different types of engines are about to be accessed + and any of them is about to be updated. For example: + Innodb and Falcon; Innodb and MyIsam. + */ + my_bool multi_access_engine= FALSE; + /* + If non-transactional and transactional engines are about + to be accessed and any of them is about to be updated. + For example: Innodb and MyIsam. + */ + my_bool trans_non_trans_access_engines= FALSE; + /* + If all engines that are about to be updated are + transactional. + */ + my_bool all_trans_write_engines= TRUE; TABLE* prev_write_table= NULL; TABLE* prev_access_table= NULL; @@ -3621,32 +3646,112 @@ int THD::decide_logging_format(TABLE_LIST *tables) continue; if (table->table->s->table_category == TABLE_CATEGORY_PERFORMANCE) lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_TABLE); + handler::Table_flags const flags= table->table->file->ha_table_flags(); + DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx", + table->table_name, flags)); if (table->lock_type >= TL_WRITE_ALLOW_WRITE) { - handler::Table_flags const flags= table->table->file->ha_table_flags(); - DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx", - table->table_name, flags)); if (prev_write_table && prev_write_table->file->ht != table->table->file->ht) - multi_engine= TRUE; - all_trans_engines= all_trans_engines && - table->table->file->has_transactions(); + multi_write_engine= TRUE; + /* + Every temporary table must be always written to the binary + log in transaction boundaries and as such we artificially + classify them as transactional. + + Indirectly, this avoids classifying a temporary table created + on a non-transactional engine as unsafe when it is modified + after any transactional table: + + BEGIN; + INSERT INTO innodb_t VALUES (1); + INSERT INTO myisam_t_temp VALUES (1); + COMMIT; + + BINARY LOG: + + BEGIN; + INSERT INTO innodb_t VALUES (1); + INSERT INTO myisam_t_temp VALUES (1); + COMMIT; + */ + all_trans_write_engines= all_trans_write_engines && + (table->table->file->has_transactions() || + table->table->s->tmp_table); prev_write_table= table->table; - flags_all_set &= flags; - flags_some_set |= flags; + flags_write_all_set &= flags; + flags_write_some_set |= flags; } - if (prev_access_table && prev_access_table->file->ht != table->table->file->ht) - mixed_engine= mixed_engine || (prev_access_table->file->has_transactions() != - table->table->file->has_transactions()); + flags_some_set |= flags; + /* + The mixture of non-transactional and transactional tables must + identified and classified as unsafe. However, a temporary table + must be always handled as a transactional table. Based on that, + we have the following statements classified as mixed and by + consequence as unsafe: + + 1: INSERT INTO myisam_t SELECT * FROM innodb_t; + + 2: INSERT INTO innodb_t SELECT * FROM myisam_t; + + 3: INSERT INTO myisam_t SELECT * FROM myisam_t_temp; + + 4: INSERT INTO myisam_t_temp SELECT * FROM myisam_t; + + 5: CREATE TEMPORARY TABLE myisam_t_temp SELECT * FROM mysiam_t; + + The following statements are not considered mixed and as such + are safe: + + 1: INSERT INTO innodb_t SELECT * FROM myisam_t_temp; + + 2: INSERT INTO myisam_t_temp SELECT * FROM innodb_t_temp; + */ + if (!trans_non_trans_access_engines && prev_access_table && + (lex->sql_command != SQLCOM_CREATE_TABLE || + (lex->sql_command == SQLCOM_CREATE_TABLE && + (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)))) + { + my_bool prev_trans; + my_bool act_trans; + if (prev_access_table->s->tmp_table || table->table->s->tmp_table) + { + prev_trans= prev_access_table->s->tmp_table ? TRUE : + prev_access_table->file->has_transactions(); + act_trans= table->table->s->tmp_table ? TRUE : + table->table->file->has_transactions(); + } + else + { + prev_trans= prev_access_table->file->has_transactions(); + act_trans= table->table->file->has_transactions(); + } + trans_non_trans_access_engines= (prev_trans != act_trans); + multi_access_engine= TRUE; + } + thread_temporary_used |= table->table->s->tmp_table; prev_access_table= table->table; } + DBUG_PRINT("info", ("flags_write_all_set: 0x%llx", flags_write_all_set)); + DBUG_PRINT("info", ("flags_write_some_set: 0x%llx", flags_write_some_set)); + DBUG_PRINT("info", ("flags_some_set: 0x%llx", flags_some_set)); + DBUG_PRINT("info", ("multi_write_engine: %d", multi_write_engine)); + DBUG_PRINT("info", ("multi_access_engine: %d", multi_access_engine)); + DBUG_PRINT("info", ("trans_non_trans_access_engines: %d", + trans_non_trans_access_engines)); + + int error= 0; + int unsafe_flags; + /* Set the statement as unsafe if: . it is a mixed statement, i.e. access transactional and non-transactional - tables, and updates at least one; - or + tables, and update any of them; + + or: + . an early statement updated a transactional table; . and, the current statement updates a non-transactional table. @@ -3660,6 +3765,12 @@ int THD::decide_logging_format(TABLE_LIST *tables) 2: INSERT INTO innodb_t SELECT * FROM myisam_t; + 3: INSERT INTO myisam_t SELECT * FROM myisam_t_temp; + + 4: INSERT INTO myisam_t_temp SELECT * FROM myisam_t; + + 5: CREATE TEMPORARY TABLE myisam_t_temp SELECT * FROM mysiam_t; + are classified as unsafe to ensure that in mixed mode the execution is completely safe and equivalent to the row mode. Consider the following statements and sessions (connections) to understand the reason: @@ -3710,32 +3821,26 @@ int THD::decide_logging_format(TABLE_LIST *tables) isolation level but if we have pure repeatable read or serializable the lock history on the slave will be different from the master. */ - if (mixed_engine || - (trans_has_updated_trans_table(this) && !all_trans_engines)) + if (trans_non_trans_access_engines) + lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MIXED_STATEMENT); + else if (trans_has_updated_trans_table(this) && !all_trans_write_engines) lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS); - DBUG_PRINT("info", ("flags_all_set: 0x%llx", flags_all_set)); - DBUG_PRINT("info", ("flags_some_set: 0x%llx", flags_some_set)); - DBUG_PRINT("info", ("multi_engine: %d", multi_engine)); - - int error= 0; - int unsafe_flags; - /* If more than one engine is involved in the statement and at least one is doing it's own logging (is *self-logging*), the statement cannot be logged atomically, so we generate an error rather than allowing the binlog to become corrupt. */ - if (multi_engine && - (flags_some_set & HA_HAS_OWN_BINLOGGING)) - { + if (multi_write_engine && + (flags_write_some_set & HA_HAS_OWN_BINLOGGING)) my_error((error= ER_BINLOG_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE), MYF(0)); - } + else if (multi_access_engine && flags_some_set & HA_HAS_OWN_BINLOGGING) + lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE); /* both statement-only and row-only engines involved */ - if ((flags_all_set & (HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE)) == 0) + if ((flags_write_all_set & (HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE)) == 0) { /* 1. Error: Binary logging impossible since both row-incapable @@ -3744,7 +3849,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) my_error((error= ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE), MYF(0)); } /* statement-only engines involved */ - else if ((flags_all_set & HA_BINLOG_ROW_CAPABLE) == 0) + else if ((flags_write_all_set & HA_BINLOG_ROW_CAPABLE) == 0) { if (lex->is_stmt_row_injection()) { @@ -3792,7 +3897,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) */ my_error((error= ER_BINLOG_ROW_INJECTION_AND_STMT_MODE), MYF(0)); } - else if ((flags_all_set & HA_BINLOG_STMT_CAPABLE) == 0) + else if ((flags_write_all_set & HA_BINLOG_STMT_CAPABLE) == 0) { /* 5. Error: Cannot modify table that uses a storage engine @@ -3820,7 +3925,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) else { if (lex->is_stmt_unsafe() || lex->is_stmt_row_injection() - || (flags_all_set & HA_BINLOG_STMT_CAPABLE) == 0) + || (flags_write_all_set & HA_BINLOG_STMT_CAPABLE) == 0) { /* log in row format! */ set_current_stmt_binlog_format_row_if_mixed(); diff --git a/sql/sql_class.h b/sql/sql_class.h index de6d92eccfd..916b79f8353 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; @@ -248,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. */ @@ -1944,7 +1994,50 @@ public: } ulonglong limit_found_rows; - longlong row_count_func; /* For the ROW_COUNT() function */ + +private: + /** + Stores the result of ROW_COUNT() function. + + ROW_COUNT() function is a MySQL extention, but we try to keep it + similar to ROW_COUNT member of the GET DIAGNOSTICS stack of the SQL + standard (see SQL99, part 2, search for ROW_COUNT). It's value is + implementation defined for anything except INSERT, DELETE, UPDATE. + + ROW_COUNT is assigned according to the following rules: + + - In my_ok(): + - for DML statements: to the number of affected rows; + - for DDL statements: to 0. + + - In my_eof(): to -1 to indicate that there was a result set. + + We derive this semantics from the JDBC specification, where int + java.sql.Statement.getUpdateCount() is defined to (sic) "return the + current result as an update count; if the result is a ResultSet + object or there are no more results, -1 is returned". + + - In my_error(): to -1 to be compatible with the MySQL C API and + MySQL ODBC driver. + + - For SIGNAL statements: to 0 per WL#2110 specification (see also + sql_signal.cc comment). Zero is used since that's the "default" + value of ROW_COUNT in the diagnostics area. + */ + + longlong m_row_count_func; /* For the ROW_COUNT() function */ + +public: + inline longlong get_row_count_func() const + { + return m_row_count_func; + } + + inline void set_row_count_func(longlong row_count_func) + { + m_row_count_func= row_count_func; + } + ha_rows cuted_fields; /* @@ -2058,6 +2151,11 @@ public: /** is set if some thread specific value(s) used in a statement. */ bool thread_specific_used; + /** + is set if a statement accesses a temporary table created through + CREATE TEMPORARY TABLE. + */ + bool thread_temporary_used; bool charset_is_system_charset, charset_is_collation_connection; bool charset_is_character_set_filesystem; bool enable_slow_log; /* enable slow log for current statement */ @@ -2254,10 +2352,6 @@ public: { return limit_found_rows; } - inline bool active_transaction() - { - return server_status & SERVER_STATUS_IN_TRANS; - } /** Returns TRUE if session is in a multi-statement transaction mode. @@ -2268,11 +2362,60 @@ public: OPTION_BEGIN: Regardless of the autocommit status, a multi-statement transaction can be explicitly started with the statements "START TRANSACTION", "BEGIN [WORK]", "[COMMIT | ROLLBACK] AND CHAIN", etc. + + Note: this doesn't tell you whether a transaction is active. + A session can be in multi-statement transaction mode, and yet + have no active transaction, e.g., in case of: + set @@autocommit=0; + set @a= 3; <-- these statements don't + set transaction isolation level serializable; <-- start an active + flush tables; <-- transaction + + I.e. for the above scenario this function returns TRUE, even + though no active transaction has begun. + @sa in_active_multi_stmt_transaction() */ - inline bool in_multi_stmt_transaction() + inline bool in_multi_stmt_transaction_mode() { return variables.option_bits & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN); } + /** + TRUE if the session is in a multi-statement transaction mode + (@sa in_multi_stmt_transaction_mode()) *and* there is an + active transaction, i.e. there is an explicit start of a + transaction with BEGIN statement, or implicit with a + statement that uses a transactional engine. + + For example, these scenarios don't start an active transaction + (even though the server is in multi-statement transaction mode): + + set @@autocommit=0; + select * from nontrans_table; + set @var=TRUE; + flush tables; + + Note, that even for a statement that starts a multi-statement + transaction (i.e. select * from trans_table), this + flag won't be set until we open the statement's tables + and the engines register themselves for the transaction + (see trans_register_ha()), + hence this method is reliable to use only after + open_tables() has completed. + + Why do we need a flag? + ---------------------- + We need to maintain a (at first glance redundant) + session flag, rather than looking at thd->transaction.all.ha_list + because of explicit start of a transaction with BEGIN. + + I.e. in case of + BEGIN; + select * from nontrans_t1; <-- in_active_multi_stmt_transaction() is true + */ + inline bool in_active_multi_stmt_transaction() + { + return server_status & SERVER_STATUS_IN_TRANS; + } inline bool fill_derived_tables() { return !stmt_arena->is_stmt_prepare() && !lex->only_view_structure(); @@ -2481,11 +2624,11 @@ public: ("temporary_tables: %s, in_sub_stmt: %s, system_thread: %s", YESNO(temporary_tables), YESNO(in_sub_stmt), show_system_thread(system_thread))); - if ((temporary_tables == NULL) && (in_sub_stmt == 0)) + if (in_sub_stmt == 0) { if (variables.binlog_format == BINLOG_FORMAT_ROW) set_current_stmt_binlog_format_row(); - else + else if (temporary_tables == NULL) clear_current_stmt_binlog_format_row(); } DBUG_VOID_RETURN; @@ -2726,6 +2869,7 @@ inline void my_ok(THD *thd, ulonglong affected_rows= 0, ulonglong id= 0, const char *message= NULL) { + thd->set_row_count_func(affected_rows); thd->stmt_da->set_ok_status(thd, affected_rows, id, message); } @@ -2735,6 +2879,7 @@ my_ok(THD *thd, ulonglong affected_rows= 0, ulonglong id= 0, inline void my_eof(THD *thd) { + thd->set_row_count_func(-1); thd->stmt_da->set_eof_status(thd); } @@ -2766,8 +2911,6 @@ public: bool escaped_given(void); }; -#include "log_event.h" - /* This is used to get result from a select */ @@ -3398,7 +3541,7 @@ public: /* Bits in sql_command_flags */ #define CF_CHANGES_DATA (1U << 0) -#define CF_HAS_ROW_COUNT (1U << 1) +/* The 2nd bit is unused -- it used to be CF_HAS_ROW_COUNT. */ #define CF_STATUS_COMMAND (1U << 2) #define CF_SHOW_TABLE_COMMAND (1U << 3) #define CF_WRITE_LOGS_COMMAND (1U << 4) @@ -3484,13 +3627,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 e700dd93a55..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" 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..10bdb8a22a6 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 */ @@ -170,8 +187,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (prune_partitions(thd, table, conds)) { free_underlaid_joins(thd, select_lex); - thd->row_count_func= 0; - my_ok(thd, (ha_rows) thd->row_count_func); // No matching records + // No matching record + my_ok(thd, 0); DBUG_RETURN(0); } #endif @@ -187,7 +204,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, { delete select; free_underlaid_joins(thd, select_lex); - thd->row_count_func= 0; /* Error was already created by quick select evaluation (check_quick()). TODO: Add error code output parameter to Item::val_xxx() methods. @@ -196,7 +212,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, */ if (thd->is_error()) DBUG_RETURN(TRUE); - my_ok(thd, (ha_rows) thd->row_count_func); + my_ok(thd, 0); /* We don't need to call reset_auto_increment in this case, because mysql_truncate always gives a NULL conds argument, hence we never @@ -294,6 +310,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 +413,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 +448,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 || @@ -433,8 +459,7 @@ cleanup: If a TRUNCATE TABLE was issued, the number of rows should be reported as zero since the exact number is unknown. */ - thd->row_count_func= reset_auto_increment ? 0 : deleted; - my_ok(thd, (ha_rows) thd->row_count_func); + my_ok(thd, reset_auto_increment ? 0 : deleted); DBUG_PRINT("info",("%ld records deleted",(long) deleted)); } DBUG_RETURN(error >= 0 || thd->is_error()); @@ -1031,8 +1056,7 @@ bool multi_delete::send_eof() if (!local_error) { - thd->row_count_func= deleted; - ::my_ok(thd, (ha_rows) thd->row_count_func); + ::my_ok(thd, deleted); } return 0; } @@ -1049,12 +1073,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 +1090,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 dfa06495e9d..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> 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 7423dd9d292..1f9d69a798e 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" @@ -993,10 +1005,10 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (values_list.elements == 1 && (!(thd->variables.option_bits & OPTION_WARNINGS) || !thd->cuted_fields)) { - thd->row_count_func= info.copied + info.deleted + - ((thd->client_capabilities & CLIENT_FOUND_ROWS) ? - info.touched : info.updated); - my_ok(thd, (ulong) thd->row_count_func, id); + my_ok(thd, info.copied + info.deleted + + ((thd->client_capabilities & CLIENT_FOUND_ROWS) ? + info.touched : info.updated), + id); } else { @@ -1012,8 +1024,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records, (ulong) (info.deleted + updated), (ulong) thd->warning_info->statement_warn_count()); - thd->row_count_func= info.copied + info.deleted + updated; - ::my_ok(thd, (ulong) thd->row_count_func, id, buff); + ::my_ok(thd, info.copied + info.deleted + updated, id, buff); } thd->abort_on_warning= 0; DBUG_RETURN(FALSE); @@ -3325,7 +3336,7 @@ bool select_insert::send_eof() { int error; bool const trans_table= table->file->has_transactions(); - ulonglong id; + ulonglong id, row_count; bool changed; THD::killed_state killed_status= thd->killed; DBUG_ENTER("select_insert::send_eof"); @@ -3391,16 +3402,15 @@ bool select_insert::send_eof() sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records, (ulong) (info.deleted+info.updated), (ulong) thd->warning_info->statement_warn_count()); - thd->row_count_func= info.copied + info.deleted + - ((thd->client_capabilities & CLIENT_FOUND_ROWS) ? - info.touched : info.updated); - + row_count= info.copied + info.deleted + + ((thd->client_capabilities & CLIENT_FOUND_ROWS) ? + info.touched : info.updated); id= (thd->first_successful_insert_id_in_cur_stmt > 0) ? thd->first_successful_insert_id_in_cur_stmt : (thd->arg_of_last_insert_id_function ? thd->first_successful_insert_id_in_prev_stmt : (info.copied ? autoinc_value_of_last_inserted_row : 0)); - ::my_ok(thd, (ulong) thd->row_count_func, id, buff); + ::my_ok(thd, row_count, id, buff); DBUG_RETURN(0); } 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..1795bc272f1 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> @@ -52,7 +56,9 @@ Query_tables_list::binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT] = ER_BINLOG_UNSAFE_UDF, ER_BINLOG_UNSAFE_SYSTEM_VARIABLE, ER_BINLOG_UNSAFE_SYSTEM_FUNCTION, - ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS + ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS, + ER_BINLOG_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE, + ER_BINLOG_UNSAFE_MIXED_STATEMENT, }; @@ -136,37 +142,64 @@ st_parsing_options::reset() allows_derived= TRUE; } + +/** + Perform initialization of Lex_input_stream instance. + + Basically, a buffer for pre-processed query. This buffer should be large + enough to keep multi-statement query. The allocation is done once in the + Lex_input_stream constructor in order to prevent memory pollution when + the server is processing large multi-statement queries. + + @todo Check return value of THD::alloc(). +*/ + Lex_input_stream::Lex_input_stream(THD *thd, const char* buffer, unsigned int length) -: m_thd(thd), - yylineno(1), - yytoklen(0), - yylval(NULL), - lookahead_token(-1), - lookahead_yylval(NULL), - m_ptr(buffer), - m_tok_start(NULL), - m_tok_end(NULL), - m_end_of_query(buffer + length), - m_tok_start_prev(NULL), - m_buf(buffer), - m_buf_length(length), - m_echo(TRUE), - m_cpp_tok_start(NULL), - m_cpp_tok_start_prev(NULL), - m_cpp_tok_end(NULL), - m_body_utf8(NULL), - m_cpp_utf8_processed_ptr(NULL), - next_state(MY_LEX_START), - found_semicolon(NULL), - ignore_space(test(thd->variables.sql_mode & MODE_IGNORE_SPACE)), - stmt_prepare_mode(FALSE), - multi_statements(TRUE), - in_comment(NO_COMMENT), - m_underscore_cs(NULL) + :m_thd(thd) { m_cpp_buf= (char*) thd->alloc(length + 1); + reset(buffer, length); +} + + +/** + Prepare Lex_input_stream instance state for use for handling next SQL statement. + + It should be called between two statements in a multi-statement query. + The operation resets the input stream to the beginning-of-parse state, + but does not reallocate m_cpp_buf. +*/ + +void +Lex_input_stream::reset(const char *buffer, unsigned int length) +{ + yylineno= 1; + yytoklen= 0; + yylval= NULL; + lookahead_token= -1; + lookahead_yylval= NULL; + m_ptr= buffer; + m_tok_start= NULL; + m_tok_end= NULL; + m_end_of_query= buffer + length; + m_tok_start_prev= NULL; + m_buf= buffer; + m_buf_length= length; + m_echo= TRUE; + m_cpp_tok_start= NULL; + m_cpp_tok_start_prev= NULL; + m_cpp_tok_end= NULL; + m_body_utf8= NULL; + m_cpp_utf8_processed_ptr= NULL; + next_state= MY_LEX_START; + found_semicolon= NULL; + ignore_space= test(m_thd->variables.sql_mode & MODE_IGNORE_SPACE); + stmt_prepare_mode= FALSE; + multi_statements= TRUE; + in_comment=NO_COMMENT; + m_underscore_cs= NULL; m_cpp_ptr= m_cpp_buf; } @@ -344,7 +377,6 @@ void lex_start(THD *thd) lex->subqueries= FALSE; lex->view_prepare_mode= FALSE; lex->derived_tables= 0; - lex->lock_option= TL_READ; lex->safe_to_cache_query= 1; lex->leaf_tables_insert= 0; lex->parsing_options.reset(); @@ -357,7 +389,6 @@ void lex_start(THD *thd) lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc; lex->select_lex.group_list.empty(); lex->select_lex.order_list.empty(); - lex->sql_command= SQLCOM_END; lex->duplicates= DUP_ERROR; lex->ignore= 0; lex->spname= NULL; @@ -1702,7 +1733,6 @@ void st_select_lex::init_query() exclude_from_table_unique_test= no_wrap_view_item= FALSE; nest_level= 0; link_next= 0; - lock_option= TL_READ_DEFAULT; } void st_select_lex::init_select() @@ -2213,6 +2243,7 @@ void LEX::cleanup_lex_after_parse_error(THD *thd) void Query_tables_list::reset_query_tables_list(bool init) { + sql_command= SQLCOM_END; if (!init && query_tables) { TABLE_LIST *table= query_tables; @@ -2275,8 +2306,7 @@ void Query_tables_list::destroy_query_tables_list() */ LEX::LEX() - :result(0), - sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0) + :result(0), option_type(OPT_DEFAULT), is_lex_started(0) { my_init_dynamic_array2(&plugins, sizeof(plugin_ref), diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 0b27f73e763..2ce6bdeed42 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 */ @@ -721,14 +739,6 @@ public: List<udf_func> udf_list; /* udf function calls stack */ - /** - Per sub-query locking strategy. - Note: This variable might interfer with the corresponding statement-level - variable Lex::lock_option because on how different parser rules depend - on eachother. - */ - thr_lock_type lock_option; - /* This is a copy of the original JOIN USING list that comes from the parser. The parser : @@ -987,8 +997,11 @@ extern const LEX_STRING empty_lex_str; /* - Class representing list of all tables used by statement. - It also contains information about stored functions used by statement + Class representing list of all tables used by statement and other + information which is necessary for opening and locking its tables, + like SQL command for this statement. + + Also contains information about stored functions used by statement since during its execution we may have to add all tables used by its stored functions/triggers to this list in order to pre-open and lock them. @@ -1000,6 +1013,13 @@ extern const LEX_STRING empty_lex_str; class Query_tables_list { public: + /** + SQL command for this statement. Part of this class since the + process of opening and locking tables for the statement needs + this information to determine correct type of lock for some of + the tables. + */ + enum_sql_command sql_command; /* Global list of all tables used by this statement */ TABLE_LIST *query_tables; /* Pointer to next_global member of last element in the previous list. */ @@ -1143,6 +1163,18 @@ public: */ BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS, + /** + Mixing self-logging and non-self-logging engines in a statement + is unsafe. + */ + BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE, + + /** + Statements that read from both transactional and non-transactional + tables and write to any of them are unsafe. + */ + BINLOG_STMT_UNSAFE_MIXED_STATEMENT, + /* The last element of this enumeration type. */ BINLOG_STMT_UNSAFE_COUNT }; @@ -1347,6 +1379,8 @@ public: Lex_input_stream(THD *thd, const char* buff, unsigned int length); ~Lex_input_stream(); + void reset(const char *buff, unsigned int length); + /** Set the echo mode. @@ -1888,7 +1922,6 @@ struct LEX: public Query_tables_list the variable can contain 0 or 1 for each nest level. */ nesting_map allow_sum_func; - enum_sql_command sql_command; Sql_statement *m_stmt; @@ -1900,7 +1933,6 @@ struct LEX: public Query_tables_list */ bool expr_allows_subselect; - thr_lock_type lock_option; enum SSL_type ssl_type; /* defined in violite.h */ enum enum_duplicates duplicates; enum enum_tx_isolation tx_isolation; @@ -2176,8 +2208,8 @@ struct LEX: public Query_tables_list class Set_signal_information { public: - /** Constructor. */ - Set_signal_information(); + /** Empty default constructor, use clear() */ + Set_signal_information() {} /** Copy constructor. */ Set_signal_information(const Set_signal_information& set); @@ -2190,7 +2222,7 @@ public: void clear(); /** - For each contition item assignment, m_item[] contains the parsed tree + For each condition item assignment, m_item[] contains the parsed tree that represents the expression assigned, if any. m_item[] is an array indexed by Diag_condition_item_name. */ @@ -2207,12 +2239,30 @@ class Yacc_state { public: Yacc_state() - : yacc_yyss(NULL), yacc_yyvs(NULL) - {} + { + reset(); + } + + void reset() + { + yacc_yyss= NULL; + yacc_yyvs= NULL; + m_set_signal_info.clear(); + m_lock_type= TL_READ_DEFAULT; + } ~Yacc_state(); /** + Reset part of the state which needs resetting before parsing + substatement. + */ + void reset_before_substatement() + { + m_lock_type= TL_READ_DEFAULT; + } + + /** Bison internal state stack, yyss, when dynamically allocated using my_yyoverflow(). */ @@ -2230,6 +2280,25 @@ public: */ Set_signal_information m_set_signal_info; + /** + Type of lock to be used for tables being added to the statement's + table list in table_factor, table_alias_ref, single_multi and + table_wild_one rules. + Statements which use these rules but require lock type different + from one specified by this member have to override it by using + st_select_lex::set_lock_for_tables() method. + + The default value of this member is TL_READ_DEFAULT. The only two + cases in which we change it are: + - When parsing SELECT HIGH_PRIORITY. + - Rule for DELETE. In which we use this member to pass information + about type of lock from delete to single_multi part of rule. + + We should try to avoid introducing new use cases as we would like + to get rid of this member eventually. + */ + thr_lock_type m_lock_type; + /* TODO: move more attributes from the LEX structure here. */ @@ -2253,6 +2322,12 @@ public: Lex_input_stream m_lip; Yacc_state m_yacc; + + void reset(const char *found_semicolon, unsigned int length) + { + m_lip.reset(found_semicolon, length); + m_yacc.reset(); + } }; @@ -2287,6 +2362,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..ff9c16d229b 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" @@ -119,6 +132,7 @@ static int read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, const char* db_arg, /* table's database */ const char* table_name_arg, + bool is_concurrent, enum enum_duplicates duplicates, bool ignore, bool transactional_table, @@ -171,6 +185,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, char *tdb= thd->db ? thd->db : db; // Result is never null ulong skip_lines= ex->skip_lines; bool transactional_table; + bool is_concurrent; THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_load"); @@ -232,6 +247,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, table= table_list->table; transactional_table= table->file->has_transactions(); + is_concurrent= (table_list->lock_type == TL_WRITE_CONCURRENT_INSERT); if (!fields_vars.elements) { @@ -549,6 +565,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, (void) write_execute_load_query_log_event(thd, ex, table_list->db, table_list->table_name, + is_concurrent, handle_duplicates, ignore, transactional_table, errcode); @@ -597,6 +614,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, int errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); error= write_execute_load_query_log_event(thd, ex, table_list->db, table_list->table_name, + is_concurrent, handle_duplicates, ignore, transactional_table, errcode); @@ -625,6 +643,7 @@ err: static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, const char* db_arg, /* table's database */ const char* table_name_arg, + bool is_concurrent, enum enum_duplicates duplicates, bool ignore, bool transactional_table, @@ -660,8 +679,8 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, tbl= string_buf.c_ptr_safe(); } - Load_log_event lle(thd, ex, tdb, tbl, fv, duplicates, - ignore, transactional_table); + Load_log_event lle(thd, ex, tdb, tbl, fv, is_concurrent, + duplicates, ignore, transactional_table); /* force in a LOCAL if there was one in the original. @@ -683,7 +702,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, { if (n++) pfields.append(", "); - if (item->name) + if (item->type() == Item::FIELD_ITEM) { pfields.append("`"); pfields.append(item->name); 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 23e0d8c0d70..2e47ce1e02a 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" @@ -31,9 +92,12 @@ #include "transaction.h" #include "sql_audit.h" #include "sql_prepare.h" +#include "debug_sync.h" #include "probes_mysql.h" #include "set_var.h" +#define FLAGSTR(V,F) ((V)&(F)?#F" ":"") + /** @defgroup Runtime_Environment Runtime Environment @{ @@ -210,22 +274,20 @@ void init_update_queries(void) sql_command_flags[SQLCOM_CREATE_TRIGGER]= CF_AUTO_COMMIT_TRANS; sql_command_flags[SQLCOM_DROP_TRIGGER]= CF_AUTO_COMMIT_TRANS; - sql_command_flags[SQLCOM_UPDATE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE | CF_PROTECT_AGAINST_GRL; - sql_command_flags[SQLCOM_UPDATE_MULTI]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE | CF_PROTECT_AGAINST_GRL; - sql_command_flags[SQLCOM_INSERT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE | CF_PROTECT_AGAINST_GRL; - sql_command_flags[SQLCOM_INSERT_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE | CF_PROTECT_AGAINST_GRL; - sql_command_flags[SQLCOM_DELETE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE | CF_PROTECT_AGAINST_GRL; - sql_command_flags[SQLCOM_DELETE_MULTI]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE | CF_PROTECT_AGAINST_GRL; - sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE; - sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT | - CF_REEXECUTION_FRAGILE; + sql_command_flags[SQLCOM_UPDATE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE | + CF_PROTECT_AGAINST_GRL; + sql_command_flags[SQLCOM_UPDATE_MULTI]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE | + CF_PROTECT_AGAINST_GRL; + sql_command_flags[SQLCOM_INSERT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE | + CF_PROTECT_AGAINST_GRL; + sql_command_flags[SQLCOM_INSERT_SELECT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE | + CF_PROTECT_AGAINST_GRL; + sql_command_flags[SQLCOM_DELETE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE | + CF_PROTECT_AGAINST_GRL; + sql_command_flags[SQLCOM_DELETE_MULTI]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE | + CF_PROTECT_AGAINST_GRL; + sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE; + sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE; sql_command_flags[SQLCOM_SELECT]= CF_REEXECUTION_FRAGILE; sql_command_flags[SQLCOM_SET_OPTION]= CF_REEXECUTION_FRAGILE | CF_AUTO_COMMIT_TRANS; sql_command_flags[SQLCOM_DO]= CF_REEXECUTION_FRAGILE; @@ -303,8 +365,7 @@ void init_update_queries(void) last called (or executed) statement is preserved. See mysql_execute_command() for how CF_ROW_COUNT is used. */ - sql_command_flags[SQLCOM_CALL]= CF_HAS_ROW_COUNT | CF_REEXECUTION_FRAGILE; - sql_command_flags[SQLCOM_EXECUTE]= CF_HAS_ROW_COUNT; + sql_command_flags[SQLCOM_CALL]= CF_REEXECUTION_FRAGILE; /* The following admin table operations are allowed @@ -397,7 +458,6 @@ static void handle_bootstrap_impl(THD *thd) { MYSQL_FILE *file= bootstrap_file; char *buff; - const char* found_semicolon= NULL; DBUG_ENTER("handle_bootstrap"); @@ -470,7 +530,8 @@ static void handle_bootstrap_impl(THD *thd) mode we have only one thread. */ thd->set_time(); - mysql_parse(thd, thd->query(), length, & found_semicolon); + Parser_state parser_state(thd, thd->query(), length); + mysql_parse(thd, thd->query(), length, &parser_state); close_thread_tables(thd); // Free tables bootstrap_error= thd->is_error(); @@ -1013,19 +1074,21 @@ bool dispatch_command(enum enum_server_command command, THD *thd, (char *) thd->security_ctx->host_or_ip); char *packet_end= thd->query() + thd->query_length(); /* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */ - const char* end_of_stmt= NULL; general_log_write(thd, command, thd->query(), thd->query_length()); DBUG_PRINT("query",("%-.4096s",thd->query())); #if defined(ENABLED_PROFILING) thd->profiling.set_query_source(thd->query(), thd->query_length()); #endif + Parser_state parser_state(thd, thd->query(), thd->query_length()); - mysql_parse(thd, thd->query(), thd->query_length(), &end_of_stmt); + mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); - while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error()) + while (!thd->killed && (parser_state.m_lip.found_semicolon != NULL) && + ! thd->is_error()) { - char *beginning_of_next_stmt= (char*) end_of_stmt; + char *beginning_of_next_stmt= (char*) + parser_state.m_lip.found_semicolon; thd->protocol->end_statement(); query_cache_end_of_result(thd); @@ -1066,8 +1129,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, */ statistic_increment(thd->status_var.questions, &LOCK_status); thd->set_time(); /* Reset the query start time. */ + parser_state.reset(beginning_of_next_stmt, length); /* TODO: set thd->lex->sql_command to SQLCOM_END here */ - mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt); + mysql_parse(thd, beginning_of_next_stmt, length, &parser_state); } DBUG_PRINT("info",("query ready")); @@ -2115,6 +2179,11 @@ mysql_execute_command(THD *thd) if (thd->global_read_lock.wait_if_global_read_lock(thd, FALSE, TRUE)) goto error; +#ifndef DBUG_OFF + if (lex->sql_command != SQLCOM_SET_OPTION) + DEBUG_SYNC(thd,"before_execute_sql_command"); +#endif + switch (lex->sql_command) { case SQLCOM_SHOW_EVENTS: @@ -2696,7 +2765,7 @@ end_with_restore_list: client thread has locked tables */ if (thd->locked_tables_mode || - thd->active_transaction() || thd->global_read_lock.is_acquired()) + thd->in_active_multi_stmt_transaction() || thd->global_read_lock.is_acquired()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); @@ -2848,15 +2917,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; @@ -2869,6 +2943,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: %lx", + first_table->grant.privilege)); if (check_some_access(thd, SHOW_CREATE_TABLE_ACLS, first_table) || (first_table->grant.privilege & SHOW_CREATE_TABLE_ACLS) == 0) { @@ -3108,7 +3184,7 @@ end_with_restore_list: res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values, lex->update_list, lex->value_list, lex->duplicates, lex->ignore); - MYSQL_INSERT_DONE(res, (ulong) thd->row_count_func); + MYSQL_INSERT_DONE(res, (ulong) thd->get_row_count_func()); /* If we have inserted into a VIEW, and the base table has AUTO_INCREMENT column, but this column is not accessible through @@ -3174,7 +3250,7 @@ end_with_restore_list: delete sel_result; } /* revert changes for SP */ - MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->row_count_func); + MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func()); select_lex->table_list.first= (uchar*) first_table; } /* @@ -3197,7 +3273,7 @@ end_with_restore_list: Don't allow this within a transaction because we want to use re-generate table */ - if (thd->active_transaction()) + if (thd->in_active_multi_stmt_transaction()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); @@ -3220,7 +3296,7 @@ end_with_restore_list: &select_lex->order_list, unit->select_limit_cnt, select_lex->options, FALSE); - MYSQL_DELETE_DONE(res, (ulong) thd->row_count_func); + MYSQL_DELETE_DONE(res, (ulong) thd->get_row_count_func()); break; } case SQLCOM_DELETE_MULTI: @@ -4223,8 +4299,9 @@ create_sp_error: thd->server_status&= ~bits_to_be_cleared; if (!res) - my_ok(thd, (ulong) (thd->row_count_func < 0 ? 0 : - thd->row_count_func)); + { + my_ok(thd, (thd->get_row_count_func() < 0) ? 0 : thd->get_row_count_func()); + } else { DBUG_ASSERT(thd->is_error() || thd->killed); @@ -4611,15 +4688,6 @@ create_sp_error: if (thd->one_shot_set && lex->sql_command != SQLCOM_SET_OPTION) reset_one_shot_variables(thd); - /* - The return value for ROW_COUNT() is "implementation dependent" if the - statement is not DELETE, INSERT or UPDATE, but -1 is what JDBC and ODBC - wants. We also keep the last value in case of SQLCOM_CALL or - SQLCOM_EXECUTE. - */ - if (!(sql_command_flags[lex->sql_command] & CF_HAS_ROW_COUNT)) - thd->row_count_func= -1; - goto finish; error: @@ -4635,6 +4703,9 @@ finish: thd->global_read_lock.start_waiting_global_read_lock(thd); } + DBUG_ASSERT(!thd->in_active_multi_stmt_transaction() || + thd->in_multi_stmt_transaction_mode()); + if (stmt_causes_implicit_commit(thd, CF_IMPLICIT_COMMIT_END)) { /* If commit fails, we should be able to reset the OK status. */ @@ -5448,13 +5519,13 @@ void THD::reset_for_next_command() OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings in ha_rollback_trans() about some tables couldn't be rolled back. */ - if (!thd->in_multi_stmt_transaction()) + if (!thd->in_multi_stmt_transaction_mode()) { thd->variables.option_bits&= ~OPTION_KEEP_LOG; thd->transaction.all.modified_non_trans_table= FALSE; } DBUG_ASSERT(thd->security_ctx== &thd->main_security_ctx); - thd->thread_specific_used= FALSE; + thd->thread_specific_used= thd->thread_temporary_used= FALSE; if (opt_bin_log) { @@ -5634,7 +5705,6 @@ void mysql_init_multi_delete(LEX *lex) lex->select_lex.select_limit= 0; lex->unit.select_limit_cnt= HA_POS_ERROR; lex->select_lex.table_list.save_and_clear(&lex->auxiliary_table_list); - lex->lock_option= TL_READ_DEFAULT; lex->query_tables= 0; lex->query_tables_last= &lex->query_tables; } @@ -5656,7 +5726,7 @@ void mysql_init_multi_delete(LEX *lex) */ void mysql_parse(THD *thd, const char *inBuf, uint length, - const char ** found_semicolon) + Parser_state *parser_state) { int error; DBUG_ENTER("mysql_parse"); @@ -5686,10 +5756,7 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, { LEX *lex= thd->lex; - Parser_state parser_state(thd, inBuf, length); - - bool err= parse_sql(thd, & parser_state, NULL); - *found_semicolon= parser_state.m_lip.found_semicolon; + bool err= parse_sql(thd, parser_state, NULL); if (!err) { @@ -5704,6 +5771,7 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, { if (! thd->is_error()) { + const char *found_semicolon= parser_state->m_lip.found_semicolon; /* Binlog logs a string starting from thd->query and having length thd->query_length; so we set thd->query_length correctly (to not @@ -5714,12 +5782,12 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, PROCESSLIST. Note that we don't need LOCK_thread_count to modify query_length. */ - if (*found_semicolon && (ulong) (*found_semicolon - thd->query())) + if (found_semicolon && (ulong) (found_semicolon - thd->query())) thd->set_query_inner(thd->query(), - (uint32) (*found_semicolon - + (uint32) (found_semicolon - thd->query() - 1)); /* Actually execute the query */ - if (*found_semicolon) + if (found_semicolon) { lex->safe_to_cache_query= 0; thd->server_status|= SERVER_MORE_RESULTS_EXISTS; @@ -5756,11 +5824,6 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, thd->cleanup_after_query(); DBUG_ASSERT(thd->change_list.is_empty()); } - else - { - /* There are no multi queries in the cache. */ - *found_semicolon= NULL; - } DBUG_VOID_RETURN; } diff --git a/sql/sql_parse.h b/sql/sql_parse.h new file mode 100644 index 00000000000..e1543a09549 --- /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, + Parser_state *parser_state); +void mysql_reset_thd_for_next_command(THD *thd); +bool mysql_new_select(LEX *lex, bool move_down); +void create_select_for_variable(const char *var_name); +void create_table_set_open_action_and_adjust_tables(LEX *lex); +void mysql_init_multi_delete(LEX *lex); +bool multi_delete_set_locks_and_link_aux_tables(LEX *lex); +void create_table_set_open_action_and_adjust_tables(LEX *lex); +pthread_handler_t handle_bootstrap(void *arg); +bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, + bool *write_to_binlog); +int mysql_execute_command(THD *thd); +bool do_command(THD *thd); +void do_handle_bootstrap(THD *thd); +bool dispatch_command(enum enum_server_command command, THD *thd, + char* packet, uint packet_length); +void log_slow_statement(THD *thd); +bool append_file_to_dir(THD *thd, const char **filename_ptr, + const char *table_name); +bool append_file_to_dir(THD *thd, const char **filename_ptr, + const char *table_name); +void execute_init_command(THD *thd, LEX_STRING *init_command, + mysql_rwlock_t *var_lock); +bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type, + char *length, char *decimal, + uint type_modifier, + Item *default_value, Item *on_update_value, + LEX_STRING *comment, + char *change, List<String> *interval_list, + CHARSET_INFO *cs, + uint uint_geom_type); +bool add_to_list(THD *thd, SQL_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 7508b0c9fc0..4f6a62343cc 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" @@ -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++; } @@ -4533,6 +4554,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 8c16c7cbaae..2e0ea740555 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -20,12 +20,50 @@ #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 { longlong list_value; uint32 partition_id; @@ -87,6 +125,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. @@ -206,4 +245,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 94a35db3a2d..c2d3c595d95 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. @@ -1693,7 +1708,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt) res= select_like_stmt_test(stmt, 0, 0); - lex->link_first_table_back(create_table, &link_to_local); + lex->link_first_table_back(create_table, link_to_local); } else { @@ -3231,7 +3246,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len) locks have already been released and our savepoint points to ticket which has been released as well. */ - if (thd->in_multi_stmt_transaction()) + if (thd->in_multi_stmt_transaction_mode()) thd->mdl_context.rollback_to_savepoint(mdl_savepoint); thd->restore_backup_statement(this, &stmt_backup); thd->stmt_arena= old_stmt_arena; diff --git a/sql/sql_priv.h b/sql/sql_priv.h new file mode 100644 index 00000000000..20893e0caa8 --- /dev/null +++ b/sql/sql_priv.h @@ -0,0 +1,271 @@ +/* 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 SQL_PRIV_INCLUDED +#define SQL_PRIV_INCLUDED + +#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) +/** + Indicates that this is a HIGH_PRIORITY SELECT. + Currently used only for printing of such selects. + Type of locks to be acquired is specified directly. +*/ +#define SELECT_HIGH_PRIORITY (1ULL << 34) // SELECT, user + + +/* 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 /* SQL_PRIV_INCLUDED */ 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..ea95b59b0c2 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); @@ -45,7 +54,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) if the user is trying to to do this in a transcation context */ - if (thd->locked_tables_mode || thd->active_transaction()) + if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); 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..d126d0e4ec6 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; } /** @@ -17113,8 +17179,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) /* First add options */ if (options & SELECT_STRAIGHT_JOIN) str->append(STRING_WITH_LEN("straight_join ")); - if ((thd->lex->lock_option == TL_READ_HIGH_PRIORITY) && - (this == &thd->lex->select_lex)) + if (options & SELECT_HIGH_PRIORITY) str->append(STRING_WITH_LEN("high_priority ")); if (options & SELECT_DISTINCT) str->append(STRING_WITH_LEN("distinct ")); @@ -17150,7 +17215,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 e808cb2e888..931103a8b47 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. +/* Copyright 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,15 +11,31 @@ 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 */ /* 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>") @@ -641,7 +658,9 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) { Show_create_error_handler view_error_suppressor(thd, table_list); thd->push_internal_handler(&view_error_suppressor); - bool error= open_normal_and_derived_tables(thd, table_list, 0); + bool error= + open_normal_and_derived_tables(thd, table_list, + MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL); thd->pop_internal_handler(); if (error && (thd->killed || thd->is_error())) DBUG_RETURN(TRUE); @@ -815,7 +834,8 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild) DBUG_ENTER("mysqld_list_fields"); DBUG_PRINT("enter",("table: %s",table_list->table_name)); - if (open_normal_and_derived_tables(thd, table_list, 0)) + if (open_normal_and_derived_tables(thd, table_list, + MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL)) DBUG_VOID_RETURN; table= table_list->table; @@ -3321,7 +3341,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) LEX *lex= thd->lex; TABLE *table= tables->table; SELECT_LEX *old_all_select_lex= lex->all_selects_list; - enum_sql_command save_sql_command= lex->sql_command; SELECT_LEX *lsel= tables->schema_select_lex; ST_SCHEMA_TABLE *schema_table= tables->schema_table; SELECT_LEX sel; @@ -3357,6 +3376,12 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) lex->view_prepare_mode= TRUE; lex->reset_n_backup_query_tables_list(&query_tables_list_backup); + /* + Restore Query_tables_list::sql_command value, which was reset + above, as ST_SCHEMA_TABLE::process_table() functions often rely + that this value reflects which SHOW statement is executed. + */ + lex->sql_command= query_tables_list_backup.sql_command; /* We should not introduce deadlocks even if we already have some @@ -3519,7 +3544,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) (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; + lex->sql_command= query_tables_list_backup.sql_command; /* XXX: show_table_list has a flag i_is_requested, and when it's set, open_normal_and_derived_tables() @@ -3578,7 +3603,6 @@ err: lex->derived_tables= derived_tables; lex->all_selects_list= old_all_select_lex; lex->view_prepare_mode= save_view_prepare_mode; - lex->sql_command= save_sql_command; DBUG_RETURN(error); } 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..f340da373e8 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" @@ -75,10 +75,6 @@ const LEX_STRING Diag_statement_item_names[]= { C_STRING_WITH_LEN("TRANSACTION_ACTIVE") } }; -Set_signal_information::Set_signal_information() -{ - clear(); -} Set_signal_information::Set_signal_information( const Set_signal_information& set) @@ -458,8 +454,20 @@ bool Signal_statement::execute(THD *thd) DBUG_ENTER("Signal_statement::execute"); + /* + WL#2110 SIGNAL specification says: + + When SIGNAL is executed, it has five effects, in the following order: + + (1) First, the diagnostics area is completely cleared. So if the + SIGNAL is in a DECLARE HANDLER then any pending errors or warnings + are gone. So is 'row count'. + + This has roots in the SQL standard specification for SIGNAL. + */ + thd->stmt_da->reset_diagnostics_area(); - thd->row_count_func= 0; + thd->set_row_count_func(0); thd->warning_info->clear_warning_info(thd->query_id); result= raise_condition(thd, &cond); 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 266687f5829..19281dbbf37 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" @@ -1973,8 +1999,13 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, case 0: // removed temporary table tmp_table_deleted= 1; - if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED && - thd->is_current_stmt_binlog_format_row()) + /* + One needs to always log any temporary table drop if the current + statement logging format is set to row. This happens because one + might have created a temporary table while the statement logging + format was statement and then switched to mixed or row format. + */ + if (thd->is_current_stmt_binlog_format_row()) { if (built_tmp_query.is_empty()) { @@ -2166,7 +2197,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, deleted one or more non-temporary tables (and no temporary tables). In this case, we can write the original query into the binary log. - */ + */ error |= write_bin_log(thd, !error, thd->query(), thd->query_length()); } else if (thd->is_current_stmt_binlog_format_row() && @@ -2193,11 +2224,12 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } /* - One needs to always log any temporary table drop, if: - 1. thread logging format is mixed mode; AND - 2. current statement logging format is set to row. + One needs to always log any temporary table drop if the current + statement logging format is set to row. This happens because one + might have created a temporary table while the statement logging + format was statement and then switched to mixed or row format. */ - if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED) + if (thd->is_current_stmt_binlog_format_row()) { /* In this case we have deleted some temporary tables but we are using @@ -2208,8 +2240,14 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, */ built_tmp_query.chop(); // Chop of the last comma built_tmp_query.append(" /* generated by server */"); - error|= write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length(), - thd->in_multi_stmt_transaction()); + /* + We cannot call the write_bin_log as we do not care about any errors + in the master as the statement is always DROP TEMPORARY TABLE IF EXISTS + and as such there will be no errors in the slave. + */ + error|= thd->binlog_query(THD::STMT_QUERY_TYPE, built_tmp_query.ptr(), + built_tmp_query.length(), FALSE, FALSE, FALSE, + 0); } } @@ -3724,43 +3762,6 @@ void sp_prepare_create_field(THD *thd, Create_field *sql_field) (void) prepare_blob_field(thd, sql_field); } - -/* - Write CREATE TABLE binlog - - SYNOPSIS - write_create_table_bin_log() - thd Thread object - create_info Create information - internal_tmp_table Set to 1 if this is an internal temporary table - - DESCRIPTION - This function only is called in mysql_create_table_no_lock and - mysql_create_table - - RETURN VALUES - NONE - */ -static inline int write_create_table_bin_log(THD *thd, - const HA_CREATE_INFO *create_info, - bool internal_tmp_table) -{ - /* - Don't write statement if: - - It is an internal temporary table, - - Row-based logging is used and it we are creating a temporary table, or - - The binary log is not open. - Otherwise, the statement shall be binlogged. - */ - if (!internal_tmp_table && - (!thd->is_current_stmt_binlog_format_row() || - (thd->is_current_stmt_binlog_format_row() && - !(create_info->options & HA_LEX_CREATE_TMP_TABLE)))) - return write_bin_log(thd, TRUE, thd->query(), thd->query_length()); - return 0; -} - - /* Create a table @@ -4808,6 +4809,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, /* purecov: begin inspected */ char buff[FN_REFLEN + MYSQL_ERRMSG_SIZE]; size_t length; + enum_sql_command save_sql_command= lex->sql_command; DBUG_PRINT("admin", ("sending error message")); protocol->prepare_for_resend(); protocol->store(table_name, system_charset_info); @@ -4821,6 +4823,11 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, close_thread_tables(thd); thd->mdl_context.release_transactional_locks(); lex->reset_query_tables_list(FALSE); + /* + Restore Query_tables_list::sql_command value to make statement + safe for re-execution. + */ + lex->sql_command= save_sql_command; table->table=0; // For query cache if (protocol->write()) goto err; @@ -5017,11 +5024,17 @@ send_result_message: { /* Clear the ticket released in close_thread_tables(). */ table->mdl_request.ticket= NULL; - if ((table->table= open_ltable(thd, table, lock_type, 0)) && - ((result_code= table->table->file->ha_analyze(thd, check_opt)) > 0)) - result_code= 0; // analyze went ok - if (result_code) // analyze failed - table->table->file->print_error(result_code, MYF(0)); + DEBUG_SYNC(thd, "ha_admin_open_ltable"); + if ((table->table= open_ltable(thd, table, lock_type, 0))) + { + result_code= table->table->file->ha_analyze(thd, check_opt); + if (result_code == HA_ADMIN_ALREADY_DONE) + result_code= HA_ADMIN_OK; + else if (result_code) // analyze failed + table->table->file->print_error(result_code, MYF(0)); + } + else + result_code= -1; // open failed } /* Start a new row for the final status row */ protocol->prepare_for_resend(); @@ -5491,6 +5504,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 @@ -5579,6 +5631,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, @@ -6507,7 +6560,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if the user is trying to to do this in a transcation context */ - if (thd->locked_tables_mode || thd->active_transaction()) + if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); @@ -6859,10 +6912,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); @@ -7951,22 +8008,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..9ce62d9f2a4 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 /*************************************************************************/ @@ -399,6 +411,13 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) destructive changes necessary to open the trigger's table. */ thd->lex->reset_n_backup_query_tables_list(&backup); + /* + Restore Query_tables_list::sql_command, which was + reset above, as the code that writes the query to the + binary log assumes that this value corresponds to the + statement that is being executed. + */ + thd->lex->sql_command= backup.sql_command; if (add_table_for_trigger(thd, thd->lex->spname, if_exists, & tables)) goto end; 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 62a35335374..300ca1098fb 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 */ @@ -206,7 +222,6 @@ int mysql_update(THD *thd, 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"); if (open_tables(thd, &table_list, &table_count, 0)) @@ -828,9 +843,8 @@ int mysql_update(THD *thd, my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated, (ulong) thd->warning_info->statement_warn_count()); - thd->row_count_func= - (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated; - my_ok(thd, (ulong) thd->row_count_func, id, buff); + my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, + id, buff); DBUG_PRINT("info",("%ld records updated", (long) updated)); } thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */ @@ -956,7 +970,6 @@ 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); - 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 */ @@ -1040,7 +1053,7 @@ int mysql_multi_update_prepare(THD *thd) be write-locked (for example, trigger to be invoked might try to update this table). */ - tl->lock_type= read_lock_type_for_table(thd, table); + tl->lock_type= read_lock_type_for_table(thd, lex, tl); tl->updating= 0; /* Update TABLE::lock_type accordingly. */ if (!tl->placeholder() && !using_lock_tables) @@ -2136,8 +2149,7 @@ bool multi_update::send_eof() thd->first_successful_insert_id_in_prev_stmt : 0; my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated, (ulong) thd->cuted_fields); - thd->row_count_func= - (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated; - ::my_ok(thd, (ulong) thd->row_count_func, id, buff); + ::my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, + id, buff); DBUG_RETURN(FALSE); } 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..aa336f3c072 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 @@ -29,13 +29,21 @@ #define YYLEX_PARAM yythd #define YYTHD ((THD *)yythd) #define YYLIP (& YYTHD->m_parser_state->m_lip) +#define YYPS (& YYTHD->m_parser_state->m_yacc) #define MYSQL_YACC #define YYINITDEPTH 100 #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" @@ -4930,7 +4938,6 @@ create_select: SELECT_SYM { LEX *lex=Lex; - lex->lock_option= TL_READ_DEFAULT; if (lex->sql_command == SQLCOM_INSERT) lex->sql_command= SQLCOM_INSERT_SELECT; else if (lex->sql_command == SQLCOM_REPLACE) @@ -7295,7 +7302,6 @@ select_lock_type: { LEX *lex=Lex; lex->current_select->set_lock_for_tables(TL_WRITE); - lex->current_select->lock_option= TL_WRITE; lex->safe_to_cache_query=0; lex->protect_against_global_read_lock= TRUE; } @@ -7304,7 +7310,6 @@ select_lock_type: LEX *lex=Lex; lex->current_select-> set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS); - lex->current_select->lock_option= TL_READ_WITH_SHARED_LOCKS; lex->safe_to_cache_query=0; } ; @@ -8562,7 +8567,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 +8589,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); } } @@ -9214,7 +9219,7 @@ table_factor: { if (!($$= Select->add_table_to_list(YYTHD, $2, $3, Select->get_table_join_options(), - Lex->lock_option, + YYPS->m_lock_type, Select->pop_index_hints()))) MYSQL_YYABORT; Select->add_joined_table($$); @@ -9823,7 +9828,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; } @@ -10238,7 +10276,7 @@ table_alias_ref: { if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING | TL_OPTION_ALIAS, - Lex->lock_option )) + YYPS->m_lock_type)) MYSQL_YYABORT; } ; @@ -10263,8 +10301,6 @@ insert: lex->sql_command= SQLCOM_INSERT; lex->duplicates= DUP_ERROR; mysql_init_select(lex); - /* for subselects */ - lex->lock_option= TL_READ_DEFAULT; } insert_lock_option opt_ignore insert2 @@ -10455,7 +10491,6 @@ update: LEX *lex= Lex; mysql_init_select(lex); lex->sql_command= SQLCOM_UPDATE; - lex->lock_option= TL_UNLOCK; /* Will be set later */ lex->duplicates= DUP_ERROR; } opt_low_priority opt_ignore join_table_list @@ -10522,7 +10557,7 @@ delete: LEX *lex= Lex; lex->sql_command= SQLCOM_DELETE; mysql_init_select(lex); - lex->lock_option= TL_WRITE_DEFAULT; + YYPS->m_lock_type= TL_WRITE_DEFAULT; lex->ignore= 0; lex->select_lex.init_order(); } @@ -10533,20 +10568,27 @@ single_multi: FROM table_ident { if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING, - Lex->lock_option)) + YYPS->m_lock_type)) MYSQL_YYABORT; + YYPS->m_lock_type= TL_READ_DEFAULT; } where_clause opt_order_clause delete_limit_clause {} | table_wild_list - { mysql_init_multi_delete(Lex); } + { + mysql_init_multi_delete(Lex); + YYPS->m_lock_type= TL_READ_DEFAULT; + } FROM join_table_list where_clause { if (multi_delete_set_locks_and_link_aux_tables(Lex)) MYSQL_YYABORT; } | FROM table_alias_ref_list - { mysql_init_multi_delete(Lex); } + { + mysql_init_multi_delete(Lex); + YYPS->m_lock_type= TL_READ_DEFAULT; + } USING join_table_list where_clause { if (multi_delete_set_locks_and_link_aux_tables(Lex)) @@ -10569,7 +10611,7 @@ table_wild_one: ti, NULL, TL_OPTION_UPDATING | TL_OPTION_ALIAS, - Lex->lock_option)) + YYPS->m_lock_type)) MYSQL_YYABORT; } | ident '.' ident opt_wild @@ -10581,7 +10623,7 @@ table_wild_one: ti, NULL, TL_OPTION_UPDATING | TL_OPTION_ALIAS, - Lex->lock_option)) + YYPS->m_lock_type)) MYSQL_YYABORT; } ; @@ -10598,7 +10640,7 @@ opt_delete_options: opt_delete_option: QUICK { Select->options|= OPTION_QUICK; } - | LOW_PRIORITY { Lex->lock_option= TL_WRITE_LOW_PRIORITY; } + | LOW_PRIORITY { YYPS->m_lock_type= TL_WRITE_LOW_PRIORITY; } | IGNORE_SYM { Lex->ignore= 1; } ; @@ -10684,7 +10726,6 @@ show: { LEX *lex=Lex; lex->wild=0; - lex->lock_option= TL_READ; mysql_init_select(lex); lex->current_select->parsing_place= SELECT_LIST; bzero((char*) &lex->create_info,sizeof(lex->create_info)); @@ -11037,7 +11078,6 @@ describe: describe_command table_ident { LEX *lex= Lex; - lex->lock_option= TL_READ; mysql_init_select(lex); lex->current_select->parsing_place= SELECT_LIST; lex->sql_command= SQLCOM_SHOW_FIELDS; @@ -11251,7 +11291,6 @@ load: { LEX *lex=Lex; lex->sql_command= SQLCOM_LOAD; - lex->lock_option= $4; lex->local_file= $5; lex->duplicates= DUP_ERROR; lex->ignore= 0; @@ -11262,7 +11301,7 @@ load: { LEX *lex=Lex; if (!Select->add_table_to_list(YYTHD, $12, NULL, TL_OPTION_UPDATING, - lex->lock_option)) + $4)) MYSQL_YYABORT; lex->field_list.empty(); lex->update_list.empty(); @@ -13694,17 +13733,6 @@ subselect_start: subselect_end: { LEX *lex=Lex; - /* - Set the required lock level for the tables associated with the - current sub-select. This will overwrite previous lock options set - using st_select_lex::add_table_to_list in any of the following - rules: single_multi, table_wild_one, load_data, table_alias_ref, - table_factor. - The default lock level is TL_READ_DEFAULT but it can be modified - with query options specific for a certain (sub-)SELECT. - */ - lex->current_select-> - set_lock_for_tables(lex->current_select->lock_option); lex->pop_context(); SELECT_LEX *child= lex->current_select; @@ -13736,8 +13764,8 @@ query_expression_option: { if (check_simple_select()) MYSQL_YYABORT; - Lex->lock_option= TL_READ_HIGH_PRIORITY; - Lex->current_select->lock_option= TL_READ_HIGH_PRIORITY; + YYPS->m_lock_type= TL_READ_HIGH_PRIORITY; + Select->options|= SELECT_HIGH_PRIORITY; } | DISTINCT { Select->options|= SELECT_DISTINCT; } | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; } 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 e14286210b4..b8312fc3255 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -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 @@ -241,6 +258,12 @@ static bool check_has_super(sys_var *self, THD *thd, set_var *var) } static bool binlog_format_check(sys_var *self, THD *thd, set_var *var) { + if (check_has_super(self, thd, var)) + return true; + + if (var->type == OPT_GLOBAL) + return false; + /* If RBR and open temporary tables, their CREATE TABLE may not be in the binlog, so we can't toggle to SBR in this connection. @@ -272,18 +295,12 @@ static bool binlog_format_check(sys_var *self, THD *thd, set_var *var) /* Make the session variable 'binlog_format' read-only inside a transaction. */ - if (thd->active_transaction() && (var->type == OPT_SESSION)) + if (thd->in_active_multi_stmt_transaction()) { my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0)); return true; } - if (check_has_super(self, thd, var)) - return true; - if (var->type == OPT_GLOBAL || - (thd->variables.binlog_format == var->save_result.ulonglong_value)) - return false; - return false; } @@ -312,32 +329,31 @@ static Sys_var_enum Sys_binlog_format( static bool binlog_direct_check(sys_var *self, THD *thd, set_var *var) { + if (check_has_super(self, thd, var)) + return true; + + if (var->type == OPT_GLOBAL) + return false; + /* Makes the session variable 'binlog_direct_non_transactional_updates' - read-only inside a transaction. + read-only if within a procedure, trigger or function. */ - if (thd->active_transaction() && (var->type == OPT_SESSION)) + if (thd->in_sub_stmt) { - my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); - return 1; + my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); + return true; } /* Makes the session variable 'binlog_direct_non_transactional_updates' - read-only if within a procedure, trigger or function. + read-only inside a transaction. */ - if (thd->in_sub_stmt) + if (thd->in_active_multi_stmt_transaction()) { - my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); - return 1; + my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); + return true; } - if (check_has_super(self, thd, var)) - return true; - if (var->type == OPT_GLOBAL || - (thd->variables.binlog_direct_non_trans_update == - static_cast<my_bool>(var->save_result.ulonglong_value))) - return false; - return false; } @@ -1412,7 +1428,7 @@ static my_bool read_only; static bool check_read_only(sys_var *self, THD *thd, set_var *var) { /* Prevent self dead-lock */ - if (thd->locked_tables_mode || thd->active_transaction()) + if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction()) { my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); return true; @@ -1906,7 +1922,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 @@ -1990,15 +2006,20 @@ static Sys_var_ulong Sys_thread_pool_size( VALID_RANGE(1, 16384), DEFAULT(20), BLOCK_SIZE(0)); #endif -// Can't change the 'next' tx_isolation if we are already in a transaction +/** + Can't change the 'next' tx_isolation if we are already in a + transaction. +*/ + static bool check_tx_isolation(sys_var *self, THD *thd, set_var *var) { - if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS)) + if (var->type == OPT_DEFAULT && thd->in_active_multi_stmt_transaction()) { + DBUG_ASSERT(thd->in_multi_stmt_transaction_mode()); my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0)); - return true; + return TRUE; } - return false; + return FALSE; } /* @@ -2011,6 +2032,7 @@ static bool fix_tx_isolation(sys_var *self, THD *thd, enum_var_type type) thd->session_tx_isolation= (enum_tx_isolation)thd->variables.tx_isolation; return false; } + // NO_CMD_LINE - different name of the option static Sys_var_enum Sys_tx_isolation( "tx_isolation", "Default transaction isolation level", @@ -2803,7 +2825,7 @@ static Sys_var_charptr Sys_slave_load_tmpdir( static bool fix_slave_net_timeout(sys_var *self, THD *thd, enum_var_type type) { mysql_mutex_lock(&LOCK_active_mi); - DBUG_PRINT("info", ("slave_net_timeout=%lu mi->heartbeat_period=%.3f", + DBUG_PRINT("info", ("slave_net_timeout=%u mi->heartbeat_period=%.3f", slave_net_timeout, (active_mi? active_mi->heartbeat_period : 0.0))); if (active_mi && slave_net_timeout < active_mi->heartbeat_period) 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 8d63626fb81..5ffe1cf17ae 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" @@ -4071,9 +4084,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 2850f352bbd..af357807add 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, @@ -355,6 +488,19 @@ typedef struct st_table_field_def } TABLE_FIELD_DEF; +#ifdef WITH_PARTITION_STORAGE_ENGINE +/** + Partition specific ha_data struct. +*/ +typedef struct st_ha_data_partition +{ + bool auto_inc_initialized; + mysql_mutex_t LOCK_auto_inc; /**< protecting auto_inc val */ + ulonglong next_auto_inc_val; /**< first non reserved value */ +} HA_DATA_PARTITION; +#endif + + class Table_check_intact { protected: @@ -521,9 +667,9 @@ struct TABLE_SHARE #ifdef WITH_PARTITION_STORAGE_ENGINE /** place to store partition specific data, LOCK_ha_data hold while init. */ - void *ha_part_data; + HA_DATA_PARTITION *ha_part_data; /* Destructor for ha_part_data */ - void (*ha_part_data_destroy)(void *); + void (*ha_part_data_destroy)(HA_DATA_PARTITION *); #endif @@ -1865,4 +2011,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..5047de1ccdc 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" @@ -169,7 +169,7 @@ bool trans_commit_implicit(THD *thd) if (trans_check(thd)) DBUG_RETURN(TRUE); - if (thd->in_multi_stmt_transaction() || + if (thd->in_multi_stmt_transaction_mode() || (thd->variables.option_bits & OPTION_TABLE_LOCK)) { /* Safety if one did "drop table" on locked tables */ @@ -305,7 +305,7 @@ bool trans_savepoint(THD *thd, LEX_STRING name) SAVEPOINT **sv, *newsv; DBUG_ENTER("trans_savepoint"); - if (!(thd->in_multi_stmt_transaction() || thd->in_sub_stmt) || + if (!(thd->in_multi_stmt_transaction_mode() || thd->in_sub_stmt) || !opt_using_transactions) DBUG_RETURN(FALSE); @@ -467,7 +467,7 @@ bool trans_xa_start(THD *thd) my_error(ER_XAER_INVAL, MYF(0)); else if (xa_state != XA_NOTR) my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]); - else if (thd->locked_tables_mode || thd->active_transaction()) + else if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction()) my_error(ER_XAER_OUTSIDE, MYF(0)); else if (xid_cache_search(thd->lex->xid)) my_error(ER_XAER_DUPID, MYF(0)); diff --git a/sql/tztime.cc b/sql/tztime.cc index 7d88b7276f2..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. 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/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 |