summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorGuilhem Bichot <guilhem@mysql.com>2009-08-04 13:25:19 +0200
committerGuilhem Bichot <guilhem@mysql.com>2009-08-04 13:25:19 +0200
commitb57e4dbd88671df86e2cf39aff5178976d710b64 (patch)
tree32be2bfec3ca062c65566c60ecf59b673d1f97e9 /sql
parent1a0c2153a036296785dcdfa7b5f4974515616e11 (diff)
parent94efc1c6b084ed531b513e70fb66e7b7a1186b56 (diff)
downloadmariadb-git-b57e4dbd88671df86e2cf39aff5178976d710b64.tar.gz
Creation of mysql-trunk = {summit + "Innodb plugin replacing the builtin"}:
bzr branch mysql-5.1-performance-version mysql-trunk # Summit cd mysql-trunk bzr merge mysql-5.1-innodb_plugin # which is 5.1 + Innodb plugin bzr rm innobase # remove the builtin Next step: build, test fixes.
Diffstat (limited to 'sql')
-rwxr-xr-xsql/CMakeLists.txt80
-rw-r--r--sql/field.cc40
-rw-r--r--sql/field_conv.cc12
-rw-r--r--sql/gstream.cc2
-rw-r--r--sql/ha_ndbcluster.cc46
-rw-r--r--sql/ha_ndbcluster_binlog.cc36
-rw-r--r--sql/ha_partition.cc5
-rw-r--r--sql/handler.cc61
-rw-r--r--sql/handler.h16
-rw-r--r--sql/item.cc309
-rw-r--r--sql/item.h199
-rw-r--r--sql/item_cmpfunc.cc23
-rw-r--r--sql/item_func.cc155
-rw-r--r--sql/item_func.h9
-rw-r--r--sql/item_geofunc.cc13
-rw-r--r--sql/item_strfunc.cc42
-rw-r--r--sql/item_strfunc.h4
-rw-r--r--sql/item_subselect.cc8
-rw-r--r--sql/item_sum.cc24
-rw-r--r--sql/item_timefunc.cc8
-rw-r--r--sql/log.cc208
-rw-r--r--sql/log.h7
-rw-r--r--sql/log_event.cc104
-rw-r--r--sql/log_event.h7
-rw-r--r--sql/my_decimal.h17
-rw-r--r--sql/mysql_priv.h85
-rw-r--r--sql/mysqld.cc16
-rw-r--r--sql/opt_range.cc30
-rw-r--r--sql/opt_sum.cc4
-rw-r--r--sql/parse_file.cc4
-rw-r--r--sql/password.c53
-rw-r--r--sql/rpl_reporting.cc7
-rw-r--r--sql/rpl_reporting.h10
-rw-r--r--sql/rpl_rli.cc14
-rw-r--r--sql/set_var.cc4
-rw-r--r--sql/share/errmsg.txt26
-rw-r--r--sql/slave.cc73
-rw-r--r--sql/slave.h4
-rw-r--r--sql/sp.cc30
-rw-r--r--sql/sp.h4
-rw-r--r--sql/sp_head.cc3
-rw-r--r--sql/spatial.h12
-rw-r--r--sql/sql_acl.cc147
-rw-r--r--sql/sql_acl.h4
-rw-r--r--sql/sql_analyse.cc2
-rw-r--r--sql/sql_base.cc62
-rw-r--r--sql/sql_cache.cc428
-rw-r--r--sql/sql_cache.h23
-rw-r--r--sql/sql_class.cc48
-rw-r--r--sql/sql_class.h45
-rw-r--r--sql/sql_connect.cc20
-rw-r--r--sql/sql_db.cc33
-rw-r--r--sql/sql_delete.cc42
-rw-r--r--sql/sql_derived.cc1
-rw-r--r--sql/sql_help.cc2
-rw-r--r--sql/sql_insert.cc83
-rw-r--r--sql/sql_lex.cc25
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_list.h2
-rw-r--r--sql/sql_load.cc21
-rw-r--r--sql/sql_parse.cc51
-rw-r--r--sql/sql_partition.cc56
-rw-r--r--sql/sql_plugin.cc346
-rw-r--r--sql/sql_plugin.h1
-rw-r--r--sql/sql_prepare.cc62
-rw-r--r--sql/sql_profile.h23
-rw-r--r--sql/sql_rename.cc8
-rw-r--r--sql/sql_repl.cc3
-rw-r--r--sql/sql_select.cc138
-rw-r--r--sql/sql_show.cc34
-rw-r--r--sql/sql_string.cc14
-rw-r--r--sql/sql_table.cc352
-rw-r--r--sql/sql_trigger.cc2
-rw-r--r--sql/sql_union.cc16
-rw-r--r--sql/sql_update.cc69
-rw-r--r--sql/sql_view.cc17
-rw-r--r--sql/sql_yacc.yy22
-rw-r--r--sql/structs.h4
-rw-r--r--sql/table.cc68
-rw-r--r--sql/thr_malloc.cc2
-rw-r--r--sql/time.cc8
-rw-r--r--sql/tztime.cc4
-rw-r--r--sql/uniques.cc4
-rw-r--r--sql/unireg.cc3
84 files changed, 2801 insertions, 1310 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index cfd049e1864..6f162f4d84d 100755
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -39,7 +39,8 @@ SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/sql_yacc.h
ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN -DHAVE_EVENT_SCHEDULER)
-ADD_EXECUTABLE(mysqld
+
+SET (SQL_SOURCE
../sql-common/client.c derror.cc des_key_file.cc
discover.cc ../libmysql/errmsg.c field.cc field_conv.cc
filesort.cc gstream.cc
@@ -82,54 +83,45 @@ ADD_EXECUTABLE(mysqld
${PROJECT_SOURCE_DIR}/include/mysql_version.h
${PROJECT_SOURCE_DIR}/sql/sql_builtin.cc
${PROJECT_SOURCE_DIR}/sql/lex_hash.h)
+ADD_LIBRARY(sql ${SQL_SOURCE})
-TARGET_LINK_LIBRARIES(mysqld
- heap myisam myisammrg mysys yassl zlib debug dbug yassl
- taocrypt strings vio regex wsock32 ws2_32)
+IF (NOT EXISTS cmake_dummy.cc)
+ FILE (WRITE cmake_dummy.cc "")
+ENDIF (NOT EXISTS cmake_dummy.cc)
+ADD_EXECUTABLE(mysqld cmake_dummy.cc)
SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX})
+SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE)
+
+SET (MYSQLD_CORE_LIBS mysys zlib dbug strings yassl taocrypt vio regex sql)
+TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_CORE_LIBS} ${MYSQLD_STATIC_ENGINE_LIBS})
+TARGET_LINK_LIBRARIES(mysqld ws2_32.lib)
+
-IF(cmake_version EQUAL 20406)
-# Work around for 2.4.6 bug, OUTPUT_NAME will not set the right .PDB
-# file name. Note that COMPILE_FLAGS set some temporary pdb during build,
-# LINK_FLAGS sets the real one.
-SET_TARGET_PROPERTIES(mysqld PROPERTIES
- COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/mysqld${MYSQLD_EXE_SUFFIX}.pdb"
- LINK_FLAGS "/PDB:${CMAKE_CFG_INTDIR}/mysqld${MYSQLD_EXE_SUFFIX}.pdb")
-ENDIF(cmake_version EQUAL 20406)
-
-IF(EMBED_MANIFESTS)
- MYSQL_EMBED_MANIFEST("mysqld" "asInvoker")
-ENDIF(EMBED_MANIFESTS)
-IF(WITH_ARCHIVE_STORAGE_ENGINE)
- TARGET_LINK_LIBRARIES(mysqld archive)
-ENDIF(WITH_ARCHIVE_STORAGE_ENGINE)
-IF(WITH_BLACKHOLE_STORAGE_ENGINE)
- TARGET_LINK_LIBRARIES(mysqld blackhole)
-ENDIF(WITH_BLACKHOLE_STORAGE_ENGINE)
-IF(WITH_CSV_STORAGE_ENGINE)
- TARGET_LINK_LIBRARIES(mysqld csv)
-ENDIF(WITH_CSV_STORAGE_ENGINE)
-IF(WITH_EXAMPLE_STORAGE_ENGINE)
- TARGET_LINK_LIBRARIES(mysqld example)
-ENDIF(WITH_EXAMPLE_STORAGE_ENGINE)
-IF(WITH_FEDERATED_STORAGE_ENGINE)
- TARGET_LINK_LIBRARIES(mysqld federated)
-ENDIF(WITH_FEDERATED_STORAGE_ENGINE)
-IF(WITH_INNOBASE_STORAGE_ENGINE)
- TARGET_LINK_LIBRARIES(mysqld innobase)
-ENDIF(WITH_INNOBASE_STORAGE_ENGINE)
-
-ADD_DEPENDENCIES(mysqld GenError)
-
-# NOTE CMake 2.4.6 creates strange dependencies between files in OUTPUT,
-# so for now we only list one if more than one
+IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS)
+ # Set module definition file. Also use non-incremental linker,
+ # incremental appears to crash from time to time,if used with /DEF option
+ SET_TARGET_PROPERTIES(mysqld PROPERTIES LINK_FLAGS "/DEF:mysqld.def /INCREMENTAL:NO")
+
+ FOREACH (CORELIB ${MYSQLD_CORE_LIBS})
+ GET_TARGET_PROPERTY(LOC ${CORELIB} LOCATION)
+ FILE(TO_NATIVE_PATH ${LOC} LOC)
+ SET (LIB_LOCATIONS ${LIB_LOCATIONS} ${LOC})
+ ENDFOREACH (CORELIB ${MYSQLD_CORE_LIBS})
+
+ ADD_CUSTOM_COMMAND(TARGET mysqld PRE_LINK
+ COMMAND cscript ARGS //nologo ${PROJECT_SOURCE_DIR}/win/create_def_file.js
+ ${PLATFORM} ${LIB_LOCATIONS} > mysqld.def
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sql)
+ENDIF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS)
+
+ADD_DEPENDENCIES(sql GenError)
# Sql Parser custom command
ADD_CUSTOM_COMMAND(
OUTPUT ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h
-# ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
- COMMAND bison.exe ARGS -y -p MYSQL --defines=sql_yacc.h
+ ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
+ COMMAND bison ARGS -y -p MYSQL --defines=sql_yacc.h
--output=sql_yacc.cc sql_yacc.yy
DEPENDS ${PROJECT_SOURCE_DIR}/sql/sql_yacc.yy)
@@ -146,16 +138,16 @@ ADD_CUSTOM_COMMAND(
ADD_CUSTOM_TARGET(
GenServerSource ALL
DEPENDS ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h
-# ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
+ ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
${PROJECT_SOURCE_DIR}/sql/message.h
-# ${PROJECT_SOURCE_DIR}/sql/message.rc
+ ${PROJECT_SOURCE_DIR}/sql/message.rc
${PROJECT_SOURCE_DIR}/sql/lex_hash.h)
ADD_DEPENDENCIES(mysqld GenServerSource)
# Remove the auto-generated files as part of 'Clean Solution'
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
- "lex_hash.h;sql_yacc.h;sql_yacc.cc")
+ "lex_hash.h;sql_yacc.h;sql_yacc.cc;mysqld.def")
ADD_LIBRARY(udf_example MODULE udf_example.c udf_example.def)
ADD_DEPENDENCIES(udf_example strings GenError)
diff --git a/sql/field.cc b/sql/field.cc
index d11b509075b..ed085de1db3 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1165,7 +1165,7 @@ bool Field_num::get_int(CHARSET_INFO *cs, const char *from, uint len,
if (unsigned_flag)
{
- if (((ulonglong) *rnd > unsigned_max) && (*rnd= (longlong) unsigned_max) ||
+ if ((((ulonglong) *rnd > unsigned_max) && (*rnd= (longlong) unsigned_max)) ||
error == MY_ERRNO_ERANGE)
{
goto out_of_range;
@@ -1350,7 +1350,7 @@ void Field::copy_from_tmp(int row_offset)
if (null_ptr)
{
*null_ptr= (uchar) ((null_ptr[0] & (uchar) ~(uint) null_bit) |
- null_ptr[row_offset] & (uchar) null_bit);
+ (null_ptr[row_offset] & (uchar) null_bit));
}
}
@@ -4081,8 +4081,8 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
int error;
char *end;
double nr= my_strntod(cs,(char*) from,len,&end,&error);
- if (error || (!len || (uint) (end-from) != len &&
- table->in_use->count_cuted_fields))
+ if (error || (!len || ((uint) (end-from) != len &&
+ table->in_use->count_cuted_fields)))
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
(error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), 1);
@@ -4343,8 +4343,8 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
int error;
char *end;
double nr= my_strntod(cs,(char*) from, len, &end, &error);
- if (error || (!len || (uint) (end-from) != len &&
- table->in_use->count_cuted_fields))
+ if (error || (!len || ((uint) (end-from) != len &&
+ table->in_use->count_cuted_fields)))
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
(error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), 1);
@@ -5196,7 +5196,7 @@ int Field_time::store(longlong nr, bool unsigned_val)
MYSQL_TIMESTAMP_TIME, 1);
error= 1;
}
- else if (nr > (longlong) TIME_MAX_VALUE || nr < 0 && unsigned_val)
+ else if (nr > (longlong) TIME_MAX_VALUE || (nr < 0 && unsigned_val))
{
tmp= TIME_MAX_VALUE;
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
@@ -5307,7 +5307,7 @@ bool Field_time::get_time(MYSQL_TIME *ltime)
ltime->neg= 1;
tmp=-tmp;
}
- ltime->day= 0;
+ ltime->year= ltime->month= ltime->day= 0;
ltime->hour= (int) (tmp/10000);
tmp-=ltime->hour*10000;
ltime->minute= (int) tmp/100;
@@ -5361,7 +5361,7 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
int error;
longlong nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155 ||
+ if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155 ||
error == MY_ERRNO_ERANGE)
{
*ptr=0;
@@ -5405,7 +5405,7 @@ int Field_year::store(double nr)
int Field_year::store(longlong nr, bool unsigned_val)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155)
+ if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155)
{
*ptr= 0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
@@ -6429,16 +6429,16 @@ int Field_str::store(double nr)
/* Calculate the exponent from the 'e'-format conversion */
if (anr < 1.0 && anr > 0)
{
- for (exp= 0; anr < 1e-100; exp-= 100, anr*= 1e100);
- for (; anr < 1e-10; exp-= 10, anr*= 1e10);
- for (i= 1; anr < 1 / log_10[i]; exp--, i++);
+ for (exp= 0; anr < 1e-100; exp-= 100, anr*= 1e100) ;
+ for (; anr < 1e-10; exp-= 10, anr*= 1e10) ;
+ for (i= 1; anr < 1 / log_10[i]; exp--, i++) ;
exp--;
}
else
{
- for (exp= 0; anr > 1e100; exp+= 100, anr/= 1e100);
- for (; anr > 1e10; exp+= 10, anr/= 1e10);
- for (i= 1; anr > log_10[i]; exp++, i++);
+ for (exp= 0; anr > 1e100; exp+= 100, anr/= 1e100) ;
+ for (; anr > 1e10; exp+= 10, anr/= 1e10) ;
+ for (i= 1; anr > log_10[i]; exp++, i++) ;
}
max_length= local_char_length - neg;
@@ -8833,7 +8833,7 @@ bool Field_num::eq_def(Field *field)
Field_num *from_num= (Field_num*) field;
if (unsigned_flag != from_num->unsigned_flag ||
- zerofill && !from_num->zerofill && !zero_pack() ||
+ (zerofill && !from_num->zerofill && !zero_pack()) ||
dec != from_num->dec)
return 0;
return 1;
@@ -8974,7 +8974,7 @@ int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs)
ASSERT_COLUMN_MARKED_FOR_WRITE;
int delta;
- for (; length && !*from; from++, length--); // skip left 0's
+ for (; length && !*from; from++, length--) ; // skip left 0's
delta= bytes_in_rec - length;
if (delta < -1 ||
@@ -9306,7 +9306,7 @@ Field_bit::unpack(uchar *to, const uchar *from, uint param_data,
and slave have the same sizes, then use the old unpack() method.
*/
if (param_data == 0 ||
- (from_bit_len == bit_len) && (from_len == bytes_in_rec))
+ ((from_bit_len == bit_len) && (from_len == bytes_in_rec)))
{
if (bit_len > 0)
{
@@ -9385,7 +9385,7 @@ int Field_bit_as_char::store(const char *from, uint length, CHARSET_INFO *cs)
int delta;
uchar bits= (uchar) (field_length & 7);
- for (; length && !*from; from++, length--); // skip left 0's
+ for (; length && !*from; from++, length--) ; // skip left 0's
delta= bytes_in_rec - length;
if (delta < 0 ||
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 11d0bb9cc82..3574534722e 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -99,7 +99,7 @@ static void do_field_to_null_str(Copy_field *copy)
static void do_outer_field_to_null_str(Copy_field *copy)
{
if (*copy->null_row ||
- copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit))
+ (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
{
bzero(copy->to_ptr,copy->from_length);
copy->to_null_ptr[0]=1; // Always bit 1
@@ -212,7 +212,7 @@ static void do_copy_null(Copy_field *copy)
static void do_outer_field_null(Copy_field *copy)
{
if (*copy->null_row ||
- copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit))
+ (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
{
*copy->to_null_ptr|=copy->to_bit;
copy->to_field->reset();
@@ -665,9 +665,9 @@ Copy_field::get_copy_func(Field *to,Field *from)
*/
if (to->real_type() != from->real_type() ||
!compatible_db_low_byte_first ||
- ((to->table->in_use->variables.sql_mode &
+ (((to->table->in_use->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) &&
- to->type() == MYSQL_TYPE_DATE ||
+ to->type() == MYSQL_TYPE_DATE) ||
to->type() == MYSQL_TYPE_DATETIME))
{
if (from->real_type() == MYSQL_TYPE_ENUM ||
@@ -770,8 +770,8 @@ int field_conv(Field *to,Field *from)
to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
(!(to->table->in_use->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) ||
- to->type() != MYSQL_TYPE_DATE &&
- to->type() != MYSQL_TYPE_DATETIME) &&
+ (to->type() != MYSQL_TYPE_DATE &&
+ to->type() != MYSQL_TYPE_DATETIME)) &&
(from->real_type() != MYSQL_TYPE_VARCHAR ||
((Field_varstring*)from)->length_bytes ==
((Field_varstring*)to)->length_bytes))
diff --git a/sql/gstream.cc b/sql/gstream.cc
index 0c8011549f3..e2bb41b8541 100644
--- a/sql/gstream.cc
+++ b/sql/gstream.cc
@@ -75,7 +75,7 @@ bool Gis_read_stream::get_next_number(double *d)
skip_space();
if ((m_cur >= m_limit) ||
- (*m_cur < '0' || *m_cur > '9') && *m_cur != '-' && *m_cur != '+')
+ ((*m_cur < '0' || *m_cur > '9') && *m_cur != '-' && *m_cur != '+'))
{
set_error_msg("Numeric constant expected");
return 1;
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 03bae38d94c..264e5649ea9 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -1263,7 +1263,7 @@ int ha_ndbcluster::add_index_handle(THD *thd, NDBDICT *dict, KEY *key_info,
}
if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX)
{
- char unique_index_name[FN_LEN];
+ char unique_index_name[FN_LEN + 1];
static const char* unique_suffix= "$unique";
m_has_unique_index= TRUE;
strxnmov(unique_index_name, FN_LEN, index_name, unique_suffix, NullS);
@@ -5205,7 +5205,7 @@ int ha_ndbcluster::create(const char *name,
uchar *data= NULL, *pack_data= NULL;
bool create_from_engine= (create_info->table_options & HA_OPTION_CREATE_FROM_ENGINE);
bool is_truncate= (thd->lex->sql_command == SQLCOM_TRUNCATE);
- char tablespace[FN_LEN];
+ char tablespace[FN_LEN + 1];
NdbDictionary::Table::SingleUserMode single_user_mode= NdbDictionary::Table::SingleUserModeLocked;
DBUG_ENTER("ha_ndbcluster::create");
@@ -5668,7 +5668,7 @@ int ha_ndbcluster::create_index(const char *name, KEY *key_info,
NDB_INDEX_TYPE idx_type, uint idx_no)
{
int error= 0;
- char unique_name[FN_LEN];
+ char unique_name[FN_LEN + 1];
static const char* unique_suffix= "$unique";
DBUG_ENTER("ha_ndbcluster::create_ordered_index");
DBUG_PRINT("info", ("Creating index %u: %s", idx_no, name));
@@ -6716,7 +6716,7 @@ int ndbcluster_discover(handlerton *hton, THD* thd, const char *db,
size_t len;
uchar* data= NULL;
Ndb* ndb;
- char key[FN_REFLEN];
+ char key[FN_REFLEN + 1];
DBUG_ENTER("ndbcluster_discover");
DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
@@ -6727,7 +6727,7 @@ int ndbcluster_discover(handlerton *hton, THD* thd, const char *db,
ERR_RETURN(ndb->getNdbError());
}
NDBDICT* dict= ndb->getDictionary();
- build_table_filename(key, sizeof(key), db, name, "", 0);
+ build_table_filename(key, sizeof(key) - 1, db, name, "", 0);
/* ndb_share reference temporary */
NDB_SHARE *share= get_share(key, 0, FALSE);
if (share)
@@ -6892,9 +6892,9 @@ int ndbcluster_drop_database_impl(const char *path)
drop_list.push_back(thd->strdup(elmt.name));
}
// Drop any tables belonging to database
- char full_path[FN_REFLEN];
+ char full_path[FN_REFLEN + 1];
char *tmp= full_path +
- build_table_filename(full_path, sizeof(full_path), dbname, "", "", 0);
+ build_table_filename(full_path, sizeof(full_path) - 1, dbname, "", "", 0);
if (ndb->setDatabaseName(dbname))
{
ERR_RETURN(ndb->getNdbError());
@@ -6963,7 +6963,7 @@ int ndb_create_table_from_engine(THD *thd, const char *db,
int ndbcluster_find_all_files(THD *thd)
{
Ndb* ndb;
- char key[FN_REFLEN];
+ char key[FN_REFLEN + 1];
NDBDICT *dict;
int unhandled, retries= 5, skipped;
DBUG_ENTER("ndbcluster_find_all_files");
@@ -7021,7 +7021,7 @@ int ndbcluster_find_all_files(THD *thd)
/* check if database exists */
char *end= key +
- build_table_filename(key, sizeof(key), elmt.database, "", "", 0);
+ build_table_filename(key, sizeof(key) - 1, elmt.database, "", "", 0);
if (my_access(key, F_OK))
{
/* no such database defined, skip table */
@@ -7102,7 +7102,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
{ // extra bracket to avoid gcc 2.95.3 warning
uint i;
Ndb* ndb;
- char name[FN_REFLEN];
+ char name[FN_REFLEN + 1];
HASH ndb_tables, ok_tables;
NDBDICT::List list;
@@ -7172,7 +7172,8 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
DBUG_PRINT("info", ("%s", file_name->str));
if (hash_search(&ndb_tables, (uchar*) file_name->str, file_name->length))
{
- build_table_filename(name, sizeof(name), db, file_name->str, reg_ext, 0);
+ build_table_filename(name, sizeof(name) - 1, db,
+ file_name->str, reg_ext, 0);
if (my_access(name, F_OK))
{
pthread_mutex_lock(&LOCK_open);
@@ -7194,7 +7195,8 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
}
// Check for .ndb file with this name
- build_table_filename(name, sizeof(name), db, file_name->str, ha_ndb_ext, 0);
+ build_table_filename(name, sizeof(name) - 1, db,
+ file_name->str, ha_ndb_ext, 0);
DBUG_PRINT("info", ("Check access for %s", name));
if (my_access(name, F_OK))
{
@@ -7237,7 +7239,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
/* setup logging to binlog for all discovered tables */
{
char *end, *end1= name +
- build_table_filename(name, sizeof(name), db, "", "", 0);
+ build_table_filename(name, sizeof(name) - 1, db, "", "", 0);
for (i= 0; i < ok_tables.records; i++)
{
file_name_str= (char*)hash_element(&ok_tables, i);
@@ -7259,7 +7261,8 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
file_name_str= (char*) hash_element(&ndb_tables, i);
if (!hash_search(&ok_tables, (uchar*) file_name_str, strlen(file_name_str)))
{
- build_table_filename(name, sizeof(name), db, file_name_str, reg_ext, 0);
+ build_table_filename(name, sizeof(name) - 1,
+ db, file_name_str, reg_ext, 0);
if (my_access(name, F_OK))
{
DBUG_PRINT("info", ("%s must be discovered", file_name_str));
@@ -7639,7 +7642,7 @@ void ndbcluster_print_error(int error, const NdbOperation *error_op)
void ha_ndbcluster::set_dbname(const char *path_name, char *dbname)
{
char *end, *ptr, *tmp_name;
- char tmp_buff[FN_REFLEN];
+ char tmp_buff[FN_REFLEN + 1];
tmp_name= tmp_buff;
/* Scan name from the end */
@@ -7665,7 +7668,7 @@ void ha_ndbcluster::set_dbname(const char *path_name, char *dbname)
ptr++;
}
#endif
- filename_to_tablename(tmp_name, dbname, FN_REFLEN);
+ filename_to_tablename(tmp_name, dbname, sizeof(tmp_buff) - 1);
}
/**
@@ -7685,7 +7688,7 @@ void
ha_ndbcluster::set_tabname(const char *path_name, char * tabname)
{
char *end, *ptr, *tmp_name;
- char tmp_buff[FN_REFLEN];
+ char tmp_buff[FN_REFLEN + 1];
tmp_name= tmp_buff;
/* Scan name from the end */
@@ -7706,7 +7709,7 @@ ha_ndbcluster::set_tabname(const char *path_name, char * tabname)
ptr++;
}
#endif
- filename_to_tablename(tmp_name, tabname, FN_REFLEN);
+ filename_to_tablename(tmp_name, tabname, sizeof(tmp_buff) - 1);
}
/**
@@ -7892,11 +7895,12 @@ uint8 ha_ndbcluster::table_cache_type()
uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname,
Uint64 *commit_count)
{
- char name[FN_REFLEN];
+ char name[FN_REFLEN + 1];
NDB_SHARE *share;
DBUG_ENTER("ndb_get_commitcount");
- build_table_filename(name, sizeof(name), dbname, tabname, "", 0);
+ build_table_filename(name, sizeof(name) - 1,
+ dbname, tabname, "", 0);
DBUG_PRINT("enter", ("name: %s", name));
pthread_mutex_lock(&ndbcluster_mutex);
if (!(share=(NDB_SHARE*) hash_search(&ndbcluster_open_tables,
@@ -10040,7 +10044,7 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *create_info,
ai=1;
}
- char tablespace_name[FN_LEN];
+ char tablespace_name[FN_LEN + 1];
if (get_tablespace_name(current_thd, tablespace_name, FN_LEN))
{
if (create_info->tablespace)
diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
index baf86d739eb..f705af8bf47 100644
--- a/sql/ha_ndbcluster_binlog.cc
+++ b/sql/ha_ndbcluster_binlog.cc
@@ -788,7 +788,7 @@ static int ndbcluster_create_ndb_apply_status_table(THD *thd)
if (g_ndb_cluster_connection->get_no_ready() <= 0)
DBUG_RETURN(0);
- char buf[1024], *end;
+ char buf[1024 + 1], *end;
if (ndb_extra_logging)
sql_print_information("NDB: Creating " NDB_REP_DB "." NDB_APPLY_TABLE);
@@ -798,7 +798,7 @@ static int ndbcluster_create_ndb_apply_status_table(THD *thd)
if so, remove it since there is none in Ndb
*/
{
- build_table_filename(buf, sizeof(buf),
+ build_table_filename(buf, sizeof(buf) - 1,
NDB_REP_DB, NDB_APPLY_TABLE, reg_ext, 0);
my_delete(buf, MYF(0));
}
@@ -846,7 +846,7 @@ static int ndbcluster_create_schema_table(THD *thd)
if (g_ndb_cluster_connection->get_no_ready() <= 0)
DBUG_RETURN(0);
- char buf[1024], *end;
+ char buf[1024 + 1], *end;
if (ndb_extra_logging)
sql_print_information("NDB: Creating " NDB_REP_DB "." NDB_SCHEMA_TABLE);
@@ -856,7 +856,7 @@ static int ndbcluster_create_schema_table(THD *thd)
if so, remove it since there is none in Ndb
*/
{
- build_table_filename(buf, sizeof(buf),
+ build_table_filename(buf, sizeof(buf) - 1,
NDB_REP_DB, NDB_SCHEMA_TABLE, reg_ext, 0);
my_delete(buf, MYF(0));
}
@@ -1321,8 +1321,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
NDB_SCHEMA_OBJECT *ndb_schema_object;
{
- char key[FN_REFLEN];
- build_table_filename(key, sizeof(key), db, table_name, "", 0);
+ char key[FN_REFLEN + 1];
+ build_table_filename(key, sizeof(key) - 1, db, table_name, "", 0);
ndb_schema_object= ndb_get_schema_object(key, TRUE, FALSE);
}
@@ -1674,7 +1674,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp,
if (is_remote_change && is_online_alter_table)
{
const char *tabname= table_share->table_name.str;
- char key[FN_REFLEN];
+ char key[FN_REFLEN + 1];
uchar *data= 0, *pack_data= 0;
size_t length, pack_length;
int error;
@@ -1683,7 +1683,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp,
DBUG_PRINT("info", ("Detected frm change of table %s.%s",
dbname, tabname));
- build_table_filename(key, FN_LEN-1, dbname, tabname, NullS, 0);
+ build_table_filename(key, FN_LEN - 1, dbname, tabname, NullS, 0);
/*
If the there is no local table shadowing the altered table and
it has an frm that is different than the one on disk then
@@ -1855,9 +1855,11 @@ static void ndb_binlog_query(THD *thd, Cluster_schema *schema)
else
thd->server_id= schema->any_value;
thd->db= schema->db;
+ int errcode = query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::STMT_QUERY_TYPE, schema->query,
schema->query_length, FALSE,
- schema->name[0] == 0 || thd->db[0] == 0);
+ schema->name[0] == 0 || thd->db[0] == 0,
+ errcode);
thd->server_id= thd_server_id_save;
thd->db= thd_db_save;
}
@@ -1924,8 +1926,8 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb,
break;
case SOT_TRUNCATE_TABLE:
{
- char key[FN_REFLEN];
- build_table_filename(key, sizeof(key),
+ char key[FN_REFLEN + 1];
+ build_table_filename(key, sizeof(key) - 1,
schema->db, schema->name, "", 0);
/* ndb_share reference temporary, free below */
NDB_SHARE *share= get_share(key, 0, FALSE, FALSE);
@@ -2171,8 +2173,8 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd,
int log_query= 0;
{
enum SCHEMA_OP_TYPE schema_type= (enum SCHEMA_OP_TYPE)schema->type;
- char key[FN_REFLEN];
- build_table_filename(key, sizeof(key), schema->db, schema->name, "", 0);
+ char key[FN_REFLEN + 1];
+ build_table_filename(key, sizeof(key) - 1, schema->db, schema->name, "", 0);
if (schema_type == SOT_CLEAR_SLOCK)
{
pthread_mutex_lock(&ndbcluster_mutex);
@@ -2506,8 +2508,8 @@ ndb_rep_event_name(String *event_name,const char *db, const char *tbl)
bool
ndbcluster_check_if_local_table(const char *dbname, const char *tabname)
{
- char key[FN_REFLEN];
- char ndb_file[FN_REFLEN];
+ char key[FN_REFLEN + 1];
+ char ndb_file[FN_REFLEN + 1];
DBUG_ENTER("ndbcluster_check_if_local_table");
build_table_filename(key, FN_LEN-1, dbname, tabname, reg_ext, 0);
@@ -2532,9 +2534,9 @@ ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname)
DBUG_PRINT("info", ("Looking for files in directory %s", dbname));
LEX_STRING *tabname;
List<LEX_STRING> files;
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
- build_table_filename(path, sizeof(path), dbname, "", "", 0);
+ build_table_filename(path, sizeof(path) - 1, dbname, "", "", 0);
if (find_files(thd, &files, dbname, path, NullS, 0) != FIND_FILES_OK)
{
DBUG_PRINT("info", ("Failed to find files"));
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 67bc3156260..74742f58028 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -3179,6 +3179,7 @@ int ha_partition::delete_row(const uchar *buf)
int ha_partition::delete_all_rows()
{
int error;
+ bool truncate= FALSE;
handler **file;
THD *thd= ha_thd();
DBUG_ENTER("ha_partition::delete_all_rows");
@@ -3190,12 +3191,16 @@ int ha_partition::delete_all_rows()
ha_data->next_auto_inc_val= 0;
ha_data->auto_inc_initialized= FALSE;
unlock_auto_increment();
+ truncate= TRUE;
}
file= m_file;
do
{
if ((error= (*file)->ha_delete_all_rows()))
DBUG_RETURN(error);
+ /* Ignore the error */
+ if (truncate)
+ (void) (*file)->ha_reset_auto_increment(0);
} while (*(++file));
DBUG_RETURN(0);
}
diff --git a/sql/handler.cc b/sql/handler.cc
index 0de7718d113..285690ea66a 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1074,6 +1074,13 @@ int ha_commit_trans(THD *thd, bool all)
user, or an implicit commit issued by a DDL.
*/
THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt;
+ /*
+ "real" is a nick name for a transaction for which a commit will
+ make persistent changes. E.g. a 'stmt' transaction inside a 'all'
+ transation is not 'real': even though it's possible to commit it,
+ the changes are not durable as they might be rolled back if the
+ enclosing 'all' transaction is rolled back.
+ */
bool is_real_trans= all || thd->transaction.all.ha_list == 0;
Ha_trx_info *ha_info= trans->ha_list;
my_xid xid= thd->transaction.xid_state.xid.get_my_xid();
@@ -1185,16 +1192,9 @@ end:
if (rw_trans)
start_waiting_global_read_lock(thd);
}
- else if (all)
- {
- /*
- A COMMIT of an empty transaction. There may be savepoints.
- Destroy them. If the transaction is not empty
- savepoints are cleared in ha_commit_one_phase()
- or ha_rollback_trans().
- */
+ /* Free resources and perform other cleanup even for 'empty' transactions. */
+ else if (is_real_trans)
thd->transaction.cleanup();
- }
#endif /* USING_TRANSACTIONS */
DBUG_RETURN(error);
}
@@ -1207,6 +1207,13 @@ int ha_commit_one_phase(THD *thd, bool all)
{
int error=0;
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
+ /*
+ "real" is a nick name for a transaction for which a commit will
+ make persistent changes. E.g. a 'stmt' transaction inside a 'all'
+ transation is not 'real': even though it's possible to commit it,
+ the changes are not durable as they might be rolled back if the
+ enclosing 'all' transaction is rolled back.
+ */
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
DBUG_ENTER("ha_commit_one_phase");
@@ -1228,8 +1235,6 @@ int ha_commit_one_phase(THD *thd, bool all)
}
trans->ha_list= 0;
trans->no_2pc=0;
- if (is_real_trans)
- thd->transaction.xid_state.xid.null();
if (all)
{
#ifdef HAVE_QUERY_CACHE
@@ -1237,9 +1242,11 @@ int ha_commit_one_phase(THD *thd, bool all)
query_cache.invalidate(thd->transaction.changed_tables);
#endif
thd->variables.tx_isolation=thd->session_tx_isolation;
- thd->transaction.cleanup();
}
}
+ /* Free resources and perform other cleanup even for 'empty' transactions. */
+ if (is_real_trans)
+ thd->transaction.cleanup();
#endif /* USING_TRANSACTIONS */
DBUG_RETURN(error);
}
@@ -1250,6 +1257,13 @@ int ha_rollback_trans(THD *thd, bool all)
int error=0;
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
+ /*
+ "real" is a nick name for a transaction for which a commit will
+ make persistent changes. E.g. a 'stmt' transaction inside a 'all'
+ transation is not 'real': even though it's possible to commit it,
+ the changes are not durable as they might be rolled back if the
+ enclosing 'all' transaction is rolled back.
+ */
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
DBUG_ENTER("ha_rollback_trans");
@@ -1295,18 +1309,13 @@ int ha_rollback_trans(THD *thd, bool all)
}
trans->ha_list= 0;
trans->no_2pc=0;
- if (is_real_trans)
- {
- if (thd->transaction_rollback_request)
- thd->transaction.xid_state.rm_error= thd->main_da.sql_errno();
- else
- thd->transaction.xid_state.xid.null();
- }
+ if (is_real_trans && thd->transaction_rollback_request)
+ thd->transaction.xid_state.rm_error= thd->main_da.sql_errno();
if (all)
thd->variables.tx_isolation=thd->session_tx_isolation;
}
/* Always cleanup. Even if there nht==0. There may be savepoints. */
- if (all)
+ if (is_real_trans)
thd->transaction.cleanup();
#endif /* USING_TRANSACTIONS */
if (all)
@@ -2284,8 +2293,8 @@ int handler::update_auto_increment()
DBUG_ASSERT(next_insert_id >= auto_inc_interval_for_cur_row.minimum());
if ((nr= table->next_number_field->val_int()) != 0 ||
- table->auto_increment_field_not_null &&
- thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)
+ (table->auto_increment_field_not_null &&
+ thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO))
{
/*
Update next_insert_id if we had already generated a value in this
@@ -3575,7 +3584,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
int error;
uchar *frmblob;
size_t frmlen;
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
HA_CREATE_INFO create_info;
TABLE table;
TABLE_SHARE share;
@@ -3594,7 +3603,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
frmblob and frmlen are set, write the frm to disk
*/
- build_table_filename(path, FN_REFLEN-1, db, name, "", 0);
+ build_table_filename(path, sizeof(path) - 1, db, name, "", 0);
// Save the frm file
error= writefrm(path, frmblob, frmlen);
my_free(frmblob, MYF(0));
@@ -4821,7 +4830,7 @@ fl_log_iterator_buffer_init(struct handler_iterator *iterator)
if ((ptr= (uchar*)my_malloc(ALIGN_SIZE(sizeof(fl_buff)) +
((ALIGN_SIZE(sizeof(LEX_STRING)) +
sizeof(enum log_status) +
- + FN_REFLEN) *
+ + FN_REFLEN + 1) *
(uint) dirp->number_off_files),
MYF(0))) == 0)
{
@@ -4849,7 +4858,7 @@ fl_log_iterator_buffer_init(struct handler_iterator *iterator)
name_ptr= strxnmov(buff->names[buff->entries].str= name_ptr,
FN_REFLEN, fl_dir, file->name, NullS);
buff->names[buff->entries].length= (name_ptr -
- buff->names[buff->entries].str) - 1;
+ buff->names[buff->entries].str);
buff->statuses[buff->entries]= st;
buff->entries++;
}
diff --git a/sql/handler.h b/sql/handler.h
index d43fc4725dd..11d0f71fc72 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -876,9 +876,9 @@ typedef struct {
ulonglong delete_length;
ha_rows records;
ulong mean_rec_length;
- time_t create_time;
- time_t check_time;
- time_t update_time;
+ ulong create_time;
+ ulong check_time;
+ ulong update_time;
ulonglong check_sum;
} PARTITION_INFO;
@@ -1037,9 +1037,9 @@ public:
ha_rows records;
ha_rows deleted; /* Deleted records */
ulong mean_rec_length; /* physical reclength */
- time_t create_time; /* When table was created */
- time_t check_time;
- time_t update_time;
+ ulong create_time; /* When table was created */
+ ulong check_time;
+ ulong update_time;
uint block_size; /* index block size */
ha_statistics():
@@ -1932,8 +1932,8 @@ private:
/* Some extern variables used with handlers */
extern const char *ha_row_type[];
-extern const char *tx_isolation_names[];
-extern const char *binlog_format_names[];
+extern MYSQL_PLUGIN_IMPORT const char *tx_isolation_names[];
+extern MYSQL_PLUGIN_IMPORT const char *binlog_format_names[];
extern TYPELIB tx_isolation_typelib;
extern TYPELIB myisam_stats_method_typelib;
extern ulong total_ha, total_ha_2pc;
diff --git a/sql/item.cc b/sql/item.cc
index d1418b9a137..4d9004fff26 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -417,6 +417,7 @@ Item::Item(THD *thd, Item *item):
name(item->name),
orig_name(item->orig_name),
max_length(item->max_length),
+ name_length(item->name_length),
marker(item->marker),
decimals(item->decimals),
maybe_null(item->maybe_null),
@@ -424,7 +425,9 @@ Item::Item(THD *thd, Item *item):
unsigned_flag(item->unsigned_flag),
with_sum_func(item->with_sum_func),
fixed(item->fixed),
+ is_autogenerated_name(item->is_autogenerated_name),
collation(item->collation),
+ with_subselect(item->with_subselect),
cmp_context(item->cmp_context)
{
next= thd->free_list; // Put in free list
@@ -1504,10 +1507,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
{
set(dt);
}
- else
- {
- // Do nothing
- }
}
else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
left_is_superset(this, &dt))
@@ -2261,8 +2260,10 @@ Item_decimal::Item_decimal(const char *str_arg, uint length,
name= (char*) str_arg;
decimals= (uint8) decimal_value.frac;
fixed= 1;
- max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
- decimals, unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
+ decimals,
+ decimals,
+ unsigned_flag);
}
Item_decimal::Item_decimal(longlong val, bool unsig)
@@ -2270,8 +2271,10 @@ Item_decimal::Item_decimal(longlong val, bool unsig)
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
decimals= (uint8) decimal_value.frac;
fixed= 1;
- max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
- decimals, unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
+ decimals,
+ decimals,
+ unsigned_flag);
}
@@ -2280,8 +2283,10 @@ Item_decimal::Item_decimal(double val, int precision, int scale)
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
decimals= (uint8) decimal_value.frac;
fixed= 1;
- max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
- decimals, unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
+ decimals,
+ decimals,
+ unsigned_flag);
}
@@ -2301,8 +2306,10 @@ Item_decimal::Item_decimal(my_decimal *value_par)
my_decimal2decimal(value_par, &decimal_value);
decimals= (uint8) decimal_value.frac;
fixed= 1;
- max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
- decimals, unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
+ decimals,
+ decimals,
+ unsigned_flag);
}
@@ -2312,8 +2319,8 @@ Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
&decimal_value, precision, scale);
decimals= (uint8) decimal_value.frac;
fixed= 1;
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
+ unsigned_flag);
}
@@ -2368,8 +2375,10 @@ void Item_decimal::set_decimal_value(my_decimal *value_par)
my_decimal2decimal(value_par, &decimal_value);
decimals= (uint8) decimal_value.frac;
unsigned_flag= !decimal_value.sign();
- max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
- decimals, unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
+ decimals,
+ decimals,
+ unsigned_flag);
}
@@ -2472,8 +2481,9 @@ longlong_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
TODO: Give error if we wanted a signed integer and we got an unsigned
one
*/
- if (err > 0 ||
- (end != org_end && !check_if_only_end_space(cs, end, org_end)))
+ if (!current_thd->no_errors &&
+ (err > 0 ||
+ (end != org_end && !check_if_only_end_space(cs, end, org_end))))
{
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE,
@@ -2640,8 +2650,9 @@ void Item_param::set_decimal(const char *str, ulong length)
str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
state= DECIMAL_VALUE;
decimals= decimal_value.frac;
- max_length= my_decimal_precision_to_length(decimal_value.precision(),
- decimals, unsigned_flag);
+ max_length=
+ my_decimal_precision_to_length_no_truncation(decimal_value.precision(),
+ decimals, unsigned_flag);
maybe_null= 0;
DBUG_VOID_RETURN;
}
@@ -2771,8 +2782,8 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
CHARSET_INFO *tocs= thd->variables.collation_connection;
uint32 dummy_offset;
- value.cs_info.character_set_of_placeholder=
- value.cs_info.character_set_client= fromcs;
+ value.cs_info.character_set_of_placeholder= fromcs;
+ value.cs_info.character_set_client= thd->variables.character_set_client;
/*
Setup source and destination character sets so that they
are different only if conversion is necessary: this will
@@ -2797,8 +2808,9 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
my_decimal2decimal(ent_value, &decimal_value);
state= DECIMAL_VALUE;
decimals= ent_value->frac;
- max_length= my_decimal_precision_to_length(ent_value->precision(),
- decimals, unsigned_flag);
+ max_length=
+ my_decimal_precision_to_length_no_truncation(ent_value->precision(),
+ decimals, unsigned_flag);
item_type= Item::DECIMAL_ITEM;
break;
}
@@ -3268,9 +3280,57 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
}
/****************************************************************************
+ Item_copy
+****************************************************************************/
+Item_copy *Item_copy::create (Item *item)
+{
+ switch (item->result_type())
+ {
+ case STRING_RESULT:
+ return new Item_copy_string (item);
+ case REAL_RESULT:
+ return new Item_copy_float (item);
+ case INT_RESULT:
+ return item->unsigned_flag ?
+ new Item_copy_uint (item) : new Item_copy_int (item);
+ case DECIMAL_RESULT:
+ return new Item_copy_decimal (item);
+
+ case ROW_RESULT:
+ DBUG_ASSERT (0);
+ }
+ /* should not happen */
+ return NULL;
+}
+
+/****************************************************************************
Item_copy_string
****************************************************************************/
+double Item_copy_string::val_real()
+{
+ int err_not_used;
+ char *end_not_used;
+ return (null_value ? 0.0 :
+ my_strntod(str_value.charset(), (char*) str_value.ptr(),
+ str_value.length(), &end_not_used, &err_not_used));
+}
+
+longlong Item_copy_string::val_int()
+{
+ int err;
+ return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
+ str_value.length(),10, (char**) 0,
+ &err);
+}
+
+
+int Item_copy_string::save_in_field(Field *field, bool no_conversions)
+{
+ return save_str_value_in_field(field, &str_value);
+}
+
+
void Item_copy_string::copy()
{
String *res=item->val_str(&str_value);
@@ -3293,12 +3353,163 @@ my_decimal *Item_copy_string::val_decimal(my_decimal *decimal_value)
{
// Item_copy_string is used without fix_fields call
if (null_value)
- return 0;
+ return (my_decimal *) 0;
string2my_decimal(E_DEC_FATAL_ERROR, &str_value, decimal_value);
return (decimal_value);
}
+/****************************************************************************
+ Item_copy_int
+****************************************************************************/
+
+void Item_copy_int::copy()
+{
+ cached_value= item->val_int();
+ null_value=item->null_value;
+}
+
+static int save_int_value_in_field (Field *field, longlong nr,
+ bool null_value, bool unsigned_flag);
+
+int Item_copy_int::save_in_field(Field *field, bool no_conversions)
+{
+ return save_int_value_in_field(field, cached_value,
+ null_value, unsigned_flag);
+}
+
+
+String *Item_copy_int::val_str(String *str)
+{
+ if (null_value)
+ return (String *) 0;
+
+ str->set(cached_value, &my_charset_bin);
+ return str;
+}
+
+
+my_decimal *Item_copy_int::val_decimal(my_decimal *decimal_value)
+{
+ if (null_value)
+ return (my_decimal *) 0;
+
+ int2my_decimal(E_DEC_FATAL_ERROR, cached_value, unsigned_flag, decimal_value);
+ return decimal_value;
+}
+
+
+/****************************************************************************
+ Item_copy_uint
+****************************************************************************/
+
+String *Item_copy_uint::val_str(String *str)
+{
+ if (null_value)
+ return (String *) 0;
+
+ str->set((ulonglong) cached_value, &my_charset_bin);
+ return str;
+}
+
+
+/****************************************************************************
+ Item_copy_float
+****************************************************************************/
+
+String *Item_copy_float::val_str(String *str)
+{
+ if (null_value)
+ return (String *) 0;
+ else
+ {
+ double nr= val_real();
+ str->set_real(nr,decimals, &my_charset_bin);
+ return str;
+ }
+}
+
+
+my_decimal *Item_copy_float::val_decimal(my_decimal *decimal_value)
+{
+ if (null_value)
+ return (my_decimal *) 0;
+ else
+ {
+ double nr= val_real();
+ double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
+ return decimal_value;
+ }
+}
+
+
+int Item_copy_float::save_in_field(Field *field, bool no_conversions)
+{
+ if (null_value)
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store(cached_value);
+}
+
+
+/****************************************************************************
+ Item_copy_decimal
+****************************************************************************/
+
+int Item_copy_decimal::save_in_field(Field *field, bool no_conversions)
+{
+ if (null_value)
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store_decimal(&cached_value);
+}
+
+
+String *Item_copy_decimal::val_str(String *result)
+{
+ if (null_value)
+ return (String *) 0;
+ result->set_charset(&my_charset_bin);
+ my_decimal2string(E_DEC_FATAL_ERROR, &cached_value, 0, 0, 0, result);
+ return result;
+}
+
+
+double Item_copy_decimal::val_real()
+{
+ if (null_value)
+ return 0.0;
+ else
+ {
+ double result;
+ my_decimal2double(E_DEC_FATAL_ERROR, &cached_value, &result);
+ return result;
+ }
+}
+
+
+longlong Item_copy_decimal::val_int()
+{
+ if (null_value)
+ return LL(0);
+ else
+ {
+ longlong result;
+ my_decimal2int(E_DEC_FATAL_ERROR, &cached_value, unsigned_flag, &result);
+ return result;
+ }
+}
+
+
+void Item_copy_decimal::copy()
+{
+ my_decimal *nr= item->val_decimal(&cached_value);
+ if (nr && nr != &cached_value)
+ memcpy (&cached_value, nr, sizeof (my_decimal));
+ null_value= item->null_value;
+}
+
+
/*
Functions to convert item to field (for send_fields)
*/
@@ -3390,14 +3601,12 @@ static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
current->mark_as_dependent(last);
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
- char warn_buff[MYSQL_ERRMSG_SIZE];
- sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
- db_name, (db_name[0] ? "." : ""),
- table_name, (table_name [0] ? "." : ""),
- resolved_item->field_name,
- current->select_number, last->select_number);
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
- ER_WARN_FIELD_RESOLVED, warn_buff);
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_WARN_FIELD_RESOLVED, ER(ER_WARN_FIELD_RESOLVED),
+ db_name, (db_name[0] ? "." : ""),
+ table_name, (table_name [0] ? "." : ""),
+ resolved_item->field_name,
+ current->select_number, last->select_number);
}
}
@@ -4209,16 +4418,22 @@ mark_non_agg_field:
Fields from outer selects added to the aggregate function
outer_fields list as its unknown at the moment whether it's
aggregated or not.
+ We're using either the select lex of the cached table (if present)
+ or the field's resolution context. context->select_lex is
+ safe for use because it's either the SELECT we want to use
+ (the current level) or a stub added by non-SELECT queries.
*/
+ SELECT_LEX *select_lex= cached_table ?
+ cached_table->select_lex : context->select_lex;
if (!thd->lex->in_sum_func)
- cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
+ select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
else
{
if (outer_fixed)
thd->lex->in_sum_func->outer_fields.push_back(this);
else if (thd->lex->in_sum_func->nest_level !=
thd->lex->current_select->nest_level)
- cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
+ select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
}
}
return FALSE;
@@ -4875,7 +5090,10 @@ int Item_null::save_safe_in_field(Field *field)
/*
This implementation can lose str_value content, so if the
Item uses str_value to store something, it should
- reimplement it's ::save_in_field() as Item_string, for example, does
+ reimplement it's ::save_in_field() as Item_string, for example, does.
+
+ Note: all Item_XXX::val_str(str) methods must NOT rely on the fact that
+ str != str_value. For example, see fix for bug #44743.
*/
int Item::save_in_field(Field *field, bool no_conversions)
@@ -4945,10 +5163,9 @@ int Item_uint::save_in_field(Field *field, bool no_conversions)
return Item_int::save_in_field(field, no_conversions);
}
-
-int Item_int::save_in_field(Field *field, bool no_conversions)
+static int save_int_value_in_field (Field *field, longlong nr,
+ bool null_value, bool unsigned_flag)
{
- longlong nr=val_int();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
@@ -4956,6 +5173,12 @@ int Item_int::save_in_field(Field *field, bool no_conversions)
}
+int Item_int::save_in_field(Field *field, bool no_conversions)
+{
+ return save_int_value_in_field (field, val_int(), null_value, unsigned_flag);
+}
+
+
int Item_decimal::save_in_field(Field *field, bool no_conversions)
{
field->set_notnull();
@@ -5812,7 +6035,8 @@ void Item_ref::print(String *str, enum_query_type query_type)
!table_name && name && alias_name_used)
{
THD *thd= current_thd;
- append_identifier(thd, str, name, (uint) strlen(name));
+ append_identifier(thd, str, (*ref)->real_item()->name,
+ (*ref)->real_item()->name_length);
}
else
(*ref)->print(str, query_type);
@@ -7084,8 +7308,9 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
int precision= min(item_prec, DECIMAL_MAX_PRECISION);
unsigned_flag&= item->unsigned_flag;
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision,
+ decimals,
+ unsigned_flag);
}
switch (Field::result_merge_type(fld_type))
diff --git a/sql/item.h b/sql/item.h
index 96a4e9f7a31..3dfcd7c2612 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2443,48 +2443,203 @@ public:
#include "item_xmlfunc.h"
#endif
-class Item_copy_string :public Item
+/**
+ Base class to implement typed value caching Item classes
+
+ Item_copy_ classes are very similar to the corresponding Item_
+ classes (e.g. Item_copy_int is similar to Item_int) but they add
+ the following additional functionality to Item_ :
+ 1. Nullability
+ 2. Possibility to store the value not only on instantiation time,
+ but also later.
+ Item_copy_ classes are a functionality subset of Item_cache_
+ classes, as e.g. they don't support comparisons with the original Item
+ as Item_cache_ classes do.
+ Item_copy_ classes are used in GROUP BY calculation.
+ TODO: Item_copy should be made an abstract interface and Item_copy_
+ classes should inherit both the respective Item_ class and the interface.
+ Ideally we should drop Item_copy_ classes altogether and merge
+ their functionality to Item_cache_ (and these should be made to inherit
+ from Item_).
+*/
+
+class Item_copy :public Item
{
+protected:
+
+ /**
+ Stores the type of the resulting field that would be used to store the data
+ in the cache. This is to avoid calls to the original item.
+ */
enum enum_field_types cached_field_type;
-public:
+
+ /** The original item that is copied */
Item *item;
- Item_copy_string(Item *i) :item(i)
+
+ /**
+ Stores the result type of the original item, so it can be returned
+ without calling the original item's method
+ */
+ Item_result cached_result_type;
+
+ /**
+ Constructor of the Item_copy class
+
+ stores metadata information about the original class as well as a
+ pointer to it.
+ */
+ Item_copy(Item *i)
{
+ item= i;
null_value=maybe_null=item->maybe_null;
decimals=item->decimals;
max_length=item->max_length;
name=item->name;
cached_field_type= item->field_type();
+ cached_result_type= item->result_type();
+ unsigned_flag= item->unsigned_flag;
}
+
+public:
+ /**
+ Factory method to create the appropriate subclass dependent on the type of
+ the original item.
+
+ @param item the original item.
+ */
+ static Item_copy *create (Item *item);
+
+ /**
+ Update the cache with the value of the original item
+
+ This is the method that updates the cached value.
+ It must be explicitly called by the user of this class to store the value
+ of the orginal item in the cache.
+ */
+ virtual void copy() = 0;
+
+ Item *get_item() { return item; }
+ /** All of the subclasses should have the same type tag */
enum Type type() const { return COPY_STR_ITEM; }
- enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return cached_field_type; }
- double val_real()
+ enum Item_result result_type () const { return cached_result_type; }
+
+ void make_field(Send_field *field) { item->make_field(field); }
+ table_map used_tables() const { return (table_map) 1L; }
+ bool const_item() const { return 0; }
+ bool is_null() { return null_value; }
+
+ /*
+ Override the methods below as pure virtual to make sure all the
+ sub-classes implement them.
+ */
+
+ virtual String *val_str(String*) = 0;
+ virtual my_decimal *val_decimal(my_decimal *) = 0;
+ virtual double val_real() = 0;
+ virtual longlong val_int() = 0;
+ virtual int save_in_field(Field *field, bool no_conversions) = 0;
+};
+
+/**
+ Implementation of a string cache.
+
+ Uses Item::str_value for storage
+*/
+class Item_copy_string : public Item_copy
+{
+public:
+ Item_copy_string (Item *item) : Item_copy(item) {}
+
+ String *val_str(String*);
+ my_decimal *val_decimal(my_decimal *);
+ double val_real();
+ longlong val_int();
+ void copy();
+ int save_in_field(Field *field, bool no_conversions);
+};
+
+
+class Item_copy_int : public Item_copy
+{
+protected:
+ longlong cached_value;
+public:
+ Item_copy_int (Item *i) : Item_copy(i) {}
+ int save_in_field(Field *field, bool no_conversions);
+
+ virtual String *val_str(String*);
+ virtual my_decimal *val_decimal(my_decimal *);
+ virtual double val_real()
{
- int err_not_used;
- char *end_not_used;
- return (null_value ? 0.0 :
- my_strntod(str_value.charset(), (char*) str_value.ptr(),
- str_value.length(), &end_not_used, &err_not_used));
+ return null_value ? 0.0 : (double) cached_value;
}
- longlong val_int()
+ virtual longlong val_int()
+ {
+ return null_value ? LL(0) : cached_value;
+ }
+ virtual void copy();
+};
+
+
+class Item_copy_uint : public Item_copy_int
+{
+public:
+ Item_copy_uint (Item *item) : Item_copy_int(item)
+ {
+ unsigned_flag= 1;
+ }
+
+ String *val_str(String*);
+ double val_real()
{
- int err;
- return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
- str_value.length(),10, (char**) 0,
- &err);
+ return null_value ? 0.0 : (double) (ulonglong) cached_value;
}
+};
+
+
+class Item_copy_float : public Item_copy
+{
+protected:
+ double cached_value;
+public:
+ Item_copy_float (Item *i) : Item_copy(i) {}
+ int save_in_field(Field *field, bool no_conversions);
+
String *val_str(String*);
my_decimal *val_decimal(my_decimal *);
- void make_field(Send_field *field) { item->make_field(field); }
- void copy();
- int save_in_field(Field *field, bool no_conversions)
+ double val_real()
{
- return save_str_value_in_field(field, &str_value);
+ return null_value ? 0.0 : cached_value;
}
- table_map used_tables() const { return (table_map) 1L; }
- bool const_item() const { return 0; }
- bool is_null() { return null_value; }
+ longlong val_int()
+ {
+ return (longlong) rint(val_real());
+ }
+ void copy()
+ {
+ cached_value= item->val_real();
+ null_value= item->null_value;
+ }
+};
+
+
+class Item_copy_decimal : public Item_copy
+{
+protected:
+ my_decimal cached_value;
+public:
+ Item_copy_decimal (Item *i) : Item_copy(i) {}
+ int save_in_field(Field *field, bool no_conversions);
+
+ String *val_str(String*);
+ my_decimal *val_decimal(my_decimal *)
+ {
+ return null_value ? NULL: &cached_value;
+ }
+ double val_real();
+ longlong val_int();
+ void copy();
};
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index a9bfea1b806..1ff9ca6a419 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1484,8 +1484,8 @@ longlong Item_func_truth::val_int()
bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
{
- if (!args[0]->fixed && args[0]->fix_fields(thd, args) ||
- !cache && !(cache= Item_cache::get_cache(args[0])))
+ if ((!args[0]->fixed && args[0]->fix_fields(thd, args)) ||
+ (!cache && !(cache= Item_cache::get_cache(args[0]))))
return 1;
cache->setup(args[0]);
@@ -2724,16 +2724,6 @@ void Item_func_case::fix_length_and_dec()
nagg++;
if (!(found_types= collect_cmp_types(agg, nagg)))
return;
- if (with_sum_func || current_thd->lex->current_select->group_list.elements)
- {
- /*
- See TODO commentary in the setup_copy_fields function:
- item in a group may be wrapped with an Item_copy_string item.
- That item has a STRING_RESULT result type, so we need
- to take this type into account.
- */
- found_types |= (1 << item_cmp_type(left_result_type, STRING_RESULT));
- }
for (i= 0; i <= (uint)DECIMAL_RESULT; i++)
{
@@ -2770,8 +2760,9 @@ void Item_func_case::fix_length_and_dec()
agg_num_lengths(args[i + 1]);
if (else_expr_num != -1)
agg_num_lengths(args[else_expr_num]);
- max_length= my_decimal_precision_to_length(max_length + decimals, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(max_length +
+ decimals, decimals,
+ unsigned_flag);
}
}
@@ -3006,8 +2997,8 @@ int cmp_longlong(void *cmp_arg,
One of the args is unsigned and is too big to fit into the
positive signed range. Report no match.
*/
- if (a->unsigned_flag && ((ulonglong) a->val) > (ulonglong) LONGLONG_MAX ||
- b->unsigned_flag && ((ulonglong) b->val) > (ulonglong) LONGLONG_MAX)
+ if ((a->unsigned_flag && ((ulonglong) a->val) > (ulonglong) LONGLONG_MAX) ||
+ (b->unsigned_flag && ((ulonglong) b->val) > (ulonglong) LONGLONG_MAX))
return a->unsigned_flag ? 1 : -1;
/*
Although the signedness differs both args can fit into the signed
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 876aee719a3..0af3c4954cd 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -452,11 +452,45 @@ Field *Item_func::tmp_table_field(TABLE *table)
return make_string_field(table);
break;
case DECIMAL_RESULT:
- field= new Field_new_decimal(my_decimal_precision_to_length(decimal_precision(),
- decimals,
- unsigned_flag),
- maybe_null, name, decimals, unsigned_flag);
+ {
+ uint8 dec= decimals;
+ uint8 intg= decimal_precision() - dec;
+ uint32 len= max_length;
+
+ /*
+ Trying to put too many digits overall in a DECIMAL(prec,dec)
+ will always throw a warning. We must limit dec to
+ DECIMAL_MAX_SCALE however to prevent an assert() later.
+ */
+
+ if (dec > 0)
+ {
+ int overflow;
+
+ dec= min(dec, DECIMAL_MAX_SCALE);
+
+ /*
+ If the value still overflows the field with the corrected dec,
+ we'll throw out decimals rather than integers. This is still
+ bad and of course throws a truncation warning.
+ */
+
+ const int required_length=
+ my_decimal_precision_to_length(intg + dec, dec,
+ unsigned_flag);
+
+ overflow= required_length - len;
+
+ if (overflow > 0)
+ dec= max(0, dec - overflow); // too long, discard fract
+ else
+ /* Corrected value fits. */
+ len= required_length;
+ }
+
+ field= new Field_new_decimal(len, maybe_null, name, dec, unsigned_flag);
break;
+ }
case ROW_RESULT:
default:
// This case should never be chosen
@@ -545,8 +579,8 @@ void Item_func::count_decimal_length()
set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
}
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
+ unsigned_flag);
}
@@ -1141,16 +1175,15 @@ void Item_func_additive_op::result_precision()
decimals= max(args[0]->decimals, args[1]->decimals);
int arg1_int= args[0]->decimal_precision() - args[0]->decimals;
int arg2_int= args[1]->decimal_precision() - args[1]->decimals;
- int est_prec= max(arg1_int, arg2_int) + 1 + decimals;
- int precision= min(est_prec, DECIMAL_MAX_PRECISION);
+ int precision= max(arg1_int, arg2_int) + 1 + decimals;
/* Integer operations keep unsigned_flag if one of arguments is unsigned */
if (result_type() == INT_RESULT)
unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
else
unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
+ unsigned_flag);
}
@@ -1255,7 +1288,8 @@ void Item_func_mul::result_precision()
decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision();
uint precision= min(est_prec, DECIMAL_MAX_PRECISION);
- max_length= my_decimal_precision_to_length(precision, decimals,unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
+ unsigned_flag);
}
@@ -1311,8 +1345,8 @@ void Item_func_div::result_precision()
else
unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
+ unsigned_flag);
}
@@ -1944,8 +1978,8 @@ void Item_func_round::fix_length_and_dec()
unsigned_flag= args[0]->unsigned_flag;
if (!args[1]->const_item())
{
- max_length= args[0]->max_length;
decimals= args[0]->decimals;
+ max_length= float_length(decimals);
if (args[0]->result_type() == DECIMAL_RESULT)
{
max_length++;
@@ -1965,8 +1999,8 @@ void Item_func_round::fix_length_and_dec()
if (args[0]->decimals == NOT_FIXED_DEC)
{
- max_length= args[0]->max_length;
decimals= min(decimals_to_set, NOT_FIXED_DEC);
+ max_length= float_length(decimals);
hybrid_type= REAL_RESULT;
return;
}
@@ -1999,8 +2033,9 @@ void Item_func_round::fix_length_and_dec()
precision-= decimals_delta - length_increase;
decimals= min(decimals_to_set, DECIMAL_MAX_SCALE);
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision,
+ decimals,
+ unsigned_flag);
break;
}
default:
@@ -2143,9 +2178,6 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref)
if (!rand && !(rand= (struct rand_struct*)
thd->stmt_arena->alloc(sizeof(*rand))))
return TRUE;
-
- if (args[0]->const_item())
- seed_random (args[0]);
}
else
{
@@ -2175,8 +2207,21 @@ void Item_func_rand::update_used_tables()
double Item_func_rand::val_real()
{
DBUG_ASSERT(fixed == 1);
- if (arg_count && !args[0]->const_item())
- seed_random (args[0]);
+ if (arg_count)
+ {
+ if (!args[0]->const_item())
+ seed_random(args[0]);
+ else if (first_eval)
+ {
+ /*
+ Constantness of args[0] may be set during JOIN::optimize(), if arg[0]
+ is a field item of "constant" table. Thus, we have to evaluate
+ seed_random() for constant arg there but not at the fix_fields method.
+ */
+ first_eval= FALSE;
+ seed_random(args[0]);
+ }
+ }
return my_rnd(rand);
}
@@ -2233,8 +2278,9 @@ void Item_func_min_max::fix_length_and_dec()
}
}
else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
- max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(max_int_part +
+ decimals, decimals,
+ unsigned_flag);
cached_field_type= agg_field_type(args, arg_count);
}
@@ -4178,6 +4224,41 @@ Item_func_set_user_var::check(bool use_result_field)
/**
+ @brief Evaluate and store item's result.
+ This function is invoked on "SELECT ... INTO @var ...".
+
+ @param item An item to get value from.
+*/
+
+void Item_func_set_user_var::save_item_result(Item *item)
+{
+ DBUG_ENTER("Item_func_set_user_var::save_item_result");
+
+ switch (cached_result_type) {
+ case REAL_RESULT:
+ save_result.vreal= item->val_result();
+ break;
+ case INT_RESULT:
+ save_result.vint= item->val_int_result();
+ unsigned_flag= item->unsigned_flag;
+ break;
+ case STRING_RESULT:
+ save_result.vstr= item->str_result(&value);
+ break;
+ case DECIMAL_RESULT:
+ save_result.vdec= item->val_decimal_result(&decimal_buff);
+ break;
+ case ROW_RESULT:
+ default:
+ // Should never happen
+ DBUG_ASSERT(0);
+ break;
+ }
+ DBUG_VOID_RETURN;
+}
+
+
+/**
This functions is invoked on
SET \@variable or \@variable:= expression.
@@ -4418,8 +4499,8 @@ int Item_func_set_user_var::save_in_field(Field *field, bool no_conversions,
update();
if (result_type() == STRING_RESULT ||
- result_type() == REAL_RESULT &&
- field->result_type() == STRING_RESULT)
+ (result_type() == REAL_RESULT &&
+ field->result_type() == STRING_RESULT))
{
String *result;
CHARSET_INFO *cs= collation.collation;
@@ -4835,10 +4916,20 @@ bool Item_func_get_system_var::is_written_to_binlog()
}
+void Item_func_get_system_var::update_null_value()
+{
+ THD *thd= current_thd;
+ int save_no_errors= thd->no_errors;
+ thd->no_errors= TRUE;
+ Item::update_null_value();
+ thd->no_errors= save_no_errors;
+}
+
+
void Item_func_get_system_var::fix_length_and_dec()
{
char *cptr;
- maybe_null=0;
+ maybe_null= TRUE;
max_length= 0;
if (var->check_type(var_type))
@@ -5747,6 +5838,14 @@ Item_func_sp::func_name() const
}
+int my_missing_function_error(const LEX_STRING &token, const char *func_name)
+{
+ if (token.length && is_lex_native_function (&token))
+ return my_error(ER_FUNC_INEXISTENT_NAME_COLLISION, MYF(0), func_name);
+ else
+ return my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", func_name);
+}
+
/**
@brief Initialize the result field by creating a temporary dummy table
@@ -5779,7 +5878,7 @@ Item_func_sp::init_result_field(THD *thd)
if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
&thd->sp_func_cache, TRUE)))
{
- my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
+ my_missing_function_error (m_name->m_name, m_name->m_qname.str);
context->process_error(thd);
DBUG_RETURN(TRUE);
}
diff --git a/sql/item_func.h b/sql/item_func.h
index d23d821baf6..514f93a39ea 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -378,7 +378,8 @@ public:
Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a)
{
decimals= dec;
- max_length= my_decimal_precision_to_length(len, dec, unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(len, dec,
+ unsigned_flag);
}
String *val_str(String *str);
double val_real();
@@ -696,14 +697,16 @@ public:
class Item_func_rand :public Item_real_func
{
struct rand_struct *rand;
+ bool first_eval; // TRUE if val_real() is called 1st time
public:
- Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
+ Item_func_rand(Item *a) :Item_real_func(a), rand(0), first_eval(TRUE) {}
Item_func_rand() :Item_real_func() {}
double val_real();
const char *func_name() const { return "rand"; }
bool const_item() const { return 0; }
void update_used_tables();
bool fix_fields(THD *thd, Item **ref);
+ void cleanup() { first_eval= TRUE; Item_real_func::cleanup(); }
private:
void seed_random (Item * val);
};
@@ -1341,6 +1344,7 @@ public:
bool send(Protocol *protocol, String *str_arg);
void make_field(Send_field *tmp_field);
bool check(bool use_result_field);
+ void save_item_result(Item *item);
bool update();
enum Item_result result_type () const { return cached_result_type; }
bool fix_fields(THD *thd, Item **ref);
@@ -1452,6 +1456,7 @@ public:
LEX_STRING *component_arg, const char *name_arg,
size_t name_len_arg);
enum Functype functype() const { return GSYSVAR_FUNC; }
+ void update_null_value();
void fix_length_and_dec();
void print(String *str, enum_query_type query_type);
bool const_item() const { return true; }
diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc
index 24a92c78e9c..a34204b7181 100644
--- a/sql/item_geofunc.cc
+++ b/sql/item_geofunc.cc
@@ -416,7 +416,10 @@ String *Item_func_spatial_collection::val_str(String *str)
else
{
enum Geometry::wkbType wkb_type;
- const char *data= res->ptr() + 4/*SRID*/ + 1;
+ const uint data_offset= 4/*SRID*/ + 1;
+ if (res->length() < data_offset + sizeof(uint32))
+ goto err;
+ const char *data= res->ptr() + data_offset;
/*
In the case of named collection we must check that items
@@ -439,7 +442,7 @@ String *Item_func_spatial_collection::val_str(String *str)
break;
case Geometry::wkb_linestring:
- if (str->append(data, POINT_DATA_SIZE, 512))
+ if (len < POINT_DATA_SIZE || str->append(data, POINT_DATA_SIZE, 512))
goto err;
break;
case Geometry::wkb_polygon:
@@ -448,11 +451,15 @@ String *Item_func_spatial_collection::val_str(String *str)
double x1, y1, x2, y2;
const char *org_data= data;
- if (len < 4 + 2 * POINT_DATA_SIZE)
+ if (len < 4)
goto err;
n_points= uint4korr(data);
data+= 4;
+
+ if (n_points < 2 || len < 4 + n_points * POINT_DATA_SIZE)
+ goto err;
+
float8get(x1, data);
data+= SIZEOF_STORED_DOUBLE;
float8get(y1, data);
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 267036e4a3d..be94f19f597 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1629,16 +1629,17 @@ String *Item_func_password::val_str(String *str)
return 0;
if (res->length() == 0)
return &my_empty_string;
- make_scrambled_password(tmp_value, res->c_ptr());
+ my_make_scrambled_password(tmp_value, res->ptr(), res->length());
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, res->charset());
return str;
}
-char *Item_func_password::alloc(THD *thd, const char *password)
+char *Item_func_password::alloc(THD *thd, const char *password,
+ size_t pass_len)
{
char *buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
if (buff)
- make_scrambled_password(buff, password);
+ my_make_scrambled_password(buff, password, pass_len);
return buff;
}
@@ -1652,16 +1653,17 @@ String *Item_func_old_password::val_str(String *str)
return 0;
if (res->length() == 0)
return &my_empty_string;
- make_scrambled_password_323(tmp_value, res->c_ptr());
+ my_make_scrambled_password_323(tmp_value, res->ptr(), res->length());
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, res->charset());
return str;
}
-char *Item_func_old_password::alloc(THD *thd, const char *password)
+char *Item_func_old_password::alloc(THD *thd, const char *password,
+ size_t pass_len)
{
char *buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
if (buff)
- make_scrambled_password_323(buff, password);
+ my_make_scrambled_password_323(buff, password, pass_len);
return buff;
}
@@ -2706,7 +2708,13 @@ String *Item_func_conv_charset::val_str(String *str)
DBUG_ASSERT(fixed == 1);
if (use_cached_value)
return null_value ? 0 : &str_value;
- String *arg= args[0]->val_str(str);
+ /*
+ Here we don't pass 'str' as a parameter to args[0]->val_str()
+ as 'str' may point to 'str_value' (e.g. see Item::save_in_field()),
+ which we use below to convert string.
+ Use argument's 'str_value' instead.
+ */
+ String *arg= args[0]->val_str(&args[0]->str_value);
uint dummy_errors;
if (!arg)
{
@@ -2943,7 +2951,7 @@ String *Item_load_file::val_str(String *str)
)
goto err;
- (void) fn_format(path, file_name->c_ptr(), mysql_real_data_home, "",
+ (void) fn_format(path, file_name->c_ptr_safe(), mysql_real_data_home, "",
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
/* Read only allowed from within dir specified by secure_file_priv */
@@ -2969,7 +2977,7 @@ String *Item_load_file::val_str(String *str)
}
if (tmp_value.alloc(stat_info.st_size))
goto err;
- if ((file = my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0)
+ if ((file = my_open(file_name->ptr(), O_RDONLY, MYF(0))) < 0)
goto err;
if (my_read(file, (uchar*) tmp_value.ptr(), stat_info.st_size, MYF(MY_NABP)))
{
@@ -3219,7 +3227,21 @@ longlong Item_func_uncompressed_length::val_int()
if (res->is_empty()) return 0;
/*
- res->ptr() using is safe because we have tested that string is not empty,
+ If length is <= 4 bytes, data is corrupt. This is the best we can do
+ to detect garbage input without decompressing it.
+ */
+ if (res->length() <= 4)
+ {
+ push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+ ER_ZLIB_Z_DATA_ERROR,
+ ER(ER_ZLIB_Z_DATA_ERROR));
+ null_value= 1;
+ return 0;
+ }
+
+ /*
+ res->ptr() using is safe because we have tested that string is at least
+ 5 bytes long.
res->c_ptr() is not used because:
- we do not need \0 terminated string to get first 4 bytes
- c_ptr() tests simbol after string end (uninitialiozed memory) which
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 5265f608344..2cdb45100ae 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -268,7 +268,7 @@ public:
String *val_str(String *str);
void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH; }
const char *func_name() const { return "password"; }
- static char *alloc(THD *thd, const char *password);
+ static char *alloc(THD *thd, const char *password, size_t pass_len);
};
@@ -287,7 +287,7 @@ public:
String *val_str(String *str);
void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; }
const char *func_name() const { return "old_password"; }
- static char *alloc(THD *thd, const char *password);
+ static char *alloc(THD *thd, const char *password, size_t pass_len);
};
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 3981b91a27c..00c09679737 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1314,8 +1314,8 @@ Item_in_subselect::row_value_transformer(JOIN *join)
Item *item_having_part2= 0;
for (uint i= 0; i < cols_num; i++)
{
- DBUG_ASSERT(left_expr->fixed &&
- select_lex->ref_pointer_array[i]->fixed ||
+ DBUG_ASSERT((left_expr->fixed &&
+ select_lex->ref_pointer_array[i]->fixed) ||
(select_lex->ref_pointer_array[i]->type() == REF_ITEM &&
((Item_ref*)(select_lex->ref_pointer_array[i]))->ref_type() ==
Item_ref::OUTER_REF));
@@ -1392,8 +1392,8 @@ Item_in_subselect::row_value_transformer(JOIN *join)
for (uint i= 0; i < cols_num; i++)
{
Item *item, *item_isnull;
- DBUG_ASSERT(left_expr->fixed &&
- select_lex->ref_pointer_array[i]->fixed ||
+ DBUG_ASSERT((left_expr->fixed &&
+ select_lex->ref_pointer_array[i]->fixed) ||
(select_lex->ref_pointer_array[i]->type() == REF_ITEM &&
((Item_ref*)(select_lex->ref_pointer_array[i]))->ref_type() ==
Item_ref::OUTER_REF));
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index a6d8bb8a52d..38251294053 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -798,8 +798,9 @@ void Item_sum_sum::fix_length_and_dec()
{
/* SUM result can't be longer than length(arg) + length(MAX_ROWS) */
int precision= args[0]->decimal_precision() + DECIMAL_LONGLONG_DIGITS;
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision,
+ decimals,
+ unsigned_flag);
curr_dec_buff= 0;
hybrid_type= DECIMAL_RESULT;
my_decimal_set_zero(dec_buffs);
@@ -1233,8 +1234,9 @@ void Item_sum_avg::fix_length_and_dec()
{
int precision= args[0]->decimal_precision() + prec_increment;
decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision,
+ decimals,
+ unsigned_flag);
f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
f_scale= args[0]->decimals;
dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
@@ -1439,8 +1441,9 @@ void Item_sum_variance::fix_length_and_dec()
{
int precision= args[0]->decimal_precision()*2 + prec_increment;
decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
- max_length= my_decimal_precision_to_length(precision, decimals,
- unsigned_flag);
+ max_length= my_decimal_precision_to_length_no_truncation(precision,
+ decimals,
+ unsigned_flag);
break;
}
@@ -2640,8 +2643,8 @@ bool Item_sum_count_distinct::setup(THD *thd)
enum enum_field_types f_type= f->type();
tree_key_length+= f->pack_length();
if ((f_type == MYSQL_TYPE_VARCHAR) ||
- !f->binary() && (f_type == MYSQL_TYPE_STRING ||
- f_type == MYSQL_TYPE_VAR_STRING))
+ (!f->binary() && (f_type == MYSQL_TYPE_STRING ||
+ f_type == MYSQL_TYPE_VAR_STRING)))
{
all_binary= FALSE;
break;
@@ -3324,8 +3327,13 @@ bool Item_func_group_concat::add()
TREE_ELEMENT *el= 0; // Only for safety
if (row_eligible && tree)
+ {
el= tree_insert(tree, table->record[0] + table->s->null_bytes, 0,
tree->custom_arg);
+ /* check if there was enough memory to insert the row */
+ if (!el)
+ return 1;
+ }
/*
If the row is not a duplicate (el->count == 1)
we can dump the row here in case of GROUP_CONCAT(DISTINCT...)
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 8caff22eab9..d79b0b02998 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -446,7 +446,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
strict_week_number= (*ptr=='V' || *ptr=='v');
tmp= (char*) val + min(val_len, 2);
if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
- strict_week_number && !week_number ||
+ (strict_week_number && !week_number) ||
week_number > 53)
goto err;
val= tmp;
@@ -542,10 +542,10 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
%V,%v require %X,%x resprectively,
%U,%u should be used with %Y and not %X or %x
*/
- if (strict_week_number &&
+ if ((strict_week_number &&
(strict_week_number_year < 0 ||
- strict_week_number_year_type != sunday_first_n_first_week_non_iso) ||
- !strict_week_number && strict_week_number_year >= 0)
+ strict_week_number_year_type != sunday_first_n_first_week_non_iso)) ||
+ (!strict_week_number && strict_week_number_year >= 0))
goto err;
/* Number of days since year 0 till 1st Jan of this year */
diff --git a/sql/log.cc b/sql/log.cc
index ed2eff6625d..8bb6ba8e9c6 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -153,7 +153,8 @@ private:
class binlog_trx_data {
public:
binlog_trx_data()
- : at_least_one_stmt(0), m_pending(0), before_stmt_pos(MY_OFF_T_UNDEF)
+ : at_least_one_stmt(0), incident(FALSE), m_pending(0),
+ before_stmt_pos(MY_OFF_T_UNDEF)
{
trans_log.end_of_file= max_binlog_cache_size;
}
@@ -184,6 +185,7 @@ public:
delete pending();
set_pending(0);
reinit_io_cache(&trans_log, WRITE_CACHE, pos, 0, 0);
+ trans_log.end_of_file= max_binlog_cache_size;
if (pos < before_stmt_pos)
before_stmt_pos= MY_OFF_T_UNDEF;
@@ -206,6 +208,7 @@ public:
if (!empty())
truncate(0);
before_stmt_pos= MY_OFF_T_UNDEF;
+ incident= FALSE;
trans_log.end_of_file= max_binlog_cache_size;
DBUG_ASSERT(empty());
}
@@ -222,11 +225,22 @@ public:
IO_CACHE trans_log; // The transaction cache
+ void set_incident(void)
+ {
+ incident= TRUE;
+ }
+
+ bool has_incident(void)
+ {
+ return(incident);
+ }
+
/**
Boolean that is true if there is at least one statement in the
transaction cache.
*/
bool at_least_one_stmt;
+ bool incident;
private:
/*
@@ -942,7 +956,7 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
bool error= FALSE;
Log_event_handler **current_handler;
bool is_command= FALSE;
- char user_host_buff[MAX_USER_HOST_SIZE];
+ char user_host_buff[MAX_USER_HOST_SIZE + 1];
Security_context *sctx= thd->security_ctx;
uint user_host_len= 0;
ulonglong query_utime, lock_utime;
@@ -1008,7 +1022,7 @@ bool LOGGER::general_log_write(THD *thd, enum enum_server_command command,
{
bool error= FALSE;
Log_event_handler **current_handler= general_log_handler_list;
- char user_host_buff[MAX_USER_HOST_SIZE];
+ char user_host_buff[MAX_USER_HOST_SIZE + 1];
Security_context *sctx= thd->security_ctx;
ulong id;
uint user_host_len= 0;
@@ -1391,7 +1405,8 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
*/
if (end_ev != NULL)
{
- thd->binlog_flush_pending_rows_event(TRUE);
+ if (thd->binlog_flush_pending_rows_event(TRUE))
+ DBUG_RETURN(1);
/*
Doing a commit or a rollback including non-transactional tables,
i.e., ending a transaction where we might write the transaction
@@ -1402,7 +1417,8 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
were, we would have to ensure that we're not ending a statement
inside a stored function.
*/
- error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev);
+ error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev,
+ trx_data->has_incident());
trx_data->reset();
/*
@@ -1428,7 +1444,11 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
*/
thd->binlog_remove_pending_rows_event(TRUE);
if (all || !(thd->options & (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT)))
+ {
+ if (trx_data->has_incident())
+ mysql_bin_log.write_incident(thd, TRUE);
trx_data->reset();
+ }
else // ...statement
trx_data->truncate(trx_data->before_stmt_pos);
@@ -1502,8 +1522,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all)
YESNO(thd->transaction.stmt.modified_non_trans_table)));
if (!in_transaction || all)
{
- Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE);
- qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
+ Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, TRUE, 0);
error= binlog_end_trans(thd, trx_data, &qev, all);
goto end;
}
@@ -1545,9 +1564,11 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
YESNO(all),
YESNO(thd->transaction.all.modified_non_trans_table),
YESNO(thd->transaction.stmt.modified_non_trans_table)));
- if (all && thd->transaction.all.modified_non_trans_table ||
- !all && thd->transaction.stmt.modified_non_trans_table ||
- (thd->options & OPTION_KEEP_LOG))
+ if ((all && thd->transaction.all.modified_non_trans_table) ||
+ (!all && thd->transaction.stmt.modified_non_trans_table &&
+ !mysql_bin_log.check_write_error(thd)) ||
+ ((thd->options & OPTION_KEEP_LOG) &&
+ !mysql_bin_log.check_write_error(thd)))
{
/*
We write the transaction cache with a rollback last if we have
@@ -1557,18 +1578,25 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
transactional table in that statement as well, which needs to be
rolled back on the slave.
*/
- Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE);
- qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
+ Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, TRUE, 0);
error= binlog_end_trans(thd, trx_data, &qev, all);
}
- else if (all && !thd->transaction.all.modified_non_trans_table ||
- !all && !thd->transaction.stmt.modified_non_trans_table)
+ else
{
/*
- If we have modified only transactional tables, we can truncate
- the transaction cache without writing anything to the binary
- log.
+ We reach this point if either only transactional tables were modified or
+ the effect of a statement that did not get into the binlog needs to be
+ rolled back. In the latter case, if a statement changed non-transactional
+ tables or had the OPTION_KEEP_LOG associated, we write an incident event
+ to the binlog in order to stop slaves and notify users that some changes
+ on the master did not get into the binlog and slaves will be inconsistent.
+ On the other hand, if a statement is transactional, we just safely roll it
+ back.
*/
+ if ((thd->transaction.stmt.modified_non_trans_table ||
+ (thd->options & OPTION_KEEP_LOG)) &&
+ mysql_bin_log.check_write_error(thd))
+ trx_data->set_incident();
error= binlog_end_trans(thd, trx_data, 0, all);
}
if (!all)
@@ -1576,6 +1604,44 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
DBUG_RETURN(error);
}
+void MYSQL_BIN_LOG::set_write_error(THD *thd)
+{
+ DBUG_ENTER("MYSQL_BIN_LOG::set_write_error");
+
+ write_error= 1;
+
+ if (check_write_error(thd))
+ DBUG_VOID_RETURN;
+
+ if (my_errno == EFBIG)
+ my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(MY_WME));
+ else
+ my_error(ER_ERROR_ON_WRITE, MYF(MY_WME), name, errno);
+
+ DBUG_VOID_RETURN;
+}
+
+bool MYSQL_BIN_LOG::check_write_error(THD *thd)
+{
+ DBUG_ENTER("MYSQL_BIN_LOG::check_write_error");
+
+ bool checked= FALSE;
+
+ if (!thd->is_error())
+ DBUG_RETURN(checked);
+
+ switch (thd->main_da.sql_errno())
+ {
+ case ER_TRANS_CACHE_FULL:
+ case ER_ERROR_ON_WRITE:
+ case ER_BINLOG_LOGGING_IMPOSSIBLE:
+ checked= TRUE;
+ break;
+ }
+
+ DBUG_RETURN(checked);
+}
+
/**
@note
How do we handle this (unlikely but legal) case:
@@ -1606,10 +1672,11 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv)
binlog_trans_log_savepos(thd, (my_off_t*) sv);
/* Write it to the binary log */
-
+
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
int const error=
thd->binlog_query(THD::STMT_QUERY_TYPE,
- thd->query, thd->query_length, TRUE, FALSE);
+ thd->query, thd->query_length, TRUE, FALSE, errcode);
DBUG_RETURN(error);
}
@@ -1625,9 +1692,10 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
if (unlikely(thd->transaction.all.modified_non_trans_table ||
(thd->options & OPTION_KEEP_LOG)))
{
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
int error=
thd->binlog_query(THD::STMT_QUERY_TYPE,
- thd->query, thd->query_length, TRUE, FALSE);
+ thd->query, thd->query_length, TRUE, FALSE, errcode);
DBUG_RETURN(error);
}
binlog_trans_log_truncate(thd, *(my_off_t*)sv);
@@ -2065,6 +2133,9 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host,
/* Test if someone closed between the is_open test and lock */
if (is_open())
{
+ /* for testing output of timestamp and thread id */
+ DBUG_EXECUTE_IF("reset_log_last_time", last_time= 0;);
+
/* Note that my_b_write() assumes it knows the length for this */
if (event_time != last_time)
{
@@ -2073,7 +2144,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host,
localtime_r(&event_time, &start);
time_buff_len= my_snprintf(local_time_buff, MAX_TIME_SIZE,
- "%02d%02d%02d %2d:%02d:%02d",
+ "%02d%02d%02d %2d:%02d:%02d\t",
start.tm_year % 100, start.tm_mon + 1,
start.tm_mday, start.tm_hour,
start.tm_min, start.tm_sec);
@@ -3851,6 +3922,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
if (pending->write(file))
{
pthread_mutex_unlock(&LOCK_log);
+ set_write_error(thd);
DBUG_RETURN(1);
}
@@ -3925,7 +3997,8 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
*/
bool const end_stmt=
thd->prelocked_mode && thd->lex->requires_prelocking();
- thd->binlog_flush_pending_rows_event(end_stmt);
+ if (thd->binlog_flush_pending_rows_event(end_stmt))
+ DBUG_RETURN(error);
pthread_mutex_lock(&LOCK_log);
@@ -3976,8 +4049,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
DBUG_PRINT("info", ("Using trans_log: cache: %d, trans_log_pos: %lu",
event_info->get_cache_stmt(),
(ulong) trans_log_pos));
- if (trans_log_pos == 0)
- thd->binlog_start_trans_and_stmt();
+ thd->binlog_start_trans_and_stmt();
file= trans_log;
}
/*
@@ -4055,7 +4127,8 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
Write the SQL command
*/
- if (event_info->write(file))
+ if (event_info->write(file) ||
+ DBUG_EVALUATE_IF("injecting_fault_writing", 1, 0))
goto err;
if (file == &log_file) // we are writing to the real log (disk)
@@ -4069,13 +4142,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
err:
if (error)
- {
- if (my_errno == EFBIG)
- my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(0));
- else
- my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno);
- write_error=1;
- }
+ set_write_error(thd);
}
if (event_info->flags & LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F)
@@ -4327,6 +4394,58 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
return 0; // All OK
}
+/*
+ Helper function to get the error code of the query to be binlogged.
+ */
+int query_error_code(THD *thd, bool not_killed)
+{
+ int error;
+
+ if (not_killed)
+ {
+ error= thd->is_error() ? thd->main_da.sql_errno() : 0;
+
+ /* thd->main_da.sql_errno() might be ER_SERVER_SHUTDOWN or
+ ER_QUERY_INTERRUPTED, So here we need to make sure that error
+ is not set to these errors when specified not_killed by the
+ caller.
+ */
+ if (error == ER_SERVER_SHUTDOWN || error == ER_QUERY_INTERRUPTED)
+ error= 0;
+ }
+ else
+ {
+ /* killed status for DELAYED INSERT thread should never be used */
+ DBUG_ASSERT(!(thd->system_thread & SYSTEM_THREAD_DELAYED_INSERT));
+ error= thd->killed_errno();
+ }
+
+ return error;
+}
+
+bool MYSQL_BIN_LOG::write_incident(THD *thd, bool lock)
+{
+ uint error= 0;
+ DBUG_ENTER("MYSQL_BIN_LOG::write_incident");
+ LEX_STRING const write_error_msg=
+ { C_STRING_WITH_LEN("error writing to the binary log") };
+ Incident incident= INCIDENT_LOST_EVENTS;
+ Incident_log_event ev(thd, incident, write_error_msg);
+ if (lock)
+ pthread_mutex_lock(&LOCK_log);
+ ev.write(&log_file);
+ if (lock)
+ {
+ if (!error && !(error= flush_and_sync()))
+ {
+ signal_update();
+ rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
+ }
+ pthread_mutex_unlock(&LOCK_log);
+ }
+ DBUG_RETURN(error);
+}
+
/**
Write a cached log entry to the binary log.
- To support transaction over replication, we wrap the transaction
@@ -4339,6 +4458,9 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
@param cache The cache to copy to the binlog
@param commit_event The commit event to print after writing the
contents of the cache.
+ @param incident Defines if an incident event should be created to
+ notify that some non-transactional changes did
+ not get into the binlog.
@note
We only come here if there is something in the cache.
@@ -4348,7 +4470,8 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
'cache' needs to be reinitialized after this functions returns.
*/
-bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
+bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event,
+ bool incident)
{
DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)");
VOID(pthread_mutex_lock(&LOCK_log));
@@ -4370,19 +4493,8 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
transaction is either a BEGIN..COMMIT block or a single
statement in autocommit mode.
*/
- Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE);
- /*
- Imagine this is rollback due to net timeout, after all
- statements of the transaction succeeded. Then we want a
- zero-error code in BEGIN. In other words, if there was a
- really serious error code it's already in the statement's
- events, there is no need to put it also in this internally
- generated event, and as this event is generated late it would
- lead to false alarms.
-
- This is safer than thd->clear_error() against kills at shutdown.
- */
- qinfo.error_code= 0;
+ Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, TRUE, 0);
+
/*
Now this Query_log_event has artificial log_pos 0. It must be
adjusted to reflect the real position in the log. Not doing it
@@ -4408,6 +4520,10 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
if (commit_event && commit_event->write(&log_file))
goto err;
+
+ if (incident && write_incident(thd, FALSE))
+ goto err;
+
if (flush_and_sync())
goto err;
DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
diff --git a/sql/log.h b/sql/log.h
index d54df8add3b..d306d6f7182 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -356,9 +356,12 @@ public:
void new_file();
bool write(Log_event* event_info); // binary log write
- bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event);
+ bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event, bool incident);
+ bool write_incident(THD *thd, bool lock);
int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync);
+ void set_write_error(THD *thd);
+ bool check_write_error(THD *thd);
void start_union_events(THD *thd, query_id_t query_id_param);
void stop_union_events(THD *thd);
@@ -581,4 +584,6 @@ enum enum_binlog_format {
};
extern TYPELIB binlog_format_typelib;
+int query_error_code(THD *thd, bool not_killed);
+
#endif /* LOG_H */
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 1a8cb8ee4fa..5f77ab3dcc4 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -369,6 +369,34 @@ int convert_handler_error(int error, THD* thd, TABLE *table)
return (actual_error);
}
+inline bool concurrency_error_code(int error)
+{
+ switch (error)
+ {
+ case ER_LOCK_WAIT_TIMEOUT:
+ case ER_LOCK_DEADLOCK:
+ case ER_XA_RBDEADLOCK:
+ return TRUE;
+ default:
+ return (FALSE);
+ }
+}
+
+inline bool unexpected_error_code(int unexpected_error)
+{
+ switch (unexpected_error)
+ {
+ case ER_NET_READ_ERROR:
+ case ER_NET_ERROR_ON_WRITE:
+ case ER_QUERY_INTERRUPTED:
+ case ER_SERVER_SHUTDOWN:
+ case ER_NEW_ABORTING_CONNECTION:
+ return(TRUE);
+ default:
+ return(FALSE);
+ }
+}
+
/*
pretty_print_str()
*/
@@ -791,8 +819,8 @@ Log_event::do_shall_skip(Relay_log_info *rli)
(ulong) server_id, (ulong) ::server_id,
rli->replicate_same_server_id,
rli->slave_skip_counter));
- if (server_id == ::server_id && !rli->replicate_same_server_id ||
- rli->slave_skip_counter == 1 && rli->is_in_group())
+ if ((server_id == ::server_id && !rli->replicate_same_server_id) ||
+ (rli->slave_skip_counter == 1 && rli->is_in_group()))
return EVENT_SKIP_IGNORE;
else if (rli->slave_skip_counter > 0)
return EVENT_SKIP_COUNT;
@@ -2316,19 +2344,16 @@ Query_log_event::Query_log_event()
query_length - size of the `query_arg' array
using_trans - there is a modified transactional table
suppress_use - suppress the generation of 'USE' statements
- killed_status_arg - an optional with default to THD::KILLED_NO_VALUE
- if the value is different from the default, the arg
- is set to the current thd->killed value.
- A caller might need to masquerade thd->killed with
- THD::NOT_KILLED.
+ errcode - the error code of the query
+
DESCRIPTION
Creates an event for binlogging
- The value for local `killed_status' can be supplied by caller.
+ The value for `errcode' should be supplied by caller.
*/
Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
ulong query_length, bool using_trans,
- bool suppress_use,
- THD::killed_state killed_status_arg)
+ bool suppress_use, int errcode)
+
:Log_event(thd_arg,
(thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F :
0) |
@@ -2349,22 +2374,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
{
time_t end_time;
- if (killed_status_arg == THD::KILLED_NO_VALUE)
- killed_status_arg= thd_arg->killed;
- error_code=
- (killed_status_arg == THD::NOT_KILLED) ?
- (thd_arg->is_error() ? thd_arg->main_da.sql_errno() : 0) :
- ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ? 0 :
- thd_arg->killed_errno());
-
- /* thd_arg->main_da.sql_errno() might be ER_SERVER_SHUTDOWN or
- ER_QUERY_INTERRUPTED, So here we need to make sure that
- error_code is not set to these errors when specified NOT_KILLED
- by the caller
- */
- if ((killed_status_arg == THD::NOT_KILLED) &&
- (error_code == ER_SERVER_SHUTDOWN || error_code == ER_QUERY_INTERRUPTED))
- error_code= 0;
+ error_code= errcode;
time(&end_time);
exec_time = (ulong) (end_time - thd_arg->start_time);
@@ -2751,7 +2761,8 @@ void Query_log_event::print_query_header(IO_CACHE* file,
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
{
- if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
+ different_db= memcmp(print_event_info->db, db, db_len + 1);
+ if (different_db)
memcpy(print_event_info->db, db, db_len + 1);
if (db[0] && different_db)
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
@@ -3008,7 +3019,10 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
::do_apply_event(), then the companion SET also have so
we don't need to reset_one_shot_variables().
*/
- if (rpl_filter->db_ok(thd->db))
+ if (!strncmp(query_arg, "BEGIN", q_len_arg) ||
+ !strncmp(query_arg, "COMMIT", q_len_arg) ||
+ !strncmp(query_arg, "ROLLBACK", q_len_arg) ||
+ rpl_filter->db_ok(thd->db))
{
thd->set_time((time_t)when);
thd->query_length= q_len_arg;
@@ -3020,7 +3034,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
DBUG_PRINT("query",("%s",thd->query));
if (ignored_error_code((expected_error= error_code)) ||
- !check_expected_error(thd,rli,expected_error))
+ !unexpected_error_code(expected_error))
{
if (flags2_inited)
/*
@@ -3152,8 +3166,8 @@ compare_errors:
actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0;
DBUG_PRINT("info",("expected_error: %d sql_errno: %d",
expected_error, actual_error));
- if ((expected_error != actual_error) &&
- expected_error &&
+ if ((expected_error && expected_error != actual_error &&
+ !concurrency_error_code(expected_error)) &&
!ignored_error_code(actual_error) &&
!ignored_error_code(expected_error))
{
@@ -3172,7 +3186,8 @@ Default database: '%s'. Query: '%s'",
/*
If we get the same error code as expected, or they should be ignored.
*/
- else if (expected_error == actual_error ||
+ else if ((expected_error == actual_error &&
+ !concurrency_error_code(expected_error)) ||
ignored_error_code(actual_error))
{
DBUG_PRINT("info",("error ignored"));
@@ -3344,8 +3359,8 @@ void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
my_b_printf(&cache," at startup");
my_b_printf(&cache, "\n");
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
- my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
- "Most probably mysqld crashed writing it.\n");
+ my_b_printf(&cache, "# Warning: this binlog is either in use or was not "
+ "closed properly.\n");
}
if (!is_artificial_event() && created)
{
@@ -4366,7 +4381,7 @@ void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
{
if (i)
my_b_printf(&cache, ",");
- my_b_printf(&cache, field);
+ my_b_printf(&cache, "%s", field);
field += field_lens[i] + 1;
}
@@ -6619,9 +6634,9 @@ Execute_load_query_log_event(THD *thd_arg, const char* query_arg,
uint fn_pos_end_arg,
enum_load_dup_handling dup_handling_arg,
bool using_trans, bool suppress_use,
- THD::killed_state killed_err_arg):
+ int errcode):
Query_log_event(thd_arg, query_arg, query_length_arg, using_trans,
- suppress_use, killed_err_arg),
+ suppress_use, errcode),
file_id(thd_arg->file_id), fn_pos_start(fn_pos_start_arg),
fn_pos_end(fn_pos_end_arg), dup_handling(dup_handling_arg)
{
@@ -6694,7 +6709,7 @@ void Execute_load_query_log_event::print(FILE* file,
{
my_b_write(&cache, (uchar*) query, fn_pos_start);
my_b_printf(&cache, " LOCAL INFILE \'");
- my_b_printf(&cache, local_fname);
+ my_b_printf(&cache, "%s", local_fname);
my_b_printf(&cache, "\'");
if (dup_handling == LOAD_DUP_REPLACE)
my_b_printf(&cache, " REPLACE");
@@ -6912,8 +6927,8 @@ Rows_log_event::Rows_log_event(THD *thd_arg, TABLE *tbl_arg, ulong tid,
solution, to be able to terminate a started statement in the
binary log: the extraneous events will be removed in the future.
*/
- DBUG_ASSERT(tbl_arg && tbl_arg->s && tid != ~0UL ||
- !tbl_arg && !cols && tid == ~0UL);
+ DBUG_ASSERT((tbl_arg && tbl_arg->s && tid != ~0UL) ||
+ (!tbl_arg && !cols && tid == ~0UL));
if (thd_arg->options & OPTION_NO_FOREIGN_KEY_CHECKS)
set_flags(NO_FOREIGN_KEY_CHECKS_F);
@@ -7105,7 +7120,7 @@ int Rows_log_event::do_add_row_data(uchar *row_data, size_t length)
#endif
DBUG_ASSERT(m_rows_buf <= m_rows_cur);
- DBUG_ASSERT(!m_rows_buf || m_rows_end && m_rows_buf < m_rows_end);
+ DBUG_ASSERT(!m_rows_buf || (m_rows_end && m_rows_buf < m_rows_end));
DBUG_ASSERT(m_rows_cur <= m_rows_end);
/* The cast will always work since m_rows_cur <= m_rows_end */
@@ -7862,10 +7877,11 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid,
/*
Now set the size of the data to the size of the field metadata array
- plus one or two bytes for number of elements in the field metadata array.
+ plus one or three bytes (see pack.c:net_store_length) for number of
+ elements in the field metadata array.
*/
if (m_field_metadata_size > 255)
- m_data_size+= m_field_metadata_size + 2;
+ m_data_size+= m_field_metadata_size + 3;
else
m_data_size+= m_field_metadata_size + 1;
@@ -9312,7 +9328,7 @@ Incident_log_event::print(FILE *file,
Write_on_release_cache cache(&print_event_info->head_cache, file);
print_header(&cache, print_event_info, FALSE);
- my_b_printf(&cache, "\n# Incident: %s", description());
+ my_b_printf(&cache, "\n# Incident: %s\nRELOAD DATABASE; # Shall generate syntax error\n", description());
}
#endif
diff --git a/sql/log_event.h b/sql/log_event.h
index bda53da8ab0..8202dddcc76 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -676,6 +676,7 @@ typedef struct st_print_event_info
#ifdef MYSQL_CLIENT
uint verbose;
table_mapping m_table_map;
+ table_mapping m_table_map_ignored;
#endif
/*
@@ -1623,8 +1624,7 @@ public:
#ifndef MYSQL_CLIENT
Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
- bool using_trans, bool suppress_use,
- THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
+ bool using_trans, bool suppress_use, int error);
const char* get_db() { return db; }
#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
@@ -2875,8 +2875,7 @@ public:
uint fn_pos_end_arg,
enum_load_dup_handling dup_handling_arg,
bool using_trans, bool suppress_use,
- THD::killed_state
- killed_err_arg= THD::KILLED_NO_VALUE);
+ int errcode);
#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
#endif /* HAVE_REPLICATION */
diff --git a/sql/my_decimal.h b/sql/my_decimal.h
index 0e79f70ab4e..21669e82c44 100644
--- a/sql/my_decimal.h
+++ b/sql/my_decimal.h
@@ -183,6 +183,19 @@ inline uint my_decimal_length_to_precision(uint length, uint scale,
(unsigned_flag || !length ? 0:1));
}
+inline uint32 my_decimal_precision_to_length_no_truncation(uint precision,
+ uint8 scale,
+ bool unsigned_flag)
+{
+ /*
+ When precision is 0 it means that original length was also 0. Thus
+ unsigned_flag is ignored in this case.
+ */
+ DBUG_ASSERT(precision || !scale);
+ return (uint32)(precision + (scale > 0 ? 1 : 0) +
+ (unsigned_flag || !precision ? 0 : 1));
+}
+
inline uint32 my_decimal_precision_to_length(uint precision, uint8 scale,
bool unsigned_flag)
{
@@ -192,8 +205,8 @@ inline uint32 my_decimal_precision_to_length(uint precision, uint8 scale,
*/
DBUG_ASSERT(precision || !scale);
set_if_smaller(precision, DECIMAL_MAX_PRECISION);
- return (uint32)(precision + (scale>0 ? 1:0) +
- (unsigned_flag || !precision ? 0:1));
+ return my_decimal_precision_to_length_no_truncation(precision, scale,
+ unsigned_flag);
}
inline
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 949fabe3928..8a7501ba108 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -82,9 +82,9 @@ extern query_id_t global_query_id;
inline query_id_t next_query_id() { return global_query_id++; }
/* useful constants */
-extern const key_map key_map_empty;
-extern key_map key_map_full; /* Should be threaded as const */
-extern const char *primary_key_name;
+extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty;
+extern MYSQL_PLUGIN_IMPORT key_map key_map_full; /* Should be threaded as const */
+extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
#include "mysql_com.h"
#include <violite.h>
@@ -123,8 +123,10 @@ char* query_table_status(THD *thd,const char *db,const char *table_name);
"in MySQL %s. Please use %s instead.", (Old), (Ver), (New)); \
} while(0)
-extern CHARSET_INFO *system_charset_info, *files_charset_info ;
-extern CHARSET_INFO *national_charset_info, *table_alias_charset;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *national_charset_info;
+extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *table_alias_charset;
enum Derivation
@@ -690,14 +692,19 @@ typedef struct st_sql_list {
}
} SQL_LIST;
-
+#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
+extern "C" THD *_current_thd_noinline();
+#define _current_thd() _current_thd_noinline()
+#else
extern pthread_key(THD*, THR_THD);
inline THD *_current_thd(void)
{
return my_pthread_getspecific_ptr(THD*,THR_THD);
}
+#endif
#define current_thd _current_thd()
+
/**
The meat of thd_proc_info(THD*, char*), a macro that packs the last
three calling-info parameters.
@@ -1415,14 +1422,14 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
/* sql_prepare.cc */
-void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length);
-void mysql_stmt_execute(THD *thd, char *packet, uint packet_length);
-void mysql_stmt_close(THD *thd, char *packet);
+void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length);
+void mysqld_stmt_execute(THD *thd, char *packet, uint packet_length);
+void mysqld_stmt_close(THD *thd, char *packet);
void mysql_sql_stmt_prepare(THD *thd);
void mysql_sql_stmt_execute(THD *thd);
void mysql_sql_stmt_close(THD *thd);
-void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length);
-void mysql_stmt_reset(THD *thd, char *packet);
+void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length);
+void mysqld_stmt_reset(THD *thd, char *packet);
void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
void reinit_stmt_before_use(THD *thd, LEX *lex);
@@ -1884,8 +1891,12 @@ extern time_t server_start_time, flush_status_time;
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
extern uint mysql_data_home_len;
-extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
- mysql_real_data_home[], mysql_unpacked_real_data_home[];
+
+extern MYSQL_PLUGIN_IMPORT char *mysql_data_home;
+extern char server_version[SERVER_VERSION_LENGTH];
+extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
+extern char mysql_unpacked_real_data_home[];
+
extern CHARSET_INFO *character_set_filesystem;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
@@ -1893,10 +1904,13 @@ extern char *opt_mysql_tmpdir, mysql_charsets_dir[],
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
extern int mysql_unpacked_real_data_home_len;
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
-extern MY_TMPDIR mysql_tmpdir_list;
+extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list;
extern const LEX_STRING command_name[];
-extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
-extern const char **errmesg; /* Error messages */
+
+extern const char *first_keyword, *delayed_user, *binary_keyword;
+extern MYSQL_PLUGIN_IMPORT const char *my_localhost;
+extern MYSQL_PLUGIN_IMPORT const char **errmesg; /* Error messages */
+
extern const char *myisam_recover_options_str;
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
extern const char * const TRG_EXT;
@@ -1910,8 +1924,8 @@ extern Le_creator le_creator;
extern char language[FN_REFLEN];
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern char reg_ext[FN_EXTLEN];
-extern uint reg_ext_length;
+extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN];
+extern MYSQL_PLUGIN_IMPORT uint reg_ext_length;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
@@ -1931,20 +1945,22 @@ extern ulong slave_open_temp_tables;
extern ulong query_cache_size, query_cache_min_res_unit;
extern ulong slow_launch_threads, slow_launch_time;
extern ulong table_cache_size, table_def_size;
-extern ulong max_connections,max_connect_errors, connect_timeout;
+extern MYSQL_PLUGIN_IMPORT ulong max_connections;
+extern ulong max_connect_errors, connect_timeout;
extern ulong slave_net_timeout, slave_trans_retries;
extern uint max_user_connections;
extern ulong what_to_log,flush_time;
extern ulong query_buff_size;
extern ulong max_prepared_stmt_count, prepared_stmt_count;
-extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
+extern ulong binlog_cache_size, open_files_limit;
+extern ulonglong max_binlog_cache_size;
extern ulong max_binlog_size, max_relay_log_size;
extern ulong opt_binlog_rows_event_max_size;
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
extern ulong back_log;
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern ulong specialflag;
+extern ulong MYSQL_PLUGIN_IMPORT specialflag;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
extern ulong current_pid;
@@ -1957,7 +1973,7 @@ extern uint protocol_version, mysqld_port, dropping_tables;
extern uint delay_key_write_options;
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern uint lower_case_table_names;
+extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
extern bool opt_endinfo, using_udf_functions;
@@ -1965,7 +1981,7 @@ extern my_bool locked_in_memory;
extern bool opt_using_transactions;
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern bool mysqld_embedded;
+extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
extern bool opt_large_files, server_id_supplied;
@@ -2003,7 +2019,7 @@ extern uint opt_large_page_size;
extern char *opt_logname, *opt_slow_logname;
extern const char *log_output_str;
-extern MYSQL_BIN_LOG mysql_bin_log;
+extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
extern LOGGER logger;
extern TABLE_LIST general_log, slow_log;
extern FILE *bootstrap_file;
@@ -2011,13 +2027,14 @@ extern int bootstrap_error;
extern FILE *stderror_file;
extern pthread_key(MEM_ROOT**,THR_MALLOC);
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
- LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
+ LOCK_mapped_file,LOCK_user_locks, LOCK_status,
LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
LOCK_global_system_variables, LOCK_user_conn,
LOCK_prepared_stmt_count,
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
+extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count;
#ifdef HAVE_OPENSSL
extern pthread_mutex_t LOCK_des_key_file;
#endif
@@ -2037,7 +2054,7 @@ extern const String my_null_string;
extern SHOW_VAR status_vars[];
#endif /* MYSQL_SERVER */
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
-extern struct system_variables global_system_variables;
+extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
extern struct system_variables max_system_variables;
@@ -2255,6 +2272,16 @@ char *fn_rext(char *name);
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
uint strconvert(CHARSET_INFO *from_cs, const char *from,
CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
+/* depends on errmsg.txt Database `db`, Table `t` ... */
+#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63
+enum enum_explain_filename_mode
+{
+ EXPLAIN_ALL_VERBOSE= 0,
+ EXPLAIN_PARTITIONS_VERBOSE,
+ EXPLAIN_PARTITIONS_AS_COMMENT
+};
+uint explain_filename(const char *from, char *to, uint to_length,
+ enum_explain_filename_mode explain_mode);
uint filename_to_tablename(const char *from, char *to, uint to_length);
uint tablename_to_filename(const char *from, char *to, uint to_length);
uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length);
@@ -2313,6 +2340,12 @@ extern void turn_parser_debug_on();
SQL_CRYPT *get_crypt_for_frm(void);
#endif
+/* password.c */
+extern "C" void my_make_scrambled_password_323(char *to, const char *password,
+ size_t pass_len);
+extern "C" void my_make_scrambled_password(char *to, const char *password,
+ size_t pass_len);
+
#include "sql_view.h"
/* Some inline functions for more speed */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 140b7d1490d..83101f6ed0e 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -519,7 +519,8 @@ ulong slave_net_timeout, slave_trans_retries;
ulong slave_exec_mode_options;
const char *slave_exec_mode_str= "STRICT";
ulong thread_cache_size=0, thread_pool_size= 0;
-ulong binlog_cache_size=0, max_binlog_cache_size=0;
+ulong binlog_cache_size=0;
+ulonglong max_binlog_cache_size=0;
ulong query_cache_size=0;
ulong refresh_version; /* Increments on each reload */
query_id_t global_query_id;
@@ -994,6 +995,7 @@ static void close_connections(void)
}
(void) pthread_mutex_unlock(&LOCK_thread_count);
+ close_active_mi();
DBUG_PRINT("quit",("close_connections thread"));
DBUG_VOID_RETURN;
}
@@ -1675,7 +1677,6 @@ static void network_init(void)
opt_enable_named_pipe)
{
- pipe_name[sizeof(pipe_name)-1]= 0; /* Safety if too long string */
strxnmov(pipe_name, sizeof(pipe_name)-1, "\\\\.\\pipe\\",
mysqld_unix_port, NullS);
bzero((char*) &saPipeSecurity, sizeof(saPipeSecurity));
@@ -4870,8 +4871,9 @@ void handle_connection_in_main_thread(THD *thd)
safe_mutex_assert_owner(&LOCK_thread_count);
thread_cache_size=0; // Safety
threads.append(thd);
- (void) pthread_mutex_unlock(&LOCK_thread_count);
- handle_one_connection((void*) thd);
+ pthread_mutex_unlock(&LOCK_thread_count);
+ thd->start_utime= my_micro_time();
+ handle_one_connection(thd);
}
@@ -4896,7 +4898,7 @@ void create_thread_to_handle_connection(THD *thd)
thread_created++;
threads.append(thd);
DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id));
- thd->connect_utime= thd->start_utime= my_micro_time();
+ thd->prior_thr_create_utime= thd->start_utime= my_micro_time();
if ((error=pthread_create(&thd->real_id,&connection_attrib,
handle_one_connection,
(void*) thd)))
@@ -6679,7 +6681,7 @@ log and this option does nothing anymore.",
{"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE,
"Can be used to restrict the total size used to cache a multi-transaction query.",
(uchar**) &max_binlog_cache_size, (uchar**) &max_binlog_cache_size, 0,
- GET_ULONG, REQUIRED_ARG, ULONG_MAX, IO_SIZE, ULONG_MAX, 0, IO_SIZE, 0},
+ GET_ULL, REQUIRED_ARG, ULONG_MAX, IO_SIZE, ULONGLONG_MAX, 0, IO_SIZE, 0},
{"max_binlog_size", OPT_MAX_BINLOG_SIZE,
"Binary log will be rotated automatically when the size exceeds this \
value. Will also apply to relay logs if max_relay_log_size is 0. \
@@ -6862,7 +6864,7 @@ The minimum value for this variable is 4096.",
(uchar**) &opt_plugin_dir_ptr, (uchar**) &opt_plugin_dir_ptr, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"plugin-load", OPT_PLUGIN_LOAD,
- "Optional colon-separated list of plugins to load, where each plugin is "
+ "Optional semicolon-separated list of plugins to load, where each plugin is "
"identified as name=library, where name is the plugin name and library "
"is the plugin library in plugin_dir.",
(uchar**) &opt_plugin_load, (uchar**) &opt_plugin_load, 0,
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 147874611ce..e3aef02637f 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -3760,8 +3760,8 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
DBUG_PRINT("info", ("index_merge scans cost %g", imerge_cost));
if (imerge_too_expensive || (imerge_cost > read_time) ||
- (non_cpk_scan_records+cpk_scan_records >= param->table->file->stats.records) &&
- read_time != DBL_MAX)
+ ((non_cpk_scan_records+cpk_scan_records >= param->table->file->stats.records) &&
+ read_time != DBL_MAX))
{
/*
Bail out if it is obvious that both index_merge and ROR-union will be
@@ -7950,7 +7950,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
goto err;
quick->records= records;
- if (cp_buffer_from_ref(thd, table, ref) && thd->is_fatal_error ||
+ if ((cp_buffer_from_ref(thd, table, ref) && thd->is_fatal_error) ||
!(range= new(alloc) QUICK_RANGE()))
goto err; // out of memory
@@ -8556,7 +8556,7 @@ int QUICK_RANGE_SELECT::get_next_prefix(uint prefix_length,
result= file->read_range_first(last_range->min_keypart_map ? &start_key : 0,
last_range->max_keypart_map ? &end_key : 0,
test(last_range->flag & EQ_RANGE),
- sorted);
+ TRUE);
if (last_range->flag == (UNIQUE_RANGE | EQ_RANGE))
last_range= 0; // Stop searching
@@ -8826,7 +8826,7 @@ int QUICK_RANGE_SELECT::cmp_prev(QUICK_RANGE *range_arg)
cmp= key_cmp(key_part_info, range_arg->min_key,
range_arg->min_length);
- if (cmp > 0 || cmp == 0 && !(range_arg->flag & NEAR_MIN))
+ if (cmp > 0 || (cmp == 0 && !(range_arg->flag & NEAR_MIN)))
return 0;
return 1; // outside of range
}
@@ -10886,8 +10886,14 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range()
/* Compare the found key with max_key. */
int cmp_res= key_cmp(index_info->key_part, max_key,
real_prefix_len + min_max_arg_len);
- if (!((cur_range->flag & NEAR_MAX) && (cmp_res == -1) ||
- (cmp_res <= 0)))
+ /*
+ The key is outside of the range if:
+ the interval is open and the key is equal to the maximum boundry
+ or
+ the key is greater than the maximum
+ */
+ if (((cur_range->flag & NEAR_MAX) && cmp_res == 0) ||
+ cmp_res > 0)
{
result= HA_ERR_KEY_NOT_FOUND;
continue;
@@ -11004,8 +11010,14 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range()
/* Compare the found key with min_key. */
int cmp_res= key_cmp(index_info->key_part, min_key,
real_prefix_len + min_max_arg_len);
- if (!((cur_range->flag & NEAR_MIN) && (cmp_res == 1) ||
- (cmp_res >= 0)))
+ /*
+ The key is outside of the range if:
+ the interval is open and the key is equal to the minimum boundry
+ or
+ the key is less than the minimum
+ */
+ if (((cur_range->flag & NEAR_MIN) && cmp_res == 0) ||
+ cmp_res < 0)
continue;
}
/* If we got to this point, the current key qualifies as MAX. */
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 3ccc1e5cf41..8e7265ba1ad 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -744,8 +744,8 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
}
else if (eq_type)
{
- if (!is_null && !cond->val_int() ||
- is_null && !test(part->field->is_null()))
+ if ((!is_null && !cond->val_int()) ||
+ (is_null && !test(part->field->is_null())))
return 0; // Impossible test
}
else if (is_field_part)
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index f2dbeba1bbf..3d65fa1de31 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -231,7 +231,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
including dir name, file name itself, and an extension,
and with unpack_filename() executed over it.
*/
- path_end= strxnmov(path, FN_REFLEN, file_name->str, NullS) - path;
+ path_end= strxnmov(path, sizeof(path) - 1, file_name->str, NullS) - path;
}
// temporary file name
@@ -314,7 +314,7 @@ my_bool rename_in_schema_file(THD *thd,
const char *schema, const char *old_name,
const char *new_db, const char *new_name)
{
- char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];
+ char old_path[FN_REFLEN + 1], new_path[FN_REFLEN + 1], arc_path[FN_REFLEN + 1];
build_table_filename(old_path, sizeof(old_path) - 1,
schema, old_name, reg_ext, 0);
diff --git a/sql/password.c b/sql/password.c
index 1ff67888ea4..9204c660b77 100644
--- a/sql/password.c
+++ b/sql/password.c
@@ -137,20 +137,39 @@ void hash_password(ulong *result, const char *password, uint password_len)
Create password to be stored in user database from raw string
Used for pre-4.1 password handling
SYNOPSIS
- make_scrambled_password_323()
+ my_make_scrambled_password_323()
to OUT store scrambled password here
password IN user-supplied password
+ pass_len IN length of password string
*/
-void make_scrambled_password_323(char *to, const char *password)
+void my_make_scrambled_password_323(char *to, const char *password,
+ size_t pass_len)
{
ulong hash_res[2];
- hash_password(hash_res, password, (uint) strlen(password));
+ hash_password(hash_res, password, (uint) pass_len);
sprintf(to, "%08lx%08lx", hash_res[0], hash_res[1]);
}
/*
+ Wrapper around my_make_scrambled_password_323() to maintain client lib ABI
+ compatibility.
+ In server code usage of my_make_scrambled_password_323() is preferred to
+ avoid strlen().
+ SYNOPSIS
+ make_scrambled_password_323()
+ to OUT store scrambled password here
+ password IN NULL-terminated string with user-supplied password
+*/
+
+void make_scrambled_password_323(char *to, const char *password)
+{
+ my_make_scrambled_password_323(to, password, strlen(password));
+}
+
+
+/*
Scramble string with password.
Used in pre 4.1 authentication phase.
SYNOPSIS
@@ -383,20 +402,21 @@ my_crypt(char *to, const uchar *s1, const uchar *s2, uint len)
The result of this function is used as return value from PASSWORD() and
is stored in the database.
SYNOPSIS
- make_scrambled_password()
+ my_make_scrambled_password()
buf OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
- password IN NULL-terminated password string
+ password IN password string
+ pass_len IN length of password string
*/
-void
-make_scrambled_password(char *to, const char *password)
+void my_make_scrambled_password(char *to, const char *password,
+ size_t pass_len)
{
SHA1_CONTEXT sha1_context;
uint8 hash_stage2[SHA1_HASH_SIZE];
mysql_sha1_reset(&sha1_context);
/* stage 1: hash password */
- mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) strlen(password));
+ mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) pass_len);
mysql_sha1_result(&sha1_context, (uint8 *) to);
/* stage 2: hash stage1 output */
mysql_sha1_reset(&sha1_context);
@@ -410,6 +430,23 @@ make_scrambled_password(char *to, const char *password)
/*
+ Wrapper around my_make_scrambled_password() to maintain client lib ABI
+ compatibility.
+ In server code usage of my_make_scrambled_password() is preferred to
+ avoid strlen().
+ SYNOPSIS
+ make_scrambled_password()
+ buf OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
+ password IN NULL-terminated password string
+*/
+
+void make_scrambled_password(char *to, const char *password)
+{
+ my_make_scrambled_password(to, password, strlen(password));
+}
+
+
+/*
Produce an obscure octet sequence from password and random
string, recieved from the server. This sequence corresponds to the
password, but password can not be easily restored from it. The sequence
diff --git a/sql/rpl_reporting.cc b/sql/rpl_reporting.cc
index 28f257790c7..a09140de3c4 100644
--- a/sql/rpl_reporting.cc
+++ b/sql/rpl_reporting.cc
@@ -13,6 +13,7 @@ Slave_reporting_capability::report(loglevel level, int err_code,
va_list args;
va_start(args, msg);
+ pthread_mutex_lock(&err_lock);
switch (level)
{
case ERROR_LEVEL:
@@ -38,6 +39,7 @@ Slave_reporting_capability::report(loglevel level, int err_code,
my_vsnprintf(pbuff, pbuffsize, msg, args);
+ pthread_mutex_unlock(&err_lock);
va_end(args);
/* If the msg string ends with '.', do not add a ',' it would be ugly */
@@ -46,3 +48,8 @@ Slave_reporting_capability::report(loglevel level, int err_code,
(pbuff[0] && *(strend(pbuff)-1) == '.') ? "" : ",",
err_code);
}
+
+Slave_reporting_capability::~Slave_reporting_capability()
+{
+ pthread_mutex_destroy(&err_lock);
+}
diff --git a/sql/rpl_reporting.h b/sql/rpl_reporting.h
index 2e3fa3cea83..ce33407e516 100644
--- a/sql/rpl_reporting.h
+++ b/sql/rpl_reporting.h
@@ -16,6 +16,8 @@
class Slave_reporting_capability
{
public:
+ /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/
+ mutable pthread_mutex_t err_lock;
/**
Constructor.
@@ -24,6 +26,7 @@ public:
Slave_reporting_capability(char const *thread_name)
: m_thread_name(thread_name)
{
+ pthread_mutex_init(&err_lock, MY_MUTEX_INIT_FAST);
}
/**
@@ -44,7 +47,9 @@ public:
STATUS</code>.
*/
void clear_error() {
+ pthread_mutex_lock(&err_lock);
m_last_error.clear();
+ pthread_mutex_unlock(&err_lock);
}
/**
@@ -72,6 +77,7 @@ public:
Error const& last_error() const { return m_last_error; }
+ virtual ~Slave_reporting_capability()= 0;
private:
/**
Last error produced by the I/O or SQL thread respectively.
@@ -79,6 +85,10 @@ private:
mutable Error m_last_error;
char const *const m_thread_name;
+
+ // not implemented
+ Slave_reporting_capability(const Slave_reporting_capability& rhs);
+ Slave_reporting_capability& operator=(const Slave_reporting_capability& rhs);
};
#endif // RPL_REPORTING_H
diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc
index e93417374fe..18fbae9bb9d 100644
--- a/sql/rpl_rli.cc
+++ b/sql/rpl_rli.cc
@@ -104,9 +104,16 @@ int init_relay_log_info(Relay_log_info* rli,
rli->tables_to_lock= 0;
rli->tables_to_lock_count= 0;
- fn_format(rli->slave_patternload_file, PREFIX_SQL_LOAD, slave_load_tmpdir, "",
- MY_PACK_FILENAME | MY_UNPACK_FILENAME |
- MY_RETURN_REAL_PATH);
+ char pattern[FN_REFLEN];
+ if (fn_format(pattern, PREFIX_SQL_LOAD, slave_load_tmpdir, "",
+ MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS)
+ {
+ pthread_mutex_unlock(&rli->data_lock);
+ sql_print_error("Unable to use slave's temporary directory %s",
+ slave_load_tmpdir);
+ DBUG_RETURN(1);
+ }
+ unpack_filename(rli->slave_patternload_file, pattern);
rli->slave_patternload_file_size= strlen(rli->slave_patternload_file);
/*
@@ -940,6 +947,7 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset,
if (count_relay_log_space(rli))
{
*errmsg= "Error counting relay log space";
+ error=1;
goto err;
}
if (!just_reset)
diff --git a/sql/set_var.cc b/sql/set_var.cc
index bc8c91342e6..0b89333ce03 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -359,8 +359,8 @@ static sys_var_const sys_lower_case_table_names(&vars,
&lower_case_table_names);
static sys_var_thd_ulong_session_readonly sys_max_allowed_packet(&vars, "max_allowed_packet",
&SV::max_allowed_packet);
-static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
- &max_binlog_cache_size);
+static sys_var_ulonglong_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
+ &max_binlog_cache_size);
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
&max_binlog_size,
fix_max_binlog_size);
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index f9b66990e93..42bca02984d 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -6076,7 +6076,7 @@ ER_SLAVE_INCIDENT
ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT
eng "Table has no partition for some existing values"
ER_BINLOG_UNSAFE_STATEMENT
- eng "Statement is not safe to log in statement format."
+ eng "Statement may not be safe to log in statement format."
swe "Detta är inte säkert att logga i statement-format."
ER_SLAVE_FATAL_ERROR
eng "Fatal error: %s"
@@ -6177,3 +6177,27 @@ ER_TOO_LONG_TABLE_COMMENT
ER_TOO_LONG_FIELD_COMMENT
eng "Comment for field '%-.64s' is too long (max = %lu)"
por "Comentário para o campo '%-.64s' é longo demais (max = %lu)"
+
+ER_FUNC_INEXISTENT_NAME_COLLISION 42000
+ eng "FUNCTION %s does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual"
+
+# When updating these, please update EXPLAIN_FILENAME_MAX_EXTRA_LENGTH in
+# mysql_priv.h with the new maximal additional length for explain_filename.
+ER_DATABASE_NAME
+ eng "Database `%s`"
+ swe "Databas `%s`"
+ER_TABLE_NAME
+ eng "Table `%s`"
+ swe "Tabell `%s`"
+ER_PARTITION_NAME
+ eng "Partition `%s`"
+ swe "Partition `%s`"
+ER_SUBPARTITION_NAME
+ eng "Subpartition `%s`"
+ swe "Subpartition `%s`"
+ER_TEMPORARY_NAME
+ eng "Temporary"
+ swe "Temporär"
+ER_RENAMED_NAME
+ eng "Renamed"
+ swe "Namnändrad"
diff --git a/sql/slave.cc b/sql/slave.cc
index 81c18c5e04b..81be7064f89 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -389,6 +389,13 @@ void init_slave_skip_errors(const char* arg)
DBUG_VOID_RETURN;
}
+static void set_thd_in_use_temporary_tables(Relay_log_info *rli)
+{
+ TABLE *table;
+
+ for (table= rli->save_temporary_tables ; table ; table= table->next)
+ table->in_use= rli->sql_thd;
+}
int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock)
{
@@ -661,7 +668,7 @@ static int end_slave_on_walk(Master_info* mi, uchar* /*unused*/)
/*
- Free all resources used by slave
+ Release slave threads at time of executing shutdown.
SYNOPSIS
end_slave()
@@ -687,15 +694,32 @@ void end_slave()
once multi-master code is ready.
*/
terminate_slave_threads(active_mi,SLAVE_FORCE_ALL);
+ }
+ pthread_mutex_unlock(&LOCK_active_mi);
+ DBUG_VOID_RETURN;
+}
+
+/**
+ Free all resources used by slave threads at time of executing shutdown.
+ The routine must be called after all possible users of @c active_mi
+ have left.
+
+ SYNOPSIS
+ close_active_mi()
+
+*/
+void close_active_mi()
+{
+ pthread_mutex_lock(&LOCK_active_mi);
+ if (active_mi)
+ {
end_master_info(active_mi);
delete active_mi;
active_mi= 0;
}
pthread_mutex_unlock(&LOCK_active_mi);
- DBUG_VOID_RETURN;
}
-
static bool io_slave_killed(THD* thd, Master_info* mi)
{
DBUG_ENTER("io_slave_killed");
@@ -803,7 +827,7 @@ int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
up to and including newline.
*/
int c;
- while (((c=my_b_get(f)) != '\n' && c != my_b_EOF));
+ while (((c=my_b_get(f)) != '\n' && c != my_b_EOF)) ;
}
DBUG_RETURN(0);
}
@@ -1486,6 +1510,8 @@ bool show_master_info(THD* thd, Master_info* mi)
pthread_mutex_lock(&mi->data_lock);
pthread_mutex_lock(&mi->rli.data_lock);
+ pthread_mutex_lock(&mi->err_lock);
+ pthread_mutex_lock(&mi->rli.err_lock);
protocol->store(mi->host, &my_charset_bin);
protocol->store(mi->user, &my_charset_bin);
protocol->store((uint32) mi->port);
@@ -1585,6 +1611,8 @@ bool show_master_info(THD* thd, Master_info* mi)
// Last_SQL_Error
protocol->store(mi->rli.last_error().message, &my_charset_bin);
+ pthread_mutex_unlock(&mi->rli.err_lock);
+ pthread_mutex_unlock(&mi->err_lock);
pthread_mutex_unlock(&mi->rli.data_lock);
pthread_mutex_unlock(&mi->data_lock);
@@ -1856,25 +1884,6 @@ static ulong read_event(MYSQL* mysql, Master_info *mi, bool* suppress_warnings)
DBUG_RETURN(len - 1);
}
-
-int check_expected_error(THD* thd, Relay_log_info const *rli,
- int expected_error)
-{
- DBUG_ENTER("check_expected_error");
-
- switch (expected_error) {
- case ER_NET_READ_ERROR:
- case ER_NET_ERROR_ON_WRITE:
- case ER_QUERY_INTERRUPTED:
- case ER_SERVER_SHUTDOWN:
- case ER_NEW_ABORTING_CONNECTION:
- DBUG_RETURN(1);
- default:
- DBUG_RETURN(0);
- }
-}
-
-
/*
Check if the current error is of temporary nature of not.
Some errors are temporary in nature, such as
@@ -2228,7 +2237,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli)
"the slave_transaction_retries variable.",
slave_trans_retries);
}
- else if (exec_res && !temp_err ||
+ else if ((exec_res && !temp_err) ||
(opt_using_transactions &&
rli->group_relay_log_pos == rli->event_relay_log_pos))
{
@@ -2390,6 +2399,7 @@ pthread_handler_t handle_slave_io(void *arg)
pthread_detach_this_thread();
thd->thread_stack= (char*) &thd; // remember where our stack is
+ mi->clear_error();
if (init_slave_thread(thd, SLAVE_THD_IO))
{
pthread_cond_broadcast(&mi->start_cond);
@@ -2504,6 +2514,7 @@ requesting master dump") ||
goto connected;
});
+ DBUG_ASSERT(mi->last_error().number == 0);
while (!io_slave_killed(thd,mi))
{
ulong event_len;
@@ -2668,14 +2679,21 @@ err:
LOAD DATA INFILE.
*/
static
-int check_temp_dir(char* tmp_dir, char *tmp_file)
+int check_temp_dir(char* tmp_file)
{
int fd;
MY_DIR *dirp;
+ char tmp_dir[FN_REFLEN];
+ size_t tmp_dir_size;
DBUG_ENTER("check_temp_dir");
/*
+ Get the directory from the temporary file.
+ */
+ dirname_part(tmp_dir, tmp_file, &tmp_dir_size);
+
+ /*
Check if the directory exists.
*/
if (!(dirp=my_dir(tmp_dir,MYF(MY_WME))))
@@ -2750,6 +2768,7 @@ pthread_handler_t handle_slave_sql(void *arg)
}
thd->init_for_queries();
thd->temporary_tables = rli->save_temporary_tables; // restore temp tables
+ set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp tables
pthread_mutex_lock(&LOCK_thread_count);
threads.append(thd);
pthread_mutex_unlock(&LOCK_thread_count);
@@ -2830,7 +2849,7 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME,
llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name,
llstr(rli->group_relay_log_pos,llbuff1));
- if (check_temp_dir(slave_load_tmpdir, rli->slave_patternload_file))
+ if (check_temp_dir(rli->slave_patternload_file))
{
rli->report(ERROR_LEVEL, thd->main_da.sql_errno(),
"Unable to use slave's temporary directory %s - %s",
@@ -2996,6 +3015,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \
DBUG_ASSERT(rli->sql_thd == thd);
THD_CHECK_SENTRY(thd);
rli->sql_thd= 0;
+ set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp tables
pthread_mutex_lock(&LOCK_thread_count);
THD_CHECK_SENTRY(thd);
delete thd;
@@ -3694,6 +3714,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
if (!slave_was_killed)
{
+ mi->clear_error(); // clear possible left over reconnect error
if (reconnect)
{
if (!suppress_warnings && global_system_variables.log_warnings)
diff --git a/sql/slave.h b/sql/slave.h
index abd63315e62..a44a7eed83e 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -171,10 +171,10 @@ bool rpl_master_has_bug(const Relay_log_info *rli, uint bug_id, bool report,
bool rpl_master_erroneous_autoinc(THD* thd);
const char *print_slave_db_safe(const char *db);
-int check_expected_error(THD* thd, Relay_log_info const *rli, int error_code);
void skip_load_data_infile(NET* net);
-void end_slave(); /* clean up */
+void end_slave(); /* release slave threads */
+void close_active_mi(); /* clean up slave threads data */
void clear_until_condition(Relay_log_info* rli);
void clear_slave_error(Relay_log_info* rli);
void end_relay_log_info(Relay_log_info* rli);
diff --git a/sql/sp.cc b/sql/sp.cc
index 8c8149d0afc..29e228f5e45 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -941,7 +941,7 @@ sp_create_routine(THD *thd, int type, sp_head *sp)
/* Such a statement can always go directly to binlog, no trans cache */
thd->binlog_query(THD::MYSQL_QUERY_TYPE,
log_query.c_ptr(), log_query.length(),
- FALSE, FALSE, THD::NOT_KILLED);
+ FALSE, FALSE, 0);
thd->variables.sql_mode= 0;
}
@@ -1308,13 +1308,20 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp,
/**
This is used by sql_acl.cc:mysql_routine_grant() and is used to find
the routines in 'routines'.
+
+ @param thd Thread handler
+ @param routines List of needles in the hay stack
+ @param any Any of the needles are good enough
+
+ @return
+ @retval FALSE Found.
+ @retval TRUE Not found
*/
-int
-sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error)
+bool
+sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any)
{
TABLE_LIST *routine;
- bool result= 0;
bool sp_object_found;
DBUG_ENTER("sp_exists_routine");
for (routine= routines; routine; routine= routine->next_global)
@@ -1336,21 +1343,16 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error)
if (sp_object_found)
{
if (any)
- DBUG_RETURN(1);
- result= 1;
+ break;
}
else if (!any)
{
- if (!no_error)
- {
- my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE",
- routine->table_name);
- DBUG_RETURN(-1);
- }
- DBUG_RETURN(0);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE",
+ routine->table_name);
+ DBUG_RETURN(TRUE);
}
}
- DBUG_RETURN(result);
+ DBUG_RETURN(FALSE);
}
diff --git a/sql/sp.h b/sql/sp.h
index 75088ea0b83..75c6856f64b 100644
--- a/sql/sp.h
+++ b/sql/sp.h
@@ -39,8 +39,8 @@ sp_head *
sp_find_routine(THD *thd, int type, sp_name *name,
sp_cache **cp, bool cache_only);
-int
-sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any, bool no_error);
+bool
+sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any);
int
sp_routine_exists_in_table(THD *thd, int type, sp_name *name);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index d6984bf5ad0..b7ad8c5c906 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -1780,8 +1780,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
thd->options= binlog_save_options;
if (thd->binlog_evt_union.unioned_events)
{
+ int errcode = query_error_code(thd, thd->killed == THD::NOT_KILLED);
Query_log_event qinfo(thd, binlog_buf.ptr(), binlog_buf.length(),
- thd->binlog_evt_union.unioned_events_trans, FALSE);
+ thd->binlog_evt_union.unioned_events_trans, FALSE, errcode);
if (mysql_bin_log.write(&qinfo) &&
thd->binlog_evt_union.unioned_events_trans)
{
diff --git a/sql/spatial.h b/sql/spatial.h
index dbf5da6665b..86c2ed8c197 100644
--- a/sql/spatial.h
+++ b/sql/spatial.h
@@ -116,12 +116,12 @@ struct MBR
int touches(const MBR *mbr)
{
/* The following should be safe, even if we compare doubles */
- return ((((mbr->xmin == xmax) || (mbr->xmax == xmin)) &&
- (((mbr->ymin >= ymin) && (mbr->ymin <= ymax)) ||
- ((mbr->ymax >= ymin) && (mbr->ymax <= ymax)))) ||
- (((mbr->ymin == ymax) || (mbr->ymax == ymin)) &&
- (((mbr->xmin >= xmin) && (mbr->xmin <= xmax)) ||
- ((mbr->xmax >= xmin) && (mbr->xmax <= xmax)))));
+ return ((mbr->xmin == xmax || mbr->xmax == xmin) &&
+ ((mbr->ymin >= ymin && mbr->ymin <= ymax) ||
+ (mbr->ymax >= ymin && mbr->ymax <= ymax))) ||
+ ((mbr->ymin == ymax || mbr->ymax == ymin) &&
+ ((mbr->xmin >= xmin && mbr->xmin <= xmax) ||
+ (mbr->xmax >= xmin && mbr->xmax <= xmax)));
}
int within(const MBR *mbr)
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index b1dbb7031ce..ab18a2d1d04 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -936,6 +936,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh,
#ifdef HAVE_OPENSSL
Vio *vio=thd->net.vio;
SSL *ssl= (SSL*) vio->ssl_arg;
+ X509 *cert;
#endif
/*
@@ -964,8 +965,11 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh,
*/
if (vio_type(vio) == VIO_TYPE_SSL &&
SSL_get_verify_result(ssl) == X509_V_OK &&
- SSL_get_peer_certificate(ssl))
+ (cert= SSL_get_peer_certificate(ssl)))
+ {
user_access= acl_user->access;
+ X509_free(cert);
+ }
break;
case SSL_TYPE_SPECIFIED: /* Client should have specified attrib */
/*
@@ -974,7 +978,6 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh,
If cipher name is specified, we compare it to actual cipher in
use.
*/
- X509 *cert;
if (vio_type(vio) != VIO_TYPE_SSL ||
SSL_get_verify_result(ssl) != X509_V_OK)
break;
@@ -1014,6 +1017,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh,
sql_print_information("X509 issuer mismatch: should be '%s' "
"but is '%s'", acl_user->x509_issuer, ptr);
free(ptr);
+ X509_free(cert);
user_access=NO_ACCESS;
break;
}
@@ -1033,12 +1037,15 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh,
sql_print_information("X509 subject mismatch: should be '%s' but is '%s'",
acl_user->x509_subject, ptr);
free(ptr);
+ X509_free(cert);
user_access=NO_ACCESS;
break;
}
user_access= acl_user->access;
free(ptr);
}
+ /* Deallocate the X509 certificate. */
+ X509_free(cert);
break;
#else /* HAVE_OPENSSL */
default:
@@ -1185,12 +1192,12 @@ static void acl_update_user(const char *user, const char *host,
for (uint i=0 ; i < acl_users.elements ; i++)
{
ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*);
- if (!acl_user->user && !user[0] ||
- acl_user->user && !strcmp(user,acl_user->user))
+ if ((!acl_user->user && !user[0]) ||
+ (acl_user->user && !strcmp(user,acl_user->user)))
{
- if (!acl_user->host.hostname && !host[0] ||
- acl_user->host.hostname &&
- !my_strcasecmp(system_charset_info, host, acl_user->host.hostname))
+ if ((!acl_user->host.hostname && !host[0]) ||
+ (acl_user->host.hostname &&
+ !my_strcasecmp(system_charset_info, host, acl_user->host.hostname)))
{
acl_user->access=privileges;
if (mqh->specified_limits & USER_RESOURCES::QUERIES_PER_HOUR)
@@ -1268,16 +1275,16 @@ static void acl_update_db(const char *user, const char *host, const char *db,
for (uint i=0 ; i < acl_dbs.elements ; i++)
{
ACL_DB *acl_db=dynamic_element(&acl_dbs,i,ACL_DB*);
- if (!acl_db->user && !user[0] ||
- acl_db->user &&
- !strcmp(user,acl_db->user))
+ if ((!acl_db->user && !user[0]) ||
+ (acl_db->user &&
+ !strcmp(user,acl_db->user)))
{
- if (!acl_db->host.hostname && !host[0] ||
- acl_db->host.hostname &&
- !strcmp(host, acl_db->host.hostname))
+ if ((!acl_db->host.hostname && !host[0]) ||
+ (acl_db->host.hostname &&
+ !strcmp(host, acl_db->host.hostname)))
{
- if (!acl_db->db && !db[0] ||
- acl_db->db && !strcmp(db,acl_db->db))
+ if ((!acl_db->db && !db[0]) ||
+ (acl_db->db && !strcmp(db,acl_db->db)))
{
if (privileges)
acl_db->access=privileges;
@@ -1486,8 +1493,8 @@ bool acl_check_host(const char *host, const char *ip)
return 0;
VOID(pthread_mutex_lock(&acl_cache->lock));
- if (host && hash_search(&acl_check_hosts,(uchar*) host,strlen(host)) ||
- ip && hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip)))
+ if ((host && hash_search(&acl_check_hosts,(uchar*) host,strlen(host))) ||
+ (ip && hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip))))
{
VOID(pthread_mutex_unlock(&acl_cache->lock));
return 0; // Found host
@@ -1648,7 +1655,7 @@ bool change_password(THD *thd, const char *host, const char *user,
new_password));
thd->clear_error();
thd->binlog_query(THD::MYSQL_QUERY_TYPE, buff, query_length,
- FALSE, FALSE, THD::NOT_KILLED);
+ FALSE, FALSE, 0);
}
end:
close_thread_tables(thd);
@@ -1704,8 +1711,8 @@ find_acl_user(const char *host, const char *user, my_bool exact)
host,
acl_user->host.hostname ? acl_user->host.hostname :
""));
- if (!acl_user->user && !user[0] ||
- acl_user->user && !strcmp(user,acl_user->user))
+ if ((!acl_user->user && !user[0]) ||
+ (acl_user->user && !strcmp(user,acl_user->user)))
{
if (exact ? !my_strcasecmp(system_charset_info, host,
acl_user->host.hostname ?
@@ -2988,8 +2995,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
if (!(rights & CREATE_ACL))
{
- char buf[FN_REFLEN];
- build_table_filename(buf, sizeof(buf), table_list->db,
+ char buf[FN_REFLEN + 1];
+ build_table_filename(buf, sizeof(buf) - 1, table_list->db,
table_list->table_name, reg_ext, 0);
fn_format(buf, buf, "", "", MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS |
MY_RETURN_REAL_PATH | MY_APPEND_EXT);
@@ -3191,26 +3198,24 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
}
-/*
+/**
Store routine level grants in the privilege tables
- SYNOPSIS
- mysql_routine_grant()
- thd Thread handle
- table_list List of routines to give grant
- is_proc true indicates routine list are procedures
- user_list List of users to give grant
- rights Table level grant
- revoke_grant Set to 1 if this is a REVOKE command
+ @param thd Thread handle
+ @param table_list List of routines to give grant
+ @param is_proc Is this a list of procedures?
+ @param user_list List of users to give grant
+ @param rights Table level grant
+ @param revoke_grant Is this is a REVOKE command?
- RETURN
- 0 ok
- 1 error
+ @return
+ @retval FALSE Success.
+ @retval TRUE An error occurred.
*/
bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
List <LEX_USER> &user_list, ulong rights,
- bool revoke_grant, bool no_error)
+ bool revoke_grant, bool write_to_binlog)
{
List_iterator <LEX_USER> str_list (user_list);
LEX_USER *Str, *tmp_Str;
@@ -3221,22 +3226,20 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
if (!initialized)
{
- if (!no_error)
- my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
- "--skip-grant-tables");
+ my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
+ "--skip-grant-tables");
DBUG_RETURN(TRUE);
}
if (rights & ~PROC_ACLS)
{
- if (!no_error)
- my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE),
- MYF(0));
+ my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE),
+ MYF(0));
DBUG_RETURN(TRUE);
}
if (!revoke_grant)
{
- if (sp_exist_routines(thd, table_list, is_proc, no_error)<0)
+ if (sp_exist_routines(thd, table_list, is_proc))
DBUG_RETURN(TRUE);
}
@@ -3317,9 +3320,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
{
if (revoke_grant)
{
- if (!no_error)
- my_error(ER_NONEXISTING_PROC_GRANT, MYF(0),
- Str->user.str, Str->host.str, table_name);
+ my_error(ER_NONEXISTING_PROC_GRANT, MYF(0),
+ Str->user.str, Str->host.str, table_name);
result= TRUE;
continue;
}
@@ -3344,16 +3346,14 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
}
thd->mem_root= old_root;
pthread_mutex_unlock(&acl_cache->lock);
- if (!result && !no_error)
+
+ if (write_to_binlog)
{
write_bin_log(thd, TRUE, thd->query, thd->query_length);
}
rw_unlock(&LOCK_grant);
- if (!result && !no_error)
- my_ok(thd);
-
/* Tables are automatically closed */
DBUG_RETURN(result);
}
@@ -5319,16 +5319,13 @@ static int handle_grant_struct(uint struct_no, bool drop,
uint elements;
const char *user;
const char *host;
- ACL_USER *acl_user;
- ACL_DB *acl_db;
- GRANT_NAME *grant_name;
+ ACL_USER *acl_user= NULL;
+ ACL_DB *acl_db= NULL;
+ GRANT_NAME *grant_name= NULL;
DBUG_ENTER("handle_grant_struct");
DBUG_PRINT("info",("scan struct: %u search: '%s'@'%s'",
struct_no, user_from->user.str, user_from->host.str));
- LINT_INIT(acl_user);
- LINT_INIT(acl_db);
- LINT_INIT(grant_name);
LINT_INIT(user);
LINT_INIT(host);
@@ -5696,6 +5693,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
List_iterator <LEX_USER> user_list(list);
TABLE_LIST tables[GRANT_TABLES];
bool some_users_deleted= FALSE;
+ ulong old_sql_mode= thd->variables.sql_mode;
DBUG_ENTER("mysql_drop_user");
/*
@@ -5709,6 +5707,8 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
if ((result= open_grant_tables(thd, tables)))
DBUG_RETURN(result != 1);
+ thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
+
rw_wrlock(&LOCK_grant);
VOID(pthread_mutex_lock(&acl_cache->lock));
@@ -5741,6 +5741,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
rw_unlock(&LOCK_grant);
close_thread_tables(thd);
+ thd->variables.sql_mode= old_sql_mode;
DBUG_RETURN(result);
}
@@ -6150,21 +6151,20 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name,
}
-/*
+/**
Grant EXECUTE,ALTER privilege for a stored procedure
- SYNOPSIS
- sp_grant_privileges()
- thd The current thread.
- db DB of the stored procedure
- name Name of the stored procedure
+ @param thd The current thread.
+ @param sp_db
+ @param sp_name
+ @param is_proc
- RETURN
- 0 OK.
- < 0 Error. Error message not yet sent.
+ @return
+ @retval FALSE Success
+ @retval TRUE An error occured. Error message not yet sent.
*/
-int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
+bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
bool is_proc)
{
Security_context *sctx= thd->security_ctx;
@@ -6174,6 +6174,7 @@ int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
bool result;
ACL_USER *au;
char passwd_buff[SCRAMBLED_PASSWORD_CHAR_LENGTH+1];
+ Dummy_error_handler error_handler;
DBUG_ENTER("sp_grant_privileges");
if (!(combo=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
@@ -6224,8 +6225,11 @@ int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
}
else
{
- my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH);
- return -1;
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_PASSWD_LENGTH,
+ ER(ER_PASSWD_LENGTH),
+ SCRAMBLED_PASSWORD_CHAR_LENGTH);
+ return TRUE;
}
combo->password.str= passwd_buff;
}
@@ -6239,10 +6243,17 @@ int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
DBUG_RETURN(TRUE);
thd->lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
+ thd->lex->ssl_cipher= thd->lex->x509_subject= thd->lex->x509_issuer= 0;
bzero((char*) &thd->lex->mqh, sizeof(thd->lex->mqh));
+ /*
+ Only care about whether the operation failed or succeeded
+ as all errors will be handled later.
+ */
+ thd->push_internal_handler(&error_handler);
result= mysql_routine_grant(thd, tables, is_proc, user_list,
- DEFAULT_CREATE_PROC_ACLS, 0, 1);
+ DEFAULT_CREATE_PROC_ACLS, FALSE, FALSE);
+ thd->pop_internal_handler();
DBUG_RETURN(result);
}
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index 9ae17a4bf02..a8090fba2e7 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -233,7 +233,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table, List <LEX_USER> &user_list,
bool revoke);
bool mysql_routine_grant(THD *thd, TABLE_LIST *table, bool is_proc,
List <LEX_USER> &user_list, ulong rights,
- bool revoke, bool no_error);
+ bool revoke, bool write_to_binlog);
my_bool grant_init();
void grant_free(void);
my_bool grant_reload(THD *thd);
@@ -264,7 +264,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant,
const char *db, const char *table);
bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name,
bool is_proc);
-int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
+bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
bool is_proc);
bool check_routine_level_acl(THD *thd, const char *db, const char *name,
bool is_proc);
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index 9ca6e0a0a2b..d273b3319ee 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -246,7 +246,7 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
}
DBUG_RETURN(0);
}
- for (str++; *(end - 1) == '0'; end--); // jump over zeros at the end
+ for (str++; *(end - 1) == '0'; end--) ; // jump over zeros at the end
if (str == end) // number was something like '123.000'
{
char *endpos= (char*) str;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0dc29f7e3c2..88e1620b152 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -473,13 +473,14 @@ static TABLE_SHARE
@todo Rework alternative ways to deal with ER_NO_SUCH TABLE.
*/
- if (share || thd->is_error() && thd->main_da.sql_errno() != ER_NO_SUCH_TABLE)
+ if (share || (thd->is_error() && thd->main_da.sql_errno() != ER_NO_SUCH_TABLE))
DBUG_RETURN(share);
/* Table didn't exist. Check if some engine can provide it */
- if ((tmp= ha_create_table_from_engine(thd, table_list->db,
- table_list->table_name)) < 0)
+ tmp= ha_create_table_from_engine(thd, table_list->db,
+ table_list->table_name);
+ if (tmp < 0)
{
/*
No such table in any engine.
@@ -1431,11 +1432,10 @@ static inline uint tmpkeyval(THD *thd, TABLE *table)
void close_temporary_tables(THD *thd)
{
TABLE *table;
- TABLE *next;
+ TABLE *next= NULL;
TABLE *prev_table;
/* Assume thd->options has OPTION_QUOTE_SHOW_CREATE */
bool was_quote_show= TRUE;
- LINT_INIT(next);
if (!thd->temporary_tables)
return;
@@ -1541,7 +1541,7 @@ void close_temporary_tables(THD *thd)
thd->variables.character_set_client= system_charset_info;
Query_log_event qinfo(thd, s_query.ptr(),
s_query.length() - 1 /* to remove trailing ',' */,
- 0, FALSE, THD::NOT_KILLED);
+ 0, FALSE, 0);
thd->variables.character_set_client= cs_save;
mysql_bin_log.write(&qinfo);
thd->variables.pseudo_thread_id= save_pseudo_thread_id;
@@ -2432,7 +2432,7 @@ bool lock_table_name_if_not_cached(THD *thd, const char *db,
bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists)
{
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
int rc;
DBUG_ENTER("check_if_table_exists");
@@ -2617,8 +2617,8 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
distance > 0 - we have lock mode higher then we require
distance == 0 - we have lock mode exactly which we need
*/
- if (best_distance < 0 && distance > best_distance ||
- distance >= 0 && distance < best_distance)
+ if ((best_distance < 0 && distance > best_distance) ||
+ (distance >= 0 && distance < best_distance))
{
best_distance= distance;
best_table= table;
@@ -2649,7 +2649,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
real fix will be made after definition cache will be made)
*/
{
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
enum legacy_db_type not_used;
build_table_filename(path, sizeof(path) - 1,
table_list->db, table_list->table_name, reg_ext, 0);
@@ -2963,6 +2963,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->insert_values= 0;
table->fulltext_searched= 0;
table->file->ft_handler= 0;
+ table->reginfo.impossible_range= 0;
/* Catch wrong handling of the auto_increment_field_not_null. */
DBUG_ASSERT(!table->auto_increment_field_not_null);
table->auto_increment_field_not_null= FALSE;
@@ -4015,9 +4016,10 @@ retry:
/* this DELETE FROM is needed even with row-based binlogging */
end = strxmov(strmov(query, "DELETE FROM `"),
share->db.str,"`.`",share->table_name.str,"`", NullS);
+ int errcode= query_error_code(thd, TRUE);
thd->binlog_query(THD::STMT_QUERY_TYPE,
query, (ulong)(end-query),
- FALSE, FALSE, THD::NOT_KILLED);
+ FALSE, FALSE, errcode);
my_free(query, MYF(0));
}
else
@@ -5585,6 +5587,13 @@ static void update_field_dependencies(THD *thd, Field *field, TABLE *table)
other_bitmap= table->read_set;
}
+ /*
+ The test-and-set mechanism in the bitmap is not reliable during
+ multi-UPDATE statements under MARK_COLUMNS_READ mode
+ (thd->mark_used_columns == MARK_COLUMNS_READ), as this bitmap contains
+ only those columns that are used in the SET clause. I.e they are being
+ set here. See multi_update::prepare()
+ */
if (bitmap_fast_test_and_set(current_bitmap, field->field_index))
{
if (thd->mark_used_columns == MARK_COLUMNS_WRITE)
@@ -6332,7 +6341,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
(report_error == REPORT_ALL_ERRORS ||
report_error == REPORT_EXCEPT_NON_UNIQUE))
{
- char buff[NAME_LEN*2+1];
+ char buff[NAME_LEN*2 + 2];
if (db && db[0])
{
strxnmov(buff,sizeof(buff)-1,db,".",table_name,NullS);
@@ -6405,8 +6414,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
(and not an item that happens to have a name).
*/
bool is_ref_by_name= 0;
- uint unaliased_counter;
- LINT_INIT(unaliased_counter); // Dependent on found_unaliased
+ uint unaliased_counter= 0;
*resolution= NOT_RESOLVED;
@@ -7431,7 +7439,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
thd->lex->current_select->cur_pos_in_select_list= 0;
while ((item= it++))
{
- if (!item->fixed && item->fix_fields(thd, it.ref()) ||
+ if ((!item->fixed && item->fix_fields(thd, it.ref())) ||
(item= *(it.ref()))->check_cols(1))
{
thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
@@ -7745,8 +7753,8 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
DBUG_ASSERT(tables->is_leaf_for_name_resolution());
- if (table_name && my_strcasecmp(table_alias_charset, table_name,
- tables->alias) ||
+ if ((table_name && my_strcasecmp(table_alias_charset, table_name,
+ tables->alias)) ||
(db_name && strcmp(tables->db,db_name)))
continue;
@@ -7777,8 +7785,8 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
information_schema table, or a nested table reference. See the comment
for TABLE_LIST.
*/
- if (!(table && !tables->view && (table->grant.privilege & SELECT_ACL) ||
- tables->view && (tables->grant.privilege & SELECT_ACL)) &&
+ if (!((table && !tables->view && (table->grant.privilege & SELECT_ACL)) ||
+ (tables->view && (tables->grant.privilege & SELECT_ACL))) &&
!any_privileges)
{
field_iterator.set(tables);
@@ -7832,7 +7840,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
*/
if (any_privileges)
{
- DBUG_ASSERT(tables->field_translation == NULL && table ||
+ DBUG_ASSERT((tables->field_translation == NULL && table) ||
tables->is_natural_join);
DBUG_ASSERT(item->type() == Item::FIELD_ITEM);
Item_field *fld= (Item_field*) item;
@@ -7971,7 +7979,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
if (*conds)
{
thd->where="where clause";
- if (!(*conds)->fixed && (*conds)->fix_fields(thd, conds) ||
+ if ((!(*conds)->fixed && (*conds)->fix_fields(thd, conds)) ||
(*conds)->check_cols(1))
goto err_no_arena;
}
@@ -7991,8 +7999,8 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
{
/* Make a join an a expression */
thd->where="on clause";
- if (!embedded->on_expr->fixed &&
- embedded->on_expr->fix_fields(thd, &embedded->on_expr) ||
+ if ((!embedded->on_expr->fixed &&
+ embedded->on_expr->fix_fields(thd, &embedded->on_expr)) ||
embedded->on_expr->check_cols(1))
goto err_no_arena;
select_lex->cond_count++;
@@ -8147,8 +8155,8 @@ fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
enum trg_event_type event)
{
return (fill_record(thd, fields, values, ignore_errors) ||
- triggers && triggers->process_triggers(thd, event,
- TRG_ACTION_BEFORE, TRUE));
+ (triggers && triggers->process_triggers(thd, event,
+ TRG_ACTION_BEFORE, TRUE)));
}
@@ -8242,8 +8250,8 @@ fill_record_n_invoke_before_triggers(THD *thd, Field **ptr,
enum trg_event_type event)
{
return (fill_record(thd, ptr, values, ignore_errors) ||
- triggers && triggers->process_triggers(thd, event,
- TRG_ACTION_BEFORE, TRUE));
+ (triggers && triggers->process_triggers(thd, event,
+ TRG_ACTION_BEFORE, TRUE)));
}
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 7c104ccc455..52de41ef1b2 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -353,11 +353,6 @@ TODO list:
#define RW_UNLOCK(M) {DBUG_PRINT("lock", ("rwlock unlock 0x%lx",(ulong)(M))); \
if (!rw_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \
else DBUG_PRINT("lock", ("rwlock unlock FAILED %d", errno)); }
-#define STRUCT_LOCK(M) {DBUG_PRINT("lock", ("%d struct lock...",__LINE__)); \
- pthread_mutex_lock(M);DBUG_PRINT("lock", ("struct lock OK"));}
-#define STRUCT_UNLOCK(M) { \
- DBUG_PRINT("lock", ("%d struct unlock...",__LINE__)); \
- pthread_mutex_unlock(M);DBUG_PRINT("lock", ("struct unlock OK"));}
#define BLOCK_LOCK_WR(B) {DBUG_PRINT("lock", ("%d LOCK_WR 0x%lx",\
__LINE__,(ulong)(B))); \
B->query()->lock_writing();}
@@ -404,8 +399,6 @@ static void debug_wait_for_kill(const char *info)
#define RW_WLOCK(M) rw_wrlock(M)
#define RW_RLOCK(M) rw_rdlock(M)
#define RW_UNLOCK(M) rw_unlock(M)
-#define STRUCT_LOCK(M) pthread_mutex_lock(M)
-#define STRUCT_UNLOCK(M) pthread_mutex_unlock(M)
#define BLOCK_LOCK_WR(B) B->query()->lock_writing()
#define BLOCK_LOCK_RD(B) B->query()->lock_reading()
#define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing()
@@ -421,6 +414,140 @@ TYPELIB query_cache_type_typelib=
/**
+ Serialize access to the query cache.
+ If the lock cannot be granted the thread hangs in a conditional wait which
+ is signalled on each unlock.
+
+ The lock attempt will also fail without wait if lock_and_suspend() is in
+ effect by another thread. This enables a quick path in execution to skip waits
+ when the outcome is known.
+
+ @return
+ @retval FALSE An exclusive lock was taken
+ @retval TRUE The locking attempt failed
+*/
+
+bool Query_cache::try_lock(void)
+{
+ bool interrupt= FALSE;
+ DBUG_ENTER("Query_cache::try_lock");
+
+ pthread_mutex_lock(&structure_guard_mutex);
+ while (1)
+ {
+ if (m_cache_lock_status == Query_cache::UNLOCKED)
+ {
+ m_cache_lock_status= Query_cache::LOCKED;
+#ifndef DBUG_OFF
+ THD *thd= current_thd;
+ if (thd)
+ m_cache_lock_thread_id= thd->thread_id;
+#endif
+ break;
+ }
+ else if (m_cache_lock_status == Query_cache::LOCKED_NO_WAIT)
+ {
+ /*
+ If query cache is protected by a LOCKED_NO_WAIT lock this thread
+ should avoid using the query cache as it is being evicted.
+ */
+ interrupt= TRUE;
+ break;
+ }
+ else
+ {
+ DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED);
+ pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
+ }
+ }
+ pthread_mutex_unlock(&structure_guard_mutex);
+
+ DBUG_RETURN(interrupt);
+}
+
+
+/**
+ Serialize access to the query cache.
+ If the lock cannot be granted the thread hangs in a conditional wait which
+ is signalled on each unlock.
+
+ This method also suspends the query cache so that other threads attempting to
+ lock the cache with try_lock() will fail directly without waiting.
+
+ It is used by all methods which flushes or destroys the whole cache.
+ */
+
+void Query_cache::lock_and_suspend(void)
+{
+ DBUG_ENTER("Query_cache::lock_and_suspend");
+
+ pthread_mutex_lock(&structure_guard_mutex);
+ while (m_cache_lock_status != Query_cache::UNLOCKED)
+ pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
+ m_cache_lock_status= Query_cache::LOCKED_NO_WAIT;
+#ifndef DBUG_OFF
+ THD *thd= current_thd;
+ if (thd)
+ m_cache_lock_thread_id= thd->thread_id;
+#endif
+ /* Wake up everybody, a whole cache flush is starting! */
+ pthread_cond_broadcast(&COND_cache_status_changed);
+ pthread_mutex_unlock(&structure_guard_mutex);
+
+ DBUG_VOID_RETURN;
+}
+
+/**
+ Serialize access to the query cache.
+ If the lock cannot be granted the thread hangs in a conditional wait which
+ is signalled on each unlock.
+
+ It is used by all methods which invalidates one or more tables.
+ */
+
+void Query_cache::lock(void)
+{
+ DBUG_ENTER("Query_cache::lock");
+
+ pthread_mutex_lock(&structure_guard_mutex);
+ while (m_cache_lock_status != Query_cache::UNLOCKED)
+ pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
+ m_cache_lock_status= Query_cache::LOCKED;
+#ifndef DBUG_OFF
+ THD *thd= current_thd;
+ if (thd)
+ m_cache_lock_thread_id= thd->thread_id;
+#endif
+ pthread_mutex_unlock(&structure_guard_mutex);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/**
+ Set the query cache to UNLOCKED and signal waiting threads.
+*/
+
+void Query_cache::unlock(void)
+{
+ DBUG_ENTER("Query_cache::unlock");
+ pthread_mutex_lock(&structure_guard_mutex);
+#ifndef DBUG_OFF
+ THD *thd= current_thd;
+ if (thd)
+ DBUG_ASSERT(m_cache_lock_thread_id == thd->thread_id);
+#endif
+ DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED ||
+ m_cache_lock_status == Query_cache::LOCKED_NO_WAIT);
+ m_cache_lock_status= Query_cache::UNLOCKED;
+ DBUG_PRINT("Query_cache",("Sending signal"));
+ pthread_cond_signal(&COND_cache_status_changed);
+ pthread_mutex_unlock(&structure_guard_mutex);
+ DBUG_VOID_RETURN;
+}
+
+
+/**
Helper function for determine if a SELECT statement has a SQL_NO_CACHE
directive.
@@ -714,14 +841,8 @@ void query_cache_insert(NET *net, const char *packet, ulong length)
DBUG_EXECUTE_IF("wait_in_query_cache_insert",
debug_wait_for_kill("wait_in_query_cache_insert"); );
- STRUCT_LOCK(&query_cache.structure_guard_mutex);
- bool interrupt;
- query_cache.wait_while_table_flush_is_in_progress(&interrupt);
- if (interrupt)
- {
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ if (query_cache.try_lock())
DBUG_VOID_RETURN;
- }
Query_cache_block *query_block= (Query_cache_block*)net->query_cache_query;
if (!query_block)
@@ -730,7 +851,7 @@ void query_cache_insert(NET *net, const char *packet, ulong length)
We lost the writer and the currently processed query has been
invalidated; there is nothing left to do.
*/
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ query_cache.unlock();
DBUG_VOID_RETURN;
}
@@ -756,7 +877,7 @@ void query_cache_insert(NET *net, const char *packet, ulong length)
query_cache.free_query(query_block);
query_cache.refused++;
// append_result_data no success => we need unlock
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ query_cache.unlock();
DBUG_VOID_RETURN;
}
@@ -778,14 +899,8 @@ void query_cache_abort(NET *net)
if (net->query_cache_query == 0)
DBUG_VOID_RETURN;
- STRUCT_LOCK(&query_cache.structure_guard_mutex);
- bool interrupt;
- query_cache.wait_while_table_flush_is_in_progress(&interrupt);
- if (interrupt)
- {
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ if (query_cache.try_lock())
DBUG_VOID_RETURN;
- }
/*
While we were waiting another thread might have changed the status
@@ -804,8 +919,7 @@ void query_cache_abort(NET *net)
DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
}
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
-
+ query_cache.unlock();
DBUG_VOID_RETURN;
}
@@ -833,15 +947,8 @@ void query_cache_end_of_result(THD *thd)
emb_count_querycache_size(thd));
#endif
- STRUCT_LOCK(&query_cache.structure_guard_mutex);
-
- bool interrupt;
- query_cache.wait_while_table_flush_is_in_progress(&interrupt);
- if (interrupt)
- {
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ if (query_cache.try_lock())
DBUG_VOID_RETURN;
- }
query_block= ((Query_cache_block*) thd->net.query_cache_query);
if (query_block)
@@ -870,10 +977,9 @@ void query_cache_end_of_result(THD *thd)
*/
DBUG_ASSERT(0);
query_cache.free_query(query_block);
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ query_cache.unlock();
DBUG_VOID_RETURN;
}
-
last_result_block= header->result()->prev;
allign_size= ALIGN_SIZE(last_result_block->used);
len= max(query_cache.min_allocation_unit, allign_size);
@@ -886,13 +992,11 @@ void query_cache_end_of_result(THD *thd)
/* Drop the writer. */
header->writer(0);
thd->net.query_cache_query= 0;
-
BLOCK_UNLOCK_WR(query_block);
DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
}
-
- STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
+ query_cache.unlock();
DBUG_VOID_RETURN;
}
@@ -952,11 +1056,7 @@ ulong Query_cache::resize(ulong query_cache_size_arg)
query_cache_size_arg));
DBUG_ASSERT(initialized);
- STRUCT_LOCK(&structure_guard_mutex);
- while (is_flushing())
- pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
- m_cache_status= Query_cache::FLUSH_IN_PROGRESS;
- STRUCT_UNLOCK(&structure_guard_mutex);
+ lock_and_suspend();
/*
Wait for all readers and writers to exit. When the list of all queries
@@ -988,13 +1088,10 @@ ulong Query_cache::resize(ulong query_cache_size_arg)
query_cache_size= query_cache_size_arg;
new_query_cache_size= init_cache();
- STRUCT_LOCK(&structure_guard_mutex);
- m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS;
- pthread_cond_signal(&COND_cache_status_changed);
if (new_query_cache_size)
DBUG_EXECUTE("check_querycache",check_integrity(1););
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_RETURN(new_query_cache_size);
}
@@ -1091,15 +1188,16 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
*/
ha_release_temporary_latches(thd);
- STRUCT_LOCK(&structure_guard_mutex);
- if (query_cache_size == 0 || is_flushing())
+ /*
+ A table- or a full flush operation can potentially take a long time to
+ finish. We choose not to wait for them and skip caching statements
+ instead.
+ */
+ if (try_lock())
+ DBUG_VOID_RETURN;
+ if (query_cache_size == 0)
{
- /*
- A table- or a full flush operation can potentially take a long time to
- finish. We choose not to wait for them and skip caching statements
- instead.
- */
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_VOID_RETURN;
}
DUMP(this);
@@ -1107,7 +1205,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
if (ask_handler_allowance(thd, tables_used))
{
refused++;
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_VOID_RETURN;
}
@@ -1155,7 +1253,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
DBUG_PRINT("qcache", ("insertion in query hash"));
header->unlock_n_destroy();
free_memory_block(query_block);
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
goto end;
}
if (!register_all_tables(query_block, tables_used, local_tables))
@@ -1165,7 +1263,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
hash_delete(&queries, (uchar *) query_block);
header->unlock_n_destroy();
free_memory_block(query_block);
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
goto end;
}
double_linked_list_simple_include(query_block, &queries_blocks);
@@ -1175,7 +1273,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
header->writer(net);
header->tables_type(tables_type);
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
// init_n_lock make query block locked
BLOCK_UNLOCK_WR(query_block);
@@ -1184,7 +1282,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
{
// We have not enough memory to store query => do nothing
refused++;
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_PRINT("warning", ("Can't allocate query"));
}
}
@@ -1192,7 +1290,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
{
// Another thread is processing the same query => do nothing
refused++;
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_PRINT("qcache", ("Another thread process same query"));
}
}
@@ -1291,18 +1389,17 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
}
}
- STRUCT_LOCK(&structure_guard_mutex);
+ /*
+ Try to obtain an exclusive lock on the query cache. If the cache is
+ disabled or if a full cache flush is in progress, the attempt to
+ get the lock is aborted.
+ */
+ if (try_lock())
+ goto err;
if (query_cache_size == 0)
goto err_unlock;
- if (is_flushing())
- {
- /* Return; Query cache is temporarily disabled while we flush. */
- DBUG_PRINT("qcache",("query cache disabled"));
- goto err_unlock;
- }
-
/*
Check that we haven't forgot to reset the query cache variables;
make sure there are no attached query cache writer to this thread.
@@ -1436,7 +1533,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
DBUG_PRINT("qcache",
("Temporary table detected: '%s.%s'",
table_list.db, table_list.alias));
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
/*
We should not store result of this query because it contain
temporary tables => assign following variable to make check
@@ -1457,7 +1554,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
DBUG_PRINT("qcache",
("probably no SELECT access to %s.%s => return to normal processing",
table_list.db, table_list.alias));
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
thd->lex->safe_to_cache_query=0; // Don't try to cache this
BLOCK_UNLOCK_RD(query_block);
DBUG_RETURN(-1); // Privilege error
@@ -1500,7 +1597,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
}
move_to_query_list_end(query_block);
hits++;
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
/*
Send cached result to client
@@ -1540,7 +1637,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
DBUG_RETURN(1); // Result sent to client
err_unlock:
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
err:
MYSQL_QUERY_CACHE_MISS(thd->query);
DBUG_RETURN(0); // Query was not cached
@@ -1662,47 +1759,6 @@ void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length,
/**
- Synchronize the thread with any flushing operations.
-
- This helper function is called whenever a thread needs to operate on the
- query cache structure (example: during invalidation). If a table flush is in
- progress this function will wait for it to stop. If a full flush is in
- progress, the function will set the interrupt parameter to indicate that the
- current operation is redundant and should be interrupted.
-
- @param[out] interrupt This out-parameter will be set to TRUE if the calling
- function is redundant and should be interrupted.
-
- @return If the interrupt-parameter is TRUE then m_cache_status is set to
- NO_FLUSH_IN_PROGRESS. If the interrupt-parameter is FALSE then
- m_cache_status is set to FLUSH_IN_PROGRESS.
- The structure_guard_mutex will in any case be locked.
-*/
-
-void Query_cache::wait_while_table_flush_is_in_progress(bool *interrupt)
-{
- while (is_flushing())
- {
- /*
- If there already is a full flush in progress query cache isn't enabled
- and additional flushes are redundant; just return instead.
- */
- if (m_cache_status == Query_cache::FLUSH_IN_PROGRESS)
- {
- *interrupt= TRUE;
- return;
- }
- /*
- If a table flush is in progress; wait on cache status to change.
- */
- if (m_cache_status == Query_cache::TABLE_FLUSH_IN_PROGRESS)
- pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
- }
- *interrupt= FALSE;
-}
-
-
-/**
Remove all cached queries that uses the given database.
*/
@@ -1711,14 +1767,11 @@ void Query_cache::invalidate(char *db)
bool restart= FALSE;
DBUG_ENTER("Query_cache::invalidate (db)");
- STRUCT_LOCK(&structure_guard_mutex);
- bool interrupt;
- wait_while_table_flush_is_in_progress(&interrupt);
- if (interrupt)
- {
- STRUCT_UNLOCK(&structure_guard_mutex);
- return;
- }
+ /*
+ Lock the query cache and queue all invalidation attempts to avoid
+ the risk of a race between invalidation, cache inserts and flushes.
+ */
+ lock();
THD *thd= current_thd;
@@ -1774,7 +1827,7 @@ void Query_cache::invalidate(char *db)
} while (restart);
} // end if( tables_blocks )
}
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_VOID_RETURN;
}
@@ -1798,7 +1851,10 @@ void Query_cache::invalidate_by_MyISAM_filename(const char *filename)
void Query_cache::flush()
{
DBUG_ENTER("Query_cache::flush");
- STRUCT_LOCK(&structure_guard_mutex);
+ DBUG_EXECUTE_IF("wait_in_query_cache_flush1",
+ debug_wait_for_kill("wait_in_query_cache_flush1"););
+
+ lock_and_suspend();
if (query_cache_size > 0)
{
DUMP(this);
@@ -1807,7 +1863,7 @@ void Query_cache::flush()
}
DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_VOID_RETURN;
}
@@ -1826,18 +1882,16 @@ void Query_cache::pack(ulong join_limit, uint iteration_limit)
{
DBUG_ENTER("Query_cache::pack");
- bool interrupt;
- STRUCT_LOCK(&structure_guard_mutex);
- wait_while_table_flush_is_in_progress(&interrupt);
- if (interrupt)
- {
- STRUCT_UNLOCK(&structure_guard_mutex);
+ /*
+ If the entire qc is being invalidated we can bail out early
+ instead of waiting for the lock.
+ */
+ if (try_lock())
DBUG_VOID_RETURN;
- }
if (query_cache_size == 0)
{
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_VOID_RETURN;
}
@@ -1847,7 +1901,7 @@ void Query_cache::pack(ulong join_limit, uint iteration_limit)
pack_cache();
} while ((++i < iteration_limit) && join_results(join_limit));
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_VOID_RETURN;
}
@@ -1862,9 +1916,9 @@ void Query_cache::destroy()
else
{
/* Underlying code expects the lock. */
- STRUCT_LOCK(&structure_guard_mutex);
+ lock_and_suspend();
free_cache();
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
pthread_cond_destroy(&COND_cache_status_changed);
pthread_mutex_destroy(&structure_guard_mutex);
@@ -1883,7 +1937,7 @@ void Query_cache::init()
DBUG_ENTER("Query_cache::init");
pthread_mutex_init(&structure_guard_mutex,MY_MUTEX_INIT_FAST);
pthread_cond_init(&COND_cache_status_changed, NULL);
- m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS;
+ m_cache_lock_status= Query_cache::UNLOCKED;
initialized = 1;
DBUG_VOID_RETURN;
}
@@ -2123,23 +2177,9 @@ void Query_cache::free_cache()
void Query_cache::flush_cache()
{
- /*
- If there is flush in progress, wait for it to finish, and then do
- our flush. This is necessary because something could be added to
- the cache before we acquire the lock again, and some code (like
- Query_cache::free_cache()) depends on the fact that after the
- flush the cache is empty.
- */
- while (is_flushing())
- pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
-
- /*
- Setting 'FLUSH_IN_PROGRESS' will prevent other threads from using
- the cache while we are in the middle of the flush, and we release
- the lock so that other threads won't block.
- */
- m_cache_status= Query_cache::FLUSH_IN_PROGRESS;
- STRUCT_UNLOCK(&structure_guard_mutex);
+
+ DBUG_EXECUTE_IF("wait_in_query_cache_flush2",
+ debug_wait_for_kill("wait_in_query_cache_flush2"););
my_hash_reset(&queries);
while (queries_blocks != 0)
@@ -2147,10 +2187,6 @@ void Query_cache::flush_cache()
BLOCK_LOCK_WR(queries_blocks);
free_query_internal(queries_blocks);
}
-
- STRUCT_LOCK(&structure_guard_mutex);
- m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS;
- pthread_cond_signal(&COND_cache_status_changed);
}
/*
@@ -2330,10 +2366,6 @@ Query_cache::write_block_data(ulong data_len, uchar* data,
}
-/*
- On success STRUCT_UNLOCK(&query_cache.structure_guard_mutex) will be done.
-*/
-
my_bool
Query_cache::append_result_data(Query_cache_block **current_block,
ulong data_len, uchar* data,
@@ -2353,10 +2385,6 @@ Query_cache::append_result_data(Query_cache_block **current_block,
if (*current_block == 0)
{
DBUG_PRINT("qcache", ("allocated first result data block %lu", data_len));
- /*
- STRUCT_UNLOCK(&structure_guard_mutex) Will be done by
- write_result_data if success;
- */
DBUG_RETURN(write_result_data(current_block, data_len, data, query_block,
Query_cache_block::RES_BEG));
}
@@ -2387,10 +2415,6 @@ Query_cache::append_result_data(Query_cache_block **current_block,
DBUG_PRINT("qcache", ("allocate new block for %lu bytes",
data_len-last_block_free_space));
Query_cache_block *new_block = 0;
- /*
- On success STRUCT_UNLOCK(&structure_guard_mutex) will be done
- by the next call
- */
success = write_result_data(&new_block, data_len-last_block_free_space,
(uchar*)(((uchar*)data)+last_block_free_space),
query_block,
@@ -2405,7 +2429,7 @@ Query_cache::append_result_data(Query_cache_block **current_block,
else
{
// It is success (nobody can prevent us write data)
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
}
// Now finally write data to the last block
@@ -2443,7 +2467,7 @@ my_bool Query_cache::write_result_data(Query_cache_block **result_block,
if (success)
{
// It is success (nobody can prevent us write data)
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
uint headers_len = (ALIGN_SIZE(sizeof(Query_cache_block)) +
ALIGN_SIZE(sizeof(Query_cache_result)));
#ifndef EMBEDDED_LIBRARY
@@ -2601,6 +2625,18 @@ void Query_cache::invalidate_table(THD *thd, TABLE *table)
void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length)
{
+#ifdef TO_BE_REMOVED
+/*
+ This ifdef'd piece comes from Summit, it's a manual backport (2008-10-15) of
+ http://lists.mysql.com/commits/56418.
+ But that was an early, non-final patch: after that backport was made, the
+ author of the patch decided to abandon it, and his final patch (put into 6.0)
+ was different.
+ Then 5.1's code was changed for some other reasons, so now we have a
+ conflict between the old patch backported to Summit and the latest 5.1.
+ The backport cannot stay, it has to be removed and then rewritten if
+ desired.
+*/
bool interrupt;
if (m_query_cache_is_disabled)
@@ -2619,28 +2655,35 @@ void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length)
STRUCT_UNLOCK(&structure_guard_mutex);
return;
}
+||||||| BASE-REVISION
+ bool interrupt;
+ STRUCT_LOCK(&structure_guard_mutex);
+ wait_while_table_flush_is_in_progress(&interrupt);
+ if (interrupt)
+ {
+ STRUCT_UNLOCK(&structure_guard_mutex);
+ return;
+ }
+=======
+/* current 5.1 code: */
+#endif
+ DBUG_EXECUTE_IF("wait_in_query_cache_invalidate1",
+ debug_wait_for_kill("wait_in_query_cache_invalidate1"); );
/*
- Setting 'TABLE_FLUSH_IN_PROGRESS' will temporarily disable the cache
- so that structural changes to cache won't block the entire server.
- However, threads requesting to change the query cache will still have
- to wait for the flush to finish.
+ Lock the query cache and queue all invalidation attempts to avoid
+ the risk of a race between invalidation, cache inserts and flushes.
*/
- m_cache_status= Query_cache::TABLE_FLUSH_IN_PROGRESS;
- STRUCT_UNLOCK(&structure_guard_mutex);
+ lock();
+
+ DBUG_EXECUTE_IF("wait_in_query_cache_invalidate2",
+ debug_wait_for_kill("wait_in_query_cache_invalidate2"); );
+
if (query_cache_size > 0)
invalidate_table_internal(thd, key, key_length);
- STRUCT_LOCK(&structure_guard_mutex);
- m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS;
-
- /*
- net_real_write might be waiting on a change on the m_cache_status
- variable.
- */
- pthread_cond_signal(&COND_cache_status_changed);
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
}
@@ -2649,7 +2692,7 @@ void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length)
The caller must ensure that no other thread is trying to work with
the query cache when this function is executed.
- @pre structure_guard_mutex is acquired or TABLE_FLUSH_IN_PROGRESS is set.
+ @pre structure_guard_mutex is acquired or LOCKED is set.
*/
void
@@ -2667,7 +2710,7 @@ Query_cache::invalidate_table_internal(THD *thd, uchar *key, uint32 key_length)
/**
Invalidate a linked list of query cache blocks.
- Each block tries to aquire a block level lock before
+ Each block tries to acquire a block level lock before
free_query is a called. This function will in turn affect
related table- and result-blocks.
@@ -4191,10 +4234,7 @@ my_bool Query_cache::check_integrity(bool locked)
DBUG_ENTER("check_integrity");
if (!locked)
- STRUCT_LOCK(&structure_guard_mutex);
-
- while (is_flushing())
- pthread_cond_wait(&COND_cache_status_changed,&structure_guard_mutex);
+ lock_and_suspend();
if (hash_check(&queries))
{
@@ -4443,7 +4483,7 @@ my_bool Query_cache::check_integrity(bool locked)
}
DBUG_ASSERT(result == 0);
if (!locked)
- STRUCT_UNLOCK(&structure_guard_mutex);
+ unlock();
DBUG_RETURN(result);
}
diff --git a/sql/sql_cache.h b/sql/sql_cache.h
index 15e97238335..a8636381956 100644
--- a/sql/sql_cache.h
+++ b/sql/sql_cache.h
@@ -272,12 +272,12 @@ public:
private:
+#ifndef DBUG_OFF
+ my_thread_id m_cache_lock_thread_id;
+#endif
pthread_cond_t COND_cache_status_changed;
-
- enum Cache_status { NO_FLUSH_IN_PROGRESS, FLUSH_IN_PROGRESS,
- TABLE_FLUSH_IN_PROGRESS };
-
- Cache_status m_cache_status;
+ enum Cache_lock_status { UNLOCKED, LOCKED_NO_WAIT, LOCKED };
+ Cache_lock_status m_cache_lock_status;
bool m_query_cache_is_disabled;
@@ -382,8 +382,6 @@ protected:
Query_cache_block *pprev);
my_bool join_results(ulong join_limit);
- void wait_while_table_flush_is_in_progress(bool *interrupt);
-
/*
Following function control structure_guard_mutex
by themself or don't need structure_guard_mutex
@@ -480,12 +478,6 @@ protected:
friend void query_cache_abort(NET *net);
bool is_disabled(void) { return m_query_cache_is_disabled; }
-
- bool is_flushing(void)
- {
- return (m_cache_status != Query_cache::NO_FLUSH_IN_PROGRESS);
- }
-
/*
The following functions are only used when debugging
We don't protect these with ifndef DBUG_OFF to not have to recompile
@@ -503,6 +495,11 @@ protected:
Query_cache_block_table * point,
const char *name);
my_bool in_blocks(Query_cache_block * point);
+
+ bool try_lock(void);
+ void lock(void);
+ void lock_and_suspend(void);
+ void unlock(void);
};
extern Query_cache query_cache;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index b73822f5a48..5933b233901 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -27,6 +27,7 @@
#include "mysql_priv.h"
#include "rpl_rli.h"
+#include "rpl_filter.h"
#include "rpl_record.h"
#include "slave.h"
#include <my_bitmap.h>
@@ -546,6 +547,7 @@ THD::THD()
first_successful_insert_id_in_prev_stmt_for_binlog(0),
first_successful_insert_id_in_cur_stmt(0),
stmt_depends_on_first_successful_insert_id_in_prev_stmt(FALSE),
+ examined_row_count(0),
global_read_lock(0),
is_fatal_error(0),
transaction_rollback_request(0),
@@ -590,7 +592,7 @@ THD::THD()
// Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0;
start_time=(time_t) 0;
- start_utime= 0L;
+ start_utime= prior_thr_create_utime= 0L;
utime_after_lock= 0L;
current_linfo = 0;
slave_thread = 0;
@@ -674,31 +676,40 @@ THD::THD()
void THD::push_internal_handler(Internal_error_handler *handler)
{
- /*
- TODO: The current implementation is limited to 1 handler at a time only.
- THD and sp_rcontext need to be modified to use a common handler stack.
- */
- DBUG_ASSERT(m_internal_handler == NULL);
- m_internal_handler= handler;
+ if (m_internal_handler)
+ {
+ handler->m_prev_internal_handler= m_internal_handler;
+ m_internal_handler= handler;
+ }
+ else
+ {
+ m_internal_handler= handler;
+ }
}
bool THD::handle_error(uint sql_errno, const char *message,
MYSQL_ERROR::enum_warning_level level)
{
- if (m_internal_handler)
+ if (!m_internal_handler)
+ return FALSE;
+
+ for (Internal_error_handler *error_handler= m_internal_handler;
+ error_handler;
+ error_handler= m_internal_handler->m_prev_internal_handler)
{
- return m_internal_handler->handle_error(sql_errno, message, level, this);
+ if (error_handler->handle_error(sql_errno, message, level, this))
+ return TRUE;
}
- return FALSE; // 'FALSE', as per coding style
+ return FALSE;
}
void THD::pop_internal_handler()
{
DBUG_ASSERT(m_internal_handler != NULL);
- m_internal_handler= NULL;
+ m_internal_handler= m_internal_handler->m_prev_internal_handler;
}
extern "C"
@@ -746,6 +757,12 @@ void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid)
*xid = *(MYSQL_XID *) &thd->transaction.xid_state.xid;
}
+#ifdef _WIN32
+extern "C" THD *_current_thd_noinline(void)
+{
+ return my_pthread_getspecific_ptr(THD*,THR_THD);
+}
+#endif
/*
Init common variables that has to be reset on start and on change_user
*/
@@ -2599,7 +2616,7 @@ bool select_dumpvar::send_data(List<Item> &items)
{
Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item);
suv->fix_fields(thd, 0);
- suv->check(0);
+ suv->save_item_result(item);
suv->update();
}
}
@@ -3649,7 +3666,7 @@ show_query_type(THD::enum_binlog_query_type qtype)
*/
int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
ulong query_len, bool is_trans, bool suppress_use,
- THD::killed_state killed_status_arg)
+ int errcode)
{
DBUG_ENTER("THD::binlog_query");
DBUG_PRINT("enter", ("qtype: %s query: '%s'",
@@ -3674,7 +3691,8 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
we should print a warning.
*/
if (sql_log_bin_toplevel && lex->is_stmt_unsafe() &&
- variables.binlog_format == BINLOG_FORMAT_STMT)
+ variables.binlog_format == BINLOG_FORMAT_STMT &&
+ binlog_filter->db_ok(this->db))
{
/*
A warning can be elevated a error when STRICT sql mode.
@@ -3716,7 +3734,7 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
*/
{
Query_log_event qinfo(this, query_arg, query_len, is_trans, suppress_use,
- killed_status_arg);
+ errcode);
qinfo.flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F;
/*
Binlog table maps will be irrelevant after a Query_log_event
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 158f4bc27d6..e7e56cf9a4b 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -91,7 +91,7 @@ enum enum_mark_columns
extern char internal_table_name[2];
extern char empty_c_string[1];
-extern const char **errmesg;
+extern MYSQL_PLUGIN_IMPORT const char **errmesg;
#define TC_LOG_PAGE_SIZE 8192
#define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE)
@@ -1036,7 +1036,10 @@ show_system_thread(enum_thread_type thread)
class Internal_error_handler
{
protected:
- Internal_error_handler() {}
+ Internal_error_handler() :
+ m_prev_internal_handler(NULL)
+ {}
+
virtual ~Internal_error_handler() {}
public:
@@ -1069,6 +1072,28 @@ public:
const char *message,
MYSQL_ERROR::enum_warning_level level,
THD *thd) = 0;
+private:
+ Internal_error_handler *m_prev_internal_handler;
+ friend class THD;
+};
+
+
+/**
+ Implements the trivial error handler which cancels all error states
+ and prevents an SQLSTATE to be set.
+*/
+
+class Dummy_error_handler : public Internal_error_handler
+{
+public:
+ bool handle_error(uint sql_errno,
+ const char *message,
+ MYSQL_ERROR::enum_warning_level level,
+ THD *thd)
+ {
+ /* Ignore error */
+ return TRUE;
+ }
};
@@ -1345,7 +1370,8 @@ public:
/* remote (peer) port */
uint16 peer_port;
time_t start_time, user_time;
- ulonglong connect_utime, thr_create_utime; // track down slow pthread_create
+ // track down slow pthread_create
+ ulonglong prior_thr_create_utime, thr_create_utime;
ulonglong start_utime, utime_after_lock;
thr_lock_type update_lock_default;
@@ -1439,6 +1465,14 @@ public:
{
changed_tables= 0;
savepoints= 0;
+ /*
+ If rm_error is raised, it means that this piece of a distributed
+ transaction has failed and must be rolled back. But the user must
+ rollback it explicitly, so don't start a new distributed XA until
+ then.
+ */
+ if (!xid_state.rm_error)
+ xid_state.xid.null();
#ifdef USING_TRANSACTIONS
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
#endif
@@ -1889,7 +1923,7 @@ public:
int binlog_query(enum_binlog_query_type qtype,
char const *query, ulong query_len,
bool is_trans, bool suppress_use,
- THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
+ int errcode);
#endif
/*
@@ -2210,6 +2244,9 @@ public:
thd_scheduler scheduler;
public:
+ inline Internal_error_handler *get_internal_handler()
+ { return m_internal_handler; }
+
/**
Add an internal error handler to the thread execution context.
@param handler the exception handler to add
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index 06528a27da5..3952567c329 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -1075,8 +1075,8 @@ static void prepare_new_connection_state(THD* thd)
pthread_handler_t handle_one_connection(void *arg)
{
THD *thd= (THD*) arg;
- ulong launch_time= (ulong) ((thd->thr_create_utime= my_micro_time()) -
- thd->connect_utime);
+
+ thd->thr_create_utime= my_micro_time();
if (thread_scheduler.init_new_connection_thread())
{
@@ -1085,8 +1085,20 @@ pthread_handler_t handle_one_connection(void *arg)
thread_scheduler.end_thread(thd,0);
return 0;
}
- if (launch_time >= slow_launch_time*1000000L)
- statistic_increment(slow_launch_threads,&LOCK_status);
+
+ /*
+ If a thread was created to handle this connection:
+ increment slow_launch_threads counter if it took more than
+ slow_launch_time seconds to create the thread.
+ */
+ if (thd->prior_thr_create_utime)
+ {
+ ulong launch_time= (ulong) (thd->thr_create_utime -
+ thd->prior_thr_create_utime);
+ if (launch_time >= slow_launch_time*1000000L)
+ statistic_increment(slow_launch_threads, &LOCK_status);
+ thd->prior_thr_create_utime= 0;
+ }
/*
handle_one_connection() is normally the only way a thread would
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 5a266c3fac9..98d17fdd318 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -181,8 +181,7 @@ uchar* dboptions_get_key(my_dbopt_t *opt, size_t *length,
static inline void write_to_binlog(THD *thd, char *query, uint q_len,
char *db, uint db_len)
{
- Query_log_event qinfo(thd, query, q_len, 0, 0, THD::NOT_KILLED);
- qinfo.error_code= 0;
+ Query_log_event qinfo(thd, query, q_len, 0, 0, 0);
qinfo.db= db;
qinfo.db_len= db_len;
mysql_bin_log.write(&qinfo);
@@ -538,13 +537,13 @@ err1:
bool load_db_opt_by_name(THD *thd, const char *db_name,
HA_CREATE_INFO *db_create_info)
{
- char db_opt_path[FN_REFLEN];
+ char db_opt_path[FN_REFLEN + 1];
/*
Pass an empty file name, and the database options file name as extension
to avoid table name to file name encoding.
*/
- (void) build_table_filename(db_opt_path, sizeof(db_opt_path),
+ (void) build_table_filename(db_opt_path, sizeof(db_opt_path) - 1,
db_name, "", MY_DB_OPT_FILE, 0);
return load_db_opt(thd, db_opt_path, db_create_info);
@@ -646,7 +645,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
/* Check directory */
- path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
+ path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
path[path_len-1]= 0; // Remove last '/' from path
if (my_stat(path,&stat_info,MYF(0)))
@@ -723,8 +722,9 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
if (mysql_bin_log.is_open())
{
+ int errcode= query_error_code(thd, TRUE);
Query_log_event qinfo(thd, query, query_length, 0,
- /* suppress_use */ TRUE, THD::NOT_KILLED);
+ /* suppress_use */ TRUE, errcode);
/*
Write should use the database being created as the "current
@@ -791,7 +791,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
We pass MY_DB_OPT_FILE as "extension" to avoid
"table name to file name" encoding.
*/
- build_table_filename(path, sizeof(path), db, "", MY_DB_OPT_FILE, 0);
+ build_table_filename(path, sizeof(path) - 1, db, "", MY_DB_OPT_FILE, 0);
if ((error=write_db_opt(thd, path, create_info)))
goto exit;
@@ -811,8 +811,9 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
if (mysql_bin_log.is_open())
{
+ int errcode= query_error_code(thd, TRUE);
Query_log_event qinfo(thd, thd->query, thd->query_length, 0,
- /* suppress_use */ TRUE, THD::NOT_KILLED);
+ /* suppress_use */ TRUE, errcode);
/*
Write should use the database being created as the "current
@@ -883,7 +884,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
- length= build_table_filename(path, sizeof(path), db, "", "", 0);
+ length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
strmov(path+length, MY_DB_OPT_FILE); // Append db option file name
del_dbopt(path); // Remove dboption hash entry
path[length]= '\0'; // Remove file name
@@ -958,8 +959,9 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
}
if (mysql_bin_log.is_open())
{
+ int errcode= query_error_code(thd, TRUE);
Query_log_event qinfo(thd, query, query_length, 0,
- /* suppress_use */ TRUE, THD::NOT_KILLED);
+ /* suppress_use */ TRUE, errcode);
/*
Write should use the database being created as the "current
database" and not the threads current database, which is the
@@ -1839,7 +1841,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
for (uint idx=0 ; idx < nfiles && !thd->killed ; idx++)
{
FILEINFO *file= dirp->dir_entry + idx;
- char *extension, tname[FN_REFLEN];
+ char *extension, tname[FN_REFLEN + 1];
LEX_STRING table_str;
DBUG_PRINT("info",("Examining: %s", file->name));
@@ -1928,7 +1930,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
for (uint idx=0 ; idx < nfiles ; idx++)
{
FILEINFO *file= dirp->dir_entry + idx;
- char oldname[FN_REFLEN], newname[FN_REFLEN];
+ char oldname[FN_REFLEN + 1], newname[FN_REFLEN + 1];
DBUG_PRINT("info",("Examining: %s", file->name));
/* skiping . and .. and MY_DB_OPT_FILE */
@@ -1958,8 +1960,9 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
/* Step8: logging */
if (mysql_bin_log.is_open())
{
+ int errcode= query_error_code(thd, TRUE);
Query_log_event qinfo(thd, thd->query, thd->query_length,
- 0, TRUE, THD::NOT_KILLED);
+ 0, TRUE, errcode);
thd->clear_error();
mysql_bin_log.write(&qinfo);
}
@@ -1997,10 +2000,10 @@ exit:
bool check_db_dir_existence(const char *db_name)
{
- char db_dir_path[FN_REFLEN];
+ char db_dir_path[FN_REFLEN + 1];
uint db_dir_path_len;
- db_dir_path_len= build_table_filename(db_dir_path, sizeof(db_dir_path),
+ db_dir_path_len= build_table_filename(db_dir_path, sizeof(db_dir_path) - 1,
db_name, "", "", 0);
if (db_dir_path_len && db_dir_path[db_dir_path_len - 1] == FN_LIBCHAR)
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1b42e522491..677098d275a 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -389,8 +389,12 @@ cleanup:
FALSE :
transactional_table;
+ int errcode= 0;
if (error < 0)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
+
/*
[binlog]: If 'handler::delete_all_rows()' was called and the
storage engine does not inject the rows itself, we replicate
@@ -402,9 +406,9 @@ cleanup:
*/
int log_result= thd->binlog_query(query_type,
thd->query, thd->query_length,
- is_trans, FALSE, killed_status);
+ is_trans, FALSE, errcode);
- if (log_result && transactional_table)
+ if (log_result)
{
error=1;
}
@@ -582,6 +586,11 @@ int mysql_multi_delete_prepare(THD *thd)
}
}
}
+ /*
+ Reset the exclude flag to false so it doesn't interfare
+ with further calls to unique_table
+ */
+ lex->select_lex.exclude_from_table_unique_test= FALSE;
DBUG_RETURN(FALSE);
}
@@ -617,11 +626,24 @@ multi_delete::initialize_tables(JOIN *join)
DBUG_RETURN(1);
table_map tables_to_delete_from=0;
+ delete_while_scanning= 1;
for (walk= delete_tables; walk; walk= walk->next_local)
+ {
tables_to_delete_from|= walk->table->map;
+ if (delete_while_scanning &&
+ unique_table(thd, walk, join->tables_list, false))
+ {
+ /*
+ If the table we are going to delete from appears
+ in join, we need to defer delete. So the delete
+ doesn't interfers with the scaning of results.
+ */
+ delete_while_scanning= 0;
+ }
+ }
+
walk= delete_tables;
- delete_while_scanning= 1;
for (JOIN_TAB *tab=join->join_tab, *end=join->join_tab+join->tables;
tab < end;
tab++)
@@ -784,7 +806,7 @@ void multi_delete::abort()
/* the error was handled or nothing deleted and no side effects return */
if (error_handled ||
- !thd->transaction.stmt.modified_non_trans_table && !deleted)
+ (!thd->transaction.stmt.modified_non_trans_table && !deleted))
DBUG_VOID_RETURN;
/* Something already deleted so we have to invalidate cache */
@@ -818,9 +840,10 @@ void multi_delete::abort()
*/
if (mysql_bin_log.is_open())
{
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- transactional_tables, FALSE);
+ transactional_tables, FALSE, errcode);
}
thd->transaction.all.modified_non_trans_table= true;
}
@@ -961,11 +984,14 @@ bool multi_delete::send_eof()
{
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (local_error == 0)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- transactional_tables, FALSE, killed_status) &&
+ transactional_tables, FALSE, errcode) &&
!normal_tables)
{
local_error=1; // Log write failed: roll back the SQL statement
@@ -1025,7 +1051,7 @@ static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list)
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
{
HA_CREATE_INFO create_info;
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
TABLE *table;
bool error;
uint path_length;
@@ -1062,7 +1088,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
goto end;
}
- path_length= build_table_filename(path, sizeof(path), table_list->db,
+ path_length= build_table_filename(path, sizeof(path) - 1, table_list->db,
table_list->table_name, reg_ext, 0);
if (!dont_send_ok)
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 41be98621a6..37adf5c403a 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -179,6 +179,7 @@ exit:
{
if (thd->is_error() &&
(thd->main_da.sql_errno() == ER_BAD_FIELD_ERROR ||
+ thd->main_da.sql_errno() == ER_FUNC_INEXISTENT_NAME_COLLISION ||
thd->main_da.sql_errno() == ER_SP_DOES_NOT_EXIST))
{
thd->clear_error();
diff --git a/sql/sql_help.cc b/sql/sql_help.cc
index f51ad318568..2818aa5082c 100644
--- a/sql/sql_help.cc
+++ b/sql/sql_help.cc
@@ -526,7 +526,7 @@ int send_variant_2_list(MEM_ROOT *mem_root, Protocol *protocol,
String **end= pointers + names->elements;
List_iterator<String> it(*names);
- for (pos= pointers; pos!=end; (*pos++= it++));
+ for (pos= pointers; pos!=end; (*pos++= it++)) ;
my_qsort(pointers,names->elements,sizeof(String*),string_ptr_cmp);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 9eef9d224e6..77b83b0e6fe 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -301,9 +301,7 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
List<Item> &update_fields, table_map *map)
{
TABLE *table= insert_table_list->table;
- my_bool timestamp_mark;
-
- LINT_INIT(timestamp_mark);
+ my_bool timestamp_mark= 0;
if (table->timestamp_field)
{
@@ -393,7 +391,7 @@ void upgrade_lock_type(THD *thd, thr_lock_type *lock_type,
bool is_multi_insert)
{
if (duplic == DUP_UPDATE ||
- duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT)
+ (duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT))
{
*lock_type= TL_WRITE_DEFAULT;
return;
@@ -858,11 +856,13 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
*/
query_cache_invalidate3(thd, table_list, 1);
}
- if (changed && error <= 0 || thd->transaction.stmt.modified_non_trans_table
- || was_insert_delayed)
+ if ((changed && error <= 0) ||
+ thd->transaction.stmt.modified_non_trans_table ||
+ was_insert_delayed)
{
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (error <= 0)
{
/*
@@ -877,6 +877,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
/* todo: consider removing */
thd->clear_error();
}
+ else
+ errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
+
/* bug#22725:
A query which per-row-loop can not be interrupted with
@@ -893,8 +896,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
transactional_table, FALSE,
- (error>0) ? thd->killed : THD::NOT_KILLED) &&
- transactional_table)
+ errcode))
{
error=1;
}
@@ -1114,6 +1116,33 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
/*
+ Get extra info for tables we insert into
+
+ @param table table(TABLE object) we insert into,
+ might be NULL in case of view
+ @param table(TABLE_LIST object) or view we insert into
+*/
+
+static void prepare_for_positional_update(TABLE *table, TABLE_LIST *tables)
+{
+ if (table)
+ {
+ if(table->reginfo.lock_type != TL_WRITE_DELAYED)
+ table->prepare_for_position();
+ return;
+ }
+
+ DBUG_ASSERT(tables->view);
+ List_iterator<TABLE_LIST> it(*tables->view_tables);
+ TABLE_LIST *tbl;
+ while ((tbl= it++))
+ prepare_for_positional_update(tbl->table, tbl);
+
+ return;
+}
+
+
+/*
Prepare items in INSERT statement
SYNOPSIS
@@ -1262,9 +1291,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
Only call prepare_for_posistion() if we are not performing a DELAYED
operation. It will instead be executed by delayed insert thread.
*/
- if ((duplic == DUP_UPDATE || duplic == DUP_REPLACE) &&
- (table->reginfo.lock_type != TL_WRITE_DELAYED))
- table->prepare_for_position();
+ if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
+ prepare_for_positional_update(table, table_list);
DBUG_RETURN(FALSE);
}
@@ -2667,6 +2695,12 @@ bool Delayed_insert::handle_inserts(void)
thd.variables.time_zone = row->time_zone;
}
+ /* if the delayed insert was killed, the killed status is
+ ignored while binlogging */
+ int errcode= 0;
+ if (thd.killed == THD::NOT_KILLED)
+ errcode= query_error_code(&thd, TRUE);
+
/*
If the query has several rows to insert, only the first row will come
here. In row-based binlogging, this means that the first row will be
@@ -2677,7 +2711,7 @@ bool Delayed_insert::handle_inserts(void)
*/
thd.binlog_query(THD::ROW_QUERY_TYPE,
row->query.str, row->query.length,
- FALSE, FALSE);
+ FALSE, FALSE, errcode);
thd.time_zone_used = backup_time_zone_used;
thd.variables.time_zone = backup_time_zone;
@@ -3090,7 +3124,10 @@ bool select_insert::send_data(List<Item> &values)
store_values(values);
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
if (thd->is_error())
+ {
+ table->auto_increment_field_not_null= FALSE;
DBUG_RETURN(1);
+ }
if (table_list) // Not CREATE ... SELECT
{
switch (table_list->view_check_option(thd, info.ignore)) {
@@ -3104,6 +3141,9 @@ bool select_insert::send_data(List<Item> &values)
// Release latches in case bulk insert takes a long time
ha_release_temporary_latches(thd);
+ // Release latches in case bulk insert takes a long time
+ ha_release_temporary_latches(thd);
+
error= write_record(thd, table, &info);
table->auto_increment_field_not_null= FALSE;
@@ -3176,7 +3216,8 @@ bool select_insert::send_eof()
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
- if (changed= (info.copied || info.deleted || info.updated))
+ changed= (info.copied || info.deleted || info.updated);
+ if (changed)
{
/*
We must invalidate the table in the query cache before binlog writing
@@ -3197,11 +3238,14 @@ bool select_insert::send_eof()
*/
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (!error)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- trans_table, FALSE, killed_status);
+ trans_table, FALSE, errcode);
}
table->file->ha_release_auto_increment();
@@ -3268,8 +3312,11 @@ void select_insert::abort() {
if (thd->transaction.stmt.modified_non_trans_table)
{
if (mysql_bin_log.is_open())
+ {
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length,
- transactional_table, FALSE);
+ transactional_table, FALSE, errcode);
+ }
if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
thd->transaction.all.modified_non_trans_table= TRUE;
if (changed)
@@ -3661,10 +3708,14 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
DBUG_ASSERT(result == 0); /* store_create_info() always return 0 */
if (mysql_bin_log.is_open())
+ {
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::STMT_QUERY_TYPE,
query.ptr(), query.length(),
/* is_trans */ TRUE,
- /* suppress_use */ FALSE);
+ /* suppress_use */ FALSE,
+ errcode);
+ }
}
void select_create::store_values(List<Item> &values)
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index b96ac91679b..444a8ae0736 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -433,6 +433,16 @@ bool is_keyword(const char *name, uint len)
return get_hash_symbol(name,len,0)!=0;
}
+/**
+ Check if name is a sql function
+
+ @param name checked name
+
+ @return is this a native function or not
+ @retval 0 name is a function
+ @retval 1 name isn't a function
+*/
+
bool is_lex_native_function(const LEX_STRING *name)
{
DBUG_ASSERT(name != NULL);
@@ -770,7 +780,7 @@ bool consume_comment(Lex_input_stream *lip, int remaining_recursions_permitted)
int MYSQLlex(void *arg, void *yythd)
{
- reg1 uchar c;
+ reg1 uchar c= 0;
bool comment_closed;
int tokval, result_state;
uint length;
@@ -788,7 +798,6 @@ int MYSQLlex(void *arg, void *yythd)
lip->start_token();
state=lip->next_state;
lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
- LINT_INIT(c);
for (;;)
{
switch (state) {
@@ -917,7 +926,7 @@ int MYSQLlex(void *arg, void *yythd)
else
#endif
{
- for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c);
+ for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) ;
/* If there were non-ASCII characters, mark that we must convert */
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
}
@@ -929,7 +938,7 @@ int MYSQLlex(void *arg, void *yythd)
If we find a space then this can't be an identifier. We notice this
below by checking start != lex->ptr.
*/
- for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet());
+ for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) ;
}
if (start == lip->get_ptr() && c == '.' && ident_map[lip->yyPeek()])
lip->next_state=MY_LEX_IDENT_SEP;
@@ -1002,7 +1011,7 @@ int MYSQLlex(void *arg, void *yythd)
}
else if (c == 'b')
{
- while ((c= lip->yyGet()) == '0' || c == '1');
+ while ((c= lip->yyGet()) == '0' || c == '1') ;
if ((lip->yyLength() >= 3) && !ident_map[c])
{
/* Skip '0b' */
@@ -1061,7 +1070,7 @@ int MYSQLlex(void *arg, void *yythd)
else
#endif
{
- for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c);
+ for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) ;
/* If there were non-ASCII characters, mark that we must convert */
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
}
@@ -1161,7 +1170,7 @@ int MYSQLlex(void *arg, void *yythd)
case MY_LEX_BIN_NUMBER: // Found b'bin-string'
lip->yySkip(); // Accept opening '
- while ((c= lip->yyGet()) == '0' || c == '1');
+ while ((c= lip->yyGet()) == '0' || c == '1') ;
if (c != '\'')
return(ABORT_SYM); // Illegal hex constant
lip->yySkip(); // Accept closing '
@@ -1436,7 +1445,7 @@ int MYSQLlex(void *arg, void *yythd)
[(global | local | session) .]variable_name
*/
- for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c);
+ for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) ;
/* If there were non-ASCII characters, mark that we must convert */
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 62106a2500b..22b7d2e359c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1976,4 +1976,6 @@ extern bool is_lex_native_function(const LEX_STRING *name);
@} (End of group Semantic_Analysis)
*/
+int my_missing_function_error(const LEX_STRING &token, const char *name);
+
#endif /* MYSQL_SERVER */
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 0d267111dad..22df77afeb3 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -86,7 +86,7 @@ struct list_node :public Sql_alloc
};
-extern list_node end_of_list;
+extern MYSQL_PLUGIN_IMPORT list_node end_of_list;
class base_list :public Sql_alloc
{
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index d4f499b8d44..1758a6df5f9 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -86,7 +86,7 @@ static int read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
static bool write_execute_load_query_log_event(THD *thd,
bool duplicates, bool ignore,
bool transactional_table,
- THD::killed_state killed_status);
+ int errcode);
#endif /* EMBEDDED_LIBRARY */
/*
@@ -483,10 +483,12 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
/* If the file was not empty, wrote_create_file is true */
if (lf_info.wrote_create_file)
{
+ int errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
+
if (thd->transaction.stmt.modified_non_trans_table)
write_execute_load_query_log_event(thd, handle_duplicates,
ignore, transactional_table,
- killed_status);
+ errcode);
else
{
Delete_file_log_event d(thd, db, transactional_table);
@@ -528,8 +530,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
read_info.end_io_cache();
if (lf_info.wrote_create_file)
{
+ int errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
write_execute_load_query_log_event(thd, handle_duplicates, ignore,
- transactional_table,killed_status);
+ transactional_table, errcode);
}
}
}
@@ -553,7 +556,7 @@ err:
static bool write_execute_load_query_log_event(THD *thd,
bool duplicates, bool ignore,
bool transactional_table,
- THD::killed_state killed_err_arg)
+ int errcode)
{
Execute_load_query_log_event
e(thd, thd->query, thd->query_length,
@@ -561,7 +564,7 @@ static bool write_execute_load_query_log_event(THD *thd,
(uint) ((char*)thd->lex->fname_end - (char*)thd->query),
(duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE :
(ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR),
- transactional_table, FALSE, killed_err_arg);
+ transactional_table, FALSE, errcode);
e.flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F;
return mysql_bin_log.write(&e);
}
@@ -747,9 +750,9 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
real_item= item->real_item();
- if (!read_info.enclosed &&
+ if ((!read_info.enclosed &&
(enclosed_length && length == 4 &&
- !memcmp(pos, STRING_WITH_LEN("NULL"))) ||
+ !memcmp(pos, STRING_WITH_LEN("NULL")))) ||
(length == 1 && read_info.found_null))
{
@@ -1148,8 +1151,8 @@ int READ_INFO::read_field()
}
// End of enclosed field if followed by field_term or line_term
if (chr == my_b_EOF ||
- chr == line_term_char && terminator(line_term_ptr,
- line_term_length))
+ (chr == line_term_char && terminator(line_term_ptr,
+ line_term_length)))
{ // Maybe unexpected linefeed
enclosed=1;
found_end_of_line=1;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 87497b35bd3..0faed66cd4e 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -196,11 +196,8 @@ bool begin_trans(THD *thd)
error= -1;
else
{
- LEX *lex= thd->lex;
thd->options|= OPTION_BEGIN;
thd->server_status|= SERVER_STATUS_IN_TRANS;
- if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
- error= ha_start_consistent_snapshot(thd);
}
return error;
}
@@ -1173,12 +1170,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
}
case COM_STMT_EXECUTE:
{
- mysql_stmt_execute(thd, packet, packet_length);
+ mysqld_stmt_execute(thd, packet, packet_length);
break;
}
case COM_STMT_FETCH:
{
- mysql_stmt_fetch(thd, packet, packet_length);
+ mysqld_stmt_fetch(thd, packet, packet_length);
break;
}
case COM_STMT_SEND_LONG_DATA:
@@ -1188,17 +1185,17 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
}
case COM_STMT_PREPARE:
{
- mysql_stmt_prepare(thd, packet, packet_length);
+ mysqld_stmt_prepare(thd, packet, packet_length);
break;
}
case COM_STMT_CLOSE:
{
- mysql_stmt_close(thd, packet);
+ mysqld_stmt_close(thd, packet);
break;
}
case COM_STMT_RESET:
{
- mysql_stmt_reset(thd, packet);
+ mysqld_stmt_reset(thd, packet);
break;
}
case COM_QUERY:
@@ -1372,7 +1369,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (check_access(thd, CREATE_ACL, db.str , 0, 1, 0,
is_schema_db(db.str)))
break;
- general_log_print(thd, command, packet);
+ general_log_print(thd, command, "%.*s", db.length, db.str);
bzero(&create_info, sizeof(create_info));
mysql_create_db(thd, (lower_case_table_names == 2 ? alias.str : db.str),
&create_info, 0);
@@ -1397,7 +1394,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
break;
}
- general_log_write(thd, command, db.str, db.length);
+ general_log_write(thd, command, "%.*s", db.length, db.str);
mysql_rm_db(thd, db.str, 0, 0);
break;
}
@@ -1582,14 +1579,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break;
}
- /* If commit fails, we should be able to reset the OK status. */
- thd->main_da.can_overwrite_status= TRUE;
- ha_autocommit_or_rollback(thd, thd->is_error());
- thd->main_da.can_overwrite_status= FALSE;
-
- thd->transaction.stmt.reset();
-
-
/* report error issued during command execution */
if (thd->killed_errno())
{
@@ -1602,6 +1591,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->mysys_var->abort= 0;
}
+ /* If commit fails, we should be able to reset the OK status. */
+ thd->main_da.can_overwrite_status= TRUE;
+ ha_autocommit_or_rollback(thd, thd->is_error());
+ thd->main_da.can_overwrite_status= FALSE;
+
+ thd->transaction.stmt.reset();
+
net_end_statement(thd);
query_cache_end_of_result(thd);
@@ -3946,7 +3942,9 @@ end_with_restore_list:
res= mysql_routine_grant(thd, all_tables,
lex->type == TYPE_ENUM_PROCEDURE,
lex->users_list, grants,
- lex->sql_command == SQLCOM_REVOKE, 0);
+ lex->sql_command == SQLCOM_REVOKE, TRUE);
+ if (!res)
+ my_ok(thd);
}
else
{
@@ -4090,6 +4088,11 @@ end_with_restore_list:
}
if (begin_trans(thd))
goto error;
+ if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
+ {
+ if (ha_start_consistent_snapshot(thd))
+ goto error;
+ }
my_ok(thd);
break;
case SQLCOM_COMMIT:
@@ -5230,7 +5233,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
if (schema_db)
{
- if (!(sctx->master_access & FILE_ACL) && (want_access & FILE_ACL) ||
+ if ((!(sctx->master_access & FILE_ACL) && (want_access & FILE_ACL)) ||
(want_access & ~(SELECT_ACL | EXTRA_ACL | FILE_ACL)))
{
if (!no_errors)
@@ -5264,7 +5267,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
DBUG_RETURN(FALSE);
}
if (((want_access & ~sctx->master_access) & ~(DB_ACLS | EXTRA_ACL)) ||
- ! db && dont_check_global_grants)
+ (! db && dont_check_global_grants))
{ // We can never grant this
DBUG_PRINT("error",("No possible access"));
if (!no_errors)
@@ -5542,7 +5545,7 @@ bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table)
if (!check_access(thd, access, table->db,
&table->grant.privilege, 0, 1,
test(table->schema_table)) &&
- !check_grant(thd, access, table, 0, 1, 1))
+ !check_grant(thd, access, table, 0, 1, 1))
DBUG_RETURN(0);
}
}
@@ -5798,7 +5801,7 @@ mysql_new_select(LEX *lex, bool move_down)
/*
Don't evaluate this subquery during statement prepare even if
it's a constant one. The flag is switched off in the end of
- mysql_stmt_prepare.
+ mysqld_stmt_prepare.
*/
if (thd->stmt_arena->is_stmt_prepare())
select_lex->uncacheable|= UNCACHEABLE_PREPARE;
@@ -7873,7 +7876,7 @@ bool parse_sql(THD *thd,
/* Check that if MYSQLparse() failed, thd->is_error() is set. */
DBUG_ASSERT(!mysql_parse_status ||
- mysql_parse_status && thd->is_error());
+ (mysql_parse_status && thd->is_error()));
/* Reset parser state. */
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 4a50650b6f4..284eaebbe87 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -918,6 +918,9 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
Set-up the TABLE_LIST object to be a list with a single table
Set the object to zero to create NULL pointers and set alias
and real name to table name and get database name from file name.
+ TODO: Consider generalizing or refactoring Lex::add_table_to_list() so
+ it can be used in all places where we create TABLE_LIST objects.
+ Also consider creating appropriate constructors for TABLE_LIST.
*/
bzero((void*)&tables, sizeof(TABLE_LIST));
@@ -925,6 +928,13 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
tables.table= table;
tables.next_local= 0;
tables.next_name_resolution_table= 0;
+ /*
+ Cache the table in Item_fields. All the tables can be cached except
+ the trigger pseudo table.
+ */
+ tables.cacheable_table= TRUE;
+ context= thd->lex->current_context();
+ tables.select_lex= context->select_lex;
strmov(db_name_string, table->s->normalized_path.str);
dir_length= dirname_length(db_name_string);
db_name_string[dir_length - 1]= 0;
@@ -932,7 +942,6 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
db_name= &db_name_string[home_dir_length];
tables.db= db_name;
- context= thd->lex->current_context();
table->map= 1; //To ensure correct calculation of const item
table->get_fields_in_item_tree= TRUE;
save_table_list= context->table_list;
@@ -964,8 +973,9 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
save_use_only_table_context= thd->lex->use_only_table_context;
thd->lex->use_only_table_context= TRUE;
+ thd->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
- error= func_expr->fix_fields(thd, (Item**)0);
+ error= func_expr->fix_fields(thd, (Item**)&func_expr);
thd->lex->use_only_table_context= save_use_only_table_context;
@@ -5090,7 +5100,7 @@ static bool mysql_change_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
handler *file= lpt->table->file;
DBUG_ENTER("mysql_change_partitions");
- build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "", 0);
+ build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0);
if ((error= file->ha_change_partitions(lpt->create_info, path, &lpt->copied,
&lpt->deleted, lpt->pack_frm_data,
lpt->pack_frm_len)))
@@ -5130,7 +5140,7 @@ static bool mysql_rename_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
int error;
DBUG_ENTER("mysql_rename_partitions");
- build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "", 0);
+ build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0);
if ((error= lpt->table->file->ha_rename_partitions(path)))
{
if (error != 1)
@@ -5171,7 +5181,7 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt)
int error;
DBUG_ENTER("mysql_drop_partitions");
- build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "", 0);
+ build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0);
if ((error= lpt->table->file->ha_drop_partitions(path)))
{
lpt->table->file->print_error(error, MYF(0));
@@ -5516,10 +5526,10 @@ static bool write_log_drop_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt)
partition_info *part_info= lpt->part_info;
DDL_LOG_MEMORY_ENTRY *log_entry;
DDL_LOG_MEMORY_ENTRY *exec_log_entry= NULL;
- char shadow_path[FN_REFLEN];
+ char shadow_path[FN_REFLEN + 1];
DBUG_ENTER("write_log_drop_shadow_frm");
- build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt);
+ build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt);
pthread_mutex_lock(&LOCK_gdl);
if (write_log_replace_delete_frm(lpt, 0UL, NULL,
(const char*)shadow_path, FALSE))
@@ -5559,15 +5569,15 @@ static bool write_log_rename_frm(ALTER_PARTITION_PARAM_TYPE *lpt)
partition_info *part_info= lpt->part_info;
DDL_LOG_MEMORY_ENTRY *log_entry;
DDL_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry;
- char path[FN_REFLEN];
- char shadow_path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
+ char shadow_path[FN_REFLEN + 1];
DDL_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry;
DBUG_ENTER("write_log_rename_frm");
part_info->first_log_entry= NULL;
- build_table_filename(path, sizeof(path), lpt->db,
+ build_table_filename(path, sizeof(path) - 1, lpt->db,
lpt->table_name, "", 0);
- build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt);
+ build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt);
pthread_mutex_lock(&LOCK_gdl);
if (write_log_replace_delete_frm(lpt, 0UL, shadow_path, path, TRUE))
goto error;
@@ -5610,16 +5620,16 @@ static bool write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
partition_info *part_info= lpt->part_info;
DDL_LOG_MEMORY_ENTRY *log_entry;
DDL_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry;
- char tmp_path[FN_REFLEN];
- char path[FN_REFLEN];
+ char tmp_path[FN_REFLEN + 1];
+ char path[FN_REFLEN + 1];
uint next_entry= 0;
DDL_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry;
DBUG_ENTER("write_log_drop_partition");
part_info->first_log_entry= NULL;
- build_table_filename(path, sizeof(path), lpt->db,
+ build_table_filename(path, sizeof(path) - 1, lpt->db,
lpt->table_name, "", 0);
- build_table_filename(tmp_path, sizeof(tmp_path), lpt->db,
+ build_table_filename(tmp_path, sizeof(tmp_path) - 1, lpt->db,
lpt->table_name, "#", 0);
pthread_mutex_lock(&LOCK_gdl);
if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path,
@@ -5669,14 +5679,14 @@ static bool write_log_add_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
partition_info *part_info= lpt->part_info;
DDL_LOG_MEMORY_ENTRY *log_entry;
DDL_LOG_MEMORY_ENTRY *exec_log_entry= NULL;
- char tmp_path[FN_REFLEN];
- char path[FN_REFLEN];
+ char tmp_path[FN_REFLEN + 1];
+ char path[FN_REFLEN + 1];
uint next_entry= 0;
DBUG_ENTER("write_log_add_change_partition");
- build_table_filename(path, sizeof(path), lpt->db,
+ build_table_filename(path, sizeof(path) - 1, lpt->db,
lpt->table_name, "", 0);
- build_table_filename(tmp_path, sizeof(tmp_path), lpt->db,
+ build_table_filename(tmp_path, sizeof(tmp_path) - 1, lpt->db,
lpt->table_name, "#", 0);
pthread_mutex_lock(&LOCK_gdl);
if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path,
@@ -5723,16 +5733,16 @@ static bool write_log_final_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
partition_info *part_info= lpt->part_info;
DDL_LOG_MEMORY_ENTRY *log_entry;
DDL_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry;
- char path[FN_REFLEN];
- char shadow_path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
+ char shadow_path[FN_REFLEN + 1];
DDL_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry;
uint next_entry= 0;
DBUG_ENTER("write_log_final_change_partition");
part_info->first_log_entry= NULL;
- build_table_filename(path, sizeof(path), lpt->db,
+ build_table_filename(path, sizeof(path) - 1, lpt->db,
lpt->table_name, "", 0);
- build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt);
+ build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt);
pthread_mutex_lock(&LOCK_gdl);
if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path,
lpt->alter_info->flags & ALTER_REORGANIZE_PARTITION))
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 1465b6d2d30..da168d36429 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -29,6 +29,18 @@
extern struct st_mysql_plugin *mysqld_builtins[];
+/**
+ @note The order of the enumeration is critical.
+ @see construct_options
+*/
+static const char *global_plugin_typelib_names[]=
+ { "OFF", "ON", "FORCE", NULL };
+enum enum_plugin_load_policy {PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE};
+static TYPELIB global_plugin_typelib=
+ { array_elements(global_plugin_typelib_names)-1,
+ "", global_plugin_typelib_names, NULL };
+
+
char *opt_plugin_load= NULL;
char *opt_plugin_dir_ptr;
char opt_plugin_dir[FN_REFLEN];
@@ -192,7 +204,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv);
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
const char *list);
static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *,
- int *, char **, my_bool);
+ int *, char **);
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
struct st_plugin_int **);
static void unlock_variables(THD *thd, struct system_variables *vars);
@@ -751,7 +763,7 @@ static bool plugin_add(MEM_ROOT *tmp_root,
tmp.name.length= name_len;
tmp.ref_count= 0;
tmp.state= PLUGIN_IS_UNINITIALIZED;
- if (test_plugin_options(tmp_root, &tmp, argc, argv, true))
+ if (test_plugin_options(tmp_root, &tmp, argc, argv))
tmp.state= PLUGIN_IS_DISABLED;
if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
@@ -997,7 +1009,6 @@ static int plugin_initialize(struct st_plugin_int *plugin)
DBUG_ENTER("plugin_initialize");
safe_mutex_assert_owner(&LOCK_plugin);
-
if (plugin_type_initialize[plugin->plugin->type])
{
if ((*plugin_type_initialize[plugin->plugin->type])(plugin))
@@ -1083,6 +1094,20 @@ uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
return (uchar*) var->key;
}
+static inline void convert_dash_to_underscore(char *str, int len)
+{
+ for (char *p= str; p <= str+len; p++)
+ if (*p == '-')
+ *p= '_';
+}
+
+static inline void convert_underscore_to_dash(char *str, int len)
+{
+ for (char *p= str; p <= str+len; p++)
+ if (*p == '_')
+ *p= '-';
+}
+
/*
The logic is that we first load and initialize all compiled in plugins.
@@ -1094,11 +1119,12 @@ uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
int plugin_init(int *argc, char **argv, int flags)
{
uint i;
- bool def_enabled, is_myisam;
+ bool is_myisam;
struct st_mysql_plugin **builtins;
struct st_mysql_plugin *plugin;
struct st_plugin_int tmp, *plugin_ptr, **reap;
MEM_ROOT tmp_root;
+ bool reaped_mandatory_plugin= FALSE;
DBUG_ENTER("plugin_init");
if (initialized)
@@ -1142,17 +1168,13 @@ int plugin_init(int *argc, char **argv, int flags)
!my_strnncoll(&my_charset_latin1, (const uchar*) plugin->name,
6, (const uchar*) "InnoDB", 6))
continue;
- /* by default, ndbcluster and federated are disabled */
- def_enabled=
- my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0 &&
- my_strcasecmp(&my_charset_latin1, plugin->name, "FEDERATED") != 0;
bzero(&tmp, sizeof(tmp));
tmp.plugin= plugin;
tmp.name.str= (char *)plugin->name;
tmp.name.length= strlen(plugin->name);
tmp.state= 0;
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
- if (test_plugin_options(&tmp_root, &tmp, argc, argv, def_enabled))
+ if (test_plugin_options(&tmp_root, &tmp, argc, argv))
tmp.state= PLUGIN_IS_DISABLED;
else
tmp.state= PLUGIN_IS_UNINITIALIZED;
@@ -1227,6 +1249,8 @@ int plugin_init(int *argc, char **argv, int flags)
while ((plugin_ptr= *(--reap)))
{
pthread_mutex_unlock(&LOCK_plugin);
+ if (plugin_ptr->is_mandatory)
+ reaped_mandatory_plugin= TRUE;
plugin_deinitialize(plugin_ptr, true);
pthread_mutex_lock(&LOCK_plugin);
plugin_del(plugin_ptr);
@@ -1234,6 +1258,8 @@ int plugin_init(int *argc, char **argv, int flags)
pthread_mutex_unlock(&LOCK_plugin);
my_afree(reap);
+ if (reaped_mandatory_plugin)
+ goto err;
end:
free_root(&tmp_root, MYF(0));
@@ -1299,7 +1325,7 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin)
pthread_mutex_lock(&LOCK_plugin);
rw_wrlock(&LOCK_system_variables_hash);
- if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true))
+ if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL))
goto end;
tmp.state= PLUGIN_IS_UNINITIALIZED;
if ((result= register_builtin(plugin, &tmp, &ptr)))
@@ -2889,59 +2915,78 @@ my_bool get_one_plugin_option(int optid __attribute__((unused)),
}
+/**
+ Creates a set of my_option objects associated with a specified plugin-
+ handle.
+
+ @param mem_root Memory allocator to be used.
+ @param tmp A pointer to a plugin handle
+ @param[out] options A pointer to a pre-allocated static array
+
+ The set is stored in the pre-allocated static array supplied to the function.
+ The size of the array is calculated as (number_of_plugin_varaibles*2+3). The
+ reason is that each option can have a prefix '--plugin-' in addtion to the
+ shorter form '--&lt;plugin-name&gt;'. There is also space allocated for
+ terminating NULL pointers.
+
+ @return
+ @retval -1 An error occurred
+ @retval 0 Success
+*/
+
static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
- my_option *options, my_bool **enabled,
- bool can_disable)
+ my_option *options)
{
const char *plugin_name= tmp->plugin->name;
- uint namelen= strlen(plugin_name), optnamelen;
- uint buffer_length= namelen * 4 + (can_disable ? 75 : 10);
- char *name= (char*) alloc_root(mem_root, buffer_length) + 1;
- char *optname, *p;
+ const LEX_STRING plugin_dash = { C_STRING_WITH_LEN("plugin-") };
+ uint plugin_name_len= strlen(plugin_name);
+ uint optnamelen;
+ const int max_comment_len= 180;
+ char *comment= (char *) alloc_root(mem_root, max_comment_len + 1);
+ char *optname;
+
int index= 0, offset= 0;
st_mysql_sys_var *opt, **plugin_option;
st_bookmark *v;
+
+ /** Used to circumvent the const attribute on my_option::name */
+ char *plugin_name_ptr, *plugin_name_with_prefix_ptr;
+
DBUG_ENTER("construct_options");
- DBUG_PRINT("plugin", ("plugin: '%s' enabled: %d can_disable: %d",
- plugin_name, **enabled, can_disable));
+ options[0].name= plugin_name_ptr= (char*) alloc_root(mem_root,
+ plugin_name_len + 1);
+ strcpy(plugin_name_ptr, plugin_name);
+ my_casedn_str(&my_charset_latin1, plugin_name_ptr);
+ convert_underscore_to_dash(plugin_name_ptr, plugin_name_len);
/* support --skip-plugin-foo syntax */
- memcpy(name, plugin_name, namelen + 1);
- my_casedn_str(&my_charset_latin1, name);
- strxmov(name + namelen + 1, "plugin-", name, NullS);
- /* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
-
- for (p= name + namelen*2 + 8; p > name; p--)
- if (*p == '_')
- *p= '-';
+ options[1].name= plugin_name_with_prefix_ptr= (char*) alloc_root(mem_root,
+ plugin_name_len +
+ plugin_dash.length + 1);
+ strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, options[0].name, NullS);
- if (can_disable)
- {
- strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. "
- "Disable with --skip-", name," (will save memory).", NullS);
- /*
- Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
- 20 + namelen + 20 + 1 == namelen * 4 + 67.
- */
+ options[0].id= options[1].id= 256; /* must be >255. dup id ok */
+ options[0].var_type= options[1].var_type= GET_ENUM;
+ options[0].arg_type= options[1].arg_type= OPT_ARG;
+ options[0].def_value= options[1].def_value= 1; /* ON */
+ options[0].typelib= options[1].typelib= &global_plugin_typelib;
- options[0].comment= name + namelen*2 + 10;
- }
+ strxnmov(comment, max_comment_len, "Enable or disable ", plugin_name,
+ " plugin. Possible values are ON, OFF, FORCE (don't start "
+ "if the plugin fails to load).", NullS);
+ options[0].comment= comment;
/*
- NOTE: 'name' is one char above the allocated buffer!
- NOTE: This code assumes that 'my_bool' and 'char' are of same size.
+ Allocate temporary space for the value of the tristate.
+ This option will have a limited lifetime and is not used beyond
+ server initialization.
+ GET_ENUM value is an integer.
*/
- *((my_bool *)(name -1))= **enabled;
- *enabled= (my_bool *)(name - 1);
-
+ options[0].value= options[1].value= (uchar **)alloc_root(mem_root,
+ sizeof(int));
+ *((uint*) options[0].value)= *((uint*) options[1].value)=
+ (uint) options[0].def_value;
- options[1].name= (options[0].name= name) + namelen + 1;
- options[0].id= options[1].id= 256; /* must be >255. dup id ok */
- options[0].var_type= options[1].var_type= GET_BOOL;
- options[0].arg_type= options[1].arg_type= NO_ARG;
- options[0].def_value= options[1].def_value= **enabled;
- options[0].value= options[0].u_max_value=
- options[1].value= options[1].u_max_value= (uchar**) (name - 1);
options+= 2;
/*
@@ -2955,7 +3000,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
opt= *plugin_option;
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
continue;
- if (!(register_var(name, opt->name, opt->flags)))
+ if (!(register_var(plugin_name_ptr, opt->name, opt->flags)))
continue;
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
case PLUGIN_VAR_BOOL:
@@ -3020,7 +3065,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
if (!opt->update)
{
opt->update= update_func_str;
- if (!(opt->flags & PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY))
+ if (!(opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)))
{
opt->flags|= PLUGIN_VAR_READONLY;
sql_print_warning("Server variable %s of plugin %s was forced "
@@ -3062,14 +3107,14 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
{
optnamelen= strlen(opt->name);
- optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
- strxmov(optname, name, "-", opt->name, NullS);
- optnamelen= namelen + optnamelen + 1;
+ optname= (char*) alloc_root(mem_root, plugin_name_len + optnamelen + 2);
+ strxmov(optname, plugin_name_ptr, "-", opt->name, NullS);
+ optnamelen= plugin_name_len + optnamelen + 1;
}
else
{
/* this should not fail because register_var should create entry */
- if (!(v= find_bookmark(name, opt->name, opt->flags)))
+ if (!(v= find_bookmark(plugin_name_ptr, opt->name, opt->flags)))
{
sql_print_error("Thread local variable '%s' not allocated "
"in plugin '%s'.", opt->name, plugin_name);
@@ -3085,10 +3130,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
(optnamelen= v->name_len) + 1);
}
- /* convert '_' to '-' */
- for (p= optname; *p; p++)
- if (*p == '_')
- *p= '-';
+ convert_underscore_to_dash(optname, optnamelen);
options->name= optname;
options->comment= opt->comment;
@@ -3103,10 +3145,13 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
else
options->value= options->u_max_value= *(uchar***) (opt + 1);
+ char *option_name_ptr;
options[1]= options[0];
- options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8);
- options[1].comment= 0; // hidden
- strxmov(p, "plugin-", optname, NullS);
+ options[1].name= option_name_ptr= (char*) alloc_root(mem_root,
+ plugin_dash.length +
+ optnamelen + 1);
+ options[1].comment= 0; /* Hidden from the help text */
+ strxmov(option_name_ptr, plugin_dash.str, optname, NullS);
options+= 2;
}
@@ -3120,55 +3165,57 @@ static my_option *construct_help_options(MEM_ROOT *mem_root,
{
st_mysql_sys_var **opt;
my_option *opts;
- my_bool dummy, can_disable;
- my_bool *dummy2= &dummy;
uint count= EXTRA_OPTIONS;
DBUG_ENTER("construct_help_options");
- for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2);
+ for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2)
+ ;
if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
DBUG_RETURN(NULL);
bzero(opts, sizeof(my_option) * count);
- dummy= TRUE; /* plugin is enabled. */
-
- can_disable=
- my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") &&
- my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
-
- if (construct_options(mem_root, p, opts, &dummy2, can_disable))
+ if (construct_options(mem_root, p, opts))
DBUG_RETURN(NULL);
DBUG_RETURN(opts);
}
-/*
- SYNOPSIS
- test_plugin_options()
- tmp_root temporary scratch space
- plugin internal plugin structure
- argc user supplied arguments
- argv user supplied arguments
- default_enabled default plugin enable status
- RETURNS:
- 0 SUCCESS - plugin should be enabled/loaded
- NOTE:
- Requires that a write-lock is held on LOCK_system_variables_hash
+/**
+ Create and register system variables supplied from the plugin and
+ assigns initial values from corresponding command line arguments.
+
+ @param tmp_root Temporary scratch space
+ @param[out] plugin Internal plugin structure
+ @param argc Number of command line arguments
+ @param argv Command line argument vector
+
+ The plugin will be updated with a policy on how to handle errors during
+ initialization.
+
+ @note Requires that a write-lock is held on LOCK_system_variables_hash
+
+ @return How initialization of the plugin should be handled.
+ @retval 0 Initialization should proceed.
+ @retval 1 Plugin is disabled.
+ @retval -1 An error has occurred.
*/
+
static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
- int *argc, char **argv, my_bool default_enabled)
+ int *argc, char **argv)
{
struct sys_var_chain chain= { NULL, NULL };
- my_bool enabled_saved= default_enabled, can_disable;
- my_bool *enabled= &default_enabled;
+ my_bool can_disable;
+ bool disable_plugin;
+ enum_plugin_load_policy plugin_load_policy= PLUGIN_ON;
+
MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
&tmp->mem_root : &plugin_mem_root;
st_mysql_sys_var **opt;
my_option *opts= NULL;
- char *p, *varname;
+ char *varname;
int error;
st_mysql_sys_var *o;
sys_var *v;
@@ -3177,13 +3224,17 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
DBUG_ENTER("test_plugin_options");
DBUG_ASSERT(tmp->plugin && tmp->name.str);
+ /*
+ The 'federated' and 'ndbcluster' storage engines are always disabled by
+ default.
+ */
+ if (!(my_strcasecmp(&my_charset_latin1, tmp->name.str, "federated") &&
+ my_strcasecmp(&my_charset_latin1, tmp->name.str, "ndbcluster")))
+ plugin_load_policy= PLUGIN_OFF;
+
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
- can_disable=
- my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
- my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
-
if (count > EXTRA_OPTIONS || (*argc > 1))
{
if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
@@ -3193,12 +3244,18 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
}
bzero(opts, sizeof(my_option) * count);
- if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
+ if (construct_options(tmp_root, tmp, opts))
{
sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
DBUG_RETURN(-1);
}
+ /*
+ We adjust the default value to account for the hardcoded exceptions
+ we have set for the federated and ndbcluster storage engines.
+ */
+ opts[0].def_value= opts[1].def_value= (int)plugin_load_policy;
+
error= handle_options(argc, &argv, opts, get_one_plugin_option);
(*argc)++; /* add back one for the program name */
@@ -3208,64 +3265,79 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
tmp->name.str);
goto err;
}
+ /*
+ Set plugin loading policy from option value. First element in the option
+ list is always the <plugin name> option value.
+ */
+ plugin_load_policy= (enum_plugin_load_policy)*(uint*)opts[0].value;
}
- if (!*enabled && !can_disable)
+ disable_plugin= (plugin_load_policy == PLUGIN_OFF);
+ /*
+ The 'MyISAM' and 'Memory' storage engines currently can't be disabled.
+ */
+ can_disable=
+ my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
+ my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
+
+ tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE) || !can_disable;
+
+ if (disable_plugin && !can_disable)
{
sql_print_warning("Plugin '%s' cannot be disabled", tmp->name.str);
- *enabled= TRUE;
+ disable_plugin= FALSE;
}
- error= 1;
+ /*
+ If the plugin is disabled it should not be initialized.
+ */
+ if (disable_plugin)
+ {
+ if (global_system_variables.log_warnings)
+ sql_print_information("Plugin '%s' is disabled.",
+ tmp->name.str);
+ if (opts)
+ my_cleanup_options(opts);
+ DBUG_RETURN(1);
+ }
- if (*enabled)
+ error= 1;
+ for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
{
- for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
+ if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
+ continue;
+ if ((var= find_bookmark(tmp->name.str, o->name, o->flags)))
+ v= new (mem_root) sys_var_pluginvar(var->key + 1, o);
+ else
{
- if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
- continue;
-
- if ((var= find_bookmark(tmp->name.str, o->name, o->flags)))
- v= new (mem_root) sys_var_pluginvar(var->key + 1, o);
- else
- {
- len= tmp->name.length + strlen(o->name) + 2;
- varname= (char*) alloc_root(mem_root, len);
- strxmov(varname, tmp->name.str, "-", o->name, NullS);
- my_casedn_str(&my_charset_latin1, varname);
-
- for (p= varname; *p; p++)
- if (*p == '-')
- *p= '_';
-
- v= new (mem_root) sys_var_pluginvar(varname, o);
- }
- DBUG_ASSERT(v); /* check that an object was actually constructed */
-
- /*
- Add to the chain of variables.
- Done like this for easier debugging so that the
- pointer to v is not lost on optimized builds.
- */
- v->chain_sys_var(&chain);
+ len= tmp->name.length + strlen(o->name) + 2;
+ varname= (char*) alloc_root(mem_root, len);
+ strxmov(varname, tmp->name.str, "-", o->name, NullS);
+ my_casedn_str(&my_charset_latin1, varname);
+ convert_dash_to_underscore(varname, len-1);
+ v= new (mem_root) sys_var_pluginvar(varname, o);
}
- if (chain.first)
+ DBUG_ASSERT(v); /* check that an object was actually constructed */
+ /*
+ Add to the chain of variables.
+ Done like this for easier debugging so that the
+ pointer to v is not lost on optimized builds.
+ */
+ v->chain_sys_var(&chain);
+ } /* end for */
+ if (chain.first)
+ {
+ chain.last->next = NULL;
+ if (mysql_add_sys_var_chain(chain.first, NULL))
{
- chain.last->next = NULL;
- if (mysql_add_sys_var_chain(chain.first, NULL))
- {
- sql_print_error("Plugin '%s' has conflicting system variables",
- tmp->name.str);
- goto err;
- }
- tmp->system_vars= chain.first;
+ sql_print_error("Plugin '%s' has conflicting system variables",
+ tmp->name.str);
+ goto err;
}
- DBUG_RETURN(0);
+ tmp->system_vars= chain.first;
}
-
- if (enabled_saved && global_system_variables.log_warnings)
- sql_print_information("Plugin '%s' disabled by command line option",
- tmp->name.str);
+ DBUG_RETURN(0);
+
err:
if (opts)
my_cleanup_options(opts);
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index 8ae38d58845..004d0d5abb7 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -79,6 +79,7 @@ struct st_plugin_int
void *data; /* plugin type specific, e.g. handlerton */
MEM_ROOT mem_root; /* memory for dynamic plugin structures */
sys_var *system_vars; /* server variables for this plugin */
+ bool is_mandatory; /* If true then plugin must not fail to load */
};
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 29d948472c7..8921f7c0d82 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -717,9 +717,9 @@ static void setup_one_conversion_function(THD *thd, Item_param *param,
prepared statement, parameter markers are replaced with variable names.
Example:
@verbatim
- mysql_stmt_prepare("UPDATE t1 SET a=a*1.25 WHERE a=?")
+ mysqld_stmt_prepare("UPDATE t1 SET a=a*1.25 WHERE a=?")
--> general logs gets [Prepare] UPDATE t1 SET a*1.25 WHERE a=?"
- mysql_stmt_execute(stmt);
+ mysqld_stmt_execute(stmt);
--> general and binary logs get
[Execute] UPDATE t1 SET a*1.25 WHERE a=1"
@endverbatim
@@ -1435,8 +1435,8 @@ static bool mysql_test_set_fields(Prepared_statement *stmt,
THD *thd= stmt->thd;
set_var_base *var;
- if (tables && check_table_access(thd, SELECT_ACL, tables, UINT_MAX, FALSE) ||
- open_normal_and_derived_tables(thd, tables, 0))
+ if ((tables && check_table_access(thd, SELECT_ACL, tables, UINT_MAX, FALSE))
+ || open_normal_and_derived_tables(thd, tables, 0))
goto error;
while ((var= it++))
@@ -1471,13 +1471,13 @@ static bool mysql_test_call_fields(Prepared_statement *stmt,
THD *thd= stmt->thd;
Item *item;
- if (tables && check_table_access(thd, SELECT_ACL, tables, UINT_MAX, FALSE) ||
+ if ((tables && check_table_access(thd, SELECT_ACL, tables, UINT_MAX, FALSE)) ||
open_normal_and_derived_tables(thd, tables, 0))
goto err;
while ((item= it++))
{
- if (!item->fixed && item->fix_fields(thd, it.ref()) ||
+ if ((!item->fixed && item->fix_fields(thd, it.ref())) ||
item->check_cols(1))
goto err;
}
@@ -2057,11 +2057,11 @@ static bool init_param_array(Prepared_statement *stmt)
to the client, otherwise an error message is set in THD.
*/
-void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length)
+void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length)
{
Prepared_statement *stmt;
bool error;
- DBUG_ENTER("mysql_stmt_prepare");
+ DBUG_ENTER("mysqld_stmt_prepare");
DBUG_PRINT("prep_query", ("%s", packet));
@@ -2228,9 +2228,8 @@ void mysql_sql_stmt_prepare(THD *thd)
LEX_STRING *name= &lex->prepared_stmt_name;
Prepared_statement *stmt;
const char *query;
- uint query_len;
+ uint query_len= 0;
DBUG_ENTER("mysql_sql_stmt_prepare");
- LINT_INIT(query_len);
DBUG_ASSERT(thd->protocol == &thd->protocol_text);
if ((stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name)))
@@ -2424,7 +2423,7 @@ static void reset_stmt_params(Prepared_statement *stmt)
client, otherwise an error message is set in THD.
*/
-void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
+void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
{
uchar *packet= (uchar*)packet_arg; // GCC 4.0.1 workaround
ulong stmt_id= uint4korr(packet);
@@ -2434,7 +2433,7 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
uchar *packet_end= packet + packet_length;
Prepared_statement *stmt;
bool open_cursor;
- DBUG_ENTER("mysql_stmt_execute");
+ DBUG_ENTER("mysqld_stmt_execute");
packet+= 9; /* stmt_id + 5 bytes of flags */
@@ -2445,7 +2444,7 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
{
char llbuf[22];
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf),
- llstr(stmt_id, llbuf), "mysql_stmt_execute");
+ llstr(stmt_id, llbuf), "mysqld_stmt_execute");
DBUG_VOID_RETURN;
}
@@ -2462,6 +2461,9 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
stmt->execute_loop(&expanded_query, open_cursor, packet, packet_end);
+ /* Close connection socket; for use with client testing (Bug#43560). */
+ DBUG_EXECUTE_IF("close_conn_after_stmt_execute", vio_close(thd->net.vio););
+
DBUG_VOID_RETURN;
}
@@ -2523,7 +2525,7 @@ void mysql_sql_stmt_execute(THD *thd)
@param packet_length Length of packet
*/
-void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
+void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length)
{
/* assume there is always place for 8-16 bytes */
ulong stmt_id= uint4korr(packet);
@@ -2531,7 +2533,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
Prepared_statement *stmt;
Statement stmt_backup;
Server_side_cursor *cursor;
- DBUG_ENTER("mysql_stmt_fetch");
+ DBUG_ENTER("mysqld_stmt_fetch");
/* First of all clear possible warnings from the previous command */
mysql_reset_thd_for_next_command(thd);
@@ -2540,7 +2542,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
{
char llbuf[22];
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf),
- llstr(stmt_id, llbuf), "mysql_stmt_fetch");
+ llstr(stmt_id, llbuf), "mysqld_stmt_fetch");
DBUG_VOID_RETURN;
}
@@ -2581,9 +2583,9 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
This function resets statement to the state it was right after prepare.
It can be used to:
- - clear an error happened during mysql_stmt_send_long_data
+ - clear an error happened during mysqld_stmt_send_long_data
- cancel long data stream for all placeholders without
- having to call mysql_stmt_execute.
+ having to call mysqld_stmt_execute.
- close an open cursor
Sends 'OK' packet in case of success (statement was reset)
or 'ERROR' packet (unrecoverable error/statement not found/etc).
@@ -2592,12 +2594,12 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
@param packet Packet with stmt id
*/
-void mysql_stmt_reset(THD *thd, char *packet)
+void mysqld_stmt_reset(THD *thd, char *packet)
{
/* There is always space for 4 bytes in buffer */
ulong stmt_id= uint4korr(packet);
Prepared_statement *stmt;
- DBUG_ENTER("mysql_stmt_reset");
+ DBUG_ENTER("mysqld_stmt_reset");
/* First of all clear possible warnings from the previous command */
mysql_reset_thd_for_next_command(thd);
@@ -2607,7 +2609,7 @@ void mysql_stmt_reset(THD *thd, char *packet)
{
char llbuf[22];
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf),
- llstr(stmt_id, llbuf), "mysql_stmt_reset");
+ llstr(stmt_id, llbuf), "mysqld_stmt_reset");
DBUG_VOID_RETURN;
}
@@ -2615,7 +2617,7 @@ void mysql_stmt_reset(THD *thd, char *packet)
/*
Clear parameters from data which could be set by
- mysql_stmt_send_long_data() call.
+ mysqld_stmt_send_long_data() call.
*/
reset_stmt_params(stmt);
@@ -2636,12 +2638,12 @@ void mysql_stmt_reset(THD *thd, char *packet)
we don't send any reply to this command.
*/
-void mysql_stmt_close(THD *thd, char *packet)
+void mysqld_stmt_close(THD *thd, char *packet)
{
/* There is always space for 4 bytes in packet buffer */
ulong stmt_id= uint4korr(packet);
Prepared_statement *stmt;
- DBUG_ENTER("mysql_stmt_close");
+ DBUG_ENTER("mysqld_stmt_close");
thd->main_da.disable_status();
@@ -2740,7 +2742,7 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
stmt->state= Query_arena::ERROR;
stmt->last_errno= ER_WRONG_ARGUMENTS;
sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS),
- "mysql_stmt_send_long_data");
+ "mysqld_stmt_send_long_data");
DBUG_VOID_RETURN;
}
#endif
@@ -2844,7 +2846,7 @@ void Prepared_statement::setup_set_params()
Decide if we have to expand the query (because we must write it to logs or
because we want to look it up in the query cache) or not.
*/
- if (mysql_bin_log.is_open() && is_update_query(lex->sql_command) ||
+ if ((mysql_bin_log.is_open() && is_update_query(lex->sql_command)) ||
opt_log || opt_slow_log ||
query_cache_is_cacheable_query(lex))
{
@@ -3164,7 +3166,7 @@ Prepared_statement::set_parameters(String *expanded_query,
if (res)
{
my_error(ER_WRONG_ARGUMENTS, MYF(0),
- is_sql_ps ? "EXECUTE" : "mysql_stmt_execute");
+ is_sql_ps ? "EXECUTE" : "mysqld_stmt_execute");
reset_stmt_params(this);
}
return res;
@@ -3295,7 +3297,7 @@ Prepared_statement::reprepare()
&cur_db_changed))
return TRUE;
- error= (name.str && copy.set_name(&name) ||
+ error= ((name.str && copy.set_name(&name)) ||
copy.prepare(query, query_length) ||
validate_metadata(&copy));
@@ -3626,11 +3628,11 @@ error:
}
-/** Common part of DEALLOCATE PREPARE and mysql_stmt_close. */
+/** Common part of DEALLOCATE PREPARE and mysqld_stmt_close. */
void Prepared_statement::deallocate()
{
- /* We account deallocate in the same manner as mysql_stmt_close */
+ /* We account deallocate in the same manner as mysqld_stmt_close */
status_var_increment(thd->status_var.com_stmt_close);
/* Statement map calls delete stmt on erase */
thd->stmt_map.erase(this);
diff --git a/sql/sql_profile.h b/sql/sql_profile.h
index b5537487d26..245959e0953 100644
--- a/sql/sql_profile.h
+++ b/sql/sql_profile.h
@@ -16,25 +16,12 @@
#ifndef _SQL_PROFILE_H
#define _SQL_PROFILE_H
-#if __STDC_VERSION__ < 199901L
-# if __GNUC__ >= 2
-# define __func__ __FUNCTION__
-# else
-# define __func__ _unknown_func_
-extern const char * const _unknown_func_;
-# endif
-#elif defined(_MSC_VER)
-# if _MSC_VER < 1300
-# define __func__ _unknown_func_
-extern const char * const _unknown_func_;
-# else
-# define __func__ __FUNCTION__
-# endif
-#elif defined(__BORLANDC__)
-# define __func__ __FUNC__
+#ifndef __func__
+#ifdef __FUNCTION__
+#define __func__ __FUNCTION__
#else
-# define __func__ _unknown_func_
-extern const char * const _unknown_func_;
+#define __func__ "unknown function"
+#endif
#endif
extern ST_FIELD_INFO query_profile_statistics_info[];
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index d4331b12cd4..0e0b8eb60b9 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -244,7 +244,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
char *new_table_alias, bool skip_error)
{
int rc= 1;
- char name[FN_REFLEN];
+ char name[FN_REFLEN + 1];
const char *new_alias, *old_alias;
frm_type_enum frm_type;
enum legacy_db_type table_type;
@@ -261,14 +261,16 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
old_alias= ren_table->table_name;
new_alias= new_table_name;
}
- build_table_filename(name, sizeof(name),
+ DBUG_ASSERT(new_alias);
+
+ build_table_filename(name, sizeof(name) - 1,
new_db, new_alias, reg_ext, 0);
if (!access(name,F_OK))
{
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
DBUG_RETURN(1); // This can't be skipped
}
- build_table_filename(name, sizeof(name),
+ build_table_filename(name, sizeof(name) - 1,
ren_table->db, old_alias, reg_ext, 0);
frm_type= mysql_frm_type(thd, name, &table_type);
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 06c6c022780..476c8aaaefb 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -147,7 +147,7 @@ static int send_file(THD *thd)
if (errmsg)
{
sql_print_error("Failed in send_file() %s", errmsg);
- DBUG_PRINT("error", (errmsg));
+ DBUG_PRINT("error", ("%s", errmsg));
}
DBUG_RETURN(error);
}
@@ -1043,6 +1043,7 @@ int reset_slave(THD *thd, Master_info* mi)
Reset errors (the idea is that we forget about the
old master).
*/
+ mi->clear_error();
mi->rli.clear_error();
mi->rli.clear_until_condition();
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index b6cf3848eee..0f2b3183c0c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1353,7 +1353,7 @@ JOIN::optimize()
join_tab[const_tables].type != JT_ALL &&
join_tab[const_tables].type != JT_FT &&
join_tab[const_tables].type != JT_REF_OR_NULL &&
- (order && simple_order || group_list && simple_group))
+ ((order && simple_order) || (group_list && simple_group)))
{
if (add_ref_to_table_cond(thd,&join_tab[const_tables])) {
DBUG_RETURN(1);
@@ -1871,9 +1871,9 @@ JOIN::exec()
like SEC_TO_TIME(SUM(...)).
*/
- if (curr_join->group_list && (!test_if_subpart(curr_join->group_list,
+ if ((curr_join->group_list && (!test_if_subpart(curr_join->group_list,
curr_join->order) ||
- curr_join->select_distinct) ||
+ curr_join->select_distinct)) ||
(curr_join->select_distinct &&
curr_join->tmp_table_param.using_indirect_summary_function))
{ /* Must copy to another table */
@@ -2251,6 +2251,14 @@ JOIN::destroy()
cond_equal= 0;
cleanup(1);
+ /* Cleanup items referencing temporary table columns */
+ if (!tmp_all_fields3.is_empty())
+ {
+ List_iterator_fast<Item> it(tmp_all_fields3);
+ Item *item;
+ while ((item= it++))
+ item->cleanup();
+ }
if (exec_tmp_table1)
free_tmp_table(thd, exec_tmp_table1);
if (exec_tmp_table2)
@@ -2339,9 +2347,10 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
}
else
{
- if (err= join->prepare(rref_pointer_array, tables, wild_num,
- conds, og_num, order, group, having, proc_param,
- select_lex, unit))
+ err= join->prepare(rref_pointer_array, tables, wild_num,
+ conds, og_num, order, group, having, proc_param,
+ select_lex, unit);
+ if (err)
{
goto err;
}
@@ -2356,9 +2365,10 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
DBUG_RETURN(TRUE);
thd_proc_info(thd, "init");
thd->used_tables=0; // Updated by setup_fields
- if (err= join->prepare(rref_pointer_array, tables, wild_num,
- conds, og_num, order, group, having, proc_param,
- select_lex, unit))
+ err= join->prepare(rref_pointer_array, tables, wild_num,
+ conds, og_num, order, group, having, proc_param,
+ select_lex, unit);
+ if (err)
{
goto err;
}
@@ -2425,7 +2435,6 @@ static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select,
if (select)
{
select->head=table;
- table->reginfo.impossible_range=0;
if ((error= select->test_quick_select(thd, *(key_map *)keys,(table_map) 0,
limit, 0)) == 1)
DBUG_RETURN(select->quick->records);
@@ -3836,7 +3845,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
if (use->key == prev->key && use->table == prev->table)
{
if (prev->keypart+1 < use->keypart ||
- prev->keypart == use->keypart && found_eq_constant)
+ (prev->keypart == use->keypart && found_eq_constant))
continue; /* remove */
}
else if (use->keypart != 0) // First found must be 0
@@ -5141,8 +5150,8 @@ best_extension_by_limited_search(JOIN *join,
{
if (best_record_count > current_record_count ||
best_read_time > current_read_time ||
- idx == join->const_tables && // 's' is the first table in the QEP
- s->table == join->sort_by_table)
+ (idx == join->const_tables && // 's' is the first table in the QEP
+ s->table == join->sort_by_table))
{
if (best_record_count >= current_record_count &&
best_read_time >= current_read_time &&
@@ -5268,7 +5277,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
double current_read_time=read_time+best;
if (best_record_count > current_record_count ||
best_read_time > current_read_time ||
- idx == join->const_tables && s->table == join->sort_by_table)
+ (idx == join->const_tables && s->table == join->sort_by_table))
{
if (best_record_count >= current_record_count &&
best_read_time >= current_read_time &&
@@ -6215,8 +6224,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
the index if we are using limit and this is the first table
*/
- if (cond &&
- (!tab->keys.is_subset(tab->const_keys) && i > 0) ||
+ if ((cond &&
+ !tab->keys.is_subset(tab->const_keys) && i > 0) ||
(!tab->const_keys.is_clear_all() && i == join->const_tables &&
join->unit->select_limit_cnt <
join->best_positions[i].records_read &&
@@ -7087,15 +7096,17 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables,
if (!(result->send_fields(fields,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)))
{
+ bool send_error= FALSE;
if (send_row)
{
List_iterator_fast<Item> it(fields);
Item *item;
while ((item= it++))
item->no_rows_in_result();
- result->send_data(fields);
+ send_error= result->send_data(fields);
}
- result->send_eof(); // Should be safe
+ if (!send_error)
+ result->send_eof(); // Should be safe
}
/* Update results for FOUND_ROWS */
join->thd->limit_found_rows= join->thd->examined_row_count= 0;
@@ -7347,7 +7358,7 @@ static bool check_simple_equality(Item *left_item, Item *right_item,
left_item_equal->merge(right_item_equal);
/* Remove the merged multiple equality from the list */
List_iterator<Item_equal> li(cond_equal->current_level);
- while ((li++) != right_item_equal);
+ while ((li++) != right_item_equal) ;
li.remove();
}
}
@@ -9383,13 +9394,17 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
+1: for decimal point
*/
- overflow= my_decimal_precision_to_length(intg + dec, dec,
- item->unsigned_flag) - len;
+ const int required_length=
+ my_decimal_precision_to_length(intg + dec, dec,
+ item->unsigned_flag);
+
+ overflow= required_length - len;
if (overflow > 0)
dec= max(0, dec - overflow); // too long, discard fract
else
- len -= item->decimals - dec; // corrected value fits
+ /* Corrected value fits. */
+ len= required_length;
}
new_field= new Field_new_decimal(len, maybe_null, item->name,
@@ -10025,9 +10040,9 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
reclength=1; // Dummy select
/* Use packed rows if there is blobs or a lot of space to gain */
if (blob_count ||
- string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS &&
+ (string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS &&
(reclength / string_total_length <= RATIO_TO_PACK_ROWS ||
- string_total_length / string_count >= AVG_STRING_LENGTH_TO_PACK_ROWS))
+ string_total_length / string_count >= AVG_STRING_LENGTH_TO_PACK_ROWS)))
use_packed_rows= 1;
share->reclength= reclength;
@@ -10828,9 +10843,8 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
{
int rc= 0;
enum_nested_loop_state error= NESTED_LOOP_OK;
- JOIN_TAB *join_tab;
+ JOIN_TAB *join_tab= NULL;
DBUG_ENTER("do_select");
- LINT_INIT(join_tab);
join->procedure=procedure;
join->tmp_table= table; /* Save for easy recursion */
@@ -12651,7 +12665,10 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
one row). The sorting doesn't matter.
*/
if (key_part == key_part_end && reverse == 0)
+ {
+ *used_key_parts= 0;
DBUG_RETURN(1);
+ }
}
else
DBUG_RETURN(0);
@@ -13066,9 +13083,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
*/
uint nr;
key_map keys;
- uint best_key_parts;
- int best_key_direction;
- ha_rows best_records;
+ uint best_key_parts= 0;
+ int best_key_direction= 0;
+ ha_rows best_records= 0;
double read_time;
int best_key= -1;
bool is_best_covering= FALSE;
@@ -13078,9 +13095,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
ha_rows table_records= table->file->stats.records;
bool group= join->group && order == join->group_list;
ha_rows ref_key_quick_rows= HA_POS_ERROR;
- LINT_INIT(best_key_parts);
- LINT_INIT(best_key_direction);
- LINT_INIT(best_records);
/*
If not used with LIMIT, only use keys if the whole query can be
@@ -13121,12 +13135,20 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
for (nr=0; nr < table->s->keys ; nr++)
{
int direction;
+
if (keys.is_set(nr) &&
(direction= test_if_order_by_key(order, table, nr, &used_key_parts)))
{
+ /*
+ At this point we are sure that ref_key is a non-ordering
+ key (where "ordering key" is a key that will return rows
+ in the order required by ORDER BY).
+ */
+ DBUG_ASSERT (ref_key != (int) nr);
+
bool is_covering= table->covering_keys.is_set(nr) ||
- nr == table->s->primary_key &&
- table->file->primary_key_is_clustered();
+ (nr == table->s->primary_key &&
+ table->file->primary_key_is_clustered());
/*
Don't use an index scan with ORDER BY without limit.
@@ -13139,7 +13161,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
*/
if (is_covering ||
select_limit != HA_POS_ERROR ||
- ref_key < 0 && (group || table->force_index))
+ (ref_key < 0 && (group || table->force_index)))
{
double rec_per_key;
double index_scan_time;
@@ -13148,7 +13170,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
select_limit= table_records;
if (group)
{
- rec_per_key= keyinfo->rec_per_key[used_key_parts-1];
+ rec_per_key= used_key_parts ? keyinfo->rec_per_key[used_key_parts-1]
+ : 1;
set_if_bigger(rec_per_key, 1);
/*
With a grouping query each group containing on average
@@ -13203,13 +13226,13 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
*/
index_scan_time= select_limit/rec_per_key *
min(rec_per_key, table->file->scan_time());
- if (is_covering ||
- ref_key < 0 && (group || table->force_index) ||
+ if ((ref_key < 0 && is_covering) ||
+ (ref_key < 0 && (group || table->force_index)) ||
index_scan_time < read_time)
{
ha_rows quick_records= table_records;
- if (is_best_covering && !is_covering ||
- is_covering && ref_key_quick_rows < select_limit)
+ if ((is_best_covering && !is_covering) ||
+ (is_covering && ref_key_quick_rows < select_limit))
continue;
if (table->quick_keys.is_set(nr))
quick_records= table->quick_rows[nr];
@@ -13417,8 +13440,8 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
*/
if ((order != join->group_list ||
!(join->select_options & SELECT_BIG_RESULT) ||
- select && select->quick &&
- select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX) &&
+ (select && select->quick &&
+ select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)) &&
test_if_skip_sort_order(tab,order,select_limit,0,
is_order_by ? &table->keys_in_use_for_order_by :
&table->keys_in_use_for_group_by))
@@ -13479,9 +13502,24 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
tab->records= table->sort.found_records; // For SQL_CALC_ROWS
if (select)
{
+ /*
+ We need to preserve tablesort's output resultset here, because
+ QUICK_INDEX_MERGE_SELECT::~QUICK_INDEX_MERGE_SELECT (called by
+ SQL_SELECT::cleanup()) may free it assuming it's the result of the quick
+ select operation that we no longer need. Note that all the other parts of
+ this data structure are cleaned up when
+ QUICK_INDEX_MERGE_SELECT::get_next encounters end of data, so the next
+ SQL_SELECT::cleanup() call changes sort.io_cache alone.
+ */
+ IO_CACHE *tablesort_result_cache;
+
+ tablesort_result_cache= table->sort.io_cache;
+ table->sort.io_cache= NULL;
+
select->cleanup(); // filesort did select
tab->select= 0;
table->quick_keys.clear_all(); // as far as we cleanup select->quick
+ table->sort.io_cache= tablesort_result_cache;
}
tab->select_cond=0;
tab->last_inner= 0;
@@ -13855,7 +13893,7 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length,
pos->field= ((Item_sum*) item)->get_tmp_table_field();
else if (item->type() == Item::COPY_STR_ITEM)
{ // Blob patch
- pos->item= ((Item_copy_string*) item)->item;
+ pos->item= ((Item_copy*) item)->get_item();
}
else
pos->item= *order->item;
@@ -14244,8 +14282,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
/* Lookup the current GROUP field in the FROM clause. */
order_item_type= order_item->type();
from_field= (Field*) not_found_field;
- if (is_group_field &&
- order_item_type == Item::FIELD_ITEM ||
+ if ((is_group_field &&
+ order_item_type == Item::FIELD_ITEM) ||
order_item_type == Item::REF_ITEM)
{
from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables,
@@ -14680,7 +14718,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables)
if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT)))
DBUG_RETURN(0);
- for (; !(map & tables->table->map); tables= tables->next_leaf);
+ for (; !(map & tables->table->map); tables= tables->next_leaf) ;
if (map != tables->table->map)
DBUG_RETURN(0); // More than one table
DBUG_PRINT("exit",("sort by table: %d",tables->table->tablenr));
@@ -14926,7 +14964,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
pos= item;
if (item->field->flags & BLOB_FLAG)
{
- if (!(pos= new Item_copy_string(pos)))
+ if (!(pos= Item_copy::create(pos)))
goto err;
/*
Item_copy_string::copy for function can call
@@ -14980,7 +15018,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
on how the value is to be used: In some cases this may be an
argument in a group function, like: IF(ISNULL(col),0,COUNT(*))
*/
- if (!(pos=new Item_copy_string(pos)))
+ if (!(pos= Item_copy::create(pos)))
goto err;
if (i < border) // HAVING, ORDER and GROUP BY
{
@@ -15033,8 +15071,8 @@ copy_fields(TMP_TABLE_PARAM *param)
(*ptr->do_copy)(ptr);
List_iterator_fast<Item> it(param->copy_funcs);
- Item_copy_string *item;
- while ((item = (Item_copy_string*) it++))
+ Item_copy *item;
+ while ((item = (Item_copy*) it++))
item->copy();
}
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index d08b3a248c4..d07e951bfd1 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -601,7 +601,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if (open_normal_and_derived_tables(thd, table_list, 0))
{
if (!table_list->view ||
- thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
+ (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID))
DBUG_RETURN(TRUE);
/*
@@ -2819,8 +2819,8 @@ make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
LOOKUP_FIELD_VALUES *lookup_field_vals,
bool with_i_schema, LEX_STRING *db_name)
{
- char path[FN_REFLEN];
- build_table_filename(path, sizeof(path), db_name->str, "", "", 0);
+ char path[FN_REFLEN + 1];
+ build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0);
if (!lookup_field_vals->wild_table_value &&
lookup_field_vals->table_value.str)
{
@@ -2982,8 +2982,8 @@ static int fill_schema_table_names(THD *thd, TABLE *table,
else
{
enum legacy_db_type not_used;
- char path[FN_REFLEN];
- (void) build_table_filename(path, sizeof(path), db_name->str,
+ char path[FN_REFLEN + 1];
+ (void) build_table_filename(path, sizeof(path) - 1, db_name->str,
table_name->str, reg_ext, 0);
switch (mysql_frm_type(thd, path, &not_used)) {
case FRMTYPE_ERROR:
@@ -3238,10 +3238,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
if lookup value is empty string then
it's impossible table name or db name
*/
- if (lookup_field_vals.db_value.str &&
- !lookup_field_vals.db_value.str[0] ||
- lookup_field_vals.table_value.str &&
- !lookup_field_vals.table_value.str[0])
+ if ((lookup_field_vals.db_value.str &&
+ !lookup_field_vals.db_value.str[0]) ||
+ (lookup_field_vals.table_value.str &&
+ !lookup_field_vals.table_value.str[0]))
{
error= 0;
goto err;
@@ -3470,7 +3470,7 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
MY_STAT stat_info;
if (!lookup_field_vals.db_value.str[0])
DBUG_RETURN(0);
- path_len= build_table_filename(path, sizeof(path),
+ path_len= build_table_filename(path, sizeof(path) - 1,
lookup_field_vals.db_value.str, "", "", 0);
path[path_len-1]= 0;
if (!my_stat(path,&stat_info,MYF(0)))
@@ -4116,10 +4116,10 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
TYPE_ENUM_PROCEDURE))
return 0;
- if (lex->sql_command == SQLCOM_SHOW_STATUS_PROC &&
- proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE ||
- lex->sql_command == SQLCOM_SHOW_STATUS_FUNC &&
- proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION ||
+ if ((lex->sql_command == SQLCOM_SHOW_STATUS_PROC &&
+ proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE) ||
+ (lex->sql_command == SQLCOM_SHOW_STATUS_FUNC &&
+ proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION) ||
(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0)
{
restore_record(table, s->default_values);
@@ -7071,6 +7071,12 @@ bool show_create_trigger(THD *thd, const sp_name *trg_name)
if (!lst)
return TRUE;
+ if (check_table_access(thd, TRIGGER_ACL, lst, 1, TRUE))
+ {
+ my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "TRIGGER");
+ return TRUE;
+ }
+
/*
Open the table by name in order to load Table_triggers_list object.
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index 1dd7b55d136..7759985ba85 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -322,12 +322,24 @@ bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
return copy_aligned(str, arg_length, offset, cs);
}
- /* Copy with charset conversion */
+
+/**
+ Copies the character data into this String, with optional character set
+ conversion.
+
+ @return
+ FALSE ok
+ TRUE Could not allocate result buffer
+
+*/
bool String::copy(const char *str, uint32 arg_length,
CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
{
uint32 offset;
+
+ DBUG_ASSERT(!str || str != Ptr);
+
if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
{
*errors= 0;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 29d43155778..e752421223a 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -68,6 +68,234 @@ static void wait_for_kill_signal(THD *thd)
#endif
+/**
+ @brief Helper function for explain_filename
+*/
+static char* add_identifier(char *to_p, const char * end_p,
+ const char* name, uint name_len, int errcode)
+{
+ uint res;
+ uint errors;
+ const char *conv_name;
+ char tmp_name[FN_REFLEN];
+ char conv_string[FN_REFLEN];
+
+ DBUG_ENTER("add_identifier");
+ if (!name[name_len])
+ conv_name= name;
+ else
+ {
+ strnmov(tmp_name, name, name_len);
+ tmp_name[name_len]= 0;
+ conv_name= tmp_name;
+ }
+ res= strconvert(&my_charset_filename, conv_name, system_charset_info,
+ conv_string, FN_REFLEN, &errors);
+ if (!res || errors)
+ conv_name= name;
+ else
+ {
+ DBUG_PRINT("info", ("conv '%s' -> '%s'", conv_name, conv_string));
+ conv_name= conv_string;
+ }
+
+ if (errcode)
+ to_p+= my_snprintf(to_p, end_p - to_p, ER(errcode), conv_name);
+ else
+ to_p+= my_snprintf(to_p, end_p - to_p, "`%s`", conv_name);
+ return to_p;
+}
+
+
+/**
+ @brief Explain a path name by split it to database, table etc.
+
+ @details Break down the path name to its logic parts
+ (database, table, partition, subpartition).
+ filename_to_tablename cannot be used on partitions, due to the #P# part.
+ There can be up to 6 '#', #P# for partition, #SP# for subpartition
+ and #TMP# or #REN# for temporary or renamed partitions.
+ This should be used when something should be presented to a user in a
+ diagnostic, error etc. when it would be useful to know what a particular
+ file [and directory] means. Such as SHOW ENGINE STATUS, error messages etc.
+
+ @param from Path name in my_charset_filename
+ Null terminated in my_charset_filename, normalized
+ to use '/' as directory separation character.
+ @param to Explained name in system_charset_info
+ @param to_length Size of to buffer
+ @param explain_mode Requested output format.
+ EXPLAIN_ALL_VERBOSE ->
+ [Database `db`, ]Table `tbl`[,[ Temporary| Renamed]
+ Partition `p` [, Subpartition `sp`]]
+ EXPLAIN_PARTITIONS_VERBOSE -> `db`.`tbl`
+ [[ Temporary| Renamed] Partition `p`
+ [, Subpartition `sp`]]
+ EXPLAIN_PARTITIONS_AS_COMMENT -> `db`.`tbl` |*
+ [,[ Temporary| Renamed] Partition `p`
+ [, Subpartition `sp`]] *|
+ (| is really a /, and it is all in one line)
+
+ @retval Length of returned string
+*/
+
+uint explain_filename(const char *from,
+ char *to,
+ uint to_length,
+ enum_explain_filename_mode explain_mode)
+{
+ uint res= 0;
+ char *to_p= to;
+ char *end_p= to_p + to_length;
+ const char *db_name= NULL;
+ int db_name_len= 0;
+ const char *table_name;
+ int table_name_len= 0;
+ const char *part_name= NULL;
+ int part_name_len= 0;
+ const char *subpart_name= NULL;
+ int subpart_name_len= 0;
+ enum enum_file_name_type {NORMAL, TEMP, RENAMED} name_type= NORMAL;
+ const char *tmp_p;
+ DBUG_ENTER("explain_filename");
+ DBUG_PRINT("enter", ("from '%s'", from));
+ tmp_p= from;
+ table_name= from;
+ /*
+ If '/' then take last directory part as database.
+ '/' is the directory separator, not FN_LIB_CHAR
+ */
+ while ((tmp_p= strchr(tmp_p, '/')))
+ {
+ db_name= table_name;
+ /* calculate the length */
+ db_name_len= tmp_p - db_name;
+ tmp_p++;
+ table_name= tmp_p;
+ }
+ tmp_p= table_name;
+ while (!res && (tmp_p= strchr(tmp_p, '#')))
+ {
+ tmp_p++;
+ switch (tmp_p[0]) {
+ case 'P':
+ case 'p':
+ if (tmp_p[1] == '#')
+ part_name= tmp_p + 2;
+ else
+ res= 1;
+ tmp_p+= 2;
+ break;
+ case 'S':
+ case 's':
+ if ((tmp_p[1] == 'P' || tmp_p[1] == 'p') && tmp_p[2] == '#')
+ {
+ part_name_len= tmp_p - part_name - 1;
+ subpart_name= tmp_p + 3;
+ }
+ else
+ res= 2;
+ tmp_p+= 3;
+ break;
+ case 'T':
+ case 't':
+ if ((tmp_p[1] == 'M' || tmp_p[1] == 'm') &&
+ (tmp_p[2] == 'P' || tmp_p[2] == 'p') &&
+ tmp_p[3] == '#' && !tmp_p[4])
+ name_type= TEMP;
+ else
+ res= 3;
+ tmp_p+= 4;
+ break;
+ case 'R':
+ case 'r':
+ if ((tmp_p[1] == 'E' || tmp_p[1] == 'e') &&
+ (tmp_p[2] == 'N' || tmp_p[2] == 'n') &&
+ tmp_p[3] == '#' && !tmp_p[4])
+ name_type= RENAMED;
+ else
+ res= 4;
+ tmp_p+= 4;
+ break;
+ default:
+ res= 5;
+ }
+ }
+ if (res)
+ {
+ /* Better to give something back if we fail parsing, than nothing at all */
+ DBUG_PRINT("info", ("Error in explain_filename: %u", res));
+ sql_print_warning("Invalid (old?) table or database name '%s'", from);
+ DBUG_RETURN(my_snprintf(to, to_length,
+ "<result %u when explaining filename '%s'>",
+ res, from));
+ }
+ if (part_name)
+ {
+ table_name_len= part_name - table_name - 3;
+ if (subpart_name)
+ subpart_name_len= strlen(subpart_name);
+ else
+ part_name_len= strlen(part_name);
+ if (name_type != NORMAL)
+ {
+ if (subpart_name)
+ subpart_name_len-= 5;
+ else
+ part_name_len-= 5;
+ }
+ }
+ if (db_name)
+ {
+ if (explain_mode == EXPLAIN_ALL_VERBOSE)
+ {
+ to_p= add_identifier(to_p, end_p, db_name, db_name_len,
+ ER_DATABASE_NAME);
+ to_p= strnmov(to_p, ", ", end_p - to_p);
+ }
+ else
+ {
+ to_p= add_identifier(to_p, end_p, db_name, db_name_len, 0);
+ to_p= strnmov(to_p, ".", end_p - to_p);
+ }
+ }
+ if (explain_mode == EXPLAIN_ALL_VERBOSE)
+ to_p= add_identifier(to_p, end_p, table_name, table_name_len,
+ ER_TABLE_NAME);
+ else
+ to_p= add_identifier(to_p, end_p, table_name, table_name_len, 0);
+ if (part_name)
+ {
+ if (explain_mode == EXPLAIN_PARTITIONS_AS_COMMENT)
+ to_p= strnmov(to_p, " /* ", end_p - to_p);
+ else if (explain_mode == EXPLAIN_PARTITIONS_VERBOSE)
+ to_p= strnmov(to_p, " ", end_p - to_p);
+ else
+ to_p= strnmov(to_p, ", ", end_p - to_p);
+ if (name_type != NORMAL)
+ {
+ if (name_type == TEMP)
+ to_p= strnmov(to_p, ER(ER_TEMPORARY_NAME), end_p - to_p);
+ else
+ to_p= strnmov(to_p, ER(ER_RENAMED_NAME), end_p - to_p);
+ to_p= strnmov(to_p, " ", end_p - to_p);
+ }
+ to_p= add_identifier(to_p, end_p, part_name, part_name_len,
+ ER_PARTITION_NAME);
+ if (subpart_name)
+ {
+ to_p= strnmov(to_p, ", ", end_p - to_p);
+ to_p= add_identifier(to_p, end_p, subpart_name, subpart_name_len,
+ ER_SUBPARTITION_NAME);
+ }
+ if (explain_mode == EXPLAIN_PARTITIONS_AS_COMMENT)
+ to_p= strnmov(to_p, " */", end_p - to_p);
+ }
+ DBUG_PRINT("exit", ("to '%s'", to));
+ DBUG_RETURN(to_p - to);
+}
+
+
/*
Translate a file name to a table name (WL #1324).
@@ -1287,7 +1515,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
/*
Build shadow frm file name
*/
- build_table_shadow_filename(shadow_path, sizeof(shadow_path), lpt);
+ build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt);
strxmov(shadow_frm_name, shadow_path, reg_ext, NullS);
if (flags & WFRM_WRITE_SHADOW)
{
@@ -1362,7 +1590,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
/*
Build frm file name
*/
- build_table_filename(path, sizeof(path), lpt->db,
+ build_table_filename(path, sizeof(path) - 1, lpt->db,
lpt->table_name, "", 0);
strxmov(frm_name, path, reg_ext, NullS);
/*
@@ -1460,10 +1688,13 @@ void write_bin_log(THD *thd, bool clear_error,
{
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (clear_error)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, TRUE);
thd->binlog_query(THD::STMT_QUERY_TYPE,
- query, query_length, FALSE, FALSE, THD::NOT_KILLED);
+ query, query_length, FALSE, FALSE, errcode);
}
}
@@ -1561,7 +1792,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool dont_log_query)
{
TABLE_LIST *table;
- char path[FN_REFLEN], *alias;
+ char path[FN_REFLEN + 1], *alias;
uint path_length;
String wrong_tables;
int error= 0;
@@ -1691,13 +1922,14 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
}
alias= (lower_case_table_names == 2) ? table->alias : table->table_name;
/* remove .frm file and engine files */
- path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext,
+ path_length= build_table_filename(path, sizeof(path) - 1, db, alias,
+ reg_ext,
table->internal_tmp_table ?
FN_IS_TMP : 0);
}
if (drop_temporary ||
- (table_type == NULL &&
- (access(path, F_OK) &&
+ ((table_type == NULL &&
+ access(path, F_OK) &&
ha_create_table_from_engine(thd, db, alias)) ||
(!drop_view &&
mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
@@ -1779,7 +2011,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
if (!dont_log_query)
{
if (!thd->current_stmt_binlog_row_based ||
- non_temp_tables_count > 0 && !tmp_table_deleted)
+ (non_temp_tables_count > 0 && !tmp_table_deleted))
{
/*
In this case, we are either using statement-based
@@ -1847,11 +2079,11 @@ err_with_placeholders:
bool quick_rm_table(handlerton *base,const char *db,
const char *table_name, uint flags)
{
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
bool error= 0;
DBUG_ENTER("quick_rm_table");
- uint path_length= build_table_filename(path, sizeof(path),
+ uint path_length= build_table_filename(path, sizeof(path) - 1,
db, table_name, reg_ext, flags);
if (my_delete(path,MYF(0)))
error= 1; /* purecov: inspected */
@@ -2488,8 +2720,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
/* Don't pack rows in old tables if the user has requested this */
if ((sql_field->flags & BLOB_FLAG) ||
- sql_field->sql_type == MYSQL_TYPE_VARCHAR &&
- create_info->row_type != ROW_TYPE_FIXED)
+ (sql_field->sql_type == MYSQL_TYPE_VARCHAR &&
+ create_info->row_type != ROW_TYPE_FIXED))
(*db_options)|= HA_OPTION_PACK_RECORD;
it2.rewind();
}
@@ -2958,7 +3190,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
sql_field->sql_type == MYSQL_TYPE_VARCHAR ||
sql_field->pack_flag & FIELDFLAG_BLOB)))
{
- if (column_nr == 0 && (sql_field->pack_flag & FIELDFLAG_BLOB) ||
+ if ((column_nr == 0 && (sql_field->pack_flag & FIELDFLAG_BLOB)) ||
sql_field->sql_type == MYSQL_TYPE_VARCHAR)
key_info->flags|= HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
else
@@ -3126,7 +3358,7 @@ static bool prepare_blob_field(THD *thd, Create_field *sql_field)
}
sql_field->sql_type= MYSQL_TYPE_BLOB;
sql_field->flags|= BLOB_FLAG;
- sprintf(warn_buff, ER(ER_AUTO_CONVERT), sql_field->field_name,
+ my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_AUTO_CONVERT), sql_field->field_name,
(sql_field->charset == &my_charset_bin) ? "VARBINARY" : "VARCHAR",
(sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT");
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
@@ -3240,7 +3472,7 @@ bool mysql_create_table_no_lock(THD *thd,
bool internal_tmp_table,
uint select_field_count)
{
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
uint path_length;
const char *alias;
uint db_options, key_count;
@@ -3448,7 +3680,7 @@ bool mysql_create_table_no_lock(THD *thd,
}
else
{
- path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext,
+ path_length= build_table_filename(path, sizeof(path) - 1, db, alias, reg_ext,
internal_tmp_table ? FN_IS_TMP : 0);
}
@@ -3762,7 +3994,8 @@ mysql_rename_table(handlerton *base, const char *old_db,
const char *new_name, uint flags)
{
THD *thd= current_thd;
- char from[FN_REFLEN], to[FN_REFLEN], lc_from[FN_REFLEN], lc_to[FN_REFLEN];
+ char from[FN_REFLEN + 1], to[FN_REFLEN + 1],
+ lc_from[FN_REFLEN + 1], lc_to[FN_REFLEN + 1];
char *from_base= from, *to_base= to;
char tmp_name[NAME_LEN+1];
handler *file;
@@ -3774,9 +4007,9 @@ mysql_rename_table(handlerton *base, const char *old_db,
file= (base == NULL ? 0 :
get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base));
- build_table_filename(from, sizeof(from), old_db, old_name, "",
+ build_table_filename(from, sizeof(from) - 1, old_db, old_name, "",
flags & FN_FROM_IS_TMP);
- build_table_filename(to, sizeof(to), new_db, new_name, "",
+ build_table_filename(to, sizeof(to) - 1, new_db, new_name, "",
flags & FN_TO_IS_TMP);
/*
@@ -3789,13 +4022,13 @@ mysql_rename_table(handlerton *base, const char *old_db,
{
strmov(tmp_name, old_name);
my_casedn_str(files_charset_info, tmp_name);
- build_table_filename(lc_from, sizeof(lc_from), old_db, tmp_name, "",
+ build_table_filename(lc_from, sizeof(lc_from) - 1, old_db, tmp_name, "",
flags & FN_FROM_IS_TMP);
from_base= lc_from;
strmov(tmp_name, new_name);
my_casedn_str(files_charset_info, tmp_name);
- build_table_filename(lc_to, sizeof(lc_to), new_db, tmp_name, "",
+ build_table_filename(lc_to, sizeof(lc_to) - 1, new_db, tmp_name, "",
flags & FN_TO_IS_TMP);
to_base= lc_to;
}
@@ -3926,16 +4159,16 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table,
else
{
char* backup_dir= thd->lex->backup_dir;
- char src_path[FN_REFLEN], dst_path[FN_REFLEN], uname[FN_REFLEN];
+ char src_path[FN_REFLEN], dst_path[FN_REFLEN + 1], uname[FN_REFLEN];
char* table_name= table->table_name;
char* db= table->db;
- VOID(tablename_to_filename(table->table_name, uname, sizeof(uname)));
+ VOID(tablename_to_filename(table->table_name, uname, sizeof(uname) - 1));
if (fn_format_relative_to_data_home(src_path, uname, backup_dir, reg_ext))
DBUG_RETURN(-1); // protect buffer overflow
- build_table_filename(dst_path, sizeof(dst_path),
+ build_table_filename(dst_path, sizeof(dst_path) - 1,
db, table_name, reg_ext, 0);
if (lock_and_wait_for_table_name(thd,table))
@@ -4547,7 +4780,7 @@ send_result_message:
const char *err_msg= thd->main_da.message();
if (!thd->vio_ok())
{
- sql_print_error(err_msg);
+ sql_print_error("%s", err_msg);
}
else
{
@@ -4857,7 +5090,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
HA_CREATE_INFO *create_info)
{
TABLE *name_lock= 0;
- char src_path[FN_REFLEN], dst_path[FN_REFLEN];
+ char src_path[FN_REFLEN], dst_path[FN_REFLEN + 1];
uint dst_path_length;
char *db= table->db;
char *table_name= table->table_name;
@@ -4867,7 +5100,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
#ifdef WITH_PARTITION_STORAGE_ENGINE
char tmp_path[FN_REFLEN];
#endif
- char ts_name[FN_LEN];
+ char ts_name[FN_LEN + 1];
DBUG_ENTER("mysql_create_like_table");
@@ -4916,7 +5149,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
goto err;
if (!name_lock)
goto table_exists;
- dst_path_length= build_table_filename(dst_path, sizeof(dst_path),
+ dst_path_length= build_table_filename(dst_path, sizeof(dst_path) - 1,
db, table_name, reg_ext, 0);
if (!access(dst_path, F_OK))
goto table_exists;
@@ -5314,7 +5547,7 @@ compare_tables(TABLE *table,
create_info->used_fields & HA_CREATE_USED_ENGINE ||
create_info->used_fields & HA_CREATE_USED_CHARSET ||
create_info->used_fields & HA_CREATE_USED_DEFAULT_CHARSET ||
- create_info->used_fields & HA_CREATE_USED_ROW_FORMAT ||
+ (table->s->row_type != create_info->row_type) ||
create_info->used_fields & HA_CREATE_USED_PACK_KEYS ||
create_info->used_fields & HA_CREATE_USED_MAX_ROWS ||
(alter_info->flags & (ALTER_RECREATE | ALTER_FOREIGN_KEY)) ||
@@ -5358,8 +5591,8 @@ compare_tables(TABLE *table,
/* Don't pack rows in old tables if the user has requested this. */
if (create_info->row_type == ROW_TYPE_DYNAMIC ||
(tmp_new_field->flags & BLOB_FLAG) ||
- tmp_new_field->sql_type == MYSQL_TYPE_VARCHAR &&
- create_info->row_type != ROW_TYPE_FIXED)
+ (tmp_new_field->sql_type == MYSQL_TYPE_VARCHAR &&
+ create_info->row_type != ROW_TYPE_FIXED))
create_info->table_options|= HA_OPTION_PACK_RECORD;
/* Check if field was renamed */
@@ -5657,7 +5890,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
if (!create_info->tablespace && create_info->storage_media != HA_SM_MEMORY)
{
- char *tablespace= static_cast<char *>(thd->alloc(FN_LEN));
+ char *tablespace= static_cast<char *>(thd->alloc(FN_LEN + 1));
/*
Regular alter table of disk stored table (no tablespace/storage change)
Copy tablespace name
@@ -6024,10 +6257,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
TABLE *table, *new_table= 0, *name_lock= 0;
int error= 0;
- char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN];
+ char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN + 1];
char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
char index_file[FN_REFLEN], data_file[FN_REFLEN];
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
char reg_path[FN_REFLEN+1];
ha_rows copied,deleted;
handlerton *old_db_type, *new_db_type, *save_old_db_type;
@@ -6040,21 +6273,15 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
#endif
bool need_lock_for_indexes= TRUE;
KEY *key_info_buffer;
- uint index_drop_count;
- uint *index_drop_buffer;
- uint index_add_count;
- uint *index_add_buffer;
- uint candidate_key_count;
+ uint index_drop_count= 0;
+ uint *index_drop_buffer= NULL;
+ uint index_add_count= 0;
+ uint *index_add_buffer= NULL;
+ uint candidate_key_count= 0;
bool committed= 0;
bool no_pk;
DBUG_ENTER("mysql_alter_table");
- LINT_INIT(index_add_count);
- LINT_INIT(index_drop_count);
- LINT_INIT(index_add_buffer);
- LINT_INIT(index_drop_buffer);
- LINT_INIT(candidate_key_count);
-
/*
Check if we attempt to alter mysql.slow_log or
mysql.general_log table and return an error if
@@ -6108,8 +6335,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
db=table_list->db;
if (!new_db || !my_strcasecmp(table_alias_charset, new_db, db))
new_db= db;
- build_table_filename(reg_path, sizeof(reg_path), db, table_name, reg_ext, 0);
- build_table_filename(path, sizeof(path), db, table_name, "", 0);
+ build_table_filename(reg_path, sizeof(reg_path) - 1, db, table_name, reg_ext, 0);
+ build_table_filename(path, sizeof(path) - 1, db, table_name, "", 0);
mysql_ha_rm_tables(thd, table_list, FALSE);
@@ -6140,6 +6367,20 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME))
{
/*
+ The following branch handles "ALTER VIEW v1 /no arguments/;"
+ This feature is not documented one.
+ However, before "OPTIMIZE TABLE t1;" was implemented,
+ ALTER TABLE with no alter_specifications was used to force-rebuild
+ the table. That's why this grammar is allowed. That's why we ignore
+ it for views. So just do nothing in such a case.
+ */
+ if (!new_name)
+ {
+ my_ok(thd);
+ DBUG_RETURN(FALSE);
+ }
+
+ /*
Avoid problems with a rename on a table that we have locked or
if the user is trying to to do this in a transcation context
*/
@@ -6166,7 +6407,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length,
- 0, FALSE, THD::NOT_KILLED);
+ 0, FALSE, 0);
mysql_bin_log.write(&qinfo);
}
my_ok(thd);
@@ -6242,7 +6483,7 @@ view_err:
DBUG_RETURN(TRUE);
}
- build_table_filename(new_name_buff, sizeof(new_name_buff),
+ build_table_filename(new_name_buff, sizeof(new_name_buff) - 1,
new_db, new_name_buff, reg_ext, 0);
if (!access(new_name_buff, F_OK))
{
@@ -6293,7 +6534,10 @@ view_err:
}
if (create_info->row_type == ROW_TYPE_NOT_USED)
+ {
create_info->row_type= table->s->row_type;
+ create_info->used_fields |= HA_CREATE_USED_ROW_FORMAT;
+ }
DBUG_PRINT("info", ("old type: %s new type: %s",
ha_resolve_storage_engine_name(old_db_type),
@@ -6740,9 +6984,9 @@ view_err:
}
else
{
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
/* table is a normal table: Create temporary table in same directory */
- build_table_filename(path, sizeof(path), new_db, tmp_name, "",
+ build_table_filename(path, sizeof(path) - 1, new_db, tmp_name, "",
FN_IS_TMP);
/* Open our intermediate table */
new_table=open_temporary_table(thd, path, new_db, tmp_name,0);
@@ -6972,12 +7216,12 @@ view_err:
}
else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
new_alias, FN_FROM_IS_TMP) ||
- (new_name != table_name || new_db != db) && // we also do rename
+ ((new_name != table_name || new_db != db) && // we also do rename
(need_copy_table != ALTER_TABLE_METADATA_ONLY ||
mysql_rename_table(save_old_db_type, db, table_name, new_db,
new_alias, NO_FRM_RENAME)) &&
Table_triggers_list::change_table_name(thd, db, table_name,
- new_db, new_alias))
+ new_db, new_alias)))
{
/* Try to get everything back. */
error=1;
@@ -7070,7 +7314,7 @@ view_err:
*/
char path[FN_REFLEN];
TABLE *t_table;
- build_table_filename(path, sizeof(path), new_db, table_name, "", 0);
+ build_table_filename(path + 1, sizeof(path) - 1, new_db, table_name, "", 0);
t_table= open_temporary_table(thd, path, new_db, tmp_name, 0);
if (t_table)
{
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 8cab8fff2f3..c055268ecca 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -344,7 +344,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
need second part of condition below, since check_access() function also
checks that db is specified.
*/
- if (!thd->lex->spname->m_db.length || create && !tables->db_length)
+ if (!thd->lex->spname->m_db.length || (create && !tables->db_length))
{
my_error(ER_NO_DB_ERROR, MYF(0));
DBUG_RETURN(TRUE);
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index fd3036e3d80..cbf94ad7181 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -653,10 +653,22 @@ bool st_select_lex_unit::cleanup()
join->tables= 0;
}
error|= fake_select_lex->cleanup();
- if (fake_select_lex->order_list.elements)
+ /*
+ There are two cases when we should clean order items:
+ 1. UNION with SELECTs which all enclosed into braces
+ in this case global_parameters == fake_select_lex
+ 2. UNION where last SELECT is not enclosed into braces
+ in this case global_parameters == 'last select'
+ So we should use global_parameters->order_list for
+ proper order list clean up.
+ Note: global_parameters and fake_select_lex are always
+ initialized for UNION
+ */
+ DBUG_ASSERT(global_parameters);
+ if (global_parameters->order_list.elements)
{
ORDER *ord;
- for (ord= (ORDER*)fake_select_lex->order_list.first; ord; ord= ord->next)
+ for (ord= (ORDER*)global_parameters->order_list.first; ord; ord= ord->next)
(*ord->item)->cleanup();
}
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 1edd6952a34..d7c9fc83270 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -797,12 +797,15 @@ int mysql_update(THD *thd,
{
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (error < 0)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
+
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- transactional_table, FALSE, killed_status) &&
- transactional_table)
+ transactional_table, FALSE, errcode))
{
error=1; // Rollback update
}
@@ -820,7 +823,7 @@ int mysql_update(THD *thd,
if (error < 0)
{
char buff[STRING_BUFFER_USUAL_SIZE];
- sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
+ my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
(ulong) thd->cuted_fields);
thd->row_count_func=
(thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
@@ -1035,7 +1038,6 @@ reopen_tables:
DBUG_RETURN(TRUE);
}
- table->mark_columns_needed_for_update();
DBUG_PRINT("info",("setting table `%s` for update", tl->alias));
/*
If table will be updated we should not downgrade lock for it and
@@ -1282,12 +1284,40 @@ int multi_update::prepare(List<Item> &not_used_values,
}
/*
+ We gather the set of columns read during evaluation of SET expression in
+ TABLE::tmp_set by pointing TABLE::read_set to it and then restore it after
+ setup_fields().
+ */
+ for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf)
+ {
+ TABLE *table= table_ref->table;
+ if (tables_to_update & table->map)
+ {
+ DBUG_ASSERT(table->read_set == &table->def_read_set);
+ table->read_set= &table->tmp_set;
+ bitmap_clear_all(table->read_set);
+ }
+ }
+
+ /*
We have to check values after setup_tables to get covering_keys right in
reference tables
*/
- if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0))
- DBUG_RETURN(1);
+ int error= setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0);
+
+ for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf)
+ {
+ TABLE *table= table_ref->table;
+ if (tables_to_update & table->map)
+ {
+ table->read_set= &table->def_read_set;
+ bitmap_union(table->read_set, &table->tmp_set);
+ }
+ }
+
+ if (error)
+ DBUG_RETURN(1);
/*
Save tables beeing updated in update_tables
@@ -1382,6 +1412,8 @@ int multi_update::prepare(List<Item> &not_used_values,
a row in this table will never be read twice. This is true under
the following conditions:
+ - No column is both written to and read in SET expressions.
+
- We are doing a table scan and the data is in a separate file (MyISAM) or
if we don't update a clustered key.
@@ -1396,6 +1428,9 @@ int multi_update::prepare(List<Item> &not_used_values,
WARNING
This code is a bit dependent of how make_join_readinfo() works.
+ The field table->tmp_set is used for keeping track of which fields are
+ read during evaluation of the SET expression. See multi_update::prepare.
+
RETURN
0 Not safe to update
1 Safe to update
@@ -1416,6 +1451,8 @@ static bool safe_update_on_fly(THD *thd, JOIN_TAB *join_tab,
case JT_REF_OR_NULL:
return !is_key_used(table, join_tab->ref.key, table->write_set);
case JT_ALL:
+ if (bitmap_is_overlapping(&table->tmp_set, table->write_set))
+ return FALSE;
/* If range search on index */
if (join_tab->quick)
return !join_tab->quick->is_keys_used(table->write_set);
@@ -1471,17 +1508,18 @@ multi_update::initialize_tables(JOIN *join)
ORDER group;
TMP_TABLE_PARAM *tmp_param;
- table->mark_columns_needed_for_update();
if (ignore)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
if (table == main_table) // First table in join
{
if (safe_update_on_fly(thd, join->join_tab, table_ref, all_tables))
{
- table_to_update= main_table; // Update table on the fly
+ table->mark_columns_needed_for_update();
+ table_to_update= table; // Update table on the fly
continue;
}
}
+ table->mark_columns_needed_for_update();
table->prepare_for_position();
/*
@@ -1782,7 +1820,7 @@ void multi_update::abort()
{
/* the error was handled or nothing deleted and no side effects return */
if (error_handled ||
- !thd->transaction.stmt.modified_non_trans_table && !updated)
+ (!thd->transaction.stmt.modified_non_trans_table && !updated))
return;
/* Something already updated so we have to invalidate cache */
@@ -1819,9 +1857,10 @@ void multi_update::abort()
got caught and if happens later the killed error is written
into repl event.
*/
+ int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- transactional_tables, FALSE);
+ transactional_tables, FALSE, errcode);
}
thd->transaction.all.modified_non_trans_table= TRUE;
}
@@ -2047,12 +2086,14 @@ bool multi_update::send_eof()
{
if (mysql_bin_log.is_open())
{
+ int errcode= 0;
if (local_error == 0)
thd->clear_error();
+ else
+ errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
- transactional_tables, FALSE, killed_status) &&
- trans_safe)
+ transactional_tables, FALSE, errcode))
{
local_error= 1; // Rollback update
}
@@ -2073,8 +2114,8 @@ bool multi_update::send_eof()
id= thd->arg_of_last_insert_id_function ?
thd->first_successful_insert_id_in_prev_stmt : 0;
- sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
- (ulong) thd->cuted_fields);
+ my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO),
+ (ulong) found, (ulong) updated, (ulong) thd->cuted_fields);
thd->row_count_func=
(thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
::my_ok(thd, (ulong) thd->row_count_func, id, buff);
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 4f207f78688..2a4c5c950fe 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -661,8 +661,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
buff.append(STRING_WITH_LEN(" AS "));
buff.append(views->source.str, views->source.length);
+ int errcode= query_error_code(thd, TRUE);
thd->binlog_query(THD::STMT_QUERY_TYPE,
- buff.ptr(), buff.length(), FALSE, FALSE, THD::NOT_KILLED);
+ buff.ptr(), buff.length(), FALSE, FALSE, errcode);
}
VOID(pthread_mutex_unlock(&LOCK_open));
@@ -800,7 +801,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
char md5[MD5_BUFF_LENGTH];
bool can_be_merged;
- char dir_buff[FN_REFLEN], path_buff[FN_REFLEN];
+ char dir_buff[FN_REFLEN + 1], path_buff[FN_REFLEN + 1];
LEX_STRING dir, file, path;
int error= 0;
DBUG_ENTER("mysql_register_view");
@@ -877,11 +878,11 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
}
loop_out:
/* print file name */
- dir.length= build_table_filename(dir_buff, sizeof(dir_buff),
+ dir.length= build_table_filename(dir_buff, sizeof(dir_buff) - 1,
view->db, "", "", 0);
dir.str= dir_buff;
- path.length= build_table_filename(path_buff, sizeof(path_buff),
+ path.length= build_table_filename(path_buff, sizeof(path_buff) - 1,
view->db, view->table_name, reg_ext, 0);
path.str= path_buff;
@@ -1568,7 +1569,7 @@ err:
bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
{
- char path[FN_REFLEN];
+ char path[FN_REFLEN + 1];
TABLE_LIST *view;
String non_existant_views;
char *wrong_object_db= NULL, *wrong_object_name= NULL;
@@ -1583,7 +1584,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
{
TABLE_SHARE *share;
frm_type_enum type= FRMTYPE_ERROR;
- build_table_filename(path, sizeof(path),
+ build_table_filename(path, sizeof(path) - 1,
view->db, view->table_name, reg_ext, 0);
if (access(path, F_OK) ||
@@ -1928,7 +1929,7 @@ mysql_rename_view(THD *thd,
{
LEX_STRING pathstr;
File_parser *parser;
- char path_buff[FN_REFLEN];
+ char path_buff[FN_REFLEN + 1];
bool error= TRUE;
DBUG_ENTER("mysql_rename_view");
@@ -1941,7 +1942,7 @@ mysql_rename_view(THD *thd,
is_equal(&view_type, parser->type()))
{
TABLE_LIST view_def;
- char dir_buff[FN_REFLEN];
+ char dir_buff[FN_REFLEN + 1];
LEX_STRING dir, file;
/*
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 0b158ff7574..7d6a7ade540 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -5925,7 +5925,7 @@ alter_list_item:
MYSQL_YYABORT;
}
if (check_table_name($3->table.str,$3->table.length) ||
- $3->db.str && check_db_name(&$3->db))
+ ($3->db.str && check_db_name(&$3->db)))
{
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
MYSQL_YYABORT;
@@ -6079,8 +6079,8 @@ slave_until:
| UNTIL_SYM slave_until_opts
{
LEX *lex=Lex;
- if ((lex->mi.log_file_name || lex->mi.pos) &&
- (lex->mi.relay_log_name || lex->mi.relay_log_pos) ||
+ if (((lex->mi.log_file_name || lex->mi.pos) &&
+ (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
!((lex->mi.log_file_name && lex->mi.pos) ||
(lex->mi.relay_log_name && lex->mi.relay_log_pos)))
{
@@ -8493,6 +8493,7 @@ table_factor:
MYSQL_YYABORT;
sel->add_joined_table($$);
lex->pop_context();
+ lex->nest_level--;
}
else if ($4 || $6)
{
@@ -8501,7 +8502,11 @@ table_factor:
MYSQL_YYABORT;
}
else
+ {
+ /* nested join: FROM (t1 JOIN t2 ...),
+ nest_level is the same as in the outer query */
$$= $3;
+ }
}
;
@@ -12118,15 +12123,16 @@ text_or_password:
| PASSWORD '(' TEXT_STRING ')'
{
$$= $3.length ? YYTHD->variables.old_passwords ?
- Item_func_old_password::alloc(YYTHD, $3.str) :
- Item_func_password::alloc(YYTHD, $3.str) :
+ Item_func_old_password::alloc(YYTHD, $3.str, $3.length) :
+ Item_func_password::alloc(YYTHD, $3.str, $3.length) :
$3.str;
if ($$ == NULL)
MYSQL_YYABORT;
}
| OLD_PASSWORD '(' TEXT_STRING ')'
{
- $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str) :
+ $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str,
+ $3.length) :
$3.str;
if ($$ == NULL)
MYSQL_YYABORT;
@@ -12588,7 +12594,7 @@ grant_user:
(char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
if (buff == NULL)
MYSQL_YYABORT;
- make_scrambled_password_323(buff, $4.str);
+ my_make_scrambled_password_323(buff, $4.str, $4.length);
$1->password.str= buff;
$1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
}
@@ -12598,7 +12604,7 @@ grant_user:
(char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
if (buff == NULL)
MYSQL_YYABORT;
- make_scrambled_password(buff, $4.str);
+ my_make_scrambled_password(buff, $4.str, $4.length);
$1->password.str= buff;
$1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH;
}
diff --git a/sql/structs.h b/sql/structs.h
index 0a20eee0e9a..a58c18f97c5 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -107,6 +107,10 @@ typedef struct st_reginfo { /* Extra info about reg */
struct st_join_table *join_tab; /* Used by SELECT() */
enum thr_lock_type lock_type; /* How database is used */
bool not_exists_optimize;
+ /*
+ TRUE <=> range optimizer found that there is no rows satisfying
+ table conditions.
+ */
bool impossible_range;
} REGINFO;
diff --git a/sql/table.cc b/sql/table.cc
index d24ee4c6a27..60a27e136b1 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -464,34 +464,35 @@ inline bool is_system_table_name(const char *name, uint length)
CHARSET_INFO *ci= system_charset_info;
return (
- /* mysql.proc table */
- length == 4 &&
- my_tolower(ci, name[0]) == 'p' &&
- my_tolower(ci, name[1]) == 'r' &&
- my_tolower(ci, name[2]) == 'o' &&
- my_tolower(ci, name[3]) == 'c' ||
-
- length > 4 &&
- (
- /* one of mysql.help* tables */
- my_tolower(ci, name[0]) == 'h' &&
- my_tolower(ci, name[1]) == 'e' &&
- my_tolower(ci, name[2]) == 'l' &&
- my_tolower(ci, name[3]) == 'p' ||
-
- /* one of mysql.time_zone* tables */
- my_tolower(ci, name[0]) == 't' &&
- my_tolower(ci, name[1]) == 'i' &&
- my_tolower(ci, name[2]) == 'm' &&
- my_tolower(ci, name[3]) == 'e' ||
-
- /* mysql.event table */
- my_tolower(ci, name[0]) == 'e' &&
- my_tolower(ci, name[1]) == 'v' &&
- my_tolower(ci, name[2]) == 'e' &&
- my_tolower(ci, name[3]) == 'n' &&
- my_tolower(ci, name[4]) == 't'
- )
+ /* mysql.proc table */
+ (length == 4 &&
+ my_tolower(ci, name[0]) == 'p' &&
+ my_tolower(ci, name[1]) == 'r' &&
+ my_tolower(ci, name[2]) == 'o' &&
+ my_tolower(ci, name[3]) == 'c') ||
+
+ (length > 4 &&
+ (
+ /* one of mysql.help* tables */
+ (my_tolower(ci, name[0]) == 'h' &&
+ my_tolower(ci, name[1]) == 'e' &&
+ my_tolower(ci, name[2]) == 'l' &&
+ my_tolower(ci, name[3]) == 'p') ||
+
+ /* one of mysql.time_zone* tables */
+ (my_tolower(ci, name[0]) == 't' &&
+ my_tolower(ci, name[1]) == 'i' &&
+ my_tolower(ci, name[2]) == 'm' &&
+ my_tolower(ci, name[3]) == 'e') ||
+
+ /* mysql.event table */
+ (my_tolower(ci, name[0]) == 'e' &&
+ my_tolower(ci, name[1]) == 'v' &&
+ my_tolower(ci, name[2]) == 'e' &&
+ my_tolower(ci, name[3]) == 'n' &&
+ my_tolower(ci, name[4]) == 't')
+ )
+ )
);
}
@@ -779,7 +780,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
strpos=disk_buff+6;
if (!(rec_per_key= (ulong*) alloc_root(&share->mem_root,
- sizeof(ulong*)*key_parts)))
+ sizeof(ulong)*key_parts)))
goto err;
for (i=0 ; i < keys ; i++, keyinfo++)
@@ -3314,8 +3315,8 @@ bool TABLE_LIST::prep_check_option(THD *thd, uint8 check_opt_type)
{
const char *save_where= thd->where;
thd->where= "check option";
- if (!check_option->fixed &&
- check_option->fix_fields(thd, &check_option) ||
+ if ((!check_option->fixed &&
+ check_option->fix_fields(thd, &check_option)) ||
check_option->check_cols(1))
{
DBUG_RETURN(TRUE);
@@ -3341,6 +3342,7 @@ void TABLE_LIST::hide_view_error(THD *thd)
if (thd->main_da.sql_errno() == ER_BAD_FIELD_ERROR ||
thd->main_da.sql_errno() == ER_SP_DOES_NOT_EXIST ||
+ thd->main_da.sql_errno() == ER_FUNC_INEXISTENT_NAME_COLLISION ||
thd->main_da.sql_errno() == ER_PROCACCESS_DENIED_ERROR ||
thd->main_da.sql_errno() == ER_COLUMNACCESS_DENIED_ERROR ||
thd->main_da.sql_errno() == ER_TABLEACCESS_DENIED_ERROR ||
@@ -4030,7 +4032,7 @@ void Field_iterator_table_ref::set_field_iterator()
/* Necesary, but insufficient conditions. */
DBUG_ASSERT(table_ref->is_natural_join ||
table_ref->nested_join ||
- table_ref->join_columns &&
+ (table_ref->join_columns &&
/* This is a merge view. */
((table_ref->field_translation &&
table_ref->join_columns->elements ==
@@ -4039,7 +4041,7 @@ void Field_iterator_table_ref::set_field_iterator()
/* This is stored table or a tmptable view. */
(!table_ref->field_translation &&
table_ref->join_columns->elements ==
- table_ref->table->s->fields)));
+ table_ref->table->s->fields))));
field_it= &natural_join_it;
DBUG_PRINT("info",("field_it for '%s' is Field_iterator_natural_join",
table_ref->alias));
diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc
index 6bf43b51df0..0764fe8be33 100644
--- a/sql/thr_malloc.cc
+++ b/sql/thr_malloc.cc
@@ -21,7 +21,7 @@
extern "C" {
void sql_alloc_error_handler(void)
{
- sql_print_error(ER(ER_OUT_OF_RESOURCES));
+ sql_print_error("%s", ER(ER_OUT_OF_RESOURCES));
THD *thd= current_thd;
if (thd)
diff --git a/sql/time.cc b/sql/time.cc
index a6619cf4cee..962b65e454c 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -111,8 +111,8 @@ uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year)
if (l_time->month == 1 && l_time->day <= 7-weekday)
{
if (!week_year &&
- (first_weekday && weekday != 0 ||
- !first_weekday && weekday >= 4))
+ ((first_weekday && weekday != 0) ||
+ (!first_weekday && weekday >= 4)))
return 0;
week_year= 1;
(*year)--;
@@ -129,8 +129,8 @@ uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year)
if (week_year && days >= 52*7)
{
weekday= (weekday + calc_days_in_year(*year)) % 7;
- if (!first_weekday && weekday < 4 ||
- first_weekday && weekday == 0)
+ if ((!first_weekday && weekday < 4) ||
+ (first_weekday && weekday == 0))
{
(*year)++;
return 1;
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 2a94e179600..c7a4ad049ec 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -447,8 +447,8 @@ prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage)
}
if (end_t == MY_TIME_T_MAX ||
- (cur_off_and_corr > 0) &&
- (end_t >= MY_TIME_T_MAX - cur_off_and_corr))
+ ((cur_off_and_corr > 0) &&
+ (end_t >= MY_TIME_T_MAX - cur_off_and_corr)))
/* end of t space */
break;
diff --git a/sql/uniques.cc b/sql/uniques.cc
index 858bedb04cd..7b6b628f924 100644
--- a/sql/uniques.cc
+++ b/sql/uniques.cc
@@ -603,9 +603,9 @@ bool Unique::get(TABLE *table)
outfile=table->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
MYF(MY_ZEROFILL));
- if (!outfile || ! my_b_inited(outfile) &&
+ if (!outfile || (! my_b_inited(outfile) &&
open_cached_file(outfile,mysql_tmpdir,TEMP_PREFIX,READ_RECORD_BUFFER,
- MYF(MY_WME)))
+ MYF(MY_WME))))
return 1;
reinit_io_cache(outfile,WRITE_CACHE,0L,0,0);
diff --git a/sql/unireg.cc b/sql/unireg.cc
index 51293184ad8..68a352e4a44 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -37,8 +37,7 @@ static bool pack_header(uchar *forminfo,enum legacy_db_type table_type,
List<Create_field> &create_fields,
uint info_length, uint screens, uint table_options,
ulong data_offset, handler *file);
-static uint get_interval_id(uint *int_count,List<Create_field> &create_fields,
- Create_field *last_field);
+static uint get_interval_id(uint *,List<Create_field> &, Create_field *);
static bool pack_fields(File file, List<Create_field> &create_fields,
ulong data_offset);
static bool make_empty_rec(THD *thd, int file, enum legacy_db_type table_type,