summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/debug_sync.cc38
-rw-r--r--sql/debug_sync.h1
-rw-r--r--sql/field.cc23
-rw-r--r--sql/field.h13
-rw-r--r--sql/ha_partition.cc16
-rw-r--r--sql/item.cc40
-rw-r--r--sql/item.h21
-rw-r--r--sql/item_cmpfunc.cc45
-rw-r--r--sql/item_cmpfunc.h4
-rw-r--r--sql/item_create.cc30
-rw-r--r--sql/item_create.h8
-rw-r--r--sql/item_func.cc74
-rw-r--r--sql/item_row.cc4
-rw-r--r--sql/item_row.h4
-rw-r--r--sql/item_subselect.cc8
-rw-r--r--sql/item_sum.cc10
-rw-r--r--sql/item_sum.h4
-rw-r--r--sql/log.cc2
-rw-r--r--sql/log_event.cc2
-rw-r--r--sql/log_event_old.cc66
-rw-r--r--sql/mysql_priv.h14
-rw-r--r--sql/mysqld.cc6
-rw-r--r--sql/opt_sum.cc96
-rw-r--r--sql/protocol.cc5
-rw-r--r--sql/share/Makefile.am12
-rw-r--r--sql/slave.cc32
-rw-r--r--sql/sql_base.cc3
-rw-r--r--sql/sql_delete.cc20
-rw-r--r--sql/sql_partition.cc17
-rw-r--r--sql/sql_plugin.cc3
-rw-r--r--sql/sql_profile.cc12
-rw-r--r--sql/sql_repl.cc1
-rw-r--r--sql/sql_select.cc79
-rw-r--r--sql/sql_table.cc84
-rw-r--r--sql/sql_view.cc32
-rw-r--r--sql/sql_yacc.yy6
-rw-r--r--sql/table.cc4
37 files changed, 555 insertions, 284 deletions
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index 517aab93707..a6a5dfe739a 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -1867,4 +1867,42 @@ void debug_sync(THD *thd, const char *sync_point_name, size_t name_len)
DBUG_VOID_RETURN;
}
+/**
+ Define debug sync action.
+
+ @param[in] thd thread handle
+ @param[in] action_str action string
+
+ @return status
+ @retval FALSE ok
+ @retval TRUE error
+
+ @description
+ The function is similar to @c debug_sync_eval_action but is
+ to be called immediately from the server code rather than
+ to be triggered by setting a value to DEBUG_SYNC system variable.
+
+ @note
+ The input string is copied prior to be fed to
+ @c debug_sync_eval_action to let the latter modify it.
+
+ Caution.
+ The function allocates in THD::mem_root and therefore
+ is not recommended to be deployed inside big loops.
+*/
+
+bool debug_sync_set_action(THD *thd, const char *action_str, size_t len)
+{
+ bool rc;
+ char *value;
+ DBUG_ENTER("debug_sync_set_action");
+ DBUG_ASSERT(thd);
+ DBUG_ASSERT(action_str);
+
+ value= strmake_root(thd->mem_root, action_str, len);
+ rc= debug_sync_eval_action(thd, value);
+ DBUG_RETURN(rc);
+}
+
+
#endif /* defined(ENABLED_DEBUG_SYNC) */
diff --git a/sql/debug_sync.h b/sql/debug_sync.h
index f4cd0b364cf..9ac7da39d4d 100644
--- a/sql/debug_sync.h
+++ b/sql/debug_sync.h
@@ -50,6 +50,7 @@ extern void debug_sync_end(void);
extern void debug_sync_init_thread(THD *thd);
extern void debug_sync_end_thread(THD *thd);
extern void debug_sync(THD *thd, const char *sync_point_name, size_t name_len);
+extern bool debug_sync_set_action(THD *thd, const char *action_str, size_t len);
#else /* defined(ENABLED_DEBUG_SYNC) */
diff --git a/sql/field.cc b/sql/field.cc
index 8efa765a4bc..7eade7f91bf 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -2981,16 +2981,16 @@ Field_new_decimal::unpack(uchar* to,
a decimal and write that to the raw data buffer.
*/
decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION];
- decimal_t dec;
- dec.len= from_precision;
- dec.buf= dec_buf;
+ decimal_t dec_val;
+ dec_val.len= from_precision;
+ dec_val.buf= dec_buf;
/*
Note: bin2decimal does not change the length of the field. So it is
just the first step the resizing operation. The second step does the
resizing using the precision and decimals from the slave.
*/
- bin2decimal((uchar *)from, &dec, from_precision, from_decimal);
- decimal2bin(&dec, to, precision, decimals());
+ bin2decimal((uchar *)from, &dec_val, from_precision, from_decimal);
+ decimal2bin(&dec_val, to, precision, decimals());
}
else
memcpy(to, from, len); // Sizes are the same, just copy the data.
@@ -6287,7 +6287,7 @@ check_string_copy_error(Field_str *field,
SYNOPSIS
Field_longstr::report_if_important_data()
- ptr - Truncated rest of string
+ pstr - Truncated rest of string
end - End of truncated string
count_spaces - Treat traling spaces as important data
@@ -6303,12 +6303,12 @@ check_string_copy_error(Field_str *field,
*/
int
-Field_longstr::report_if_important_data(const char *ptr, const char *end,
+Field_longstr::report_if_important_data(const char *pstr, const char *end,
bool count_spaces)
{
- if ((ptr < end) && table->in_use->count_cuted_fields)
+ if ((pstr < end) && table->in_use->count_cuted_fields)
{
- if (test_if_important_data(field_charset, ptr, end))
+ if (test_if_important_data(field_charset, pstr, end))
{
if (table->in_use->abort_on_warning)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
@@ -6824,9 +6824,8 @@ const uint Field_varstring::MAX_SIZE= UINT_MAX16;
*/
int Field_varstring::do_save_field_metadata(uchar *metadata_ptr)
{
- char *ptr= (char *)metadata_ptr;
DBUG_ASSERT(field_length <= 65535);
- int2store(ptr, field_length);
+ int2store((char*)metadata_ptr, field_length);
return 2;
}
diff --git a/sql/field.h b/sql/field.h
index fb985ab9930..b4f5977d756 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1,7 +1,7 @@
#ifndef FIELD_INCLUDED
#define FIELD_INCLUDED
-/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/*
Because of the function new_field() all field classes that have static
@@ -57,7 +57,11 @@ public:
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
uchar *ptr; // Position to field in record
- uchar *null_ptr; // Byte where null_bit is
+ /**
+ Byte where the @c NULL bit is stored inside a record. If this Field is a
+ @c NOT @c NULL field, this member is @c NULL.
+ */
+ uchar *null_ptr;
/*
Note that you can use table->in_use as replacement for current_thd member
only inside of val_*() and store() members (e.g. you can't use it in cons)
@@ -254,6 +258,9 @@ public:
inline void set_notnull(my_ptrdiff_t row_offset= 0)
{ if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
+ /**
+ Signals that this field is NULL-able.
+ */
inline bool real_maybe_null(void) { return null_ptr != 0; }
enum {
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index e0118d55d7b..ea5b4079b3f 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -5241,6 +5241,7 @@ int ha_partition::info(uint flag)
file= m_file[handler_instance];
file->info(HA_STATUS_CONST);
+ stats.block_size= file->stats.block_size;
stats.create_time= file->stats.create_time;
ref_length= m_ref_length;
}
@@ -6625,9 +6626,22 @@ void ha_partition::release_auto_increment()
ulonglong next_auto_inc_val;
lock_auto_increment();
next_auto_inc_val= ha_data->next_auto_inc_val;
+ /*
+ If the current auto_increment values is lower than the reserved
+ value, and the reserved value was reserved by this thread,
+ we can lower the reserved value.
+ */
if (next_insert_id < next_auto_inc_val &&
auto_inc_interval_for_cur_row.maximum() >= next_auto_inc_val)
- ha_data->next_auto_inc_val= next_insert_id;
+ {
+ THD *thd= ha_thd();
+ /*
+ Check that we do not lower the value because of a failed insert
+ with SET INSERT_ID, i.e. forced/non generated values.
+ */
+ if (thd->auto_inc_intervals_forced.maximum() < next_insert_id)
+ 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));
diff --git a/sql/item.cc b/sql/item.cc
index e269f6399e9..9a685c80c18 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -589,6 +589,18 @@ Item_ident::Item_ident(Name_resolution_context *context_arg,
}
+Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg)
+ :orig_db_name(NullS), orig_table_name(view_arg->table_name),
+ orig_field_name(field_name_arg), context(&view_arg->view->select_lex.context),
+ db_name(NullS), table_name(view_arg->alias),
+ field_name(field_name_arg),
+ alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
+ cached_table(NULL), depended_from(NULL)
+{
+ name = (char*) field_name_arg;
+}
+
+
/**
Constructor used by Item_field & Item_*_ref (see Item comment)
*/
@@ -4710,6 +4722,7 @@ void Item_field::cleanup()
I.e. we can drop 'field'.
*/
field= result_field= 0;
+ item_equal= NULL;
null_value= FALSE;
DBUG_VOID_RETURN;
}
@@ -5990,9 +6003,14 @@ void Item_field::print(String *str, enum_query_type query_type)
char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),str->charset());
field->val_str(&tmp);
- str->append('\'');
- str->append(tmp);
- str->append('\'');
+ if (field->is_null())
+ str->append("NULL");
+ else
+ {
+ str->append('\'');
+ str->append(tmp);
+ str->append('\'');
+ }
return;
}
Item_ident::print(str, query_type);
@@ -6015,6 +6033,20 @@ Item_ref::Item_ref(Name_resolution_context *context_arg,
}
+Item_ref::Item_ref(TABLE_LIST *view_arg, Item **item,
+ const char *field_name_arg, bool alias_name_used_arg)
+ :Item_ident(view_arg, field_name_arg),
+ result_field(NULL), ref(item)
+{
+ alias_name_used= alias_name_used_arg;
+ /*
+ This constructor is used to create some internal references over fixed items
+ */
+ if (ref && *ref && (*ref)->fixed)
+ set_properties();
+}
+
+
/**
Resolve the name of a reference to a column reference.
@@ -7504,7 +7536,7 @@ double Item_cache_decimal::val_real()
DBUG_ASSERT(fixed);
double res;
if (!value_cached && !cache_value())
- return NULL;
+ return 0.0;
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
return res;
}
diff --git a/sql/item.h b/sql/item.h
index a5c664dd159..5d811b50bbc 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1,7 +1,7 @@
#ifndef ITEM_INCLUDED
#define ITEM_INCLUDED
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1543,6 +1543,7 @@ public:
const char *db_name_arg, const char *table_name_arg,
const char *field_name_arg);
Item_ident(THD *thd, Item_ident *item);
+ Item_ident(TABLE_LIST *view_arg, const char *field_name_arg);
const char *full_name() const;
void cleanup();
bool remove_dependence_processor(uchar * arg);
@@ -2386,6 +2387,8 @@ public:
Item_ref(Name_resolution_context *context_arg, Item **item,
const char *table_name_arg, const char *field_name_arg,
bool alias_name_used_arg= FALSE);
+ Item_ref(TABLE_LIST *view_arg, Item **item,
+ const char *field_name_arg, bool alias_name_used_arg= FALSE);
/* Constructor need to process subselect with temporary tables (see Item) */
Item_ref(THD *thd, Item_ref *item)
@@ -2481,6 +2484,11 @@ public:
if (ref && result_type() == ROW_RESULT)
(*ref)->bring_value();
}
+ bool get_time(MYSQL_TIME *ltime)
+ {
+ DBUG_ASSERT(fixed);
+ return (*ref)->get_time(ltime);
+ }
bool basic_const_item() { return (*ref)->basic_const_item(); }
};
@@ -2502,6 +2510,12 @@ public:
{}
/* Constructor need to process subselect with temporary tables (see Item) */
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
+ Item_direct_ref(TABLE_LIST *view_arg, Item **item,
+ const char *field_name_arg,
+ bool alias_name_used_arg= FALSE)
+ :Item_ref(view_arg, item, field_name_arg,
+ alias_name_used_arg)
+ {}
double val_real();
longlong val_int();
@@ -2527,6 +2541,10 @@ public:
/* Constructor need to process subselect with temporary tables (see Item) */
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
:Item_direct_ref(thd, item) {}
+ Item_direct_view_ref(TABLE_LIST *view_arg, Item **item,
+ const char *field_name_arg)
+ :Item_direct_ref(view_arg, item, field_name_arg)
+ {}
bool fix_fields(THD *, Item **);
bool eq(const Item *item, bool binary_cmp) const;
@@ -3184,6 +3202,7 @@ public:
Item_cache_int(enum_field_types field_type_arg):
Item_cache(field_type_arg), value(0) {}
+ virtual void store(Item *item){ Item_cache::store(item); }
void store(Item *item, longlong val_arg);
double val_real();
longlong val_int();
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 08383325580..36d05a2d0f4 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1024,12 +1024,12 @@ bool Arg_comparator::try_year_cmp_func(Item_result type)
@return cache item or original value.
*/
-Item** Arg_comparator::cache_converted_constant(THD *thd, Item **value,
+Item** Arg_comparator::cache_converted_constant(THD *thd_arg, Item **value,
Item **cache_item,
Item_result type)
{
/* Don't need cache if doing context analysis only. */
- if (!thd->is_context_analysis_only() &&
+ if (!thd_arg->is_context_analysis_only() &&
(*value)->const_item() && type != (*value)->result_type())
{
Item_cache *cache= Item_cache::get_cache(*value, type);
@@ -1192,12 +1192,21 @@ get_year_value(THD *thd, Item ***item_arg, Item **cache_arg,
/*
Coerce value to the 19XX form in order to correctly compare
YEAR(2) & YEAR(4) types.
+ Here we are converting all item values but YEAR(4) fields since
+ 1) YEAR(4) already has a regular YYYY form and
+ 2) we don't want to convert zero/bad YEAR(4) values to the
+ value of 2000.
*/
- if (value < 70)
- value+= 100;
- if (value <= 1900)
- value+= 1900;
-
+ Item *real_item= item->real_item();
+ if (!(real_item->type() == Item::FIELD_ITEM &&
+ ((Item_field *)real_item)->field->type() == MYSQL_TYPE_YEAR &&
+ ((Item_field *)real_item)->field->field_length == 4))
+ {
+ if (value < 70)
+ value+= 100;
+ if (value <= 1900)
+ value+= 1900;
+ }
/* Convert year to DATETIME of form YYYY-00-00 00:00:00 (YYYY0000000000). */
value*= 10000000000LL;
@@ -1370,12 +1379,12 @@ int Arg_comparator::compare_real()
int Arg_comparator::compare_decimal()
{
- my_decimal value1;
- my_decimal *val1= (*a)->val_decimal(&value1);
+ my_decimal decimal1;
+ my_decimal *val1= (*a)->val_decimal(&decimal1);
if (!(*a)->null_value)
{
- my_decimal value2;
- my_decimal *val2= (*b)->val_decimal(&value2);
+ my_decimal decimal2;
+ my_decimal *val2= (*b)->val_decimal(&decimal2);
if (!(*b)->null_value)
{
if (set_null)
@@ -1399,9 +1408,9 @@ int Arg_comparator::compare_e_real()
int Arg_comparator::compare_e_decimal()
{
- my_decimal value1, value2;
- my_decimal *val1= (*a)->val_decimal(&value1);
- my_decimal *val2= (*b)->val_decimal(&value2);
+ my_decimal decimal1, decimal2;
+ my_decimal *val1= (*a)->val_decimal(&decimal1);
+ my_decimal *val2= (*b)->val_decimal(&decimal2);
if ((*a)->null_value || (*b)->null_value)
return test((*a)->null_value && (*b)->null_value);
return test(my_decimal_cmp(val1, val2) == 0);
@@ -5403,11 +5412,11 @@ void Item_equal::merge(Item_equal *item)
members follow in a wrong order they are swapped. This is performed
again and again until we get all members in a right order.
- @param cmp function to compare field item
+ @param compare function to compare field item
@param arg context extra parameter for the cmp function
*/
-void Item_equal::sort(Item_field_cmpfunc cmp, void *arg)
+void Item_equal::sort(Item_field_cmpfunc compare, void *arg)
{
bool swap;
List_iterator<Item_field> it(fields);
@@ -5421,7 +5430,7 @@ void Item_equal::sort(Item_field_cmpfunc cmp, void *arg)
while ((item2= it++))
{
Item_field **ref2= it.ref();
- if (cmp(item1, item2, arg) < 0)
+ if (compare(item1, item2, arg) < 0)
{
Item_field *item= *ref1;
*ref1= *ref2;
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 3232a77ac3e..767bc0a2b0f 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -1,7 +1,7 @@
#ifndef ITEM_CMPFUNC_INCLUDED
#define ITEM_CMPFUNC_INCLUDED
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1624,7 +1624,7 @@ public:
longlong val_int();
const char *func_name() const { return "multiple equal"; }
optimize_type select_optimize() const { return OPTIMIZE_EQUAL; }
- void sort(Item_field_cmpfunc cmp, void *arg);
+ void sort(Item_field_cmpfunc compare, void *arg);
friend class Item_equal_iterator;
void fix_length_and_dec();
bool fix_fields(THD *thd, Item **ref);
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 5277e2c7b1d..89a7fbd696d 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@
class Create_native_func : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
Builder method, with no arguments.
@@ -69,7 +69,7 @@ protected:
class Create_func_arg0 : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
Builder method, with no arguments.
@@ -93,7 +93,7 @@ protected:
class Create_func_arg1 : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
Builder method, with one argument.
@@ -118,7 +118,7 @@ protected:
class Create_func_arg2 : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
Builder method, with two arguments.
@@ -144,7 +144,7 @@ protected:
class Create_func_arg3 : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
Builder method, with three arguments.
@@ -194,7 +194,7 @@ protected:
class Create_func_no_geom : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/** Singleton. */
static Create_func_no_geom s_singleton;
@@ -2327,7 +2327,7 @@ static bool has_named_parameters(List<Item> *params)
Create_func_no_geom Create_func_no_geom::s_singleton;
Item*
-Create_func_no_geom::create(THD * /* unused */,
+Create_func_no_geom::create_func(THD * /* unused */,
LEX_STRING /* unused */,
List<Item> * /* unused */)
{
@@ -2340,7 +2340,7 @@ Create_func_no_geom::create(THD * /* unused */,
Item*
-Create_qfunc::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_qfunc::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
LEX_STRING db;
@@ -2373,7 +2373,7 @@ Create_qfunc::create(THD *thd, LEX_STRING name, List<Item> *item_list)
Create_udf_func Create_udf_func::s_singleton;
Item*
-Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_udf_func::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
udf_func *udf= find_udf(name.str, name.length);
DBUG_ASSERT(udf);
@@ -2525,7 +2525,7 @@ Create_sp_func::create(THD *thd, LEX_STRING db, LEX_STRING name,
Item*
-Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_native_func::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
if (has_named_parameters(item_list))
{
@@ -2538,7 +2538,7 @@ Create_native_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
Item*
-Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_func_arg0::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
int arg_count= 0;
@@ -2556,7 +2556,7 @@ Create_func_arg0::create(THD *thd, LEX_STRING name, List<Item> *item_list)
Item*
-Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_func_arg1::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
int arg_count= 0;
@@ -2582,7 +2582,7 @@ Create_func_arg1::create(THD *thd, LEX_STRING name, List<Item> *item_list)
Item*
-Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_func_arg2::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
int arg_count= 0;
@@ -2610,7 +2610,7 @@ Create_func_arg2::create(THD *thd, LEX_STRING name, List<Item> *item_list)
Item*
-Create_func_arg3::create(THD *thd, LEX_STRING name, List<Item> *item_list)
+Create_func_arg3::create_func(THD *thd, LEX_STRING name, List<Item> *item_list)
{
int arg_count= 0;
diff --git a/sql/item_create.h b/sql/item_create.h
index a3ba6bd26a6..d84c764a3d9 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -53,7 +53,7 @@ public:
@param item_list The list of arguments to the function, can be NULL
@return An item representing the parsed function call, or NULL
*/
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list) = 0;
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list) = 0;
protected:
/** Constructor */
@@ -80,7 +80,7 @@ public:
@param item_list The list of arguments to the function, can be NULL
@return An item representing the parsed function call
*/
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
The builder create method, for qualified functions.
@@ -127,7 +127,7 @@ extern Create_qfunc * find_qualified_function_builder(THD *thd);
class Create_udf_func : public Create_func
{
public:
- virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
+ virtual Item *create_func(THD *thd, LEX_STRING name, List<Item> *item_list);
/**
The builder create method, for User Defined Functions.
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 1616acff942..2c0d90642b4 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -3656,80 +3656,6 @@ longlong Item_master_pos_wait::val_int()
return event_count;
}
-#ifdef EXTRA_DEBUG
-void debug_sync_point(const char* lock_name, uint lock_timeout)
-{
- THD* thd=current_thd;
- User_level_lock* ull;
- struct timespec abstime;
- size_t lock_name_len;
- lock_name_len= strlen(lock_name);
- mysql_mutex_lock(&LOCK_user_locks);
-
- if (thd->ull)
- {
- item_user_lock_release(thd->ull);
- thd->ull=0;
- }
-
- /*
- If the lock has not been aquired by some client, we do not want to
- create an entry for it, since we immediately release the lock. In
- this case, we will not be waiting, but rather, just waste CPU and
- memory on the whole deal
- */
- if (!(ull= ((User_level_lock*) my_hash_search(&hash_user_locks,
- (uchar*) lock_name,
- lock_name_len))))
- {
- mysql_mutex_unlock(&LOCK_user_locks);
- return;
- }
- ull->count++;
-
- /*
- Structure is now initialized. Try to get the lock.
- Set up control struct to allow others to abort locks
- */
- thd_proc_info(thd, "User lock");
- thd->mysys_var->current_mutex= &LOCK_user_locks;
- thd->mysys_var->current_cond= &ull->cond;
-
- set_timespec(abstime,lock_timeout);
- while (ull->locked && !thd->killed)
- {
- int error= mysql_cond_timedwait(&ull->cond, &LOCK_user_locks, &abstime);
- if (error == ETIMEDOUT || error == ETIME)
- break;
- }
-
- if (ull->locked)
- {
- if (!--ull->count)
- delete ull; // Should never happen
- }
- else
- {
- ull->locked=1;
- ull->set_thread(thd);
- thd->ull=ull;
- }
- mysql_mutex_unlock(&LOCK_user_locks);
- mysql_mutex_lock(&thd->mysys_var->mutex);
- thd_proc_info(thd, 0);
- thd->mysys_var->current_mutex= 0;
- thd->mysys_var->current_cond= 0;
- mysql_mutex_unlock(&thd->mysys_var->mutex);
- mysql_mutex_lock(&LOCK_user_locks);
- if (thd->ull)
- {
- item_user_lock_release(thd->ull);
- thd->ull=0;
- }
- mysql_mutex_unlock(&LOCK_user_locks);
-}
-
-#endif
/**
diff --git a/sql/item_row.cc b/sql/item_row.cc
index 29b37eb2bc0..7535c1fa80b 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -30,7 +30,8 @@
*/
Item_row::Item_row(List<Item> &arg):
- Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
+ Item(), used_tables_cache(0), not_null_tables_cache(0),
+ const_item_cache(1), with_null(0)
{
//TODO: think placing 2-3 component items in item (as it done for function)
@@ -71,6 +72,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref)
Item *item= *arg;
used_tables_cache |= item->used_tables();
const_item_cache&= item->const_item() && !with_null;
+ not_null_tables_cache|= item->not_null_tables();
/*
Some subqueries transformations aren't done in the view_prepare_mode thus
is_null() will fail. So we skip is_null() calculation for CREATE VIEW as
diff --git a/sql/item_row.h b/sql/item_row.h
index 7c08c5888e0..87988e718ca 100644
--- a/sql/item_row.h
+++ b/sql/item_row.h
@@ -19,7 +19,7 @@
class Item_row: public Item
{
Item **items;
- table_map used_tables_cache;
+ table_map used_tables_cache, not_null_tables_cache;
uint arg_count;
bool const_item_cache;
bool with_null;
@@ -29,6 +29,7 @@ public:
Item(),
items(item->items),
used_tables_cache(item->used_tables_cache),
+ not_null_tables_cache(0),
arg_count(item->arg_count),
const_item_cache(item->const_item_cache),
with_null(0)
@@ -68,6 +69,7 @@ public:
bool const_item() const { return const_item_cache; };
enum Item_result result_type() const { return ROW_RESULT; }
void update_used_tables();
+ table_map not_null_tables() const { return not_null_tables_cache; }
virtual void print(String *str, enum_query_type query_type);
bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 267a4b38450..83e1f9b0625 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -249,9 +249,13 @@ bool Item_subselect::exec()
{
int res;
- if (thd->is_error())
- /* Do not execute subselect in case of a fatal error */
+ /*
+ Do not execute subselect in case of a fatal error
+ or if the query has been killed.
+ */
+ if (thd->is_error() || thd->killed)
return 1;
+
/*
Simulate a failure in sub-query execution. Used to test e.g.
out of memory or query being killed conditions.
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index cb0fd82bd54..ce39fd245be 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1176,7 +1176,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
default:
DBUG_ASSERT(0);
};
- setup(args[0], NULL);
+ setup_hybrid(args[0], NULL);
/* MIN/MAX can return NULL for empty set indepedent of the used column */
maybe_null= 1;
unsigned_flag=item->unsigned_flag;
@@ -1210,7 +1210,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
of the original MIN/MAX object and it is saved in this object's cache.
*/
-void Item_sum_hybrid::setup(Item *item, Item *value_arg)
+void Item_sum_hybrid::setup_hybrid(Item *item, Item *value_arg)
{
value= Item_cache::get_cache(item);
value->setup(item);
@@ -1972,7 +1972,7 @@ void Item_sum_hybrid::no_rows_in_result()
Item *Item_sum_min::copy_or_same(THD* thd)
{
Item_sum_min *item= new (thd->mem_root) Item_sum_min(thd, this);
- item->setup(args[0], value);
+ item->setup_hybrid(args[0], value);
return item;
}
@@ -1995,7 +1995,7 @@ bool Item_sum_min::add()
Item *Item_sum_max::copy_or_same(THD* thd)
{
Item_sum_max *item= new (thd->mem_root) Item_sum_max(thd, this);
- item->setup(args[0], value);
+ item->setup_hybrid(args[0], value);
return item;
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 26f0a08096e..65f64520156 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -1,7 +1,7 @@
#ifndef ITEM_SUM_INCLUDED
#define ITEM_SUM_INCLUDED
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -987,7 +987,7 @@ protected:
was_values(item->was_values)
{ }
bool fix_fields(THD *, Item **);
- void setup(Item *item, Item *value_arg);
+ void setup_hybrid(Item *item, Item *value_arg);
void clear();
double val_real();
longlong val_int();
diff --git a/sql/log.cc b/sql/log.cc
index 279782d271b..225fc51ffc6 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -4993,7 +4993,7 @@ int query_error_code(THD *thd, bool not_killed)
{
int error;
- if (not_killed)
+ if (not_killed || (thd->killed == THD::KILL_BAD_DATA))
{
error= thd->is_error() ? thd->stmt_da->sql_errno() : 0;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 6412f0047d1..fe86e78f7e3 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -9638,7 +9638,7 @@ Incident_log_event::write_data_body(IO_CACHE *file)
they will always be printed for the first event.
*/
st_print_event_info::st_print_event_info()
- :flags2_inited(0), sql_mode_inited(0),
+ :flags2_inited(0), sql_mode_inited(0), sql_mode(0),
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
lc_time_names_number(~0),
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc
index e87c3688cac..c55aaa2b0fb 100644
--- a/sql/log_event_old.cc
+++ b/sql/log_event_old.cc
@@ -16,7 +16,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
{
DBUG_ENTER("Old_rows_log_event::do_apply_event(st_relay_log_info*)");
int error= 0;
- THD *thd= ev->thd;
+ THD *ev_thd= ev->thd;
uchar const *row_start= ev->m_rows_buf;
/*
@@ -33,17 +33,17 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
*/
DBUG_ASSERT(ev->get_flags(Old_rows_log_event::STMT_END_F));
- const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd);
- thd->clear_error();
+ const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(ev_thd);
+ ev_thd->clear_error();
DBUG_RETURN(0);
}
/*
- 'thd' has been set by exec_relay_log_event(), just before calling
+ 'ev_thd' has been set by exec_relay_log_event(), just before calling
do_apply_event(). We still check here to prevent future coding
errors.
*/
- DBUG_ASSERT(rli->sql_thd == thd);
+ DBUG_ASSERT(rli->sql_thd == ev_thd);
/*
If there is no locks taken, this is the first binrow event seen
@@ -51,10 +51,10 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
used in the transaction and proceed with execution of the actual
event.
*/
- if (!thd->lock)
+ if (!ev_thd->lock)
{
/*
- Lock_tables() reads the contents of thd->lex, so they must be
+ Lock_tables() reads the contents of ev_thd->lex, so they must be
initialized.
We also call the mysql_reset_thd_for_next_command(), since this
@@ -62,8 +62,8 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
call might reset the value of current_stmt_binlog_format, so
we need to do any changes to that value after this function.
*/
- lex_start(thd);
- mysql_reset_thd_for_next_command(thd);
+ lex_start(ev_thd);
+ mysql_reset_thd_for_next_command(ev_thd);
/*
This is a row injection, so we flag the "statement" as
@@ -71,12 +71,12 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
injections and when the BINLOG statement is used to do row
injections.
*/
- thd->lex->set_stmt_row_injection();
+ ev_thd->lex->set_stmt_row_injection();
- if (open_and_lock_tables(thd, rli->tables_to_lock, FALSE, 0))
+ if (open_and_lock_tables(ev_thd, rli->tables_to_lock, FALSE, 0))
{
- uint actual_error= thd->stmt_da->sql_errno();
- if (thd->is_slave_error || thd->is_fatal_error)
+ uint actual_error= ev_thd->stmt_da->sql_errno();
+ if (ev_thd->is_slave_error || ev_thd->is_fatal_error)
{
/*
Error reporting borrowed from Query_log_event with many excessive
@@ -84,9 +84,9 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
*/
rli->report(ERROR_LEVEL, actual_error,
"Error '%s' on opening tables",
- (actual_error ? thd->stmt_da->message() :
+ (actual_error ? ev_thd->stmt_da->message() :
"unexpected success or fatal error"));
- thd->is_slave_error= 1;
+ ev_thd->is_slave_error= 1;
}
const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd);
DBUG_RETURN(actual_error);
@@ -108,8 +108,8 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli),
ptr->table, &conv_table))
{
- thd->is_slave_error= 1;
- const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd);
+ ev_thd->is_slave_error= 1;
+ const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(ev_thd);
DBUG_RETURN(Old_rows_log_event::ERR_BAD_TABLE_DEF);
}
DBUG_PRINT("debug", ("Table: %s.%s is compatible with master"
@@ -161,23 +161,23 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
TIMESTAMP column to a table with one.
So we call set_time(), like in SBR. Presently it changes nothing.
*/
- thd->set_time((time_t)ev->when);
+ ev_thd->set_time((time_t)ev->when);
/*
There are a few flags that are replicated with each row event.
Make sure to set/clear them before executing the main body of
the event.
*/
if (ev->get_flags(Old_rows_log_event::NO_FOREIGN_KEY_CHECKS_F))
- thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS;
+ ev_thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS;
else
- thd->variables.option_bits&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
+ ev_thd->variables.option_bits&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
if (ev->get_flags(Old_rows_log_event::RELAXED_UNIQUE_CHECKS_F))
- thd->variables.option_bits|= OPTION_RELAXED_UNIQUE_CHECKS;
+ ev_thd->variables.option_bits|= OPTION_RELAXED_UNIQUE_CHECKS;
else
- thd->variables.option_bits&= ~OPTION_RELAXED_UNIQUE_CHECKS;
+ ev_thd->variables.option_bits&= ~OPTION_RELAXED_UNIQUE_CHECKS;
/* A small test to verify that objects have consistent types */
- DBUG_ASSERT(sizeof(thd->variables.option_bits) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
+ DBUG_ASSERT(sizeof(ev_thd->variables.option_bits) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
/*
Now we are in a statement and will stay in a statement until we
@@ -194,7 +194,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
while (error == 0 && row_start < ev->m_rows_end)
{
uchar const *row_end= NULL;
- if ((error= do_prepare_row(thd, rli, table, row_start, &row_end)))
+ if ((error= do_prepare_row(ev_thd, rli, table, row_start, &row_end)))
break; // We should perform the after-row operation even in
// the case of error
@@ -204,7 +204,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
/* in_use can have been set to NULL in close_tables_for_reopen */
THD* old_thd= table->in_use;
if (!table->in_use)
- table->in_use= thd;
+ table->in_use= ev_thd;
error= do_exec_row(table);
table->in_use = old_thd;
switch (error)
@@ -218,10 +218,10 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
break;
default:
- rli->report(ERROR_LEVEL, thd->stmt_da->sql_errno(),
+ rli->report(ERROR_LEVEL, ev_thd->stmt_da->sql_errno(),
"Error in %s event: row application failed. %s",
ev->get_type_str(),
- thd->is_error() ? thd->stmt_da->message() : "");
+ ev_thd->is_error() ? ev_thd->stmt_da->message() : "");
thd->is_slave_error= 1;
break;
}
@@ -234,18 +234,18 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
if (!ev->use_trans_cache())
{
DBUG_PRINT("info", ("Marked that we need to keep log"));
- thd->variables.option_bits|= OPTION_KEEP_LOG;
+ ev_thd->variables.option_bits|= OPTION_KEEP_LOG;
}
}
if (error)
{ /* error has occured during the transaction */
- rli->report(ERROR_LEVEL, thd->stmt_da->sql_errno(),
+ rli->report(ERROR_LEVEL, ev_thd->stmt_da->sql_errno(),
"Error in %s event: error during transaction execution "
"on table %s.%s. %s",
ev->get_type_str(), table->s->db.str,
table->s->table_name.str,
- thd->is_error() ? thd->stmt_da->message() : "");
+ ev_thd->is_error() ? ev_thd->stmt_da->message() : "");
/*
If one day we honour --skip-slave-errors in row-based replication, and
@@ -258,9 +258,9 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
thread is certainly going to stop.
rollback at the caller along with sbr.
*/
- thd->reset_current_stmt_binlog_format_row();
- const_cast<Relay_log_info*>(rli)->cleanup_context(thd, error);
- thd->is_slave_error= 1;
+ ev_thd->reset_current_stmt_binlog_format_row();
+ const_cast<Relay_log_info*>(rli)->cleanup_context(ev_thd, error);
+ ev_thd->is_slave_error= 1;
DBUG_RETURN(error);
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index b398baa064e..6b77c95c76f 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -671,20 +671,6 @@ protected:
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
#define UNDEF_POS (-1)
-#ifdef EXTRA_DEBUG
-/**
- Sync points allow us to force the server to reach a certain line of code
- and block there until the client tells the server it is ok to go on.
- The client tells the server to block with SELECT GET_LOCK()
- and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
- concurrency problems
-*/
-#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
- debug_sync_point(lock_name,lock_timeout)
-void debug_sync_point(const char* lock_name, uint lock_timeout);
-#else
-#define DBUG_SYNC_POINT(lock_name,lock_timeout)
-#endif /* EXTRA_DEBUG */
/* BINLOG_DUMP options */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 37713992a90..22aa91e7fc4 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1456,6 +1456,7 @@ void clean_up(bool print_message)
item_user_lock_free();
lex_free(); /* Free some memory */
item_create_cleanup();
+ free_charsets();
if (!opt_noacl)
{
#ifdef HAVE_DLOPEN
@@ -6123,7 +6124,10 @@ thread is in the master's binlogs.",
"Tells the slave thread to not replicate to the specified database. To specify more than one database to ignore, use the directive multiple times, once for each database. This option will not work if you use cross database updates. If you need cross database updates to work, make sure you have 3.23.28 or later, and use replicate-wild-ignore-table=db_name.%. ",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE,
- "Tells the slave thread to not replicate to the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. This will work for cross-datbase updates, in contrast to replicate-ignore-db.",
+ "Tells the slave thread to not replicate to the specified table. To specify "
+ "more than one table to ignore, use the directive multiple times, once for "
+ "each table. This will work for cross-database updates, in contrast to "
+ "replicate-ignore-db.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB,
"Updates to a database with a different name than the original. Example: replicate-rewrite-db=master_db_name->slave_db_name.",
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index ae54a462c67..5384c165d65 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
@@ -96,7 +96,7 @@ static ulonglong get_exact_record_count(TABLE_LIST *tables)
@param conds WHERE clause
@note
- This function is only called for queries with sum functions and no
+ This function is only called for queries with aggregate functions and no
GROUP BY part. This means that the result set shall contain a single
row only
@@ -563,31 +563,57 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order)
/**
Check whether a condition matches a key to get {MAX|MIN}(field):.
- For the index specified by the keyinfo parameter, index that
- contains field as its component (field_part), the function
- checks whether the condition cond is a conjunction and all its
- conjuncts referring to the columns of the same table as column
- field are one of the following forms:
- - f_i= const_i or const_i= f_i or f_i is null,
- where f_i is part of the index
- - field {<|<=|>=|>|=} const or const {<|<=|>=|>|=} field
- - field between const1 and const2
-
- @param[in] max_fl Set to 1 if we are optimising MAX()
- @param[in,out] ref Reference to the structure we store the key
- value
- @param[in] keyinfo Reference to the key info
- @param[in] field_part Pointer to the key part for the field
- @param[in] cond WHERE condition
- @param[in,out] key_part_used Map of matchings parts
- @param[in,out] range_fl Says whether including key will be used
- @param[out] prefix_len Length of common key part for the range
- where MAX/MIN is searched for
+ For the index specified by the keyinfo parameter and an index that
+ contains the field as its component (field_part), the function
+ checks whether
+
+ - the condition cond is a conjunction,
+ - all of its conjuncts refer to columns of the same table, and
+ - each conjunct is on one of the following forms:
+ - f_i = const_i or const_i = f_i or f_i IS NULL,
+ where f_i is part of the index
+ - field {<|<=|>=|>|=} const
+ - const {<|<=|>=|>|=} field
+ - field BETWEEN const_1 AND const_2
+
+ As a side-effect, the key value to be used for looking up the MIN/MAX value
+ is actually stored inside the Field object. An interesting feature is that
+ the function will find the most restrictive endpoint by over-eager
+ evaluation of the @c WHERE condition. It continually stores the current
+ endpoint inside the Field object. For a query such as
+
+ @code
+ SELECT MIN(a) FROM t1 WHERE a > 3 AND a > 5;
+ @endcode
+
+ the algorithm will recurse over the conjuction, storing first a 3 in the
+ field. In the next recursive invocation the expression a > 5 is evaluated
+ as 3 > 5 (Due to the dual nature of Field objects as value carriers and
+ field identifiers), which will obviously fail, leading to 5 being stored in
+ the Field object.
+
+ @param[in] max_fl Set to true if we are optimizing MAX(),
+ false means we are optimizing %MIN()
+ @param[in, out] ref Reference to the structure where the function
+ stores the key value
+ @param[in] keyinfo Reference to the key info
+ @param[in] field_part Pointer to the key part for the field
+ @param[in] cond WHERE condition
+ @param[in,out] key_part_used Map of matchings parts. The function will output
+ the set of key parts actually being matched in
+ this set, yet it relies on the caller to
+ initialize the value to zero. This is due
+ to the fact that this value is passed
+ recursively.
+ @param[in,out] range_fl Says whether endpoints use strict greater/less
+ than.
+ @param[out] prefix_len Length of common key part for the range
+ where MAX/MIN is searched for
@retval
- 0 Index can't be used.
+ false Index can't be used.
@retval
- 1 We can use index to get MIN/MAX value
+ true We can use the index to get MIN/MAX value
*/
static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
@@ -624,17 +650,20 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
return 0; // Not operator, can't optimize
bool eq_type= 0; // =, <=> or IS NULL
+ bool is_null_safe_eq= FALSE; // The operator is NULL safe, e.g. <=>
bool noeq_type= 0; // < or >
bool less_fl= 0; // < or <=
- bool is_null= 0;
- bool between= 0;
+ bool is_null= 0; // IS NULL
+ bool between= 0; // BETWEEN ... AND ...
switch (((Item_func*) cond)->functype()) {
case Item_func::ISNULL_FUNC:
is_null= 1; /* fall through */
case Item_func::EQ_FUNC:
+ eq_type= TRUE;
+ break;
case Item_func::EQUAL_FUNC:
- eq_type= 1;
+ eq_type= is_null_safe_eq= TRUE;
break;
case Item_func::LT_FUNC:
noeq_type= 1; /* fall through */
@@ -662,6 +691,10 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
if (!simple_pred((Item_func*) cond, args, &inv))
return 0;
+ if (!is_null_safe_eq && !is_null &&
+ (args[1]->is_null() || (between && args[2]->is_null())))
+ return FALSE;
+
if (inv && !eq_type)
less_fl= 1-less_fl; // Convert '<' -> '>' (etc)
@@ -712,15 +745,16 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo,
- field {>|>=} const, when searching for MIN
*/
- if (is_null)
+ if (is_null || (is_null_safe_eq && args[1]->is_null()))
{
part->field->set_null();
*key_ptr= (uchar) 1;
}
else
{
- store_val_in_field(part->field, args[between && max_fl ? 2 : 1],
- CHECK_FIELD_IGNORE);
+ /* Update endpoints for MAX/MIN, see function comment. */
+ Item *value= args[between && max_fl ? 2 : 1];
+ store_val_in_field(part->field, value, CHECK_FIELD_IGNORE);
if (part->null_bit)
*key_ptr++= (uchar) test(part->field->is_null());
part->field->get_key_image(key_ptr, part->length, Field::itRAW);
diff --git a/sql/protocol.cc b/sql/protocol.cc
index fd943c98bd6..a8cf250689e 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -648,8 +648,7 @@ void Protocol::init(THD *thd_arg)
void Protocol::end_partial_result_set(THD *thd_arg)
{
- net_send_eof(thd_arg, thd_arg->server_status,
- 0 /* no warnings, we're inside SP */);
+ net_send_eof(thd_arg, thd_arg->server_status, 0 /* no warnings, we're inside SP */);
}
diff --git a/sql/share/Makefile.am b/sql/share/Makefile.am
index cd4f7a83279..03f9a1652b7 100644
--- a/sql/share/Makefile.am
+++ b/sql/share/Makefile.am
@@ -17,13 +17,13 @@
EXTRA_DIST= errmsg-utf8.txt \
CMakeLists.txt
-
+
dist-hook:
for dir in charsets @AVAILABLE_LANGUAGES@; do \
test -d $(distdir)/$$dir || mkdir $(distdir)/$$dir; \
$(INSTALL_DATA) $(srcdir)/$$dir/*.* $(distdir)/$$dir; \
done; \
- sleep 1 ; touch $(builddir)/*/errmsg.sys
+ sleep 1 ; touch $(srcdir)/*/errmsg.sys
$(INSTALL_DATA) $(srcdir)/charsets/README $(distdir)/charsets
$(INSTALL_DATA) $(srcdir)/charsets/Index.xml $(distdir)/charsets
@@ -40,12 +40,12 @@ install-data-local:
for lang in @AVAILABLE_LANGUAGES@; \
do \
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/$$lang; \
- $(INSTALL_DATA) $(builddir)/$$lang/errmsg.sys \
+ $(INSTALL_DATA) $(srcdir)/$$lang/errmsg.sys \
$(DESTDIR)$(pkgdatadir)/$$lang/errmsg.sys; \
done
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/charsets
- $(INSTALL_DATA) $(builddir)/errmsg-utf8.txt \
- $(DESTDIR)$(pkgdatadir)/errmsg-utf8.txt; \
+ $(INSTALL_DATA) $(srcdir)/errmsg-utf8.txt \
+ $(DESTDIR)$(pkgdatadir)/errmsg-utf8.txt; \
$(INSTALL_DATA) $(srcdir)/charsets/README $(DESTDIR)$(pkgdatadir)/charsets/README
$(INSTALL_DATA) $(srcdir)/charsets/*.xml $(DESTDIR)$(pkgdatadir)/charsets
@@ -54,7 +54,7 @@ uninstall-local:
@RM@ -f -r $(DESTDIR)$(pkgdatadir)
distclean-local:
- @RM@ -f $(builddir)/*/errmsg.sys
+ @RM@ -f */errmsg.sys
# Do nothing
link_sources:
diff --git a/sql/slave.cc b/sql/slave.cc
index 2f06d468d64..b0bb1d5882b 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -46,6 +46,7 @@
#ifdef HAVE_REPLICATION
#include "rpl_tblmap.h"
+#include "debug_sync.h"
#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
@@ -1269,7 +1270,16 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
unavailable (very old master not supporting UNIX_TIMESTAMP()?).
*/
- DBUG_SYNC_POINT("debug_lock.before_get_UNIX_TIMESTAMP", 10);
+ DBUG_EXECUTE_IF("dbug.before_get_UNIX_TIMESTAMP",
+ {
+ const char act[]=
+ "now "
+ "wait_for signal.get_unix_timestamp";
+ DBUG_ASSERT(opt_debug_sync_timeout > 0);
+ DBUG_ASSERT(!debug_sync_set_action(current_thd,
+ STRING_WITH_LEN(act)));
+ };);
+
master_res= NULL;
if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) &&
(master_res= mysql_store_result(mysql)) &&
@@ -1310,7 +1320,15 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
Note: we could have put a @@SERVER_ID in the previous SELECT
UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters.
*/
- DBUG_SYNC_POINT("debug_lock.before_get_SERVER_ID", 10);
+ DBUG_EXECUTE_IF("dbug.before_get_SERVER_ID",
+ {
+ const char act[]=
+ "now "
+ "wait_for signal.get_server_id";
+ DBUG_ASSERT(opt_debug_sync_timeout > 0);
+ DBUG_ASSERT(!debug_sync_set_action(current_thd,
+ STRING_WITH_LEN(act)));
+ };);
master_res= NULL;
master_row= NULL;
if (!mysql_real_query(mysql,
@@ -2763,6 +2781,16 @@ pthread_handler_t handle_slave_io(void *arg)
connected:
+ DBUG_EXECUTE_IF("dbug.before_get_running_status_yes",
+ {
+ const char act[]=
+ "now "
+ "wait_for signal.io_thread_let_running";
+ DBUG_ASSERT(opt_debug_sync_timeout > 0);
+ DBUG_ASSERT(!debug_sync_set_action(thd,
+ STRING_WITH_LEN(act)));
+ };);
+
// TODO: the assignment below should be under mutex (5.0)
mi->slave_running= MYSQL_SLAVE_RUN_CONNECT;
thd->slave_net = &mysql->net;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index a85a863abd9..651787a7969 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1675,6 +1675,7 @@ void close_temporary_tables(THD *thd)
{
if (is_user_table(table))
{
+ bool save_thread_specific_used= thd->thread_specific_used;
my_thread_id save_pseudo_thread_id= thd->variables.pseudo_thread_id;
/* Set pseudo_thread_id to be that of the processed table */
thd->variables.pseudo_thread_id= tmpkeyval(thd, table);
@@ -1704,6 +1705,7 @@ void close_temporary_tables(THD *thd)
thd->clear_error();
CHARSET_INFO *cs_save= thd->variables.character_set_client;
thd->variables.character_set_client= system_charset_info;
+ thd->thread_specific_used= TRUE;
Query_log_event qinfo(thd, s_query.ptr(),
s_query.length() - 1 /* to remove trailing ',' */,
FALSE, TRUE, FALSE, 0);
@@ -1716,6 +1718,7 @@ void close_temporary_tables(THD *thd)
"Failed to write the DROP statement for temporary tables to binary log");
}
thd->variables.pseudo_thread_id= save_pseudo_thread_id;
+ thd->thread_specific_used= save_thread_specific_used;
}
else
{
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 2c3242c10cd..58073a40319 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -51,6 +51,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
SELECT_LEX *select_lex= &thd->lex->select_lex;
THD::killed_state killed_status= THD::NOT_KILLED;
DBUG_ENTER("mysql_delete");
+ bool save_binlog_row_based;
THD::enum_binlog_query_type query_type=
thd->lex->sql_command == SQLCOM_TRUNCATE ?
@@ -148,12 +149,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
query_type= THD::STMT_QUERY_TYPE;
error= -1; // ok
deleted= maybe_deleted;
+ save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
goto cleanup;
}
if (error != HA_ERR_WRONG_COMMAND)
{
table->file->print_error(error,MYF(0));
error=0;
+ save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
goto cleanup;
}
/* Handler didn't support fast delete; Delete rows one by one */
@@ -294,6 +297,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
table->mark_columns_needed_for_delete();
+ save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
+ if (thd->lex->sql_command == SQLCOM_TRUNCATE &&
+ thd->is_current_stmt_binlog_format_row())
+ thd->clear_current_stmt_binlog_format_row();
+
while (!(error=info.read_record(&info)) && !thd->killed &&
! thd->is_error())
{
@@ -392,7 +400,10 @@ cleanup:
/* See similar binlogging code in sql_update.cc, for comments */
if ((error < 0) || thd->transaction.stmt.modified_non_trans_table)
{
- if (mysql_bin_log.is_open())
+ if (mysql_bin_log.is_open() &&
+ !(thd->lex->sql_command == SQLCOM_TRUNCATE &&
+ thd->is_current_stmt_binlog_format_row() &&
+ find_temporary_table(thd, table_list)))
{
bool const is_trans=
thd->lex->sql_command == SQLCOM_TRUNCATE ?
@@ -424,6 +435,8 @@ cleanup:
}
}
}
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table);
free_underlaid_joins(thd, select_lex);
if (error < 0 ||
@@ -1049,12 +1062,11 @@ bool multi_delete::send_eof()
static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list)
{
- bool error, save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
+ bool error;
DBUG_ENTER("mysql_truncate_by_delete");
table_list->lock_type= TL_WRITE;
table_list->mdl_request.set_type(MDL_SHARED_WRITE);
mysql_init_select(thd->lex);
- thd->clear_current_stmt_binlog_format_row();
/* Delete all rows from table */
error= mysql_delete(thd, table_list, NULL, NULL, HA_POS_ERROR, LL(0), TRUE);
/*
@@ -1067,8 +1079,6 @@ static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list)
trans_rollback_stmt(thd);
trans_rollback(thd);
}
- if (save_binlog_row_based)
- thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(error);
}
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index cfb57475b68..490ef4e9e27 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -3359,6 +3359,7 @@ int get_partition_id_range(partition_info *part_info,
*func_value= part_func_value;
if (unsigned_flag)
part_func_value-= 0x8000000000000000ULL;
+ /* Search for the partition containing part_func_value */
while (max_part_id > min_part_id)
{
loc_part_id= (max_part_id + min_part_id) / 2;
@@ -3498,11 +3499,17 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
part_end_val= range_array[loc_part_id];
if (left_endpoint)
{
+ DBUG_ASSERT(part_func_value > part_end_val ?
+ (loc_part_id == max_partition &&
+ !part_info->defined_max_value) :
+ 1);
/*
In case of PARTITION p VALUES LESS THAN MAXVALUE
- the maximum value is in the current partition.
+ the maximum value is in the current (last) partition.
+ If value is equal or greater than the endpoint,
+ the range starts from the next partition.
*/
- if (part_func_value == part_end_val &&
+ if (part_func_value >= part_end_val &&
(loc_part_id < max_partition || !part_info->defined_max_value))
loc_part_id++;
}
@@ -4536,6 +4543,12 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
{
DBUG_ENTER("prep_alter_part_table");
+ /* Foreign keys on partitioned tables are not supported, waits for WL#148 */
+ if (table->part_info && (alter_info->flags & ALTER_FOREIGN_KEY))
+ {
+ my_error(ER_FOREIGN_KEY_ON_PARTITIONED, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
/*
We are going to manipulate the partition info on the table object
so we need to ensure that the table instance is removed from the
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 3d1380d46f3..3ff5e91ccb6 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1817,6 +1817,9 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE);
+ if (check_table_access(thd, DELETE_ACL, &tables, FALSE, 1, FALSE))
+ DBUG_RETURN(TRUE);
+
/* need to open before acquiring LOCK_plugin or it will deadlock */
if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
DBUG_RETURN(TRUE);
diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc
index 74d7beede47..20c1b336f5c 100644
--- a/sql/sql_profile.cc
+++ b/sql/sql_profile.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007 MySQL AB
+/* Copyright (c) 2007, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -508,7 +508,7 @@ void PROFILING::set_query_source(char *query_source_arg, uint query_length_arg)
There are two ways to get to this function: Selecting from the information
schema, and a SHOW command.
*/
-int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
+int PROFILING::fill_statistics_info(THD *thd_arg, TABLE_LIST *tables, Item *cond)
{
DBUG_ENTER("PROFILING::fill_statistics_info");
TABLE *table= tables->table;
@@ -543,7 +543,7 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
/* Skip the first. We count spans of fence, not fence-posts. */
if (previous == NULL) continue;
- if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE)
+ if (thd_arg->lex->sql_command == SQLCOM_SHOW_PROFILE)
{
/*
We got here via a SHOW command. That means that we stored
@@ -556,14 +556,14 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
struct where and having conditions at the SQL layer, then this
condition should be ripped out.
*/
- if (thd->lex->profile_query_id == 0) /* 0 == show final query */
+ if (thd_arg->lex->profile_query_id == 0) /* 0 == show final query */
{
if (query != last)
continue;
}
else
{
- if (thd->lex->profile_query_id != query->profiling_query_id)
+ if (thd_arg->lex->profile_query_id != query->profiling_query_id)
continue;
}
}
@@ -701,7 +701,7 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
table->field[17]->set_notnull();
}
- if (schema_table_store_record(thd, table))
+ if (schema_table_store_record(thd_arg, table))
DBUG_RETURN(1);
}
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 510f9d8dc01..207f5994d5d 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -1994,7 +1994,6 @@ int log_loaded_block(IO_CACHE* file)
if (mysql_bin_log.write(&b))
DBUG_RETURN(1);
lf_info->wrote_create_file= 1;
- DBUG_SYNC_POINT("debug_lock.created_file_event",10);
}
}
DBUG_RETURN(0);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 099d1a87bfd..3a62396b880 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1116,6 +1116,31 @@ JOIN::optimize()
conds=new Item_int((longlong) 0,1); // Always false
}
+ /*
+ It's necessary to check const part of HAVING cond as
+ there is a chance that some cond parts may become
+ const items after make_join_statisctics(for example
+ when Item is a reference to cost table field from
+ outer join).
+ This check is performed only for those conditions
+ which do not use aggregate functions. In such case
+ temporary table may not be used and const condition
+ elements may be lost during further having
+ condition transformation in JOIN::exec.
+ */
+ if (having && !having->with_sum_func)
+ {
+ COND *const_cond= make_cond_for_table(having, const_table_map, 0);
+ DBUG_EXECUTE("where", print_where(const_cond, "const_having_cond",
+ QT_ORDINARY););
+ if (const_cond && !const_cond->val_int())
+ {
+ zero_result_cause= "Impossible HAVING noticed after reading const tables";
+ error= 0;
+ DBUG_RETURN(0);
+ }
+ }
+
/* Cache constant expressions in WHERE, HAVING, ON clauses. */
cache_const_exprs();
@@ -2964,7 +2989,8 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
s->quick=select->quick;
s->needed_reg=select->needed_reg;
select->quick=0;
- if (records == 0 && s->table->reginfo.impossible_range)
+ if (records == 0 && s->table->reginfo.impossible_range &&
+ (s->table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT))
{
/*
Impossible WHERE or ON expression
@@ -5946,7 +5972,7 @@ store_val_in_field(Field *field, Item *item, enum_check_fields check_flag)
@retval TRUE error occurred
*/
bool
-JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table)
+JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
{
DBUG_ENTER("JOIN::make_simple_join");
@@ -5959,7 +5985,7 @@ JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table)
DBUG_RETURN(TRUE); /* purecov: inspected */
join_tab= parent->join_tab_reexec;
- parent->table_reexec[0]= tmp_table;
+ parent->table_reexec[0]= temp_table;
tables= 1;
const_tables= 0;
const_table_map= 0;
@@ -5979,7 +6005,7 @@ JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table)
do_send_rows= row_limit ? 1 : 0;
join_tab->cache.buff=0; /* No caching */
- join_tab->table=tmp_table;
+ join_tab->table=temp_table;
join_tab->select=0;
join_tab->select_cond=0;
join_tab->quick=0;
@@ -5996,8 +6022,8 @@ JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table)
join_tab->join= this;
join_tab->ref.key_parts= 0;
bzero((char*) &join_tab->read_record,sizeof(join_tab->read_record));
- tmp_table->status=0;
- tmp_table->null_row=0;
+ temp_table->status=0;
+ temp_table->null_row=0;
DBUG_RETURN(FALSE);
}
@@ -13098,12 +13124,35 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
uint find_shortest_key(TABLE *table, const key_map *usable_keys)
{
- uint min_length= (uint) ~0;
uint best= MAX_KEY;
+ uint usable_clustered_pk= (table->file->primary_key_is_clustered() &&
+ table->s->primary_key != MAX_KEY &&
+ usable_keys->is_set(table->s->primary_key)) ?
+ table->s->primary_key : MAX_KEY;
if (!usable_keys->is_clear_all())
{
+ uint min_length= (uint) ~0;
for (uint nr=0; nr < table->s->keys ; nr++)
{
+ /*
+ As far as
+ 1) clustered primary key entry data set is a set of all record
+ fields (key fields and not key fields) and
+ 2) secondary index entry data is a union of its key fields and
+ primary key fields (at least InnoDB and its derivatives don't
+ duplicate primary key fields there, even if the primary and
+ the secondary keys have a common subset of key fields),
+ then secondary index entry data is always a subset of primary key
+ entry, and the PK is always longer.
+ Unfortunately, key_info[nr].key_length doesn't show the length
+ of key/pointer pair but a sum of key field lengths only, thus
+ we can't estimate index IO volume comparing only this key_length
+ value of seconday keys and clustered PK.
+ So, try secondary keys first, and choose PK only if there are no
+ usable secondary covering keys:
+ */
+ if (nr == usable_clustered_pk)
+ continue;
if (usable_keys->is_set(nr))
{
if (table->key_info[nr].key_length < min_length)
@@ -13114,7 +13163,7 @@ uint find_shortest_key(TABLE *table, const key_map *usable_keys)
}
}
}
- return best;
+ return best != MAX_KEY ? best : usable_clustered_pk;
}
/**
@@ -17150,7 +17199,17 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
first= 0;
else
str->append(',');
- item->print_item_w_name(str, query_type);
+
+ if (master_unit()->item && item->is_autogenerated_name)
+ {
+ /*
+ Do not print auto-generated aliases in subqueries. It has no purpose
+ in a view definition or other contexts where the query is printed.
+ */
+ item->print(str, query_type);
+ }
+ else
+ item->print_item_w_name(str, query_type);
}
/*
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 2a9e01daf18..393200a81db 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -5490,6 +5490,45 @@ err:
DBUG_RETURN(-1);
}
+/**
+ @brief Check if both DROP and CREATE are present for an index in ALTER TABLE
+
+ @details Checks if any index is being modified (present as both DROP INDEX
+ and ADD INDEX) in the current ALTER TABLE statement. Needed for disabling
+ online ALTER TABLE.
+
+ @param table The table being altered
+ @param alter_info The ALTER TABLE structure
+ @return presence of index being altered
+ @retval FALSE No such index
+ @retval TRUE Have at least 1 index modified
+*/
+
+static bool
+is_index_maintenance_unique (TABLE *table, Alter_info *alter_info)
+{
+ List_iterator<Key> key_it(alter_info->key_list);
+ List_iterator<Alter_drop> drop_it(alter_info->drop_list);
+ Key *key;
+
+ while ((key= key_it++))
+ {
+ if (key->name.str)
+ {
+ Alter_drop *drop;
+
+ drop_it.rewind();
+ while ((drop= drop_it++))
+ {
+ if (drop->type == Alter_drop::KEY &&
+ !my_strcasecmp(system_charset_info, key->name.str, drop->name))
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
/*
SYNOPSIS
@@ -5578,6 +5617,7 @@ compare_tables(TABLE *table,
*/
Alter_info tmp_alter_info(*alter_info, thd->mem_root);
uint db_options= 0; /* not used */
+
/* Create the prepared information. */
if (mysql_prepare_create_table(thd, create_info,
&tmp_alter_info,
@@ -6858,10 +6898,14 @@ view_err:
*/
new_db_type= create_info->db_type;
+ if (is_index_maintenance_unique (table, alter_info))
+ need_copy_table= ALTER_TABLE_DATA_CHANGED;
+
if (mysql_prepare_alter_table(thd, table, create_info, alter_info))
goto err;
-
- need_copy_table= alter_info->change_level;
+
+ if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
+ need_copy_table= alter_info->change_level;
set_table_default_charset(thd, create_info, db);
@@ -7950,22 +7994,28 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
for (uint i= 0; i < t->s->fields; i++ )
{
Field *f= t->field[i];
- enum_field_types field_type= f->type();
- /*
- BLOB and VARCHAR have pointers in their field, we must convert
- to string; GEOMETRY is implemented on top of BLOB.
- */
- if ((field_type == MYSQL_TYPE_BLOB) ||
- (field_type == MYSQL_TYPE_VARCHAR) ||
- (field_type == MYSQL_TYPE_GEOMETRY))
- {
- String tmp;
- f->val_str(&tmp);
- row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(), tmp.length());
+
+ /*
+ BLOB and VARCHAR have pointers in their field, we must convert
+ to string; GEOMETRY is implemented on top of BLOB.
+ BIT may store its data among NULL bits, convert as well.
+ */
+ switch (f->type()) {
+ case MYSQL_TYPE_BLOB:
+ case MYSQL_TYPE_VARCHAR:
+ case MYSQL_TYPE_GEOMETRY:
+ case MYSQL_TYPE_BIT:
+ {
+ String tmp;
+ f->val_str(&tmp);
+ row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(),
+ tmp.length());
+ break;
+ }
+ default:
+ row_crc= my_checksum(row_crc, f->ptr, f->pack_length());
+ break;
}
- else
- row_crc= my_checksum(row_crc, f->ptr,
- f->pack_length());
}
crc+= row_crc;
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 4438f1c37b5..2f40720c7ae 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -146,6 +146,35 @@ err:
DBUG_RETURN(TRUE);
}
+
+/**
+ Check if auto generated column names are conforming and
+ possibly generate a conforming name for them if not.
+
+ @param item_list List of Items which should be checked
+*/
+
+static void make_valid_column_names(List<Item> &item_list)
+{
+ Item *item;
+ uint name_len;
+ List_iterator_fast<Item> it(item_list);
+ char buff[NAME_LEN];
+ DBUG_ENTER("make_valid_column_names");
+
+ for (uint column_no= 1; (item= it++); column_no++)
+ {
+ if (!item->is_autogenerated_name || !check_column_name(item->name))
+ continue;
+ name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no);
+ item->orig_name= item->name;
+ item->set_name(buff, name_len, system_charset_info);
+ }
+
+ DBUG_VOID_RETURN;
+}
+
+
/*
Fill defined view parts
@@ -543,6 +572,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
}
}
+ /* Check if the auto generated column names are conforming. */
+ make_valid_column_names(select_lex->item_list);
+
if (check_duplicate_names(select_lex->item_list, 1))
{
res= TRUE;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 5648e3cbdb5..ea9605687d3 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
+/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -8562,7 +8562,7 @@ function_call_generic:
builder= find_native_function_builder(thd, $1);
if (builder)
{
- item= builder->create(thd, $1, $4);
+ item= builder->create_func(thd, $1, $4);
}
else
{
@@ -8584,7 +8584,7 @@ function_call_generic:
{
builder= find_qualified_function_builder(thd);
DBUG_ASSERT(builder);
- item= builder->create(thd, $1, $4);
+ item= builder->create_func(thd, $1, $4);
}
}
diff --git a/sql/table.cc b/sql/table.cc
index fa1186c2a45..94f3037a81b 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -4069,9 +4069,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
{
DBUG_RETURN(field);
}
- Item *item= new Item_direct_view_ref(&view->view->select_lex.context,
- field_ref, view->alias,
- name);
+ Item *item= new Item_direct_view_ref(view, field_ref, name);
DBUG_RETURN(item);
}