diff options
author | Seppo Jaakola <seppo.jaakola@codership.com> | 2013-05-26 11:26:58 +0300 |
---|---|---|
committer | Seppo Jaakola <seppo.jaakola@codership.com> | 2013-05-26 11:26:58 +0300 |
commit | bd0eae595fc5d050913ea01bd4c6a8e47f379176 (patch) | |
tree | dc2915fa2f49d6c015d7f6f4d54fda9ae0ae046e /sql | |
parent | 9d1546fe2cdced5efb4af831fa2e560b7f80fb54 (diff) | |
parent | cb246b20d6e0dad16797b9e09bef6f0431b88d37 (diff) | |
download | mariadb-git-bd0eae595fc5d050913ea01bd4c6a8e47f379176.tar.gz |
References: MDEV-4572 - merge with mariaDB 5.5.31
bzr merge lp:maria/5.5 -rtag:mariadb-5.5.31
Text conflict in cmake/cpack_rpm.cmake
Text conflict in debian/dist/Debian/control
Text conflict in debian/dist/Ubuntu/control
Text conflict in sql/CMakeLists.txt
Conflict adding file sql/db.opt. Moved existing file to sql/db.opt.moved.
Conflict adding file sql/db.opt.moved. Moved existing file to sql/db.opt.moved.moved.
Text conflict in sql/mysqld.cc
Text conflict in support-files/mysql.spec.sh
8 conflicts encountered.
Diffstat (limited to 'sql')
90 files changed, 2399 insertions, 727 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 948e0e037df..057976bf9a4 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -204,9 +204,12 @@ INSTALL_DEBUG_TARGET(mysqld PDB_DESTINATION ${INSTALL_SBINDIR}/debug RENAME mysqld-debug) +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/bison.cmake) + # Handle out-of-source build from source package with possibly broken # bison. Copy bison output to from source to build directory, if not already # there +IF (NOT BISON_USABLE) IF (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.cc) IF(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc) @@ -217,8 +220,8 @@ IF (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) ENDIF() ENDIF() ENDIF() +ENDIF() -INCLUDE(${CMAKE_SOURCE_DIR}/cmake/bison.cmake) RUN_BISON( ${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.yy ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc @@ -286,12 +289,9 @@ ADD_CUSTOM_TARGET(distclean IF(INSTALL_LAYOUT STREQUAL "STANDALONE") -# We need to create empty directories (data/test) the installation. -# This does not work with current CPack due to http://www.cmake.org/Bug/view.php?id=8767 -# Avoid completely empty directories and install dummy file instead. -SET(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/db.opt ) -FILE(WRITE ${DUMMY_FILE} "") -INSTALL(FILES ${DUMMY_FILE} DESTINATION data/test COMPONENT DataFiles) +# Copy db.opt into data/test/ +SET(DBOPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/db.opt ) +INSTALL(FILES ${DBOPT_FILE} DESTINATION data/test COMPONENT DataFiles) # Install initial database on windows IF(NOT CMAKE_CROSSCOMPILING) diff --git a/sql/db.opt b/sql/db.opt new file mode 100644 index 00000000000..d8429c4e0de --- /dev/null +++ b/sql/db.opt @@ -0,0 +1,2 @@ +default-character-set=latin1 +default-collation=latin1_swedish_ci diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 14927a66915..37dff0da714 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -55,7 +55,7 @@ const TABLE_FIELD_TYPE event_table_fields[ET_FIELD_COUNT] = }, { { C_STRING_WITH_LEN("definer") }, - { C_STRING_WITH_LEN("char(77)") }, + { C_STRING_WITH_LEN("char(") }, { C_STRING_WITH_LEN("utf8") } }, { diff --git a/sql/filesort.cc b/sql/filesort.cc index 9af57f669e4..ef5ef5357de 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -875,7 +875,10 @@ static void make_sortkey(register SORTPARAM *param, { MYSQL_TIME buf; if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES)) - DBUG_ASSERT(maybe_null && item->null_value); + { + DBUG_ASSERT(maybe_null); + DBUG_ASSERT(item->null_value); + } else value= pack_time(&buf); } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index b10de0362f2..838c1c374d8 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2012, Oracle and/or its affiliates. + Copyright (c) 2005, 2013, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -63,6 +63,8 @@ #include "key.h" #include "sql_plugin.h" #include "table.h" /* HA_DATA_PARTITION */ +#include "sql_show.h" // append_identifier +#include "sql_admin.h" // SQL_ADMIN_MSG_TEXT_SIZE #include "debug_sync.h" @@ -275,6 +277,7 @@ void ha_partition::init_handler_variables() m_rec_length= 0; m_last_part= 0; m_rec0= 0; + m_err_rec= NULL; m_curr_key_info[0]= NULL; m_curr_key_info[1]= NULL; m_part_func_monotonicity_info= NON_MONOTONIC; @@ -1042,10 +1045,11 @@ int ha_partition::preload_keys(THD *thd, HA_CHECK_OPT *check_opt) 0 Success */ -static int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, - handler *file, uint flag) +int ha_partition::handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, + uint part_id, uint flag) { int error; + handler *file= m_file[part_id]; DBUG_ENTER("handle_opt_part"); DBUG_PRINT("enter", ("flag = %u", flag)); @@ -1054,9 +1058,27 @@ static int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, else if (flag == ANALYZE_PARTS) error= file->ha_analyze(thd, check_opt); else if (flag == CHECK_PARTS) + { error= file->ha_check(thd, check_opt); + if (!error || + error == HA_ADMIN_ALREADY_DONE || + error == HA_ADMIN_NOT_IMPLEMENTED) + { + if (check_opt->flags & (T_MEDIUM | T_EXTEND)) + error= check_misplaced_rows(part_id, false); + } + } else if (flag == REPAIR_PARTS) + { error= file->ha_repair(thd, check_opt); + if (!error || + error == HA_ADMIN_ALREADY_DONE || + error == HA_ADMIN_NOT_IMPLEMENTED) + { + if (check_opt->flags & (T_MEDIUM | T_EXTEND)) + error= check_misplaced_rows(part_id, true); + } + } else if (flag == ASSIGN_KEYCACHE_PARTS) error= file->assign_to_keycache(thd, check_opt); else if (flag == PRELOAD_KEYS_PARTS) @@ -1078,11 +1100,11 @@ static int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, TODO: move this into the handler, or rewrite mysql_admin_table. */ static bool print_admin_msg(THD* thd, const char* msg_type, - const char* db_name, const char* table_name, + const char* db_name, String &table_name, const char* op_name, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 6, 7); static bool print_admin_msg(THD* thd, const char* msg_type, - const char* db_name, const char* table_name, + const char* db_name, String &table_name, const char* op_name, const char *fmt, ...) { va_list args; @@ -1103,7 +1125,7 @@ static bool print_admin_msg(THD* thd, const char* msg_type, return TRUE; } - length=(uint) (strxmov(name, db_name, ".", table_name,NullS) - name); + length=(uint) (strxmov(name, db_name, ".", table_name.c_ptr_safe(), NullS) - name); /* TODO: switch from protocol to push_warning here. The main reason we didn't it yet is parallel repair. Due to following trace: @@ -1175,15 +1197,14 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, part= i * num_subparts + j; DBUG_PRINT("info", ("Optimize subpartition %u (%s)", part, sub_elem->partition_name)); - if ((error= handle_opt_part(thd, check_opt, m_file[part], flag))) + if ((error= handle_opt_part(thd, check_opt, part, flag))) { /* print a line which partition the error belongs to */ if (error != HA_ADMIN_NOT_IMPLEMENTED && error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, "error", table_share->db.str, - table->alias.c_ptr(), + print_admin_msg(thd, "error", table_share->db.str, table->alias, opt_op_name[flag], "Subpartition %s returned error", sub_elem->partition_name); @@ -1202,15 +1223,14 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, { DBUG_PRINT("info", ("Optimize partition %u (%s)", i, part_elem->partition_name)); - if ((error= handle_opt_part(thd, check_opt, m_file[i], flag))) + if ((error= handle_opt_part(thd, check_opt, i, flag))) { /* print a line which partition the error belongs to */ if (error != HA_ADMIN_NOT_IMPLEMENTED && error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, "error", table_share->db.str, - table->alias.c_ptr(), + print_admin_msg(thd, "error", table_share->db.str, table->alias, opt_op_name[flag], "Partition %s returned error", part_elem->partition_name); } @@ -3557,7 +3577,7 @@ exit: Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc. new_data is always record[0] - old_data is normally record[1] but may be anything + old_data is always record[1] */ int ha_partition::update_row(const uchar *old_data, uchar *new_data) @@ -3568,6 +3588,7 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) longlong func_value; timestamp_auto_set_type orig_timestamp_type= table->timestamp_field_type; DBUG_ENTER("ha_partition::update_row"); + m_err_rec= NULL; /* We need to set timestamp field once before we calculate @@ -3585,6 +3606,25 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) m_part_info->err_value= func_value; goto exit; } + /* + The protocol for updating a row is: + 1) position the handler (cursor) on the row to be updated, + either through the last read row (rnd or index) or by rnd_pos. + 2) call update_row with both old and new full records as arguments. + + This means that m_last_part should already be set to actual partition + where the row was read from. And if that is not the same as the + calculated part_id we found a misplaced row, we return an error to + notify the user that something is broken in the row distribution + between partitions! Since we don't check all rows on read, we return an + error instead of correcting m_last_part, to make the user aware of the + problem! + */ + if (old_part_id != m_last_part) + { + m_err_rec= old_data; + DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND); + } m_last_part= new_part_id; start_part_bulk_insert(thd, new_part_id); @@ -3690,12 +3730,34 @@ int ha_partition::delete_row(const uchar *buf) int error; THD *thd= ha_thd(); DBUG_ENTER("ha_partition::delete_row"); + m_err_rec= NULL; if ((error= get_part_for_delete(buf, m_rec0, m_part_info, &part_id))) { DBUG_RETURN(error); } - m_last_part= part_id; + /* + The protocol for deleting a row is: + 1) position the handler (cursor) on the row to be deleted, + either through the last read row (rnd or index) or by rnd_pos. + 2) call delete_row with the full record as argument. + + This means that m_last_part should already be set to actual partition + where the row was read from. And if that is not the same as the + calculated part_id we found a misplaced row, we return an error to + notify the user that something is broken in the row distribution + between partitions! Since we don't check all rows on read, we return an + error instead of forwarding the delete to the correct (m_last_part) + partition! + TODO: change the assert in InnoDB into an error instead and make this one + an assert instead and remove the get_part_for_delete()! + */ + if (part_id != m_last_part) + { + m_err_rec= buf; + DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND); + } + tmp_disable_binlog(thd); error= m_file[part_id]->ha_delete_row(buf); reenable_binlog(thd); @@ -4541,7 +4603,6 @@ int ha_partition::index_init(uint inx, bool sorted) file= m_file; do { - /* TODO RONM: Change to index_init() when code is stable */ if (bitmap_is_set(&(m_part_info->used_partitions), (file - m_file))) if ((error= (*file)->ha_index_init(inx, sorted))) { @@ -6994,6 +7055,57 @@ enum row_type ha_partition::get_row_type() const } +void ha_partition::append_row_to_str(String &str) +{ + Field **field_ptr; + const uchar *rec; + bool is_rec0= !m_err_rec || m_err_rec == table->record[0]; + if (is_rec0) + rec= table->record[0]; + else + rec= m_err_rec; + // If PK, use full PK instead of full part field array! + if (table->s->primary_key != MAX_KEY) + { + KEY *key= table->key_info + table->s->primary_key; + KEY_PART_INFO *key_part= key->key_part; + KEY_PART_INFO *key_part_end= key_part + key->key_parts; + if (!is_rec0) + set_key_field_ptr(key, rec, table->record[0]); + for (; key_part != key_part_end; key_part++) + { + Field *field= key_part->field; + str.append(" "); + str.append(field->field_name); + str.append(":"); + field_unpack(&str, field, rec, 0, false); + } + if (!is_rec0) + set_key_field_ptr(key, table->record[0], rec); + } + else + { + if (!is_rec0) + set_field_ptr(m_part_info->full_part_field_array, rec, + table->record[0]); + /* No primary key, use full partition field array. */ + for (field_ptr= m_part_info->full_part_field_array; + *field_ptr; + field_ptr++) + { + Field *field= *field_ptr; + str.append(" "); + str.append(field->field_name); + str.append(":"); + field_unpack(&str, field, rec, 0, false); + } + if (!is_rec0) + set_field_ptr(m_part_info->full_part_field_array, table->record[0], + rec); + } +} + + void ha_partition::print_error(int error, myf errflag) { THD *thd= ha_thd(); @@ -7002,24 +7114,72 @@ void ha_partition::print_error(int error, myf errflag) /* Should probably look for my own errors first */ DBUG_PRINT("enter", ("error: %d", error)); - if ((error == HA_ERR_NO_PARTITION_FOUND) && - ! (thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION)) - m_part_info->print_no_partition_found(table); - else + if (error == HA_ERR_NO_PARTITION_FOUND) { - /* In case m_file has not been initialized, like in bug#42438 */ - if (m_file) + switch(thd_sql_command(thd)) { - if (m_last_part >= m_tot_parts) + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + if (m_err_rec) { - DBUG_ASSERT(0); - m_last_part= 0; + uint max_length; + char buf[MAX_KEY_LENGTH]; + const char *msg= "Found a row in wrong partition ("; + String str(buf,sizeof(buf),system_charset_info); + uint32 part_id; + /* Should only happen on DELETE or UPDATE! */ + str.length(0); + str.append_ulonglong(m_last_part); + str.append(" != "); + if (!get_part_for_delete(m_err_rec, m_rec0, m_part_info, &part_id)) + { + str.append_ulonglong(part_id); + } + str.append(")"); + append_row_to_str(str); + /* Log this error, so the DBA can notice it and fix it! */ + sql_print_error("Table '%-192s' corrupted: %s%s\n" + "Please CHECK and REPAIR the table!", + table->s->table_name.str, msg, str.c_ptr_safe()); + + max_length= (MYSQL_ERRMSG_SIZE- + (uint) strlen(msg)); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } + my_printf_error(ER_NO_PARTITION_FOR_GIVEN_VALUE, "%s%s", MYF(0), + msg, str.c_ptr_safe()); + m_err_rec= NULL; + DBUG_VOID_RETURN; + } + default: + { + if (!(thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION)) + { + m_part_info->print_no_partition_found(table); + DBUG_VOID_RETURN; + } } - m_file[m_last_part]->print_error(error, errflag); + /* fall through to generic error handling. */ } - else - handler::print_error(error, errflag); } + + /* In case m_file has not been initialized, like in bug#42438 */ + if (m_file) + { + if (m_last_part >= m_tot_parts) + { + DBUG_ASSERT(0); + m_last_part= 0; + } + m_file[m_last_part]->print_error(error, errflag); + } + else + handler::print_error(error, errflag); DBUG_VOID_RETURN; } @@ -7728,6 +7888,288 @@ int ha_partition::indexes_are_disabled(void) } +/** + Check/fix misplaced rows. + + @param read_part_id Partition to check/fix. + @param repair If true, move misplaced rows to correct partition. + + @return Operation status. + @retval 0 Success + @retval != 0 Error +*/ + +int ha_partition::check_misplaced_rows(uint read_part_id, bool repair) +{ + int result= 0; + uint32 correct_part_id; + longlong func_value; + longlong num_misplaced_rows= 0; + + DBUG_ENTER("ha_partition::check_misplaced_rows"); + + DBUG_ASSERT(m_file); + + if (repair) + { + /* We must read the full row, if we need to move it! */ + bitmap_set_all(table->read_set); + bitmap_set_all(table->write_set); + } + else + { + /* Only need to read the partitioning fields. */ + bitmap_union(table->read_set, &m_part_info->full_part_field_set); + } + + if ((result= m_file[read_part_id]->ha_rnd_init(1))) + DBUG_RETURN(result); + + while (true) + { + if ((result= m_file[read_part_id]->rnd_next(m_rec0))) + { + if (result == HA_ERR_RECORD_DELETED) + continue; + if (result != HA_ERR_END_OF_FILE) + break; + + if (num_misplaced_rows > 0) + { + print_admin_msg(ha_thd(), "warning", table_share->db.str, table->alias, + opt_op_name[REPAIR_PARTS], + "Moved %lld misplaced rows", + num_misplaced_rows); + } + /* End-of-file reached, all rows are now OK, reset result and break. */ + result= 0; + break; + } + + result= m_part_info->get_partition_id(m_part_info, &correct_part_id, + &func_value); + if (result) + break; + + if (correct_part_id != read_part_id) + { + num_misplaced_rows++; + if (!repair) + { + /* Check. */ + print_admin_msg(ha_thd(), "error", table_share->db.str, table->alias, + opt_op_name[CHECK_PARTS], + "Found a misplaced row"); + /* Break on first misplaced row! */ + result= HA_ADMIN_NEEDS_UPGRADE; + break; + } + else + { + DBUG_PRINT("info", ("Moving row from partition %d to %d", + read_part_id, correct_part_id)); + + /* + Insert row into correct partition. Notice that there are no commit + for every N row, so the repair will be one large transaction! + */ + if ((result= m_file[correct_part_id]->ha_write_row(m_rec0))) + { + /* + We have failed to insert a row, it might have been a duplicate! + */ + char buf[MAX_KEY_LENGTH]; + String str(buf,sizeof(buf),system_charset_info); + str.length(0); + if (result == HA_ERR_FOUND_DUPP_KEY) + { + str.append("Duplicate key found, " + "please update or delete the record:\n"); + result= HA_ADMIN_CORRUPT; + } + m_err_rec= NULL; + append_row_to_str(str); + + /* + If the engine supports transactions, the failure will be + rollbacked. + */ + if (!m_file[correct_part_id]->has_transactions()) + { + /* Log this error, so the DBA can notice it and fix it! */ + sql_print_error("Table '%-192s' failed to move/insert a row" + " from part %d into part %d:\n%s", + table->s->table_name.str, + read_part_id, + correct_part_id, + str.c_ptr_safe()); + } + print_admin_msg(ha_thd(), "error", table_share->db.str, table->alias, + opt_op_name[REPAIR_PARTS], + "Failed to move/insert a row" + " from part %d into part %d:\n%s", + read_part_id, + correct_part_id, + str.c_ptr_safe()); + break; + } + + /* Delete row from wrong partition. */ + if ((result= m_file[read_part_id]->ha_delete_row(m_rec0))) + { + if (m_file[correct_part_id]->has_transactions()) + break; + /* + We have introduced a duplicate, since we failed to remove it + from the wrong partition. + */ + char buf[MAX_KEY_LENGTH]; + String str(buf,sizeof(buf),system_charset_info); + str.length(0); + m_err_rec= NULL; + append_row_to_str(str); + + /* Log this error, so the DBA can notice it and fix it! */ + sql_print_error("Table '%-192s': Delete from part %d failed with" + " error %d. But it was already inserted into" + " part %d, when moving the misplaced row!" + "\nPlease manually fix the duplicate row:\n%s", + table->s->table_name.str, + read_part_id, + result, + correct_part_id, + str.c_ptr_safe()); + break; + } + } + } + } + + int tmp_result= m_file[read_part_id]->ha_rnd_end(); + DBUG_RETURN(result ? result : tmp_result); +} + + +#define KEY_PARTITIONING_CHANGED_STR \ + "KEY () partitioning changed, please run:\nALTER TABLE %s.%s %s" + +int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt) +{ + int error= HA_ADMIN_NEEDS_CHECK; + DBUG_ENTER("ha_partition::check_for_upgrade"); + + /* + This is called even without FOR UPGRADE, + if the .frm version is lower than the current version. + In that case return that it needs checking! + */ + if (!(check_opt->sql_flags & TT_FOR_UPGRADE)) + DBUG_RETURN(error); + + /* + Partitions will be checked for during their ha_check! + + Check if KEY (sub)partitioning was used and any field's hash calculation + differs from 5.1, see bug#14521864. + */ + if (table->s->mysql_version < 50503 && // 5.1 table (<5.5.3) + ((m_part_info->part_type == HASH_PARTITION && // KEY partitioned + m_part_info->list_of_part_fields) || + (m_is_sub_partitioned && // KEY subpartitioned + m_part_info->list_of_subpart_fields))) + { + Field **field; + if (m_is_sub_partitioned) + { + field= m_part_info->subpart_field_array; + } + else + { + field= m_part_info->part_field_array; + } + for (; *field; field++) + { + switch ((*field)->real_type()) { + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_ENUM: + case MYSQL_TYPE_SET: + { + THD *thd= ha_thd(); + char *part_buf; + String db_name, table_name; + uint part_buf_len; + bool skip_generation= false; + partition_info::enum_key_algorithm old_algorithm; + old_algorithm= m_part_info->key_algorithm; + error= HA_ADMIN_FAILED; + append_identifier(ha_thd(), &db_name, table_share->db.str, + table_share->db.length); + append_identifier(ha_thd(), &table_name, table_share->table_name.str, + table_share->table_name.length); + if (m_part_info->key_algorithm != partition_info::KEY_ALGORITHM_NONE) + { + /* + Only possible when someone tampered with .frm files, + like during tests :) + */ + skip_generation= true; + } + m_part_info->key_algorithm= partition_info::KEY_ALGORITHM_51; + if (skip_generation || + !(part_buf= generate_partition_syntax(m_part_info, + &part_buf_len, + true, + true, + NULL, + NULL, + NULL)) || + /* Also check that the length is smaller than the output field! */ + (part_buf_len + db_name.length() + table_name.length()) >= + (SQL_ADMIN_MSG_TEXT_SIZE - + (strlen(KEY_PARTITIONING_CHANGED_STR) - 3))) + { + print_admin_msg(thd, "error", table_share->db.str, table->alias, + opt_op_name[CHECK_PARTS], + KEY_PARTITIONING_CHANGED_STR, + db_name.c_ptr_safe(), table_name.c_ptr_safe(), + "<old partition clause>, but add ALGORITHM = 1" + " between 'KEY' and '(' to change the metadata" + " without the need of a full table rebuild."); + } + else + { + print_admin_msg(thd, "error", table_share->db.str, table->alias, + opt_op_name[CHECK_PARTS], + KEY_PARTITIONING_CHANGED_STR, + db_name.c_ptr_safe(), table_name.c_ptr_safe(), + part_buf); + } + m_part_info->key_algorithm= old_algorithm; + DBUG_RETURN(error); + } + default: + /* Not affected! */ + ; + } + } + } + + DBUG_RETURN(error); +} + + struct st_mysql_storage_engine partition_storage_engine= { MYSQL_HANDLERTON_INTERFACE_VERSION }; diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 30262b25bd9..ebf9dcdb842 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -2,7 +2,7 @@ #define HA_PARTITION_INCLUDED /* - Copyright (c) 2005, 2012, Oracle and/or its affiliates. + Copyright (c) 2005, 2013, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,13 +25,15 @@ #include "queues.h" /* QUEUE */ enum partition_keywords -{ +{ PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR, - PKW_COLUMNS + PKW_COLUMNS, PKW_ALGORITHM }; #define PARTITION_BYTES_IN_POS 2 -#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ) +#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | \ + HA_REC_NOT_IN_SEQ | \ + HA_CAN_REPAIR) #define PARTITION_DISABLED_TABLE_FLAGS (HA_CAN_GEOMETRY | \ HA_CAN_FULLTEXT | \ HA_DUPLICATE_POS | \ @@ -84,6 +86,7 @@ private: */ KEY *m_curr_key_info[3]; // Current index uchar *m_rec0; // table->record[0] + const uchar *m_err_rec; // record which gave error QUEUE m_queue; // Prio queue used by sorted read /* Since the partition handler is a handler on top of other handlers, it @@ -1095,9 +1098,18 @@ public: virtual bool check_and_repair(THD *thd); virtual bool auto_repair(int error) const; virtual bool is_crashed() const; + virtual int check_for_upgrade(HA_CHECK_OPT *check_opt); private: int handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, uint flags); + int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, uint part_id, + uint flag); + /** + Check if the rows are placed in the correct partition. If the given + argument is true, then move the rows to the correct partition. + */ + int check_misplaced_rows(uint read_part_id, bool repair); + void append_row_to_str(String &str); public: /* ------------------------------------------------------------------------- diff --git a/sql/handler.cc b/sql/handler.cc index 8f7391511b4..2a6398e9acb 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. - Copyright (c) 2009-2011 Monty Program Ab +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,6 +43,7 @@ #include "myisam.h" #include "probes_mysql.h" #include "debug_sync.h" // DEBUG_SYNC +#include "sql_audit.h" #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" @@ -285,7 +286,8 @@ handler *get_ha_partition(partition_info *part_info) } else { - my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(sizeof(ha_partition))); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), + static_cast<int>(sizeof(ha_partition))); } DBUG_RETURN(((handler*) partition)); } @@ -2158,7 +2160,7 @@ handle_condition(THD *, { *cond_hdl= NULL; /* Grab the error message */ - strmake(buff, msg, sizeof(buff)-1); + strmake_buf(buff, msg); return TRUE; } @@ -3503,6 +3505,9 @@ int handler::ha_check(THD *thd, HA_CHECK_OPT *check_opt) } if ((error= check(thd, check_opt))) return error; + /* Skip updating frm version if not main handler. */ + if (table->file != this) + return error; return update_frm_version(table); } @@ -3755,7 +3760,6 @@ int handler::ha_delete_table(const char *name) { mark_trx_read_write(); - return delete_table(name); } @@ -3788,8 +3792,11 @@ int handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info) { mark_trx_read_write(); - - return create(name, form, info); + int error= create(name, form, info); + if (!error && + !(info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER))) + mysql_audit_create_table(form); + return error; } @@ -5169,7 +5176,11 @@ int handler::ha_external_lock(THD *thd, int lock_type) int error= external_lock(thd, lock_type); if (error == 0) + { cached_table_flags= table_flags(); + if (table_share->tmp_table == NO_TMP_TABLE) + mysql_audit_external_lock(thd, table_share, lock_type); + } if (MYSQL_HANDLER_RDLOCK_DONE_ENABLED() || MYSQL_HANDLER_WRLOCK_DONE_ENABLED() || @@ -5224,6 +5235,8 @@ int handler::ha_write_row(uchar *buf) Log_func *log_func= Write_rows_log_event::binlog_row_logging_function; DBUG_ENTER("handler::ha_write_row"); DEBUG_SYNC_C("ha_write_row_start"); + DBUG_EXECUTE_IF("inject_error_ha_write_row", + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); ); MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str); mark_trx_read_write(); @@ -5252,6 +5265,7 @@ int handler::ha_update_row(const uchar *old_data, uchar *new_data) (and the old record is in record[1]). */ DBUG_ASSERT(new_data == table->record[0]); + DBUG_ASSERT(old_data == table->record[1]); MYSQL_UPDATE_ROW_START(table_share->db.str, table_share->table_name.str); mark_trx_read_write(); @@ -5271,6 +5285,13 @@ int handler::ha_delete_row(const uchar *buf) { int error; Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function; + /* + Normally table->record[0] is used, but sometimes table->record[1] is used. + */ + DBUG_ASSERT(buf == table->record[0] || + buf == table->record[1]); + DBUG_EXECUTE_IF("inject_error_ha_delete_row", + return HA_ERR_INTERNAL_ERROR; ); MYSQL_DELETE_ROW_START(table_share->db.str, table_share->table_name.str); mark_trx_read_write(); diff --git a/sql/handler.h b/sql/handler.h index 7c0c5fac67d..5573f6a5e27 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -285,7 +285,7 @@ (yes, the sum is deliberately inaccurate) TODO remove the limit, use dynarrays */ -#define MAX_HA 15 +#define MAX_HA 64 /* Use this instead of 0 as the initial value for the slot number of @@ -318,6 +318,7 @@ #define HA_LEX_CREATE_TMP_TABLE 1 #define HA_LEX_CREATE_IF_NOT_EXISTS 2 #define HA_LEX_CREATE_TABLE_LIKE 4 +#define HA_CREATE_TMP_ALTER 8 #define HA_MAX_REC_LENGTH 65535 /* Table caching type */ diff --git a/sql/innodb_priv.h b/sql/innodb_priv.h index 5406c292b18..24ee848bed1 100644 --- a/sql/innodb_priv.h +++ b/sql/innodb_priv.h @@ -25,7 +25,7 @@ class THD; int get_quote_char_for_identifier(THD *thd, const char *name, uint length); bool schema_table_store_record(THD *thd, TABLE *table); void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); -bool check_global_access(THD *thd, ulong want_access); +bool check_global_access(THD *thd, ulong want_access, bool no_errors=false); uint strconvert(CHARSET_INFO *from_cs, const char *from, CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors); diff --git a/sql/item.cc b/sql/item.cc index 2c435eb6a9f..c251e3d6df3 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. - Copyright (c) 2010, 2012, Monty Program Ab + Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2010, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -513,7 +513,7 @@ Item::Item(THD *thd, Item *item): with_field(item->with_field), fixed(item->fixed), is_autogenerated_name(item->is_autogenerated_name), - with_subselect(item->with_subselect), + with_subselect(item->has_subquery()), collation(item->collation), cmp_context(item->cmp_context) { @@ -1272,11 +1272,15 @@ bool Item::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) DBUG_ASSERT(0); } - return 0; + return null_value= 0; err: + /* + if the item was not null and convertion failed, we return a zero date + if allowed, otherwise - null. + */ bzero((char*) ltime,sizeof(*ltime)); - return 1; + return null_value|= (fuzzydate & (TIME_NO_ZERO_DATE|TIME_NO_ZERO_IN_DATE)); } bool Item::get_seconds(ulonglong *sec, ulong *sec_part) @@ -4409,7 +4413,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) if (db_name && lower_case_table_names) { /* Convert database to lower case for comparison */ - strmake(name_buff, db_name, sizeof(name_buff)-1); + strmake_buf(name_buff, db_name); my_casedn_str(files_charset_info, name_buff); db_name= name_buff; } @@ -6121,17 +6125,8 @@ inline uint char_val(char X) X-'a'+10); } -Item_hex_string::Item_hex_string() -{ - hex_string_init("", 0); -} -Item_hex_string::Item_hex_string(const char *str, uint str_length) -{ - hex_string_init(str, str_length); -} - -void Item_hex_string::hex_string_init(const char *str, uint str_length) +void Item_hex_constant::hex_string_init(const char *str, uint str_length) { max_length=(str_length+1)/2; char *ptr=(char*) sql_alloc(max_length+1); @@ -6155,7 +6150,7 @@ void Item_hex_string::hex_string_init(const char *str, uint str_length) unsigned_flag= 1; } -longlong Item_hex_string::val_int() +longlong Item_hex_hybrid::val_int() { // following assert is redundant, because fixed=1 assigned in constructor DBUG_ASSERT(fixed == 1); @@ -6169,17 +6164,7 @@ longlong Item_hex_string::val_int() } -my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value) -{ - // following assert is redundant, because fixed=1 assigned in constructor - DBUG_ASSERT(fixed == 1); - ulonglong value= (ulonglong)val_int(); - int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value); - return (decimal_value); -} - - -int Item_hex_string::save_in_field(Field *field, bool no_conversions) +int Item_hex_hybrid::save_in_field(Field *field, bool no_conversions) { field->set_notnull(); if (field->result_type() == STRING_RESULT) @@ -6212,22 +6197,27 @@ warn: } -void Item_hex_string::print(String *str, enum_query_type query_type) +void Item_hex_hybrid::print(String *str, enum_query_type query_type) { - char *end= (char*) str_value.ptr() + str_value.length(), - *ptr= end - min(str_value.length(), sizeof(longlong)); + uint32 len= min(str_value.length(), sizeof(longlong)); + const char *ptr= str_value.ptr() + str_value.length() - len; str->append("0x"); - for (; ptr != end ; ptr++) - { - str->append(_dig_vec_lower[((uchar) *ptr) >> 4]); - str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]); - } + str->append_hex(ptr, len); } -bool Item_hex_string::eq(const Item *arg, bool binary_cmp) const +void Item_hex_string::print(String *str, enum_query_type query_type) { - if (arg->basic_const_item() && arg->type() == type()) + str->append("X'"); + str->append_hex(str_value.ptr(), str_value.length()); + str->append("'"); +} + + +bool Item_hex_constant::eq(const Item *arg, bool binary_cmp) const +{ + if (arg->basic_const_item() && arg->type() == type() && + arg->cast_to_int_type() == cast_to_int_type()) { if (binary_cmp) return !stringcmp(&str_value, &arg->str_value); @@ -6237,7 +6227,7 @@ bool Item_hex_string::eq(const Item *arg, bool binary_cmp) const } -Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs) +Item *Item_hex_constant::safe_charset_converter(CHARSET_INFO *tocs) { Item_string *conv; String tmp, *str= val_str(&tmp); @@ -8093,7 +8083,7 @@ bool Item_default_value::fix_fields(THD *thd, Item **items) } if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of()))) goto error; - memcpy(def_field, field_arg->field, field_arg->field->size_of()); + memcpy((void *)def_field, (void *)field_arg->field, field_arg->field->size_of()); def_field->move_field_offset((my_ptrdiff_t) (def_field->table->s->default_values - def_field->table->record[0])); @@ -8229,7 +8219,7 @@ bool Item_insert_value::fix_fields(THD *thd, Item **items) Field *def_field= (Field*) sql_alloc(field_arg->field->size_of()); if (!def_field) return TRUE; - memcpy(def_field, field_arg->field, field_arg->field->size_of()); + memcpy((void *)def_field, (void *)field_arg->field, field_arg->field->size_of()); def_field->move_field_offset((my_ptrdiff_t) (def_field->table->insert_values - def_field->table->record[0])); @@ -8643,7 +8633,7 @@ int stored_field_cmp_to_item(THD *thd, Field *field, Item *item) Item_cache* Item_cache::get_cache(const Item *item) { - return get_cache(item, item->result_type()); + return get_cache(item, item->cmp_type()); } diff --git a/sql/item.h b/sql/item.h index bdf6fbe548e..2b0456bd30c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1,8 +1,8 @@ #ifndef SQL_ITEM_INCLUDED #define SQL_ITEM_INCLUDED -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. - Copyright (c) 2009, 2013 Monty Program Ab +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2013 Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -384,6 +384,12 @@ struct Name_resolution_context: Sql_alloc { (*error_processor)(thd, error_processor_data); } + st_select_lex *outer_select() + { + return (outer_context ? + outer_context->select_lex : + NULL); + } }; @@ -1444,6 +1450,12 @@ public: Return TRUE if the item points to a column of an outer-joined table. */ virtual bool is_outer_field() const { DBUG_ASSERT(fixed); return FALSE; } + + /** + Checks if this item or any of its decendents contains a subquery. + */ + virtual bool has_subquery() const { return with_subselect; } + Item* set_expr_cache(THD *thd); virtual Item_equal *get_item_equal() { return NULL; } @@ -2724,36 +2736,112 @@ public: }; -class Item_hex_string: public Item_basic_constant +/** + Item_hex_constant -- a common class for hex literals: X'HHHH' and 0xHHHH +*/ +class Item_hex_constant: public Item_basic_constant { +private: + void hex_string_init(const char *str, uint str_length); public: - Item_hex_string(); - Item_hex_string(const char *str,uint str_length); + Item_hex_constant() + { + hex_string_init("", 0); + } + Item_hex_constant(const char *str, uint str_length) + { + hex_string_init(str, str_length); + } enum Type type() const { return VARBIN_ITEM; } + enum Item_result result_type () const { return STRING_RESULT; } + enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } + virtual Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(uchar *int_arg) {return FALSE;} + bool check_vcol_func_processor(uchar *arg) { return FALSE;} + bool basic_const_item() const { return 1; } + bool eq(const Item *item, bool binary_cmp) const; + String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } +}; + + +/** + Item_hex_hybrid -- is a class implementing 0xHHHH literals, e.g.: + SELECT 0x3132; + They can behave as numbers and as strings depending on context. +*/ +class Item_hex_hybrid: public Item_hex_constant +{ +public: + Item_hex_hybrid(): Item_hex_constant() {} + Item_hex_hybrid(const char *str, uint str_length): + Item_hex_constant(str, str_length) {} double val_real() { DBUG_ASSERT(fixed == 1); - return (double) (ulonglong) Item_hex_string::val_int(); + return (double) (ulonglong) Item_hex_hybrid::val_int(); } longlong val_int(); - bool basic_const_item() const { return 1; } - String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } - my_decimal *val_decimal(my_decimal *); + my_decimal *val_decimal(my_decimal *decimal_value) + { + // following assert is redundant, because fixed=1 assigned in constructor + DBUG_ASSERT(fixed == 1); + ulonglong value= (ulonglong) Item_hex_hybrid::val_int(); + int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value); + return decimal_value; + } int save_in_field(Field *field, bool 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); - bool eq(const Item *item, bool binary_cmp) const; - virtual Item *safe_charset_converter(CHARSET_INFO *tocs); - bool check_partition_func_processor(uchar *int_arg) {return FALSE;} - bool check_vcol_func_processor(uchar *arg) { return FALSE;} -private: - void hex_string_init(const char *str, uint str_length); + void print(String *str, enum_query_type query_type); +}; + + +/** + Item_hex_string -- is a class implementing X'HHHH' literals, e.g.: + SELECT X'3132'; + Unlike Item_hex_hybrid, X'HHHH' literals behave as strings in all contexts. + X'HHHH' are also used in replication of string constants in case of + "dangerous" charsets (sjis, cp932, big5, gbk) who can have backslash (0x5C) + as the second byte of a multi-byte character, so using '\' escaping for + these charsets is not desirable. +*/ +class Item_hex_string: public Item_hex_constant +{ +public: + Item_hex_string(): Item_hex_constant() {} + Item_hex_string(const char *str, uint str_length): + Item_hex_constant(str, str_length) {} + longlong val_int() + { + DBUG_ASSERT(fixed == 1); + return longlong_from_string_with_check(str_value.charset(), + str_value.ptr(), + str_value.ptr()+ + str_value.length()); + } + double val_real() + { + DBUG_ASSERT(fixed == 1); + return double_from_string_with_check(str_value.charset(), + str_value.ptr(), + str_value.ptr() + + str_value.length()); + } + my_decimal *val_decimal(my_decimal *decimal_value) + { + return val_decimal_from_string(decimal_value); + } + int save_in_field(Field *field, bool no_conversions) + { + field->set_notnull(); + return field->store(str_value.ptr(), str_value.length(), + collation.collation); + } + enum Item_result cast_to_int_type() const { return STRING_RESULT; } + void print(String *str, enum_query_type query_type); }; -class Item_bin_string: public Item_hex_string +class Item_bin_string: public Item_hex_hybrid { public: Item_bin_string(const char *str,uint str_length); @@ -2957,6 +3045,14 @@ public: DBUG_ASSERT(ref); return (*ref)->is_outer_field(); } + + /** + Checks if the item tree that ref points to contains a subquery. + */ + virtual bool has_subquery() const + { + return (*ref)->has_subquery(); + } }; @@ -4030,6 +4126,7 @@ public: bool cache_value(); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); int save_in_field(Field *field, bool no_conversions); + Item_result cmp_type() const { return TIME_RESULT; } void store_packed(longlong val_arg, Item *example); /* Having a clone_item method tells optimizer that this object diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 9a0ed877bf1..dfd60316039 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -906,7 +906,8 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, } if ((*is_null= item->null_value)) return ~(ulonglong) 0; - if (cache_arg && item->const_item() && item->type() != Item::CACHE_ITEM) + if (cache_arg && item->const_item() && + !(item->type() == Item::CACHE_ITEM && item->cmp_type() == TIME_RESULT)) { Query_arena backup; Query_arena *save_arena= thd->switch_to_arena_for_cached_items(&backup); @@ -4311,7 +4312,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) with_sum_func= with_sum_func || item->with_sum_func; with_field= with_field || item->with_field; - with_subselect|= item->with_subselect; + with_subselect|= item->has_subquery(); if (item->maybe_null) maybe_null=1; } @@ -4978,7 +4979,7 @@ Item_func_regex::fix_fields(THD *thd, Item **ref) return TRUE; /* purecov: inspected */ with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func; with_field= args[0]->with_field || args[1]->with_field; - with_subselect|= args[0]->with_subselect | args[1]->with_subselect; + with_subselect= args[0]->has_subquery() || args[1]->has_subquery(); max_length= 1; decimals= 0; diff --git a/sql/item_create.cc b/sql/item_create.cc index 96837a8f262..45de3850fcd 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -4373,8 +4373,7 @@ Create_func_make_set::create_native(THD *thd, LEX_STRING name, return NULL; } - Item *param_1= item_list->pop(); - return new (thd->mem_root) Item_func_make_set(param_1, *item_list); + return new (thd->mem_root) Item_func_make_set(*item_list); } diff --git a/sql/item_func.cc b/sql/item_func.cc index c7c8901af79..14bf71add3d 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -225,7 +225,7 @@ Item_func::fix_fields(THD *thd, Item **ref) with_field= with_field || item->with_field; used_tables_cache|= item->used_tables(); const_item_cache&= item->const_item(); - with_subselect|= item->with_subselect; + with_subselect|= item->has_subquery(); } } fix_length_and_dec(); @@ -769,13 +769,14 @@ void Item_num_op::find_num_type(void) { hybrid_type= DECIMAL_RESULT; result_precision(); + fix_decimals(); } else { DBUG_ASSERT(r0 == INT_RESULT && r1 == INT_RESULT); - decimals= 0; hybrid_type=INT_RESULT; result_precision(); + decimals= 0; } DBUG_PRINT("info", ("Type: %s", (hybrid_type == REAL_RESULT ? "REAL_RESULT" : @@ -1708,6 +1709,7 @@ void Item_func_div::fix_length_and_dec() break; case DECIMAL_RESULT: result_precision(); + fix_decimals(); break; case STRING_RESULT: case ROW_RESULT: @@ -1907,6 +1909,16 @@ longlong Item_func_neg::int_op() if (args[0]->unsigned_flag && (ulonglong) value > (ulonglong) LONGLONG_MAX + 1) return raise_integer_overflow(); + + if (value == LONGLONG_MIN) + { + if (args[0]->unsigned_flag != unsigned_flag) + /* negation of LONGLONG_MIN is LONGLONG_MIN. */ + return LONGLONG_MIN; + else + return raise_integer_overflow(); + } + return check_integer_overflow(-value, !args[0]->unsigned_flag && value < 0); } @@ -5363,7 +5375,7 @@ enum Item_result Item_func_get_user_var::result_type() const void Item_func_get_user_var::print(String *str, enum_query_type query_type) { str->append(STRING_WITH_LEN("(@")); - str->append(name.str,name.length); + append_identifier(current_thd, str, name.str, name.length); str->append(')'); } @@ -5990,15 +6002,12 @@ void Item_func_match::init_search(bool no_order) { DBUG_ENTER("Item_func_match::init_search"); + if (!table->file->get_table()) // the handler isn't opened yet + DBUG_VOID_RETURN; + /* Check if init_search() has been called before */ if (ft_handler) { - /* - We should reset ft_handler as it is cleaned up - on destruction of FT_SELECT object - (necessary in case of re-execution of subquery). - TODO: FT_SELECT should not clean up ft_handler. - */ if (join_key) table->file->ft_handler= ft_handler; DBUG_VOID_RETURN; @@ -6007,10 +6016,10 @@ void Item_func_match::init_search(bool no_order) if (key == NO_SUCH_KEY) { List<Item> fields; - fields.push_back(new Item_string(" ",1, cmp_collation.collation)); - for (uint i=1; i < arg_count; i++) + fields.push_back(new Item_string(" ", 1, cmp_collation.collation)); + for (uint i= 1; i < arg_count; i++) fields.push_back(args[i]); - concat_ws=new Item_func_concat_ws(fields); + concat_ws= new Item_func_concat_ws(fields); /* Above function used only to get value and do not need fix_fields for it: Item_string - basic constant @@ -6022,10 +6031,10 @@ void Item_func_match::init_search(bool no_order) if (master) { - join_key=master->join_key=join_key|master->join_key; + join_key= master->join_key= join_key | master->join_key; master->init_search(no_order); - ft_handler=master->ft_handler; - join_key=master->join_key; + ft_handler= master->ft_handler; + join_key= master->join_key; DBUG_VOID_RETURN; } @@ -6035,7 +6044,7 @@ void Item_func_match::init_search(bool no_order) if (!(ft_tmp=key_item()->val_str(&value))) { ft_tmp= &value; - value.set("",0,cmp_collation.collation); + value.set("", 0, cmp_collation.collation); } if (ft_tmp->charset() != cmp_collation.collation) @@ -6048,7 +6057,11 @@ void Item_func_match::init_search(bool no_order) if (join_key && !no_order) flags|=FT_SORTED; - ft_handler=table->file->ft_init_ext(flags, key, ft_tmp); + + if (key != NO_SUCH_KEY) + thd_proc_info(table->in_use, "FULLTEXT initialization"); + + ft_handler= table->file->ft_init_ext(flags, key, ft_tmp); if (join_key) table->file->ft_handler=ft_handler; diff --git a/sql/item_func.h b/sql/item_func.h index 7b6b60b2914..1fef9938a18 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -431,6 +431,13 @@ public: void fix_num_length_and_dec(); virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */ + inline void fix_decimals() + { + DBUG_ASSERT(result_type() == DECIMAL_RESULT); + if (decimals == NOT_FIXED_DEC) + set_if_smaller(decimals, max_length - 1); + } + double val_real(); longlong val_int(); my_decimal *val_decimal(my_decimal *); @@ -543,12 +550,18 @@ public: class Item_func_signed :public Item_int_func { public: - Item_func_signed(Item *a) :Item_int_func(a) {} + Item_func_signed(Item *a) :Item_int_func(a) + { + unsigned_flag= 0; + } const char *func_name() const { return "cast_as_signed"; } longlong val_int(); longlong val_int_from_str(int *error); void fix_length_and_dec() - { fix_char_length(args[0]->max_char_length()); unsigned_flag=0; } + { + fix_char_length(min(args[0]->max_char_length(), + MY_INT64_NUM_DECIMAL_DIGITS)); + } virtual void print(String *str, enum_query_type query_type); uint decimal_precision() const { return args[0]->decimal_precision(); } }; @@ -557,14 +570,11 @@ public: class Item_func_unsigned :public Item_func_signed { public: - Item_func_unsigned(Item *a) :Item_func_signed(a) {} - const char *func_name() const { return "cast_as_unsigned"; } - void fix_length_and_dec() + Item_func_unsigned(Item *a) :Item_func_signed(a) { - fix_char_length(min(args[0]->max_char_length(), - DECIMAL_MAX_PRECISION + 2)); - unsigned_flag=1; + unsigned_flag= 1; } + const char *func_name() const { return "cast_as_unsigned"; } longlong val_int(); virtual void print(String *str, enum_query_type query_type); }; diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index e3e80bdf59f..0a7f18e6546 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -561,8 +561,8 @@ longlong Item_func_spatial_mbr_rel::val_int() args[1]->null_value || !(g1= Geometry::construct(&buffer1, res1->ptr(), res1->length())) || !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length())) || - g1->get_mbr(&mbr1, &dummy) || - g2->get_mbr(&mbr2, &dummy)))) + g1->get_mbr(&mbr1, &dummy) || !mbr1.valid() || + g2->get_mbr(&mbr2, &dummy) || !mbr2.valid()))) return 0; switch (spatial_rel) { @@ -687,12 +687,11 @@ longlong Item_func_spatial_rel::val_int() if ((null_value= (args[0]->null_value || args[1]->null_value || !(g1= Geometry::construct(&buffer1, res1->ptr(), res1->length())) || - !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length()))))) + !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length())) || + g1->get_mbr(&mbr1, &c_end) || !mbr1.valid() || + g2->get_mbr(&mbr2, &c_end) || !mbr2.valid()))) goto exit; - g1->get_mbr(&mbr1, &c_end); - g2->get_mbr(&mbr2, &c_end); - umbr= mbr1; umbr.add_mbr(&mbr2); collector.set_extent(umbr.xmin, umbr.xmax, umbr.ymin, umbr.ymax); @@ -826,14 +825,14 @@ String *Item_func_spatial_operation::val_str(String *str_value) if ((null_value= (args[0]->null_value || args[1]->null_value || !(g1= Geometry::construct(&buffer1, res1->ptr(), res1->length())) || - !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length()))))) + !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length())) || + g1->get_mbr(&mbr1, &c_end) || !mbr1.valid() || + g2->get_mbr(&mbr2, &c_end) || !mbr2.valid()))) { str_value= 0; goto exit; } - g1->get_mbr(&mbr1, &c_end); - g2->get_mbr(&mbr2, &c_end); mbr1.add_mbr(&mbr2); collector.set_extent(mbr1.xmin, mbr1.xmax, mbr1.ymin, mbr1.ymax); @@ -1358,11 +1357,11 @@ longlong Item_func_issimple::val_int() DBUG_ENTER("Item_func_issimple::val_int"); DBUG_ASSERT(fixed == 1); - if ((null_value= args[0]->null_value) || - !(g= Geometry::construct(&buffer, swkb->ptr(), swkb->length()))) + if ((null_value= (args[0]->null_value || + !(g= Geometry::construct(&buffer, swkb->ptr(), swkb->length())) || + g->get_mbr(&mbr, &c_end)))) DBUG_RETURN(0); - g->get_mbr(&mbr, &c_end); collector.set_extent(mbr.xmin, mbr.xmax, mbr.ymin, mbr.ymax); if (g->get_class_info()->m_type_id == Geometry::wkb_point) @@ -1598,11 +1597,11 @@ double Item_func_distance::val_real() if ((null_value= (args[0]->null_value || args[1]->null_value || !(g1= Geometry::construct(&buffer1, res1->ptr(), res1->length())) || - !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length()))))) + !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length())) || + g1->get_mbr(&mbr1, &c_end) || + g2->get_mbr(&mbr2, &c_end)))) goto mem_error; - g1->get_mbr(&mbr1, &c_end); - g2->get_mbr(&mbr2, &c_end); mbr1.add_mbr(&mbr2); collector.set_extent(mbr1.xmin, mbr1.xmax, mbr1.ymin, mbr1.ymax); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index c0a6120b361..a18ded2de80 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -59,6 +59,8 @@ C_MODE_START #include "../mysys/my_static.h" // For soundex_map C_MODE_END +size_t username_char_length= 16; + /** @todo Remove this. It is not safe to use a shared String object. */ @@ -2460,38 +2462,16 @@ String *Item_func_elt::val_str(String *str) } -void Item_func_make_set::split_sum_func(THD *thd, Item **ref_pointer_array, - List<Item> &fields) -{ - item->split_sum_func2(thd, ref_pointer_array, fields, &item, TRUE); - Item_str_func::split_sum_func(thd, ref_pointer_array, fields); -} - - void Item_func_make_set::fix_length_and_dec() { - uint32 char_length= arg_count - 1; /* Separators */ + uint32 char_length= arg_count - 2; /* Separators */ - if (agg_arg_charsets_for_string_result(collation, args, arg_count)) + if (agg_arg_charsets_for_string_result(collation, args + 1, arg_count - 1)) return; - for (uint i=0 ; i < arg_count ; i++) + for (uint i=1 ; i < arg_count ; i++) char_length+= args[i]->max_char_length(); fix_char_length(char_length); - used_tables_cache|= item->used_tables(); - not_null_tables_cache&= item->not_null_tables(); - const_item_cache&= item->const_item(); - with_sum_func= with_sum_func || item->with_sum_func; - with_field= with_field || item->with_field; -} - - -void Item_func_make_set::update_used_tables() -{ - Item_func::update_used_tables(); - item->update_used_tables(); - used_tables_cache|=item->used_tables(); - const_item_cache&=item->const_item(); } @@ -2500,15 +2480,15 @@ String *Item_func_make_set::val_str(String *str) DBUG_ASSERT(fixed == 1); ulonglong bits; bool first_found=0; - Item **ptr=args; + Item **ptr=args+1; String *result=&my_empty_string; - bits=item->val_int(); - if ((null_value=item->null_value)) + bits=args[0]->val_int(); + if ((null_value=args[0]->null_value)) return NULL; - if (arg_count < 64) - bits &= ((ulonglong) 1 << arg_count)-1; + if (arg_count < 65) + bits &= ((ulonglong) 1 << (arg_count-1))-1; for (; bits; bits >>= 1, ptr++) { @@ -2548,39 +2528,6 @@ String *Item_func_make_set::val_str(String *str) } -Item *Item_func_make_set::transform(Item_transformer transformer, uchar *arg) -{ - DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare()); - - Item *new_item= item->transform(transformer, arg); - if (!new_item) - return 0; - - /* - THD::change_item_tree() should be called only if the tree was - really transformed, i.e. when a new item has been created. - Otherwise we'll be allocating a lot of unnecessary memory for - change records at each execution. - */ - if (item != new_item) - current_thd->change_item_tree(&item, new_item); - return Item_str_func::transform(transformer, arg); -} - - -void Item_func_make_set::print(String *str, enum_query_type query_type) -{ - str->append(STRING_WITH_LEN("make_set(")); - item->print(str, query_type); - if (arg_count) - { - str->append(','); - print_args(str, 0, query_type); - } - str->append(')'); -} - - String *Item_func_char::val_str(String *str) { DBUG_ASSERT(fixed == 1); @@ -2987,7 +2934,7 @@ String *Item_func_conv_charset::val_str(String *str) return null_value ? 0 : &str_value; String *arg= args[0]->val_str(str); uint dummy_errors; - if (!arg) + if (args[0]->null_value) { null_value=1; return 0; @@ -4497,11 +4444,16 @@ null: void Item_dyncol_get::print(String *str, enum_query_type query_type) { + /* see create_func_dyncol_get */ + DBUG_ASSERT(str->length() >= 5); + DBUG_ASSERT(strncmp(str->ptr() + str->length() - 5, "cast(", 5) == 0); + + str->length(str->length() - 5); // removing "cast(" str->append(STRING_WITH_LEN("column_get(")); args[0]->print(str, query_type); str->append(','); args[1]->print(str, query_type); - str->append(')'); + /* let the parent cast item add " as <type>)" */ } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 786f66e3aab..77179195283 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -25,6 +25,8 @@ #pragma interface /* gcc class implementation */ #endif +extern size_t username_char_length; + class MY_LOCALE; class Item_str_func :public Item_func @@ -494,8 +496,8 @@ public: bool fix_fields(THD *thd, Item **ref); void fix_length_and_dec() { - max_length= (USERNAME_LENGTH + - (HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN); + max_length= (username_char_length + + HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN; } const char *func_name() const { return "user"; } const char *fully_qualified_func_name() const { return "user()"; } @@ -544,31 +546,13 @@ public: class Item_func_make_set :public Item_str_func { - Item *item; String tmp_str; public: - Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {} + Item_func_make_set(List<Item> &list) :Item_str_func(list) {} String *val_str(String *str); - bool fix_fields(THD *thd, Item **ref) - { - DBUG_ASSERT(fixed == 0); - return ((!item->fixed && item->fix_fields(thd, &item)) || - item->check_cols(1) || - Item_func::fix_fields(thd, ref)); - } - void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields); void fix_length_and_dec(); - void update_used_tables(); const char *func_name() const { return "make_set"; } - - bool walk(Item_processor processor, bool walk_subquery, uchar *arg) - { - return item->walk(processor, walk_subquery, arg) || - Item_str_func::walk(processor, walk_subquery, arg); - } - Item *transform(Item_transformer transformer, uchar *arg); - virtual void print(String *str, enum_query_type query_type); }; @@ -859,25 +843,37 @@ public: { if (args[0]->result_type() == STRING_RESULT) return Item_str_func::val_int(); - return args[0]->val_int(); + longlong res= args[0]->val_int(); + if ((null_value= args[0]->null_value)) + return 0; + return res; } double val_real() { if (args[0]->result_type() == STRING_RESULT) return Item_str_func::val_real(); - return args[0]->val_real(); + double res= args[0]->val_real(); + if ((null_value= args[0]->null_value)) + return 0; + return res; } my_decimal *val_decimal(my_decimal *d) { if (args[0]->result_type() == STRING_RESULT) return Item_str_func::val_decimal(d); - return args[0]->val_decimal(d); + my_decimal *res= args[0]->val_decimal(d); + if ((null_value= args[0]->null_value)) + return NULL; + return res; } bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) { if (args[0]->result_type() == STRING_RESULT) return Item_str_func::get_date(ltime, fuzzydate); - return args[0]->get_date(ltime, fuzzydate); + bool res= args[0]->get_date(ltime, fuzzydate); + if ((null_value= args[0]->null_value)) + return 1; + return res; } void fix_length_and_dec(); const char *func_name() const { return "convert"; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 152b50da616..43855286d4f 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -547,8 +547,19 @@ bool Item_subselect::is_expensive() if (!cur_join) continue; - /* If a subquery is not optimized we cannot estimate its cost. */ - if (!cur_join->join_tab) + /* + Subqueries whose result is known after optimization are not expensive. + Such subqueries have all tables optimized away, thus have no join plan. + */ + if (cur_join->optimized && + (cur_join->zero_result_cause || !cur_join->tables_list)) + return false; + + /* + If a subquery is not optimized we cannot estimate its cost. A subquery is + considered optimized if it has a join plan. + */ + if (!(cur_join->optimized && cur_join->join_tab)) return true; if (sl->first_inner_unit()) @@ -1087,6 +1098,11 @@ enum Item_result Item_singlerow_subselect::result_type() const return engine->type(); } +enum Item_result Item_singlerow_subselect::cmp_type() const +{ + return engine->cmptype(); +} + /* Don't rely on the result type to calculate field type. Ask the engine instead. @@ -3044,12 +3060,13 @@ void subselect_engine::set_row(List<Item> &item_list, Item_cache **row) { Item *sel_item; List_iterator_fast<Item> li(item_list); - res_type= STRING_RESULT; + cmp_type= res_type= STRING_RESULT; res_field_type= MYSQL_TYPE_VAR_STRING; for (uint i= 0; (sel_item= li++); i++) { item->max_length= sel_item->max_length; res_type= sel_item->result_type(); + cmp_type= sel_item->cmp_type(); res_field_type= sel_item->field_type(); item->decimals= sel_item->decimals; item->unsigned_flag= sel_item->unsigned_flag; @@ -3060,7 +3077,7 @@ void subselect_engine::set_row(List<Item> &item_list, Item_cache **row) //psergey-backport-timours: row[i]->store(sel_item); } if (item_list.elements > 1) - res_type= ROW_RESULT; + cmp_type= res_type= ROW_RESULT; } void subselect_single_select_engine::fix_length_and_dec(Item_cache **row) diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 1da129380e7..25852b55d98 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -286,6 +286,7 @@ public: bool val_bool(); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); enum Item_result result_type() const; + enum Item_result cmp_type() const; enum_field_types field_type() const; void fix_length_and_dec(); @@ -698,6 +699,7 @@ protected: THD *thd; /* pointer to current THD */ Item_subselect *item; /* item, that use this engine */ enum Item_result res_type; /* type of results */ + enum Item_result cmp_type; /* how to compare the results */ enum_field_types res_field_type; /* column type of the results */ bool maybe_null; /* may be null (first item in select) */ public: @@ -712,7 +714,7 @@ public: { result= res; item= si; - res_type= STRING_RESULT; + cmp_type= res_type= STRING_RESULT; res_field_type= MYSQL_TYPE_VAR_STRING; maybe_null= 0; set_thd(thd_arg); @@ -752,6 +754,7 @@ public: virtual uint cols()= 0; /* return number of columns in select */ virtual uint8 uncacheable()= 0; /* query is uncacheable */ enum Item_result type() { return res_type; } + enum Item_result cmptype() { return cmp_type; } enum_field_types field_type() { return res_field_type; } virtual void exclude()= 0; virtual bool may_be_null() { return maybe_null; }; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 72e0e637d38..4f4d8588a3a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -65,7 +65,15 @@ ulonglong Item_sum::ram_limitation(THD *thd) bool Item_sum::init_sum_func_check(THD *thd) { - if (!thd->lex->allow_sum_func) + SELECT_LEX *curr_sel= thd->lex->current_select; + if (!curr_sel->name_visibility_map) + { + for (SELECT_LEX *sl= curr_sel; sl; sl= sl->context.outer_select()) + { + curr_sel->name_visibility_map|= (1 << sl-> nest_level); + } + } + if (!(thd->lex->allow_sum_func & curr_sel->name_visibility_map)) { my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), MYF(0)); @@ -136,8 +144,11 @@ bool Item_sum::init_sum_func_check(THD *thd) bool Item_sum::check_sum_func(THD *thd, Item **ref) { + SELECT_LEX *curr_sel= thd->lex->current_select; + nesting_map allow_sum_func= (thd->lex->allow_sum_func & + curr_sel->name_visibility_map); bool invalid= FALSE; - nesting_map allow_sum_func= thd->lex->allow_sum_func; + DBUG_ASSERT(curr_sel->name_visibility_map); // should be set already /* The value of max_arg_level is updated if an argument of the set function contains a column reference resolved against a subquery whose level is @@ -172,7 +183,7 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) if (!invalid && aggr_level < 0) { aggr_level= nest_level; - aggr_sel= thd->lex->current_select; + aggr_sel= curr_sel; } /* By this moment we either found a subquery where the set function is @@ -309,9 +320,9 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) { SELECT_LEX *sl; nesting_map allow_sum_func= thd->lex->allow_sum_func; - for (sl= thd->lex->current_select->master_unit()->outer_select() ; + for (sl= thd->lex->current_select->context.outer_select() ; sl && sl->nest_level > max_arg_level; - sl= sl->master_unit()->outer_select() ) + sl= sl->context.outer_select()) { if (aggr_level < 0 && (allow_sum_func & ((nesting_map)1 << sl->nest_level))) @@ -719,6 +730,14 @@ static int simple_raw_key_cmp(void* arg, const void* key1, const void* key2) } +static int item_sum_distinct_walk_for_count(void *element, + element_count num_of_dups, + void *item) +{ + return ((Aggregator_distinct*) (item))->unique_walk_function_for_count(element); +} + + static int item_sum_distinct_walk(void *element, element_count num_of_dups, void *item) { @@ -1089,7 +1108,12 @@ void Aggregator_distinct::endup() { /* go over the tree of distinct keys and calculate the aggregate value */ use_distinct_values= TRUE; - tree->walk(table, item_sum_distinct_walk, (void*) this); + tree_walk_action func; + if (item_sum->sum_func() == Item_sum::COUNT_DISTINCT_FUNC) + func= item_sum_distinct_walk_for_count; + else + func= item_sum_distinct_walk; + tree->walk(table, func, (void*) this); use_distinct_values= FALSE; } /* prevent consecutive recalculations */ @@ -1466,6 +1490,22 @@ bool Aggregator_distinct::unique_walk_function(void *element) } +/* + A variant of unique_walk_function() that is to be used with Item_sum_count. + + COUNT is a special aggregate function: it doesn't need the values, it only + needs to count them. COUNT needs to know the values are not NULLs, but NULL + values are not put into the Unique, so we don't need to check for NULLs here. +*/ + +bool Aggregator_distinct::unique_walk_function_for_count(void *element) +{ + Item_sum_count *sum= (Item_sum_count *)item_sum; + sum->count++; + return 0; +} + + Aggregator_distinct::~Aggregator_distinct() { if (tree) @@ -1581,9 +1621,10 @@ void Item_sum_avg::fix_length_and_dec() f_scale= args[0]->decimals; dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale); } - else { + else + { decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC); - max_length= args[0]->max_length + prec_increment; + max_length= min(args[0]->max_length + prec_increment, float_length(decimals)); } } @@ -3287,8 +3328,12 @@ bool Item_func_group_concat::add() TREE_ELEMENT *el= 0; // Only for safety if (row_eligible && tree) { + DBUG_EXECUTE_IF("trigger_OOM_in_gconcat_add", + DBUG_SET("+d,simulate_persistent_out_of_memory");); el= tree_insert(tree, table->record[0] + table->s->null_bytes, 0, tree->custom_arg); + DBUG_EXECUTE_IF("trigger_OOM_in_gconcat_add", + DBUG_SET("-d,simulate_persistent_out_of_memory");); /* check if there was enough memory to insert the row */ if (!el) return 1; diff --git a/sql/item_sum.h b/sql/item_sum.h index 40a28d8beae..a954b0f65c1 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -642,6 +642,7 @@ public: virtual bool arg_is_null(); bool unique_walk_function(void *element); + bool unique_walk_function_for_count(void *element); static int composite_key_cmp(void* arg, uchar* key1, uchar* key2); }; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 02a7b8511af..69a6dac5381 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -923,16 +923,14 @@ longlong Item_func_dayofmonth::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - (void) get_arg0_date(<ime, TIME_FUZZY_DATE); - return (longlong) ltime.day; + return get_arg0_date(<ime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.day; } longlong Item_func_month::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - (void) get_arg0_date(<ime, TIME_FUZZY_DATE); - return (longlong) ltime.month; + return get_arg0_date(<ime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.month; } @@ -983,16 +981,14 @@ longlong Item_func_hour::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - (void) get_arg0_time(<ime); - return ltime.hour; + return get_arg0_time(<ime) ? 0 : ltime.hour; } longlong Item_func_minute::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - (void) get_arg0_time(<ime); - return ltime.minute; + return get_arg0_time(<ime) ? 0 : ltime.minute; } /** @@ -1002,8 +998,7 @@ longlong Item_func_second::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - (void) get_arg0_time(<ime); - return ltime.second; + return get_arg0_time(<ime) ? 0 : ltime.second; } @@ -1120,8 +1115,7 @@ longlong Item_func_year::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - (void) get_arg0_date(<ime, TIME_FUZZY_DATE); - return (longlong) ltime.year; + return get_arg0_date(<ime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.year; } diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 3e3cd698efc..9b2db9e816e 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -491,6 +491,7 @@ public: enum Item_result result_type () const { return STRING_RESULT; } CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; } enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } + Item_result cmp_type() const { return TIME_RESULT; } String *val_str(String *str); longlong val_int(); double val_real(); diff --git a/sql/key.cc b/sql/key.cc index dd7818119c8..0d3db2d5bf5 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -335,6 +335,70 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length) return 0; } + +/** + Unpack a field and append it. + + @param[inout] to String to append the field contents to. + @param field Field to unpack. + @param rec Record which contains the field data. + @param max_length Maximum length of field to unpack + or 0 for unlimited. + @param prefix_key The field is used as a prefix key. +*/ + +void field_unpack(String *to, Field *field, const uchar *rec, uint max_length, + bool prefix_key) +{ + String tmp; + DBUG_ENTER("field_unpack"); + if (!max_length) + max_length= field->pack_length(); + if (field) + { + if (field->is_null()) + { + to->append(STRING_WITH_LEN("NULL")); + DBUG_VOID_RETURN; + } + CHARSET_INFO *cs= field->charset(); + field->val_str(&tmp); + /* + For BINARY(N) strip trailing zeroes to make + the error message nice-looking + */ + if (field->binary() && field->type() == MYSQL_TYPE_STRING && tmp.length()) + { + const char *tmp_end= tmp.ptr() + tmp.length(); + while (tmp_end > tmp.ptr() && !*--tmp_end) ; + tmp.length(tmp_end - tmp.ptr() + 1); + } + if (cs->mbmaxlen > 1 && prefix_key) + { + /* + Prefix key, multi-byte charset. + For the columns of type CHAR(N), the above val_str() + call will return exactly "key_part->length" bytes, + which can break a multi-byte characters in the middle. + Align, returning not more than "char_length" characters. + */ + uint charpos, char_length= max_length / cs->mbmaxlen; + if ((charpos= my_charpos(cs, tmp.ptr(), + tmp.ptr() + tmp.length(), + char_length)) < tmp.length()) + tmp.length(charpos); + } + if (max_length < field->pack_length()) + tmp.length(min(tmp.length(),max_length)); + ErrConvString err(&tmp); + to->append(err.ptr()); + } + else + to->append(STRING_WITH_LEN("???")); + DBUG_VOID_RETURN; +} + + /* unpack key-fields from record to some buffer. @@ -352,8 +416,6 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length) void key_unpack(String *to,TABLE *table,uint idx) { KEY_PART_INFO *key_part,*key_part_end; - Field *field; - String tmp; my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set); DBUG_ENTER("key_unpack"); @@ -369,47 +431,13 @@ void key_unpack(String *to,TABLE *table,uint idx) { if (table->record[0][key_part->null_offset] & key_part->null_bit) { - to->append(STRING_WITH_LEN("NULL")); - continue; - } - } - if ((field=key_part->field)) - { - CHARSET_INFO *cs= field->charset(); - field->val_str(&tmp); - /* - For BINARY(N) strip trailing zeroes to make - the error message nice-looking - */ - if (field->binary() && field->type() == MYSQL_TYPE_STRING && tmp.length()) - { - const char *tmp_end= tmp.ptr() + tmp.length(); - while (tmp_end > tmp.ptr() && !*--tmp_end) ; - tmp.length(tmp_end - tmp.ptr() + 1); - } - if (cs->mbmaxlen > 1 && (key_part->key_part_flag & HA_PART_KEY_SEG)) - { - /* - Prefix key, multi-byte charset. - For the columns of type CHAR(N), the above val_str() - call will return exactly "key_part->length" bytes, - which can break a multi-byte characters in the middle. - Align, returning not more than "char_length" characters. - */ - uint charpos, char_length= key_part->length / cs->mbmaxlen; - if ((charpos= my_charpos(cs, tmp.ptr(), - tmp.ptr() + tmp.length(), - char_length)) < tmp.length()) - tmp.length(charpos); + to->append(STRING_WITH_LEN("NULL")); + continue; } - if (key_part->length < field->pack_length()) - tmp.length(min(tmp.length(),key_part->length)); - ErrConvString err(&tmp); - to->append(err.ptr()); } - else - to->append(STRING_WITH_LEN("???")); - } + field_unpack(to, key_part->field, table->record[0], key_part->length, + test(key_part->key_part_flag & HA_PART_KEY_SEG)); + } dbug_tmp_restore_column_map(table->read_set, old_map); DBUG_VOID_RETURN; } diff --git a/sql/key.h b/sql/key.h index 8bf6f88fa04..0eeda58cd17 100644 --- a/sql/key.h +++ b/sql/key.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,6 +33,8 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, uint key_length); bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length); void key_unpack(String *to,TABLE *form,uint index); +void field_unpack(String *to, Field *field, const uchar *rec, uint max_length, + bool prefix_key); bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields); int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length); ulong key_hashnr(KEY *key_info, uint used_key_parts, const uchar *key); diff --git a/sql/log.cc b/sql/log.cc index c5b69214290..f7d3b62b0d0 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -175,7 +175,7 @@ Silence_log_table_errors::handle_condition(THD *, MYSQL_ERROR ** cond_hdl) { *cond_hdl= NULL; - strmake(m_message, msg, sizeof(m_message)-1); + strmake_buf(m_message, msg); return TRUE; } @@ -2425,7 +2425,7 @@ static int find_uniq_filename(char *name) my_dirend(dir_info); /* check if reached the maximum possible extension number */ - if ((max_found == MAX_LOG_UNIQUE_FN_EXT)) + if (max_found == MAX_LOG_UNIQUE_FN_EXT) { sql_print_error("Log filename extension number exhausted: %06lu. \ Please fix this by archiving old logs and \ @@ -3355,8 +3355,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, mysql_file_sync(log_file.file, MYF(MY_WME|MY_SYNC_FILESIZE))) goto err; mysql_mutex_lock(&LOCK_commit_ordered); - strmake(last_commit_pos_file, log_file_name, - sizeof(last_commit_pos_file)-1); + strmake_buf(last_commit_pos_file, log_file_name); last_commit_pos_offset= my_b_tell(&log_file); mysql_mutex_unlock(&LOCK_commit_ordered); @@ -3425,7 +3424,7 @@ int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo) int MYSQL_BIN_LOG::raw_get_current_log(LOG_INFO* linfo) { - strmake(linfo->log_file_name, log_file_name, sizeof(linfo->log_file_name)-1); + strmake_buf(linfo->log_file_name, log_file_name); linfo->pos = my_b_tell(&log_file); return 0; } @@ -3863,8 +3862,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) Reset rli's coordinates to the current log. */ rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); /* If we removed the rli->group_relay_log_name file, @@ -3874,8 +3872,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) if (included) { rli->group_relay_log_pos = BIN_LOG_HEADER_SIZE; - strmake(rli->group_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->group_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name,rli->linfo.log_file_name); rli->notify_group_relay_log_name_update(); } @@ -4385,9 +4382,7 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) else { if (stat_area.st_mtime < purge_time) - strmake(to_log, - log_info.log_file_name, - sizeof(log_info.log_file_name) - 1); + strmake_buf(to_log, log_info.log_file_name); else break; } @@ -5003,8 +4998,7 @@ binlog_start_consistent_snapshot(handlerton *hton, THD *thd) binlog_cache_mngr *const cache_mngr= thd->binlog_setup_trx_data(); /* Server layer calls us with LOCK_commit_ordered locked, so this is safe. */ - strmake(cache_mngr->last_commit_pos_file, mysql_bin_log.last_commit_pos_file, - sizeof(cache_mngr->last_commit_pos_file)-1); + strmake_buf(cache_mngr->last_commit_pos_file, mysql_bin_log.last_commit_pos_file); cache_mngr->last_commit_pos_offset= mysql_bin_log.last_commit_pos_offset; trans_register_ha(thd, TRUE, hton); @@ -6249,8 +6243,7 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) current->error= write_transaction_or_stmt(current); - strmake(cache_mngr->last_commit_pos_file, log_file_name, - sizeof(cache_mngr->last_commit_pos_file)-1); + strmake_buf(cache_mngr->last_commit_pos_file, log_file_name); commit_offset= my_b_write_tell(&log_file); cache_mngr->last_commit_pos_offset= commit_offset; if (cache_mngr->using_xa && cache_mngr->xa_xid) @@ -7628,7 +7621,7 @@ int TC_LOG_BINLOG::open(const char *opt_name) do { - strmake(log_name, log_info.log_file_name, sizeof(log_name)-1); + strmake_buf(log_name, log_info.log_file_name); } while (!(error= find_next_log(&log_info, 1))); if (error != LOG_INFO_EOF) @@ -7943,7 +7936,7 @@ static void set_binlog_snapshot_file(const char *src) { int dir_len = dirname_length(src); - strmake(binlog_snapshot_file, src + dir_len, sizeof(binlog_snapshot_file)-1); + strmake_buf(binlog_snapshot_file, src + dir_len); } /* diff --git a/sql/log_event.cc b/sql/log_event.cc index e9f79bc1354..21c6a64df90 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -625,16 +625,18 @@ static inline int read_str(const char **buf, const char *buf_end, /** - Transforms a string into "" or its expression in 0x... form. + Transforms a string into "" or its expression in X'HHHH' form. */ char *str_to_hex(char *to, const char *from, uint len) { if (len) { - *to++= '0'; - *to++= 'x'; + *to++= 'X'; + *to++= '\''; to= octet2hex(to, from, len); + *to++= '\''; + *to= '\0'; } else to= strmov(to, "\"\""); @@ -655,7 +657,7 @@ append_query_string(THD *thd, CHARSET_INFO *csinfo, { char *beg, *ptr; uint32 const orig_len= to->length(); - if (to->reserve(orig_len + from->length()*2+3)) + if (to->reserve(orig_len + from->length() * 2 + 4)) return 1; beg= (char*) to->ptr() + to->length(); @@ -1217,7 +1219,9 @@ bool Log_event::write_header(IO_CACHE* file, ulong event_data_length) int Log_event::read_log_event(IO_CACHE* file, String* packet, mysql_mutex_t* log_lock, - uint8 checksum_alg_arg) + uint8 checksum_alg_arg, + const char *log_file_name_arg, + bool* is_binlog_active) { ulong data_len; int result=0; @@ -1227,6 +1231,10 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, if (log_lock) mysql_mutex_lock(log_lock); + + if (log_file_name_arg) + *is_binlog_active= mysql_bin_log.is_active(log_file_name_arg); + if (my_b_read(file, (uchar*) buf, sizeof(buf))) { /* @@ -1372,7 +1380,7 @@ failed my_b_read")); Log_event *res= 0; #ifndef max_allowed_packet THD *thd=current_thd; - uint max_allowed_packet= thd ? slave_max_allowed_packet:~(ulong)0; + uint max_allowed_packet= thd ? slave_max_allowed_packet:~(uint)0; #endif if (data_len > max_allowed_packet) @@ -1807,6 +1815,7 @@ void Log_event::print_header(IO_CACHE* file, /** Prints a quoted string to io cache. Control characters are displayed as hex sequence, e.g. \x00 + Single-quote and backslash characters are escaped with a \ @param[in] file IO cache @param[in] prt Pointer to string @@ -1822,6 +1831,10 @@ my_b_write_quoted(IO_CACHE *file, const uchar *ptr, uint length) { if (*s > 0x1F) my_b_write(file, s, 1); + else if (*s == '\'') + my_b_write(file, "\\'", 2); + else if (*s == '\\') + my_b_write(file, "\\\\", 2); else { uchar hex[10]; @@ -6289,7 +6302,7 @@ void User_var_log_event::pack_info(THD *thd, Protocol* protocol) buf.append(" ")) return; old_len= buf.length(); - if (buf.reserve(old_len + val_len*2 + 2 + sizeof(" COLLATE ") + + if (buf.reserve(old_len + val_len * 2 + 3 + sizeof(" COLLATE ") + MY_CS_NAME_SIZE)) return; beg= const_cast<char *>(buf.ptr()) + old_len; @@ -6332,10 +6345,9 @@ User_var_log_event(const char* buf, uint event_len, /* We don't know yet is_null value, so we must assume that name_len may have the bigger value possible, is_null= True and there is no - payload for val. + payload for val, or even that name_len is 0. */ - if (0 == name_len || - !valid_buffer_range<uint>(name_len, buf_start, name, + if (!valid_buffer_range<uint>(name_len, buf_start, name, event_len - UV_VAL_IS_NULL)) { error= true; @@ -6558,7 +6570,8 @@ void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) char *hex_str; CHARSET_INFO *cs; - hex_str= (char *)my_malloc(2*val_len+1+2,MYF(MY_WME)); // 2 hex digits / byte + // 2 hex digits / byte + hex_str= (char *) my_malloc(2 * val_len + 1 + 3, MYF(MY_WME)); if (!hex_str) return; str_to_hex(hex_str, val, val_len); @@ -9516,6 +9529,7 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli) table_list->table_id= DBUG_EVALUATE_IF("inject_tblmap_same_id_maps_diff_table", 0, m_table_id); table_list->updating= 1; + table_list->required_type= FRMTYPE_TABLE; DBUG_PRINT("debug", ("table: %s is mapped to %u", table_list->table_name, table_list->table_id)); enum_tbl_map_status tblmap_status= check_table_map(rli, table_list); if (tblmap_status == OK_TO_PROCESS) diff --git a/sql/log_event.h b/sql/log_event.h index 99c9a0fb1d7..6f5e64eb8f3 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1056,8 +1056,35 @@ public: const Format_description_log_event *description_event, my_bool crc_check); + + /** + Reads an event from a binlog or relay log. Used by the dump thread + this method reads the event into a raw buffer without parsing it. + + @Note If mutex is 0, the read will proceed without mutex. + + @Note If a log name is given than the method will check if the + given binlog is still active. + + @param[in] file log file to be read + @param[out] packet packet to hold the event + @param[in] lock the lock to be used upon read + @param[in] log_file_name_arg the log's file name + @param[out] is_binlog_active is the current log still active + + @retval 0 success + @retval LOG_READ_EOF end of file, nothing was read + @retval LOG_READ_BOGUS malformed event + @retval LOG_READ_IO io error while reading + @retval LOG_READ_MEM packet memory allocation failed + @retval LOG_READ_TRUNC only a partial event could be read + @retval LOG_READ_TOO_LARGE event too large + */ static int read_log_event(IO_CACHE* file, String* packet, - mysql_mutex_t* log_lock, uint8 checksum_alg_arg); + mysql_mutex_t* log_lock, + uint8 checksum_alg_arg, + const char *log_file_name_arg = NULL, + bool* is_binlog_active = NULL); /* init_show_field_list() prepares the column names and types for the output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG diff --git a/sql/multi_range_read.cc b/sql/multi_range_read.cc index 800602fe9e1..175405790b5 100644 --- a/sql/multi_range_read.cc +++ b/sql/multi_range_read.cc @@ -1648,7 +1648,7 @@ int DsMrr_impl::dsmrr_explain_info(uint mrr_mode, char *str, size_t size) uint used_str_len= strlen(used_str); uint copy_len= min(used_str_len, size); - memcpy(str, used_str, size); + memcpy(str, used_str, copy_len); return copy_len; } return 0; diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 6e2c6ec07f3..9c1a234241f 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -54,6 +54,7 @@ static char *opt_os_password; static my_bool opt_default_user; static my_bool opt_allow_remote_root_access; static my_bool opt_skip_networking; +static my_bool opt_verbose_bootstrap; static my_bool verbose_errors; @@ -83,6 +84,8 @@ static struct my_option my_long_options[]= 0, 0}, {"silent", 's', "Print less information", &opt_silent, &opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose-bootstrap", 'o', "Include mysqld bootstrap output",&opt_verbose_bootstrap, + &opt_verbose_bootstrap, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -244,11 +247,12 @@ static char *init_bootstrap_command_line(char *cmdline, size_t size) get_basedir(basedir, sizeof(basedir), mysqld_path); my_snprintf(cmdline, size-1, - "\"\"%s\" --no-defaults --bootstrap" - " \"--language=%s\\share\\english\"" + "\"\"%s\" --no-defaults %s --bootstrap" + " \"--lc-messages-dir=%s/share\"" " --basedir=. --datadir=. --default-storage-engine=myisam" " --max_allowed_packet=9M --loose-skip-innodb" - " --net-buffer-length=16k\"", mysqld_path, basedir); + " --net-buffer-length=16k\"", mysqld_path, + opt_verbose_bootstrap?"--console":"", basedir ); return cmdline; } @@ -377,7 +381,7 @@ static int register_service() static void clean_directory(const char *dir) { char dir2[MAX_PATH+2]; - *(strmake(dir2, dir, MAX_PATH+1)+1)= 0; + *(strmake_buf(dir2, dir)+1)= 0; SHFILEOPSTRUCT fileop; fileop.hwnd= NULL; /* no status display */ @@ -552,7 +556,9 @@ static int create_db_instance() /* Do mysqld --bootstrap. */ init_bootstrap_command_line(cmdline, sizeof(cmdline)); - /* verbose("Executing %s", cmdline); */ + + if(opt_verbose_bootstrap) + printf("Executing %s\n", cmdline); in= popen(cmdline, "wt"); if (!in) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ce8431fbcbd..9276952491d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2288,8 +2288,28 @@ static my_socket activate_tcp_port(uint port) for (a= ai; a != NULL; a= a->ai_next) { ip_sock= socket(a->ai_family, a->ai_socktype, a->ai_protocol); - if (ip_sock != INVALID_SOCKET) + + char ip_addr[INET6_ADDRSTRLEN]; + + if (vio_get_normalized_ip_string(a->ai_addr, a->ai_addrlen, + ip_addr, sizeof (ip_addr))) + { + ip_addr[0]= 0; + } + + if (ip_sock == INVALID_SOCKET) + { + sql_print_error("Failed to create a socket for %s '%s': errno: %d.", + (a->ai_family == AF_INET) ? "IPv4" : "IPv6", + (const char *) ip_addr, + (int) socket_errno); + } + else + { + sql_print_information("Server socket created on IP: '%s'.", + (const char *) ip_addr); break; + } } if (ip_sock == INVALID_SOCKET) @@ -3346,14 +3366,25 @@ sizeof(load_default_groups)/sizeof(load_default_groups[0]); #ifndef EMBEDDED_LIBRARY -static -int -check_enough_stack_size() +/** + This function is used to check for stack overrun for pathological + cases of regular expressions and 'like' expressions. + The call to current_thd is quite expensive, so we try to avoid it + for the normal cases. + The size of each stack frame for the wildcmp() routines is ~128 bytes, + so checking *every* recursive call is not necessary. + */ +extern "C" int +check_enough_stack_size(int recurse_level) { uchar stack_top; + if (recurse_level % 16 != 0) + return 0; - return check_stack_overrun(current_thd, STACK_MIN_SIZE, - &stack_top); + THD *my_thd= current_thd; + if (my_thd != NULL) + return check_stack_overrun(my_thd, STACK_MIN_SIZE * 2, &stack_top); + return 0; } #endif @@ -3582,7 +3613,7 @@ static int init_common_variables() WideCharToMultiByte(CP_UTF8,0, wtz_name, -1, system_time_zone, sizeof(system_time_zone) - 1, NULL, NULL); #else - strmake(system_time_zone, tz_name, sizeof(system_time_zone)-1); + strmake_buf(system_time_zone, tz_name); #endif /* _WIN32 */ #endif /* HAVE_TZNAME */ @@ -3857,6 +3888,7 @@ static int init_common_variables() item_init(); #ifndef EMBEDDED_LIBRARY my_regex_init(&my_charset_latin1, check_enough_stack_size); + my_string_stack_guard= check_enough_stack_size; #else my_regex_init(&my_charset_latin1, NULL); #endif @@ -4425,11 +4457,13 @@ will be ignored as the --log-bin option is not defined."); } } #endif /* WITH_WSREP */ + DBUG_ASSERT(!opt_bin_log || opt_bin_logname); + if (opt_bin_log) { /* Reports an error and aborts, if the --log-bin's path is a directory.*/ - if (opt_bin_logname && + if (opt_bin_logname[0] && opt_bin_logname[strlen(opt_bin_logname) - 1] == FN_LIBCHAR) { sql_print_error("Path '%s' is a directory name, please specify \ @@ -4451,7 +4485,7 @@ a file name for --log-bin-index option", opt_binlog_index_name); char buf[FN_REFLEN]; const char *ln; ln= mysql_bin_log.generate_name(opt_bin_logname, "-bin", 1, buf); - if (!opt_bin_logname && !opt_binlog_index_name) + if (!opt_bin_logname[0] && !opt_binlog_index_name) { /* User didn't give us info to name the binlog index file. @@ -8102,8 +8136,8 @@ static int mysql_init_variables(void) /* Set directory paths */ mysql_real_data_home_len= - strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR), - sizeof(mysql_real_data_home)-1) - mysql_real_data_home; + strmake_buf(mysql_real_data_home, + get_relative_path(MYSQL_DATADIR)) - mysql_real_data_home; /* Replication parameters */ master_info_file= (char*) "master.info", relay_log_info_file= (char*) "relay-log.info"; @@ -8206,7 +8240,7 @@ static int mysql_init_variables(void) const char *tmpenv; if (!(tmpenv = getenv("MY_BASEDIR_VERSION"))) tmpenv = DEFAULT_MYSQL_HOME; - (void) strmake(mysql_home, tmpenv, sizeof(mysql_home)-1); + strmake_buf(mysql_home, tmpenv); #endif #ifdef WITH_WSREP if (WSREP_ON && wsrep_init_vars()) @@ -8249,7 +8283,7 @@ mysqld_get_one_option(int optid, global_system_variables.tx_isolation= ISO_SERIALIZABLE; break; case 'b': - strmake(mysql_home,argument,sizeof(mysql_home)-1); + strmake_buf(mysql_home, argument); break; case 'C': if (default_collation_name == compiled_default_collation_name) @@ -8260,7 +8294,7 @@ mysqld_get_one_option(int optid, opt_log=1; break; case 'h': - strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1); + strmake_buf(mysql_real_data_home, argument); /* Correct pointer set by my_getopt (for embedded library) */ mysql_real_data_home_ptr= mysql_real_data_home; break; @@ -8271,7 +8305,7 @@ mysqld_get_one_option(int optid, sql_print_warning("Ignoring user change to '%s' because the user was set to '%s' earlier on the command line\n", argument, mysqld_user); break; case 'L': - strmake(lc_messages_dir, argument, sizeof(lc_messages_dir)-1); + strmake_buf(lc_messages_dir, argument); break; case OPT_BINLOG_FORMAT: binlog_format_used= true; @@ -8451,28 +8485,6 @@ mysqld_get_one_option(int optid, case (int) OPT_WANT_CORE: test_flags |= TEST_CORE_ON_SIGNAL; break; - case (int) OPT_BIND_ADDRESS: - { - struct addrinfo *res_lst, hints; - - bzero(&hints, sizeof(struct addrinfo)); - hints.ai_socktype= SOCK_STREAM; - hints.ai_protocol= IPPROTO_TCP; - - if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0) - { - sql_print_error("Can't start server: cannot resolve hostname!"); - return 1; - } - - if (res_lst->ai_next) - { - sql_print_error("Can't start server: bind-address refers to multiple interfaces!"); - return 1; - } - freeaddrinfo(res_lst); - } - break; case OPT_CONSOLE: if (opt_console) opt_error_log= 0; // Force logs to stdout @@ -8986,7 +8998,7 @@ static int fix_paths(void) char *sharedir=get_relative_path(SHAREDIR); if (test_if_hard_path(sharedir)) - strmake(buff,sharedir,sizeof(buff)-1); /* purecov: tested */ + strmake_buf(buff, sharedir); /* purecov: tested */ else strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NullS); convert_dirname(buff,buff,NullS); @@ -8994,7 +9006,7 @@ static int fix_paths(void) /* If --character-sets-dir isn't given, use shared library dir */ if (charsets_dir) - strmake(mysql_charsets_dir, charsets_dir, sizeof(mysql_charsets_dir)-1); + strmake_buf(mysql_charsets_dir, charsets_dir); else strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff, CHARSET_DIR, NullS); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 36da59fd6ef..5d71ec71903 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -132,7 +132,12 @@ static int sel_cmp(Field *f,uchar *a,uchar *b,uint8 a_flag,uint8 b_flag); -static uchar is_null_string[2]= {1,0}; +/* + this should be long enough so that any memcmp with a string that + starts from '\0' won't cross is_null_string boundaries, even + if the memcmp is optimized to compare 4- 8- or 16- bytes at once +*/ +static uchar is_null_string[20]= {1,0}; class RANGE_OPT_PARAM; /* @@ -1996,7 +2001,7 @@ int QUICK_ROR_INTERSECT_SELECT::init() 1 error */ -int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) +int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc) { handler *save_file= file, *org_file; my_bool org_key_read; @@ -2024,7 +2029,7 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) DBUG_RETURN(0); } - if (!(file= head->file->clone(head->s->normalized_path.str, thd->mem_root))) + if (!(file= head->file->clone(head->s->normalized_path.str, alloc))) { /* Manually set the error flag. Note: there seems to be quite a few @@ -2125,7 +2130,8 @@ failure: 0 OK other error code */ -int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler) +int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler, + MEM_ROOT *alloc) { List_iterator_fast<QUICK_SELECT_WITH_RECORD> quick_it(quick_selects); QUICK_SELECT_WITH_RECORD *cur; @@ -2142,7 +2148,7 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler) There is no use of this->file. Use it for the first of merged range selects. */ - int error= quick->init_ror_merged_scan(TRUE); + int error= quick->init_ror_merged_scan(TRUE, alloc); if (error) DBUG_RETURN(error); quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS); @@ -2154,7 +2160,7 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler) const MY_BITMAP * const save_read_set= quick->head->read_set; const MY_BITMAP * const save_write_set= quick->head->write_set; #endif - if (quick->init_ror_merged_scan(FALSE)) + if (quick->init_ror_merged_scan(FALSE, alloc)) DBUG_RETURN(1); quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS); @@ -2188,7 +2194,7 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler) int QUICK_ROR_INTERSECT_SELECT::reset() { DBUG_ENTER("QUICK_ROR_INTERSECT_SELECT::reset"); - if (!scans_inited && init_ror_merged_scan(TRUE)) + if (!scans_inited && init_ror_merged_scan(TRUE, &alloc)) DBUG_RETURN(1); scans_inited= TRUE; List_iterator_fast<QUICK_SELECT_WITH_RECORD> it(quick_selects); @@ -2324,7 +2330,7 @@ int QUICK_ROR_UNION_SELECT::reset() List_iterator_fast<QUICK_SELECT_I> it(quick_selects); while ((quick= it++)) { - if (quick->init_ror_merged_scan(FALSE)) + if (quick->init_ror_merged_scan(FALSE, &alloc)) DBUG_RETURN(1); } scans_inited= TRUE; @@ -7288,6 +7294,14 @@ static SEL_TREE *get_full_func_mm_tree(RANGE_OPT_PARAM *param, param->current_table); DBUG_ENTER("get_full_func_mm_tree"); +#ifdef HAVE_SPATIAL + if (field_item->field->type() == MYSQL_TYPE_GEOMETRY) + { + /* We have to be able to store all sorts of spatial features here */ + ((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY; + } +#endif /*HAVE_SPATIAL*/ + for (uint i= 0; i < cond_func->arg_count; i++) { Item *arg= cond_func->arguments()[i]->real_item(); @@ -7367,8 +7381,10 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond) DBUG_RETURN(tree); } /* Here when simple cond */ - if (cond->const_item() && !cond->is_expensive()) + if (cond->const_item()) { + if (cond->is_expensive()) + DBUG_RETURN(0); /* During the cond->val_int() evaluation we can come across a subselect item which may allocate memory on the thd->mem_root and assumes @@ -10845,9 +10861,13 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() do { + DBUG_EXECUTE_IF("innodb_quick_report_deadlock", + DBUG_SET("+d,innodb_report_deadlock");); if ((error= quick->get_next())) { - quick_with_last_rowid->file->unlock_row(); + /* On certain errors like deadlock, trx might be rolled back.*/ + if (!current_thd->transaction_rollback_request) + quick_with_last_rowid->file->unlock_row(); DBUG_RETURN(error); } quick->file->position(quick->record); @@ -10873,7 +10893,9 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() quick->file->unlock_row(); /* row not in range; unlock */ if ((error= quick->get_next())) { - quick_with_last_rowid->file->unlock_row(); + /* On certain errors like deadlock, trx might be rolled back.*/ + if (!current_thd->transaction_rollback_request) + quick_with_last_rowid->file->unlock_row(); DBUG_RETURN(error); } } @@ -11758,13 +11780,15 @@ cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts, NGA1.If in the index I there is a gap between the last GROUP attribute G_k, and the MIN/MAX attribute C, then NGA must consist of exactly the index attributes that constitute the gap. As a result there is a - permutation of NGA that coincides with the gap in the index - <B_1, ..., B_m>. + permutation of NGA, BA=<B_1,...,B_m>, that coincides with the gap + in the index. NGA2.If BA <> {}, then the WHERE clause must contain a conjunction EQ of equality conditions for all NG_i of the form (NG_i = const) or (const = NG_i), such that each NG_i is referenced in exactly one conjunct. Informally, the predicates provide constants to fill the gap in the index. + NGA3.If BA <> {}, there can only be one range. TODO: This is a code + limitation and is not strictly needed. See BUG#15947433 WA1. There are no other attributes in the WHERE clause except the ones referenced in predicates RNG, PA, PC, EQ defined above. Therefore WA is subset of (GA union NGA union C) for GA,NGA,C that pass the @@ -12507,6 +12531,74 @@ check_group_min_max_predicates(Item *cond, Item_field *min_max_arg_item, /* + Get SEL_ARG tree, if any, for the keypart covering non grouping + attribute (NGA) field 'nga_field'. + + This function enforces the NGA3 test: If 'keypart_tree' contains a + condition for 'nga_field', there can only be one range. In the + opposite case, this function returns with error and 'cur_range' + should not be used. + + Note that the NGA1 and NGA2 requirements, like whether or not the + range predicate for 'nga_field' is equality, is not tested by this + function. + + @param[in] nga_field The NGA field we want the SEL_ARG tree for + @param[in] keypart_tree Root node of the SEL_ARG* tree for the index + @param[out] cur_range The SEL_ARG tree, if any, for the keypart + covering field 'keypart_field' + @retval true 'keypart_tree' contained a predicate for 'nga_field' but + multiple ranges exists. 'cur_range' should not be used. + @retval false otherwise +*/ + +static bool +get_sel_arg_for_keypart(Field *nga_field, + SEL_ARG *keypart_tree, + SEL_ARG **cur_range) +{ + if(keypart_tree == NULL) + return false; + if(keypart_tree->field->eq(nga_field)) + { + /* + Enforce NGA3: If a condition for nga_field has been found, only + a single range is allowed. + */ + if (keypart_tree->prev || keypart_tree->next) + return true; // There are multiple ranges + + *cur_range= keypart_tree; + return false; + } + + SEL_ARG *found_tree= NULL; + SEL_ARG *first_kp= keypart_tree->first(); + + for (SEL_ARG *cur_kp= first_kp; cur_kp && !found_tree; + cur_kp= cur_kp->next) + { + if (cur_kp->next_key_part) + { + if (get_sel_arg_for_keypart(nga_field, + cur_kp->next_key_part, + &found_tree)) + return true; + + } + /* + Enforce NGA3: If a condition for nga_field has been found,only + a single range is allowed. + */ + if (found_tree && first_kp->next) + return true; // There are multiple ranges + } + *cur_range= found_tree; + return false; +} + + +/* Extract a sequence of constants from a conjunction of equality predicates. SYNOPSIS @@ -12520,12 +12612,13 @@ check_group_min_max_predicates(Item *cond, Item_field *min_max_arg_item, key_infix [out] Infix of constants to be used for index lookup key_infix_len [out] Lenghth of the infix first_non_infix_part [out] The first keypart after the infix (if any) - + DESCRIPTION - Test conditions (NGA1, NGA2) from get_best_group_min_max(). Namely, - for each keypart field NGF_i not in GROUP-BY, check that there is a - constant equality predicate among conds with the form (NGF_i = const_ci) or - (const_ci = NGF_i). + Test conditions (NGA1, NGA2, NGA3) from get_best_group_min_max(). Namely, + for each keypart field NG_i not in GROUP-BY, check that there is exactly one + constant equality predicate among conds with the form (NG_i = const_ci) or + (const_ci = NG_i).. In addition, there can only be one range when there is + such a gap. Thus all the NGF_i attributes must fill the 'gap' between the last group-by attribute and the MIN/MAX attribute in the index (if present). If these conditions hold, copy each constant from its corresponding predicate into @@ -12554,17 +12647,14 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree, uchar *key_ptr= key_infix; for (cur_part= first_non_group_part; cur_part != end_part; cur_part++) { + cur_range= NULL; /* Find the range tree for the current keypart. We assume that - index_range_tree points to the leftmost keypart in the index. + index_range_tree points to the first keypart in the index. */ - for (cur_range= index_range_tree; - cur_range && cur_range->type == SEL_ARG::KEY_RANGE; - cur_range= cur_range->next_key_part) - { - if (cur_range->field->eq(cur_part->field)) - break; - } + if(get_sel_arg_for_keypart(cur_part->field, index_range_tree, &cur_range)) + return false; + if (!cur_range || cur_range->type != SEL_ARG::KEY_RANGE) { if (min_max_arg_part) @@ -12576,9 +12666,6 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree, } } - /* Check that the current range tree is a single point interval. */ - if (cur_range->prev || cur_range->next) - return FALSE; /* This is not the only range predicate for the field. */ if ((cur_range->min_flag & NO_MIN_RANGE) || (cur_range->max_flag & NO_MAX_RANGE) || (cur_range->min_flag & NEAR_MIN) || (cur_range->max_flag & NEAR_MAX)) diff --git a/sql/opt_range.h b/sql/opt_range.h index c59b2a7eb02..fff6e414ad9 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -323,7 +323,7 @@ public: 0 Ok other Error */ - virtual int init_ror_merged_scan(bool reuse_handler) + virtual int init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc) { DBUG_ASSERT(0); return 1; } /* @@ -473,7 +473,7 @@ public: uchar *cur_prefix); bool reverse_sorted() { return 0; } bool unique_key_range(); - int init_ror_merged_scan(bool reuse_handler); + int init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc); void save_last_pos() { file->position(record); } int get_type() { return QS_TYPE_RANGE; } @@ -722,7 +722,7 @@ public: #ifndef DBUG_OFF void dbug_dump(int indent, bool verbose); #endif - int init_ror_merged_scan(bool reuse_handler); + int init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc); bool push_quick_back(MEM_ROOT *alloc, QUICK_RANGE_SELECT *quick_sel_range); class QUICK_SELECT_WITH_RECORD : public Sql_alloc diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index dfe2ece76d9..c0a01dded35 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1509,6 +1509,9 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) */ parent_lex->leaf_tables.concat(&subq_lex->leaf_tables); + if (subq_lex->options & OPTION_SCHEMA_TABLE) + parent_lex->options |= OPTION_SCHEMA_TABLE; + /* Same as above for next_local chain (a theory: a next_local chain always starts with ::leaf_tables @@ -1725,6 +1728,9 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, */ parent_lex->leaf_tables.push_back(jtbm); + if (subq_pred->unit->first_select()->options & OPTION_SCHEMA_TABLE) + parent_lex->options |= OPTION_SCHEMA_TABLE; + /* Same as above for TABLE_LIST::next_local chain (a theory: a next_local chain always starts with ::leaf_tables diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index fa3a07b72c5..069fe6452e8 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -84,7 +84,7 @@ static ulonglong get_exact_record_count(List<TABLE_LIST> &tables) while ((tl= ti++)) { ha_rows tmp= tl->table->file->records(); - if ((tmp == HA_POS_ERROR)) + if (tmp == HA_POS_ERROR) return ULONGLONG_MAX; count*= tmp; } diff --git a/sql/partition_element.h b/sql/partition_element.h index 87f3d00e68c..4f03d91035a 100644 --- a/sql/partition_element.h +++ b/sql/partition_element.h @@ -1,7 +1,7 @@ #ifndef PARTITION_ELEMENT_INCLUDED #define PARTITION_ELEMENT_INCLUDED -/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -107,9 +107,8 @@ public: enum partition_state part_state; uint16 nodegroup_id; bool has_null_value; - /* signed_flag and max_value only relevant for subpartitions */ - bool signed_flag; - bool max_value; + bool signed_flag; // Range value signed + bool max_value; // MAXVALUE range partition_element() : part_max_rows(0), part_min_rows(0), range_value(0), diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 028afd7899e..d877491e770 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -1,5 +1,4 @@ -/* - Copyright (c) 2006, 2010, Oracle and/or its affiliates. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -2181,9 +2180,36 @@ int partition_info::fix_parser_data(THD *thd) if (!(part_type == RANGE_PARTITION || part_type == LIST_PARTITION)) { - /* Nothing to do for HASH/KEY partitioning */ + if (part_type == HASH_PARTITION && list_of_part_fields) + { + /* KEY partitioning, check ALGORITHM = N. Should not pass the parser! */ + if (key_algorithm > KEY_ALGORITHM_55) + { + my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); + DBUG_RETURN(true); + } + /* If not set, use DEFAULT = 2 for CREATE and ALTER! */ + if ((thd_sql_command(thd) == SQLCOM_CREATE_TABLE || + thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && + key_algorithm == KEY_ALGORITHM_NONE) + key_algorithm= KEY_ALGORITHM_55; + } DBUG_RETURN(FALSE); } + if (is_sub_partitioned() && list_of_subpart_fields) + { + /* KEY subpartitioning, check ALGORITHM = N. Should not pass the parser! */ + if (key_algorithm > KEY_ALGORITHM_55) + { + my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); + DBUG_RETURN(true); + } + /* If not set, use DEFAULT = 2 for CREATE and ALTER! */ + if ((thd_sql_command(thd) == SQLCOM_CREATE_TABLE || + thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && + key_algorithm == KEY_ALGORITHM_NONE) + key_algorithm= KEY_ALGORITHM_55; + } do { part_elem= it++; @@ -2232,6 +2258,263 @@ int partition_info::fix_parser_data(THD *thd) DBUG_RETURN(FALSE); } + +/** + helper function to compare strings that can also be + a NULL pointer. + + @param a char pointer (can be NULL). + @param b char pointer (can be NULL). + + @return false if equal + @retval true strings differs + @retval false strings is equal +*/ + +static bool strcmp_null(const char *a, const char *b) +{ + if (!a && !b) + return false; + if (a && b && !strcmp(a, b)) + return false; + return true; +} + + +/** + Check if the new part_info has the same partitioning. + + @param new_part_info New partition definition to compare with. + + @return True if not considered to have changed the partitioning. + @retval true Allowed change (only .frm change, compatible distribution). + @retval false Different partitioning, will need redistribution of rows. + + @note Currently only used to allow changing from non-set key_algorithm + to a specified key_algorithm, to avoid rebuild when upgrading from 5.1 of + such partitioned tables using numeric colums in the partitioning expression. + For more info see bug#14521864. + Does not check if columns etc has changed, i.e. only for + alter_info->flags == ALTER_PARTITION. +*/ + +bool partition_info::has_same_partitioning(partition_info *new_part_info) +{ + DBUG_ENTER("partition_info::has_same_partitioning"); + + DBUG_ASSERT(part_field_array && part_field_array[0]); + + /* + Only consider pre 5.5.3 .frm's to have same partitioning as + a new one with KEY ALGORITHM = 1 (). + */ + + if (part_field_array[0]->table->s->mysql_version >= 50503) + DBUG_RETURN(false); + + if (!new_part_info || + part_type != new_part_info->part_type || + num_parts != new_part_info->num_parts || + use_default_partitions != new_part_info->use_default_partitions || + new_part_info->is_sub_partitioned() != is_sub_partitioned()) + DBUG_RETURN(false); + + if (part_type != HASH_PARTITION) + { + /* + RANGE or LIST partitioning, check if KEY subpartitioned. + Also COLUMNS partitioning was added in 5.5, so treat that as different. + */ + if (!is_sub_partitioned() || + !new_part_info->is_sub_partitioned() || + column_list || + new_part_info->column_list || + !list_of_subpart_fields || + !new_part_info->list_of_subpart_fields || + new_part_info->num_subparts != num_subparts || + new_part_info->subpart_field_list.elements != + subpart_field_list.elements || + new_part_info->use_default_subpartitions != + use_default_subpartitions) + DBUG_RETURN(false); + } + else + { + /* Check if KEY partitioned. */ + if (!new_part_info->list_of_part_fields || + !list_of_part_fields || + new_part_info->part_field_list.elements != part_field_list.elements) + DBUG_RETURN(false); + } + + /* Check that it will use the same fields in KEY (fields) list. */ + List_iterator<char> old_field_name_it(part_field_list); + List_iterator<char> new_field_name_it(new_part_info->part_field_list); + char *old_name, *new_name; + while ((old_name= old_field_name_it++)) + { + new_name= new_field_name_it++; + if (!new_name || my_strcasecmp(system_charset_info, + new_name, + old_name)) + DBUG_RETURN(false); + } + + if (is_sub_partitioned()) + { + /* Check that it will use the same fields in KEY subpart fields list. */ + List_iterator<char> old_field_name_it(subpart_field_list); + List_iterator<char> new_field_name_it(new_part_info->subpart_field_list); + char *old_name, *new_name; + while ((old_name= old_field_name_it++)) + { + new_name= new_field_name_it++; + if (!new_name || my_strcasecmp(system_charset_info, + new_name, + old_name)) + DBUG_RETURN(false); + } + } + + if (!use_default_partitions) + { + /* + Loop over partitions/subpartition to verify that they are + the same, including state and name. + */ + List_iterator<partition_element> part_it(partitions); + List_iterator<partition_element> new_part_it(new_part_info->partitions); + uint i= 0; + do + { + partition_element *part_elem= part_it++; + partition_element *new_part_elem= new_part_it++; + /* + The following must match: + partition_name, tablespace_name, data_file_name, index_file_name, + engine_type, part_max_rows, part_min_rows, nodegroup_id. + (max_value, signed_flag, has_null_value only on partition level, + RANGE/LIST) + The following can differ: + - part_comment + part_state must be PART_NORMAL! + */ + if (!part_elem || !new_part_elem || + strcmp(part_elem->partition_name, + new_part_elem->partition_name) || + part_elem->part_state != PART_NORMAL || + new_part_elem->part_state != PART_NORMAL || + part_elem->max_value != new_part_elem->max_value || + part_elem->signed_flag != new_part_elem->signed_flag || + part_elem->has_null_value != new_part_elem->has_null_value) + DBUG_RETURN(false); + + /* new_part_elem may not have engine_type set! */ + if (new_part_elem->engine_type && + part_elem->engine_type != new_part_elem->engine_type) + DBUG_RETURN(false); + + if (is_sub_partitioned()) + { + /* + Check that both old and new partition has the same definition + (VALUES IN/VALUES LESS THAN) (No COLUMNS partitioning, see above) + */ + if (part_type == LIST_PARTITION) + { + List_iterator<part_elem_value> list_vals(part_elem->list_val_list); + List_iterator<part_elem_value> + new_list_vals(new_part_elem->list_val_list); + part_elem_value *val; + part_elem_value *new_val; + while ((val= list_vals++)) + { + new_val= new_list_vals++; + if (!new_val) + DBUG_RETURN(false); + if ((!val->null_value && !new_val->null_value) && + val->value != new_val->value) + DBUG_RETURN(false); + } + if (new_list_vals++) + DBUG_RETURN(false); + } + else + { + DBUG_ASSERT(part_type == RANGE_PARTITION); + if (new_part_elem->range_value != part_elem->range_value) + DBUG_RETURN(false); + } + + if (!use_default_subpartitions) + { + List_iterator<partition_element> + sub_part_it(part_elem->subpartitions); + List_iterator<partition_element> + new_sub_part_it(new_part_elem->subpartitions); + uint j= 0; + do + { + partition_element *sub_part_elem= sub_part_it++; + partition_element *new_sub_part_elem= new_sub_part_it++; + /* new_part_elem may not have engine_type set! */ + if (new_sub_part_elem->engine_type && + sub_part_elem->engine_type != new_part_elem->engine_type) + DBUG_RETURN(false); + + if (strcmp(sub_part_elem->partition_name, + new_sub_part_elem->partition_name) || + sub_part_elem->part_state != PART_NORMAL || + new_sub_part_elem->part_state != PART_NORMAL || + sub_part_elem->part_min_rows != + new_sub_part_elem->part_min_rows || + sub_part_elem->part_max_rows != + new_sub_part_elem->part_max_rows || + sub_part_elem->nodegroup_id != + new_sub_part_elem->nodegroup_id) + DBUG_RETURN(false); + + if (strcmp_null(sub_part_elem->data_file_name, + new_sub_part_elem->data_file_name) || + strcmp_null(sub_part_elem->index_file_name, + new_sub_part_elem->index_file_name) || + strcmp_null(sub_part_elem->tablespace_name, + new_sub_part_elem->tablespace_name)) + DBUG_RETURN(false); + + } while (++j < num_subparts); + } + } + else + { + if (part_elem->part_min_rows != new_part_elem->part_min_rows || + part_elem->part_max_rows != new_part_elem->part_max_rows || + part_elem->nodegroup_id != new_part_elem->nodegroup_id) + DBUG_RETURN(false); + + if (strcmp_null(part_elem->data_file_name, + new_part_elem->data_file_name) || + strcmp_null(part_elem->index_file_name, + new_part_elem->index_file_name) || + strcmp_null(part_elem->tablespace_name, + new_part_elem->tablespace_name)) + DBUG_RETURN(false); + } + } while (++i < num_parts); + } + + /* + Only if key_algorithm was not specified before and it is now set, + consider this as nothing was changed, and allow change without rebuild! + */ + if (key_algorithm != partition_info::KEY_ALGORITHM_NONE || + new_part_info->key_algorithm == partition_info::KEY_ALGORITHM_NONE) + DBUG_RETURN(false); + + DBUG_RETURN(true); +} + + void partition_info::print_debug(const char *str, uint *value) { DBUG_ENTER("print_debug"); diff --git a/sql/partition_info.h b/sql/partition_info.h index e59d4ec8ba4..d3706c8abf4 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -1,7 +1,7 @@ #ifndef PARTITION_INFO_INCLUDED #define PARTITION_INFO_INCLUDED -/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -192,6 +192,19 @@ public: but mainly of use to handlers supporting partitioning. */ uint16 linear_hash_mask; + /* + PARTITION BY KEY ALGORITHM=N + Which algorithm to use for hashing the fields. + N = 1 - Use 5.1 hashing (numeric fields are hashed as binary) + N = 2 - Use 5.5 hashing (numeric fields are hashed like latin1 bytes) + */ + enum enum_key_algorithm + { + KEY_ALGORITHM_NONE= 0, + KEY_ALGORITHM_51= 1, + KEY_ALGORITHM_55= 2 + }; + enum_key_algorithm key_algorithm; bool use_default_partitions; bool use_default_num_partitions; @@ -232,6 +245,7 @@ public: count_curr_subparts(0), part_error_code(0), num_list_values(0), num_part_fields(0), num_subpart_fields(0), num_full_part_fields(0), has_null_part_id(0), linear_hash_mask(0), + key_algorithm(KEY_ALGORITHM_NONE), use_default_partitions(TRUE), use_default_num_partitions(TRUE), use_default_subpartitions(TRUE), use_default_num_subpartitions(TRUE), default_partitions_setup(FALSE), defined_max_value(FALSE), @@ -298,6 +312,7 @@ public: bool add_column_list_value(THD *thd, Item *item); void set_show_version_string(String *packet); void report_part_expr_error(bool use_subpart_expr); + bool has_same_partitioning(partition_info *new_part_info); private: static int list_part_cmp(const void* a, const void* b); bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info, diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index 64525f81603..f9c8c8ea5b2 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -67,7 +67,7 @@ class Master_info : public Slave_reporting_capability /* the variables below are needed because we can change masters on the fly */ char master_log_name[FN_REFLEN]; char host[HOSTNAME_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1]; - char user[USERNAME_LENGTH*+1]; + char user[USERNAME_LENGTH+1]; char password[MAX_PASSWORD_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1]; bool ssl; // enables use of SSL connection if true char ssl_ca[FN_REFLEN], ssl_capath[FN_REFLEN], ssl_cert[FN_REFLEN]; diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index cbd7ac8f5ef..e03d46606d5 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -309,8 +309,7 @@ Failed to open the existing relay log info file '%s' (errno %d)", msg="Error reading slave log configuration"; goto err; } - strmake(rli->event_relay_log_name,rli->group_relay_log_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->group_relay_log_name); rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos; rli->group_master_log_pos= master_log_pos; @@ -528,10 +527,8 @@ int init_relay_log_pos(Relay_log_info* rli,const char* log, *errmsg="Could not find target log during relay log initialization"; goto err; } - strmake(rli->group_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name,rli->linfo.log_file_name); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); if (rli->relay_log.is_active(rli->linfo.log_file_name)) { /* @@ -871,8 +868,7 @@ void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, mysql_mutex_lock(&data_lock); inc_event_relay_log_pos(); group_relay_log_pos= event_relay_log_pos; - strmake(group_relay_log_name,event_relay_log_name, - sizeof(group_relay_log_name)-1); + strmake_buf(group_relay_log_name,event_relay_log_name); notify_group_relay_log_name_update(); @@ -1005,10 +1001,8 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, goto err; } /* Save name of used relay log file */ - strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname()); + strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname()); rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; if (count_relay_log_space(rli)) { diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index c83e52fe26b..ed6b9d13584 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -1172,6 +1172,7 @@ void Deferred_log_events::rewind() Log_event *ev= *(Log_event **) dynamic_array_ptr(&array, i); delete ev; } + last_added= NULL; if (array.elements > array.max_element) freeze_size(&array); reset_dynamic(&array); diff --git a/sql/set_var.cc b/sql/set_var.cc index 4e6354d9af4..7c3cec38601 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. - Copyright (c) 2008-2011 Monty Program Ab +/* Copyright (c) 2002, 2013, Oracle and/or its affiliates. + Copyright (c) 2008, 2011, Monty Program Ab This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -255,17 +255,14 @@ uchar *sys_var::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) return session_value_ptr(thd, base); } -bool sys_var::set_default(THD *thd, enum_var_type type) +bool sys_var::set_default(THD *thd, set_var* var) { - LEX_STRING empty={0,0}; - set_var var(type, 0, &empty, 0); - - if (type == OPT_GLOBAL || scope() == GLOBAL) - global_save_default(thd, &var); + if (var->type == OPT_GLOBAL || scope() == GLOBAL) + global_save_default(thd, var); else - session_save_default(thd, &var); + session_save_default(thd, var); - return check(thd, &var) || update(thd, &var); + return check(thd, var) || update(thd, var); } void sys_var::do_deprecated_warning(THD *thd) @@ -667,7 +664,7 @@ int set_var::light_check(THD *thd) */ int set_var::update(THD *thd) { - return value ? var->update(thd, this) : var->set_default(thd, type); + return value ? var->update(thd, this) : var->set_default(thd, this); } diff --git a/sql/set_var.h b/sql/set_var.h index ec6d2c28e6a..15707512663 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -1,6 +1,6 @@ #ifndef SET_VAR_INCLUDED #define SET_VAR_INCLUDED -/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. +/* Copyright (c) 2002, 2013, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -104,7 +104,13 @@ public: bool check(THD *thd, set_var *var); uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); - bool set_default(THD *thd, enum_var_type type); + + /** + Update the system variable with the default value from either + session or global scope. The default value is stored in the + 'var' argument. Return false when successful. + */ + bool set_default(THD *thd, set_var *var); bool update(THD *thd, set_var *var); SHOW_TYPE show_type() { return show_val_type; } diff --git a/sql/slave.cc b/sql/slave.cc index 89a325efb53..caef5acd5f1 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -362,16 +362,13 @@ int init_recovery(Master_info* mi, const char** errmsg) { mi->master_log_pos= max(BIN_LOG_HEADER_SIZE, rli->group_master_log_pos); - strmake(mi->master_log_name, rli->group_master_log_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, rli->group_master_log_name); sql_print_warning("Recovery from master pos %ld and file %s.", (ulong) mi->master_log_pos, mi->master_log_name); - strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(mi->rli.event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname()); + strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname()); rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; } @@ -1219,6 +1216,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) int err_code= 0; MYSQL_RES *master_res= 0; MYSQL_ROW master_row; + uint version= mysql_get_server_version(mysql) / 10000; DBUG_ENTER("get_master_version_and_clock"); /* @@ -1239,20 +1237,20 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) /* Note the following switch will bug when we have MySQL branch 30 ;) */ - switch (*mysql->server_version) + switch (version) { - case '0': - case '1': - case '2': + case 0: + case 1: + case 2: errmsg = "Master reported unrecognized MySQL version"; err_code= ER_SLAVE_FATAL_ERROR; sprintf(err_buff, ER(err_code), errmsg); break; - case '3': + case 3: mi->rli.relay_log.description_event_for_queue= new Format_description_log_event(1, mysql->server_version); break; - case '4': + case 4: mi->rli.relay_log.description_event_for_queue= new Format_description_log_event(3, mysql->server_version); break; @@ -1473,10 +1471,10 @@ maybe it is a *VERY OLD MASTER*."); */ /* redundant with rest of code but safer against later additions */ - if (*mysql->server_version == '3') + if (version == 3) goto err; - if (*mysql->server_version == '4') + if (version == 4) { master_res= NULL; if (!mysql_real_query(mysql, @@ -1539,7 +1537,7 @@ inconsistency if replicated data deals with collation."); This check is only necessary for 4.x masters (and < 5.0.4 masters but those were alpha). */ - if (*mysql->server_version == '4') + if (version == 4) { master_res= NULL; if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) && @@ -3612,8 +3610,8 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, mysql_mutex_lock(&rli->data_lock); if (rli->slave_skip_counter) { - strmake(saved_log_name, rli->group_relay_log_name, FN_REFLEN - 1); - strmake(saved_master_log_name, rli->group_master_log_name, FN_REFLEN - 1); + strmake_buf(saved_log_name, rli->group_relay_log_name); + strmake_buf(saved_master_log_name, rli->group_master_log_name); saved_log_pos= rli->group_relay_log_pos; saved_master_log_pos= rli->group_master_log_pos; saved_skip= rli->slave_skip_counter; @@ -5247,8 +5245,7 @@ static Log_event* next_event(Relay_log_info* rli) goto err; } rli->event_relay_log_pos = BIN_LOG_HEADER_SIZE; - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); flush_relay_log_info(rli); } diff --git a/sql/sp.cc b/sql/sp.cc index acd10bc45a4..269917d6863 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -114,7 +114,7 @@ TABLE_FIELD_TYPE proc_table_fields[MYSQL_PROC_FIELD_COUNT] = }, { { C_STRING_WITH_LEN("definer") }, - { C_STRING_WITH_LEN("char(77)") }, + { C_STRING_WITH_LEN("char(") }, { C_STRING_WITH_LEN("utf8") } }, { diff --git a/sql/sp_head.cc b/sql/sp_head.cc index be6dc935dcc..244fba2819c 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1160,8 +1160,9 @@ find_handler_after_execution(THD *thd, sp_rcontext *ctx) MYSQL_ERROR *err; while ((err= it++)) { - if (err->get_level() != MYSQL_ERROR::WARN_LEVEL_WARN && - err->get_level() != MYSQL_ERROR::WARN_LEVEL_NOTE) + if ((err->get_level() != MYSQL_ERROR::WARN_LEVEL_WARN && + err->get_level() != MYSQL_ERROR::WARN_LEVEL_NOTE) || + err->handled()) continue; if (ctx->find_handler(thd, @@ -1170,6 +1171,7 @@ find_handler_after_execution(THD *thd, sp_rcontext *ctx) err->get_level(), err->get_message_text())) { + err->mark_handled(); break; } } @@ -1419,6 +1421,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success) Will write this SP statement into binlog separately. TODO: consider changing the condition to "not inside event union". */ + MEM_ROOT *user_var_events_alloc_saved= thd->user_var_events_alloc; if (thd->locked_tables_mode <= LTM_LOCK_TABLES) thd->user_var_events_alloc= thd->mem_root; @@ -1434,7 +1437,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success) if (thd->locked_tables_mode <= LTM_LOCK_TABLES) { reset_dynamic(&thd->user_var_events); - thd->user_var_events_alloc= NULL;//DEBUG + thd->user_var_events_alloc= user_var_events_alloc_saved; } /* we should cleanup free_list and memroot, used by instruction */ diff --git a/sql/spatial.cc b/sql/spatial.cc index 267e038c5b8..2359f4fa271 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -312,6 +312,9 @@ bool Geometry::envelope(String *result) const const char *end; if (get_mbr(&mbr, &end)) + return 1; + + if (!mbr.valid()) { /* Empty geometry */ if (result->reserve(1 + 4*2)) @@ -444,18 +447,19 @@ const char *Geometry::append_points(String *txt, uint32 n_points, const char *Geometry::get_mbr_for_points(MBR *mbr, const char *data, uint offset) const { - uint32 points; + uint32 n_points; /* read number of points */ if (no_data(data, 4)) return 0; - points= uint4korr(data); + n_points= uint4korr(data); data+= 4; - if (no_data(data, (POINT_DATA_SIZE + offset) * points)) + if (n_points > max_n_points || + no_data(data, (POINT_DATA_SIZE + offset) * n_points)) return 0; /* Calculate MBR for points */ - while (points--) + while (n_points--) { data+= offset; mbr->add_xy(data, data + SIZEOF_STORED_DOUBLE); @@ -559,9 +563,12 @@ const Geometry::Class_info *Gis_point::get_class_info() const uint32 Gis_line_string::get_data_size() const { - if (no_data(m_data, 4)) + uint32 n_points, size; + if (no_data(m_data, 4) || + (n_points= uint4korr(m_data)) > max_n_points || + no_data(m_data, (size= 4 + n_points * POINT_DATA_SIZE))) return GET_SIZE_ERROR; - return 4 + uint4korr(m_data) * POINT_DATA_SIZE; + return size; } @@ -754,6 +761,9 @@ int Gis_line_string::end_point(String *result) const if (no_data(m_data, 4)) return 1; n_points= uint4korr(m_data); + if (n_points == 0 || n_points > max_n_points || + no_data(m_data, POINT_DATA_SIZE * n_points)) + return 1; return create_point(result, m_data + 4 + (n_points - 1) * POINT_DATA_SIZE); } @@ -763,11 +773,14 @@ int Gis_line_string::point_n(uint32 num, String *result) const uint32 n_points; if (no_data(m_data, 4)) return 1; + num--; n_points= uint4korr(m_data); - if ((uint32) (num - 1) >= n_points) // means (num > n_points || num < 1) + if (num >= n_points || + num > max_n_points || // means (num > n_points || num < 1) + no_data(m_data, num * POINT_DATA_SIZE)) return 1; - return create_point(result, m_data + 4 + (num - 1) * POINT_DATA_SIZE); + return create_point(result, m_data + 4 + num*POINT_DATA_SIZE); } @@ -817,6 +830,7 @@ const Geometry::Class_info *Gis_line_string::get_class_info() const uint32 Gis_polygon::get_data_size() const { uint32 n_linear_rings; + uint32 n_points; const char *data= m_data; if (no_data(data, 4)) @@ -826,10 +840,13 @@ uint32 Gis_polygon::get_data_size() const while (n_linear_rings--) { - if (no_data(data, 4)) + if (no_data(data, 4) || + (n_points= uint4korr(data)) > max_n_points) return GET_SIZE_ERROR; - data+= 4 + uint4korr(data)*POINT_DATA_SIZE; + data+= 4 + n_points*POINT_DATA_SIZE; } + if (no_data(data, 0)) + return GET_SIZE_ERROR; return (uint32) (data - m_data); } @@ -1022,7 +1039,8 @@ int Gis_polygon::area(double *ar, const char **end_of_data) const if (no_data(data, 4)) return 1; n_points= uint4korr(data); - if (n_points > max_n_points || no_data(data, POINT_DATA_SIZE * n_points)) + if (n_points == 0 || n_points > max_n_points || + no_data(data, POINT_DATA_SIZE * n_points)) return 1; get_point(&prev_x, &prev_y, data+4); data+= (4+POINT_DATA_SIZE); @@ -1126,13 +1144,11 @@ int Gis_polygon::centroid_xy(double *x, double *y) const const char *data= m_data; bool first_loop= 1; - if (no_data(data, 4)) + if (no_data(data, 4) || + (n_linear_rings= uint4korr(data)) == 0) return 1; - n_linear_rings= uint4korr(data); data+= 4; - DBUG_ASSERT(n_linear_rings > 0); - while (n_linear_rings--) { uint32 n_points, org_n_points; @@ -1145,7 +1161,8 @@ int Gis_polygon::centroid_xy(double *x, double *y) const return 1; org_n_points= n_points= uint4korr(data); data+= 4; - if (n_points > max_n_points || no_data(data, POINT_DATA_SIZE * n_points)) + if (n_points == 0 || n_points > max_n_points || + no_data(data, POINT_DATA_SIZE * n_points)) return 1; get_point(&prev_x, &prev_y, data); data+= POINT_DATA_SIZE; @@ -1273,9 +1290,14 @@ const Geometry::Class_info *Gis_polygon::get_class_info() const uint32 Gis_multi_point::get_data_size() const { - if (no_data(m_data, 4)) - return GET_SIZE_ERROR; - return 4 + uint4korr(m_data)*(POINT_DATA_SIZE + WKB_HEADER_SIZE); + uint32 n_points; + uint32 size; + + if (no_data(m_data, 4) || + (n_points= uint4korr(m_data)) > max_n_points || + no_data(m_data, (size= 4 + n_points*(POINT_DATA_SIZE + WKB_HEADER_SIZE)))) + return GET_SIZE_ERROR; + return size; } @@ -1369,8 +1391,8 @@ bool Gis_multi_point::get_data_as_wkt(String *txt, const char **end) const return 1; n_points= uint4korr(m_data); - if (no_data(m_data+4, - n_points * (POINT_DATA_SIZE + WKB_HEADER_SIZE)) || + if (n_points > max_n_points || + no_data(m_data+4, n_points * (POINT_DATA_SIZE + WKB_HEADER_SIZE)) || txt->reserve(((MAX_DIGITS_IN_DOUBLE + 1) * 2 + 1) * n_points)) return 1; *end= append_points(txt, n_points, m_data+4, WKB_HEADER_SIZE); @@ -1451,6 +1473,7 @@ const Geometry::Class_info *Gis_multi_point::get_class_info() const uint32 Gis_multi_line_string::get_data_size() const { uint32 n_line_strings; + uint32 n_points; const char *data= m_data; if (no_data(data, 4)) @@ -1460,11 +1483,13 @@ uint32 Gis_multi_line_string::get_data_size() const while (n_line_strings--) { - if (no_data(data, WKB_HEADER_SIZE + 4)) + if (no_data(data, WKB_HEADER_SIZE + 4) || + (n_points= uint4korr(data + WKB_HEADER_SIZE)) > max_n_points) return GET_SIZE_ERROR; - data+= (WKB_HEADER_SIZE + 4 + uint4korr(data + WKB_HEADER_SIZE) * - POINT_DATA_SIZE); + data+= (WKB_HEADER_SIZE + 4 + n_points*POINT_DATA_SIZE); } + if (no_data(data, 0)) + return GET_SIZE_ERROR; return (uint32) (data - m_data); } @@ -1649,7 +1674,7 @@ int Gis_multi_line_string::geometry_n(uint32 num, String *result) const return 1; n_points= uint4korr(data + WKB_HEADER_SIZE); length= WKB_HEADER_SIZE + 4+ POINT_DATA_SIZE * n_points; - if (no_data(data, length)) + if (n_points > max_n_points || no_data(data, length)) return 1; if (!--num) break; @@ -1760,6 +1785,7 @@ const Geometry::Class_info *Gis_multi_line_string::get_class_info() const uint32 Gis_multi_polygon::get_data_size() const { uint32 n_polygons; + uint32 n_points; const char *data= m_data; if (no_data(data, 4)) @@ -1778,11 +1804,14 @@ uint32 Gis_multi_polygon::get_data_size() const while (n_linear_rings--) { - if (no_data(data, 4)) + if (no_data(data, 4) || + (n_points= uint4korr(data)) > max_n_points) return GET_SIZE_ERROR; - data+= 4 + uint4korr(data) * POINT_DATA_SIZE; + data+= 4 + n_points * POINT_DATA_SIZE; } } + if (no_data(data, 0)) + return GET_SIZE_ERROR; return (uint32) (data - m_data); } @@ -2325,7 +2354,7 @@ bool Gis_geometry_collection::get_mbr(MBR *mbr, const char **end) const n_objects= uint4korr(data); data+= 4; if (n_objects == 0) - return 1; + goto exit; while (n_objects--) { @@ -2342,6 +2371,7 @@ bool Gis_geometry_collection::get_mbr(MBR *mbr, const char **end) const if (geom->get_mbr(mbr, &data)) return 1; } +exit: *end= data; return 0; } @@ -2359,10 +2389,11 @@ int Gis_geometry_collection::area(double *ar, const char **end) const return 1; n_objects= uint4korr(data); data+= 4; - if (n_objects == 0) - return 1; result= 0.0; + if (n_objects == 0) + goto exit; + while (n_objects--) { uint32 wkb_type; @@ -2379,6 +2410,7 @@ int Gis_geometry_collection::area(double *ar, const char **end) const return 1; result+= *ar; } +exit: *end= data; *ar= result; return 0; @@ -2397,10 +2429,11 @@ int Gis_geometry_collection::geom_length(double *len, const char **end) const return 1; n_objects= uint4korr(data); data+= 4; + result= 0.0; + if (n_objects == 0) - return 1; + goto exit; - result= 0.0; while (n_objects--) { uint32 wkb_type; @@ -2417,6 +2450,8 @@ int Gis_geometry_collection::geom_length(double *len, const char **end) const return 1; result+= *len; } + +exit: *end= data; *len= result; return 0; diff --git a/sql/spatial.h b/sql/spatial.h index f55d1ccba8e..9aaedfe8a20 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -200,6 +200,9 @@ struct MBR return (d == intersection.dimension()); } + + int valid() const + { return xmin <= xmax && ymin <= ymax; } }; @@ -212,7 +215,7 @@ class Geometry public: // Maximum number of points in feature that can fit into String static const uint32 max_n_points= - (uint32) (UINT_MAX32 - WKB_HEADER_SIZE - 4 /* n_points */) / + (uint32) (INT_MAX32 - WKB_HEADER_SIZE - 4 /* n_points */) / POINT_DATA_SIZE; Geometry() {} /* Remove gcc warning */ diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index b843a86068d..8f77d2758dd 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -52,6 +52,8 @@ #include "sql_db.h" #include "sql_array.h" +#include "sql_plugin_compat.h" + bool mysql_user_table_is_in_short_password_format= false; static const @@ -68,7 +70,7 @@ TABLE_FIELD_TYPE mysql_db_table_fields[MYSQL_DB_FIELD_COUNT] = { }, { { C_STRING_WITH_LEN("User") }, - { C_STRING_WITH_LEN("char(16)") }, + { C_STRING_WITH_LEN("char(") }, {NULL, 0} }, { @@ -826,6 +828,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) table->use_all_columns(); (void) my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100); + username_char_length= min(table->field[1]->char_length(), USERNAME_CHAR_LENGTH); password_length= table->field[2]->field_length / table->field[2]->charset()->mbmaxlen; if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH_323) @@ -1433,12 +1436,12 @@ bool acl_getroot(Security_context *sctx, char *user, char *host, sctx->master_access= acl_user->access; if (acl_user->user) - strmake(sctx->priv_user, user, USERNAME_LENGTH); + strmake_buf(sctx->priv_user, user); else *sctx->priv_user= 0; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); + strmake_buf(sctx->priv_host, acl_user->host.hostname); else *sctx->priv_host= 0; } @@ -8334,6 +8337,12 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) cs->coll->hash_sort(cs, (uchar*) sctx->user, strlen(sctx->user), &nr1, &nr2); mysql_mutex_lock(&acl_cache->lock); + if (!acl_users.elements) + { + mysql_mutex_unlock(&acl_cache->lock); + login_failed_error(mpvio->thd); + DBUG_RETURN(1); + } uint i= nr1 % acl_users.elements; ACL_USER *acl_user_tmp= dynamic_element(&acl_users, i, ACL_USER*); mpvio->acl_user= acl_user_tmp->copy(mpvio->thd->mem_root); @@ -8359,10 +8368,9 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) mpvio->auth_info.user_name= sctx->user; mpvio->auth_info.user_name_length= strlen(sctx->user); mpvio->auth_info.auth_string= mpvio->acl_user->auth_string.str; - mpvio->auth_info.auth_string_length= - (unsigned long) mpvio->acl_user->auth_string.length; - strmake(mpvio->auth_info.authenticated_as, mpvio->acl_user->user ? - mpvio->acl_user->user : "", USERNAME_LENGTH); + mpvio->auth_info.auth_string_length= (unsigned long) mpvio->acl_user->auth_string.length; + strmake_buf(mpvio->auth_info.authenticated_as, mpvio->acl_user->user ? + mpvio->acl_user->user : ""); DBUG_PRINT("info", ("exit: user=%s, auth_string=%s, authenticated as=%s" "plugin=%s", @@ -8446,7 +8454,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) /* Clear variables that are allocated */ thd->user_connect= 0; - strmake(sctx->priv_user, sctx->user, USERNAME_LENGTH); + strmake_buf(sctx->priv_user, sctx->user); if (thd->make_lex_string(&mpvio->db, db_buff, db_len, 0) == 0) DBUG_RETURN(1); /* The error is set by make_lex_string(). */ @@ -8661,14 +8669,15 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio, /* Clip username to allowed length in characters (not bytes). This is - mostly for backward compatibility. + mostly for backward compatibility (to truncate long usernames, as + old 5.1 did) */ { CHARSET_INFO *cs= system_charset_info; int err; user_len= (uint) cs->cset->well_formed_len(cs, user, user + user_len, - USERNAME_CHAR_LENGTH, &err); + username_char_length, &err); user[user_len]= '\0'; } @@ -9063,7 +9072,20 @@ static int do_auth_once(THD *thd, const LEX_STRING *auth_plugin_name, if (plugin) { st_mysql_auth *auth= (st_mysql_auth *) plugin_decl(plugin)->info; - res= auth->authenticate_user(mpvio, &mpvio->auth_info); + switch (auth->interface_version) { + case 0x0200: + res= auth->authenticate_user(mpvio, &mpvio->auth_info); + break; + case 0x0100: + { + MYSQL_SERVER_AUTH_INFO_0x0100 compat; + compat.downgrade(&mpvio->auth_info); + res= auth->authenticate_user(mpvio, (MYSQL_SERVER_AUTH_INFO *)&compat); + compat.upgrade(&mpvio->auth_info); + } + break; + default: DBUG_ASSERT(0); + } if (unlock_plugin) plugin_unlock(thd, plugin); @@ -9114,8 +9136,6 @@ bool acl_authenticate(THD *thd, uint connect_errors, : COM_CONNECT; DBUG_ENTER("acl_authenticate"); - compile_time_assert(MYSQL_USERNAME_LENGTH == USERNAME_LENGTH); - bzero(&mpvio, sizeof(mpvio)); mpvio.read_packet= server_mpvio_read_packet; mpvio.write_packet= server_mpvio_write_packet; @@ -9252,12 +9272,12 @@ bool acl_authenticate(THD *thd, uint connect_errors, sctx->master_access= acl_user->access; if (acl_user->user) - strmake(sctx->priv_user, acl_user->user, USERNAME_LENGTH - 1); + strmake_buf(sctx->priv_user, acl_user->user); else *sctx->priv_user= 0; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); + strmake_buf(sctx->priv_host, acl_user->host.hostname); else *sctx->priv_host= 0; diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index c68d4dc16a4..ae5b21fc959 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -332,7 +332,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, item->maybe_null = 1; field_list.push_back(item = new Item_empty_string("Msg_type", 10)); item->maybe_null = 1; - field_list.push_back(item = new Item_empty_string("Msg_text", 255)); + field_list.push_back(item = new Item_empty_string("Msg_text", + SQL_ADMIN_MSG_TEXT_SIZE)); item->maybe_null = 1; if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) diff --git a/sql/sql_admin.h b/sql/sql_admin.h index f7ec76efd5e..5398e3019f1 100644 --- a/sql/sql_admin.h +++ b/sql/sql_admin.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,8 @@ #ifndef SQL_TABLE_MAINTENANCE_H #define SQL_TABLE_MAINTENANCE_H +/* Must be able to hold ALTER TABLE t PARTITION BY ... KEY ALGORITHM = 1 ... */ +#define SQL_ADMIN_MSG_TEXT_SIZE 128 * 1024 bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list, LEX_STRING *key_cache_name); diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 523f07592bc..8e17f49df28 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -31,8 +31,7 @@ unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; static mysql_mutex_t LOCK_audit_mask; -static void event_class_dispatch(THD *thd, unsigned int event_class, - const void *event); +static void event_class_dispatch(THD *, unsigned int, const void *); static inline @@ -111,9 +110,36 @@ static void connection_class_handler(THD *thd, uint event_subclass, va_list ap) } +static void table_class_handler(THD *thd, uint event_subclass, va_list ap) +{ + mysql_event_table event; + event.event_subclass= event_subclass; + event.read_only= va_arg(ap, int); + event.thread_id= va_arg(ap, unsigned long); + event.user= va_arg(ap, const char *); + event.priv_user= va_arg(ap, const char *); + event.priv_host= va_arg(ap, const char *); + event.external_user= va_arg(ap, const char *); + event.proxy_user= va_arg(ap, const char *); + event.host= va_arg(ap, const char *); + event.ip= va_arg(ap, const char *); + event.database= va_arg(ap, const char *); + event.database_length= va_arg(ap, unsigned int); + event.table= va_arg(ap, const char *); + event.table_length= va_arg(ap, unsigned int); + event.new_database= va_arg(ap, const char *); + event.new_database_length= va_arg(ap, unsigned int); + event.new_table= va_arg(ap, const char *); + event.new_table_length= va_arg(ap, unsigned int); + event_class_dispatch(thd, MYSQL_AUDIT_TABLE_CLASS, &event); +} + + static audit_handler_t audit_handlers[] = { - general_class_handler, connection_class_handler + general_class_handler, connection_class_handler, + 0,0,0,0,0,0,0,0,0,0,0,0,0, /* placeholders */ + table_class_handler }; static const uint audit_handlers_count= diff --git a/sql/sql_audit.h b/sql/sql_audit.h index 46afe4b7596..75b338a16c8 100644 --- a/sql/sql_audit.h +++ b/sql/sql_audit.h @@ -43,17 +43,23 @@ static inline bool mysql_audit_general_enabled() return mysql_global_audit_mask[0] & MYSQL_AUDIT_GENERAL_CLASSMASK; } +static inline bool mysql_audit_table_enabled() +{ + return mysql_global_audit_mask[0] & MYSQL_AUDIT_TABLE_CLASSMASK; +} + #else static inline void mysql_audit_notify(THD *thd, uint event_class, uint event_subtype, ...) { } #define mysql_audit_general_enabled() 0 +#define mysql_audit_table_enabled() 0 #endif extern void mysql_audit_release(THD *thd); #define MAX_USER_HOST_SIZE 512 static inline uint make_user_name(THD *thd, char *buf) { - Security_context *sctx= thd->security_ctx; + const Security_context *sctx= thd->security_ctx; return strxnmov(buf, MAX_USER_HOST_SIZE, sctx->priv_user[0] ? sctx->priv_user : "", "[", sctx->user ? sctx->user : "", "] @ ", @@ -174,4 +180,87 @@ void mysql_audit_general(THD *thd, uint event_subtype, (thd)->security_ctx->ip ? strlen((thd)->security_ctx->ip) : 0,\ (thd)->db, (thd)->db ? strlen((thd)->db) : 0) +static inline +void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) +{ + if (lock != F_UNLCK && mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_LOCK, + (int)(lock == F_RDLCK), (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, share->db.str, (uint)share->db.length, + share->table_name.str, (uint)share->table_name.length, + 0,0,0,0); + } +} + +static inline +void mysql_audit_create_table(TABLE *table) +{ + if (mysql_audit_table_enabled()) + { + THD *thd= table->in_use; + const TABLE_SHARE *share= table->s; + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_CREATE, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, share->db.str, (uint)share->db.length, + share->table_name.str, (uint)share->table_name.length, + 0,0,0,0); + } +} + +static inline +void mysql_audit_drop_table(THD *thd, TABLE_LIST *table) +{ + if (mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_DROP, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, table->db, (uint)table->db_length, + table->table_name, (uint)table->table_name_length, + 0,0,0,0); + } +} + +static inline +void mysql_audit_rename_table(THD *thd, const char *old_db, const char *old_tb, + const char *new_db, const char *new_tb) +{ + if (mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_RENAME, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, + old_db, (uint)strlen(old_db), old_tb, (uint)strlen(old_tb), + new_db, (uint)strlen(new_db), new_tb, (uint)strlen(new_tb)); + } +} + +static inline +void mysql_audit_alter_table(THD *thd, TABLE_LIST *table) +{ + if (mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_ALTER, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, table->db, (uint)table->db_length, + table->table_name, (uint)table->table_name_length, + 0,0,0,0); + } +} + #endif /* SQL_AUDIT_INCLUDED */ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6483ab283ea..9d2120439f1 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6948,7 +6948,7 @@ find_field_in_tables(THD *thd, Item_ident *item, We can't do this in Item_field as this would change the 'name' of the item which may be used in the select list */ - strmake(name_buff, db, sizeof(name_buff)-1); + strmake_buf(name_buff, db); my_casedn_str(files_charset_info, name_buff); db= name_buff; } @@ -8521,7 +8521,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, We can't do this in Item_field as this would change the 'name' of the item which may be used in the select list */ - strmake(name_buff, db_name, sizeof(name_buff)-1); + strmake_buf(name_buff, db_name); my_casedn_str(files_charset_info, name_buff); db_name= name_buff; } @@ -9523,7 +9523,6 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order) List_iterator<Item_func_match> li(*(select_lex->ftfunc_list)); Item_func_match *ifm; DBUG_PRINT("info",("Performing FULLTEXT search")); - thd_proc_info(thd, "FULLTEXT initialization"); while ((ifm=li++)) ifm->init_search(no_order); diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc index a4664da2bf6..3bb5deab406 100644 --- a/sql/sql_binlog.cc +++ b/sql/sql_binlog.cc @@ -107,7 +107,7 @@ void mysql_client_binlog_statement(THD* thd) rli->relay_log.description_event_for_exec && buf)) { - my_error(ER_OUTOFMEMORY, MYF(0), 1); /* needed 1 bytes */ + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), 1); /* needed 1 bytes */ goto end; } diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 016973ab51a..1e5c99822ff 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -466,6 +466,8 @@ static void make_base_query(String *new_query, /* The following is guaranteed by the query_cache interface */ DBUG_ASSERT(query[query_length] == 0); DBUG_ASSERT(!is_white_space(query[0])); + /* We do not support UCS2, UTF16, UTF32 as a client character set */ + DBUG_ASSERT(current_thd->variables.character_set_client->mbminlen == 1); new_query->length(0); // Don't copy anything from old buffer if (new_query->realloc(query_length + additional_length)) @@ -828,18 +830,18 @@ void Query_cache_block::destroy() DBUG_VOID_RETURN; } -inline uint Query_cache_block::headers_len() +uint Query_cache_block::headers_len() { return (ALIGN_SIZE(sizeof(Query_cache_block_table)*n_tables) + ALIGN_SIZE(sizeof(Query_cache_block))); } -inline uchar* Query_cache_block::data(void) +uchar* Query_cache_block::data(void) { return (uchar*)( ((uchar*)this) + headers_len() ); } -inline Query_cache_query * Query_cache_block::query() +Query_cache_query * Query_cache_block::query() { #ifndef DBUG_OFF if (type != QUERY) @@ -848,7 +850,7 @@ inline Query_cache_query * Query_cache_block::query() return (Query_cache_query *) data(); } -inline Query_cache_table * Query_cache_block::table() +Query_cache_table * Query_cache_block::table() { #ifndef DBUG_OFF if (type != TABLE) @@ -857,7 +859,7 @@ inline Query_cache_table * Query_cache_block::table() return (Query_cache_table *) data(); } -inline Query_cache_result * Query_cache_block::result() +Query_cache_result * Query_cache_block::result() { #ifndef DBUG_OFF if (type != RESULT && type != RES_CONT && type != RES_BEG && @@ -867,7 +869,7 @@ inline Query_cache_result * Query_cache_block::result() return (Query_cache_result *) data(); } -inline Query_cache_block_table * Query_cache_block::table(TABLE_COUNTER_TYPE n) +Query_cache_block_table * Query_cache_block::table(TABLE_COUNTER_TYPE n) { return ((Query_cache_block_table *) (((uchar*)this)+ALIGN_SIZE(sizeof(Query_cache_block)) + @@ -2430,7 +2432,28 @@ void Query_cache::init() m_cache_status= Query_cache::OK; m_requests_in_progress= 0; initialized = 1; - query_state_map= default_charset_info->state_map; + /* + Using state_map from latin1 should be fine in all cases: + 1. We do not support UCS2, UTF16, UTF32 as a client character set. + 2. The other character sets are compatible on the lower ASCII-range + 0x00-0x20, and have the following characters marked as spaces: + + 0x09 TAB + 0x0A LINE FEED + 0x0B VERTICAL TAB + 0x0C FORM FEED + 0x0D CARRIAGE RETUR + 0x20 SPACE + + Additionally, only some of the ASCII-compatible character sets + (including latin1) can have 0xA0 mapped to "NON-BREAK SPACE" + and thus marked as space. + That should not be a problem for those charsets that map 0xA0 + to something else: the parser will just return syntax error + if this character appears straight in the query + (i.e. not inside a string literal or comment). + */ + query_state_map= my_charset_latin1.state_map; /* If we explicitly turn off query cache from the command line query cache will be disabled for the reminder of the server life diff --git a/sql/sql_cache.h b/sql/sql_cache.h index 7444d444cf9..f35ac889b23 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -141,12 +141,12 @@ struct Query_cache_block inline bool is_free(void) { return type == FREE; } void init(ulong length); void destroy(); - inline uint headers_len(); - inline uchar* data(void); - inline Query_cache_query *query(); - inline Query_cache_table *table(); - inline Query_cache_result *result(); - inline Query_cache_block_table *table(TABLE_COUNTER_TYPE n); + uint headers_len(); + uchar* data(void); + Query_cache_query *query(); + Query_cache_table *table(); + Query_cache_result *result(); + Query_cache_block_table *table(TABLE_COUNTER_TYPE n); }; struct Query_cache_query diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 898787fa953..65b8b77bae8 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1369,10 +1369,16 @@ MYSQL_ERROR* THD::raise_condition(uint sql_errno, query_cache_abort(&query_cache_tls); - /* When simulating OOM, skip writing to error log to avoid mtr errors */ - DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_RETURN(NULL);); - - cond= warning_info->push_warning(this, sql_errno, sqlstate, level, msg); + /* + Avoid pushing a condition for fatal out of memory errors as this will + require memory allocation and therefore might fail. Non fatal out of + memory errors can occur if raised by SIGNAL/RESIGNAL statement. + */ + if (!(is_fatal_error && (sql_errno == EE_OUTOFMEMORY || + sql_errno == ER_OUTOFMEMORY))) + { + cond= warning_info->push_warning(this, sql_errno, sqlstate, level, msg); + } DBUG_RETURN(cond); } @@ -2318,7 +2324,7 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length) key_length + 1); if (!new_table) { - my_error(EE_OUTOFMEMORY, MYF(ME_BELL), + my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_FATALERROR), ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); killed= KILL_CONNECTION; return 0; @@ -2777,7 +2783,7 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u) bool string_results= FALSE, non_string_results= FALSE; unit= u; if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) - strmake(path,exchange->file_name,FN_REFLEN-1); + strmake_buf(path,exchange->file_name); write_cs= exchange->cs ? exchange->cs : &my_charset_bin; @@ -2915,7 +2921,7 @@ int select_export::send_data(List<Item> &items) set_if_smaller(estimated_bytes, UINT_MAX32); if (cvt_str.realloc((uint32) estimated_bytes)) { - my_error(ER_OUTOFMEMORY, MYF(0), (uint32) estimated_bytes); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), (uint32) estimated_bytes); goto err; } diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index ddac46eb943..c350334b46c 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -438,7 +438,7 @@ void init_user_stats(USER_STATS *user_stats, memcpy(user_stats->user, user, user_length); user_stats->user[user_length]= 0; user_stats->user_name_length= user_length; - strmake(user_stats->priv_user, priv_user, sizeof(user_stats->priv_user)-1); + strmake_buf(user_stats->priv_user, priv_user); user_stats->total_connections= total_connections; user_stats->concurrent_connections= concurrent_connections; diff --git a/sql/sql_const.h b/sql/sql_const.h index de2704a8553..9d227601a20 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -92,7 +92,7 @@ #define FIELD_NR_MASK 16383 /* To get fieldnumber */ #define FERR -1 /* Error from my_functions */ #define CREATE_MODE 0 /* Default mode on new files */ -#define NAMES_SEP_CHAR '\377' /* Char to sep. names */ +#define NAMES_SEP_CHAR 255 /* Char to sep. names */ #define READ_RECORD_BUFFER (uint) (IO_SIZE*8) /* Pointer_buffer_size */ #define DISK_BUFFER_SIZE (uint) (IO_SIZE*16) /* Size of diskbuffer */ diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index a3d68f54c9c..48bae0af29a 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -681,7 +681,7 @@ multi_delete::initialize_tables(JOIN *join) tab; tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) { - if (tab->table->map & tables_to_delete_from) + if (!tab->bush_children && tab->table->map & tables_to_delete_from) { /* We are going to delete from this table */ TABLE *tbl=walk->table=tab->table; diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 06da6250e71..a4f5b210285 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -185,6 +185,7 @@ MYSQL_ERROR::MYSQL_ERROR() m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin), m_message_text(), m_sql_errno(0), + m_handled(0), m_level(MYSQL_ERROR::WARN_LEVEL_ERROR), m_mem_root(NULL) { @@ -212,6 +213,7 @@ void MYSQL_ERROR::clear() m_cursor_name.length(0); m_message_text.length(0); m_sql_errno= 0; + m_handled= 0; m_level= MYSQL_ERROR::WARN_LEVEL_ERROR; } @@ -229,6 +231,7 @@ MYSQL_ERROR::MYSQL_ERROR(MEM_ROOT *mem_root) m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin), m_message_text(), m_sql_errno(0), + m_handled(0), m_level(MYSQL_ERROR::WARN_LEVEL_ERROR), m_mem_root(mem_root) { @@ -267,6 +270,7 @@ MYSQL_ERROR::copy_opt_attributes(const MYSQL_ERROR *cond) copy_string(m_mem_root, & m_table_name, & cond->m_table_name); copy_string(m_mem_root, & m_column_name, & cond->m_column_name); copy_string(m_mem_root, & m_cursor_name, & cond->m_cursor_name); + m_handled= cond->m_handled; } void @@ -367,7 +371,7 @@ Diagnostics_area::set_ok_status(THD *thd, ulonglong affected_rows_arg, m_affected_rows= affected_rows_arg; m_last_insert_id= last_insert_id_arg; if (message_arg) - strmake(m_message, message_arg, sizeof(m_message) - 1); + strmake_buf(m_message, message_arg); else m_message[0]= '\0'; m_status= DA_OK; @@ -435,7 +439,7 @@ Diagnostics_area::set_error_status(THD *thd, uint sql_errno_arg, m_sql_errno= sql_errno_arg; memcpy(m_sqlstate, sqlstate, SQLSTATE_LENGTH); m_sqlstate[SQLSTATE_LENGTH]= '\0'; - strmake(m_message, message_arg, sizeof(m_message)-1); + strmake_buf(m_message, message_arg); m_status= DA_ERROR; DBUG_VOID_RETURN; diff --git a/sql/sql_error.h b/sql/sql_error.h index 00ade934226..0483e7c65d1 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -191,6 +191,17 @@ public: MYSQL_ERROR::enum_warning_level get_level() const { return m_level; } + /** check if condition was handled by a condition handler */ + bool handled() const + { + return m_handled; + } + /** mark that condition was handled */ + void mark_handled() + { + m_handled= 1; + } + private: /* The interface of MYSQL_ERROR is mostly private, by design, @@ -306,6 +317,9 @@ private: /** MySQL extension, MYSQL_ERRNO condition item. */ uint m_sql_errno; + /** Marker if error/warning was handled by a continue handler */ + bool m_handled; + /** SQL RETURNED_SQLSTATE condition item. This member is always NUL terminated. diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index d779f679021..df979c62541 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. - Copyright (c) 2011 Monty Program Ab +/* Copyright (c) 2001, 2013, Oracle and/or its affiliates. + Copyright (c) 2011, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1008,11 +1008,13 @@ static SQL_HANDLER *mysql_ha_find_match(THD *thd, TABLE_LIST *tables) for (tables= first; tables; tables= tables->next_local) { + if (tables->is_anonymous_derived_table()) + continue; if ((! *tables->db || ! my_strcasecmp(&my_charset_latin1, hash_tables->db.str, - tables->db)) && + tables->get_db_name())) && ! my_strcasecmp(&my_charset_latin1, hash_tables->table_name.str, - tables->table_name)) + tables->get_table_name())) { /* Link into hash_tables list */ hash_tables->next= head; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 4f080235069..8f08c129519 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2015,8 +2015,7 @@ public: DBUG_ENTER("Delayed_insert constructor"); thd.security_ctx->user=(char*) delayed_user; thd.security_ctx->host=(char*) my_localhost; - strmake(thd.security_ctx->priv_user, thd.security_ctx->user, - USERNAME_LENGTH); + strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user); thd.current_tablenr=0; thd.command=COM_DELAYED_INSERT; thd.lex->current_select= 0; // for my_message_sql diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 659cf36ff43..6a1ab788e20 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1411,7 +1411,7 @@ int lex_one_token(void *arg, void *yythd) yylval->lex_str=get_token(lip, 2, // skip x' length-3); // don't count x' and last ' - return (HEX_NUM); + return HEX_STRING; case MY_LEX_BIN_NUMBER: // Found b'bin-string' lip->yySkip(); // Accept opening ' @@ -1928,6 +1928,7 @@ void st_select_lex::init_select() merged_into= 0; m_non_agg_field_used= false; m_agg_func_used= false; + name_visibility_map= 0; } /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 2f3214646de..2af1ddbf39c 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -887,6 +887,9 @@ public: */ List<String> *prev_join_using; + /* namp of nesting SELECT visibility (for aggregate functions check) */ + nesting_map name_visibility_map; + void init_query(); void init_select(); st_select_lex_unit* master_unit(); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 52ca997bef5..0765138c1c9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1715,7 +1715,8 @@ void log_slow_statement(THD *thd) /* Follow the slow log filter configuration. */ if (!thd->enable_slow_log || - !(thd->variables.log_slow_filter & thd->query_plan_flags)) + (thd->variables.log_slow_filter + && !(thd->variables.log_slow_filter & thd->query_plan_flags))) DBUG_VOID_RETURN; if (((thd->server_status & SERVER_QUERY_WAS_SLOW) || @@ -1848,7 +1849,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, break; case SCH_USER_STATS: case SCH_CLIENT_STATS: - if (check_global_access(thd, SUPER_ACL | PROCESS_ACL)) + if (check_global_access(thd, SUPER_ACL | PROCESS_ACL, true)) DBUG_RETURN(1); case SCH_TABLE_STATS: case SCH_INDEX_STATS: @@ -2023,7 +2024,7 @@ bool sp_process_definer(THD *thd) if ((strcmp(lex->definer->user.str, thd->security_ctx->priv_user) || my_strcasecmp(system_charset_info, lex->definer->host.str, thd->security_ctx->priv_host)) && - check_global_access(thd, SUPER_ACL)) + check_global_access(thd, SUPER_ACL, true)) { my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER"); DBUG_RETURN(TRUE); @@ -5692,14 +5693,17 @@ bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) 1 Access denied. In this case an error is sent to the client */ -bool check_global_access(THD *thd, ulong want_access) +bool check_global_access(THD *thd, ulong want_access, bool no_errors) { #ifndef NO_EMBEDDED_ACCESS_CHECKS char command[128]; if ((thd->security_ctx->master_access & want_access)) return 0; - get_privilege_desc(command, sizeof(command), want_access); - my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command); + if (!no_errors) + { + get_privilege_desc(command, sizeof(command), want_access); + my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command); + } status_var_increment(thd->status_var.access_denied_errors); return 1; #else diff --git a/sql/sql_parse.h b/sql/sql_parse.h index 1303eba84b7..6f7869ed5e4 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -196,7 +196,7 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, /* These were under the INNODB_COMPATIBILITY_HOOKS */ -bool check_global_access(THD *thd, ulong want_access); +bool check_global_access(THD *thd, ulong want_access, bool no_errors= false); inline bool is_supported_parser_charset(CHARSET_INFO *cs) { diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 2bec12e4f66..72061f90e67 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. - Copyright (c) 2009-2011, Monty Program Ab +/* Copyright (c) 2005, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2011, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -87,7 +87,9 @@ const LEX_STRING partition_keywords[]= { C_STRING_WITH_LEN("KEY") }, { C_STRING_WITH_LEN("MAXVALUE") }, { C_STRING_WITH_LEN("LINEAR ") }, - { C_STRING_WITH_LEN(" COLUMNS") } + { C_STRING_WITH_LEN(" COLUMNS") }, + { C_STRING_WITH_LEN("ALGORITHM") } + }; static const char *part_str= "PARTITION"; static const char *sub_str= "SUB"; @@ -368,7 +370,7 @@ int get_parts_for_update(const uchar *old_data, uchar *new_data, longlong old_func_value; DBUG_ENTER("get_parts_for_update"); - DBUG_ASSERT(new_data == rec0); + DBUG_ASSERT(new_data == rec0); // table->record[0] set_field_ptr(part_field_array, old_data, rec0); error= part_info->get_partition_id(part_info, old_part_id, &old_func_value); @@ -526,12 +528,12 @@ static bool set_up_field_array(TABLE *table, } if (num_fields > MAX_REF_PARTS) { - char *ptr; + char *err_str; if (is_sub_part) - ptr= (char*)"subpartition function"; + err_str= (char*)"subpartition function"; else - ptr= (char*)"partition function"; - my_error(ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0), ptr); + err_str= (char*)"partition function"; + my_error(ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0), err_str); DBUG_RETURN(TRUE); } if (num_fields == 0) @@ -2339,6 +2341,58 @@ end: return err; } + +/** + Add 'KEY' word, with optional 'ALGORTIHM = N'. + + @param fptr File to write to. + @param part_info partition_info holding the used key_algorithm + @param current_comment_start NULL, or comment string encapsulating the + PARTITION BY clause. + + @return Operation status. + @retval 0 Success + @retval != 0 Failure +*/ + +static int add_key_with_algorithm(File fptr, partition_info *part_info, + const char *current_comment_start) +{ + int err= 0; + err+= add_part_key_word(fptr, partition_keywords[PKW_KEY].str); + + /* + current_comment_start is given when called from SHOW CREATE TABLE, + Then only add ALGORITHM = 1, not the default 2 or non-set 0! + For .frm current_comment_start is NULL, then add ALGORITHM if != 0. + */ + if (part_info->key_algorithm == partition_info::KEY_ALGORITHM_51 || // SHOW + (!current_comment_start && // .frm + (part_info->key_algorithm != partition_info::KEY_ALGORITHM_NONE))) + { + /* If we already are within a comment, end that comment first. */ + if (current_comment_start) + err+= add_string(fptr, "*/ "); + err+= add_string(fptr, "/*!50531 "); + err+= add_part_key_word(fptr, partition_keywords[PKW_ALGORITHM].str); + err+= add_equal(fptr); + err+= add_space(fptr); + err+= add_int(fptr, part_info->key_algorithm); + err+= add_space(fptr); + err+= add_string(fptr, "*/ "); + if (current_comment_start) + { + /* Skip new line. */ + if (current_comment_start[0] == '\n') + current_comment_start++; + err+= add_string(fptr, current_comment_start); + err+= add_space(fptr); + } + } + return err; +} + + /* Generate the partition syntax from the partition data structure. Useful for support of generating defaults, SHOW CREATE TABLES @@ -2383,7 +2437,8 @@ char *generate_partition_syntax(partition_info *part_info, bool use_sql_alloc, bool show_partition_options, HA_CREATE_INFO *create_info, - Alter_info *alter_info) + Alter_info *alter_info, + const char *current_comment_start) { uint i,j, tot_num_parts, num_subparts; partition_element *part_elem; @@ -2417,7 +2472,8 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_string(fptr, partition_keywords[PKW_LINEAR].str); if (part_info->list_of_part_fields) { - err+= add_part_key_word(fptr, partition_keywords[PKW_KEY].str); + err+= add_key_with_algorithm(fptr, part_info, + current_comment_start); err+= add_part_field_list(fptr, part_info->part_field_list); } else @@ -2457,8 +2513,9 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_string(fptr, partition_keywords[PKW_LINEAR].str); if (part_info->list_of_subpart_fields) { - add_part_key_word(fptr, partition_keywords[PKW_KEY].str); - add_part_field_list(fptr, part_info->subpart_field_list); + err+= add_key_with_algorithm(fptr, part_info, + current_comment_start); + err+= add_part_field_list(fptr, part_info->subpart_field_list); } else err+= add_part_key_word(fptr, partition_keywords[PKW_HASH].str); @@ -2667,10 +2724,82 @@ static uint32 calculate_key_value(Field **field_array) { ulong nr1= 1; ulong nr2= 4; + bool use_51_hash; + use_51_hash= test((*field_array)->table->part_info->key_algorithm == + partition_info::KEY_ALGORITHM_51); do { Field *field= *field_array; + if (use_51_hash) + { + switch (field->real_type()) { + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_NEWDATE: + { + if (field->is_null()) + { + nr1^= (nr1 << 1) | 1; + continue; + } + /* Force this to my_hash_sort_bin, which was used in 5.1! */ + uint len= field->pack_length(); + my_charset_bin.coll->hash_sort(&my_charset_bin, field->ptr, len, + &nr1, &nr2); + /* Done with this field, continue with next one. */ + continue; + } + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_BIT: + /* Not affected, same in 5.1 and 5.5 */ + break; + /* + ENUM/SET uses my_hash_sort_simple in 5.1 (i.e. my_charset_latin1) + and my_hash_sort_bin in 5.5! + */ + case MYSQL_TYPE_ENUM: + case MYSQL_TYPE_SET: + { + if (field->is_null()) + { + nr1^= (nr1 << 1) | 1; + continue; + } + /* Force this to my_hash_sort_bin, which was used in 5.1! */ + uint len= field->pack_length(); + my_charset_latin1.coll->hash_sort(&my_charset_latin1, field->ptr, + len, &nr1, &nr2); + continue; + } + /* These types should not be allowed for partitioning! */ + case MYSQL_TYPE_NULL: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_GEOMETRY: + /* fall through. */ + default: + DBUG_ASSERT(0); // New type? + /* Fall through for default hashing (5.5). */ + } + /* fall through, use collation based hashing. */ + } field->hash(&nr1, &nr2); } while (*(++field_array)); return (uint32) nr1; @@ -5413,14 +5542,25 @@ the generated partition syntax in a correct manner. Need to cater for engine types that can handle partition without using the partition handler. */ - if (thd->work_part_info != table->part_info) + if (part_info != table->part_info) { - DBUG_PRINT("info", ("partition changed")); - *partition_changed= TRUE; - if (thd->work_part_info->fix_parser_data(thd)) + if (part_info->fix_parser_data(thd)) { goto err; } + /* + Compare the old and new part_info. If only key_algorithm + change is done, don't consider it as changed partitioning (to avoid + rebuild). This is to handle KEY (numeric_cols) partitioned tables + created in 5.1. For more info, see bug#14521864. + */ + if (alter_info->flags != ALTER_PARTITION || + !table->part_info || + !table->part_info->has_same_partitioning(part_info)) + { + DBUG_PRINT("info", ("partition changed")); + *partition_changed= true; + } } /* Set up partition default_engine_type either from the create_info @@ -6975,7 +7115,8 @@ void set_key_field_ptr(KEY *key_info, const uchar *new_buf, void mem_alloc_error(size_t size) { - my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(size)); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), + static_cast<int>(size)); } #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -7062,12 +7203,12 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) definition) IMPLEMENTATION - There are two available interval analyzer functions: - (1) get_part_iter_for_interval_via_mapping + There are three available interval analyzer functions: + (1) get_part_iter_for_interval_via_mapping (2) get_part_iter_for_interval_cols_via_map (3) get_part_iter_for_interval_via_walking - They both have limited applicability: + They all have limited applicability: (1) is applicable for "PARTITION BY <RANGE|LIST>(func(t.field))", where func is a monotonic function. @@ -7440,6 +7581,9 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, get_endpoint_func UNINIT_VAR(get_endpoint); bool can_match_multiple_values; /* is not '=' */ uint field_len= field->pack_length_in_rec(); + MYSQL_TIME start_date; + bool check_zero_dates= false; + bool zero_in_start_date= true; DBUG_ENTER("get_part_iter_for_interval_via_mapping"); DBUG_ASSERT(!is_subpart); (void) store_length_array; @@ -7496,6 +7640,7 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, { /* col is NOT NULL, but F(col) can return NULL, add NULL partition */ part_iter->ret_null_part= part_iter->ret_null_part_orig= TRUE; + check_zero_dates= true; } } @@ -7539,6 +7684,19 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, DBUG_RETURN(1); } part_iter->part_nums.cur= part_iter->part_nums.start; + if (check_zero_dates && !part_info->part_expr->null_value) + { + if (!(flags & NO_MAX_RANGE) && + (field->type() == MYSQL_TYPE_DATE || + field->type() == MYSQL_TYPE_DATETIME)) + { + /* Monotonic, but return NULL for dates with zeros in month/day. */ + zero_in_start_date= field->get_date(&start_date, 0); + DBUG_PRINT("info", ("zero start %u %04d-%02d-%02d", + zero_in_start_date, start_date.year, + start_date.month, start_date.day)); + } + } if (part_iter->part_nums.start == max_endpoint_val) DBUG_RETURN(0); /* No partitions */ } @@ -7552,6 +7710,29 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, store_key_image_to_rec(field, max_value, field_len); bool include_endp= !test(flags & NEAR_MAX); part_iter->part_nums.end= get_endpoint(part_info, 0, include_endp); + if (check_zero_dates && + !zero_in_start_date && + !part_info->part_expr->null_value) + { + MYSQL_TIME end_date; + bool zero_in_end_date= field->get_date(&end_date, 0); + /* + This is an optimization for TO_DAYS()/TO_SECONDS() to avoid scanning + the NULL partition for ranges that cannot include a date with 0 as + month/day. + */ + DBUG_PRINT("info", ("zero end %u %04d-%02d-%02d", + zero_in_end_date, + end_date.year, end_date.month, end_date.day)); + DBUG_ASSERT(!memcmp(((Item_func*) part_info->part_expr)->func_name(), + "to_days", 7) || + !memcmp(((Item_func*) part_info->part_expr)->func_name(), + "to_seconds", 10)); + if (!zero_in_end_date && + start_date.month == end_date.month && + start_date.year == end_date.year) + part_iter->ret_null_part= part_iter->ret_null_part_orig= false; + } if (part_iter->part_nums.start >= part_iter->part_nums.end && !part_iter->ret_null_part) DBUG_RETURN(0); /* No partitions */ diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 2fd9b4c3d75..951d58a655b 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -1,8 +1,7 @@ #ifndef SQL_PARTITION_INCLUDED #define SQL_PARTITION_INCLUDED -/* - Copyright (c) 2006, 2010, Oracle and/or its affiliates. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -268,7 +267,8 @@ char *generate_partition_syntax(partition_info *part_info, uint *buf_length, bool use_sql_alloc, bool show_partition_options, HA_CREATE_INFO *create_info, - Alter_info *alter_info); + Alter_info *alter_info, + const char *current_comment_start); bool partition_key_modified(TABLE *table, const MY_BITMAP *fields); #else #define partition_key_modified(X,Y) 0 diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index 4edd47de855..b9bf3dbc217 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -141,7 +141,9 @@ bool Alter_table_truncate_partition_statement::execute(THD *thd) TODO: Add support for TRUNCATE PARTITION for NDB and other engines supporting native partitioning. */ - if (first_table->table->s->db_type() != partition_hton) + + if (!first_table->table || first_table->view || + first_table->table->s->db_type() != partition_hton) { my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0)); DBUG_RETURN(TRUE); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index a66b3b633d2..e635fdd5dbe 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -35,6 +35,8 @@ #include <mysql/plugin_auth.h> #include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT #include <mysql/plugin_auth.h> +#include "sql_plugin_compat.h" + #define REPORT_TO_LOG 1 #define REPORT_TO_USER 2 @@ -135,7 +137,7 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, MYSQL_AUDIT_INTERFACE_VERSION, MYSQL_REPLICATION_INTERFACE_VERSION, - MYSQL_AUTHENTICATION_INTERFACE_VERSION + MIN_AUTHENTICATION_INTERFACE_VERSION }; static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= { diff --git a/sql/sql_plugin_compat.h b/sql/sql_plugin_compat.h new file mode 100644 index 00000000000..5c7bb620575 --- /dev/null +++ b/sql/sql_plugin_compat.h @@ -0,0 +1,65 @@ +/* Copyright (C) 2013 Sergei Golubchik and Monty Program Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/* old plugin api structures, used for backward compatibility */ + +#define upgrade_var(X) latest->X= X +#define upgrade_str(X) strmake_buf(latest->X, X) +#define downgrade_var(X) X= latest->X +#define downgrade_str(X) strmake_buf(X, latest->X) + +/**************************************************************/ +/* Authentication API, version 0x0100 *************************/ +#define MIN_AUTHENTICATION_INTERFACE_VERSION 0x0100 + +struct MYSQL_SERVER_AUTH_INFO_0x0100 { + char *user_name; + unsigned int user_name_length; + const char *auth_string; + unsigned long auth_string_length; + char authenticated_as[49]; + char external_user[512]; + int password_used; + const char *host_or_ip; + unsigned int host_or_ip_length; + + void upgrade(MYSQL_SERVER_AUTH_INFO *latest) + { + upgrade_var(user_name); + upgrade_var(user_name_length); + upgrade_var(auth_string); + upgrade_var(auth_string_length); + upgrade_str(authenticated_as); + upgrade_str(external_user); + upgrade_var(password_used); + upgrade_var(host_or_ip); + upgrade_var(host_or_ip_length); + } + void downgrade(MYSQL_SERVER_AUTH_INFO *latest) + { + downgrade_var(user_name); + downgrade_var(user_name_length); + downgrade_var(auth_string); + downgrade_var(auth_string_length); + downgrade_str(authenticated_as); + downgrade_str(external_user); + downgrade_var(password_used); + downgrade_var(host_or_ip); + downgrade_var(host_or_ip_length); + } +}; + +/**************************************************************/ + diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 10aa1ccec26..d278ccb870e 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -879,7 +879,7 @@ static bool insert_params_with_log(Prepared_statement *stmt, uchar *null_array, if (param->state == Item_param::NO_VALUE) DBUG_RETURN(1); - if (param->limit_clause_param && param->item_type != Item::INT_ITEM) + if (param->limit_clause_param) { param->set_int(param->val_int(), MY_INT64_NUM_DECIMAL_DIGITS); param->item_type= Item::INT_ITEM; @@ -1503,7 +1503,8 @@ static int mysql_test_select(Prepared_statement *stmt, if (!lex->result && !(lex->result= new (stmt->mem_root) select_send)) { - my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(sizeof(select_send))); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), + static_cast<int>(sizeof(select_send))); goto error; } @@ -1877,7 +1878,7 @@ static bool mysql_test_multidelete(Prepared_statement *stmt, stmt->thd->lex->current_select= &stmt->thd->lex->select_lex; if (add_item_to_list(stmt->thd, new Item_null())) { - my_error(ER_OUTOFMEMORY, MYF(0), 0); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), 0); goto error; } @@ -3878,7 +3879,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) alloc_query(thd, (char*) expanded_query->ptr(), expanded_query->length())) { - my_error(ER_OUTOFMEMORY, 0, expanded_query->length()); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), expanded_query->length()); goto error; } /* diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 1f5f63c87b5..abb78f6f1d3 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. - Copyright (c) 2008, 2012, Monty Program Ab +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2008, 2012, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -631,6 +631,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, uint8 current_checksum_alg= BINLOG_CHECKSUM_ALG_UNDEF; int old_max_allowed_packet= thd->variables.max_allowed_packet; + #ifndef DBUG_OFF int left_events = max_binlog_dump_events; #endif @@ -878,8 +879,11 @@ impossible position"; if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg)) goto err; - while (!(error = Log_event::read_log_event(&log, packet, log_lock, - current_checksum_alg))) + bool is_active_binlog= false; + while (!(error= Log_event::read_log_event(&log, packet, log_lock, + current_checksum_alg, + log_file_name, + &is_active_binlog))) { #ifndef DBUG_OFF if (max_binlog_dump_events && !left_events--) @@ -961,6 +965,13 @@ impossible position"; goto err; } + DBUG_EXECUTE_IF("wait_after_binlog_EOF", + { + const char act[]= "now wait_for signal.rotate_finished"; + DBUG_ASSERT(!debug_sync_set_action(current_thd, + STRING_WITH_LEN(act))); + };); + /* TODO: now that we are logging the offset, check to make sure the recorded offset and the actual match. @@ -971,8 +982,11 @@ impossible position"; if (test_for_non_eof_log_read_errors(error, &errmsg)) goto err; - if (!(flags & BINLOG_DUMP_NON_BLOCK) && - mysql_bin_log.is_active(log_file_name)) + /* + We should only move to the next binlog when the last read event + came from a already deactivated binlog. + */ + if (!(flags & BINLOG_DUMP_NON_BLOCK) && is_active_binlog) { /* Block until there is more data in the log @@ -1026,7 +1040,8 @@ impossible position"; mysql_mutex_unlock(log_lock); read_packet = 1; p_coord->pos= uint4korr(packet->ptr() + ev_offset + LOG_POS_OFFSET); - event_type= (Log_event_type)((*packet)[LOG_EVENT_OFFSET+ev_offset]); + event_type= + (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET+ev_offset]); break; case LOG_READ_EOF: @@ -1272,8 +1287,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) We don't check thd->lex->mi.log_file_name for NULL here since it is checked in sql_yacc.yy */ - strmake(mi->rli.until_log_name, thd->lex->mi.log_file_name, - sizeof(mi->rli.until_log_name)-1); + strmake_buf(mi->rli.until_log_name, thd->lex->mi.log_file_name); } else if (thd->lex->mi.relay_log_pos) { @@ -1281,8 +1295,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) slave_errno=ER_BAD_SLAVE_UNTIL_COND; mi->rli.until_condition= Relay_log_info::UNTIL_RELAY_POS; mi->rli.until_log_pos= thd->lex->mi.relay_log_pos; - strmake(mi->rli.until_log_name, thd->lex->mi.relay_log_name, - sizeof(mi->rli.until_log_name)-1); + strmake_buf(mi->rli.until_log_name, thd->lex->mi.relay_log_name); } else mi->rli.clear_until_condition(); @@ -1564,14 +1577,15 @@ void kill_zombie_dump_threads(uint32 slave_server_id) */ static bool get_string_parameter(char *to, const char *from, size_t length, - const char *name) + const char *name, CHARSET_INFO *cs) { if (from) // Empty paramaters allowed { - size_t from_length; - if ((from_length= strlen(from)) > length) + size_t from_length= strlen(from); + uint from_numchars= cs->cset->numchars(cs, from, from + from_length); + if (from_numchars > length / cs->mbmaxlen) { - my_error(ER_WRONG_STRING_LENGTH, MYF(0), from, name, (int) length); + my_error(ER_WRONG_STRING_LENGTH, MYF(0), from, name, length / cs->mbmaxlen); return 1; } memcpy(to, from, from_length+1); @@ -1646,9 +1660,9 @@ bool change_master(THD* thd, Master_info* mi) /* Before processing the command, save the previous state. */ - strmake(saved_host, mi->host, HOSTNAME_LENGTH); + strmake_buf(saved_host, mi->host); saved_port= mi->port; - strmake(saved_log_name, mi->master_log_name, FN_REFLEN - 1); + strmake_buf(saved_log_name, mi->master_log_name); saved_log_pos= mi->master_log_pos; /* @@ -1663,8 +1677,7 @@ bool change_master(THD* thd, Master_info* mi) } if (lex_mi->log_file_name) - strmake(mi->master_log_name, lex_mi->log_file_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, lex_mi->log_file_name); if (lex_mi->pos) { mi->master_log_pos= lex_mi->pos; @@ -1672,11 +1685,12 @@ bool change_master(THD* thd, Master_info* mi) DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); if (get_string_parameter(mi->host, lex_mi->host, sizeof(mi->host)-1, - "MASTER_HOST") || + "MASTER_HOST", system_charset_info) || get_string_parameter(mi->user, lex_mi->user, sizeof(mi->user)-1, - "MASTER_USER") || + "MASTER_USER", system_charset_info) || get_string_parameter(mi->password, lex_mi->password, - sizeof(mi->password)-1, "MASTER_PASSWORD")) + sizeof(mi->password)-1, "MASTER_PASSWORD", + &my_charset_bin)) { ret= TRUE; goto err; @@ -1728,15 +1742,15 @@ bool change_master(THD* thd, Master_info* mi) (lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE); if (lex_mi->ssl_ca) - strmake(mi->ssl_ca, lex_mi->ssl_ca, sizeof(mi->ssl_ca)-1); + strmake_buf(mi->ssl_ca, lex_mi->ssl_ca); if (lex_mi->ssl_capath) - strmake(mi->ssl_capath, lex_mi->ssl_capath, sizeof(mi->ssl_capath)-1); + strmake_buf(mi->ssl_capath, lex_mi->ssl_capath); if (lex_mi->ssl_cert) - strmake(mi->ssl_cert, lex_mi->ssl_cert, sizeof(mi->ssl_cert)-1); + strmake_buf(mi->ssl_cert, lex_mi->ssl_cert); if (lex_mi->ssl_cipher) - strmake(mi->ssl_cipher, lex_mi->ssl_cipher, sizeof(mi->ssl_cipher)-1); + strmake_buf(mi->ssl_cipher, lex_mi->ssl_cipher); if (lex_mi->ssl_key) - strmake(mi->ssl_key, lex_mi->ssl_key, sizeof(mi->ssl_key)-1); + strmake_buf(mi->ssl_key, lex_mi->ssl_key); #ifndef HAVE_OPENSSL if (lex_mi->ssl || lex_mi->ssl_ca || lex_mi->ssl_capath || lex_mi->ssl_cert || lex_mi->ssl_cipher || lex_mi->ssl_key || @@ -1750,10 +1764,8 @@ bool change_master(THD* thd, Master_info* mi) need_relay_log_purge= 0; char relay_log_name[FN_REFLEN]; mi->rli.relay_log.make_log_name(relay_log_name, lex_mi->relay_log_name); - strmake(mi->rli.group_relay_log_name, relay_log_name, - sizeof(mi->rli.group_relay_log_name)-1); - strmake(mi->rli.event_relay_log_name, relay_log_name, - sizeof(mi->rli.event_relay_log_name)-1); + strmake_buf(mi->rli.group_relay_log_name, relay_log_name); + strmake_buf(mi->rli.event_relay_log_name, relay_log_name); } if (lex_mi->relay_log_pos) @@ -1789,8 +1801,7 @@ bool change_master(THD* thd, Master_info* mi) */ mi->master_log_pos = max(BIN_LOG_HEADER_SIZE, mi->rli.group_master_log_pos); - strmake(mi->master_log_name, mi->rli.group_master_log_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, mi->rli.group_master_log_name); } /* Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never @@ -1843,8 +1854,7 @@ bool change_master(THD* thd, Master_info* mi) */ mi->rli.group_master_log_pos= mi->master_log_pos; DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - strmake(mi->rli.group_master_log_name,mi->master_log_name, - sizeof(mi->rli.group_master_log_name)-1); + strmake_buf(mi->rli.group_master_log_name,mi->master_log_name); if (!mi->rli.group_master_log_name[0]) // uninitialized case mi->rli.group_master_log_pos=0; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e1397b05bff..39512034cba 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2367,7 +2367,12 @@ JOIN::exec() List<Item> *curr_all_fields= &all_fields; List<Item> *curr_fields_list= &fields_list; TABLE *curr_tmp_table= 0; - bool tmp_having_used_tables_updated= FALSE; + /* + curr_join->join_free() will call JOIN::cleanup(full=TRUE). It will not + be safe to call update_used_tables() after that. + */ + if (curr_join->tmp_having) + curr_join->tmp_having->update_used_tables(); /* Initialize examined rows here because the values from all join parts @@ -2618,16 +2623,6 @@ JOIN::exec() curr_join->select_distinct=0; /* Each row is unique */ - /* - curr_join->join_free() will call JOIN::cleanup(full=TRUE). It will not - be safe to call update_used_tables() after that. - */ - if (curr_join->tmp_having) - { - curr_join->tmp_having->update_used_tables(); - tmp_having_used_tables_updated= TRUE; - } - curr_join->join_free(); /* Free quick selects */ if (curr_join->select_distinct && ! curr_join->group_list) @@ -2708,9 +2703,6 @@ JOIN::exec() if (curr_join->tmp_having && ! curr_join->group_list && ! curr_join->sort_and_group) { - // Some tables may have been const - if (!tmp_having_used_tables_updated) - curr_join->tmp_having->update_used_tables(); JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables]; table_map used_tables= (curr_join->const_table_map | curr_table->table->map); @@ -3523,9 +3515,16 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, !table->fulltext_searched && (!embedding || (embedding->sj_on_expr && !embedding->embedding))) { + key_map base_part, base_const_ref, base_eq_part; + base_part.set_prefix(keyinfo->key_parts); + base_const_ref= const_ref; + base_const_ref.intersect(base_part); + base_eq_part= eq_part; + base_eq_part.intersect(base_part); if (table->actual_key_flags(keyinfo) & HA_NOSAME) { - if (const_ref == eq_part && + + if (base_const_ref == base_eq_part && !has_expensive_keyparts && !((outer_join & table->map) && (*s->on_expr_ref)->is_expensive())) @@ -3551,7 +3550,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, else found_ref|= refs; // Table is const if all refs are const } - else if (const_ref == eq_part) + else if (base_const_ref == base_eq_part) s->const_keys.set_bit(key); } } @@ -3682,6 +3681,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, DBUG_RETURN(TRUE); join->join_tab=stat; + join->top_join_tab_count= table_count; join->map2table=stat_ref; join->table= table_vector; join->const_tables=const_count; @@ -3729,6 +3729,8 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, if (join->choose_subquery_plan(all_table_map & ~join->const_table_map)) goto error; + DEBUG_SYNC(join->thd, "inside_make_join_statistics"); + /* Generate an execution plan from the found optimal join order. */ DBUG_RETURN(join->thd->killed || get_best_combination(join)); @@ -10398,6 +10400,11 @@ bool JOIN_TAB::preread_init() preread_init_done= TRUE; if (select && select->quick) select->quick->replace_handler(table->file); + + /* init ftfuns for just initialized derived table */ + if (table->fulltext_searched) + init_ftfuncs(join->thd, join->select_lex, test(join->order)); + return FALSE; } @@ -10925,7 +10932,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, *simple_order=0; // Must do a temp table to sort else if (!(order_tables & not_const_tables)) { - if (order->item[0]->with_subselect) + if (order->item[0]->has_subquery()) { /* Delay the evaluation of constant ORDER and/or GROUP expressions that @@ -12853,9 +12860,6 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, table->prep_on_expr= table->on_expr= 0; } } - - if (!top) - continue; /* Only inner tables of non-convertible outer joins @@ -13250,13 +13254,13 @@ static void restore_prev_nj_state(JOIN_TAB *last) bool was_fully_covered= nest->is_fully_covered(); + join->cur_embedding_map|= nest->nj_map; + if (--nest->counter == 0) join->cur_embedding_map&= ~nest->nj_map; if (!was_fully_covered) break; - - join->cur_embedding_map|= nest->nj_map; } } } @@ -13474,7 +13478,27 @@ internal_remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) if (new_item_and_list->is_empty()) li.remove(); else + { + Item *list_item; + Item *new_list_item; + uint cnt= new_item_and_list->elements; + List_iterator<Item> it(*new_item_and_list); + while ((list_item= it++)) + { + uchar* is_subst_valid= (uchar *) Item::ANY_SUBST; + new_list_item= + list_item->compile(&Item::subst_argument_checker, + &is_subst_valid, + &Item::equal_fields_propagator, + (uchar *) &cond_and->cond_equal); + if (new_list_item != list_item) + it.replace(new_list_item); + new_list_item->update_used_tables(); + } li.replace(*new_item_and_list); + for (cnt--; cnt; cnt--) + item= li++; + } cond_and_list->concat((List<Item>*) cond_equal_items); } else if (new_item->type() == Item::FUNC_ITEM && @@ -13494,7 +13518,13 @@ internal_remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) if (new_item->type() == Item::COND_ITEM && ((Item_cond*) new_item)->functype() == ((Item_cond*) cond)->functype()) - li.replace(*((Item_cond*) new_item)->argument_list()); + { + List<Item> *arg_list= ((Item_cond*) new_item)->argument_list(); + uint cnt= arg_list->elements; + li.replace(*arg_list); + for ( cnt--; cnt; cnt--) + item= li++; + } else li.replace(new_item); } @@ -14076,6 +14106,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, } case Item::FIELD_ITEM: case Item::DEFAULT_VALUE_ITEM: + case Item::INSERT_VALUE_ITEM: { Item_field *field= (Item_field*) item; bool orig_modify= modify_item; @@ -18823,7 +18854,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, !(table->file->index_flags(best_key, 0, 1) & HA_CLUSTERED_INDEX))) goto use_filesort; - if (table->quick_keys.is_set(best_key) && best_key != ref_key) + if (select && + table->quick_keys.is_set(best_key) && best_key != ref_key) { key_map map; map.clear_all(); // Force the creation of quick select @@ -19476,7 +19508,7 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, } if (copy_blobs(first_field)) { - my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(0)); + my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(ME_FATALERROR)); error=0; goto err; } @@ -19509,7 +19541,8 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, if (!found) break; // End of file /* Restart search on saved row */ - error=file->restart_rnd_next(record); + if ((error= file->restart_rnd_next(record))) + goto err; } file->extra(HA_EXTRA_NO_CACHE); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 18241c4f80f..ec4633dadf9 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. - Copyright (c) 2009, 2012, Monty Program Ab +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2012, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1532,6 +1532,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, MODE_MYSQL323 | MODE_MYSQL40)) != 0; my_bitmap_map *old_map; + int error= 0; DBUG_ENTER("store_create_info"); DBUG_PRINT("enter",("table: %s", table->s->table_name.str)); @@ -1893,28 +1894,35 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, } #ifdef WITH_PARTITION_STORAGE_ENGINE { - /* - Partition syntax for CREATE TABLE is at the end of the syntax. - */ - uint part_syntax_len; - char *part_syntax; if (table->part_info && - (!table->part_info->is_auto_partitioned) && - ((part_syntax= generate_partition_syntax(table->part_info, + !((table->s->db_type()->partition_flags() & HA_USE_AUTO_PARTITION) && + table->part_info->is_auto_partitioned)) + { + /* + Partition syntax for CREATE TABLE is at the end of the syntax. + */ + uint part_syntax_len; + char *part_syntax; + String comment_start; + table->part_info->set_show_version_string(&comment_start); + if ((part_syntax= generate_partition_syntax(table->part_info, &part_syntax_len, FALSE, show_table_options, - NULL, NULL)))) - { - table->part_info->set_show_version_string(packet); - packet->append(part_syntax, part_syntax_len); - packet->append(STRING_WITH_LEN(" */")); - my_free(part_syntax); + NULL, NULL, + comment_start.c_ptr()))) + { + packet->append(comment_start); + if (packet->append(part_syntax, part_syntax_len) || + packet->append(STRING_WITH_LEN(" */"))) + error= 1; + my_free(part_syntax); + } } } #endif tmp_restore_column_map(table->read_set, old_map); - DBUG_RETURN(0); + DBUG_RETURN(error); } @@ -2158,7 +2166,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) DBUG_ENTER("mysqld_list_processes"); field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS)); - field_list.push_back(new Item_empty_string("User",16)); + field_list.push_back(new Item_empty_string("User", USERNAME_CHAR_LENGTH)); field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN)); field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN)); field->maybe_null=1; @@ -2923,8 +2931,8 @@ int fill_schema_user_stats(THD* thd, TABLE_LIST* tables, COND* cond) int result; DBUG_ENTER("fill_schema_user_stats"); - if (check_global_access(thd, SUPER_ACL | PROCESS_ACL)) - DBUG_RETURN(1); + if (check_global_access(thd, SUPER_ACL | PROCESS_ACL, true)) + DBUG_RETURN(0); /* Iterates through all the global stats and sends them to the client. @@ -2958,8 +2966,8 @@ int fill_schema_client_stats(THD* thd, TABLE_LIST* tables, COND* cond) int result; DBUG_ENTER("fill_schema_client_stats"); - if (check_global_access(thd, SUPER_ACL | PROCESS_ACL)) - DBUG_RETURN(1); + if (check_global_access(thd, SUPER_ACL | PROCESS_ACL, true)) + DBUG_RETURN(0); /* Iterates through all the global stats and sends them to the client. @@ -7044,7 +7052,7 @@ struct schema_table_ref ST_FIELD_INFO user_stats_fields_info[]= { - {"USER", USERNAME_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE}, + {"USER", USERNAME_CHAR_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE}, {"TOTAL_CONNECTIONS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Total_connections",SKIP_OPEN_TABLE}, {"CONCURRENT_CONNECTIONS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Concurrent_connections",SKIP_OPEN_TABLE}, {"CONNECTED_TIME", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Connected_time",SKIP_OPEN_TABLE}, @@ -7244,20 +7252,20 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list) break; case MYSQL_TYPE_DATE: if (!(item=new Item_return_date_time(fields_info->field_name, - MAX_DATE_WIDTH, + strlen(fields_info->field_name), fields_info->field_type))) DBUG_RETURN(0); break; case MYSQL_TYPE_TIME: if (!(item=new Item_return_date_time(fields_info->field_name, - MAX_TIME_FULL_WIDTH, + strlen(fields_info->field_name), fields_info->field_type))) DBUG_RETURN(0); break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATETIME: if (!(item=new Item_return_date_time(fields_info->field_name, - MAX_DATETIME_WIDTH, + strlen(fields_info->field_name), fields_info->field_type))) DBUG_RETURN(0); break; @@ -8410,7 +8418,8 @@ ST_FIELD_INFO variables_fields_info[]= ST_FIELD_INFO processlist_fields_info[]= { {"ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE}, - {"USER", 16, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE}, + {"USER", USERNAME_CHAR_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", + SKIP_OPEN_TABLE}, {"HOST", LIST_PROCESS_HOST_LEN, MYSQL_TYPE_STRING, 0, 0, "Host", SKIP_OPEN_TABLE}, {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Db", SKIP_OPEN_TABLE}, diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 4aba2ee51c5..4f3ec940cef 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -732,7 +732,7 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length) { if (from->Alloced_length >= from_length) return from; - if (from->alloced || !to || from == to) + if ((from->alloced && (from->Alloced_length != 0)) || !to || from == to) { (void) from->realloc(from_length); return from; diff --git a/sql/sql_string.h b/sql/sql_string.h index 8b09d449c2b..7a2f27da998 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -364,6 +364,16 @@ public: } return 0; } + bool append_hex(const char *src, uint32 srclen) + { + for (const char *end= src + srclen ; src != end ; src++) + { + if (append(_dig_vec_lower[((uchar) *src) >> 4]) || + append(_dig_vec_lower[((uchar) *src) & 0x0F])) + return true; + } + return false; + } bool fill(uint32 max_length,char fill); void strip_sp(); friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 8aac364265d..616e60a6199 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. - Copyright (c) 2010, 2013, Monty Program Ab + Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2010, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,6 +54,7 @@ #include "sql_show.h" #include "transaction.h" #include "datadict.h" // dd_frm_type() +#include "sql_audit.h" #ifdef __WIN__ #include <io.h> @@ -1692,7 +1693,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) &syntax_len, TRUE, TRUE, lpt->create_info, - lpt->alter_info))) + lpt->alter_info, + NULL))) { DBUG_RETURN(TRUE); } @@ -1785,7 +1787,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) &syntax_len, TRUE, TRUE, lpt->create_info, - lpt->alter_info))) + lpt->alter_info, + NULL))) { error= 1; goto err; @@ -2344,6 +2347,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, wrong_tables.append(','); wrong_tables.append(String(table->table_name,system_charset_info)); } + else + { + mysql_audit_drop_table(thd, table); + } DBUG_PRINT("table", ("table: 0x%lx s: 0x%lx", (long) table->table, table->table ? (long) table->table->s : (long) -1)); @@ -4252,7 +4259,8 @@ bool mysql_create_table_no_lock(THD *thd, &syntax_len, TRUE, TRUE, create_info, - alter_info))) + alter_info, + NULL))) goto err; part_info->part_info_string= part_syntax_buf; part_info->part_info_len= syntax_len; @@ -4728,6 +4736,8 @@ mysql_rename_table(handlerton *base, const char *old_db, my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER TABLE"); else if (error) my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error); + else if (!(flags & FN_IS_TMP)) + mysql_audit_rename_table(thd, old_db, old_name, new_db, new_name); DBUG_RETURN(error != 0); } @@ -6054,6 +6064,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, mysql_ha_rm_tables(thd, table_list); + mysql_audit_alter_table(thd, table_list); + /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */ if (alter_info->tablespace_op != NO_TABLESPACE_OP) /* Conditionally writes to binlog. */ @@ -6725,6 +6737,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, HA_OPTION_PACK_RECORD)); } tmp_disable_binlog(thd); + create_info->options|=HA_CREATE_TMP_ALTER; error= mysql_create_table_no_lock(thd, new_db, tmp_name, create_info, alter_info, diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 57dbd979933..dadf579b2e7 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -302,6 +302,9 @@ str_to_datetime_with_warn(CHARSET_INFO *cs, make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, str, length, flags & TIME_TIME_ONLY ? MYSQL_TIMESTAMP_TIME : ts_type, NullS); + DBUG_EXECUTE_IF("str_to_datetime_warn", + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_YES, str);); return ts_type; } diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index b0dd2183b62..65282de71cc 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -701,10 +701,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, thd->security_ctx->priv_host))) { if (check_global_access(thd, SUPER_ACL)) - { - my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER"); return TRUE; - } } /* diff --git a/sql/sql_view.cc b/sql/sql_view.cc index bbc5c324573..0e22db11eb8 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1156,9 +1156,10 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, TODO: when VIEWs will be stored in cache, table mem_root should be used here */ - if (parser->parse((uchar*)table, thd->mem_root, view_parameters, - required_view_parameters, &file_parser_dummy_hook)) - goto err; + if ((result= parser->parse((uchar*)table, thd->mem_root, + view_parameters, required_view_parameters, + &file_parser_dummy_hook))) + goto end; /* check old format view .frm @@ -1221,6 +1222,11 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, now Lex placed in statement memory */ table->view= lex= thd->lex= (LEX*) new(thd->mem_root) st_lex_local; + if (!table->view) + { + result= true; + goto end; + } { char old_db_buf[SAFE_NAME_LEN+1]; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 253ec61460e..c621c61aff3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. - Copyright (c) 2010, 2011 Monty Program Ab + Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2010, 2011, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -788,10 +788,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %pure_parser /* We have threads */ /* - Currently there are 174 shift/reduce conflicts. + Currently there are 175 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 174 +%expect 175 /* Comments for TOKENS. @@ -1021,6 +1021,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token HAVING /* SQL-2003-R */ %token HELP_SYM %token HEX_NUM +%token HEX_STRING %token HIGH_PRIORITY %token HOST_SYM %token HOSTS_SYM @@ -1448,7 +1449,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %left INTERVAL_SYM %type <lex_str> - IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM + IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM + HEX_NUM HEX_STRING hex_num_or_string LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text IDENT_sys TEXT_STRING_sys TEXT_STRING_literal NCHAR_STRING opt_component key_cache_name @@ -4418,7 +4420,7 @@ partition: ; part_type_def: - opt_linear KEY_SYM '(' part_field_list ')' + opt_linear KEY_SYM opt_key_algo '(' part_field_list ')' { partition_info *part_info= Lex->part_info; part_info->list_of_part_fields= TRUE; @@ -4444,6 +4446,25 @@ opt_linear: { Lex->part_info->linear_hash_ind= TRUE;} ; +opt_key_algo: + /* empty */ + { Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_NONE;} + | ALGORITHM_SYM EQ real_ulong_num + { + switch ($3) { + case 1: + Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_51; + break; + case 2: + Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_55; + break; + default: + my_parse_error(ER(ER_SYNTAX_ERROR)); + MYSQL_YYABORT; + } + } + ; + part_field_list: /* empty */ {} | part_field_item_list {} @@ -4525,7 +4546,7 @@ opt_sub_part: | SUBPARTITION_SYM BY opt_linear HASH_SYM sub_part_func { Lex->part_info->subpart_type= HASH_PARTITION; } opt_num_subparts {} - | SUBPARTITION_SYM BY opt_linear KEY_SYM + | SUBPARTITION_SYM BY opt_linear KEY_SYM opt_key_algo '(' sub_part_field_list ')' { partition_info *part_info= Lex->part_info; @@ -5977,6 +5998,11 @@ now_or_signed_literal: { $$=$1; } ; +hex_num_or_string: + HEX_NUM {} + | HEX_STRING {} + ; + charset: CHAR_SYM SET {} | CHARSET {} @@ -12242,7 +12268,7 @@ text_string: } | HEX_NUM { - Item *tmp= new (YYTHD->mem_root) Item_hex_string($1.str, $1.length); + Item *tmp= new (YYTHD->mem_root) Item_hex_hybrid($1.str, $1.length); if (tmp == NULL) MYSQL_YYABORT; /* @@ -12252,6 +12278,14 @@ text_string: tmp->quick_fix_field(); $$= tmp->val_str((String*) 0); } + | HEX_STRING + { + Item *tmp= new (YYTHD->mem_root) Item_hex_string($1.str, $1.length); + if (tmp == NULL) + MYSQL_YYABORT; + tmp->quick_fix_field(); + $$= tmp->val_str((String*) 0); + } | BIN_NUM { Item *tmp= new (YYTHD->mem_root) Item_bin_string($1.str, $1.length); @@ -12321,6 +12355,12 @@ literal: } | HEX_NUM { + $$ = new (YYTHD->mem_root) Item_hex_hybrid($1.str, $1.length); + if ($$ == NULL) + MYSQL_YYABORT; + } + | HEX_STRING + { $$ = new (YYTHD->mem_root) Item_hex_string($1.str, $1.length); if ($$ == NULL) MYSQL_YYABORT; @@ -12331,7 +12371,7 @@ literal: if ($$ == NULL) MYSQL_YYABORT; } - | UNDERSCORE_CHARSET HEX_NUM + | UNDERSCORE_CHARSET hex_num_or_string { Item *tmp= new (YYTHD->mem_root) Item_hex_string($2.str, $2.length); if (tmp == NULL) @@ -12887,7 +12927,7 @@ user: $$->auth= empty_lex_str; if (check_string_char_length(&$$->user, ER(ER_USERNAME), - USERNAME_CHAR_LENGTH, + username_char_length, system_charset_info, 0)) MYSQL_YYABORT; } @@ -12902,7 +12942,7 @@ user: $$->auth= empty_lex_str; if (check_string_char_length(&$$->user, ER(ER_USERNAME), - USERNAME_CHAR_LENGTH, + username_char_length, system_charset_info, 0) || check_host_name(&$$->host)) MYSQL_YYABORT; @@ -12960,6 +13000,7 @@ keyword: | LANGUAGE_SYM {} | NO_SYM {} | OPEN_SYM {} + | OPTION {} | OPTIONS_SYM {} | OWNER_SYM {} | PARSER_SYM {} diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index da971516141..bc54c9a5db7 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1068,7 +1068,7 @@ static Sys_var_ulonglong Sys_max_binlog_cache_size( "Sets the total size of the transactional cache", GLOBAL_VAR(max_binlog_cache_size), CMD_LINE(REQUIRED_ARG), VALID_RANGE(IO_SIZE, ULONGLONG_MAX), - DEFAULT((UINT_MAX/IO_SIZE)*IO_SIZE), + DEFAULT((ULONGLONG_MAX/IO_SIZE)*IO_SIZE), BLOCK_SIZE(IO_SIZE)); static Sys_var_ulonglong Sys_max_binlog_stmt_cache_size( @@ -1076,7 +1076,7 @@ static Sys_var_ulonglong Sys_max_binlog_stmt_cache_size( "Sets the total size of the statement cache", GLOBAL_VAR(max_binlog_stmt_cache_size), CMD_LINE(REQUIRED_ARG), VALID_RANGE(IO_SIZE, ULONGLONG_MAX), - DEFAULT((UINT_MAX/IO_SIZE)*IO_SIZE), + DEFAULT((ULONGLONG_MAX/IO_SIZE)*IO_SIZE), BLOCK_SIZE(IO_SIZE)); static bool fix_max_binlog_size(sys_var *self, THD *thd, enum_var_type type) diff --git a/sql/sys_vars.h b/sql/sys_vars.h index 95a8e45f7c3..8345a2836dd 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -547,8 +547,7 @@ public: protected: virtual uchar *session_value_ptr(THD *thd, LEX_STRING *base) { - return thd->security_ctx->proxy_user[0] ? - (uchar *) &(thd->security_ctx->proxy_user[0]) : NULL; + return (uchar*)thd->security_ctx->external_user; } }; diff --git a/sql/table.cc b/sql/table.cc index c92a096be90..77e251729c7 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3537,9 +3537,9 @@ bool check_column_name(const char *name) } #else last_char_is_space= *name==' '; -#endif - if (*name == NAMES_SEP_CHAR) + if (*name == '\377') return 1; +#endif name++; name_length++; } diff --git a/sql/tztime.cc b/sql/tztime.cc index 0e793290bba..95a1001485b 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -2559,7 +2559,7 @@ main(int argc, char **argv) if (argc == 2) { - root_name_end= strmake(fullname, argv[1], FN_REFLEN); + root_name_end= strmake_buf(fullname, argv[1]); printf("TRUNCATE TABLE time_zone;\n"); printf("TRUNCATE TABLE time_zone_name;\n"); @@ -2713,7 +2713,7 @@ main(int argc, char **argv) (int)t, (int)t1); /* Let us load time zone description */ - str_end= strmake(fullname, TZDIR, FN_REFLEN); + str_end= strmake_buf(fullname, TZDIR); strmake(str_end, "/MET", FN_REFLEN - (str_end - fullname)); if (tz_load(fullname, &tz_info, &tz_storage)) |