summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <jani@ua141d10.elisa.omakaista.fi>2007-04-12 12:50:02 +0300
committerunknown <jani@ua141d10.elisa.omakaista.fi>2007-04-12 12:50:02 +0300
commit239b385933864bff3694f95ccc9d0c645f6a0aad (patch)
tree30b412b9ebad3ddaa08bcf7eb478c89eeebc2ed2 /sql
parentc4879fe6dde9890496a6555e78fa9bde5e21f8f4 (diff)
parentd2667d1a6ebe7feeb8b80fcc5cfefac80ed729b0 (diff)
downloadmariadb-git-239b385933864bff3694f95ccc9d0c645f6a0aad.tar.gz
Merge jamppa@bk-internal.mysql.com:/home/bk/mysql-5.0
into ua141d10.elisa.omakaista.fi:/home/my/bk/mysql-5.0-marvel client/mysqldump.c: Auto merged mysql-test/t/sp.test: Auto merged mysys/my_malloc.c: Auto merged mysys/my_static.c: Auto merged mysys/safemalloc.c: Auto merged ndb/src/mgmclient/CommandInterpreter.cpp: Auto merged sql/ha_archive.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/handler.cc: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_func.h: Auto merged sql/log.cc: Auto merged sql/log_event.cc: Auto merged sql/mysql_priv.h: Auto merged sql-common/client.c: Auto merged sql/sp.cc: Auto merged sql/sp_head.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_update.cc: Auto merged sql/table.cc: Auto merged sql-common/my_time.c: Auto merged mysql-test/r/sp.result: Merged from main 5.0 sql/sql_load.cc: Merged from main 5.0
Diffstat (limited to 'sql')
-rw-r--r--sql/examples/ha_example.cc6
-rw-r--r--sql/field.cc368
-rw-r--r--sql/field.h7
-rw-r--r--sql/ha_archive.cc2
-rw-r--r--sql/ha_innodb.cc9
-rw-r--r--sql/ha_ndbcluster.cc73
-rw-r--r--sql/ha_ndbcluster.h2
-rw-r--r--sql/handler.cc8
-rw-r--r--sql/handler.h11
-rw-r--r--sql/item.h11
-rw-r--r--sql/item_cmpfunc.cc20
-rw-r--r--sql/item_cmpfunc.h1
-rw-r--r--sql/item_func.cc343
-rw-r--r--sql/item_func.h39
-rw-r--r--sql/item_strfunc.cc2
-rw-r--r--sql/item_sum.cc32
-rw-r--r--sql/log.cc96
-rw-r--r--sql/log_event.cc27
-rw-r--r--sql/mysql_priv.h2
-rw-r--r--sql/parse_file.cc15
-rw-r--r--sql/sp.cc2
-rw-r--r--sql/sp_head.cc6
-rw-r--r--sql/sp_head.h6
-rw-r--r--sql/spatial.h43
-rw-r--r--sql/sql_delete.cc24
-rw-r--r--sql/sql_insert.cc51
-rw-r--r--sql/sql_load.cc17
-rw-r--r--sql/sql_show.cc9
-rw-r--r--sql/sql_table.cc45
-rw-r--r--sql/sql_trigger.h5
-rw-r--r--sql/sql_update.cc26
-rw-r--r--sql/sql_yacc.yy11
32 files changed, 743 insertions, 576 deletions
diff --git a/sql/examples/ha_example.cc b/sql/examples/ha_example.cc
index 19c686ee495..d59ada3b445 100644
--- a/sql/examples/ha_example.cc
+++ b/sql/examples/ha_example.cc
@@ -211,6 +211,12 @@ ha_example::ha_example(TABLE *table_arg)
If frm_error() is called then we will use this to to find out what file extentions
exist for the storage engine. This is also used by the default rename_table and
delete_table method in handler.cc.
+
+ For engines that have two file name extentions (separate meta/index file
+ and data file), the order of elements is relevant. First element of engine
+ file name extentions array should be meta/index file extention. Second
+ element - data file extention. This order is assumed by
+ prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
*/
static const char *ha_example_exts[] = {
NullS
diff --git a/sql/field.cc b/sql/field.cc
index 152c1bdc364..635b10e0e5e 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -964,6 +964,31 @@ static Item_result field_types_result_type [FIELDTYPE_NUM]=
/*
+ Test if the given string contains important data:
+ not spaces for character string,
+ or any data for binary string.
+
+ SYNOPSIS
+ test_if_important_data()
+ cs Character set
+ str String to test
+ strend String end
+
+ RETURN
+ FALSE - If string does not have important data
+ TRUE - If string has some important data
+*/
+
+static bool
+test_if_important_data(CHARSET_INFO *cs, const char *str, const char *strend)
+{
+ if (cs != &my_charset_bin)
+ str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
+ return (str < strend);
+}
+
+
+/*
Detect Item_result by given field type of UNION merge result
SYNOPSIS
@@ -1052,64 +1077,113 @@ void Field_num::prepend_zeros(String *value)
}
/*
- Test if given number is a int (or a fixed format float with .000)
+ Test if given number is a int.
SYNOPSIS
- test_if_int()
+ Field_num::check_int
+ cs Character set
str String to test
end Pointer to char after last used digit
- cs Character set
+ length String length
+ error Error returned by strntoull10rnd()
- NOTES
- This is called after one has called my_strntol() or similar function.
- This is only used to give warnings in ALTER TABLE or LOAD DATA...
-
- TODO
- Make this multi-byte-character safe
+ NOTE
+ This is called after one has called strntoull10rnd() function.
RETURN
- 0 OK
- 1 error. A warning is pushed if field_name != 0
+ 0 ok
+ 1 error: empty string or wrong integer.
+ 2 error: garbage at the end of string.
*/
-bool Field::check_int(const char *str, int length, const char *int_end,
- CHARSET_INFO *cs)
+int Field_num::check_int(CHARSET_INFO *cs, const char *str, int length,
+ const char *int_end, int error)
{
- const char *end;
- if (str == int_end)
+ /* Test if we get an empty string or wrong integer */
+ if (str == int_end || error == MY_ERRNO_EDOM)
{
char buff[128];
- String tmp(buff,(uint32) sizeof(buff), system_charset_info);
+ String tmp(buff, (uint32) sizeof(buff), system_charset_info);
tmp.copy(str, length, system_charset_info);
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
"integer", tmp.c_ptr(), field_name,
(ulong) table->in_use->row_count);
- return 1; // Empty string
+ return 1;
}
- end= str+length;
- if ((str= int_end) == end)
- return 0; // OK; All digits was used
+ /* Test if we have garbage at the end of the given string. */
+ if (test_if_important_data(cs, int_end, str + length))
+ {
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
+ return 2;
+ }
+ return 0;
+}
- /* Allow end .0000 */
- if (*str == '.')
+
+/*
+ Conver a string to an integer then check bounds.
+
+ SYNOPSIS
+ Field_num::get_int
+ cs Character set
+ from String to convert
+ len Length of the string
+ rnd OUT longlong value
+ unsigned_max max unsigned value
+ signed_min min signed value
+ signed_max max signed value
+
+ DESCRIPTION
+ The function calls strntoull10rnd() to get an integer value then
+ check bounds and errors returned. In case of any error a warning
+ is raised.
+
+ RETURN
+ 0 ok
+ 1 error
+*/
+
+bool Field_num::get_int(CHARSET_INFO *cs, const char *from, uint len,
+ longlong *rnd, ulonglong unsigned_max,
+ longlong signed_min, longlong signed_max)
+{
+ char *end;
+ int error;
+
+ *rnd= (longlong) cs->cset->strntoull10rnd(cs, from, len, unsigned_flag, &end,
+ &error);
+ if (unsigned_flag)
{
- for (str++ ; str != end && *str == '0'; str++)
- ;
+
+ if (((ulonglong) *rnd > unsigned_max) && (*rnd= (longlong) unsigned_max) ||
+ error == MY_ERRNO_ERANGE)
+ {
+ goto out_of_range;
+ }
}
- /* Allow end space */
- for ( ; str != end ; str++)
+ else
{
- if (!my_isspace(cs,*str))
+ if (*rnd < signed_min)
{
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
- return 1;
+ *rnd= signed_min;
+ goto out_of_range;
+ }
+ else if (*rnd > signed_max)
+ {
+ *rnd= signed_max;
+ goto out_of_range;
}
}
+ if (table->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
+ return 1;
return 0;
-}
+out_of_range:
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+ return 1;
+}
/*
Process decimal library return codes and issue warnings for overflow and
@@ -2506,45 +2580,11 @@ void Field_new_decimal::sql_type(String &str) const
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
{
- char *end;
int error;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > 255)
- {
- set_if_smaller(tmp, 255);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- ptr[0]= (char) tmp;
- }
- else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < -128)
- {
- tmp= -128;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp >= 128)
- {
- tmp= 127;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- ptr[0]= (char) tmp;
- }
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, 255, -128, 127);
+ ptr[0]= unsigned_flag ? (char) (ulonglong) rnd : (char) rnd;
return error;
}
@@ -2709,59 +2749,20 @@ void Field_tiny::sql_type(String &res) const
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
{
- char *end;
+ int store_tmp;
int error;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > UINT_MAX16)
- {
- set_if_smaller(tmp, UINT_MAX16);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, UINT_MAX16, INT_MIN16, INT_MAX16);
+ store_tmp= unsigned_flag ? (int) (ulonglong) rnd : (int) rnd;
#ifdef WORDS_BIGENDIAN
- if (table->s->db_low_byte_first)
- {
- int2store(ptr,tmp);
- }
- else
-#endif
- shortstore(ptr,(short) tmp);
+ if (table->s->db_low_byte_first)
+ {
+ int2store(ptr, store_tmp);
}
else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < INT_MIN16)
- {
- tmp= INT_MIN16;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > INT_MAX16)
- {
- tmp=INT_MAX16;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
-#ifdef WORDS_BIGENDIAN
- if (table->s->db_low_byte_first)
- {
- int2store(ptr,tmp);
- }
- else
#endif
- shortstore(ptr,(short) tmp);
- }
+ shortstore(ptr, (short) store_tmp);
return error;
}
@@ -2989,45 +2990,13 @@ void Field_short::sql_type(String &res) const
int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
{
- char *end;
+ int store_tmp;
int error;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > UINT_MAX24)
- {
- set_if_smaller(tmp, UINT_MAX24);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- int3store(ptr,tmp);
- }
- else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < INT_MIN24)
- {
- tmp= INT_MIN24;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > INT_MAX24)
- {
- tmp=INT_MAX24;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- int3store(ptr,tmp);
- }
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, UINT_MAX24, INT_MIN24, INT_MAX24);
+ store_tmp= unsigned_flag ? (int) (ulonglong) rnd : (int) rnd;
+ int3store(ptr, store_tmp);
return error;
}
@@ -3206,45 +3175,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
{
long store_tmp;
int error;
- char *end;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > (ulonglong) UINT_MAX32)
- {
- set_if_smaller(tmp, (ulonglong) UINT_MAX32);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- store_tmp= (long) tmp;
- }
- else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < INT_MIN32)
- {
- tmp= INT_MIN32;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > INT_MAX32)
- {
- tmp=INT_MAX32;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- store_tmp= (long) tmp;
- }
-
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, UINT_MAX32, INT_MIN32, INT_MAX32);
+ store_tmp= unsigned_flag ? (long) (ulonglong) rnd : (long) rnd;
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
@@ -3490,7 +3424,8 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ else if (table->in_use->count_cuted_fields &&
+ check_int(cs, from, len, end, error))
error= 1;
else
error= 0;
@@ -5008,16 +4943,25 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
{
char *end;
int error;
- long nr= my_strntol(cs, from, len, 10, &end, &error);
+ longlong nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155 || error)
+ if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155 ||
+ error == MY_ERRNO_ERANGE)
{
*ptr=0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
return 1;
}
- if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ if (table->in_use->count_cuted_fields &&
+ (error= check_int(cs, from, len, end, error)))
+ {
+ if (error == 1) /* empty or incorrect string */
+ {
+ *ptr= 0;
+ return 1;
+ }
error= 1;
+ }
if (nr != 0 || len != 4)
{
@@ -5907,31 +5851,6 @@ report_data_too_long(Field_str *field)
}
-/*
- Test if the given string contains important data:
- not spaces for character string,
- or any data for binary string.
-
- SYNOPSIS
- test_if_important_data()
- cs Character set
- str String to test
- strend String end
-
- RETURN
- FALSE - If string does not have important data
- TRUE - If string has some important data
-*/
-
-static bool
-test_if_important_data(CHARSET_INFO *cs, const char *str, const char *strend)
-{
- if (cs != &my_charset_bin)
- str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
- return (str < strend);
-}
-
-
/* Copy a string and fill with space */
int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
@@ -8676,11 +8595,6 @@ bool create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
break;
case FIELD_TYPE_SET:
{
- if (fld_interval_list->elements > sizeof(longlong)*8)
- {
- my_error(ER_TOO_BIG_SET, MYF(0), fld_name); /* purecov: inspected */
- DBUG_RETURN(TRUE);
- }
pack_length= get_set_pack_length(fld_interval_list->elements);
List_iterator<String> it(*fld_interval_list);
diff --git a/sql/field.h b/sql/field.h
index e82e90ce5ab..fc68a4549a9 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -306,8 +306,6 @@ public:
virtual void set_derivation(enum Derivation derivation_arg) { }
bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
int cuted_increment);
- bool check_int(const char *str, int length, const char *int_end,
- CHARSET_INFO *cs);
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
const char *str, uint str_len,
timestamp_type ts_type, int cuted_increment);
@@ -369,6 +367,11 @@ public:
bool eq_def(Field *field);
int store_decimal(const my_decimal *);
my_decimal *val_decimal(my_decimal *);
+ int check_int(CHARSET_INFO *cs, const char *str, int length,
+ const char *int_end, int error);
+ bool get_int(CHARSET_INFO *cs, const char *from, uint len,
+ longlong *rnd, ulonglong unsigned_max,
+ longlong signed_min, longlong signed_max);
};
diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc
index 2ee514f29c9..e2a2211259f 100644
--- a/sql/ha_archive.cc
+++ b/sql/ha_archive.cc
@@ -503,8 +503,8 @@ int ha_archive::init_archive_writer()
We just implement one additional file extension.
*/
static const char *ha_archive_exts[] = {
- ARZ,
ARM,
+ ARZ,
NullS
};
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index cbefa9d3949..217f59d4b7e 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -6066,6 +6066,15 @@ ha_innobase::external_lock(
trx->isolation_level = innobase_map_isolation_level(
(enum_tx_isolation)
thd->variables.tx_isolation);
+
+ if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
+ && trx->global_read_view) {
+
+ /* At low transaction isolation levels we let
+ each consistent read set its own snapshot */
+
+ read_view_close_for_mysql(trx);
+ }
}
if (trx->isolation_level == TRX_ISO_SERIALIZABLE
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index b02be09251f..33744b49cef 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -203,6 +203,8 @@ static const err_code_mapping err_map[]=
{ 284, HA_ERR_TABLE_DEF_CHANGED, 0 },
+ {4009, HA_ERR_NO_CONNECTION, 1 },
+
{ 0, 1, 0 },
{ -1, -1, 1 }
@@ -2521,8 +2523,13 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
ERR_RETURN(op->getNdbError());
}
- // Execute update operation
- if (!cursor && execute_no_commit(this,trans,false) != 0) {
+ /*
+ Execute update operation if we are not doing a scan for update
+ and there exist UPDATE AFTER triggers
+ */
+
+ if ((!cursor || m_update_cannot_batch) &&
+ execute_no_commit(this,trans,false) != 0) {
no_uncommitted_rows_execute_failure();
DBUG_RETURN(ndb_err(trans));
}
@@ -2563,7 +2570,7 @@ int ha_ndbcluster::delete_row(const byte *record)
no_uncommitted_rows_update(-1);
- if (!m_primary_key_update)
+ if (!(m_primary_key_update || m_delete_cannot_batch))
// If deleting from cursor, NoCommit will be handled in next_result
DBUG_RETURN(0);
}
@@ -3404,6 +3411,16 @@ int ha_ndbcluster::extra(enum ha_extra_function operation)
DBUG_PRINT("info", ("Turning OFF use of write instead of insert"));
m_use_write= FALSE;
break;
+ case HA_EXTRA_DELETE_CANNOT_BATCH:
+ DBUG_PRINT("info", ("HA_EXTRA_DELETE_CANNOT_BATCH"));
+ m_delete_cannot_batch= TRUE;
+ break;
+ case HA_EXTRA_UPDATE_CANNOT_BATCH:
+ DBUG_PRINT("info", ("HA_EXTRA_UPDATE_CANNOT_BATCH"));
+ m_update_cannot_batch= TRUE;
+ break;
+ default:
+ break;
}
DBUG_RETURN(0);
@@ -3420,6 +3437,8 @@ int ha_ndbcluster::reset()
m_retrieve_primary_key= FALSE;
m_ignore_dup_key= FALSE;
m_use_write= FALSE;
+ m_delete_cannot_batch= FALSE;
+ m_update_cannot_batch= FALSE;
DBUG_RETURN(0);
}
@@ -4785,6 +4804,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
m_bulk_insert_rows((ha_rows) 1024),
m_rows_changed((ha_rows) 0),
m_bulk_insert_not_flushed(FALSE),
+ m_delete_cannot_batch(FALSE),
+ m_update_cannot_batch(FALSE),
m_ops_pending(0),
m_skip_auto_increment(TRUE),
m_blobs_pending(0),
@@ -5067,14 +5088,11 @@ int ndbcluster_table_exists_in_engine(THD* thd, const char *db, const char *name
dict->invalidateTable(name);
if (!(tab= dict->getTable(name)))
{
- const NdbError err= dict->getNdbError();
- if (err.code == 709)
- DBUG_RETURN(0);
- ERR_RETURN(err);
+ ERR_RETURN(dict->getNdbError());
}
DBUG_PRINT("info", ("Found table %s", tab->getName()));
- DBUG_RETURN(1);
+ DBUG_RETURN(HA_ERR_TABLE_EXIST);
}
@@ -5259,7 +5277,7 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path,
DBUG_PRINT("info", ("%s existed on disk", name));
// The .ndb file exists on disk, but it's not in list of tables in ndb
// Verify that handler agrees table is gone.
- if (ndbcluster_table_exists_in_engine(thd, db, file_name) == 0)
+ if (ndbcluster_table_exists_in_engine(thd, db, file_name) == HA_ERR_NO_SUCH_TABLE)
{
DBUG_PRINT("info", ("NDB says %s does not exists", file_name));
it.remove();
@@ -6696,7 +6714,8 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
DBUG_RETURN(NULL);
}
- List<NDB_SHARE> util_open_tables;
+ uint share_list_size= 0;
+ NDB_SHARE **share_list= NULL;
set_timespec(abstime, 0);
for (;;)
{
@@ -6726,7 +6745,22 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
/* Lock mutex and fill list with pointers to all open tables */
NDB_SHARE *share;
pthread_mutex_lock(&ndbcluster_mutex);
- for (uint i= 0; i < ndbcluster_open_tables.records; i++)
+ uint i, record_count= ndbcluster_open_tables.records;
+ if (share_list_size < record_count)
+ {
+ NDB_SHARE ** new_share_list= new NDB_SHARE * [record_count];
+ if (!new_share_list)
+ {
+ sql_print_warning("ndb util thread: malloc failure, "
+ "query cache not maintained properly");
+ pthread_mutex_unlock(&ndbcluster_mutex);
+ goto next; // At least do not crash
+ }
+ delete [] share_list;
+ share_list_size= record_count;
+ share_list= new_share_list;
+ }
+ for (i= 0; i < record_count; i++)
{
share= (NDB_SHARE *)hash_element(&ndbcluster_open_tables, i);
share->use_count++; /* Make sure the table can't be closed */
@@ -6735,14 +6769,14 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
i, share->table_name, share->use_count));
/* Store pointer to table */
- util_open_tables.push_back(share);
+ share_list[i]= share;
}
pthread_mutex_unlock(&ndbcluster_mutex);
- /* Iterate through the open files list */
- List_iterator_fast<NDB_SHARE> it(util_open_tables);
- while ((share= it++))
+ /* Iterate through the open files list */
+ for (i= 0; i < record_count; i++)
{
+ share= share_list[i];
/* Split tab- and dbname */
char buf[FN_REFLEN];
char *tabname, *db;
@@ -6791,10 +6825,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
/* Decrease the use count and possibly free share */
free_share(share);
}
-
- /* Clear the list of open tables */
- util_open_tables.empty();
-
+next:
/* Calculate new time to wake up */
int secs= 0;
int msecs= ndb_cache_check_time;
@@ -6817,6 +6848,8 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
}
}
+ if (share_list)
+ delete [] share_list;
thd->cleanup();
delete thd;
delete ndb;
@@ -7114,7 +7147,7 @@ void ndb_serialize_cond(const Item *item, void *arg)
Check that the field is part of the table of the handler
instance and that we expect a field with of this result type.
*/
- if (context->table == field->table)
+ if (context->table->s == field->table->s)
{
const NDBTAB *tab= (const NDBTAB *) context->ndb_table;
DBUG_PRINT("info", ("FIELD_ITEM"));
diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h
index 6b49b0e3c70..3495f35e10f 100644
--- a/sql/ha_ndbcluster.h
+++ b/sql/ha_ndbcluster.h
@@ -774,6 +774,8 @@ bool uses_blob_value(bool all_fields);
ha_rows m_bulk_insert_rows;
ha_rows m_rows_changed;
bool m_bulk_insert_not_flushed;
+ bool m_delete_cannot_batch;
+ bool m_update_cannot_batch;
ha_rows m_ops_pending;
bool m_skip_auto_increment;
bool m_blobs_pending;
diff --git a/sql/handler.cc b/sql/handler.cc
index 6788d21b40f..c6c31593a5f 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2438,14 +2438,14 @@ ha_find_files(THD *thd,const char *db,const char *path,
Ask handler if the table exists in engine
RETURN
- 0 Table does not exist
- 1 Table exists
- # Error code
+ HA_ERR_NO_SUCH_TABLE Table does not exist
+ HA_ERR_TABLE_EXIST Table exists
+ # Error code
*/
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
{
- int error= 0;
+ int error= HA_ERR_NO_SUCH_TABLE;
DBUG_ENTER("ha_table_exists_in_engine");
DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
#ifdef HAVE_NDBCLUSTER_DB
diff --git a/sql/handler.h b/sql/handler.h
index 9e381ca4482..9863d541b5f 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -780,6 +780,17 @@ public:
virtual void free_foreign_key_create_info(char* str) {}
/* The following can be called without an open handler */
virtual const char *table_type() const =0;
+ /*
+ If frm_error() is called then we will use this to find out what file
+ extentions exist for the storage engine. This is also used by the default
+ rename_table and delete_table method in handler.cc.
+
+ For engines that have two file name extentions (separate meta/index file
+ and data file), the order of elements is relevant. First element of engine
+ file name extentions array should be meta/index file extention. Second
+ element - data file extention. This order is assumed by
+ prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
+ */
virtual const char **bas_ext() const =0;
virtual ulong table_flags(void) const =0;
virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
diff --git a/sql/item.h b/sql/item.h
index 7b0d18e19c5..2c4943bea6e 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -694,12 +694,11 @@ public:
virtual bool get_date_result(TIME *ltime,uint fuzzydate)
{ return get_date(ltime,fuzzydate); }
/*
- This function is used only in Item_func_isnull/Item_func_isnotnull
- (implementations of IS NULL/IS NOT NULL clauses). Item_func_is{not}null
- calls this method instead of one of val/result*() methods, which
- normally will set null_value. This allows to determine nullness of
- a complex expression without fully evaluating it.
- Any new item which can be NULL must implement this call.
+ The method allows to determine nullness of a complex expression
+ without fully evaluating it, instead of calling val/result*() then
+ checking null_value. Used in Item_func_isnull/Item_func_isnotnull
+ and Item_sum_count/Item_sum_count_distinct.
+ Any new item which can be NULL must implement this method.
*/
virtual bool is_null() { return 0; }
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index c5e7d8a0b29..3bb537c2fd5 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1079,6 +1079,26 @@ longlong Item_func_strcmp::val_int()
}
+bool Item_func_opt_neg::eq(const Item *item, bool binary_cmp) const
+{
+ /* Assume we don't have rtti */
+ if (this == item)
+ return 1;
+ if (item->type() != FUNC_ITEM)
+ return 0;
+ Item_func *item_func=(Item_func*) item;
+ if (arg_count != item_func->arg_count ||
+ functype() != item_func->functype())
+ return 0;
+ if (negated != ((Item_func_opt_neg *) item_func)->negated)
+ return 0;
+ for (uint i=0; i < arg_count ; i++)
+ if (!args[i]->eq(item_func->arguments()[i], binary_cmp))
+ return 0;
+ return 1;
+}
+
+
void Item_func_interval::fix_length_and_dec()
{
use_decimal_comparison= (row->element_index(0)->result_type() == DECIMAL_RESULT) ||
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index f6c6f612c5b..0c4a62aaa24 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -561,6 +561,7 @@ public:
negated= !negated;
return this;
}
+ bool eq(const Item *item, bool binary_cmp) const;
bool subst_argument_checker(byte **arg) { return TRUE; }
};
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 3d92be5e9d2..c4279d1bd4e 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -230,6 +230,8 @@ void Item_func::traverse_cond(Cond_traverser traverser,
(*traverser)(this, argument);
}
}
+ else
+ (*traverser)(this, argument);
}
@@ -4615,14 +4617,14 @@ void Item_func_match::init_search(bool no_order)
fields.push_back(new Item_string(" ",1, cmp_collation.collation));
for (uint i=1; i < arg_count; i++)
fields.push_back(args[i]);
- concat=new Item_func_concat_ws(fields);
+ concat_ws=new Item_func_concat_ws(fields);
/*
Above function used only to get value and do not need fix_fields for it:
Item_string - basic constant
fields - fix_fields() was already called for this arguments
Item_func_concat_ws - do not need fix_fields() to produce value
*/
- concat->quick_fix_field();
+ concat_ws->quick_fix_field();
}
if (master)
@@ -4837,8 +4839,8 @@ double Item_func_match::val_real()
if (key == NO_SUCH_KEY)
{
- String *a= concat->val_str(&value);
- if ((null_value= (a == 0)))
+ String *a= concat_ws->val_str(&value);
+ if ((null_value= (a == 0)) || !a->length())
DBUG_RETURN(0);
DBUG_RETURN(ft_handler->please->find_relevance(ft_handler,
(byte *)a->ptr(), a->length()));
@@ -4996,10 +4998,10 @@ longlong Item_func_row_count::val_int()
}
-Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
- sp_name *name_arg)
- :Item_func(), context(context_arg), m_name(name_arg), m_sp(NULL),
- result_field(NULL)
+
+
+Item_func_sp::Item_func_sp(Name_resolution_context *context_arg, sp_name *name)
+ :Item_func(), context(context_arg), m_name(name), m_sp(NULL), sp_result_field(NULL)
{
maybe_null= 1;
m_name->init_qname(current_thd);
@@ -5008,22 +5010,22 @@ Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
- sp_name *name_arg, List<Item> &list)
- :Item_func(list), context(context_arg), m_name(name_arg), m_sp(NULL),
- result_field(NULL)
+ sp_name *name, List<Item> &list)
+ :Item_func(list), context(context_arg), m_name(name), m_sp(NULL),sp_result_field(NULL)
{
maybe_null= 1;
m_name->init_qname(current_thd);
dummy_table= (TABLE*) sql_calloc(sizeof(TABLE));
}
+
void
Item_func_sp::cleanup()
{
- if (result_field)
+ if (sp_result_field)
{
- delete result_field;
- result_field= NULL;
+ delete sp_result_field;
+ sp_result_field= NULL;
}
m_sp= NULL;
dummy_table->s= NULL;
@@ -5035,7 +5037,7 @@ Item_func_sp::func_name() const
{
THD *thd= current_thd;
/* Calculate length to avoid reallocation of string for sure */
- uint len= ((m_name->m_db.length +
+ uint len= ((m_name->m_explicit_name ? m_name->m_db.length : 0 +
m_name->m_name.length)*2 + //characters*quoting
2 + // ` and `
1 + // .
@@ -5045,89 +5047,127 @@ Item_func_sp::func_name() const
system_charset_info);
qname.length(0);
- append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);
- qname.append('.');
+ if (m_name->m_explicit_name)
+ {
+ append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);
+ qname.append('.');
+ }
append_identifier(thd, &qname, m_name->m_name.str, m_name->m_name.length);
return qname.ptr();
}
-Field *
-Item_func_sp::sp_result_field(void) const
+
+/**
+ @brief Initialize the result field by creating a temporary dummy table
+ and assign it to a newly created field object. Meta data used to
+ create the field is fetched from the sp_head belonging to the stored
+ proceedure found in the stored procedure functon cache.
+
+ @note This function should be called from fix_fields to init the result
+ field. It is some what related to Item_field.
+
+ @see Item_field
+
+ @param thd A pointer to the session and thread context.
+
+ @return Function return error status.
+ @retval TRUE is returned on an error
+ @retval FALSE is returned on success.
+*/
+bool
+Item_func_sp::init_result_field(THD *thd)
{
- Field *field;
- DBUG_ENTER("Item_func_sp::sp_result_field");
- DBUG_PRINT("info", ("sp: %s, flags: %x, level: %lu",
- (m_sp ? "YES" : "NO"),
- (m_sp ? m_sp->m_flags : (uint)0),
- (m_sp ? m_sp->m_recursion_level : (ulong)0)));
+ DBUG_ENTER("Item_func_sp::init_result_field");
+
+ char *empty_name= (char *) "";
+ TABLE_SHARE *share;
- if (!m_sp)
+ DBUG_ASSERT(m_sp == NULL);
+ DBUG_ASSERT(sp_result_field == NULL);
+ DBUG_ASSERT(dummy_table->s == NULL);
+
+ if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
+ &thd->sp_func_cache, TRUE)))
{
- THD *thd= current_thd;
- if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
- &thd->sp_func_cache, TRUE)))
- {
- my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
- DBUG_RETURN(0);
- }
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
+ context->process_error(thd);
+ DBUG_RETURN(TRUE);
+ }
+
+ /*
+ A Field need to be attached to a Table.
+ Below we "create" a dummy table by initializing
+ the needed pointers.
+ */
+ dummy_table->s= share= &dummy_table->share_not_to_be_used;
+ dummy_table->alias = empty_name;
+ dummy_table->maybe_null = maybe_null;
+ dummy_table->in_use= thd;
+ dummy_table->copy_blobs= TRUE;
+ share->table_cache_key = empty_name;
+ share->table_name = empty_name;
+
+ if (!(sp_result_field= m_sp->create_result_field(max_length, name, dummy_table)))
+ {
+ DBUG_RETURN(TRUE);
}
- if (!dummy_table->s)
+
+ if (sp_result_field->pack_length() > sizeof(result_buf))
{
- char *empty_name= (char *) "";
- TABLE_SHARE *share;
- dummy_table->s= share= &dummy_table->share_not_to_be_used;
- dummy_table->alias = empty_name;
- dummy_table->maybe_null = maybe_null;
- dummy_table->in_use= current_thd;
- dummy_table->copy_blobs= TRUE;
- share->table_cache_key = empty_name;
- share->table_name = empty_name;
+ sp_result_field->move_field(sql_alloc(sp_result_field->pack_length()));
+ } else {
+ sp_result_field->move_field(result_buf);
}
- if (!(field= m_sp->create_result_field(max_length, name, dummy_table)))
- my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
+
+ sp_result_field->null_ptr= (uchar *) &null_value;
+ sp_result_field->null_bit= 1;
+
- DBUG_RETURN(field);
+ DBUG_RETURN(FALSE);
}
+/**
+ @brief Initialize local members with values from the Field interface.
-/*
- Execute function & store value in field
+ @note called from Item::fix_fields.
+*/
+void Item_func_sp::fix_length_and_dec()
+{
+ DBUG_ENTER("Item_func_sp::fix_length_and_dec");
- RETURN
- 0 value <> NULL
- 1 value = NULL or error
+ DBUG_ASSERT(sp_result_field);
+ decimals= sp_result_field->decimals();
+ max_length= sp_result_field->field_length;
+ collation.set(sp_result_field->charset());
+ maybe_null= 1;
+ unsigned_flag= test(sp_result_field->flags & UNSIGNED_FLAG);
+
+ DBUG_VOID_RETURN;
+}
+
+/**
+ @brief Execute function & store value in field.
+
+ @return Function returns error status.
+ @retval FALSE on success.
+ @retval TRUE if an error occurred.
*/
bool
-Item_func_sp::execute(Field **flp)
+Item_func_sp::execute()
{
THD *thd= current_thd;
- Field *f;
-
+
/*
Get field in virtual tmp table to store result. Create the field if
invoked first time.
*/
-
- if (!(f= *flp))
- {
- if (!(*flp= f= sp_result_field()))
- {
- /* Error set by sp_result_field() */
- null_value= 1;
- return TRUE;
- }
- f->move_field((f->pack_length() > sizeof(result_buf)) ?
- sql_alloc(f->pack_length()) : result_buf);
- f->null_ptr= (uchar *)&null_value;
- f->null_bit= 1;
- }
/* Execute function and store the return value in the field. */
- if (execute_impl(thd, f))
+ if (execute_impl(thd))
{
null_value= 1;
context->process_error(thd);
@@ -5136,14 +5176,24 @@ Item_func_sp::execute(Field **flp)
/* Check that the field (the value) is not NULL. */
- null_value= f->is_null();
+ null_value= sp_result_field->is_null();
return null_value;
}
+/**
+ @brief Execute function and store the return value in the field.
+
+ @note This function was intended to be the concrete implementation of
+ the interface function execute. This was never realized.
+
+ @return The error state.
+ @retval FALSE on success
+ @retval TRUE if an error occurred.
+*/
bool
-Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
+Item_func_sp::execute_impl(THD *thd)
{
bool err_status= TRUE;
Sub_statement_state statement_state;
@@ -5160,7 +5210,7 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
thd->security_ctx= context->security_ctx;
}
#endif
- if (find_and_check_access(thd))
+ if (sp_check_access(thd))
goto error;
/*
@@ -5169,7 +5219,7 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
function call into binlog.
*/
thd->reset_sub_statement_state(&statement_state, SUB_STMT_FUNCTION);
- err_status= m_sp->execute_function(thd, args, arg_count, return_value_fld);
+ err_status= m_sp->execute_function(thd, args, arg_count, sp_result_field);
thd->restore_sub_statement_state(&statement_state);
error:
@@ -5184,15 +5234,9 @@ error:
void
Item_func_sp::make_field(Send_field *tmp_field)
{
- Field *field;
DBUG_ENTER("Item_func_sp::make_field");
- if ((field= sp_result_field()))
- {
- field->make_field(tmp_field);
- delete field;
- DBUG_VOID_RETURN;
- }
- init_make_field(tmp_field, MYSQL_TYPE_VARCHAR);
+ DBUG_ASSERT(sp_result_field);
+ sp_result_field->make_field(tmp_field);
DBUG_VOID_RETURN;
}
@@ -5200,67 +5244,20 @@ Item_func_sp::make_field(Send_field *tmp_field)
enum enum_field_types
Item_func_sp::field_type() const
{
- Field *field;
DBUG_ENTER("Item_func_sp::field_type");
-
- if (result_field)
- DBUG_RETURN(result_field->type());
- if ((field= sp_result_field()))
- {
- enum_field_types result= field->type();
- delete field;
- DBUG_RETURN(result);
- }
- DBUG_RETURN(MYSQL_TYPE_VARCHAR);
+ DBUG_ASSERT(sp_result_field);
+ DBUG_RETURN(sp_result_field->type());
}
-
Item_result
Item_func_sp::result_type() const
{
- Field *field;
DBUG_ENTER("Item_func_sp::result_type");
DBUG_PRINT("info", ("m_sp = %p", m_sp));
-
- if (result_field)
- DBUG_RETURN(result_field->result_type());
- if ((field= sp_result_field()))
- {
- Item_result result= field->result_type();
- delete field;
- DBUG_RETURN(result);
- }
- DBUG_RETURN(STRING_RESULT);
-}
-
-void
-Item_func_sp::fix_length_and_dec()
-{
- Field *field;
- DBUG_ENTER("Item_func_sp::fix_length_and_dec");
-
- if (result_field)
- {
- decimals= result_field->decimals();
- max_length= result_field->field_length;
- collation.set(result_field->charset());
- DBUG_VOID_RETURN;
- }
-
- if (!(field= sp_result_field()))
- {
- context->process_error(current_thd);
- DBUG_VOID_RETURN;
- }
- decimals= field->decimals();
- max_length= field->field_length;
- collation.set(field->charset());
- maybe_null= 1;
- delete field;
- DBUG_VOID_RETURN;
+ DBUG_ASSERT(sp_result_field);
+ DBUG_RETURN(sp_result_field->result_type());
}
-
longlong Item_func_found_rows::val_int()
{
DBUG_ASSERT(fixed == 1);
@@ -5271,57 +5268,39 @@ longlong Item_func_found_rows::val_int()
Field *
Item_func_sp::tmp_table_field(TABLE *t_arg)
{
- Field *field= 0;
DBUG_ENTER("Item_func_sp::tmp_table_field");
- if (m_sp)
- field= m_sp->create_result_field(max_length, (const char*) name, t_arg);
-
- if (!field)
- field= Item_func::tmp_table_field(t_arg);
-
- if (!field)
- my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
-
- DBUG_RETURN(field);
+ DBUG_ASSERT(sp_result_field);
+ DBUG_RETURN(sp_result_field);
}
-/*
- Find the function and check access rights to the function
-
- SYNOPSIS
- find_and_check_access()
- thd thread handler
-
- RETURN
- FALSE Access granted
- TRUE Requested access can't be granted or function doesn't exists
-
- NOTES
- Checks if requested access to function can be granted to user.
+/**
+ @brief Checks if requested access to function can be granted to user.
If function isn't found yet, it searches function first.
If function can't be found or user don't have requested access
error is raised.
+
+ @param thd thread handler
+
+ @return Indication if the access was granted or not.
+ @retval FALSE Access is granted.
+ @retval TRUE Requested access can't be granted or function doesn't exists.
+
*/
bool
-Item_func_sp::find_and_check_access(THD *thd)
+Item_func_sp::sp_check_access(THD *thd)
{
- if (! m_sp && ! (m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
- &thd->sp_func_cache, TRUE)))
- {
- my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
- return TRUE;
- }
-
+ DBUG_ENTER("Item_func_sp::sp_check_access");
+ DBUG_ASSERT(m_sp);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (check_routine_access(thd, EXECUTE_ACL,
m_sp->m_db.str, m_sp->m_name.str, 0, FALSE))
- return TRUE;
+ DBUG_RETURN(TRUE);
#endif
- return FALSE;
+ DBUG_RETURN(FALSE);
}
@@ -5329,9 +5308,25 @@ bool
Item_func_sp::fix_fields(THD *thd, Item **ref)
{
bool res;
+ DBUG_ENTER("Item_func_sp::fix_fields");
DBUG_ASSERT(fixed == 0);
+
+ /*
+ We must call init_result_field before Item_func::fix_fields()
+ to make m_sp and result_field members available to fix_length_and_dec(),
+ which is called from Item_func::fix_fields().
+ */
+ res= init_result_field(thd);
+
+ if (res)
+ DBUG_RETURN(res);
+
res= Item_func::fix_fields(thd, ref);
- if (!res && thd->lex->view_prepare_mode)
+
+ if (res)
+ DBUG_RETURN(res);
+
+ if (thd->lex->view_prepare_mode)
{
/*
Here we check privileges of the stored routine only during view
@@ -5343,15 +5338,17 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
good idea especially if the view has SQL SECURITY DEFINER and
the used stored procedure has SQL SECURITY DEFINER.
*/
- res= find_and_check_access(thd);
+ res= sp_check_access(thd);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ /*
+ Try to set and restore the security context to see whether it's valid
+ */
Security_context *save_secutiry_ctx;
- if (!res && !(res= set_routine_security_ctx(thd, m_sp, false,
- &save_secutiry_ctx)))
- {
+ res= set_routine_security_ctx(thd, m_sp, false, &save_secutiry_ctx);
+ if (!res)
sp_restore_security_context(thd, save_secutiry_ctx);
- }
+
#endif /* ! NO_EMBEDDED_ACCESS_CHECKS */
}
- return res;
+ DBUG_RETURN(res);
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 24f30994b22..635a409e0a2 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -1308,12 +1308,12 @@ public:
FT_INFO *ft_handler;
TABLE *table;
Item_func_match *master; // for master-slave optimization
- Item *concat; // Item_func_concat_ws
- String value; // value of concat
+ Item *concat_ws; // Item_func_concat_ws
+ String value; // value of concat_ws
String search_value; // key_item()'s value converted to cmp_collation
Item_func_match(List<Item> &a, uint b): Item_real_func(a), key(0), flags(b),
- join_key(0), ft_handler(0), table(0), master(0), concat(0) { }
+ join_key(0), ft_handler(0), table(0), master(0), concat_ws(0) { }
void cleanup()
{
DBUG_ENTER("Item_func_match");
@@ -1321,7 +1321,7 @@ public:
if (!master && ft_handler)
ft_handler->please->close_search(ft_handler);
ft_handler= 0;
- concat= 0;
+ concat_ws= 0;
DBUG_VOID_RETURN;
}
enum Functype functype() const { return FT_FUNC; }
@@ -1405,12 +1405,15 @@ private:
sp_name *m_name;
mutable sp_head *m_sp;
TABLE *dummy_table;
- Field *result_field;
char result_buf[64];
+ /*
+ The result field of the concrete stored function.
+ */
+ Field *sp_result_field;
- bool execute(Field **flp);
- bool execute_impl(THD *thd, Field *return_value_fld);
- Field *sp_result_field(void) const;
+ bool execute();
+ bool execute_impl(THD *thd);
+ bool init_result_field(THD *thd);
public:
@@ -1438,23 +1441,23 @@ public:
longlong val_int()
{
- if (execute(&result_field))
+ if (execute())
return (longlong) 0;
- return result_field->val_int();
+ return sp_result_field->val_int();
}
double val_real()
{
- if (execute(&result_field))
+ if (execute())
return 0.0;
- return result_field->val_real();
+ return sp_result_field->val_real();
}
my_decimal *val_decimal(my_decimal *dec_buf)
{
- if (execute(&result_field))
+ if (execute())
return NULL;
- return result_field->val_decimal(dec_buf);
+ return sp_result_field->val_decimal(dec_buf);
}
String *val_str(String *str)
@@ -1463,7 +1466,7 @@ public:
char buff[20];
buf.set(buff, 20, str->charset());
buf.length(0);
- if (execute(&result_field))
+ if (execute())
return NULL;
/*
result_field will set buf pointing to internal buffer
@@ -1471,7 +1474,7 @@ public:
when SP is executed. In order to prevent occasional
corruption of returned value, we make here a copy.
*/
- result_field->val_str(&buf);
+ sp_result_field->val_str(&buf);
str->copy(buf);
return str;
}
@@ -1479,11 +1482,11 @@ public:
virtual bool change_context_processor(byte *cntx)
{ context= (Name_resolution_context *)cntx; return FALSE; }
- void fix_length_and_dec();
- bool find_and_check_access(THD * thd);
+ bool sp_check_access(THD * thd);
virtual enum Functype functype() const { return FUNC_SP; }
bool fix_fields(THD *thd, Item **ref);
+ void fix_length_and_dec(void);
bool is_expensive() { return 1; }
};
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 03887629519..1991526345c 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2319,7 +2319,7 @@ String *Item_func_repeat::val_str(String *str)
goto err; // string and/or delim are null
null_value= 0;
- if (count == 0 || count < 0 && !args[1]->unsigned_flag)
+ if (count <= 0 && (count == 0 || !args[1]->unsigned_flag))
return &my_empty_string;
/* Assumes that the maximum length of a String is < INT_MAX32. */
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 359b4516c3c..752cefa07d6 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1080,14 +1080,8 @@ void Item_sum_count::clear()
bool Item_sum_count::add()
{
- if (!args[0]->maybe_null)
+ if (!args[0]->maybe_null || !args[0]->is_null())
count++;
- else
- {
- args[0]->update_null_value();
- if (!args[0]->null_value)
- count++;
- }
return 0;
}
@@ -1921,14 +1915,8 @@ void Item_sum_count::reset_field()
char *res=result_field->ptr;
longlong nr=0;
- if (!args[0]->maybe_null)
+ if (!args[0]->maybe_null || !args[0]->is_null())
nr=1;
- else
- {
- args[0]->update_null_value();
- if (!args[0]->null_value)
- nr=1;
- }
int8store(res,nr);
}
@@ -2031,14 +2019,8 @@ void Item_sum_count::update_field()
char *res=result_field->ptr;
nr=sint8korr(res);
- if (!args[0]->maybe_null)
+ if (!args[0]->maybe_null || !args[0]->is_null())
nr++;
- else
- {
- args[0]->update_null_value();
- if (!args[0]->null_value)
- nr++;
- }
int8store(res,nr);
}
@@ -2462,12 +2444,8 @@ bool Item_sum_count_distinct::setup(THD *thd)
Item *item=args[i];
if (list.push_back(item))
return TRUE; // End of memory
- if (item->const_item())
- {
- item->update_null_value();
- if (item->null_value)
- always_null=1;
- }
+ if (item->const_item() && item->is_null())
+ always_null= 1;
}
if (always_null)
return FALSE;
diff --git a/sql/log.cc b/sql/log.cc
index a0068dce1c5..7563d754556 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -283,7 +283,7 @@ err:
#ifdef __NT__
static int eventSource = 0;
-void setup_windows_event_source()
+static void setup_windows_event_source()
{
HKEY hRegKey= NULL;
DWORD dwError= 0;
@@ -2229,37 +2229,6 @@ static bool test_if_number(register const char *str,
} /* test_if_number */
-void print_buffer_to_file(enum loglevel level, const char *buffer)
-{
- time_t skr;
- struct tm tm_tmp;
- struct tm *start;
- DBUG_ENTER("print_buffer_to_file");
- DBUG_PRINT("enter",("buffer: %s", buffer));
-
- VOID(pthread_mutex_lock(&LOCK_error_log));
-
- skr=time(NULL);
- localtime_r(&skr, &tm_tmp);
- start=&tm_tmp;
- fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
- start->tm_year % 100,
- start->tm_mon+1,
- start->tm_mday,
- start->tm_hour,
- start->tm_min,
- start->tm_sec,
- (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
- "Warning" : "Note"),
- buffer);
-
- fflush(stderr);
-
- VOID(pthread_mutex_unlock(&LOCK_error_log));
- DBUG_VOID_RETURN;
-}
-
-
void sql_perror(const char *message)
{
#ifdef HAVE_STRERROR
@@ -2326,23 +2295,15 @@ void MYSQL_LOG::signal_update()
}
#ifdef __NT__
-void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
- uint length, int buffLen)
+static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
+ size_t length, size_t buffLen)
{
HANDLE event;
- char *buffptr;
- LPCSTR *buffmsgptr;
+ char *buffptr= buff;
DBUG_ENTER("print_buffer_to_nt_eventlog");
- buffptr= buff;
- if (length > (uint)(buffLen-5))
- {
- char *newBuff= new char[length + 5];
- strcpy(newBuff, buff);
- buffptr= newBuff;
- }
- strmov(buffptr+length, "\r\n\r\n");
- buffmsgptr= (LPCSTR*) &buffptr; // Keep windows happy
+ /* Add ending CR/LF's to string, overwrite last chars if necessary */
+ strmov(buffptr+min(length, buffLen-5), "\r\n\r\n");
setup_windows_event_source();
if ((event= RegisterEventSource(NULL,"MySQL")))
@@ -2350,24 +2311,20 @@ void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
switch (level) {
case ERROR_LEVEL:
ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
- buffmsgptr, NULL);
+ (LPCSTR*)&buffptr, NULL);
break;
case WARNING_LEVEL:
ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
- buffmsgptr, NULL);
+ (LPCSTR*) &buffptr, NULL);
break;
case INFORMATION_LEVEL:
ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1,
- 0, buffmsgptr, NULL);
+ 0, (LPCSTR*) &buffptr, NULL);
break;
}
DeregisterEventSource(event);
}
- /* if we created a string buffer, then delete it */
- if (buffptr != buff)
- delete[] buffptr;
-
DBUG_VOID_RETURN;
}
#endif /* __NT__ */
@@ -2399,13 +2356,44 @@ void vprint_msg_to_log(enum loglevel level __attribute__((unused)),
va_list argsi __attribute__((unused)))
{}
#else /*!EMBEDDED_LIBRARY*/
+static void print_buffer_to_file(enum loglevel level, const char *buffer)
+{
+ time_t skr;
+ struct tm tm_tmp;
+ struct tm *start;
+ DBUG_ENTER("print_buffer_to_file");
+ DBUG_PRINT("enter",("buffer: %s", buffer));
+
+ VOID(pthread_mutex_lock(&LOCK_error_log));
+
+ skr=time(NULL);
+ localtime_r(&skr, &tm_tmp);
+ start=&tm_tmp;
+ fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
+ start->tm_year % 100,
+ start->tm_mon+1,
+ start->tm_mday,
+ start->tm_hour,
+ start->tm_min,
+ start->tm_sec,
+ (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
+ "Warning" : "Note"),
+ buffer);
+
+ fflush(stderr);
+
+ VOID(pthread_mutex_unlock(&LOCK_error_log));
+ DBUG_VOID_RETURN;
+}
+
+
void vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
{
char buff[1024];
- uint length;
+ size_t length;
DBUG_ENTER("vprint_msg_to_log");
- length= my_vsnprintf(buff, sizeof(buff)-5, format, args);
+ length= my_vsnprintf(buff, sizeof(buff), format, args);
print_buffer_to_file(level, buff);
#ifdef __NT__
diff --git a/sql/log_event.cc b/sql/log_event.cc
index e272140c080..8bb63e72bde 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -669,19 +669,34 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet,
LOG_READ_TOO_LARGE);
goto end;
}
- packet->append(buf, sizeof(buf));
+
+ /* Append the log event header to packet */
+ if (packet->append(buf, sizeof(buf)))
+ {
+ /* Failed to allocate packet */
+ result= LOG_READ_MEM;
+ goto end;
+ }
data_len-= LOG_EVENT_MINIMAL_HEADER_LEN;
if (data_len)
{
+ /* Append rest of event, read directly from file into packet */
if (packet->append(file, data_len))
{
/*
- Here if we hit EOF it's really an error: as data_len is >=0
- there's supposed to be more bytes available.
- EOF means we are reading the event partially, which should
- never happen: either we read badly or the binlog is truncated.
+ Fatal error occured when appending rest of the event
+ to packet, possible failures:
+ 1. EOF occured when reading from file, it's really an error
+ as data_len is >=0 there's supposed to be more bytes available.
+ file->error will have been set to number of bytes left to read
+ 2. Read was interrupted, file->error would normally be set to -1
+ 3. Failed to allocate memory for packet, my_errno
+ will be ENOMEM(file->error shuold be 0, but since the
+ memory allocation occurs before the call to read it might
+ be uninitialized)
*/
- result= file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO;
+ result= (my_errno == ENOMEM ? LOG_READ_MEM :
+ (file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO));
/* Implicit goto end; */
}
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 629ffb93b97..a9c20e142c5 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -842,6 +842,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
bool ignore);
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
TABLE_LIST *table_list);
+void prepare_triggers_for_insert_stmt(THD *thd, TABLE *table,
+ enum_duplicates duplic);
void mark_fields_used_by_triggers_for_insert_stmt(THD *thd, TABLE *table,
enum_duplicates duplic);
bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index 1351cf66161..aa352433141 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -719,14 +719,18 @@ nlist_err:
/*
parse parameters
-
+
SYNOPSIS
File_parser::parse()
base base address for parameter writing (structure like
TABLE)
mem_root MEM_ROOT for parameters allocation
parameters parameters description
- required number of required parameters in above list
+ required number of parameters in the above list. If the file
+ contains more parameters than "required", they will
+ be ignored. If the file contains less parameters
+ then "required", non-existing parameters will
+ remain their values.
hook hook called for unknown keys
hook_data some data specific for the hook
@@ -909,6 +913,13 @@ list_err:
}
}
}
+
+ /*
+ NOTE: if we read less than "required" parameters, it is still Ok.
+ Probably, we've just read the file of the previous version, which
+ contains less parameters.
+ */
+
DBUG_RETURN(FALSE);
}
diff --git a/sql/sp.cc b/sql/sp.cc
index 506b0bcd92b..4fc9ea1f602 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -1068,7 +1068,7 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error)
lex_name.length= strlen(routine->table_name);
lex_db.str= thd->strmake(routine->db, lex_db.length);
lex_name.str= thd->strmake(routine->table_name, lex_name.length);
- name= new sp_name(lex_db, lex_name);
+ name= new sp_name(lex_db, lex_name, true);
name->init_qname(thd);
sp_object_found= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name,
&thd->sp_proc_cache, FALSE) != NULL ||
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index bba231ba685..338b2eb84bb 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -954,6 +954,12 @@ sp_head::execute(THD *thd)
m_first_instance->m_last_cached_sp == this) ||
(m_recursion_level + 1 == m_next_cached_sp->m_recursion_level));
+ /*
+ NOTE: The SQL Standard does not specify the context that should be
+ preserved for stored routines. However, at SAP/Walldorf meeting it was
+ decided that current database should be preserved.
+ */
+
if (m_db.length &&
(err_status= sp_use_new_db(thd, m_db, &old_db, 0, &dbchanged)))
goto done;
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 901b7a19c39..cce400d6a14 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -59,9 +59,10 @@ public:
calling set_routine_type().
*/
LEX_STRING m_sroutines_key;
+ bool m_explicit_name; /**< Prepend the db name? */
- sp_name(LEX_STRING db, LEX_STRING name)
- : m_db(db), m_name(name)
+ sp_name(LEX_STRING db, LEX_STRING name, bool use_explicit_name)
+ : m_db(db), m_name(name), m_explicit_name(use_explicit_name)
{
m_qname.str= m_sroutines_key.str= 0;
m_qname.length= m_sroutines_key.length= 0;
@@ -79,6 +80,7 @@ public:
m_name.length= m_qname.length= key_len - 1;
m_db.str= 0;
m_db.length= 0;
+ m_explicit_name= false;
}
// Init. the qualified name from the db and name.
diff --git a/sql/spatial.h b/sql/spatial.h
index 86232fcd524..837ae153310 100644
--- a/sql/spatial.h
+++ b/sql/spatial.h
@@ -144,15 +144,46 @@ struct MBR
return (xmin<x) && (xmax>x) && (ymin<y) && (ymax>y);
}
+ /**
+ The dimension maps to an integer as:
+ - Polygon -> 2
+ - Horizontal or vertical line -> 1
+ - Point -> 0
+ - Invalid MBR -> -1
+ */
+ int dimension() const
+ {
+ int d= 0;
+
+ if (xmin > xmax)
+ return -1;
+ else if (xmin < xmax)
+ d++;
+
+ if (ymin > ymax)
+ return -1;
+ else if (ymin < ymax)
+ d++;
+
+ return d;
+ }
+
int overlaps(const MBR *mbr)
{
- int lb= mbr->inner_point(xmin, ymin);
- int rb= mbr->inner_point(xmax, ymin);
- int rt= mbr->inner_point(xmax, ymax);
- int lt= mbr->inner_point(xmin, ymax);
+ /*
+ overlaps() requires that some point inside *this is also inside
+ *mbr, and that both geometries and their intersection are of the
+ same dimension.
+ */
+ int d = dimension();
+
+ if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
+ return 0;
+
+ MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin),
+ min(xmax, mbr->xmax), min(ymax, mbr->ymax));
- int a = lb+rb+rt+lt;
- return (a>0) && (a<4) && (!within(mbr));
+ return (d == intersection.dimension());
}
};
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 0488fdd4eb8..bccd4d4cafe 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -217,7 +217,19 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
thd->proc_info="updating";
if (table->triggers)
+ {
table->triggers->mark_fields_used(thd, TRG_EVENT_DELETE);
+ if (table->triggers->has_triggers(TRG_EVENT_DELETE,
+ TRG_ACTION_AFTER))
+ {
+ /*
+ The table has AFTER DELETE triggers that might access to subject table
+ and therefore might need delete to be done immediately. So we turn-off
+ the batching.
+ */
+ (void) table->file->extra(HA_EXTRA_DELETE_CANNOT_BATCH);
+ }
+ }
while (!(error=info.read_record(&info)) && !thd->killed &&
!thd->net.report_error)
@@ -540,7 +552,19 @@ multi_delete::initialize_tables(JOIN *join)
else
normal_tables= 1;
if (tbl->triggers)
+ {
tbl->triggers->mark_fields_used(thd, TRG_EVENT_DELETE);
+ if (tbl->triggers->has_triggers(TRG_EVENT_DELETE,
+ TRG_ACTION_AFTER))
+ {
+ /*
+ The table has AFTER DELETE triggers that might access to subject
+ table and therefore might need delete to be done immediately.
+ So we turn-off the batching.
+ */
+ (void) tbl->file->extra(HA_EXTRA_DELETE_CANNOT_BATCH);
+ }
+ }
}
else if ((tab->type != JT_SYSTEM && tab->type != JT_CONST) &&
walk == delete_tables)
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 49b271dd219..f1d86224adb 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -330,6 +330,51 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
/*
+ Prepare triggers for INSERT-like statement.
+
+ SYNOPSIS
+ prepare_triggers_for_insert_stmt()
+ thd The current thread
+ table Table to which insert will happen
+ duplic Type of duplicate handling for insert which will happen
+
+ NOTE
+ Prepare triggers for INSERT-like statement by marking fields
+ used by triggers and inform handlers that batching of UPDATE/DELETE
+ cannot be done if there are BEFORE UPDATE/DELETE triggers.
+*/
+
+void prepare_triggers_for_insert_stmt(THD *thd, TABLE *table,
+ enum_duplicates duplic)
+{
+ if (table->triggers)
+ {
+ if (table->triggers->has_triggers(TRG_EVENT_DELETE,
+ TRG_ACTION_AFTER))
+ {
+ /*
+ The table has AFTER DELETE triggers that might access to
+ subject table and therefore might need delete to be done
+ immediately. So we turn-off the batching.
+ */
+ (void) table->file->extra(HA_EXTRA_DELETE_CANNOT_BATCH);
+ }
+ if (table->triggers->has_triggers(TRG_EVENT_UPDATE,
+ TRG_ACTION_AFTER))
+ {
+ /*
+ The table has AFTER UPDATE triggers that might access to subject
+ table and therefore might need update to be done immediately.
+ So we turn-off the batching.
+ */
+ (void) table->file->extra(HA_EXTRA_UPDATE_CANNOT_BATCH);
+ }
+ mark_fields_used_by_triggers_for_insert_stmt(thd, table, duplic);
+ }
+}
+
+
+/*
Mark fields used by triggers for INSERT-like statement.
SYNOPSIS
@@ -589,7 +634,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
- mark_fields_used_by_triggers_for_insert_stmt(thd, table, duplic);
+ prepare_triggers_for_insert_stmt(thd, table, duplic);
if (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd))
@@ -2528,8 +2573,8 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table_list->prepare_check_option(thd));
if (!res)
- mark_fields_used_by_triggers_for_insert_stmt(thd, table,
- info.handle_duplicates);
+ prepare_triggers_for_insert_stmt(thd, table,
+ info.handle_duplicates);
DBUG_RETURN(res);
}
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 64022fa719b..ee6d2d0a572 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -222,7 +222,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
}
- mark_fields_used_by_triggers_for_insert_stmt(thd, table, handle_duplicates);
+ prepare_triggers_for_insert_stmt(thd, table, handle_duplicates);
uint tot_length=0;
bool use_blobs= 0, use_vars= 0;
@@ -532,7 +532,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
Item_field *sql_field;
TABLE *table= table_list->table;
ulonglong id;
- bool no_trans_update_stmt;
+ bool no_trans_update_stmt, err;
DBUG_ENTER("read_fixed_length");
id= 0;
@@ -624,7 +624,9 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
DBUG_RETURN(-1);
}
- if (write_record(thd, table, &info))
+ err= write_record(thd, table, &info);
+ table->auto_increment_field_not_null= FALSE;
+ if (err)
DBUG_RETURN(1);
thd->no_trans_update.stmt= no_trans_update_stmt;
@@ -669,7 +671,7 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
TABLE *table= table_list->table;
uint enclosed_length;
ulonglong id;
- bool no_trans_update_stmt;
+ bool no_trans_update_stmt, err;
DBUG_ENTER("read_sep_field");
enclosed_length=enclosed.length();
@@ -716,8 +718,6 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
DBUG_RETURN(1);
}
field->set_null();
- if (field == table->next_number_field)
- table->auto_increment_field_not_null= TRUE;
if (!field->maybe_null())
{
if (field->type() == FIELD_TYPE_TIMESTAMP)
@@ -803,8 +803,9 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
DBUG_RETURN(-1);
}
-
- if (write_record(thd, table, &info))
+ err= write_record(thd, table, &info);
+ table->auto_increment_field_not_null= FALSE;
+ if (err)
DBUG_RETURN(1);
/*
If auto_increment values are used, save the first one for
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index fa78db50532..8cf3dc022d9 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -3603,7 +3603,16 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
DBUG_RETURN(0);
}
break;
+ case MYSQL_TYPE_FLOAT:
+ case MYSQL_TYPE_DOUBLE:
+ if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
+ fields_info->field_length)) == NULL)
+ DBUG_RETURN(NULL);
+ break;
default:
+ /* Don't let unimplemented types pass through. Could be a grave error. */
+ DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
+
/* this should be changed when Item_empty_string is fixed(in 4.1) */
if (!(item= new Item_empty_string("", 0, cs)))
{
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 8ee762044cc..6836811e7f3 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -407,6 +407,7 @@ static int sort_keys(KEY *a, KEY *b)
set_or_name "SET" or "ENUM" string for warning message
name name of the checked column
typelib list of values for the column
+ dup_val_count returns count of duplicate elements
DESCRIPTION
This function prints an warning for each value in list
@@ -418,11 +419,12 @@ static int sort_keys(KEY *a, KEY *b)
void check_duplicates_in_interval(const char *set_or_name,
const char *name, TYPELIB *typelib,
- CHARSET_INFO *cs)
+ CHARSET_INFO *cs, unsigned int *dup_val_count)
{
TYPELIB tmp= *typelib;
const char **cur_value= typelib->type_names;
unsigned int *cur_length= typelib->type_lengths;
+ *dup_val_count= 0;
for ( ; tmp.count > 1; cur_value++, cur_length++)
{
@@ -435,6 +437,7 @@ void check_duplicates_in_interval(const char *set_or_name,
ER_DUPLICATED_VALUE_IN_TYPE,
ER(ER_DUPLICATED_VALUE_IN_TYPE),
name,*cur_value,set_or_name);
+ (*dup_val_count)++;
}
}
}
@@ -498,6 +501,7 @@ int prepare_create_field(create_field *sql_field,
int *timestamps, int *timestamps_with_niladic,
uint table_flags)
{
+ unsigned int dup_val_count;
DBUG_ENTER("prepare_field");
/*
@@ -573,7 +577,7 @@ int prepare_create_field(create_field *sql_field,
sql_field->unireg_check=Field::INTERVAL_FIELD;
check_duplicates_in_interval("ENUM",sql_field->field_name,
sql_field->interval,
- sql_field->charset);
+ sql_field->charset, &dup_val_count);
break;
case FIELD_TYPE_SET:
sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
@@ -583,7 +587,13 @@ int prepare_create_field(create_field *sql_field,
sql_field->unireg_check=Field::BIT_FIELD;
check_duplicates_in_interval("SET",sql_field->field_name,
sql_field->interval,
- sql_field->charset);
+ sql_field->charset, &dup_val_count);
+ /* Check that count of unique members is not more then 64 */
+ if (sql_field->interval->count - dup_val_count > sizeof(longlong)*8)
+ {
+ my_error(ER_TOO_BIG_SET, MYF(0), sql_field->field_name);
+ DBUG_RETURN(1);
+ }
break;
case FIELD_TYPE_DATE: // Rest of string types
case FIELD_TYPE_NEWDATE:
@@ -1697,6 +1707,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
alias);
DBUG_RETURN(FALSE);
}
+ DBUG_PRINT("info",("1"));
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias);
DBUG_RETURN(TRUE);
}
@@ -1707,6 +1718,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
{
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
goto warn;
+ DBUG_PRINT("info",("2"));
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
goto end;
}
@@ -1725,14 +1737,25 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
{
bool create_if_not_exists =
create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS;
- if (ha_table_exists_in_engine(thd, db, table_name))
+ int retcode = ha_table_exists_in_engine(thd, db, table_name);
+ DBUG_PRINT("info", ("exists_in_engine: %u",retcode));
+ switch (retcode)
{
- DBUG_PRINT("info", ("Table with same name already existed in handler"));
+ case HA_ERR_NO_SUCH_TABLE:
+ /* Normal case, no table exists. we can go and create it */
+ break;
+ case HA_ERR_TABLE_EXIST:
+ DBUG_PRINT("info", ("Table existed in handler"));
- if (create_if_not_exists)
- goto warn;
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
- goto end;
+ if (create_if_not_exists)
+ goto warn;
+ my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
+ goto end;
+ break;
+ default:
+ DBUG_PRINT("info", ("error: %u from storage engine", retcode));
+ my_error(retcode, MYF(0),table_name);
+ goto end;
}
}
@@ -2068,7 +2091,9 @@ static int prepare_for_repair(THD* thd, TABLE_LIST *table_list,
/*
Check if this is a table type that stores index and data separately,
- like ISAM or MyISAM
+ like ISAM or MyISAM. We assume fixed order of engine file name
+ extentions array. First element of engine file name extentions array
+ is meta/index file extention. Second element - data file extention.
*/
if (!ext[0] || !ext[1])
goto end; // No data file
diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h
index 19b2b24a3fe..b029a70ca20 100644
--- a/sql/sql_trigger.h
+++ b/sql/sql_trigger.h
@@ -110,6 +110,11 @@ public:
const char *old_table,
const char *new_db,
const char *new_table);
+ bool has_triggers(trg_event_type event_type,
+ trg_action_time_type action_time)
+ {
+ return (bodies[event_type][action_time] != NULL);
+ }
bool has_delete_triggers()
{
return (bodies[TRG_EVENT_DELETE][TRG_ACTION_BEFORE] ||
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 860d00b5bdd..6f6c4538040 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -436,7 +436,19 @@ int mysql_update(THD *thd,
MODE_STRICT_ALL_TABLES)));
if (table->triggers)
+ {
table->triggers->mark_fields_used(thd, TRG_EVENT_UPDATE);
+ if (table->triggers->has_triggers(TRG_EVENT_UPDATE,
+ TRG_ACTION_AFTER))
+ {
+ /*
+ The table has AFTER UPDATE triggers that might access to subject
+ table and therefore might need update to be done immediately.
+ So we turn-off the batching.
+ */
+ (void) table->file->extra(HA_EXTRA_UPDATE_CANNOT_BATCH);
+ }
+ }
/*
We can use compare_record() to optimize away updates if
@@ -1001,6 +1013,20 @@ int multi_update::prepare(List<Item> &not_used_values,
table->no_keyread=1;
table->used_keys.clear_all();
table->pos_in_table_list= tl;
+ if (table->triggers)
+ {
+ table->triggers->mark_fields_used(thd, TRG_EVENT_UPDATE);
+ if (table->triggers->has_triggers(TRG_EVENT_UPDATE,
+ TRG_ACTION_AFTER))
+ {
+ /*
+ The table has AFTER UPDATE triggers that might access to subject
+ table and therefore might need update to be done immediately.
+ So we turn-off the batching.
+ */
+ (void) table->file->extra(HA_EXTRA_UPDATE_CANNOT_BATCH);
+ }
+ }
}
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index bbb0d11b942..4a50a602121 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1577,7 +1577,7 @@ sp_name:
my_error(ER_SP_WRONG_NAME, MYF(0), $3.str);
MYSQL_YYABORT;
}
- $$= new sp_name($1, $3);
+ $$= new sp_name($1, $3, true);
$$->init_qname(YYTHD);
}
| ident
@@ -1591,7 +1591,7 @@ sp_name:
}
if (thd->copy_db_to(&db.str, &db.length))
MYSQL_YYABORT;
- $$= new sp_name(db, $1);
+ $$= new sp_name(db, $1, false);
if ($$)
$$->init_qname(YYTHD);
}
@@ -5041,7 +5041,7 @@ simple_expr:
| ident '.' ident '(' opt_expr_list ')'
{
LEX *lex= Lex;
- sp_name *name= new sp_name($1, $3);
+ sp_name *name= new sp_name($1, $3, true);
name->init_qname(YYTHD);
sp_add_used_routine(lex, YYTHD, name, TYPE_ENUM_FUNCTION);
@@ -5156,7 +5156,7 @@ simple_expr:
LEX_STRING db;
if (thd->copy_db_to(&db.str, &db.length))
MYSQL_YYABORT;
- sp_name *name= new sp_name(db, $1);
+ sp_name *name= new sp_name(db, $1, false);
if (name)
name->init_qname(thd);
@@ -9050,7 +9050,8 @@ grant_ident:
| table_ident
{
LEX *lex=Lex;
- if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
+ if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,
+ TL_OPTION_UPDATING))
MYSQL_YYABORT;
if (lex->grant == GLOBAL_ACLS)
lex->grant = TABLE_ACLS & ~GRANT_ACL;