diff options
Diffstat (limited to 'sql')
96 files changed, 4273 insertions, 12785 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 258e3caab9d..58ba26782f9 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -40,7 +40,8 @@ SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/sql_yacc.h ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN -DHAVE_EVENT_SCHEDULER) -ADD_EXECUTABLE(mysqld + +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 @@ -83,57 +84,45 @@ ADD_EXECUTABLE(mysqld ${PROJECT_SOURCE_DIR}/include/mysql_version.h ${PROJECT_SOURCE_DIR}/sql/sql_builtin.cc ${PROJECT_SOURCE_DIR}/sql/lex_hash.h) +ADD_LIBRARY(sql ${SQL_SOURCE}) -TARGET_LINK_LIBRARIES(mysqld - heap myisam myisammrg mysys yassl zlib debug dbug yassl - taocrypt strings vio regex libevent wsock32 ws2_32) +IF (NOT EXISTS cmake_dummy.cc) + FILE (WRITE cmake_dummy.cc "") +ENDIF (NOT EXISTS cmake_dummy.cc) +ADD_EXECUTABLE(mysqld cmake_dummy.cc) SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX}) +SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) + +SET (MYSQLD_CORE_LIBS mysys zlib dbug strings yassl taocrypt vio regex sql libevent) +TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_CORE_LIBS} ${MYSQLD_STATIC_ENGINE_LIBS}) +TARGET_LINK_LIBRARIES(mysqld ws2_32.lib) + -IF(cmake_version EQUAL 20406) -# Work around for 2.4.6 bug, OUTPUT_NAME will not set the right .PDB -# file name. Note that COMPILE_FLAGS set some temporary pdb during build, -# LINK_FLAGS sets the real one. -SET_TARGET_PROPERTIES(mysqld PROPERTIES - COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/mysqld${MYSQLD_EXE_SUFFIX}.pdb" - LINK_FLAGS "/PDB:${CMAKE_CFG_INTDIR}/mysqld${MYSQLD_EXE_SUFFIX}.pdb") -ENDIF(cmake_version EQUAL 20406) - -IF(EMBED_MANIFESTS) - MYSQL_EMBED_MANIFEST("mysqld" "asInvoker") -ENDIF(EMBED_MANIFESTS) -IF(WITH_ARCHIVE_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld archive) -ENDIF(WITH_ARCHIVE_STORAGE_ENGINE) -IF(WITH_BLACKHOLE_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld blackhole) -ENDIF(WITH_BLACKHOLE_STORAGE_ENGINE) -IF(WITH_CSV_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld csv) -ENDIF(WITH_CSV_STORAGE_ENGINE) -IF(WITH_EXAMPLE_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld example) -ENDIF(WITH_EXAMPLE_STORAGE_ENGINE) -IF(WITH_FEDERATED_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld federated) -ENDIF(WITH_FEDERATED_STORAGE_ENGINE) -IF(WITH_INNOBASE_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld innobase) -ENDIF(WITH_INNOBASE_STORAGE_ENGINE) -IF(WITH_MARIA_STORAGE_ENGINE) - TARGET_LINK_LIBRARIES(mysqld maria) -ENDIF(WITH_MARIA_STORAGE_ENGINE) - -ADD_DEPENDENCIES(mysqld GenError) - -# NOTE CMake 2.4.6 creates strange dependencies between files in OUTPUT, -# so for now we only list one if more than one +IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS) + # Set module definition file. Also use non-incremental linker, + # incremental appears to crash from time to time,if used with /DEF option + SET_TARGET_PROPERTIES(mysqld PROPERTIES LINK_FLAGS "/DEF:mysqld.def /INCREMENTAL:NO") + + FOREACH (CORELIB ${MYSQLD_CORE_LIBS}) + GET_TARGET_PROPERTY(LOC ${CORELIB} LOCATION) + FILE(TO_NATIVE_PATH ${LOC} LOC) + SET (LIB_LOCATIONS ${LIB_LOCATIONS} ${LOC}) + ENDFOREACH (CORELIB ${MYSQLD_CORE_LIBS}) + + ADD_CUSTOM_COMMAND(TARGET mysqld PRE_LINK + COMMAND cscript ARGS //nologo ${PROJECT_SOURCE_DIR}/win/create_def_file.js + ${PLATFORM} ${LIB_LOCATIONS} > mysqld.def + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sql) +ENDIF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS) + +ADD_DEPENDENCIES(sql GenError) # Sql Parser custom command ADD_CUSTOM_COMMAND( OUTPUT ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h -# ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc - COMMAND bison.exe ARGS -y -p MYSQL --defines=sql_yacc.h + ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc + COMMAND bison ARGS -y -p MYSQL --defines=sql_yacc.h --output=sql_yacc.cc sql_yacc.yy DEPENDS ${PROJECT_SOURCE_DIR}/sql/sql_yacc.yy) @@ -150,16 +139,16 @@ ADD_CUSTOM_COMMAND( ADD_CUSTOM_TARGET( GenServerSource ALL DEPENDS ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h -# ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc + ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc ${PROJECT_SOURCE_DIR}/sql/message.h -# ${PROJECT_SOURCE_DIR}/sql/message.rc + ${PROJECT_SOURCE_DIR}/sql/message.rc ${PROJECT_SOURCE_DIR}/sql/lex_hash.h) ADD_DEPENDENCIES(mysqld GenServerSource) # Remove the auto-generated files as part of 'Clean Solution' SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES - "lex_hash.h;sql_yacc.h;sql_yacc.cc") + "lex_hash.h;sql_yacc.h;sql_yacc.cc;mysqld.def") ADD_LIBRARY(udf_example MODULE udf_example.c udf_example.def) ADD_DEPENDENCIES(udf_example strings GenError) diff --git a/sql/Makefile.am b/sql/Makefile.am index e9e579edb0f..00342f7034e 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -139,7 +139,7 @@ mysql_tzinfo_to_sql_CXXFLAGS= -DTZINFO2SQL DEFS = -DMYSQL_SERVER \ -DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \ - -DDATADIR="\"$(MYSQLDATAdir)\"" \ + -DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \ -DSHAREDIR="\"$(MYSQLSHAREdir)\"" \ -DPLUGINDIR="\"$(pkgplugindir)\"" \ -DHAVE_EVENT_SCHEDULER \ diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 721279fb77c..331b437b7ff 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -1429,13 +1429,7 @@ Event_job_data::execute(THD *thd, bool drop) thd->variables.sql_mode= sql_mode; thd->variables.time_zone= time_zone; - /* - Peculiar initialization order is a crutch to avoid races in SHOW - PROCESSLIST which reads thd->{query/query_length} without a mutex. - */ - thd->query_length= 0; - thd->query= sp_sql.c_ptr_safe(); - thd->query_length= sp_sql.length(); + thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length()); { Parser_state parser_state(thd, thd->query, thd->query_length); @@ -1495,13 +1489,8 @@ end_no_lex_start: else { ulong saved_master_access; - /* - Peculiar initialization order is a crutch to avoid races in SHOW - PROCESSLIST which reads thd->{query/query_length} without a mutex. - */ - thd->query_length= 0; - thd->query= sp_sql.c_ptr_safe(); - thd->query_length= sp_sql.length(); + + thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length()); /* NOTE: even if we run in read-only mode, we should be able to lock @@ -1526,8 +1515,7 @@ end_no_lex_start: thd->end_statement(); thd->cleanup_after_query(); /* Avoid races with SHOW PROCESSLIST */ - thd->query_length= 0; - thd->query= NULL; + thd->set_query(NULL, 0); DBUG_PRINT("info", ("EXECUTED %s.%s ret: %d", dbname.str, name.str, ret)); diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 7a668e2e2d7..06b7bd3fc6a 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -158,6 +158,7 @@ deinit_event_thread(THD *thd) thread_count--; thread_running--; delete thd; + pthread_cond_broadcast(&COND_thread_count); pthread_mutex_unlock(&LOCK_thread_count); } @@ -426,6 +427,7 @@ Event_scheduler::start() thread_count--; thread_running--; delete new_thd; + pthread_cond_broadcast(&COND_thread_count); pthread_mutex_unlock(&LOCK_thread_count); } end: @@ -558,6 +560,7 @@ error: thread_count--; thread_running--; delete new_thd; + pthread_cond_broadcast(&COND_thread_count); pthread_mutex_unlock(&LOCK_thread_count); } delete event_name; @@ -633,13 +636,13 @@ Event_scheduler::stop() DBUG_PRINT("info", ("Scheduler thread has id %lu", scheduler_thd->thread_id)); /* Lock from delete */ - pthread_mutex_lock(&scheduler_thd->LOCK_delete); + pthread_mutex_lock(&scheduler_thd->LOCK_thd_data); /* This will wake up the thread if it waits on Queue's conditional */ sql_print_information("Event Scheduler: Killing the scheduler thread, " "thread id %lu", scheduler_thd->thread_id); scheduler_thd->awake(THD::KILL_CONNECTION); - pthread_mutex_unlock(&scheduler_thd->LOCK_delete); + pthread_mutex_unlock(&scheduler_thd->LOCK_thd_data); /* thd could be 0x0, when shutting down */ sql_print_information("Event Scheduler: " diff --git a/sql/events.cc b/sql/events.cc index 968e86c427b..c4c00e09b4a 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -411,6 +411,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, if (!(ret= db_repository->create_event(thd, parse_data, if_not_exists))) { Event_queue_element *new_element; + bool dropped= 0; if (!(new_element= new Event_queue_element())) ret= TRUE; // OOM @@ -418,8 +419,9 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, parse_data->name, new_element))) { - db_repository->drop_event(thd, parse_data->dbname, parse_data->name, - TRUE); + if (!db_repository->drop_event(thd, parse_data->dbname, parse_data->name, + TRUE)) + dropped= 1; delete new_element; } else @@ -428,6 +430,12 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, bool created; if (event_queue) event_queue->create_event(thd, new_element, &created); + } + /* + binlog the create event unless it's been successfully dropped + */ + if (!dropped) + { /* Binlog the create event. */ DBUG_ASSERT(thd->query && thd->query_length); write_bin_log(thd, TRUE, thd->query, thd->query_length); @@ -842,22 +850,23 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) } -/* - Inits the scheduler's structures. +/** + Initializes the scheduler's structures. - SYNOPSIS - Events::init() + @param opt_noacl_or_bootstrap + TRUE if there is --skip-grant-tables or --bootstrap + option. In that case we disable the event scheduler. - NOTES - This function is not synchronized. + @note This function is not synchronized. - RETURN VALUE - FALSE OK - TRUE Error in case the scheduler can't start + @retval FALSE Perhaps there was an error, and the event scheduler + is disabled. But the error is not fatal and the + server start up can continue. + @retval TRUE Fatal error. Startup must terminate (call unireg_abort()). */ bool -Events::init(my_bool opt_noacl) +Events::init(my_bool opt_noacl_or_bootstrap) { THD *thd; @@ -865,11 +874,6 @@ Events::init(my_bool opt_noacl) DBUG_ENTER("Events::init"); - /* Disable the scheduler if running with --skip-grant-tables */ - if (opt_noacl) - opt_event_scheduler= EVENTS_DISABLED; - - /* We need a temporary THD during boot */ if (!(thd= new THD())) { @@ -898,23 +902,30 @@ Events::init(my_bool opt_noacl) /* Since we allow event DDL even if the scheduler is disabled, check the system tables, as we might need them. + + If run with --skip-grant-tables or --bootstrap, don't try to do the + check of system tables and don't complain: in these modes the tables + are most likely not there and we're going to disable the event + scheduler anyway. */ - if (Event_db_repository::check_system_tables(thd)) + if (opt_noacl_or_bootstrap || Event_db_repository::check_system_tables(thd)) { - sql_print_error("Event Scheduler: An error occurred when initializing " - "system tables.%s", - opt_event_scheduler == EVENTS_DISABLED ? - "" : " Disabling the Event Scheduler."); + if (! opt_noacl_or_bootstrap) + { + sql_print_error("Event Scheduler: An error occurred when initializing " + "system tables. Disabling the Event Scheduler."); + check_system_tables_error= TRUE; + } /* Disable the scheduler since the system tables are not up to date */ opt_event_scheduler= EVENTS_DISABLED; - check_system_tables_error= TRUE; goto end; } /* Was disabled explicitly from the command line, or because we're running - with --skip-grant-tables, or because we have no system tables. + with --skip-grant-tables, or --bootstrap, or because we have no system + tables. */ if (opt_event_scheduler == Events::EVENTS_DISABLED) goto end; diff --git a/sql/field.cc b/sql/field.cc index a278c125df2..5bce6a412fc 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4599,7 +4599,6 @@ bool Field_double::send_binary(Protocol *protocol) int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr) { - ASSERT_COLUMN_MARKED_FOR_READ; double a,b; #ifdef WORDS_BIGENDIAN if (table->s->db_low_byte_first) @@ -5308,7 +5307,7 @@ bool Field_time::get_time(MYSQL_TIME *ltime) ltime->neg= 1; tmp=-tmp; } - ltime->day= 0; + ltime->year= ltime->month= ltime->day= 0; ltime->hour= (int) (tmp/10000); tmp-=ltime->hour*10000; ltime->minute= (int) tmp/100; @@ -6270,48 +6269,15 @@ check_string_copy_error(Field_str *field, const char *end, CHARSET_INFO *cs) { - const char *pos, *end_orig; - char tmp[64], *t; + const char *pos; + char tmp[32]; if (!(pos= well_formed_error_pos) && !(pos= cannot_convert_error_pos)) return FALSE; - end_orig= end; - set_if_smaller(end, pos + 6); + convert_to_printable(tmp, sizeof(tmp), pos, (end - pos), cs, 6); - for (t= tmp; pos < end; pos++) - { - /* - If the source string is ASCII compatible (mbminlen==1) - and the source character is in ASCII printable range (0x20..0x7F), - then display the character as is. - - Otherwise, if the source string is not ASCII compatible (e.g. UCS2), - or the source character is not in the printable range, - then print the character using HEX notation. - */ - if (((unsigned char) *pos) >= 0x20 && - ((unsigned char) *pos) <= 0x7F && - cs->mbminlen == 1) - { - *t++= *pos; - } - else - { - *t++= '\\'; - *t++= 'x'; - *t++= _dig_vec_upper[((unsigned char) *pos) >> 4]; - *t++= _dig_vec_upper[((unsigned char) *pos) & 15]; - } - } - if (end_orig > end) - { - *t++= '.'; - *t++= '.'; - *t++= '.'; - } - *t= '\0'; push_warning_printf(field->table->in_use, field->table->in_use->abort_on_warning ? MYSQL_ERROR::WARN_LEVEL_ERROR : @@ -6453,13 +6419,13 @@ int Field_str::store(double nr) calculate the maximum number of significant digits if the 'f'-format would be used (+1 for decimal point if the number has a fractional part). */ - digits= max(0, (int) max_length - fractional); + digits= max(1, (int) max_length - fractional); /* If the exponent is negative, decrease digits by the number of leading zeros after the decimal point that do not count as significant digits. */ if (exp < 0) - digits= max(0, (int) digits + exp); + digits= max(1, (int) digits + exp); /* 'e'-format is used only if the exponent is less than -4 or greater than or equal to the precision. In this case we need to adjust the number of @@ -6467,7 +6433,7 @@ int Field_str::store(double nr) We also have to reserve one additional character if abs(exp) >= 100. */ if (exp >= (int) digits || exp < -4) - digits= max(0, (int) (max_length - 5 - (exp >= 100 || exp <= -100))); + digits= max(1, (int) (max_length - 5 - (exp >= 100 || exp <= -100))); /* Limit precision to DBL_DIG to avoid garbage past significant digits */ set_if_smaller(digits, DBL_DIG); @@ -9692,16 +9658,16 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, else if (tmp_length > PRECISION_FOR_FLOAT) { sql_type= MYSQL_TYPE_DOUBLE; - length= DBL_DIG+7; /* -[digits].E+### */ + length= MAX_DOUBLE_STR_LENGTH; } else - length= FLT_DIG+6; /* -[digits].E+## */ + length= MAX_FLOAT_STR_LENGTH; decimals= NOT_FIXED_DEC; break; } if (!fld_length && !fld_decimals) { - length= FLT_DIG+6; + length= MAX_FLOAT_STR_LENGTH; decimals= NOT_FIXED_DEC; } if (length < decimals && diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 9be4bfba9ab..c6b48c5b744 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -1247,7 +1247,7 @@ int ha_ndbcluster::add_index_handle(THD *thd, NDBDICT *dict, KEY *key_info, } if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX) { - char unique_index_name[FN_LEN]; + char unique_index_name[FN_LEN + 1]; static const char* unique_suffix= "$unique"; m_has_unique_index= TRUE; strxnmov(unique_index_name, FN_LEN, index_name, unique_suffix, NullS); @@ -5152,7 +5152,7 @@ int ha_ndbcluster::create(const char *name, uchar *data= NULL, *pack_data= NULL; bool create_from_engine= (create_info->table_options & HA_OPTION_CREATE_FROM_ENGINE); bool is_truncate= (thd->lex->sql_command == SQLCOM_TRUNCATE); - char tablespace[FN_LEN]; + char tablespace[FN_LEN + 1]; NdbDictionary::Table::SingleUserMode single_user_mode= NdbDictionary::Table::SingleUserModeLocked; DBUG_ENTER("ha_ndbcluster::create"); @@ -5615,7 +5615,7 @@ int ha_ndbcluster::create_index(const char *name, KEY *key_info, NDB_INDEX_TYPE idx_type, uint idx_no) { int error= 0; - char unique_name[FN_LEN]; + char unique_name[FN_LEN + 1]; static const char* unique_suffix= "$unique"; DBUG_ENTER("ha_ndbcluster::create_ordered_index"); DBUG_PRINT("info", ("Creating index %u: %s", idx_no, name)); @@ -6664,7 +6664,7 @@ int ndbcluster_discover(handlerton *hton, THD* thd, const char *db, size_t len; uchar* data= NULL; Ndb* ndb; - char key[FN_REFLEN]; + char key[FN_REFLEN + 1]; DBUG_ENTER("ndbcluster_discover"); DBUG_PRINT("enter", ("db: %s, name: %s", db, name)); @@ -6675,7 +6675,7 @@ int ndbcluster_discover(handlerton *hton, THD* thd, const char *db, ERR_RETURN(ndb->getNdbError()); } NDBDICT* dict= ndb->getDictionary(); - build_table_filename(key, sizeof(key), db, name, "", 0); + build_table_filename(key, sizeof(key) - 1, db, name, "", 0); /* ndb_share reference temporary */ NDB_SHARE *share= get_share(key, 0, FALSE); if (share) @@ -6840,9 +6840,9 @@ int ndbcluster_drop_database_impl(const char *path) drop_list.push_back(thd->strdup(elmt.name)); } // Drop any tables belonging to database - char full_path[FN_REFLEN]; + char full_path[FN_REFLEN + 1]; char *tmp= full_path + - build_table_filename(full_path, sizeof(full_path), dbname, "", "", 0); + build_table_filename(full_path, sizeof(full_path) - 1, dbname, "", "", 0); if (ndb->setDatabaseName(dbname)) { ERR_RETURN(ndb->getNdbError()); @@ -6911,7 +6911,7 @@ int ndb_create_table_from_engine(THD *thd, const char *db, int ndbcluster_find_all_files(THD *thd) { Ndb* ndb; - char key[FN_REFLEN]; + char key[FN_REFLEN + 1]; NDBDICT *dict; int unhandled, retries= 5, skipped; DBUG_ENTER("ndbcluster_find_all_files"); @@ -6969,7 +6969,7 @@ int ndbcluster_find_all_files(THD *thd) /* check if database exists */ char *end= key + - build_table_filename(key, sizeof(key), elmt.database, "", "", 0); + build_table_filename(key, sizeof(key) - 1, elmt.database, "", "", 0); if (my_access(key, F_OK)) { /* no such database defined, skip table */ @@ -7050,7 +7050,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, { // extra bracket to avoid gcc 2.95.3 warning uint i; Ndb* ndb; - char name[FN_REFLEN]; + char name[FN_REFLEN + 1]; HASH ndb_tables, ok_tables; NDBDICT::List list; @@ -7120,7 +7120,8 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, DBUG_PRINT("info", ("%s", file_name->str)); if (hash_search(&ndb_tables, (uchar*) file_name->str, file_name->length)) { - build_table_filename(name, sizeof(name), db, file_name->str, reg_ext, 0); + build_table_filename(name, sizeof(name) - 1, db, + file_name->str, reg_ext, 0); if (my_access(name, F_OK)) { pthread_mutex_lock(&LOCK_open); @@ -7142,7 +7143,8 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, } // Check for .ndb file with this name - build_table_filename(name, sizeof(name), db, file_name->str, ha_ndb_ext, 0); + build_table_filename(name, sizeof(name) - 1, db, + file_name->str, ha_ndb_ext, 0); DBUG_PRINT("info", ("Check access for %s", name)); if (my_access(name, F_OK)) { @@ -7185,7 +7187,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, /* setup logging to binlog for all discovered tables */ { char *end, *end1= name + - build_table_filename(name, sizeof(name), db, "", "", 0); + build_table_filename(name, sizeof(name) - 1, db, "", "", 0); for (i= 0; i < ok_tables.records; i++) { file_name_str= (char*)hash_element(&ok_tables, i); @@ -7207,7 +7209,8 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, file_name_str= (char*) hash_element(&ndb_tables, i); if (!hash_search(&ok_tables, (uchar*) file_name_str, strlen(file_name_str))) { - build_table_filename(name, sizeof(name), db, file_name_str, reg_ext, 0); + build_table_filename(name, sizeof(name) - 1, + db, file_name_str, reg_ext, 0); if (my_access(name, F_OK)) { DBUG_PRINT("info", ("%s must be discovered", file_name_str)); @@ -7587,7 +7590,7 @@ void ndbcluster_print_error(int error, const NdbOperation *error_op) void ha_ndbcluster::set_dbname(const char *path_name, char *dbname) { char *end, *ptr, *tmp_name; - char tmp_buff[FN_REFLEN]; + char tmp_buff[FN_REFLEN + 1]; tmp_name= tmp_buff; /* Scan name from the end */ @@ -7613,7 +7616,7 @@ void ha_ndbcluster::set_dbname(const char *path_name, char *dbname) ptr++; } #endif - filename_to_tablename(tmp_name, dbname, FN_REFLEN); + filename_to_tablename(tmp_name, dbname, sizeof(tmp_buff) - 1); } /** @@ -7633,7 +7636,7 @@ void ha_ndbcluster::set_tabname(const char *path_name, char * tabname) { char *end, *ptr, *tmp_name; - char tmp_buff[FN_REFLEN]; + char tmp_buff[FN_REFLEN + 1]; tmp_name= tmp_buff; /* Scan name from the end */ @@ -7654,7 +7657,7 @@ ha_ndbcluster::set_tabname(const char *path_name, char * tabname) ptr++; } #endif - filename_to_tablename(tmp_name, tabname, FN_REFLEN); + filename_to_tablename(tmp_name, tabname, sizeof(tmp_buff) - 1); } /** @@ -7840,11 +7843,12 @@ uint8 ha_ndbcluster::table_cache_type() uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, Uint64 *commit_count) { - char name[FN_REFLEN]; + char name[FN_REFLEN + 1]; NDB_SHARE *share; DBUG_ENTER("ndb_get_commitcount"); - build_table_filename(name, sizeof(name), dbname, tabname, "", 0); + build_table_filename(name, sizeof(name) - 1, + dbname, tabname, "", 0); DBUG_PRINT("enter", ("name: %s", name)); pthread_mutex_lock(&ndbcluster_mutex); if (!(share=(NDB_SHARE*) hash_search(&ndbcluster_open_tables, @@ -9950,7 +9954,7 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *create_info, ai=1; } - char tablespace_name[FN_LEN]; + char tablespace_name[FN_LEN + 1]; if (get_tablespace_name(current_thd, tablespace_name, FN_LEN)) { if (create_info->tablespace) diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index 4f25068feb8..baca22dffc7 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -253,8 +253,7 @@ static void run_query(THD *thd, char *buf, char *end, const char* found_semicolon= NULL; bzero((char*) &thd->net, sizeof(NET)); - thd->query_length= end - buf; - thd->query= buf; + thd->set_query(buf, (uint) (end - buf)); thd->variables.pseudo_thread_id= thread_id; thd->transaction.stmt.modified_non_trans_table= FALSE; if (disable_binlog) @@ -297,8 +296,7 @@ static void run_query(THD *thd, char *buf, char *end, thd->main_da.reset_diagnostics_area(); thd->options= save_thd_options; - thd->query_length= save_thd_query_length; - thd->query= save_thd_query; + thd->set_query(save_thd_query, save_thd_query_length); thd->variables.pseudo_thread_id= save_thread_id; thd->status_var= save_thd_status_var; thd->transaction.all= save_thd_transaction_all; @@ -788,7 +786,7 @@ static int ndbcluster_create_ndb_apply_status_table(THD *thd) if (g_ndb_cluster_connection->get_no_ready() <= 0) DBUG_RETURN(0); - char buf[1024], *end; + char buf[1024 + 1], *end; if (ndb_extra_logging) sql_print_information("NDB: Creating " NDB_REP_DB "." NDB_APPLY_TABLE); @@ -798,7 +796,7 @@ static int ndbcluster_create_ndb_apply_status_table(THD *thd) if so, remove it since there is none in Ndb */ { - build_table_filename(buf, sizeof(buf), + build_table_filename(buf, sizeof(buf) - 1, NDB_REP_DB, NDB_APPLY_TABLE, reg_ext, 0); my_delete(buf, MYF(0)); } @@ -846,7 +844,7 @@ static int ndbcluster_create_schema_table(THD *thd) if (g_ndb_cluster_connection->get_no_ready() <= 0) DBUG_RETURN(0); - char buf[1024], *end; + char buf[1024 + 1], *end; if (ndb_extra_logging) sql_print_information("NDB: Creating " NDB_REP_DB "." NDB_SCHEMA_TABLE); @@ -856,7 +854,7 @@ static int ndbcluster_create_schema_table(THD *thd) if so, remove it since there is none in Ndb */ { - build_table_filename(buf, sizeof(buf), + build_table_filename(buf, sizeof(buf) - 1, NDB_REP_DB, NDB_SCHEMA_TABLE, reg_ext, 0); my_delete(buf, MYF(0)); } @@ -1321,8 +1319,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, NDB_SCHEMA_OBJECT *ndb_schema_object; { - char key[FN_REFLEN]; - build_table_filename(key, sizeof(key), db, table_name, "", 0); + char key[FN_REFLEN + 1]; + build_table_filename(key, sizeof(key) - 1, db, table_name, "", 0); ndb_schema_object= ndb_get_schema_object(key, TRUE, FALSE); } @@ -1676,7 +1674,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, if (is_remote_change && is_online_alter_table) { const char *tabname= table_share->table_name.str; - char key[FN_REFLEN]; + char key[FN_REFLEN + 1]; uchar *data= 0, *pack_data= 0; size_t length, pack_length; int error; @@ -1685,7 +1683,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, DBUG_PRINT("info", ("Detected frm change of table %s.%s", dbname, tabname)); - build_table_filename(key, FN_LEN-1, dbname, tabname, NullS, 0); + build_table_filename(key, FN_LEN - 1, dbname, tabname, NullS, 0); /* If the there is no local table shadowing the altered table and it has an frm that is different than the one on disk then @@ -1857,9 +1855,11 @@ static void ndb_binlog_query(THD *thd, Cluster_schema *schema) else thd->server_id= schema->any_value; thd->db= schema->db; + int errcode = query_error_code(thd, thd->killed == THD::NOT_KILLED); thd->binlog_query(THD::STMT_QUERY_TYPE, schema->query, schema->query_length, FALSE, - schema->name[0] == 0 || thd->db[0] == 0); + schema->name[0] == 0 || thd->db[0] == 0, + errcode); thd->server_id= thd_server_id_save; thd->db= thd_db_save; } @@ -1926,8 +1926,8 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, break; case SOT_TRUNCATE_TABLE: { - char key[FN_REFLEN]; - build_table_filename(key, sizeof(key), + char key[FN_REFLEN + 1]; + build_table_filename(key, sizeof(key) - 1, schema->db, schema->name, "", 0); /* ndb_share reference temporary, free below */ NDB_SHARE *share= get_share(key, 0, FALSE, FALSE); @@ -2173,8 +2173,8 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd, int log_query= 0; { enum SCHEMA_OP_TYPE schema_type= (enum SCHEMA_OP_TYPE)schema->type; - char key[FN_REFLEN]; - build_table_filename(key, sizeof(key), schema->db, schema->name, "", 0); + char key[FN_REFLEN + 1]; + build_table_filename(key, sizeof(key) - 1, schema->db, schema->name, "", 0); if (schema_type == SOT_CLEAR_SLOCK) { pthread_mutex_lock(&ndbcluster_mutex); @@ -2508,8 +2508,8 @@ ndb_rep_event_name(String *event_name,const char *db, const char *tbl) bool ndbcluster_check_if_local_table(const char *dbname, const char *tabname) { - char key[FN_REFLEN]; - char ndb_file[FN_REFLEN]; + char key[FN_REFLEN + 1]; + char ndb_file[FN_REFLEN + 1]; DBUG_ENTER("ndbcluster_check_if_local_table"); build_table_filename(key, FN_LEN-1, dbname, tabname, reg_ext, 0); @@ -2534,9 +2534,9 @@ ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname) DBUG_PRINT("info", ("Looking for files in directory %s", dbname)); LEX_STRING *tabname; List<LEX_STRING> files; - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; - build_table_filename(path, sizeof(path), dbname, "", "", 0); + build_table_filename(path, sizeof(path) - 1, dbname, "", "", 0); if (find_files(thd, &files, dbname, path, NullS, 0) != FIND_FILES_OK) { DBUG_PRINT("info", ("Failed to find files")); @@ -3755,7 +3755,6 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) if (ndbcluster_terminating) { pthread_mutex_unlock(&LOCK_server_started); - pthread_mutex_lock(&LOCK_ndb_util_thread); goto err; } } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 79724ebcc60..10e011ec06f 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -423,12 +423,9 @@ bool ha_partition::initialize_partition(MEM_ROOT *mem_root) int ha_partition::delete_table(const char *name) { - int error; DBUG_ENTER("ha_partition::delete_table"); - if ((error= del_ren_cre_table(name, NULL, NULL, NULL))) - DBUG_RETURN(error); - DBUG_RETURN(handler::delete_table(name)); + DBUG_RETURN(del_ren_cre_table(name, NULL, NULL, NULL)); } @@ -456,12 +453,9 @@ int ha_partition::delete_table(const char *name) int ha_partition::rename_table(const char *from, const char *to) { - int error; DBUG_ENTER("ha_partition::rename_table"); - if ((error= del_ren_cre_table(from, to, NULL, NULL))) - DBUG_RETURN(error); - DBUG_RETURN(handler::rename_table(from, to)); + DBUG_RETURN(del_ren_cre_table(from, to, NULL, NULL)); } @@ -1807,6 +1801,15 @@ uint ha_partition::del_ren_cre_table(const char *from, DBUG_PRINT("enter", ("from: (%s) to: (%s)", from, to)); name_buffer_ptr= m_name_buffer_ptr; file= m_file; + if (to == NULL && table_arg == NULL) + { + /* + Delete table, start by delete the .par file. If error, break, otherwise + delete as much as possible. + */ + if ((error= handler::delete_table(from))) + DBUG_RETURN(error); + } /* Since ha_partition has HA_FILE_BASED, it must alter underlying table names if they do not have HA_FILE_BASED and lower_case_table_names == 2. @@ -1828,6 +1831,8 @@ uint ha_partition::del_ren_cre_table(const char *from, create_partition_name(to_buff, to_path, name_buffer_ptr, NORMAL_PART_NAME, FALSE); error= (*file)->ha_rename_table(from_buff, to_buff); + if (error) + goto rename_error; } else if (table_arg == NULL) // delete branch error= (*file)->ha_delete_table(from_buff); @@ -1843,6 +1848,15 @@ uint ha_partition::del_ren_cre_table(const char *from, save_error= error; i++; } while (*(++file)); + if (to != NULL) + { + if ((error= handler::rename_table(from, to))) + { + /* Try to revert everything, ignore errors */ + (void) handler::rename_table(to, from); + goto rename_error; + } + } DBUG_RETURN(save_error); create_error: name_buffer_ptr= m_name_buffer_ptr; @@ -1850,7 +1864,21 @@ create_error: { create_partition_name(from_buff, from_path, name_buffer_ptr, NORMAL_PART_NAME, FALSE); - VOID((*file)->ha_delete_table((const char*) from_buff)); + (void) (*file)->ha_delete_table((const char*) from_buff); + name_buffer_ptr= strend(name_buffer_ptr) + 1; + } + DBUG_RETURN(error); +rename_error: + name_buffer_ptr= m_name_buffer_ptr; + for (abort_file= file, file= m_file; file < abort_file; file++) + { + /* Revert the rename, back from 'to' to the original 'from' */ + create_partition_name(from_buff, from_path, name_buffer_ptr, + NORMAL_PART_NAME, FALSE); + create_partition_name(to_buff, to_path, name_buffer_ptr, + NORMAL_PART_NAME, FALSE); + /* Ignore error here */ + (void) (*file)->ha_rename_table(to_buff, from_buff); name_buffer_ptr= strend(name_buffer_ptr) + 1; } DBUG_RETURN(error); @@ -3179,6 +3207,7 @@ int ha_partition::delete_row(const uchar *buf) int ha_partition::delete_all_rows() { int error; + bool truncate= FALSE; handler **file; THD *thd= ha_thd(); DBUG_ENTER("ha_partition::delete_all_rows"); @@ -3190,12 +3219,16 @@ int ha_partition::delete_all_rows() ha_data->next_auto_inc_val= 0; ha_data->auto_inc_initialized= FALSE; unlock_auto_increment(); + truncate= TRUE; } file= m_file; do { if ((error= (*file)->ha_delete_all_rows())) DBUG_RETURN(error); + /* Ignore the error */ + if (truncate) + (void) (*file)->ha_reset_auto_increment(0); } while (*(++file)); DBUG_RETURN(0); } @@ -3698,7 +3731,7 @@ int ha_partition::index_init(uint inx, bool sorted) */ if (m_lock_type == F_WRLCK) bitmap_union(table->read_set, &m_part_info->full_part_field_set); - else if (sorted) + if (sorted) { /* An ordered scan is requested. We must make sure all fields of the @@ -5380,6 +5413,13 @@ int ha_partition::extra(enum ha_extra_function operation) /* Currently only NDB use the *_CANNOT_BATCH */ break; } + /* + http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations.html + says we no longer support logging to partitioned tables, so we fail + here. + */ + case HA_EXTRA_MARK_AS_LOG_TABLE: + DBUG_RETURN(ER_UNSUPORTED_LOG_ENGINE); default: { /* Temporary crash to discover what is wrong */ diff --git a/sql/handler.cc b/sql/handler.cc index 19d8b29b937..4903a93bd3b 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -62,7 +62,9 @@ static const LEX_STRING sys_table_aliases[]= }; const char *ha_row_type[] = { - "", "FIXED", "DYNAMIC", "COMPRESSED", "REDUNDANT", "COMPACT", "PAGE", "?","?","?" + "", "FIXED", "DYNAMIC", "COMPRESSED", "REDUNDANT", "COMPACT", + "PAGE", + "?","?","?" }; const char *tx_isolation_names[] = @@ -342,6 +344,7 @@ int ha_init_errors(void) SETMSG(HA_ERR_TABLE_READONLY, ER(ER_OPEN_AS_READONLY)); SETMSG(HA_ERR_AUTOINC_READ_FAILED, ER(ER_AUTOINC_READ_FAILED)); SETMSG(HA_ERR_AUTOINC_ERANGE, ER(ER_WARN_DATA_OUT_OF_RANGE)); + SETMSG(HA_ERR_TOO_MANY_CONCURRENT_TRXS, ER(ER_TOO_MANY_CONCURRENT_TRXS)); /* Register the error messages for use with my_error(). */ return my_error_register(errmsgs, HA_ERR_FIRST, HA_ERR_LAST); @@ -1078,6 +1081,13 @@ int ha_commit_trans(THD *thd, bool all) user, or an implicit commit issued by a DDL. */ THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt; + /* + "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, + the changes are not durable as they might be rolled back if the + enclosing 'all' transaction is rolled back. + */ bool is_real_trans= all || thd->transaction.all.ha_list == 0; Ha_trx_info *ha_info= trans->ha_list; my_xid xid= thd->transaction.xid_state.xid.get_my_xid(); @@ -1189,6 +1199,9 @@ end: if (rw_trans) start_waiting_global_read_lock(thd); } + /* Free resources and perform other cleanup even for 'empty' transactions. */ + else if (is_real_trans) + thd->transaction.cleanup(); #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); } @@ -1201,6 +1214,13 @@ int ha_commit_one_phase(THD *thd, bool all) { int error=0; THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt; + /* + "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, + the changes are not durable as they might be rolled back if the + enclosing 'all' transaction is rolled back. + */ bool is_real_trans=all || thd->transaction.all.ha_list == 0; Ha_trx_info *ha_info= trans->ha_list, *ha_info_next; DBUG_ENTER("ha_commit_one_phase"); @@ -1222,8 +1242,6 @@ int ha_commit_one_phase(THD *thd, bool all) } trans->ha_list= 0; trans->no_2pc=0; - if (is_real_trans) - thd->transaction.xid_state.xid.null(); if (all) { #ifdef HAVE_QUERY_CACHE @@ -1231,9 +1249,11 @@ int ha_commit_one_phase(THD *thd, bool all) query_cache.invalidate(thd->transaction.changed_tables); #endif thd->variables.tx_isolation=thd->session_tx_isolation; - thd->transaction.cleanup(); } } + /* Free resources and perform other cleanup even for 'empty' transactions. */ + if (is_real_trans) + thd->transaction.cleanup(); #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); } @@ -1244,6 +1264,13 @@ int ha_rollback_trans(THD *thd, bool all) int error=0; THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt; Ha_trx_info *ha_info= trans->ha_list, *ha_info_next; + /* + "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, + the changes are not durable as they might be rolled back if the + enclosing 'all' transaction is rolled back. + */ bool is_real_trans=all || thd->transaction.all.ha_list == 0; DBUG_ENTER("ha_rollback_trans"); @@ -1289,19 +1316,14 @@ int ha_rollback_trans(THD *thd, bool all) } trans->ha_list= 0; trans->no_2pc=0; - if (is_real_trans) - { - if (thd->transaction_rollback_request) - thd->transaction.xid_state.rm_error= thd->main_da.sql_errno(); - else - thd->transaction.xid_state.xid.null(); - } + if (is_real_trans && thd->transaction_rollback_request) + thd->transaction.xid_state.rm_error= thd->main_da.sql_errno(); if (all) - { thd->variables.tx_isolation=thd->session_tx_isolation; - thd->transaction.cleanup(); - } } + /* Always cleanup. Even if there nht==0. There may be savepoints. */ + if (is_real_trans) + thd->transaction.cleanup(); #endif /* USING_TRANSACTIONS */ if (all) thd->transaction_rollback_request= FALSE; @@ -2736,6 +2758,9 @@ void handler::print_error(int error, myf errflag) case HA_ERR_AUTOINC_ERANGE: textno= ER_WARN_DATA_OUT_OF_RANGE; break; + case HA_ERR_TOO_MANY_CONCURRENT_TRXS: + textno= ER_TOO_MANY_CONCURRENT_TRXS; + break; default: { /* The error was "unknown" to this function. @@ -2962,6 +2987,7 @@ uint handler::get_dup_key(int error) */ int handler::delete_table(const char *name) { + int saved_error= 0; int error= 0; int enoent_or_zero= ENOENT; // Error if no file was deleted char buff[FN_REFLEN]; @@ -2971,21 +2997,31 @@ int handler::delete_table(const char *name) fn_format(buff, name, "", *ext, MY_UNPACK_FILENAME|MY_APPEND_EXT); if (my_delete_with_symlink(buff, MYF(0))) { - if ((error= my_errno) != ENOENT) - break; + if (my_errno != ENOENT) + { + /* + If error on the first existing file, return the error. + Otherwise delete as much as possible. + */ + if (enoent_or_zero) + return my_errno; + saved_error= my_errno; + } } else enoent_or_zero= 0; // No error for ENOENT error= enoent_or_zero; } - return error; + return saved_error ? saved_error : error; } int handler::rename_table(const char * from, const char * to) { int error= 0; - for (const char **ext= bas_ext(); *ext ; ext++) + const char **ext, **start_ext; + start_ext= bas_ext(); + for (ext= start_ext; *ext ; ext++) { if (rename_file_ext(from, to, *ext)) { @@ -2994,6 +3030,12 @@ int handler::rename_table(const char * from, const char * to) error= 0; } } + if (error) + { + /* Try to revert the rename. Ignore errors. */ + for (; ext >= start_ext; ext--) + rename_file_ext(to, from, *ext); + } return error; } @@ -3572,7 +3614,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name) int error; uchar *frmblob; size_t frmlen; - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; HA_CREATE_INFO create_info; TABLE table; TABLE_SHARE share; @@ -3591,7 +3633,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name) frmblob and frmlen are set, write the frm to disk */ - build_table_filename(path, FN_REFLEN-1, db, name, "", 0); + build_table_filename(path, sizeof(path) - 1, db, name, "", 0); // Save the frm file error= writefrm(path, frmblob, frmlen); my_free(frmblob, MYF(0)); @@ -4767,7 +4809,7 @@ fl_log_iterator_buffer_init(struct handler_iterator *iterator) if ((ptr= (uchar*)my_malloc(ALIGN_SIZE(sizeof(fl_buff)) + ((ALIGN_SIZE(sizeof(LEX_STRING)) + sizeof(enum log_status) + - + FN_REFLEN) * + + FN_REFLEN + 1) * (uint) dirp->number_off_files), MYF(0))) == 0) { @@ -4795,7 +4837,7 @@ fl_log_iterator_buffer_init(struct handler_iterator *iterator) name_ptr= strxnmov(buff->names[buff->entries].str= name_ptr, FN_REFLEN, fl_dir, file->name, NullS); buff->names[buff->entries].length= (name_ptr - - buff->names[buff->entries].str) - 1; + buff->names[buff->entries].str); buff->statuses[buff->entries]= st; buff->entries++; } diff --git a/sql/handler.h b/sql/handler.h index 8856ea5abde..fb1904f23dc 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -281,7 +281,9 @@ enum legacy_db_type 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 }; + ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, + /** Unused. Reserved for future versions. */ + ROW_TYPE_PAGE }; enum enum_binlog_func { BFN_RESET_LOGS= 1, @@ -324,6 +326,7 @@ enum enum_binlog_command { #define HA_CREATE_USED_PASSWORD (1L << 17) #define HA_CREATE_USED_CONNECTION (1L << 18) #define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19) +/* The following two are used by Maria engine: */ #define HA_CREATE_USED_TRANSACTIONAL (1L << 20) #define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21) @@ -884,9 +887,9 @@ typedef struct { ulonglong delete_length; ha_rows records; ulong mean_rec_length; - time_t create_time; - time_t check_time; - time_t update_time; + ulong create_time; + ulong check_time; + ulong update_time; ulonglong check_sum; } PARTITION_INFO; @@ -922,7 +925,7 @@ typedef struct st_ha_create_information uint options; /* OR of HA_CREATE_ options */ uint merge_insert_method; uint extra_size; /* length of extra data segment */ - /* 0 not used, 1 if not transactional, 2 if transactional */ + /** Transactional or not. Unused; reserved for future versions. */ enum ha_choice transactional; bool table_existed; /* 1 in create if table existed */ bool frm_only; /* 1 if no ha_create_table() */ @@ -1044,9 +1047,9 @@ public: ha_rows records; ha_rows deleted; /* Deleted records */ ulong mean_rec_length; /* physical reclength */ - time_t create_time; /* When table was created */ - time_t check_time; - time_t update_time; + ulong create_time; /* When table was created */ + ulong check_time; + ulong update_time; uint block_size; /* index block size */ ha_statistics(): @@ -1947,8 +1950,8 @@ private: /* Some extern variables used with handlers */ extern const char *ha_row_type[]; -extern const char *tx_isolation_names[]; -extern const char *binlog_format_names[]; +extern MYSQL_PLUGIN_IMPORT const char *tx_isolation_names[]; +extern MYSQL_PLUGIN_IMPORT const char *binlog_format_names[]; extern TYPELIB tx_isolation_typelib; extern TYPELIB myisam_stats_method_typelib; extern ulong total_ha, total_ha_2pc; diff --git a/sql/item.cc b/sql/item.cc index ed352d7b366..b2ab28a77fd 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -415,6 +415,7 @@ Item::Item(THD *thd, Item *item): name(item->name), orig_name(item->orig_name), max_length(item->max_length), + name_length(item->name_length), marker(item->marker), decimals(item->decimals), maybe_null(item->maybe_null), @@ -422,7 +423,9 @@ Item::Item(THD *thd, Item *item): unsigned_flag(item->unsigned_flag), with_sum_func(item->with_sum_func), fixed(item->fixed), + is_autogenerated_name(item->is_autogenerated_name), collation(item->collation), + with_subselect(item->with_subselect), cmp_context(item->cmp_context) { next= thd->free_list; // Put in free list @@ -594,6 +597,7 @@ bool Item_ident::remove_dependence_processor(uchar * arg) DBUG_ENTER("Item_ident::remove_dependence_processor"); if (depended_from == (st_select_lex *) arg) depended_from= 0; + context= &((st_select_lex *) arg)->context; DBUG_RETURN(0); } @@ -1311,7 +1315,10 @@ bool Item_name_const::fix_fields(THD *thd, Item **ref) my_error(ER_RESERVED_SYNTAX, MYF(0), "NAME_CONST"); return TRUE; } - set_name(item_name->ptr(), (uint) item_name->length(), system_charset_info); + if (is_autogenerated_name) + { + set_name(item_name->ptr(), (uint) item_name->length(), system_charset_info); + } collation.set(value_item->collation.collation, DERIVATION_IMPLICIT); max_length= value_item->max_length; decimals= value_item->decimals; @@ -2263,8 +2270,10 @@ Item_decimal::Item_decimal(const char *str_arg, uint length, name= (char*) str_arg; decimals= (uint8) decimal_value.frac; fixed= 1; - max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, - decimals, unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg + + decimals, + decimals, + unsigned_flag); } Item_decimal::Item_decimal(longlong val, bool unsig) @@ -2272,8 +2281,10 @@ Item_decimal::Item_decimal(longlong val, bool unsig) int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value); decimals= (uint8) decimal_value.frac; fixed= 1; - max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, - decimals, unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg + + decimals, + decimals, + unsigned_flag); } @@ -2282,8 +2293,10 @@ Item_decimal::Item_decimal(double val, int precision, int scale) double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value); decimals= (uint8) decimal_value.frac; fixed= 1; - max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, - decimals, unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg + + decimals, + decimals, + unsigned_flag); } @@ -2303,8 +2316,10 @@ Item_decimal::Item_decimal(my_decimal *value_par) my_decimal2decimal(value_par, &decimal_value); decimals= (uint8) decimal_value.frac; fixed= 1; - max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, - decimals, unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg + + decimals, + decimals, + unsigned_flag); } @@ -2314,8 +2329,8 @@ Item_decimal::Item_decimal(const uchar *bin, int precision, int scale) &decimal_value, precision, scale); decimals= (uint8) decimal_value.frac; fixed= 1; - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals, + unsigned_flag); } @@ -2370,8 +2385,10 @@ void Item_decimal::set_decimal_value(my_decimal *value_par) my_decimal2decimal(value_par, &decimal_value); decimals= (uint8) decimal_value.frac; unsigned_flag= !decimal_value.sign(); - max_length= my_decimal_precision_to_length(decimal_value.intg + decimals, - decimals, unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg + + decimals, + decimals, + unsigned_flag); } @@ -2474,8 +2491,9 @@ longlong_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end) TODO: Give error if we wanted a signed integer and we got an unsigned one */ - if (err > 0 || - (end != org_end && !check_if_only_end_space(cs, end, org_end))) + if (!current_thd->no_errors && + (err > 0 || + (end != org_end && !check_if_only_end_space(cs, end, org_end)))) { push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, @@ -2642,8 +2660,9 @@ void Item_param::set_decimal(const char *str, ulong length) str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end); state= DECIMAL_VALUE; decimals= decimal_value.frac; - max_length= my_decimal_precision_to_length(decimal_value.precision(), - decimals, unsigned_flag); + max_length= + my_decimal_precision_to_length_no_truncation(decimal_value.precision(), + decimals, unsigned_flag); maybe_null= 0; DBUG_VOID_RETURN; } @@ -2773,8 +2792,8 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry) CHARSET_INFO *tocs= thd->variables.collation_connection; uint32 dummy_offset; - value.cs_info.character_set_of_placeholder= - value.cs_info.character_set_client= fromcs; + value.cs_info.character_set_of_placeholder= fromcs; + value.cs_info.character_set_client= thd->variables.character_set_client; /* Setup source and destination character sets so that they are different only if conversion is necessary: this will @@ -2799,8 +2818,9 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry) my_decimal2decimal(ent_value, &decimal_value); state= DECIMAL_VALUE; decimals= ent_value->frac; - max_length= my_decimal_precision_to_length(ent_value->precision(), - decimals, unsigned_flag); + max_length= + my_decimal_precision_to_length_no_truncation(ent_value->precision(), + decimals, unsigned_flag); item_type= Item::DECIMAL_ITEM; break; } @@ -3270,9 +3290,57 @@ Item_param::set_param_type_and_swap_value(Item_param *src) } /**************************************************************************** + Item_copy +****************************************************************************/ +Item_copy *Item_copy::create (Item *item) +{ + switch (item->result_type()) + { + case STRING_RESULT: + return new Item_copy_string (item); + case REAL_RESULT: + return new Item_copy_float (item); + case INT_RESULT: + return item->unsigned_flag ? + new Item_copy_uint (item) : new Item_copy_int (item); + case DECIMAL_RESULT: + return new Item_copy_decimal (item); + case IMPOSSIBLE_RESULT: + case ROW_RESULT: + DBUG_ASSERT (0); + } + /* should not happen */ + return NULL; +} + +/**************************************************************************** Item_copy_string ****************************************************************************/ +double Item_copy_string::val_real() +{ + int err_not_used; + char *end_not_used; + return (null_value ? 0.0 : + my_strntod(str_value.charset(), (char*) str_value.ptr(), + str_value.length(), &end_not_used, &err_not_used)); +} + +longlong Item_copy_string::val_int() +{ + int err; + return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(), + str_value.length(),10, (char**) 0, + &err); +} + + +int Item_copy_string::save_in_field(Field *field, bool no_conversions) +{ + return save_str_value_in_field(field, &str_value); +} + + void Item_copy_string::copy() { String *res=item->val_str(&str_value); @@ -3295,12 +3363,163 @@ my_decimal *Item_copy_string::val_decimal(my_decimal *decimal_value) { // Item_copy_string is used without fix_fields call if (null_value) - return 0; + return (my_decimal *) 0; string2my_decimal(E_DEC_FATAL_ERROR, &str_value, decimal_value); return (decimal_value); } +/**************************************************************************** + Item_copy_int +****************************************************************************/ + +void Item_copy_int::copy() +{ + cached_value= item->val_int(); + null_value=item->null_value; +} + +static int save_int_value_in_field (Field *field, longlong nr, + bool null_value, bool unsigned_flag); + +int Item_copy_int::save_in_field(Field *field, bool no_conversions) +{ + return save_int_value_in_field(field, cached_value, + null_value, unsigned_flag); +} + + +String *Item_copy_int::val_str(String *str) +{ + if (null_value) + return (String *) 0; + + str->set(cached_value, &my_charset_bin); + return str; +} + + +my_decimal *Item_copy_int::val_decimal(my_decimal *decimal_value) +{ + if (null_value) + return (my_decimal *) 0; + + int2my_decimal(E_DEC_FATAL_ERROR, cached_value, unsigned_flag, decimal_value); + return decimal_value; +} + + +/**************************************************************************** + Item_copy_uint +****************************************************************************/ + +String *Item_copy_uint::val_str(String *str) +{ + if (null_value) + return (String *) 0; + + str->set((ulonglong) cached_value, &my_charset_bin); + return str; +} + + +/**************************************************************************** + Item_copy_float +****************************************************************************/ + +String *Item_copy_float::val_str(String *str) +{ + if (null_value) + return (String *) 0; + else + { + double nr= val_real(); + str->set_real(nr,decimals, &my_charset_bin); + return str; + } +} + + +my_decimal *Item_copy_float::val_decimal(my_decimal *decimal_value) +{ + if (null_value) + return (my_decimal *) 0; + else + { + double nr= val_real(); + double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value); + return decimal_value; + } +} + + +int Item_copy_float::save_in_field(Field *field, bool no_conversions) +{ + if (null_value) + return set_field_to_null(field); + field->set_notnull(); + return field->store(cached_value); +} + + +/**************************************************************************** + Item_copy_decimal +****************************************************************************/ + +int Item_copy_decimal::save_in_field(Field *field, bool no_conversions) +{ + if (null_value) + return set_field_to_null(field); + field->set_notnull(); + return field->store_decimal(&cached_value); +} + + +String *Item_copy_decimal::val_str(String *result) +{ + if (null_value) + return (String *) 0; + result->set_charset(&my_charset_bin); + my_decimal2string(E_DEC_FATAL_ERROR, &cached_value, 0, 0, 0, result); + return result; +} + + +double Item_copy_decimal::val_real() +{ + if (null_value) + return 0.0; + else + { + double result; + my_decimal2double(E_DEC_FATAL_ERROR, &cached_value, &result); + return result; + } +} + + +longlong Item_copy_decimal::val_int() +{ + if (null_value) + return LL(0); + else + { + longlong result; + my_decimal2int(E_DEC_FATAL_ERROR, &cached_value, unsigned_flag, &result); + return result; + } +} + + +void Item_copy_decimal::copy() +{ + my_decimal *nr= item->val_decimal(&cached_value); + if (nr && nr != &cached_value) + memcpy (&cached_value, nr, sizeof (my_decimal)); + null_value= item->null_value; +} + + /* Functions to convert item to field (for send_fields) */ @@ -3392,14 +3611,12 @@ static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current, current->mark_as_dependent(last, resolved_item); if (thd->lex->describe & DESCRIBE_EXTENDED) { - char warn_buff[MYSQL_ERRMSG_SIZE]; - sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED), - db_name, (db_name[0] ? "." : ""), - table_name, (table_name [0] ? "." : ""), - resolved_item->field_name, - current->select_number, last->select_number); - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, - ER_WARN_FIELD_RESOLVED, warn_buff); + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_WARN_FIELD_RESOLVED, ER(ER_WARN_FIELD_RESOLVED), + db_name, (db_name[0] ? "." : ""), + table_name, (table_name [0] ? "." : ""), + resolved_item->field_name, + current->select_number, last->select_number); } } @@ -4211,16 +4428,22 @@ mark_non_agg_field: Fields from outer selects added to the aggregate function outer_fields list as its unknown at the moment whether it's aggregated or not. + We're using either the select lex of the cached table (if present) + or the field's resolution context. context->select_lex is + safe for use because it's either the SELECT we want to use + (the current level) or a stub added by non-SELECT queries. */ + SELECT_LEX *select_lex= cached_table ? + cached_table->select_lex : context->select_lex; if (!thd->lex->in_sum_func) - cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED; + select_lex->full_group_by_flag|= NON_AGG_FIELD_USED; else { if (outer_fixed) thd->lex->in_sum_func->outer_fields.push_back(this); else if (thd->lex->in_sum_func->nest_level != thd->lex->current_select->nest_level) - cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED; + select_lex->full_group_by_flag|= NON_AGG_FIELD_USED; } } return FALSE; @@ -4470,7 +4693,7 @@ Item *Item_field::replace_equal_field(uchar *arg) return const_item; } Item_field *subst= item_equal->get_first(); - if (subst && !field->eq(subst->field)) + if (subst && field->table != subst->field->table && !field->eq(subst->field)) return subst; } return this; @@ -4877,7 +5100,10 @@ int Item_null::save_safe_in_field(Field *field) /* This implementation can lose str_value content, so if the Item uses str_value to store something, it should - reimplement it's ::save_in_field() as Item_string, for example, does + reimplement it's ::save_in_field() as Item_string, for example, does. + + Note: all Item_XXX::val_str(str) methods must NOT rely on the fact that + str != str_value. For example, see fix for bug #44743. */ int Item::save_in_field(Field *field, bool no_conversions) @@ -4947,10 +5173,9 @@ int Item_uint::save_in_field(Field *field, bool no_conversions) return Item_int::save_in_field(field, no_conversions); } - -int Item_int::save_in_field(Field *field, bool no_conversions) +static int save_int_value_in_field (Field *field, longlong nr, + bool null_value, bool unsigned_flag) { - longlong nr=val_int(); if (null_value) return set_field_to_null(field); field->set_notnull(); @@ -4958,6 +5183,12 @@ int Item_int::save_in_field(Field *field, bool no_conversions) } +int Item_int::save_in_field(Field *field, bool no_conversions) +{ + return save_int_value_in_field (field, val_int(), null_value, unsigned_flag); +} + + int Item_decimal::save_in_field(Field *field, bool no_conversions) { field->set_notnull(); @@ -5814,7 +6045,8 @@ void Item_ref::print(String *str, enum_query_type query_type) !table_name && name && alias_name_used) { THD *thd= current_thd; - append_identifier(thd, str, name, (uint) strlen(name)); + append_identifier(thd, str, (*ref)->real_item()->name, + (*ref)->real_item()->name_length); } else (*ref)->print(str, query_type); @@ -7086,8 +7318,9 @@ bool Item_type_holder::join_types(THD *thd, Item *item) int item_prec = max(prev_decimal_int_part, item_int_part) + decimals; int precision= min(item_prec, DECIMAL_MAX_PRECISION); unsigned_flag&= item->unsigned_flag; - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, + decimals, + unsigned_flag); } switch (Field::result_merge_type(fld_type)) @@ -7127,18 +7360,26 @@ bool Item_type_holder::join_types(THD *thd, Item *item) { if (decimals != NOT_FIXED_DEC) { - int delta1= max_length_orig - decimals_orig; - int delta2= item->max_length - item->decimals; - max_length= max(delta1, delta2) + decimals; - if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) - { - max_length= FLT_DIG + 6; - decimals= NOT_FIXED_DEC; - } - if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2) + /* + For FLOAT(M,D)/DOUBLE(M,D) do not change precision + if both fields have the same M and D + */ + if (item->max_length != max_length_orig || + item->decimals != decimals_orig) { - max_length= DBL_DIG + 7; - decimals= NOT_FIXED_DEC; + int delta1= max_length_orig - decimals_orig; + int delta2= item->max_length - item->decimals; + max_length= max(delta1, delta2) + decimals; + if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) + { + max_length= MAX_FLOAT_STR_LENGTH; + decimals= NOT_FIXED_DEC; + } + else if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2) + { + max_length= MAX_DOUBLE_STR_LENGTH; + decimals= NOT_FIXED_DEC; + } } } else diff --git a/sql/item.h b/sql/item.h index d680c9cf4c6..74c4ca701f7 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2478,48 +2478,203 @@ public: #include "item_xmlfunc.h" #endif -class Item_copy_string :public Item +/** + Base class to implement typed value caching Item classes + + Item_copy_ classes are very similar to the corresponding Item_ + classes (e.g. Item_copy_int is similar to Item_int) but they add + the following additional functionality to Item_ : + 1. Nullability + 2. Possibility to store the value not only on instantiation time, + but also later. + Item_copy_ classes are a functionality subset of Item_cache_ + classes, as e.g. they don't support comparisons with the original Item + as Item_cache_ classes do. + Item_copy_ classes are used in GROUP BY calculation. + TODO: Item_copy should be made an abstract interface and Item_copy_ + classes should inherit both the respective Item_ class and the interface. + Ideally we should drop Item_copy_ classes altogether and merge + their functionality to Item_cache_ (and these should be made to inherit + from Item_). +*/ + +class Item_copy :public Item { +protected: + + /** + Stores the type of the resulting field that would be used to store the data + in the cache. This is to avoid calls to the original item. + */ enum enum_field_types cached_field_type; -public: + + /** The original item that is copied */ Item *item; - Item_copy_string(Item *i) :item(i) + + /** + Stores the result type of the original item, so it can be returned + without calling the original item's method + */ + Item_result cached_result_type; + + /** + Constructor of the Item_copy class + + stores metadata information about the original class as well as a + pointer to it. + */ + Item_copy(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(); + cached_result_type= item->result_type(); + unsigned_flag= item->unsigned_flag; } + +public: + /** + Factory method to create the appropriate subclass dependent on the type of + the original item. + + @param item the original item. + */ + static Item_copy *create (Item *item); + + /** + Update the cache with the value of the original item + + This is the method that updates the cached value. + It must be explicitly called by the user of this class to store the value + of the orginal item in the cache. + */ + virtual void copy() = 0; + + Item *get_item() { return item; } + /** All of the subclasses should have the same type tag */ 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() + enum Item_result result_type () const { return cached_result_type; } + + void make_field(Send_field *field) { item->make_field(field); } + table_map used_tables() const { return (table_map) 1L; } + bool const_item() const { return 0; } + bool is_null() { return null_value; } + + /* + Override the methods below as pure virtual to make sure all the + sub-classes implement them. + */ + + virtual String *val_str(String*) = 0; + virtual my_decimal *val_decimal(my_decimal *) = 0; + virtual double val_real() = 0; + virtual longlong val_int() = 0; + virtual int save_in_field(Field *field, bool no_conversions) = 0; +}; + +/** + Implementation of a string cache. + + Uses Item::str_value for storage +*/ +class Item_copy_string : public Item_copy +{ +public: + Item_copy_string (Item *item) : Item_copy(item) {} + + String *val_str(String*); + my_decimal *val_decimal(my_decimal *); + double val_real(); + longlong val_int(); + void copy(); + int save_in_field(Field *field, bool no_conversions); +}; + + +class Item_copy_int : public Item_copy +{ +protected: + longlong cached_value; +public: + Item_copy_int (Item *i) : Item_copy(i) {} + int save_in_field(Field *field, bool no_conversions); + + virtual String *val_str(String*); + virtual my_decimal *val_decimal(my_decimal *); + virtual double val_real() { - int err_not_used; - char *end_not_used; - return (null_value ? 0.0 : - my_strntod(str_value.charset(), (char*) str_value.ptr(), - str_value.length(), &end_not_used, &err_not_used)); + return null_value ? 0.0 : (double) cached_value; } - longlong val_int() + virtual longlong val_int() + { + return null_value ? LL(0) : cached_value; + } + virtual void copy(); +}; + + +class Item_copy_uint : public Item_copy_int +{ +public: + Item_copy_uint (Item *item) : Item_copy_int(item) + { + unsigned_flag= 1; + } + + String *val_str(String*); + double val_real() { - int err; - return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(), - str_value.length(),10, (char**) 0, - &err); + return null_value ? 0.0 : (double) (ulonglong) cached_value; } +}; + + +class Item_copy_float : public Item_copy +{ +protected: + double cached_value; +public: + Item_copy_float (Item *i) : Item_copy(i) {} + int save_in_field(Field *field, bool no_conversions); + 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, bool no_conversions) + double val_real() { - return save_str_value_in_field(field, &str_value); + return null_value ? 0.0 : cached_value; } - table_map used_tables() const { return (table_map) 1L; } - bool const_item() const { return 0; } - bool is_null() { return null_value; } + longlong val_int() + { + return (longlong) rint(val_real()); + } + void copy() + { + cached_value= item->val_real(); + null_value= item->null_value; + } +}; + + +class Item_copy_decimal : public Item_copy +{ +protected: + my_decimal cached_value; +public: + Item_copy_decimal (Item *i) : Item_copy(i) {} + int save_in_field(Field *field, bool no_conversions); + + String *val_str(String*); + my_decimal *val_decimal(my_decimal *) + { + return null_value ? NULL: &cached_value; + } + double val_real(); + longlong val_int(); + void copy(); }; diff --git a/sql/item_func.cc b/sql/item_func.cc index fa835542eb1..7aa455b1b4a 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -451,11 +451,45 @@ Field *Item_func::tmp_table_field(TABLE *table) case STRING_RESULT: return make_string_field(table); case DECIMAL_RESULT: - field= new Field_new_decimal(my_decimal_precision_to_length(decimal_precision(), - decimals, - unsigned_flag), - maybe_null, name, decimals, unsigned_flag); + { + uint8 dec= decimals; + uint8 intg= decimal_precision() - dec; + uint32 len= max_length; + + /* + Trying to put too many digits overall in a DECIMAL(prec,dec) + will always throw a warning. We must limit dec to + DECIMAL_MAX_SCALE however to prevent an assert() later. + */ + + if (dec > 0) + { + int overflow; + + dec= min(dec, DECIMAL_MAX_SCALE); + + /* + If the value still overflows the field with the corrected dec, + we'll throw out decimals rather than integers. This is still + bad and of course throws a truncation warning. + */ + + const int required_length= + my_decimal_precision_to_length(intg + dec, dec, + unsigned_flag); + + overflow= required_length - len; + + if (overflow > 0) + dec= max(0, dec - overflow); // too long, discard fract + else + /* Corrected value fits. */ + len= required_length; + } + + field= new Field_new_decimal(len, maybe_null, name, dec, unsigned_flag); break; + } case ROW_RESULT: default: // This case should never be chosen @@ -544,8 +578,8 @@ void Item_func::count_decimal_length() set_if_smaller(unsigned_flag, args[i]->unsigned_flag); } int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION); - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals, + unsigned_flag); } @@ -1140,16 +1174,15 @@ void Item_func_additive_op::result_precision() decimals= max(args[0]->decimals, args[1]->decimals); int arg1_int= args[0]->decimal_precision() - args[0]->decimals; int arg2_int= args[1]->decimal_precision() - args[1]->decimals; - int est_prec= max(arg1_int, arg2_int) + 1 + decimals; - int precision= min(est_prec, DECIMAL_MAX_PRECISION); + int precision= max(arg1_int, arg2_int) + 1 + decimals; /* Integer operations keep unsigned_flag if one of arguments is unsigned */ if (result_type() == INT_RESULT) unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag; else unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag; - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals, + unsigned_flag); } @@ -1254,7 +1287,8 @@ void Item_func_mul::result_precision() decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE); uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision(); uint precision= min(est_prec, DECIMAL_MAX_PRECISION); - max_length= my_decimal_precision_to_length(precision, decimals,unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals, + unsigned_flag); } @@ -1310,8 +1344,8 @@ void Item_func_div::result_precision() else unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag; decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE); - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, decimals, + unsigned_flag); } @@ -1943,8 +1977,8 @@ void Item_func_round::fix_length_and_dec() unsigned_flag= args[0]->unsigned_flag; if (!args[1]->const_item()) { - max_length= args[0]->max_length; decimals= args[0]->decimals; + max_length= float_length(decimals); if (args[0]->result_type() == DECIMAL_RESULT) { max_length++; @@ -1964,8 +1998,8 @@ void Item_func_round::fix_length_and_dec() if (args[0]->decimals == NOT_FIXED_DEC) { - max_length= args[0]->max_length; decimals= min(decimals_to_set, NOT_FIXED_DEC); + max_length= float_length(decimals); hybrid_type= REAL_RESULT; return; } @@ -1998,8 +2032,9 @@ void Item_func_round::fix_length_and_dec() precision-= decimals_delta - length_increase; decimals= min(decimals_to_set, DECIMAL_MAX_SCALE); - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, + decimals, + unsigned_flag); break; } default: @@ -2142,9 +2177,6 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref) if (!rand && !(rand= (struct my_rnd_struct*) thd->stmt_arena->alloc(sizeof(*rand)))) return TRUE; - - if (args[0]->const_item()) - seed_random (args[0]); } else { @@ -2174,8 +2206,21 @@ void Item_func_rand::update_used_tables() double Item_func_rand::val_real() { DBUG_ASSERT(fixed == 1); - if (arg_count && !args[0]->const_item()) - seed_random (args[0]); + if (arg_count) + { + if (!args[0]->const_item()) + seed_random(args[0]); + else if (first_eval) + { + /* + Constantness of args[0] may be set during JOIN::optimize(), if arg[0] + is a field item of "constant" table. Thus, we have to evaluate + seed_random() for constant arg there but not at the fix_fields method. + */ + first_eval= FALSE; + seed_random(args[0]); + } + } return my_rnd(rand); } @@ -2232,8 +2277,9 @@ void Item_func_min_max::fix_length_and_dec() } } else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT)) - max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(max_int_part + + decimals, decimals, + unsigned_flag); cached_field_type= agg_field_type(args, arg_count); } @@ -2714,7 +2760,7 @@ longlong Item_func_find_in_set::val_int() if ((int) (buffer->length() - find->length()) >= 0) { - my_wc_t wc; + my_wc_t wc= 0; CHARSET_INFO *cs= cmp_collation.collation; const char *str_begin= buffer->ptr(); const char *str_end= buffer->ptr(); @@ -4181,6 +4227,41 @@ Item_func_set_user_var::check(bool use_result_field) /** + @brief Evaluate and store item's result. + This function is invoked on "SELECT ... INTO @var ...". + + @param item An item to get value from. +*/ + +void Item_func_set_user_var::save_item_result(Item *item) +{ + DBUG_ENTER("Item_func_set_user_var::save_item_result"); + + switch (cached_result_type) { + case REAL_RESULT: + save_result.vreal= item->val_result(); + break; + case INT_RESULT: + save_result.vint= item->val_int_result(); + unsigned_flag= item->unsigned_flag; + break; + case STRING_RESULT: + save_result.vstr= item->str_result(&value); + break; + case DECIMAL_RESULT: + save_result.vdec= item->val_decimal_result(&decimal_buff); + break; + case ROW_RESULT: + default: + // Should never happen + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + + +/** This functions is invoked on SET \@variable or \@variable:= expression. @@ -4838,10 +4919,20 @@ bool Item_func_get_system_var::is_written_to_binlog() } +void Item_func_get_system_var::update_null_value() +{ + THD *thd= current_thd; + int save_no_errors= thd->no_errors; + thd->no_errors= TRUE; + Item::update_null_value(); + thd->no_errors= save_no_errors; +} + + void Item_func_get_system_var::fix_length_and_dec() { char *cptr; - maybe_null=0; + maybe_null= TRUE; max_length= 0; if (var->check_type(var_type)) @@ -5750,6 +5841,14 @@ Item_func_sp::func_name() const } +int my_missing_function_error(const LEX_STRING &token, const char *func_name) +{ + if (token.length && is_lex_native_function (&token)) + return my_error(ER_FUNC_INEXISTENT_NAME_COLLISION, MYF(0), func_name); + else + return my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", func_name); +} + /** @brief Initialize the result field by creating a temporary dummy table @@ -5782,7 +5881,7 @@ Item_func_sp::init_result_field(THD *thd) if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name, &thd->sp_func_cache, TRUE))) { - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str); + my_missing_function_error (m_name->m_name, m_name->m_qname.str); context->process_error(thd); DBUG_RETURN(TRUE); } @@ -5894,6 +5993,9 @@ Item_func_sp::execute_impl(THD *thd) #ifndef NO_EMBEDDED_ACCESS_CHECKS Security_context *save_security_ctx= thd->security_ctx; #endif + enum enum_sp_data_access access= + (m_sp->m_chistics->daccess == SP_DEFAULT_ACCESS) ? + SP_DEFAULT_ACCESS_MAPPING : m_sp->m_chistics->daccess; DBUG_ENTER("Item_func_sp::execute_impl"); @@ -5911,11 +6013,13 @@ Item_func_sp::execute_impl(THD *thd) Throw an error if a non-deterministic function is called while statement-based replication (SBR) is active. */ + if (!m_sp->m_chistics->detistic && !trust_function_creators && + (access == SP_CONTAINS_SQL || access == SP_MODIFIES_SQL_DATA) && (mysql_bin_log.is_open() && thd->variables.binlog_format == BINLOG_FORMAT_STMT)) { - my_error(ER_BINLOG_ROW_RBR_TO_SBR, MYF(0)); + my_error(ER_BINLOG_UNSAFE_ROUTINE, MYF(0)); goto error; } @@ -6107,13 +6211,12 @@ void uuid_short_init() (((ulonglong) server_start_time) << 24)); } -pthread_mutex_t LOCK_uuid_short; longlong Item_func_uuid_short::val_int() { ulonglong val; - pthread_mutex_lock(&LOCK_uuid_short); + pthread_mutex_lock(&LOCK_uuid_generator); val= uuid_value++; - pthread_mutex_unlock(&LOCK_uuid_short); + pthread_mutex_unlock(&LOCK_uuid_generator); return (longlong) val; } diff --git a/sql/item_func.h b/sql/item_func.h index b843a974da5..eee3a7ef0f6 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -378,7 +378,8 @@ public: Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a) { decimals= dec; - max_length= my_decimal_precision_to_length(len, dec, unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(len, dec, + unsigned_flag); } String *val_str(String *str); double val_real(); @@ -696,14 +697,16 @@ public: class Item_func_rand :public Item_real_func { struct my_rnd_struct *rand; + bool first_eval; // TRUE if val_real() is called 1st time public: - Item_func_rand(Item *a) :Item_real_func(a), rand(0) {} + Item_func_rand(Item *a) :Item_real_func(a), rand(0), first_eval(TRUE) {} Item_func_rand() :Item_real_func() {} double val_real(); const char *func_name() const { return "rand"; } bool const_item() const { return 0; } void update_used_tables(); bool fix_fields(THD *thd, Item **ref); + void cleanup() { first_eval= TRUE; Item_real_func::cleanup(); } private: void seed_random (Item * val); }; @@ -1341,6 +1344,7 @@ public: bool send(Protocol *protocol, String *str_arg); void make_field(Send_field *tmp_field); bool check(bool use_result_field); + void save_item_result(Item *item); bool update(); enum Item_result result_type () const { return cached_result_type; } bool fix_fields(THD *thd, Item **ref); @@ -1452,6 +1456,7 @@ public: LEX_STRING *component_arg, const char *name_arg, size_t name_len_arg); enum Functype functype() const { return GSYSVAR_FUNC; } + void update_null_value(); void fix_length_and_dec(); void print(String *str, enum_query_type query_type); bool const_item() const { return true; } @@ -1513,6 +1518,7 @@ public: ft_handler->please->close_search(ft_handler); ft_handler= 0; concat_ws= 0; + table= 0; // required by Item_func_match::eq() DBUG_VOID_RETURN; } enum Functype functype() const { return FT_FUNC; } diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index ac1b7738a27..a34204b7181 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -78,10 +78,17 @@ String *Item_func_geometry_from_wkb::val_str(String *str) { DBUG_ASSERT(fixed == 1); String arg_val; - String *wkb= args[0]->val_str(&arg_val); + String *wkb; Geometry_buffer buffer; uint32 srid= 0; + if (args[0]->field_type() == MYSQL_TYPE_GEOMETRY) + { + return args[0]->val_str(str); + } + + wkb= args[0]->val_str(&arg_val); + if ((arg_count == 2) && !args[1]->null_value) srid= (uint32)args[1]->val_int(); @@ -91,8 +98,8 @@ String *Item_func_geometry_from_wkb::val_str(String *str) str->length(0); str->q_append(srid); if ((null_value= - (args[0]->null_value || - !Geometry::create_from_wkb(&buffer, wkb->ptr(), wkb->length(), str)))) + (args[0]->null_value || + !Geometry::create_from_wkb(&buffer, wkb->ptr(), wkb->length(), str)))) return 0; return str; } @@ -345,14 +352,16 @@ String *Item_func_point::val_str(String *str) DBUG_ASSERT(fixed == 1); double x= args[0]->val_real(); double y= args[1]->val_real(); + uint32 srid= 0; if ((null_value= (args[0]->null_value || args[1]->null_value || - str->realloc(1 + 4 + SIZEOF_STORED_DOUBLE*2)))) + str->realloc(4/*SRID*/ + 1 + 4 + SIZEOF_STORED_DOUBLE*2)))) return 0; str->set_charset(&my_charset_bin); str->length(0); + str->q_append(srid); str->q_append((char)Geometry::wkb_ndr); str->q_append((uint32)Geometry::wkb_point); str->q_append(x); @@ -376,12 +385,14 @@ String *Item_func_spatial_collection::val_str(String *str) DBUG_ASSERT(fixed == 1); String arg_value; uint i; + uint32 srid= 0; str->set_charset(&my_charset_bin); str->length(0); - if (str->reserve(1 + 4 + 4, 512)) + if (str->reserve(4/*SRID*/ + 1 + 4 + 4, 512)) goto err; + str->q_append(srid); str->q_append((char) Geometry::wkb_ndr); str->q_append((uint32) coll_type); str->q_append((uint32) arg_count); @@ -399,13 +410,16 @@ String *Item_func_spatial_collection::val_str(String *str) In the case of GeometryCollection we don't need any checkings for item types, so just copy them into target collection */ - if (str->append(res->ptr(), len, (uint32) 512)) + if (str->append(res->ptr() + 4/*SRID*/, len - 4/*SRID*/, (uint32) 512)) goto err; } else { enum Geometry::wkbType wkb_type; - const char *data= res->ptr() + 1; + const uint data_offset= 4/*SRID*/ + 1; + if (res->length() < data_offset + sizeof(uint32)) + goto err; + const char *data= res->ptr() + data_offset; /* In the case of named collection we must check that items @@ -414,7 +428,7 @@ String *Item_func_spatial_collection::val_str(String *str) wkb_type= (Geometry::wkbType) uint4korr(data); data+= 4; - len-= 5; + len-= 5 + 4/*SRID*/; if (wkb_type != item_type) goto err; @@ -428,7 +442,7 @@ String *Item_func_spatial_collection::val_str(String *str) break; case Geometry::wkb_linestring: - if (str->append(data, POINT_DATA_SIZE, 512)) + if (len < POINT_DATA_SIZE || str->append(data, POINT_DATA_SIZE, 512)) goto err; break; case Geometry::wkb_polygon: @@ -437,11 +451,15 @@ String *Item_func_spatial_collection::val_str(String *str) double x1, y1, x2, y2; const char *org_data= data; - if (len < 4 + 2 * POINT_DATA_SIZE) + if (len < 4) goto err; n_points= uint4korr(data); data+= 4; + + if (n_points < 2 || len < 4 + n_points * POINT_DATA_SIZE) + goto err; + float8get(x1, data); data+= SIZEOF_STORED_DOUBLE; float8get(y1, data); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 77991c4fe6f..8efc3c98328 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -504,17 +504,22 @@ String *Item_func_des_encrypt::val_str(String *str) string marking change of string length. */ - tail= (8-(res_length) % 8); // 1..8 marking extra length + tail= 8 - (res_length % 8); // 1..8 marking extra length res_length+=tail; + if (tmp_arg.realloc(res_length)) + goto error; + tmp_arg.length(0); + tmp_arg.append(res->ptr(), res->length()); code= ER_OUT_OF_RESOURCES; - if ((tail && res->append(append_str, tail)) || tmp_value.alloc(res_length+1)) + if (tmp_arg.append(append_str, tail) || tmp_value.alloc(res_length+1)) goto error; - (*res)[res_length-1]=tail; // save extra length + tmp_arg[res_length-1]=tail; // save extra length + tmp_value.realloc(res_length+1); tmp_value.length(res_length+1); tmp_value[0]=(char) (128 | key_number); // Real encryption bzero((char*) &ivec,sizeof(ivec)); - DES_ede3_cbc_encrypt((const uchar*) (res->ptr()), + DES_ede3_cbc_encrypt((const uchar*) (tmp_arg.ptr()), (uchar*) (tmp_value.ptr()+1), res_length, &keyschedule.ks1, @@ -1625,16 +1630,17 @@ String *Item_func_password::val_str(String *str) return 0; if (res->length() == 0) return &my_empty_string; - make_scrambled_password(tmp_value, res->c_ptr()); + my_make_scrambled_password(tmp_value, res->ptr(), res->length()); str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, res->charset()); return str; } -char *Item_func_password::alloc(THD *thd, const char *password) +char *Item_func_password::alloc(THD *thd, const char *password, + size_t pass_len) { char *buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1); if (buff) - make_scrambled_password(buff, password); + my_make_scrambled_password(buff, password, pass_len); return buff; } @@ -1648,16 +1654,17 @@ String *Item_func_old_password::val_str(String *str) return 0; if (res->length() == 0) return &my_empty_string; - make_scrambled_password_323(tmp_value, res->c_ptr()); + my_make_scrambled_password_323(tmp_value, res->ptr(), res->length()); str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, res->charset()); return str; } -char *Item_func_old_password::alloc(THD *thd, const char *password) +char *Item_func_old_password::alloc(THD *thd, const char *password, + size_t pass_len) { char *buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1); if (buff) - make_scrambled_password_323(buff, password); + my_make_scrambled_password_323(buff, password, pass_len); return buff; } @@ -1689,10 +1696,10 @@ String *Item_func_encrypt::val_str(String *str) String *salt_str=args[1]->val_str(&tmp_value); if ((null_value= (args[1]->null_value || salt_str->length() < 2))) return 0; - salt_ptr= salt_str->c_ptr(); + salt_ptr= salt_str->c_ptr_safe(); } pthread_mutex_lock(&LOCK_crypt); - char *tmp= crypt(res->c_ptr(),salt_ptr); + char *tmp= crypt(res->c_ptr_safe(),salt_ptr); if (!tmp) { pthread_mutex_unlock(&LOCK_crypt); @@ -1738,7 +1745,7 @@ String *Item_func_encode::val_str(String *str) null_value=0; res=copy_if_not_alloced(str,res,res->length()); - SQL_CRYPT sql_crypt(password->ptr()); + SQL_CRYPT sql_crypt(password->ptr(), password->length()); sql_crypt.init(); sql_crypt.encode((char*) res->ptr(),res->length()); res->set_charset(&my_charset_bin); @@ -1767,7 +1774,7 @@ String *Item_func_decode::val_str(String *str) null_value=0; res=copy_if_not_alloced(str,res,res->length()); - SQL_CRYPT sql_crypt(password->ptr()); + SQL_CRYPT sql_crypt(password->ptr(), password->length()); sql_crypt.init(); sql_crypt.decode((char*) res->ptr(),res->length()); return res; @@ -2702,7 +2709,13 @@ String *Item_func_conv_charset::val_str(String *str) DBUG_ASSERT(fixed == 1); if (use_cached_value) return null_value ? 0 : &str_value; - String *arg= args[0]->val_str(str); + /* + Here we don't pass 'str' as a parameter to args[0]->val_str() + as 'str' may point to 'str_value' (e.g. see Item::save_in_field()), + which we use below to convert string. + Use argument's 'str_value' instead. + */ + String *arg= args[0]->val_str(&args[0]->str_value); uint dummy_errors; if (!arg) { @@ -2939,7 +2952,7 @@ String *Item_load_file::val_str(String *str) ) goto err; - (void) fn_format(path, file_name->c_ptr(), mysql_real_data_home, "", + (void) fn_format(path, file_name->c_ptr_safe(), mysql_real_data_home, "", MY_RELATIVE_PATH | MY_UNPACK_FILENAME); /* Read only allowed from within dir specified by secure_file_priv */ @@ -2965,7 +2978,7 @@ String *Item_load_file::val_str(String *str) } if (tmp_value.alloc(stat_info.st_size)) goto err; - if ((file = my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0) + if ((file = my_open(file_name->ptr(), O_RDONLY, MYF(0))) < 0) goto err; if (my_read(file, (uchar*) tmp_value.ptr(), stat_info.st_size, MYF(MY_NABP))) { @@ -3215,7 +3228,21 @@ longlong Item_func_uncompressed_length::val_int() if (res->is_empty()) return 0; /* - res->ptr() using is safe because we have tested that string is not empty, + If length is <= 4 bytes, data is corrupt. This is the best we can do + to detect garbage input without decompressing it. + */ + if (res->length() <= 4) + { + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_ZLIB_Z_DATA_ERROR, + ER(ER_ZLIB_Z_DATA_ERROR)); + null_value= 1; + return 0; + } + + /* + res->ptr() using is safe because we have tested that string is at least + 5 bytes long. res->c_ptr() is not used because: - we do not need \0 terminated string to get first 4 bytes - c_ptr() tests simbol after string end (uninitialiozed memory) which diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index daf384236a5..8625add8d2d 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -268,7 +268,7 @@ public: String *val_str(String *str); void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH; } const char *func_name() const { return "password"; } - static char *alloc(THD *thd, const char *password); + static char *alloc(THD *thd, const char *password, size_t pass_len); }; @@ -287,19 +287,23 @@ public: String *val_str(String *str); void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; } const char *func_name() const { return "old_password"; } - static char *alloc(THD *thd, const char *password); + static char *alloc(THD *thd, const char *password, size_t pass_len); }; class Item_func_des_encrypt :public Item_str_func { - String tmp_value; + String tmp_value,tmp_arg; public: Item_func_des_encrypt(Item *a) :Item_str_func(a) {} Item_func_des_encrypt(Item *a, Item *b): Item_str_func(a,b) {} String *val_str(String *); void fix_length_and_dec() - { maybe_null=1; max_length = args[0]->max_length+8; } + { + maybe_null=1; + /* 9 = MAX ((8- (arg_len % 8)) + 1) */ + max_length = args[0]->max_length + 9; + } const char *func_name() const { return "des_encrypt"; } }; @@ -310,7 +314,12 @@ public: Item_func_des_decrypt(Item *a) :Item_str_func(a) {} Item_func_des_decrypt(Item *a, Item *b): Item_str_func(a,b) {} String *val_str(String *); - void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; } + void fix_length_and_dec() + { + maybe_null=1; + /* 9 = MAX ((8- (arg_len % 8)) + 1) */ + max_length = args[0]->max_length - 9; + } const char *func_name() const { return "des_decrypt"; } }; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 22792a5b8b9..7ee22fb3c1c 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1253,6 +1253,10 @@ Item_in_subselect::single_value_transformer(JOIN *join, else { // it is single select without tables => possible optimization + // remove the dependence mark since the item is moved to upper + // select and is not outer anymore. + item->walk(&Item::remove_dependence_processor, 0, + (uchar *) select_lex->outer_select()); item= func->create(left_expr, item); // fix_field of item will be done in time of substituting substitution= item; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index fab64dfbeaf..ab2da503209 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -793,8 +793,9 @@ void Item_sum_sum::fix_length_and_dec() { /* SUM result can't be longer than length(arg) + length(MAX_ROWS) */ int precision= args[0]->decimal_precision() + DECIMAL_LONGLONG_DIGITS; - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, + decimals, + unsigned_flag); curr_dec_buff= 0; hybrid_type= DECIMAL_RESULT; my_decimal_set_zero(dec_buffs); @@ -1228,8 +1229,9 @@ void Item_sum_avg::fix_length_and_dec() { int precision= args[0]->decimal_precision() + prec_increment; decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE); - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, + decimals, + unsigned_flag); f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION); f_scale= args[0]->decimals; dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale); @@ -1434,8 +1436,9 @@ void Item_sum_variance::fix_length_and_dec() { int precision= args[0]->decimal_precision()*2 + prec_increment; decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE); - max_length= my_decimal_precision_to_length(precision, decimals, - unsigned_flag); + max_length= my_decimal_precision_to_length_no_truncation(precision, + decimals, + unsigned_flag); break; } @@ -3319,8 +3322,13 @@ bool Item_func_group_concat::add() TREE_ELEMENT *el= 0; // Only for safety if (row_eligible && tree) + { el= tree_insert(tree, table->record[0] + table->s->null_bytes, 0, tree->custom_arg); + /* check if there was enough memory to insert the row */ + if (!el) + return 1; + } /* If the row is not a duplicate (el->count == 1) we can dump the row here in case of GROUP_CONCAT(DISTINCT...) diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index a2342975aec..8a5804ffd63 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -2788,6 +2788,7 @@ String *Item_xml_str_func::parse_xml(String *raw_xml, String *parsed_xml_buf) String *Item_func_xml_extractvalue::val_str(String *str) { String *res; + null_value= 0; if (!nodeset_func || !(res= args[0]->val_str(str)) || !parse_xml(res, &pxml)) @@ -2804,6 +2805,7 @@ String *Item_func_xml_update::val_str(String *str) { String *res, *nodeset, *rep; + null_value= 0; if (!nodeset_func || !(res= args[0]->val_str(str)) || !(rep= args[2]->val_str(&tmp_value3)) || diff --git a/sql/lex.h b/sql/lex.h index c2ee1c020b3..d9c382347c9 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -387,7 +387,7 @@ static SYMBOL symbols[] = { { "PACK_KEYS", SYM(PACK_KEYS_SYM)}, { "PARSER", SYM(PARSER_SYM)}, { "PAGE", SYM(PAGE_SYM)}, - { "PAGE_CHECKSUM", SYM(PAGE_CHECKSUM_SYM)}, + { "PAGE_CHECKSUM", SYM(PAGE_CHECKSUM_SYM)}, { "PARTIAL", SYM(PARTIAL)}, { "PARTITION", SYM(PARTITION_SYM)}, { "PARTITIONING", SYM(PARTITIONING_SYM)}, diff --git a/sql/log.cc b/sql/log.cc index 5b79ade261f..ea71e6caefd 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -153,7 +153,8 @@ private: class binlog_trx_data { public: binlog_trx_data() - : at_least_one_stmt(0), m_pending(0), before_stmt_pos(MY_OFF_T_UNDEF) + : at_least_one_stmt(0), incident(FALSE), m_pending(0), + before_stmt_pos(MY_OFF_T_UNDEF) { trans_log.end_of_file= max_binlog_cache_size; } @@ -184,6 +185,7 @@ public: delete pending(); set_pending(0); reinit_io_cache(&trans_log, WRITE_CACHE, pos, 0, 0); + trans_log.end_of_file= max_binlog_cache_size; if (pos < before_stmt_pos) before_stmt_pos= MY_OFF_T_UNDEF; @@ -206,6 +208,7 @@ public: if (!empty()) truncate(0); before_stmt_pos= MY_OFF_T_UNDEF; + incident= FALSE; trans_log.end_of_file= max_binlog_cache_size; DBUG_ASSERT(empty()); } @@ -222,11 +225,22 @@ public: IO_CACHE trans_log; // The transaction cache + void set_incident(void) + { + incident= TRUE; + } + + bool has_incident(void) + { + return(incident); + } + /** Boolean that is true if there is at least one statement in the transaction cache. */ bool at_least_one_stmt; + bool incident; private: /* @@ -845,6 +859,7 @@ void LOGGER::cleanup_base() { table_log_handler->cleanup(); delete table_log_handler; + table_log_handler= NULL; } if (file_log_handler) file_log_handler->cleanup(); @@ -855,7 +870,11 @@ void LOGGER::cleanup_end() { DBUG_ASSERT(inited == 1); if (file_log_handler) + { delete file_log_handler; + file_log_handler=NULL; + } + inited= 0; } @@ -937,7 +956,7 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length, bool error= FALSE; Log_event_handler **current_handler; bool is_command= FALSE; - char user_host_buff[MAX_USER_HOST_SIZE]; + char user_host_buff[MAX_USER_HOST_SIZE + 1]; Security_context *sctx= thd->security_ctx; uint user_host_len= 0; ulonglong query_utime, lock_utime; @@ -1014,7 +1033,7 @@ bool LOGGER::general_log_write(THD *thd, enum enum_server_command command, { bool error= FALSE; Log_event_handler **current_handler= general_log_handler_list; - char user_host_buff[MAX_USER_HOST_SIZE]; + char user_host_buff[MAX_USER_HOST_SIZE + 1]; Security_context *sctx= thd->security_ctx; ulong id; uint user_host_len= 0; @@ -1397,7 +1416,8 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data, */ if (end_ev != NULL) { - thd->binlog_flush_pending_rows_event(TRUE); + if (thd->binlog_flush_pending_rows_event(TRUE)) + DBUG_RETURN(1); /* Doing a commit or a rollback including non-transactional tables, i.e., ending a transaction where we might write the transaction @@ -1408,7 +1428,8 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data, were, we would have to ensure that we're not ending a statement inside a stored function. */ - error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev); + error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev, + trx_data->has_incident()); trx_data->reset(); /* @@ -1434,7 +1455,11 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data, */ thd->binlog_remove_pending_rows_event(TRUE); if (all || !(thd->options & (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT))) + { + if (trx_data->has_incident()) + mysql_bin_log.write_incident(thd, TRUE); trx_data->reset(); + } else // ...statement trx_data->truncate(trx_data->before_stmt_pos); @@ -1510,8 +1535,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) { if (!in_transaction || all) { - Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE); - qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) + Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, TRUE, 0); error= binlog_end_trans(thd, trx_data, &qev, all); goto end; } @@ -1558,37 +1582,101 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all) YESNO(all), YESNO(thd->transaction.all.modified_non_trans_table), YESNO(thd->transaction.stmt.modified_non_trans_table))); - if ((all && thd->transaction.all.modified_non_trans_table) || - (!all && thd->transaction.stmt.modified_non_trans_table) || - (thd->options & OPTION_KEEP_LOG)) + if (mysql_bin_log.check_write_error(thd)) { /* - We write the transaction cache with a rollback last if we have - modified any non-transactional table. We do this even if we are - committing a single statement that has modified a - non-transactional table since it can have modified a - transactional table in that statement as well, which needs to be - rolled back on the slave. + "all == true" means that a "rollback statement" triggered the error and + this function was called. However, this must not happen as a rollback + is written directly to the binary log. And in auto-commit mode, a single + statement that is rolled back has the flag all == false. + */ + DBUG_ASSERT(!all); + /* + We reach this point if either only transactional tables were modified or + the effect of a statement that did not get into the binlog needs to be + rolled back. In the latter case, if a statement changed non-transactional + tables or had the OPTION_KEEP_LOG associated, we write an incident event + to the binlog in order to stop slaves and notify users that some changes + on the master did not get into the binlog and slaves will be inconsistent. + On the other hand, if a statement is transactional, we just safely roll it + back. */ - Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE); - qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) - error= binlog_end_trans(thd, trx_data, &qev, all); + if ((thd->transaction.stmt.modified_non_trans_table || + (thd->options & OPTION_KEEP_LOG)) && + mysql_bin_log.check_write_error(thd)) + trx_data->set_incident(); + error= binlog_end_trans(thd, trx_data, 0, all); } - else if ((all && !thd->transaction.all.modified_non_trans_table) || - (!all && !thd->transaction.stmt.modified_non_trans_table)) + else { + /* + We flush the cache with a rollback, 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; + . the OPTION_KEEP_LOG is activate. + */ + if ((all && thd->transaction.all.modified_non_trans_table) || + (!all && thd->transaction.stmt.modified_non_trans_table && + !(thd->options & (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT))) || + ((thd->options & OPTION_KEEP_LOG))) + { + Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, TRUE, 0); + error= binlog_end_trans(thd, trx_data, &qev, all); + } /* - If we have modified only transactional tables, we can truncate - the transaction cache without writing anything to the binary - log. - */ - error= binlog_end_trans(thd, trx_data, 0, all); + Otherwise, we simply truncate the cache as there is no change on + non-transactional tables as follows. + */ + else if ((all && !thd->transaction.all.modified_non_trans_table) || + (!all && !thd->transaction.stmt.modified_non_trans_table)) + error= binlog_end_trans(thd, trx_data, 0, all); } if (!all) trx_data->before_stmt_pos = MY_OFF_T_UNDEF; // part of the stmt rollback DBUG_RETURN(error); } +void MYSQL_BIN_LOG::set_write_error(THD *thd) +{ + DBUG_ENTER("MYSQL_BIN_LOG::set_write_error"); + + write_error= 1; + + if (check_write_error(thd)) + DBUG_VOID_RETURN; + + if (my_errno == EFBIG) + my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(MY_WME)); + else + my_error(ER_ERROR_ON_WRITE, MYF(MY_WME), name, errno); + + DBUG_VOID_RETURN; +} + +bool MYSQL_BIN_LOG::check_write_error(THD *thd) +{ + DBUG_ENTER("MYSQL_BIN_LOG::check_write_error"); + + bool checked= FALSE; + + if (!thd->is_error()) + DBUG_RETURN(checked); + + switch (thd->main_da.sql_errno()) + { + case ER_TRANS_CACHE_FULL: + case ER_ERROR_ON_WRITE: + case ER_BINLOG_LOGGING_IMPOSSIBLE: + checked= TRUE; + break; + } + + DBUG_RETURN(checked); +} + + /** @note How do we handle this (unlikely but legal) case: @@ -1619,10 +1707,11 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv) binlog_trans_log_savepos(thd, (my_off_t*) sv); /* Write it to the binary log */ - + + int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int const error= thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, TRUE, FALSE); + thd->query, thd->query_length, TRUE, FALSE, errcode); DBUG_RETURN(error); } @@ -1638,9 +1727,10 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) if (unlikely(thd->transaction.all.modified_non_trans_table || (thd->options & OPTION_KEEP_LOG))) { + int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int error= thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, TRUE, FALSE); + thd->query, thd->query_length, TRUE, FALSE, errcode); DBUG_RETURN(error); } binlog_trans_log_truncate(thd, *(my_off_t*)sv); @@ -2078,6 +2168,9 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, /* Test if someone closed between the is_open test and lock */ if (is_open()) { + /* for testing output of timestamp and thread id */ + DBUG_EXECUTE_IF("reset_log_last_time", last_time= 0;); + /* Note that my_b_write() assumes it knows the length for this */ if (event_time != last_time) { @@ -2086,7 +2179,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, localtime_r(&event_time, &start); time_buff_len= my_snprintf(local_time_buff, MAX_TIME_SIZE, - "%02d%02d%02d %2d:%02d:%02d", + "%02d%02d%02d %2d:%02d:%02d\t", start.tm_year % 100, start.tm_mon + 1, start.tm_mday, start.tm_hour, start.tm_min, start.tm_sec); @@ -3889,6 +3982,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd, if (pending->write(file)) { pthread_mutex_unlock(&LOCK_log); + set_write_error(thd); DBUG_RETURN(1); } @@ -3963,7 +4057,8 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) */ bool const end_stmt= thd->prelocked_mode && thd->lex->requires_prelocking(); - thd->binlog_flush_pending_rows_event(end_stmt); + if (thd->binlog_flush_pending_rows_event(end_stmt)) + DBUG_RETURN(error); pthread_mutex_lock(&LOCK_log); @@ -4014,8 +4109,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) DBUG_PRINT("info", ("Using trans_log: cache: %d, trans_log_pos: %lu", event_info->get_cache_stmt(), (ulong) trans_log_pos)); - if (trans_log_pos == 0) - thd->binlog_start_trans_and_stmt(); + thd->binlog_start_trans_and_stmt(); file= trans_log; } /* @@ -4093,7 +4187,8 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) Write the SQL command */ - if (event_info->write(file)) + if (event_info->write(file) || + DBUG_EVALUATE_IF("injecting_fault_writing", 1, 0)) goto err; if (file == &log_file) // we are writing to the real log (disk) @@ -4107,13 +4202,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) err: if (error) - { - if (my_errno == EFBIG) - my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(0)); - else - my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno); - write_error=1; - } + set_write_error(thd); } if (event_info->flags & LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F) @@ -4365,6 +4454,58 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log) return 0; // All OK } +/* + Helper function to get the error code of the query to be binlogged. + */ +int query_error_code(THD *thd, bool not_killed) +{ + int error; + + if (not_killed) + { + error= thd->is_error() ? thd->main_da.sql_errno() : 0; + + /* thd->main_da.sql_errno() might be ER_SERVER_SHUTDOWN or + ER_QUERY_INTERRUPTED, So here we need to make sure that error + is not set to these errors when specified not_killed by the + caller. + */ + if (error == ER_SERVER_SHUTDOWN || error == ER_QUERY_INTERRUPTED) + error= 0; + } + else + { + /* killed status for DELAYED INSERT thread should never be used */ + DBUG_ASSERT(!(thd->system_thread & SYSTEM_THREAD_DELAYED_INSERT)); + error= thd->killed_errno(); + } + + return error; +} + +bool MYSQL_BIN_LOG::write_incident(THD *thd, bool lock) +{ + uint error= 0; + DBUG_ENTER("MYSQL_BIN_LOG::write_incident"); + LEX_STRING const write_error_msg= + { C_STRING_WITH_LEN("error writing to the binary log") }; + Incident incident= INCIDENT_LOST_EVENTS; + Incident_log_event ev(thd, incident, write_error_msg); + if (lock) + pthread_mutex_lock(&LOCK_log); + ev.write(&log_file); + if (lock) + { + if (!error && !(error= flush_and_sync())) + { + signal_update(); + rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED); + } + pthread_mutex_unlock(&LOCK_log); + } + DBUG_RETURN(error); +} + /** Write a cached log entry to the binary log. - To support transaction over replication, we wrap the transaction @@ -4377,6 +4518,9 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log) @param cache The cache to copy to the binlog @param commit_event The commit event to print after writing the contents of the cache. + @param incident Defines if an incident event should be created to + notify that some non-transactional changes did + not get into the binlog. @note We only come here if there is something in the cache. @@ -4386,7 +4530,8 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log) 'cache' needs to be reinitialized after this functions returns. */ -bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event) +bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, + bool incident) { DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)"); VOID(pthread_mutex_lock(&LOCK_log)); @@ -4408,19 +4553,8 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event) transaction is either a BEGIN..COMMIT block or a single statement in autocommit mode. */ - Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE); - /* - Imagine this is rollback due to net timeout, after all - statements of the transaction succeeded. Then we want a - zero-error code in BEGIN. In other words, if there was a - really serious error code it's already in the statement's - events, there is no need to put it also in this internally - generated event, and as this event is generated late it would - lead to false alarms. - - This is safer than thd->clear_error() against kills at shutdown. - */ - qinfo.error_code= 0; + Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, TRUE, 0); + /* Now this Query_log_event has artificial log_pos 0. It must be adjusted to reflect the real position in the log. Not doing it @@ -4446,6 +4580,10 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event) if (commit_event && commit_event->write(&log_file)) goto err; + + if (incident && write_incident(thd, FALSE)) + goto err; + if (flush_and_sync()) goto err; DBUG_EXECUTE_IF("half_binlogged_transaction", DBUG_ABORT();); diff --git a/sql/log.h b/sql/log.h index d54df8add3b..d306d6f7182 100644 --- a/sql/log.h +++ b/sql/log.h @@ -356,9 +356,12 @@ public: void new_file(); bool write(Log_event* event_info); // binary log write - bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event); + bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event, bool incident); + bool write_incident(THD *thd, bool lock); int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync); + void set_write_error(THD *thd); + bool check_write_error(THD *thd); void start_union_events(THD *thd, query_id_t query_id_param); void stop_union_events(THD *thd); @@ -581,4 +584,6 @@ enum enum_binlog_format { }; extern TYPELIB binlog_format_typelib; +int query_error_code(THD *thd, bool not_killed); + #endif /* LOG_H */ diff --git a/sql/log_event.cc b/sql/log_event.cc index 485dc2fddc3..f33ee8310cf 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -277,6 +277,47 @@ static void clear_all_errors(THD *thd, Relay_log_info *rli) rli->clear_error(); } +inline int idempotent_error_code(int err_code) +{ + int ret= 0; + + switch (err_code) + { + case 0: + ret= 1; + break; + /* + The following list of "idempotent" errors + means that an error from the list might happen + because of idempotent (more than once) + applying of a binlog file. + Notice, that binlog has a ddl operation its + second applying may cause + + case HA_ERR_TABLE_DEF_CHANGED: + case HA_ERR_CANNOT_ADD_FOREIGN: + + which are not included into to the list. + + Note that HA_ERR_RECORD_DELETED is not in the list since + do_exec_row() should not return that error code. + */ + case HA_ERR_RECORD_CHANGED: + case HA_ERR_KEY_NOT_FOUND: + case HA_ERR_END_OF_FILE: + case HA_ERR_FOUND_DUPP_KEY: + case HA_ERR_FOUND_DUPP_UNIQUE: + case HA_ERR_FOREIGN_DUPLICATE_KEY: + case HA_ERR_NO_REFERENCED_ROW: + case HA_ERR_ROW_IS_REFERENCED: + ret= 1; + break; + default: + ret= 0; + break; + } + return (ret); +} /** Ignore error code specified on command line. @@ -301,14 +342,65 @@ inline int ignored_error_code(int err_code) return ((err_code == ER_SLAVE_IGNORED_TABLE) || (use_slave_mask && bitmap_is_set(&slave_error_mask, err_code))); } -#endif +/* + This function converts an engine's error to a server error. + + If the thread does not have an error already reported, it tries to + define it by calling the engine's method print_error. However, if a + mapping is not found, it uses the ER_UNKNOWN_ERROR and prints out a + warning message. +*/ +int convert_handler_error(int error, THD* thd, TABLE *table) +{ + uint actual_error= (thd->is_error() ? thd->main_da.sql_errno() : + 0); + + if (actual_error == 0) + { + table->file->print_error(error, MYF(0)); + actual_error= (thd->is_error() ? thd->main_da.sql_errno() : + ER_UNKNOWN_ERROR); + if (actual_error == ER_UNKNOWN_ERROR) + if (global_system_variables.log_warnings) + sql_print_warning("Unknown error detected %d in handler", error); + } + + return (actual_error); +} + +inline bool concurrency_error_code(int error) +{ + switch (error) + { + case ER_LOCK_WAIT_TIMEOUT: + case ER_LOCK_DEADLOCK: + case ER_XA_RBDEADLOCK: + return TRUE; + default: + return (FALSE); + } +} + +inline bool unexpected_error_code(int unexpected_error) +{ + switch (unexpected_error) + { + case ER_NET_READ_ERROR: + case ER_NET_ERROR_ON_WRITE: + case ER_QUERY_INTERRUPTED: + case ER_SERVER_SHUTDOWN: + case ER_NEW_ABORTING_CONNECTION: + return(TRUE); + default: + return(FALSE); + } +} /* pretty_print_str() */ -#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) static char *pretty_print_str(char *packet, const char *str, int len) { const char *end= str + len; @@ -2251,19 +2343,16 @@ Query_log_event::Query_log_event() query_length - size of the `query_arg' array using_trans - there is a modified transactional table suppress_use - suppress the generation of 'USE' statements - killed_status_arg - an optional with default to THD::KILLED_NO_VALUE - if the value is different from the default, the arg - is set to the current thd->killed value. - A caller might need to masquerade thd->killed with - THD::NOT_KILLED. + errcode - the error code of the query + DESCRIPTION Creates an event for binlogging - The value for local `killed_status' can be supplied by caller. + The value for `errcode' should be supplied by caller. */ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length, bool using_trans, - bool suppress_use, - THD::killed_state killed_status_arg) + bool suppress_use, int errcode) + :Log_event(thd_arg, (thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0) | @@ -2284,14 +2373,8 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, { time_t end_time; - if (killed_status_arg == THD::KILLED_NO_VALUE) - killed_status_arg= thd_arg->killed; - error_code= - (killed_status_arg == THD::NOT_KILLED) ? - (thd_arg->is_error() ? thd_arg->main_da.sql_errno() : 0) : - ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ? 0 : - thd_arg->killed_errno()); - + error_code= errcode; + time(&end_time); exec_time = (ulong) (end_time - thd_arg->start_time); /** @@ -2677,7 +2760,8 @@ void Query_log_event::print_query_header(IO_CACHE* file, if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db) { - if ((different_db= memcmp(print_event_info->db, db, db_len + 1))) + different_db= memcmp(print_event_info->db, db, db_len + 1); + if (different_db) memcpy(print_event_info->db, db, db_len + 1); if (db[0] && different_db) my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter); @@ -2934,11 +3018,13 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, ::do_apply_event(), then the companion SET also have so we don't need to reset_one_shot_variables(). */ - if (rpl_filter->db_ok(thd->db)) + if (!strncmp(query_arg, "BEGIN", q_len_arg) || + !strncmp(query_arg, "COMMIT", q_len_arg) || + !strncmp(query_arg, "ROLLBACK", q_len_arg) || + rpl_filter->db_ok(thd->db)) { thd->set_time((time_t)when); - thd->query_length= q_len_arg; - thd->query= (char*)query_arg; + thd->set_query((char*)query_arg, q_len_arg); VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query_id = next_query_id(); VOID(pthread_mutex_unlock(&LOCK_thread_count)); @@ -2946,7 +3032,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, DBUG_PRINT("query",("%s",thd->query)); if (ignored_error_code((expected_error= error_code)) || - !check_expected_error(thd,rli,expected_error)) + !unexpected_error_code(expected_error)) { if (flags2_inited) /* @@ -3078,8 +3164,8 @@ compare_errors: actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0; DBUG_PRINT("info",("expected_error: %d sql_errno: %d", expected_error, actual_error)); - if ((expected_error != actual_error) && - expected_error && + if ((expected_error && expected_error != actual_error && + !concurrency_error_code(expected_error)) && !ignored_error_code(actual_error) && !ignored_error_code(expected_error)) { @@ -3098,7 +3184,8 @@ Default database: '%s'. Query: '%s'", /* If we get the same error code as expected, or they should be ignored. */ - else if (expected_error == actual_error || + else if ((expected_error == actual_error && + !concurrency_error_code(expected_error)) || ignored_error_code(actual_error)) { DBUG_PRINT("info",("error ignored")); @@ -3142,7 +3229,6 @@ Default database: '%s'. Query: '%s'", } /* End of if (db_ok(... */ end: - VOID(pthread_mutex_lock(&LOCK_thread_count)); /* Probably we have set thd->query, thd->db, thd->catalog to point to places in the data_buf of this event. Now the event is going to be deleted @@ -3155,10 +3241,8 @@ end: */ thd->catalog= 0; thd->set_db(NULL, 0); /* will free the current database */ + thd->set_query(NULL, 0); DBUG_PRINT("info", ("end: query= 0")); - thd->query= 0; // just to be sure - thd->query_length= 0; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); close_thread_tables(thd); /* As a disk space optimization, future masters will not log an event for @@ -3270,8 +3354,8 @@ void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info) my_b_printf(&cache," at startup"); my_b_printf(&cache, "\n"); if (flags & LOG_EVENT_BINLOG_IN_USE_F) - my_b_printf(&cache, "# Warning: this binlog was not closed properly. " - "Most probably mysqld crashed writing it.\n"); + my_b_printf(&cache, "# Warning: this binlog is either in use or was not " + "closed properly.\n"); } if (!is_artificial_event() && created) { @@ -4292,7 +4376,7 @@ void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info, { if (i) my_b_printf(&cache, ","); - my_b_printf(&cache, field); + my_b_printf(&cache, "%s", field); field += field_lens[i] + 1; } @@ -4468,8 +4552,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli, print_query(FALSE, load_data_query, &end, (char **)&thd->lex->fname_start, (char **)&thd->lex->fname_end); *end= 0; - thd->query_length= end - load_data_query; - thd->query= load_data_query; + thd->set_query(load_data_query, (uint) (end - load_data_query)); if (sql_ex.opt_flags & REPLACE_FLAG) { @@ -4575,12 +4658,9 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli, error: thd->net.vio = 0; const char *remember_db= thd->db; - VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->catalog= 0; thd->set_db(NULL, 0); /* will free the current database */ - thd->query= 0; - thd->query_length= 0; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + thd->set_query(NULL, 0); close_thread_tables(thd); DBUG_EXECUTE_IF("LOAD_DATA_INFILE_has_fatal_error", @@ -6548,9 +6628,9 @@ Execute_load_query_log_event(THD *thd_arg, const char* query_arg, uint fn_pos_end_arg, enum_load_dup_handling dup_handling_arg, bool using_trans, bool suppress_use, - THD::killed_state killed_err_arg): + int errcode): Query_log_event(thd_arg, query_arg, query_length_arg, using_trans, - suppress_use, killed_err_arg), + suppress_use, errcode), file_id(thd_arg->file_id), fn_pos_start(fn_pos_start_arg), fn_pos_end(fn_pos_end_arg), dup_handling(dup_handling_arg) { @@ -6623,7 +6703,7 @@ void Execute_load_query_log_event::print(FILE* file, { my_b_write(&cache, (uchar*) query, fn_pos_start); my_b_printf(&cache, " LOCAL INFILE \'"); - my_b_printf(&cache, local_fname); + my_b_printf(&cache, "%s", local_fname); my_b_printf(&cache, "\'"); if (dup_handling == LOAD_DUP_REPLACE) my_b_printf(&cache, " REPLACE"); @@ -7123,7 +7203,12 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) */ lex_start(thd); mysql_reset_thd_for_next_command(thd); - + /* + The current statement is just about to begin and + has not yet modified anything. Note, all.modified is reset + by mysql_reset_thd_for_next_command. + */ + thd->transaction.stmt.modified_non_trans_table= FALSE; /* Check if the slave is set to use SBR. If so, it should switch to using RBR until the end of the "statement", i.e., next @@ -7160,7 +7245,9 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) { /* Error reporting borrowed from Query_log_event with many excessive - simplifications (we don't honour --slave-skip-errors) + simplifications. + We should not honour --slave-skip-errors at this point as we are + having severe errors which should not be skiped. */ rli->report(ERROR_LEVEL, actual_error, "Error '%s' on opening tables", @@ -7186,6 +7273,10 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) { if (ptr->m_tabledef.compatible_with(rli, ptr->table)) { + /* + We should not honour --slave-skip-errors at this point as we are + having severe errors which should not be skiped. + */ mysql_unlock_tables(thd, thd->lock); thd->lock= 0; thd->is_slave_error= 1; @@ -7226,6 +7317,7 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) if (table) { + bool transactional_table= table->file->has_transactions(); /* table == NULL means that this table should not be replicated (this was set up by Table_map_log_event::do_apply_event() @@ -7293,48 +7385,27 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) DBUG_ASSERT(error != HA_ERR_RECORD_DELETED); table->in_use = old_thd; - switch (error) - { - case 0: - break; - /* - The following list of "idempotent" errors - means that an error from the list might happen - because of idempotent (more than once) - applying of a binlog file. - Notice, that binlog has a ddl operation its - second applying may cause - - case HA_ERR_TABLE_DEF_CHANGED: - case HA_ERR_CANNOT_ADD_FOREIGN: - - which are not included into to the list. - Note that HA_ERR_RECORD_DELETED is not in the list since - do_exec_row() should not return that error code. - */ - case HA_ERR_RECORD_CHANGED: - case HA_ERR_KEY_NOT_FOUND: - case HA_ERR_END_OF_FILE: - case HA_ERR_FOUND_DUPP_KEY: - case HA_ERR_FOUND_DUPP_UNIQUE: - case HA_ERR_FOREIGN_DUPLICATE_KEY: - case HA_ERR_NO_REFERENCED_ROW: - case HA_ERR_ROW_IS_REFERENCED: - - if (bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1) + if (error) + { + int actual_error= convert_handler_error(error, thd, table); + bool idempotent_error= (idempotent_error_code(error) && + ((bit_is_set(slave_exec_mode, + SLAVE_EXEC_MODE_IDEMPOTENT)) == 1)); + bool ignored_error= (idempotent_error == 0 ? + ignored_error_code(actual_error) : 0); + + if (idempotent_error || ignored_error) { if (global_system_variables.log_warnings) slave_rows_error_report(WARNING_LEVEL, error, rli, thd, table, get_type_str(), RPL_LOG_NAME, (ulong) log_pos); + clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); error= 0; + if (idempotent_error == 0) + break; } - break; - - default: - thd->is_slave_error= 1; - break; } /* @@ -7348,7 +7419,7 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) (ulong) m_curr_row, (ulong) m_curr_row_end, (ulong) m_rows_end)); if (!m_curr_row_end && !error) - unpack_current_row(rli); + error= unpack_current_row(rli); // at this moment m_curr_row_end should be set DBUG_ASSERT(error || m_curr_row_end != NULL); @@ -7357,11 +7428,26 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) m_curr_row= m_curr_row_end; + if (error == 0 && !transactional_table) + thd->transaction.all.modified_non_trans_table= + thd->transaction.stmt.modified_non_trans_table= TRUE; } // row processing loop DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event", const_cast<Relay_log_info*>(rli)->abort_slave= 1;); - error= do_after_row_operations(rli, error); + + if ((error= do_after_row_operations(rli, error)) && + ignored_error_code(convert_handler_error(error, thd, table))) + { + + if (global_system_variables.log_warnings) + slave_rows_error_report(WARNING_LEVEL, error, rli, thd, table, + get_type_str(), + RPL_LOG_NAME, (ulong) log_pos); + clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); + error= 0; + } + if (!cache_stmt) { DBUG_PRINT("info", ("Marked that we need to keep log")); @@ -7377,36 +7463,21 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) const_cast<Relay_log_info*>(rli)->clear_tables_to_lock(); if (error) - { /* error has occured during the transaction */ - slave_rows_error_report(ERROR_LEVEL, error, rli, thd, table, - get_type_str(), RPL_LOG_NAME, (ulong) log_pos); - } - if (error) { - /* - If one day we honour --skip-slave-errors in row-based replication, and - the error should be skipped, then we would clear mappings, rollback, - close tables, but the slave SQL thread would not stop and then may - assume the mapping is still available, the tables are still open... - So then we should clear mappings/rollback/close here only if this is a - STMT_END_F. - For now we code, knowing that error is not skippable and so slave SQL - thread is certainly going to stop. - rollback at the caller along with sbr. - */ + slave_rows_error_report(ERROR_LEVEL, error, rli, thd, table, + get_type_str(), + RPL_LOG_NAME, (ulong) log_pos); thd->reset_current_stmt_binlog_row_based(); const_cast<Relay_log_info*>(rli)->cleanup_context(thd, error); thd->is_slave_error= 1; - DBUG_RETURN(error); } - /* This code would ideally be placed in do_update_pos() instead, but since we have no access to table there, we do the setting of last_event_start_time here instead. */ - if (table && (table->s->primary_key == MAX_KEY) && - !cache_stmt && get_flags(STMT_END_F) == RLE_NO_FLAGS) + else if (table && (table->s->primary_key == MAX_KEY) && + !cache_stmt && get_flags(STMT_END_F) == RLE_NO_FLAGS) { /* ------------ Temporary fix until WL#2975 is implemented --------- @@ -7427,7 +7498,7 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) const_cast<Relay_log_info*>(rli)->last_event_start_time= my_time(0); } - DBUG_RETURN(0); + DBUG_RETURN(error); } Log_event::enum_skip_reason @@ -7800,10 +7871,11 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, /* Now set the size of the data to the size of the field metadata array - plus one or two bytes for number of elements in the field metadata array. + plus one or three bytes (see pack.c:net_store_length) for number of + elements in the field metadata array. */ if (m_field_metadata_size > 255) - m_data_size+= m_field_metadata_size + 2; + m_data_size+= m_field_metadata_size + 3; else m_data_size+= m_field_metadata_size + 1; @@ -9189,7 +9261,7 @@ Incident_log_event::Incident_log_event(const char *buf, uint event_len, // If the incident is not recognized, this binlog event is // invalid. If we set incident_number to INCIDENT_NONE, the // invalidity will be detected by is_valid(). - incident_number= INCIDENT_NONE; + m_incident= INCIDENT_NONE; DBUG_VOID_RETURN; } m_incident= static_cast<Incident>(incident_number); @@ -9249,7 +9321,7 @@ Incident_log_event::print(FILE *file, Write_on_release_cache cache(&print_event_info->head_cache, file); print_header(&cache, print_event_info, FALSE); - my_b_printf(&cache, "\n# Incident: %s", description()); + my_b_printf(&cache, "\n# Incident: %s\nRELOAD DATABASE; # Shall generate syntax error\n", description()); } #endif diff --git a/sql/log_event.h b/sql/log_event.h index 45dcf297697..13ab4330415 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -676,6 +676,7 @@ typedef struct st_print_event_info #ifdef MYSQL_CLIENT uint verbose; table_mapping m_table_map; + table_mapping m_table_map_ignored; #endif /* @@ -1623,8 +1624,7 @@ public: #ifndef MYSQL_CLIENT Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length, - bool using_trans, bool suppress_use, - THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE); + bool using_trans, bool suppress_use, int error); const char* get_db() { return db; } #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); @@ -2875,8 +2875,7 @@ public: uint fn_pos_end_arg, enum_load_dup_handling dup_handling_arg, bool using_trans, bool suppress_use, - THD::killed_state - killed_err_arg= THD::KILLED_NO_VALUE); + int errcode); #ifdef HAVE_REPLICATION void pack_info(Protocol* protocol); #endif /* HAVE_REPLICATION */ diff --git a/sql/my_decimal.h b/sql/my_decimal.h index ae081ce5617..d736bad9a4b 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -183,6 +183,19 @@ inline uint my_decimal_length_to_precision(uint length, uint scale, (unsigned_flag || !length ? 0:1)); } +inline uint32 my_decimal_precision_to_length_no_truncation(uint precision, + uint8 scale, + bool unsigned_flag) +{ + /* + When precision is 0 it means that original length was also 0. Thus + unsigned_flag is ignored in this case. + */ + DBUG_ASSERT(precision || !scale); + return (uint32)(precision + (scale > 0 ? 1 : 0) + + (unsigned_flag || !precision ? 0 : 1)); +} + inline uint32 my_decimal_precision_to_length(uint precision, uint8 scale, bool unsigned_flag) { @@ -192,8 +205,8 @@ inline uint32 my_decimal_precision_to_length(uint precision, uint8 scale, */ DBUG_ASSERT(precision || !scale); set_if_smaller(precision, DECIMAL_MAX_PRECISION); - return (uint32)(precision + (scale>0 ? 1:0) + - (unsigned_flag || !precision ? 0:1)); + return my_decimal_precision_to_length_no_truncation(precision, scale, + unsigned_flag); } inline diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index d3a4b2d3686..63d5621742e 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -83,9 +83,9 @@ extern query_id_t global_query_id; inline query_id_t next_query_id() { return global_query_id++; } /* useful constants */ -extern const key_map key_map_empty; -extern key_map key_map_full; /* Should be threaded as const */ -extern const char *primary_key_name; +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> @@ -124,8 +124,10 @@ char* query_table_status(THD *thd,const char *db,const char *table_name); "in MySQL %s. Please use %s instead.", (Old), (Ver), (New)); \ } while(0) -extern CHARSET_INFO *system_charset_info, *files_charset_info ; -extern CHARSET_INFO *national_charset_info, *table_alias_charset; +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; enum Derivation @@ -364,6 +366,11 @@ protected: #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 @@ -646,6 +653,7 @@ enum enum_parsing_place struct st_table; +#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__) class THD; enum enum_check_fields @@ -655,6 +663,7 @@ enum enum_check_fields CHECK_FIELD_ERROR_FOR_NULL }; + /** Struct to handle simple linked lists. */ typedef struct st_sql_list { uint elements; @@ -697,14 +706,19 @@ typedef struct st_sql_list { } } 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. @@ -1426,14 +1440,14 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table); /* sql_prepare.cc */ -void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length); -void mysql_stmt_execute(THD *thd, char *packet, uint packet_length); -void mysql_stmt_close(THD *thd, char *packet); +void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length); +void mysqld_stmt_execute(THD *thd, char *packet, uint packet_length); +void mysqld_stmt_close(THD *thd, char *packet); void mysql_sql_stmt_prepare(THD *thd); void mysql_sql_stmt_execute(THD *thd); void mysql_sql_stmt_close(THD *thd); -void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length); -void mysql_stmt_reset(THD *thd, char *packet); +void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length); +void mysqld_stmt_reset(THD *thd, char *packet); void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length); void reinit_stmt_before_use(THD *thd, LEX *lex); @@ -1895,8 +1909,12 @@ 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; -extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH], - mysql_real_data_home[], mysql_unpacked_real_data_home[]; + +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 @@ -1904,10 +1922,13 @@ extern char *opt_mysql_tmpdir, mysql_charsets_dir[], def_ft_boolean_syntax[sizeof(ft_boolean_syntax)]; extern int mysql_unpacked_real_data_home_len; #define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list)) -extern MY_TMPDIR mysql_tmpdir_list; +extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list; extern const LEX_STRING command_name[]; -extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword; -extern const char **errmesg; /* Error messages */ + +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 const char * const TRG_EXT; @@ -1921,8 +1942,8 @@ extern Le_creator le_creator; extern char language[FN_REFLEN]; #endif /* MYSQL_SERVER */ #if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern char reg_ext[FN_EXTLEN]; -extern uint reg_ext_length; +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 glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; @@ -1942,21 +1963,23 @@ 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 ulong max_connections,max_connect_errors, connect_timeout; +extern MYSQL_PLUGIN_IMPORT ulong max_connections; +extern ulong max_connect_errors, connect_timeout; extern ulong extra_max_connections; extern ulong slave_net_timeout, slave_trans_retries; 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, max_binlog_cache_size, open_files_limit; +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 specialflag; +extern ulong MYSQL_PLUGIN_IMPORT specialflag; #endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ #ifdef MYSQL_SERVER extern ulong current_pid; @@ -1969,7 +1992,7 @@ extern uint protocol_version, mysqld_port, mysqld_extra_port, dropping_tables; extern uint delay_key_write_options; #endif /* MYSQL_SERVER */ #if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern uint lower_case_table_names; +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; @@ -1977,7 +2000,7 @@ extern my_bool locked_in_memory; extern bool opt_using_transactions; #endif /* MYSQL_SERVER */ #if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern bool mysqld_embedded; +extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded; #endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ #ifdef MYSQL_SERVER extern bool opt_large_files, server_id_supplied; @@ -1989,6 +2012,7 @@ 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, thread_running, global_read_lock; extern ulong thread_created; extern uint connection_count, extra_connection_count; @@ -2016,7 +2040,7 @@ extern uint opt_large_page_size; extern char *opt_logname, *opt_slow_logname; extern const char *log_output_str; -extern MYSQL_BIN_LOG mysql_bin_log; +extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log; extern LOGGER logger; extern TABLE_LIST general_log, slow_log; extern FILE *bootstrap_file; @@ -2024,14 +2048,14 @@ extern int bootstrap_error; extern FILE *stderror_file; extern pthread_key(MEM_ROOT**,THR_MALLOC); extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db, - LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status, + 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_bytes_sent, LOCK_bytes_received, LOCK_connection_count, - LOCK_uuid_short; + LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count; +extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count; #ifdef HAVE_OPENSSL extern pthread_mutex_t LOCK_des_key_file; #endif @@ -2051,16 +2075,13 @@ extern const String my_null_string; extern SHOW_VAR status_vars[]; #endif /* MYSQL_SERVER */ #if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS -extern struct system_variables global_system_variables; +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 my_rnd_struct sql_rand; -extern handlerton *maria_hton; /* @todo remove, make it static in ha_maria.cc - currently it's needed for sql_delete.cc */ - extern const char *opt_date_time_formats[]; extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[]; @@ -2077,10 +2098,14 @@ extern uint sql_command_flags[]; extern TYPELIB log_output_typelib; /* optional things, have_* variables */ -extern SHOW_COMP_OPTION have_maria_db; extern SHOW_COMP_OPTION have_community_features; + extern handlerton *partition_hton; extern handlerton *myisam_hton; +/* + @todo remove, make it static in ha_maria.cc + currently it's needed for sql_select.cc +*/ extern handlerton *maria_hton; extern handlerton *heap_hton; @@ -2273,6 +2298,16 @@ char *fn_rext(char *name); #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(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); @@ -2331,6 +2366,12 @@ extern void turn_parser_debug_on(); 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 */ diff --git a/sql/mysql_priv.h.pp b/sql/mysql_priv.h.pp deleted file mode 100644 index 8bb31f64587..00000000000 --- a/sql/mysql_priv.h.pp +++ /dev/null @@ -1,10978 +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 size_t strip_sp(char * str); -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_extra_sort_file_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 26324821ef6..8988ad0671b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -427,6 +427,21 @@ my_bool locked_in_memory; bool opt_using_transactions; bool volatile abort_loop; bool volatile shutdown_in_progress; +/* + True if the bootstrap thread is running. Protected by LOCK_thread_count, + just like thread_count. + Used in bootstrap() function to determine if the bootstrap thread + has completed. Note, that we can't use 'thread_count' instead, + since in 5.1, in presence of the Event Scheduler, there may be + event threads running in parallel, so it's impossible to know + what value of 'thread_count' is a sign of completion of the + bootstrap thread. + + At the same time, we can't start the event scheduler after + bootstrap either, since we want to be able to process event-related + SQL commands in the init file and in --bootstrap mode. +*/ +bool in_bootstrap= FALSE; /** @brief 'grant_option' is used to indicate if privileges needs to be checked, in which case the lock, LOCK_grant, is used @@ -519,7 +534,8 @@ ulong slave_net_timeout, slave_trans_retries; ulong slave_exec_mode_options; const char *slave_exec_mode_str= "STRICT"; ulong thread_cache_size=0, thread_pool_size= 0; -ulong binlog_cache_size=0, max_binlog_cache_size=0; +ulong binlog_cache_size=0; +ulonglong max_binlog_cache_size=0; ulong query_cache_size=0; ulong refresh_version; /* Increments on each reload */ query_id_t global_query_id; @@ -632,7 +648,7 @@ pthread_mutex_t LOCK_mysql_create_db, LOCK_Acl, LOCK_open, LOCK_thread_count, LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received, LOCK_global_system_variables, LOCK_user_conn, LOCK_slave_list, LOCK_active_mi, - LOCK_connection_count; + LOCK_connection_count, LOCK_uuid_generator; /** The below lock protects access to two global server variables: max_prepared_stmt_count and prepared_stmt_count. These variables @@ -661,7 +677,8 @@ uint master_port= MYSQL_PORT, master_connect_retry = 60; uint report_port= MYSQL_PORT; ulong master_retry_count=0; char *master_user, *master_password, *master_host, *master_info_file; -char *relay_log_info_file, *report_user, *report_password, *report_host; +char *relay_log_info_file; +char *report_user, *report_password, *report_host; char *opt_relay_logname = 0, *opt_relaylog_index_name=0; my_bool master_ssl; char *master_ssl_key, *master_ssl_cert; @@ -1011,6 +1028,7 @@ static void close_connections(void) } (void) pthread_mutex_unlock(&LOCK_thread_count); + close_active_mi(); DBUG_PRINT("quit",("close_connections thread")); DBUG_VOID_RETURN; } @@ -1356,7 +1374,6 @@ void clean_up(bool print_message) /* do the broadcast inside the lock to ensure that my_end() is not called */ (void) pthread_cond_broadcast(&COND_thread_count); (void) pthread_mutex_unlock(&LOCK_thread_count); - my_uuid_end(); /* The following lines may never be executed as the main thread may have @@ -1430,7 +1447,7 @@ static void clean_up_mutexes() (void) rwlock_destroy(&LOCK_sys_init_connect); (void) rwlock_destroy(&LOCK_sys_init_slave); (void) pthread_mutex_destroy(&LOCK_global_system_variables); - (void) pthread_mutex_destroy(&LOCK_uuid_short); + (void) pthread_mutex_destroy(&LOCK_uuid_generator); (void) rwlock_destroy(&LOCK_system_variables_hash); (void) pthread_mutex_destroy(&LOCK_global_read_lock); (void) pthread_mutex_destroy(&LOCK_prepared_stmt_count); @@ -1741,7 +1758,6 @@ static void network_init(void) opt_enable_named_pipe) { - pipe_name[sizeof(pipe_name)-1]= 0; /* Safety if too long string */ strxnmov(pipe_name, sizeof(pipe_name)-1, "\\\\.\\pipe\\", mysqld_unix_port, NullS); bzero((char*) &saPipeSecurity, sizeof(saPipeSecurity)); @@ -3607,7 +3623,7 @@ static int init_thread_environment() (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_lock_db,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_Acl,MY_MUTEX_INIT_SLOW); - (void) pthread_mutex_init(&LOCK_open, NULL); + (void) pthread_mutex_init(&LOCK_open, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_mapped_file,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST); @@ -3625,7 +3641,7 @@ static int init_thread_environment() (void) my_rwlock_init(&LOCK_system_variables_hash, NULL); (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_uuid_short, MY_MUTEX_INIT_FAST); + (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_connection_count, MY_MUTEX_INIT_FAST); #ifdef HAVE_OPENSSL (void) pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); @@ -3755,14 +3771,17 @@ static void init_ssl() #ifdef HAVE_OPENSSL if (opt_use_ssl) { + enum enum_ssl_init_error error= SSL_INITERR_NOERROR; + /* having ssl_acceptor_fd != 0 signals the use of SSL */ ssl_acceptor_fd= new_VioSSLAcceptorFd(opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, - opt_ssl_cipher); + opt_ssl_cipher, &error); DBUG_PRINT("info",("ssl_acceptor_fd: 0x%lx", (long) ssl_acceptor_fd)); if (!ssl_acceptor_fd) { sql_print_warning("Failed to setup SSL"); + sql_print_warning("SSL error: %s", sslGetErrString(error)); opt_use_ssl = 0; have_ssl= SHOW_OPTION_DISABLED; } @@ -4412,7 +4431,6 @@ int main(int argc, char **argv) select_thread=pthread_self(); select_thread_in_use=1; - init_ssl(); #ifdef HAVE_LIBWRAP libwrapName= my_progname+dirname_length(my_progname); @@ -4467,6 +4485,7 @@ we force server id to 2, but this MySQL server will not act as a slave."); if (init_server_components()) unireg_abort(1); + init_ssl(); network_init(); #ifdef __WIN__ @@ -4534,6 +4553,11 @@ we force server id to 2, but this MySQL server will not act as a slave."); unireg_abort(1); } + execute_ddl_log_recovery(); + + if (Events::init(opt_noacl || opt_bootstrap)) + unireg_abort(1); + if (opt_bootstrap) { select_thread_in_use= 0; // Allow 'kill' to work @@ -4545,14 +4569,10 @@ we force server id to 2, but this MySQL server will not act as a slave."); if (read_init_file(opt_init_file)) unireg_abort(1); } - execute_ddl_log_recovery(); create_shutdown_thread(); start_handle_manager(); - if (Events::init(opt_noacl)) - unireg_abort(1); - sql_print_information(ER(ER_STARTUP),my_progname,server_version, ((unix_sock == INVALID_SOCKET) ? (char*) "" : mysqld_unix_port), @@ -4678,15 +4698,28 @@ default_service_handling(char **argv, const char *account_name) { char path_and_service[FN_REFLEN+FN_REFLEN+32], *pos, *end; + const char *opt_delim; end= path_and_service + sizeof(path_and_service)-3; /* We have to quote filename if it contains spaces */ pos= add_quoted_string(path_and_service, file_path, end); if (*extra_opt) { - /* Add (possible quoted) option after file_path */ + /* + Add option after file_path. There will be zero or one extra option. It's + assumed to be --defaults-file=file but isn't checked. The variable (not + the option name) should be quoted if it contains a string. + */ *pos++= ' '; - pos= add_quoted_string(pos, extra_opt, end); + if (opt_delim= strchr(extra_opt, '=')) + { + size_t length= ++opt_delim - extra_opt; + strnmov(pos, extra_opt, length); + } + else + opt_delim= extra_opt; + + pos= add_quoted_string(pos, opt_delim, end); } /* We must have servicename last */ *pos++= ' '; @@ -4832,6 +4865,7 @@ static void bootstrap(FILE *file) thd->security_ctx->master_access= ~(ulong)0; thd->thread_id= thd->variables.pseudo_thread_id= thread_id++; thread_count++; + in_bootstrap= TRUE; bootstrap_file=file; #ifndef EMBEDDED_LIBRARY // TODO: Enable this @@ -4844,7 +4878,7 @@ static void bootstrap(FILE *file) } /* Wait for thread to die */ (void) pthread_mutex_lock(&LOCK_thread_count); - while (thread_count) + while (in_bootstrap) { (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count); DBUG_PRINT("quit",("One thread died (count=%u)",thread_count)); @@ -4889,9 +4923,10 @@ void handle_connection_in_main_thread(THD *thd) safe_mutex_assert_owner(&LOCK_thread_count); thread_cache_size=0; // Safety threads.append(thd); - thd->connect_utime= my_micro_time(); - (void) pthread_mutex_unlock(&LOCK_thread_count); - handle_one_connection((void*) thd); + thd->start_utime= my_micro_time(); + pthread_mutex_unlock(&LOCK_thread_count); + thd->start_utime= my_micro_time(); + handle_one_connection(thd); } @@ -4916,7 +4951,7 @@ void create_thread_to_handle_connection(THD *thd) thread_created++; threads.append(thd); DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id)); - thd->connect_utime= thd->start_utime= my_micro_time(); + thd->prior_thr_create_utime= thd->start_utime= my_micro_time(); if ((error=pthread_create(&thd->real_id,&connection_attrib, handle_one_connection, (void*) thd))) @@ -6799,8 +6834,7 @@ log and this option does nothing anymore.", {"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE, "Can be used to restrict the total size used to cache a multi-transaction query.", (uchar**) &max_binlog_cache_size, (uchar**) &max_binlog_cache_size, 0, - GET_ULONG, REQUIRED_ARG, (longlong) ULONG_MAX, IO_SIZE, - (longlong) ULONG_MAX, 0, IO_SIZE, 0}, + GET_ULL, REQUIRED_ARG, ULONG_MAX, IO_SIZE, ULONGLONG_MAX, 0, IO_SIZE, 0}, {"max_binlog_size", OPT_MAX_BINLOG_SIZE, "Binary log will be rotated automatically when the size exceeds this \ value. Will also apply to relay logs if max_relay_log_size is 0. \ @@ -6981,7 +7015,7 @@ The minimum value for this variable is 4096.", (uchar**) &opt_plugin_dir_ptr, (uchar**) &opt_plugin_dir_ptr, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"plugin-load", OPT_PLUGIN_LOAD, - "Optional colon-separated list of plugins to load, where each plugin is " + "Optional semicolon-separated list of plugins to load, where each plugin is " "identified as name=library, where name is the plugin name and library " "is the plugin library in plugin_dir.", (uchar**) &opt_plugin_load, (uchar**) &opt_plugin_load, 0, @@ -7851,7 +7885,7 @@ static int mysql_init_variables(void) /* Set directory paths */ strmake(language, LANGUAGE, sizeof(language)-1); - strmake(mysql_real_data_home, get_relative_path(DATADIR), + strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR), sizeof(mysql_real_data_home)-1); mysql_data_home_buff[0]=FN_CURLIB; // all paths are relative from here mysql_data_home_buff[1]=0; diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 0a8720bae64..73892f31ccf 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -186,10 +186,12 @@ my_bool net_realloc(NET *net, size_t length) pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* We must allocate some extra bytes for the end 0 and to be able to - read big compressed blocks + read big compressed blocks + 1 safety byte since uint3korr() in + my_real_read() may actually read 4 bytes depending on build flags and + platform. */ if (!(buff= (uchar*) my_realloc((char*) net->buff, pkt_length + - NET_HEADER_SIZE + COMP_HEADER_SIZE, + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, MYF(MY_WME)))) { /* @todo: 1 and 2 codes are identical. */ @@ -921,6 +923,13 @@ my_real_read(NET *net, size_t *complen) #ifdef HAVE_COMPRESS if (net->compress) { + /* + The following uint3korr() may read 4 bytes, so make sure we don't + read unallocated or uninitialized memory. The right-hand expression + must match the size of the buffer allocated in net_realloc(). + */ + DBUG_ASSERT(net->where_b + NET_HEADER_SIZE + sizeof(uint32) <= + net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1); /* If the packet is compressed then complen > 0 and contains the number of bytes in the uncompressed packet diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 1d6ea404900..0d7d7253f08 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -8557,7 +8557,7 @@ int QUICK_RANGE_SELECT::get_next_prefix(uint prefix_length, result= file->read_range_first(last_range->min_keypart_map ? &start_key : 0, last_range->max_keypart_map ? &end_key : 0, test(last_range->flag & EQ_RANGE), - sorted); + TRUE); if (last_range->flag == (UNIQUE_RANGE | EQ_RANGE)) last_range= 0; // Stop searching @@ -10887,8 +10887,14 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range() /* Compare the found key with max_key. */ int cmp_res= key_cmp(index_info->key_part, max_key, real_prefix_len + min_max_arg_len); - if (!(((cur_range->flag & NEAR_MAX) && (cmp_res == -1)) || - (cmp_res <= 0))) + /* + The key is outside of the range if: + the interval is open and the key is equal to the maximum boundry + or + the key is greater than the maximum + */ + if (((cur_range->flag & NEAR_MAX) && cmp_res == 0) || + cmp_res > 0) { result= HA_ERR_KEY_NOT_FOUND; continue; @@ -11005,8 +11011,14 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range() /* Compare the found key with min_key. */ int cmp_res= key_cmp(index_info->key_part, min_key, real_prefix_len + min_max_arg_len); - if (!(((cur_range->flag & NEAR_MIN) && (cmp_res == 1)) || - (cmp_res >= 0))) + /* + The key is outside of the range if: + the interval is open and the key is equal to the minimum boundry + or + the key is less than the minimum + */ + if (((cur_range->flag & NEAR_MIN) && cmp_res == 0) || + cmp_res < 0) continue; } /* If we got to this point, the current key qualifies as MAX. */ diff --git a/sql/parse_file.cc b/sql/parse_file.cc index 07ea434e8e0..3d65fa1de31 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -231,7 +231,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, including dir name, file name itself, and an extension, and with unpack_filename() executed over it. */ - path_end= strxnmov(path, FN_REFLEN, file_name->str, NullS) - path; + path_end= strxnmov(path, sizeof(path) - 1, file_name->str, NullS) - path; } // temporary file name @@ -302,6 +302,7 @@ err_w_file: @thd thread handler @param schema name of given schema @param old_name original file name + @param new_db new schema @param new_name new file name @retval @@ -311,14 +312,14 @@ err_w_file: */ my_bool rename_in_schema_file(THD *thd, const char *schema, const char *old_name, - const char *new_name) + const char *new_db, const char *new_name) { - char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN]; + char old_path[FN_REFLEN + 1], new_path[FN_REFLEN + 1], arc_path[FN_REFLEN + 1]; build_table_filename(old_path, sizeof(old_path) - 1, schema, old_name, reg_ext, 0); build_table_filename(new_path, sizeof(new_path) - 1, - schema, new_name, reg_ext, 0); + new_db, new_name, reg_ext, 0); if (my_rename(old_path, new_path, MYF(MY_WME))) return 1; diff --git a/sql/parse_file.h b/sql/parse_file.h index cfac69cc471..84647e45927 100644 --- a/sql/parse_file.h +++ b/sql/parse_file.h @@ -83,7 +83,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, uchar* base, File_option *parameters); my_bool rename_in_schema_file(THD *thd, const char *schema, const char *old_name, - const char *new_name); + const char *new_db, const char *new_name); class File_parser: public Sql_alloc { diff --git a/sql/password.c b/sql/password.c index 43430f37f96..3c662e0c8f3 100644 --- a/sql/password.c +++ b/sql/password.c @@ -108,20 +108,39 @@ void hash_password(ulong *result, const char *password, uint password_len) Create password to be stored in user database from raw string Used for pre-4.1 password handling SYNOPSIS - make_scrambled_password_323() + my_make_scrambled_password_323() to OUT store scrambled password here password IN user-supplied password + pass_len IN length of password string */ -void make_scrambled_password_323(char *to, const char *password) +void my_make_scrambled_password_323(char *to, const char *password, + size_t pass_len) { ulong hash_res[2]; - hash_password(hash_res, password, (uint) strlen(password)); + hash_password(hash_res, password, (uint) pass_len); sprintf(to, "%08lx%08lx", hash_res[0], hash_res[1]); } /* + Wrapper around my_make_scrambled_password_323() to maintain client lib ABI + compatibility. + In server code usage of my_make_scrambled_password_323() is preferred to + avoid strlen(). + SYNOPSIS + make_scrambled_password_323() + to OUT store scrambled password here + password IN NULL-terminated string with user-supplied password +*/ + +void make_scrambled_password_323(char *to, const char *password) +{ + my_make_scrambled_password_323(to, password, strlen(password)); +} + + +/* Scramble string with password. Used in pre 4.1 authentication phase. SYNOPSIS @@ -355,20 +374,21 @@ my_crypt(char *to, const uchar *s1, const uchar *s2, uint len) The result of this function is used as return value from PASSWORD() and is stored in the database. SYNOPSIS - make_scrambled_password() + my_make_scrambled_password() buf OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string - password IN NULL-terminated password string + password IN password string + pass_len IN length of password string */ -void -make_scrambled_password(char *to, const char *password) +void my_make_scrambled_password(char *to, const char *password, + size_t pass_len) { SHA1_CONTEXT sha1_context; uint8 hash_stage2[SHA1_HASH_SIZE]; mysql_sha1_reset(&sha1_context); /* stage 1: hash password */ - mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) strlen(password)); + mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) pass_len); mysql_sha1_result(&sha1_context, (uint8 *) to); /* stage 2: hash stage1 output */ mysql_sha1_reset(&sha1_context); @@ -382,6 +402,23 @@ make_scrambled_password(char *to, const char *password) /* + Wrapper around my_make_scrambled_password() to maintain client lib ABI + compatibility. + In server code usage of my_make_scrambled_password() is preferred to + avoid strlen(). + SYNOPSIS + make_scrambled_password() + buf OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string + password IN NULL-terminated password string +*/ + +void make_scrambled_password(char *to, const char *password) +{ + my_make_scrambled_password(to, password, strlen(password)); +} + + +/* Produce an obscure octet sequence from password and random string, recieved from the server. This sequence corresponds to the password, but password can not be easily restored from it. The sequence diff --git a/sql/protocol.cc b/sql/protocol.cc index e61ad00b50f..11b4c085505 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -29,11 +29,11 @@ static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024; /* Declared non-static only because of the embedded library. */ -void net_send_error_packet(THD *thd, uint sql_errno, const char *err); -void net_send_ok(THD *, uint, uint, ha_rows, ulonglong, const char *); -void net_send_eof(THD *thd, uint server_status, uint total_warn_count); +bool net_send_error_packet(THD *thd, uint sql_errno, const char *err); +bool net_send_ok(THD *, uint, uint, ha_rows, ulonglong, const char *); +bool net_send_eof(THD *thd, uint server_status, uint total_warn_count); #ifndef EMBEDDED_LIBRARY -static void write_eof_packet(THD *thd, NET *net, +static bool write_eof_packet(THD *thd, NET *net, uint server_status, uint total_warn_count); #endif @@ -129,8 +129,17 @@ bool Protocol::net_store_data(const uchar *from, size_t length, For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's critical that every error that can be intercepted is issued in one place only, my_message_sql. + + @param thd Thread handler + @param sql_errno The error code to send + @param err A pointer to the error message + + @return + @retval FALSE The message was sent to the client + @retval TRUE An error occurred and the message wasn't sent properly */ -void net_send_error(THD *thd, uint sql_errno, const char *err) + +bool net_send_error(THD *thd, uint sql_errno, const char *err) { DBUG_ENTER("net_send_error"); @@ -139,6 +148,7 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) DBUG_ASSERT(err && err[0]); DBUG_PRINT("enter",("sql_errno: %d err: %s", sql_errno, err)); + bool error; /* It's one case when we can push an error even though there @@ -149,11 +159,11 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) /* Abort multi-result sets */ thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS; - net_send_error_packet(thd, sql_errno, err); + error= net_send_error_packet(thd, sql_errno, err); thd->main_da.can_overwrite_status= FALSE; - DBUG_VOID_RETURN; + DBUG_RETURN(error); } /** @@ -172,25 +182,33 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) Is not stored if no message. @param thd Thread handler + @param server_status The server status + @param total_warn_count Total number of warnings @param affected_rows Number of rows changed by statement @param id Auto_increment id for first row (if used) @param message Message to send to the client (Used by mysql_status) + + @return + @retval FALSE The message was successfully sent + @retval TRUE An error occurred and the messages wasn't sent properly + */ #ifndef EMBEDDED_LIBRARY -void +bool net_send_ok(THD *thd, uint server_status, uint total_warn_count, ha_rows affected_rows, ulonglong id, const char *message) { NET *net= &thd->net; uchar buff[MYSQL_ERRMSG_SIZE+10],*pos; + bool error= FALSE; DBUG_ENTER("my_ok"); if (! net->vio) // hack for re-parsing queries { DBUG_PRINT("info", ("vio present: NO")); - DBUG_VOID_RETURN; + DBUG_RETURN(FALSE); } buff[0]=0; // No fields @@ -221,13 +239,14 @@ net_send_ok(THD *thd, if (message && message[0]) pos= net_store_data(pos, (uchar*) message, strlen(message)); - VOID(my_net_write(net, buff, (size_t) (pos-buff))); - VOID(net_flush(net)); + error= my_net_write(net, buff, (size_t) (pos-buff)); + if (!error) + error= net_flush(net); thd->main_da.can_overwrite_status= FALSE; DBUG_PRINT("info", ("OK sent, so no more error sending allowed")); - DBUG_VOID_RETURN; + DBUG_RETURN(error); } static uchar eof_buff[1]= { (uchar) 254 }; /* Marker for end of fields */ @@ -247,37 +266,54 @@ static uchar eof_buff[1]= { (uchar) 254 }; /* Marker for end of fields */ client. @param thd Thread handler - @param no_flush Set to 1 if there will be more data to the client, - like in send_fields(). + @param server_status The server status + @param total_warn_count Total number of warnings + + @return + @retval FALSE The message was successfully sent + @retval TRUE An error occurred and the message wasn't sent properly */ -void +bool net_send_eof(THD *thd, uint server_status, uint total_warn_count) { NET *net= &thd->net; + bool error= FALSE; DBUG_ENTER("net_send_eof"); /* Set to TRUE if no active vio, to work well in case of --init-file */ if (net->vio != 0) { thd->main_da.can_overwrite_status= TRUE; - write_eof_packet(thd, net, server_status, total_warn_count); - VOID(net_flush(net)); + error= write_eof_packet(thd, net, server_status, total_warn_count); + if (!error) + error= net_flush(net); thd->main_da.can_overwrite_status= FALSE; DBUG_PRINT("info", ("EOF sent, so no more error sending allowed")); } - DBUG_VOID_RETURN; + DBUG_RETURN(error); } /** Format EOF packet according to the current protocol and write it to the network output buffer. + + @param thd The thread handler + @param net The network handler + @param server_status The server status + @param total_warn_count The number of warnings + + + @return + @retval FALSE The message was sent successfully + @retval TRUE An error occurred and the messages wasn't sent properly */ -static void write_eof_packet(THD *thd, NET *net, +static bool write_eof_packet(THD *thd, NET *net, uint server_status, uint total_warn_count) { + bool error; if (thd->client_capabilities & CLIENT_PROTOCOL_41) { uchar buff[5]; @@ -296,10 +332,12 @@ static void write_eof_packet(THD *thd, NET *net, if (thd->is_fatal_error) server_status&= ~SERVER_MORE_RESULTS_EXISTS; int2store(buff + 3, server_status); - VOID(my_net_write(net, buff, 5)); + error= my_net_write(net, buff, 5); } else - VOID(my_net_write(net, eof_buff, 1)); + error= my_net_write(net, eof_buff, 1); + + return error; } /** @@ -320,7 +358,17 @@ bool send_old_password_request(THD *thd) } -void net_send_error_packet(THD *thd, uint sql_errno, const char *err) +/** + @param thd Thread handler + @param sql_errno The error code to send + @param err A pointer to the error message + + @return + @retval FALSE The message was successfully sent + @retval TRUE An error occurred and the messages wasn't sent properly +*/ + +bool net_send_error_packet(THD *thd, uint sql_errno, const char *err) { NET *net= &thd->net; uint length; @@ -338,7 +386,7 @@ void net_send_error_packet(THD *thd, uint sql_errno, const char *err) /* In bootstrap it's ok to print on stderr */ fprintf(stderr,"ERROR: %d %s\n",sql_errno,err); } - DBUG_VOID_RETURN; + DBUG_RETURN(FALSE); } if (net->return_errno) @@ -360,9 +408,8 @@ void net_send_error_packet(THD *thd, uint sql_errno, const char *err) length=(uint) strlen(err); set_if_smaller(length,MYSQL_ERRMSG_SIZE-1); } - VOID(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err, + DBUG_RETURN(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err, length)); - DBUG_VOID_RETURN; } #endif /* EMBEDDED_LIBRARY */ @@ -449,36 +496,39 @@ void net_end_statement(THD *thd) if (thd->main_da.is_sent) return; + bool error= FALSE; + switch (thd->main_da.status()) { case Diagnostics_area::DA_ERROR: /* The query failed, send error to log and abort bootstrap. */ - net_send_error(thd, - thd->main_da.sql_errno(), - thd->main_da.message()); + error= net_send_error(thd, + thd->main_da.sql_errno(), + thd->main_da.message()); break; case Diagnostics_area::DA_EOF: - net_send_eof(thd, - thd->main_da.server_status(), - thd->main_da.total_warn_count()); + error= net_send_eof(thd, + thd->main_da.server_status(), + thd->main_da.total_warn_count()); break; case Diagnostics_area::DA_OK: - net_send_ok(thd, - thd->main_da.server_status(), - thd->main_da.total_warn_count(), - thd->main_da.affected_rows(), - thd->main_da.last_insert_id(), - thd->main_da.message()); + error= net_send_ok(thd, + thd->main_da.server_status(), + thd->main_da.total_warn_count(), + thd->main_da.affected_rows(), + thd->main_da.last_insert_id(), + thd->main_da.message()); break; case Diagnostics_area::DA_DISABLED: break; case Diagnostics_area::DA_EMPTY: default: DBUG_ASSERT(0); - net_send_ok(thd, thd->server_status, thd->total_warn_count, - 0, 0, NULL); + error= net_send_ok(thd, thd->server_status, thd->total_warn_count, + 0, 0, NULL); break; } - thd->main_da.is_sent= TRUE; + if (!error) + thd->main_da.is_sent= TRUE; DBUG_VOID_RETURN; } diff --git a/sql/protocol.h b/sql/protocol.h index 339ae1be346..5a043d9c482 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -175,7 +175,7 @@ public: }; 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); +bool net_send_error(THD *thd, uint sql_errno=0, const char *err=0); void net_end_statement(THD *thd); bool send_old_password_request(THD *thd); uchar *net_store_data(uchar *to,const uchar *from, size_t length); diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index 2d7234f78d7..68272c58bb1 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -340,8 +340,7 @@ Rpl_filter::add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec) e->tbl_name= e->db + (dot - table_spec) + 1; e->key_len= len; memcpy(e->db, table_spec, len); - insert_dynamic(a, (uchar*)&e); - return 0; + return insert_dynamic(a, (uchar*)&e); } diff --git a/sql/rpl_reporting.cc b/sql/rpl_reporting.cc index 28f257790c7..a09140de3c4 100644 --- a/sql/rpl_reporting.cc +++ b/sql/rpl_reporting.cc @@ -13,6 +13,7 @@ Slave_reporting_capability::report(loglevel level, int err_code, va_list args; va_start(args, msg); + pthread_mutex_lock(&err_lock); switch (level) { case ERROR_LEVEL: @@ -38,6 +39,7 @@ Slave_reporting_capability::report(loglevel level, int err_code, my_vsnprintf(pbuff, pbuffsize, msg, args); + pthread_mutex_unlock(&err_lock); va_end(args); /* If the msg string ends with '.', do not add a ',' it would be ugly */ @@ -46,3 +48,8 @@ Slave_reporting_capability::report(loglevel level, int err_code, (pbuff[0] && *(strend(pbuff)-1) == '.') ? "" : ",", err_code); } + +Slave_reporting_capability::~Slave_reporting_capability() +{ + pthread_mutex_destroy(&err_lock); +} diff --git a/sql/rpl_reporting.h b/sql/rpl_reporting.h index 2e3fa3cea83..ce33407e516 100644 --- a/sql/rpl_reporting.h +++ b/sql/rpl_reporting.h @@ -16,6 +16,8 @@ class Slave_reporting_capability { public: + /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/ + mutable pthread_mutex_t err_lock; /** Constructor. @@ -24,6 +26,7 @@ public: Slave_reporting_capability(char const *thread_name) : m_thread_name(thread_name) { + pthread_mutex_init(&err_lock, MY_MUTEX_INIT_FAST); } /** @@ -44,7 +47,9 @@ public: STATUS</code>. */ void clear_error() { + pthread_mutex_lock(&err_lock); m_last_error.clear(); + pthread_mutex_unlock(&err_lock); } /** @@ -72,6 +77,7 @@ public: Error const& last_error() const { return m_last_error; } + virtual ~Slave_reporting_capability()= 0; private: /** Last error produced by the I/O or SQL thread respectively. @@ -79,6 +85,10 @@ private: mutable Error m_last_error; char const *const m_thread_name; + + // not implemented + Slave_reporting_capability(const Slave_reporting_capability& rhs); + Slave_reporting_capability& operator=(const Slave_reporting_capability& rhs); }; #endif // RPL_REPORTING_H diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 3fbe9b16d23..be1845d10b0 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -99,9 +99,16 @@ int init_relay_log_info(Relay_log_info* rli, rli->tables_to_lock= 0; rli->tables_to_lock_count= 0; - fn_format(rli->slave_patternload_file, PREFIX_SQL_LOAD, slave_load_tmpdir, "", - MY_PACK_FILENAME | MY_UNPACK_FILENAME | - MY_RETURN_REAL_PATH); + char pattern[FN_REFLEN]; + if (fn_format(pattern, PREFIX_SQL_LOAD, slave_load_tmpdir, "", + MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS) + { + pthread_mutex_unlock(&rli->data_lock); + sql_print_error("Unable to use slave's temporary directory %s", + slave_load_tmpdir); + DBUG_RETURN(1); + } + unpack_filename(rli->slave_patternload_file, pattern); rli->slave_patternload_file_size= strlen(rli->slave_patternload_file); /* @@ -935,6 +942,7 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, if (count_relay_log_space(rli)) { *errmsg= "Error counting relay log space"; + error=1; goto err; } if (!just_reset) diff --git a/sql/scheduler.cc b/sql/scheduler.cc index f25ae2b663e..e0a7837de8e 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -235,9 +235,9 @@ void thd_scheduler::thread_detach() if (thread_attached) { THD* thd = (THD*)list.data; - pthread_mutex_lock(&thd->LOCK_delete); + pthread_mutex_lock(&thd->LOCK_thd_data); thd->mysys_var= NULL; - pthread_mutex_unlock(&thd->LOCK_delete); + pthread_mutex_unlock(&thd->LOCK_thd_data); thread_attached= FALSE; #ifndef DBUG_OFF /* @@ -481,7 +481,7 @@ static void libevent_add_connection(THD *thd) @brief Signal a waiting connection it's time to die. @details This function will signal libevent the THD should be killed. - Either the global LOCK_thd_count or the THD's LOCK_delete must be locked + Either the global LOCK_thd_count or the THD's LOCK_thd_data must be locked upon entry. @param[in] thd The connection to kill diff --git a/sql/set_var.cc b/sql/set_var.cc index 3b3dad8a486..113e22c6aaa 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -383,8 +383,8 @@ static sys_var_const sys_lower_case_table_names(&vars, &lower_case_table_names); static sys_var_thd_ulong_session_readonly sys_max_allowed_packet(&vars, "max_allowed_packet", &SV::max_allowed_packet); -static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size", - &max_binlog_cache_size); +static sys_var_ulonglong_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size", + &max_binlog_cache_size); static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size", &max_binlog_size, fix_max_binlog_size); diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index aa1521acab6..5531ee71620 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5614,7 +5614,7 @@ ER_SP_WRONG_NAME 42000 eng "Incorrect routine name '%-.192s'" ger "Ungültiger Routinenname '%-.192s'" ER_TABLE_NEEDS_UPGRADE - eng "Table upgrade required. Please do \"REPAIR TABLE `%-.32s`\" to fix it!" + eng "Table upgrade required. Please do \"REPAIR TABLE `%-.32s`\" or dump/reload to fix it!" ger "Tabellenaktualisierung erforderlich. Bitte zum Reparieren \"REPAIR TABLE `%-.32s`\" eingeben!" ER_SP_NO_AGGREGATE 42000 eng "AGGREGATE is not supported for stored functions" @@ -6076,7 +6076,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 "Statement is not safe to log in statement format." + eng "Statement may not be safe to log in statement format." swe "Detta är inte säkert att logga i statement-format." ER_SLAVE_FATAL_ERROR eng "Fatal error: %s" @@ -6177,3 +6177,32 @@ ER_TOO_LONG_TABLE_COMMENT ER_TOO_LONG_FIELD_COMMENT eng "Comment for field '%-.64s' is too long (max = %lu)" por "Comentário para o campo '%-.64s' é longo demais (max = %lu)" + +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. +ER_DATABASE_NAME + eng "Database `%s`" + swe "Databas `%s`" +ER_TABLE_NAME + eng "Table `%s`" + swe "Tabell `%s`" +ER_PARTITION_NAME + eng "Partition `%s`" + swe "Partition `%s`" +ER_SUBPARTITION_NAME + eng "Subpartition `%s`" + swe "Subpartition `%s`" +ER_TEMPORARY_NAME + eng "Temporary" + swe "Temporär" +ER_RENAMED_NAME + eng "Renamed" + swe "Namnändrad" +ER_TOO_MANY_CONCURRENT_TRXS + eng "Too many active concurrent transactions" + +WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED + eng "Non-ASCII separator arguments are not fully supported" diff --git a/sql/slave.cc b/sql/slave.cc index d4c6049b748..926db30be15 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -38,6 +38,7 @@ #include <my_dir.h> #include <sql_common.h> #include <errmsg.h> +#include <mysqld_error.h> #include <mysys_err.h> #ifdef HAVE_REPLICATION @@ -128,6 +129,7 @@ static bool wait_for_relay_log_space(Relay_log_info* rli); static inline bool io_slave_killed(THD* thd,Master_info* mi); static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli); static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type); +static void print_slave_skip_errors(void); static int safe_connect(THD* thd, MYSQL* mysql, Master_info* mi); static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi, bool suppress_warnings); @@ -142,8 +144,8 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi); static Log_event* next_event(Relay_log_info* rli); static int queue_event(Master_info* mi,const char* buf,ulong event_len); static int terminate_slave_thread(THD *thd, - pthread_mutex_t* term_lock, - pthread_cond_t* term_cond, + pthread_mutex_t *term_lock, + pthread_cond_t *term_cond, volatile uint *slave_running, bool skip_lock); static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info); @@ -232,6 +234,15 @@ int init_slave() active_mi= new Master_info; /* + If --slave-skip-errors=... was not used, the string value for the + system variable has not been set up yet. Do it now. + */ + if (!use_slave_mask) + { + print_slave_skip_errors(); + } + + /* If master_host is not specified, try to read it from the master_info file. If master_host is specified, create the master_info file if it doesn't exists. @@ -311,7 +322,7 @@ static void print_slave_skip_errors(void) char *bend= buff + sizeof(slave_skip_error_names); int errnum; - for (errnum= 1; errnum < MAX_SLAVE_ERROR; errnum++) + for (errnum= 0; errnum < MAX_SLAVE_ERROR; errnum++) { if (bitmap_is_set(&slave_error_mask, errnum)) { @@ -361,6 +372,7 @@ void init_slave_skip_errors(const char* arg) if (!my_strnncoll(system_charset_info,(uchar*)arg,4,(const uchar*)"all",4)) { bitmap_set_all(&slave_error_mask); + print_slave_skip_errors(); DBUG_VOID_RETURN; } for (p= arg ; *p; ) @@ -378,6 +390,13 @@ void init_slave_skip_errors(const char* arg) DBUG_VOID_RETURN; } +static void set_thd_in_use_temporary_tables(Relay_log_info *rli) +{ + TABLE *table; + + for (table= rli->save_temporary_tables ; table ; table= table->next) + table->in_use= rli->sql_thd; +} int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) { @@ -388,22 +407,22 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) int error,force_all = (thread_mask & SLAVE_FORCE_ALL); pthread_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock; - if ((thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL))) + if (thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL)) { DBUG_PRINT("info",("Terminating IO thread")); mi->abort_slave=1; - if ((error=terminate_slave_thread(mi->io_thd,io_lock, + if ((error=terminate_slave_thread(mi->io_thd, io_lock, &mi->stop_cond, &mi->slave_running, skip_lock)) && !force_all) DBUG_RETURN(error); } - if ((thread_mask & (SLAVE_SQL|SLAVE_FORCE_ALL))) + if (thread_mask & (SLAVE_SQL|SLAVE_FORCE_ALL)) { DBUG_PRINT("info",("Terminating SQL thread")); mi->rli.abort_slave=1; - if ((error=terminate_slave_thread(mi->rli.sql_thd,sql_lock, + if ((error=terminate_slave_thread(mi->rli.sql_thd, sql_lock, &mi->rli.stop_cond, &mi->rli.slave_running, skip_lock)) && @@ -441,29 +460,44 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) the condition. In this case, it is assumed that the calling function acquires the lock before calling this function. - @retval 0 All OK + @retval 0 All OK ER_SLAVE_NOT_RUNNING otherwise. + + @note If the executing thread has to acquire term_lock (skip_lock + is false), the negative running status does not represent + any issue therefore no error is reported. + */ static int terminate_slave_thread(THD *thd, - pthread_mutex_t* term_lock, - pthread_cond_t* term_cond, + pthread_mutex_t *term_lock, + pthread_cond_t *term_cond, volatile uint *slave_running, bool skip_lock) { - int error; - DBUG_ENTER("terminate_slave_thread"); - if (!skip_lock) + { pthread_mutex_lock(term_lock); - - safe_mutex_assert_owner(term_lock); - + } + else + { + safe_mutex_assert_owner(term_lock); + } if (!*slave_running) { if (!skip_lock) + { + /* + if run_lock (term_lock) is acquired locally then either + slave_running status is fine + */ pthread_mutex_unlock(term_lock); - DBUG_RETURN(ER_SLAVE_NOT_RUNNING); + DBUG_RETURN(0); + } + else + { + DBUG_RETURN(ER_SLAVE_NOT_RUNNING); + } } DBUG_ASSERT(thd != 0); THD_CHECK_SENTRY(thd); @@ -475,9 +509,10 @@ terminate_slave_thread(THD *thd, while (*slave_running) // Should always be true { + int error; DBUG_PRINT("loop", ("killing slave thread")); - pthread_mutex_lock(&thd->LOCK_delete); + pthread_mutex_lock(&thd->LOCK_thd_data); #ifndef DONT_USE_THR_ALARM /* Error codes from pthread_kill are: @@ -488,7 +523,7 @@ terminate_slave_thread(THD *thd, DBUG_ASSERT(err != EINVAL); #endif thd->awake(THD::NOT_KILLED); - pthread_mutex_unlock(&thd->LOCK_delete); + pthread_mutex_unlock(&thd->LOCK_thd_data); /* There is a small chance that slave thread might miss the first @@ -616,7 +651,7 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, &mi->rli.slave_running, &mi->rli.slave_run_id, mi, 0); if (error) - terminate_slave_threads(mi, thread_mask & SLAVE_IO, 0); + terminate_slave_threads(mi, thread_mask & SLAVE_IO, !need_slave_mutex); } DBUG_RETURN(error); } @@ -634,7 +669,7 @@ static int end_slave_on_walk(Master_info* mi, uchar* /*unused*/) /* - Free all resources used by slave + Release slave threads at time of executing shutdown. SYNOPSIS end_slave() @@ -660,15 +695,32 @@ void end_slave() once multi-master code is ready. */ terminate_slave_threads(active_mi,SLAVE_FORCE_ALL); + } + pthread_mutex_unlock(&LOCK_active_mi); + DBUG_VOID_RETURN; +} + +/** + Free all resources used by slave threads at time of executing shutdown. + The routine must be called after all possible users of @c active_mi + have left. + + SYNOPSIS + close_active_mi() + +*/ +void close_active_mi() +{ + pthread_mutex_lock(&LOCK_active_mi); + if (active_mi) + { end_master_info(active_mi); delete active_mi; active_mi= 0; } pthread_mutex_unlock(&LOCK_active_mi); - DBUG_VOID_RETURN; } - static bool io_slave_killed(THD* thd, Master_info* mi) { DBUG_ENTER("io_slave_killed"); @@ -687,6 +739,9 @@ static bool sql_slave_killed(THD* thd, Relay_log_info* rli) DBUG_ASSERT(rli->slave_running == 1);// tracking buffer overrun if (abort_loop || thd->killed || rli->abort_slave) { + if (rli->abort_slave && rli->is_in_group() && + thd->transaction.all.modified_non_trans_table) + DBUG_RETURN(0); /* If we are in an unsafe situation (stopping could corrupt replication), we give one minute to the slave SQL thread of grace before really @@ -755,6 +810,29 @@ const char *print_slave_db_safe(const char* db) DBUG_RETURN((db ? db : "")); } + +/* + Check if the error is caused by network. + @param[in] errorno Number of the error. + RETURNS: + TRUE network error + FALSE not network error +*/ + +bool is_network_error(uint errorno) +{ + if (errorno == CR_CONNECTION_ERROR || + errorno == CR_CONN_HOST_ERROR || + errorno == CR_SERVER_GONE_ERROR || + errorno == CR_SERVER_LOST || + errorno == ER_CON_COUNT_ERROR || + errorno == ER_SERVER_SHUTDOWN) + return TRUE; + + return FALSE; +} + + /* Note that we rely on the master's version (3.23, 4.0.14 etc) instead of relying on the binlog's version. This is not perfect: imagine an upgrade @@ -767,6 +845,7 @@ const char *print_slave_db_safe(const char* db) RETURNS 0 ok 1 error + 2 transient network problem, the caller should try to reconnect */ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) @@ -852,6 +931,8 @@ 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); + master_res= NULL; if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) && (master_res= mysql_store_result(mysql)) && (master_row= mysql_fetch_row(master_res))) @@ -859,7 +940,13 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) mi->clock_diff_with_master= (long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10)); } - else if (!check_io_slave_killed(mi->io_thd, mi, NULL)) + else if (is_network_error(mysql_errno(mysql))) + { + mi->report(WARNING_LEVEL, mysql_errno(mysql), + "Get master clock failed with error: %s", mysql_error(mysql)); + goto network_err; + } + else { mi->clock_diff_with_master= 0; /* The "most sensible" value */ sql_print_warning("\"SELECT UNIX_TIMESTAMP()\" failed on master, " @@ -868,7 +955,10 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) mysql_error(mysql), mysql_errno(mysql)); } if (master_res) + { mysql_free_result(master_res); + master_res= NULL; + } /* Check that the master's server id and ours are different. Because if they @@ -880,12 +970,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); + master_res= NULL; + master_row= NULL; if (!mysql_real_query(mysql, STRING_WITH_LEN("SHOW VARIABLES LIKE 'SERVER_ID'")) && - (master_res= mysql_store_result(mysql))) + (master_res= mysql_store_result(mysql)) && + (master_row= mysql_fetch_row(master_res))) { - if ((master_row= mysql_fetch_row(master_res)) && - (::server_id == strtoul(master_row[1], 0, 10)) && + if ((::server_id == strtoul(master_row[1], 0, 10)) && !mi->rli.replicate_same_server_id) { errmsg= "The slave I/O thread stops because master and slave have equal \ @@ -894,10 +987,34 @@ the --replicate-same-server-id option must be used on slave but this does \ not always make sense; please check the manual before using it)."; err_code= ER_SLAVE_FATAL_ERROR; sprintf(err_buff, ER(err_code), errmsg); + goto err; + } + } + else if (mysql_errno(mysql)) + { + if (is_network_error(mysql_errno(mysql))) + { + mi->report(WARNING_LEVEL, mysql_errno(mysql), + "Get master SERVER_ID failed with error: %s", mysql_error(mysql)); + goto network_err; } + /* Fatal error */ + errmsg= "The slave I/O thread stops because a fatal error is encountered \ +when it try to get the value of SERVER_ID variable from master."; + err_code= mysql_errno(mysql); + sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql)); + goto err; + } + else if (!master_row && master_res) + { + mi->report(WARNING_LEVEL, ER_UNKNOWN_SYSTEM_VARIABLE, + "Unknown system variable 'SERVER_ID' on master, \ +maybe it is a *VERY OLD MASTER*."); + } + if (master_res) + { mysql_free_result(master_res); - if (errmsg) - goto err; + master_res= NULL; } /* @@ -921,23 +1038,50 @@ not always make sense; please check the manual before using it)."; if (*mysql->server_version == '3') goto err; - if ((*mysql->server_version == '4') && - !mysql_real_query(mysql, - STRING_WITH_LEN("SELECT @@GLOBAL.COLLATION_SERVER")) && - (master_res= mysql_store_result(mysql))) + if (*mysql->server_version == '4') { - if ((master_row= mysql_fetch_row(master_res)) && - strcmp(master_row[0], global_system_variables.collation_server->name)) + master_res= NULL; + if (!mysql_real_query(mysql, + STRING_WITH_LEN("SELECT @@GLOBAL.COLLATION_SERVER")) && + (master_res= mysql_store_result(mysql)) && + (master_row= mysql_fetch_row(master_res))) { - errmsg= "The slave I/O thread stops because master and slave have \ + if (strcmp(master_row[0], global_system_variables.collation_server->name)) + { + errmsg= "The slave I/O thread stops because master and slave have \ different values for the COLLATION_SERVER global variable. The values must \ -be equal for replication to work"; - err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), errmsg); +be equal for the Statement-format replication to work"; + err_code= ER_SLAVE_FATAL_ERROR; + sprintf(err_buff, ER(err_code), errmsg); + goto err; + } } - mysql_free_result(master_res); - if (errmsg) + else if (is_network_error(mysql_errno(mysql))) + { + mi->report(WARNING_LEVEL, mysql_errno(mysql), + "Get master COLLATION_SERVER failed with error: %s", mysql_error(mysql)); + goto network_err; + } + else if (mysql_errno(mysql) != ER_UNKNOWN_SYSTEM_VARIABLE) + { + /* Fatal error */ + errmsg= "The slave I/O thread stops because a fatal error is encountered \ +when it try to get the value of COLLATION_SERVER global variable from master."; + err_code= mysql_errno(mysql); + sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql)); goto err; + } + else + mi->report(WARNING_LEVEL, ER_UNKNOWN_SYSTEM_VARIABLE, + "Unknown system variable 'COLLATION_SERVER' on master, \ +maybe it is a *VERY OLD MASTER*. *NOTE*: slave may experience \ +inconsistency if replicated data deals with collation."); + + if (master_res) + { + mysql_free_result(master_res); + master_res= NULL; + } } /* @@ -955,35 +1099,62 @@ be equal for replication to work"; This check is only necessary for 4.x masters (and < 5.0.4 masters but those were alpha). */ - if ((*mysql->server_version == '4') && - !mysql_real_query(mysql, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) && - (master_res= mysql_store_result(mysql))) + if (*mysql->server_version == '4') { - if ((master_row= mysql_fetch_row(master_res)) && - strcmp(master_row[0], - global_system_variables.time_zone->get_name()->ptr())) + master_res= NULL; + if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) && + (master_res= mysql_store_result(mysql)) && + (master_row= mysql_fetch_row(master_res))) { - errmsg= "The slave I/O thread stops because master and slave have \ + if (strcmp(master_row[0], + global_system_variables.time_zone->get_name()->ptr())) + { + errmsg= "The slave I/O thread stops because master and slave have \ different values for the TIME_ZONE global variable. The values must \ -be equal for replication to work"; - err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), errmsg); +be equal for the Statement-format replication to work"; + err_code= ER_SLAVE_FATAL_ERROR; + sprintf(err_buff, ER(err_code), errmsg); + goto err; + } } - mysql_free_result(master_res); - - if (errmsg) + else if (is_network_error(mysql_errno(mysql))) + { + mi->report(WARNING_LEVEL, mysql_errno(mysql), + "Get master TIME_ZONE failed with error: %s", mysql_error(mysql)); + goto network_err; + } + else + { + /* Fatal error */ + errmsg= "The slave I/O thread stops because a fatal error is encountered \ +when it try to get the value of TIME_ZONE global variable from master."; + err_code= mysql_errno(mysql); + sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql)); goto err; + } + if (master_res) + { + mysql_free_result(master_res); + master_res= NULL; + } } err: if (errmsg) { + if (master_res) + mysql_free_result(master_res); DBUG_ASSERT(err_code != 0); mi->report(ERROR_LEVEL, err_code, err_buff); DBUG_RETURN(1); } DBUG_RETURN(0); + +network_err: + if (master_res) + mysql_free_result(master_res); + DBUG_RETURN(2); } /* @@ -1029,15 +1200,13 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, DBUG_RETURN(1); } thd->command = COM_TABLE_DUMP; - thd->query_length= packet_len; - /* Note that we should not set thd->query until the area is initalized */ if (!(query = thd->strmake((char*) net->read_pos, packet_len))) { sql_print_error("create_table_from_dump: out of memory"); my_message(ER_GET_ERRNO, "Out of memory", MYF(0)); DBUG_RETURN(1); } - thd->query= query; + thd->set_query(query, packet_len); thd->is_slave_error = 0; bzero((char*) &tables,sizeof(tables)); @@ -1406,6 +1575,8 @@ bool show_master_info(THD* thd, Master_info* mi) pthread_mutex_lock(&mi->data_lock); pthread_mutex_lock(&mi->rli.data_lock); + pthread_mutex_lock(&mi->err_lock); + pthread_mutex_lock(&mi->rli.err_lock); protocol->store(mi->host, &my_charset_bin); protocol->store(mi->user, &my_charset_bin); protocol->store((uint32) mi->port); @@ -1505,6 +1676,8 @@ bool show_master_info(THD* thd, Master_info* mi) // Last_SQL_Error protocol->store(mi->rli.last_error().message, &my_charset_bin); + pthread_mutex_unlock(&mi->rli.err_lock); + pthread_mutex_unlock(&mi->err_lock); pthread_mutex_unlock(&mi->rli.data_lock); pthread_mutex_unlock(&mi->data_lock); @@ -1777,25 +1950,6 @@ static ulong read_event(MYSQL* mysql, Master_info *mi, bool* suppress_warnings) DBUG_RETURN(len - 1); } - -int check_expected_error(THD* thd, Relay_log_info const *rli, - int expected_error) -{ - DBUG_ENTER("check_expected_error"); - - switch (expected_error) { - case ER_NET_READ_ERROR: - case ER_NET_ERROR_ON_WRITE: - case ER_QUERY_INTERRUPTED: - case ER_SERVER_SHUTDOWN: - case ER_NEW_ABORTING_CONNECTION: - DBUG_RETURN(1); - default: - DBUG_RETURN(0); - } -} - - /* Check if the current error is of temporary nature of not. Some errors are temporary in nature, such as @@ -2286,6 +2440,7 @@ pthread_handler_t handle_slave_io(void *arg) char llbuff[22]; uint retry_count; bool suppress_warnings; + int ret; #ifndef DBUG_OFF uint retry_count_reg= 0, retry_count_dump= 0, retry_count_event= 0; #endif @@ -2311,6 +2466,7 @@ pthread_handler_t handle_slave_io(void *arg) pthread_detach_this_thread(); thd->thread_stack= (char*) &thd; // remember where our stack is + mi->clear_error(); if (init_slave_thread(thd, SLAVE_THD_IO)) { pthread_cond_broadcast(&mi->start_cond); @@ -2365,8 +2521,23 @@ connected: mi->slave_running= MYSQL_SLAVE_RUN_CONNECT; thd->slave_net = &mysql->net; thd_proc_info(thd, "Checking master version"); - if (get_master_version_and_clock(mysql, mi)) + ret= get_master_version_and_clock(mysql, mi); + if (ret == 1) + /* Fatal error */ goto err; + + if (ret == 2) + { + if (check_io_slave_killed(mi->io_thd, mi, "Slave I/O thread killed" + "while calling get_master_version_and_clock(...)")) + goto err; + suppress_warnings= FALSE; + /* Try to reconnect because the error was caused by a transient network problem */ + if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings, + reconnect_messages[SLAVE_RECON_ACT_REG])) + goto err; + goto connected; + } if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1) { @@ -2425,6 +2596,7 @@ requesting master dump") || goto connected; }); + DBUG_ASSERT(mi->last_error().number == 0); while (!io_slave_killed(thd,mi)) { ulong event_len; @@ -2532,10 +2704,8 @@ err: // print the current replication position sql_print_information("Slave I/O thread exiting, read up to log '%s', position %s", IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff)); - VOID(pthread_mutex_lock(&LOCK_thread_count)); - thd->query = thd->db = 0; // extra safety - thd->query_length= thd->db_length= 0; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + thd->set_query(NULL, 0); + thd->reset_db(NULL, 0); if (mysql) { /* @@ -2577,6 +2747,7 @@ err: delete the mi structure leading to a crash! (see BUG#25306 for details) */ pthread_cond_broadcast(&mi->stop_cond); // tell the world we are done + DBUG_EXECUTE_IF("simulate_slave_delay_at_terminate_bug38694", sleep(5);); pthread_mutex_unlock(&mi->run_lock); my_thread_end(); pthread_exit(0); @@ -2588,14 +2759,21 @@ err: LOAD DATA INFILE. */ static -int check_temp_dir(char* tmp_dir, char *tmp_file) +int check_temp_dir(char* tmp_file) { int fd; MY_DIR *dirp; + char tmp_dir[FN_REFLEN]; + size_t tmp_dir_size; DBUG_ENTER("check_temp_dir"); /* + Get the directory from the temporary file. + */ + dirname_part(tmp_dir, tmp_file, &tmp_dir_size); + + /* Check if the directory exists. */ if (!(dirp=my_dir(tmp_dir,MYF(MY_WME)))) @@ -2664,11 +2842,13 @@ pthread_handler_t handle_slave_sql(void *arg) */ pthread_cond_broadcast(&rli->start_cond); pthread_mutex_unlock(&rli->run_lock); - sql_print_error("Failed during slave thread initialization"); + rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + "Failed during slave thread initialization"); goto err; } thd->init_for_queries(); thd->temporary_tables = rli->save_temporary_tables; // restore temp tables + set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp tables pthread_mutex_lock(&LOCK_thread_count); threads.append(thd); pthread_mutex_unlock(&LOCK_thread_count); @@ -2708,9 +2888,9 @@ pthread_handler_t handle_slave_sql(void *arg) rli->group_relay_log_pos, 1 /*need data lock*/, &errmsg, 1 /*look for a description_event*/)) - { - sql_print_error("Error initializing relay log position: %s", - errmsg); + { + rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + "Error initializing relay log position: %s", errmsg); goto err; } THD_CHECK_SENTRY(thd); @@ -2749,7 +2929,7 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name, llstr(rli->group_relay_log_pos,llbuff1)); - if (check_temp_dir(slave_load_tmpdir, rli->slave_patternload_file)) + if (check_temp_dir(rli->slave_patternload_file)) { rli->report(ERROR_LEVEL, thd->main_da.sql_errno(), "Unable to use slave's temporary directory %s - %s", @@ -2763,8 +2943,8 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, execute_init_command(thd, &sys_init_slave, &LOCK_sys_init_slave); if (thd->is_slave_error) { - sql_print_error("\ -Slave SQL thread aborted. Can't execute init_slave query"); + rli->report(ERROR_LEVEL, thd->main_da.sql_errno(), + "Slave SQL thread aborted. Can't execute init_slave query"); goto err; } } @@ -2814,10 +2994,20 @@ Slave SQL thread aborted. Can't execute init_slave query"); thd->main_da.sql_errno(), last_errno)); if (last_errno == 0) { + /* + This function is reporting an error which was not reported + while executing exec_relay_log_event(). + */ rli->report(ERROR_LEVEL, thd->main_da.sql_errno(), errmsg); } else if (last_errno != thd->main_da.sql_errno()) { + /* + * An error was reported while executing exec_relay_log_event() + * however the error code differs from what is in the thread. + * This function prints out more information to help finding + * what caused the problem. + */ sql_print_error("Slave (additional info): %s Error_code: %d", errmsg, thd->main_da.sql_errno()); } @@ -2867,15 +3057,14 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ must "proactively" clear playgrounds: */ rli->cleanup_context(thd, 1); - VOID(pthread_mutex_lock(&LOCK_thread_count)); /* Some extra safety, which should not been needed (normally, event deletion should already have done these assignments (each event which sets these variables is supposed to set them to 0 before terminating)). */ - thd->query= thd->db= thd->catalog= 0; - thd->query_length= thd->db_length= 0; - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + thd->catalog= 0; + thd->set_query(NULL, 0); + thd->reset_db(NULL, 0); thd_proc_info(thd, "Waiting for slave mutex on exit"); pthread_mutex_lock(&rli->run_lock); /* We need data_lock, at least to wake up any waiting master_pos_wait() */ @@ -2905,6 +3094,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ DBUG_ASSERT(rli->sql_thd == thd); THD_CHECK_SENTRY(thd); rli->sql_thd= 0; + set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp tables pthread_mutex_lock(&LOCK_thread_count); THD_CHECK_SENTRY(thd); delete thd; @@ -2915,6 +3105,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ delete the mi structure leading to a crash! (see BUG#25306 for details) */ pthread_cond_broadcast(&rli->stop_cond); + DBUG_EXECUTE_IF("simulate_slave_delay_at_terminate_bug38694", sleep(5);); pthread_mutex_unlock(&rli->run_lock); // tell the world we are done my_thread_end(); @@ -3602,6 +3793,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, if (!slave_was_killed) { + mi->clear_error(); // clear possible left over reconnect error if (reconnect) { if (!suppress_warnings && global_system_variables.log_warnings) diff --git a/sql/slave.h b/sql/slave.h index abd63315e62..fe9694c2392 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -101,7 +101,8 @@ extern MY_BITMAP slave_error_mask; extern char slave_skip_error_names[]; extern bool use_slave_mask; extern char *slave_load_tmpdir; -extern char *master_info_file, *relay_log_info_file; +extern char *master_info_file; +extern MYSQL_PLUGIN_IMPORT char *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; @@ -171,10 +172,10 @@ bool rpl_master_has_bug(const Relay_log_info *rli, uint bug_id, bool report, bool 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(); /* clean up */ +void end_slave(); /* release slave threads */ +void close_active_mi(); /* clean up slave threads data */ 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); @@ -205,7 +206,7 @@ extern int disconnect_slave_event_count, abort_slave_event_count ; /* the master variables are defaults read from my.cnf or command line */ 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 *master_info_file, *report_user; extern char *report_host, *report_password; extern my_bool master_ssl; diff --git a/sql/sp.cc b/sql/sp.cc index b2c7c389136..4d840f53e2f 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -70,9 +70,6 @@ enum MYSQL_PROC_FIELD_COUNT }; -/* Tells what SP_DEFAULT_ACCESS should be mapped to */ -#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL - /*************************************************************************/ /** @@ -940,7 +937,8 @@ sp_create_routine(THD *thd, int type, sp_head *sp) thd->variables.sql_mode= saved_mode; /* Such a statement can always go directly to binlog, no trans cache */ thd->binlog_query(THD::MYSQL_QUERY_TYPE, - log_query.c_ptr(), log_query.length(), FALSE, FALSE); + log_query.c_ptr(), log_query.length(), + FALSE, FALSE, 0); thd->variables.sql_mode= 0; } @@ -1307,13 +1305,20 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, /** This is used by sql_acl.cc:mysql_routine_grant() and is used to find the routines in 'routines'. + + @param thd Thread handler + @param routines List of needles in the hay stack + @param any Any of the needles are good enough + + @return + @retval FALSE Found. + @retval TRUE Not found */ -int -sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error) +bool +sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any) { TABLE_LIST *routine; - bool result= 0; bool sp_object_found; DBUG_ENTER("sp_exists_routine"); for (routine= routines; routine; routine= routine->next_global) @@ -1335,21 +1340,16 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error) if (sp_object_found) { if (any) - DBUG_RETURN(1); - result= 1; + break; } else if (!any) { - if (!no_error) - { - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", - routine->table_name); - DBUG_RETURN(-1); - } - DBUG_RETURN(0); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", + routine->table_name); + DBUG_RETURN(TRUE); } } - DBUG_RETURN(result); + DBUG_RETURN(FALSE); } @@ -17,6 +17,9 @@ #ifndef _SP_H_ #define _SP_H_ +/* Tells what SP_DEFAULT_ACCESS should be mapped to */ +#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL + // Return codes from sp_create_*, sp_drop_*, and sp_show_*: #define SP_OK 0 #define SP_KEY_NOT_FOUND -1 @@ -39,8 +42,8 @@ sp_head * sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, bool cache_only); -int -sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any, bool no_error); +bool +sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any); int sp_routine_exists_in_table(THD *thd, int type, sp_name *name); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 7fef7b30759..e7310787a35 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -207,6 +207,7 @@ sp_get_flags_for_command(LEX *lex) case SQLCOM_SHOW_STATUS_PROC: case SQLCOM_SHOW_STORAGE_ENGINES: case SQLCOM_SHOW_TABLES: + case SQLCOM_SHOW_TABLE_STATUS: case SQLCOM_SHOW_VARIABLES: case SQLCOM_SHOW_WARNS: case SQLCOM_REPAIR: @@ -1011,8 +1012,7 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) else DBUG_RETURN(TRUE); - thd->query= pbuf; - thd->query_length= qbuf.length(); + thd->set_query(pbuf, qbuf.length()); DBUG_RETURN(FALSE); } @@ -1248,7 +1248,7 @@ sp_head::execute(THD *thd) */ if (thd->prelocked_mode == NON_PRELOCKED) thd->user_var_events_alloc= thd->mem_root; - + err_status= i->execute(thd, &ip); if (i->free_list) @@ -1778,8 +1778,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, thd->options= binlog_save_options; if (thd->binlog_evt_union.unioned_events) { + int errcode = query_error_code(thd, thd->killed == THD::NOT_KILLED); Query_log_event qinfo(thd, binlog_buf.ptr(), binlog_buf.length(), - thd->binlog_evt_union.unioned_events_trans, FALSE); + thd->binlog_evt_union.unioned_events_trans, FALSE, errcode); if (mysql_bin_log.write(&qinfo) && thd->binlog_evt_union.unioned_events_trans) { @@ -2131,17 +2132,16 @@ sp_head::restore_lex(THD *thd) /** Put the instruction on the backpatch list, associated with the label. */ -void +int sp_head::push_backpatch(sp_instr *i, sp_label_t *lab) { bp_t *bp= (bp_t *)sql_alloc(sizeof(bp_t)); - if (bp) - { - bp->lab= lab; - bp->instr= i; - (void)m_backpatch.push_front(bp); - } + if (!bp) + return 1; + bp->lab= lab; + bp->instr= i; + return m_backpatch.push_front(bp); } /** @@ -2216,7 +2216,7 @@ sp_head::fill_field_definition(THD *thd, LEX *lex, } -void +int sp_head::new_cont_backpatch(sp_instr_opt_meta *i) { m_cont_level+= 1; @@ -2224,15 +2224,17 @@ sp_head::new_cont_backpatch(sp_instr_opt_meta *i) { /* Use the cont. destination slot to store the level */ i->m_cont_dest= m_cont_level; - (void)m_cont_backpatch.push_front(i); + if (m_cont_backpatch.push_front(i)) + return 1; } + return 0; } -void +int sp_head::add_cont_backpatch(sp_instr_opt_meta *i) { i->m_cont_dest= m_cont_level; - (void)m_cont_backpatch.push_front(i); + return m_cont_backpatch.push_front(i); } void @@ -2467,7 +2469,7 @@ sp_head::show_create_routine(THD *thd, int type) @param instr Instruction */ -void sp_head::add_instr(sp_instr *instr) +int sp_head::add_instr(sp_instr *instr) { instr->free_list= m_thd->free_list; m_thd->free_list= 0; @@ -2478,7 +2480,7 @@ void sp_head::add_instr(sp_instr *instr) entire stored procedure, as their life span is equal. */ instr->mem_root= &main_mem_root; - insert_dynamic(&m_instr, (uchar*)&instr); + return insert_dynamic(&m_instr, (uchar*)&instr); } @@ -2853,14 +2855,13 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) } else *nextp= m_ip+1; - thd->query= query; - thd->query_length= query_length; + thd->set_query(query, query_length); thd->query_name_consts= 0; if (!thd->is_error()) thd->main_da.reset_diagnostics_area(); } - DBUG_RETURN(res); + DBUG_RETURN(res || thd->is_error()); } diff --git a/sql/sp_head.h b/sql/sp_head.h index c17b67f962a..dd11f8693ac 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -308,7 +308,7 @@ public: bool show_create_routine(THD *thd, int type); - void + int add_instr(sp_instr *instr); inline uint @@ -344,7 +344,7 @@ public: restore_lex(THD *thd); /// Put the instruction on the backpatch list, associated with the label. - void + int push_backpatch(sp_instr *, struct sp_label *); /// Update all instruction with this label in the backpatch list to @@ -353,11 +353,11 @@ public: backpatch(struct sp_label *); /// Start a new cont. backpatch level. If 'i' is NULL, the level is just incr. - void + int new_cont_backpatch(sp_instr_opt_meta *i); /// Add an instruction to the current level - void + int add_cont_backpatch(sp_instr_opt_meta *i); /// Backpatch (and pop) the current level to the current position. diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc index 414ea12cd7a..302faf3f681 100644 --- a/sql/sp_pcontext.cc +++ b/sql/sp_pcontext.cc @@ -265,8 +265,8 @@ sp_pcontext::push_variable(LEX_STRING *name, enum enum_field_types type, p->mode= mode; p->offset= current_var_count(); p->dflt= NULL; - insert_dynamic(&m_vars, (uchar*)&p); - + if (insert_dynamic(&m_vars, (uchar*)&p)) + return NULL; return p; } @@ -310,18 +310,17 @@ sp_pcontext::find_label(char *name) return NULL; } -void +int sp_pcontext::push_cond(LEX_STRING *name, sp_cond_type_t *val) { sp_cond_t *p= (sp_cond_t *)sql_alloc(sizeof(sp_cond_t)); - if (p) - { - p->name.str= name->str; - p->name.length= name->length; - p->val= val; - insert_dynamic(&m_conds, (uchar*)&p); - } + if (p == NULL) + return 1; + p->name.str= name->str; + p->name.length= name->length; + p->val= val; + return insert_dynamic(&m_conds, (uchar *)&p); } /* @@ -384,7 +383,7 @@ sp_pcontext::find_handler(sp_cond_type_t *cond) return FALSE; } -void +int sp_pcontext::push_cursor(LEX_STRING *name) { LEX_STRING n; @@ -393,7 +392,7 @@ sp_pcontext::push_cursor(LEX_STRING *name) m_max_cursor_index+= 1; n.str= name->str; n.length= name->length; - insert_dynamic(&m_cursors, (uchar*)&n); + return insert_dynamic(&m_cursors, (uchar *)&n); } /* diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h index aefc501b3b0..3145ba2fea4 100644 --- a/sql/sp_pcontext.h +++ b/sql/sp_pcontext.h @@ -323,7 +323,7 @@ public: // Conditions // - void + int push_cond(LEX_STRING *name, sp_cond_type_t *val); inline void @@ -365,7 +365,7 @@ public: // Cursors // - void + int push_cursor(LEX_STRING *name); my_bool diff --git a/sql/spatial.h b/sql/spatial.h index dbf5da6665b..86c2ed8c197 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -116,12 +116,12 @@ struct MBR int touches(const MBR *mbr) { /* The following should be safe, even if we compare doubles */ - return ((((mbr->xmin == xmax) || (mbr->xmax == xmin)) && - (((mbr->ymin >= ymin) && (mbr->ymin <= ymax)) || - ((mbr->ymax >= ymin) && (mbr->ymax <= ymax)))) || - (((mbr->ymin == ymax) || (mbr->ymax == ymin)) && - (((mbr->xmin >= xmin) && (mbr->xmin <= xmax)) || - ((mbr->xmax >= xmin) && (mbr->xmax <= xmax))))); + return ((mbr->xmin == xmax || mbr->xmax == xmin) && + ((mbr->ymin >= ymin && mbr->ymin <= ymax) || + (mbr->ymax >= ymin && mbr->ymax <= ymax))) || + ((mbr->ymin == ymax || mbr->ymax == ymin) && + ((mbr->xmin >= xmin && mbr->xmin <= xmax) || + (mbr->xmax >= xmin && mbr->xmax <= xmax))); } int within(const MBR *mbr) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index d8d43fbd878..07b00d186b5 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -936,6 +936,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, #ifdef HAVE_OPENSSL Vio *vio=thd->net.vio; SSL *ssl= (SSL*) vio->ssl_arg; + X509 *cert; #endif /* @@ -964,8 +965,11 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, */ if (vio_type(vio) == VIO_TYPE_SSL && SSL_get_verify_result(ssl) == X509_V_OK && - SSL_get_peer_certificate(ssl)) + (cert= SSL_get_peer_certificate(ssl))) + { user_access= acl_user->access; + X509_free(cert); + } break; case SSL_TYPE_SPECIFIED: /* Client should have specified attrib */ /* @@ -974,7 +978,6 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, If cipher name is specified, we compare it to actual cipher in use. */ - X509 *cert; if (vio_type(vio) != VIO_TYPE_SSL || SSL_get_verify_result(ssl) != X509_V_OK) break; @@ -1014,6 +1017,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, sql_print_information("X509 issuer mismatch: should be '%s' " "but is '%s'", acl_user->x509_issuer, ptr); free(ptr); + X509_free(cert); user_access=NO_ACCESS; break; } @@ -1033,12 +1037,15 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, sql_print_information("X509 subject mismatch: should be '%s' but is '%s'", acl_user->x509_subject, ptr); free(ptr); + X509_free(cert); user_access=NO_ACCESS; break; } user_access= acl_user->access; free(ptr); } + /* Deallocate the X509 certificate. */ + X509_free(cert); break; #else /* HAVE_OPENSSL */ default: @@ -1269,14 +1276,16 @@ static void acl_update_db(const char *user, const char *host, const char *db, { ACL_DB *acl_db=dynamic_element(&acl_dbs,i,ACL_DB*); if ((!acl_db->user && !user[0]) || - (acl_db->user && !strcmp(user,acl_db->user))) + (acl_db->user && + !strcmp(user,acl_db->user))) { if ((!acl_db->host.hostname && !host[0]) || (acl_db->host.hostname && - !strcmp(host, acl_db->host.hostname))) + !strcmp(host, acl_db->host.hostname))) { if ((!acl_db->db && !db[0]) || (acl_db->db && !strcmp(db,acl_db->db))) + { if (privileges) acl_db->access=privileges; @@ -1646,7 +1655,8 @@ bool change_password(THD *thd, const char *host, const char *user, acl_user->host.hostname ? acl_user->host.hostname : "", new_password)); thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, buff, query_length, FALSE, FALSE); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, buff, query_length, + FALSE, FALSE, 0); } end: close_thread_tables(thd); @@ -2986,8 +2996,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { if (!(rights & CREATE_ACL)) { - char buf[FN_REFLEN]; - build_table_filename(buf, sizeof(buf), table_list->db, + char buf[FN_REFLEN + 1]; + build_table_filename(buf, sizeof(buf) - 1, table_list->db, table_list->table_name, reg_ext, 0); fn_format(buf, buf, "", "", MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS | MY_RETURN_REAL_PATH | MY_APPEND_EXT); @@ -3189,26 +3199,24 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, } -/* +/** Store routine level grants in the privilege tables - SYNOPSIS - mysql_routine_grant() - thd Thread handle - table_list List of routines to give grant - is_proc true indicates routine list are procedures - user_list List of users to give grant - rights Table level grant - revoke_grant Set to 1 if this is a REVOKE command + @param thd Thread handle + @param table_list List of routines to give grant + @param is_proc Is this a list of procedures? + @param user_list List of users to give grant + @param rights Table level grant + @param revoke_grant Is this is a REVOKE command? - RETURN - 0 ok - 1 error + @return + @retval FALSE Success. + @retval TRUE An error occurred. */ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, List <LEX_USER> &user_list, ulong rights, - bool revoke_grant, bool no_error) + bool revoke_grant, bool write_to_binlog) { List_iterator <LEX_USER> str_list (user_list); LEX_USER *Str, *tmp_Str; @@ -3219,22 +3227,20 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, if (!initialized) { - if (!no_error) - my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), - "--skip-grant-tables"); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), + "--skip-grant-tables"); DBUG_RETURN(TRUE); } if (rights & ~PROC_ACLS) { - if (!no_error) - my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), - MYF(0)); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + MYF(0)); DBUG_RETURN(TRUE); } if (!revoke_grant) { - if (sp_exist_routines(thd, table_list, is_proc, no_error)<0) + if (sp_exist_routines(thd, table_list, is_proc)) DBUG_RETURN(TRUE); } @@ -3315,9 +3321,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, { if (revoke_grant) { - if (!no_error) - my_error(ER_NONEXISTING_PROC_GRANT, MYF(0), - Str->user.str, Str->host.str, table_name); + my_error(ER_NONEXISTING_PROC_GRANT, MYF(0), + Str->user.str, Str->host.str, table_name); result= TRUE; continue; } @@ -3342,16 +3347,14 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, } thd->mem_root= old_root; pthread_mutex_unlock(&acl_cache->lock); - if (!result && !no_error) + + if (write_to_binlog) { write_bin_log(thd, TRUE, thd->query, thd->query_length); } rw_unlock(&LOCK_grant); - if (!result && !no_error) - my_ok(thd); - /* Tables are automatically closed */ DBUG_RETURN(result); } @@ -5317,16 +5320,13 @@ static int handle_grant_struct(uint struct_no, bool drop, uint elements; const char *user; const char *host; - ACL_USER *acl_user; - ACL_DB *acl_db; - GRANT_NAME *grant_name; + ACL_USER *acl_user= NULL; + ACL_DB *acl_db= NULL; + GRANT_NAME *grant_name= NULL; DBUG_ENTER("handle_grant_struct"); DBUG_PRINT("info",("scan struct: %u search: '%s'@'%s'", struct_no, user_from->user.str, user_from->host.str)); - LINT_INIT(acl_user); - LINT_INIT(acl_db); - LINT_INIT(grant_name); LINT_INIT(user); LINT_INIT(host); @@ -5692,6 +5692,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) List_iterator <LEX_USER> user_list(list); TABLE_LIST tables[GRANT_TABLES]; bool some_users_deleted= FALSE; + ulong old_sql_mode= thd->variables.sql_mode; DBUG_ENTER("mysql_drop_user"); /* @@ -5705,6 +5706,8 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) if ((result= open_grant_tables(thd, tables))) DBUG_RETURN(result != 1); + thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH; + rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -5737,6 +5740,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) rw_unlock(&LOCK_grant); close_thread_tables(thd); + thd->variables.sql_mode= old_sql_mode; DBUG_RETURN(result); } @@ -6146,21 +6150,20 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, } -/* +/** Grant EXECUTE,ALTER privilege for a stored procedure - SYNOPSIS - sp_grant_privileges() - thd The current thread. - db DB of the stored procedure - name Name of the stored procedure + @param thd The current thread. + @param sp_db + @param sp_name + @param is_proc - RETURN - 0 OK. - < 0 Error. Error message not yet sent. + @return + @retval FALSE Success + @retval TRUE An error occured. Error message not yet sent. */ -int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, +bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool is_proc) { Security_context *sctx= thd->security_ctx; @@ -6170,6 +6173,7 @@ int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool result; ACL_USER *au; char passwd_buff[SCRAMBLED_PASSWORD_CHAR_LENGTH+1]; + Dummy_error_handler error_handler; DBUG_ENTER("sp_grant_privileges"); if (!(combo=(LEX_USER*) thd->alloc(sizeof(st_lex_user)))) @@ -6220,8 +6224,11 @@ int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, } else { - my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH); - return -1; + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_PASSWD_LENGTH, + ER(ER_PASSWD_LENGTH), + SCRAMBLED_PASSWORD_CHAR_LENGTH); + return TRUE; } combo->password.str= passwd_buff; } @@ -6235,10 +6242,17 @@ int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, DBUG_RETURN(TRUE); thd->lex->ssl_type= SSL_TYPE_NOT_SPECIFIED; + thd->lex->ssl_cipher= thd->lex->x509_subject= thd->lex->x509_issuer= 0; bzero((char*) &thd->lex->mqh, sizeof(thd->lex->mqh)); + /* + Only care about whether the operation failed or succeeded + as all errors will be handled later. + */ + thd->push_internal_handler(&error_handler); result= mysql_routine_grant(thd, tables, is_proc, user_list, - DEFAULT_CREATE_PROC_ACLS, 0, 1); + DEFAULT_CREATE_PROC_ACLS, FALSE, FALSE); + thd->pop_internal_handler(); DBUG_RETURN(result); } diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 9ae17a4bf02..a8090fba2e7 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -233,7 +233,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table, List <LEX_USER> &user_list, bool revoke); bool mysql_routine_grant(THD *thd, TABLE_LIST *table, bool is_proc, List <LEX_USER> &user_list, ulong rights, - bool revoke, bool no_error); + bool revoke, bool write_to_binlog); my_bool grant_init(); void grant_free(void); my_bool grant_reload(THD *thd); @@ -264,7 +264,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, const char *db, const char *table); bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, bool is_proc); -int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, +bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool is_proc); bool check_routine_level_acl(THD *thd, const char *db, const char *name, bool is_proc); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index ac4be080123..d94a35259f4 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -478,8 +478,9 @@ static TABLE_SHARE DBUG_RETURN(share); /* Table didn't exist. Check if some engine can provide it */ - if ((tmp= ha_create_table_from_engine(thd, table_list->db, - table_list->table_name)) < 0) + tmp= ha_create_table_from_engine(thd, table_list->db, + table_list->table_name); + if (tmp < 0) { /* No such table in any engine. @@ -1431,11 +1432,10 @@ static inline uint tmpkeyval(THD *thd, TABLE *table) void close_temporary_tables(THD *thd) { TABLE *table; - TABLE *next; + TABLE *next= NULL; TABLE *prev_table; /* Assume thd->options has OPTION_QUOTE_SHOW_CREATE */ bool was_quote_show= TRUE; - LINT_INIT(next); if (!thd->temporary_tables) return; @@ -1541,19 +1541,8 @@ void close_temporary_tables(THD *thd) thd->variables.character_set_client= system_charset_info; Query_log_event qinfo(thd, s_query.ptr(), s_query.length() - 1 /* to remove trailing ',' */, - 0, FALSE); + 0, FALSE, 0); thd->variables.character_set_client= cs_save; - /* - Imagine the thread had created a temp table, then was doing a - SELECT, and the SELECT was killed. Then it's not clever to - mark the statement above as "killed", because it's not really - a statement updating data, and there are 99.99% chances it - will succeed on slave. If a real update (one updating a - persistent table) was killed on the master, then this real - update will be logged with error_code=killed, rightfully - causing the slave to stop. - */ - qinfo.error_code= 0; mysql_bin_log.write(&qinfo); thd->variables.pseudo_thread_id= save_pseudo_thread_id; } @@ -2446,7 +2435,7 @@ bool lock_table_name_if_not_cached(THD *thd, const char *db, bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists) { - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; int rc; DBUG_ENTER("check_if_table_exists"); @@ -2603,27 +2592,11 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, { // Using table locks TABLE *best_table= 0; int best_distance= INT_MIN; - bool check_if_used= thd->prelocked_mode && - ((int) table_list->lock_type >= - (int) TL_WRITE_ALLOW_WRITE); for (table=thd->open_tables; table ; table=table->next) { if (table->s->table_cache_key.length == key_length && !memcmp(table->s->table_cache_key.str, key, key_length)) { - if (check_if_used && table->query_id && - table->query_id != thd->query_id) - { - /* - If we are in stored function or trigger we should ensure that - we won't change table that is already used by calling statement. - So if we are opening table for writing, we should check that it - is not already open by some calling stamement. - */ - my_error(ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG, MYF(0), - table->s->table_name.str); - DBUG_RETURN(0); - } /* When looking for a usable TABLE, ignore MERGE children, as they belong to their parent and cannot be used explicitly. @@ -2652,13 +2625,13 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, { best_distance= distance; best_table= table; - if (best_distance == 0 && !check_if_used) + if (best_distance == 0) { /* - If we have found perfect match and we don't need to check that - table is not used by one of calling statements (assuming that - we are inside of function or trigger) we can finish iterating - through open tables list. + We have found a perfect match and can finish iterating + through open tables list. Check for table use conflict + between calling statement and SP/trigger is done in + lock_tables(). */ break; } @@ -2679,7 +2652,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, real fix will be made after definition cache will be made) */ { - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; enum legacy_db_type not_used; build_table_filename(path, sizeof(path) - 1, table_list->db, table_list->table_name, reg_ext, 0); @@ -2993,6 +2966,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, table->insert_values= 0; table->fulltext_searched= 0; table->file->ft_handler= 0; + table->reginfo.impossible_range= 0; /* Catch wrong handling of the auto_increment_field_not_null. */ DBUG_ASSERT(!table->auto_increment_field_not_null); table->auto_increment_field_not_null= FALSE; @@ -3889,6 +3863,16 @@ retry: if (share->is_view) { /* + If parent_l of the table_list is non null then a merge table + has this view as child table, which is not supported. + */ + if (table_list->parent_l) + { + my_error(ER_WRONG_MRG_TABLE, MYF(0)); + goto err; + } + + /* This table is a view. Validate its metadata version: in particular, that it was a view when the statement was prepared. */ @@ -4050,8 +4034,10 @@ retry: /* this DELETE FROM is needed even with row-based binlogging */ end = strxmov(strmov(query, "DELETE FROM `"), share->db.str,"`.`",share->table_name.str,"`", NullS); + int errcode= query_error_code(thd, TRUE); thd->binlog_query(THD::STMT_QUERY_TYPE, - query, (ulong)(end-query), FALSE, FALSE); + query, (ulong)(end-query), + FALSE, FALSE, errcode); my_free(query, MYF(0)); } else @@ -4906,9 +4892,9 @@ TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l, lock_flags Flags passed to mysql_lock_table NOTE - This function don't do anything like SP/SF/views/triggers analysis done - in open_tables(). It is intended for opening of only one concrete table. - And used only in special contexts. + This function doesn't do anything like SP/SF/views/triggers analysis done + in open_table()/lock_tables(). It is intended for opening of only one + concrete table. And used only in special contexts. RETURN VALUES table Opened table @@ -4926,6 +4912,9 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type, bool refresh; DBUG_ENTER("open_ltable"); + /* should not be used in a prelocked_mode context, see NOTE above */ + DBUG_ASSERT(!thd->prelocked_mode); + thd_proc_info(thd, "Opening table"); thd->current_tablenr= 0; /* open_ltable can be used only for BASIC TABLEs */ @@ -5392,8 +5381,29 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen) table && table != first_not_own; table= table->next_global) { - if (!table->placeholder() && - check_lock_and_start_stmt(thd, table->table, table->lock_type)) + if (table->placeholder()) + continue; + + /* + In a stored function or trigger we should ensure that we won't change + a table that is already used by the calling statement. + */ + if (thd->prelocked_mode && + table->lock_type >= TL_WRITE_ALLOW_WRITE) + { + for (TABLE* opentab= thd->open_tables; opentab; opentab= opentab->next) + { + if (table->table->s == opentab->s && opentab->query_id && + table->table->query_id != opentab->query_id) + { + my_error(ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG, MYF(0), + table->table->s->table_name.str); + DBUG_RETURN(-1); + } + } + } + + if (check_lock_and_start_stmt(thd, table->table, table->lock_type)) { DBUG_RETURN(-1); } @@ -5589,6 +5599,13 @@ static void update_field_dependencies(THD *thd, Field *field, TABLE *table) else current_bitmap= table->write_set; + /* + The test-and-set mechanism in the bitmap is not reliable during + multi-UPDATE statements under MARK_COLUMNS_READ mode + (thd->mark_used_columns == MARK_COLUMNS_READ), as this bitmap contains + only those columns that are used in the SET clause. I.e they are being + set here. See multi_update::prepare() + */ if (bitmap_fast_test_and_set(current_bitmap, field->field_index)) { if (thd->mark_used_columns == MARK_COLUMNS_WRITE) @@ -6336,7 +6353,7 @@ find_field_in_tables(THD *thd, Item_ident *item, (report_error == REPORT_ALL_ERRORS || report_error == REPORT_EXCEPT_NON_UNIQUE)) { - char buff[NAME_LEN*2+1]; + char buff[NAME_LEN*2 + 2]; if (db && db[0]) { strxnmov(buff,sizeof(buff)-1,db,".",table_name,NullS); @@ -6409,8 +6426,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, (and not an item that happens to have a name). */ bool is_ref_by_name= 0; - uint unaliased_counter; - LINT_INIT(unaliased_counter); // Dependent on found_unaliased + uint unaliased_counter= 0; *resolution= NOT_RESOLVED; @@ -7374,6 +7390,12 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, #ifdef HAVE_valgrind if (&select_lex->item_list != &fields) // Avoid warning #endif + /* + The assignment below is translated to memcpy() call (at least on some + platforms). memcpy() expects that source and destination areas do not + overlap. That problem was detected by valgrind. + */ + if (&select_lex->item_list != &fields) select_lex->item_list= fields; thd->restore_active_arena(arena, &backup); diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index c03f10c6583..a97dcab0b55 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -352,11 +352,6 @@ TODO list: #define RW_UNLOCK(M) {DBUG_PRINT("lock", ("rwlock unlock 0x%lx",(ulong)(M))); \ if (!rw_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \ else DBUG_PRINT("lock", ("rwlock unlock FAILED %d", errno)); } -#define STRUCT_LOCK(M) {DBUG_PRINT("lock", ("%d struct lock...",__LINE__)); \ - pthread_mutex_lock(M);DBUG_PRINT("lock", ("struct lock OK"));} -#define STRUCT_UNLOCK(M) { \ - DBUG_PRINT("lock", ("%d struct unlock...",__LINE__)); \ - pthread_mutex_unlock(M);DBUG_PRINT("lock", ("struct unlock OK"));} #define BLOCK_LOCK_WR(B) {DBUG_PRINT("lock", ("%d LOCK_WR 0x%lx",\ __LINE__,(ulong)(B))); \ B->query()->lock_writing();} @@ -403,8 +398,6 @@ static void debug_wait_for_kill(const char *info) #define RW_WLOCK(M) rw_wrlock(M) #define RW_RLOCK(M) rw_rdlock(M) #define RW_UNLOCK(M) rw_unlock(M) -#define STRUCT_LOCK(M) pthread_mutex_lock(M) -#define STRUCT_UNLOCK(M) pthread_mutex_unlock(M) #define BLOCK_LOCK_WR(B) B->query()->lock_writing() #define BLOCK_LOCK_RD(B) B->query()->lock_reading() #define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing() @@ -420,6 +413,140 @@ TYPELIB query_cache_type_typelib= /** + Serialize access to the query cache. + If the lock cannot be granted the thread hangs in a conditional wait which + is signalled on each unlock. + + The lock attempt will also fail without wait if lock_and_suspend() is in + effect by another thread. This enables a quick path in execution to skip waits + when the outcome is known. + + @return + @retval FALSE An exclusive lock was taken + @retval TRUE The locking attempt failed +*/ + +bool Query_cache::try_lock(void) +{ + bool interrupt= FALSE; + DBUG_ENTER("Query_cache::try_lock"); + + pthread_mutex_lock(&structure_guard_mutex); + while (1) + { + if (m_cache_lock_status == Query_cache::UNLOCKED) + { + m_cache_lock_status= Query_cache::LOCKED; +#ifndef DBUG_OFF + THD *thd= current_thd; + if (thd) + m_cache_lock_thread_id= thd->thread_id; +#endif + break; + } + else if (m_cache_lock_status == Query_cache::LOCKED_NO_WAIT) + { + /* + If query cache is protected by a LOCKED_NO_WAIT lock this thread + should avoid using the query cache as it is being evicted. + */ + interrupt= TRUE; + break; + } + else + { + DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED); + pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); + } + } + pthread_mutex_unlock(&structure_guard_mutex); + + DBUG_RETURN(interrupt); +} + + +/** + Serialize access to the query cache. + If the lock cannot be granted the thread hangs in a conditional wait which + is signalled on each unlock. + + This method also suspends the query cache so that other threads attempting to + lock the cache with try_lock() will fail directly without waiting. + + It is used by all methods which flushes or destroys the whole cache. + */ + +void Query_cache::lock_and_suspend(void) +{ + DBUG_ENTER("Query_cache::lock_and_suspend"); + + pthread_mutex_lock(&structure_guard_mutex); + while (m_cache_lock_status != Query_cache::UNLOCKED) + pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); + m_cache_lock_status= Query_cache::LOCKED_NO_WAIT; +#ifndef DBUG_OFF + THD *thd= current_thd; + if (thd) + m_cache_lock_thread_id= thd->thread_id; +#endif + /* Wake up everybody, a whole cache flush is starting! */ + pthread_cond_broadcast(&COND_cache_status_changed); + pthread_mutex_unlock(&structure_guard_mutex); + + DBUG_VOID_RETURN; +} + +/** + Serialize access to the query cache. + If the lock cannot be granted the thread hangs in a conditional wait which + is signalled on each unlock. + + It is used by all methods which invalidates one or more tables. + */ + +void Query_cache::lock(void) +{ + DBUG_ENTER("Query_cache::lock"); + + pthread_mutex_lock(&structure_guard_mutex); + while (m_cache_lock_status != Query_cache::UNLOCKED) + pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); + m_cache_lock_status= Query_cache::LOCKED; +#ifndef DBUG_OFF + THD *thd= current_thd; + if (thd) + m_cache_lock_thread_id= thd->thread_id; +#endif + pthread_mutex_unlock(&structure_guard_mutex); + + DBUG_VOID_RETURN; +} + + +/** + Set the query cache to UNLOCKED and signal waiting threads. +*/ + +void Query_cache::unlock(void) +{ + DBUG_ENTER("Query_cache::unlock"); + pthread_mutex_lock(&structure_guard_mutex); +#ifndef DBUG_OFF + THD *thd= current_thd; + if (thd) + DBUG_ASSERT(m_cache_lock_thread_id == thd->thread_id); +#endif + DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED || + m_cache_lock_status == Query_cache::LOCKED_NO_WAIT); + m_cache_lock_status= Query_cache::UNLOCKED; + DBUG_PRINT("Query_cache",("Sending signal")); + pthread_cond_signal(&COND_cache_status_changed); + pthread_mutex_unlock(&structure_guard_mutex); + DBUG_VOID_RETURN; +} + + +/** Helper function for determine if a SELECT statement has a SQL_NO_CACHE directive. @@ -713,14 +840,8 @@ void query_cache_insert(NET *net, const char *packet, ulong length) DBUG_EXECUTE_IF("wait_in_query_cache_insert", debug_wait_for_kill("wait_in_query_cache_insert"); ); - STRUCT_LOCK(&query_cache.structure_guard_mutex); - bool interrupt; - query_cache.wait_while_table_flush_is_in_progress(&interrupt); - if (interrupt) - { - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + if (query_cache.try_lock()) DBUG_VOID_RETURN; - } Query_cache_block *query_block= (Query_cache_block*)net->query_cache_query; if (!query_block) @@ -729,7 +850,7 @@ void query_cache_insert(NET *net, const char *packet, ulong length) We lost the writer and the currently processed query has been invalidated; there is nothing left to do. */ - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + query_cache.unlock(); DBUG_VOID_RETURN; } @@ -755,7 +876,7 @@ void query_cache_insert(NET *net, const char *packet, ulong length) query_cache.free_query(query_block); query_cache.refused++; // append_result_data no success => we need unlock - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + query_cache.unlock(); DBUG_VOID_RETURN; } @@ -777,14 +898,8 @@ void query_cache_abort(NET *net) if (net->query_cache_query == 0) DBUG_VOID_RETURN; - STRUCT_LOCK(&query_cache.structure_guard_mutex); - bool interrupt; - query_cache.wait_while_table_flush_is_in_progress(&interrupt); - if (interrupt) - { - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + if (query_cache.try_lock()) DBUG_VOID_RETURN; - } /* While we were waiting another thread might have changed the status @@ -803,8 +918,7 @@ void query_cache_abort(NET *net) DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1);); } - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); - + query_cache.unlock(); DBUG_VOID_RETURN; } @@ -832,15 +946,8 @@ void query_cache_end_of_result(THD *thd) emb_count_querycache_size(thd)); #endif - STRUCT_LOCK(&query_cache.structure_guard_mutex); - - bool interrupt; - query_cache.wait_while_table_flush_is_in_progress(&interrupt); - if (interrupt) - { - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + if (query_cache.try_lock()) DBUG_VOID_RETURN; - } query_block= ((Query_cache_block*) thd->net.query_cache_query); if (query_block) @@ -869,10 +976,9 @@ void query_cache_end_of_result(THD *thd) */ DBUG_ASSERT(0); query_cache.free_query(query_block); - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + query_cache.unlock(); DBUG_VOID_RETURN; } - last_result_block= header->result()->prev; allign_size= ALIGN_SIZE(last_result_block->used); len= max(query_cache.min_allocation_unit, allign_size); @@ -885,13 +991,11 @@ void query_cache_end_of_result(THD *thd) /* Drop the writer. */ header->writer(0); thd->net.query_cache_query= 0; - BLOCK_UNLOCK_WR(query_block); DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1);); } - - STRUCT_UNLOCK(&query_cache.structure_guard_mutex); + query_cache.unlock(); DBUG_VOID_RETURN; } @@ -950,11 +1054,7 @@ ulong Query_cache::resize(ulong query_cache_size_arg) query_cache_size_arg)); DBUG_ASSERT(initialized); - STRUCT_LOCK(&structure_guard_mutex); - while (is_flushing()) - pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); - m_cache_status= Query_cache::FLUSH_IN_PROGRESS; - STRUCT_UNLOCK(&structure_guard_mutex); + lock_and_suspend(); /* Wait for all readers and writers to exit. When the list of all queries @@ -986,13 +1086,10 @@ ulong Query_cache::resize(ulong query_cache_size_arg) query_cache_size= query_cache_size_arg; new_query_cache_size= init_cache(); - STRUCT_LOCK(&structure_guard_mutex); - m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS; - pthread_cond_signal(&COND_cache_status_changed); if (new_query_cache_size) DBUG_EXECUTE("check_querycache",check_integrity(1);); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_RETURN(new_query_cache_size); } @@ -1089,15 +1186,16 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", */ ha_release_temporary_latches(thd); - STRUCT_LOCK(&structure_guard_mutex); - if (query_cache_size == 0 || is_flushing()) + /* + A table- or a full flush operation can potentially take a long time to + finish. We choose not to wait for them and skip caching statements + instead. + */ + if (try_lock()) + DBUG_VOID_RETURN; + if (query_cache_size == 0) { - /* - A table- or a full flush operation can potentially take a long time to - finish. We choose not to wait for them and skip caching statements - instead. - */ - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_VOID_RETURN; } DUMP(this); @@ -1105,7 +1203,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", if (ask_handler_allowance(thd, tables_used)) { refused++; - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_VOID_RETURN; } @@ -1153,7 +1251,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", DBUG_PRINT("qcache", ("insertion in query hash")); header->unlock_n_destroy(); free_memory_block(query_block); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); goto end; } if (!register_all_tables(query_block, tables_used, local_tables)) @@ -1163,7 +1261,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", hash_delete(&queries, (uchar *) query_block); header->unlock_n_destroy(); free_memory_block(query_block); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); goto end; } double_linked_list_simple_include(query_block, &queries_blocks); @@ -1173,7 +1271,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", header->writer(net); header->tables_type(tables_type); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); // init_n_lock make query block locked BLOCK_UNLOCK_WR(query_block); @@ -1182,7 +1280,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", { // We have not enough memory to store query => do nothing refused++; - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_PRINT("warning", ("Can't allocate query")); } } @@ -1190,7 +1288,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", { // Another thread is processing the same query => do nothing refused++; - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_PRINT("qcache", ("Another thread process same query")); } } @@ -1285,18 +1383,17 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) } } - STRUCT_LOCK(&structure_guard_mutex); + /* + Try to obtain an exclusive lock on the query cache. If the cache is + disabled or if a full cache flush is in progress, the attempt to + get the lock is aborted. + */ + if (try_lock()) + goto err; if (query_cache_size == 0) goto err_unlock; - if (is_flushing()) - { - /* Return; Query cache is temporarily disabled while we flush. */ - DBUG_PRINT("qcache",("query cache disabled")); - goto err_unlock; - } - /* Check that we haven't forgot to reset the query cache variables; make sure there are no attached query cache writer to this thread. @@ -1433,7 +1530,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", DBUG_PRINT("qcache", ("Temporary table detected: '%s.%s'", table_list.db, table_list.alias)); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); /* We should not store result of this query because it contain temporary tables => assign following variable to make check @@ -1454,7 +1551,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", DBUG_PRINT("qcache", ("probably no SELECT access to %s.%s => return to normal processing", table_list.db, table_list.alias)); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); thd->lex->safe_to_cache_query=0; // Don't try to cache this BLOCK_UNLOCK_RD(query_block); DBUG_RETURN(-1); // Privilege error @@ -1497,7 +1594,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", } move_to_query_list_end(query_block); hits++; - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); /* Send cached result to client @@ -1537,7 +1634,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", DBUG_RETURN(1); // Result sent to client err_unlock: - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); err: /* query_plan_flags doesn't have to be changed here as it contains @@ -1662,47 +1759,6 @@ void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length, /** - Synchronize the thread with any flushing operations. - - This helper function is called whenever a thread needs to operate on the - query cache structure (example: during invalidation). If a table flush is in - progress this function will wait for it to stop. If a full flush is in - progress, the function will set the interrupt parameter to indicate that the - current operation is redundant and should be interrupted. - - @param[out] interrupt This out-parameter will be set to TRUE if the calling - function is redundant and should be interrupted. - - @return If the interrupt-parameter is TRUE then m_cache_status is set to - NO_FLUSH_IN_PROGRESS. If the interrupt-parameter is FALSE then - m_cache_status is set to FLUSH_IN_PROGRESS. - The structure_guard_mutex will in any case be locked. -*/ - -void Query_cache::wait_while_table_flush_is_in_progress(bool *interrupt) -{ - while (is_flushing()) - { - /* - If there already is a full flush in progress query cache isn't enabled - and additional flushes are redundant; just return instead. - */ - if (m_cache_status == Query_cache::FLUSH_IN_PROGRESS) - { - *interrupt= TRUE; - return; - } - /* - If a table flush is in progress; wait on cache status to change. - */ - if (m_cache_status == Query_cache::TABLE_FLUSH_IN_PROGRESS) - pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); - } - *interrupt= FALSE; -} - - -/** Remove all cached queries that uses the given database. */ @@ -1711,14 +1767,11 @@ void Query_cache::invalidate(char *db) bool restart= FALSE; DBUG_ENTER("Query_cache::invalidate (db)"); - STRUCT_LOCK(&structure_guard_mutex); - bool interrupt; - wait_while_table_flush_is_in_progress(&interrupt); - if (interrupt) - { - STRUCT_UNLOCK(&structure_guard_mutex); - return; - } + /* + Lock the query cache and queue all invalidation attempts to avoid + the risk of a race between invalidation, cache inserts and flushes. + */ + lock(); THD *thd= current_thd; @@ -1774,7 +1827,7 @@ void Query_cache::invalidate(char *db) } while (restart); } // end if( tables_blocks ) } - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_VOID_RETURN; } @@ -1798,7 +1851,10 @@ void Query_cache::invalidate_by_MyISAM_filename(const char *filename) void Query_cache::flush() { DBUG_ENTER("Query_cache::flush"); - STRUCT_LOCK(&structure_guard_mutex); + DBUG_EXECUTE_IF("wait_in_query_cache_flush1", + debug_wait_for_kill("wait_in_query_cache_flush1");); + + lock_and_suspend(); if (query_cache_size > 0) { DUMP(this); @@ -1807,7 +1863,7 @@ void Query_cache::flush() } DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1);); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_VOID_RETURN; } @@ -1826,18 +1882,16 @@ void Query_cache::pack(ulong join_limit, uint iteration_limit) { DBUG_ENTER("Query_cache::pack"); - bool interrupt; - STRUCT_LOCK(&structure_guard_mutex); - wait_while_table_flush_is_in_progress(&interrupt); - if (interrupt) - { - STRUCT_UNLOCK(&structure_guard_mutex); + /* + If the entire qc is being invalidated we can bail out early + instead of waiting for the lock. + */ + if (try_lock()) DBUG_VOID_RETURN; - } if (query_cache_size == 0) { - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_VOID_RETURN; } @@ -1847,7 +1901,7 @@ void Query_cache::pack(ulong join_limit, uint iteration_limit) pack_cache(); } while ((++i < iteration_limit) && join_results(join_limit)); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_VOID_RETURN; } @@ -1862,9 +1916,9 @@ void Query_cache::destroy() else { /* Underlying code expects the lock. */ - STRUCT_LOCK(&structure_guard_mutex); + lock_and_suspend(); free_cache(); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); pthread_cond_destroy(&COND_cache_status_changed); pthread_mutex_destroy(&structure_guard_mutex); @@ -1883,7 +1937,7 @@ void Query_cache::init() DBUG_ENTER("Query_cache::init"); pthread_mutex_init(&structure_guard_mutex,MY_MUTEX_INIT_FAST); pthread_cond_init(&COND_cache_status_changed, NULL); - m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS; + m_cache_lock_status= Query_cache::UNLOCKED; initialized = 1; DBUG_VOID_RETURN; } @@ -2123,23 +2177,9 @@ void Query_cache::free_cache() void Query_cache::flush_cache() { - /* - If there is flush in progress, wait for it to finish, and then do - our flush. This is necessary because something could be added to - the cache before we acquire the lock again, and some code (like - Query_cache::free_cache()) depends on the fact that after the - flush the cache is empty. - */ - while (is_flushing()) - pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); - - /* - Setting 'FLUSH_IN_PROGRESS' will prevent other threads from using - the cache while we are in the middle of the flush, and we release - the lock so that other threads won't block. - */ - m_cache_status= Query_cache::FLUSH_IN_PROGRESS; - STRUCT_UNLOCK(&structure_guard_mutex); + + DBUG_EXECUTE_IF("wait_in_query_cache_flush2", + debug_wait_for_kill("wait_in_query_cache_flush2");); my_hash_reset(&queries); while (queries_blocks != 0) @@ -2147,10 +2187,6 @@ void Query_cache::flush_cache() BLOCK_LOCK_WR(queries_blocks); free_query_internal(queries_blocks); } - - STRUCT_LOCK(&structure_guard_mutex); - m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS; - pthread_cond_signal(&COND_cache_status_changed); } /* @@ -2330,10 +2366,6 @@ Query_cache::write_block_data(ulong data_len, uchar* data, } -/* - On success STRUCT_UNLOCK(&query_cache.structure_guard_mutex) will be done. -*/ - my_bool Query_cache::append_result_data(Query_cache_block **current_block, ulong data_len, uchar* data, @@ -2353,10 +2385,6 @@ Query_cache::append_result_data(Query_cache_block **current_block, if (*current_block == 0) { DBUG_PRINT("qcache", ("allocated first result data block %lu", data_len)); - /* - STRUCT_UNLOCK(&structure_guard_mutex) Will be done by - write_result_data if success; - */ DBUG_RETURN(write_result_data(current_block, data_len, data, query_block, Query_cache_block::RES_BEG)); } @@ -2387,10 +2415,6 @@ Query_cache::append_result_data(Query_cache_block **current_block, DBUG_PRINT("qcache", ("allocate new block for %lu bytes", data_len-last_block_free_space)); Query_cache_block *new_block = 0; - /* - On success STRUCT_UNLOCK(&structure_guard_mutex) will be done - by the next call - */ success = write_result_data(&new_block, data_len-last_block_free_space, (uchar*)(((uchar*)data)+last_block_free_space), query_block, @@ -2405,7 +2429,7 @@ Query_cache::append_result_data(Query_cache_block **current_block, else { // It is success (nobody can prevent us write data) - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); } // Now finally write data to the last block @@ -2443,7 +2467,7 @@ my_bool Query_cache::write_result_data(Query_cache_block **result_block, if (success) { // It is success (nobody can prevent us write data) - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); uint headers_len = (ALIGN_SIZE(sizeof(Query_cache_block)) + ALIGN_SIZE(sizeof(Query_cache_result))); #ifndef EMBEDDED_LIBRARY @@ -2601,36 +2625,23 @@ void Query_cache::invalidate_table(THD *thd, TABLE *table) void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length) { - bool interrupt; - STRUCT_LOCK(&structure_guard_mutex); - wait_while_table_flush_is_in_progress(&interrupt); - if (interrupt) - { - STRUCT_UNLOCK(&structure_guard_mutex); - return; - } + DBUG_EXECUTE_IF("wait_in_query_cache_invalidate1", + debug_wait_for_kill("wait_in_query_cache_invalidate1"); ); /* - Setting 'TABLE_FLUSH_IN_PROGRESS' will temporarily disable the cache - so that structural changes to cache won't block the entire server. - However, threads requesting to change the query cache will still have - to wait for the flush to finish. + Lock the query cache and queue all invalidation attempts to avoid + the risk of a race between invalidation, cache inserts and flushes. */ - m_cache_status= Query_cache::TABLE_FLUSH_IN_PROGRESS; - STRUCT_UNLOCK(&structure_guard_mutex); + lock(); + + DBUG_EXECUTE_IF("wait_in_query_cache_invalidate2", + debug_wait_for_kill("wait_in_query_cache_invalidate2"); ); + if (query_cache_size > 0) invalidate_table_internal(thd, key, key_length); - STRUCT_LOCK(&structure_guard_mutex); - m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS; - - /* - net_real_write might be waiting on a change on the m_cache_status - variable. - */ - pthread_cond_signal(&COND_cache_status_changed); - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); } @@ -2639,7 +2650,7 @@ void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length) The caller must ensure that no other thread is trying to work with the query cache when this function is executed. - @pre structure_guard_mutex is acquired or TABLE_FLUSH_IN_PROGRESS is set. + @pre structure_guard_mutex is acquired or LOCKED is set. */ void @@ -2657,7 +2668,7 @@ Query_cache::invalidate_table_internal(THD *thd, uchar *key, uint32 key_length) /** Invalidate a linked list of query cache blocks. - Each block tries to aquire a block level lock before + Each block tries to acquire a block level lock before free_query is a called. This function will in turn affect related table- and result-blocks. @@ -4181,10 +4192,7 @@ my_bool Query_cache::check_integrity(bool locked) DBUG_ENTER("check_integrity"); if (!locked) - STRUCT_LOCK(&structure_guard_mutex); - - while (is_flushing()) - pthread_cond_wait(&COND_cache_status_changed,&structure_guard_mutex); + lock_and_suspend(); if (hash_check(&queries)) { @@ -4433,7 +4441,7 @@ my_bool Query_cache::check_integrity(bool locked) } DBUG_ASSERT(result == 0); if (!locked) - STRUCT_UNLOCK(&structure_guard_mutex); + unlock(); DBUG_RETURN(result); } diff --git a/sql/sql_cache.h b/sql/sql_cache.h index f2c33eff614..777ddd39280 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -272,12 +272,12 @@ public: private: +#ifndef DBUG_OFF + my_thread_id m_cache_lock_thread_id; +#endif pthread_cond_t COND_cache_status_changed; - - enum Cache_status { NO_FLUSH_IN_PROGRESS, FLUSH_IN_PROGRESS, - TABLE_FLUSH_IN_PROGRESS }; - - Cache_status m_cache_status; + enum Cache_lock_status { UNLOCKED, LOCKED_NO_WAIT, LOCKED }; + Cache_lock_status m_cache_lock_status; void free_query_internal(Query_cache_block *point); void invalidate_table_internal(THD *thd, uchar *key, uint32 key_length); @@ -380,8 +380,6 @@ protected: Query_cache_block *pprev); my_bool join_results(ulong join_limit); - void wait_while_table_flush_is_in_progress(bool *interrupt); - /* Following function control structure_guard_mutex by themself or don't need structure_guard_mutex @@ -469,11 +467,6 @@ protected: friend void query_cache_end_of_result(THD *thd); friend void query_cache_abort(NET *net); - bool is_flushing(void) - { - return (m_cache_status != Query_cache::NO_FLUSH_IN_PROGRESS); - } - /* The following functions are only used when debugging We don't protect these with ifndef DBUG_OFF to not have to recompile @@ -491,6 +484,11 @@ protected: Query_cache_block_table * point, const char *name); my_bool in_blocks(Query_cache_block * point); + + bool try_lock(void); + void lock(void); + void lock_and_suspend(void); + void unlock(void); }; extern Query_cache query_cache; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 51fd9a54e52..0805eda59e4 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -27,6 +27,7 @@ #include "mysql_priv.h" #include "rpl_rli.h" +#include "rpl_filter.h" #include "rpl_record.h" #include "slave.h" #include <my_bitmap.h> @@ -551,6 +552,7 @@ THD::THD() first_successful_insert_id_in_prev_stmt_for_binlog(0), first_successful_insert_id_in_cur_stmt(0), stmt_depends_on_first_successful_insert_id_in_prev_stmt(FALSE), + examined_row_count(0), global_read_lock(0), is_fatal_error(0), transaction_rollback_request(0), @@ -597,7 +599,7 @@ THD::THD() // Must be reset to handle error with THD's created for init of mysqld lex->current_select= 0; start_time=(time_t) 0; - start_utime= 0L; + start_utime= prior_thr_create_utime= 0L; utime_after_lock= 0L; current_linfo = 0; slave_thread = 0; @@ -636,7 +638,7 @@ THD::THD() #ifdef SIGNAL_WITH_VIO_CLOSE active_vio = 0; #endif - pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST); + pthread_mutex_init(&LOCK_thd_data, MY_MUTEX_INIT_FAST); /* Variables with default values */ proc_info="login"; @@ -685,31 +687,40 @@ THD::THD() void THD::push_internal_handler(Internal_error_handler *handler) { - /* - TODO: The current implementation is limited to 1 handler at a time only. - THD and sp_rcontext need to be modified to use a common handler stack. - */ - DBUG_ASSERT(m_internal_handler == NULL); - m_internal_handler= handler; + if (m_internal_handler) + { + handler->m_prev_internal_handler= m_internal_handler; + m_internal_handler= handler; + } + else + { + m_internal_handler= handler; + } } bool THD::handle_error(uint sql_errno, const char *message, MYSQL_ERROR::enum_warning_level level) { - if (m_internal_handler) + if (!m_internal_handler) + return FALSE; + + for (Internal_error_handler *error_handler= m_internal_handler; + error_handler; + error_handler= m_internal_handler->m_prev_internal_handler) { - return m_internal_handler->handle_error(sql_errno, message, level, this); + if (error_handler->handle_error(sql_errno, message, level, this)) + return TRUE; } - return FALSE; // 'FALSE', as per coding style + return FALSE; } void THD::pop_internal_handler() { DBUG_ASSERT(m_internal_handler != NULL); - m_internal_handler= NULL; + m_internal_handler= m_internal_handler->m_prev_internal_handler; } extern "C" @@ -757,6 +768,12 @@ void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid) *xid = *(MYSQL_XID *) &thd->transaction.xid_state.xid; } +#ifdef _WIN32 +extern "C" THD *_current_thd_noinline(void) +{ + return my_pthread_getspecific_ptr(THD*,THR_THD); +} +#endif /* Init common variables that has to be reset on start and on change_user */ @@ -912,8 +929,8 @@ THD::~THD() THD_CHECK_SENTRY(this); DBUG_ENTER("~THD()"); /* Ensure that no one is using THD */ - pthread_mutex_lock(&LOCK_delete); - pthread_mutex_unlock(&LOCK_delete); + pthread_mutex_lock(&LOCK_thd_data); + pthread_mutex_unlock(&LOCK_thd_data); add_to_status(&global_status_var, &status_var); /* Close connection */ @@ -941,7 +958,7 @@ THD::~THD() free_root(&transaction.mem_root,MYF(0)); #endif mysys_var=0; // Safety (shouldn't be needed) - pthread_mutex_destroy(&LOCK_delete); + pthread_mutex_destroy(&LOCK_thd_data); #ifndef DBUG_OFF dbug_sentry= THD_SENTRY_GONE; #endif @@ -1022,7 +1039,7 @@ void THD::awake(THD::killed_state state_to_set) DBUG_ENTER("THD::awake"); DBUG_PRINT("enter", ("this: 0x%lx", (long) this)); THD_CHECK_SENTRY(this); - safe_mutex_assert_owner(&LOCK_delete); + safe_mutex_assert_owner(&LOCK_thd_data); killed= state_to_set; if (state_to_set != THD::KILL_QUERY) @@ -1075,7 +1092,7 @@ void THD::awake(THD::killed_state state_to_set) pthread_mutex_lock(), we can cause a deadlock as we are here locking the mysys_var->mutex and mysys_var->current_mutex in a different order than in the thread we are trying to kill. - We only sleep for 2 seconds as we don't want to have LOCK_delete + We only sleep for 2 seconds as we don't want to have LOCK_thd_data locked too long time. There is a small change we may not succeed in aborting a thread that @@ -1139,11 +1156,11 @@ bool THD::store_globals() #ifdef SAFE_MUTEX /* Register order of mutex for wrong mutex deadlock detector */ - pthread_mutex_lock(&LOCK_delete); + pthread_mutex_lock(&LOCK_thd_data); pthread_mutex_lock(&mysys_var->mutex); pthread_mutex_unlock(&mysys_var->mutex); - pthread_mutex_unlock(&LOCK_delete); + pthread_mutex_unlock(&LOCK_thd_data); #endif return 0; } @@ -1453,7 +1470,7 @@ int THD::send_explain_fields(select_result *result) void THD::close_active_vio() { DBUG_ENTER("close_active_vio"); - safe_mutex_assert_owner(&LOCK_delete); + safe_mutex_assert_owner(&LOCK_thd_data); #ifndef EMBEDDED_LIBRARY if (active_vio) { @@ -1834,6 +1851,8 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u) if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) strmake(path,exchange->file_name,FN_REFLEN-1); + write_cs= exchange->cs ? exchange->cs : &my_charset_bin; + if ((file= create_file(thd, path, exchange, &cache)) < 0) return 1; /* Check if there is any blobs in data */ @@ -1853,6 +1872,31 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u) non_string_results= TRUE; } } + if (exchange->escaped->numchars() > 1 || exchange->enclosed->numchars() > 1) + { + my_error(ER_WRONG_FIELD_TERMINATORS, MYF(0)); + return TRUE; + } + if (exchange->escaped->length() > 1 || exchange->enclosed->length() > 1 || + !my_isascii(exchange->escaped->ptr()[0]) || + !my_isascii(exchange->enclosed->ptr()[0]) || + !exchange->field_term->is_ascii() || !exchange->line_term->is_ascii() || + !exchange->line_start->is_ascii()) + { + /* + Current LOAD DATA INFILE recognizes field/line separators "as is" without + converting from client charset to data file charset. So, it is supposed, + that input file of LOAD DATA INFILE consists of data in one charset and + separators in other charset. For the compatibility with that [buggy] + behaviour SELECT INTO OUTFILE implementation has been saved "as is" too, + but the new warning message has been added: + + Non-ASCII separator arguments are not fully supported + */ + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED, + ER(WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED)); + } field_term_length=exchange->field_term->length(); field_term_char= field_term_length ? (int) (uchar) (*exchange->field_term)[0] : INT_MAX; @@ -1902,6 +1946,8 @@ bool select_export::send_data(List<Item> &items) DBUG_ENTER("select_export::send_data"); char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH]; + char cvt_buff[MAX_FIELD_WIDTH]; + String cvt_str(cvt_buff, sizeof(cvt_buff), write_cs); bool space_inited=0; String tmp(buff,sizeof(buff),&my_charset_bin),*res; tmp.length(0); @@ -1925,6 +1971,37 @@ bool select_export::send_data(List<Item> &items) bool enclosed = (exchange->enclosed->length() && (!exchange->opt_enclosed || result_type == STRING_RESULT)); res=item->str_result(&tmp); + if (res && !my_charset_same(write_cs, res->charset()) && + !my_charset_same(write_cs, &my_charset_bin)) + { + const char *well_formed_error_pos; + const char *cannot_convert_error_pos; + const char *from_end_pos; + const char *error_pos; + uint32 bytes; + bytes= well_formed_copy_nchars(write_cs, cvt_buff, sizeof(cvt_buff), + res->charset(), res->ptr(), res->length(), + sizeof(cvt_buff), + &well_formed_error_pos, + &cannot_convert_error_pos, + &from_end_pos); + error_pos= well_formed_error_pos ? well_formed_error_pos + : cannot_convert_error_pos; + if (error_pos) + { + char printable_buff[32]; + convert_to_printable(printable_buff, sizeof(printable_buff), + error_pos, res->ptr() + res->length() - error_pos, + res->charset(), 6); + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, + ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), + "string", printable_buff, + item->name, row_count); + } + cvt_str.length(bytes); + res= &cvt_str; + } if (res && enclosed) { if (my_b_write(&cache,(uchar*) exchange->enclosed->ptr(), @@ -2654,7 +2731,7 @@ bool select_dumpvar::send_data(List<Item> &items) { Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item); suv->fix_fields(thd, 0); - suv->check(0); + suv->save_item_result(item); suv->update(); } } @@ -3101,6 +3178,25 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) } +void THD::set_statement(Statement *stmt) +{ + pthread_mutex_lock(&LOCK_thd_data); + Statement::set_statement(stmt); + pthread_mutex_unlock(&LOCK_thd_data); +} + + +/** Assign a new value to thd->query. */ + +void THD::set_query(char *query_arg, uint32 query_length_arg) +{ + pthread_mutex_lock(&LOCK_thd_data); + query= query_arg; + query_length= query_length_arg; + pthread_mutex_unlock(&LOCK_thd_data); +} + + /** Mark transaction to rollback and mark error as fatal to a sub-statement. @@ -3642,7 +3738,7 @@ show_query_type(THD::enum_binlog_query_type qtype) */ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, ulong query_len, bool is_trans, bool suppress_use, - THD::killed_state killed_status_arg) + int errcode) { DBUG_ENTER("THD::binlog_query"); DBUG_PRINT("enter", ("qtype: %s query: '%s'", @@ -3667,12 +3763,18 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, we should print a warning. */ if (sql_log_bin_toplevel && lex->is_stmt_unsafe() && - variables.binlog_format == BINLOG_FORMAT_STMT) + variables.binlog_format == BINLOG_FORMAT_STMT && + binlog_filter->db_ok(this->db)) { - push_warning(this, MYSQL_ERROR::WARN_LEVEL_WARN, + /* + A warning can be elevated a error when STRICT sql mode. + But we don't want to elevate binlog warning to error here. + */ + push_warning(this, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_BINLOG_UNSAFE_STATEMENT, ER(ER_BINLOG_UNSAFE_STATEMENT)); - if (!(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED)) + if (global_system_variables.log_warnings && + !(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED)) { sql_print_warning("%s Statement: %.*s", ER(ER_BINLOG_UNSAFE_STATEMENT), @@ -3705,7 +3807,7 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, */ { Query_log_event qinfo(this, query_arg, query_len, is_trans, suppress_use, - killed_status_arg); + errcode); qinfo.flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F; /* Binlog table maps will be irrelevant after a Query_log_event diff --git a/sql/sql_class.h b/sql/sql_class.h index a7235a2a755..60ab952a3ab 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -93,7 +93,7 @@ enum enum_mark_columns extern char internal_table_name[2]; extern char empty_c_string[1]; -extern const char **errmesg; +extern MYSQL_PLUGIN_IMPORT const char **errmesg; #define TC_LOG_PAGE_SIZE 8192 #define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE) @@ -641,22 +641,16 @@ public: we need to declare it char * because all table handlers are written in C and need to point to it. - Note that (A) if we set query = NULL, we must at the same time set - query_length = 0, and protect the whole operation with the - LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a - non-NULL value if its previous value is NULL. We do not need to protect - operation (B) with any mutex. To avoid crashes in races, if we do not - know that thd->query cannot change at the moment, one should print + Note that if we set query = NULL, we must at the same time set + query_length = 0, and protect the whole operation with + LOCK_thd_data mutex. To avoid crashes in races, if we do not + know that thd->query cannot change at the moment, we should print thd->query like this: - (1) reserve the LOCK_thread_count mutex; - (2) check if thd->query is NULL; - (3) if not NULL, then print at most thd->query_length characters from - it. We will see the query_length field as either 0, or the right value - for it. - Assuming that the write and read of an n-bit memory field in an n-bit - computer is atomic, we can avoid races in the above way. - This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB - STATUS. + (1) reserve the LOCK_thd_data mutex; + (2) print or copy the value of query and query_length + (3) release LOCK_thd_data mutex. + This printing is needed at least in SHOW PROCESSLIST and SHOW + ENGINE INNODB STATUS. */ char *query; uint32 query_length; // current query length @@ -688,7 +682,7 @@ public: virtual ~Statement(); /* Assign execution context (note: not all members) of given stmt to self */ - void set_statement(Statement *stmt); + virtual void set_statement(Statement *stmt); void set_n_backup_statement(Statement *stmt, Statement *backup); void restore_backup_statement(Statement *stmt, Statement *backup); /* return class type */ @@ -1047,7 +1041,10 @@ show_system_thread(enum_thread_type thread) class Internal_error_handler { protected: - Internal_error_handler() {} + Internal_error_handler() : + m_prev_internal_handler(NULL) + {} + virtual ~Internal_error_handler() {} public: @@ -1080,6 +1077,28 @@ public: const char *message, MYSQL_ERROR::enum_warning_level level, THD *thd) = 0; +private: + Internal_error_handler *m_prev_internal_handler; + friend class THD; +}; + + +/** + Implements the trivial error handler which cancels all error states + and prevents an SQLSTATE to be set. +*/ + +class Dummy_error_handler : public Internal_error_handler +{ +public: + bool handle_error(uint sql_errno, + const char *message, + MYSQL_ERROR::enum_warning_level level, + THD *thd) + { + /* Ignore error */ + return TRUE; + } }; @@ -1285,7 +1304,15 @@ public: THR_LOCK_OWNER main_lock_id; // To use for conventional queries THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to // the lock_id of a cursor. - pthread_mutex_t LOCK_delete; // Locked before thd is deleted + /** + Protects THD data accessed from other threads: + - thd->query and thd->query_length (used by SHOW ENGINE + INNODB STATUS and SHOW PROCESSLIST + - thd->mysys_var (used by KILL statement and shutdown). + Is locked when THD is deleted. + */ + pthread_mutex_t LOCK_thd_data; + /* all prepared statements and cursors of this connection */ Statement_map stmt_map; /* @@ -1322,6 +1349,10 @@ public: Set it using the thd_proc_info(THD *thread, const char *message) macro/function. + + This member is accessed and assigned without any synchronization. + Therefore, it may point only to constant (statically + allocated) strings, which memory won't go away over time. */ const char *proc_info; @@ -1357,7 +1388,8 @@ public: /* remote (peer) port */ uint16 peer_port; time_t start_time, user_time; - ulonglong connect_utime, thr_create_utime; // track down slow pthread_create + // track down slow pthread_create + ulonglong prior_thr_create_utime, thr_create_utime; ulonglong start_utime, utime_after_lock; thr_lock_type update_lock_default; @@ -1452,6 +1484,14 @@ public: { changed_tables= 0; savepoints= 0; + /* + If rm_error is raised, it means that this piece of a distributed + transaction has failed and must be rolled back. But the user must + rollback it explicitly, so don't start a new distributed XA until + then. + */ + if (!xid_state.rm_error) + xid_state.xid.null(); #ifdef USING_TRANSACTIONS free_root(&mem_root,MYF(MY_KEEP_PREALLOC)); #endif @@ -1869,15 +1909,15 @@ public: #ifdef SIGNAL_WITH_VIO_CLOSE inline void set_active_vio(Vio* vio) { - pthread_mutex_lock(&LOCK_delete); + pthread_mutex_lock(&LOCK_thd_data); active_vio = vio; - pthread_mutex_unlock(&LOCK_delete); + pthread_mutex_unlock(&LOCK_thd_data); } inline void clear_active_vio() { - pthread_mutex_lock(&LOCK_delete); + pthread_mutex_lock(&LOCK_thd_data); active_vio = 0; - pthread_mutex_unlock(&LOCK_delete); + pthread_mutex_unlock(&LOCK_thd_data); } void close_active_vio(); #endif @@ -1906,7 +1946,7 @@ public: int binlog_query(enum_binlog_query_type qtype, char const *query, ulong query_len, bool is_trans, bool suppress_use, - THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE); + int errcode); #endif /* @@ -2227,6 +2267,9 @@ public: thd_scheduler event_scheduler; public: + inline Internal_error_handler *get_internal_handler() + { return m_internal_handler; } + /** Add an internal error handler to the thread execution context. @param handler the exception handler to add @@ -2247,6 +2290,14 @@ public: */ void pop_internal_handler(); + /** Overloaded to guard query/query_length fields */ + virtual void set_statement(Statement *stmt); + + /** + Assign a new value to thd->query. + Protected with LOCK_thd_data mutex. + */ + void set_query(char *query_arg, uint32 query_length_arg); private: /** The current internal error handler for this thread, or NULL. */ Internal_error_handler *m_internal_handler; @@ -2459,6 +2510,7 @@ class select_export :public select_to_file { */ bool is_unsafe_field_sep; bool fixed_row_size; + CHARSET_INFO *write_cs; // output charset public: select_export(sql_exchange *ex) :select_to_file(ex) {} /** diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 1b6c337a43e..8f02828e18c 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1077,8 +1077,8 @@ void prepare_new_connection_state(THD* thd) pthread_handler_t handle_one_connection(void *arg) { THD *thd= (THD*) arg; - ulong launch_time= (ulong) ((thd->thr_create_utime= my_micro_time()) - - thd->connect_utime); + + thd->thr_create_utime= my_micro_time(); if (thread_scheduler.init_new_connection_thread()) { @@ -1087,8 +1087,20 @@ pthread_handler_t handle_one_connection(void *arg) thd->scheduler->end_thread(thd,0); return 0; } - if (launch_time >= slow_launch_time*1000000L) - statistic_increment(slow_launch_threads,&LOCK_status); + + /* + If a thread was created to handle this connection: + increment slow_launch_threads counter if it took more than + slow_launch_time seconds to create the thread. + */ + if (thd->prior_thr_create_utime) + { + ulong launch_time= (ulong) (thd->thr_create_utime - + thd->prior_thr_create_utime); + if (launch_time >= slow_launch_time*1000000L) + statistic_increment(slow_launch_threads, &LOCK_status); + thd->prior_thr_create_utime= 0; + } /* handle_one_connection() is normally the only way a thread would diff --git a/sql/sql_crypt.cc b/sql/sql_crypt.cc index f7f63efa077..4b5c0a66e43 100644 --- a/sql/sql_crypt.cc +++ b/sql/sql_crypt.cc @@ -28,10 +28,10 @@ #include "mysql_priv.h" -SQL_CRYPT::SQL_CRYPT(const char *password) +SQL_CRYPT::SQL_CRYPT(const char *password, uint length) { ulong rand_nr[2]; - hash_password(rand_nr,password, (uint) strlen(password)); + hash_password(rand_nr,password, length); crypt_init(rand_nr); } diff --git a/sql/sql_crypt.h b/sql/sql_crypt.h index 7d803245b0b..50ff1217193 100644 --- a/sql/sql_crypt.h +++ b/sql/sql_crypt.h @@ -25,7 +25,7 @@ class SQL_CRYPT :public Sql_alloc uint shift; void crypt_init(ulong *seed); public: - SQL_CRYPT(const char *seed); + SQL_CRYPT(const char *seed, uint length); SQL_CRYPT(ulong *seed) { crypt_init(seed); diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 8a891f88057..9e528622416 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -181,8 +181,7 @@ uchar* dboptions_get_key(my_dbopt_t *opt, size_t *length, static inline void write_to_binlog(THD *thd, char *query, uint q_len, char *db, uint db_len) { - Query_log_event qinfo(thd, query, q_len, 0, 0); - qinfo.error_code= 0; + Query_log_event qinfo(thd, query, q_len, 0, 0, 0); qinfo.db= db; qinfo.db_len= db_len; mysql_bin_log.write(&qinfo); @@ -538,13 +537,13 @@ err1: bool load_db_opt_by_name(THD *thd, const char *db_name, HA_CREATE_INFO *db_create_info) { - char db_opt_path[FN_REFLEN]; + char db_opt_path[FN_REFLEN + 1]; /* Pass an empty file name, and the database options file name as extension to avoid table name to file name encoding. */ - (void) build_table_filename(db_opt_path, sizeof(db_opt_path), + (void) build_table_filename(db_opt_path, sizeof(db_opt_path) - 1, db_name, "", MY_DB_OPT_FILE, 0); return load_db_opt(thd, db_opt_path, db_create_info); @@ -646,7 +645,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, VOID(pthread_mutex_lock(&LOCK_mysql_create_db)); /* Check directory */ - path_len= build_table_filename(path, sizeof(path), db, "", "", 0); + path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0); path[path_len-1]= 0; // Remove last '/' from path if (my_stat(path,&stat_info,MYF(0))) @@ -723,8 +722,9 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, if (mysql_bin_log.is_open()) { + int errcode= query_error_code(thd, TRUE); Query_log_event qinfo(thd, query, query_length, 0, - /* suppress_use */ TRUE); + /* suppress_use */ TRUE, errcode); /* Write should use the database being created as the "current @@ -791,7 +791,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) We pass MY_DB_OPT_FILE as "extension" to avoid "table name to file name" encoding. */ - build_table_filename(path, sizeof(path), db, "", MY_DB_OPT_FILE, 0); + build_table_filename(path, sizeof(path) - 1, db, "", MY_DB_OPT_FILE, 0); if ((error=write_db_opt(thd, path, create_info))) goto exit; @@ -811,8 +811,9 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) if (mysql_bin_log.is_open()) { + int errcode= query_error_code(thd, TRUE); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, - /* suppress_use */ TRUE); + /* suppress_use */ TRUE, errcode); /* Write should use the database being created as the "current @@ -883,7 +884,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) VOID(pthread_mutex_lock(&LOCK_mysql_create_db)); - length= build_table_filename(path, sizeof(path), db, "", "", 0); + length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0); strmov(path+length, MY_DB_OPT_FILE); // Append db option file name del_dbopt(path); // Remove dboption hash entry path[length]= '\0'; // Remove file name @@ -958,8 +959,9 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) } if (mysql_bin_log.is_open()) { + int errcode= query_error_code(thd, TRUE); Query_log_event qinfo(thd, query, query_length, 0, - /* suppress_use */ TRUE); + /* suppress_use */ TRUE, errcode); /* Write should use the database being created as the "current database" and not the threads current database, which is the @@ -1835,7 +1837,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db) for (uint idx=0 ; idx < nfiles && !thd->killed ; idx++) { FILEINFO *file= dirp->dir_entry + idx; - char *extension, tname[FN_REFLEN]; + char *extension, tname[FN_REFLEN + 1]; LEX_STRING table_str; DBUG_PRINT("info",("Examining: %s", file->name)); @@ -1924,7 +1926,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db) for (uint idx=0 ; idx < nfiles ; idx++) { FILEINFO *file= dirp->dir_entry + idx; - char oldname[FN_REFLEN], newname[FN_REFLEN]; + char oldname[FN_REFLEN + 1], newname[FN_REFLEN + 1]; DBUG_PRINT("info",("Examining: %s", file->name)); /* skiping . and .. and MY_DB_OPT_FILE */ @@ -1954,7 +1956,9 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db) /* Step8: logging */ if (mysql_bin_log.is_open()) { - Query_log_event qinfo(thd, thd->query, thd->query_length, 0, TRUE); + int errcode= query_error_code(thd, TRUE); + Query_log_event qinfo(thd, thd->query, thd->query_length, + 0, TRUE, errcode); thd->clear_error(); mysql_bin_log.write(&qinfo); } @@ -1992,10 +1996,10 @@ exit: bool check_db_dir_existence(const char *db_name) { - char db_dir_path[FN_REFLEN]; + char db_dir_path[FN_REFLEN + 1]; uint db_dir_path_len; - db_dir_path_len= build_table_filename(db_dir_path, sizeof(db_dir_path), + db_dir_path_len= build_table_filename(db_dir_path, sizeof(db_dir_path) - 1, db_name, "", "", 0); if (db_dir_path_len && db_dir_path[db_dir_path_len - 1] == FN_LIBCHAR) diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 7a355bdd8c2..8fa396a8553 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -187,6 +187,14 @@ 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. + Currently they rely on the user checking DA for + errors when unwinding the stack after calling Item::val_xxx(). + */ + if (thd->is_error()) + DBUG_RETURN(TRUE); my_ok(thd, (ha_rows) thd->row_count_func); /* We don't need to call reset_auto_increment in this case, because @@ -389,8 +397,12 @@ cleanup: FALSE : transactional_table; + int errcode= 0; if (error < 0) thd->clear_error(); + else + errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); + /* [binlog]: If 'handler::delete_all_rows()' was called and the storage engine does not inject the rows itself, we replicate @@ -402,9 +414,9 @@ cleanup: */ int log_result= thd->binlog_query(query_type, thd->query, thd->query_length, - is_trans, FALSE, killed_status); + is_trans, FALSE, errcode); - if (log_result && transactional_table) + if (log_result) { error=1; } @@ -486,7 +498,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) if (select_lex->inner_refs_list.elements && fix_inner_refs(thd, all_fields, select_lex, select_lex->ref_pointer_array)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); select_lex->fix_prepare_information(thd, conds, &fake_conds); DBUG_RETURN(FALSE); @@ -582,6 +594,11 @@ int mysql_multi_delete_prepare(THD *thd) } } } + /* + Reset the exclude flag to false so it doesn't interfare + with further calls to unique_table + */ + lex->select_lex.exclude_from_table_unique_test= FALSE; DBUG_RETURN(FALSE); } @@ -617,11 +634,24 @@ multi_delete::initialize_tables(JOIN *join) DBUG_RETURN(1); table_map tables_to_delete_from=0; + delete_while_scanning= 1; for (walk= delete_tables; walk; walk= walk->next_local) + { tables_to_delete_from|= walk->table->map; + if (delete_while_scanning && + unique_table(thd, walk, join->tables_list, false)) + { + /* + If the table we are going to delete from appears + in join, we need to defer delete. So the delete + doesn't interfers with the scaning of results. + */ + delete_while_scanning= 0; + } + } + walk= delete_tables; - delete_while_scanning= 1; for (JOIN_TAB *tab=join->join_tab, *end=join->join_tab+join->tables; tab < end; tab++) @@ -709,6 +739,8 @@ bool multi_delete::send_data(List<Item> &values) TABLE_LIST *del_table; DBUG_ENTER("multi_delete::send_data"); + bool ignore= thd->lex->current_select->no_error; + for (del_table= delete_tables; del_table; del_table= del_table->next_local, secure_counter++) @@ -741,8 +773,12 @@ bool multi_delete::send_data(List<Item> &values) TRG_ACTION_AFTER, FALSE)) DBUG_RETURN(1); } - else + else if (!ignore) { + /* + If the IGNORE option is used errors caused by ha_delete_row don't + have to stop the iteration. + */ table->file->print_error(error,MYF(0)); DBUG_RETURN(1); } @@ -812,9 +848,10 @@ void multi_delete::abort() */ if (mysql_bin_log.is_open()) { + int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - transactional_tables, FALSE); + transactional_tables, FALSE, errcode); } thd->transaction.all.modified_non_trans_table= true; } @@ -834,6 +871,11 @@ int multi_delete::do_deletes() { int local_error= 0, counter= 0, tmp_error; bool will_batch; + /* + If the IGNORE option is used all non fatal errors will be translated + to warnings and we should not break the row-by-row iteration + */ + bool ignore= thd->lex->current_select->no_error; DBUG_ENTER("do_deletes"); DBUG_ASSERT(do_delete); @@ -872,18 +914,29 @@ int multi_delete::do_deletes() local_error= 1; break; } - if ((local_error=table->file->ha_delete_row(table->record[0]))) + + local_error= table->file->ha_delete_row(table->record[0]); + if (local_error && !ignore) { - table->file->print_error(local_error,MYF(0)); - break; + table->file->print_error(local_error,MYF(0)); + break; } - deleted++; - if (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_DELETE, - TRG_ACTION_AFTER, FALSE)) + + /* + Increase the reported number of deleted rows only if no error occurred + during ha_delete_row. + Also, don't execute the AFTER trigger if the row operation failed. + */ + if (!local_error) { - local_error= 1; - break; + deleted++; + if (table->triggers && + table->triggers->process_triggers(thd, TRG_EVENT_DELETE, + TRG_ACTION_AFTER, FALSE)) + { + local_error= 1; + break; + } } } if (will_batch && (tmp_error= table->file->end_bulk_delete())) @@ -939,11 +992,14 @@ bool multi_delete::send_eof() { if (mysql_bin_log.is_open()) { + int errcode= 0; if (local_error == 0) thd->clear_error(); + else + errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); if (thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - transactional_tables, FALSE, killed_status) && + transactional_tables, FALSE, errcode) && !normal_tables) { local_error=1; // Log write failed: roll back the SQL statement @@ -1003,7 +1059,7 @@ static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list) bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) { HA_CREATE_INFO create_info; - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; TABLE *table; bool error; uint path_length; @@ -1042,7 +1098,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) goto end; } - path_length= build_table_filename(path, sizeof(path), table_list->db, + path_length= build_table_filename(path, sizeof(path) - 1, table_list->db, table_list->table_name, reg_ext, 0); if (!dont_send_ok) diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 41be98621a6..37adf5c403a 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -179,6 +179,7 @@ exit: { if (thd->is_error() && (thd->main_da.sql_errno() == ER_BAD_FIELD_ERROR || + thd->main_da.sql_errno() == ER_FUNC_INEXISTENT_NAME_COLLISION || thd->main_da.sql_errno() == ER_SP_DOES_NOT_EXIST)) { thd->clear_error(); diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 9c8bba6208c..1e92d95573a 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -199,6 +199,14 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) tables->db, tables->table_name, tables->alias, (int) reopen)); + if (tables->schema_table) + { + my_error(ER_WRONG_USAGE, MYF(0), "HANDLER OPEN", + INFORMATION_SCHEMA_NAME.str); + DBUG_PRINT("exit",("ERROR")); + DBUG_RETURN(TRUE); + } + if (! hash_inited(&thd->handler_tables_hash)) { /* @@ -244,14 +252,37 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) /* for now HANDLER can be used only for real TABLES */ tables->required_type= FRMTYPE_TABLE; + /* + We use open_tables() here, rather than, say, + open_ltable() or open_table() because we would like to be able + to open a temporary table. + */ error= open_tables(thd, &tables, &counter, 0); - /* restore the state and merge the opened table into handler_tables list */ if (thd->open_tables) { - thd->open_tables->next= thd->handler_tables; - thd->handler_tables= thd->open_tables; + if (thd->open_tables->next) + { + /* + We opened something that is more than a single table. + This happens with MERGE engine. Don't try to link + this mess into thd->handler_tables list, close it + and report an error. We must do it right away + because mysql_ha_close_table(), called down the road, + can close a single table only. + */ + close_thread_tables(thd); + my_error(ER_ILLEGAL_HA, MYF(0), tables->alias); + error= 1; + } + else + { + /* Merge the opened table into handler_tables list. */ + thd->open_tables->next= thd->handler_tables; + thd->handler_tables= thd->open_tables; + } } + /* Restore the state. */ thd->open_tables= backup_open_tables; if (error) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 09e977ea801..710da7067e4 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -322,7 +322,6 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list, { TABLE *table= insert_table_list->table; my_bool timestamp_mark; - LINT_INIT(timestamp_mark); if (table->timestamp_field) @@ -888,6 +887,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, { if (mysql_bin_log.is_open()) { + int errcode= 0; if (error <= 0) { /* @@ -902,6 +902,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, /* todo: consider removing */ thd->clear_error(); } + else + errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); + /* bug#22725: A query which per-row-loop can not be interrupted with @@ -918,8 +921,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, transactional_table, FALSE, - (error>0) ? thd->killed : THD::NOT_KILLED) && - transactional_table) + errcode)) { error=1; } @@ -1139,6 +1141,33 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list, /* + Get extra info for tables we insert into + + @param table table(TABLE object) we insert into, + might be NULL in case of view + @param table(TABLE_LIST object) or view we insert into +*/ + +static void prepare_for_positional_update(TABLE *table, TABLE_LIST *tables) +{ + if (table) + { + if(table->reginfo.lock_type != TL_WRITE_DELAYED) + table->prepare_for_position(); + return; + } + + DBUG_ASSERT(tables->view); + List_iterator<TABLE_LIST> it(*tables->view_tables); + TABLE_LIST *tbl; + while ((tbl= it++)) + prepare_for_positional_update(tbl->table, tbl); + + return; +} + + +/* Prepare items in INSERT statement SYNOPSIS @@ -1183,7 +1212,7 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, bool res= 0; table_map map= 0; DBUG_ENTER("mysql_prepare_insert"); - DBUG_PRINT("enter", ("table_list 0x%lx table 0x%lx view %d", + DBUG_PRINT("enter", ("table_list: 0x%lx table: 0x%lx view: %d", (ulong)table_list, (ulong)table, (int)insert_into_view)); /* INSERT should have a SELECT or VALUES clause */ @@ -1288,9 +1317,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, Only call prepare_for_posistion() if we are not performing a DELAYED operation. It will instead be executed by delayed insert thread. */ - if ((duplic == DUP_UPDATE || duplic == DUP_REPLACE) && - (table->reginfo.lock_type != TL_WRITE_DELAYED)) - table->prepare_for_position(); + if (duplic == DUP_UPDATE || duplic == DUP_REPLACE) + prepare_for_positional_update(table, table_list); DBUG_RETURN(FALSE); } @@ -1908,7 +1936,7 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list) thread_count++; pthread_mutex_unlock(&LOCK_thread_count); di->thd.set_db(table_list->db, (uint) strlen(table_list->db)); - di->thd.query= my_strdup(table_list->table_name, MYF(MY_WME)); + di->thd.set_query(my_strdup(table_list->table_name, MYF(MY_WME)), 0); if (di->thd.db == NULL || di->thd.query == NULL) { /* The error is reported */ @@ -2696,6 +2724,12 @@ bool Delayed_insert::handle_inserts(void) thd.variables.time_zone = row->time_zone; } + /* if the delayed insert was killed, the killed status is + ignored while binlogging */ + int errcode= 0; + if (thd.killed == THD::NOT_KILLED) + errcode= query_error_code(&thd, TRUE); + /* If the query has several rows to insert, only the first row will come here. In row-based binlogging, this means that the first row will be @@ -2706,7 +2740,7 @@ bool Delayed_insert::handle_inserts(void) */ thd.binlog_query(THD::ROW_QUERY_TYPE, row->query.str, row->query.length, - FALSE, FALSE); + FALSE, FALSE, errcode); thd.time_zone_used = backup_time_zone_used; thd.variables.time_zone = backup_time_zone; @@ -3119,7 +3153,10 @@ bool select_insert::send_data(List<Item> &values) store_values(values); thd->count_cuted_fields= CHECK_FIELD_IGNORE; if (thd->is_error()) + { + table->auto_increment_field_not_null= FALSE; DBUG_RETURN(1); + } if (table_list) // Not CREATE ... SELECT { switch (table_list->view_check_option(thd, info.ignore)) { @@ -3130,6 +3167,9 @@ bool select_insert::send_data(List<Item> &values) } } + // Release latches in case bulk insert takes a long time + ha_release_temporary_latches(thd); + error= write_record(thd, table, &info); table->auto_increment_field_not_null= FALSE; @@ -3223,11 +3263,14 @@ bool select_insert::send_eof() */ if (mysql_bin_log.is_open()) { + int errcode= 0; if (!error) thd->clear_error(); + else + errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - trans_table, FALSE, killed_status); + trans_table, FALSE, errcode); } table->file->ha_release_auto_increment(); @@ -3294,8 +3337,11 @@ void select_insert::abort() { if (thd->transaction.stmt.modified_non_trans_table) { if (mysql_bin_log.is_open()) + { + int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - transactional_table, FALSE); + transactional_table, FALSE, errcode); + } if (!thd->current_stmt_binlog_row_based && !can_rollback_data()) thd->transaction.all.modified_non_trans_table= TRUE; if (changed) @@ -3694,10 +3740,14 @@ select_create::binlog_show_create_table(TABLE **tables, uint count) DBUG_ASSERT(result == 0); /* store_create_info() always return 0 */ if (mysql_bin_log.is_open()) + { + int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); thd->binlog_query(THD::STMT_QUERY_TYPE, query.ptr(), query.length(), /* is_trans */ TRUE, - /* suppress_use */ FALSE); + /* suppress_use */ FALSE, + errcode); + } } void select_create::store_values(List<Item> &values) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 680a3851723..6d047197992 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -348,6 +348,7 @@ void lex_start(THD *thd) lex->nest_level=0 ; lex->allow_sum_func= 0; lex->in_sum_func= NULL; + lex->protect_against_global_read_lock= FALSE; /* ok, there must be a better solution for this, long-term I tried "bzero" in the sql_yacc.yy code, but that for @@ -432,6 +433,16 @@ bool is_keyword(const char *name, uint len) return get_hash_symbol(name,len,0)!=0; } +/** + Check if name is a sql function + + @param name checked name + + @return is this a native function or not + @retval 0 name is a function + @retval 1 name isn't a function +*/ + bool is_lex_native_function(const LEX_STRING *name) { DBUG_ASSERT(name != NULL); @@ -712,6 +723,53 @@ static inline uint int_token(const char *str,uint length) return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger; } + +/** + Given a stream that is advanced to the first contained character in + an open comment, consume the comment. Optionally, if we are allowed, + recurse so that we understand comments within this current comment. + + At this level, we do not support version-condition comments. We might + have been called with having just passed one in the stream, though. In + that case, we probably want to tolerate mundane comments inside. Thus, + the case for recursion. + + @retval Whether EOF reached before comment is closed. +*/ +bool consume_comment(Lex_input_stream *lip, int remaining_recursions_permitted) +{ + reg1 uchar c; + while (! lip->eof()) + { + c= lip->yyGet(); + + if (remaining_recursions_permitted > 0) + { + if ((c == '/') && (lip->yyPeek() == '*')) + { + lip->yySkip(); /* Eat asterisk */ + consume_comment(lip, remaining_recursions_permitted-1); + continue; + } + } + + if (c == '*') + { + if (lip->yyPeek() == '/') + { + lip->yySkip(); /* Eat slash */ + return FALSE; + } + } + + if (c == '\n') + lip->yylineno++; + } + + return TRUE; +} + + /* MYSQLlex remember the following states from the following MYSQLlex() @@ -735,12 +793,12 @@ int MYSQLlex(void *arg, void *yythd) uchar *state_map= cs->state_map; uchar *ident_map= cs->ident_map; + LINT_INIT(c); lip->yylval=yylval; // The global state lip->start_token(); state=lip->next_state; lip->next_state=MY_LEX_OPERATOR_OR_IDENT; - LINT_INIT(c); for (;;) { switch (state) { @@ -1056,9 +1114,12 @@ int MYSQLlex(void *arg, void *yythd) } } #ifdef USE_MB - else if (var_length < 1) - break; // Error - lip->skip_binary(var_length-1); + else if (use_mb(cs)) + { + if ((var_length= my_ismbchar(cs, lip->get_ptr() - 1, + lip->get_end_of_query()))) + lip->skip_binary(var_length-1); + } #endif } if (double_quotes) @@ -1213,6 +1274,8 @@ int MYSQLlex(void *arg, void *yythd) /* Reject '/' '*', since we might need to turn off the echo */ lip->yyUnget(); + lip->save_in_comment_state(); + if (lip->yyPeekn(2) == '!') { lip->in_comment= DISCARD_COMMENT; @@ -1255,11 +1318,17 @@ int MYSQLlex(void *arg, void *yythd) /* Expand the content of the special comment as real code */ lip->set_echo(TRUE); state=MY_LEX_START; - break; + break; /* Do not treat contents as a comment. */ + } + else + { + comment_closed= ! consume_comment(lip, 1); + /* version allowed to have one level of comment inside. */ } } else { + /* Not a version comment. */ state=MY_LEX_START; lip->set_echo(TRUE); break; @@ -1270,38 +1339,30 @@ int MYSQLlex(void *arg, void *yythd) lip->in_comment= PRESERVE_COMMENT; lip->yySkip(); // Accept / lip->yySkip(); // Accept * + comment_closed= ! consume_comment(lip, 0); + /* regular comments can have zero comments inside. */ } /* Discard: - regular '/' '*' comments, - special comments '/' '*' '!' for a future version, by scanning until we find a closing '*' '/' marker. - Note: There is no such thing as nesting comments, - the first '*' '/' sequence seen will mark the end. + + Nesting regular comments isn't allowed. The first + '*' '/' returns the parser to the previous state. + + /#!VERSI oned containing /# regular #/ is allowed #/ + + Inside one versioned comment, another versioned comment + is treated as a regular discardable comment. It gets + no special parsing. */ - comment_closed= FALSE; - while (! lip->eof()) - { - c= lip->yyGet(); - if (c == '*') - { - if (lip->yyPeek() == '/') - { - lip->yySkip(); - comment_closed= TRUE; - state = MY_LEX_START; - break; - } - } - else if (c == '\n') - lip->yylineno++; - } + /* Unbalanced comments with a missing '*' '/' are a syntax error */ if (! comment_closed) return (ABORT_SYM); state = MY_LEX_START; // Try again - lip->in_comment= NO_COMMENT; - lip->set_echo(TRUE); + lip->restore_in_comment_state(); break; case MY_LEX_END_LONG_COMMENT: if ((lip->in_comment != NO_COMMENT) && lip->yyPeek() == '/') diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 69fad07d2e3..4b9b35819fe 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1160,6 +1160,18 @@ public: m_echo= echo; } + void save_in_comment_state() + { + m_echo_saved= m_echo; + in_comment_saved= in_comment; + } + + void restore_in_comment_state() + { + m_echo= m_echo_saved; + in_comment= in_comment_saved; + } + /** Skip binary from the input stream. @param n number of bytes to accept. @@ -1178,7 +1190,7 @@ public: Get a character, and advance in the stream. @return the next character to parse. */ - char yyGet() + unsigned char yyGet() { char c= *m_ptr++; if (m_echo) @@ -1190,7 +1202,7 @@ public: Get the last character accepted. @return the last character accepted. */ - char yyGetLast() + unsigned char yyGetLast() { return m_ptr[-1]; } @@ -1198,7 +1210,7 @@ public: /** Look at the next character to parse, but do not accept it. */ - char yyPeek() + unsigned char yyPeek() { return m_ptr[0]; } @@ -1207,7 +1219,7 @@ public: Look ahead at some character to parse. @param n offset of the character to look up */ - char yyPeekn(int n) + unsigned char yyPeekn(int n) { return m_ptr[n]; } @@ -1417,6 +1429,7 @@ private: /** Echo the parsed stream to the pre-processed buffer. */ bool m_echo; + bool m_echo_saved; /** Pre-processed buffer. */ char *m_cpp_buf; @@ -1479,6 +1492,7 @@ public: /** State of the lexical analyser for comments. */ enum_comment_state in_comment; + enum_comment_state in_comment_saved; /** Starting position of the TEXT_STRING or IDENT in the pre-processed @@ -1745,6 +1759,22 @@ typedef struct st_lex : public Query_tables_list bool escape_used; bool is_lex_started; /* If lex_start() did run. For debugging. */ + /* + Special case for SELECT .. FOR UPDATE and LOCK TABLES .. WRITE. + + Protect from a impending GRL as otherwise the thread might deadlock + if it starts waiting for the GRL in mysql_lock_tables. + + The protection is needed because there is a race between setting + the global read lock and waiting for all open tables to be closed. + The problem is a circular wait where a thread holding "old" open + tables will wait for the global read lock to be released while the + thread holding the global read lock will wait for all "old" open + tables to be closed -- the flush part of flush tables with read + lock. + */ + bool protect_against_global_read_lock; + st_lex(); virtual ~st_lex() @@ -1946,4 +1976,6 @@ extern bool is_lex_native_function(const LEX_STRING *name); @} (End of group Semantic_Analysis) */ +int my_missing_function_error(const LEX_STRING &token, const char *name); + #endif /* MYSQL_SERVER */ diff --git a/sql/sql_list.h b/sql/sql_list.h index eb580120c1b..93cdd20c299 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -86,7 +86,7 @@ struct list_node :public Sql_alloc }; -extern list_node end_of_list; +extern MYSQL_PLUGIN_IMPORT list_node end_of_list; class base_list :public Sql_alloc { diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 771aef33434..1929c233f23 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -86,7 +86,7 @@ static int read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, static bool write_execute_load_query_log_event(THD *thd, bool duplicates, bool ignore, bool transactional_table, - THD::killed_state killed_status); + int errcode); #endif /* EMBEDDED_LIBRARY */ /* @@ -148,6 +148,17 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, MYF(0)); DBUG_RETURN(TRUE); } + + /* Report problems with non-ascii separators */ + if (!escaped->is_ascii() || !enclosed->is_ascii() || + !field_term->is_ascii() || + !ex->line_term->is_ascii() || !ex->line_start->is_ascii()) + { + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED, + ER(WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED)); + } + if (open_and_lock_tables(thd, table_list)) DBUG_RETURN(TRUE); if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context, @@ -483,10 +494,12 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, /* If the file was not empty, wrote_create_file is true */ if (lf_info.wrote_create_file) { + int errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); + if (thd->transaction.stmt.modified_non_trans_table) write_execute_load_query_log_event(thd, handle_duplicates, ignore, transactional_table, - killed_status); + errcode); else { Delete_file_log_event d(thd, db, transactional_table); @@ -528,8 +541,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, read_info.end_io_cache(); if (lf_info.wrote_create_file) { + int errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); write_execute_load_query_log_event(thd, handle_duplicates, ignore, - transactional_table,killed_status); + transactional_table, errcode); } } } @@ -553,7 +567,7 @@ err: static bool write_execute_load_query_log_event(THD *thd, bool duplicates, bool ignore, bool transactional_table, - THD::killed_state killed_err_arg) + int errcode) { Execute_load_query_log_event e(thd, thd->query, thd->query_length, @@ -561,7 +575,7 @@ static bool write_execute_load_query_log_event(THD *thd, (uint) ((char*)thd->lex->fname_end - (char*)thd->query), (duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE : (ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR), - transactional_table, FALSE, killed_err_arg); + transactional_table, FALSE, errcode); e.flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F; return mysql_bin_log.write(&e); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 761fac5a2eb..20033e23b93 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -202,11 +202,8 @@ bool begin_trans(THD *thd) error= -1; else { - LEX *lex= thd->lex; thd->options|= OPTION_BEGIN; thd->server_status|= SERVER_STATUS_IN_TRANS; - if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) - error= ha_start_consistent_snapshot(thd); } return error; } @@ -467,6 +464,7 @@ pthread_handler_t handle_bootstrap(void *arg) thd->init_for_queries(); while (fgets(buff, thd->net.max_packet, file)) { + char *query; /* strlen() can't be deleted because fgets() doesn't return length */ ulong length= (ulong) strlen(buff); while (buff[length-1] != '\n' && !feof(file)) @@ -499,11 +497,10 @@ pthread_handler_t handle_bootstrap(void *arg) if (strncmp(buff, STRING_WITH_LEN("delimiter")) == 0) continue; - thd->query_length=length; - thd->query= (char*) thd->memdup_w_gap(buff, length+1, - thd->db_length+1+ - QUERY_CACHE_FLAGS_SIZE); - thd->query[length] = '\0'; + query= (char *) thd->memdup_w_gap(buff, length + 1, + thd->db_length + 1 + + QUERY_CACHE_FLAGS_SIZE); + thd->set_query(query, length); DBUG_PRINT("query",("%-.4096s",thd->query)); #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER) thd->profiling.start_new_query(); @@ -543,8 +540,9 @@ end: #ifndef EMBEDDED_LIBRARY (void) pthread_mutex_lock(&LOCK_thread_count); thread_count--; - (void) pthread_mutex_unlock(&LOCK_thread_count); + in_bootstrap= FALSE; (void) pthread_cond_broadcast(&COND_thread_count); + (void) pthread_mutex_unlock(&LOCK_thread_count); my_thread_end(); pthread_exit(0); #endif @@ -668,8 +666,7 @@ int mysql_table_dump(THD *thd, LEX_STRING *db, char *tbl_name) if (check_one_table_access(thd, SELECT_ACL, table_list)) goto err; thd->free_list = 0; - thd->query_length=(uint) strlen(tbl_name); - thd->query = tbl_name; + thd->set_query(tbl_name, (uint) strlen(tbl_name)); if ((error = mysqld_dump_create_info(thd, table_list, -1))) { my_error(ER_GET_ERRNO, MYF(0), my_errno); @@ -1178,12 +1175,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_STMT_EXECUTE: { - mysql_stmt_execute(thd, packet, packet_length); + mysqld_stmt_execute(thd, packet, packet_length); break; } case COM_STMT_FETCH: { - mysql_stmt_fetch(thd, packet, packet_length); + mysqld_stmt_fetch(thd, packet, packet_length); break; } case COM_STMT_SEND_LONG_DATA: @@ -1193,17 +1190,17 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_STMT_PREPARE: { - mysql_stmt_prepare(thd, packet, packet_length); + mysqld_stmt_prepare(thd, packet, packet_length); break; } case COM_STMT_CLOSE: { - mysql_stmt_close(thd, packet); + mysqld_stmt_close(thd, packet); break; } case COM_STMT_RESET: { - mysql_stmt_reset(thd, packet); + mysqld_stmt_reset(thd, packet); break; } case COM_QUERY: @@ -1256,9 +1253,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->profiling.set_query_source(beginning_of_next_stmt, length); #endif + thd->set_query(beginning_of_next_stmt, length); VOID(pthread_mutex_lock(&LOCK_thread_count)); - thd->query_length= length; - thd->query= beginning_of_next_stmt; /* Count each statement from the client. */ @@ -1311,9 +1307,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, table_list.schema_table= schema_table; } - thd->query_length= (uint) (packet_end - packet); // Don't count end \0 - if (!(thd->query=fields= (char*) thd->memdup(packet,thd->query_length+1))) + uint query_length= (uint) (packet_end - packet); // Don't count end \0 + if (!(fields= (char *) thd->memdup(packet, query_length + 1))) break; + thd->set_query(fields, query_length); general_log_print(thd, command, "%s %s", table_list.table_name, fields); if (lower_case_table_names) my_casedn_str(files_charset_info, table_list.table_name); @@ -1367,7 +1364,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (check_access(thd, CREATE_ACL, db.str , 0, 1, 0, is_schema_db(db.str))) break; - general_log_print(thd, command, packet); + general_log_print(thd, command, "%.*s", db.length, db.str); bzero(&create_info, sizeof(create_info)); mysql_create_db(thd, (lower_case_table_names == 2 ? alias.str : db.str), &create_info, 0); @@ -1392,7 +1389,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); break; } - general_log_write(thd, command, db.str, db.length); + general_log_write(thd, command, "%.*s", db.length, db.str); mysql_rm_db(thd, db.str, 0, 0); break; } @@ -1582,14 +1579,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; } - /* If commit fails, we should be able to reset the OK status. */ - thd->main_da.can_overwrite_status= TRUE; - ha_autocommit_or_rollback(thd, thd->is_error()); - thd->main_da.can_overwrite_status= FALSE; - - thd->transaction.stmt.reset(); - - /* report error issued during command execution */ if (thd->killed_errno()) { @@ -1602,6 +1591,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->mysys_var->abort= 0; } + /* If commit fails, we should be able to reset the OK status. */ + thd->main_da.can_overwrite_status= TRUE; + ha_autocommit_or_rollback(thd, thd->is_error()); + thd->main_da.can_overwrite_status= FALSE; + + thd->transaction.stmt.reset(); + #ifdef WITH_MARIA_STORAGE_ENGINE ha_maria::implicit_commit(thd, FALSE); #endif @@ -1616,13 +1612,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd, log_slow_statement(thd); thd_proc_info(thd, "cleaning up"); - VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list - thd_proc_info(thd, 0); + thd->set_query(NULL, 0); thd->command=COM_SLEEP; - thd->query=0; - thd->query_length=0; + VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list thread_running--; VOID(pthread_mutex_unlock(&LOCK_thread_count)); + thd_proc_info(thd, 0); thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); DBUG_RETURN(error); @@ -1828,6 +1823,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, bool alloc_query(THD *thd, const char *packet, uint packet_length) { + char *query; /* Remove garbage at start and end of query */ while (packet_length > 0 && my_isspace(thd->charset(), packet[0])) { @@ -1842,14 +1838,13 @@ bool alloc_query(THD *thd, const char *packet, uint packet_length) packet_length--; } /* We must allocate some extra memory for query cache */ - thd->query_length= 0; // Extra safety: Avoid races - if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet), - packet_length, - thd->db_length+ 1 + - QUERY_CACHE_FLAGS_SIZE))) - return TRUE; - thd->query[packet_length]=0; - thd->query_length= packet_length; + if (! (query= (char*) thd->memdup_w_gap(packet, + packet_length, + 1 + thd->db_length + + QUERY_CACHE_FLAGS_SIZE))) + return TRUE; + query[packet_length]= '\0'; + thd->set_query(query, packet_length); /* Reclaim some memory */ thd->packet.shrink(thd->variables.net_buffer_length); @@ -2236,8 +2231,15 @@ mysql_execute_command(THD *thd) res= check_access(thd, lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL, any_db, 0, 0, 0, 0); - if (!res) - res= execute_sqlcom_select(thd, all_tables); + + if (res) + break; + + if (!thd->locked_tables && lex->protect_against_global_read_lock && + !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) + break; + + res= execute_sqlcom_select(thd, all_tables); break; case SQLCOM_PREPARE: { @@ -3052,6 +3054,9 @@ end_with_restore_list: DBUG_ASSERT(first_table == all_tables && first_table != 0); if (update_precheck(thd, all_tables)) break; + if (!thd->locked_tables && + !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) + goto error; DBUG_ASSERT(select_lex->offset_limit == 0); unit->set_limit(select_lex); res= (up_result= mysql_update(thd, all_tables, @@ -3078,6 +3083,15 @@ end_with_restore_list: else res= 0; + /* + Protection might have already been risen if its a fall through + from the SQLCOM_UPDATE case above. + */ + if (!thd->locked_tables && + lex->sql_command == SQLCOM_UPDATE_MULTI && + !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) + goto error; + res= mysql_multi_update_prepare(thd); #ifdef HAVE_REPLICATION @@ -3275,7 +3289,8 @@ end_with_restore_list: ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } - + if (!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) + goto error; res= mysql_truncate(thd, first_table, 0); break; case SQLCOM_DELETE: @@ -3448,6 +3463,10 @@ end_with_restore_list: if (check_one_table_access(thd, privilege, all_tables)) goto error; + if (!thd->locked_tables && + !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) + goto error; + res= mysql_load(thd, lex->exchange, first_table, lex->field_list, lex->update_list, lex->value_list, lex->duplicates, lex->ignore, (bool) lex->local_file); @@ -3518,6 +3537,9 @@ end_with_restore_list: if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables, UINT_MAX, FALSE)) goto error; + if (lex->protect_against_global_read_lock && + !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1))) + goto error; thd->in_lock_tables=1; thd->options|= OPTION_TABLE_LOCK; @@ -3902,7 +3924,9 @@ end_with_restore_list: res= mysql_routine_grant(thd, all_tables, lex->type == TYPE_ENUM_PROCEDURE, lex->users_list, grants, - lex->sql_command == SQLCOM_REVOKE, 0); + lex->sql_command == SQLCOM_REVOKE, TRUE); + if (!res) + my_ok(thd); } else { @@ -4046,6 +4070,11 @@ end_with_restore_list: } if (begin_trans(thd)) goto error; + if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) + { + if (ha_start_consistent_snapshot(thd)) + goto error; + } my_ok(thd); break; case SQLCOM_COMMIT: @@ -5497,7 +5526,7 @@ bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) if (!check_access(thd, access, table->db, &table->grant.privilege, 0, 1, test(table->schema_table)) && - !check_grant(thd, access, table, 0, 1, 1)) + !check_grant(thd, access, table, 0, 1, 1)) DBUG_RETURN(0); } } @@ -5756,7 +5785,7 @@ mysql_new_select(LEX *lex, bool move_down) /* Don't evaluate this subquery during statement prepare even if it's a constant one. The flag is switched off in the end of - mysql_stmt_prepare. + mysqld_stmt_prepare. */ if (thd->stmt_arena->is_stmt_prepare()) select_lex->uncacheable|= UNCACHEABLE_PREPARE; @@ -6968,7 +6997,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) continue; if (tmp->thread_id == id) { - pthread_mutex_lock(&tmp->LOCK_delete); // Lock from delete + pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete break; } } @@ -7001,7 +7030,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) } else error=ER_KILL_DENIED_ERROR; - pthread_mutex_unlock(&tmp->LOCK_delete); + pthread_mutex_unlock(&tmp->LOCK_thd_data); } DBUG_PRINT("exit", ("%d", error)); DBUG_RETURN(error); diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 41766d15c2a..236df78d455 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -918,6 +918,9 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, Set-up the TABLE_LIST object to be a list with a single table Set the object to zero to create NULL pointers and set alias and real name to table name and get database name from file name. + TODO: Consider generalizing or refactoring Lex::add_table_to_list() so + it can be used in all places where we create TABLE_LIST objects. + Also consider creating appropriate constructors for TABLE_LIST. */ bzero((void*)&tables, sizeof(TABLE_LIST)); @@ -925,6 +928,13 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, tables.table= table; tables.next_local= 0; tables.next_name_resolution_table= 0; + /* + Cache the table in Item_fields. All the tables can be cached except + the trigger pseudo table. + */ + tables.cacheable_table= TRUE; + context= thd->lex->current_context(); + tables.select_lex= context->select_lex; strmov(db_name_string, table->s->normalized_path.str); dir_length= dirname_length(db_name_string); db_name_string[dir_length - 1]= 0; @@ -932,7 +942,6 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, db_name= &db_name_string[home_dir_length]; tables.db= db_name; - context= thd->lex->current_context(); table->map= 1; //To ensure correct calculation of const item table->get_fields_in_item_tree= TRUE; save_table_list= context->table_list; @@ -964,8 +973,9 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, save_use_only_table_context= thd->lex->use_only_table_context; thd->lex->use_only_table_context= TRUE; + thd->lex->current_select->cur_pos_in_select_list= UNDEF_POS; - error= func_expr->fix_fields(thd, (Item**)0); + error= func_expr->fix_fields(thd, (Item**)&func_expr); thd->lex->use_only_table_context= save_use_only_table_context; @@ -2937,7 +2947,8 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info, the maximum value is in the current partition. */ if (part_func_value > bound || - (part_func_value == bound && !part_info->defined_max_value)) + (part_func_value == bound && + (!part_info->defined_max_value || loc_part_id < max_partition))) loc_part_id++; } else @@ -3813,8 +3824,13 @@ bool mysql_unpack_partition(THD *thd, Item_field objects. This is not a nice solution since if the parser uses current_select for anything else it will corrupt the current LEX object. + Also, we need to make sure there even is a select -- if the statement + was a "USE ...", current_select will be NULL, but we may still end up + here if we try to log to a partitioned table. This is currently + unsupported, but should still fail rather than crash! */ - thd->lex->current_select= old_lex->current_select; + if (!(thd->lex->current_select= old_lex->current_select)) + goto end; /* All Items created is put into a free list on the THD object. This list is used to free all Item objects after completing a query. We don't @@ -5089,7 +5105,7 @@ static bool mysql_change_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) handler *file= lpt->table->file; DBUG_ENTER("mysql_change_partitions"); - build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); if ((error= file->ha_change_partitions(lpt->create_info, path, &lpt->copied, &lpt->deleted, lpt->pack_frm_data, lpt->pack_frm_len))) @@ -5129,7 +5145,7 @@ static bool mysql_rename_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) int error; DBUG_ENTER("mysql_rename_partitions"); - build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); if ((error= lpt->table->file->ha_rename_partitions(path))) { if (error != 1) @@ -5170,7 +5186,7 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) int error; DBUG_ENTER("mysql_drop_partitions"); - build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); if ((error= lpt->table->file->ha_drop_partitions(path))) { lpt->table->file->print_error(error, MYF(0)); @@ -5515,10 +5531,10 @@ static bool write_log_drop_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt) partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; DDL_LOG_MEMORY_ENTRY *exec_log_entry= NULL; - char shadow_path[FN_REFLEN]; + char shadow_path[FN_REFLEN + 1]; DBUG_ENTER("write_log_drop_shadow_frm"); - build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt); + build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); pthread_mutex_lock(&LOCK_gdl); if (write_log_replace_delete_frm(lpt, 0UL, NULL, (const char*)shadow_path, FALSE)) @@ -5558,15 +5574,15 @@ static bool write_log_rename_frm(ALTER_PARTITION_PARAM_TYPE *lpt) partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; DDL_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry; - char path[FN_REFLEN]; - char shadow_path[FN_REFLEN]; + char path[FN_REFLEN + 1]; + char shadow_path[FN_REFLEN + 1]; DDL_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry; DBUG_ENTER("write_log_rename_frm"); part_info->first_log_entry= NULL; - build_table_filename(path, sizeof(path), lpt->db, + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); - build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt); + build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); pthread_mutex_lock(&LOCK_gdl); if (write_log_replace_delete_frm(lpt, 0UL, shadow_path, path, TRUE)) goto error; @@ -5609,16 +5625,16 @@ static bool write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt) partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; DDL_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry; - char tmp_path[FN_REFLEN]; - char path[FN_REFLEN]; + char tmp_path[FN_REFLEN + 1]; + char path[FN_REFLEN + 1]; uint next_entry= 0; DDL_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry; DBUG_ENTER("write_log_drop_partition"); part_info->first_log_entry= NULL; - build_table_filename(path, sizeof(path), lpt->db, + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); - build_table_filename(tmp_path, sizeof(tmp_path), lpt->db, + build_table_filename(tmp_path, sizeof(tmp_path) - 1, lpt->db, lpt->table_name, "#", 0); pthread_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, @@ -5668,14 +5684,14 @@ static bool write_log_add_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; DDL_LOG_MEMORY_ENTRY *exec_log_entry= NULL; - char tmp_path[FN_REFLEN]; - char path[FN_REFLEN]; + char tmp_path[FN_REFLEN + 1]; + char path[FN_REFLEN + 1]; uint next_entry= 0; DBUG_ENTER("write_log_add_change_partition"); - build_table_filename(path, sizeof(path), lpt->db, + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); - build_table_filename(tmp_path, sizeof(tmp_path), lpt->db, + build_table_filename(tmp_path, sizeof(tmp_path) - 1, lpt->db, lpt->table_name, "#", 0); pthread_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, @@ -5722,16 +5738,16 @@ static bool write_log_final_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; DDL_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry; - char path[FN_REFLEN]; - char shadow_path[FN_REFLEN]; + char path[FN_REFLEN + 1]; + char shadow_path[FN_REFLEN + 1]; DDL_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry; uint next_entry= 0; DBUG_ENTER("write_log_final_change_partition"); part_info->first_log_entry= NULL; - build_table_filename(path, sizeof(path), lpt->db, + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); - build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt); + build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); pthread_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, lpt->alter_info->flags & ALTER_REORGANIZE_PARTITION)) diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index a1748c0f5f5..fa19d7188bf 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -29,6 +29,18 @@ extern struct st_mysql_plugin *mysqld_builtins[]; +/** + @note The order of the enumeration is critical. + @see construct_options +*/ +static const char *global_plugin_typelib_names[]= + { "OFF", "ON", "FORCE", NULL }; +enum enum_plugin_load_policy {PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE}; +static TYPELIB global_plugin_typelib= + { array_elements(global_plugin_typelib_names)-1, + "", global_plugin_typelib_names, NULL }; + + char *opt_plugin_load= NULL; char *opt_plugin_dir_ptr; char opt_plugin_dir[FN_REFLEN]; @@ -192,7 +204,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv); static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, const char *list); static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *, - int *, char **, my_bool); + int *, char **); static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *, struct st_plugin_int **); static void unlock_variables(THD *thd, struct system_variables *vars); @@ -751,7 +763,7 @@ static bool plugin_add(MEM_ROOT *tmp_root, tmp.name.length= name_len; tmp.ref_count= 0; tmp.state= PLUGIN_IS_UNINITIALIZED; - if (test_plugin_options(tmp_root, &tmp, argc, argv, true)) + if (test_plugin_options(tmp_root, &tmp, argc, argv)) tmp.state= PLUGIN_IS_DISABLED; if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp))) @@ -997,7 +1009,6 @@ static int plugin_initialize(struct st_plugin_int *plugin) DBUG_ENTER("plugin_initialize"); safe_mutex_assert_owner(&LOCK_plugin); - if (plugin_type_initialize[plugin->plugin->type]) { if ((*plugin_type_initialize[plugin->plugin->type])(plugin)) @@ -1083,6 +1094,20 @@ uchar *get_bookmark_hash_key(const uchar *buff, size_t *length, return (uchar*) var->key; } +static inline void convert_dash_to_underscore(char *str, int len) +{ + for (char *p= str; p <= str+len; p++) + if (*p == '-') + *p= '_'; +} + +static inline void convert_underscore_to_dash(char *str, int len) +{ + for (char *p= str; p <= str+len; p++) + if (*p == '_') + *p= '-'; +} + /* The logic is that we first load and initialize all compiled in plugins. @@ -1094,11 +1119,12 @@ uchar *get_bookmark_hash_key(const uchar *buff, size_t *length, int plugin_init(int *argc, char **argv, int flags) { uint i; - bool def_enabled, is_myisam; + bool is_myisam; struct st_mysql_plugin **builtins; struct st_mysql_plugin *plugin; struct st_plugin_int tmp, *plugin_ptr, **reap; MEM_ROOT tmp_root; + bool reaped_mandatory_plugin= FALSE; DBUG_ENTER("plugin_init"); if (initialized) @@ -1142,17 +1168,13 @@ int plugin_init(int *argc, char **argv, int flags) !my_strnncoll(&my_charset_latin1, (const uchar*) plugin->name, 6, (const uchar*) "InnoDB", 6)) continue; - /* by default, ndbcluster and federated are disabled */ - def_enabled= - my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0 && - my_strcasecmp(&my_charset_latin1, plugin->name, "FEDERATED") != 0; bzero(&tmp, sizeof(tmp)); tmp.plugin= plugin; tmp.name.str= (char *)plugin->name; tmp.name.length= strlen(plugin->name); tmp.state= 0; free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE)); - if (test_plugin_options(&tmp_root, &tmp, argc, argv, def_enabled)) + if (test_plugin_options(&tmp_root, &tmp, argc, argv)) tmp.state= PLUGIN_IS_DISABLED; else tmp.state= PLUGIN_IS_UNINITIALIZED; @@ -1227,6 +1249,8 @@ int plugin_init(int *argc, char **argv, int flags) while ((plugin_ptr= *(--reap))) { pthread_mutex_unlock(&LOCK_plugin); + if (plugin_ptr->is_mandatory) + reaped_mandatory_plugin= TRUE; plugin_deinitialize(plugin_ptr, true); pthread_mutex_lock(&LOCK_plugin); plugin_del(plugin_ptr); @@ -1234,6 +1258,8 @@ int plugin_init(int *argc, char **argv, int flags) pthread_mutex_unlock(&LOCK_plugin); my_afree(reap); + if (reaped_mandatory_plugin) + goto err; end: free_root(&tmp_root, MYF(0)); @@ -1299,7 +1325,7 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin) pthread_mutex_lock(&LOCK_plugin); rw_wrlock(&LOCK_system_variables_hash); - if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true)) + if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL)) goto end; tmp.state= PLUGIN_IS_UNINITIALIZED; if ((result= register_builtin(plugin, &tmp, &ptr))) @@ -2889,59 +2915,78 @@ my_bool get_one_plugin_option(int optid __attribute__((unused)), } +/** + Creates a set of my_option objects associated with a specified plugin- + handle. + + @param mem_root Memory allocator to be used. + @param tmp A pointer to a plugin handle + @param[out] options A pointer to a pre-allocated static array + + The set is stored in the pre-allocated static array supplied to the function. + The size of the array is calculated as (number_of_plugin_varaibles*2+3). The + reason is that each option can have a prefix '--plugin-' in addtion to the + shorter form '--<plugin-name>'. There is also space allocated for + terminating NULL pointers. + + @return + @retval -1 An error occurred + @retval 0 Success +*/ + static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, - my_option *options, my_bool **enabled, - bool can_disable) + my_option *options) { const char *plugin_name= tmp->plugin->name; - uint namelen= strlen(plugin_name), optnamelen; - uint buffer_length= namelen * 4 + (can_disable ? 75 : 10); - char *name= (char*) alloc_root(mem_root, buffer_length) + 1; - char *optname, *p; + const LEX_STRING plugin_dash = { C_STRING_WITH_LEN("plugin-") }; + uint plugin_name_len= strlen(plugin_name); + uint optnamelen; + const int max_comment_len= 180; + char *comment= (char *) alloc_root(mem_root, max_comment_len + 1); + char *optname; + int index= 0, offset= 0; st_mysql_sys_var *opt, **plugin_option; st_bookmark *v; + + /** Used to circumvent the const attribute on my_option::name */ + char *plugin_name_ptr, *plugin_name_with_prefix_ptr; + DBUG_ENTER("construct_options"); - DBUG_PRINT("plugin", ("plugin: '%s' enabled: %d can_disable: %d", - plugin_name, **enabled, can_disable)); + options[0].name= plugin_name_ptr= (char*) alloc_root(mem_root, + plugin_name_len + 1); + strcpy(plugin_name_ptr, plugin_name); + my_casedn_str(&my_charset_latin1, plugin_name_ptr); + convert_underscore_to_dash(plugin_name_ptr, plugin_name_len); /* support --skip-plugin-foo syntax */ - memcpy(name, plugin_name, namelen + 1); - my_casedn_str(&my_charset_latin1, name); - strxmov(name + namelen + 1, "plugin-", name, NullS); - /* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */ - - for (p= name + namelen*2 + 8; p > name; p--) - if (*p == '_') - *p= '-'; + options[1].name= plugin_name_with_prefix_ptr= (char*) alloc_root(mem_root, + plugin_name_len + + plugin_dash.length + 1); + strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, options[0].name, NullS); - if (can_disable) - { - strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. " - "Disable with --skip-", name," (will save memory).", NullS); - /* - Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 + - 20 + namelen + 20 + 1 == namelen * 4 + 67. - */ + options[0].id= options[1].id= 256; /* must be >255. dup id ok */ + options[0].var_type= options[1].var_type= GET_ENUM; + options[0].arg_type= options[1].arg_type= OPT_ARG; + options[0].def_value= options[1].def_value= 1; /* ON */ + options[0].typelib= options[1].typelib= &global_plugin_typelib; - options[0].comment= name + namelen*2 + 10; - } + strxnmov(comment, max_comment_len, "Enable or disable ", plugin_name, + " plugin. Possible values are ON, OFF, FORCE (don't start " + "if the plugin fails to load).", NullS); + options[0].comment= comment; /* - NOTE: 'name' is one char above the allocated buffer! - NOTE: This code assumes that 'my_bool' and 'char' are of same size. + Allocate temporary space for the value of the tristate. + This option will have a limited lifetime and is not used beyond + server initialization. + GET_ENUM value is an ulong. */ - *((my_bool *)(name -1))= **enabled; - *enabled= (my_bool *)(name - 1); - + options[0].value= options[1].value= (uchar **)alloc_root(mem_root, + sizeof(ulong)); + *((ulong*) options[0].value)= *((ulong*) options[1].value)= + (ulong) options[0].def_value; - options[1].name= (options[0].name= name) + namelen + 1; - options[0].id= options[1].id= 256; /* must be >255. dup id ok */ - options[0].var_type= options[1].var_type= GET_BOOL; - options[0].arg_type= options[1].arg_type= NO_ARG; - options[0].def_value= options[1].def_value= **enabled; - options[0].value= options[0].u_max_value= - options[1].value= options[1].u_max_value= (uchar**) (name - 1); options+= 2; /* @@ -2955,7 +3000,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, opt= *plugin_option; if (!(opt->flags & PLUGIN_VAR_THDLOCAL)) continue; - if (!(register_var(name, opt->name, opt->flags))) + if (!(register_var(plugin_name_ptr, opt->name, opt->flags))) continue; switch (opt->flags & PLUGIN_VAR_TYPEMASK) { case PLUGIN_VAR_BOOL: @@ -3062,14 +3107,14 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, if (!(opt->flags & PLUGIN_VAR_THDLOCAL)) { optnamelen= strlen(opt->name); - optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2); - strxmov(optname, name, "-", opt->name, NullS); - optnamelen= namelen + optnamelen + 1; + optname= (char*) alloc_root(mem_root, plugin_name_len + optnamelen + 2); + strxmov(optname, plugin_name_ptr, "-", opt->name, NullS); + optnamelen= plugin_name_len + optnamelen + 1; } else { /* this should not fail because register_var should create entry */ - if (!(v= find_bookmark(name, opt->name, opt->flags))) + if (!(v= find_bookmark(plugin_name_ptr, opt->name, opt->flags))) { sql_print_error("Thread local variable '%s' not allocated " "in plugin '%s'.", opt->name, plugin_name); @@ -3085,10 +3130,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, (optnamelen= v->name_len) + 1); } - /* convert '_' to '-' */ - for (p= optname; *p; p++) - if (*p == '_') - *p= '-'; + convert_underscore_to_dash(optname, optnamelen); options->name= optname; options->comment= opt->comment; @@ -3103,10 +3145,13 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, else options->value= options->u_max_value= *(uchar***) (opt + 1); + char *option_name_ptr; options[1]= options[0]; - options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8); - options[1].comment= 0; // hidden - strxmov(p, "plugin-", optname, NullS); + options[1].name= option_name_ptr= (char*) alloc_root(mem_root, + plugin_dash.length + + optnamelen + 1); + options[1].comment= 0; /* Hidden from the help text */ + strxmov(option_name_ptr, plugin_dash.str, optname, NullS); options+= 2; } @@ -3120,8 +3165,6 @@ static my_option *construct_help_options(MEM_ROOT *mem_root, { st_mysql_sys_var **opt; my_option *opts; - my_bool dummy, can_disable; - my_bool *dummy2= &dummy; uint count= EXTRA_OPTIONS; DBUG_ENTER("construct_help_options"); @@ -3133,43 +3176,46 @@ static my_option *construct_help_options(MEM_ROOT *mem_root, bzero(opts, sizeof(my_option) * count); - dummy= TRUE; /* plugin is enabled. */ - - can_disable= - my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") && - my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY"); - - if (construct_options(mem_root, p, opts, &dummy2, can_disable)) + if (construct_options(mem_root, p, opts)) DBUG_RETURN(NULL); DBUG_RETURN(opts); } -/* - SYNOPSIS - test_plugin_options() - tmp_root temporary scratch space - plugin internal plugin structure - argc user supplied arguments - argv user supplied arguments - default_enabled default plugin enable status - RETURNS: - 0 SUCCESS - plugin should be enabled/loaded - NOTE: - Requires that a write-lock is held on LOCK_system_variables_hash +/** + Create and register system variables supplied from the plugin and + assigns initial values from corresponding command line arguments. + + @param tmp_root Temporary scratch space + @param[out] plugin Internal plugin structure + @param argc Number of command line arguments + @param argv Command line argument vector + + The plugin will be updated with a policy on how to handle errors during + initialization. + + @note Requires that a write-lock is held on LOCK_system_variables_hash + + @return How initialization of the plugin should be handled. + @retval 0 Initialization should proceed. + @retval 1 Plugin is disabled. + @retval -1 An error has occurred. */ + static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, - int *argc, char **argv, my_bool default_enabled) + int *argc, char **argv) { struct sys_var_chain chain= { NULL, NULL }; - my_bool enabled_saved= default_enabled, can_disable; - my_bool *enabled= &default_enabled; + my_bool can_disable; + bool disable_plugin; + enum_plugin_load_policy plugin_load_policy= PLUGIN_ON; + MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ? &tmp->mem_root : &plugin_mem_root; st_mysql_sys_var **opt; my_option *opts= NULL; - char *p, *varname; + char *varname; int error; st_mysql_sys_var *o; sys_var *v; @@ -3178,13 +3224,17 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, DBUG_ENTER("test_plugin_options"); DBUG_ASSERT(tmp->plugin && tmp->name.str); + /* + The 'federated' and 'ndbcluster' storage engines are always disabled by + default. + */ + if (!(my_strcasecmp(&my_charset_latin1, tmp->name.str, "federated") && + my_strcasecmp(&my_charset_latin1, tmp->name.str, "ndbcluster"))) + plugin_load_policy= PLUGIN_OFF; + for (opt= tmp->plugin->system_vars; opt && *opt; opt++) count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */ - can_disable= - my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") && - my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY"); - if (count > EXTRA_OPTIONS || (*argc > 1)) { if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count))) @@ -3194,12 +3244,18 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, } bzero(opts, sizeof(my_option) * count); - if (construct_options(tmp_root, tmp, opts, &enabled, can_disable)) + if (construct_options(tmp_root, tmp, opts)) { sql_print_error("Bad options for plugin '%s'.", tmp->name.str); DBUG_RETURN(-1); } + /* + We adjust the default value to account for the hardcoded exceptions + we have set for the federated and ndbcluster storage engines. + */ + opts[0].def_value= opts[1].def_value= (int)plugin_load_policy; + error= handle_options(argc, &argv, opts, get_one_plugin_option); (*argc)++; /* add back one for the program name */ @@ -3209,64 +3265,79 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, tmp->name.str); goto err; } + /* + Set plugin loading policy from option value. First element in the option + list is always the <plugin name> option value. + */ + plugin_load_policy= (enum_plugin_load_policy)*(ulong*)opts[0].value; } - if (!*enabled && !can_disable) + disable_plugin= (plugin_load_policy == PLUGIN_OFF); + /* + The 'MyISAM' and 'Memory' storage engines currently can't be disabled. + */ + can_disable= + my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") && + my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY"); + + tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE) || !can_disable; + + if (disable_plugin && !can_disable) { sql_print_warning("Plugin '%s' cannot be disabled", tmp->name.str); - *enabled= TRUE; + disable_plugin= FALSE; } - error= 1; + /* + If the plugin is disabled it should not be initialized. + */ + if (disable_plugin) + { + if (global_system_variables.log_warnings) + sql_print_information("Plugin '%s' is disabled.", + tmp->name.str); + if (opts) + my_cleanup_options(opts); + DBUG_RETURN(1); + } - if (*enabled) + error= 1; + for (opt= tmp->plugin->system_vars; opt && *opt; opt++) { - for (opt= tmp->plugin->system_vars; opt && *opt; opt++) + if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR)) + continue; + if ((var= find_bookmark(tmp->name.str, o->name, o->flags))) + v= new (mem_root) sys_var_pluginvar(var->key + 1, o); + else { - if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR)) - continue; - - if ((var= find_bookmark(tmp->name.str, o->name, o->flags))) - v= new (mem_root) sys_var_pluginvar(var->key + 1, o); - else - { - len= tmp->name.length + strlen(o->name) + 2; - varname= (char*) alloc_root(mem_root, len); - strxmov(varname, tmp->name.str, "-", o->name, NullS); - my_casedn_str(&my_charset_latin1, varname); - - for (p= varname; *p; p++) - if (*p == '-') - *p= '_'; - - v= new (mem_root) sys_var_pluginvar(varname, o); - } - DBUG_ASSERT(v); /* check that an object was actually constructed */ - - /* - Add to the chain of variables. - Done like this for easier debugging so that the - pointer to v is not lost on optimized builds. - */ - v->chain_sys_var(&chain); + len= tmp->name.length + strlen(o->name) + 2; + varname= (char*) alloc_root(mem_root, len); + strxmov(varname, tmp->name.str, "-", o->name, NullS); + my_casedn_str(&my_charset_latin1, varname); + convert_dash_to_underscore(varname, len-1); + v= new (mem_root) sys_var_pluginvar(varname, o); } - if (chain.first) + DBUG_ASSERT(v); /* check that an object was actually constructed */ + /* + Add to the chain of variables. + Done like this for easier debugging so that the + pointer to v is not lost on optimized builds. + */ + v->chain_sys_var(&chain); + } /* end for */ + if (chain.first) + { + chain.last->next = NULL; + if (mysql_add_sys_var_chain(chain.first, NULL)) { - chain.last->next = NULL; - if (mysql_add_sys_var_chain(chain.first, NULL)) - { - sql_print_error("Plugin '%s' has conflicting system variables", - tmp->name.str); - goto err; - } - tmp->system_vars= chain.first; + sql_print_error("Plugin '%s' has conflicting system variables", + tmp->name.str); + goto err; } - DBUG_RETURN(0); + tmp->system_vars= chain.first; } - - if (enabled_saved && global_system_variables.log_warnings) - sql_print_information("Plugin '%s' disabled by command line option", - tmp->name.str); + DBUG_RETURN(0); + err: if (opts) my_cleanup_options(opts); diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 8ae38d58845..004d0d5abb7 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -79,6 +79,7 @@ struct st_plugin_int void *data; /* plugin type specific, e.g. handlerton */ MEM_ROOT mem_root; /* memory for dynamic plugin structures */ sys_var *system_vars; /* server variables for this plugin */ + bool is_mandatory; /* If true then plugin must not fail to load */ }; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 427402133d2..5fee201dcd2 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -127,12 +127,12 @@ class Prepared_statement: public Statement public: enum flag_values { - IS_IN_USE= 1 + IS_IN_USE= 1, + IS_SQL_PREPARE= 2 }; THD *thd; Select_fetch_protocol_binary result; - Protocol *protocol; Item_param **param_array; uint param_count; uint last_errno; @@ -148,7 +148,7 @@ public: List<LEX_STRING>& varnames, String *expanded_query); public: - Prepared_statement(THD *thd_arg, Protocol *protocol_arg); + Prepared_statement(THD *thd_arg); virtual ~Prepared_statement(); void setup_set_params(); virtual Query_arena::Type type() const; @@ -156,7 +156,8 @@ public: bool set_name(LEX_STRING *name); inline void close_cursor() { delete cursor; cursor= 0; } inline bool is_in_use() { return flags & (uint) IS_IN_USE; } - inline bool is_protocol_text() const { return protocol == &thd->protocol_text; } + inline bool is_sql_prepare() const { return flags & (uint) IS_SQL_PREPARE; } + void set_sql_prepare() { flags|= (uint) IS_SQL_PREPARE; } bool prepare(const char *packet, uint packet_length); bool execute_loop(String *expanded_query, bool open_cursor, @@ -716,9 +717,9 @@ static void setup_one_conversion_function(THD *thd, Item_param *param, prepared statement, parameter markers are replaced with variable names. Example: @verbatim - mysql_stmt_prepare("UPDATE t1 SET a=a*1.25 WHERE a=?") + mysqld_stmt_prepare("UPDATE t1 SET a=a*1.25 WHERE a=?") --> general logs gets [Prepare] UPDATE t1 SET a*1.25 WHERE a=?" - mysql_stmt_execute(stmt); + mysqld_stmt_execute(stmt); --> general and binary logs get [Execute] UPDATE t1 SET a*1.25 WHERE a=1" @endverbatim @@ -1360,7 +1361,7 @@ static int mysql_test_select(Prepared_statement *stmt, */ if (unit->prepare(thd, 0, 0)) goto error; - if (!lex->describe && !stmt->is_protocol_text()) + if (!lex->describe && !stmt->is_sql_prepare()) { /* Make copy of item list, as change_columns may change it */ List<Item> fields(lex->select_lex.item_list); @@ -1992,7 +1993,7 @@ static bool check_prepared_statement(Prepared_statement *stmt) break; } if (res == 0) - DBUG_RETURN(stmt->is_protocol_text() ? + DBUG_RETURN(stmt->is_sql_prepare() ? FALSE : (send_prep_stmt(stmt, 0) || thd->protocol->flush())); error: DBUG_RETURN(TRUE); @@ -2060,18 +2061,19 @@ static bool init_param_array(Prepared_statement *stmt) to the client, otherwise an error message is set in THD. */ -void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length) +void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length) { + Protocol *save_protocol= thd->protocol; Prepared_statement *stmt; bool error; - DBUG_ENTER("mysql_stmt_prepare"); + DBUG_ENTER("mysqld_stmt_prepare"); DBUG_PRINT("prep_query", ("%s", packet)); /* First of all clear possible warnings from the previous command */ mysql_reset_thd_for_next_command(thd); - if (! (stmt= new Prepared_statement(thd, &thd->protocol_binary))) + if (! (stmt= new Prepared_statement(thd))) DBUG_VOID_RETURN; /* out of memory: error is set in Sql_alloc */ if (thd->stmt_map.insert(thd, stmt)) @@ -2088,6 +2090,8 @@ void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length) sp_cache_flush_obsolete(&thd->sp_proc_cache); sp_cache_flush_obsolete(&thd->sp_func_cache); + thd->protocol= &thd->protocol_binary; + if (!(specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),QUERY_PRIOR); @@ -2101,6 +2105,9 @@ void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length) /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); } + + thd->protocol= save_protocol; + /* check_prepared_statemnt sends the metadata packet in case of success */ DBUG_VOID_RETURN; } @@ -2231,10 +2238,8 @@ void mysql_sql_stmt_prepare(THD *thd) LEX_STRING *name= &lex->prepared_stmt_name; Prepared_statement *stmt; const char *query; - uint query_len; + uint query_len= 0; DBUG_ENTER("mysql_sql_stmt_prepare"); - LINT_INIT(query_len); - DBUG_ASSERT(thd->protocol == &thd->protocol_text); if ((stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name))) { @@ -2252,11 +2257,13 @@ void mysql_sql_stmt_prepare(THD *thd) } if (! (query= get_dynamic_sql_string(lex, &query_len)) || - ! (stmt= new Prepared_statement(thd, &thd->protocol_text))) + ! (stmt= new Prepared_statement(thd))) { DBUG_VOID_RETURN; /* out of memory */ } + stmt->set_sql_prepare(); + /* Set the name first, insert should know that this statement has a name */ if (stmt->set_name(name)) { @@ -2427,7 +2434,7 @@ static void reset_stmt_params(Prepared_statement *stmt) client, otherwise an error message is set in THD. */ -void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length) +void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length) { uchar *packet= (uchar*)packet_arg; // GCC 4.0.1 workaround ulong stmt_id= uint4korr(packet); @@ -2436,8 +2443,9 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length) String expanded_query; uchar *packet_end= packet + packet_length; Prepared_statement *stmt; + Protocol *save_protocol= thd->protocol; bool open_cursor; - DBUG_ENTER("mysql_stmt_execute"); + DBUG_ENTER("mysqld_stmt_execute"); packet+= 9; /* stmt_id + 5 bytes of flags */ @@ -2448,7 +2456,7 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length) { char llbuf[22]; my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf), - llstr(stmt_id, llbuf), "mysql_stmt_execute"); + llstr(stmt_id, llbuf), "mysqld_stmt_execute"); DBUG_VOID_RETURN; } @@ -2463,7 +2471,12 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length) open_cursor= test(flags & (ulong) CURSOR_TYPE_READ_ONLY); + thd->protocol= &thd->protocol_binary; stmt->execute_loop(&expanded_query, open_cursor, packet, packet_end); + thd->protocol= save_protocol; + + /* Close connection socket; for use with client testing (Bug#43560). */ + DBUG_EXECUTE_IF("close_conn_after_stmt_execute", vio_close(thd->net.vio);); DBUG_VOID_RETURN; } @@ -2525,7 +2538,7 @@ void mysql_sql_stmt_execute(THD *thd) @param packet_length Length of packet */ -void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) +void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length) { /* assume there is always place for 8-16 bytes */ ulong stmt_id= uint4korr(packet); @@ -2533,7 +2546,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) Prepared_statement *stmt; Statement stmt_backup; Server_side_cursor *cursor; - DBUG_ENTER("mysql_stmt_fetch"); + DBUG_ENTER("mysqld_stmt_fetch"); /* First of all clear possible warnings from the previous command */ mysql_reset_thd_for_next_command(thd); @@ -2542,7 +2555,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) { char llbuf[22]; my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf), - llstr(stmt_id, llbuf), "mysql_stmt_fetch"); + llstr(stmt_id, llbuf), "mysqld_stmt_fetch"); DBUG_VOID_RETURN; } @@ -2583,9 +2596,9 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) This function resets statement to the state it was right after prepare. It can be used to: - - clear an error happened during mysql_stmt_send_long_data + - clear an error happened during mysqld_stmt_send_long_data - cancel long data stream for all placeholders without - having to call mysql_stmt_execute. + having to call mysqld_stmt_execute. - close an open cursor Sends 'OK' packet in case of success (statement was reset) or 'ERROR' packet (unrecoverable error/statement not found/etc). @@ -2594,12 +2607,12 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) @param packet Packet with stmt id */ -void mysql_stmt_reset(THD *thd, char *packet) +void mysqld_stmt_reset(THD *thd, char *packet) { /* There is always space for 4 bytes in buffer */ ulong stmt_id= uint4korr(packet); Prepared_statement *stmt; - DBUG_ENTER("mysql_stmt_reset"); + DBUG_ENTER("mysqld_stmt_reset"); /* First of all clear possible warnings from the previous command */ mysql_reset_thd_for_next_command(thd); @@ -2609,7 +2622,7 @@ void mysql_stmt_reset(THD *thd, char *packet) { char llbuf[22]; my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf), - llstr(stmt_id, llbuf), "mysql_stmt_reset"); + llstr(stmt_id, llbuf), "mysqld_stmt_reset"); DBUG_VOID_RETURN; } @@ -2617,7 +2630,7 @@ void mysql_stmt_reset(THD *thd, char *packet) /* Clear parameters from data which could be set by - mysql_stmt_send_long_data() call. + mysqld_stmt_send_long_data() call. */ reset_stmt_params(stmt); @@ -2638,12 +2651,12 @@ void mysql_stmt_reset(THD *thd, char *packet) we don't send any reply to this command. */ -void mysql_stmt_close(THD *thd, char *packet) +void mysqld_stmt_close(THD *thd, char *packet) { /* There is always space for 4 bytes in packet buffer */ ulong stmt_id= uint4korr(packet); Prepared_statement *stmt; - DBUG_ENTER("mysql_stmt_close"); + DBUG_ENTER("mysqld_stmt_close"); thd->main_da.disable_status(); @@ -2742,7 +2755,7 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length) stmt->state= Query_arena::ERROR; stmt->last_errno= ER_WRONG_ARGUMENTS; sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), - "mysql_stmt_send_long_data"); + "mysqld_stmt_send_long_data"); DBUG_VOID_RETURN; } #endif @@ -2815,12 +2828,11 @@ Select_fetch_protocol_binary::send_data(List<Item> &fields) Prepared_statement ****************************************************************************/ -Prepared_statement::Prepared_statement(THD *thd_arg, Protocol *protocol_arg) +Prepared_statement::Prepared_statement(THD *thd_arg) :Statement(NULL, &main_mem_root, INITIALIZED, ++thd_arg->statement_id_counter), thd(thd_arg), result(thd_arg), - protocol(protocol_arg), param_array(0), param_count(0), last_errno(0), @@ -3166,7 +3178,7 @@ Prepared_statement::set_parameters(String *expanded_query, if (res) { my_error(ER_WRONG_ARGUMENTS, MYF(0), - is_sql_ps ? "EXECUTE" : "mysql_stmt_execute"); + is_sql_ps ? "EXECUTE" : "mysqld_stmt_execute"); reset_stmt_params(this); } return res; @@ -3289,7 +3301,9 @@ Prepared_statement::reprepare() bool cur_db_changed; bool error; - Prepared_statement copy(thd, &thd->protocol_text); + Prepared_statement copy(thd); + + copy.set_sql_prepare(); /* To suppress sending metadata to the client. */ status_var_increment(thd->status_var.com_stmt_reprepare); @@ -3347,7 +3361,7 @@ bool Prepared_statement::validate_metadata(Prepared_statement *copy) return FALSE -- the metadata of the original SELECT, if any, has not been sent to the client. */ - if (is_protocol_text() || lex->describe) + if (is_sql_prepare() || lex->describe) return FALSE; if (lex->select_lex.item_list.elements != @@ -3410,7 +3424,6 @@ Prepared_statement::swap_prepared_statement(Prepared_statement *copy) DBUG_ASSERT(thd == copy->thd); last_error[0]= '\0'; last_errno= 0; - /* Do not swap protocols, the copy always has protocol_text */ } @@ -3551,8 +3564,6 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) thd->stmt_arena= this; reinit_stmt_before_use(thd, lex); - thd->protocol= protocol; /* activate stmt protocol */ - /* Go! */ if (open_cursor) @@ -3583,8 +3594,6 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) if (cur_db_changed) mysql_change_db(thd, &saved_cur_db_name, TRUE); - thd->protocol= &thd->protocol_text; /* use normal protocol */ - /* Assert that if an error, no cursor is open */ DBUG_ASSERT(! (error && cursor)); @@ -3621,11 +3630,11 @@ error: } -/** Common part of DEALLOCATE PREPARE and mysql_stmt_close. */ +/** Common part of DEALLOCATE PREPARE and mysqld_stmt_close. */ void Prepared_statement::deallocate() { - /* We account deallocate in the same manner as mysql_stmt_close */ + /* We account deallocate in the same manner as mysqld_stmt_close */ status_var_increment(thd->status_var.com_stmt_close); /* Statement map calls delete stmt on erase */ thd->stmt_map.erase(this); diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index fc87356e452..0e0b8eb60b9 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -244,7 +244,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name, char *new_table_alias, bool skip_error) { int rc= 1; - char name[FN_REFLEN]; + char name[FN_REFLEN + 1]; const char *new_alias, *old_alias; frm_type_enum frm_type; enum legacy_db_type table_type; @@ -261,14 +261,16 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name, old_alias= ren_table->table_name; new_alias= new_table_name; } - build_table_filename(name, sizeof(name), + DBUG_ASSERT(new_alias); + + build_table_filename(name, sizeof(name) - 1, new_db, new_alias, reg_ext, 0); if (!access(name,F_OK)) { my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias); DBUG_RETURN(1); // This can't be skipped } - build_table_filename(name, sizeof(name), + build_table_filename(name, sizeof(name) - 1, ren_table->db, old_alias, reg_ext, 0); frm_type= mysql_frm_type(thd, name, &table_type); @@ -301,12 +303,17 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name, } break; case FRMTYPE_VIEW: - /* change of schema is not allowed */ - if (strcmp(ren_table->db, new_db)) + /* + change of schema is not allowed + except of ALTER ...UPGRADE DATA DIRECTORY NAME command + because a view has valid internal db&table names in this case. + */ + if (thd->lex->sql_command != SQLCOM_ALTER_DB_UPGRADE && + strcmp(ren_table->db, new_db)) my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db, new_db); else - rc= mysql_rename_view(thd, new_alias, ren_table); + rc= mysql_rename_view(thd, new_db, new_alias, ren_table); break; default: DBUG_ASSERT(0); // should never happen diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 57319e4cda7..06489d8bbd3 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -147,7 +147,7 @@ static int send_file(THD *thd) if (errmsg) { sql_print_error("Failed in send_file() %s", errmsg); - DBUG_PRINT("error", (errmsg)); + DBUG_PRINT("error", ("%s", errmsg)); } DBUG_RETURN(error); } @@ -1026,7 +1026,10 @@ int reset_slave(THD *thd, Master_info* mi) if ((error= purge_relay_logs(&mi->rli, thd, 1 /* just reset */, &errmsg))) + { + sql_errno= ER_RELAY_LOG_FAIL; goto err; + } /* Clear master's log coordinates and reset host/user/etc to the values @@ -1040,6 +1043,7 @@ int reset_slave(THD *thd, Master_info* mi) Reset errors (the idea is that we forget about the old master). */ + mi->clear_error(); mi->rli.clear_error(); mi->rli.clear_until_condition(); @@ -1098,7 +1102,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) if (tmp->command == COM_BINLOG_DUMP && tmp->server_id == slave_server_id) { - pthread_mutex_lock(&tmp->LOCK_delete); // Lock from delete + pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete break; } } @@ -1111,7 +1115,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) again. We just to do kill the thread ourselves. */ tmp->awake(THD::KILL_QUERY); - pthread_mutex_unlock(&tmp->LOCK_delete); + pthread_mutex_unlock(&tmp->LOCK_thd_data); } } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1c05fbe6cc2..014b63c057c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -31,6 +31,7 @@ #include "mysql_priv.h" #include "sql_select.h" #include "sql_cursor.h" + #include <m_ctype.h> #include <my_bit.h> #include <hash.h> @@ -2279,6 +2280,14 @@ JOIN::destroy() cond_equal= 0; cleanup(1); + /* Cleanup items referencing temporary table columns */ + if (!tmp_all_fields3.is_empty()) + { + List_iterator_fast<Item> it(tmp_all_fields3); + Item *item; + while ((item= it++)) + item->cleanup(); + } if (exec_tmp_table1) free_tmp_table(thd, exec_tmp_table1); if (exec_tmp_table2) @@ -3358,6 +3367,27 @@ add_key_equal_fields(KEY_FIELD **key_fields, uint and_level, } +/** + Check if an expression is a non-outer field. + + Checks if an expression is a field and belongs to the current select. + + @param field Item expression to check + + @return boolean + @retval TRUE the expression is a local field + @retval FALSE it's something else +*/ + +inline static bool +is_local_field (Item *field) +{ + field= field->real_item(); + return field->type() == Item::FIELD_ITEM && + !((Item_field *)field)->depended_from; +} + + /* In this and other functions, and_level is a number that is ever-growing and is different for the contents of every AND or OR clause. For example, @@ -3452,13 +3482,12 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, { Item **values; // BETWEEN, IN, NE - if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM && + if (is_local_field (cond_func->key_item()) && !(cond_func->used_tables() & OUTER_REF_TABLE_BIT)) { values= cond_func->arguments()+1; if (cond_func->functype() == Item_func::NE_FUNC && - cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && - !(cond_func->arguments()[0]->used_tables() & OUTER_REF_TABLE_BIT)) + is_local_field (cond_func->arguments()[1])) values--; DBUG_ASSERT(cond_func->functype() != Item_func::IN_FUNC || cond_func->argument_count() != 2); @@ -3474,9 +3503,7 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, for (uint i= 1 ; i < cond_func->argument_count() ; i++) { Item_field *field_item; - if (cond_func->arguments()[i]->real_item()->type() == Item::FIELD_ITEM - && - !(cond_func->arguments()[i]->used_tables() & OUTER_REF_TABLE_BIT)) + if (is_local_field (cond_func->arguments()[i])) { field_item= (Item_field *) (cond_func->arguments()[i]->real_item()); add_key_equal_fields(key_fields, *and_level, cond_func, @@ -3492,8 +3519,7 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, bool equal_func=(cond_func->functype() == Item_func::EQ_FUNC || cond_func->functype() == Item_func::EQUAL_FUNC); - if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && - !(cond_func->arguments()[0]->used_tables() & OUTER_REF_TABLE_BIT)) + if (is_local_field (cond_func->arguments()[0])) { add_key_equal_fields(key_fields, *and_level, cond_func, (Item_field*) (cond_func->arguments()[0])->real_item(), @@ -3501,9 +3527,8 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, cond_func->arguments()+1, 1, usable_tables, sargables); } - if (cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && - cond_func->functype() != Item_func::LIKE_FUNC && - !(cond_func->arguments()[1]->used_tables() & OUTER_REF_TABLE_BIT)) + if (is_local_field (cond_func->arguments()[1]) && + cond_func->functype() != Item_func::LIKE_FUNC) { add_key_equal_fields(key_fields, *and_level, cond_func, (Item_field*) (cond_func->arguments()[1])->real_item(), @@ -3515,7 +3540,7 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, } case Item_func::OPTIMIZE_NULL: /* column_name IS [NOT] NULL */ - if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && + if (is_local_field (cond_func->arguments()[0]) && !(cond_func->used_tables() & OUTER_REF_TABLE_BIT)) { Item *tmp=new Item_null; @@ -3573,14 +3598,6 @@ add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, } } -/** - Add all keys with uses 'field' for some keypart. - - If field->and_level != and_level then only mark key_part as const_part. - - @todo - ft-keys in non-ft queries. SerG -*/ static uint max_part_bit(key_part_map bits) @@ -3590,7 +3607,16 @@ max_part_bit(key_part_map bits) return found; } -static void +/* + Add all keys with uses 'field' for some keypart + If field->and_level != and_level then only mark key_part as const_part + + RETURN + 0 - OK + 1 - Out of memory. +*/ + +static bool add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field) { Field *field=key_field->field; @@ -3620,24 +3646,26 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field) keyuse.optimize= key_field->optimize & KEY_OPTIMIZE_REF_OR_NULL; keyuse.null_rejecting= key_field->null_rejecting; keyuse.cond_guard= key_field->cond_guard; - VOID(insert_dynamic(keyuse_array,(uchar*) &keyuse)); + if (insert_dynamic(keyuse_array,(uchar*) &keyuse)) + return TRUE; } } } } + return FALSE; } #define FT_KEYPART (MAX_REF_PARTS+10) -static void +static bool add_ft_keys(DYNAMIC_ARRAY *keyuse_array, JOIN_TAB *stat,COND *cond,table_map usable_tables) { Item_func_match *cond_func=NULL; if (!cond) - return; + return FALSE; if (cond->type() == Item::FUNC_ITEM) { @@ -3671,13 +3699,16 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, { Item *item; while ((item=li++)) - add_ft_keys(keyuse_array,stat,item,usable_tables); + { + if (add_ft_keys(keyuse_array,stat,item,usable_tables)) + return TRUE; + } } } if (!cond_func || cond_func->key == NO_SUCH_KEY || !(usable_tables & cond_func->table->map)) - return; + return FALSE; KEYUSE keyuse; keyuse.table= cond_func->table; @@ -3687,7 +3718,7 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, keyuse.used_tables=cond_func->key_item()->used_tables(); keyuse.optimize= 0; keyuse.keypart_map= 0; - VOID(insert_dynamic(keyuse_array,(uchar*) &keyuse)); + return insert_dynamic(keyuse_array,(uchar*) &keyuse); } @@ -3841,7 +3872,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, sargables); for (; field != end ; field++) { - add_key_part(keyuse,field); + if (add_key_part(keyuse,field)) + return TRUE; /* Mark that we can optimize LEFT JOIN */ if (field->val->type() == Item::NULL_ITEM && !field->field->real_maybe_null()) @@ -3879,11 +3911,15 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, /* fill keyuse with found key parts */ for ( ; field != end ; field++) - add_key_part(keyuse,field); + { + if (add_key_part(keyuse,field)) + return TRUE; + } if (select_lex->ftfunc_list->elements) { - add_ft_keys(keyuse,join_tab,cond,normal_tables); + if (add_ft_keys(keyuse,join_tab,cond,normal_tables)) + return TRUE; } /* @@ -3904,7 +3940,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, (qsort_cmp) sort_keyuse); bzero((char*) &key_end,sizeof(key_end)); /* Add for easy testing */ - VOID(insert_dynamic(keyuse,(uchar*) &key_end)); + if (insert_dynamic(keyuse,(uchar*) &key_end)) + return TRUE; use=save_pos=dynamic_element(keyuse,0,KEYUSE*); prev= &key_end; @@ -6217,7 +6254,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) } } - if (tmp || !cond) + if (tmp || !cond || tab->type == JT_REF) { DBUG_EXECUTE("where",print_where(tmp,tab->table->alias, QT_ORDINARY);); SQL_SELECT *sel= tab->select= ((SQL_SELECT*) @@ -6231,7 +6268,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) The guard will turn the predicate on only after the first match for outer tables is encountered. */ - if (cond) + if (cond && tmp) { /* Because of QUICK_GROUP_MIN_MAX_SELECT there may be a select without @@ -7175,15 +7212,17 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables, if (!(result->send_fields(fields, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))) { + bool send_error= FALSE; if (send_row) { List_iterator_fast<Item> it(fields); Item *item; while ((item= it++)) item->no_rows_in_result(); - result->send_data(fields); + send_error= result->send_data(fields); } - result->send_eof(); // Should be safe + if (!send_error) + result->send_eof(); // Should be safe } /* Update results for FOUND_ROWS */ join->thd->limit_found_rows= join->thd->examined_row_count= 0; @@ -7435,8 +7474,7 @@ static bool check_simple_equality(Item *left_item, Item *right_item, left_item_equal->merge(right_item_equal); /* Remove the merged multiple equality from the list */ List_iterator<Item_equal> li(cond_equal->current_level); - while ((li++) != right_item_equal) - ; + while ((li++) != right_item_equal) ; li.remove(); } } @@ -12960,7 +12998,10 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, one row). The sorting doesn't matter. */ if (key_part == key_part_end && reverse == 0) + { + *used_key_parts= 0; DBUG_RETURN(1); + } } else DBUG_RETURN(0); @@ -13226,6 +13267,8 @@ find_field_in_item_list (Field *field, void *data) The index must cover all fields in <order>, or it will not be considered. + @param no_changes No changes will be made to the query plan. + @todo - sergeyp: Results of all index merge selects actually are ordered by clustered PK values. @@ -13430,12 +13473,20 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, for (nr=0; nr < table->s->keys ; nr++) { int direction; + if (keys.is_set(nr) && (direction= test_if_order_by_key(order, table, nr, &used_key_parts))) { - bool is_covering= (table->covering_keys.is_set(nr) || - (nr == table->s->primary_key && - table->file->primary_key_is_clustered())); + /* + At this point we are sure that ref_key is a non-ordering + key (where "ordering key" is a key that will return rows + in the order required by ORDER BY). + */ + DBUG_ASSERT (ref_key != (int) nr); + + bool is_covering= table->covering_keys.is_set(nr) || + (nr == table->s->primary_key && + table->file->primary_key_is_clustered()); /* Don't use an index scan with ORDER BY without limit. @@ -13457,7 +13508,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, select_limit= table_records; if (group) { - rec_per_key= keyinfo->rec_per_key[used_key_parts-1]; + rec_per_key= used_key_parts ? keyinfo->rec_per_key[used_key_parts-1] + : 1; set_if_bigger(rec_per_key, 1); /* With a grouping query each group containing on average @@ -13512,7 +13564,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, */ index_scan_time= select_limit/rec_per_key * min(rec_per_key, table->file->scan_time()); - if (is_covering || + if ((ref_key < 0 && is_covering) || (ref_key < 0 && (group || table->force_index)) || index_scan_time < read_time) { @@ -13554,6 +13606,15 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, } if (!no_changes) { + /* + If ref_key used index tree reading only ('Using index' in EXPLAIN), + and best_key doesn't, then revert the decision. + */ + if (!table->covering_keys.is_set(best_key) && table->key_read) + { + table->key_read= 0; + table->file->extra(HA_EXTRA_NO_KEYREAD); + } if (!quick_created) { tab->index= best_key; @@ -13570,16 +13631,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, table->key_read=1; table->file->extra(HA_EXTRA_KEYREAD); } - else if (table->key_read) - { - /* - Clear the covering key read flags that might have been - previously set for some key other than the current best_key. - */ - table->key_read= 0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } - table->file->ha_index_or_rnd_end(); if (join->select_options & SELECT_DESCRIBE) { @@ -13728,9 +13779,8 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, !(join->select_options & SELECT_BIG_RESULT) || (select && select->quick && select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)) && - test_if_skip_sort_order(tab,order,select_limit, 0, - is_order_by ? - &table->keys_in_use_for_order_by : + test_if_skip_sort_order(tab,order,select_limit,0, + is_order_by ? &table->keys_in_use_for_order_by : &table->keys_in_use_for_group_by)) DBUG_RETURN(0); for (ORDER *ord= join->order; ord; ord= ord->next) @@ -13789,8 +13839,24 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, tab->records= table->sort.found_records; // For SQL_CALC_ROWS if (select) { + /* + We need to preserve tablesort's output resultset here, because + QUICK_INDEX_MERGE_SELECT::~QUICK_INDEX_MERGE_SELECT (called by + SQL_SELECT::cleanup()) may free it assuming it's the result of the quick + select operation that we no longer need. Note that all the other parts of + this data structure are cleaned up when + QUICK_INDEX_MERGE_SELECT::get_next encounters end of data, so the next + SQL_SELECT::cleanup() call changes sort.io_cache alone. + */ + IO_CACHE *tablesort_result_cache; + + tablesort_result_cache= table->sort.io_cache; + table->sort.io_cache= NULL; + select->cleanup(); // filesort did select tab->select= 0; + table->quick_keys.clear_all(); // as far as we cleanup select->quick + table->sort.io_cache= tablesort_result_cache; } tab->select_cond=0; tab->last_inner= 0; @@ -14165,7 +14231,7 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length, pos->field= ((Item_sum*) item)->get_tmp_table_field(); else if (item->type() == Item::COPY_STR_ITEM) { // Blob patch - pos->item= ((Item_copy_string*) item)->item; + pos->item= ((Item_copy*) item)->get_item(); } else pos->item= *order->item; @@ -14989,8 +15055,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables) if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT))) DBUG_RETURN(0); - for (; !(map & tables->table->map); tables= tables->next_leaf) - ; + for (; !(map & tables->table->map); tables= tables->next_leaf) ; if (map != tables->table->map) DBUG_RETURN(0); // More than one table DBUG_PRINT("exit",("sort by table: %d",tables->table->tablenr)); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8f1e173b5e9..18e83498f7d 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1150,7 +1150,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, { const LEX_STRING *const db= table_list->schema_table ? &INFORMATION_SCHEMA_NAME : &table->s->db; - if (strcmp(db->str, thd->db) != 0) + if (!thd->db || strcmp(db->str, thd->db)) { append_identifier(thd, packet, db->str, db->length); packet->append(STRING_WITH_LEN(".")); @@ -1769,6 +1769,8 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) thd_info->start_time= tmp->start_time; thd_info->query=0; + /* Lock THD mutex that protects its data when looking at it. */ + pthread_mutex_lock(&tmp->LOCK_thd_data); if (tmp->query) { /* @@ -1779,6 +1781,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) uint length= min(max_query_length, tmp->query_length); thd_info->query=(char*) thd->strmake(tmp->query,length); } + pthread_mutex_unlock(&tmp->LOCK_thd_data); thread_infos.append(thd_info); } } @@ -2818,8 +2821,8 @@ make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex, LOOKUP_FIELD_VALUES *lookup_field_vals, bool with_i_schema, LEX_STRING *db_name) { - char path[FN_REFLEN]; - build_table_filename(path, sizeof(path), db_name->str, "", "", 0); + char path[FN_REFLEN + 1]; + build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0); if (!lookup_field_vals->wild_table_value && lookup_field_vals->table_value.str) { @@ -2981,8 +2984,8 @@ static int fill_schema_table_names(THD *thd, TABLE *table, else { enum legacy_db_type not_used; - char path[FN_REFLEN]; - (void) build_table_filename(path, sizeof(path), db_name->str, + char path[FN_REFLEN + 1]; + (void) build_table_filename(path, sizeof(path) - 1, db_name->str, table_name->str, reg_ext, 0); switch (mysql_frm_type(thd, path, ¬_used)) { case FRMTYPE_ERROR: @@ -3469,7 +3472,7 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond) MY_STAT stat_info; if (!lookup_field_vals.db_value.str[0]) DBUG_RETURN(0); - path_len= build_table_filename(path, sizeof(path), + path_len= build_table_filename(path, sizeof(path) - 1, lookup_field_vals.db_value.str, "", "", 0); path[path_len-1]= 0; if (!my_stat(path,&stat_info,MYF(0))) @@ -7060,6 +7063,12 @@ bool show_create_trigger(THD *thd, const sp_name *trg_name) if (!lst) return TRUE; + if (check_table_access(thd, TRIGGER_ACL, lst, 1, TRUE)) + { + my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "TRIGGER"); + return TRUE; + } + /* Open the table by name in order to load Table_triggers_list object. diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 8b4294c5caf..e9927c8e85c 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -322,12 +322,24 @@ bool String::set_or_copy_aligned(const char *str,uint32 arg_length, return copy_aligned(str, arg_length, offset, cs); } - /* Copy with charset conversion */ + +/** + Copies the character data into this String, with optional character set + conversion. + + @return + FALSE ok + TRUE Could not allocate result buffer + +*/ bool String::copy(const char *str, uint32 arg_length, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors) { uint32 offset; + + DBUG_ASSERT(!str || str != Ptr); + if (!needs_conversion(arg_length, from_cs, to_cs, &offset)) { *errors= 0; @@ -1167,3 +1179,76 @@ void String::swap(String &s) swap_variables(bool, alloced, s.alloced); swap_variables(CHARSET_INFO*, str_charset, s.str_charset); } + + +/** + Convert string to printable ASCII string + + @details This function converts input string "from" replacing non-ASCII bytes + with hexadecimal sequences ("\xXX") optionally appending "..." to the end of + the resulting string. + This function used in the ER_TRUNCATED_WRONG_VALUE_FOR_FIELD error messages, + e.g. when a string cannot be converted to a result charset. + + + @param to output buffer + @param to_len size of the output buffer (8 bytes or greater) + @param from input string + @param from_len size of the input string + @param from_cs input charset + @param nbytes maximal number of bytes to convert (from_len if 0) + + @return number of bytes in the output string +*/ + +uint convert_to_printable(char *to, size_t to_len, + const char *from, size_t from_len, + CHARSET_INFO *from_cs, size_t nbytes /*= 0*/) +{ + /* needs at least 8 bytes for '\xXX...' and zero byte */ + DBUG_ASSERT(to_len >= 8); + + char *t= to; + char *t_end= to + to_len - 1; // '- 1' is for the '\0' at the end + const char *f= from; + const char *f_end= from + (nbytes ? min(from_len, nbytes) : from_len); + char *dots= to; // last safe place to append '...' + + if (!f || t == t_end) + return 0; + + for (; t < t_end && f < f_end; f++) + { + /* + If the source string is ASCII compatible (mbminlen==1) + and the source character is in ASCII printable range (0x20..0x7F), + then display the character as is. + + Otherwise, if the source string is not ASCII compatible (e.g. UCS2), + or the source character is not in the printable range, + then print the character using HEX notation. + */ + if (((unsigned char) *f) >= 0x20 && + ((unsigned char) *f) <= 0x7F && + from_cs->mbminlen == 1) + { + *t++= *f; + } + else + { + if (t_end - t < 4) // \xXX + break; + *t++= '\\'; + *t++= 'x'; + *t++= _dig_vec_upper[((unsigned char) *f) >> 4]; + *t++= _dig_vec_upper[((unsigned char) *f) & 0x0F]; + } + if (t_end - t >= 3) // '...' + dots= t; + } + if (f < from + from_len) + memcpy(dots, STRING_WITH_LEN("...\0")); + else + *t= '\0'; + return t - to; +} diff --git a/sql/sql_string.h b/sql/sql_string.h index 9088863ac4d..9e22f7b6a27 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -40,6 +40,9 @@ uint32 well_formed_copy_nchars(CHARSET_INFO *to_cs, size_t my_copy_with_hex_escaping(CHARSET_INFO *cs, char *dst, size_t dstlen, const char *src, size_t srclen); +uint convert_to_printable(char *to, size_t to_len, + const char *from, size_t from_len, + CHARSET_INFO *from_cs, size_t nbytes= 0); class String { @@ -371,6 +374,19 @@ public: { return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length); } + bool is_ascii() const + { + if (length() == 0) + return TRUE; + if (charset()->mbminlen > 1) + return FALSE; + for (const char *c= ptr(), *end= c + length(); c < end; c++) + { + if (!my_isascii(*c)) + return FALSE; + } + return TRUE; + } }; static inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index eb01ab872a0..3aa9722c6ea 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -68,6 +68,234 @@ static void wait_for_kill_signal(THD *thd) #endif +/** + @brief Helper function for explain_filename +*/ +static char* add_identifier(char *to_p, const char * end_p, + const char* name, uint name_len, int errcode) +{ + uint res; + uint errors; + const char *conv_name; + char tmp_name[FN_REFLEN]; + char conv_string[FN_REFLEN]; + + DBUG_ENTER("add_identifier"); + if (!name[name_len]) + conv_name= name; + else + { + strnmov(tmp_name, name, name_len); + tmp_name[name_len]= 0; + conv_name= tmp_name; + } + res= strconvert(&my_charset_filename, conv_name, system_charset_info, + conv_string, FN_REFLEN, &errors); + if (!res || errors) + conv_name= name; + else + { + DBUG_PRINT("info", ("conv '%s' -> '%s'", conv_name, conv_string)); + conv_name= conv_string; + } + + if (errcode) + to_p+= my_snprintf(to_p, end_p - to_p, ER(errcode), conv_name); + else + to_p+= my_snprintf(to_p, end_p - to_p, "`%s`", conv_name); + return to_p; +} + + +/** + @brief Explain a path name by split it to database, table etc. + + @details Break down the path name to its logic parts + (database, table, partition, subpartition). + filename_to_tablename cannot be used on partitions, due to the #P# part. + There can be up to 6 '#', #P# for partition, #SP# for subpartition + and #TMP# or #REN# for temporary or renamed partitions. + This should be used when something should be presented to a user in a + diagnostic, error etc. when it would be useful to know what a particular + file [and directory] means. Such as SHOW ENGINE STATUS, error messages etc. + + @param from Path name in my_charset_filename + Null terminated in my_charset_filename, normalized + to use '/' as directory separation character. + @param to Explained name in system_charset_info + @param to_length Size of to buffer + @param explain_mode Requested output format. + EXPLAIN_ALL_VERBOSE -> + [Database `db`, ]Table `tbl`[,[ Temporary| Renamed] + Partition `p` [, Subpartition `sp`]] + EXPLAIN_PARTITIONS_VERBOSE -> `db`.`tbl` + [[ Temporary| Renamed] Partition `p` + [, Subpartition `sp`]] + EXPLAIN_PARTITIONS_AS_COMMENT -> `db`.`tbl` |* + [,[ Temporary| Renamed] Partition `p` + [, Subpartition `sp`]] *| + (| is really a /, and it is all in one line) + + @retval Length of returned string +*/ + +uint explain_filename(const char *from, + char *to, + uint to_length, + enum_explain_filename_mode explain_mode) +{ + uint res= 0; + char *to_p= to; + char *end_p= to_p + to_length; + const char *db_name= NULL; + int db_name_len= 0; + const char *table_name; + int table_name_len= 0; + const char *part_name= NULL; + int part_name_len= 0; + const char *subpart_name= NULL; + int subpart_name_len= 0; + enum enum_file_name_type {NORMAL, TEMP, RENAMED} name_type= NORMAL; + const char *tmp_p; + DBUG_ENTER("explain_filename"); + DBUG_PRINT("enter", ("from '%s'", from)); + tmp_p= from; + table_name= from; + /* + If '/' then take last directory part as database. + '/' is the directory separator, not FN_LIB_CHAR + */ + while ((tmp_p= strchr(tmp_p, '/'))) + { + db_name= table_name; + /* calculate the length */ + db_name_len= tmp_p - db_name; + tmp_p++; + table_name= tmp_p; + } + tmp_p= table_name; + while (!res && (tmp_p= strchr(tmp_p, '#'))) + { + tmp_p++; + switch (tmp_p[0]) { + case 'P': + case 'p': + if (tmp_p[1] == '#') + part_name= tmp_p + 2; + else + res= 1; + tmp_p+= 2; + break; + case 'S': + case 's': + if ((tmp_p[1] == 'P' || tmp_p[1] == 'p') && tmp_p[2] == '#') + { + part_name_len= tmp_p - part_name - 1; + subpart_name= tmp_p + 3; + } + else + res= 2; + tmp_p+= 3; + break; + case 'T': + case 't': + if ((tmp_p[1] == 'M' || tmp_p[1] == 'm') && + (tmp_p[2] == 'P' || tmp_p[2] == 'p') && + tmp_p[3] == '#' && !tmp_p[4]) + name_type= TEMP; + else + res= 3; + tmp_p+= 4; + break; + case 'R': + case 'r': + if ((tmp_p[1] == 'E' || tmp_p[1] == 'e') && + (tmp_p[2] == 'N' || tmp_p[2] == 'n') && + tmp_p[3] == '#' && !tmp_p[4]) + name_type= RENAMED; + else + res= 4; + tmp_p+= 4; + break; + default: + res= 5; + } + } + if (res) + { + /* Better to give something back if we fail parsing, than nothing at all */ + DBUG_PRINT("info", ("Error in explain_filename: %u", res)); + sql_print_warning("Invalid (old?) table or database name '%s'", from); + DBUG_RETURN(my_snprintf(to, to_length, + "<result %u when explaining filename '%s'>", + res, from)); + } + if (part_name) + { + table_name_len= part_name - table_name - 3; + if (subpart_name) + subpart_name_len= strlen(subpart_name); + else + part_name_len= strlen(part_name); + if (name_type != NORMAL) + { + if (subpart_name) + subpart_name_len-= 5; + else + part_name_len-= 5; + } + } + if (db_name) + { + if (explain_mode == EXPLAIN_ALL_VERBOSE) + { + to_p= add_identifier(to_p, end_p, db_name, db_name_len, + ER_DATABASE_NAME); + to_p= strnmov(to_p, ", ", end_p - to_p); + } + else + { + to_p= add_identifier(to_p, end_p, db_name, db_name_len, 0); + to_p= strnmov(to_p, ".", end_p - to_p); + } + } + if (explain_mode == EXPLAIN_ALL_VERBOSE) + to_p= add_identifier(to_p, end_p, table_name, table_name_len, + ER_TABLE_NAME); + else + to_p= add_identifier(to_p, end_p, table_name, table_name_len, 0); + if (part_name) + { + if (explain_mode == EXPLAIN_PARTITIONS_AS_COMMENT) + to_p= strnmov(to_p, " /* ", end_p - to_p); + else if (explain_mode == EXPLAIN_PARTITIONS_VERBOSE) + to_p= strnmov(to_p, " ", end_p - to_p); + else + to_p= strnmov(to_p, ", ", end_p - to_p); + if (name_type != NORMAL) + { + if (name_type == TEMP) + to_p= strnmov(to_p, ER(ER_TEMPORARY_NAME), end_p - to_p); + else + to_p= strnmov(to_p, ER(ER_RENAMED_NAME), end_p - to_p); + to_p= strnmov(to_p, " ", end_p - to_p); + } + to_p= add_identifier(to_p, end_p, part_name, part_name_len, + ER_PARTITION_NAME); + if (subpart_name) + { + to_p= strnmov(to_p, ", ", end_p - to_p); + to_p= add_identifier(to_p, end_p, subpart_name, subpart_name_len, + ER_SUBPARTITION_NAME); + } + if (explain_mode == EXPLAIN_PARTITIONS_AS_COMMENT) + to_p= strnmov(to_p, " */", end_p - to_p); + } + DBUG_PRINT("exit", ("to '%s'", to)); + DBUG_RETURN(to_p - to); +} + + /* Translate a file name to a table name (WL #1324). @@ -1287,7 +1515,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) /* Build shadow frm file name */ - build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt); + build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); strxmov(shadow_frm_name, shadow_path, reg_ext, NullS); if (flags & WFRM_WRITE_SHADOW) { @@ -1362,7 +1590,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) /* Build frm file name */ - build_table_filename(path, sizeof(path), lpt->db, + build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); strxmov(frm_name, path, reg_ext, NullS); /* @@ -1460,10 +1688,13 @@ void write_bin_log(THD *thd, bool clear_error, { if (mysql_bin_log.is_open()) { + int errcode= 0; if (clear_error) thd->clear_error(); + else + errcode= query_error_code(thd, TRUE); thd->binlog_query(THD::STMT_QUERY_TYPE, - query, query_length, FALSE, FALSE); + query, query_length, FALSE, FALSE, errcode); } } @@ -1561,13 +1792,14 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, bool dont_log_query) { TABLE_LIST *table; - char path[FN_REFLEN], *alias; + char path[FN_REFLEN + 1], *alias; uint path_length; String wrong_tables; int error= 0; int non_temp_tables_count= 0; bool some_tables_deleted=0, tmp_table_deleted=0, foreign_key_error=0; String built_query; + String built_tmp_query; DBUG_ENTER("mysql_rm_table_part2"); LINT_INIT(alias); @@ -1635,6 +1867,25 @@ 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->current_stmt_binlog_row_based) + { + if (built_tmp_query.is_empty()) + { + built_tmp_query.set_charset(system_charset_info); + built_tmp_query.append("DROP TEMPORARY TABLE IF EXISTS "); + } + + built_tmp_query.append("`"); + if (thd->db == NULL || strcmp(db,thd->db) != 0) + { + built_tmp_query.append(db); + built_tmp_query.append("`.`"); + } + built_tmp_query.append(table->table_name); + built_tmp_query.append("`,"); + } + continue; case -1: DBUG_ASSERT(thd->in_sub_stmt); @@ -1691,14 +1942,15 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } alias= (lower_case_table_names == 2) ? table->alias : table->table_name; /* remove .frm file and engine files */ - path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext, + path_length= build_table_filename(path, sizeof(path) - 1, db, alias, + reg_ext, table->internal_tmp_table ? FN_IS_TMP : 0); } if (drop_temporary || - ((table_type == NULL && - (access(path, F_OK) && - ha_create_table_from_engine(thd, db, alias))) || + ((table_type == NULL && + access(path, F_OK) && + ha_create_table_from_engine(thd, db, alias)) || (!drop_view && mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE))) { @@ -1791,29 +2043,52 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, write_bin_log(thd, !error, thd->query, thd->query_length); } else if (thd->current_stmt_binlog_row_based && - non_temp_tables_count > 0 && tmp_table_deleted) { + if (non_temp_tables_count > 0) + { + /* + In this case we have deleted both temporary and + non-temporary tables, so: + - since we have deleted a non-temporary table we have to + binlog the statement, but + - since we have deleted a temporary table we cannot binlog + the statement (since the table may have not been created on the + slave - check "if" branch below, this might cause the slave to + stop). + + Instead, we write a built statement, only containing the + non-temporary tables, to the binary log + */ + built_query.chop(); // Chop of the last comma + built_query.append(" /* generated by server */"); + write_bin_log(thd, !error, built_query.ptr(), built_query.length()); + } + /* - In this case we have deleted both temporary and - non-temporary tables, so: - - since we have deleted a non-temporary table we have to - binlog the statement, but - - since we have deleted a temporary table we cannot binlog - the statement (since the table has not been created on the - slave, this might cause the slave to stop). - - Instead, we write a built statement, only containing the - non-temporary tables, to the binary log + 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. */ - built_query.chop(); // Chop of the last comma - built_query.append(" /* generated by server */"); - write_bin_log(thd, !error, built_query.ptr(), built_query.length()); + if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED) + { + /* + In this case we have deleted some temporary tables but we are using + row based logging for the statement. However, thread uses mixed mode + format, thence we need to log the dropping as we cannot tell for + sure whether the create was logged as statement previously or not, ie, + before switching to row mode. + */ + built_tmp_query.chop(); // Chop of the last comma + built_tmp_query.append(" /* generated by server */"); + write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length()); + } } + /* The remaining cases are: - - no tables where deleted and - - only temporary tables where deleted and row-based + - no tables were deleted and + - only temporary tables were deleted and row-based replication is used. In both these cases, nothing should be written to the binary log. @@ -1847,11 +2122,11 @@ err_with_placeholders: bool quick_rm_table(handlerton *base,const char *db, const char *table_name, uint flags) { - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; bool error= 0; DBUG_ENTER("quick_rm_table"); - uint path_length= build_table_filename(path, sizeof(path), + uint path_length= build_table_filename(path, sizeof(path) - 1, db, table_name, reg_ext, flags); if (my_delete(path,MYF(0))) error= 1; /* purecov: inspected */ @@ -3126,7 +3401,7 @@ static bool prepare_blob_field(THD *thd, Create_field *sql_field) } sql_field->sql_type= MYSQL_TYPE_BLOB; sql_field->flags|= BLOB_FLAG; - sprintf(warn_buff, ER(ER_AUTO_CONVERT), sql_field->field_name, + my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_AUTO_CONVERT), sql_field->field_name, (sql_field->charset == &my_charset_bin) ? "VARBINARY" : "VARCHAR", (sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT"); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT, @@ -3240,7 +3515,7 @@ bool mysql_create_table_no_lock(THD *thd, bool internal_tmp_table, uint select_field_count) { - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; uint path_length; const char *alias; uint db_options, key_count; @@ -3449,7 +3724,7 @@ bool mysql_create_table_no_lock(THD *thd, } else { - path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext, + path_length= build_table_filename(path, sizeof(path) - 1, db, alias, reg_ext, internal_tmp_table ? FN_IS_TMP : 0); } @@ -3770,7 +4045,8 @@ mysql_rename_table(handlerton *base, const char *old_db, const char *new_name, uint flags) { THD *thd= current_thd; - char from[FN_REFLEN], to[FN_REFLEN], lc_from[FN_REFLEN], lc_to[FN_REFLEN]; + char from[FN_REFLEN + 1], to[FN_REFLEN + 1], + lc_from[FN_REFLEN + 1], lc_to[FN_REFLEN + 1]; char *from_base= from, *to_base= to; char tmp_name[NAME_LEN+1]; handler *file; @@ -3782,9 +4058,9 @@ mysql_rename_table(handlerton *base, const char *old_db, file= (base == NULL ? 0 : get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base)); - build_table_filename(from, sizeof(from), old_db, old_name, "", + build_table_filename(from, sizeof(from) - 1, old_db, old_name, "", flags & FN_FROM_IS_TMP); - build_table_filename(to, sizeof(to), new_db, new_name, "", + build_table_filename(to, sizeof(to) - 1, new_db, new_name, "", flags & FN_TO_IS_TMP); /* @@ -3797,13 +4073,13 @@ mysql_rename_table(handlerton *base, const char *old_db, { strmov(tmp_name, old_name); my_casedn_str(files_charset_info, tmp_name); - build_table_filename(lc_from, sizeof(lc_from), old_db, tmp_name, "", + build_table_filename(lc_from, sizeof(lc_from) - 1, old_db, tmp_name, "", flags & FN_FROM_IS_TMP); from_base= lc_from; strmov(tmp_name, new_name); my_casedn_str(files_charset_info, tmp_name); - build_table_filename(lc_to, sizeof(lc_to), new_db, tmp_name, "", + build_table_filename(lc_to, sizeof(lc_to) - 1, new_db, tmp_name, "", flags & FN_TO_IS_TMP); to_base= lc_to; } @@ -3935,16 +4211,16 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table, else { char* backup_dir= thd->lex->backup_dir; - char src_path[FN_REFLEN], dst_path[FN_REFLEN], uname[FN_REFLEN]; + char src_path[FN_REFLEN], dst_path[FN_REFLEN + 1], uname[FN_REFLEN]; char* table_name= table->table_name; char* db= table->db; - VOID(tablename_to_filename(table->table_name, uname, sizeof(uname))); + VOID(tablename_to_filename(table->table_name, uname, sizeof(uname) - 1)); if (fn_format_relative_to_data_home(src_path, uname, backup_dir, reg_ext)) DBUG_RETURN(-1); // protect buffer overflow - build_table_filename(dst_path, sizeof(dst_path), + build_table_filename(dst_path, sizeof(dst_path) - 1, db, table_name, reg_ext, 0); if (lock_and_wait_for_table_name(thd,table)) @@ -4556,7 +4832,7 @@ send_result_message: const char *err_msg= thd->main_da.message(); if (!thd->vio_ok()) { - sql_print_error(err_msg); + sql_print_error("%s", err_msg); } else { @@ -4866,7 +5142,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, HA_CREATE_INFO *create_info) { TABLE *name_lock= 0; - char src_path[FN_REFLEN], dst_path[FN_REFLEN]; + char src_path[FN_REFLEN], dst_path[FN_REFLEN + 1]; uint dst_path_length; char *db= table->db; char *table_name= table->table_name; @@ -4876,7 +5152,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, #ifdef WITH_PARTITION_STORAGE_ENGINE char tmp_path[FN_REFLEN]; #endif - char ts_name[FN_LEN]; + char ts_name[FN_LEN + 1]; DBUG_ENTER("mysql_create_like_table"); @@ -4925,7 +5201,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, goto err; if (!name_lock) goto table_exists; - dst_path_length= build_table_filename(dst_path, sizeof(dst_path), + dst_path_length= build_table_filename(dst_path, sizeof(dst_path) - 1, db, table_name, reg_ext, 0); if (!access(dst_path, F_OK)) goto table_exists; @@ -5680,7 +5956,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, if (!create_info->tablespace && create_info->storage_media != HA_SM_MEMORY) { - char *tablespace= static_cast<char *>(thd->alloc(FN_LEN)); + char *tablespace= static_cast<char *>(thd->alloc(FN_LEN + 1)); /* Regular alter table of disk stored table (no tablespace/storage change) Copy tablespace name @@ -6049,10 +6325,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { TABLE *table, *new_table= 0, *name_lock= 0; int error= 0; - char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN]; + char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN + 1]; char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias; char index_file[FN_REFLEN], data_file[FN_REFLEN]; - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; char reg_path[FN_REFLEN+1]; ha_rows copied,deleted; handlerton *old_db_type, *new_db_type, *save_old_db_type; @@ -6065,20 +6341,14 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, #endif bool need_lock_for_indexes= TRUE; KEY *key_info_buffer; - uint index_drop_count; - uint *index_drop_buffer; - uint index_add_count; - uint *index_add_buffer; - uint candidate_key_count; + uint index_drop_count= 0; + uint *index_drop_buffer= NULL; + uint index_add_count= 0; + uint *index_add_buffer= NULL; + uint candidate_key_count= 0; bool no_pk; DBUG_ENTER("mysql_alter_table"); - LINT_INIT(index_add_count); - LINT_INIT(index_drop_count); - LINT_INIT(index_add_buffer); - LINT_INIT(index_drop_buffer); - LINT_INIT(candidate_key_count); - /* Check if we attempt to alter mysql.slow_log or mysql.general_log table and return an error if @@ -6132,8 +6402,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, db=table_list->db; if (!new_db || !my_strcasecmp(table_alias_charset, new_db, db)) new_db= db; - build_table_filename(reg_path, sizeof(reg_path), db, table_name, reg_ext, 0); - build_table_filename(path, sizeof(path), db, table_name, "", 0); + build_table_filename(reg_path, sizeof(reg_path) - 1, db, table_name, reg_ext, 0); + build_table_filename(path, sizeof(path) - 1, db, table_name, "", 0); mysql_ha_rm_tables(thd, table_list, FALSE); @@ -6164,6 +6434,20 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME)) { /* + The following branch handles "ALTER VIEW v1 /no arguments/;" + This feature is not documented one. + However, before "OPTIMIZE TABLE t1;" was implemented, + ALTER TABLE with no alter_specifications was used to force-rebuild + the table. That's why this grammar is allowed. That's why we ignore + it for views. So just do nothing in such a case. + */ + if (!new_name) + { + my_ok(thd); + DBUG_RETURN(FALSE); + } + + /* Avoid problems with a rename on a table that we have locked or if the user is trying to to do this in a transcation context */ @@ -6189,7 +6473,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (mysql_bin_log.is_open()) { thd->clear_error(); - Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE); + Query_log_event qinfo(thd, thd->query, thd->query_length, + 0, FALSE, 0); mysql_bin_log.write(&qinfo); } my_ok(thd); @@ -6265,7 +6550,7 @@ view_err: DBUG_RETURN(TRUE); } - build_table_filename(new_name_buff, sizeof(new_name_buff), + build_table_filename(new_name_buff, sizeof(new_name_buff) - 1, new_db, new_name_buff, reg_ext, 0); if (!access(new_name_buff, F_OK)) { @@ -6766,9 +7051,9 @@ view_err: } else { - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; /* table is a normal table: Create temporary table in same directory */ - build_table_filename(path, sizeof(path), new_db, tmp_name, "", + build_table_filename(path, sizeof(path) - 1, new_db, tmp_name, "", FN_IS_TMP); /* Open our intermediate table */ new_table=open_temporary_table(thd, path, new_db, tmp_name,0); @@ -7095,7 +7380,7 @@ view_err: */ char path[FN_REFLEN]; TABLE *t_table; - build_table_filename(path, sizeof(path), new_db, table_name, "", 0); + build_table_filename(path + 1, sizeof(path) - 1, new_db, table_name, "", 0); t_table= open_temporary_table(thd, path, new_db, tmp_name, 0); if (t_table) { @@ -7519,6 +7804,16 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, { for (;;) { + if (thd->killed) + { + /* + we've been killed; let handler clean up, and remove the + partial current row from the recordset (embedded lib) + */ + t->file->ha_rnd_end(); + thd->protocol->remove_last_row(); + goto err; + } ha_checksum row_crc= 0; int error= t->file->rnd_next(t->record[0]); if (unlikely(error)) diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 78932396efe..eeb9a21b6f5 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -33,18 +33,20 @@ static const char *lock_descriptions[] = { - "No lock", - "Low priority read lock", - "Shared Read lock", - "High priority read lock", - "Read lock without concurrent inserts", - "Write lock that allows other writers", - "Write lock, but allow reading", - "Concurrent insert lock", - "Lock Used by delayed insert", - "Low priority write lock", - "High priority write lock", - "Highest priority write lock" + /* TL_UNLOCK */ "No lock", + /* TL_READ_DEFAULT */ NULL, + /* TL_READ */ "Low priority read lock", + /* TL_READ_WITH_SHARED_LOCKS */ "Shared read lock", + /* TL_READ_HIGH_PRIORITY */ "High priority read lock", + /* TL_READ_NO_INSERT */ "Read lock without concurrent inserts", + /* TL_WRITE_ALLOW_WRITE */ "Write lock that allows other writers", + /* TL_WRITE_ALLOW_READ */ "Write lock, but allow reading", + /* TL_WRITE_CONCURRENT_INSERT */ "Concurrent insert lock", + /* TL_WRITE_DELAYED */ "Lock used by delayed insert", + /* TL_WRITE_DEFAULT */ NULL, + /* TL_WRITE_LOW_PRIORITY */ "Low priority write lock", + /* TL_WRITE */ "High priority write lock", + /* TL_WRITE_ONLY */ "Highest priority write lock" }; @@ -75,6 +77,8 @@ void print_cached_tables(void) uint idx,count,unused; TABLE *start_link,*lnk; + compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions)); + /* purecov: begin tested */ VOID(pthread_mutex_lock(&LOCK_open)); puts("DB Table Version Thread Open Lock"); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 68a614c710e..1a7e171edf3 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -653,10 +653,22 @@ bool st_select_lex_unit::cleanup() join->tables= 0; } error|= fake_select_lex->cleanup(); - if (fake_select_lex->order_list.elements) + /* + There are two cases when we should clean order items: + 1. UNION with SELECTs which all enclosed into braces + in this case global_parameters == fake_select_lex + 2. UNION where last SELECT is not enclosed into braces + in this case global_parameters == 'last select' + So we should use global_parameters->order_list for + proper order list clean up. + Note: global_parameters and fake_select_lex are always + initialized for UNION + */ + DBUG_ASSERT(global_parameters); + if (global_parameters->order_list.elements) { ORDER *ord; - for (ord= (ORDER*)fake_select_lex->order_list.first; ord; ord= ord->next) + for (ord= (ORDER*)global_parameters->order_list.first; ord; ord= ord->next) (*ord->item)->cleanup(); } } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 302624a0e33..4c9a50000aa 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -292,7 +292,7 @@ int mysql_update(THD *thd, if (select_lex->inner_refs_list.elements && fix_inner_refs(thd, all_fields, select_lex, select_lex->ref_pointer_array)) - DBUG_RETURN(-1); + DBUG_RETURN(1); if (conds) { @@ -332,7 +332,14 @@ int mysql_update(THD *thd, { delete select; free_underlaid_joins(thd, select_lex); - if (error) + /* + There was an error or the error was already sent by + the quick select evaluation. + TODO: Add error code output parameter to Item::val_xxx() methods. + Currently they rely on the user checking DA for + errors when unwinding the stack after calling Item::val_xxx(). + */ + if (error || thd->is_error()) { DBUG_RETURN(1); // Error in where } @@ -795,12 +802,15 @@ int mysql_update(THD *thd, { if (mysql_bin_log.is_open()) { + int errcode= 0; if (error < 0) thd->clear_error(); + else + errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); + if (thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - transactional_table, FALSE, killed_status) && - transactional_table) + transactional_table, FALSE, errcode)) { error=1; // Rollback update } @@ -818,7 +828,7 @@ int mysql_update(THD *thd, if (error < 0) { char buff[STRING_BUFFER_USUAL_SIZE]; - sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated, + 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; @@ -1031,7 +1041,6 @@ reopen_tables: DBUG_RETURN(TRUE); } - table->mark_columns_needed_for_update(); DBUG_PRINT("info",("setting table `%s` for update", tl->alias)); /* If table will be updated we should not downgrade lock for it and @@ -1275,12 +1284,40 @@ int multi_update::prepare(List<Item> ¬_used_values, } /* + We gather the set of columns read during evaluation of SET expression in + TABLE::tmp_set by pointing TABLE::read_set to it and then restore it after + setup_fields(). + */ + for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf) + { + TABLE *table= table_ref->table; + if (tables_to_update & table->map) + { + DBUG_ASSERT(table->read_set == &table->def_read_set); + table->read_set= &table->tmp_set; + bitmap_clear_all(table->read_set); + } + } + + /* We have to check values after setup_tables to get covering_keys right in reference tables */ - if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0)) - DBUG_RETURN(1); + int error= setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0); + + for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf) + { + TABLE *table= table_ref->table; + if (tables_to_update & table->map) + { + table->read_set= &table->def_read_set; + bitmap_union(table->read_set, &table->tmp_set); + } + } + + if (error) + DBUG_RETURN(1); /* Save tables beeing updated in update_tables @@ -1375,6 +1412,8 @@ int multi_update::prepare(List<Item> ¬_used_values, a row in this table will never be read twice. This is true under the following conditions: + - No column is both written to and read in SET expressions. + - We are doing a table scan and the data is in a separate file (MyISAM) or if we don't update a clustered key. @@ -1389,6 +1428,9 @@ int multi_update::prepare(List<Item> ¬_used_values, WARNING This code is a bit dependent of how make_join_readinfo() works. + The field table->tmp_set is used for keeping track of which fields are + read during evaluation of the SET expression. See multi_update::prepare. + RETURN 0 Not safe to update 1 Safe to update @@ -1409,6 +1451,8 @@ static bool safe_update_on_fly(THD *thd, JOIN_TAB *join_tab, case JT_REF_OR_NULL: return !is_key_used(table, join_tab->ref.key, table->write_set); case JT_ALL: + if (bitmap_is_overlapping(&table->tmp_set, table->write_set)) + return FALSE; /* If range search on index */ if (join_tab->quick) return !join_tab->quick->is_keys_used(table->write_set); @@ -1464,17 +1508,18 @@ multi_update::initialize_tables(JOIN *join) ORDER group; TMP_TABLE_PARAM *tmp_param; - table->mark_columns_needed_for_update(); if (ignore) table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); if (table == main_table) // First table in join { if (safe_update_on_fly(thd, join->join_tab, table_ref, all_tables)) { - table_to_update= main_table; // Update table on the fly + table->mark_columns_needed_for_update(); + table_to_update= table; // Update table on the fly continue; } } + table->mark_columns_needed_for_update(); table->prepare_for_position(); /* @@ -1812,9 +1857,10 @@ void multi_update::abort() got caught and if happens later the killed error is written into repl event. */ + int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - transactional_tables, FALSE); + transactional_tables, FALSE, errcode); } thd->transaction.all.modified_non_trans_table= TRUE; } @@ -2040,12 +2086,14 @@ bool multi_update::send_eof() { if (mysql_bin_log.is_open()) { + int errcode= 0; if (local_error == 0) thd->clear_error(); + else + errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); if (thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, - transactional_tables, FALSE, killed_status) && - trans_safe) + transactional_tables, FALSE, errcode)) { local_error= 1; // Rollback update } @@ -2066,8 +2114,8 @@ bool multi_update::send_eof() id= thd->arg_of_last_insert_id_function ? thd->first_successful_insert_id_in_prev_stmt : 0; - sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated, - (ulong) thd->cuted_fields); + 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); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 07ab7df0d92..1b210226992 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -661,8 +661,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, buff.append(STRING_WITH_LEN(" AS ")); buff.append(views->source.str, views->source.length); + int errcode= query_error_code(thd, TRUE); thd->binlog_query(THD::STMT_QUERY_TYPE, - buff.ptr(), buff.length(), FALSE, FALSE); + buff.ptr(), buff.length(), FALSE, FALSE, errcode); } VOID(pthread_mutex_unlock(&LOCK_open)); @@ -800,7 +801,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, char md5[MD5_BUFF_LENGTH]; bool can_be_merged; - char dir_buff[FN_REFLEN], path_buff[FN_REFLEN]; + char dir_buff[FN_REFLEN + 1], path_buff[FN_REFLEN + 1]; LEX_STRING dir, file, path; int error= 0; DBUG_ENTER("mysql_register_view"); @@ -877,11 +878,11 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, } loop_out: /* print file name */ - dir.length= build_table_filename(dir_buff, sizeof(dir_buff), + dir.length= build_table_filename(dir_buff, sizeof(dir_buff) - 1, view->db, "", "", 0); dir.str= dir_buff; - path.length= build_table_filename(path_buff, sizeof(path_buff), + path.length= build_table_filename(path_buff, sizeof(path_buff) - 1, view->db, view->table_name, reg_ext, 0); path.str= path_buff; @@ -1567,7 +1568,7 @@ err: bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) { - char path[FN_REFLEN]; + char path[FN_REFLEN + 1]; TABLE_LIST *view; String non_existant_views; char *wrong_object_db= NULL, *wrong_object_name= NULL; @@ -1582,7 +1583,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) { TABLE_SHARE *share; frm_type_enum type= FRMTYPE_ERROR; - build_table_filename(path, sizeof(path), + build_table_filename(path, sizeof(path) - 1, view->db, view->table_name, reg_ext, 0); if (access(path, F_OK) || @@ -1911,6 +1912,7 @@ int view_checksum(THD *thd, TABLE_LIST *view) Parameters: thd thread handler + new_db new name of database new_name new name of view view view @@ -1920,12 +1922,13 @@ int view_checksum(THD *thd, TABLE_LIST *view) */ bool mysql_rename_view(THD *thd, + const char *new_db, const char *new_name, TABLE_LIST *view) { LEX_STRING pathstr; File_parser *parser; - char path_buff[FN_REFLEN]; + char path_buff[FN_REFLEN + 1]; bool error= TRUE; DBUG_ENTER("mysql_rename_view"); @@ -1938,7 +1941,7 @@ mysql_rename_view(THD *thd, is_equal(&view_type, parser->type())) { TABLE_LIST view_def; - char dir_buff[FN_REFLEN]; + char dir_buff[FN_REFLEN + 1]; LEX_STRING dir, file; /* @@ -1958,16 +1961,16 @@ mysql_rename_view(THD *thd, goto err; /* rename view and it's backups */ - if (rename_in_schema_file(thd, view->db, view->table_name, new_name)) + if (rename_in_schema_file(thd, view->db, view->table_name, new_db, new_name)) goto err; dir.str= dir_buff; dir.length= build_table_filename(dir_buff, sizeof(dir_buff) - 1, - view->db, "", "", 0); + new_db, "", "", 0); pathstr.str= path_buff; pathstr.length= build_table_filename(path_buff, sizeof(path_buff) - 1, - view->db, new_name, reg_ext, 0); + new_db, new_name, reg_ext, 0); file.str= pathstr.str + dir.length; file.length= pathstr.length - dir.length; @@ -1976,7 +1979,7 @@ mysql_rename_view(THD *thd, (uchar*)&view_def, view_parameters)) { /* restore renamed view in case of error */ - rename_in_schema_file(thd, view->db, new_name, view->table_name); + rename_in_schema_file(thd, new_db, new_name, view->db, view->table_name); goto err; } } else diff --git a/sql/sql_view.h b/sql/sql_view.h index b8138663489..e08c2168e14 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -37,7 +37,8 @@ int view_checksum(THD *thd, TABLE_LIST *view); extern TYPELIB updatable_views_with_limit_typelib; bool check_duplicate_names(List<Item>& item_list, bool gen_unique_view_names); -bool mysql_rename_view(THD *thd, const char *new_name, TABLE_LIST *view); +bool mysql_rename_view(THD *thd, const char *new_db, const char *new_name, + TABLE_LIST *view); #define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 34d3bbf5887..e08e44d34d7 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -47,6 +47,12 @@ #include <myisam.h> #include <myisammrg.h> +/* this is to get the bison compilation windows warnings out */ +#ifdef _MSC_VER +/* warning C4065: switch statement contains 'default' but no 'case' labels */ +#pragma warning (disable : 4065) +#endif + int yylex(void *yylval, void *yythd); const LEX_STRING null_lex_str= {0,0}; @@ -280,9 +286,7 @@ int case_stmt_action_expr(LEX *lex, Item* expr) parsing_ctx, case_expr_id, expr, lex); sp->add_cont_backpatch(i); - sp->add_instr(i); - - return 0; + return sp->add_instr(i); } /** @@ -293,7 +297,7 @@ int case_stmt_action_expr(LEX *lex, Item* expr) @param simple true for simple cases, false for searched cases */ -void case_stmt_action_when(LEX *lex, Item *when, bool simple) +int case_stmt_action_when(LEX *lex, Item *when, bool simple) { sp_head *sp= lex->sphead; sp_pcontext *ctx= lex->spcont; @@ -325,9 +329,10 @@ void case_stmt_action_when(LEX *lex, Item *when, bool simple) (jump_if_not from instruction 2 to 5, 5 to 8 ... in the example) */ - sp->push_backpatch(i, ctx->push_label((char *)"", 0)); - sp->add_cont_backpatch(i); - sp->add_instr(i); + return !test(i) || + sp->push_backpatch(i, ctx->push_label((char *)"", 0)) || + sp->add_cont_backpatch(i) || + sp->add_instr(i); } /** @@ -336,13 +341,14 @@ void case_stmt_action_when(LEX *lex, Item *when, bool simple) @param lex the parser lex context */ -void case_stmt_action_then(LEX *lex) +int case_stmt_action_then(LEX *lex) { sp_head *sp= lex->sphead; sp_pcontext *ctx= lex->spcont; uint ip= sp->instructions(); sp_instr_jump *i = new sp_instr_jump(ip, ctx); - sp->add_instr(i); + if (!test(i) || sp->add_instr(i)) + return 1; /* BACKPATCH: Resolving forward jump from @@ -358,7 +364,7 @@ void case_stmt_action_then(LEX *lex) (jump from instruction 4 to 12, 7 to 12 ... in the example) */ - sp->push_backpatch(i, ctx->last_label()); + return sp->push_backpatch(i, ctx->last_label()); } /** @@ -2322,10 +2328,9 @@ sp_decl: var_type, lex, (i == num_vars - 1)); - if (is == NULL) + if (is == NULL || + lex->sphead->add_instr(is)) MYSQL_YYABORT; - - lex->sphead->add_instr(is); } pctx->declare_var_boundary(0); @@ -2339,12 +2344,13 @@ sp_decl: LEX *lex= Lex; sp_pcontext *spc= lex->spcont; - if (spc->find_cond(&$2, TRUE)) - { - my_error(ER_SP_DUP_COND, MYF(0), $2.str); + if (spc->find_cond(&$2, TRUE)) + { + my_error(ER_SP_DUP_COND, MYF(0), $2.str); + MYSQL_YYABORT; + } + if(YYTHD->lex->spcont->push_cond(&$2, $5)) MYSQL_YYABORT; - } - YYTHD->lex->spcont->push_cond(&$2, $5); $$.vars= $$.hndlrs= $$.curs= 0; $$.conds= 1; } @@ -2358,11 +2364,11 @@ sp_decl: sp_pcontext *ctx= lex->spcont; sp_instr_hpush_jump *i= new sp_instr_hpush_jump(sp->instructions(), ctx, $2, - ctx->current_var_count()); - if (i == NULL) + ctx->current_var_count()); + if (i == NULL || + sp->add_instr(i) || + sp->push_backpatch(i, ctx->push_label((char *)"", 0))) MYSQL_YYABORT; - sp->add_instr(i); - sp->push_backpatch(i, ctx->push_label((char *)"", 0)); } sp_hcond_list sp_proc_stmt { @@ -2376,17 +2382,17 @@ sp_decl: { i= new sp_instr_hreturn(sp->instructions(), ctx, ctx->current_var_count()); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } else { /* EXIT or UNDO handler, just jump to the end of the block */ i= new sp_instr_hreturn(sp->instructions(), ctx, 0); - if (i == NULL) + if (i == NULL || + sp->add_instr(i) || + sp->push_backpatch(i, lex->spcont->last_label())) /* Block end */ MYSQL_YYABORT; - sp->add_instr(i); - sp->push_backpatch(i, lex->spcont->last_label()); /* Block end */ } lex->sphead->backpatch(hlab); @@ -2412,10 +2418,10 @@ sp_decl: } i= new sp_instr_cpush(sp->instructions(), ctx, $5, ctx->current_cursor_count()); - if (i == NULL) + if (i == NULL || + sp->add_instr(i) || + ctx->push_cursor(&$2)) MYSQL_YYABORT; - sp->add_instr(i); - ctx->push_cursor(&$2); $$.vars= $$.conds= $$.hndlrs= 0; $$.curs= 1; } @@ -2652,10 +2658,11 @@ sp_proc_stmt_statement: i->m_query.length= lip->get_ptr() - sp->m_tmp_query; else i->m_query.length= lip->get_tok_end() - sp->m_tmp_query; - i->m_query.str= strmake_root(thd->mem_root, - sp->m_tmp_query, - i->m_query.length); - sp->add_instr(i); + if (!(i->m_query.str= strmake_root(thd->mem_root, + sp->m_tmp_query, + i->m_query.length)) || + sp->add_instr(i)) + MYSQL_YYABORT; } sp->restore_lex(thd); } @@ -2680,9 +2687,9 @@ sp_proc_stmt_return: i= new sp_instr_freturn(sp->instructions(), lex->spcont, $3, sp->m_return_field_def.sql_type, lex); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); sp->m_flags|= sp_head::HAS_RETURN; } sp->restore_lex(YYTHD); @@ -2779,22 +2786,22 @@ sp_proc_stmt_iterate: if (n) { sp_instr_hpop *hpop= new sp_instr_hpop(ip++, ctx, n); - if (hpop == NULL) + if (hpop == NULL || + sp->add_instr(hpop)) MYSQL_YYABORT; - sp->add_instr(hpop); } n= ctx->diff_cursors(lab->ctx, FALSE); /* Inclusive the dest. */ if (n) { sp_instr_cpop *cpop= new sp_instr_cpop(ip++, ctx, n); - if (cpop == NULL) + if (cpop == NULL || + sp->add_instr(cpop)) MYSQL_YYABORT; - sp->add_instr(cpop); } i= new sp_instr_jump(ip, ctx, lab->ip); /* Jump back */ - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } } ; @@ -2813,9 +2820,9 @@ sp_proc_stmt_open: MYSQL_YYABORT; } i= new sp_instr_copen(sp->instructions(), lex->spcont, offset); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } ; @@ -2833,9 +2840,9 @@ sp_proc_stmt_fetch: MYSQL_YYABORT; } i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } sp_fetch_list {} @@ -2855,9 +2862,9 @@ sp_proc_stmt_close: MYSQL_YYABORT; } i= new sp_instr_cclose(sp->instructions(), lex->spcont, offset); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } ; @@ -2920,12 +2927,11 @@ sp_if: uint ip= sp->instructions(); sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, ctx, $2, lex); - if (i == NULL) + if (i == NULL || + sp->push_backpatch(i, ctx->push_label((char *)"", 0)) || + sp->add_cont_backpatch(i) || + sp->add_instr(i)) MYSQL_YYABORT; - - sp->push_backpatch(i, ctx->push_label((char *)"", 0)); - sp->add_cont_backpatch(i); - sp->add_instr(i); sp->restore_lex(YYTHD); } sp_proc_stmts1 @@ -2934,10 +2940,9 @@ sp_if: sp_pcontext *ctx= Lex->spcont; uint ip= sp->instructions(); sp_instr_jump *i = new sp_instr_jump(ip, ctx); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - - sp->add_instr(i); sp->backpatch(ctx->pop_label()); sp->push_backpatch(i, ctx->push_label((char *)"", 0)); } @@ -3021,14 +3026,16 @@ simple_when_clause: /* Simple case: <caseval> = <whenval> */ LEX *lex= Lex; - case_stmt_action_when(lex, $3, true); + if (case_stmt_action_when(lex, $3, true)) + MYSQL_YYABORT; lex->sphead->restore_lex(YYTHD); /* For expr $3 */ } THEN_SYM sp_proc_stmts1 { LEX *lex= Lex; - case_stmt_action_then(lex); + if (case_stmt_action_then(lex)) + MYSQL_YYABORT; } ; @@ -3040,14 +3047,16 @@ searched_when_clause: expr { LEX *lex= Lex; - case_stmt_action_when(lex, $3, false); + if (case_stmt_action_when(lex, $3, false)) + MYSQL_YYABORT; lex->sphead->restore_lex(YYTHD); /* For expr $3 */ } THEN_SYM sp_proc_stmts1 { LEX *lex= Lex; - case_stmt_action_then(lex); + if (case_stmt_action_then(lex)) + MYSQL_YYABORT; } ; @@ -3059,9 +3068,9 @@ else_clause_opt: uint ip= sp->instructions(); sp_instr_error *i= new sp_instr_error(ip, lex->spcont, ER_SP_CASE_NOT_FOUND); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } | ELSE sp_proc_stmts1 ; @@ -3175,16 +3184,16 @@ sp_block_content: if ($3.hndlrs) { i= new sp_instr_hpop(sp->instructions(), ctx, $3.hndlrs); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } if ($3.curs) { i= new sp_instr_cpop(sp->instructions(), ctx, $3.curs); - if (i == NULL) + if (i == NULL || + sp->add_instr(i)) MYSQL_YYABORT; - sp->add_instr(i); } lex->spcont= ctx->pop_context(); } @@ -3198,10 +3207,10 @@ sp_unlabeled_control: uint ip= lex->sphead->instructions(); sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */ sp_instr_jump *i = new sp_instr_jump(ip, lex->spcont, lab->ip); - if (i == NULL) + if (i == NULL || + lex->sphead->add_instr(i)) MYSQL_YYABORT; - lex->sphead->add_instr(i); - } + } | WHILE_SYM { Lex->sphead->reset_lex(YYTHD); } expr DO_SYM @@ -3211,12 +3220,12 @@ sp_unlabeled_control: uint ip= sp->instructions(); sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, lex->spcont, $3, lex); - if (i == NULL) + if (i == NULL || + /* Jumping forward */ + sp->push_backpatch(i, lex->spcont->last_label()) || + sp->new_cont_backpatch(i) || + sp->add_instr(i)) MYSQL_YYABORT; - /* Jumping forward */ - sp->push_backpatch(i, lex->spcont->last_label()); - sp->new_cont_backpatch(i); - sp->add_instr(i); sp->restore_lex(YYTHD); } sp_proc_stmts1 END WHILE_SYM @@ -3225,9 +3234,9 @@ sp_unlabeled_control: uint ip= lex->sphead->instructions(); sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */ sp_instr_jump *i = new sp_instr_jump(ip, lex->spcont, lab->ip); - if (i == NULL) + if (i == NULL || + lex->sphead->add_instr(i)) MYSQL_YYABORT; - lex->sphead->add_instr(i); lex->sphead->do_cont_backpatch(); } | REPEAT_SYM sp_proc_stmts1 UNTIL_SYM @@ -3240,9 +3249,9 @@ sp_unlabeled_control: sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, lex->spcont, $5, lab->ip, lex); - if (i == NULL) + if (i == NULL || + lex->sphead->add_instr(i)) MYSQL_YYABORT; - lex->sphead->add_instr(i); lex->sphead->restore_lex(YYTHD); /* We can shortcut the cont_backpatch here */ i->m_cont_dest= ip+1; @@ -4199,6 +4208,10 @@ opt_sub_partition: if (Lex->part_info->no_subparts != 0 && !Lex->part_info->use_default_subpartitions) { + /* + We come here when we have defined subpartitions on the first + partition but not on all the subsequent partitions. + */ my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR)); MYSQL_YYABORT; } @@ -4241,6 +4254,23 @@ sub_part_definition: partition_info *part_info= lex->part_info; partition_element *curr_part= part_info->current_partition; partition_element *sub_p_elem= new partition_element(curr_part); + if (part_info->use_default_subpartitions && + part_info->partitions.elements >= 2) + { + /* + create table t1 (a int) + partition by list (a) subpartition by hash (a) + (partition p0 values in (1), + partition p1 values in (2) subpartition sp11); + causes use to arrive since we are on the second + partition, but still use_default_subpartitions + is set. When we come here we're processing at least + the second partition (the current partition processed + have already been put into the partitions list. + */ + my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR)); + MYSQL_YYABORT; + } if (!sub_p_elem || curr_part->subpartitions.push_back(sub_p_elem)) { @@ -6538,6 +6568,7 @@ select_lock_type: 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; } | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM { @@ -8489,6 +8520,7 @@ table_factor: MYSQL_YYABORT; sel->add_joined_table($$); lex->pop_context(); + lex->nest_level--; } else if ($4 || $6) { @@ -8497,7 +8529,11 @@ table_factor: MYSQL_YYABORT; } else + { + /* nested join: FROM (t1 JOIN t2 ...), + nest_level is the same as in the outer query */ $$= $3; + } } ; @@ -9190,6 +9226,8 @@ into_destination: !(lex->result= new select_export(lex->exchange, lex->nest_level))) MYSQL_YYABORT; } + opt_load_data_charset + { Lex->exchange->cs= $4; } opt_field_term opt_line_term | DUMPFILE TEXT_STRING_filesystem { @@ -11544,7 +11582,6 @@ keyword_sp: | ONE_SYM {} | PACK_KEYS_SYM {} | PAGE_SYM {} - | PAGE_CHECKSUM_SYM {} | PARTIAL {} | PARTITIONING_SYM {} | PARTITIONS_SYM {} @@ -11750,7 +11787,8 @@ option_type_value: qbuff.length); qbuff.length+= 4; i->m_query= qbuff; - sp->add_instr(i); + if (sp->add_instr(i)) + MYSQL_YYABORT; } lex->sphead->restore_lex(thd); } @@ -11842,7 +11880,8 @@ sys_option_value: (uchar **) &trg_fld-> next_trg_field); - lex->sphead->add_instr(sp_fld); + if (lex->sphead->add_instr(sp_fld)) + MYSQL_YYABORT; } else if ($2.var) { /* System variable */ @@ -11881,9 +11920,9 @@ sys_option_value: } sp_set= new sp_instr_set(lex->sphead->instructions(), ctx, spv->offset, it, spv->type, lex, TRUE); - if (sp_set == NULL) + if (sp_set == NULL || + lex->sphead->add_instr(sp_set)) MYSQL_YYABORT; - lex->sphead->add_instr(sp_set); } } | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types @@ -12112,15 +12151,16 @@ text_or_password: | PASSWORD '(' TEXT_STRING ')' { $$= $3.length ? YYTHD->variables.old_passwords ? - Item_func_old_password::alloc(YYTHD, $3.str) : - Item_func_password::alloc(YYTHD, $3.str) : + Item_func_old_password::alloc(YYTHD, $3.str, $3.length) : + Item_func_password::alloc(YYTHD, $3.str, $3.length) : $3.str; if ($$ == NULL) MYSQL_YYABORT; } | OLD_PASSWORD '(' TEXT_STRING ')' { - $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str) : + $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str, + $3.length) : $3.str; if ($$ == NULL) MYSQL_YYABORT; @@ -12182,8 +12222,12 @@ table_lock_list: table_lock: table_ident opt_table_alias lock_option { - if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3)) + thr_lock_type lock_type= (thr_lock_type) $3; + if (!Select->add_table_to_list(YYTHD, $1, $2, 0, lock_type)) MYSQL_YYABORT; + /* If table is to be write locked, protect from a impending GRL. */ + if (lock_type >= TL_WRITE_ALLOW_WRITE) + Lex->protect_against_global_read_lock= TRUE; } ; @@ -12588,7 +12632,7 @@ grant_user: (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1); if (buff == NULL) MYSQL_YYABORT; - make_scrambled_password_323(buff, $4.str); + my_make_scrambled_password_323(buff, $4.str, $4.length); $1->password.str= buff; $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; } @@ -12598,7 +12642,7 @@ grant_user: (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1); if (buff == NULL) MYSQL_YYABORT; - make_scrambled_password(buff, $4.str); + my_make_scrambled_password(buff, $4.str, $4.length); $1->password.str= buff; $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH; } diff --git a/sql/structs.h b/sql/structs.h index 0a20eee0e9a..a58c18f97c5 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -107,6 +107,10 @@ typedef struct st_reginfo { /* Extra info about reg */ struct st_join_table *join_tab; /* Used by SELECT() */ enum thr_lock_type lock_type; /* How database is used */ bool not_exists_optimize; + /* + TRUE <=> range optimizer found that there is no rows satisfying + table conditions. + */ bool impossible_range; } REGINFO; diff --git a/sql/table.cc b/sql/table.cc index 9928c52759f..edf671b5a3b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -779,7 +779,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, strpos=disk_buff+6; if (!(rec_per_key= (ulong*) alloc_root(&share->mem_root, - sizeof(ulong*)*key_parts))) + sizeof(ulong)*key_parts))) goto err; for (i=0 ; i < keys ; i++, keyinfo++) @@ -3343,6 +3343,7 @@ void TABLE_LIST::hide_view_error(THD *thd) if (thd->main_da.sql_errno() == ER_BAD_FIELD_ERROR || thd->main_da.sql_errno() == ER_SP_DOES_NOT_EXIST || + thd->main_da.sql_errno() == ER_FUNC_INEXISTENT_NAME_COLLISION || thd->main_da.sql_errno() == ER_PROCACCESS_DENIED_ERROR || thd->main_da.sql_errno() == ER_COLUMNACCESS_DENIED_ERROR || thd->main_da.sql_errno() == ER_TABLEACCESS_DENIED_ERROR || diff --git a/sql/table.h b/sql/table.h index d3c1542420b..a7ae50b8e72 100644 --- a/sql/table.h +++ b/sql/table.h @@ -361,7 +361,9 @@ typedef struct st_table_share } enum row_type row_type; /* How rows are stored */ enum tmp_table_type tmp_table; + /** Transactional or not. */ enum ha_choice transactional; + /** Per-page checksums or not. */ enum ha_choice page_checksum; uint ref_count; /* How many TABLE objects uses this */ @@ -753,7 +755,13 @@ struct st_table { */ my_bool force_index; my_bool distinct,const_table,no_rows; - my_bool key_read, no_keyread; + + /** + If set, the optimizer has found that row retrieval should access index + tree only. + */ + my_bool key_read; + my_bool no_keyread; /* Placeholder for an open table which prevents other connections from taking name-locks on this table. Typically used with diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index 6bf43b51df0..0764fe8be33 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -21,7 +21,7 @@ extern "C" { void sql_alloc_error_handler(void) { - sql_print_error(ER(ER_OUT_OF_RESOURCES)); + sql_print_error("%s", ER(ER_OUT_OF_RESOURCES)); THD *thd= current_thd; if (thd) diff --git a/sql/unireg.cc b/sql/unireg.cc index 954f0bc3c7b..3b1836aeb88 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -37,8 +37,7 @@ static bool pack_header(uchar *forminfo,enum legacy_db_type table_type, List<Create_field> &create_fields, uint info_length, uint screens, uint table_options, ulong data_offset, handler *file); -static uint get_interval_id(uint *int_count,List<Create_field> &create_fields, - Create_field *last_field); +static uint get_interval_id(uint *,List<Create_field> &, Create_field *); static bool pack_fields(File file, List<Create_field> &create_fields, ulong data_offset); static bool make_empty_rec(THD *thd, int file, enum legacy_db_type table_type, diff --git a/sql/unireg.h b/sql/unireg.h index 5104aa1926d..4fbde3b8631 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -29,8 +29,8 @@ #define TEMP_PREFIX "MY" #define LOG_PREFIX "ML" #define PROGDIR "bin/" -#ifndef DATADIR -#define DATADIR "data/" +#ifndef MYSQL_DATADIR +#define MYSQL_DATADIR "data/" #endif #ifndef SHAREDIR #define SHAREDIR "share/" |