summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorGuilhem Bichot <guilhem@mysql.com>2008-11-21 15:21:50 +0100
committerGuilhem Bichot <guilhem@mysql.com>2008-11-21 15:21:50 +0100
commit33b194c36ec28528fd349dd17412848de2f1171c (patch)
tree68cba4897925b9395dd0bfe53b5b95a777d78637 /sql
parent8d96bcda72df224f7a656cbcc1535a027bada75f (diff)
parent1d521f6c20881997c9162bd11cadcbc77d20520b (diff)
downloadmariadb-git-33b194c36ec28528fd349dd17412848de2f1171c.tar.gz
Merge of 5.1-main into 5.1-maria. There were no changes to storage/myisam, or mysql-test/t/*myisam*.
However there were three new tests mysql-test/suite/parts/t/partition*myisam.test, of which I make here copies for Maria.
Diffstat (limited to 'sql')
-rwxr-xr-xsql/CMakeLists.txt14
-rw-r--r--sql/MSG00001.binbin0 -> 184 bytes
-rw-r--r--sql/Makefile.am6
-rw-r--r--sql/event_db_repository.cc14
-rw-r--r--sql/event_parse_data.cc44
-rw-r--r--sql/event_parse_data.h10
-rw-r--r--sql/event_scheduler.cc13
-rw-r--r--sql/field.cc50
-rw-r--r--sql/field.h12
-rw-r--r--sql/ha_ndbcluster.cc25
-rw-r--r--sql/ha_partition.cc832
-rw-r--r--sql/ha_partition.h155
-rw-r--r--sql/handler.cc136
-rw-r--r--sql/handler.h31
-rw-r--r--sql/item.cc77
-rw-r--r--sql/item.h7
-rw-r--r--sql/item_cmpfunc.cc13
-rw-r--r--sql/item_func.cc424
-rw-r--r--sql/item_func.h52
-rw-r--r--sql/item_sum.cc37
-rw-r--r--sql/item_sum.h25
-rw-r--r--sql/key.cc144
-rw-r--r--sql/lock.cc2
-rw-r--r--sql/log.cc11
-rw-r--r--sql/log_event.cc69
-rw-r--r--sql/log_event_old.cc47
-rw-r--r--sql/message.h55
-rw-r--r--sql/message.mc8
-rw-r--r--sql/message.rc2
-rw-r--r--sql/mysql_priv.h5
-rw-r--r--sql/mysqld.cc94
-rw-r--r--sql/opt_range.cc88
-rw-r--r--sql/opt_sum.cc6
-rw-r--r--sql/parse_file.cc24
-rw-r--r--sql/parse_file.h5
-rw-r--r--sql/partition_info.cc10
-rw-r--r--sql/partition_info.h5
-rw-r--r--sql/set_var.cc130
-rw-r--r--sql/set_var.h1
-rw-r--r--sql/share/errmsg.txt18
-rw-r--r--sql/sp_head.cc13
-rw-r--r--sql/sql_base.cc135
-rw-r--r--sql/sql_cache.cc3
-rw-r--r--sql/sql_class.cc88
-rw-r--r--sql/sql_class.h28
-rw-r--r--sql/sql_db.cc17
-rw-r--r--sql/sql_delete.cc6
-rw-r--r--sql/sql_error.cc8
-rw-r--r--sql/sql_insert.cc36
-rw-r--r--sql/sql_lex.cc13
-rw-r--r--sql/sql_lex.h11
-rw-r--r--sql/sql_load.cc4
-rw-r--r--sql/sql_parse.cc131
-rw-r--r--sql/sql_partition.cc324
-rw-r--r--sql/sql_plugin.cc8
-rw-r--r--sql/sql_select.cc41
-rw-r--r--sql/sql_select.h2
-rw-r--r--sql/sql_show.cc68
-rw-r--r--sql/sql_show.h2
-rw-r--r--sql/sql_table.cc168
-rw-r--r--sql/sql_union.cc1
-rw-r--r--sql/sql_update.cc35
-rw-r--r--sql/sql_view.cc30
-rw-r--r--sql/sql_yacc.yy21
-rw-r--r--sql/table.cc24
-rw-r--r--sql/table.h11
66 files changed, 2909 insertions, 1020 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 5da1285f29a..83872803dd4 100755
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -27,9 +27,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/zlib
)
-SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/message.rc
- ${CMAKE_SOURCE_DIR}/sql/message.h
- ${CMAKE_SOURCE_DIR}/sql/sql_yacc.h
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/sql_yacc.h
${CMAKE_SOURCE_DIR}/sql/sql_yacc.cc
${CMAKE_SOURCE_DIR}/include/mysql_version.h
${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc
@@ -138,14 +136,6 @@ ADD_CUSTOM_COMMAND(
--output=sql_yacc.cc sql_yacc.yy
DEPENDS ${PROJECT_SOURCE_DIR}/sql/sql_yacc.yy)
-IF(WIN32)
- # Windows message file
- ADD_CUSTOM_COMMAND(
- OUTPUT ${PROJECT_SOURCE_DIR}/sql/message.h
-# ${PROJECT_SOURCE_DIR}/sql/message.rc
- COMMAND mc ARGS message.mc
- DEPENDS ${PROJECT_SOURCE_DIR}/sql/message.mc)
-ENDIF(WIN32)
# Gen_lex_hash
ADD_EXECUTABLE(gen_lex_hash gen_lex_hash.cc)
@@ -168,7 +158,7 @@ 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;message.rc;message.h;sql_yacc.h;sql_yacc.cc")
+ "lex_hash.h;sql_yacc.h;sql_yacc.cc")
ADD_LIBRARY(udf_example MODULE udf_example.c udf_example.def)
ADD_DEPENDENCIES(udf_example strings GenError)
diff --git a/sql/MSG00001.bin b/sql/MSG00001.bin
new file mode 100644
index 00000000000..89f547694f5
--- /dev/null
+++ b/sql/MSG00001.bin
Binary files differ
diff --git a/sql/Makefile.am b/sql/Makefile.am
index b9de9b279a3..e477a6123ec 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -146,8 +146,10 @@ DEFS = -DMYSQL_SERVER \
BUILT_MAINT_SRC = sql_yacc.cc sql_yacc.h
BUILT_SOURCES = $(BUILT_MAINT_SRC) lex_hash.h link_sources
EXTRA_DIST = udf_example.c udf_example.def $(BUILT_MAINT_SRC) \
- nt_servc.cc nt_servc.h message.mc CMakeLists.txt \
- udf_example.c udf_example.def
+ nt_servc.cc nt_servc.h \
+ message.mc message.h message.rc MSG00001.bin \
+ CMakeLists.txt
+
CLEANFILES = lex_hash.h sql_yacc.output link_sources
DISTCLEANFILES = $(EXTRA_PROGRAMS)
MAINTAINERCLEANFILES = $(BUILT_MAINT_SRC)
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index 382fd024aa8..c26b740d24a 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -185,6 +185,8 @@ mysql_event_fill_row(THD *thd,
DBUG_PRINT("info", ("dbname=[%s]", et->dbname.str));
DBUG_PRINT("info", ("name =[%s]", et->name.str));
+ DBUG_ASSERT(et->on_completion != Event_parse_data::ON_COMPLETION_DEFAULT);
+
if (table->s->fields < ET_FIELD_COUNT)
{
/*
@@ -745,6 +747,18 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data,
store_record(table,record[1]);
+ /*
+ We check whether ALTER EVENT was given dates that are in the past.
+ However to know how to react, we need the ON COMPLETION type. The
+ check is deferred to this point because by now we have the previous
+ setting (from the event-table) to fall back on if nothing was specified
+ in the ALTER EVENT-statement.
+ */
+
+ if (parse_data->check_dates(thd,
+ (int) table->field[ET_FIELD_ON_COMPLETION]->val_int()))
+ goto end;
+
/* Don't update create on row update. */
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc
index e87e4593f8f..df419e92d0d 100644
--- a/sql/event_parse_data.cc
+++ b/sql/event_parse_data.cc
@@ -45,7 +45,7 @@ Event_parse_data::new_instance(THD *thd)
*/
Event_parse_data::Event_parse_data()
- :on_completion(Event_parse_data::ON_COMPLETION_DROP),
+ :on_completion(Event_parse_data::ON_COMPLETION_DEFAULT),
status(Event_parse_data::ENABLED),
do_not_create(FALSE),
body_changed(FALSE),
@@ -114,6 +114,12 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
if (ltime_utc >= (my_time_t) thd->query_start())
return;
+ /*
+ We'll come back later when we have the real on_completion value
+ */
+ if (on_completion == Event_parse_data::ON_COMPLETION_DEFAULT)
+ return;
+
if (on_completion == Event_parse_data::ON_COMPLETION_DROP)
{
switch (thd->lex->sql_command) {
@@ -142,6 +148,42 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
/*
+ Check time/dates in ALTER EVENT
+
+ We check whether ALTER EVENT was given dates that are in the past.
+ However to know how to react, we need the ON COMPLETION type. Hence,
+ the check is deferred until we have the previous ON COMPLETION type
+ from the event-db to fall back on if nothing was specified in the
+ ALTER EVENT-statement.
+
+ SYNOPSIS
+ Event_parse_data::check_dates()
+ thd Thread
+ on_completion ON COMPLETION value currently in event-db.
+ Will be overridden by value in ALTER EVENT if given.
+
+ RETURN VALUE
+ TRUE an error occurred, do not ALTER
+ FALSE OK
+*/
+
+bool
+Event_parse_data::check_dates(THD *thd, int previous_on_completion)
+{
+ if (on_completion == Event_parse_data::ON_COMPLETION_DEFAULT)
+ {
+ on_completion= previous_on_completion;
+ if (!ends_null)
+ check_if_in_the_past(thd, ends);
+ if (!execute_at_null)
+ check_if_in_the_past(thd, execute_at);
+ }
+ return do_not_create;
+}
+
+
+
+/*
Sets time for execution for one-time event.
SYNOPSIS
diff --git a/sql/event_parse_data.h b/sql/event_parse_data.h
index 221bf92664f..87a800c2078 100644
--- a/sql/event_parse_data.h
+++ b/sql/event_parse_data.h
@@ -38,7 +38,12 @@ public:
enum enum_on_completion
{
- ON_COMPLETION_DROP = 1,
+ /*
+ On CREATE EVENT, DROP is the DEFAULT as per the docs.
+ On ALTER EVENT, "no change" is the DEFAULT.
+ */
+ ON_COMPLETION_DEFAULT = 0,
+ ON_COMPLETION_DROP,
ON_COMPLETION_PRESERVE
};
@@ -80,6 +85,9 @@ public:
bool
check_parse_data(THD *thd);
+ bool
+ check_dates(THD *thd, int previous_on_completion);
+
private:
void
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc
index 5655a8acc99..d9d010783e8 100644
--- a/sql/event_scheduler.cc
+++ b/sql/event_scheduler.cc
@@ -301,12 +301,6 @@ Event_worker_thread::run(THD *thd, Event_queue_element_for_exec *event)
goto end;
}
- sql_print_information("Event Scheduler: "
- "[%s].[%s.%s] started in thread %lu.",
- job_data.definer.str,
- job_data.dbname.str, job_data.name.str,
- thd->thread_id);
-
thd->enable_slow_log= TRUE;
res= job_data.execute(thd, event->dropped);
@@ -318,13 +312,6 @@ Event_worker_thread::run(THD *thd, Event_queue_element_for_exec *event)
"[%s].[%s.%s] event execution failed.",
job_data.definer.str,
job_data.dbname.str, job_data.name.str);
- else
- sql_print_information("Event Scheduler: "
- "[%s].[%s.%s] executed successfully in thread %lu.",
- job_data.definer.str,
- job_data.dbname.str, job_data.name.str,
- thd->thread_id);
-
end:
DBUG_PRINT("info", ("Done with Event %s.%s", event->dbname.str,
event->name.str));
diff --git a/sql/field.cc b/sql/field.cc
index 6af2ea97b2d..95f3956521b 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -6608,7 +6608,8 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)),
uint length;
if (table->in_use->variables.sql_mode &
MODE_PAD_CHAR_TO_FULL_LENGTH)
- length= my_charpos(field_charset, ptr, ptr + field_length, field_length);
+ length= my_charpos(field_charset, ptr, ptr + field_length,
+ field_length / field_charset->mbmaxlen);
else
length= field_charset->cset->lengthsp(field_charset, (const char*) ptr,
field_length);
@@ -7696,8 +7697,18 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
return 0;
}
- if (from == value.ptr())
+ /*
+ If the 'from' address is in the range of the temporary 'value'-
+ object we need to copy the content to a different location or it will be
+ invalidated when the 'value'-object is reallocated to make room for
+ the new character set.
+ */
+ if (from >= value.ptr() && from <= value.ptr()+value.length())
{
+ /*
+ If content of the 'from'-address is cached in the 'value'-object
+ it is possible that the content needs a character conversion.
+ */
uint32 dummy_offset;
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
{
@@ -8770,28 +8781,43 @@ bool Field::eq_def(Field *field)
return 1;
}
+
/**
@return
returns 1 if the fields are equally defined
*/
+
bool Field_enum::eq_def(Field *field)
{
if (!Field::eq_def(field))
return 0;
- TYPELIB *from_lib=((Field_enum*) field)->typelib;
+ return compare_enum_values(((Field_enum*) field)->typelib);
+}
- if (typelib->count < from_lib->count)
- return 0;
- for (uint i=0 ; i < from_lib->count ; i++)
+
+bool Field_enum::compare_enum_values(TYPELIB *values)
+{
+ if (typelib->count != values->count)
+ return FALSE;
+ for (uint i= 0; i < typelib->count; i++)
if (my_strnncoll(field_charset,
- (const uchar*)typelib->type_names[i],
- strlen(typelib->type_names[i]),
- (const uchar*)from_lib->type_names[i],
- strlen(from_lib->type_names[i])))
- return 0;
- return 1;
+ (const uchar*) typelib->type_names[i],
+ typelib->type_lengths[i],
+ (const uchar*) values->type_names[i],
+ values->type_lengths[i]))
+ return FALSE;
+ return TRUE;
+}
+
+
+uint Field_enum::is_equal(Create_field *new_field)
+{
+ if (!Field_str::is_equal(new_field))
+ return 0;
+ return compare_enum_values(new_field->interval);
}
+
/**
@return
returns 1 if the fields are equally defined
diff --git a/sql/field.h b/sql/field.h
index 6152cfccaba..851bce2f07a 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1597,8 +1597,16 @@ private:
class Field_blob :public Field_longstr {
protected:
+ /**
+ The number of bytes used to represent the length of the blob.
+ */
uint packlength;
- String value; // For temporaries
+
+ /**
+ The 'value'-object is a cache fronting the storage engine.
+ */
+ String value;
+
public:
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
@@ -1845,6 +1853,8 @@ public:
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
private:
int do_save_field_metadata(uchar *first_byte);
+ bool compare_enum_values(TYPELIB *values);
+ uint is_equal(Create_field *new_field);
};
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 4e1300c044c..ea5b340c970 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -9971,34 +9971,23 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *create_info,
if (table_changes != IS_EQUAL_YES)
DBUG_RETURN(COMPATIBLE_DATA_NO);
- /**
- * Changing from/to primary key
- *
- * This is _not_ correct, but check_if_incompatible_data-interface
- * doesnt give more info, so I guess that we can't do any
- * online add index if not using primary key
- *
- * This as mysql will handle a unique not null index as primary
- * even wo/ user specifiying it... :-(
- *
- */
- if ((table_share->primary_key == MAX_KEY && pk) ||
- (table_share->primary_key != MAX_KEY && !pk) ||
- (table_share->primary_key == MAX_KEY && !pk && ai))
- {
- DBUG_RETURN(COMPATIBLE_DATA_NO);
- }
-
/* Check that auto_increment value was not changed */
if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
create_info->auto_increment_value != 0)
+ {
+ DBUG_PRINT("info", ("auto_increment value changed"));
DBUG_RETURN(COMPATIBLE_DATA_NO);
+ }
/* Check that row format didn't change */
if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
get_row_type() != create_info->row_type)
+ {
+ DBUG_PRINT("info", ("row format changed"));
DBUG_RETURN(COMPATIBLE_DATA_NO);
+ }
+ DBUG_PRINT("info", ("new table seems compatible"));
DBUG_RETURN(COMPATIBLE_DATA_YES);
}
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 078b22bff02..fe09ce3107e 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -107,7 +107,7 @@ static handler *partition_create_handler(handlerton *hton,
MEM_ROOT *mem_root)
{
ha_partition *file= new (mem_root) ha_partition(hton, share);
- if (file && file->initialise_partition(mem_root))
+ if (file && file->initialize_partition(mem_root))
{
delete file;
file= 0;
@@ -160,7 +160,7 @@ const uint ha_partition::NO_CURRENT_PART_ID= 0xFFFFFFFF;
ha_partition::ha_partition(handlerton *hton, TABLE_SHARE *share)
:handler(hton, share), m_part_info(NULL), m_create_handler(FALSE),
- m_is_sub_partitioned(0), is_clone(FALSE)
+ m_is_sub_partitioned(0)
{
DBUG_ENTER("ha_partition::ha_partition(table)");
init_handler_variables();
@@ -180,9 +180,8 @@ ha_partition::ha_partition(handlerton *hton, TABLE_SHARE *share)
*/
ha_partition::ha_partition(handlerton *hton, partition_info *part_info)
- :handler(hton, NULL), m_part_info(part_info),
- m_create_handler(TRUE),
- m_is_sub_partitioned(m_part_info->is_sub_partitioned()), is_clone(FALSE)
+ :handler(hton, NULL), m_part_info(part_info), m_create_handler(TRUE),
+ m_is_sub_partitioned(m_part_info->is_sub_partitioned())
{
DBUG_ENTER("ha_partition::ha_partition(part_info)");
init_handler_variables();
@@ -192,7 +191,7 @@ ha_partition::ha_partition(handlerton *hton, partition_info *part_info)
/*
- Initialise handler object
+ Initialize handler object
SYNOPSIS
init_handler_variables()
@@ -229,7 +228,7 @@ void ha_partition::init_handler_variables()
m_innodb= FALSE;
m_extra_cache= FALSE;
m_extra_cache_size= 0;
- m_table_flags= HA_FILE_BASED | HA_REC_NOT_IN_SEQ;
+ m_handler_status= handler_not_initialized;
m_low_byte_first= 1;
m_part_field_array= NULL;
m_ordered_rec_buffer= NULL;
@@ -237,7 +236,11 @@ void ha_partition::init_handler_variables()
m_rec_length= 0;
m_last_part= 0;
m_rec0= 0;
- m_curr_key_info= 0;
+ m_curr_key_info[0]= NULL;
+ m_curr_key_info[1]= NULL;
+ is_clone= FALSE,
+ auto_increment_lock= FALSE;
+ auto_increment_safe_stmt_log_lock= FALSE;
/*
this allows blackhole to work properly
*/
@@ -284,10 +287,10 @@ ha_partition::~ha_partition()
/*
- Initialise partition handler object
+ Initialize partition handler object
SYNOPSIS
- initialise_partition()
+ initialize_partition()
mem_root Allocate memory through this
RETURN VALUE
@@ -317,8 +320,8 @@ ha_partition::~ha_partition()
normal storage engine
The flag HA_FILE_BASED will be set independent of the underlying handlers
4) Index flags initialisation
- When knowledge exists on the indexes it is also possible to initialise the
- index flags. Again the index flags must be initialised by using the under-
+ When knowledge exists on the indexes it is also possible to initialize the
+ index flags. Again the index flags must be initialized by using the under-
lying handlers since this is storage engine dependent.
The flag HA_READ_ORDER will be reset for the time being to indicate no
ordered output is available from partition handler indexes. Later a merge
@@ -328,10 +331,11 @@ ha_partition::~ha_partition()
*/
-bool ha_partition::initialise_partition(MEM_ROOT *mem_root)
+bool ha_partition::initialize_partition(MEM_ROOT *mem_root)
{
handler **file_array, *file;
- DBUG_ENTER("ha_partition::initialise_partition");
+ ulonglong check_table_flags;
+ DBUG_ENTER("ha_partition::initialize_partition");
if (m_create_handler)
{
@@ -343,11 +347,9 @@ bool ha_partition::initialise_partition(MEM_ROOT *mem_root)
else if (!table_share || !table_share->normalized_path.str)
{
/*
- Called with dummy table share (delete, rename and alter table)
- Don't need to set-up table flags other than
- HA_FILE_BASED here
+ Called with dummy table share (delete, rename and alter table).
+ Don't need to set-up anything.
*/
- m_table_flags|= HA_FILE_BASED | HA_REC_NOT_IN_SEQ;
DBUG_RETURN(0);
}
else if (get_from_handler_file(table_share->normalized_path.str, mem_root))
@@ -359,15 +361,12 @@ bool ha_partition::initialise_partition(MEM_ROOT *mem_root)
We create all underlying table handlers here. We do it in this special
method to be able to report allocation errors.
- Set up table_flags, low_byte_first, primary_key_is_clustered and
+ Set up low_byte_first, primary_key_is_clustered and
has_transactions since they are called often in all kinds of places,
other parameters are calculated on demand.
- HA_FILE_BASED is always set for partition handler since we use a
- special file for handling names of partitions, engine types.
- HA_CAN_GEOMETRY, HA_CAN_FULLTEXT, HA_CAN_SQL_HANDLER, HA_DUPLICATE_POS,
- HA_CAN_INSERT_DELAYED is disabled until further investigated.
+ Verify that all partitions have the same table_flags.
*/
- m_table_flags= (ulong)m_file[0]->ha_table_flags();
+ check_table_flags= m_file[0]->ha_table_flags();
m_low_byte_first= m_file[0]->low_byte_first();
m_pkey_is_clustered= TRUE;
file_array= m_file;
@@ -382,12 +381,13 @@ bool ha_partition::initialise_partition(MEM_ROOT *mem_root)
}
if (!file->primary_key_is_clustered())
m_pkey_is_clustered= FALSE;
- m_table_flags&= file->ha_table_flags();
+ if (check_table_flags != file->ha_table_flags())
+ {
+ my_error(ER_MIX_HANDLER_ERROR, MYF(0));
+ DBUG_RETURN(1);
+ }
} while (*(++file_array));
- m_table_flags&= ~(HA_CAN_GEOMETRY | HA_CAN_FULLTEXT | HA_DUPLICATE_POS |
- HA_CAN_SQL_HANDLER | HA_CAN_INSERT_DELAYED |
- HA_PRIMARY_KEY_REQUIRED_FOR_POSITION);
- m_table_flags|= HA_FILE_BASED | HA_REC_NOT_IN_SEQ;
+ m_handler_status= handler_initialized;
DBUG_RETURN(0);
}
@@ -874,10 +874,7 @@ int ha_partition::optimize(THD *thd, HA_CHECK_OPT *check_opt)
{
DBUG_ENTER("ha_partition::optimize");
- DBUG_RETURN(handle_opt_partitions(thd, check_opt,
- OPTIMIZE_PARTS,
- thd->lex->alter_info.flags &
- ALTER_OPTIMIZE_PARTITION ? FALSE : TRUE));
+ DBUG_RETURN(handle_opt_partitions(thd, check_opt, OPTIMIZE_PARTS));
}
@@ -898,10 +895,7 @@ int ha_partition::analyze(THD *thd, HA_CHECK_OPT *check_opt)
{
DBUG_ENTER("ha_partition::analyze");
- DBUG_RETURN(handle_opt_partitions(thd, check_opt,
- ANALYZE_PARTS,
- thd->lex->alter_info.flags &
- ALTER_ANALYZE_PARTITION ? FALSE : TRUE));
+ DBUG_RETURN(handle_opt_partitions(thd, check_opt, ANALYZE_PARTS));
}
@@ -922,10 +916,7 @@ int ha_partition::check(THD *thd, HA_CHECK_OPT *check_opt)
{
DBUG_ENTER("ha_partition::check");
- DBUG_RETURN(handle_opt_partitions(thd, check_opt,
- CHECK_PARTS,
- thd->lex->alter_info.flags &
- ALTER_CHECK_PARTITION ? FALSE : TRUE));
+ DBUG_RETURN(handle_opt_partitions(thd, check_opt, CHECK_PARTS));
}
@@ -946,12 +937,10 @@ int ha_partition::repair(THD *thd, HA_CHECK_OPT *check_opt)
{
DBUG_ENTER("ha_partition::repair");
- DBUG_RETURN(handle_opt_partitions(thd, check_opt,
- REPAIR_PARTS,
- thd->lex->alter_info.flags &
- ALTER_REPAIR_PARTITION ? FALSE : TRUE));
+ DBUG_RETURN(handle_opt_partitions(thd, check_opt, REPAIR_PARTS));
}
+
/*
Handle optimize/analyze/check/repair of one partition
@@ -1054,7 +1043,6 @@ static bool print_admin_msg(THD* thd, const char* msg_type,
thd Thread object
check_opt Options
flag Optimize/Analyze/Check/Repair flag
- all_parts All partitions or only a subset
RETURN VALUE
>0 Failure
@@ -1062,7 +1050,7 @@ static bool print_admin_msg(THD* thd, const char* msg_type,
*/
int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
- uint flag, bool all_parts)
+ uint flag)
{
List_iterator<partition_element> part_it(m_part_info->partitions);
uint no_parts= m_part_info->no_parts;
@@ -1070,7 +1058,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
uint i= 0;
int error;
DBUG_ENTER("ha_partition::handle_opt_partitions");
- DBUG_PRINT("enter", ("all_parts %u, flag= %u", all_parts, flag));
+ DBUG_PRINT("enter", ("flag= %u", flag));
do
{
@@ -1079,7 +1067,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
when ALTER TABLE <CMD> PARTITION ...
it should only do named partitions, otherwise all partitions
*/
- if (all_parts ||
+ if (!(thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION) ||
part_elem->part_state == PART_CHANGED)
{
if (m_is_sub_partitioned)
@@ -1248,7 +1236,7 @@ int ha_partition::prepare_new_partition(TABLE *tbl,
assumes that external_lock() is last call that may fail here.
Otherwise see description for cleanup_new_partition().
*/
- if ((error= file->ha_external_lock(current_thd, m_lock_type)))
+ if ((error= file->ha_external_lock(ha_thd(), m_lock_type)))
goto error;
DBUG_RETURN(0);
@@ -1336,8 +1324,8 @@ void ha_partition::cleanup_new_partition(uint part_count)
int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
const char *path,
- ulonglong *copied,
- ulonglong *deleted,
+ ulonglong * const copied,
+ ulonglong * const deleted,
const uchar *pack_frm_data
__attribute__((unused)),
size_t pack_frm_len
@@ -1354,7 +1342,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
int error= 1;
bool first;
uint temp_partitions= m_part_info->temp_partitions.elements;
- THD *thd= current_thd;
+ THD *thd= ha_thd();
DBUG_ENTER("ha_partition::change_partitions");
/*
@@ -1628,7 +1616,8 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
partitions.
*/
-int ha_partition::copy_partitions(ulonglong *copied, ulonglong *deleted)
+int ha_partition::copy_partitions(ulonglong * const copied,
+ ulonglong * const deleted)
{
uint reorg_part= 0;
int result= 0;
@@ -1674,13 +1663,13 @@ int ha_partition::copy_partitions(ulonglong *copied, ulonglong *deleted)
table since it doesn't fit into any partition any longer due to
changed partitioning ranges or list values.
*/
- deleted++;
+ (*deleted)++;
}
else
{
THD *thd= ha_thd();
/* Copy record to new handler */
- copied++;
+ (*copied)++;
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
result= m_new_file[new_part]->ha_write_row(m_rec0);
reenable_binlog(thd);
@@ -1714,6 +1703,14 @@ error:
void ha_partition::update_create_info(HA_CREATE_INFO *create_info)
{
+ /*
+ Fix for bug#38751, some engines needs info-calls in ALTER.
+ Archive need this since it flushes in ::info.
+ HA_STATUS_AUTO is optimized so it will not always be forwarded
+ to all partitions, but HA_STATUS_VARIABLE will.
+ */
+ info(HA_STATUS_VARIABLE);
+
info(HA_STATUS_AUTO);
if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
@@ -1804,7 +1801,7 @@ uint ha_partition::del_ren_cre_table(const char *from,
handler **file, **abort_file;
DBUG_ENTER("del_ren_cre_table()");
- if (get_from_handler_file(from, current_thd->mem_root))
+ if (get_from_handler_file(from, ha_thd()->mem_root))
DBUG_RETURN(TRUE);
DBUG_ASSERT(m_file_buffer);
DBUG_PRINT("enter", ("from: (%s) to: (%s)", from, to));
@@ -1931,7 +1928,7 @@ int ha_partition::set_up_table_before_create(TABLE *tbl,
{
int error= 0;
const char *partition_name;
- THD *thd= current_thd;
+ THD *thd= ha_thd();
DBUG_ENTER("set_up_table_before_create");
if (!part_elem)
@@ -2327,7 +2324,7 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root)
tot_partition_words= (m_tot_parts + 3) / 4;
engine_array= (handlerton **) my_alloca(m_tot_parts * sizeof(handlerton*));
for (i= 0; i < m_tot_parts; i++)
- engine_array[i]= ha_resolve_by_legacy_type(current_thd,
+ engine_array[i]= ha_resolve_by_legacy_type(ha_thd(),
(enum legacy_db_type)
*(uchar *) ((file_buffer) + 12 + i));
address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words;
@@ -2398,8 +2395,11 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
uint alloc_len;
handler **file;
char name_buff[FN_REFLEN];
+ bool is_not_tmp_table= (table_share->tmp_table == NO_TMP_TABLE);
+ ulonglong check_table_flags= 0;
DBUG_ENTER("ha_partition::open");
+ DBUG_ASSERT(table->s == table_share);
ref_length= 0;
m_mode= mode;
m_open_test_lock= test_if_locked;
@@ -2408,9 +2408,9 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
DBUG_RETURN(1);
m_start_key.length= 0;
m_rec0= table->record[0];
- m_rec_length= table->s->reclength;
+ m_rec_length= table_share->reclength;
alloc_len= m_tot_parts * (m_rec_length + PARTITION_BYTES_IN_POS);
- alloc_len+= table->s->max_key_length;
+ alloc_len+= table_share->max_key_length;
if (!m_ordered_rec_buffer)
{
if (!(m_ordered_rec_buffer= (uchar*)my_malloc(alloc_len, MYF(MY_WME))))
@@ -2436,7 +2436,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
}
}
- /* Initialise the bitmap we use to determine what partitions are used */
+ /* Initialize the bitmap we use to determine what partitions are used */
if (!is_clone)
{
if (bitmap_init(&(m_part_info->used_partitions), NULL, m_tot_parts, TRUE))
@@ -2444,8 +2444,6 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
bitmap_set_all(&(m_part_info->used_partitions));
}
- /* Recalculate table flags as they may change after open */
- m_table_flags= m_file[0]->ha_table_flags();
file= m_file;
do
{
@@ -2457,11 +2455,24 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
m_no_locks+= (*file)->lock_count();
name_buffer_ptr+= strlen(name_buffer_ptr) + 1;
set_if_bigger(ref_length, ((*file)->ref_length));
- m_table_flags&= (*file)->ha_table_flags();
+ /*
+ Verify that all partitions have the same set of table flags.
+ Mask all flags that partitioning enables/disables.
+ */
+ if (!check_table_flags)
+ {
+ check_table_flags= (((*file)->ha_table_flags() &
+ ~(PARTITION_DISABLED_TABLE_FLAGS)) |
+ (PARTITION_ENABLED_TABLE_FLAGS));
+ }
+ else if (check_table_flags != (((*file)->ha_table_flags() &
+ ~(PARTITION_DISABLED_TABLE_FLAGS)) |
+ (PARTITION_ENABLED_TABLE_FLAGS)))
+ {
+ error= HA_ERR_INITIALIZATION;
+ goto err_handler;
+ }
} while (*(++file));
- m_table_flags&= ~(HA_CAN_GEOMETRY | HA_CAN_FULLTEXT | HA_DUPLICATE_POS |
- HA_CAN_SQL_HANDLER | HA_CAN_INSERT_DELAYED);
- m_table_flags|= HA_FILE_BASED | HA_REC_NOT_IN_SEQ;
key_used_on_scan= m_file[0]->key_used_on_scan;
implicit_emptied= m_file[0]->implicit_emptied;
/*
@@ -2476,18 +2487,43 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
*/
clear_handler_file();
/*
- Initialise priority queue, initialised to reading forward.
+ Initialize priority queue, initialized to reading forward.
*/
if ((error= init_queue(&m_queue, m_tot_parts, (uint) PARTITION_BYTES_IN_POS,
0, key_rec_cmp, (void*)this)))
goto err_handler;
/*
+ Use table_share->ha_data to share auto_increment_value among all handlers
+ for the same table.
+ */
+ if (is_not_tmp_table)
+ pthread_mutex_lock(&table_share->mutex);
+ if (!table_share->ha_data)
+ {
+ HA_DATA_PARTITION *ha_data;
+ /* currently only needed for auto_increment */
+ table_share->ha_data= ha_data= (HA_DATA_PARTITION*)
+ alloc_root(&table_share->mem_root,
+ sizeof(HA_DATA_PARTITION));
+ if (!ha_data)
+ {
+ if (is_not_tmp_table)
+ pthread_mutex_unlock(&table_share->mutex);
+ goto err_handler;
+ }
+ DBUG_PRINT("info", ("table_share->ha_data 0x%p", ha_data));
+ bzero(ha_data, sizeof(HA_DATA_PARTITION));
+ }
+ if (is_not_tmp_table)
+ pthread_mutex_unlock(&table_share->mutex);
+ /*
Some handlers update statistics as part of the open call. This will in
some cases corrupt the statistics of the partition handler and thus
to ensure we have correct statistics we call info from open after
calling open on all individual handlers.
*/
+ m_handler_status= handler_opened;
info(HA_STATUS_VARIABLE | HA_STATUS_CONST);
DBUG_RETURN(0);
@@ -2539,6 +2575,7 @@ int ha_partition::close(void)
handler **file;
DBUG_ENTER("ha_partition::close");
+ DBUG_ASSERT(table->s == table_share);
delete_queue(&m_queue);
if (!is_clone)
bitmap_free(&(m_part_info->used_partitions));
@@ -2557,6 +2594,7 @@ repeat:
goto repeat;
}
+ m_handler_status= handler_closed;
DBUG_RETURN(0);
}
@@ -2607,6 +2645,7 @@ int ha_partition::external_lock(THD *thd, int lock_type)
handler **file;
DBUG_ENTER("ha_partition::external_lock");
+ DBUG_ASSERT(!auto_increment_lock && !auto_increment_safe_stmt_log_lock);
file= m_file;
m_lock_type= lock_type;
@@ -2825,8 +2864,9 @@ int ha_partition::write_row(uchar * buf)
uint32 part_id;
int error;
longlong func_value;
- bool autoincrement_lock= FALSE;
+ bool have_auto_increment= table->next_number_field && buf == table->record[0];
my_bitmap_map *old_map;
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
THD *thd= ha_thd();
timestamp_auto_set_type orig_timestamp_type= table->timestamp_field_type;
#ifdef NOT_NEEDED
@@ -2844,28 +2884,16 @@ int ha_partition::write_row(uchar * buf)
If we have an auto_increment column and we are writing a changed row
or a new row, then update the auto_increment value in the record.
*/
- if (table->next_number_field && buf == table->record[0])
+ if (have_auto_increment)
{
- /*
- Some engines (InnoDB for example) can change autoincrement
- counter only after 'table->write_row' operation.
- So if another thread gets inside the ha_partition::write_row
- before it is complete, it gets same auto_increment value,
- which means DUP_KEY error (bug #27405)
- Here we separate the access using table_share->mutex, and
- use autoincrement_lock variable to avoid unnecessary locks.
- Probably not an ideal solution.
- */
- if (table_share->tmp_table == NO_TMP_TABLE)
+ if (!ha_data->auto_inc_initialized &&
+ !table->s->next_number_keypart)
{
/*
- Bug#30878 crash when alter table from non partitioned table
- to partitioned.
- Checking if tmp table then there is no need to lock,
- and the table_share->mutex may not be initialised.
+ If auto_increment in table_share is not initialized, start by
+ initializing it.
*/
- autoincrement_lock= TRUE;
- pthread_mutex_lock(&table_share->mutex);
+ info(HA_STATUS_AUTO);
}
error= update_auto_increment();
@@ -2903,11 +2931,11 @@ int ha_partition::write_row(uchar * buf)
DBUG_PRINT("info", ("Insert in partition %d", part_id));
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
error= m_file[part_id]->ha_write_row(buf);
+ if (have_auto_increment && !table->s->next_number_keypart)
+ set_auto_increment_if_higher(table->next_number_field->val_int());
reenable_binlog(thd);
exit:
table->timestamp_field_type= orig_timestamp_type;
- if (autoincrement_lock)
- pthread_mutex_unlock(&table_share->mutex);
DBUG_RETURN(error);
}
@@ -2931,13 +2959,6 @@ exit:
Keep in mind that the server can do updates based on ordering if an
ORDER BY clause was used. Consecutive ordering is not guarenteed.
- Currently new_data will not have an updated auto_increament record, or
- and updated timestamp field. You can do these for partition by doing these:
- if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
- table->timestamp_field->set_time();
- if (table->next_number_field && record == table->record[0])
- update_auto_increment();
-
Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc.
new_data is always record[0]
old_data is normally record[1] but may be anything
@@ -2969,11 +2990,6 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data)
goto exit;
}
- /*
- TODO:
- set_internal_auto_increment=
- max(set_internal_auto_increment, new_data->auto_increment)
- */
m_last_part= new_part_id;
if (new_part_id == old_part_id)
{
@@ -3006,6 +3022,22 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data)
}
exit:
+ /*
+ if updating an auto_increment column, update
+ table_share->ha_data->next_auto_inc_val if needed.
+ (not to be used if auto_increment on secondary field in a multi-column
+ index)
+ mysql_update does not set table->next_number_field, so we use
+ table->found_next_number_field instead.
+ */
+ if (table->found_next_number_field && new_data == table->record[0] &&
+ !table->s->next_number_keypart)
+ {
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
+ if (!ha_data->auto_inc_initialized)
+ info(HA_STATUS_AUTO);
+ set_auto_increment_if_higher(table->found_next_number_field->val_int());
+ }
table->timestamp_field_type= orig_timestamp_type;
DBUG_RETURN(error);
}
@@ -3084,8 +3116,17 @@ int ha_partition::delete_all_rows()
{
int error;
handler **file;
+ THD *thd= ha_thd();
DBUG_ENTER("ha_partition::delete_all_rows");
+ if (thd->lex->sql_command == SQLCOM_TRUNCATE)
+ {
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
+ lock_auto_increment();
+ ha_data->next_auto_inc_val= 0;
+ ha_data->auto_inc_initialized= FALSE;
+ unlock_auto_increment();
+ }
file= m_file;
do
{
@@ -3544,7 +3585,7 @@ int ha_partition::rnd_pos_by_record(uchar *record)
*/
/*
- Initialise handler before start of index scan
+ Initialize handler before start of index scan
SYNOPSIS
index_init()
@@ -3566,11 +3607,24 @@ int ha_partition::index_init(uint inx, bool sorted)
handler **file;
DBUG_ENTER("ha_partition::index_init");
+ DBUG_PRINT("info", ("inx %u sorted %u", inx, sorted));
active_index= inx;
m_part_spec.start_part= NO_CURRENT_PART_ID;
m_start_key.length= 0;
m_ordered= sorted;
- m_curr_key_info= table->key_info+inx;
+ m_curr_key_info[0]= table->key_info+inx;
+ if (m_pkey_is_clustered && table->s->primary_key != MAX_KEY)
+ {
+ /*
+ if PK is clustered, then the key cmp must use the pk to
+ differentiate between equal key in given index.
+ */
+ DBUG_PRINT("info", ("Clustered pk, using pk as secondary cmp"));
+ m_curr_key_info[1]= table->key_info+table->s->primary_key;
+ m_curr_key_info[2]= NULL;
+ }
+ else
+ m_curr_key_info[1]= NULL;
/*
Some handlers only read fields as specified by the bitmap for the
read set. For partitioned handlers we always require that the
@@ -3595,9 +3649,13 @@ int ha_partition::index_init(uint inx, bool sorted)
TODO: handle COUNT(*) queries via unordered scan.
*/
uint i;
- for (i= 0; i < m_curr_key_info->key_parts; i++)
- bitmap_set_bit(table->read_set,
- m_curr_key_info->key_part[i].field->field_index);
+ KEY **key_info= m_curr_key_info;
+ do
+ {
+ for (i= 0; i < (*key_info)->key_parts; i++)
+ bitmap_set_bit(table->read_set,
+ (*key_info)->key_part[i].field->field_index);
+ } while (*(++key_info));
}
file= m_file;
do
@@ -3654,10 +3712,10 @@ int ha_partition::index_end()
Read one record in an index scan and start an index scan
SYNOPSIS
- index_read()
+ index_read_map()
buf Read row in MySQL Row Format
key Key parts in consecutive order
- key_len Total length of key parts
+ keypart_map Which part of key is used
find_flag What type of key condition is used
RETURN VALUE
@@ -3665,12 +3723,12 @@ int ha_partition::index_end()
0 Success
DESCRIPTION
- index_read starts a new index scan using a start key. The MySQL Server
+ index_read_map starts a new index scan using a start key. The MySQL Server
will check the end key on its own. Thus to function properly the
partitioned handler need to ensure that it delivers records in the sort
order of the MySQL Server.
- index_read can be restarted without calling index_end on the previous
- index scan and without calling index_init. In this case the index_read
+ index_read_map can be restarted without calling index_end on the previous
+ index scan and without calling index_init. In this case the index_read_map
is on the same index as the previous index_scan. This is particularly
used in conjuntion with multi read ranges.
*/
@@ -3680,10 +3738,12 @@ int ha_partition::index_read_map(uchar *buf, const uchar *key,
enum ha_rkey_function find_flag)
{
DBUG_ENTER("ha_partition::index_read_map");
-
end_range= 0;
m_index_scan_type= partition_index_read;
- DBUG_RETURN(common_index_read(buf, key, keypart_map, find_flag));
+ m_start_key.key= key;
+ m_start_key.keypart_map= keypart_map;
+ m_start_key.flag= find_flag;
+ DBUG_RETURN(common_index_read(buf, TRUE));
}
@@ -3691,41 +3751,70 @@ int ha_partition::index_read_map(uchar *buf, const uchar *key,
Common routine for a number of index_read variants
SYNOPSIS
- common_index_read
-
- see index_read for rest
+ ha_partition::common_index_read()
+ buf Buffer where the record should be returned
+ have_start_key TRUE <=> the left endpoint is available, i.e.
+ we're in index_read call or in read_range_first
+ call and the range has left endpoint
+
+ FALSE <=> there is no left endpoint (we're in
+ read_range_first() call and the range has no left
+ endpoint)
+
+ DESCRIPTION
+ Start scanning the range (when invoked from read_range_first()) or doing
+ an index lookup (when invoked from index_read_XXX):
+ - If possible, perform partition selection
+ - Find the set of partitions we're going to use
+ - Depending on whether we need ordering:
+ NO: Get the first record from first used partition (see
+ handle_unordered_scan_next_partition)
+ YES: Fill the priority queue and get the record that is the first in
+ the ordering
+
+ RETURN
+ 0 OK
+ other HA_ERR_END_OF_FILE or other error code.
*/
-int ha_partition::common_index_read(uchar *buf, const uchar *key,
- key_part_map keypart_map,
- enum ha_rkey_function find_flag)
+int ha_partition::common_index_read(uchar *buf, bool have_start_key)
{
int error;
+ uint key_len;
bool reverse_order= FALSE;
- uint key_len= calculate_key_len(table, active_index, key, keypart_map);
DBUG_ENTER("ha_partition::common_index_read");
+ LINT_INIT(key_len); /* used if have_start_key==TRUE */
- memcpy((void*)m_start_key.key, key, key_len);
- m_start_key.keypart_map= keypart_map;
- m_start_key.length= key_len;
- m_start_key.flag= find_flag;
+ DBUG_PRINT("info", ("m_ordered %u m_ordered_scan_ong %u have_start_key %u",
+ m_ordered, m_ordered_scan_ongoing, have_start_key));
- if ((error= partition_scan_set_up(buf, TRUE)))
+ if (have_start_key)
+ {
+ m_start_key.length= key_len= calculate_key_len(table, active_index,
+ m_start_key.key,
+ m_start_key.keypart_map);
+ DBUG_ASSERT(key_len);
+ }
+ if ((error= partition_scan_set_up(buf, have_start_key)))
{
DBUG_RETURN(error);
}
- if (find_flag == HA_READ_PREFIX_LAST ||
- find_flag == HA_READ_PREFIX_LAST_OR_PREV ||
- find_flag == HA_READ_BEFORE_KEY)
+
+ if (have_start_key &&
+ (m_start_key.flag == HA_READ_PREFIX_LAST ||
+ m_start_key.flag == HA_READ_PREFIX_LAST_OR_PREV ||
+ m_start_key.flag == HA_READ_BEFORE_KEY))
{
reverse_order= TRUE;
m_ordered_scan_ongoing= TRUE;
}
+ DBUG_PRINT("info", ("m_ordered %u m_o_scan_ong %u have_start_key %u",
+ m_ordered, m_ordered_scan_ongoing, have_start_key));
if (!m_ordered_scan_ongoing ||
- (find_flag == HA_READ_KEY_EXACT &&
- (key_len >= m_curr_key_info->key_length ||
- key_len == 0)))
- {
+ (have_start_key && m_start_key.flag == HA_READ_KEY_EXACT &&
+ !m_pkey_is_clustered &&
+ key_len >= m_curr_key_info[0]->key_length))
+ {
/*
We use unordered index scan either when read_range is used and flag
is set to not use ordered or when an exact key is used and in this
@@ -3737,6 +3826,7 @@ int ha_partition::common_index_read(uchar *buf, const uchar *key,
Need to set unordered scan ongoing since we can come here even when
it isn't set.
*/
+ DBUG_PRINT("info", ("doing unordered scan"));
m_ordered_scan_ongoing= FALSE;
error= handle_unordered_scan_next_partition(buf);
}
@@ -3816,7 +3906,7 @@ int ha_partition::index_last(uchar * buf)
Common routine for index_first/index_last
SYNOPSIS
- common_index_first_last
+ ha_partition::common_first_last()
see index_first for rest
*/
@@ -3838,7 +3928,7 @@ int ha_partition::common_first_last(uchar *buf)
Read last using key
SYNOPSIS
- index_read_last()
+ index_read_last_map()
buf Read row in MySQL Row Format
key Key
keypart_map Which part of key is used
@@ -3860,7 +3950,10 @@ int ha_partition::index_read_last_map(uchar *buf, const uchar *key,
m_ordered= TRUE; // Safety measure
end_range= 0;
m_index_scan_type= partition_index_read_last;
- DBUG_RETURN(common_index_read(buf, key, keypart_map, HA_READ_PREFIX_LAST));
+ m_start_key.key= key;
+ m_start_key.keypart_map= keypart_map;
+ m_start_key.flag= HA_READ_PREFIX_LAST;
+ DBUG_RETURN(common_index_read(buf, TRUE));
}
@@ -3991,23 +4084,15 @@ int ha_partition::read_range_first(const key_range *start_key,
((end_key->flag == HA_READ_BEFORE_KEY) ? 1 :
(end_key->flag == HA_READ_AFTER_KEY) ? -1 : 0);
}
- range_key_part= m_curr_key_info->key_part;
- if (!start_key) // Read first record
- {
- if (m_ordered)
- m_index_scan_type= partition_index_first;
- else
- m_index_scan_type= partition_index_first_unordered;
- error= common_first_last(m_rec0);
- }
+ range_key_part= m_curr_key_info[0]->key_part;
+ if (start_key)
+ m_start_key= *start_key;
else
- {
- m_index_scan_type= partition_index_read;
- error= common_index_read(m_rec0,
- start_key->key,
- start_key->keypart_map, start_key->flag);
- }
+ m_start_key.key= NULL;
+
+ m_index_scan_type= partition_read_range;
+ error= common_index_read(m_rec0, test(start_key));
DBUG_RETURN(error);
}
@@ -4027,28 +4112,38 @@ int ha_partition::read_range_next()
{
DBUG_ENTER("ha_partition::read_range_next");
- if (m_ordered)
+ if (m_ordered_scan_ongoing)
{
- DBUG_RETURN(handler::read_range_next());
+ DBUG_RETURN(handle_ordered_next(table->record[0], eq_range));
}
- DBUG_RETURN(handle_unordered_next(m_rec0, eq_range));
+ DBUG_RETURN(handle_unordered_next(table->record[0], eq_range));
}
/*
- Common routine to set up scans
+ Common routine to set up index scans
SYNOPSIS
- buf Buffer to later return record in
- idx_read_flag Is it index scan
+ ha_partition::partition_scan_set_up()
+ buf Buffer to later return record in (this function
+ needs it to calculcate partitioning function
+ values)
+
+ idx_read_flag TRUE <=> m_start_key has range start endpoint which
+ probably can be used to determine the set of partitions
+ to scan.
+ FALSE <=> there is no start endpoint.
+
+ DESCRIPTION
+ Find out which partitions we'll need to read when scanning the specified
+ range.
+
+ If we need to scan only one partition, set m_ordered_scan_ongoing=FALSE
+ as we will not need to do merge ordering.
RETURN VALUE
>0 Error code
0 Success
-
- DESCRIPTION
- This is where we check which partitions to actually scan if not all
- of them
*/
int ha_partition::partition_scan_set_up(uchar * buf, bool idx_read_flag)
@@ -4139,10 +4234,19 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
DBUG_ENTER("ha_partition::handle_unordered_next");
/*
- We should consider if this should be split into two functions as
- next_same is alwas a local constant
+ We should consider if this should be split into three functions as
+ partition_read_range is_next_same are always local constants
*/
- if (is_next_same)
+
+ if (m_index_scan_type == partition_read_range)
+ {
+ if (!(error= file->read_range_next()))
+ {
+ m_last_part= m_part_spec.start_part;
+ DBUG_RETURN(0);
+ }
+ }
+ else if (is_next_same)
{
if (!(error= file->index_next_same(buf, m_start_key.key,
m_start_key.length)))
@@ -4151,15 +4255,13 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
DBUG_RETURN(0);
}
}
- else if (!(error= file->index_next(buf)))
+ else
{
- if (!(file->index_flags(active_index, 0, 1) & HA_READ_ORDER) ||
- compare_key(end_range) <= 0)
+ if (!(error= file->index_next(buf)))
{
m_last_part= m_part_spec.start_part;
DBUG_RETURN(0); // Row was in range
}
- error= HA_ERR_END_OF_FILE;
}
if (error == HA_ERR_END_OF_FILE)
@@ -4203,6 +4305,11 @@ int ha_partition::handle_unordered_scan_next_partition(uchar * buf)
file= m_file[i];
m_part_spec.start_part= i;
switch (m_index_scan_type) {
+ case partition_read_range:
+ DBUG_PRINT("info", ("read_range_first on partition %d", i));
+ error= file->read_range_first(m_start_key.key? &m_start_key: NULL,
+ end_range, eq_range, FALSE);
+ break;
case partition_index_read:
DBUG_PRINT("info", ("index_read on partition %d", i));
error= file->index_read_map(buf, m_start_key.key,
@@ -4211,6 +4318,17 @@ int ha_partition::handle_unordered_scan_next_partition(uchar * buf)
break;
case partition_index_first:
DBUG_PRINT("info", ("index_first on partition %d", i));
+ /* MyISAM engine can fail if we call index_first() when indexes disabled */
+ /* that happens if the table is empty. */
+ /* Here we use file->stats.records instead of file->records() because */
+ /* file->records() is supposed to return an EXACT count, and it can be */
+ /* possibly slow. We don't need an exact number, an approximate one- from*/
+ /* the last ::info() call - is sufficient. */
+ if (file->stats.records == 0)
+ {
+ error= HA_ERR_END_OF_FILE;
+ break;
+ }
error= file->index_first(buf);
break;
case partition_index_first_unordered:
@@ -4231,13 +4349,8 @@ int ha_partition::handle_unordered_scan_next_partition(uchar * buf)
}
if (!error)
{
- if (!(file->index_flags(active_index, 0, 1) & HA_READ_ORDER) ||
- compare_key(end_range) <= 0)
- {
- m_last_part= i;
- DBUG_RETURN(0);
- }
- error= HA_ERR_END_OF_FILE;
+ m_last_part= i;
+ DBUG_RETURN(0);
}
if ((error != HA_ERR_END_OF_FILE) && (error != HA_ERR_KEY_NOT_FOUND))
DBUG_RETURN(error);
@@ -4303,10 +4416,32 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
m_start_key.flag);
break;
case partition_index_first:
+ /* MyISAM engine can fail if we call index_first() when indexes disabled */
+ /* that happens if the table is empty. */
+ /* Here we use file->stats.records instead of file->records() because */
+ /* file->records() is supposed to return an EXACT count, and it can be */
+ /* possibly slow. We don't need an exact number, an approximate one- from*/
+ /* the last ::info() call - is sufficient. */
+ if (file->stats.records == 0)
+ {
+ error= HA_ERR_END_OF_FILE;
+ break;
+ }
error= file->index_first(rec_buf_ptr);
reverse_order= FALSE;
break;
case partition_index_last:
+ /* MyISAM engine can fail if we call index_last() when indexes disabled */
+ /* that happens if the table is empty. */
+ /* Here we use file->stats.records instead of file->records() because */
+ /* file->records() is supposed to return an EXACT count, and it can be */
+ /* possibly slow. We don't need an exact number, an approximate one- from*/
+ /* the last ::info() call - is sufficient. */
+ if (file->stats.records == 0)
+ {
+ error= HA_ERR_END_OF_FILE;
+ break;
+ }
error= file->index_last(rec_buf_ptr);
reverse_order= TRUE;
break;
@@ -4316,6 +4451,17 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
m_start_key.keypart_map);
reverse_order= TRUE;
break;
+ case partition_read_range:
+ {
+ /*
+ This can only read record to table->record[0], as it was set when
+ the table was being opened. We have to memcpy data ourselves.
+ */
+ error= file->read_range_first(&m_start_key, end_range, eq_range, TRUE);
+ memcpy(rec_buf_ptr, table->record[0], m_rec_length);
+ reverse_order= FALSE;
+ break;
+ }
default:
DBUG_ASSERT(FALSE);
DBUG_RETURN(HA_ERR_END_OF_FILE);
@@ -4324,7 +4470,7 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
{
found= TRUE;
/*
- Initialise queue without order first, simply insert
+ Initialize queue without order first, simply insert
*/
queue_element(&m_queue, j++)= (uchar*)queue_buf(i);
}
@@ -4396,8 +4542,13 @@ int ha_partition::handle_ordered_next(uchar *buf, bool is_next_same)
uint part_id= m_top_entry;
handler *file= m_file[part_id];
DBUG_ENTER("ha_partition::handle_ordered_next");
-
- if (!is_next_same)
+
+ if (m_index_scan_type == partition_read_range)
+ {
+ error= file->read_range_next();
+ memcpy(rec_buf(part_id), table->record[0], m_rec_length);
+ }
+ else if (!is_next_same)
error= file->index_next(rec_buf(part_id));
else
error= file->index_next_same(rec_buf(part_id), m_start_key.key,
@@ -4545,21 +4696,54 @@ int ha_partition::handle_ordered_prev(uchar *buf)
int ha_partition::info(uint flag)
{
- handler *file, **file_array;
- DBUG_ENTER("ha_partition:info");
+ DBUG_ENTER("ha_partition::info");
if (flag & HA_STATUS_AUTO)
{
- ulonglong auto_increment_value= 0;
+ bool auto_inc_is_first_in_idx= (table_share->next_number_keypart == 0);
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
DBUG_PRINT("info", ("HA_STATUS_AUTO"));
- file_array= m_file;
- do
+ if (!table->found_next_number_field)
+ stats.auto_increment_value= 0;
+ else if (ha_data->auto_inc_initialized)
{
- file= *file_array;
- file->info(HA_STATUS_AUTO);
- set_if_bigger(auto_increment_value, file->stats.auto_increment_value);
- } while (*(++file_array));
- stats.auto_increment_value= auto_increment_value;
+ lock_auto_increment();
+ stats.auto_increment_value= ha_data->next_auto_inc_val;
+ unlock_auto_increment();
+ }
+ else
+ {
+ lock_auto_increment();
+ /* to avoid two concurrent initializations, check again when locked */
+ if (ha_data->auto_inc_initialized)
+ stats.auto_increment_value= ha_data->next_auto_inc_val;
+ else
+ {
+ handler *file, **file_array;
+ ulonglong auto_increment_value= 0;
+ file_array= m_file;
+ DBUG_PRINT("info",
+ ("checking all partitions for auto_increment_value"));
+ do
+ {
+ file= *file_array;
+ file->info(HA_STATUS_AUTO);
+ set_if_bigger(auto_increment_value,
+ file->stats.auto_increment_value);
+ } while (*(++file_array));
+
+ DBUG_ASSERT(auto_increment_value);
+ stats.auto_increment_value= auto_increment_value;
+ if (auto_inc_is_first_in_idx)
+ {
+ set_if_bigger(ha_data->next_auto_inc_val, auto_increment_value);
+ ha_data->auto_inc_initialized= TRUE;
+ DBUG_PRINT("info", ("initializing next_auto_inc_val to %lu",
+ (ulong) ha_data->next_auto_inc_val));
+ }
+ }
+ unlock_auto_increment();
+ }
}
if (flag & HA_STATUS_VARIABLE)
{
@@ -4583,6 +4767,7 @@ int ha_partition::info(uint flag)
check_time: Time of last check (only applicable to MyISAM)
We report last time of all underlying handlers
*/
+ handler *file, **file_array;
stats.records= 0;
stats.deleted= 0;
stats.data_file_length= 0;
@@ -4606,7 +4791,7 @@ int ha_partition::info(uint flag)
}
} while (*(++file_array));
if (stats.records < 2 &&
- !(m_table_flags & HA_STATS_RECORDS_IS_EXACT))
+ !(m_file[0]->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT))
stats.records= 2;
if (stats.records > 0)
stats.mean_rec_length= (ulong) (stats.data_file_length / stats.records);
@@ -4664,6 +4849,7 @@ int ha_partition::info(uint flag)
So we calculate these constants by using the variables on the first
handler.
*/
+ handler *file;
file= m_file[0];
file->info(HA_STATUS_CONST);
@@ -4685,6 +4871,7 @@ int ha_partition::info(uint flag)
}
if (flag & HA_STATUS_TIME)
{
+ handler *file, **file_array;
DBUG_PRINT("info", ("info: HA_STATUS_TIME"));
/*
This flag is used to set the latest update time of the table.
@@ -4978,7 +5165,7 @@ void ha_partition::get_dynamic_partition_info(PARTITION_INFO *stat_info,
5) Parameters only used by MyISAM internally
--------------------------------------------
HA_EXTRA_REINIT_CACHE:
- This call reinitialises the READ CACHE described above if there is one
+ This call reinitializes the READ CACHE described above if there is one
and otherwise the call is ignored.
We can thus safely call it on all underlying handlers if they are
@@ -5060,7 +5247,6 @@ int ha_partition::extra(enum ha_extra_function operation)
DBUG_RETURN(prepare_for_rename());
case HA_EXTRA_NORMAL:
case HA_EXTRA_QUICK:
- case HA_EXTRA_NO_READCHECK:
case HA_EXTRA_PREPARE_FOR_UPDATE:
case HA_EXTRA_FORCE_REOPEN:
case HA_EXTRA_PREPARE_FOR_DROP:
@@ -5069,6 +5255,14 @@ int ha_partition::extra(enum ha_extra_function operation)
DBUG_RETURN(loop_extra(operation));
break;
}
+ case HA_EXTRA_NO_READCHECK:
+ {
+ /*
+ This is only done as a part of ha_open, which is also used in
+ ha_partition::open, so no need to do anything.
+ */
+ break;
+ }
case HA_EXTRA_CACHE:
{
prepare_extra_cache(0);
@@ -5600,6 +5794,89 @@ bool ha_partition::get_error_message(int error, String *buf)
/****************************************************************************
MODULE handler characteristics
****************************************************************************/
+/**
+ alter_table_flags must be on handler/table level, not on hton level
+ due to the ha_partition hton does not know what the underlying hton is.
+*/
+uint ha_partition::alter_table_flags(uint flags)
+{
+ DBUG_ENTER("ha_partition::alter_table_flags");
+ DBUG_RETURN(ht->alter_table_flags(flags) |
+ m_file[0]->alter_table_flags(flags));
+}
+
+
+/**
+ check if copy of data is needed in alter table.
+*/
+bool ha_partition::check_if_incompatible_data(HA_CREATE_INFO *create_info,
+ uint table_changes)
+{
+ handler **file;
+ bool ret= COMPATIBLE_DATA_YES;
+
+ /*
+ The check for any partitioning related changes have already been done
+ in mysql_alter_table (by fix_partition_func), so it is only up to
+ the underlying handlers.
+ */
+ for (file= m_file; *file; file++)
+ if ((ret= (*file)->check_if_incompatible_data(create_info,
+ table_changes)) !=
+ COMPATIBLE_DATA_YES)
+ break;
+ return ret;
+}
+
+
+/**
+ Support of fast or online add/drop index
+*/
+int ha_partition::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
+{
+ handler **file;
+ int ret= 0;
+
+ /*
+ There has already been a check in fix_partition_func in mysql_alter_table
+ before this call, which checks for unique/primary key violations of the
+ partitioning function. So no need for extra check here.
+ */
+ for (file= m_file; *file; file++)
+ if ((ret= (*file)->add_index(table_arg, key_info, num_of_keys)))
+ break;
+ return ret;
+}
+
+
+int ha_partition::prepare_drop_index(TABLE *table_arg, uint *key_num,
+ uint num_of_keys)
+{
+ handler **file;
+ int ret= 0;
+
+ /*
+ DROP INDEX does not affect partitioning.
+ */
+ for (file= m_file; *file; file++)
+ if ((ret= (*file)->prepare_drop_index(table_arg, key_num, num_of_keys)))
+ break;
+ return ret;
+}
+
+
+int ha_partition::final_drop_index(TABLE *table_arg)
+{
+ handler **file;
+ int ret= HA_ERR_WRONG_COMMAND;
+
+ for (file= m_file; *file; file++)
+ if ((ret= (*file)->final_drop_index(table_arg)))
+ break;
+ return ret;
+}
+
+
/*
If frm_error() is called then we will use this to to find out what file
extensions exist for the storage engine. This is also used by the default
@@ -5744,19 +6021,33 @@ int ha_partition::cmp_ref(const uchar *ref1, const uchar *ref2)
MODULE auto increment
****************************************************************************/
-void ha_partition::restore_auto_increment(ulonglong)
-{
- DBUG_ENTER("ha_partition::restore_auto_increment");
- DBUG_VOID_RETURN;
+int ha_partition::reset_auto_increment(ulonglong value)
+{
+ handler **file= m_file;
+ int res;
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
+ DBUG_ENTER("ha_partition::reset_auto_increment");
+ lock_auto_increment();
+ ha_data->auto_inc_initialized= FALSE;
+ ha_data->next_auto_inc_val= 0;
+ do
+ {
+ if ((res= (*file)->ha_reset_auto_increment(value)) != 0)
+ break;
+ } while (*(++file));
+ unlock_auto_increment();
+ DBUG_RETURN(res);
}
-/*
+/**
This method is called by update_auto_increment which in turn is called
- by the individual handlers as part of write_row. We will always let
- the first handler keep track of the auto increment value for all
- partitions.
+ by the individual handlers as part of write_row. We use the
+ table_share->ha_data->next_auto_inc_val, or search all
+ partitions for the highest auto_increment_value if not initialized or
+ if auto_increment field is a secondary part of a key, we must search
+ every partition when holding a mutex to be sure of correctness.
*/
void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment,
@@ -5764,59 +6055,88 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment,
ulonglong *first_value,
ulonglong *nb_reserved_values)
{
- ulonglong first_value_part, last_value_part, nb_reserved_values_part,
- last_value= ~ (ulonglong) 0;
- handler **pos, **end;
- bool retry= TRUE;
DBUG_ENTER("ha_partition::get_auto_increment");
-
-again:
- for (pos=m_file, end= m_file+ m_tot_parts; pos != end ; pos++)
+ DBUG_PRINT("info", ("offset: %lu inc: %lu desired_values: %lu "
+ "first_value: %lu", (ulong) offset, (ulong) increment,
+ (ulong) nb_desired_values, (ulong) *first_value));
+ DBUG_ASSERT(increment && nb_desired_values);
+ *first_value= 0;
+ if (table->s->next_number_keypart)
{
- first_value_part= *first_value;
- (*pos)->get_auto_increment(offset, increment, nb_desired_values,
- &first_value_part, &nb_reserved_values_part);
- if (first_value_part == ~(ulonglong)(0)) // error in one partition
- {
- *first_value= first_value_part;
- sql_print_error("Partition failed to reserve auto_increment value");
- DBUG_VOID_RETURN;
- }
/*
- Partition has reserved an interval. Intersect it with the intervals
- already reserved for the previous partitions.
+ next_number_keypart is != 0 if the auto_increment column is a secondary
+ column in the index (it is allowed in MyISAM)
*/
- last_value_part= (nb_reserved_values_part == ULONGLONG_MAX) ?
- ULONGLONG_MAX : (first_value_part + nb_reserved_values_part * increment);
- set_if_bigger(*first_value, first_value_part);
- set_if_smaller(last_value, last_value_part);
+ DBUG_PRINT("info", ("next_number_keypart != 0"));
+ ulonglong nb_reserved_values_part;
+ ulonglong first_value_part, max_first_value;
+ handler **file= m_file;
+ first_value_part= max_first_value= *first_value;
+ /* Must lock and find highest value among all partitions. */
+ lock_auto_increment();
+ do
+ {
+ /* Only nb_desired_values = 1 makes sense */
+ (*file)->get_auto_increment(offset, increment, 1,
+ &first_value_part, &nb_reserved_values_part);
+ if (first_value_part == ~(ulonglong)(0)) // error in one partition
+ {
+ *first_value= first_value_part;
+ /* log that the error was between table/partition handler */
+ sql_print_error("Partition failed to reserve auto_increment value");
+ unlock_auto_increment();
+ DBUG_VOID_RETURN;
+ }
+ DBUG_PRINT("info", ("first_value_part: %lu", (ulong) first_value_part));
+ set_if_bigger(max_first_value, first_value_part);
+ } while (*(++file));
+ *first_value= max_first_value;
+ *nb_reserved_values= 1;
+ unlock_auto_increment();
}
- if (last_value < *first_value) /* empty intersection, error */
+ else
{
+ THD *thd= ha_thd();
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
/*
- When we have an empty intersection, it means that one or more
- partitions may have a significantly different autoinc next value.
- We should not fail here - it just means that we should try to
- find a new reservation making use of the current *first_value
- wbich should now be compatible with all partitions.
+ This is initialized in the beginning of the first write_row call.
*/
- if (retry)
- {
- retry= FALSE;
- last_value= ~ (ulonglong) 0;
- release_auto_increment();
- goto again;
- }
+ DBUG_ASSERT(ha_data->auto_inc_initialized);
/*
- We should not get here.
+ Get a lock for handling the auto_increment in table_share->ha_data
+ for avoiding two concurrent statements getting the same number.
+ */
+
+ lock_auto_increment();
+
+ /*
+ In a multi-row insert statement like INSERT SELECT and LOAD DATA
+ where the number of candidate rows to insert is not known in advance
+ we must hold a lock/mutex for the whole statement if we have statement
+ based replication. Because the statement-based binary log contains
+ only the first generated value used by the statement, and slaves assumes
+ all other generated values used by this statement were consecutive to
+ this first one, we must exclusively lock the generator until the statement
+ is done.
*/
- sql_print_error("Failed to calculate auto_increment value for partition");
-
- *first_value= ~(ulonglong)(0);
+ if (!auto_increment_safe_stmt_log_lock &&
+ thd->lex->sql_command != SQLCOM_INSERT &&
+ mysql_bin_log.is_open() &&
+ !thd->current_stmt_binlog_row_based &&
+ (thd->options & OPTION_BIN_LOG))
+ {
+ DBUG_PRINT("info", ("locking auto_increment_safe_stmt_log_lock"));
+ auto_increment_safe_stmt_log_lock= TRUE;
+ }
+
+ /* this gets corrected (for offset/increment) in update_auto_increment */
+ *first_value= ha_data->next_auto_inc_val;
+ ha_data->next_auto_inc_val+= nb_desired_values * increment;
+
+ unlock_auto_increment();
+ DBUG_PRINT("info", ("*first_value: %lu", (ulong) *first_value));
+ *nb_reserved_values= nb_desired_values;
}
- if (increment) // If not check for values
- *nb_reserved_values= (last_value == ULONGLONG_MAX) ?
- ULONGLONG_MAX : ((last_value - *first_value) / increment);
DBUG_VOID_RETURN;
}
@@ -5824,15 +6144,37 @@ void ha_partition::release_auto_increment()
{
DBUG_ENTER("ha_partition::release_auto_increment");
- for (uint i= 0; i < m_tot_parts; i++)
+ if (table->s->next_number_keypart)
{
- m_file[i]->ha_release_auto_increment();
+ for (uint i= 0; i < m_tot_parts; i++)
+ m_file[i]->ha_release_auto_increment();
+ }
+ else if (next_insert_id)
+ {
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
+ ulonglong next_auto_inc_val;
+ lock_auto_increment();
+ next_auto_inc_val= ha_data->next_auto_inc_val;
+ if (next_insert_id < next_auto_inc_val &&
+ auto_inc_interval_for_cur_row.maximum() >= next_auto_inc_val)
+ ha_data->next_auto_inc_val= next_insert_id;
+ DBUG_PRINT("info", ("ha_data->next_auto_inc_val: %lu",
+ (ulong) ha_data->next_auto_inc_val));
+
+ /* Unlock the multi row statement lock taken in get_auto_increment */
+ if (auto_increment_safe_stmt_log_lock)
+ {
+ auto_increment_safe_stmt_log_lock= FALSE;
+ DBUG_PRINT("info", ("unlocking auto_increment_safe_stmt_log_lock"));
+ }
+
+ unlock_auto_increment();
}
DBUG_VOID_RETURN;
}
/****************************************************************************
- MODULE initialise handler for HANDLER call
+ MODULE initialize handler for HANDLER call
****************************************************************************/
void ha_partition::init_table_handle_for_HANDLER()
@@ -5925,7 +6267,7 @@ int ha_partition::indexes_are_disabled(void)
-------------------------------------------------------------------------
Variables for partition share methods. A hash used to track open tables.
A mutex for the hash table and an init variable to check if hash table
- is initialised.
+ is initialized.
There is also a constant ending of the partition handler file name.
*/
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 99e3cb50a8f..07a16a8e423 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -37,8 +37,24 @@ typedef struct st_partition_share
} PARTITION_SHARE;
#endif
+/**
+ Partition specific ha_data struct.
+ @todo: move all partition specific data from TABLE_SHARE here.
+*/
+typedef struct st_ha_data_partition
+{
+ ulonglong next_auto_inc_val; /**< first non reserved value */
+ bool auto_inc_initialized;
+} HA_DATA_PARTITION;
#define PARTITION_BYTES_IN_POS 2
+#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ)
+#define PARTITION_DISABLED_TABLE_FLAGS (HA_CAN_GEOMETRY | \
+ HA_CAN_FULLTEXT | \
+ HA_DUPLICATE_POS | \
+ HA_CAN_SQL_HANDLER | \
+ HA_CAN_INSERT_DELAYED | \
+ HA_PRIMARY_KEY_REQUIRED_FOR_POSITION)
class ha_partition :public handler
{
private:
@@ -49,7 +65,8 @@ private:
partition_index_first_unordered= 2,
partition_index_last= 3,
partition_index_read_last= 4,
- partition_no_index_scan= 5
+ partition_read_range = 5,
+ partition_no_index_scan= 6
};
/* Data for the partition handler */
int m_mode; // Open mode
@@ -63,12 +80,17 @@ private:
handler **m_reorged_file; // Reorganised partitions
handler **m_added_file; // Added parts kept for errors
partition_info *m_part_info; // local reference to partition
- uchar *m_start_key_ref; // Reference of start key in current
- // index scan info
Field **m_part_field_array; // Part field array locally to save acc
- uchar *m_ordered_rec_buffer; // Row and key buffer for ord. idx scan
- KEY *m_curr_key_info; // Current index
- uchar *m_rec0; // table->record[0]
+ uchar *m_ordered_rec_buffer; // Row and key buffer for ord. idx scan
+ /*
+ Current index.
+ When used in key_rec_cmp: If clustered pk, index compare
+ must compare pk if given index is same for two rows.
+ So normally m_curr_key_info[0]= current index and m_curr_key[1]= NULL,
+ and if clustered pk, [0]= current index, [1]= pk, [2]= NULL
+ */
+ KEY *m_curr_key_info[3]; // Current index
+ uchar *m_rec0; // table->record[0]
QUEUE m_queue; // Prio queue used by sorted read
/*
Since the partition handler is a handler on top of other handlers, it
@@ -77,8 +99,15 @@ private:
for this since the MySQL Server sometimes allocating the handler object
without freeing them.
*/
- longlong m_table_flags;
ulong m_low_byte_first;
+ enum enum_handler_status
+ {
+ handler_not_initialized= 0,
+ handler_initialized,
+ handler_opened,
+ handler_closed
+ };
+ enum_handler_status m_handler_status;
uint m_reorged_parts; // Number of reorganised parts
uint m_tot_parts; // Total number of partitions;
@@ -141,6 +170,12 @@ private:
"own" the m_part_info structure.
*/
bool is_clone;
+ bool auto_increment_lock; /**< lock reading/updating auto_inc */
+ /**
+ Flag to keep the auto_increment lock through out the statement.
+ This to ensure it will work with statement based replication.
+ */
+ bool auto_increment_safe_stmt_log_lock;
public:
handler *clone(MEM_ROOT *mem_root);
virtual void set_part_info(partition_info *part_info)
@@ -168,7 +203,7 @@ public:
enable later calls of the methods to retrieve constants from the under-
lying handlers. Returns false if not successful.
*/
- bool initialise_partition(MEM_ROOT *mem_root);
+ bool initialize_partition(MEM_ROOT *mem_root);
/*
-------------------------------------------------------------------------
@@ -197,8 +232,8 @@ public:
virtual char *update_table_comment(const char *comment);
virtual int change_partitions(HA_CREATE_INFO *create_info,
const char *path,
- ulonglong *copied,
- ulonglong *deleted,
+ ulonglong * const copied,
+ ulonglong * const deleted,
const uchar *pack_frm_data,
size_t pack_frm_len);
virtual int drop_partitions(const char *path);
@@ -210,9 +245,11 @@ public:
DBUG_RETURN(0);
}
virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
+ virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
+ uint table_changes);
private:
int prepare_for_rename();
- int copy_partitions(ulonglong *copied, ulonglong *deleted);
+ int copy_partitions(ulonglong * const copied, ulonglong * const deleted);
void cleanup_new_partition(uint part_count);
int prepare_new_partition(TABLE *table, HA_CREATE_INFO *create_info,
handler *file, const char *part_name,
@@ -429,9 +466,7 @@ public:
virtual int read_range_next();
private:
- int common_index_read(uchar * buf, const uchar * key,
- key_part_map keypart_map,
- enum ha_rkey_function find_flag);
+ int common_index_read(uchar * buf, bool have_start_key);
int common_first_last(uchar * buf);
int partition_scan_set_up(uchar * buf, bool idx_read_flag);
int handle_unordered_next(uchar * buf, bool next_same);
@@ -573,6 +608,8 @@ public:
The partition handler will support whatever the underlying handlers
support except when specifically mentioned below about exceptions
to this rule.
+ NOTE: This cannot be cached since it can depend on TRANSACTION ISOLATION
+ LEVEL which is dynamic, see bug#39084.
HA_READ_RND_SAME:
Not currently used. (Means that the handler supports the rnd_same() call)
@@ -697,9 +734,33 @@ public:
transfer those calls into index_read and other calls in the
index scan module.
(NDB)
+
+ HA_PRIMARY_KEY_REQUIRED_FOR_POSITION:
+ Does the storage engine need a PK for position?
+ Used with hidden primary key in InnoDB.
+ Hidden primary keys cannot be supported by partitioning, since the
+ partitioning expressions columns must be a part of the primary key.
+ (InnoDB)
+
+ HA_FILE_BASED is always set for partition handler since we use a
+ special file for handling names of partitions, engine types.
+ HA_REC_NOT_IN_SEQ is always set for partition handler since we cannot
+ guarantee that the records will be returned in sequence.
+ HA_CAN_GEOMETRY, HA_CAN_FULLTEXT, HA_CAN_SQL_HANDLER, HA_DUPLICATE_POS,
+ HA_CAN_INSERT_DELAYED, HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is disabled
+ until further investigated.
*/
- virtual ulonglong table_flags() const
- { return m_table_flags; }
+ virtual Table_flags table_flags() const
+ {
+ DBUG_ENTER("ha_partition::table_flags");
+ if (m_handler_status < handler_initialized ||
+ m_handler_status >= handler_closed)
+ DBUG_RETURN(PARTITION_ENABLED_TABLE_FLAGS);
+ else
+ DBUG_RETURN((m_file[0]->ha_table_flags() &
+ ~(PARTITION_DISABLED_TABLE_FLAGS)) |
+ (PARTITION_ENABLED_TABLE_FLAGS));
+ }
/*
This is a bitmap of flags that says how the storage engine
@@ -762,6 +823,11 @@ public:
return m_file[0]->index_flags(inx, part, all_parts);
}
+ /**
+ wrapper function for handlerton alter_table_flags, since
+ the ha_partition_hton cannot know all its capabilities
+ */
+ virtual uint alter_table_flags(uint flags);
/*
extensions of table handler files
*/
@@ -829,16 +895,55 @@ public:
auto_increment_column_changed
-------------------------------------------------------------------------
*/
- virtual void restore_auto_increment(ulonglong prev_insert_id);
virtual void get_auto_increment(ulonglong offset, ulonglong increment,
ulonglong nb_desired_values,
ulonglong *first_value,
ulonglong *nb_reserved_values);
virtual void release_auto_increment();
+private:
+ virtual int reset_auto_increment(ulonglong value);
+ virtual void lock_auto_increment()
+ {
+ /* lock already taken */
+ if (auto_increment_safe_stmt_log_lock)
+ return;
+ DBUG_ASSERT(table_share->ha_data && !auto_increment_lock);
+ if(table_share->tmp_table == NO_TMP_TABLE)
+ {
+ auto_increment_lock= TRUE;
+ pthread_mutex_lock(&table_share->mutex);
+ }
+ }
+ virtual void unlock_auto_increment()
+ {
+ DBUG_ASSERT(table_share->ha_data);
+ /*
+ If auto_increment_safe_stmt_log_lock is true, we have to keep the lock.
+ It will be set to false and thus unlocked at the end of the statement by
+ ha_partition::release_auto_increment.
+ */
+ if(auto_increment_lock && !auto_increment_safe_stmt_log_lock)
+ {
+ pthread_mutex_unlock(&table_share->mutex);
+ auto_increment_lock= FALSE;
+ }
+ }
+ virtual void set_auto_increment_if_higher(const ulonglong nr)
+ {
+ HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
+ lock_auto_increment();
+ DBUG_ASSERT(ha_data->auto_inc_initialized == TRUE);
+ /* must check when the mutex is taken */
+ if (nr >= ha_data->next_auto_inc_val)
+ ha_data->next_auto_inc_val= nr + 1;
+ unlock_auto_increment();
+ }
+
+public:
/*
-------------------------------------------------------------------------
- MODULE initialise handler for HANDLER call
+ MODULE initialize handler for HANDLER call
-------------------------------------------------------------------------
This method is a special InnoDB method called before a HANDLER query.
-------------------------------------------------------------------------
@@ -898,13 +1003,14 @@ public:
-------------------------------------------------------------------------
MODULE on-line ALTER TABLE
-------------------------------------------------------------------------
- These methods are in the handler interface but never used (yet)
- They are to be used by on-line alter table add/drop index:
+ These methods are in the handler interface. (used by innodb-plugin)
+ They are used for on-line/fast alter table add/drop index:
-------------------------------------------------------------------------
- virtual ulong index_ddl_flags(KEY *wanted_index) const
- virtual int add_index(TABLE *table_arg,KEY *key_info,uint num_of_keys);
- virtual int drop_index(TABLE *table_arg,uint *key_num,uint num_of_keys);
*/
+ virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
+ virtual int prepare_drop_index(TABLE *table_arg, uint *key_num,
+ uint num_of_keys);
+ virtual int final_drop_index(TABLE *table_arg);
/*
-------------------------------------------------------------------------
@@ -937,8 +1043,7 @@ public:
virtual bool is_crashed() const;
private:
- int handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
- uint flags, bool all_parts);
+ int handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, uint flags);
public:
/*
-------------------------------------------------------------------------
diff --git a/sql/handler.cc b/sql/handler.cc
index 733e77b6397..cbb951cd450 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -263,7 +263,7 @@ handler *get_ha_partition(partition_info *part_info)
DBUG_ENTER("get_ha_partition");
if ((partition= new ha_partition(partition_hton, part_info)))
{
- if (partition->initialise_partition(current_thd->mem_root))
+ if (partition->initialize_partition(current_thd->mem_root))
{
delete partition;
partition= 0;
@@ -373,7 +373,12 @@ int ha_finalize_handlerton(st_plugin_int *plugin)
handlerton *hton= (handlerton *)plugin->data;
DBUG_ENTER("ha_finalize_handlerton");
- switch (hton->state) {
+ /* hton can be NULL here, if ha_initialize_handlerton() failed. */
+ if (!hton)
+ goto end;
+
+ switch (hton->state)
+ {
case SHOW_OPTION_NO:
case SHOW_OPTION_DISABLED:
break;
@@ -400,8 +405,16 @@ int ha_finalize_handlerton(st_plugin_int *plugin)
}
}
+ /*
+ In case a plugin is uninstalled and re-installed later, it should
+ reuse an array slot. Otherwise the number of uninstall/install
+ cycles would be limited.
+ */
+ hton2plugin[hton->slot]= NULL;
+
my_free((uchar*)hton, MYF(0));
+ end:
DBUG_RETURN(0);
}
@@ -436,6 +449,7 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
case SHOW_OPTION_YES:
{
uint tmp;
+ ulong fslot;
/* now check the db_type for conflict */
if (hton->db_type <= DB_TYPE_UNKNOWN ||
hton->db_type >= DB_TYPE_DEFAULT ||
@@ -460,7 +474,31 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
tmp= hton->savepoint_offset;
hton->savepoint_offset= savepoint_alloc_size;
savepoint_alloc_size+= tmp;
- hton->slot= total_ha++;
+
+ /*
+ In case a plugin is uninstalled and re-installed later, it should
+ reuse an array slot. Otherwise the number of uninstall/install
+ cycles would be limited. So look for a free slot.
+ */
+ DBUG_PRINT("plugin", ("total_ha: %lu", total_ha));
+ for (fslot= 0; fslot < total_ha; fslot++)
+ {
+ if (!hton2plugin[fslot])
+ break;
+ }
+ if (fslot < total_ha)
+ hton->slot= fslot;
+ else
+ {
+ if (total_ha >= MAX_HA)
+ {
+ sql_print_error("Too many plugins loaded. Limit is %lu. "
+ "Failed on '%s'", (ulong) MAX_HA, plugin->name.str);
+ goto err;
+ }
+ hton->slot= total_ha++;
+ }
+
hton2plugin[hton->slot]=plugin;
if (hton->prepare)
total_ha_2pc++;
@@ -1240,7 +1278,12 @@ int ha_rollback_trans(THD *thd, bool all)
trans->ha_list= 0;
trans->no_2pc=0;
if (is_real_trans)
- thd->transaction.xid_state.xid.null();
+ {
+ if (thd->transaction_rollback_request)
+ thd->transaction.xid_state.rm_error= thd->main_da.sql_errno();
+ else
+ thd->transaction.xid_state.xid.null();
+ }
if (all)
{
thd->variables.tx_isolation=thd->session_tx_isolation;
@@ -2164,7 +2207,12 @@ prev_insert_id(ulonglong nr, struct system_variables *variables)
- In both cases, the reserved intervals are remembered in
thd->auto_inc_intervals_in_cur_stmt_for_binlog if statement-based
binlogging; the last reserved interval is remembered in
- auto_inc_interval_for_cur_row.
+ auto_inc_interval_for_cur_row. The number of reserved intervals is
+ remembered in auto_inc_intervals_count. It differs from the number of
+ elements in thd->auto_inc_intervals_in_cur_stmt_for_binlog() because the
+ latter list is cumulative over all statements forming one binlog event
+ (when stored functions and triggers are used), and collapses two
+ contiguous intervals in one (see its append() method).
The idea is that generated auto_increment values are predictable and
independent of the column values in the table. This is needed to be
@@ -2248,8 +2296,6 @@ int handler::update_auto_increment()
handler::estimation_rows_to_insert was set by
handler::ha_start_bulk_insert(); if 0 it means "unknown".
*/
- uint nb_already_reserved_intervals=
- thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
ulonglong nb_desired_values;
/*
If an estimation was given to the engine:
@@ -2261,17 +2307,17 @@ int handler::update_auto_increment()
start, starting from AUTO_INC_DEFAULT_NB_ROWS.
Don't go beyond a max to not reserve "way too much" (because
reservation means potentially losing unused values).
+ Note that in prelocked mode no estimation is given.
*/
- if (nb_already_reserved_intervals == 0 &&
- (estimation_rows_to_insert > 0))
+ if ((auto_inc_intervals_count == 0) && (estimation_rows_to_insert > 0))
nb_desired_values= estimation_rows_to_insert;
else /* go with the increasing defaults */
{
/* avoid overflow in formula, with this if() */
- if (nb_already_reserved_intervals <= AUTO_INC_DEFAULT_NB_MAX_BITS)
+ if (auto_inc_intervals_count <= AUTO_INC_DEFAULT_NB_MAX_BITS)
{
- nb_desired_values= AUTO_INC_DEFAULT_NB_ROWS *
- (1 << nb_already_reserved_intervals);
+ nb_desired_values= AUTO_INC_DEFAULT_NB_ROWS *
+ (1 << auto_inc_intervals_count);
set_if_smaller(nb_desired_values, AUTO_INC_DEFAULT_NB_MAX);
}
else
@@ -2284,7 +2330,7 @@ int handler::update_auto_increment()
&nb_reserved_values);
if (nr == ~(ulonglong) 0)
DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED); // Mark failure
-
+
/*
That rounding below should not be needed when all engines actually
respect offset and increment in get_auto_increment(). But they don't
@@ -2295,7 +2341,7 @@ int handler::update_auto_increment()
*/
nr= compute_next_insert_id(nr-1, variables);
}
-
+
if (table->s->next_number_keypart == 0)
{
/* We must defer the appending until "nr" has been possibly truncated */
@@ -2339,8 +2385,9 @@ int handler::update_auto_increment()
{
auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
variables->auto_increment_increment);
+ auto_inc_intervals_count++;
/* Row-based replication does not need to store intervals in binlog */
- if (!thd->current_stmt_binlog_row_based)
+ if (mysql_bin_log.is_open() && !thd->current_stmt_binlog_row_based)
thd->auto_inc_intervals_in_cur_stmt_for_binlog.append(auto_inc_interval_for_cur_row.minimum(),
auto_inc_interval_for_cur_row.values(),
variables->auto_increment_increment);
@@ -2460,6 +2507,7 @@ void handler::ha_release_auto_increment()
release_auto_increment();
insert_id_for_cur_row= 0;
auto_inc_interval_for_cur_row.replace(0, 0, 0);
+ auto_inc_intervals_count= 0;
if (next_insert_id > 0)
{
next_insert_id= 0;
@@ -2712,8 +2760,56 @@ bool handler::get_error_message(int error, String* buf)
}
+/**
+ Check for incompatible collation changes.
+
+ @retval
+ HA_ADMIN_NEEDS_UPGRADE Table may have data requiring upgrade.
+ @retval
+ 0 No upgrade required.
+*/
+
+int handler::check_collation_compatibility()
+{
+ ulong mysql_version= table->s->mysql_version;
+
+ if (mysql_version < 50124)
+ {
+ KEY *key= table->key_info;
+ KEY *key_end= key + table->s->keys;
+ for (; key < key_end; key++)
+ {
+ KEY_PART_INFO *key_part= key->key_part;
+ KEY_PART_INFO *key_part_end= key_part + key->key_parts;
+ for (; key_part < key_part_end; key_part++)
+ {
+ if (!key_part->fieldnr)
+ continue;
+ Field *field= table->field[key_part->fieldnr - 1];
+ uint cs_number= field->charset()->number;
+ if ((mysql_version < 50048 &&
+ (cs_number == 11 || /* ascii_general_ci - bug #29499, bug #27562 */
+ cs_number == 41 || /* latin7_general_ci - bug #29461 */
+ cs_number == 42 || /* latin7_general_cs - bug #29461 */
+ cs_number == 20 || /* latin7_estonian_cs - bug #29461 */
+ cs_number == 21 || /* latin2_hungarian_ci - bug #29461 */
+ cs_number == 22 || /* koi8u_general_ci - bug #29461 */
+ cs_number == 23 || /* cp1251_ukrainian_ci - bug #29461 */
+ cs_number == 26)) || /* cp1250_general_ci - bug #29461 */
+ (mysql_version < 50124 &&
+ (cs_number == 33 || /* utf8_general_ci - bug #27877 */
+ cs_number == 35))) /* ucs2_general_ci - bug #27877 */
+ return HA_ADMIN_NEEDS_UPGRADE;
+ }
+ }
+ }
+ return 0;
+}
+
+
int handler::ha_check_for_upgrade(HA_CHECK_OPT *check_opt)
{
+ int error;
KEY *keyinfo, *keyend;
KEY_PART_INFO *keypart, *keypartend;
@@ -2742,6 +2838,10 @@ int handler::ha_check_for_upgrade(HA_CHECK_OPT *check_opt)
}
if (table->s->frm_version != FRM_VER_TRUE_VARCHAR)
return HA_ADMIN_NEEDS_ALTER;
+
+ if ((error= check_collation_compatibility()))
+ return error;
+
return check_for_upgrade(check_opt);
}
@@ -3244,8 +3344,8 @@ handler::ha_create_handler_files(const char *name, const char *old_name,
int
handler::ha_change_partitions(HA_CREATE_INFO *create_info,
const char *path,
- ulonglong *copied,
- ulonglong *deleted,
+ ulonglong * const copied,
+ ulonglong * const deleted,
const uchar *pack_frm_data,
size_t pack_frm_len)
{
@@ -4334,6 +4434,8 @@ static int write_locked_table_maps(THD *thd)
(long) thd, (long) thd->lock,
(long) thd->locked_tables, (long) thd->extra_lock));
+ DBUG_PRINT("debug", ("get_binlog_table_maps(): %d", thd->get_binlog_table_maps()));
+
if (thd->get_binlog_table_maps() == 0)
{
MYSQL_LOCK *locks[3];
diff --git a/sql/handler.h b/sql/handler.h
index f6e29048407..68bb894a5d2 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1136,6 +1136,13 @@ public:
inserter.
*/
Discrete_interval auto_inc_interval_for_cur_row;
+ /**
+ Number of reserved auto-increment intervals. Serves as a heuristic
+ when we have no estimation of how many records the statement will insert:
+ the more intervals we have reserved, the bigger the next one. Reset in
+ handler::ha_release_auto_increment().
+ */
+ uint auto_inc_intervals_count;
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
:table_share(share_arg), table(0),
@@ -1144,7 +1151,8 @@ public:
ref_length(sizeof(my_off_t)),
ft_handler(0), inited(NONE),
locked(FALSE), implicit_emptied(0),
- pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0)
+ pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0),
+ auto_inc_intervals_count(0)
{}
virtual ~handler(void)
{
@@ -1197,6 +1205,9 @@ public:
{
return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
}
+ /**
+ The cached_table_flags is set at ha_open and ha_external_lock
+ */
Table_flags ha_table_flags() const { return cached_table_flags; }
/**
These functions represent the public interface to *users* of the
@@ -1210,6 +1221,7 @@ public:
int ha_delete_row(const uchar * buf);
void ha_release_auto_increment();
+ int check_collation_compatibility();
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
/** to be actually called to get 'check()' functionality*/
int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
@@ -1248,8 +1260,8 @@ public:
int ha_change_partitions(HA_CREATE_INFO *create_info,
const char *path,
- ulonglong *copied,
- ulonglong *deleted,
+ ulonglong * const copied,
+ ulonglong * const deleted,
const uchar *pack_frm_data,
size_t pack_frm_len);
int ha_drop_partitions(const char *path);
@@ -1734,6 +1746,12 @@ public:
but we don't have a primary key
*/
virtual void use_hidden_primary_key();
+ virtual uint alter_table_flags(uint flags)
+ {
+ if (ht->alter_table_flags)
+ return ht->alter_table_flags(flags);
+ return 0;
+ }
LEX_STRING *engine_name() { return hton_name(ht); }
@@ -1872,7 +1890,8 @@ private:
This is called to delete all rows in a table
If the handler don't support this, then this function will
return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
- by one.
+ by one. It should reset auto_increment if
+ thd->lex->sql_command == SQLCOM_TRUNCATE.
*/
virtual int delete_all_rows()
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
@@ -1911,8 +1930,8 @@ private:
virtual int change_partitions(HA_CREATE_INFO *create_info,
const char *path,
- ulonglong *copied,
- ulonglong *deleted,
+ ulonglong * const copied,
+ ulonglong * const deleted,
const uchar *pack_frm_data,
size_t pack_frm_len)
{ return HA_ERR_WRONG_COMMAND; }
diff --git a/sql/item.cc b/sql/item.cc
index d443b9d87c6..d630ca7bc60 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1246,10 +1246,12 @@ Item_name_const::Item_name_const(Item *name_arg, Item *val):
if (!(valid_args= name_item->basic_const_item() &&
(value_item->basic_const_item() ||
((value_item->type() == FUNC_ITEM) &&
- (((Item_func *) value_item)->functype() ==
- Item_func::NEG_FUNC) &&
+ ((((Item_func *) value_item)->functype() ==
+ Item_func::COLLATE_FUNC) ||
+ ((((Item_func *) value_item)->functype() ==
+ Item_func::NEG_FUNC) &&
(((Item_func *) value_item)->key_item()->type() !=
- FUNC_ITEM)))))
+ FUNC_ITEM)))))))
my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
Item::maybe_null= TRUE;
}
@@ -1334,6 +1336,7 @@ public:
else
Item_ident::print(str, query_type);
}
+ virtual Ref_Type ref_type() { return AGGREGATE_REF; }
};
@@ -1797,14 +1800,17 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
We need to copy db_name, table_name and field_name because they must
be allocated in the statement memory, not in table memory (the table
structure can go away and pop up again between subsequent executions
- of a prepared statement).
+ of a prepared statement or after the close_tables_for_reopen() call
+ in mysql_multi_update_prepare() or due to wildcard expansion in stored
+ procedures).
*/
- if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
{
if (db_name)
orig_db_name= thd->strdup(db_name);
- orig_table_name= thd->strdup(table_name);
- orig_field_name= thd->strdup(field_name);
+ if (table_name)
+ orig_table_name= thd->strdup(table_name);
+ if (field_name)
+ orig_field_name= thd->strdup(field_name);
/*
We don't restore 'name' in cleanup because it's not changed
during execution. Still we need it to point to persistent
@@ -2376,17 +2382,15 @@ void Item_string::print(String *str, enum_query_type query_type)
}
-double Item_string::val_real()
+double
+double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
{
- DBUG_ASSERT(fixed == 1);
int error;
- char *end, *org_end;
+ char *org_end;
double tmp;
- CHARSET_INFO *cs= str_value.charset();
- org_end= (char*) str_value.ptr() + str_value.length();
- tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
- &error);
+ org_end= end;
+ tmp= my_strntod(cs, (char*) cptr, end - cptr, &end, &error);
if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
{
/*
@@ -2396,26 +2400,28 @@ double Item_string::val_real()
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE,
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
- str_value.ptr());
+ cptr);
}
return tmp;
}
-/**
- @todo
- Give error if we wanted a signed integer and we got an unsigned one
-*/
-longlong Item_string::val_int()
+double Item_string::val_real()
{
DBUG_ASSERT(fixed == 1);
+ return double_from_string_with_check (str_value.charset(), str_value.ptr(),
+ (char *) str_value.ptr() + str_value.length());
+}
+
+
+longlong
+longlong_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
+{
int err;
longlong tmp;
- char *end= (char*) str_value.ptr()+ str_value.length();
char *org_end= end;
- CHARSET_INFO *cs= str_value.charset();
- tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
+ tmp= (*(cs->cset->strtoll10))(cs, cptr, &end, &err);
/*
TODO: Give error if we wanted a signed integer and we got an unsigned
one
@@ -2426,12 +2432,24 @@ longlong Item_string::val_int()
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE,
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
- str_value.ptr());
+ cptr);
}
return tmp;
}
+/**
+ @todo
+ Give error if we wanted a signed integer and we got an unsigned one
+*/
+longlong Item_string::val_int()
+{
+ DBUG_ASSERT(fixed == 1);
+ return longlong_from_string_with_check(str_value.charset(), str_value.ptr(),
+ (char *) str_value.ptr()+ str_value.length());
+}
+
+
my_decimal *Item_string::val_decimal(my_decimal *decimal_value)
{
return val_decimal_from_string(decimal_value);
@@ -4338,7 +4356,12 @@ Item *Item_field::equal_fields_propagator(uchar *arg)
item= this;
else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
{
- if (item && cmp_context != INT_RESULT)
+ /*
+ We don't need to zero-fill timestamp columns here because they will be
+ first converted to a string (in date/time format) and compared as such if
+ compared with another string.
+ */
+ if (item && field->type() != FIELD_TYPE_TIMESTAMP && cmp_context != INT_RESULT)
convert_zerofill_number_to_string(&item, (Field_num *)field);
else
item= this;
@@ -6928,7 +6951,7 @@ enum_field_types Item_type_holder::get_real_type(Item *item)
*/
Item_sum *item_sum= (Item_sum *) item;
if (item_sum->keep_field_type())
- return get_real_type(item_sum->args[0]);
+ return get_real_type(item_sum->get_arg(0));
break;
}
case FUNC_ITEM:
@@ -7192,7 +7215,7 @@ void Item_type_holder::get_full_info(Item *item)
if (item->type() == Item::SUM_FUNC_ITEM &&
(((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
((Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC))
- item = ((Item_sum*)item)->args[0];
+ item = ((Item_sum*)item)->get_arg(0);
/*
We can have enum/set type after merging only if we have one enum|set
field (or MIN|MAX(enum|set field)) and number of NULL fields
diff --git a/sql/item.h b/sql/item.h
index 97350352162..c46a3322d94 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1982,6 +1982,11 @@ private:
};
+longlong
+longlong_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end);
+double
+double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end);
+
class Item_static_string_func :public Item_string
{
const char *func_name;
@@ -2127,7 +2132,7 @@ class Item_ref :public Item_ident
protected:
void set_properties();
public:
- enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF };
+ enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF, AGGREGATE_REF };
Field *result_field; /* Save result here */
Item **ref;
Item_ref(Name_resolution_context *context_arg,
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index a79a94868c8..5fe324f1b6a 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -413,10 +413,15 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
/*
- Store the value of the field if it references an outer field because
- the call to save_in_field below overrides that value.
+ Store the value of the field/constant if it references an outer field
+ because the call to save_in_field below overrides that value.
+ Don't save field value if no data has been read yet.
+ Outer constant values are always saved.
*/
- if (field_item->depended_from)
+ bool save_field_value= (field_item->depended_from &&
+ (field_item->const_item() ||
+ !(field->table->status & STATUS_NO_RECORD)));
+ if (save_field_value)
orig_field_val= field->val_int();
if (!(*item)->is_null() && !(*item)->save_in_field(field, 1))
{
@@ -427,7 +432,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
result= 1; // Item was replaced
}
/* Restore the original field value. */
- if (field_item->depended_from)
+ if (save_field_value)
{
result= field->store(orig_field_val, TRUE);
/* orig_field_val must be a valid value that can be restored back. */
diff --git a/sql/item_func.cc b/sql/item_func.cc
index b3c50718273..87d15c7968d 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -3803,6 +3803,25 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
return entry;
}
+
+bool Item_func_set_user_var::set_entry(THD *thd, bool create_if_not_exists)
+{
+ if (thd == entry_thd && entry)
+ goto end; // update entry->update_query_id for PS
+ entry_thd= thd;
+ if (!(entry= get_variable(&thd->user_vars, name, create_if_not_exists)))
+ return TRUE;
+ /*
+ Remember the last query which updated it, this way a query can later know
+ if this variable is a constant item in the query (it is if update_query_id
+ is different from query_id).
+ */
+end:
+ entry->update_query_id= thd->query_id;
+ return FALSE;
+}
+
+
/*
When a user variable is updated (in a SET command or a query like
SELECT @a:= ).
@@ -3812,15 +3831,8 @@ bool Item_func_set_user_var::fix_fields(THD *thd, Item **ref)
{
DBUG_ASSERT(fixed == 0);
/* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
- if (Item_func::fix_fields(thd, ref) ||
- !(entry= get_variable(&thd->user_vars, name, 1)))
+ if (Item_func::fix_fields(thd, ref) || set_entry(thd, TRUE))
return TRUE;
- /*
- Remember the last query which updated it, this way a query can later know
- if this variable is a constant item in the query (it is if update_query_id
- is different from query_id).
- */
- entry->update_query_id= thd->query_id;
/*
As it is wrong and confusing to associate any
character set with NULL, @a should be latin2
@@ -4791,36 +4803,398 @@ Item_func_get_system_var::
Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
LEX_STRING *component_arg, const char *name_arg,
size_t name_len_arg)
- :var(var_arg), var_type(var_type_arg), component(*component_arg)
+ :var(var_arg), var_type(var_type_arg), orig_var_type(var_type_arg),
+ component(*component_arg), cache_present(0)
{
/* set_name() will allocate the name */
set_name(name_arg, name_len_arg, system_charset_info);
}
-bool
-Item_func_get_system_var::fix_fields(THD *thd, Item **ref)
+bool Item_func_get_system_var::is_written_to_binlog()
{
- Item *item;
- DBUG_ENTER("Item_func_get_system_var::fix_fields");
+ return var->is_written_to_binlog(var_type);
+}
- /*
- Evaluate the system variable and substitute the result (a basic constant)
- instead of this item. If the variable can not be evaluated,
- the error is reported in sys_var::item().
- */
- if (!(item= var->item(thd, var_type, &component)))
- DBUG_RETURN(1); // Impossible
- item->set_name(name, 0, system_charset_info); // don't allocate a new name
- thd->change_item_tree(ref, item);
- DBUG_RETURN(0);
+void Item_func_get_system_var::fix_length_and_dec()
+{
+ maybe_null=0;
+
+ if (var->check_type(var_type))
+ {
+ if (var_type != OPT_DEFAULT)
+ {
+ my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
+ var->name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
+ return;
+ }
+ /* As there was no local variable, return the global value */
+ var_type= OPT_GLOBAL;
+ }
+
+ switch (var->show_type())
+ {
+ case SHOW_LONG:
+ case SHOW_INT:
+ case SHOW_HA_ROWS:
+ unsigned_flag= TRUE;
+ max_length= MY_INT64_NUM_DECIMAL_DIGITS;
+ decimals=0;
+ break;
+ case SHOW_LONGLONG:
+ unsigned_flag= FALSE;
+ max_length= MY_INT64_NUM_DECIMAL_DIGITS;
+ decimals=0;
+ break;
+ case SHOW_CHAR:
+ case SHOW_CHAR_PTR:
+ collation.set(system_charset_info, DERIVATION_SYSCONST);
+ max_length= MAX_BLOB_WIDTH;
+ decimals=NOT_FIXED_DEC;
+ break;
+ case SHOW_MY_BOOL:
+ unsigned_flag= FALSE;
+ max_length= 1;
+ decimals=0;
+ break;
+ case SHOW_DOUBLE:
+ unsigned_flag= FALSE;
+ decimals= 6;
+ max_length= DBL_DIG + 6;
+ break;
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name);
+ break;
+ }
}
-bool Item_func_get_system_var::is_written_to_binlog()
+void Item_func_get_system_var::print(String *str, enum_query_type query_type)
{
- return var->is_written_to_binlog(var_type);
+ str->append(name, name_length);
+}
+
+
+enum Item_result Item_func_get_system_var::result_type() const
+{
+ switch (var->show_type())
+ {
+ case SHOW_MY_BOOL:
+ case SHOW_INT:
+ case SHOW_LONG:
+ case SHOW_LONGLONG:
+ case SHOW_HA_ROWS:
+ return INT_RESULT;
+ case SHOW_CHAR:
+ case SHOW_CHAR_PTR:
+ return STRING_RESULT;
+ case SHOW_DOUBLE:
+ return REAL_RESULT;
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name);
+ return STRING_RESULT; // keep the compiler happy
+ }
+}
+
+
+enum_field_types Item_func_get_system_var::field_type() const
+{
+ switch (var->show_type())
+ {
+ case SHOW_MY_BOOL:
+ case SHOW_INT:
+ case SHOW_LONG:
+ case SHOW_LONGLONG:
+ case SHOW_HA_ROWS:
+ return MYSQL_TYPE_LONGLONG;
+ case SHOW_CHAR:
+ case SHOW_CHAR_PTR:
+ return MYSQL_TYPE_VARCHAR;
+ case SHOW_DOUBLE:
+ return MYSQL_TYPE_DOUBLE;
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name);
+ return MYSQL_TYPE_VARCHAR; // keep the compiler happy
+ }
+}
+
+
+#define get_sys_var_safe(type) \
+do { \
+ type value; \
+ pthread_mutex_lock(&LOCK_global_system_variables); \
+ value= *(type*) var->value_ptr(thd, var_type, &component); \
+ pthread_mutex_unlock(&LOCK_global_system_variables); \
+ cache_present |= GET_SYS_VAR_CACHE_LONG; \
+ used_query_id= thd->query_id; \
+ cached_llval= null_value ? 0 : (longlong) value; \
+ cached_null_value= null_value; \
+ return cached_llval; \
+} while (0)
+
+
+longlong Item_func_get_system_var::val_int()
+{
+ THD *thd= current_thd;
+
+ if (cache_present && thd->query_id == used_query_id)
+ {
+ if (cache_present & GET_SYS_VAR_CACHE_LONG)
+ {
+ null_value= cached_null_value;
+ return cached_llval;
+ }
+ else if (cache_present & GET_SYS_VAR_CACHE_DOUBLE)
+ {
+ null_value= cached_null_value;
+ cached_llval= (longlong) cached_dval;
+ cache_present|= GET_SYS_VAR_CACHE_LONG;
+ return cached_llval;
+ }
+ else if (cache_present & GET_SYS_VAR_CACHE_STRING)
+ {
+ null_value= cached_null_value;
+ if (!null_value)
+ cached_llval= longlong_from_string_with_check (cached_strval.charset(),
+ cached_strval.c_ptr(),
+ cached_strval.c_ptr() +
+ cached_strval.length());
+ else
+ cached_llval= 0;
+ cache_present|= GET_SYS_VAR_CACHE_LONG;
+ return cached_llval;
+ }
+ }
+
+ switch (var->show_type())
+ {
+ case SHOW_INT: get_sys_var_safe (uint);
+ case SHOW_LONG: get_sys_var_safe (ulong);
+ case SHOW_LONGLONG: get_sys_var_safe (longlong);
+ case SHOW_HA_ROWS: get_sys_var_safe (ha_rows);
+ case SHOW_MY_BOOL: get_sys_var_safe (my_bool);
+ case SHOW_DOUBLE:
+ {
+ double dval= val_real();
+
+ used_query_id= thd->query_id;
+ cached_llval= (longlong) dval;
+ cache_present|= GET_SYS_VAR_CACHE_LONG;
+ return cached_llval;
+ }
+ case SHOW_CHAR:
+ case SHOW_CHAR_PTR:
+ {
+ String *str_val= val_str(NULL);
+
+ if (str_val && str_val->length())
+ cached_llval= longlong_from_string_with_check (system_charset_info,
+ str_val->c_ptr(),
+ str_val->c_ptr() +
+ str_val->length());
+ else
+ {
+ null_value= TRUE;
+ cached_llval= 0;
+ }
+
+ cache_present|= GET_SYS_VAR_CACHE_LONG;
+ return cached_llval;
+ }
+
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name);
+ return 0; // keep the compiler happy
+ }
+}
+
+
+String* Item_func_get_system_var::val_str(String* str)
+{
+ THD *thd= current_thd;
+
+ if (cache_present && thd->query_id == used_query_id)
+ {
+ if (cache_present & GET_SYS_VAR_CACHE_STRING)
+ {
+ null_value= cached_null_value;
+ return null_value ? NULL : &cached_strval;
+ }
+ else if (cache_present & GET_SYS_VAR_CACHE_LONG)
+ {
+ null_value= cached_null_value;
+ if (!null_value)
+ cached_strval.set (cached_llval, collation.collation);
+ cache_present|= GET_SYS_VAR_CACHE_STRING;
+ return null_value ? NULL : &cached_strval;
+ }
+ else if (cache_present & GET_SYS_VAR_CACHE_DOUBLE)
+ {
+ null_value= cached_null_value;
+ if (!null_value)
+ cached_strval.set_real (cached_dval, decimals, collation.collation);
+ cache_present|= GET_SYS_VAR_CACHE_STRING;
+ return null_value ? NULL : &cached_strval;
+ }
+ }
+
+ str= &cached_strval;
+ switch (var->show_type())
+ {
+ case SHOW_CHAR:
+ case SHOW_CHAR_PTR:
+ {
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ char *cptr= var->show_type() == SHOW_CHAR_PTR ?
+ *(char**) var->value_ptr(thd, var_type, &component) :
+ (char*) var->value_ptr(thd, var_type, &component);
+ if (cptr)
+ {
+ if (str->copy(cptr, strlen(cptr), collation.collation))
+ {
+ null_value= TRUE;
+ str= NULL;
+ }
+ }
+ else
+ {
+ null_value= TRUE;
+ str= NULL;
+ }
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ break;
+ }
+
+ case SHOW_INT:
+ case SHOW_LONG:
+ case SHOW_LONGLONG:
+ case SHOW_HA_ROWS:
+ case SHOW_MY_BOOL:
+ str->set (val_int(), collation.collation);
+ break;
+ case SHOW_DOUBLE:
+ str->set_real (val_real(), decimals, collation.collation);
+ break;
+
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name);
+ str= NULL;
+ break;
+ }
+
+ cache_present|= GET_SYS_VAR_CACHE_STRING;
+ used_query_id= thd->query_id;
+ cached_null_value= null_value;
+ return str;
+}
+
+
+double Item_func_get_system_var::val_real()
+{
+ THD *thd= current_thd;
+
+ if (cache_present && thd->query_id == used_query_id)
+ {
+ if (cache_present & GET_SYS_VAR_CACHE_DOUBLE)
+ {
+ null_value= cached_null_value;
+ return cached_dval;
+ }
+ else if (cache_present & GET_SYS_VAR_CACHE_LONG)
+ {
+ null_value= cached_null_value;
+ cached_dval= (double)cached_llval;
+ cache_present|= GET_SYS_VAR_CACHE_DOUBLE;
+ return cached_dval;
+ }
+ else if (cache_present & GET_SYS_VAR_CACHE_STRING)
+ {
+ null_value= cached_null_value;
+ if (!null_value)
+ cached_dval= double_from_string_with_check (cached_strval.charset(),
+ cached_strval.c_ptr(),
+ cached_strval.c_ptr() +
+ cached_strval.length());
+ else
+ cached_dval= 0;
+ cache_present|= GET_SYS_VAR_CACHE_DOUBLE;
+ return cached_dval;
+ }
+ }
+
+ switch (var->show_type())
+ {
+ case SHOW_DOUBLE:
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ cached_dval= *(double*) var->value_ptr(thd, var_type, &component);
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ used_query_id= thd->query_id;
+ cached_null_value= null_value;
+ if (null_value)
+ cached_dval= 0;
+ cache_present|= GET_SYS_VAR_CACHE_DOUBLE;
+ return cached_dval;
+ case SHOW_CHAR:
+ case SHOW_CHAR_PTR:
+ {
+ char *cptr;
+
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ cptr= var->show_type() == SHOW_CHAR ?
+ (char*) var->value_ptr(thd, var_type, &component) :
+ *(char**) var->value_ptr(thd, var_type, &component);
+ if (cptr)
+ cached_dval= double_from_string_with_check (system_charset_info,
+ cptr, cptr + strlen (cptr));
+ else
+ {
+ null_value= TRUE;
+ cached_dval= 0;
+ }
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ used_query_id= thd->query_id;
+ cached_null_value= null_value;
+ cache_present|= GET_SYS_VAR_CACHE_DOUBLE;
+ return cached_dval;
+ }
+ case SHOW_INT:
+ case SHOW_LONG:
+ case SHOW_LONGLONG:
+ case SHOW_HA_ROWS:
+ case SHOW_MY_BOOL:
+ cached_dval= (double) val_int();
+ cache_present|= GET_SYS_VAR_CACHE_DOUBLE;
+ used_query_id= thd->query_id;
+ cached_null_value= null_value;
+ return cached_dval;
+ default:
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name);
+ return 0;
+ }
+}
+
+
+bool Item_func_get_system_var::eq(const Item *item, bool binary_cmp) const
+{
+ /* Assume we don't have rtti */
+ if (this == item)
+ return 1; // Same item is same.
+ /* Check if other type is also a get_user_var() object */
+ if (item->type() != FUNC_ITEM ||
+ ((Item_func*) item)->functype() != functype())
+ return 0;
+ Item_func_get_system_var *other=(Item_func_get_system_var*) item;
+ return (var == other->var && var_type == other->var_type);
+}
+
+
+void Item_func_get_system_var::cleanup()
+{
+ Item_func::cleanup();
+ cache_present= 0;
+ var_type= orig_var_type;
+ cached_strval.free();
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 80d4f58ad8a..5f791f495b9 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -55,7 +55,7 @@ public:
NOW_FUNC, TRIG_COND_FUNC,
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC,
- NEG_FUNC };
+ NEG_FUNC, GSYSVAR_FUNC };
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
OPTIMIZE_EQUAL };
enum Type type() const { return FUNC_ITEM; }
@@ -1294,6 +1294,17 @@ class Item_func_set_user_var :public Item_func
{
enum Item_result cached_result_type;
user_var_entry *entry;
+ /*
+ The entry_thd variable is used:
+ 1) to skip unnecessary updates of the entry field (see above);
+ 2) to reset the entry field that was initialized in the other thread
+ (for example, an item tree of a trigger that updates user variables
+ may be shared between several connections, and the entry_thd field
+ prevents updates of one connection user variables from a concurrent
+ connection calling the same trigger that initially updated some
+ user variable it the first connection context).
+ */
+ THD *entry_thd;
char buffer[MAX_FIELD_WIDTH];
String value;
my_decimal decimal_buff;
@@ -1309,7 +1320,8 @@ class Item_func_set_user_var :public Item_func
public:
LEX_STRING name; // keep it public
Item_func_set_user_var(LEX_STRING a,Item *b)
- :Item_func(b), cached_result_type(INT_RESULT), name(a)
+ :Item_func(b), cached_result_type(INT_RESULT),
+ entry(NULL), entry_thd(NULL), name(a)
{}
enum Functype functype() const { return SUSERVAR_FUNC; }
double val_real();
@@ -1340,6 +1352,7 @@ public:
}
void save_org_in_field(Field *field) { (void)save_in_field(field, 1, 0); }
bool register_field_in_read_map(uchar *arg);
+ bool set_entry(THD *thd, bool create_if_not_exists);
};
@@ -1413,24 +1426,36 @@ public:
/* A system variable */
+#define GET_SYS_VAR_CACHE_LONG 1
+#define GET_SYS_VAR_CACHE_DOUBLE 2
+#define GET_SYS_VAR_CACHE_STRING 4
+
class Item_func_get_system_var :public Item_func
{
sys_var *var;
- enum_var_type var_type;
+ enum_var_type var_type, orig_var_type;
LEX_STRING component;
+ longlong cached_llval;
+ double cached_dval;
+ String cached_strval;
+ my_bool cached_null_value;
+ query_id_t used_query_id;
+ uchar cache_present;
+
public:
Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
LEX_STRING *component_arg, const char *name_arg,
size_t name_len_arg);
- bool fix_fields(THD *thd, Item **ref);
- /*
- Stubs for pure virtual methods. Should never be called: this
- item is always substituted with a constant in fix_fields().
- */
- double val_real() { DBUG_ASSERT(0); return 0.0; }
- longlong val_int() { DBUG_ASSERT(0); return 0; }
- String* val_str(String*) { DBUG_ASSERT(0); return 0; }
- void fix_length_and_dec() { DBUG_ASSERT(0); }
+ enum Functype functype() const { return GSYSVAR_FUNC; }
+ void fix_length_and_dec();
+ void print(String *str, enum_query_type query_type);
+ bool const_item() const { return true; }
+ table_map used_tables() const { return 0; }
+ enum Item_result result_type() const;
+ enum_field_types field_type() const;
+ double val_real();
+ longlong val_int();
+ String* val_str(String*);
/* TODO: fix to support views */
const char *func_name() const { return "get_system_var"; }
/**
@@ -1442,6 +1467,9 @@ public:
@return true if the variable is written to the binlog, false otherwise.
*/
bool is_written_to_binlog();
+ bool eq(const Item *item, bool binary_cmp) const;
+
+ void cleanup();
};
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 96f0b6a142d..c2b3b954634 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -369,6 +369,10 @@ Item_sum::Item_sum(List<Item> &list) :arg_count(list.elements),
args[i++]= item;
}
}
+ if (!(orig_args= (Item **) sql_alloc(sizeof(Item *) * arg_count)))
+ {
+ args= NULL;
+ }
mark_as_sum_func();
list.empty(); // Fields are used
}
@@ -379,18 +383,28 @@ Item_sum::Item_sum(List<Item> &list) :arg_count(list.elements),
*/
Item_sum::Item_sum(THD *thd, Item_sum *item):
- Item_result_field(thd, item), arg_count(item->arg_count),
+ Item_result_field(thd, item),
aggr_sel(item->aggr_sel),
nest_level(item->nest_level), aggr_level(item->aggr_level),
- quick_group(item->quick_group), used_tables_cache(item->used_tables_cache),
+ quick_group(item->quick_group),
+ arg_count(item->arg_count), orig_args(NULL),
+ used_tables_cache(item->used_tables_cache),
forced_const(item->forced_const)
{
if (arg_count <= 2)
+ {
args=tmp_args;
+ orig_args=tmp_orig_args;
+ }
else
+ {
if (!(args= (Item**) thd->alloc(sizeof(Item*)*arg_count)))
return;
+ if (!(orig_args= (Item**) thd->alloc(sizeof(Item*)*arg_count)))
+ return;
+ }
memcpy(args, item->args, sizeof(Item*)*arg_count);
+ memcpy(orig_args, item->orig_args, sizeof(Item*)*arg_count);
}
@@ -425,12 +439,13 @@ void Item_sum::make_field(Send_field *tmp_field)
void Item_sum::print(String *str, enum_query_type query_type)
{
+ Item **pargs= orig_args;
str->append(func_name());
for (uint i=0 ; i < arg_count ; i++)
{
if (i)
str->append(',');
- args[i]->print(str, query_type);
+ pargs[i]->print(str, query_type);
}
str->append(')');
}
@@ -535,6 +550,13 @@ void Item_sum::update_used_tables ()
}
+Item *Item_sum::set_arg(int i, THD *thd, Item *new_val)
+{
+ thd->change_item_tree(args + i, new_val);
+ return new_val;
+}
+
+
String *
Item_sum_num::val_str(String *str)
{
@@ -586,6 +608,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref)
if (check_sum_func(thd, ref))
return TRUE;
+ memcpy (orig_args, args, sizeof (Item *) * arg_count);
fixed= 1;
return FALSE;
}
@@ -673,6 +696,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
if (check_sum_func(thd, ref))
return TRUE;
+ orig_args[0]= args[0];
fixed= 1;
return FALSE;
}
@@ -3141,6 +3165,12 @@ Item_func_group_concat(Name_resolution_context *context_arg,
sizeof(ORDER*)*arg_count_order)))
return;
+ if (!(orig_args= (Item **) sql_alloc(sizeof(Item *) * arg_count)))
+ {
+ args= NULL;
+ return;
+ }
+
order= (ORDER**)(args + arg_count);
/* fill args items of show and sort */
@@ -3368,6 +3398,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref)
if (check_sum_func(thd, ref))
return TRUE;
+ memcpy (orig_args, args, sizeof (Item *) * arg_count);
fixed= 1;
return FALSE;
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index bee8792fbfa..d991327d847 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -228,10 +228,8 @@ public:
VARIANCE_FUNC, SUM_BIT_FUNC, UDF_SUM_FUNC, GROUP_CONCAT_FUNC
};
- Item **args, *tmp_args[2];
Item **ref_by; /* pointer to a ref to the object used to register it */
Item_sum *next; /* next in the circular chain of registered objects */
- uint arg_count;
Item_sum *in_sum_func; /* embedding set function if any */
st_select_lex * aggr_sel; /* select where the function is aggregated */
int8 nest_level; /* number of the nesting level of the set function */
@@ -248,24 +246,32 @@ public:
List<Item_field> outer_fields;
protected:
+ uint arg_count;
+ Item **args, *tmp_args[2];
+ /*
+ Copy of the arguments list to hold the original set of arguments.
+ Used in EXPLAIN EXTENDED instead of the current argument list because
+ the current argument list can be altered by usage of temporary tables.
+ */
+ Item **orig_args, *tmp_orig_args[2];
table_map used_tables_cache;
bool forced_const;
public:
void mark_as_sum_func();
- Item_sum() :arg_count(0), quick_group(1), forced_const(FALSE)
+ Item_sum() :quick_group(1), arg_count(0), forced_const(FALSE)
{
mark_as_sum_func();
}
- Item_sum(Item *a) :args(tmp_args), arg_count(1), quick_group(1),
- forced_const(FALSE)
+ Item_sum(Item *a) :quick_group(1), arg_count(1), args(tmp_args),
+ orig_args(tmp_orig_args), forced_const(FALSE)
{
args[0]=a;
mark_as_sum_func();
}
- Item_sum( Item *a, Item *b ) :args(tmp_args), arg_count(2), quick_group(1),
- forced_const(FALSE)
+ Item_sum( Item *a, Item *b ) :quick_group(1), arg_count(2), args(tmp_args),
+ orig_args(tmp_orig_args), forced_const(FALSE)
{
args[0]=a; args[1]=b;
mark_as_sum_func();
@@ -374,6 +380,10 @@ public:
bool register_sum_func(THD *thd, Item **ref);
st_select_lex *depended_from()
{ return (nest_level == aggr_level ? 0 : aggr_sel); }
+
+ Item *get_arg(int i) { return args[i]; }
+ Item *set_arg(int i, THD *thd, Item *new_val);
+ uint get_arg_count() { return arg_count; }
};
@@ -981,6 +991,7 @@ public:
if (udf.fix_fields(thd, this, this->arg_count, this->args))
return TRUE;
+ memcpy (orig_args, args, sizeof (Item *) * arg_count);
return check_sum_func(thd, ref);
}
enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
diff --git a/sql/key.cc b/sql/key.cc
index 47e5c5ebdd7..5b2ae8029dd 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -448,84 +448,104 @@ int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length)
}
-/*
- Compare two records in index order
- SYNOPSIS
- key_rec_cmp()
- key Index information
- rec0 Pointer to table->record[0]
- first_rec Pointer to record compare with
- second_rec Pointer to record compare against first_rec
-
- DESCRIPTION
- This method is set-up such that it can be called directly from the
- priority queue and it is attempted to be optimised as much as possible
- since this will be called O(N * log N) times while performing a merge
- sort in various places in the code.
-
- We retrieve the pointer to table->record[0] using the fact that key_parts
- have an offset making it possible to calculate the start of the record.
- We need to get the diff to the compared record since none of the records
- being compared are stored in table->record[0].
-
- We first check for NULL values, if there are no NULL values we use
- a compare method that gets two field pointers and a max length
- and return the result of the comparison.
+/**
+ Compare two records in index order.
+
+ This method is set-up such that it can be called directly from the
+ priority queue and it is attempted to be optimised as much as possible
+ since this will be called O(N * log N) times while performing a merge
+ sort in various places in the code.
+
+ We retrieve the pointer to table->record[0] using the fact that key_parts
+ have an offset making it possible to calculate the start of the record.
+ We need to get the diff to the compared record since none of the records
+ being compared are stored in table->record[0].
+
+ We first check for NULL values, if there are no NULL values we use
+ a compare method that gets two field pointers and a max length
+ and return the result of the comparison.
+
+ key is a null terminated array, since in some cases (clustered
+ primary key) it must compare more than one index.
+
+ @param key Null terminated array of index information
+ @param first_rec Pointer to record compare with
+ @param second_rec Pointer to record compare against first_rec
+
+ @return Return value is SIGN(first_rec - second_rec)
+ @retval 0 Keys are equal
+ @retval -1 second_rec is greater than first_rec
+ @retval +1 first_rec is greater than second_rec
*/
-int key_rec_cmp(void *key, uchar *first_rec, uchar *second_rec)
+int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec)
{
- KEY *key_info= (KEY*)key;
- uint key_parts= key_info->key_parts, i= 0;
+ KEY **key= (KEY**) key_p;
+ KEY *key_info= *(key++); // Start with first key
+ uint key_parts, key_part_num;
KEY_PART_INFO *key_part= key_info->key_part;
uchar *rec0= key_part->field->ptr - key_part->offset;
my_ptrdiff_t first_diff= first_rec - rec0, sec_diff= second_rec - rec0;
int result= 0;
+ Field *field;
DBUG_ENTER("key_rec_cmp");
+ /* loop over all given keys */
do
{
- Field *field= key_part->field;
+ key_parts= key_info->key_parts;
+ key_part= key_info->key_part;
+ key_part_num= 0;
- if (key_part->null_bit)
+ /* loop over every key part */
+ do
{
- /* The key_part can contain NULL values */
- bool first_is_null= field->is_null_in_record_with_offset(first_diff);
- bool sec_is_null= field->is_null_in_record_with_offset(sec_diff);
- /*
- NULL is smaller then everything so if first is NULL and the other
- not then we know that we should return -1 and for the opposite
- we should return +1. If both are NULL then we call it equality
- although it is a strange form of equality, we have equally little
- information of the real value.
- */
- if (!first_is_null)
+ field= key_part->field;
+
+ if (key_part->null_bit)
{
- if (!sec_is_null)
- ; /* Fall through, no NULL fields */
- else
+ /* The key_part can contain NULL values */
+ bool first_is_null= field->is_null_in_record_with_offset(first_diff);
+ bool sec_is_null= field->is_null_in_record_with_offset(sec_diff);
+ /*
+ NULL is smaller then everything so if first is NULL and the other
+ not then we know that we should return -1 and for the opposite
+ we should return +1. If both are NULL then we call it equality
+ although it is a strange form of equality, we have equally little
+ information of the real value.
+ */
+ if (!first_is_null)
{
- DBUG_RETURN(+1);
+ if (!sec_is_null)
+ ; /* Fall through, no NULL fields */
+ else
+ {
+ DBUG_RETURN(+1);
+ }
}
+ else if (!sec_is_null)
+ {
+ DBUG_RETURN(-1);
+ }
+ else
+ goto next_loop; /* Both were NULL */
}
- else if (!sec_is_null)
- {
- DBUG_RETURN(-1);
- }
- else
- goto next_loop; /* Both were NULL */
- }
- /*
- No null values in the fields
- We use the virtual method cmp_max with a max length parameter.
- For most field types this translates into a cmp without
- max length. The exceptions are the BLOB and VARCHAR field types
- that take the max length into account.
- */
- result= field->cmp_max(field->ptr+first_diff, field->ptr+sec_diff,
- key_part->length);
+ /*
+ No null values in the fields
+ We use the virtual method cmp_max with a max length parameter.
+ For most field types this translates into a cmp without
+ max length. The exceptions are the BLOB and VARCHAR field types
+ that take the max length into account.
+ */
+ if ((result= field->cmp_max(field->ptr+first_diff, field->ptr+sec_diff,
+ key_part->length)))
+ DBUG_RETURN(result);
next_loop:
- key_part++;
- } while (!result && ++i < key_parts);
- DBUG_RETURN(result);
+ key_part++;
+ key_part_num++;
+ } while (key_part_num < key_parts); /* this key is done */
+
+ key_info= *(key++);
+ } while (key_info); /* no more keys to test */
+ DBUG_RETURN(0);
}
diff --git a/sql/lock.cc b/sql/lock.cc
index dbae407d223..21255fb24b0 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -854,7 +854,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
if ((table=table_ptr[i])->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
continue;
lock_type= table->reginfo.lock_type;
- DBUG_ASSERT (lock_type != TL_WRITE_DEFAULT);
+ DBUG_ASSERT(lock_type != TL_WRITE_DEFAULT && lock_type != TL_READ_DEFAULT);
if (lock_type >= TL_WRITE_ALLOW_WRITE)
{
*write_lock_used=table;
diff --git a/sql/log.cc b/sql/log.cc
index b6fe1196835..69bd785cf27 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1377,6 +1377,8 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
FLAGSTR(thd->options, OPTION_NOT_AUTOCOMMIT),
FLAGSTR(thd->options, OPTION_BEGIN)));
+ thd->binlog_flush_pending_rows_event(TRUE);
+
/*
NULL denotes ROLLBACK with nothing to replicate: i.e., rollback of
only transactional tables. If the transaction contain changes to
@@ -1395,8 +1397,6 @@ 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.
*/
- thd->binlog_flush_pending_rows_event(TRUE);
-
error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev);
trx_data->reset();
@@ -3786,7 +3786,7 @@ THD::binlog_set_pending_rows_event(Rows_log_event* ev)
int
MYSQL_BIN_LOG::remove_pending_rows_event(THD *thd)
{
- DBUG_ENTER(__FUNCTION__);
+ DBUG_ENTER("MYSQL_BIN_LOG::remove_pending_rows_event");
binlog_trx_data *const trx_data=
(binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
@@ -4018,11 +4018,6 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
DBUG_PRINT("info",("number of auto_inc intervals: %u",
thd->auto_inc_intervals_in_cur_stmt_for_binlog.
nb_elements()));
- /*
- If the auto_increment was second in a table's index (possible with
- MyISAM or BDB) (table->next_number_keypart != 0), such event is
- in fact not necessary. We could avoid logging it.
- */
Intvar_log_event e(thd, (uchar) INSERT_ID_EVENT,
thd->auto_inc_intervals_in_cur_stmt_for_binlog.
minimum());
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 80eaf808647..686a7e6434e 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -3350,6 +3350,17 @@ int Start_log_event_v3::do_apply_event(Relay_log_info const *rli)
close_temporary_tables(thd);
cleanup_load_tmpdir();
}
+ else
+ {
+ /*
+ Set all temporary tables thread references to the current thread
+ as they may point to the "old" SQL slave thread in case of its
+ restart.
+ */
+ TABLE *table;
+ for (table= thd->temporary_tables; table; table= table->next)
+ table->in_use= thd;
+ }
break;
/*
@@ -7195,6 +7206,9 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
error= do_exec_row(rli);
+ DBUG_PRINT("info", ("error: %s", HA_ERR(error)));
+ DBUG_ASSERT(error != HA_ERR_RECORD_DELETED);
+
table->in_use = old_thd;
switch (error)
{
@@ -7210,11 +7224,13 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
case HA_ERR_TABLE_DEF_CHANGED:
case HA_ERR_CANNOT_ADD_FOREIGN:
-
+
which are not included into to the list.
+
+ Note that HA_ERR_RECORD_DELETED is not in the list since
+ do_exec_row() should not return that error code.
*/
case HA_ERR_RECORD_CHANGED:
- case HA_ERR_RECORD_DELETED:
case HA_ERR_KEY_NOT_FOUND:
case HA_ERR_END_OF_FILE:
case HA_ERR_FOUND_DUPP_KEY:
@@ -7223,7 +7239,6 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
case HA_ERR_NO_REFERENCED_ROW:
case HA_ERR_ROW_IS_REFERENCED:
- DBUG_PRINT("info", ("error: %s", HA_ERR(error)));
if (bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
{
if (global_system_variables.log_warnings)
@@ -7246,7 +7261,6 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
m_curr_row_end.
*/
- DBUG_PRINT("info", ("error: %d", error));
DBUG_PRINT("info", ("curr_row: 0x%lu; curr_row_end: 0x%lu; rows_end: 0x%lu",
(ulong) m_curr_row, (ulong) m_curr_row_end, (ulong) m_rows_end));
@@ -8064,7 +8078,6 @@ Write_rows_log_event::do_before_row_operations(const Slave_reporting_capability
*/
}
- m_table->file->ha_start_bulk_insert(0);
/*
We need TIMESTAMP_NO_AUTO_SET otherwise ha_write_row() will not use fill
any TIMESTAMP column with data from the row but instead will use
@@ -8203,7 +8216,16 @@ Rows_log_event::write_row(const Relay_log_info *const rli,
/* unpack row into table->record[0] */
error= unpack_current_row(rli); // TODO: how to handle errors?
-
+ if (m_curr_row == m_rows_buf)
+ {
+ /* this is the first row to be inserted, we estimate the rows with
+ the size of the first row and use that value to initialize
+ storage engine for bulk insertion */
+ ulong estimated_rows= (m_rows_end - m_curr_row) / (m_curr_row_end - m_curr_row);
+ m_table->file->ha_start_bulk_insert(estimated_rows);
+ }
+
+
#ifndef DBUG_OFF
DBUG_DUMP("record[0]", table->record[0], table->s->reclength);
DBUG_PRINT_BITSET("debug", "write_set = %s", table->write_set);
@@ -8253,6 +8275,8 @@ Rows_log_event::write_row(const Relay_log_info *const rli,
if (error)
{
DBUG_PRINT("info",("rnd_pos() returns error %d",error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
@@ -8285,7 +8309,9 @@ Rows_log_event::write_row(const Relay_log_info *const rli,
HA_READ_KEY_EXACT);
if (error)
{
- DBUG_PRINT("info",("index_read_idx() returns error %d",error));
+ DBUG_PRINT("info",("index_read_idx() returns %s", HA_ERR(error)));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
@@ -8558,6 +8584,8 @@ int Rows_log_event::find_row(const Relay_log_info *rli)
if (error)
{
DBUG_PRINT("info",("rnd_pos returns error %d",error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
}
DBUG_RETURN(error);
@@ -8608,15 +8636,17 @@ int Rows_log_event::find_row(const Relay_log_info *rli)
the necessary bits on the bytes and don't set the filler bits
correctly.
*/
- my_ptrdiff_t const pos=
- table->s->null_bytes > 0 ? table->s->null_bytes - 1 : 0;
- table->record[0][pos]= 0xFF;
-
+ if (table->s->null_bytes > 0)
+ table->record[0][table->s->null_bytes - 1]|=
+ 256U - (1U << table->s->last_null_bit_pos);
+
if ((error= table->file->index_read_map(table->record[0], m_key,
HA_WHOLE_KEY,
HA_READ_KEY_EXACT)))
{
DBUG_PRINT("info",("no record matching the key found in the table"));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
table->file->ha_index_end();
goto err;
@@ -8674,8 +8704,11 @@ int Rows_log_event::find_row(const Relay_log_info *rli)
256U - (1U << table->s->last_null_bit_pos);
}
- if ((error= table->file->index_next(table->record[0])))
+ while ((error= table->file->index_next(table->record[0])))
{
+ /* We just skip records that has already been deleted */
+ if (error == HA_ERR_RECORD_DELETED)
+ continue;
DBUG_PRINT("info",("no record matching the given row found"));
table->file->print_error(error, MYF(0));
table->file->ha_index_end();
@@ -8706,14 +8739,22 @@ int Rows_log_event::find_row(const Relay_log_info *rli)
/* Continue until we find the right record or have made a full loop */
do
{
+ restart_rnd_next:
error= table->file->rnd_next(table->record[0]);
+ DBUG_PRINT("info", ("error: %s", HA_ERR(error)));
switch (error) {
case 0:
- case HA_ERR_RECORD_DELETED:
break;
+ /*
+ If the record was deleted, we pick the next one without doing
+ any comparisons.
+ */
+ case HA_ERR_RECORD_DELETED:
+ goto restart_rnd_next;
+
case HA_ERR_END_OF_FILE:
if (++restart_count < 2)
table->file->ha_rnd_init(1);
@@ -8743,7 +8784,7 @@ int Rows_log_event::find_row(const Relay_log_info *rli)
DBUG_DUMP("record found", table->record[0], table->s->reclength);
table->file->ha_rnd_end();
- DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
+ DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == 0);
goto err;
}
ok:
diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc
index 96076b5c199..6ee2a4549e6 100644
--- a/sql/log_event_old.cc
+++ b/sql/log_event_old.cc
@@ -556,6 +556,9 @@ replace_record(THD *thd, TABLE *table,
error= table->file->rnd_pos(table->record[1], table->file->dup_ref);
if (error)
{
+ DBUG_PRINT("info",("rnd_pos() returns error %d",error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
@@ -582,6 +585,9 @@ replace_record(THD *thd, TABLE *table,
HA_READ_KEY_EXACT);
if (error)
{
+ DBUG_PRINT("info", ("index_read_idx() returns error %d", error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
@@ -787,11 +793,14 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
256U - (1U << table->s->last_null_bit_pos);
}
- if ((error= table->file->index_next(table->record[1])))
+ while ((error= table->file->index_next(table->record[1])))
{
- table->file->print_error(error, MYF(0));
+ /* We just skip records that has already been deleted */
+ if (error == HA_ERR_RECORD_DELETED)
+ continue;
+ table->file->print_error(error, MYF(0));
table->file->ha_index_end();
- DBUG_RETURN(error);
+ DBUG_RETURN(error);
}
}
@@ -812,6 +821,7 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
/* Continue until we find the right record or have made a full loop */
do
{
+ restart_rnd_next:
error= table->file->rnd_next(table->record[1]);
DBUG_DUMP("record[0]", table->record[0], table->s->reclength);
@@ -819,8 +829,14 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
switch (error) {
case 0:
+ break;
+
+ /*
+ If the record was deleted, we pick the next one without doing
+ any comparisons.
+ */
case HA_ERR_RECORD_DELETED:
- break;
+ goto restart_rnd_next;
case HA_ERR_END_OF_FILE:
if (++restart_count < 2)
@@ -1680,6 +1696,9 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli)
error= do_exec_row(rli);
+ DBUG_PRINT("info", ("error: %d", error));
+ DBUG_ASSERT(error != HA_ERR_RECORD_DELETED);
+
table->in_use = old_thd;
switch (error)
{
@@ -2100,6 +2119,8 @@ Old_rows_log_event::write_row(const Relay_log_info *const rli,
if (error)
{
DBUG_PRINT("info",("rnd_pos() returns error %d",error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
@@ -2132,7 +2153,9 @@ Old_rows_log_event::write_row(const Relay_log_info *const rli,
HA_READ_KEY_EXACT);
if (error)
{
- DBUG_PRINT("info",("index_read_idx() returns error %d",error));
+ DBUG_PRINT("info",("index_read_idx() returns error %d", error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
@@ -2288,6 +2311,8 @@ int Old_rows_log_event::find_row(const Relay_log_info *rli)
if (error)
{
DBUG_PRINT("info",("rnd_pos returns error %d",error));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
}
DBUG_RETURN(error);
@@ -2347,6 +2372,8 @@ int Old_rows_log_event::find_row(const Relay_log_info *rli)
HA_READ_KEY_EXACT)))
{
DBUG_PRINT("info",("no record matching the key found in the table"));
+ if (error == HA_ERR_RECORD_DELETED)
+ error= HA_ERR_KEY_NOT_FOUND;
table->file->print_error(error, MYF(0));
table->file->ha_index_end();
DBUG_RETURN(error);
@@ -2404,8 +2431,11 @@ int Old_rows_log_event::find_row(const Relay_log_info *rli)
256U - (1U << table->s->last_null_bit_pos);
}
- if ((error= table->file->index_next(table->record[0])))
+ while ((error= table->file->index_next(table->record[0])))
{
+ /* We just skip records that has already been deleted */
+ if (error == HA_ERR_RECORD_DELETED)
+ continue;
DBUG_PRINT("info",("no record matching the given row found"));
table->file->print_error(error, MYF(0));
table->file->ha_index_end();
@@ -2436,14 +2466,17 @@ int Old_rows_log_event::find_row(const Relay_log_info *rli)
/* Continue until we find the right record or have made a full loop */
do
{
+ restart_rnd_next:
error= table->file->rnd_next(table->record[0]);
switch (error) {
case 0:
- case HA_ERR_RECORD_DELETED:
break;
+ case HA_ERR_RECORD_DELETED:
+ goto restart_rnd_next;
+
case HA_ERR_END_OF_FILE:
if (++restart_count < 2)
table->file->ha_rnd_init(1);
diff --git a/sql/message.h b/sql/message.h
new file mode 100644
index 00000000000..0e7c282d5a1
--- /dev/null
+++ b/sql/message.h
@@ -0,0 +1,55 @@
+/*
+ To change or add messages mysqld writes to the Windows error log, run
+ mc.exe message.mc
+ and checkin generated messages.h, messages.rc and msg000001.bin under the
+ source control.
+ mc.exe can be installed with Windows SDK, some Visual Studio distributions
+ do not include it.
+*/
+//
+// Values are 32 bit values layed out as follows:
+//
+// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +---+-+-+-----------------------+-------------------------------+
+// |Sev|C|R| Facility | Code |
+// +---+-+-+-----------------------+-------------------------------+
+//
+// where
+//
+// Sev - is the severity code
+//
+// 00 - Success
+// 01 - Informational
+// 10 - Warning
+// 11 - Error
+//
+// C - is the Customer code flag
+//
+// R - is a reserved bit
+//
+// Facility - is the facility code
+//
+// Code - is the facility's status code
+//
+//
+// Define the facility codes
+//
+
+
+//
+// Define the severity codes
+//
+
+
+//
+// MessageId: MSG_DEFAULT
+//
+// MessageText:
+//
+// %1For more information, see Help and Support Center at http://www.mysql.com.
+//
+//
+//
+#define MSG_DEFAULT 0xC0000064L
+
diff --git a/sql/message.mc b/sql/message.mc
index a1a7c8cff7e..8d68d599365 100644
--- a/sql/message.mc
+++ b/sql/message.mc
@@ -1,3 +1,11 @@
+;/*
+; To change or add messages mysqld writes to the Windows error log, run
+; mc.exe message.mc
+; and checkin generated messages.h, messages.rc and msg000001.bin under the
+; source control.
+; mc.exe can be installed with Windows SDK, some Visual Studio distributions
+; do not include it.
+;*/
MessageId = 100
Severity = Error
Facility = Application
diff --git a/sql/message.rc b/sql/message.rc
new file mode 100644
index 00000000000..116522b7d48
--- /dev/null
+++ b/sql/message.rc
@@ -0,0 +1,2 @@
+LANGUAGE 0x9,0x1
+1 11 MSG00001.bin
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index d4182ce5474..bbb724c4ffd 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -801,6 +801,7 @@ bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
uint max_char_length, CHARSET_INFO *cs,
bool no_error);
+bool check_host_name(LEX_STRING *str);
bool parse_sql(THD *thd,
Parser_state *parser_state,
@@ -1266,6 +1267,7 @@ bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
TABLE_LIST *new_child_list, TABLE_LIST **new_last);
bool reopen_table(TABLE *table);
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
+thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table);
void close_data_files_and_morph_locks(THD *thd, const char *db,
const char *table_name);
void close_handle_and_leave_table_as_lock(TABLE *table);
@@ -1939,7 +1941,7 @@ extern bool opt_using_transactions;
extern bool mysqld_embedded;
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
#ifdef MYSQL_SERVER
-extern bool using_update_log, opt_large_files, server_id_supplied;
+extern bool opt_large_files, server_id_supplied;
extern bool opt_update_log, opt_bin_log, opt_error_log;
extern my_bool opt_log, opt_slow_log;
extern ulong log_output_options;
@@ -2246,6 +2248,7 @@ uint build_table_shadow_filename(char *buff, size_t bufflen,
#define FN_TO_IS_TMP (1 << 1)
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
#define NO_FRM_RENAME (1 << 2)
+#define FRM_ONLY (1 << 3)
/* from hostname.cc */
struct in_addr;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 3b176e8d37f..acfa6095a30 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -384,7 +384,7 @@ my_bool opt_character_set_client_handshake= 1;
bool server_id_supplied = 0;
bool opt_endinfo, using_udf_functions;
my_bool locked_in_memory;
-bool opt_using_transactions, using_update_log;
+bool opt_using_transactions;
bool volatile abort_loop;
bool volatile shutdown_in_progress;
/**
@@ -2809,11 +2809,24 @@ int my_message_sql(uint error, const char *str, myf MyFlags)
sql_print_message_func func;
DBUG_ENTER("my_message_sql");
DBUG_PRINT("error", ("error: %u message: '%s'", error, str));
+
+ DBUG_ASSERT(str != NULL);
/*
- Put here following assertion when situation with EE_* error codes
- will be fixed
+ An error should have a valid error number (!= 0), so it can be caught
+ in stored procedures by SQL exception handlers.
+ Calling my_error() with error == 0 is a bug.
+ Remaining known places to fix:
+ - storage/myisam/mi_create.c, my_printf_error()
+ TODO:
DBUG_ASSERT(error != 0);
*/
+ if (error == 0)
+ {
+ /* At least, prevent new abuse ... */
+ DBUG_ASSERT(strncmp(str, "MyISAM table", 12) == 0);
+ error= ER_UNKNOWN_ERROR;
+ }
+
if (MyFlags & ME_JUST_INFO)
{
level= MYSQL_ERROR::WARN_LEVEL_NOTE;
@@ -2864,10 +2877,6 @@ int my_message_sql(uint error, const char *str, myf MyFlags)
{
if (! thd->main_da.is_error()) // Return only first message
{
- if (error == 0)
- error= ER_UNKNOWN_ERROR;
- if (str == NULL)
- str= ER(error);
thd->main_da.set_error_status(thd, error, str);
}
query_cache_abort(&thd->net);
@@ -3414,7 +3423,7 @@ static int init_common_variables(const char *conf_file_name, int argc,
if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE)
&& !(log_output_options & LOG_NONE))
sql_print_warning("Although a path was specified for the "
- "--log-slow-queries option, log tables are used. "
+ "--log_slow_queries option, log tables are used. "
"To enable logging to files use the --log-output=file option.");
s= opt_logname ? opt_logname : make_default_log_name(buff, ".log");
@@ -3792,23 +3801,25 @@ with --log-bin instead.");
unireg_abort(1);
}
if (!opt_bin_log)
- if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
{
- sql_print_error("You need to use --log-bin to make "
- "--binlog-format work.");
- unireg_abort(1);
- }
+ if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
+ {
+ sql_print_error("You need to use --log-bin to make "
+ "--binlog-format work.");
+ unireg_abort(1);
+ }
else
- {
- global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
+ {
+ global_system_variables.binlog_format= BINLOG_FORMAT_STMT;
}
+ }
else
if (opt_binlog_format_id == BINLOG_FORMAT_UNSPEC)
- global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
+ global_system_variables.binlog_format= BINLOG_FORMAT_STMT;
else
{
DBUG_ASSERT(global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC);
- }
+ }
/* Check that we have not let the format to unspecified at this point */
DBUG_ASSERT((uint)global_system_variables.binlog_format <=
@@ -3854,12 +3865,6 @@ server.");
{
unireg_abort(1);
}
-
- /*
- Used to specify which type of lock we need to use for queries of type
- INSERT ... SELECT. This will change when we have row level logging.
- */
- using_update_log=1;
}
/* call ha_init_key_cache() on all key caches to init them */
@@ -5590,7 +5595,9 @@ enum options_mysqld
OPT_DEADLOCK_SEARCH_DEPTH_SHORT,
OPT_DEADLOCK_SEARCH_DEPTH_LONG,
OPT_DEADLOCK_TIMEOUT_SHORT,
- OPT_DEADLOCK_TIMEOUT_LONG
+ OPT_DEADLOCK_TIMEOUT_LONG,
+ OPT_GENERAL_LOG_FILE,
+ OPT_SLOW_QUERY_LOG_FILE
};
@@ -5812,7 +5819,7 @@ struct my_option my_long_options[] =
"Set up signals usable for debugging",
(uchar**) &opt_debugging, (uchar**) &opt_debugging,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"general-log", OPT_GENERAL_LOG,
+ {"general_log", OPT_GENERAL_LOG,
"Enable|disable general log", (uchar**) &opt_log,
(uchar**) &opt_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifdef HAVE_LARGE_PAGES
@@ -5848,8 +5855,12 @@ Disable with --skip-large-pages.",
(uchar**) &opt_local_infile,
(uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
1, 0, 0, 0, 0, 0},
- {"log", 'l', "Log connections and queries to file.", (uchar**) &opt_logname,
+ {"log", 'l', "Log connections and queries to file (deprecated option, use "
+ "--general_log/--general_log_file instead).", (uchar**) &opt_logname,
(uchar**) &opt_logname, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"general_log_file", OPT_GENERAL_LOG_FILE,
+ "Log connections and queries to given file.", (uchar**) &opt_logname,
+ (uchar**) &opt_logname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"log-bin", OPT_BIN_LOG,
"Log update queries in binary format. Optional (but strongly recommended "
"to avoid replication problems if server's hostname changes) argument "
@@ -5923,10 +5934,17 @@ Disable with --skip-large-pages.",
(uchar**) &opt_log_slow_slave_statements,
(uchar**) &opt_log_slow_slave_statements,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"log-slow-queries", OPT_SLOW_QUERY_LOG,
- "Log slow queries to a table or log file. Defaults logging to table mysql.slow_log or hostname-slow.log if --log-output=file is used. Must be enabled to activate other slow log options.",
+ {"log_slow_queries", OPT_SLOW_QUERY_LOG,
+ "Log slow queries to a table or log file. Defaults logging to table "
+ "mysql.slow_log or hostname-slow.log if --log-output=file is used. "
+ "Must be enabled to activate other slow log options. "
+ "(deprecated option, use --slow_query_log/--slow_query_log_file instead)",
(uchar**) &opt_slow_logname, (uchar**) &opt_slow_logname, 0, GET_STR, OPT_ARG,
0, 0, 0, 0, 0, 0},
+ {"slow_query_log_file", OPT_SLOW_QUERY_LOG_FILE,
+ "Log slow queries to given log file. Defaults logging to hostname-slow.log. Must be enabled to activate other slow log options.",
+ (uchar**) &opt_slow_logname, (uchar**) &opt_slow_logname, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"log-tc", OPT_LOG_TC,
"Path to transaction coordinator log (used for transactions that affect "
"more than one storage engine, when binary log is disabled)",
@@ -6308,7 +6326,7 @@ Can't be set to 1 if --log-slave-updates is used.",
{"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables. Deprecated option. Use --skip-symbolic-links instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-thread-priority", OPT_SKIP_PRIOR,
- "Don't give threads different priorities.", 0, 0, 0, GET_NO_ARG, NO_ARG,
+ "Don't give threads different priorities. Deprecated option.", 0, 0, 0, GET_NO_ARG, NO_ARG,
DEFAULT_SKIP_THREAD_PRIORITY, 0, 0, 0, 0, 0},
#ifdef HAVE_REPLICATION
{"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR,
@@ -6722,9 +6740,10 @@ The minimum value for this variable is 4096.",
"Directory for plugins.",
(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 "
- "identified by name and path to library seperated by an equals.",
+ {"plugin-load", OPT_PLUGIN_LOAD,
+ "Optional colon-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,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
@@ -7512,7 +7531,7 @@ static void mysql_init_variables(void)
slave_open_temp_tables= 0;
cached_thread_count= 0;
opt_endinfo= using_udf_functions= 0;
- opt_using_transactions= using_update_log= 0;
+ opt_using_transactions= 0;
abort_loop= select_thread_in_use= signal_thread_in_use= 0;
ready_to_exit= shutdown_in_progress= grant_option= 0;
aborted_threads= aborted_connects= 0;
@@ -7623,13 +7642,13 @@ static void mysql_init_variables(void)
have_community_features = SHOW_OPTION_YES;
#else
have_community_features = SHOW_OPTION_NO;
+#endif
global_system_variables.ndb_index_stat_enable=FALSE;
max_system_variables.ndb_index_stat_enable=TRUE;
global_system_variables.ndb_index_stat_cache_entries=32;
max_system_variables.ndb_index_stat_cache_entries=~0L;
global_system_variables.ndb_index_stat_update_freq=20;
max_system_variables.ndb_index_stat_update_freq=~0L;
-#endif
#ifdef HAVE_OPENSSL
have_ssl=SHOW_OPTION_YES;
#else
@@ -7747,6 +7766,7 @@ mysqld_get_one_option(int optid,
default_collation_name= 0;
break;
case 'l':
+ WARN_DEPRECATED(NULL, "7.0", "--log", "'--general_log'/'--general_log_file'");
opt_log=1;
break;
case 'h':
@@ -7916,6 +7936,7 @@ mysqld_get_one_option(int optid,
}
#endif /* HAVE_REPLICATION */
case (int) OPT_SLOW_QUERY_LOG:
+ WARN_DEPRECATED(NULL, "7.0", "--log_slow_queries", "'--slow_query_log'/'--slow_query_log_file'");
opt_slow_log= 1;
break;
#ifdef WITH_CSV_STORAGE_ENGINE
@@ -7963,6 +7984,9 @@ mysqld_get_one_option(int optid,
break;
case (int) OPT_SKIP_PRIOR:
opt_specialflag|= SPECIAL_NO_PRIOR;
+ sql_print_warning("The --skip-thread-priority startup option is deprecated "
+ "and will be removed in MySQL 7.0. MySQL 6.0 and up do not "
+ "give threads different priorities.");
break;
case (int) OPT_SKIP_LOCK:
opt_external_locking=0;
@@ -8305,7 +8329,7 @@ static void get_options(int *argc,char **argv)
if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes ||
opt_log_slow_slave_statements) &&
!opt_slow_log)
- sql_print_warning("options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log-slow-queries is not set");
+ sql_print_warning("options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set");
#if defined(HAVE_BROKEN_REALPATH)
my_use_symdir=0;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 28ee8af0699..bafc368e415 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -574,6 +574,7 @@ public:
keys_map.clear_all();
bzero((char*) keys,sizeof(keys));
}
+ SEL_TREE(SEL_TREE *arg, RANGE_OPT_PARAM *param);
/*
Note: there may exist SEL_TREE objects with sel_tree->type=KEY and
keys[i]=0 for all i. (SergeyP: it is not clear whether there is any
@@ -767,6 +768,7 @@ public:
trees_next(trees),
trees_end(trees + PREALLOCED_TREES)
{}
+ SEL_IMERGE (SEL_IMERGE *arg, RANGE_OPT_PARAM *param);
int or_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree);
int or_sel_tree_with_checks(RANGE_OPT_PARAM *param, SEL_TREE *new_tree);
int or_sel_imerge_with_checks(RANGE_OPT_PARAM *param, SEL_IMERGE* imerge);
@@ -883,6 +885,61 @@ int SEL_IMERGE::or_sel_imerge_with_checks(RANGE_OPT_PARAM *param, SEL_IMERGE* im
}
+SEL_TREE::SEL_TREE(SEL_TREE *arg, RANGE_OPT_PARAM *param): Sql_alloc()
+{
+ keys_map= arg->keys_map;
+ type= arg->type;
+ for (int idx= 0; idx < MAX_KEY; idx++)
+ {
+ if ((keys[idx]= arg->keys[idx]))
+ keys[idx]->increment_use_count(1);
+ }
+
+ List_iterator<SEL_IMERGE> it(arg->merges);
+ for (SEL_IMERGE *el= it++; el; el= it++)
+ {
+ SEL_IMERGE *merge= new SEL_IMERGE(el, param);
+ if (!merge || merge->trees == merge->trees_next)
+ {
+ merges.empty();
+ return;
+ }
+ merges.push_back (merge);
+ }
+}
+
+
+SEL_IMERGE::SEL_IMERGE (SEL_IMERGE *arg, RANGE_OPT_PARAM *param) : Sql_alloc()
+{
+ uint elements= (arg->trees_end - arg->trees);
+ if (elements > PREALLOCED_TREES)
+ {
+ uint size= elements * sizeof (SEL_TREE **);
+ if (!(trees= (SEL_TREE **)alloc_root(param->mem_root, size)))
+ goto mem_err;
+ }
+ else
+ trees= &trees_prealloced[0];
+
+ trees_next= trees;
+ trees_end= trees + elements;
+
+ for (SEL_TREE **tree = trees, **arg_tree= arg->trees; tree < trees_end;
+ tree++, arg_tree++)
+ {
+ if (!(*tree= new SEL_TREE(*arg_tree, param)))
+ goto mem_err;
+ }
+
+ return;
+
+mem_err:
+ trees= &trees_prealloced[0];
+ trees_next= trees;
+ trees_end= trees;
+}
+
+
/*
Perform AND operation on two index_merge lists and store result in *im1.
*/
@@ -942,10 +999,23 @@ int imerge_list_or_tree(RANGE_OPT_PARAM *param,
{
SEL_IMERGE *imerge;
List_iterator<SEL_IMERGE> it(*im1);
+ bool tree_used= FALSE;
while ((imerge= it++))
{
- if (imerge->or_sel_tree_with_checks(param, tree))
+ SEL_TREE *or_tree;
+ if (tree_used)
+ {
+ or_tree= new SEL_TREE (tree, param);
+ if (!or_tree ||
+ (or_tree->keys_map.is_clear_all() && or_tree->merges.is_empty()))
+ return FALSE;
+ }
+ else
+ or_tree= tree;
+
+ if (imerge->or_sel_tree_with_checks(param, or_tree))
it.remove();
+ tree_used= TRUE;
}
return im1->is_empty();
}
@@ -1081,7 +1151,7 @@ int QUICK_RANGE_SELECT::init()
if (file->inited != handler::NONE)
file->ha_index_or_rnd_end();
- DBUG_RETURN(error= file->ha_index_init(index, 1));
+ DBUG_RETURN(FALSE);
}
@@ -3145,10 +3215,12 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree)
ppar->subpart_fields););
/* Find the subpartition (it's HASH/KEY so we always have one) */
partition_info *part_info= ppar->part_info;
- uint32 subpart_id= part_info->get_subpartition_id(part_info);
-
+ uint32 part_id, subpart_id;
+
+ if (part_info->get_subpartition_id(part_info, &subpart_id))
+ return 0;
+
/* Mark this partition as used in each subpartition. */
- uint32 part_id;
while ((part_id= ppar->part_iter.get_next(&ppar->part_iter)) !=
NOT_A_PARTITION_ID)
{
@@ -5547,7 +5619,9 @@ get_mm_parts(RANGE_OPT_PARAM *param, COND *cond_func, Field *field,
tree->keys_map.set_bit(key_part->key);
}
}
-
+
+ if (tree && tree->merges.is_empty() && tree->keys_map.is_clear_all())
+ tree= NULL;
DBUG_RETURN(tree);
}
@@ -9126,7 +9200,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree)
DBUG_RETURN(NULL);
/* The argument of MIN/MAX. */
- Item *expr= min_max_item->args[0]->real_item();
+ Item *expr= min_max_item->get_arg(0)->real_item();
if (expr->type() == Item::FIELD_ITEM) /* Is it an attribute? */
{
if (! min_max_arg_item)
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 334eae55265..f0f856c3c6a 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -199,7 +199,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
to the number of rows in the tables if this number is exact and
there are no outer joins.
*/
- if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null &&
+ if (!conds && !((Item_sum_count*) item)->get_arg(0)->maybe_null &&
!outer_tables && maybe_exact_count)
{
if (!is_exact_count)
@@ -225,7 +225,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
parts of the key is found in the COND, then we can use
indexes to find the key.
*/
- Item *expr=item_sum->args[0];
+ Item *expr=item_sum->get_arg(0);
if (expr->real_item()->type() == Item::FIELD_ITEM)
{
uchar key_buff[MAX_KEY_LENGTH];
@@ -373,7 +373,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
parts of the key is found in the COND, then we can use
indexes to find the key.
*/
- Item *expr=item_sum->args[0];
+ Item *expr=item_sum->get_arg(0);
if (expr->real_item()->type() == Item::FIELD_ITEM)
{
uchar key_buff[MAX_KEY_LENGTH];
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index 1f0a45edd5e..d8cbc7ff174 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -26,6 +26,9 @@
#include <my_sys.h>
#include <my_dir.h>
+/* from sql_db.cc */
+extern long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
+
/**
Write string with escaping.
@@ -282,8 +285,9 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
DBUG_RETURN(TRUE);
}
- // archive copies management
path[path_end]='\0';
+#ifdef FRM_ARCHIVE
+ // archive copies management: disabled unused feature (see bug #17823).
if (!access(path, F_OK))
{
if (old_version != ULONGLONG_MAX && max_versions != 0)
@@ -330,6 +334,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
}
}
}
+#endif//FRM_ARCHIVE
{
// rename temporary file
@@ -352,6 +357,7 @@ err_w_file:
/**
Renames a frm file (including backups) in same schema.
+ @thd thread handler
@param schema name of given schema
@param old_name original file name
@param new_name new file name
@@ -363,7 +369,8 @@ err_w_file:
@retval
1 Error (only if renaming of frm failed)
*/
-my_bool rename_in_schema_file(const char *schema, const char *old_name,
+my_bool rename_in_schema_file(THD *thd,
+ const char *schema, const char *old_name,
const char *new_name, ulonglong revision,
uint num_view_backups)
{
@@ -377,9 +384,10 @@ my_bool rename_in_schema_file(const char *schema, const char *old_name,
if (my_rename(old_path, new_path, MYF(MY_WME)))
return 1;
- /* check if arc_dir exists */
+ /* check if arc_dir exists: disabled unused feature (see bug #17823). */
build_table_filename(arc_path, sizeof(arc_path) - 1, schema, "arc", "", 0);
+#ifdef FRM_ARCHIVE
if (revision > 0 && !access(arc_path, F_OK))
{
char old_name_buf[FN_REFLEN], new_name_buf[FN_REFLEN];
@@ -400,6 +408,16 @@ my_bool rename_in_schema_file(const char *schema, const char *old_name,
my_rename(old_path, new_path, MYF(0));
}
}
+#else//FRM_ARCHIVE
+ { // remove obsolete 'arc' directory and files if any
+ MY_DIR *new_dirp;
+ if ((new_dirp = my_dir(arc_path, MYF(MY_DONT_SORT))))
+ {
+ DBUG_PRINT("my",("Archive subdir found: %s", arc_path));
+ (void) mysql_rm_arc_files(thd, new_dirp, arc_path);
+ }
+ }
+#endif//FRM_ARCHIVE
return 0;
}
diff --git a/sql/parse_file.h b/sql/parse_file.h
index 30c902478b8..c05b2853b9a 100644
--- a/sql/parse_file.h
+++ b/sql/parse_file.h
@@ -82,8 +82,9 @@ my_bool
sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
const LEX_STRING *type,
uchar* base, File_option *parameters, uint versions);
-my_bool rename_in_schema_file(const char *schema, const char *old_name,
- const char *new_name, ulonglong revision,
+my_bool rename_in_schema_file(THD *thd,
+ const char *schema, const char *old_name,
+ const char *new_name, ulonglong revision,
uint num_view_backups);
class File_parser: public Sql_alloc
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 808f305db2c..dfdd29975ac 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -956,11 +956,13 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
#endif
{
if (part_elem->data_file_name)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "DATA DIRECTORY option ignored");
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
+ "DATA DIRECTORY");
if (part_elem->index_file_name)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "INDEX DIRECTORY option ignored");
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
+ "INDEX DIRECTORY");
part_elem->data_file_name= part_elem->index_file_name= NULL;
}
if (!is_sub_partitioned())
diff --git a/sql/partition_info.h b/sql/partition_info.h
index 2af7fa1717c..703b92305b1 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -25,8 +25,9 @@ class partition_info;
typedef int (*get_part_id_func)(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
-typedef uint32 (*get_subpart_id_func)(partition_info *part_info);
-
+typedef int (*get_subpart_id_func)(partition_info *part_info,
+ uint32 *part_id);
+
struct st_ddl_log_memory_entry;
class partition_info : public Sql_alloc
diff --git a/sql/set_var.cc b/sql/set_var.cc
index df1badebc50..cd33ae16e65 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -1747,119 +1747,6 @@ err:
}
-/**
- Return an Item for a variable.
-
- Used with @@[global.]variable_name.
-
- If type is not given, return local value if exists, else global.
-*/
-
-Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
-{
- if (check_type(var_type))
- {
- if (var_type != OPT_DEFAULT)
- {
- my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
- name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
- return 0;
- }
- /* As there was no local variable, return the global value */
- var_type= OPT_GLOBAL;
- }
- switch (show_type()) {
- case SHOW_INT:
- {
- uint value;
- pthread_mutex_lock(&LOCK_global_system_variables);
- value= *(uint*) value_ptr(thd, var_type, base);
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return new Item_uint((ulonglong) value);
- }
- case SHOW_LONG:
- {
- ulong value;
- pthread_mutex_lock(&LOCK_global_system_variables);
- value= *(ulong*) value_ptr(thd, var_type, base);
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return new Item_uint((ulonglong) value);
- }
- case SHOW_LONGLONG:
- {
- longlong value;
- pthread_mutex_lock(&LOCK_global_system_variables);
- value= *(longlong*) value_ptr(thd, var_type, base);
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return new Item_int(value);
- }
- case SHOW_DOUBLE:
- {
- double value;
- pthread_mutex_lock(&LOCK_global_system_variables);
- value= *(double*) value_ptr(thd, var_type, base);
- pthread_mutex_unlock(&LOCK_global_system_variables);
- /* 6, as this is for now only used with microseconds */
- return new Item_float(value, 6);
- }
- case SHOW_HA_ROWS:
- {
- ha_rows value;
- pthread_mutex_lock(&LOCK_global_system_variables);
- value= *(ha_rows*) value_ptr(thd, var_type, base);
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return new Item_int((ulonglong) value);
- }
- case SHOW_MY_BOOL:
- {
- int32 value;
- pthread_mutex_lock(&LOCK_global_system_variables);
- value= *(my_bool*) value_ptr(thd, var_type, base);
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return new Item_int(value,1);
- }
- case SHOW_CHAR_PTR:
- {
- Item *tmp;
- pthread_mutex_lock(&LOCK_global_system_variables);
- char *str= *(char**) value_ptr(thd, var_type, base);
- if (str)
- {
- uint length= strlen(str);
- tmp= new Item_string(thd->strmake(str, length), length,
- system_charset_info, DERIVATION_SYSCONST);
- }
- else
- {
- tmp= new Item_null();
- tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
- }
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return tmp;
- }
- case SHOW_CHAR:
- {
- Item *tmp;
- pthread_mutex_lock(&LOCK_global_system_variables);
- char *str= (char*) value_ptr(thd, var_type, base);
- if (str)
- tmp= new Item_string(str, strlen(str),
- system_charset_info, DERIVATION_SYSCONST);
- else
- {
- tmp= new Item_null();
- tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
- }
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return tmp;
- }
- default:
- my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
- }
- return 0;
-}
-
-
bool sys_var_thd_enum::update(THD *thd, set_var *var)
{
if (var->type == OPT_GLOBAL)
@@ -2403,6 +2290,12 @@ end:
bool sys_var_log_state::update(THD *thd, set_var *var)
{
bool res;
+
+ if (this == &sys_var_log)
+ WARN_DEPRECATED(thd, "7.0", "@@log", "'@@general_log'");
+ else if (this == &sys_var_log_slow)
+ WARN_DEPRECATED(thd, "7.0", "@@log_slow_queries", "'@@slow_query_log'");
+
pthread_mutex_lock(&LOCK_global_system_variables);
if (!var->save_result.ulong_value)
{
@@ -2417,6 +2310,11 @@ bool sys_var_log_state::update(THD *thd, set_var *var)
void sys_var_log_state::set_default(THD *thd, enum_var_type type)
{
+ if (this == &sys_var_log)
+ WARN_DEPRECATED(thd, "7.0", "@@log", "'@@general_log'");
+ else if (this == &sys_var_log_slow)
+ WARN_DEPRECATED(thd, "7.0", "@@log_slow_queries", "'@@slow_query_log'");
+
pthread_mutex_lock(&LOCK_global_system_variables);
logger.deactivate_log_handler(thd, log_type);
pthread_mutex_unlock(&LOCK_global_system_variables);
@@ -3723,7 +3621,7 @@ bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
void sys_var_thd_table_type::warn_deprecated(THD *thd)
{
- WARN_DEPRECATED(thd, "5.2", "table_type", "'storage_engine'");
+ WARN_DEPRECATED(thd, "5.2", "@@table_type", "'@@storage_engine'");
}
void sys_var_thd_table_type::set_default(THD *thd, enum_var_type type)
@@ -3985,8 +3883,8 @@ bool process_key_caches(process_key_cache_t func)
void sys_var_trust_routine_creators::warn_deprecated(THD *thd)
{
- WARN_DEPRECATED(thd, "5.2", "log_bin_trust_routine_creators",
- "'log_bin_trust_function_creators'");
+ WARN_DEPRECATED(thd, "5.2", "@@log_bin_trust_routine_creators",
+ "'@@log_bin_trust_function_creators'");
}
void sys_var_trust_routine_creators::set_default(THD *thd, enum_var_type type)
diff --git a/sql/set_var.h b/sql/set_var.h
index 8ae97c6502d..9681c955a98 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -105,7 +105,6 @@ public:
{ return type != INT_RESULT; } /* Assume INT */
virtual bool check_default(enum_var_type type)
{ return option_limits == 0; }
- Item *item(THD *thd, enum_var_type type, LEX_STRING *base);
virtual bool is_struct() { return 0; }
virtual bool is_readonly() const { return 0; }
virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index 84eb5f5ba64..b86007408fb 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -6128,8 +6128,26 @@ ER_LOAD_DATA_INVALID_COLUMN
ER_LOG_PURGE_NO_FILE
eng "Being purged log %s was not found"
+ER_XA_RBTIMEOUT XA106
+ eng "XA_RBTIMEOUT: Transaction branch was rolled back: took too long"
+
+ER_XA_RBDEADLOCK XA102
+ eng "XA_RBDEADLOCK: Transaction branch was rolled back: deadlock was detected"
+
ER_NEED_REPREPARE
eng "Prepared statement needs to be re-prepared"
ER_DELAYED_NOT_SUPPORTED
eng "DELAYED option not supported for table '%-.192s'"
+
+WARN_NO_MASTER_INFO
+ eng "The master info structure does not exist"
+
+WARN_OPTION_IGNORED
+ eng "<%-.64s> option ignored"
+
+WARN_PLUGIN_DELETE_BUILTIN
+ eng "Built-in plugins cannot be deleted"
+
+WARN_PLUGIN_BUSY
+ eng "Plugin is busy and will be uninstalled on shutdown"
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index d1f920fd3a5..534cd0a7ca1 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -126,6 +126,9 @@ sp_get_item_value(THD *thd, Item *item, String *str)
if (cs->escape_with_backslash_is_dangerous)
buf.append(' ');
append_query_string(cs, result, &buf);
+ buf.append(" COLLATE '");
+ buf.append(item->collation.collation->name);
+ buf.append('\'');
str->copy(buf);
return str;
@@ -1940,10 +1943,14 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
we'll leave it here.
*/
if (!thd->in_sub_stmt)
- close_thread_tables(thd);
+ {
+ thd->lex->unit.cleanup();
+ close_thread_tables(thd);
+ thd->rollback_item_tree_changes();
+ }
- DBUG_PRINT("info",(" %.*s: eval args done",
- (int) m_name.length, m_name.str));
+ DBUG_PRINT("info",(" %.*s: eval args done", (int) m_name.length,
+ m_name.str));
}
if (!(m_flags & LOG_SLOW_STATEMENTS) && thd->enable_slow_log)
{
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0b993748fc3..7ecbce4154a 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -489,12 +489,20 @@ static TABLE_SHARE
"no such table" errors.
@todo Rework the alternative ways to deal with ER_NO_SUCH TABLE.
*/
- if (thd->is_error() && table_list->belong_to_view)
+ if (thd->is_error())
{
- TABLE_LIST *view= table_list->belong_to_view;
- thd->clear_error();
- my_error(ER_VIEW_INVALID, MYF(0),
- view->view_db.str, view->view_name.str);
+ if (table_list->parent_l)
+ {
+ thd->clear_error();
+ my_error(ER_WRONG_MRG_TABLE, MYF(0));
+ }
+ else if (table_list->belong_to_view)
+ {
+ TABLE_LIST *view= table_list->belong_to_view;
+ thd->clear_error();
+ my_error(ER_VIEW_INVALID, MYF(0),
+ view->view_db.str, view->view_name.str);
+ }
}
DBUG_RETURN(0);
}
@@ -3731,6 +3739,20 @@ void assign_new_table_id(TABLE_SHARE *share)
DBUG_VOID_RETURN;
}
+#ifndef DBUG_OFF
+/* Cause a spurious statement reprepare for debug purposes. */
+static bool inject_reprepare(THD *thd)
+{
+ if (thd->m_reprepare_observer && thd->stmt_arena->is_reprepared == FALSE)
+ {
+ thd->m_reprepare_observer->report_error(thd);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+#endif
+
/**
Compare metadata versions of an element obtained from the table
definition cache and its corresponding node in the parse tree.
@@ -3784,13 +3806,7 @@ check_and_update_table_version(THD *thd,
tables->set_table_ref_id(table_share);
}
- DBUG_EXECUTE_IF("reprepare_each_statement",
- if (thd->m_reprepare_observer &&
- thd->stmt_arena->is_reprepared == FALSE)
- {
- thd->m_reprepare_observer->report_error(thd);
- return TRUE;
- });
+ DBUG_EXECUTE_IF("reprepare_each_statement", return inject_reprepare(thd););
return FALSE;
}
@@ -4365,6 +4381,38 @@ bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
/*
+ Return a appropriate read lock type given a table object.
+
+ @param thd Thread context
+ @param table TABLE object for table to be locked
+
+ @remark Due to a statement-based replication limitation, statements such as
+ INSERT INTO .. SELECT FROM .. and CREATE TABLE .. SELECT FROM need
+ to grab a TL_READ_NO_INSERT lock on the source table in order to
+ prevent the replication of a concurrent statement that modifies the
+ source table. If such a statement gets applied on the slave before
+ the INSERT .. SELECT statement finishes, data on the master could
+ differ from data on the slave and end-up with a discrepancy between
+ the binary log and table state. Furthermore, this does not apply to
+ I_S and log tables as it's always unsafe to replicate such tables
+ under statement-based replication as the table on the slave might
+ contain other data (ie: general_log is enabled on the slave). The
+ statement will be marked as unsafe for SBR in decide_logging_format().
+*/
+
+thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table)
+{
+ bool log_on= mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG);
+ ulong binlog_format= thd->variables.binlog_format;
+ if ((log_on == FALSE) || (binlog_format == BINLOG_FORMAT_ROW) ||
+ (table->s->table_category == TABLE_CATEGORY_PERFORMANCE))
+ return TL_READ;
+ else
+ return TL_READ_NO_INSERT;
+}
+
+
+/*
Open all tables in list
SYNOPSIS
@@ -4638,6 +4686,9 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags)
{
if (tables->lock_type == TL_WRITE_DEFAULT)
tables->table->reginfo.lock_type= thd->update_lock_default;
+ else if (tables->lock_type == TL_READ_DEFAULT)
+ tables->table->reginfo.lock_type=
+ read_lock_type_for_table(thd, tables->table);
else if (tables->table->s->tmp_table == NO_TMP_TABLE)
tables->table->reginfo.lock_type= tables->lock_type;
}
@@ -5045,7 +5096,11 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables)
void* prev_ht= NULL;
for (TABLE_LIST *table= tables; table; table= table->next_global)
{
- if (!table->placeholder() && table->lock_type >= TL_WRITE_ALLOW_WRITE)
+ if (table->placeholder())
+ continue;
+ if (table->table->s->table_category == TABLE_CATEGORY_PERFORMANCE)
+ thd->lex->set_stmt_unsafe();
+ if (table->lock_type >= TL_WRITE_ALLOW_WRITE)
{
ulonglong const flags= table->table->file->ha_table_flags();
DBUG_PRINT("info", ("table: %s; ha_table_flags: %s%s",
@@ -5709,8 +5764,21 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
{
/* This is a base table. */
DBUG_ASSERT(nj_col->view_field == NULL);
- DBUG_ASSERT(nj_col->table_ref->table == nj_col->table_field->table);
- found_field= nj_col->table_field;
+ /*
+ This fix_fields is not necessary (initially this item is fixed by
+ the Item_field constructor; after reopen_tables the Item_func_eq
+ calls fix_fields on that item), it's just a check during table
+ reopening for columns that was dropped by the concurrent connection.
+ */
+ if (!nj_col->table_field->fixed &&
+ nj_col->table_field->fix_fields(thd, (Item **)&nj_col->table_field))
+ {
+ DBUG_PRINT("info", ("column '%s' was dropped by the concurrent connection",
+ nj_col->table_field->name));
+ DBUG_RETURN(NULL);
+ }
+ DBUG_ASSERT(nj_col->table_ref->table == nj_col->table_field->field->table);
+ found_field= nj_col->table_field->field;
update_field_dependencies(thd, found_field, nj_col->table_ref->table);
}
@@ -6635,7 +6703,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
const char *field_name_1;
/* true if field_name_1 is a member of using_fields */
bool is_using_column_1;
- if (!(nj_col_1= it_1.get_or_create_column_ref(leaf_1)))
+ if (!(nj_col_1= it_1.get_or_create_column_ref(thd, leaf_1)))
goto err;
field_name_1= nj_col_1->name();
is_using_column_1= using_fields &&
@@ -6656,7 +6724,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
{
Natural_join_column *cur_nj_col_2;
const char *cur_field_name_2;
- if (!(cur_nj_col_2= it_2.get_or_create_column_ref(leaf_2)))
+ if (!(cur_nj_col_2= it_2.get_or_create_column_ref(thd, leaf_2)))
goto err;
cur_field_name_2= cur_nj_col_2->name();
DBUG_PRINT ("info", ("cur_field_name_2=%s.%s",
@@ -7146,15 +7214,24 @@ static bool setup_natural_join_row_types(THD *thd,
TABLE_LIST *left_neighbor;
/* Table reference to the right of the current. */
TABLE_LIST *right_neighbor= NULL;
+ bool save_first_natural_join_processing=
+ context->select_lex->first_natural_join_processing;
+
+ context->select_lex->first_natural_join_processing= FALSE;
/* Note that tables in the list are in reversed order */
for (left_neighbor= table_ref_it++; left_neighbor ; )
{
table_ref= left_neighbor;
left_neighbor= table_ref_it++;
- /* For stored procedures do not redo work if already done. */
- if (context->select_lex->first_execution)
+ /*
+ Do not redo work if already done:
+ 1) for stored procedures,
+ 2) for multitable update after lock failure and table reopening.
+ */
+ if (save_first_natural_join_processing)
{
+ context->select_lex->first_natural_join_processing= FALSE;
if (store_top_level_join_columns(thd, table_ref,
left_neighbor, right_neighbor))
return TRUE;
@@ -7299,6 +7376,22 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
if (ref_pointer_array)
bzero(ref_pointer_array, sizeof(Item *) * fields.elements);
+ /*
+ We call set_entry() there (before fix_fields() of the whole list of field
+ items) because:
+ 1) the list of field items has same order as in the query, and the
+ Item_func_get_user_var item may go before the Item_func_set_user_var:
+ SELECT @a, @a := 10 FROM t;
+ 2) The entry->update_query_id value controls constantness of
+ Item_func_get_user_var items, so in presence of Item_func_set_user_var
+ items we have to refresh their entries before fixing of
+ Item_func_get_user_var items.
+ */
+ List_iterator<Item_func_set_user_var> li(thd->lex->set_var_list);
+ Item_func_set_user_var *var;
+ while ((var= li++))
+ var->set_entry(thd, FALSE);
+
Item **ref= ref_pointer_array;
thd->lex->current_select->cur_pos_in_select_list= 0;
while ((item= it++))
@@ -7680,6 +7773,10 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
if (!(item= field_iterator.create_item(thd)))
DBUG_RETURN(TRUE);
+ DBUG_ASSERT(item->fixed);
+ /* cache the table for the Item_fields inserted by expanding stars */
+ if (item->type() == Item::FIELD_ITEM && tables->cacheable_table)
+ ((Item_field *)item)->cached_table= tables;
if (!found)
{
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index f82cad27207..1748a737b07 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1548,10 +1548,9 @@ void Query_cache::invalidate_locked_for_write(TABLE_LIST *tables_used)
for (; tables_used; tables_used= tables_used->next_local)
{
thd_proc_info(thd, "invalidating query cache entries (table)");
- if (tables_used->lock_type & (TL_WRITE_LOW_PRIORITY | TL_WRITE) &&
+ if (tables_used->lock_type >= TL_WRITE_ALLOW_WRITE &&
tables_used->table)
{
- THD *thd= current_thd;
invalidate_table(thd, tables_used->table);
}
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 9a450f245be..6d74372fd02 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -309,20 +309,25 @@ void thd_inc_row_count(THD *thd)
thd->row_count++;
}
-/*
+
+/**
Dumps a text description of a thread, its security context
(user, host) and the current query.
- SYNOPSIS
- thd_security_context()
- thd current thread context
- buffer pointer to preferred result buffer
- length length of buffer
- max_query_len how many chars of query to copy (0 for all)
-
- RETURN VALUES
- pointer to string
+ @param thd current thread context
+ @param buffer pointer to preferred result buffer
+ @param length length of buffer
+ @param max_query_len how many chars of query to copy (0 for all)
+
+ @req LOCK_thread_count
+
+ @note LOCK_thread_count mutex is not necessary when the function is invoked on
+ the currently running thread (current_thd) or if the caller in some other
+ way guarantees that access to thd->query is serialized.
+
+ @return Pointer to string
*/
+
extern "C"
char *thd_security_context(THD *thd, char *buffer, unsigned int length,
unsigned int max_query_len)
@@ -331,6 +336,16 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length,
const Security_context *sctx= &thd->main_security_ctx;
char header[64];
int len;
+ /*
+ The pointers thd->query and thd->proc_info might change since they are
+ being modified concurrently. This is acceptable for proc_info since its
+ values doesn't have to very accurate and the memory it points to is static,
+ but we need to attempt a snapshot on the pointer values to avoid using NULL
+ values. The pointer to thd->query however, doesn't point to static memory
+ and has to be protected by LOCK_thread_count or risk pointing to
+ uninitialized memory.
+ */
+ const char *proc_info= thd->proc_info;
len= my_snprintf(header, sizeof(header),
"MySQL thread id %lu, query id %lu",
@@ -356,10 +371,10 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length,
str.append(sctx->user);
}
- if (thd->proc_info)
+ if (proc_info)
{
str.append(' ');
- str.append(thd->proc_info);
+ str.append(proc_info);
}
if (thd->query)
@@ -1492,6 +1507,12 @@ sql_exchange::sql_exchange(char *name,bool flag)
cs= NULL;
}
+bool sql_exchange::escaped_given(void)
+{
+ return escaped != &default_escaped;
+}
+
+
bool select_send::send_fields(List<Item> &list, uint flags)
{
bool res;
@@ -1777,8 +1798,11 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
exchange->line_term=exchange->field_term; // Use this if it exists
field_sep_char= (exchange->enclosed->length() ?
(int) (uchar) (*exchange->enclosed)[0] : field_term_char);
- escape_char= (exchange->escaped->length() ?
- (int) (uchar) (*exchange->escaped)[0] : -1);
+ if (exchange->escaped->length() && (exchange->escaped_given() ||
+ !(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)))
+ escape_char= (int) (uchar) (*exchange->escaped)[0];
+ else
+ escape_char= -1;
is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char));
is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char));
line_sep_char= (exchange->line_term->length() ?
@@ -2854,7 +2878,10 @@ extern "C" int thd_non_transactional_update(const MYSQL_THD thd)
extern "C" int thd_binlog_format(const MYSQL_THD thd)
{
- return (int) thd->variables.binlog_format;
+ if (mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG))
+ return (int) thd->variables.binlog_format;
+ else
+ return BINLOG_FORMAT_UNSPEC;
}
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all)
@@ -3451,7 +3478,7 @@ int THD::binlog_delete_row(TABLE* table, bool is_trans,
int THD::binlog_remove_pending_rows_event(bool clear_maps)
{
- DBUG_ENTER(__FUNCTION__);
+ DBUG_ENTER("THD::binlog_remove_pending_rows_event");
if (!mysql_bin_log.is_open())
DBUG_RETURN(0);
@@ -3496,6 +3523,29 @@ int THD::binlog_flush_pending_rows_event(bool stmt_end)
}
+#if !defined(DBUG_OFF) && !defined(_lint)
+static const char *
+show_query_type(THD::enum_binlog_query_type qtype)
+{
+ switch (qtype) {
+ case THD::ROW_QUERY_TYPE:
+ return "ROW";
+ case THD::STMT_QUERY_TYPE:
+ return "STMT";
+ case THD::MYSQL_QUERY_TYPE:
+ return "MYSQL";
+ case THD::QUERY_TYPE_COUNT:
+ default:
+ DBUG_ASSERT(0 <= qtype && qtype < THD::QUERY_TYPE_COUNT);
+ }
+
+ static char buf[64];
+ sprintf(buf, "UNKNOWN#%d", qtype);
+ return buf;
+}
+#endif
+
+
/*
Member function that will log query, either row-based or
statement-based depending on the value of the 'current_stmt_binlog_row_based'
@@ -3524,7 +3574,8 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
THD::killed_state killed_status_arg)
{
DBUG_ENTER("THD::binlog_query");
- DBUG_PRINT("enter", ("qtype: %d query: '%s'", qtype, query_arg));
+ DBUG_PRINT("enter", ("qtype: %s query: '%s'",
+ show_query_type(qtype), query_arg));
DBUG_ASSERT(query_arg && mysql_bin_log.is_open());
/*
@@ -3563,6 +3614,9 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
switch (qtype) {
case THD::ROW_QUERY_TYPE:
+ DBUG_PRINT("debug",
+ ("current_stmt_binlog_row_based: %d",
+ current_stmt_binlog_row_based));
if (current_stmt_binlog_row_based)
DBUG_RETURN(0);
/* Otherwise, we fall through */
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 8bf3e2390ea..ddaa62bd159 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -745,7 +745,7 @@ struct st_savepoint {
Ha_trx_info *ha_list;
};
-enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
+enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED, XA_ROLLBACK_ONLY};
extern const char *xa_state_names[];
typedef struct st_xid_state {
@@ -753,6 +753,8 @@ typedef struct st_xid_state {
XID xid; // transaction identifier
enum xa_states xa_state; // used by external XA only
bool in_thd;
+ /* Error reported by the Resource Manager (RM) to the Transaction Manager. */
+ uint rm_error;
} XID_STATE;
extern pthread_mutex_t LOCK_xid_cache;
@@ -1002,6 +1004,22 @@ enum enum_thread_type
SYSTEM_THREAD_EVENT_WORKER= 32
};
+inline char const *
+show_system_thread(enum_thread_type thread)
+{
+#define RETURN_NAME_AS_STRING(NAME) case (NAME): return #NAME
+ switch (thread) {
+ RETURN_NAME_AS_STRING(NON_SYSTEM_THREAD);
+ RETURN_NAME_AS_STRING(SYSTEM_THREAD_DELAYED_INSERT);
+ RETURN_NAME_AS_STRING(SYSTEM_THREAD_SLAVE_IO);
+ RETURN_NAME_AS_STRING(SYSTEM_THREAD_SLAVE_SQL);
+ RETURN_NAME_AS_STRING(SYSTEM_THREAD_NDBCLUSTER_BINLOG);
+ RETURN_NAME_AS_STRING(SYSTEM_THREAD_EVENT_SCHEDULER);
+ RETURN_NAME_AS_STRING(SYSTEM_THREAD_EVENT_WORKER);
+ }
+#undef RETURN_NAME_AS_STRING
+ return "UNKNOWN"; /* keep gcc happy */
+}
/**
This class represents the interface for internal error handlers.
@@ -1531,6 +1549,9 @@ public:
then the latter INSERT will insert no rows
(first_successful_insert_id_in_cur_stmt == 0), but storing "INSERT_ID=3"
in the binlog is still needed; the list's minimum will contain 3.
+ This variable is cumulative: if several statements are written to binlog
+ as one (stored functions or triggers are used) this list is the
+ concatenation of all intervals reserved by all statements.
*/
Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
/* Used by replication and SET INSERT_ID */
@@ -2096,6 +2117,10 @@ public:
Don't reset binlog format for NDB binlog injector thread.
*/
+ DBUG_PRINT("debug",
+ ("temporary_tables: %p, in_sub_stmt: %d, system_thread: %s",
+ temporary_tables, in_sub_stmt,
+ show_system_thread(system_thread)));
if ((temporary_tables == NULL) && (in_sub_stmt == 0) &&
(system_thread != SYSTEM_THREAD_NDBCLUSTER_BINLOG))
{
@@ -2257,6 +2282,7 @@ public:
ulong skip_lines;
CHARSET_INFO *cs;
sql_exchange(char *name,bool dumpfile_flag);
+ bool escaped_given(void);
};
#include "log_event.h"
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index e1bff5e435b..0db88d7dd90 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -37,7 +37,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path, uint level,
TABLE_LIST **dropped_tables);
-static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
+long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error);
static void mysql_change_db_impl(THD *thd,
LEX_STRING *new_db_name,
@@ -1096,7 +1096,11 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
else if (file->name[0] == 'a' && file->name[1] == 'r' &&
file->name[2] == 'c' && file->name[3] == '\0')
{
- /* .frm archive */
+ /* .frm archive:
+ Those archives are obsolete, but following code should
+ exist to remove existent "arc" directories.
+ See #ifdef FRM_ARCHIVE directives for obsolete code.
+ */
char newpath[FN_REFLEN];
MY_DIR *new_dirp;
strxmov(newpath, org_path, "/", "arc", NullS);
@@ -1260,9 +1264,13 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error)
RETURN
> 0 number of removed files
-1 error
+
+ NOTE
+ A support of "arc" directories is obsolete, however this
+ function should exist to remove existent "arc" directories.
+ See #ifdef FRM_ARCHIVE directives for obsolete code.
*/
-static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp,
- const char *org_path)
+long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path)
{
long deleted= 0;
ulong found_other_files= 0;
@@ -1304,6 +1312,7 @@ static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp,
{
goto err;
}
+ deleted++;
}
if (thd->killed)
goto err;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 5debb3170f7..47d2d69ef35 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -398,7 +398,11 @@ cleanup:
free_underlaid_joins(thd, select_lex);
if (error < 0 || (thd->lex->ignore && !thd->is_fatal_error))
{
- thd->row_count_func= deleted;
+ /*
+ If a TRUNCATE TABLE was issued, the number of rows should be reported as
+ zero since the exact number is unknown.
+ */
+ thd->row_count_func= reset_auto_increment ? 0 : deleted;
my_ok(thd, (ha_rows) thd->row_count_func);
DBUG_PRINT("info",("%ld records deleted",(long) deleted));
}
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
index 0b74e3455eb..79da1936eb9 100644
--- a/sql/sql_error.cc
+++ b/sql/sql_error.cc
@@ -109,6 +109,9 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
DBUG_ENTER("push_warning");
DBUG_PRINT("enter", ("code: %d, msg: %s", code, msg));
+ DBUG_ASSERT(code != 0);
+ DBUG_ASSERT(msg != NULL);
+
if (level == MYSQL_ERROR::WARN_LEVEL_NOTE &&
!(thd->options & OPTION_SQL_NOTES))
DBUG_RETURN(0);
@@ -177,7 +180,10 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
char warning[ERRMSGSIZE+20];
DBUG_ENTER("push_warning_printf");
DBUG_PRINT("enter",("warning: %u", code));
-
+
+ DBUG_ASSERT(code != 0);
+ DBUG_ASSERT(format != NULL);
+
va_start(args,format);
my_vsnprintf(warning, sizeof(warning), format, args);
va_end(args);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index a275c680cb5..947546c4429 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -833,7 +833,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
info.copied=values_list.elements;
end_delayed_insert(thd);
}
- query_cache_invalidate3(thd, table_list, 1);
}
else
#endif
@@ -1548,6 +1547,17 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
}
}
}
+
+ /*
+ If more than one iteration of the above while loop is done, from the second
+ one the row being inserted will have an explicit value in the autoinc field,
+ which was set at the first call of handler::update_auto_increment(). This
+ value is saved to avoid thd->insert_id_for_cur_row becoming 0. Use this saved
+ autoinc value.
+ */
+ if (table->file->insert_id_for_cur_row == 0)
+ table->file->insert_id_for_cur_row= insert_id_for_cur_row;
+
thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
/*
Restore column maps if they where replaced during an duplicate key
@@ -2535,8 +2545,13 @@ bool Delayed_insert::handle_inserts(void)
thd_proc_info(&thd, "upgrading lock");
if (thr_upgrade_write_delay_lock(*thd.lock->locks))
{
- /* This can only happen if thread is killed by shutdown */
- sql_print_error(ER(ER_DELAYED_CANT_CHANGE_LOCK),table->s->table_name.str);
+ /*
+ This can happen if thread is killed either by a shutdown
+ or if another thread is removing the current table definition
+ from the table cache.
+ */
+ my_error(ER_DELAYED_CANT_CHANGE_LOCK,MYF(ME_FATALERROR),
+ table->s->table_name.str);
goto err;
}
@@ -2691,9 +2706,10 @@ bool Delayed_insert::handle_inserts(void)
query_cache_invalidate3(&thd, table, 1);
if (thr_reschedule_write_lock(*thd.lock->locks))
{
- /* This should never happen */
- sql_print_error(ER(ER_DELAYED_CANT_CHANGE_LOCK),
- table->s->table_name.str);
+ /* This is not known to happen. */
+ my_error(ER_DELAYED_CANT_CHANGE_LOCK,MYF(ME_FATALERROR),
+ table->s->table_name.str);
+ goto err;
}
if (!using_bin_log)
table->file->extra(HA_EXTRA_WRITE_CACHE);
@@ -2740,6 +2756,11 @@ bool Delayed_insert::handle_inserts(void)
/* Remove all not used rows */
while ((row=rows.get()))
{
+ if (table->s->blob_fields)
+ {
+ memcpy(table->record[0],row->record,table->s->reclength);
+ free_delayed_insert_blobs(table);
+ }
delete row;
thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
stacked_inserts--;
@@ -3621,7 +3642,8 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
tmp_table_list.table = *tables;
query.length(0); // Have to zero it since constructor doesn't
- result= store_create_info(thd, &tmp_table_list, &query, create_info);
+ result= store_create_info(thd, &tmp_table_list, &query, create_info,
+ /* show_database */ TRUE);
DBUG_ASSERT(result == 0); /* store_create_info() always return 0 */
if (mysql_bin_log.is_open())
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 1822176f00a..983d53a041d 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -293,6 +293,7 @@ void lex_start(THD *thd)
lex->select_lex.init_query();
lex->value_list.empty();
lex->update_list.empty();
+ lex->set_var_list.empty();
lex->param_list.empty();
lex->view_list.empty();
lex->prepared_stmt_params.empty();
@@ -1552,6 +1553,7 @@ void st_select_lex::init_query()
subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0;
first_execution= 1;
+ first_natural_join_processing= 1;
first_cond_optimization= 1;
parsing_place= NO_MATTER;
exclude_from_table_unique_test= no_wrap_view_item= FALSE;
@@ -2395,15 +2397,20 @@ void st_select_lex_unit::set_limit(st_select_lex *sl)
val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
select_limit_val= (ha_rows)val;
#ifndef BIG_TABLES
- /*
+ /*
Check for overflow : ha_rows can be smaller then ulonglong if
BIG_TABLES is off.
*/
if (val != (ulonglong)select_limit_val)
select_limit_val= HA_POS_ERROR;
#endif
- offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
- ULL(0));
+ val= sl->offset_limit ? sl->offset_limit->val_uint() : ULL(0);
+ offset_limit_cnt= (ha_rows)val;
+#ifndef BIG_TABLES
+ /* Check for truncation. */
+ if (val != (ulonglong)offset_limit_cnt)
+ offset_limit_cnt= HA_POS_ERROR;
+#endif
select_limit_cnt= select_limit_val + offset_limit_cnt;
if (select_limit_cnt < select_limit_val)
select_limit_cnt= HA_POS_ERROR; // no limit
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index bb3dc00fc8d..24731b600e9 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -667,6 +667,7 @@ public:
case of an error during prepare the PS is not created.
*/
bool first_execution;
+ bool first_natural_join_processing;
bool first_cond_optimization;
/* do not wrap view fields with Item_ref */
bool no_wrap_view_item;
@@ -842,15 +843,12 @@ inline bool st_select_lex_unit::is_union ()
#define ALTER_COALESCE_PARTITION (1L << 15)
#define ALTER_REORGANIZE_PARTITION (1L << 16)
#define ALTER_PARTITION (1L << 17)
-#define ALTER_OPTIMIZE_PARTITION (1L << 18)
+#define ALTER_ADMIN_PARTITION (1L << 18)
#define ALTER_TABLE_REORG (1L << 19)
#define ALTER_REBUILD_PARTITION (1L << 20)
#define ALTER_ALL_PARTITION (1L << 21)
-#define ALTER_ANALYZE_PARTITION (1L << 22)
-#define ALTER_CHECK_PARTITION (1L << 23)
-#define ALTER_REPAIR_PARTITION (1L << 24)
-#define ALTER_REMOVE_PARTITIONING (1L << 25)
-#define ALTER_FOREIGN_KEY (1L << 26)
+#define ALTER_REMOVE_PARTITIONING (1L << 22)
+#define ALTER_FOREIGN_KEY (1L << 23)
enum enum_alter_table_change_level
{
@@ -1549,6 +1547,7 @@ typedef struct st_lex : public Query_tables_list
List<Item> *insert_list,field_list,value_list,update_list;
List<List_item> many_values;
List<set_var_base> var_list;
+ List<Item_func_set_user_var> set_var_list; // in-query assignment list
List<Item_param> param_list;
List<LEX_STRING> view_list; // view list (list of field names in view)
/*
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 49015fb3e2a..cae8f682a09 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -327,7 +327,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
bzero((char*) &info,sizeof(info));
info.ignore= ignore;
info.handle_duplicates=handle_duplicates;
- info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
+ info.escape_char= (escaped->length() && (ex->escaped_given() ||
+ !(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)))
+ ? (*escaped)[0] : INT_MAX;
READ_INFO read_info(file,tot_length,
ex->cs ? ex->cs : thd->variables.collation_database,
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 819c9b9ed26..1391e6bc827 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -87,9 +87,57 @@ const LEX_STRING command_name[]={
};
const char *xa_state_names[]={
- "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
+ "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED", "ROLLBACK ONLY"
};
+/**
+ Mark a XA transaction as rollback-only if the RM unilaterally
+ rolled back the transaction branch.
+
+ @note If a rollback was requested by the RM, this function sets
+ the appropriate rollback error code and transits the state
+ to XA_ROLLBACK_ONLY.
+
+ @return TRUE if transaction was rolled back or if the transaction
+ state is XA_ROLLBACK_ONLY. FALSE otherwise.
+*/
+static bool xa_trans_rolled_back(XID_STATE *xid_state)
+{
+ if (xid_state->rm_error)
+ {
+ switch (xid_state->rm_error) {
+ case ER_LOCK_WAIT_TIMEOUT:
+ my_error(ER_XA_RBTIMEOUT, MYF(0));
+ break;
+ case ER_LOCK_DEADLOCK:
+ my_error(ER_XA_RBDEADLOCK, MYF(0));
+ break;
+ default:
+ my_error(ER_XA_RBROLLBACK, MYF(0));
+ }
+ xid_state->xa_state= XA_ROLLBACK_ONLY;
+ }
+
+ return (xid_state->xa_state == XA_ROLLBACK_ONLY);
+}
+
+/**
+ Rollback work done on behalf of at ransaction branch.
+*/
+static bool xa_trans_rollback(THD *thd)
+{
+ bool status= test(ha_rollback(thd));
+
+ thd->options&= ~(ulong) OPTION_BEGIN;
+ thd->transaction.all.modified_non_trans_table= FALSE;
+ thd->server_status&= ~SERVER_STATUS_IN_TRANS;
+ xid_cache_delete(&thd->transaction.xid_state);
+ thd->transaction.xid_state.xa_state= XA_NOTR;
+ thd->transaction.xid_state.rm_error= 0;
+
+ return status;
+}
+
static void unlock_locked_tables(THD *thd)
{
if (thd->locked_tables)
@@ -2344,8 +2392,8 @@ mysql_execute_command(THD *thd)
}
else
{
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "the master info structure does not exist");
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_NO_MASTER_INFO, ER(WARN_NO_MASTER_INFO));
my_ok(thd);
}
pthread_mutex_unlock(&LOCK_active_mi);
@@ -2744,11 +2792,13 @@ end_with_restore_list:
/* Don't yet allow changing of symlinks with ALTER TABLE */
if (create_info.data_file_name)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "DATA DIRECTORY option ignored");
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
+ "DATA DIRECTORY");
if (create_info.index_file_name)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "INDEX DIRECTORY option ignored");
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
+ "INDEX DIRECTORY");
create_info.data_file_name= create_info.index_file_name= NULL;
/* ALTER TABLE ends previous transaction */
if (end_active_trans(thd))
@@ -4527,6 +4577,7 @@ create_sp_error:
}
DBUG_ASSERT(thd->transaction.xid_state.xid.is_null());
thd->transaction.xid_state.xa_state=XA_ACTIVE;
+ thd->transaction.xid_state.rm_error= 0;
thd->transaction.xid_state.xid.set(thd->lex->xid);
xid_cache_insert(&thd->transaction.xid_state);
thd->transaction.all.modified_non_trans_table= FALSE;
@@ -4552,6 +4603,8 @@ create_sp_error:
my_error(ER_XAER_NOTA, MYF(0));
break;
}
+ if (xa_trans_rolled_back(&thd->transaction.xid_state))
+ break;
thd->transaction.xid_state.xa_state=XA_IDLE;
my_ok(thd);
break;
@@ -4583,6 +4636,12 @@ create_sp_error:
XID_STATE *xs=xid_cache_search(thd->lex->xid);
if (!xs || xs->in_thd)
my_error(ER_XAER_NOTA, MYF(0));
+ else if (xa_trans_rolled_back(xs))
+ {
+ ha_commit_or_rollback_by_xid(thd->lex->xid, 0);
+ xid_cache_delete(xs);
+ break;
+ }
else
{
ha_commit_or_rollback_by_xid(thd->lex->xid, 1);
@@ -4591,6 +4650,11 @@ create_sp_error:
}
break;
}
+ if (xa_trans_rolled_back(&thd->transaction.xid_state))
+ {
+ xa_trans_rollback(thd);
+ break;
+ }
if (thd->transaction.xid_state.xa_state == XA_IDLE &&
thd->lex->xa_opt == XA_ONE_PHASE)
{
@@ -4637,28 +4701,26 @@ create_sp_error:
my_error(ER_XAER_NOTA, MYF(0));
else
{
+ bool ok= !xa_trans_rolled_back(xs);
ha_commit_or_rollback_by_xid(thd->lex->xid, 0);
xid_cache_delete(xs);
- my_ok(thd);
+ if (ok)
+ my_ok(thd);
}
break;
}
if (thd->transaction.xid_state.xa_state != XA_IDLE &&
- thd->transaction.xid_state.xa_state != XA_PREPARED)
+ thd->transaction.xid_state.xa_state != XA_PREPARED &&
+ thd->transaction.xid_state.xa_state != XA_ROLLBACK_ONLY)
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
- if (ha_rollback(thd))
+ if (xa_trans_rollback(thd))
my_error(ER_XAER_RMERR, MYF(0));
else
my_ok(thd);
- thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
- thd->transaction.all.modified_non_trans_table= FALSE;
- thd->server_status&= ~SERVER_STATUS_IN_TRANS;
- xid_cache_delete(&thd->transaction.xid_state);
- thd->transaction.xid_state.xa_state=XA_NOTR;
break;
case SQLCOM_XA_RECOVER:
res= mysql_xa_recover(thd);
@@ -5510,6 +5572,10 @@ void mysql_reset_thd_for_next_command(THD *thd)
*/
thd->reset_current_stmt_binlog_row_based();
+ DBUG_PRINT("debug",
+ ("current_stmt_binlog_row_based: %d",
+ thd->current_stmt_binlog_row_based));
+
DBUG_VOID_RETURN;
}
@@ -5650,7 +5716,7 @@ void mysql_init_multi_delete(LEX *lex)
lex->select_lex.select_limit= 0;
lex->unit.select_limit_cnt= HA_POS_ERROR;
lex->select_lex.table_list.save_and_clear(&lex->auxiliary_table_list);
- lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
+ lex->lock_option= TL_READ_DEFAULT;
lex->query_tables= 0;
lex->query_tables_last= &lex->query_tables;
}
@@ -7530,6 +7596,39 @@ int test_if_data_home_dir(const char *dir)
C_MODE_END
+/**
+ Check that host name string is valid.
+
+ @param[in] str string to be checked
+
+ @return Operation status
+ @retval FALSE host name is ok
+ @retval TRUE host name string is longer than max_length or
+ has invalid symbols
+*/
+
+bool check_host_name(LEX_STRING *str)
+{
+ const char *name= str->str;
+ const char *end= str->str + str->length;
+ if (check_string_byte_length(str, ER(ER_HOSTNAME), HOSTNAME_LENGTH))
+ return TRUE;
+
+ while (name != end)
+ {
+ if (*name == '@')
+ {
+ my_printf_error(ER_UNKNOWN_ERROR,
+ "Malformed hostname (illegal symbol: '%c')", MYF(0),
+ *name);
+ return TRUE;
+ }
+ name++;
+ }
+ return FALSE;
+}
+
+
extern int MYSQLparse(void *thd); // from sql_yacc.cc
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 6419d336b9f..5ed64ea8fd5 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -73,10 +73,8 @@ static int get_part_id_charset_func_subpart(partition_info *part_info,
static int get_part_part_id_charset_func(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
-static uint32 get_subpart_id_charset_func(partition_info *part_info);
-int get_partition_id_list(partition_info *part_info,
- uint32 *part_id,
- longlong *func_value);
+static int get_subpart_id_charset_func(partition_info *part_info,
+ uint32 *part_id);
int get_partition_id_list(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
@@ -119,10 +117,14 @@ int get_partition_id_list_sub_linear_hash(partition_info *part_info,
int get_partition_id_list_sub_linear_key(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
-uint32 get_partition_id_hash_sub(partition_info *part_info);
-uint32 get_partition_id_key_sub(partition_info *part_info);
-uint32 get_partition_id_linear_hash_sub(partition_info *part_info);
-uint32 get_partition_id_linear_key_sub(partition_info *part_info);
+int get_partition_id_hash_sub(partition_info *part_info,
+ uint32 *part_id);
+int get_partition_id_key_sub(partition_info *part_info,
+ uint32 *part_id);
+int get_partition_id_linear_hash_sub(partition_info *part_info,
+ uint32 *part_id);
+int get_partition_id_linear_key_sub(partition_info *part_info,
+ uint32 *part_id);
static uint32 get_next_partition_via_walking(PARTITION_ITERATOR*);
static void set_up_range_analysis_info(partition_info *part_info);
static uint32 get_next_subpartition_via_walking(PARTITION_ITERATOR*);
@@ -2076,16 +2078,16 @@ char *generate_partition_syntax(partition_info *part_info,
err+= add_string_len(fptr, part_info->part_func_string,
part_info->part_func_len);
err+= add_end_parenthesis(fptr);
- err+= add_space(fptr);
if ((!part_info->use_default_no_partitions) &&
part_info->use_default_partitions)
{
+ err+= add_string(fptr, "\n");
err+= add_string(fptr, "PARTITIONS ");
err+= add_int(fptr, part_info->no_parts);
- err+= add_space(fptr);
}
if (part_info->is_sub_partitioned())
{
+ err+= add_string(fptr, "\n");
err+= add_subpartition_by(fptr);
/* Must be hash partitioning for subpartitioning */
if (part_info->linear_hash_ind)
@@ -2098,13 +2100,12 @@ char *generate_partition_syntax(partition_info *part_info,
err+= add_string_len(fptr, part_info->subpart_func_string,
part_info->subpart_func_len);
err+= add_end_parenthesis(fptr);
- err+= add_space(fptr);
if ((!part_info->use_default_no_subpartitions) &&
part_info->use_default_subpartitions)
{
+ err+= add_string(fptr, "\n");
err+= add_string(fptr, "SUBPARTITIONS ");
err+= add_int(fptr, part_info->no_subparts);
- err+= add_space(fptr);
}
}
tot_no_parts= part_info->partitions.elements;
@@ -2113,6 +2114,7 @@ char *generate_partition_syntax(partition_info *part_info,
if (!part_info->use_default_partitions)
{
bool first= TRUE;
+ err+= add_string(fptr, "\n");
err+= add_begin_parenthesis(fptr);
i= 0;
do
@@ -2124,6 +2126,7 @@ char *generate_partition_syntax(partition_info *part_info,
if (!first)
{
err+= add_comma(fptr);
+ err+= add_string(fptr, "\n");
err+= add_space(fptr);
}
first= FALSE;
@@ -2138,6 +2141,7 @@ char *generate_partition_syntax(partition_info *part_info,
}
else
{
+ err+= add_string(fptr, "\n");
err+= add_space(fptr);
err+= add_begin_parenthesis(fptr);
List_iterator<partition_element> sub_it(part_elem->subpartitions);
@@ -2152,6 +2156,8 @@ char *generate_partition_syntax(partition_info *part_info,
if (j != (no_subparts-1))
{
err+= add_comma(fptr);
+ err+= add_string(fptr, "\n");
+ err+= add_space(fptr);
err+= add_space(fptr);
}
else
@@ -2232,17 +2238,24 @@ bool partition_key_modified(TABLE *table, const MY_BITMAP *fields)
SYNOPSIS
part_val_int()
item_expr The item expression to evaluate
+ out:result The value of the partition function,
+ LONGLONG_MIN if any null value in function
RETURN VALUES
- The value of the partition function, LONGLONG_MIN if any null value
- in function
+ TRUE Error in val_int()
+ FALSE ok
*/
-static inline longlong part_val_int(Item *item_expr)
+static inline int part_val_int(Item *item_expr, longlong *result)
{
- longlong value= item_expr->val_int();
+ *result= item_expr->val_int();
if (item_expr->null_value)
- value= LONGLONG_MIN;
- return value;
+ {
+ if (current_thd->is_error())
+ return TRUE;
+ else
+ *result= LONGLONG_MIN;
+ }
+ return FALSE;
}
@@ -2319,24 +2332,29 @@ static uint32 get_part_id_for_sub(uint32 loc_part_id, uint32 sub_part_id,
get_part_id_hash()
no_parts Number of hash partitions
part_expr Item tree of hash function
- out:func_value Value of hash function
+ out:part_id The returned partition id
+ out:func_value Value of hash function
RETURN VALUE
- Calculated partition id
+ != 0 Error code
+ FALSE Success
*/
-inline
-static uint32 get_part_id_hash(uint no_parts,
- Item *part_expr,
- longlong *func_value)
+static int get_part_id_hash(uint no_parts,
+ Item *part_expr,
+ uint32 *part_id,
+ longlong *func_value)
{
longlong int_hash_id;
DBUG_ENTER("get_part_id_hash");
- *func_value= part_val_int(part_expr);
+ if (part_val_int(part_expr, func_value))
+ DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
+
int_hash_id= *func_value % no_parts;
- DBUG_RETURN(int_hash_id < 0 ? (uint32) -int_hash_id : (uint32) int_hash_id);
+ *part_id= int_hash_id < 0 ? (uint32) -int_hash_id : (uint32) int_hash_id;
+ DBUG_RETURN(FALSE);
}
@@ -2349,24 +2367,29 @@ static uint32 get_part_id_hash(uint no_parts,
desired information is given
no_parts Number of hash partitions
part_expr Item tree of hash function
+ out:part_id The returned partition id
out:func_value Value of hash function
RETURN VALUE
- Calculated partition id
+ != 0 Error code
+ 0 OK
*/
-inline
-static uint32 get_part_id_linear_hash(partition_info *part_info,
- uint no_parts,
- Item *part_expr,
- longlong *func_value)
+static int get_part_id_linear_hash(partition_info *part_info,
+ uint no_parts,
+ Item *part_expr,
+ uint32 *part_id,
+ longlong *func_value)
{
DBUG_ENTER("get_part_id_linear_hash");
- *func_value= part_val_int(part_expr);
- DBUG_RETURN(get_part_id_from_linear_hash(*func_value,
- part_info->linear_hash_mask,
- no_parts));
+ if (part_val_int(part_expr, func_value))
+ DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
+
+ *part_id= get_part_id_from_linear_hash(*func_value,
+ part_info->linear_hash_mask,
+ no_parts);
+ DBUG_RETURN(FALSE);
}
@@ -2503,49 +2526,7 @@ static void restore_part_field_pointers(Field **ptr, uchar **restore_ptr)
}
return;
}
-/*
- This function is used to calculate the partition id where all partition
- fields have been prepared to point to a record where the partition field
- values are bound.
-
- SYNOPSIS
- get_partition_id()
- part_info A reference to the partition_info struct where all the
- desired information is given
- out:part_id The partition id is returned through this pointer
- out: func_value Value of partition function (longlong)
-
- RETURN VALUE
- part_id Partition id of partition that would contain
- row with given values of PF-fields
- HA_ERR_NO_PARTITION_FOUND The fields of the partition function didn't
- fit into any partition and thus the values of
- the PF-fields are not allowed.
-
- DESCRIPTION
- A routine used from write_row, update_row and delete_row from any
- handler supporting partitioning. It is also a support routine for
- get_partition_set used to find the set of partitions needed to scan
- for a certain index scan or full table scan.
-
- It is actually 14 different variants of this function which are called
- through a function pointer.
- get_partition_id_list
- get_partition_id_range
- get_partition_id_hash_nosub
- get_partition_id_key_nosub
- get_partition_id_linear_hash_nosub
- get_partition_id_linear_key_nosub
- get_partition_id_range_sub_hash
- get_partition_id_range_sub_key
- get_partition_id_range_sub_linear_hash
- get_partition_id_range_sub_linear_key
- get_partition_id_list_sub_hash
- get_partition_id_list_sub_key
- get_partition_id_list_sub_linear_hash
- get_partition_id_list_sub_linear_key
-*/
/*
This function is used to calculate the main partition to use in the case of
@@ -2557,14 +2538,13 @@ static void restore_part_field_pointers(Field **ptr, uchar **restore_ptr)
part_info A reference to the partition_info struct where all the
desired information is given
out:part_id The partition id is returned through this pointer
- out: func_value The value calculated by partition function
+ out:func_value The value calculated by partition function
RETURN VALUE
- part_id Partition id of partition that would contain
- row with given values of PF-fields
HA_ERR_NO_PARTITION_FOUND The fields of the partition function didn't
fit into any partition and thus the values of
the PF-fields are not allowed.
+ 0 OK
DESCRIPTION
@@ -2640,13 +2620,14 @@ static int get_part_part_id_charset_func(partition_info *part_info,
}
-static uint32 get_subpart_id_charset_func(partition_info *part_info)
+static int get_subpart_id_charset_func(partition_info *part_info,
+ uint32 *part_id)
{
int res;
copy_to_part_field_buffers(part_info->subpart_charset_field_array,
part_info->subpart_field_buffers,
part_info->restore_subpart_field_ptrs);
- res= part_info->get_subpartition_id_charset(part_info);
+ res= part_info->get_subpartition_id_charset(part_info, part_id);
restore_part_field_pointers(part_info->subpart_charset_field_array,
part_info->restore_subpart_field_ptrs);
return res;
@@ -2661,11 +2642,15 @@ int get_partition_id_list(partition_info *part_info,
int list_index;
int min_list_index= 0;
int max_list_index= part_info->no_list_values - 1;
- longlong part_func_value= part_val_int(part_info->part_expr);
+ longlong part_func_value;
+ int error= part_val_int(part_info->part_expr, &part_func_value);
longlong list_value;
bool unsigned_flag= part_info->part_expr->unsigned_flag;
DBUG_ENTER("get_partition_id_list");
+ if (error)
+ goto notfound;
+
if (part_info->part_expr->null_value)
{
if (part_info->has_null_value)
@@ -2809,10 +2794,14 @@ int get_partition_id_range(partition_info *part_info,
uint min_part_id= 0;
uint max_part_id= max_partition;
uint loc_part_id;
- longlong part_func_value= part_val_int(part_info->part_expr);
+ longlong part_func_value;
+ int error= part_val_int(part_info->part_expr, &part_func_value);
bool unsigned_flag= part_info->part_expr->unsigned_flag;
DBUG_ENTER("get_partition_id_range");
+ if (error)
+ DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
+
if (part_info->part_expr->null_value)
{
*part_id= 0;
@@ -2970,9 +2959,8 @@ int get_partition_id_hash_nosub(partition_info *part_info,
uint32 *part_id,
longlong *func_value)
{
- *part_id= get_part_id_hash(part_info->no_parts, part_info->part_expr,
- func_value);
- return 0;
+ return get_part_id_hash(part_info->no_parts, part_info->part_expr,
+ part_id, func_value);
}
@@ -2980,9 +2968,8 @@ int get_partition_id_linear_hash_nosub(partition_info *part_info,
uint32 *part_id,
longlong *func_value)
{
- *part_id= get_part_id_linear_hash(part_info, part_info->no_parts,
- part_info->part_expr, func_value);
- return 0;
+ return get_part_id_linear_hash(part_info, part_info->no_parts,
+ part_info->part_expr, part_id, func_value);
}
@@ -3016,6 +3003,8 @@ int get_partition_id_range_sub_hash(partition_info *part_info,
longlong local_func_value;
int error;
DBUG_ENTER("get_partition_id_range_sub_hash");
+ LINT_INIT(loc_part_id);
+ LINT_INIT(sub_part_id);
if (unlikely((error= get_partition_id_range(part_info, &loc_part_id,
func_value))))
@@ -3023,8 +3012,12 @@ int get_partition_id_range_sub_hash(partition_info *part_info,
DBUG_RETURN(error);
}
no_subparts= part_info->no_subparts;
- sub_part_id= get_part_id_hash(no_subparts, part_info->subpart_expr,
- &local_func_value);
+ if (unlikely((error= get_part_id_hash(no_subparts, part_info->subpart_expr,
+ &sub_part_id, &local_func_value))))
+ {
+ DBUG_RETURN(error);
+ }
+
*part_id= get_part_id_for_sub(loc_part_id, sub_part_id, no_subparts);
DBUG_RETURN(0);
}
@@ -3039,6 +3032,8 @@ int get_partition_id_range_sub_linear_hash(partition_info *part_info,
longlong local_func_value;
int error;
DBUG_ENTER("get_partition_id_range_sub_linear_hash");
+ LINT_INIT(loc_part_id);
+ LINT_INIT(sub_part_id);
if (unlikely((error= get_partition_id_range(part_info, &loc_part_id,
func_value))))
@@ -3046,9 +3041,14 @@ int get_partition_id_range_sub_linear_hash(partition_info *part_info,
DBUG_RETURN(error);
}
no_subparts= part_info->no_subparts;
- sub_part_id= get_part_id_linear_hash(part_info, no_subparts,
- part_info->subpart_expr,
- &local_func_value);
+ if (unlikely((error= get_part_id_linear_hash(part_info, no_subparts,
+ part_info->subpart_expr,
+ &sub_part_id,
+ &local_func_value))))
+ {
+ DBUG_RETURN(error);
+ }
+
*part_id= get_part_id_for_sub(loc_part_id, sub_part_id, no_subparts);
DBUG_RETURN(0);
}
@@ -3063,6 +3063,7 @@ int get_partition_id_range_sub_key(partition_info *part_info,
longlong local_func_value;
int error;
DBUG_ENTER("get_partition_id_range_sub_key");
+ LINT_INIT(loc_part_id);
if (unlikely((error= get_partition_id_range(part_info, &loc_part_id,
func_value))))
@@ -3086,6 +3087,7 @@ int get_partition_id_range_sub_linear_key(partition_info *part_info,
longlong local_func_value;
int error;
DBUG_ENTER("get_partition_id_range_sub_linear_key");
+ LINT_INIT(loc_part_id);
if (unlikely((error= get_partition_id_range(part_info, &loc_part_id,
func_value))))
@@ -3110,6 +3112,7 @@ int get_partition_id_list_sub_hash(partition_info *part_info,
longlong local_func_value;
int error;
DBUG_ENTER("get_partition_id_list_sub_hash");
+ LINT_INIT(sub_part_id);
if (unlikely((error= get_partition_id_list(part_info, &loc_part_id,
func_value))))
@@ -3117,8 +3120,12 @@ int get_partition_id_list_sub_hash(partition_info *part_info,
DBUG_RETURN(error);
}
no_subparts= part_info->no_subparts;
- sub_part_id= get_part_id_hash(no_subparts, part_info->subpart_expr,
- &local_func_value);
+ if (unlikely((error= get_part_id_hash(no_subparts, part_info->subpart_expr,
+ &sub_part_id, &local_func_value))))
+ {
+ DBUG_RETURN(error);
+ }
+
*part_id= get_part_id_for_sub(loc_part_id, sub_part_id, no_subparts);
DBUG_RETURN(0);
}
@@ -3133,6 +3140,7 @@ int get_partition_id_list_sub_linear_hash(partition_info *part_info,
longlong local_func_value;
int error;
DBUG_ENTER("get_partition_id_list_sub_linear_hash");
+ LINT_INIT(sub_part_id);
if (unlikely((error= get_partition_id_list(part_info, &loc_part_id,
func_value))))
@@ -3140,9 +3148,14 @@ int get_partition_id_list_sub_linear_hash(partition_info *part_info,
DBUG_RETURN(error);
}
no_subparts= part_info->no_subparts;
- sub_part_id= get_part_id_linear_hash(part_info, no_subparts,
- part_info->subpart_expr,
- &local_func_value);
+ if (unlikely((error= get_part_id_linear_hash(part_info, no_subparts,
+ part_info->subpart_expr,
+ &sub_part_id,
+ &local_func_value))))
+ {
+ DBUG_RETURN(error);
+ }
+
*part_id= get_part_id_for_sub(loc_part_id, sub_part_id, no_subparts);
DBUG_RETURN(0);
}
@@ -3219,36 +3232,43 @@ int get_partition_id_list_sub_linear_key(partition_info *part_info,
get_partition_id_linear_key_sub
*/
-uint32 get_partition_id_hash_sub(partition_info *part_info)
+int get_partition_id_hash_sub(partition_info *part_info,
+ uint32 *part_id)
{
longlong func_value;
return get_part_id_hash(part_info->no_subparts, part_info->subpart_expr,
- &func_value);
+ part_id, &func_value);
}
-uint32 get_partition_id_linear_hash_sub(partition_info *part_info)
+int get_partition_id_linear_hash_sub(partition_info *part_info,
+ uint32 *part_id)
{
longlong func_value;
return get_part_id_linear_hash(part_info, part_info->no_subparts,
- part_info->subpart_expr, &func_value);
+ part_info->subpart_expr, part_id,
+ &func_value);
}
-uint32 get_partition_id_key_sub(partition_info *part_info)
+int get_partition_id_key_sub(partition_info *part_info,
+ uint32 *part_id)
{
longlong func_value;
- return get_part_id_key(part_info->subpart_field_array,
- part_info->no_subparts, &func_value);
+ *part_id= get_part_id_key(part_info->subpart_field_array,
+ part_info->no_subparts, &func_value);
+ return FALSE;
}
-uint32 get_partition_id_linear_key_sub(partition_info *part_info)
+int get_partition_id_linear_key_sub(partition_info *part_info,
+ uint32 *part_id)
{
longlong func_value;
- return get_part_id_linear_key(part_info,
- part_info->subpart_field_array,
- part_info->no_subparts, &func_value);
+ *part_id= get_part_id_linear_key(part_info,
+ part_info->subpart_field_array,
+ part_info->no_subparts, &func_value);
+ return FALSE;
}
@@ -3337,37 +3357,40 @@ static bool check_part_func_bound(Field **ptr)
buf A buffer that can be used to evaluate the partition function
key_info The index object
key_spec A key_range containing key and key length
+ out:part_id The returned partition id
RETURN VALUES
- part_id Subpartition id to use
+ TRUE All fields in partition function are set
+ FALSE Not all fields in partition function are set
DESCRIPTION
Use key buffer to set-up record in buf, move field pointers and
get the partition identity and restore field pointers afterwards.
*/
-static uint32 get_sub_part_id_from_key(const TABLE *table,uchar *buf,
- KEY *key_info,
- const key_range *key_spec)
+static int get_sub_part_id_from_key(const TABLE *table,uchar *buf,
+ KEY *key_info,
+ const key_range *key_spec,
+ uint32 *part_id)
{
uchar *rec0= table->record[0];
partition_info *part_info= table->part_info;
- uint32 part_id;
+ int res;
DBUG_ENTER("get_sub_part_id_from_key");
key_restore(buf, (uchar*)key_spec->key, key_info, key_spec->length);
if (likely(rec0 == buf))
{
- part_id= part_info->get_subpartition_id(part_info);
+ res= part_info->get_subpartition_id(part_info, part_id);
}
else
{
Field **part_field_array= part_info->subpart_field_array;
set_field_ptr(part_field_array, buf, rec0);
- part_id= part_info->get_subpartition_id(part_info);
+ res= part_info->get_subpartition_id(part_info, part_id);
set_field_ptr(part_field_array, rec0, buf);
}
- DBUG_RETURN(part_id);
+ DBUG_RETURN(res);
}
/*
@@ -3586,7 +3609,13 @@ void get_partition_set(const TABLE *table, uchar *buf, const uint index,
else if (part_info->is_sub_partitioned())
{
if (part_info->all_fields_in_SPF.is_set(index))
- sub_part= get_sub_part_id_from_key(table, buf, key_info, key_spec);
+ {
+ if (get_sub_part_id_from_key(table, buf, key_info, key_spec, &sub_part))
+ {
+ part_spec->start_part= no_parts;
+ DBUG_VOID_RETURN;
+ }
+ }
else if (part_info->all_fields_in_PPF.is_set(index))
{
if (get_part_id_from_key(table,buf,key_info,
@@ -3632,7 +3661,14 @@ void get_partition_set(const TABLE *table, uchar *buf, const uint index,
else if (part_info->is_sub_partitioned())
{
if (check_part_func_bound(part_info->subpart_field_array))
- sub_part= get_sub_part_id_from_key(table, buf, key_info, key_spec);
+ {
+ if (get_sub_part_id_from_key(table, buf, key_info, key_spec, &sub_part))
+ {
+ part_spec->start_part= no_parts;
+ clear_indicator_in_key_fields(key_info);
+ DBUG_VOID_RETURN;
+ }
+ }
else if (check_part_func_bound(part_info->part_field_array))
{
if (get_part_id_from_key(table,buf,key_info,key_spec,&part_part))
@@ -4163,12 +4199,13 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
!(thd->work_part_info= thd->lex->part_info->get_clone()))
DBUG_RETURN(TRUE);
+ /* ALTER_ADMIN_PARTITION is handled in mysql_admin_table */
+ DBUG_ASSERT(!(alter_info->flags & ALTER_ADMIN_PARTITION));
+
if (alter_info->flags &
(ALTER_ADD_PARTITION | ALTER_DROP_PARTITION |
ALTER_COALESCE_PARTITION | ALTER_REORGANIZE_PARTITION |
- ALTER_TABLE_REORG | ALTER_OPTIMIZE_PARTITION |
- ALTER_CHECK_PARTITION | ALTER_ANALYZE_PARTITION |
- ALTER_REPAIR_PARTITION | ALTER_REBUILD_PARTITION))
+ ALTER_TABLE_REORG | ALTER_REBUILD_PARTITION))
{
partition_info *tab_part_info= table->part_info;
partition_info *alt_part_info= thd->work_part_info;
@@ -4219,8 +4256,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
alter_info->no_parts= curr_part_no - new_part_no;
}
}
- if (table->s->db_type()->alter_table_flags &&
- (!(flags= table->s->db_type()->alter_table_flags(alter_info->flags))))
+ if (!(flags= table->file->alter_table_flags(alter_info->flags)))
{
my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
DBUG_RETURN(1);
@@ -4560,11 +4596,7 @@ that are reorganised.
}
tab_part_info->no_parts-= no_parts_dropped;
}
- else if ((alter_info->flags & ALTER_OPTIMIZE_PARTITION) ||
- (alter_info->flags & ALTER_ANALYZE_PARTITION) ||
- (alter_info->flags & ALTER_CHECK_PARTITION) ||
- (alter_info->flags & ALTER_REPAIR_PARTITION) ||
- (alter_info->flags & ALTER_REBUILD_PARTITION))
+ else if (alter_info->flags & ALTER_REBUILD_PARTITION)
{
uint no_parts_found;
uint no_parts_opt= alter_info->partition_names.elements;
@@ -4572,18 +4604,7 @@ that are reorganised.
if (no_parts_found != no_parts_opt &&
(!(alter_info->flags & ALTER_ALL_PARTITION)))
{
- const char *ptr;
- if (alter_info->flags & ALTER_OPTIMIZE_PARTITION)
- ptr= "OPTIMIZE";
- else if (alter_info->flags & ALTER_ANALYZE_PARTITION)
- ptr= "ANALYZE";
- else if (alter_info->flags & ALTER_CHECK_PARTITION)
- ptr= "CHECK";
- else if (alter_info->flags & ALTER_REPAIR_PARTITION)
- ptr= "REPAIR";
- else
- ptr= "REBUILD";
- my_error(ER_DROP_PARTITION_NON_EXISTENT, MYF(0), ptr);
+ my_error(ER_DROP_PARTITION_NON_EXISTENT, MYF(0), "REBUILD");
DBUG_RETURN(TRUE);
}
if (!(*fast_alter_partition))
@@ -6836,9 +6857,11 @@ int get_part_iter_for_interval_via_walking(partition_info *part_info,
field->set_null();
if (is_subpart)
{
- part_id= part_info->get_subpartition_id(part_info);
- init_single_partition_iterator(part_id, part_iter);
- return 1; /* Ok, iterator initialized */
+ if (!part_info->get_subpartition_id(part_info, &part_id))
+ {
+ init_single_partition_iterator(part_id, part_iter);
+ return 1; /* Ok, iterator initialized */
+ }
}
else
{
@@ -7007,13 +7030,18 @@ static uint32 get_next_partition_via_walking(PARTITION_ITERATOR *part_iter)
static uint32 get_next_subpartition_via_walking(PARTITION_ITERATOR *part_iter)
{
Field *field= part_iter->part_info->subpart_field_array[0];
+ uint32 res;
if (part_iter->field_vals.cur == part_iter->field_vals.end)
{
part_iter->field_vals.cur= part_iter->field_vals.start;
return NOT_A_PARTITION_ID;
}
field->store(part_iter->field_vals.cur++, FALSE);
- return part_iter->part_info->get_subpartition_id(part_iter->part_info);
+ if (part_iter->part_info->get_subpartition_id(part_iter->part_info,
+ &res))
+ return NOT_A_PARTITION_ID;
+ return res;
+
}
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 1b56683c0ed..436f889a56f 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1715,16 +1715,16 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
}
if (!plugin->plugin_dl)
{
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "Built-in plugins cannot be deleted,.");
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_PLUGIN_DELETE_BUILTIN, ER(WARN_PLUGIN_DELETE_BUILTIN));
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
goto err;
}
plugin->state= PLUGIN_IS_DELETED;
if (plugin->ref_count)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "Plugin is busy and will be uninstalled on shutdown");
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_PLUGIN_BUSY, ER(WARN_PLUGIN_BUSY));
else
reap_needed= true;
reap_plugins();
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index af33fdba71a..e5b00f79d6a 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -6886,6 +6886,7 @@ only_eq_ref_tables(JOIN *join,ORDER *order,table_map tables)
{
if (specialflag & SPECIAL_SAFE_MODE)
return 0; // skip this optimize /* purecov: inspected */
+ tables&= ~PSEUDO_TABLE_BITS;
for (JOIN_TAB **tab=join->map2table ; tables ; tab++, tables>>=1)
{
if (tables & 1 && !eq_ref_table(join, order, *tab))
@@ -8608,6 +8609,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
}
/* Flatten nested joins that can be flattened. */
+ TABLE_LIST *right_neighbor= NULL;
+ bool fix_name_res= FALSE;
li.rewind();
while ((table= li++))
{
@@ -8620,9 +8623,17 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
{
tbl->embedding= table->embedding;
tbl->join_list= table->join_list;
- }
+ }
li.replace(nested_join->join_list);
+ /* Need to update the name resolution table chain when flattening joins */
+ fix_name_res= TRUE;
+ table= *li.ref();
}
+ if (fix_name_res)
+ table->next_name_resolution_table= right_neighbor ?
+ right_neighbor->first_leaf_for_name_resolution() :
+ NULL;
+ right_neighbor= table;
}
DBUG_RETURN(conds);
}
@@ -9297,6 +9308,7 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
*/
if ((type= item->field_type()) == MYSQL_TYPE_DATETIME ||
type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE ||
+ type == MYSQL_TYPE_NEWDATE ||
type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_GEOMETRY)
new_field= item->tmp_table_field_from_field_type(table, 1);
/*
@@ -9813,11 +9825,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
if (type == Item::SUM_FUNC_ITEM && !group && !save_sum_fields)
{ /* Can't calc group yet */
- ((Item_sum*) item)->result_field=0;
- for (i=0 ; i < ((Item_sum*) item)->arg_count ; i++)
+ Item_sum *sum_item= (Item_sum *) item;
+ sum_item->result_field=0;
+ for (i=0 ; i < sum_item->get_arg_count() ; i++)
{
- Item **argp= ((Item_sum*) item)->args + i;
- Item *arg= *argp;
+ Item *arg= sum_item->get_arg(i);
if (!arg->const_item())
{
Field *new_field=
@@ -9845,7 +9857,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
string_total_length+= new_field->pack_length();
}
thd->mem_root= mem_root_save;
- thd->change_item_tree(argp, new Item_field(new_field));
+ arg= sum_item->set_arg(i, thd, new Item_field(new_field));
thd->mem_root= &table->mem_root;
if (!(new_field->flags & NOT_NULL_FLAG))
{
@@ -9854,7 +9866,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
new_field->maybe_null() is still false, it will be
changed below. But we have to setup Item_field correctly
*/
- (*argp)->maybe_null=1;
+ arg->maybe_null=1;
}
new_field->field_index= fieldnr++;
}
@@ -14723,9 +14735,9 @@ count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param,
param->quick_group=0; // UDF SUM function
param->sum_func_count++;
- for (uint i=0 ; i < sum_item->arg_count ; i++)
+ for (uint i=0 ; i < sum_item->get_arg_count() ; i++)
{
- if (sum_item->args[0]->real_item()->type() == Item::FIELD_ITEM)
+ if (sum_item->get_arg(i)->real_item()->type() == Item::FIELD_ITEM)
param->field_count++;
else
param->func_count++;
@@ -14994,6 +15006,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
Item *pos;
List_iterator_fast<Item> li(all_fields);
Copy_field *copy= NULL;
+ IF_DBUG(Copy_field *copy_start);
res_selected_fields.empty();
res_all_fields.empty();
List_iterator_fast<Item> itr(res_all_fields);
@@ -15006,12 +15019,19 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
goto err2;
param->copy_funcs.empty();
+ IF_DBUG(copy_start= copy);
for (i= 0; (pos= li++); i++)
{
Field *field;
uchar *tmp;
Item *real_pos= pos->real_item();
- if (real_pos->type() == Item::FIELD_ITEM)
+ /*
+ Aggregate functions can be substituted for fields (by e.g. temp tables).
+ We need to filter those substituted fields out.
+ */
+ if (real_pos->type() == Item::FIELD_ITEM &&
+ !(real_pos != pos &&
+ ((Item_ref *)pos)->ref_type() == Item_ref::AGGREGATE_REF))
{
Item_field *item;
if (!(item= new Item_field(thd, ((Item_field*) real_pos))))
@@ -15058,6 +15078,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
goto err;
if (copy)
{
+ DBUG_ASSERT (param->field_count > (uint) (copy - copy_start));
copy->set(tmp, item->result_field);
item->result_field->move_field(copy->to_ptr,copy->to_null_ptr,1);
#ifdef HAVE_purify
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 3c3b728f980..c8922d9045e 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -515,7 +515,7 @@ public:
bool send_row_on_empty_set()
{
return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
- !group_list);
+ !group_list && having_value != Item::COND_FALSE);
}
bool change_result(select_result *result);
bool is_top_level_join() const
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index b5ab6484d12..23e0514376b 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -619,7 +619,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if ((table_list->view ?
view_store_create_info(thd, table_list, &buffer) :
- store_create_info(thd, table_list, &buffer, NULL)))
+ store_create_info(thd, table_list, &buffer, NULL,
+ FALSE /* show_database */)))
DBUG_RETURN(TRUE);
List<Item> field_list;
@@ -810,7 +811,8 @@ mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd)
DBUG_PRINT("enter",("table: %s",table_list->table->s->table_name.str));
protocol->prepare_for_resend();
- if (store_create_info(thd, table_list, packet, NULL))
+ if (store_create_info(thd, table_list, packet, NULL,
+ FALSE /* show_database */))
DBUG_RETURN(-1);
if (fd < 0)
@@ -1062,7 +1064,7 @@ static bool get_field_default_value(THD *thd, TABLE *table,
*/
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
- HA_CREATE_INFO *create_info_arg)
+ HA_CREATE_INFO *create_info_arg, bool show_database)
{
List<Item> field_list;
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
@@ -1110,6 +1112,25 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
alias= share->table_name.str;
}
}
+
+ /*
+ Print the database before the table name if told to do that. The
+ database name is only printed in the event that it is different
+ from the current database. The main reason for doing this is to
+ avoid having to update gazillions of tests and result files, but
+ it also saves a few bytes of the binary log.
+ */
+ if (show_database)
+ {
+ const LEX_STRING *const db=
+ table_list->schema_table ? &INFORMATION_SCHEMA_NAME : &table->s->db;
+ if (strcmp(db->str, thd->db) != 0)
+ {
+ append_identifier(thd, packet, db->str, db->length);
+ packet->append(STRING_WITH_LEN("."));
+ }
+ }
+
append_identifier(thd, packet, alias, strlen(alias));
packet->append(STRING_WITH_LEN(" (\n"));
/*
@@ -1434,7 +1455,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
FALSE,
show_table_options))))
{
- packet->append(STRING_WITH_LEN(" /*!50100"));
+ packet->append(STRING_WITH_LEN("\n/*!50100"));
packet->append(part_syntax, part_syntax_len);
packet->append(STRING_WITH_LEN(" */"));
my_free(part_syntax, MYF(0));
@@ -2964,7 +2985,7 @@ static int fill_schema_table_names(THD *thd, TABLE *table,
@retval SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
*/
-static uint get_table_open_method(TABLE_LIST *tables,
+uint get_table_open_method(TABLE_LIST *tables,
ST_SCHEMA_TABLE *schema_table,
enum enum_schema_tables schema_table_idx)
{
@@ -2975,12 +2996,22 @@ static uint get_table_open_method(TABLE_LIST *tables,
{
Field **ptr, *field;
int table_open_method= 0, field_indx= 0;
+ uint star_table_open_method= OPEN_FULL_TABLE;
+ bool used_star= true; // true if '*' is used in select
for (ptr=tables->table->field; (field= *ptr) ; ptr++)
{
+ star_table_open_method=
+ min(star_table_open_method,
+ schema_table->fields_info[field_indx].open_method);
if (bitmap_is_set(tables->table->read_set, field->field_index))
+ {
+ used_star= false;
table_open_method|= schema_table->fields_info[field_indx].open_method;
+ }
field_indx++;
}
+ if (used_star)
+ return star_table_open_method;
return table_open_method;
}
/* I_S tables which use get_all_tables but can not be optimized */
@@ -4232,6 +4263,27 @@ static int get_schema_views_record(THD *thd, TABLE_LIST *tables,
!my_strcasecmp(system_charset_info, tables->definer.host.str,
sctx->priv_host))
tables->allowed_show= TRUE;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ else
+ {
+ if ((thd->col_access & (SHOW_VIEW_ACL|SELECT_ACL)) ==
+ (SHOW_VIEW_ACL|SELECT_ACL))
+ tables->allowed_show= TRUE;
+ else
+ {
+ TABLE_LIST table_list;
+ uint view_access;
+ memset(&table_list, 0, sizeof(table_list));
+ table_list.db= tables->view_db.str;
+ table_list.table_name= tables->view_name.str;
+ table_list.grant.privilege= thd->col_access;
+ view_access= get_table_grant(thd, &table_list);
+ if ((view_access & (SHOW_VIEW_ACL|SELECT_ACL)) ==
+ (SHOW_VIEW_ACL|SELECT_ACL))
+ tables->allowed_show= TRUE;
+ }
+ }
+#endif
}
restore_record(table, s->default_values);
tmp_db_name= &tables->view_db;
@@ -6091,7 +6143,7 @@ ST_FIELD_INFO events_fields_info[]=
SKIP_OPEN_TABLE},
{"INTERVAL_FIELD", 18, MYSQL_TYPE_STRING, 0, 1, "Interval field",
SKIP_OPEN_TABLE},
- {"SQL_MODE", 65535, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
+ {"SQL_MODE", 32*256, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
{"STARTS", 0, MYSQL_TYPE_DATETIME, 0, 1, "Starts", SKIP_OPEN_TABLE},
{"ENDS", 0, MYSQL_TYPE_DATETIME, 0, 1, "Ends", SKIP_OPEN_TABLE},
{"STATUS", 18, MYSQL_TYPE_STRING, 0, 0, "Status", SKIP_OPEN_TABLE},
@@ -6334,8 +6386,8 @@ ST_FIELD_INFO triggers_fields_info[]=
{"ACTION_REFERENCE_OLD_ROW", 3, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"ACTION_REFERENCE_NEW_ROW", 3, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"CREATED", 0, MYSQL_TYPE_DATETIME, 0, 1, "Created", OPEN_FULL_TABLE},
- {"SQL_MODE", 65535, MYSQL_TYPE_STRING, 0, 0, "sql_mode", OPEN_FULL_TABLE},
- {"DEFINER", 65535, MYSQL_TYPE_STRING, 0, 0, "Definer", OPEN_FULL_TABLE},
+ {"SQL_MODE", 32*256, MYSQL_TYPE_STRING, 0, 0, "sql_mode", OPEN_FULL_TABLE},
+ {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, "Definer", OPEN_FULL_TABLE},
{"CHARACTER_SET_CLIENT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
"character_set_client", OPEN_FULL_TABLE},
{"COLLATION_CONNECTION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
diff --git a/sql/sql_show.h b/sql/sql_show.h
index d63217584b2..3baaef00a7d 100644
--- a/sql/sql_show.h
+++ b/sql/sql_show.h
@@ -33,7 +33,7 @@ find_files_result find_files(THD *thd, List<LEX_STRING> *files, const char *db,
const char *path, const char *wild, bool dir);
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
- HA_CREATE_INFO *create_info_arg);
+ HA_CREATE_INFO *create_info_arg, bool show_database);
int view_store_create_info(THD *thd, TABLE_LIST *table, String *buff);
int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index e3447664922..6552a6bfab6 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1835,8 +1835,9 @@ bool quick_rm_table(handlerton *base,const char *db,
if (my_delete(path,MYF(0)))
error= 1; /* purecov: inspected */
path[path_length - reg_ext_length]= '\0'; // Remove reg_ext
- DBUG_RETURN(ha_delete_table(current_thd, base, path, db, table_name, 0) ||
- error);
+ if (!(flags & FRM_ONLY))
+ error|= ha_delete_table(current_thd, base, path, db, table_name, 0);
+ DBUG_RETURN(error);
}
/*
@@ -3547,11 +3548,13 @@ bool mysql_create_table_no_lock(THD *thd,
#endif /* HAVE_READLINK */
{
if (create_info->data_file_name)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "DATA DIRECTORY option ignored");
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
+ "DATA DIRECTORY");
if (create_info->index_file_name)
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
- "INDEX DIRECTORY option ignored");
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
+ "INDEX DIRECTORY");
create_info->data_file_name= create_info->index_file_name= 0;
}
create_info->table_options=db_options;
@@ -4204,7 +4207,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
table->next_local= save_next_local;
thd->open_options&= ~extra_open_options;
#ifdef WITH_PARTITION_STORAGE_ENGINE
- if (table->table && table->table->part_info)
+ if (table->table)
{
/*
Set up which partitions that should be processed
@@ -4212,11 +4215,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
*/
Alter_info *alter_info= &lex->alter_info;
- if (alter_info->flags & ALTER_ANALYZE_PARTITION ||
- alter_info->flags & ALTER_CHECK_PARTITION ||
- alter_info->flags & ALTER_OPTIMIZE_PARTITION ||
- alter_info->flags & ALTER_REPAIR_PARTITION)
+ if (alter_info->flags & ALTER_ADMIN_PARTITION)
{
+ if (!table->table->part_info)
+ {
+ my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
uint no_parts_found;
uint no_parts_opt= alter_info->partition_names.elements;
no_parts_found= set_part_state(alter_info, table->table->part_info,
@@ -5018,8 +5023,9 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
}
VOID(pthread_mutex_unlock(&LOCK_open));
- IF_DBUG(int result=) store_create_info(thd, table, &query,
- create_info);
+ IF_DBUG(int result=)
+ store_create_info(thd, table, &query,
+ create_info, FALSE /* show_database */);
DBUG_ASSERT(result == 0); // store_create_info() always return 0
write_bin_log(thd, TRUE, query.ptr(), query.length());
@@ -5172,6 +5178,7 @@ err:
index_drop_count OUT The number of elements in the array.
index_add_buffer OUT An array of offsets into key_info_buffer.
index_add_count OUT The number of elements in the array.
+ candidate_key_count OUT The number of candidate keys in original table.
DESCRIPTION
'table' (first argument) contains information of the original
@@ -5202,7 +5209,8 @@ compare_tables(TABLE *table,
enum_alter_table_change_level *need_copy_table,
KEY **key_info_buffer,
uint **index_drop_buffer, uint *index_drop_count,
- uint **index_add_buffer, uint *index_add_count)
+ uint **index_add_buffer, uint *index_add_count,
+ uint *candidate_key_count)
{
Field **f_ptr, *field;
uint changes= 0, tmp;
@@ -5217,6 +5225,9 @@ compare_tables(TABLE *table,
create_info->varchar will be reset in mysql_prepare_create_table.
*/
bool varchar= create_info->varchar;
+ bool not_nullable= true;
+ DBUG_ENTER("compare_tables");
+
/*
Create a copy of alter_info.
To compare the new and old table definitions, we need to "prepare"
@@ -5234,24 +5245,21 @@ compare_tables(TABLE *table,
*/
Alter_info tmp_alter_info(*alter_info, thd->mem_root);
uint db_options= 0; /* not used */
-
- DBUG_ENTER("compare_tables");
-
/* Create the prepared information. */
if (mysql_prepare_create_table(thd, create_info,
- &tmp_alter_info,
- (table->s->tmp_table != NO_TMP_TABLE),
- &db_options,
- table->file, key_info_buffer,
- &key_count, 0))
+ &tmp_alter_info,
+ (table->s->tmp_table != NO_TMP_TABLE),
+ &db_options,
+ table->file, key_info_buffer,
+ &key_count, 0))
DBUG_RETURN(1);
/* Allocate result buffers. */
if (! (*index_drop_buffer=
- (uint*) thd->alloc(sizeof(uint) * table->s->keys)) ||
+ (uint*) thd->alloc(sizeof(uint) * table->s->keys)) ||
! (*index_add_buffer=
- (uint*) thd->alloc(sizeof(uint) * tmp_alter_info.key_list.elements)))
+ (uint*) thd->alloc(sizeof(uint) * tmp_alter_info.key_list.elements)))
DBUG_RETURN(1);
-
+
/*
Some very basic checks. If number of fields changes, or the
handler, we need to run full ALTER TABLE. In the future
@@ -5287,6 +5295,8 @@ compare_tables(TABLE *table,
create_info->used_fields & HA_CREATE_USED_ROW_FORMAT ||
create_info->used_fields & HA_CREATE_USED_PAGE_CHECKSUM ||
create_info->used_fields & HA_CREATE_USED_TRANSACTIONAL ||
+ 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)) ||
order_num ||
!table->s->mysql_version ||
@@ -5365,12 +5375,29 @@ compare_tables(TABLE *table,
*/
*index_drop_count= 0;
*index_add_count= 0;
+ *candidate_key_count= 0;
for (table_key= table->key_info; table_key < table_key_end; table_key++)
{
KEY_PART_INFO *table_part;
KEY_PART_INFO *table_part_end= table_key->key_part + table_key->key_parts;
KEY_PART_INFO *new_part;
+ /*
+ Check if key is a candidate key, i.e. a unique index with no index
+ fields nullable, then key is either already primary key or could
+ be promoted to primary key if the original primary key is dropped.
+ Count all candidate keys.
+ */
+ not_nullable= true;
+ for (table_part= table_key->key_part;
+ table_part < table_part_end;
+ table_part++)
+ {
+ not_nullable= not_nullable && (! table_part->field->maybe_null());
+ }
+ if ((table_key->flags & HA_NOSAME) && not_nullable)
+ (*candidate_key_count)++;
+
/* Search a new key with the same name. */
for (new_key= *key_info_buffer; new_key < new_key_end; new_key++)
{
@@ -6000,12 +6027,16 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
uint *index_drop_buffer;
uint index_add_count;
uint *index_add_buffer;
+ uint candidate_key_count;
+ 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
@@ -6416,7 +6447,8 @@ view_err:
&need_copy_table_res,
&key_info_buffer,
&index_drop_buffer, &index_drop_count,
- &index_add_buffer, &index_add_count))
+ &index_add_buffer, &index_add_count,
+ &candidate_key_count))
goto err;
if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
@@ -6438,8 +6470,7 @@ view_err:
uint *idx_p;
uint *idx_end_p;
- if (table->s->db_type()->alter_table_flags)
- alter_flags= table->s->db_type()->alter_table_flags(alter_info->flags);
+ alter_flags= table->file->alter_table_flags(alter_info->flags);
DBUG_PRINT("info", ("alter_flags: %lu", alter_flags));
/* Check dropped indexes. */
for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
@@ -6450,20 +6481,40 @@ view_err:
DBUG_PRINT("info", ("index dropped: '%s'", key->name));
if (key->flags & HA_NOSAME)
{
- /* Unique key. Check for "PRIMARY". */
- if (! my_strcasecmp(system_charset_info,
- key->name, primary_key_name))
+ /*
+ Unique key. Check for "PRIMARY".
+ or if dropping last unique key
+ */
+ if ((uint) (key - table->key_info) == table->s->primary_key)
{
+ DBUG_PRINT("info", ("Dropping primary key"));
/* Primary key. */
needed_online_flags|= HA_ONLINE_DROP_PK_INDEX;
needed_fast_flags|= HA_ONLINE_DROP_PK_INDEX_NO_WRITES;
pk_changed++;
+ candidate_key_count--;
}
else
{
+ KEY_PART_INFO *part_end= key->key_part + key->key_parts;
+ bool is_candidate_key= true;
+
/* Non-primary unique key. */
needed_online_flags|= HA_ONLINE_DROP_UNIQUE_INDEX;
needed_fast_flags|= HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES;
+
+ /*
+ Check if all fields in key are declared
+ NOT NULL and adjust candidate_key_count
+ */
+ for (KEY_PART_INFO *key_part= key->key_part;
+ key_part < part_end;
+ key_part++)
+ is_candidate_key=
+ (is_candidate_key &&
+ (! table->field[key_part->fieldnr-1]->maybe_null()));
+ if (is_candidate_key)
+ candidate_key_count--;
}
}
else
@@ -6473,7 +6524,8 @@ view_err:
needed_fast_flags|= HA_ONLINE_DROP_INDEX_NO_WRITES;
}
}
-
+ no_pk= ((table->s->primary_key == MAX_KEY) ||
+ (needed_online_flags & HA_ONLINE_DROP_PK_INDEX));
/* Check added indexes. */
for (idx_p= index_add_buffer, idx_end_p= idx_p + index_add_count;
idx_p < idx_end_p;
@@ -6483,14 +6535,38 @@ view_err:
DBUG_PRINT("info", ("index added: '%s'", key->name));
if (key->flags & HA_NOSAME)
{
- /* Unique key. Check for "PRIMARY". */
- if (! my_strcasecmp(system_charset_info,
- key->name, primary_key_name))
+ /* Unique key */
+
+ KEY_PART_INFO *part_end= key->key_part + key->key_parts;
+ bool is_candidate_key= true;
+
+ /*
+ Check if all fields in key are declared
+ NOT NULL
+ */
+ for (KEY_PART_INFO *key_part= key->key_part;
+ key_part < part_end;
+ key_part++)
+ is_candidate_key=
+ (is_candidate_key &&
+ (! table->field[key_part->fieldnr]->maybe_null()));
+
+ /*
+ Check for "PRIMARY"
+ or if adding first unique key
+ defined on non-nullable fields
+ */
+
+ if ((!my_strcasecmp(system_charset_info,
+ key->name, primary_key_name)) ||
+ (no_pk && candidate_key_count == 0 && is_candidate_key))
{
+ DBUG_PRINT("info", ("Adding primary key"));
/* Primary key. */
needed_online_flags|= HA_ONLINE_ADD_PK_INDEX;
needed_fast_flags|= HA_ONLINE_ADD_PK_INDEX_NO_WRITES;
pk_changed++;
+ no_pk= false;
}
else
{
@@ -6507,6 +6583,20 @@ view_err:
}
}
+ if ((candidate_key_count > 0) &&
+ (needed_online_flags & HA_ONLINE_DROP_PK_INDEX))
+ {
+ /*
+ Dropped primary key when there is some other unique
+ not null key that should be converted to primary key
+ */
+ needed_online_flags|= HA_ONLINE_ADD_PK_INDEX;
+ needed_fast_flags|= HA_ONLINE_ADD_PK_INDEX_NO_WRITES;
+ pk_changed= 2;
+ }
+
+ DBUG_PRINT("info", ("needed_online_flags: 0x%lx, needed_fast_flags: 0x%lx",
+ needed_online_flags, needed_fast_flags));
/*
Online or fast add/drop index is possible only if
the primary key is not added and dropped in the same statement.
@@ -6650,7 +6740,6 @@ view_err:
/* Copy the data if necessary. */
thd->count_cuted_fields= CHECK_FIELD_WARN; // calc cuted fields
thd->cuted_fields=0L;
- thd_proc_info(thd, "copy to tmp table");
copied=deleted=0;
/*
We do not copy data for MERGE tables. Only the children have data.
@@ -6661,6 +6750,7 @@ view_err:
/* We don't want update TIMESTAMP fields during ALTER TABLE. */
new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
new_table->next_number_field=new_table->found_next_number_field;
+ thd_proc_info(thd, "copy to tmp table");
error= copy_data_between_tables(table, new_table,
alter_info->create_list, ignore,
order_num, order, &copied, &deleted,
@@ -6672,6 +6762,7 @@ view_err:
VOID(pthread_mutex_lock(&LOCK_open));
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
VOID(pthread_mutex_unlock(&LOCK_open));
+ thd_proc_info(thd, "manage keys");
alter_table_manage_keys(table, table->file->indexes_are_disabled(),
alter_info->keys_onoff);
error= ha_autocommit_or_rollback(thd, 0);
@@ -7004,7 +7095,10 @@ err1:
close_temporary_table(thd, new_table, 1, 1);
}
else
- VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
+ VOID(quick_rm_table(new_db_type, new_db, tmp_name,
+ create_info->frm_only
+ ? FN_IS_TMP | FRM_ONLY
+ : FN_IS_TMP));
err:
/*
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index cee1c9d6bd4..050deeaf0ae 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -399,7 +399,6 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
}
else
{
- DBUG_ASSERT(!thd->stmt_arena->is_conventional());
/*
We're in execution of a prepared statement or stored procedure:
reset field items to point at fields from the created temporary table.
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index dbbc0e58d8a..7d7b08f964a 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1039,7 +1039,7 @@ reopen_tables:
correct order of statements. Otherwise, we use a TL_READ lock to
improve performance.
*/
- tl->lock_type= using_update_log ? TL_READ_NO_INSERT : TL_READ;
+ tl->lock_type= read_lock_type_for_table(thd, table);
tl->updating= 0;
/* Update TABLE::lock_type accordingly. */
if (!tl->placeholder() && !using_lock_tables)
@@ -1076,11 +1076,14 @@ reopen_tables:
}
/* now lock and fill tables */
- if (lock_tables(thd, table_list, table_count, &need_reopen))
+ if (!thd->stmt_arena->is_stmt_prepare() &&
+ lock_tables(thd, table_list, table_count, &need_reopen))
{
if (!need_reopen)
DBUG_RETURN(TRUE);
+ DBUG_PRINT("info", ("lock_tables failed, reopening"));
+
/*
We have to reopen tables since some of them were altered or dropped
during lock_tables() or something was done with their triggers.
@@ -1096,6 +1099,34 @@ reopen_tables:
for (TABLE_LIST *tbl= table_list; tbl; tbl= tbl->next_global)
tbl->cleanup_items();
+ /*
+ To not to hog memory (as a result of the
+ unit->reinit_exec_mechanism() call below):
+ */
+ lex->unit.cleanup();
+
+ for (SELECT_LEX *sl= lex->all_selects_list;
+ sl;
+ sl= sl->next_select_in_list())
+ {
+ SELECT_LEX_UNIT *unit= sl->master_unit();
+ unit->reinit_exec_mechanism(); // reset unit->prepared flags
+ /*
+ Reset 'clean' flag back to force normal execution of
+ unit->cleanup() in Prepared_statement::cleanup_stmt()
+ (call to lex->unit.cleanup() above sets this flag to TRUE).
+ */
+ unit->unclean();
+ }
+
+ /*
+ Also we need to cleanup Natural_join_column::table_field items.
+ To not to traverse a join tree we will cleanup whole
+ thd->free_list (in PS execution mode that list may not contain
+ items from 'fields' list, so the cleanup above is necessary to.
+ */
+ cleanup_items(thd->free_list);
+
close_tables_for_reopen(thd, &table_list);
goto reopen_tables;
}
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 37fee49d37a..eb41e4c9b62 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -816,13 +816,24 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
DBUG_PRINT("info", ("View: %s", view_query.ptr()));
/* fill structure */
- view->select_stmt.str= view_query.c_ptr_safe();
- view->select_stmt.length= view_query.length();
view->source= thd->lex->create_view_select;
+ if (!thd->make_lex_string(&view->select_stmt, view_query.ptr(),
+ view_query.length(), false))
+ {
+ my_error(ER_OUT_OF_RESOURCES, MYF(0));
+ error= -1;
+ goto err;
+ }
+
view->file_version= 1;
view->calc_md5(md5);
- view->md5.str= md5;
+ if (!(view->md5.str= (char*) thd->memdup(md5, 32)))
+ {
+ my_error(ER_OUT_OF_RESOURCES, MYF(0));
+ error= -1;
+ goto err;
+ }
view->md5.length= 32;
can_be_merged= lex->can_be_merged();
if (lex->create_view_algorithm == VIEW_ALGORITHM_MERGE &&
@@ -949,8 +960,13 @@ loop_out:
lex_string_set(&view->view_connection_cl_name,
view->view_creation_ctx->get_connection_cl()->name);
- view->view_body_utf8.str= is_query.c_ptr_safe();
- view->view_body_utf8.length= is_query.length();
+ if (!thd->make_lex_string(&view->view_body_utf8, is_query.ptr(),
+ is_query.length(), false))
+ {
+ my_error(ER_OUT_OF_RESOURCES, MYF(0));
+ error= -1;
+ goto err;
+ }
/*
Check that table of main select do not used in subqueries.
@@ -1946,7 +1962,7 @@ mysql_rename_view(THD *thd,
goto err;
/* rename view and it's backups */
- if (rename_in_schema_file(view->db, view->table_name, new_name,
+ if (rename_in_schema_file(thd, view->db, view->table_name, new_name,
view_def.revision - 1, num_view_backups))
goto err;
@@ -1966,7 +1982,7 @@ mysql_rename_view(THD *thd,
num_view_backups))
{
/* restore renamed view in case of error */
- rename_in_schema_file(view->db, new_name, view->table_name,
+ rename_in_schema_file(thd, view->db, new_name, view->table_name,
view_def.revision - 1, num_view_backups);
goto err;
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 113248e980a..ba9a15d941b 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1817,6 +1817,8 @@ event_tail:
if (!(lex->event_parse_data= Event_parse_data::new_instance(thd)))
MYSQL_YYABORT;
lex->event_parse_data->identifier= $3;
+ lex->event_parse_data->on_completion=
+ Event_parse_data::ON_COMPLETION_DROP;
lex->sql_command= SQLCOM_CREATE_EVENT;
/* We need that for disallowing subqueries */
@@ -4299,7 +4301,7 @@ create_select:
SELECT_SYM
{
LEX *lex=Lex;
- lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
+ lex->lock_option= TL_READ_DEFAULT;
if (lex->sql_command == SQLCOM_INSERT)
lex->sql_command= SQLCOM_INSERT_SELECT;
else if (lex->sql_command == SQLCOM_REPLACE)
@@ -5656,7 +5658,7 @@ alter_commands:
{
LEX *lex= Lex;
lex->sql_command = SQLCOM_OPTIMIZE;
- lex->alter_info.flags|= ALTER_OPTIMIZE_PARTITION;
+ lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->no_write_to_binlog= $3;
lex->check_opt.init();
}
@@ -5666,7 +5668,7 @@ alter_commands:
{
LEX *lex= Lex;
lex->sql_command = SQLCOM_ANALYZE;
- lex->alter_info.flags|= ALTER_ANALYZE_PARTITION;
+ lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->no_write_to_binlog= $3;
lex->check_opt.init();
}
@@ -5674,7 +5676,7 @@ alter_commands:
{
LEX *lex= Lex;
lex->sql_command = SQLCOM_CHECK;
- lex->alter_info.flags|= ALTER_CHECK_PARTITION;
+ lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->check_opt.init();
}
opt_mi_check_type
@@ -5683,7 +5685,7 @@ alter_commands:
{
LEX *lex= Lex;
lex->sql_command = SQLCOM_REPAIR;
- lex->alter_info.flags|= ALTER_REPAIR_PARTITION;
+ lex->alter_info.flags|= ALTER_ADMIN_PARTITION;
lex->no_write_to_binlog= $3;
lex->check_opt.init();
}
@@ -8062,11 +8064,13 @@ variable:
variable_aux:
ident_or_text SET_VAR expr
{
- $$= new (YYTHD->mem_root) Item_func_set_user_var($1, $3);
+ Item_func_set_user_var *item;
+ $$= item= new (YYTHD->mem_root) Item_func_set_user_var($1, $3);
if ($$ == NULL)
MYSQL_YYABORT;
LEX *lex= Lex;
lex->uncacheable(UNCACHEABLE_RAND);
+ lex->set_var_list.push_back(item);
}
| ident_or_text
{
@@ -9394,7 +9398,7 @@ insert:
lex->duplicates= DUP_ERROR;
mysql_init_select(lex);
/* for subselects */
- lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
+ lex->lock_option= TL_READ_DEFAULT;
}
insert_lock_option
opt_ignore insert2
@@ -11297,8 +11301,7 @@ user:
if (check_string_char_length(&$$->user, ER(ER_USERNAME),
USERNAME_CHAR_LENGTH,
system_charset_info, 0) ||
- check_string_byte_length(&$$->host, ER(ER_HOSTNAME),
- HOSTNAME_LENGTH))
+ check_host_name(&$$->host))
MYSQL_YYABORT;
}
| CURRENT_USER optional_braces
diff --git a/sql/table.cc b/sql/table.cc
index 91a6c145610..b3c786010dd 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -3391,7 +3391,7 @@ TABLE_LIST *TABLE_LIST::find_underlying_table(TABLE *table_to_find)
}
/*
- cleunup items belonged to view fields translation table
+ cleanup items belonged to view fields translation table
SYNOPSIS
TABLE_LIST::cleanup_items()
@@ -3837,10 +3837,10 @@ Natural_join_column::Natural_join_column(Field_translator *field_param,
}
-Natural_join_column::Natural_join_column(Field *field_param,
+Natural_join_column::Natural_join_column(Item_field *field_param,
TABLE_LIST *tab)
{
- DBUG_ASSERT(tab->table == field_param->table);
+ DBUG_ASSERT(tab->table == field_param->field->table);
table_field= field_param;
view_field= NULL;
table_ref= tab;
@@ -3868,7 +3868,7 @@ Item *Natural_join_column::create_item(THD *thd)
return create_view_field(thd, table_ref, &view_field->item,
view_field->name);
}
- return new Item_field(thd, &thd->lex->current_select->context, table_field);
+ return table_field;
}
@@ -3879,7 +3879,7 @@ Field *Natural_join_column::field()
DBUG_ASSERT(table_field == NULL);
return NULL;
}
- return table_field;
+ return table_field->field;
}
@@ -4011,7 +4011,7 @@ void Field_iterator_natural_join::next()
cur_column_ref= column_ref_it++;
DBUG_ASSERT(!cur_column_ref || ! cur_column_ref->table_field ||
cur_column_ref->table_ref->table ==
- cur_column_ref->table_field->table);
+ cur_column_ref->table_field->field->table);
}
@@ -4175,7 +4175,7 @@ GRANT_INFO *Field_iterator_table_ref::grant()
*/
Natural_join_column *
-Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
+Field_iterator_table_ref::get_or_create_column_ref(THD *thd, TABLE_LIST *parent_table_ref)
{
Natural_join_column *nj_col;
bool is_created= TRUE;
@@ -4188,7 +4188,11 @@ Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
{
/* The field belongs to a stored table. */
Field *tmp_field= table_field_it.field();
- nj_col= new Natural_join_column(tmp_field, table_ref);
+ Item_field *tmp_item=
+ new Item_field(thd, &thd->lex->current_select->context, tmp_field);
+ if (!tmp_item)
+ return NULL;
+ nj_col= new Natural_join_column(tmp_item, table_ref);
field_count= table_ref->table->s->fields;
}
else if (field_it == &view_field_it)
@@ -4212,7 +4216,7 @@ Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
DBUG_ASSERT(nj_col);
}
DBUG_ASSERT(!nj_col->table_field ||
- nj_col->table_ref->table == nj_col->table_field->table);
+ nj_col->table_ref->table == nj_col->table_field->field->table);
/*
If the natural join column was just created add it to the list of
@@ -4277,7 +4281,7 @@ Field_iterator_table_ref::get_natural_column_ref()
nj_col= natural_join_it.column_ref();
DBUG_ASSERT(nj_col &&
(!nj_col->table_field ||
- nj_col->table_ref->table == nj_col->table_field->table));
+ nj_col->table_ref->table == nj_col->table_field->field->table));
return nj_col;
}
diff --git a/sql/table.h b/sql/table.h
index d21a9eefae8..ccd6b60664e 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -18,6 +18,7 @@
class Item; /* Needed by ORDER */
class Item_subselect;
+class Item_field;
class GRANT_TABLE;
class st_select_lex_unit;
class st_select_lex;
@@ -410,6 +411,7 @@ typedef struct st_table_share
int cached_row_logging_check;
#ifdef WITH_PARTITION_STORAGE_ENGINE
+ /** @todo: Move into *ha_data for partitioning */
bool auto_partitioned;
const char *partition_info;
uint partition_info_len;
@@ -419,6 +421,9 @@ typedef struct st_table_share
handlerton *default_part_db_type;
#endif
+ /** place to store storage engine specific data */
+ void *ha_data;
+
/*
Set share's table cache key and update its db and table name appropriately.
@@ -1012,7 +1017,7 @@ class Natural_join_column: public Sql_alloc
{
public:
Field_translator *view_field; /* Column reference of merge view. */
- Field *table_field; /* Column reference of table or temp view. */
+ Item_field *table_field; /* Column reference of table or temp view. */
TABLE_LIST *table_ref; /* Original base table/view reference. */
/*
True if a common join column of two NATURAL/USING join operands. Notice
@@ -1024,7 +1029,7 @@ public:
bool is_common;
public:
Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
- Natural_join_column(Field *field_param, TABLE_LIST *tab);
+ Natural_join_column(Item_field *field_param, TABLE_LIST *tab);
const char *name();
Item *create_item(THD *thd);
Field *field();
@@ -1603,7 +1608,7 @@ public:
GRANT_INFO *grant();
Item *create_item(THD *thd) { return field_it->create_item(thd); }
Field *field() { return field_it->field(); }
- Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref);
+ Natural_join_column *get_or_create_column_ref(THD *thd, TABLE_LIST *parent_table_ref);
Natural_join_column *get_natural_column_ref();
};