summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rwxr-xr-xsql/CMakeLists.txt15
-rw-r--r--sql/MSG00001.binbin0 -> 184 bytes
-rw-r--r--sql/Makefile.am3
-rw-r--r--sql/field.cc14
-rw-r--r--sql/field.h16
-rw-r--r--sql/filesort.cc66
-rw-r--r--sql/ha_federated.cc14
-rw-r--r--sql/ha_innodb.cc10
-rw-r--r--sql/handler.cc56
-rw-r--r--sql/handler.h1
-rw-r--r--sql/item.cc49
-rw-r--r--sql/item.h6
-rw-r--r--sql/item_cmpfunc.cc80
-rw-r--r--sql/item_cmpfunc.h8
-rw-r--r--sql/item_func.cc23
-rw-r--r--sql/item_strfunc.cc65
-rw-r--r--sql/item_timefunc.cc13
-rw-r--r--sql/item_timefunc.h1
-rw-r--r--sql/log.cc142
-rw-r--r--sql/message.h55
-rw-r--r--sql/message.mc8
-rw-r--r--sql/message.rc2
-rw-r--r--sql/my_decimal.cc2
-rw-r--r--sql/mysql_priv.h13
-rw-r--r--sql/mysqld.cc20
-rw-r--r--sql/nt_servc.cc12
-rw-r--r--sql/nt_servc.h14
-rw-r--r--sql/opt_range.cc164
-rw-r--r--sql/opt_range.h13
-rw-r--r--sql/parse_file.cc99
-rw-r--r--sql/parse_file.h9
-rw-r--r--sql/records.cc43
-rw-r--r--sql/set_var.cc67
-rw-r--r--sql/set_var.h47
-rw-r--r--sql/share/errmsg.txt6
-rw-r--r--sql/sp.cc5
-rw-r--r--sql/sp_head.cc13
-rw-r--r--sql/sql_acl.cc8
-rw-r--r--sql/sql_base.cc41
-rw-r--r--sql/sql_cache.cc2
-rw-r--r--sql/sql_class.cc16
-rw-r--r--sql/sql_class.h30
-rw-r--r--sql/sql_cursor.cc5
-rw-r--r--sql/sql_db.cc15
-rw-r--r--sql/sql_delete.cc4
-rw-r--r--sql/sql_help.cc8
-rw-r--r--sql/sql_insert.cc11
-rw-r--r--sql/sql_lex.cc43
-rw-r--r--sql/sql_lex.h59
-rw-r--r--sql/sql_list.h4
-rw-r--r--sql/sql_load.cc4
-rw-r--r--sql/sql_parse.cc245
-rw-r--r--sql/sql_prepare.cc7
-rw-r--r--sql/sql_select.cc102
-rw-r--r--sql/sql_select.h2
-rw-r--r--sql/sql_show.cc42
-rw-r--r--sql/sql_string.h2
-rw-r--r--sql/sql_table.cc8
-rw-r--r--sql/sql_trigger.cc14
-rw-r--r--sql/sql_udf.cc2
-rw-r--r--sql/sql_union.cc1
-rw-r--r--sql/sql_update.cc63
-rw-r--r--sql/sql_view.cc67
-rw-r--r--sql/sql_yacc.yy1840
-rw-r--r--sql/stacktrace.c67
-rw-r--r--sql/structs.h2
-rw-r--r--sql/table.cc24
-rw-r--r--sql/table.h8
-rw-r--r--sql/thr_malloc.cc31
-rw-r--r--sql/tztime.cc22
-rw-r--r--sql/tztime.h3
71 files changed, 3028 insertions, 948 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 631b1d9fdfe..b30014234a2 100755
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -28,10 +28,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/bdb/build_win32
${CMAKE_SOURCE_DIR}/bdb/dbinc)
-SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/message.rc
- ${CMAKE_SOURCE_DIR}/sql/message.h
- ${CMAKE_SOURCE_DIR}/sql/sql_yacc.h
- ${CMAKE_SOURCE_DIR}/sql/sql_yacc.cc
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/sql_yacc.h
+ ${CMAKE_SOURCE_DIR}/sql/sql_yacc.cc
${CMAKE_SOURCE_DIR}/include/mysql_version.h
${CMAKE_SOURCE_DIR}/sql/lex_hash.h
${PROJECT_SOURCE_DIR}/include/mysqld_error.h
@@ -121,13 +119,6 @@ ADD_CUSTOM_COMMAND(
DEPENDS ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
)
-# Windows message file
-ADD_CUSTOM_COMMAND(
- SOURCE ${PROJECT_SOURCE_DIR}/sql/message.mc
- OUTPUT message.rc message.h
- COMMAND mc ARGS ${PROJECT_SOURCE_DIR}/sql/message.mc
- DEPENDS ${PROJECT_SOURCE_DIR}/sql/message.mc)
-
# Gen_lex_hash
# About "mysqlclient_notls", see note in "client/CMakeLists.txt"
ADD_EXECUTABLE(gen_lex_hash gen_lex_hash.cc)
@@ -142,7 +133,7 @@ ADD_DEPENDENCIES(mysqld${MYSQLD_EXE_SUFFIX} gen_lex_hash)
# Remove the auto-generated files as part of 'Clean Solution'
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
- "lex_hash.h;message.rc;message.h;sql_yacc.h;sql_yacc.cc")
+ "lex_hash.h;sql_yacc.h;sql_yacc.cc")
ADD_LIBRARY(udf_example MODULE udf_example.c udf_example.def)
ADD_DEPENDENCIES(udf_example strings)
diff --git a/sql/MSG00001.bin b/sql/MSG00001.bin
new file mode 100644
index 00000000000..89f547694f5
--- /dev/null
+++ b/sql/MSG00001.bin
Binary files differ
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 78a1200b1c5..2a0d59d0ab9 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -120,7 +120,8 @@ DEFS = -DMYSQL_SERVER \
BUILT_SOURCES = sql_yacc.cc sql_yacc.h lex_hash.h
EXTRA_DIST = $(BUILT_SOURCES) nt_servc.cc nt_servc.h \
- message.mc examples/CMakeLists.txt CMakeLists.txt \
+ message.mc message.h message.rc MSG00001.bin \
+ examples/CMakeLists.txt CMakeLists.txt \
udf_example.c udf_example.def
DISTCLEANFILES = lex_hash.h sql_yacc.output
diff --git a/sql/field.cc b/sql/field.cc
index d840034f8dc..8188b51d4d1 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -5372,6 +5372,7 @@ int Field_newdate::store_time(MYSQL_TIME *ltime, timestamp_type time_type)
{
char buff[MAX_DATE_STRING_REP_LENGTH];
String str(buff, sizeof(buff), &my_charset_latin1);
+ tmp= 0;
make_date((DATE_TIME_FORMAT *) 0, ltime, &str);
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATE, 1);
@@ -5608,6 +5609,7 @@ int Field_datetime::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
{
char buff[MAX_DATE_STRING_REP_LENGTH];
String str(buff, sizeof(buff), &my_charset_latin1);
+ tmp= 0;
make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATETIME,1);
@@ -6992,8 +6994,18 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
return 0;
}
- if (from == value.ptr())
+ /*
+ If the 'from' address is in the range of the temporary 'value'-
+ object we need to copy the content to a different location or it will be
+ invalidated when the 'value'-object is reallocated to make room for
+ the new character set.
+ */
+ if (from >= value.ptr() && from <= value.ptr()+value.length())
{
+ /*
+ If content of the 'from'-address is cached in the 'value'-object
+ it is possible that the content needs a character conversion.
+ */
uint32 dummy_offset;
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
{
diff --git a/sql/field.h b/sql/field.h
index 8d771a151a7..2975719a591 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -48,7 +48,8 @@ class Field
Field(const Item &); /* Prevent use of these */
void operator=(Field &);
public:
- static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
+ static void *operator new(size_t size) throw ()
+ { return (void*) sql_alloc((uint) size); }
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
char *ptr; // Position to field in record
@@ -137,7 +138,7 @@ public:
virtual bool eq(Field *field)
{
return (ptr == field->ptr && null_ptr == field->null_ptr &&
- null_bit == field->null_bit);
+ null_bit == field->null_bit && field->type() == type());
}
virtual bool eq_def(Field *field);
@@ -1212,8 +1213,16 @@ public:
class Field_blob :public Field_longstr {
protected:
+ /**
+ The number of bytes used to represent the length of the blob.
+ */
uint packlength;
- String value; // For temporaries
+
+ /**
+ The 'value'-object is a cache fronting the storage engine.
+ */
+ String value;
+
public:
Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
@@ -1488,7 +1497,6 @@ public:
bool eq(Field *field)
{
return (Field::eq(field) &&
- field->type() == type() &&
bit_ptr == ((Field_bit *)field)->bit_ptr &&
bit_ofs == ((Field_bit *)field)->bit_ofs);
}
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 70fc6937b59..f56e5b3a771 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -402,6 +402,56 @@ static byte *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count,
DBUG_RETURN(tmp);
}
+#ifndef DBUG_OFF
+/*
+ Print a text, SQL-like record representation into dbug trace.
+
+ Note: this function is a work in progress: at the moment
+ - column read bitmap is ignored (can print garbage for unused columns)
+ - there is no quoting
+*/
+static void dbug_print_record(TABLE *table, bool print_rowid)
+{
+ char buff[1024];
+ Field **pfield;
+ String tmp(buff,sizeof(buff),&my_charset_bin);
+ DBUG_LOCK_FILE;
+
+ fprintf(DBUG_FILE, "record (");
+ for (pfield= table->field; *pfield ; pfield++)
+ fprintf(DBUG_FILE, "%s%s", (*pfield)->field_name, (pfield[1])? ", ":"");
+ fprintf(DBUG_FILE, ") = ");
+
+ fprintf(DBUG_FILE, "(");
+ for (pfield= table->field; *pfield ; pfield++)
+ {
+ Field *field= *pfield;
+
+ if (field->is_null())
+ fwrite("NULL", sizeof(char), 4, DBUG_FILE);
+
+ if (field->type() == MYSQL_TYPE_BIT)
+ (void) field->val_int_as_str(&tmp, 1);
+ else
+ field->val_str(&tmp);
+
+ fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);
+ if (pfield[1])
+ fwrite(", ", sizeof(char), 2, DBUG_FILE);
+ }
+ fprintf(DBUG_FILE, ")");
+ if (print_rowid)
+ {
+ fprintf(DBUG_FILE, " rowid ");
+ for (uint i=0; i < table->file->ref_length; i++)
+ {
+ fprintf(DBUG_FILE, "%x", (uchar)table->file->ref[i]);
+ }
+ }
+ fprintf(DBUG_FILE, "\n");
+ DBUG_UNLOCK_FILE;
+}
+#endif
/*
Search after sort_keys and write them into tempfile.
@@ -475,25 +525,23 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
current_thd->variables.read_buff_size);
}
- READ_RECORD read_record_info;
if (quick_select)
{
if (select->quick->reset())
DBUG_RETURN(HA_POS_ERROR);
- init_read_record(&read_record_info, current_thd, select->quick->head,
- select, 1, 1);
}
for (;;)
{
if (quick_select)
{
- if ((error= read_record_info.read_record(&read_record_info)))
+ if ((error= select->quick->get_next()))
{
error= HA_ERR_END_OF_FILE;
break;
}
file->position(sort_form->record[0]);
+ DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE););
}
else /* Not quick-select */
{
@@ -550,15 +598,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
if (thd->net.report_error)
break;
}
- if (quick_select)
- {
- /*
- index_merge quick select uses table->sort when retrieving rows, so free
- resoures it has allocated.
- */
- end_read_record(&read_record_info);
- }
- else
+ if (!quick_select)
{
(void) file->extra(HA_EXTRA_NO_CACHE); /* End cacheing of records */
if (!next_pos)
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index 2ccfeba74cb..d4144a41a2a 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -405,6 +405,9 @@ static byte *federated_get_key(FEDERATED_SHARE *share, uint *length,
bool federated_db_init()
{
DBUG_ENTER("federated_db_init");
+ /* the federated engine can be disabled by a command line option */
+ if (have_federated_db == SHOW_OPTION_DISABLED)
+ DBUG_RETURN(TRUE);
if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
goto error;
if (hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
@@ -728,7 +731,10 @@ uint ha_federated::convert_row_to_internal_format(byte *record,
old_ptr= (my_ptrdiff_t) (record - table->record[0]);
(*field)->move_field(old_ptr);
if (!row[x])
+ {
(*field)->set_null();
+ (*field)->reset();
+ }
else
{
(*field)->set_notnull();
@@ -1314,6 +1320,14 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
thr_lock_init(&share->lock);
pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST);
}
+ else
+ {
+ /*
+ Free tmp_share.scheme allocated in the parse_url()
+ as we found share in the hash and tmp_share isn't needed anymore.
+ */
+ my_free((gptr) tmp_share.scheme, MYF(MY_ALLOW_ZERO_PTR));
+ }
share->use_count++;
pthread_mutex_unlock(&federated_mutex);
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 1be6137460b..1c0f8a6e9b3 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -244,8 +244,10 @@ struct show_var_st innodb_status_variables[]= {
(char*) &export_vars.innodb_buffer_pool_pages_flushed, SHOW_LONG},
{"buffer_pool_pages_free",
(char*) &export_vars.innodb_buffer_pool_pages_free, SHOW_LONG},
+#ifdef UNIV_DEBUG
{"buffer_pool_pages_latched",
(char*) &export_vars.innodb_buffer_pool_pages_latched, SHOW_LONG},
+#endif /* UNIV_DEBUG */
{"buffer_pool_pages_misc",
(char*) &export_vars.innodb_buffer_pool_pages_misc, SHOW_LONG},
{"buffer_pool_pages_total",
@@ -4250,7 +4252,7 @@ ha_innobase::rnd_pos(
int error;
uint keynr = active_index;
DBUG_ENTER("rnd_pos");
- DBUG_DUMP("key", (uchar *)pos, ref_length);
+ DBUG_DUMP("key", (uchar*) pos, ref_length);
statistic_increment(current_thd->status_var.ha_read_rnd_count,
&LOCK_status);
@@ -6882,6 +6884,12 @@ ha_innobase::innobase_read_and_init_auto_inc(
from a table when no table has been locked in ::external_lock(). */
prebuilt->trx->n_mysql_tables_in_use++;
+ /* Since we will perform a MySQL SELECT query to determine the
+ auto-inc value, set prebuilt->sql_stat_start = TRUE so that it
+ is performed like any normal SELECT, regardless of the context
+ we come here. */
+ prebuilt->sql_stat_start = TRUE;
+
error = index_last(table->record[1]);
prebuilt->trx->n_mysql_tables_in_use--;
diff --git a/sql/handler.cc b/sql/handler.cc
index 0de772e366b..71d184ad84b 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -817,7 +817,12 @@ int ha_rollback_trans(THD *thd, bool all)
trans->nht=0;
trans->no_2pc=0;
if (is_real_trans)
- thd->transaction.xid_state.xid.null();
+ {
+ if (thd->transaction_rollback_request)
+ thd->transaction.xid_state.rm_error= thd->net.last_errno;
+ else
+ thd->transaction.xid_state.xid.null();
+ }
if (all)
{
thd->variables.tx_isolation=thd->session_tx_isolation;
@@ -1952,8 +1957,53 @@ bool handler::get_error_message(int error, String* buf)
}
+/**
+ Check for incompatible collation changes.
+
+ @retval
+ HA_ADMIN_NEEDS_UPGRADE Table may have data requiring upgrade.
+ @retval
+ 0 No upgrade required.
+*/
+
+int handler::check_collation_compatibility()
+{
+ ulong mysql_version= table->s->mysql_version;
+
+ if (mysql_version < 50048)
+ {
+ KEY *key= table->key_info;
+ KEY *key_end= key + table->s->keys;
+ for (; key < key_end; key++)
+ {
+ KEY_PART_INFO *key_part= key->key_part;
+ KEY_PART_INFO *key_part_end= key_part + key->key_parts;
+ for (; key_part < key_part_end; key_part++)
+ {
+ if (!key_part->fieldnr)
+ continue;
+ Field *field= table->field[key_part->fieldnr - 1];
+ uint cs_number= field->charset()->number;
+ if (mysql_version < 50048 &&
+ (cs_number == 11 || /* ascii_general_ci - bug #29499, bug #27562 */
+ cs_number == 41 || /* latin7_general_ci - bug #29461 */
+ cs_number == 42 || /* latin7_general_cs - bug #29461 */
+ cs_number == 20 || /* latin7_estonian_cs - bug #29461 */
+ cs_number == 21 || /* latin2_hungarian_ci - bug #29461 */
+ cs_number == 22 || /* koi8u_general_ci - bug #29461 */
+ cs_number == 23 || /* cp1251_ukrainian_ci - bug #29461 */
+ cs_number == 26)) /* cp1250_general_ci - bug #29461 */
+ return HA_ADMIN_NEEDS_UPGRADE;
+ }
+ }
+ }
+ return 0;
+}
+
+
int handler::ha_check_for_upgrade(HA_CHECK_OPT *check_opt)
{
+ int error;
KEY *keyinfo, *keyend;
KEY_PART_INFO *keypart, *keypartend;
@@ -1982,6 +2032,10 @@ int handler::ha_check_for_upgrade(HA_CHECK_OPT *check_opt)
}
if (table->s->frm_version != FRM_VER_TRUE_VARCHAR)
return HA_ADMIN_NEEDS_ALTER;
+
+ if ((error= check_collation_compatibility()))
+ return error;
+
return check_for_upgrade(check_opt);
}
diff --git a/sql/handler.h b/sql/handler.h
index aa3377c3868..8706aae5fce 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -787,6 +787,7 @@ protected:
virtual int check_for_upgrade(HA_CHECK_OPT *check_opt)
{ return 0; }
public:
+ int check_collation_compatibility();
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
int check_old_types();
/* to be actually called to get 'check()' functionality*/
diff --git a/sql/item.cc b/sql/item.cc
index bf447581afa..182f4abdfe6 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -429,8 +429,11 @@ uint Item::decimal_precision() const
Item_result restype= result_type();
if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
- return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
- DECIMAL_MAX_PRECISION);
+ {
+ uint prec=
+ my_decimal_length_to_precision(max_length, decimals, unsigned_flag);
+ return min(prec, DECIMAL_MAX_PRECISION);
+ }
return min(max_length, DECIMAL_MAX_PRECISION);
}
@@ -1214,10 +1217,12 @@ Item_name_const::Item_name_const(Item *name_arg, Item *val):
if (!(valid_args= name_item->basic_const_item() &&
(value_item->basic_const_item() ||
((value_item->type() == FUNC_ITEM) &&
- (((Item_func *) value_item)->functype() ==
- Item_func::NEG_FUNC) &&
+ ((((Item_func *) value_item)->functype() ==
+ Item_func::COLLATE_FUNC) ||
+ ((((Item_func *) value_item)->functype() ==
+ Item_func::NEG_FUNC) &&
(((Item_func *) value_item)->key_item()->type() !=
- FUNC_ITEM)))))
+ FUNC_ITEM)))))))
my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
Item::maybe_null= TRUE;
}
@@ -1753,14 +1758,17 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
We need to copy db_name, table_name and field_name because they must
be allocated in the statement memory, not in table memory (the table
structure can go away and pop up again between subsequent executions
- of a prepared statement).
+ of a prepared statement or after the close_tables_for_reopen() call
+ in mysql_multi_update_prepare() or due to wildcard expansion in stored
+ procedures).
*/
- if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
{
if (db_name)
orig_db_name= thd->strdup(db_name);
- orig_table_name= thd->strdup(table_name);
- orig_field_name= thd->strdup(field_name);
+ if (table_name)
+ orig_table_name= thd->strdup(table_name);
+ if (field_name)
+ orig_field_name= thd->strdup(field_name);
/*
We don't restore 'name' in cleanup because it's not changed
during execution. Still we need it to point to persistent
@@ -4217,7 +4225,12 @@ Item *Item_field::equal_fields_propagator(byte *arg)
item= this;
else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
{
- if (item && cmp_context != INT_RESULT)
+ /*
+ We don't need to zero-fill timestamp columns here because they will be
+ first converted to a string (in date/time format) and compared as such if
+ compared with another string.
+ */
+ if (item && field->type() != FIELD_TYPE_TIMESTAMP && cmp_context != INT_RESULT)
convert_zerofill_number_to_string(&item, (Field_num *)field);
else
item= this;
@@ -5761,6 +5774,10 @@ void Item_ref::make_field(Send_field *field)
field->table_name= table_name;
if (db_name)
field->db_name= db_name;
+ if (orig_field_name)
+ field->org_col_name= orig_field_name;
+ if (orig_table_name)
+ field->org_table_name= orig_table_name;
}
@@ -6039,6 +6056,13 @@ Item *Item_default_value::transform(Item_transformer transformer, byte *args)
{
DBUG_ASSERT(!current_thd->is_stmt_prepare());
+ /*
+ If the value of arg is NULL, then this object represents a constant,
+ so further transformation is unnecessary (and impossible).
+ */
+ if (!arg)
+ return 0;
+
Item *new_item= arg->transform(transformer, args);
if (!new_item)
return 0;
@@ -6838,8 +6862,9 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
{
decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
- int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
- + decimals, DECIMAL_MAX_PRECISION);
+ int item_int_part= item->decimal_int_part();
+ int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
+ int precision= min(item_prec, DECIMAL_MAX_PRECISION);
unsigned_flag&= item->unsigned_flag;
max_length= my_decimal_precision_to_length(precision, decimals,
unsigned_flag);
diff --git a/sql/item.h b/sql/item.h
index a948c5a45f7..250bb3f67ef 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -439,9 +439,9 @@ class Item {
Item(const Item &); /* Prevent use of these */
void operator=(Item &);
public:
- static void *operator new(size_t size)
+ static void *operator new(size_t size) throw ()
{ return (void*) sql_alloc((uint) size); }
- static void *operator new(size_t size, MEM_ROOT *mem_root)
+ static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return (void*) alloc_root(mem_root, (uint) size); }
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
@@ -1817,7 +1817,7 @@ class Item_empty_string :public Item_string
public:
Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
- { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
+ { name=(char*) header; max_length= length * collation.collation->mbmaxlen; }
void make_field(Send_field *field);
};
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 16f3e51d615..3b1d18b4252 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -745,11 +745,11 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
obtained value
*/
-ulonglong
+longlong
get_time_value(THD *thd, Item ***item_arg, Item **cache_arg,
Item *warn_item, bool *is_null)
{
- ulonglong value;
+ longlong value;
Item *item= **item_arg;
MYSQL_TIME ltime;
@@ -761,7 +761,7 @@ get_time_value(THD *thd, Item ***item_arg, Item **cache_arg,
else
{
*is_null= item->get_time(&ltime);
- value= !*is_null ? TIME_to_ulonglong_datetime(&ltime) : 0;
+ value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(&ltime) : 0;
}
/*
Do not cache GET_USER_VAR() function as its const_item() may return TRUE
@@ -886,11 +886,11 @@ void Arg_comparator::set_datetime_cmp_func(Item **a1, Item **b1)
obtained value
*/
-ulonglong
+longlong
get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
Item *warn_item, bool *is_null)
{
- ulonglong value= 0;
+ longlong value= 0;
String buf, *str= 0;
Item *item= **item_arg;
@@ -925,7 +925,7 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
enum_field_types f_type= warn_item->field_type();
timestamp_type t_type= f_type ==
MYSQL_TYPE_DATE ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME;
- value= get_date_from_str(thd, str, t_type, warn_item->name, &error);
+ value= (longlong) get_date_from_str(thd, str, t_type, warn_item->name, &error);
/*
If str did not contain a valid date according to the current
SQL_MODE, get_date_from_str() has already thrown a warning,
@@ -966,19 +966,24 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
1 if items are equal or both are null
0 otherwise
If is_nulls_eq is FALSE:
- -1 a < b or one of items is null
+ -1 a < b or at least one item is null
0 a == b
1 a > b
+ See the table:
+ is_nulls_eq | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
+ a_is_null | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
+ b_is_null | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 |
+ result | 1 | 0 | 0 |0/1|-1 |-1 |-1 |-1/0/1|
*/
int Arg_comparator::compare_datetime()
{
- bool is_null= FALSE;
- ulonglong a_value, b_value;
+ bool a_is_null, b_is_null;
+ longlong a_value, b_value;
/* Get DATE/DATETIME/TIME value of the 'a' item. */
- a_value= (*get_value_func)(thd, &a, &a_cache, *b, &is_null);
- if (!is_nulls_eq && is_null)
+ a_value= (*get_value_func)(thd, &a, &a_cache, *b, &a_is_null);
+ if (!is_nulls_eq && a_is_null)
{
if (owner)
owner->null_value= 1;
@@ -986,14 +991,15 @@ int Arg_comparator::compare_datetime()
}
/* Get DATE/DATETIME/TIME value of the 'b' item. */
- b_value= (*get_value_func)(thd, &b, &b_cache, *a, &is_null);
- if (is_null)
+ b_value= (*get_value_func)(thd, &b, &b_cache, *a, &b_is_null);
+ if (a_is_null || b_is_null)
{
if (owner)
owner->null_value= is_nulls_eq ? 0 : 1;
- return is_nulls_eq ? 1 : -1;
+ return is_nulls_eq ? (a_is_null == b_is_null) : -1;
}
+ /* Here we have two not-NULL values. */
if (owner)
owner->null_value= 0;
@@ -1428,7 +1434,8 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
}
not_null_tables_cache= args[0]->not_null_tables();
with_sum_func= args[0]->with_sum_func;
- const_item_cache= args[0]->const_item();
+ if ((const_item_cache= args[0]->const_item()))
+ cache->store(args[0]);
return 0;
}
@@ -2098,8 +2105,11 @@ Item_func_ifnull::fix_length_and_dec()
uint Item_func_ifnull::decimal_precision() const
{
- int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
- return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
+ int arg0_int_part= args[0]->decimal_int_part();
+ int arg1_int_part= args[1]->decimal_int_part();
+ int max_int_part= max(arg0_int_part, arg1_int_part);
+ int precision= max_int_part + decimals;
+ return min(precision, DECIMAL_MAX_PRECISION);
}
@@ -2281,8 +2291,9 @@ Item_func_if::fix_length_and_dec()
uint Item_func_if::decimal_precision() const
{
- int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
- decimals);
+ int arg1_prec= args[1]->decimal_int_part();
+ int arg2_prec= args[2]->decimal_int_part();
+ int precision=max(arg1_prec,arg2_prec) + decimals;
return min(precision, DECIMAL_MAX_PRECISION);
}
@@ -4337,8 +4348,20 @@ void Item_func_like::cleanup()
#ifdef USE_REGEX
-bool
-Item_func_regex::regcomp(bool send_error)
+/**
+ @brief Compile regular expression.
+
+ @param[in] send_error send error message if any.
+
+ @details Make necessary character set conversion then
+ compile regular expression passed in the args[1].
+
+ @retval 0 success.
+ @retval 1 error occurred.
+ @retval -1 given null regular expression.
+ */
+
+int Item_func_regex::regcomp(bool send_error)
{
char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),&my_charset_bin);
@@ -4346,12 +4369,12 @@ Item_func_regex::regcomp(bool send_error)
int error;
if (args[1]->null_value)
- return TRUE;
+ return -1;
if (regex_compiled)
{
if (!stringcmp(res, &prev_regexp))
- return FALSE;
+ return 0;
prev_regexp.copy(*res);
my_regfree(&preg);
regex_compiled= 0;
@@ -4363,7 +4386,7 @@ Item_func_regex::regcomp(bool send_error)
uint dummy_errors;
if (conv.copy(res->ptr(), res->length(), res->charset(),
regex_lib_charset, &dummy_errors))
- return TRUE;
+ return 1;
res= &conv;
}
@@ -4375,10 +4398,10 @@ Item_func_regex::regcomp(bool send_error)
(void) my_regerror(error, &preg, buff, sizeof(buff));
my_error(ER_REGEXP_ERROR, MYF(0), buff);
}
- return TRUE;
+ return 1;
}
regex_compiled= 1;
- return FALSE;
+ return 0;
}
@@ -4416,13 +4439,14 @@ Item_func_regex::fix_fields(THD *thd, Item **ref)
const_item_cache=args[0]->const_item() && args[1]->const_item();
if (!regex_compiled && args[1]->const_item())
{
- if (args[1]->null_value)
+ int comp_res= regcomp(TRUE);
+ if (comp_res == -1)
{ // Will always return NULL
maybe_null=1;
fixed= 1;
return FALSE;
}
- if (regcomp(TRUE))
+ else if (comp_res)
return TRUE;
regex_is_const= 1;
maybe_null= args[0]->maybe_null;
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index d250e1b366a..db831c7030c 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -42,8 +42,8 @@ class Arg_comparator: public Sql_alloc
bool is_nulls_eq; // TRUE <=> compare for the EQUAL_FUNC
enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
- ulonglong (*get_value_func)(THD *thd, Item ***item_arg, Item **cache_arg,
- Item *warn_item, bool *is_null);
+ longlong (*get_value_func)(THD *thd, Item ***item_arg, Item **cache_arg,
+ Item *warn_item, bool *is_null);
public:
DTCollation cmp_collation;
@@ -1028,7 +1028,7 @@ public:
*/
class cmp_item_datetime :public cmp_item
{
- ulonglong value;
+ longlong value;
public:
THD *thd;
/* Item used for issuing warnings. */
@@ -1323,7 +1323,7 @@ class Item_func_regex :public Item_bool_func
CHARSET_INFO *regex_lib_charset;
int regex_lib_flags;
String conv;
- bool regcomp(bool send_error);
+ int regcomp(bool send_error);
public:
Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b),
regex_compiled(0),regex_is_const(0) {}
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 1238efbb653..394556140c4 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1156,9 +1156,10 @@ my_decimal *Item_func_plus::decimal_op(my_decimal *decimal_value)
void Item_func_additive_op::result_precision()
{
decimals= max(args[0]->decimals, args[1]->decimals);
- int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
- args[1]->decimal_precision() - args[1]->decimals);
- int precision= min(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
+ int arg1_int= args[0]->decimal_precision() - args[0]->decimals;
+ int arg2_int= args[1]->decimal_precision() - args[1]->decimals;
+ int est_prec= max(arg1_int, arg2_int) + 1 + decimals;
+ int precision= min(est_prec, DECIMAL_MAX_PRECISION);
/* Integer operations keep unsigned_flag if one of arguments is unsigned */
if (result_type() == INT_RESULT)
@@ -1267,8 +1268,8 @@ void Item_func_mul::result_precision()
else
unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
- int precision= min(args[0]->decimal_precision() + args[1]->decimal_precision(),
- DECIMAL_MAX_PRECISION);
+ uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision();
+ uint precision= min(est_prec, DECIMAL_MAX_PRECISION);
max_length= my_decimal_precision_to_length(precision, decimals,unsigned_flag);
}
@@ -1315,8 +1316,10 @@ my_decimal *Item_func_div::decimal_op(my_decimal *decimal_value)
void Item_func_div::result_precision()
{
- uint precision=min(args[0]->decimal_precision() + prec_increment,
+ uint precision=min(args[0]->decimal_precision() +
+ args[1]->decimals + prec_increment,
DECIMAL_MAX_PRECISION);
+
/* Integer operations keep unsigned_flag if one of arguments is unsigned */
if (result_type() == INT_RESULT)
unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
@@ -2272,7 +2275,7 @@ void Item_func_min_max::fix_length_and_dec()
uint Item_func_min_max::cmp_datetimes(ulonglong *value)
{
- ulonglong min_max;
+ longlong min_max;
uint min_max_idx= 0;
LINT_INIT(min_max);
@@ -2280,7 +2283,7 @@ uint Item_func_min_max::cmp_datetimes(ulonglong *value)
{
Item **arg= args + i;
bool is_null;
- ulonglong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null);
+ longlong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null);
if ((null_value= args[i]->null_value))
return 0;
if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
@@ -5021,7 +5024,9 @@ bool Item_func_match::fix_index()
for (keynr=0 ; keynr < table->s->keys ; keynr++)
{
if ((table->key_info[keynr].flags & HA_FULLTEXT) &&
- (table->s->keys_in_use.is_set(keynr)))
+ (flags & FT_BOOL ? table->keys_in_use_for_query.is_set(keynr) :
+ table->s->keys_in_use.is_set(keynr)))
+
{
ft_to_key[fts]=keynr;
ft_cnt[fts]=0;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index c443364ce52..d1e3f45bba1 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -3258,7 +3258,8 @@ static char clock_seq_and_node_str[]="-0000-000000000000";
/* number of 100-nanosecond intervals between
1582-10-15 00:00:00.00 and 1970-01-01 00:00:00.00 */
-#define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * 1000 * 10 )
+#define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * \
+ 1000 * 1000 * 10)
#define UUID_VERSION 0x1000
#define UUID_VARIANT 0x8000
@@ -3317,24 +3318,64 @@ String *Item_func_uuid::val_str(String *str)
set_clock_seq_str();
}
- ulonglong tv=my_getsystime() + UUID_TIME_OFFSET + nanoseq;
- if (unlikely(tv < uuid_time))
- set_clock_seq_str();
- else if (unlikely(tv == uuid_time))
+ ulonglong tv= my_getsystime() + UUID_TIME_OFFSET + nanoseq;
+
+ if (likely(tv > uuid_time))
{
- /* special protection from low-res system clocks */
- nanoseq++;
- tv++;
+ /*
+ Current time is ahead of last timestamp, as it should be.
+ If we "borrowed time", give it back, just as long as we
+ stay ahead of the previous timestamp.
+ */
+ if (nanoseq)
+ {
+ DBUG_ASSERT((tv > uuid_time) && (nanoseq > 0));
+ /*
+ -1 so we won't make tv= uuid_time for nanoseq >= (tv - uuid_time)
+ */
+ ulong delta= min(nanoseq, (ulong) (tv - uuid_time -1));
+ tv-= delta;
+ nanoseq-= delta;
+ }
}
else
{
- if (nanoseq)
+ if (unlikely(tv == uuid_time))
{
- tv-=nanoseq;
- nanoseq=0;
+ /*
+ For low-res system clocks. If several requests for UUIDs
+ end up on the same tick, we add a nano-second to make them
+ different.
+ ( current_timestamp + nanoseq * calls_in_this_period )
+ may end up > next_timestamp; this is OK. Nonetheless, we'll
+ try to unwind nanoseq when we get a chance to.
+ If nanoseq overflows, we'll start over with a new numberspace
+ (so the if() below is needed so we can avoid the ++tv and thus
+ match the follow-up if() if nanoseq overflows!).
+ */
+ if (likely(++nanoseq))
+ ++tv;
+ }
+
+ if (unlikely(tv <= uuid_time))
+ {
+ /*
+ If the admin changes the system clock (or due to Daylight
+ Saving Time), the system clock may be turned *back* so we
+ go through a period once more for which we already gave out
+ UUIDs. To avoid duplicate UUIDs despite potentially identical
+ times, we make a new random component.
+ We also come here if the nanoseq "borrowing" overflows.
+ In either case, we throw away any nanoseq borrowing since it's
+ irrelevant in the new numberspace.
+ */
+ set_clock_seq_str();
+ tv= my_getsystime() + UUID_TIME_OFFSET;
+ nanoseq= 0;
+ DBUG_PRINT("uuid",("making new numberspace"));
}
- DBUG_ASSERT(tv > uuid_time);
}
+
uuid_time=tv;
pthread_mutex_unlock(&LOCK_uuid_generator);
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 0cb3c963dad..e9e92952908 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2550,6 +2550,8 @@ void Item_char_typecast::fix_length_and_dec()
and thus avoid unnecessary character set conversion.
- If the argument is not a number, then from_cs is set to
the argument's charset.
+
+ Note (TODO): we could use repertoire technique here.
*/
from_cs= (args[0]->result_type() == INT_RESULT ||
args[0]->result_type() == DECIMAL_RESULT ||
@@ -2557,12 +2559,13 @@ void Item_char_typecast::fix_length_and_dec()
(cast_cs->mbminlen == 1 ? cast_cs : &my_charset_latin1) :
args[0]->collation.collation;
charset_conversion= (cast_cs->mbmaxlen > 1) ||
- !my_charset_same(from_cs, cast_cs) &&
- from_cs != &my_charset_bin &&
- cast_cs != &my_charset_bin;
+ (!my_charset_same(from_cs, cast_cs) &&
+ from_cs != &my_charset_bin &&
+ cast_cs != &my_charset_bin);
collation.set(cast_cs, DERIVATION_IMPLICIT);
- char_length= (cast_length >= 0) ? cast_length :
- args[0]->max_length/from_cs->mbmaxlen;
+ char_length= (cast_length >= 0) ?
+ cast_length :
+ args[0]->max_length / args[0]->collation.collation->mbmaxlen;
max_length= char_length * cast_cs->mbmaxlen;
}
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 7960c03d2e5..81a6c3e98bd 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -408,6 +408,7 @@ public:
{
return save_time_in_field(field);
}
+ bool result_as_longlong() { return TRUE; }
};
diff --git a/sql/log.cc b/sql/log.cc
index 9e112e46c65..5a1cfe46686 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1193,6 +1193,7 @@ int MYSQL_LOG::purge_logs(const char *to_log,
int error;
bool exit_loop= 0;
LOG_INFO log_info;
+ THD *thd= current_thd;
DBUG_ENTER("purge_logs");
DBUG_PRINT("info",("to_log= %s",to_log));
@@ -1218,10 +1219,13 @@ int MYSQL_LOG::purge_logs(const char *to_log,
/*
It's not fatal if we can't stat a log file that does not exist;
If we could not stat, we won't delete.
- */
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
- ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
- log_info.log_file_name);
+ */
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+ log_info.log_file_name);
+ }
sql_print_information("Failed to execute my_stat on file '%s'",
log_info.log_file_name);
my_errno= 0;
@@ -1231,13 +1235,24 @@ int MYSQL_LOG::purge_logs(const char *to_log,
/*
Other than ENOENT are fatal
*/
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
- ER_BINLOG_PURGE_FATAL_ERR,
- "a problem with getting info on being purged %s; "
- "consider examining correspondence "
- "of your binlog index file "
- "to the actual binlog files",
- log_info.log_file_name);
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+ ER_BINLOG_PURGE_FATAL_ERR,
+ "a problem with getting info on being purged %s; "
+ "consider examining correspondence "
+ "of your binlog index file "
+ "to the actual binlog files",
+ log_info.log_file_name);
+ }
+ else
+ {
+ sql_print_information("Failed to delete log file '%s'; "
+ "consider examining correspondence "
+ "of your binlog index file "
+ "to the actual binlog files",
+ log_info.log_file_name);
+ }
error= LOG_INFO_FATAL;
goto err;
}
@@ -1254,22 +1269,36 @@ int MYSQL_LOG::purge_logs(const char *to_log,
{
if (my_errno == ENOENT)
{
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
- ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
- log_info.log_file_name);
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+ log_info.log_file_name);
+ }
sql_print_information("Failed to delete file '%s'",
log_info.log_file_name);
my_errno= 0;
}
else
{
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
- ER_BINLOG_PURGE_FATAL_ERR,
- "a problem with deleting %s; "
- "consider examining correspondence "
- "of your binlog index file "
- "to the actual binlog files",
- log_info.log_file_name);
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+ ER_BINLOG_PURGE_FATAL_ERR,
+ "a problem with deleting %s; "
+ "consider examining correspondence "
+ "of your binlog index file "
+ "to the actual binlog files",
+ log_info.log_file_name);
+ }
+ else
+ {
+ sql_print_information("Failed to delete file '%s'; "
+ "consider examining correspondence "
+ "of your binlog index file "
+ "to the actual binlog files",
+ log_info.log_file_name);
+ }
error= LOG_INFO_FATAL;
goto err;
}
@@ -1316,7 +1345,8 @@ int MYSQL_LOG::purge_logs_before_date(time_t purge_time)
int error;
LOG_INFO log_info;
MY_STAT stat_area;
-
+ THD *thd= current_thd;
+
DBUG_ENTER("purge_logs_before_date");
pthread_mutex_lock(&LOCK_index);
@@ -1338,12 +1368,15 @@ int MYSQL_LOG::purge_logs_before_date(time_t purge_time)
{
/*
It's not fatal if we can't stat a log file that does not exist.
- */
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
- ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
- log_info.log_file_name);
- sql_print_information("Failed to execute my_stat on file '%s'",
- log_info.log_file_name);
+ */
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+ log_info.log_file_name);
+ }
+ sql_print_information("Failed to execute my_stat on file '%s'",
+ log_info.log_file_name);
my_errno= 0;
}
else
@@ -1351,13 +1384,21 @@ int MYSQL_LOG::purge_logs_before_date(time_t purge_time)
/*
Other than ENOENT are fatal
*/
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
- ER_BINLOG_PURGE_FATAL_ERR,
- "a problem with getting info on being purged %s; "
- "consider examining correspondence "
- "of your binlog index file "
- "to the actual binlog files",
- log_info.log_file_name);
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+ ER_BINLOG_PURGE_FATAL_ERR,
+ "a problem with getting info on being purged %s; "
+ "consider examining correspondence "
+ "of your binlog index file "
+ "to the actual binlog files",
+ log_info.log_file_name);
+ }
+ else
+ {
+ sql_print_information("Failed to delete log file '%s'",
+ log_info.log_file_name);
+ }
error= LOG_INFO_FATAL;
goto err;
}
@@ -1371,22 +1412,33 @@ int MYSQL_LOG::purge_logs_before_date(time_t purge_time)
if (my_errno == ENOENT)
{
/* It's not fatal even if we can't delete a log file */
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
- ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
- log_info.log_file_name);
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+ log_info.log_file_name);
+ }
sql_print_information("Failed to delete file '%s'",
log_info.log_file_name);
my_errno= 0;
}
else
{
- push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
- ER_BINLOG_PURGE_FATAL_ERR,
- "a problem with deleting %s; "
- "consider examining correspondence "
- "of your binlog index file "
- "to the actual binlog files",
- log_info.log_file_name);
+ if (thd)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+ ER_BINLOG_PURGE_FATAL_ERR,
+ "a problem with deleting %s; "
+ "consider examining correspondence "
+ "of your binlog index file "
+ "to the actual binlog files",
+ log_info.log_file_name);
+ }
+ else
+ {
+ sql_print_information("Failed to delete log file '%s'",
+ log_info.log_file_name);
+ }
error= LOG_INFO_FATAL;
goto err;
}
diff --git a/sql/message.h b/sql/message.h
new file mode 100644
index 00000000000..0e7c282d5a1
--- /dev/null
+++ b/sql/message.h
@@ -0,0 +1,55 @@
+/*
+ To change or add messages mysqld writes to the Windows error log, run
+ mc.exe message.mc
+ and checkin generated messages.h, messages.rc and msg000001.bin under the
+ source control.
+ mc.exe can be installed with Windows SDK, some Visual Studio distributions
+ do not include it.
+*/
+//
+// Values are 32 bit values layed out as follows:
+//
+// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +---+-+-+-----------------------+-------------------------------+
+// |Sev|C|R| Facility | Code |
+// +---+-+-+-----------------------+-------------------------------+
+//
+// where
+//
+// Sev - is the severity code
+//
+// 00 - Success
+// 01 - Informational
+// 10 - Warning
+// 11 - Error
+//
+// C - is the Customer code flag
+//
+// R - is a reserved bit
+//
+// Facility - is the facility code
+//
+// Code - is the facility's status code
+//
+//
+// Define the facility codes
+//
+
+
+//
+// Define the severity codes
+//
+
+
+//
+// MessageId: MSG_DEFAULT
+//
+// MessageText:
+//
+// %1For more information, see Help and Support Center at http://www.mysql.com.
+//
+//
+//
+#define MSG_DEFAULT 0xC0000064L
+
diff --git a/sql/message.mc b/sql/message.mc
index a1a7c8cff7e..8d68d599365 100644
--- a/sql/message.mc
+++ b/sql/message.mc
@@ -1,3 +1,11 @@
+;/*
+; To change or add messages mysqld writes to the Windows error log, run
+; mc.exe message.mc
+; and checkin generated messages.h, messages.rc and msg000001.bin under the
+; source control.
+; mc.exe can be installed with Windows SDK, some Visual Studio distributions
+; do not include it.
+;*/
MessageId = 100
Severity = Error
Facility = Application
diff --git a/sql/message.rc b/sql/message.rc
new file mode 100644
index 00000000000..116522b7d48
--- /dev/null
+++ b/sql/message.rc
@@ -0,0 +1,2 @@
+LANGUAGE 0x9,0x1
+1 11 MSG00001.bin
diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc
index 31a5b09370a..a235edbd73c 100644
--- a/sql/my_decimal.cc
+++ b/sql/my_decimal.cc
@@ -216,7 +216,7 @@ my_decimal *date2my_decimal(MYSQL_TIME *ltime, my_decimal *dec)
date = (ltime->year*100L + ltime->month)*100L + ltime->day;
if (ltime->time_type > MYSQL_TIMESTAMP_DATE)
date= ((date*100L + ltime->hour)*100L+ ltime->minute)*100L + ltime->second;
- if (int2my_decimal(E_DEC_FATAL_ERROR, date, FALSE, dec))
+ if (int2my_decimal(E_DEC_FATAL_ERROR, ltime->neg ? -date : date, FALSE, dec))
return dec;
if (ltime->second_part)
{
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index c1694cbbbe4..e39f8431b16 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -439,6 +439,7 @@ MY_LOCALE *my_locale_by_number(uint number);
#define UNCACHEABLE_PREPARE 16
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
#define UNCACHEABLE_UNITED 32
+#define UNCACHEABLE_CHECKOPTION 64
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
#define UNDEF_POS (-1)
@@ -632,6 +633,7 @@ LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name)
LEX_USER *get_current_user(THD *thd, LEX_USER *user);
bool check_string_length(LEX_STRING *str,
const char *err_msg, uint max_length);
+bool check_host_name(LEX_STRING *str);
enum enum_mysql_completiontype {
ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7,
@@ -1284,6 +1286,7 @@ extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[],
mysql_unpacked_real_data_home[],
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
+extern int mysql_unpacked_real_data_home_len;
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
extern MY_TMPDIR mysql_tmpdir_list;
extern const char *command_name[];
@@ -1574,14 +1577,14 @@ void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
String *str);
void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
String *str);
-ulonglong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
- Item *warn_item, bool *is_null);
+longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
+ Item *warn_item, bool *is_null);
int test_if_number(char *str,int *res,bool allow_wildcards);
void change_byte(byte *,uint,char,char);
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
- SQL_SELECT *select,
- int use_record_cache, bool print_errors);
+ SQL_SELECT *select, int use_record_cache,
+ bool print_errors, bool disable_rr_cache);
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
bool print_error, uint idx);
void end_read_record(READ_RECORD *info);
@@ -1787,6 +1790,8 @@ inline void kill_delayed_threads(void) {}
#define check_stack_overrun(A, B, C) 0
#endif
+extern "C" int test_if_data_home_dir(const char *dir);
+
#endif /* MYSQL_CLIENT */
#endif
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index d591ce46af7..4412b4e3f66 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -480,6 +480,7 @@ char mysql_real_data_home[FN_REFLEN],
*opt_init_file, *opt_tc_log_file,
mysql_unpacked_real_data_home[FN_REFLEN],
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
+int mysql_unpacked_real_data_home_len;
char *mysql_data_home= mysql_real_data_home;
const key_map key_map_empty(0);
key_map key_map_full(0); // Will be initialized later
@@ -3034,12 +3035,14 @@ static int init_common_variables(const char *conf_file_name, int argc,
sys_init_connect.value_length= strlen(opt_init_connect);
else
sys_init_connect.value=my_strdup("",MYF(0));
+ sys_init_connect.is_os_charset= TRUE;
sys_init_slave.value_length= 0;
if ((sys_init_slave.value= opt_init_slave))
sys_init_slave.value_length= strlen(opt_init_slave);
else
sys_init_slave.value=my_strdup("",MYF(0));
+ sys_init_slave.is_os_charset= TRUE;
if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
return 1;
@@ -3839,6 +3842,9 @@ we force server id to 2, but this MySQL server will not act as a slave.");
: mysqld_unix_port),
mysqld_port,
MYSQL_COMPILATION_COMMENT);
+#if defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
+ Service.SetRunning();
+#endif
#if defined(__NT__) || defined(HAVE_SMEM)
handle_connections_methods();
@@ -6579,7 +6585,9 @@ struct show_var_st status_vars[]= {
{"Qcache_queries_in_cache", (char*) &query_cache.queries_in_cache, SHOW_LONG_CONST},
{"Qcache_total_blocks", (char*) &query_cache.total_blocks, SHOW_LONG_CONST},
#endif /*HAVE_QUERY_CACHE*/
- {"Questions", (char*) 0, SHOW_QUESTION},
+ {"Questions", (char*) offsetof(STATUS_VAR, questions),
+ SHOW_LONG_STATUS},
+
{"Rpl_status", (char*) 0, SHOW_RPL_STATUS},
{"Select_full_join", (char*) offsetof(STATUS_VAR, select_full_join_count), SHOW_LONG_STATUS},
{"Select_full_range_join", (char*) offsetof(STATUS_VAR, select_full_range_join_count), SHOW_LONG_STATUS},
@@ -6712,6 +6720,7 @@ static void mysql_init_variables(void)
/* Things reset to zero */
opt_skip_slave_start= opt_reckless_slave = 0;
mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
+ myisam_test_invalid_symlink= test_if_data_home_dir;
opt_log= opt_slow_log= 0;
opt_update_log= 0;
opt_bin_log= 0;
@@ -7762,9 +7771,12 @@ static void fix_paths(void)
pos[1]= 0;
}
convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS);
- (void) fn_format(buff, mysql_real_data_home, "", "",
- (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
- (void) unpack_dirname(mysql_unpacked_real_data_home, buff);
+ my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0));
+ mysql_unpacked_real_data_home_len= strlen(mysql_unpacked_real_data_home);
+ if (mysql_unpacked_real_data_home[mysql_unpacked_real_data_home_len-1] == FN_LIBCHAR)
+ --mysql_unpacked_real_data_home_len;
+
+
convert_dirname(language,language,NullS);
(void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
(void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
diff --git a/sql/nt_servc.cc b/sql/nt_servc.cc
index a04f284a3de..e570898f373 100644
--- a/sql/nt_servc.cc
+++ b/sql/nt_servc.cc
@@ -245,10 +245,6 @@ void NTService::ServiceMain(DWORD argc, LPTSTR *argv)
if (!pService->StartService())
goto error;
- // Check that the service is now running.
- if (!pService->SetStatus(SERVICE_RUNNING,NO_ERROR, 0, 0, 0))
- goto error;
-
// wait for exit event
WaitForSingleObject (pService->hExitEvent, INFINITE);
@@ -264,6 +260,14 @@ error:
return;
}
+
+void NTService::SetRunning()
+{
+ if (pService)
+ pService->SetStatus(SERVICE_RUNNING,NO_ERROR, 0, 0, 0);
+}
+
+
/* ------------------------------------------------------------------------
StartService() - starts the appliaction thread
-------------------------------------------------------------------------- */
diff --git a/sql/nt_servc.h b/sql/nt_servc.h
index a3c12569114..9b689e434e1 100644
--- a/sql/nt_servc.h
+++ b/sql/nt_servc.h
@@ -56,7 +56,19 @@ class NTService
BOOL IsService(LPCSTR ServiceName);
BOOL got_service_option(char **argv, char *service_option);
BOOL is_super_user();
- void Stop(void); //to be called from app. to stop service
+
+ /*
+ SetRunning() is to be called by the application
+ when initialization completes and it can accept
+ stop request
+ */
+ void SetRunning(void);
+
+ /*
+ Stop() is to be called by the application to stop
+ the service
+ */
+ void Stop(void);
protected:
LPSTR ServiceName;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 17a4701b515..204ebdb6f33 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -492,6 +492,7 @@ public:
keys_map.clear_all();
bzero((char*) keys,sizeof(keys));
}
+ SEL_TREE(SEL_TREE *arg, struct st_qsel_param *param);
SEL_ARG *keys[MAX_KEY];
key_map keys_map; /* bitmask of non-NULL elements in keys */
@@ -648,6 +649,7 @@ public:
trees_next(trees),
trees_end(trees + PREALLOCED_TREES)
{}
+ SEL_IMERGE (SEL_IMERGE *arg, PARAM *param);
int or_sel_tree(PARAM *param, SEL_TREE *tree);
int or_sel_tree_with_checks(PARAM *param, SEL_TREE *new_tree);
int or_sel_imerge_with_checks(PARAM *param, SEL_IMERGE* imerge);
@@ -764,6 +766,61 @@ int SEL_IMERGE::or_sel_imerge_with_checks(PARAM *param, SEL_IMERGE* imerge)
}
+SEL_TREE::SEL_TREE(SEL_TREE *arg, PARAM *param): Sql_alloc()
+{
+ keys_map= arg->keys_map;
+ type= arg->type;
+ for (int idx= 0; idx < MAX_KEY; idx++)
+ {
+ if ((keys[idx]= arg->keys[idx]))
+ keys[idx]->increment_use_count(1);
+ }
+
+ List_iterator<SEL_IMERGE> it(arg->merges);
+ for (SEL_IMERGE *el= it++; el; el= it++)
+ {
+ SEL_IMERGE *merge= new SEL_IMERGE(el, param);
+ if (!merge || merge->trees == merge->trees_next)
+ {
+ merges.empty();
+ return;
+ }
+ merges.push_back (merge);
+ }
+}
+
+
+SEL_IMERGE::SEL_IMERGE (SEL_IMERGE *arg, PARAM *param) : Sql_alloc()
+{
+ uint elements= (arg->trees_end - arg->trees);
+ if (elements > PREALLOCED_TREES)
+ {
+ uint size= elements * sizeof (SEL_TREE **);
+ if (!(trees= (SEL_TREE **)alloc_root(param->mem_root, size)))
+ goto mem_err;
+ }
+ else
+ trees= &trees_prealloced[0];
+
+ trees_next= trees;
+ trees_end= trees + elements;
+
+ for (SEL_TREE **tree = trees, **arg_tree= arg->trees; tree < trees_end;
+ tree++, arg_tree++)
+ {
+ if (!(*tree= new SEL_TREE(*arg_tree, param)))
+ goto mem_err;
+ }
+
+ return;
+
+mem_err:
+ trees= &trees_prealloced[0];
+ trees_next= trees;
+ trees_end= trees;
+}
+
+
/*
Perform AND operation on two index_merge lists and store result in *im1.
*/
@@ -823,10 +880,23 @@ int imerge_list_or_tree(PARAM *param,
{
SEL_IMERGE *imerge;
List_iterator<SEL_IMERGE> it(*im1);
+ bool tree_used= FALSE;
while ((imerge= it++))
{
- if (imerge->or_sel_tree_with_checks(param, tree))
+ SEL_TREE *or_tree;
+ if (tree_used)
+ {
+ or_tree= new SEL_TREE (tree, param);
+ if (!or_tree ||
+ (or_tree->keys_map.is_clear_all() && or_tree->merges.is_empty()))
+ return FALSE;
+ }
+ else
+ or_tree= tree;
+
+ if (imerge->or_sel_tree_with_checks(param, or_tree))
it.remove();
+ tree_used= TRUE;
}
return im1->is_empty();
}
@@ -945,7 +1015,7 @@ int QUICK_RANGE_SELECT::init()
if (file->inited != handler::NONE)
file->ha_index_or_rnd_end();
- DBUG_RETURN(error= file->ha_index_init(index));
+ DBUG_RETURN(FALSE);
}
@@ -4238,6 +4308,8 @@ get_mm_parts(PARAM *param, COND *cond_func, Field *field,
}
}
+ if (tree && tree->merges.is_empty() && tree->keys_map.is_clear_all())
+ tree= NULL;
DBUG_RETURN(tree);
}
@@ -6494,7 +6566,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
QUICK_RANGE_SELECT* cur_quick;
int result;
Unique *unique;
- DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::prepare_unique");
+ DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::read_keys_and_merge");
/* We're going to just read rowids. */
if (head->file->extra(HA_EXTRA_KEYREAD))
@@ -6565,13 +6637,17 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
}
- /* ok, all row ids are in Unique */
+ /*
+ Ok all rowids are in the Unique now. The next call will initialize
+ head->sort structure so it can be used to iterate through the rowids
+ sequence.
+ */
result= unique->get(head);
delete unique;
doing_pk_scan= FALSE;
- /* start table scan */
- init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1, 1);
- /* index_merge currently doesn't support "using index" at all */
+
+ /* Start the rnd_pos() scan. */
+ init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE);
head->file->extra(HA_EXTRA_NO_KEYREAD);
DBUG_RETURN(result);
@@ -6601,6 +6677,7 @@ int QUICK_INDEX_MERGE_SELECT::get_next()
{
result= HA_ERR_END_OF_FILE;
end_read_record(&read_record);
+ free_io_cache(head);
/* All rows from Unique have been retrieved, do a clustered PK scan */
if (pk_quick_select)
{
@@ -7094,9 +7171,17 @@ bool QUICK_RANGE_SELECT::row_in_ranges()
QUICK_SELECT_DESC::QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q,
uint used_key_parts_arg)
- : QUICK_RANGE_SELECT(*q), rev_it(rev_ranges)
+ : QUICK_RANGE_SELECT(*q), rev_it(rev_ranges),
+ used_key_parts (used_key_parts_arg)
{
QUICK_RANGE *r;
+ /*
+ Use default MRR implementation for reverse scans. No table engine
+ currently can do an MRR scan with output in reverse index order.
+ */
+ multi_range_length= 0;
+ multi_range= NULL;
+ multi_range_buff= NULL;
QUICK_RANGE **pr= (QUICK_RANGE**)ranges.buffer;
QUICK_RANGE **end_range= pr + ranges.elements;
@@ -7136,10 +7221,11 @@ int QUICK_SELECT_DESC::get_next()
int result;
if (last_range)
{ // Already read through key
- result = ((last_range->flag & EQ_RANGE)
- ? file->index_next_same(record, (byte*) last_range->min_key,
- last_range->min_length) :
- file->index_prev(record));
+ result = ((last_range->flag & EQ_RANGE &&
+ used_key_parts <= head->key_info[index].key_parts) ?
+ file->index_next_same(record, (byte*) last_range->min_key,
+ last_range->min_length) :
+ file->index_prev(record));
if (!result)
{
if (cmp_prev(*rev_it.ref()) == 0)
@@ -7163,7 +7249,9 @@ int QUICK_SELECT_DESC::get_next()
continue;
}
- if (last_range->flag & EQ_RANGE)
+ if (last_range->flag & EQ_RANGE &&
+ used_key_parts <= head->key_info[index].key_parts)
+
{
result= file->index_read(record, (byte*) last_range->max_key,
last_range->max_length, HA_READ_KEY_EXACT);
@@ -7171,6 +7259,8 @@ int QUICK_SELECT_DESC::get_next()
else
{
DBUG_ASSERT(last_range->flag & NEAR_MAX ||
+ (last_range->flag & EQ_RANGE &&
+ used_key_parts > head->key_info[index].key_parts) ||
range_reads_after_key(last_range));
result=file->index_read(record, (byte*) last_range->max_key,
last_range->max_length,
@@ -7268,54 +7358,6 @@ bool QUICK_SELECT_DESC::range_reads_after_key(QUICK_RANGE *range_arg)
}
-/* TRUE if we are reading over a key that may have a NULL value */
-
-#ifdef NOT_USED
-bool QUICK_SELECT_DESC::test_if_null_range(QUICK_RANGE *range_arg,
- uint used_key_parts)
-{
- uint offset, end;
- KEY_PART *key_part = key_parts,
- *key_part_end= key_part+used_key_parts;
-
- for (offset= 0, end = min(range_arg->min_length, range_arg->max_length) ;
- offset < end && key_part != key_part_end ;
- offset+= key_part++->store_length)
- {
- if (!memcmp((char*) range_arg->min_key+offset,
- (char*) range_arg->max_key+offset,
- key_part->store_length))
- continue;
-
- if (key_part->null_bit && range_arg->min_key[offset])
- return 1; // min_key is null and max_key isn't
- // Range doesn't cover NULL. This is ok if there is no more null parts
- break;
- }
- /*
- If the next min_range is > NULL, then we can use this, even if
- it's a NULL key
- Example: SELECT * FROM t1 WHERE a = 2 AND b >0 ORDER BY a DESC,b DESC;
-
- */
- if (key_part != key_part_end && key_part->null_bit)
- {
- if (offset >= range_arg->min_length || range_arg->min_key[offset])
- return 1; // Could be null
- key_part++;
- }
- /*
- If any of the key parts used in the ORDER BY could be NULL, we can't
- use the key to sort the data.
- */
- for (; key_part != key_part_end ; key_part++)
- if (key_part->null_bit)
- return 1; // Covers null part
- return 0;
-}
-#endif
-
-
void QUICK_RANGE_SELECT::add_info_string(String *str)
{
KEY *key_info= head->key_info + index;
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 3a737323eb7..d43f920be93 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -329,14 +329,7 @@ public:
void dbug_dump(int indent, bool verbose);
#endif
private:
- /* Used only by QUICK_SELECT_DESC */
- QUICK_RANGE_SELECT(const QUICK_RANGE_SELECT& org) : QUICK_SELECT_I()
- {
- bcopy(&org, this, sizeof(*this));
- multi_range_length= 0;
- multi_range= NULL;
- multi_range_buff= NULL;
- }
+ /* Default copy ctor used by QUICK_SELECT_DESC */
};
@@ -667,12 +660,10 @@ public:
int get_type() { return QS_TYPE_RANGE_DESC; }
private:
bool range_reads_after_key(QUICK_RANGE *range);
-#ifdef NOT_USED
- bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts);
-#endif
int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); }
List<QUICK_RANGE> rev_ranges;
List_iterator<QUICK_RANGE> rev_it;
+ uint used_key_parts;
};
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index aa352433141..ade0709cf0d 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -21,6 +21,9 @@
#include <my_sys.h>
#include <my_dir.h>
+/* from sql_db.cc */
+extern long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
+
/*
write string with escaping
@@ -85,7 +88,6 @@ write_escaped_string(IO_CACHE *file, LEX_STRING *val_s)
file pointer to IO_CACHE structure for writing
base pointer to data structure
parameter pointer to parameter descriptor
- old_version for returning back old version number value
RETURN
FALSE - OK
@@ -93,8 +95,7 @@ write_escaped_string(IO_CACHE *file, LEX_STRING *val_s)
*/
static my_bool
-write_parameter(IO_CACHE *file, gptr base, File_option *parameter,
- ulonglong *old_version)
+write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
{
char num_buf[20]; // buffer for numeric operations
// string for numeric operations
@@ -122,15 +123,6 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter,
DBUG_RETURN(TRUE);
break;
}
- case FILE_OPTIONS_REV:
- {
- ulonglong *val_i= (ulonglong *)(base + parameter->offset);
- *old_version= (*val_i)++;
- num.set(*val_i, &my_charset_bin);
- if (my_b_append(file, (const byte *)num.ptr(), num.length()))
- DBUG_RETURN(TRUE);
- break;
- }
case FILE_OPTIONS_TIMESTAMP:
{
/* string have to be allocated already */
@@ -202,7 +194,6 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter,
base base address for parameter reading (structure like
TABLE)
parameters parameters description
- max_versions number of versions to save
RETURN
FALSE - OK
@@ -212,13 +203,11 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter,
my_bool
sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
const LEX_STRING *type,
- gptr base, File_option *parameters,
- uint max_versions)
+ gptr base, File_option *parameters)
{
File handler;
IO_CACHE file;
char path[FN_REFLEN+1]; // +1 to put temporary file name for sure
- ulonglong old_version= ULONGLONG_MAX;
int path_end;
File_option *param;
DBUG_ENTER("sql_create_definition_file");
@@ -252,7 +241,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
if (my_b_append(&file, (const byte *)param->name.str,
param->name.length) ||
my_b_append(&file, (const byte *)STRING_WITH_LEN("=")) ||
- write_parameter(&file, base, param, &old_version) ||
+ write_parameter(&file, base, param) ||
my_b_append(&file, (const byte *)STRING_WITH_LEN("\n")))
goto err_w_cache;
}
@@ -265,54 +254,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
DBUG_RETURN(TRUE);
}
- // archive copies management
path[path_end]='\0';
- if (!access(path, F_OK))
- {
- if (old_version != ULONGLONG_MAX && max_versions != 0)
- {
- // save backup
- char path_arc[FN_REFLEN];
- // backup old version
- char path_to[FN_REFLEN];
-
- // check archive directory existence
- fn_format(path_arc, "arc", dir->str, "", MY_UNPACK_FILENAME);
- if (access(path_arc, F_OK))
- {
- if (my_mkdir(path_arc, 0777, MYF(MY_WME)))
- {
- DBUG_RETURN(TRUE);
- }
- }
-
- my_snprintf(path_to, FN_REFLEN, "%s/%s-%04lu",
- path_arc, file_name->str, (ulong) old_version);
- if (my_rename(path, path_to, MYF(MY_WME)))
- {
- DBUG_RETURN(TRUE);
- }
-
- // remove very old version
- if (old_version > max_versions)
- {
- my_snprintf(path_to, FN_REFLEN, "%s/%s-%04lu",
- path_arc, file_name->str,
- (ulong)(old_version - max_versions));
- if (!access(path_arc, F_OK) && my_delete(path_to, MYF(MY_WME)))
- {
- DBUG_RETURN(TRUE);
- }
- }
- }
- else
- {
- if (my_delete(path, MYF(MY_WME))) // no backups
- {
- DBUG_RETURN(TRUE);
- }
- }
- }
{
// rename temporary file
@@ -337,20 +279,19 @@ err_w_file:
SYNOPSIS
rename_in_schema_file
+ thd thread handler
schema name of given schema
old_name original file name
new_name new file name
- revision revision number
- num_view_backups number of backups
RETURN
0 - OK
1 - Error (only if renaming of frm failed)
*/
-my_bool rename_in_schema_file(const char *schema, const char *old_name,
- const char *new_name, ulonglong revision,
- uint num_view_backups)
+my_bool rename_in_schema_file(THD *thd,
+ const char *schema, const char *old_name,
+ const char *new_name)
{
char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];
@@ -365,23 +306,16 @@ my_bool rename_in_schema_file(const char *schema, const char *old_name,
if (my_rename(old_path, new_path, MYF(MY_WME)))
return 1;
- /* check if arc_dir exists */
+ /* check if arc_dir exists: disabled unused feature (see bug #17823). */
strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS);
(void) unpack_filename(arc_path, arc_path);
- if (revision > 0 && !access(arc_path, F_OK))
- {
- ulonglong limit= ((revision > num_view_backups) ?
- revision - num_view_backups : 0);
- for (; revision > limit ; revision--)
+ { // remove obsolete 'arc' directory and files if any
+ MY_DIR *new_dirp;
+ if ((new_dirp = my_dir(arc_path, MYF(MY_DONT_SORT))))
{
- my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu",
- arc_path, old_name, reg_ext, (ulong)revision);
- (void) unpack_filename(old_path, old_path);
- my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu",
- arc_path, new_name, reg_ext, (ulong)revision);
- (void) unpack_filename(new_path, new_path);
- my_rename(old_path, new_path, MYF(0));
+ DBUG_PRINT("my",("Archive subdir found: %s", arc_path));
+ (void) mysql_rm_arc_files(thd, new_dirp, arc_path);
}
}
return 0;
@@ -820,7 +754,6 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
break;
}
case FILE_OPTIONS_ULONGLONG:
- case FILE_OPTIONS_REV:
if (!(eol= strchr(ptr, '\n')))
{
my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
diff --git a/sql/parse_file.h b/sql/parse_file.h
index ab8b34561fe..ad7d1629e0a 100644
--- a/sql/parse_file.h
+++ b/sql/parse_file.h
@@ -23,7 +23,6 @@ enum file_opt_type {
FILE_OPTIONS_STRING, /* String (LEX_STRING) */
FILE_OPTIONS_ESTRING, /* Escaped string (LEX_STRING) */
FILE_OPTIONS_ULONGLONG, /* ulonglong parameter (ulonglong) */
- FILE_OPTIONS_REV, /* Revision version number (ulonglong) */
FILE_OPTIONS_TIMESTAMP, /* timestamp (LEX_STRING have to be
allocated with length 20 (19+1) */
FILE_OPTIONS_STRLIST, /* list of escaped strings
@@ -81,10 +80,10 @@ File_parser *sql_parse_prepare(const LEX_STRING *file_name,
my_bool
sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
const LEX_STRING *type,
- gptr base, File_option *parameters, uint versions);
-my_bool rename_in_schema_file(const char *schema, const char *old_name,
- const char *new_name, ulonglong revision,
- uint num_view_backups);
+ gptr base, File_option *parameters);
+my_bool rename_in_schema_file(THD *thd,
+ const char *schema, const char *old_name,
+ const char *new_name);
class File_parser: public Sql_alloc
{
diff --git a/sql/records.cc b/sql/records.cc
index f61efc13034..d5c3a421cd9 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -72,11 +72,47 @@ void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
}
-/* init struct for read with info->read_record */
+/*
+ init struct for read with info->read_record
+
+ SYNOPSIS
+ init_read_record()
+ info OUT read structure
+ thd Thread handle
+ table Table the data [originally] comes from.
+ select SQL_SELECT structure. We may select->quick or
+ select->file as data source
+ use_record_cache Call file->extra_opt(HA_EXTRA_CACHE,...)
+ if we're going to do sequential read and some
+ additional conditions are satisfied.
+ print_error Copy this to info->print_error
+ disable_rr_cache Don't use rr_from_cache (used by sort-union
+ index-merge which produces rowid sequences that
+ are already ordered)
+
+ DESCRIPTION
+ This function sets up reading data via one of the methods:
+
+ rr_unpack_from_tempfile Unpack full records from sequential file
+ rr_unpack_from_buffer ... or from buffer
+
+ rr_from_tempfile Read rowids from tempfile and get full records
+ with handler->rnd_pos() calls.
+ rr_from_pointers ... or get rowids from buffer
+
+ rr_from_cache Read a bunch of rowids from file, sort them,
+ get records in rowid order, return, repeat.
+
+ rr_quick Get data from QUICK_*_SELECT
+
+ rr_sequential Sequentially scan the table using
+ handler->rnd_next() calls
+*/
void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
SQL_SELECT *select,
- int use_record_cache, bool print_error)
+ int use_record_cache, bool print_error,
+ bool disable_rr_cache)
{
IO_CACHE *tempfile;
DBUG_ENTER("init_read_record");
@@ -121,7 +157,8 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
it doesn't make sense to use cache - we don't read from the table
and table->sort.io_cache is read sequentially
*/
- if (!table->sort.addon_field &&
+ if (!disable_rr_cache &&
+ !table->sort.addon_field &&
! (specialflag & SPECIAL_SAFE_MODE) &&
thd->variables.read_rnd_buff_size &&
!(table->file->table_flags() & HA_FAST_KEY_READ) &&
diff --git a/sql/set_var.cc b/sql/set_var.cc
index a0ddef0b386..6aba8a3b5ec 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -138,7 +138,7 @@ sys_var_thd_ulong sys_auto_increment_offset("auto_increment_offset",
sys_var_bool_ptr sys_automatic_sp_privileges("automatic_sp_privileges",
&sp_automatic_privileges);
-sys_var_const_str sys_basedir("basedir", mysql_home);
+sys_var_const_os_str sys_basedir("basedir", mysql_home);
sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size",
&binlog_cache_size);
sys_var_thd_ulong sys_bulk_insert_buff_size("bulk_insert_buffer_size",
@@ -151,6 +151,8 @@ sys_var_character_set_client sys_character_set_client("character_set_client");
sys_var_character_set_connection sys_character_set_connection("character_set_connection");
sys_var_character_set_results sys_character_set_results("character_set_results");
sys_var_character_set_filesystem sys_character_set_filesystem("character_set_filesystem");
+sys_var_const_os_str sys_character_sets_dir("character_sets_dir",
+ mysql_charsets_dir);
sys_var_thd_ulong sys_completion_type("completion_type",
&SV::completion_type,
check_completion_type,
@@ -162,7 +164,7 @@ sys_var_long_ptr sys_concurrent_insert("concurrent_insert",
&myisam_concurrent_insert);
sys_var_long_ptr sys_connect_timeout("connect_timeout",
&connect_timeout);
-sys_var_const_str sys_datadir("datadir", mysql_real_data_home);
+sys_var_const_os_str sys_datadir("datadir", mysql_real_data_home);
sys_var_enum sys_delay_key_write("delay_key_write",
&delay_key_write_options,
&delay_key_write_typelib,
@@ -311,6 +313,7 @@ sys_var_thd_ulong sys_optimizer_prune_level("optimizer_prune_level",
&SV::optimizer_prune_level);
sys_var_thd_ulong sys_optimizer_search_depth("optimizer_search_depth",
&SV::optimizer_search_depth);
+sys_var_const_os_str sys_plugin_dir("plugin_dir", opt_plugin_dir);
sys_var_thd_ulong sys_preload_buff_size("preload_buffer_size",
&SV::preload_buff_size);
sys_var_thd_ulong sys_read_buff_size("read_buffer_size",
@@ -338,7 +341,7 @@ sys_var_thd_ulong sys_query_alloc_block_size("query_alloc_block_size",
sys_var_thd_ulong sys_query_prealloc_size("query_prealloc_size",
&SV::query_prealloc_size,
0, fix_thd_mem_root);
-sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
+sys_var_readonly_os sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
sys_var_thd_ulong sys_trans_alloc_block_size("transaction_alloc_block_size",
&SV::trans_alloc_block_size,
0, fix_trans_mem_root);
@@ -363,9 +366,11 @@ sys_var_bool_ptr sys_secure_auth("secure_auth", &opt_secure_auth);
sys_var_const_str_ptr sys_secure_file_priv("secure_file_priv",
&opt_secure_file_priv);
sys_var_long_ptr sys_server_id("server_id", &server_id, fix_server_id);
+#ifdef HAVE_REPLICATION
sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol",
&opt_slave_compressed_protocol);
-#ifdef HAVE_REPLICATION
+sys_var_const_os_str_ptr sys_slave_load_tmpdir("slave_load_tmpdir",
+ &slave_load_tmpdir);
sys_var_long_ptr sys_slave_net_timeout("slave_net_timeout",
&slave_net_timeout);
sys_var_long_ptr sys_slave_trans_retries("slave_transaction_retries",
@@ -380,17 +385,17 @@ sys_var_thd_sql_mode sys_sql_mode("sql_mode",
#ifdef HAVE_OPENSSL
extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher,
*opt_ssl_key;
-sys_var_const_str_ptr sys_ssl_ca("ssl_ca", &opt_ssl_ca);
-sys_var_const_str_ptr sys_ssl_capath("ssl_capath", &opt_ssl_capath);
-sys_var_const_str_ptr sys_ssl_cert("ssl_cert", &opt_ssl_cert);
-sys_var_const_str_ptr sys_ssl_cipher("ssl_cipher", &opt_ssl_cipher);
-sys_var_const_str_ptr sys_ssl_key("ssl_key", &opt_ssl_key);
+sys_var_const_os_str_ptr sys_ssl_ca("ssl_ca", &opt_ssl_ca);
+sys_var_const_os_str_ptr sys_ssl_capath("ssl_capath", &opt_ssl_capath);
+sys_var_const_os_str_ptr sys_ssl_cert("ssl_cert", &opt_ssl_cert);
+sys_var_const_os_str_ptr sys_ssl_cipher("ssl_cipher", &opt_ssl_cipher);
+sys_var_const_os_str_ptr sys_ssl_key("ssl_key", &opt_ssl_key);
#else
-sys_var_const_str sys_ssl_ca("ssl_ca", NULL);
-sys_var_const_str sys_ssl_capath("ssl_capath", NULL);
-sys_var_const_str sys_ssl_cert("ssl_cert", NULL);
-sys_var_const_str sys_ssl_cipher("ssl_cipher", NULL);
-sys_var_const_str sys_ssl_key("ssl_key", NULL);
+sys_var_const_os_str sys_ssl_ca("ssl_ca", NULL);
+sys_var_const_os_str sys_ssl_capath("ssl_capath", NULL);
+sys_var_const_os_str sys_ssl_cert("ssl_cert", NULL);
+sys_var_const_os_str sys_ssl_cipher("ssl_cipher", NULL);
+sys_var_const_os_str sys_ssl_key("ssl_key", NULL);
#endif
sys_var_thd_enum
sys_updatable_views_with_limit("updatable_views_with_limit",
@@ -460,6 +465,14 @@ sys_var_long_ptr sys_innodb_commit_concurrency("innodb_commit_concurrency",
sys_var_long_ptr sys_innodb_flush_log_at_trx_commit(
"innodb_flush_log_at_trx_commit",
&srv_flush_log_at_trx_commit);
+sys_var_const_os_str_ptr sys_innodb_data_file_path("innodb_data_file_path",
+ &innobase_data_file_path);
+sys_var_const_os_str_ptr sys_innodb_data_home_dir("innodb_data_home_dir",
+ &innobase_data_home_dir);
+sys_var_const_os_str_ptr sys_innodb_log_arch_dir("innodb_log_arch_dir",
+ &innobase_log_arch_dir);
+sys_var_const_os_str_ptr sys_innodb_log_group_home_dir("innodb_log_group_home_dir",
+ &innobase_log_group_home_dir);
#endif
/* Condition pushdown to storage engine */
@@ -854,7 +867,7 @@ struct show_var_st init_vars[]= {
{sys_character_set_results.name,(char*) &sys_character_set_results, SHOW_SYS},
{sys_character_set_server.name, (char*) &sys_character_set_server,SHOW_SYS},
{sys_charset_system.name, (char*) &sys_charset_system, SHOW_SYS},
- {"character_sets_dir", mysql_charsets_dir, SHOW_CHAR},
+ {sys_character_sets_dir.name, (char *) &sys_character_sets_dir, SHOW_SYS},
{sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS},
{sys_collation_database.name,(char*) &sys_collation_database, SHOW_SYS},
{sys_collation_server.name,(char*) &sys_collation_server, SHOW_SYS},
@@ -915,8 +928,8 @@ struct show_var_st init_vars[]= {
{"innodb_checksums", (char*) &innobase_use_checksums, SHOW_MY_BOOL},
{sys_innodb_commit_concurrency.name, (char*) &sys_innodb_commit_concurrency, SHOW_SYS},
{sys_innodb_concurrency_tickets.name, (char*) &sys_innodb_concurrency_tickets, SHOW_SYS},
- {"innodb_data_file_path", (char*) &innobase_data_file_path, SHOW_CHAR_PTR},
- {"innodb_data_home_dir", (char*) &innobase_data_home_dir, SHOW_CHAR_PTR},
+ {sys_innodb_data_file_path.name, (char*) &sys_innodb_data_file_path, SHOW_SYS},
+ {sys_innodb_data_home_dir.name, (char*) &sys_innodb_data_home_dir, SHOW_SYS},
{"innodb_adaptive_hash_index", (char*) &innobase_adaptive_hash_index, SHOW_MY_BOOL},
{"innodb_doublewrite", (char*) &innobase_use_doublewrite, SHOW_MY_BOOL},
{sys_innodb_fast_shutdown.name,(char*) &sys_innodb_fast_shutdown, SHOW_SYS},
@@ -927,12 +940,12 @@ struct show_var_st init_vars[]= {
{"innodb_force_recovery", (char*) &innobase_force_recovery, SHOW_LONG },
{"innodb_lock_wait_timeout", (char*) &innobase_lock_wait_timeout, SHOW_LONG },
{"innodb_locks_unsafe_for_binlog", (char*) &innobase_locks_unsafe_for_binlog, SHOW_MY_BOOL},
- {"innodb_log_arch_dir", (char*) &innobase_log_arch_dir, SHOW_CHAR_PTR},
+ {sys_innodb_log_arch_dir.name, (char*) &sys_innodb_log_arch_dir, SHOW_SYS},
{"innodb_log_archive", (char*) &innobase_log_archive, SHOW_MY_BOOL},
{"innodb_log_buffer_size", (char*) &innobase_log_buffer_size, SHOW_LONG },
{"innodb_log_file_size", (char*) &innobase_log_file_size, SHOW_LONGLONG},
{"innodb_log_files_in_group", (char*) &innobase_log_files_in_group, SHOW_LONG},
- {"innodb_log_group_home_dir", (char*) &innobase_log_group_home_dir, SHOW_CHAR_PTR},
+ {sys_innodb_log_group_home_dir.name, (char*) &sys_innodb_log_group_home_dir, SHOW_SYS},
{sys_innodb_max_dirty_pages_pct.name, (char*) &sys_innodb_max_dirty_pages_pct, SHOW_SYS},
{sys_innodb_max_purge_lag.name, (char*) &sys_innodb_max_purge_lag, SHOW_SYS},
{"innodb_mirrored_log_groups", (char*) &innobase_mirrored_log_groups, SHOW_LONG},
@@ -1036,7 +1049,7 @@ struct show_var_st init_vars[]= {
{sys_optimizer_search_depth.name,(char*) &sys_optimizer_search_depth,
SHOW_SYS},
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
- {"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
+ {sys_plugin_dir.name, (char*) &sys_plugin_dir, SHOW_SYS},
{"port", (char*) &mysqld_port, SHOW_INT},
{sys_preload_buff_size.name, (char*) &sys_preload_buff_size, SHOW_SYS},
#ifdef ENABLED_PROFILING
@@ -1082,7 +1095,7 @@ struct show_var_st init_vars[]= {
#ifdef HAVE_REPLICATION
{sys_slave_compressed_protocol.name,
(char*) &sys_slave_compressed_protocol, SHOW_SYS},
- {"slave_load_tmpdir", (char*) &slave_load_tmpdir, SHOW_CHAR_PTR},
+ {sys_slave_load_tmpdir.name,(char*) &sys_slave_load_tmpdir, SHOW_SYS},
{sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout, SHOW_SYS},
{"slave_skip_errors", (char*) &slave_error_mask, SHOW_SLAVE_SKIP_ERRORS},
{sys_slave_trans_retries.name,(char*) &sys_slave_trans_retries, SHOW_SYS},
@@ -1189,6 +1202,7 @@ bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex,
old_value= var_str->value;
var_str->value= res;
var_str->value_length= new_length;
+ var_str->is_os_charset= FALSE;
rw_unlock(var_mutex);
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
return 0;
@@ -1928,11 +1942,11 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
char *str= (char*) value_ptr(thd, var_type, base);
if (str)
tmp= new Item_string(str, strlen(str),
- system_charset_info, DERIVATION_SYSCONST);
+ charset(thd), DERIVATION_SYSCONST);
else
{
tmp= new Item_null();
- tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
+ tmp->collation.set(charset(thd), DERIVATION_SYSCONST);
}
pthread_mutex_unlock(&LOCK_global_system_variables);
return tmp;
@@ -1944,6 +1958,13 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
}
+CHARSET_INFO *sys_var::charset(THD *thd)
+{
+ return is_os_charset ? thd->variables.character_set_filesystem :
+ system_charset_info;
+}
+
+
bool sys_var_thd_enum::update(THD *thd, set_var *var)
{
if (var->type == OPT_GLOBAL)
diff --git a/sql/set_var.h b/sql/set_var.h
index c37cc400e43..f43d3b75cee 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -46,9 +46,17 @@ public:
sys_after_update_func after_update;
bool no_support_one_shot;
+ /*
+ true if the value is in character_set_filesystem,
+ false otherwise.
+ Note that we can't use a pointer to the charset as the system var is
+ instantiated in global scope and the charset pointers are initialized
+ later.
+ */
+ bool is_os_charset;
sys_var(const char *name_arg, sys_after_update_func func= NULL)
:name(name_arg), after_update(func)
- , no_support_one_shot(1)
+ , no_support_one_shot(1), is_os_charset(FALSE)
{}
virtual ~sys_var() {}
virtual bool check(THD *thd, set_var *var);
@@ -68,6 +76,7 @@ public:
Item *item(THD *thd, enum_var_type type, LEX_STRING *base);
virtual bool is_struct() { return 0; }
virtual bool is_readonly() const { return 0; }
+ CHARSET_INFO *charset(THD *thd);
};
@@ -247,6 +256,17 @@ public:
};
+class sys_var_const_os_str: public sys_var_const_str
+{
+public:
+ sys_var_const_os_str(const char *name_arg, const char *value_arg)
+ :sys_var_const_str(name_arg, value_arg)
+ {
+ is_os_charset= TRUE;
+ }
+};
+
+
class sys_var_const_str_ptr :public sys_var
{
public:
@@ -276,6 +296,17 @@ public:
};
+class sys_var_const_os_str_ptr :public sys_var_const_str_ptr
+{
+public:
+ sys_var_const_os_str_ptr(const char *name_arg, char **value_arg)
+ :sys_var_const_str_ptr(name_arg, value_arg)
+ {
+ is_os_charset= TRUE;
+ }
+};
+
+
class sys_var_enum :public sys_var
{
uint *value;
@@ -791,6 +822,20 @@ public:
bool is_readonly() const { return 1; }
};
+
+class sys_var_readonly_os: public sys_var_readonly
+{
+public:
+ sys_var_readonly_os(const char *name_arg, enum_var_type type,
+ SHOW_TYPE show_type_arg,
+ sys_value_ptr_func value_ptr_func_arg)
+ :sys_var_readonly(name_arg, type, show_type_arg, value_ptr_func_arg)
+ {
+ is_os_charset= TRUE;
+ }
+};
+
+
class sys_var_thd_time_zone :public sys_var_thd
{
public:
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index 7d345d633c6..c688ba88b7b 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -4737,7 +4737,7 @@ ER_SLAVE_IGNORED_TABLE
swe "Slav SQL tråden ignorerade frågan pga en replicate-*-table regel"
ER_INCORRECT_GLOBAL_LOCAL_VAR
eng "Variable '%-.64s' is a %s variable"
- serbian "Incorrect foreign key definition for '%-.64s': %s"
+ serbian "Promenljiva '%-.64s' je %s promenljiva"
ger "Variable '%-.64s' ist eine %s-Variable"
spa "Variable '%-.64s' es una %s variable"
swe "Variabel '%-.64s' är av typ %s"
@@ -5645,3 +5645,7 @@ ER_LOAD_DATA_INVALID_COLUMN
eng "Invalid column reference (%-.64s) in LOAD DATA"
ER_LOG_PURGE_NO_FILE
eng "Being purged log %s was not found"
+ER_XA_RBTIMEOUT XA106
+ eng "XA_RBTIMEOUT: Transaction branch was rolled back: took too long"
+ER_XA_RBDEADLOCK XA102
+ eng "XA_RBDEADLOCK: Transaction branch was rolled back: deadlock was detected"
diff --git a/sql/sp.cc b/sql/sp.cc
index 2392cabb220..d2a12f2190f 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -443,11 +443,12 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
goto end;
{
- Lex_input_stream lip(thd, defstr.c_ptr(), defstr.length());
- thd->m_lip= &lip;
+ Parser_state parser_state(thd, defstr.c_ptr(), defstr.length());
+ thd->m_parser_state= &parser_state;
lex_start(thd);
thd->spcont= NULL;
ret= MYSQLparse(thd);
+ thd->m_parser_state= NULL;
if (ret == 0)
{
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 4556d70e4c3..dd71a8512b4 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -123,6 +123,9 @@ sp_get_item_value(THD *thd, Item *item, String *str)
if (cs->escape_with_backslash_is_dangerous)
buf.append(' ');
append_query_string(cs, result, &buf);
+ buf.append(" COLLATE '");
+ buf.append(item->collation.collation->name);
+ buf.append('\'');
str->copy(buf);
return str;
@@ -446,7 +449,7 @@ sp_head::operator new(size_t size) throw()
init_sql_alloc(&own_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC);
sp= (sp_head *) alloc_root(&own_root, size);
if (sp == NULL)
- return NULL;
+ DBUG_RETURN(NULL);
sp->main_mem_root= own_root;
DBUG_PRINT("info", ("mem_root 0x%lx", (ulong) &sp->mem_root));
DBUG_RETURN(sp);
@@ -591,7 +594,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
const char *endp; /* Used to trim the end */
/* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root;
- Lex_input_stream *lip=thd->m_lip;
+ Lex_input_stream *lip= & thd->m_parser_state->m_lip;
if (m_param_begin && m_param_end)
{
@@ -1787,7 +1790,11 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
we'll leave it here.
*/
if (!thd->in_sub_stmt)
- close_thread_tables(thd, 0, 0);
+ {
+ thd->lex->unit.cleanup();
+ close_thread_tables(thd);
+ thd->rollback_item_tree_changes();
+ }
DBUG_PRINT("info",(" %.*s: eval args done", m_name.length, m_name.str));
}
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 7592986ef81..df5e844749f 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -205,7 +205,8 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
acl_cache->clear(1); // Clear locked hostname cache
init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
- init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0);
+ init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0,
+ FALSE);
VOID(my_init_dynamic_array(&acl_hosts,sizeof(ACL_HOST),20,50));
while (!(read_record_info.read_record(&read_record_info)))
{
@@ -253,7 +254,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
end_read_record(&read_record_info);
freeze_size(&acl_hosts);
- init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0);
+ init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0,FALSE);
VOID(my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100));
password_length= table->field[2]->field_length /
table->field[2]->charset()->mbmaxlen;
@@ -426,7 +427,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
end_read_record(&read_record_info);
freeze_size(&acl_users);
- init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0);
+ init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0,FALSE);
VOID(my_init_dynamic_array(&acl_dbs,sizeof(ACL_DB),50,100));
while (!(read_record_info.read_record(&read_record_info)))
{
@@ -5429,7 +5430,6 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
while ((tmp_user_name= user_list++))
{
- user_name= get_current_user(thd, tmp_user_name);
if (!(user_name= get_current_user(thd, tmp_user_name)))
{
result= TRUE;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 9cdcc2bbb75..ef3d10c468f 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2102,7 +2102,10 @@ bool reopen_table(TABLE *table,bool locked)
for (key=0 ; key < table->s->keys ; key++)
{
for (part=0 ; part < table->key_info[key].usable_key_parts ; part++)
+ {
table->key_info[key].key_part[part].field->table= table;
+ table->key_info[key].key_part[part].field->orig_table= table;
+ }
}
if (table->triggers)
table->triggers->set_table(table);
@@ -3617,8 +3620,21 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
{
/* This is a base table. */
DBUG_ASSERT(nj_col->view_field == NULL);
- DBUG_ASSERT(nj_col->table_ref->table == nj_col->table_field->table);
- found_field= nj_col->table_field;
+ /*
+ This fix_fields is not necessary (initially this item is fixed by
+ the Item_field constructor; after reopen_tables the Item_func_eq
+ calls fix_fields on that item), it's just a check during table
+ reopening for columns that was dropped by the concurrent connection.
+ */
+ if (!nj_col->table_field->fixed &&
+ nj_col->table_field->fix_fields(thd, (Item **)&nj_col->table_field))
+ {
+ DBUG_PRINT("info", ("column '%s' was dropped by the concurrent connection",
+ nj_col->table_field->name));
+ DBUG_RETURN(NULL);
+ }
+ DBUG_ASSERT(nj_col->table_ref->table == nj_col->table_field->field->table);
+ found_field= nj_col->table_field->field;
update_field_dependencies(thd, found_field, nj_col->table_ref->table);
}
@@ -4450,7 +4466,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
const char *field_name_1;
/* true if field_name_1 is a member of using_fields */
bool is_using_column_1;
- if (!(nj_col_1= it_1.get_or_create_column_ref(leaf_1)))
+ if (!(nj_col_1= it_1.get_or_create_column_ref(thd, leaf_1)))
goto err;
field_name_1= nj_col_1->name();
is_using_column_1= using_fields &&
@@ -4471,7 +4487,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
{
Natural_join_column *cur_nj_col_2;
const char *cur_field_name_2;
- if (!(cur_nj_col_2= it_2.get_or_create_column_ref(leaf_2)))
+ if (!(cur_nj_col_2= it_2.get_or_create_column_ref(thd, leaf_2)))
goto err;
cur_field_name_2= cur_nj_col_2->name();
DBUG_PRINT ("info", ("cur_field_name_2=%s.%s",
@@ -4957,15 +4973,24 @@ static bool setup_natural_join_row_types(THD *thd,
TABLE_LIST *left_neighbor;
/* Table reference to the right of the current. */
TABLE_LIST *right_neighbor= NULL;
+ bool save_first_natural_join_processing=
+ context->select_lex->first_natural_join_processing;
+
+ context->select_lex->first_natural_join_processing= FALSE;
/* Note that tables in the list are in reversed order */
for (left_neighbor= table_ref_it++; left_neighbor ; )
{
table_ref= left_neighbor;
left_neighbor= table_ref_it++;
- /* For stored procedures do not redo work if already done. */
- if (context->select_lex->first_execution)
+ /*
+ Do not redo work if already done:
+ 1) for stored procedures,
+ 2) for multitable update after lock failure and table reopening.
+ */
+ if (save_first_natural_join_processing)
{
+ context->select_lex->first_natural_join_processing= FALSE;
if (store_top_level_join_columns(thd, table_ref,
left_neighbor, right_neighbor))
return TRUE;
@@ -5486,6 +5511,10 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
if (!(item= field_iterator.create_item(thd)))
DBUG_RETURN(TRUE);
+ DBUG_ASSERT(item->fixed);
+ /* cache the table for the Item_fields inserted by expanding stars */
+ if (item->type() == Item::FIELD_ITEM && tables->cacheable_table)
+ ((Item_field *)item)->cached_table= tables;
if (!found)
{
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 8ca96a2bddc..577255fbc4a 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -2528,7 +2528,7 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block,
tmp++)
unlink_table(tmp);
}
- return (n);
+ return test(n);
}
/*
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 6da6925e82d..9a1c35c7d3d 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -191,7 +191,8 @@ THD::THD()
rand_used(0), time_zone_used(0),
last_insert_id_used(0), last_insert_id_used_bin_log(0), insert_id_used(0),
clear_next_insert_id(0), in_lock_tables(0), bootstrap(0),
- derived_tables_processing(FALSE), spcont(NULL), m_lip(NULL)
+ derived_tables_processing(FALSE), spcont(NULL),
+ m_parser_state(NULL)
{
ulong tmp;
@@ -990,6 +991,12 @@ sql_exchange::sql_exchange(char *name,bool flag)
cs= NULL;
}
+bool sql_exchange::escaped_given(void)
+{
+ return escaped != &default_escaped;
+}
+
+
bool select_send::send_fields(List<Item> &list, uint flags)
{
bool res;
@@ -1250,8 +1257,11 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
exchange->line_term=exchange->field_term; // Use this if it exists
field_sep_char= (exchange->enclosed->length() ?
(int) (uchar) (*exchange->enclosed)[0] : field_term_char);
- escape_char= (exchange->escaped->length() ?
- (int) (uchar) (*exchange->escaped)[0] : -1);
+ if (exchange->escaped->length() && (exchange->escaped_given() ||
+ !(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)))
+ escape_char= (int) (uchar) (*exchange->escaped)[0];
+ else
+ escape_char= -1;
is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char));
is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char));
line_sep_char= (exchange->line_term->length() ?
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 45539f774b5..506df19241c 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -28,7 +28,7 @@ class Slave_log_event;
class Format_description_log_event;
class sp_rcontext;
class sp_cache;
-class Lex_input_stream;
+class Parser_state;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
@@ -665,10 +665,17 @@ typedef struct system_status_var
ulong com_stmt_fetch;
ulong com_stmt_reset;
ulong com_stmt_close;
+ /*
+ Number of statements sent from the client
+ */
+ ulong questions;
/*
- Status variables which it does not make sense to add to
- global status variable counter
+ IMPORTANT!
+ SEE last_system_status_var DEFINITION BELOW.
+
+ Below 'last_system_status_var' are all variables which doesn't make any
+ sense to add to the /global/ status variable counter.
*/
double last_query_cost;
} STATUS_VAR;
@@ -679,7 +686,7 @@ typedef struct system_status_var
counter
*/
-#define last_system_status_var com_stmt_close
+#define last_system_status_var questions
void free_tmp_table(THD *thd, TABLE *entry);
@@ -921,7 +928,7 @@ struct st_savepoint {
uint length, nht;
};
-enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
+enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED, XA_ROLLBACK_ONLY};
extern const char *xa_state_names[];
typedef struct st_xid_state {
@@ -929,6 +936,8 @@ typedef struct st_xid_state {
XID xid; // transaction identifier
enum xa_states xa_state; // used by external XA only
bool in_thd;
+ /* Error reported by the Resource Manager (RM) to the Transaction Manager. */
+ uint rm_error;
} XID_STATE;
extern pthread_mutex_t LOCK_xid_cache;
@@ -1583,13 +1592,11 @@ public:
} binlog_evt_union;
/**
- Character input stream consumed by the lexical analyser,
- used during parsing.
- Note that since the parser is not re-entrant, we keep only one input
- stream here. This member is valid only when executing code during parsing,
- and may point to invalid memory after that.
+ Internal parser state.
+ Note that since the parser is not re-entrant, we keep only one parser
+ state here. This member is valid only when executing code during parsing.
*/
- Lex_input_stream *m_lip;
+ Parser_state *m_parser_state;
THD();
~THD();
@@ -1906,6 +1913,7 @@ public:
ulong skip_lines;
CHARSET_INFO *cs;
sql_exchange(char *name,bool dumpfile_flag);
+ bool escaped_given(void);
};
#include "log_event.h"
diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc
index c2345f1f2cd..16567765ba6 100644
--- a/sql/sql_cursor.cc
+++ b/sql/sql_cursor.cc
@@ -111,7 +111,8 @@ class Select_materialize: public select_union
select_result *result; /* the result object of the caller (PS or SP) */
public:
Materialized_cursor *materialized_cursor;
- Select_materialize(select_result *result_arg) :result(result_arg) {}
+ Select_materialize(select_result *result_arg) :result(result_arg),
+ materialized_cursor(0) {}
virtual bool send_fields(List<Item> &list, uint flags);
};
@@ -155,6 +156,7 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
if (! (sensitive_cursor= new (thd->mem_root) Sensitive_cursor(thd, result)))
{
delete result_materialize;
+ result_materialize= NULL;
return 1;
}
@@ -212,6 +214,7 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
if ((rc= materialized_cursor->open(0)))
{
delete materialized_cursor;
+ materialized_cursor= NULL;
goto err_open;
}
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index e25ede1be03..c3cf7429222 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -35,7 +35,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path, uint level,
TABLE_LIST **dropped_tables);
-static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
+long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error);
/* Database options hash */
static HASH dboptions;
@@ -906,7 +906,10 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
else if (file->name[0] == 'a' && file->name[1] == 'r' &&
file->name[2] == 'c' && file->name[3] == '\0')
{
- /* .frm archive */
+ /* .frm archive:
+ Those archives are obsolete, but following code should
+ exist to remove existent "arc" directories.
+ */
char newpath[FN_REFLEN];
MY_DIR *new_dirp;
strxmov(newpath, org_path, "/", "arc", NullS);
@@ -1061,9 +1064,12 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error)
RETURN
> 0 number of removed files
-1 error
+
+ NOTE
+ A support of "arc" directories is obsolete, however this
+ function should exist to remove existent "arc" directories.
*/
-static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp,
- const char *org_path)
+long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path)
{
long deleted= 0;
ulong found_other_files= 0;
@@ -1105,6 +1111,7 @@ static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp,
{
goto err;
}
+ deleted++;
}
if (thd->killed)
goto err;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index b9177f65ad5..d5d09c88441 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -214,7 +214,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
DBUG_RETURN(TRUE);
}
if (usable_index==MAX_KEY)
- init_read_record(&info,thd,table,select,1,1);
+ init_read_record(&info, thd, table, select, 1, 1, FALSE);
else
init_read_record_idx(&info, thd, table, 1, usable_index);
@@ -772,7 +772,7 @@ int multi_delete::do_deletes()
}
READ_RECORD info;
- init_read_record(&info,thd,table,NULL,0,1);
+ init_read_record(&info, thd, table, NULL, 0, 1, FALSE);
/*
Ignore any rows not found in reference tables as they may already have
been deleted by foreign key handling
diff --git a/sql/sql_help.cc b/sql/sql_help.cc
index 69a257a9d37..6036a687274 100644
--- a/sql/sql_help.cc
+++ b/sql/sql_help.cc
@@ -181,7 +181,7 @@ int search_topics(THD *thd, TABLE *topics, struct st_find_field *find_fields,
int count= 0;
READ_RECORD read_record_info;
- init_read_record(&read_record_info, thd, topics, select,1,0);
+ init_read_record(&read_record_info, thd, topics, select, 1, 0, FALSE);
while (!read_record_info.read_record(&read_record_info))
{
if (!select->cond->val_int()) // Doesn't match like
@@ -221,7 +221,7 @@ int search_keyword(THD *thd, TABLE *keywords, struct st_find_field *find_fields,
int count= 0;
READ_RECORD read_record_info;
- init_read_record(&read_record_info, thd, keywords, select,1,0);
+ init_read_record(&read_record_info, thd, keywords, select, 1, 0, FALSE);
while (!read_record_info.read_record(&read_record_info) && count<2)
{
if (!select->cond->val_int()) // Dosn't match like
@@ -346,7 +346,7 @@ int search_categories(THD *thd, TABLE *categories,
DBUG_ENTER("search_categories");
- init_read_record(&read_record_info, thd, categories, select,1,0);
+ init_read_record(&read_record_info, thd, categories, select,1,0,FALSE);
while (!read_record_info.read_record(&read_record_info))
{
if (select && !select->cond->val_int())
@@ -380,7 +380,7 @@ void get_all_items_for_category(THD *thd, TABLE *items, Field *pfname,
DBUG_ENTER("get_all_items_for_category");
READ_RECORD read_record_info;
- init_read_record(&read_record_info, thd, items, select,1,0);
+ init_read_record(&read_record_info, thd, items, select,1,0,FALSE);
while (!read_record_info.read_record(&read_record_info))
{
if (!select->cond->val_int())
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 68c402d9895..3cba300fbc7 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -2589,6 +2589,11 @@ bool Delayed_insert::handle_inserts(void)
/* Remove all not used rows */
while ((row=rows.get()))
{
+ if (table->s->blob_fields)
+ {
+ memcpy(table->record[0],row->record,table->s->reclength);
+ free_delayed_insert_blobs(table);
+ }
delete row;
thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
stacked_inserts--;
@@ -2901,7 +2906,11 @@ bool select_insert::send_data(List<Item> &values)
DBUG_RETURN(1);
}
}
- if (!(error= write_record(thd, table, &info)))
+
+ error= write_record(thd, table, &info);
+ table->auto_increment_field_not_null= FALSE;
+
+ if (!error)
{
if (table->triggers || info.handle_duplicates == DUP_UPDATE)
{
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 16fab313e61..de2e5867955 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -192,7 +192,6 @@ void lex_start(THD *thd)
lex->select_lex.order_list.empty();
lex->select_lex.udf_list.empty();
lex->current_select= &lex->select_lex;
- lex->yacc_yyss=lex->yacc_yyvs=0;
lex->sql_command= lex->orig_sql_command= SQLCOM_END;
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
@@ -210,11 +209,16 @@ void lex_start(THD *thd)
void lex_end(LEX *lex)
{
- DBUG_ENTER("lex_end");
- DBUG_PRINT("enter", ("lex: 0x%lx", (long) lex));
- x_free(lex->yacc_yyss);
- x_free(lex->yacc_yyvs);
- DBUG_VOID_RETURN;
+ /* Empty in 5.0, non empty in 5.1 */
+}
+
+Yacc_state::~Yacc_state()
+{
+ if (yacc_yyss)
+ {
+ x_free(yacc_yyss);
+ x_free(yacc_yyvs);
+ }
}
@@ -531,7 +535,7 @@ int MYSQLlex(void *arg, void *yythd)
uint length;
enum my_lex_states state;
THD *thd= (THD *)yythd;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= & thd->m_parser_state->m_lip;
LEX *lex= thd->lex;
YYSTYPE *yylval=(YYSTYPE*) arg;
CHARSET_INFO *cs= thd->charset();
@@ -1201,6 +1205,7 @@ void st_select_lex::init_query()
subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0;
first_execution= 1;
+ first_natural_join_processing= 1;
first_cond_optimization= 1;
parsing_place= NO_MATTER;
exclude_from_table_unique_test= no_wrap_view_item= FALSE;
@@ -1781,7 +1786,7 @@ void Query_tables_list::destroy_query_tables_list()
*/
st_lex::st_lex()
- :result(0), yacc_yyss(0), yacc_yyvs(0),
+ :result(0),
sql_command(SQLCOM_END)
{
reset_query_tables_list(TRUE);
@@ -2036,12 +2041,26 @@ st_lex::copy_db_to(char **p_db, uint *p_db_length) const
void st_select_lex_unit::set_limit(SELECT_LEX *sl)
{
ha_rows select_limit_val;
+ ulonglong val;
DBUG_ASSERT(! thd->stmt_arena->is_stmt_prepare());
- select_limit_val= (ha_rows)(sl->select_limit ? sl->select_limit->val_uint() :
- HA_POS_ERROR);
- offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
- ULL(0));
+ val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
+ select_limit_val= (ha_rows)val;
+#ifndef BIG_TABLES
+ /*
+ Check for overflow : ha_rows can be smaller then ulonglong if
+ BIG_TABLES is off.
+ */
+ if (val != (ulonglong)select_limit_val)
+ select_limit_val= HA_POS_ERROR;
+#endif
+ val= sl->offset_limit ? sl->offset_limit->val_uint() : ULL(0);
+ offset_limit_cnt= (ha_rows)val;
+#ifndef BIG_TABLES
+ /* Check for truncation. */
+ if (val != (ulonglong)offset_limit_cnt)
+ offset_limit_cnt= HA_POS_ERROR;
+#endif
select_limit_cnt= select_limit_val + offset_limit_cnt;
if (select_limit_cnt < select_limit_val)
select_limit_cnt= HA_POS_ERROR; // no limit
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 6878e2a4694..d91e3907fb3 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -336,11 +336,11 @@ public:
bool no_table_names_allowed; /* used for global order by */
bool no_error; /* suppress error message (convert it to warnings) */
- static void *operator new(size_t size)
+ static void *operator new(size_t size) throw ()
{
return (void*) sql_alloc((uint) size);
}
- static void *operator new(size_t size, MEM_ROOT *mem_root)
+ static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return (void*) alloc_root(mem_root, (uint) size); }
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
@@ -591,6 +591,7 @@ public:
case of an error during prepare the PS is not created.
*/
bool first_execution;
+ bool first_natural_join_processing;
bool first_cond_optimization;
/* do not wrap view fields with Item_ref */
bool no_wrap_view_item;
@@ -1009,7 +1010,6 @@ typedef struct st_lex : public Query_tables_list
LEX_STRING comment, ident;
LEX_USER *grant_user;
XID *xid;
- gptr yacc_yyss,yacc_yyvs;
THD *thd;
CHARSET_INFO *charset, *underscore_charset;
bool text_string_is_7bit;
@@ -1298,6 +1298,59 @@ typedef struct st_lex : public Query_tables_list
}
} LEX;
+
+/**
+ The internal state of the syntax parser.
+ This object is only available during parsing,
+ and is private to the syntax parser implementation (sql_yacc.yy).
+*/
+class Yacc_state
+{
+public:
+ Yacc_state()
+ : yacc_yyss(NULL), yacc_yyvs(NULL)
+ {}
+
+ ~Yacc_state();
+
+ /**
+ Bison internal state stack, yyss, when dynamically allocated using
+ my_yyoverflow().
+ */
+ gptr yacc_yyss;
+
+ /**
+ Bison internal semantic value stack, yyvs, when dynamically allocated using
+ my_yyoverflow().
+ */
+ gptr yacc_yyvs;
+
+ /*
+ TODO: move more attributes from the LEX structure here.
+ */
+};
+
+/**
+ Internal state of the parser.
+ The complete state consist of:
+ - state data used during lexical parsing,
+ - state data used during syntactic parsing.
+*/
+class Parser_state
+{
+public:
+ Parser_state(THD *thd, const char* buff, unsigned int length)
+ : m_lip(thd, buff, length), m_yacc()
+ {}
+
+ ~Parser_state()
+ {}
+
+ Lex_input_stream m_lip;
+ Yacc_state m_yacc;
+};
+
+
struct st_lex_local: public st_lex
{
static void *operator new(size_t size) throw()
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 7913acfd086..1ad2051f065 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -27,7 +27,7 @@ public:
{
return (void*) sql_alloc((uint) size);
}
- static void *operator new[](size_t size)
+ static void *operator new[](size_t size) throw ()
{
return (void*) sql_alloc((uint) size);
}
@@ -466,7 +466,7 @@ public:
struct ilink
{
struct ilink **prev,*next;
- static void *operator new(size_t size)
+ static void *operator new(size_t size) throw ()
{
return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE));
}
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index e9fd04dff15..5477610bb05 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -325,7 +325,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
bzero((char*) &info,sizeof(info));
info.ignore= ignore;
info.handle_duplicates=handle_duplicates;
- info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
+ info.escape_char= (escaped->length() && (ex->escaped_given() ||
+ !(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)))
+ ? (*escaped)[0] : INT_MAX;
READ_INFO read_info(file,tot_length,
ex->cs ? ex->cs : thd->variables.collation_database,
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index e81988617a6..cb55be42339 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -76,7 +76,6 @@ static void remove_escape(char *name);
static bool append_file_to_dir(THD *thd, const char **filename_ptr,
const char *table_name);
static bool check_show_create_table_access(THD *thd, TABLE_LIST *table);
-static bool test_if_data_home_dir(const char *dir);
const char *any_db="*any*"; // Special symbol for check_access
@@ -91,9 +90,57 @@ const char *command_name[]={
};
const char *xa_state_names[]={
- "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
+ "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED", "ROLLBACK ONLY"
};
+/**
+ Mark a XA transaction as rollback-only if the RM unilaterally
+ rolled back the transaction branch.
+
+ @note If a rollback was requested by the RM, this function sets
+ the appropriate rollback error code and transits the state
+ to XA_ROLLBACK_ONLY.
+
+ @return TRUE if transaction was rolled back or if the transaction
+ state is XA_ROLLBACK_ONLY. FALSE otherwise.
+*/
+static bool xa_trans_rolled_back(XID_STATE *xid_state)
+{
+ if (xid_state->rm_error)
+ {
+ switch (xid_state->rm_error) {
+ case ER_LOCK_WAIT_TIMEOUT:
+ my_error(ER_XA_RBTIMEOUT, MYF(0));
+ break;
+ case ER_LOCK_DEADLOCK:
+ my_error(ER_XA_RBDEADLOCK, MYF(0));
+ break;
+ default:
+ my_error(ER_XA_RBROLLBACK, MYF(0));
+ }
+ xid_state->xa_state= XA_ROLLBACK_ONLY;
+ }
+
+ return (xid_state->xa_state == XA_ROLLBACK_ONLY);
+}
+
+/**
+ Rollback work done on behalf of at ransaction branch.
+*/
+static bool xa_trans_rollback(THD *thd)
+{
+ bool status= test(ha_rollback(thd));
+
+ thd->options&= ~(ulong) OPTION_BEGIN;
+ thd->transaction.all.modified_non_trans_table= FALSE;
+ thd->server_status&= ~SERVER_STATUS_IN_TRANS;
+ xid_cache_delete(&thd->transaction.xid_state);
+ thd->transaction.xid_state.xa_state= XA_NOTR;
+ thd->transaction.xid_state.rm_error= 0;
+
+ return status;
+}
+
#ifndef EMBEDDED_LIBRARY
static bool do_command(THD *thd);
#endif // EMBEDDED_LIBRARY
@@ -1711,8 +1758,24 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->set_time();
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_id= global_query_id;
- if (command != COM_STATISTICS && command != COM_PING)
+
+ switch( command ) {
+ /* Ignore these statements. */
+ case COM_STATISTICS:
+ case COM_PING:
+ break;
+ /* Only increase id on these statements but don't count them. */
+ case COM_STMT_PREPARE:
+ case COM_STMT_CLOSE:
+ case COM_STMT_RESET:
next_query_id();
+ break;
+ /* Increase id and count all other statements. */
+ default:
+ statistic_increment(thd->status_var.questions, &LOCK_status);
+ next_query_id();
+ }
+
thread_running++;
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
VOID(pthread_mutex_unlock(&LOCK_thread_count));
@@ -1927,6 +1990,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_length= length;
thd->query= next_packet;
+ /*
+ Count each statement from the client.
+ */
+ statistic_increment(thd->status_var.questions, &LOCK_status);
+
thd->query_id= next_query_id();
thd->set_time(); /* Reset the query start time. */
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
@@ -3097,13 +3165,13 @@ mysql_execute_command(THD *thd)
if (test_if_data_home_dir(lex->create_info.data_file_name))
{
- my_error(ER_WRONG_ARGUMENTS,MYF(0),"DATA DIRECORY");
+ my_error(ER_WRONG_ARGUMENTS,MYF(0),"DATA DIRECTORY");
res= -1;
break;
}
if (test_if_data_home_dir(lex->create_info.index_file_name))
{
- my_error(ER_WRONG_ARGUMENTS,MYF(0),"INDEX DIRECORY");
+ my_error(ER_WRONG_ARGUMENTS,MYF(0),"INDEX DIRECTORY");
res= -1;
break;
}
@@ -5103,6 +5171,7 @@ create_sp_error:
}
DBUG_ASSERT(thd->transaction.xid_state.xid.is_null());
thd->transaction.xid_state.xa_state=XA_ACTIVE;
+ thd->transaction.xid_state.rm_error= 0;
thd->transaction.xid_state.xid.set(thd->lex->xid);
xid_cache_insert(&thd->transaction.xid_state);
thd->transaction.all.modified_non_trans_table= FALSE;
@@ -5128,6 +5197,8 @@ create_sp_error:
my_error(ER_XAER_NOTA, MYF(0));
break;
}
+ if (xa_trans_rolled_back(&thd->transaction.xid_state))
+ break;
thd->transaction.xid_state.xa_state=XA_IDLE;
send_ok(thd);
break;
@@ -5159,6 +5230,12 @@ create_sp_error:
XID_STATE *xs=xid_cache_search(thd->lex->xid);
if (!xs || xs->in_thd)
my_error(ER_XAER_NOTA, MYF(0));
+ else if (xa_trans_rolled_back(xs))
+ {
+ ha_commit_or_rollback_by_xid(thd->lex->xid, 0);
+ xid_cache_delete(xs);
+ break;
+ }
else
{
ha_commit_or_rollback_by_xid(thd->lex->xid, 1);
@@ -5167,6 +5244,11 @@ create_sp_error:
}
break;
}
+ if (xa_trans_rolled_back(&thd->transaction.xid_state))
+ {
+ xa_trans_rollback(thd);
+ break;
+ }
if (thd->transaction.xid_state.xa_state == XA_IDLE &&
thd->lex->xa_opt == XA_ONE_PHASE)
{
@@ -5213,28 +5295,26 @@ create_sp_error:
my_error(ER_XAER_NOTA, MYF(0));
else
{
+ bool ok= !xa_trans_rolled_back(xs);
ha_commit_or_rollback_by_xid(thd->lex->xid, 0);
xid_cache_delete(xs);
- send_ok(thd);
+ if (ok)
+ send_ok(thd);
}
break;
}
if (thd->transaction.xid_state.xa_state != XA_IDLE &&
- thd->transaction.xid_state.xa_state != XA_PREPARED)
+ thd->transaction.xid_state.xa_state != XA_PREPARED &&
+ thd->transaction.xid_state.xa_state != XA_ROLLBACK_ONLY)
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
- if (ha_rollback(thd))
+ if (xa_trans_rollback(thd))
my_error(ER_XAER_RMERR, MYF(0));
else
send_ok(thd);
- thd->options&= ~OPTION_BEGIN;
- thd->transaction.all.modified_non_trans_table= FALSE;
- thd->server_status&= ~SERVER_STATUS_IN_TRANS;
- xid_cache_delete(&thd->transaction.xid_state);
- thd->transaction.xid_state.xa_state=XA_NOTR;
break;
case SQLCOM_XA_RECOVER:
res= mysql_xa_recover(thd);
@@ -5930,29 +6010,35 @@ bool check_stack_overrun(THD *thd, long margin,
bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
{
- LEX *lex= current_thd->lex;
+ Yacc_state *state= & current_thd->m_parser_state->m_yacc;
ulong old_info=0;
+ DBUG_ASSERT(state);
if ((uint) *yystacksize >= MY_YACC_MAX)
return 1;
- if (!lex->yacc_yyvs)
+ if (!state->yacc_yyvs)
old_info= *yystacksize;
*yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX);
- if (!(lex->yacc_yyvs= (char*)
- my_realloc((gptr) lex->yacc_yyvs,
+ if (!(state->yacc_yyvs= (char*)
+ my_realloc(state->yacc_yyvs,
*yystacksize*sizeof(**yyvs),
MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))) ||
- !(lex->yacc_yyss= (char*)
- my_realloc((gptr) lex->yacc_yyss,
+ !(state->yacc_yyss= (char*)
+ my_realloc(state->yacc_yyss,
*yystacksize*sizeof(**yyss),
MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))))
return 1;
if (old_info)
- { // Copy old info from stack
- memcpy(lex->yacc_yyss, (gptr) *yyss, old_info*sizeof(**yyss));
- memcpy(lex->yacc_yyvs, (gptr) *yyvs, old_info*sizeof(**yyvs));
+ {
+ /*
+ Only copy the old stack on the first call to my_yyoverflow(),
+ when replacing a static stack (YYINITDEPTH) by a dynamic stack.
+ For subsequent calls, my_realloc already did preserve the old stack.
+ */
+ memcpy(state->yacc_yyss, *yyss, old_info*sizeof(**yyss));
+ memcpy(state->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
}
- *yyss=(short*) lex->yacc_yyss;
- *yyvs=(YYSTYPE*) lex->yacc_yyvs;
+ *yyss= (short*) state->yacc_yyss;
+ *yyvs= (YYSTYPE*) state->yacc_yyvs;
return 0;
}
@@ -6191,11 +6277,12 @@ void mysql_parse(THD *thd, const char *inBuf, uint length,
sp_cache_flush_obsolete(&thd->sp_proc_cache);
sp_cache_flush_obsolete(&thd->sp_func_cache);
- Lex_input_stream lip(thd, inBuf, length);
- thd->m_lip= &lip;
+ Parser_state parser_state(thd, inBuf, length);
+ thd->m_parser_state= &parser_state;
int err= MYSQLparse(thd);
- *found_semicolon= lip.found_semicolon;
+ *found_semicolon= parser_state.m_lip.found_semicolon;
+ thd->m_parser_state= NULL;
if (!err && ! thd->is_fatal_error)
{
@@ -6220,8 +6307,9 @@ void mysql_parse(THD *thd, const char *inBuf, uint length,
PROCESSLIST.
Note that we don't need LOCK_thread_count to modify query_length.
*/
- if (lip.found_semicolon &&
- (thd->query_length= (ulong)(lip.found_semicolon - thd->query)))
+ if (parser_state.m_lip.found_semicolon &&
+ (thd->query_length= (ulong)(parser_state.m_lip.found_semicolon
+ - thd->query)))
thd->query_length--;
/* Actually execute the query */
if (*found_semicolon)
@@ -6280,11 +6368,13 @@ bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length)
bool error= 0;
DBUG_ENTER("mysql_test_parse_for_slave");
- Lex_input_stream lip(thd, inBuf, length);
- thd->m_lip= &lip;
+ Parser_state parser_state(thd, inBuf, length);
+ thd->m_parser_state= &parser_state;
+
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
int err= MYSQLparse((void*) thd);
+ thd->m_parser_state= NULL;
if (!err && ! thd->is_fatal_error &&
all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
@@ -7114,11 +7204,23 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
thd->thread_stack= (char*) &tmp_thd;
thd->store_globals();
}
+
if (thd)
{
- (void)acl_reload(thd);
- (void)grant_reload(thd);
+ bool reload_acl_failed= acl_reload(thd);
+ bool reload_grants_failed= grant_reload(thd);
+
+ if (reload_acl_failed || reload_grants_failed)
+ {
+ result= 1;
+ /*
+ When an error is returned, my_message may have not been called and
+ the client will hang waiting for a response.
+ */
+ my_error(ER_UNKNOWN_ERROR, MYF(0), "FLUSH PRIVILEGES failed");
+ }
}
+
if (tmp_thd)
{
delete tmp_thd;
@@ -7204,8 +7306,10 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
tmp_write_to_binlog= 0;
if (lock_global_read_lock(thd))
return 1; // Killed
- result=close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1,
- tables);
+ if (close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1,
+ tables))
+ result= 1;
+
if (make_global_read_lock_block_commit(thd)) // Killed
{
/* Don't leave things in a half-locked state */
@@ -7214,7 +7318,10 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
}
}
else
- result=close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1, tables);
+ {
+ if (close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1, tables))
+ result= 1;
+ }
my_dbopt_cleanup();
}
if (options & REFRESH_HOSTS)
@@ -7238,8 +7345,8 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
#ifdef OPENSSL
if (options & REFRESH_DES_KEY_FILE)
{
- if (des_key_file)
- result=load_des_key_file(des_key_file);
+ if (des_key_file && load_des_key_file(des_key_file))
+ result= 1;
}
#endif
#ifdef HAVE_REPLICATION
@@ -7350,7 +7457,7 @@ bool check_simple_select()
if (lex->current_select != &lex->select_lex)
{
char command[80];
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= & thd->m_parser_state->m_lip;
strmake(command, lip->yylval->symbol.str,
min(lip->yylval->symbol.length, sizeof(command)-1));
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
@@ -7974,10 +8081,12 @@ bool check_string_length(LEX_STRING *str, const char *err_msg,
1 error
*/
-static bool test_if_data_home_dir(const char *dir)
+C_MODE_START
+
+int test_if_data_home_dir(const char *dir)
{
- char path[FN_REFLEN], conv_path[FN_REFLEN];
- uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
+ char path[FN_REFLEN];
+ int dir_len;
DBUG_ENTER("test_if_data_home_dir");
if (!dir)
@@ -7985,21 +8094,59 @@ static bool test_if_data_home_dir(const char *dir)
(void) fn_format(path, dir, "", "",
(MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
- dir_len= unpack_dirname(conv_path, dir);
-
- if (home_dir_len <= dir_len)
+ dir_len= strlen(path);
+ if (mysql_unpacked_real_data_home_len<= dir_len)
{
+ if (dir_len > mysql_unpacked_real_data_home_len &&
+ path[mysql_unpacked_real_data_home_len] != FN_LIBCHAR)
+ DBUG_RETURN(0);
+
if (lower_case_file_system)
{
- if (!my_strnncoll(default_charset_info, (const uchar*) conv_path,
- home_dir_len,
+ if (!my_strnncoll(default_charset_info, (const uchar*) path,
+ mysql_unpacked_real_data_home_len,
(const uchar*) mysql_unpacked_real_data_home,
- home_dir_len))
+ mysql_unpacked_real_data_home_len))
DBUG_RETURN(1);
}
- else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
+ else if (!memcmp(path, mysql_unpacked_real_data_home,
+ mysql_unpacked_real_data_home_len))
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
+C_MODE_END
+
+
+/**
+ Check that host name string is valid.
+
+ @param[in] str string to be checked
+
+ @return Operation status
+ @retval FALSE host name is ok
+ @retval TRUE host name string is longer than max_length or
+ has invalid symbols
+*/
+
+bool check_host_name(LEX_STRING *str)
+{
+ const char *name= str->str;
+ const char *end= str->str + str->length;
+ if (check_string_length(str, ER(ER_HOSTNAME), HOSTNAME_LENGTH))
+ return TRUE;
+
+ while (name != end)
+ {
+ if (*name == '@')
+ {
+ my_printf_error(ER_UNKNOWN_ERROR,
+ "Malformed hostname (illegal symbol: '%c')", MYF(0),
+ *name);
+ return TRUE;
+ }
+ name++;
+ }
+ return FALSE;
+}
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index ae6764254cd..505a3d122b4 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2852,12 +2852,13 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
old_stmt_arena= thd->stmt_arena;
thd->stmt_arena= this;
- Lex_input_stream lip(thd, thd->query, thd->query_length);
- lip.stmt_prepare_mode= TRUE;
- thd->m_lip= &lip;
+ Parser_state parser_state(thd, thd->query, thd->query_length);
+ parser_state.m_lip.stmt_prepare_mode= TRUE;
+ thd->m_parser_state= &parser_state;
lex_start(thd);
lex->safe_to_cache_query= FALSE;
int err= MYSQLparse((void *)thd);
+ thd->m_parser_state= NULL;
lex->set_trg_event_type_for_tables();
error= err || thd->is_fatal_error ||
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 9492fd5337a..52434cc0794 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -390,11 +390,21 @@ inline int setup_without_group(THD *thd, Item **ref_pointer_array,
{
int res;
nesting_map save_allow_sum_func=thd->lex->allow_sum_func ;
+ /*
+ Need to save the value, so we can turn off only the new NON_AGG_FIELD
+ additions coming from the WHERE
+ */
+ uint8 saved_flag= thd->lex->current_select->full_group_by_flag;
DBUG_ENTER("setup_without_group");
thd->lex->allow_sum_func&= ~(1 << thd->lex->current_select->nest_level);
res= setup_conds(thd, tables, leaves, conds);
+ /* it's not wrong to have non-aggregated columns in a WHERE */
+ if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
+ thd->lex->current_select->full_group_by_flag= saved_flag |
+ (thd->lex->current_select->full_group_by_flag & ~NON_AGG_FIELD_USED);
+
thd->lex->allow_sum_func|= 1 << thd->lex->current_select->nest_level;
res= res || setup_order(thd, ref_pointer_array, tables, fields, all_fields,
order);
@@ -1735,7 +1745,8 @@ JOIN::exec()
if (!items1)
{
items1= items0 + all_fields.elements;
- if (sort_and_group || curr_tmp_table->group)
+ if (sort_and_group || curr_tmp_table->group ||
+ tmp_table_param.precomputed_group_by)
{
if (change_to_use_tmp_fields(thd, items1,
tmp_fields_list1, tmp_all_fields1,
@@ -6481,6 +6492,12 @@ void JOIN::cleanup(bool full)
if (tmp_join)
tmp_table_param.copy_field= 0;
group_fields.delete_elements();
+ /*
+ Ensure that the above delete_elements() would not be called
+ twice for the same list.
+ */
+ if (tmp_join && tmp_join != this)
+ tmp_join->group_fields= group_fields;
/*
We can't call delete_elements() on copy_funcs as this will cause
problems in free_elements() as some of the elements are then deleted.
@@ -6579,6 +6596,7 @@ only_eq_ref_tables(JOIN *join,ORDER *order,table_map tables)
{
if (specialflag & SPECIAL_SAFE_MODE)
return 0; // skip this optimize /* purecov: inspected */
+ tables&= ~PSEUDO_TABLE_BITS;
for (JOIN_TAB **tab=join->map2table ; tables ; tab++, tables>>=1)
{
if (tables & 1 && !eq_ref_table(join, order, *tab))
@@ -8273,6 +8291,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
}
/* Flatten nested joins that can be flattened. */
+ TABLE_LIST *right_neighbor= NULL;
+ bool fix_name_res= FALSE;
li.rewind();
while ((table= li++))
{
@@ -8285,9 +8305,17 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
{
tbl->embedding= table->embedding;
tbl->join_list= table->join_list;
- }
+ }
li.replace(nested_join->join_list);
+ /* Need to update the name resolution table chain when flattening joins */
+ fix_name_res= TRUE;
+ table= *li.ref();
}
+ if (fix_name_res)
+ table->next_name_resolution_table= right_neighbor ?
+ right_neighbor->first_leaf_for_name_resolution() :
+ NULL;
+ right_neighbor= table;
}
DBUG_RETURN(conds);
}
@@ -8969,6 +8997,7 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
*/
if ((type= item->field_type()) == MYSQL_TYPE_DATETIME ||
type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE ||
+ type == MYSQL_TYPE_NEWDATE ||
type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_GEOMETRY)
new_field= item->tmp_table_field_from_field_type(table);
/*
@@ -9265,6 +9294,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
MI_COLUMNDEF *recinfo;
uint total_uneven_bit_length= 0;
bool force_copy_fields= param->force_copy_fields;
+ /* Treat sum functions as normal ones when loose index scan is used. */
+ save_sum_fields|= param->precomputed_group_by;
DBUG_ENTER("create_tmp_table");
DBUG_PRINT("enter",("distinct: %d save_sum_fields: %d rows_limit: %lu group: %d",
(int) distinct, (int) save_sum_fields,
@@ -11321,7 +11352,7 @@ join_init_read_record(JOIN_TAB *tab)
if (tab->select && tab->select->quick && tab->select->quick->reset())
return 1;
init_read_record(&tab->read_record, tab->join->thd, tab->table,
- tab->select,1,1);
+ tab->select,1,1, FALSE);
return (*tab->read_record.read_record)(&tab->read_record);
}
@@ -12100,26 +12131,25 @@ part_of_refkey(TABLE *table,Field *field)
}
-/*****************************************************************************
- Test if one can use the key to resolve ORDER BY
-
- SYNOPSIS
- test_if_order_by_key()
- order Sort order
- table Table to sort
- idx Index to check
- used_key_parts Return value for used key parts.
-
-
- NOTES
- used_key_parts is set to correct key parts used if return value != 0
- (On other cases, used_key_part may be changed)
-
- RETURN
- 1 key is ok.
- 0 Key can't be used
- -1 Reverse key can be used
-*****************************************************************************/
+/**
+ Test if a key can be used to resolve ORDER BY
+
+ used_key_parts is set to correct key parts used if return value != 0
+ (On other cases, used_key_part may be changed).
+ Note that the value may actually be greater than the number of index
+ key parts. This can happen for storage engines that have the primary
+ key parts as a suffix for every secondary key.
+
+ @param order Sort order
+ @param table Table to sort
+ @param idx Index to check
+ @param[out] used_key_parts Return value for used key parts.
+
+ @return indication if the key can be used for sorting
+ @retval 1 key can be used for reading data in order.
+ @retval 0 Key can't be used
+ @retval -1 Reverse read on the key can be used
+*/
static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
uint *used_key_parts)
@@ -12184,11 +12214,27 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
reverse=flag; // Remember if reverse
key_part++;
}
- *used_key_parts= on_primary_key ? table->key_info[idx].key_parts :
- (uint) (key_part - table->key_info[idx].key_part);
- if (reverse == -1 && !(table->file->index_flags(idx, *used_key_parts-1, 1) &
- HA_READ_PREV))
- reverse= 0; // Index can't be used
+ if (on_primary_key)
+ {
+ uint used_key_parts_secondary= table->key_info[idx].key_parts;
+ uint used_key_parts_pk=
+ (uint) (key_part - table->key_info[table->s->primary_key].key_part);
+ *used_key_parts= used_key_parts_pk + used_key_parts_secondary;
+
+ if (reverse == -1 &&
+ (!(table->file->index_flags(idx, used_key_parts_secondary - 1, 1) &
+ HA_READ_PREV) ||
+ !(table->file->index_flags(table->s->primary_key,
+ used_key_parts_pk - 1, 1) & HA_READ_PREV)))
+ reverse= 0; // Index can't be used
+ }
+ else
+ {
+ *used_key_parts= (uint) (key_part - table->key_info[idx].key_part);
+ if (reverse == -1 &&
+ !(table->file->index_flags(idx, *used_key_parts-1, 1) & HA_READ_PREV))
+ reverse= 0; // Index can't be used
+ }
DBUG_RETURN(reverse);
}
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 42be8d3ec68..c2f0780f5be 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -464,7 +464,7 @@ public:
bool send_row_on_empty_set()
{
return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
- !group_list);
+ !group_list && having_value != Item::COND_FALSE);
}
bool change_result(select_result *result);
bool is_top_level_join() const
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 1230e8df494..fb53a6bf2d8 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1441,6 +1441,7 @@ static bool show_status_array(THD *thd, const char *wild,
char name_buffer[80];
int len;
LEX_STRING null_lex_str;
+ CHARSET_INFO *charset= system_charset_info;
DBUG_ENTER("show_status_array");
null_lex_str.str= 0; // For sys_var->value_ptr()
@@ -1469,9 +1470,10 @@ static bool show_status_array(THD *thd, const char *wild,
long nr;
if (show_type == SHOW_SYS)
{
- show_type= ((sys_var*) value)->show_type();
- value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
- &null_lex_str);
+ sys_var *var= ((sys_var *) value);
+ show_type= var->show_type();
+ value= (char*) var->value_ptr(thd, value_type, &null_lex_str);
+ charset= var->charset(thd);
}
pos= end= buff;
@@ -1524,9 +1526,6 @@ static bool show_status_array(THD *thd, const char *wild,
nr= (long) (thd->query_start() - flush_status_time);
end= int10_to_str(nr, buff, 10);
break;
- case SHOW_QUESTION:
- end= int10_to_str((long) thd->query_id, buff, 10);
- break;
#ifdef HAVE_REPLICATION
case SHOW_RPL_STATUS:
end= strmov(buff, rpl_status_type[(int)rpl_status]);
@@ -1801,7 +1800,7 @@ static bool show_status_array(THD *thd, const char *wild,
restore_record(table, s->default_values);
table->field[0]->store(name_buffer, strlen(name_buffer),
system_charset_info);
- table->field[1]->store(pos, (uint32) (end - pos), system_charset_info);
+ table->field[1]->store(pos, (uint32) (end - pos), charset);
if (schema_table_store_record(thd, table))
DBUG_RETURN(TRUE);
}
@@ -3174,6 +3173,27 @@ static int get_schema_views_record(THD *thd, TABLE_LIST *tables,
!my_strcasecmp(system_charset_info, tables->definer.host.str,
sctx->priv_host))
tables->allowed_show= TRUE;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ else
+ {
+ if ((thd->col_access & (SHOW_VIEW_ACL|SELECT_ACL)) ==
+ (SHOW_VIEW_ACL|SELECT_ACL))
+ tables->allowed_show= TRUE;
+ else
+ {
+ TABLE_LIST table_list;
+ uint view_access;
+ memset(&table_list, 0, sizeof(table_list));
+ table_list.db= tables->view_db.str;
+ table_list.table_name= tables->view_name.str;
+ table_list.grant.privilege= thd->col_access;
+ view_access= get_table_grant(thd, &table_list);
+ if ((view_access & (SHOW_VIEW_ACL|SELECT_ACL)) ==
+ (SHOW_VIEW_ACL|SELECT_ACL))
+ tables->allowed_show= TRUE;
+ }
+ }
+#endif
}
restore_record(table, s->default_values);
table->field[1]->store(tables->view_db.str, tables->view_db.length, cs);
@@ -3694,16 +3714,10 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING ||
fields_info->field_type == MYSQL_TYPE_DECIMAL);
- /**
- @todo Change when Item_empty_string is fixed (in 4.1). [Presumably,
- this means removing the first of two steps: setting a useless, bogus
- value; and then setting the attributes.]
- */
- if (!(item= new Item_empty_string("", 0, cs)))
+ if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
{
DBUG_RETURN(0);
}
- item->max_length= fields_info->field_length * cs->mbmaxlen;
item->set_name(fields_info->field_name,
strlen(fields_info->field_name), cs);
break;
diff --git a/sql/sql_string.h b/sql/sql_string.h
index c1d27cb1791..4432451464e 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -78,7 +78,7 @@ public:
Alloced_length=str.Alloced_length; alloced=0;
str_charset=str.str_charset;
}
- static void *operator new(size_t size, MEM_ROOT *mem_root)
+ static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return (void*) alloc_root(mem_root, (uint) size); }
static void operator delete(void *ptr_arg,size_t size)
{ TRASH(ptr_arg, size); }
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index accd943a05b..8f091fe6c48 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2322,6 +2322,12 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
goto send_result;
}
+ if (table->schema_table)
+ {
+ result_code= HA_ADMIN_NOT_IMPLEMENTED;
+ goto send_result;
+ }
+
if ((table->table->db_stat & HA_READ_ONLY) && open_for_modify)
{
char buff[FN_REFLEN + MYSQL_ERRMSG_SIZE];
@@ -4177,7 +4183,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
current query id
*/
from->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
- init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1,1);
+ init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1, 1, FALSE);
if (ignore)
to->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
thd->row_count= 0;
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 1737bb0d9f8..d3b5289cd68 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -479,7 +479,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
trigname.trigger_table.length= tables->table_name_length;
if (sql_create_definition_file(&dir, &trigname_file, &trigname_file_type,
- (gptr)&trigname, trigname_file_parameters, 0))
+ (gptr)&trigname, trigname_file_parameters))
return 1;
/*
@@ -569,7 +569,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
/* Create trigger definition file. */
if (!sql_create_definition_file(&dir, &file, &triggers_file_type,
- (gptr)this, triggers_file_parameters, 0))
+ (gptr)this, triggers_file_parameters))
return 0;
err_with_cleanup:
@@ -656,7 +656,7 @@ static bool save_trigger_file(Table_triggers_list *triggers, const char *db,
file.str= file_buff;
return sql_create_definition_file(&dir, &file, &triggers_file_type,
- (gptr)triggers, triggers_file_parameters, 0);
+ (gptr)triggers, triggers_file_parameters);
}
@@ -968,11 +968,13 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
thd->variables.sql_mode= (ulong)*trg_sql_mode;
- Lex_input_stream lip(thd, trg_create_str->str, trg_create_str->length);
- thd->m_lip= &lip;
+ Parser_state parser_state(thd, trg_create_str->str,
+ trg_create_str->length);
+ thd->m_parser_state= &parser_state;
lex_start(thd);
thd->spcont= NULL;
int err= MYSQLparse((void *)thd);
+ thd->m_parser_state= NULL;
if (err || thd->is_fatal_error)
{
@@ -1425,7 +1427,7 @@ Table_triggers_list::change_table_name_in_trignames(const char *db_name,
trigname.trigger_table= *new_table_name;
if (sql_create_definition_file(&dir, &trigname_file, &trigname_file_type,
- (gptr)&trigname, trigname_file_parameters, 0))
+ (gptr)&trigname, trigname_file_parameters))
return trigger;
}
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index e3a0230d2fb..6520c1a661e 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -176,7 +176,7 @@ void udf_init()
}
table= tables.table;
- init_read_record(&read_record_info, new_thd, table, NULL,1,0);
+ init_read_record(&read_record_info, new_thd, table, NULL,1,0,FALSE);
while (!(error = read_record_info.read_record(&read_record_info)))
{
DBUG_PRINT("info",("init udf record"));
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index da5e118b069..2875aefbd97 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -399,7 +399,6 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
}
else
{
- DBUG_ASSERT(!thd->stmt_arena->is_conventional());
/*
We're in execution of a prepared statement or stored procedure:
reset field items to point at fields from the created temporary table.
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 7c619092df1..ad7cb87514d 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -358,7 +358,7 @@ int mysql_update(THD *thd,
Full index scan must be started with init_read_record_idx
*/
if (used_index == MAX_KEY || (select && select->quick))
- init_read_record(&info,thd,table,select,0,1);
+ init_read_record(&info, thd, table, select, 0, 1, FALSE);
else
init_read_record_idx(&info, thd, table, 1, used_index);
@@ -422,7 +422,7 @@ int mysql_update(THD *thd,
if (select && select->quick && select->quick->reset())
goto err;
- init_read_record(&info,thd,table,select,0,1);
+ init_read_record(&info, thd, table, select, 0, 1, FALSE);
updated= found= 0;
thd->count_cuted_fields= CHECK_FIELD_WARN; /* calc cuted fields */
@@ -852,11 +852,14 @@ reopen_tables:
}
/* now lock and fill tables */
- if (lock_tables(thd, table_list, table_count, &need_reopen))
+ if (!thd->stmt_arena->is_stmt_prepare() &&
+ lock_tables(thd, table_list, table_count, &need_reopen))
{
if (!need_reopen)
DBUG_RETURN(TRUE);
+ DBUG_PRINT("info", ("lock_tables failed, reopening"));
+
/*
We have to reopen tables since some of them were altered or dropped
during lock_tables() or something was done with their triggers.
@@ -872,6 +875,34 @@ reopen_tables:
for (TABLE_LIST *tbl= table_list; tbl; tbl= tbl->next_global)
tbl->cleanup_items();
+ /*
+ To not to hog memory (as a result of the
+ unit->reinit_exec_mechanism() call below):
+ */
+ lex->unit.cleanup();
+
+ for (SELECT_LEX *sl= lex->all_selects_list;
+ sl;
+ sl= sl->next_select_in_list())
+ {
+ SELECT_LEX_UNIT *unit= sl->master_unit();
+ unit->reinit_exec_mechanism(); // reset unit->prepared flags
+ /*
+ Reset 'clean' flag back to force normal execution of
+ unit->cleanup() in Prepared_statement::cleanup_stmt()
+ (call to lex->unit.cleanup() above sets this flag to TRUE).
+ */
+ unit->unclean();
+ }
+
+ /*
+ Also we need to cleanup Natural_join_column::table_field items.
+ To not to traverse a join tree we will cleanup whole
+ thd->free_list (in PS execution mode that list may not contain
+ items from 'fields' list, so the cleanup above is necessary to.
+ */
+ cleanup_items(thd->free_list);
+
close_tables_for_reopen(thd, &table_list);
goto reopen_tables;
}
@@ -1218,6 +1249,32 @@ multi_update::initialize_tables(JOIN *join)
}
}
+ /*
+ enable uncacheable flag if we update a view with check option
+ and check option has a subselect, otherwise, the check option
+ can be evaluated after the subselect was freed as independent
+ (See full_local in JOIN::join_free()).
+ */
+ if (table_ref->check_option && !join->select_lex->uncacheable)
+ {
+ SELECT_LEX_UNIT *tmp_unit;
+ SELECT_LEX *sl;
+ for (tmp_unit= join->select_lex->first_inner_unit();
+ tmp_unit;
+ tmp_unit= tmp_unit->next_unit())
+ {
+ for (sl= tmp_unit->first_select(); sl; sl= sl->next_select())
+ {
+ if (sl->master_unit()->item)
+ {
+ join->select_lex->uncacheable|= UNCACHEABLE_CHECKOPTION;
+ goto loop_end;
+ }
+ }
+ }
+ }
+loop_end:
+
if (table == first_table_for_update && table_ref->check_option)
{
table_map unupdated_tables= table_ref->check_option->used_tables() &
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index fee71e01c78..1a758f2aecc 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -660,7 +660,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
}
VOID(pthread_mutex_unlock(&LOCK_open));
- if (view->revision != 1)
+ if (mode != VIEW_CREATE_NEW)
query_cache_invalidate3(thd, view, 0);
start_waiting_global_read_lock(thd);
if (res)
@@ -678,12 +678,8 @@ err:
}
-/* index of revision number in following table */
-static const int revision_number_position= 8;
-/* index of last required parameter for making view */
-static const int required_view_parameters= 10;
-/* number of backups */
-static const int num_view_backups= 3;
+/* number of required parameters for making view */
+static const int required_view_parameters= 9;
/*
table of VIEW .frm field descriptors
@@ -716,9 +712,6 @@ static File_option view_parameters[]=
{{(char*) STRING_WITH_LEN("with_check_option")},
my_offsetof(TABLE_LIST, with_check),
FILE_OPTIONS_ULONGLONG},
- {{(char*) STRING_WITH_LEN("revision")},
- my_offsetof(TABLE_LIST, revision),
- FILE_OPTIONS_REV},
{{(char*) STRING_WITH_LEN("timestamp")},
my_offsetof(TABLE_LIST, timestamp),
FILE_OPTIONS_TIMESTAMP},
@@ -774,8 +767,13 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
DBUG_PRINT("info", ("View: %s", str.ptr()));
/* fill structure */
- view->query.str= str.c_ptr_safe();
- view->query.length= str.length();
+ if (!make_lex_string(thd, &view->query, str.ptr(), str.length(), false))
+ {
+ my_error(ER_OUT_OF_RESOURCES, MYF(0));
+ error= -1;
+ goto err;
+ }
+
view->source.str= thd->query + thd->lex->create_view_select_start;
view->source.length= (char *)skip_rear_comments(thd->charset(),
(char *)view->source.str,
@@ -784,7 +782,12 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
view->source.str;
view->file_version= 1;
view->calc_md5(md5);
- view->md5.str= md5;
+ if (!(view->md5.str= thd->memdup(md5, 32)))
+ {
+ my_error(ER_OUT_OF_RESOURCES, MYF(0));
+ error= -1;
+ goto err;
+ }
view->md5.length= 32;
can_be_merged= lex->can_be_merged();
if (lex->create_view_algorithm == VIEW_ALGORITHM_MERGE &&
@@ -870,18 +873,9 @@ loop_out:
}
/*
- read revision number
-
TODO: read dependence list, too, to process cascade/restrict
TODO: special cascade/restrict procedure for alter?
*/
- if (parser->parse((gptr)view, thd->mem_root,
- view_parameters + revision_number_position, 1,
- &file_parser_dummy_hook))
- {
- error= thd->net.report_error? -1 : 0;
- goto err;
- }
}
else
{
@@ -923,7 +917,7 @@ loop_out:
}
if (sql_create_definition_file(&dir, &file, view_file_type,
- (gptr)view, view_parameters, num_view_backups))
+ (gptr)view, view_parameters))
{
error= thd->net.report_error? -1 : 1;
goto err;
@@ -986,13 +980,14 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
DBUG_RETURN(0);
}
- if (table->use_index || table->ignore_index)
+ List<String> *index_list= table->use_index ? table->use_index
+ : table->ignore_index;
+ if (index_list)
{
- my_error(ER_WRONG_USAGE, MYF(0),
- table->ignore_index ? "IGNORE INDEX" :
- (table->force_index ? "FORCE INDEX" : "USE INDEX"),
- "VIEW");
- DBUG_RETURN(TRUE);
+ DBUG_ASSERT(index_list->head()); // should never fail
+ my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), index_list->head()->c_ptr(),
+ table->table_name);
+ DBUG_RETURN(TRUE);
}
/* check loop via view definition */
@@ -1081,8 +1076,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
char old_db_buf[NAME_LEN+1];
LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
bool dbchanged;
- Lex_input_stream lip(thd, table->query.str, table->query.length);
- thd->m_lip= &lip;
+ Parser_state parser_state(thd, table->query.str, table->query.length);
/*
Use view db name as thread default database, in order to ensure
@@ -1091,6 +1085,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
if ((result= sp_use_new_db(thd, table->view_db, &old_db, 1, &dbchanged)))
goto end;
+ thd->m_parser_state= &parser_state;
lex_start(thd);
view_select= &lex->select_lex;
view_select->select_number= ++thd->select_number;
@@ -1125,6 +1120,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
CHARSET_INFO *save_cs= thd->variables.character_set_client;
thd->variables.character_set_client= system_charset_info;
res= MYSQLparse((void *)thd);
+ thd->m_parser_state= NULL;
if ((old_lex->sql_command == SQLCOM_SHOW_FIELDS) ||
(old_lex->sql_command == SQLCOM_SHOW_CREATE))
@@ -1857,8 +1853,7 @@ mysql_rename_view(THD *thd,
goto err;
/* rename view and it's backups */
- if (rename_in_schema_file(view->db, view->table_name, new_name,
- view_def.revision - 1, num_view_backups))
+ if (rename_in_schema_file(thd, view->db, view->table_name, new_name))
goto err;
strxnmov(dir_buff, FN_REFLEN, mysql_data_home, "/", view->db, "/", NullS);
@@ -1872,12 +1867,10 @@ mysql_rename_view(THD *thd,
- file_buff);
if (sql_create_definition_file(&pathstr, &file, view_file_type,
- (gptr)&view_def, view_parameters,
- num_view_backups))
+ (gptr)&view_def, view_parameters))
{
/* restore renamed view in case of error */
- rename_in_schema_file(view->db, new_name, view->table_name,
- view_def.revision - 1, num_view_backups);
+ rename_in_schema_file(thd, view->db, new_name, view->table_name);
goto err;
}
} else
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 76fcc15926e..b08650ac4f7 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -23,6 +23,7 @@
#define YYPARSE_PARAM yythd
#define YYLEX_PARAM yythd
#define YYTHD ((THD *)yythd)
+#define YYLIP (& YYTHD->m_parser_state->m_lip)
#define MYSQL_YACC
#define YYINITDEPTH 100
@@ -86,7 +87,7 @@ const LEX_STRING null_lex_str={0,0};
void my_parse_error(const char *s)
{
THD *thd= current_thd;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= & thd->m_parser_state->m_lip;
const char *yytext= lip->tok_start;
/* Push an error into the error stack */
@@ -1226,11 +1227,11 @@ query:
MYSQL_YYABORT;
}
thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
- thd->m_lip->found_semicolon= NULL;
+ YYLIP->found_semicolon= NULL;
}
| verb_clause
{
- Lex_input_stream *lip = YYTHD->m_lip;
+ Lex_input_stream *lip = YYLIP;
if ((YYTHD->client_capabilities & CLIENT_MULTI_QUERIES) &&
! lip->stmt_prepare_mode &&
@@ -1256,7 +1257,7 @@ query:
| verb_clause END_OF_INPUT
{
/* Single query, not terminated. */
- YYTHD->m_lip->found_semicolon= NULL;
+ YYLIP->found_semicolon= NULL;
}
;
@@ -1552,6 +1553,8 @@ create:
{
LEX *lex=Lex;
Key *key= new Key($2, $4.str, $5, 0, lex->col_list);
+ if (key == NULL)
+ MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty();
@@ -1611,6 +1614,8 @@ sp_name:
MYSQL_YYABORT;
}
$$= new sp_name($1, $3, true);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
$$->init_qname(YYTHD);
}
| ident
@@ -1626,8 +1631,9 @@ sp_name:
if (lex->copy_db_to(&db.str, &db.length))
MYSQL_YYABORT;
$$= new sp_name(db, $1, false);
- if ($$)
- $$->init_qname(YYTHD);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ $$->init_qname(YYTHD);
}
;
@@ -1878,6 +1884,8 @@ sp_decl:
if (!dflt_value_item)
{
dflt_value_item= new Item_null();
+ if (dflt_value_item == NULL)
+ MYSQL_YYABORT;
/* QQ Set to the var_type with null_value? */
}
@@ -1903,10 +1911,17 @@ sp_decl:
/* The last instruction is responsible for freeing LEX. */
- lex->sphead->add_instr(
- new sp_instr_set(lex->sphead->instructions(), pctx, var_idx,
- dflt_value_item, var_type, lex,
- (i == num_vars - 1)));
+ sp_instr_set *is= new sp_instr_set(lex->sphead->instructions(),
+ pctx,
+ var_idx,
+ dflt_value_item,
+ var_type,
+ lex,
+ (i == num_vars - 1));
+ if (is == NULL)
+ MYSQL_YYABORT;
+
+ lex->sphead->add_instr(is);
}
pctx->declare_var_boundary(0);
@@ -1940,6 +1955,8 @@ sp_decl:
sp_instr_hpush_jump *i=
new sp_instr_hpush_jump(sp->instructions(), ctx, $2,
ctx->current_var_count());
+ if (i == NULL)
+ MYSQL_YYABORT;
sp->add_instr(i);
sp->push_backpatch(i, ctx->push_label((char *)"", 0));
@@ -1992,7 +2009,7 @@ sp_decl:
}
i= new sp_instr_cpush(sp->instructions(), ctx, $5,
ctx->current_cursor_count());
- if ( i==NULL )
+ if (i == NULL)
MYSQL_YYABORT;
sp->add_instr(i);
ctx->push_cursor(&$2);
@@ -2073,6 +2090,8 @@ sp_cond:
ulong_num
{ /* mysql errno */
$$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+ if ($$ == NULL)
+ YYABORT;
$$->type= sp_cond_type_t::number;
$$->mysqlerr= $1;
}
@@ -2084,6 +2103,8 @@ sp_cond:
MYSQL_YYABORT;
}
$$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+ if ($$ == NULL)
+ YYABORT;
$$->type= sp_cond_type_t::state;
memcpy($$->sqlstate, $3.str, 5);
$$->sqlstate[5]= '\0';
@@ -2112,16 +2133,22 @@ sp_hcond:
| SQLWARNING_SYM /* SQLSTATEs 01??? */
{
$$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+ if ($$ == NULL)
+ YYABORT;
$$->type= sp_cond_type_t::warning;
}
| not FOUND_SYM /* SQLSTATEs 02??? */
{
$$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+ if ($$ == NULL)
+ YYABORT;
$$->type= sp_cond_type_t::notfound;
}
| SQLEXCEPTION_SYM /* All other SQLSTATEs */
{
$$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+ if ($$ == NULL)
+ YYABORT;
$$->type= sp_cond_type_t::exception;
}
;
@@ -2168,7 +2195,7 @@ sp_proc_stmt:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
if (lex->sphead->reset_lex(thd))
MYSQL_YYABORT;
@@ -2178,7 +2205,7 @@ sp_proc_stmt:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
sp_head *sp= lex->sphead;
sp->m_flags|= sp_get_flags_for_command(lex);
@@ -3097,6 +3124,8 @@ key_def:
{
LEX *lex=Lex;
Key *key= new Key($1, $2, $7 ? $7 : $3, 0, lex->col_list);
+ if (key == NULL)
+ MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
@@ -3106,6 +3135,8 @@ key_def:
LEX *lex=Lex;
const char *key_name= $3 ? $3:$1;
Key *key= new Key($2, key_name, $4, 0, lex->col_list);
+ if (key == NULL)
+ MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
}
@@ -3119,10 +3150,14 @@ key_def:
lex->fk_delete_opt,
lex->fk_update_opt,
lex->fk_match_option);
+ if (key == NULL)
+ MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
key= new Key(Key::MULTIPLE, key_name,
HA_KEY_ALG_UNDEF, 1,
lex->col_list);
+ if (key == NULL)
+ MYSQL_YYABORT;
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
}
@@ -3412,7 +3447,12 @@ attribute:
;
now_or_signed_literal:
- NOW_SYM optional_braces { $$= new Item_func_now_local(); }
+ NOW_SYM optional_braces
+ {
+ $$= new Item_func_now_local();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| signed_literal { $$=$1; }
;
@@ -3538,8 +3578,21 @@ opt_ref_list:
| '(' ref_list ')' opt_on_delete {};
ref_list:
- ref_list ',' ident { Lex->ref_list.push_back(new key_part_spec($3.str)); }
- | ident { Lex->ref_list.push_back(new key_part_spec($1.str)); };
+ ref_list ',' ident
+ {
+ key_part_spec *key= new key_part_spec($3.str);
+ if (key == NULL)
+ MYSQL_YYABORT;
+ Lex->ref_list.push_back(key);
+ }
+ | ident
+ {
+ key_part_spec *key= new key_part_spec($1.str);
+ if (key == NULL)
+ MYSQL_YYABORT;
+ Lex->ref_list.push_back(key);
+ }
+ ;
opt_on_delete:
@@ -3630,16 +3683,24 @@ key_list:
| key_part order_dir { Lex->col_list.push_back($1); };
key_part:
- ident { $$=new key_part_spec($1.str); }
- | ident '(' NUM ')'
- {
- int key_part_len= atoi($3.str);
- if (!key_part_len)
+ ident
{
- my_error(ER_KEY_PART_0, MYF(0), $1.str);
+ $$= new key_part_spec($1.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
- $$=new key_part_spec($1.str,(uint) key_part_len);
- };
+ | ident '(' NUM ')'
+ {
+ int key_part_len= atoi($3.str);
+ if (!key_part_len)
+ {
+ my_error(ER_KEY_PART_0, MYF(0), $1.str);
+ }
+ $$=new key_part_spec($1.str,(uint) key_part_len);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ ;
opt_ident:
/* empty */ { $$=(char*) 0; } /* Defaultlength */
@@ -3809,8 +3870,10 @@ alter_list_item:
| DROP opt_column field_ident opt_restrict
{
LEX *lex=Lex;
- lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
- $3.str));
+ Alter_drop *ad= new Alter_drop(Alter_drop::COLUMN, $3.str);
+ if (ad == NULL)
+ MYSQL_YYABORT;
+ lex->alter_info.drop_list.push_back(ad);
lex->alter_info.flags|= ALTER_DROP_COLUMN;
}
| DROP FOREIGN KEY_SYM opt_ident
@@ -3820,15 +3883,19 @@ alter_list_item:
| DROP PRIMARY_SYM KEY_SYM
{
LEX *lex=Lex;
- lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
- primary_key_name));
+ Alter_drop *ad= new Alter_drop(Alter_drop::KEY, primary_key_name);
+ if (ad == NULL)
+ MYSQL_YYABORT;
+ lex->alter_info.drop_list.push_back(ad);
lex->alter_info.flags|= ALTER_DROP_INDEX;
}
| DROP key_or_index field_ident
{
LEX *lex=Lex;
- lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
- $3.str));
+ Alter_drop *ad= new Alter_drop(Alter_drop::KEY, $3.str);
+ if (ad == NULL)
+ MYSQL_YYABORT;
+ lex->alter_info.drop_list.push_back(ad);
lex->alter_info.flags|= ALTER_DROP_INDEX;
}
| DISABLE_SYM KEYS
@@ -3846,14 +3913,19 @@ alter_list_item:
| ALTER opt_column field_ident SET DEFAULT signed_literal
{
LEX *lex=Lex;
- lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
+ Alter_column *ac= new Alter_column($3.str, $6);
+ if (ac == NULL)
+ MYSQL_YYABORT;
+ lex->alter_info.alter_list.push_back(ac);
lex->alter_info.flags|= ALTER_CHANGE_COLUMN_DEFAULT;
}
| ALTER opt_column field_ident DROP DEFAULT
{
LEX *lex=Lex;
- lex->alter_info.alter_list.push_back(new Alter_column($3.str,
- (Item*) 0));
+ Alter_column *ac= new Alter_column($3.str, (Item*) 0);
+ if (ac == NULL)
+ MYSQL_YYABORT;
+ lex->alter_info.alter_list.push_back(ac);
lex->alter_info.flags|= ALTER_CHANGE_COLUMN_DEFAULT;
}
| RENAME opt_to table_ident
@@ -4479,10 +4551,11 @@ select_item_list:
| '*'
{
THD *thd= YYTHD;
- if (add_item_to_list(thd,
- new Item_field(&thd->lex->current_select->
- context,
- NULL, NULL, "*")))
+ Item *item= new Item_field(&thd->lex->current_select->context,
+ NULL, NULL, "*");
+ if (item == NULL)
+ MYSQL_YYABORT;
+ if (add_item_to_list(thd, item))
MYSQL_YYABORT;
(thd->lex->current_select->with_wild)++;
};
@@ -4516,16 +4589,12 @@ select_item:
remember_name:
{
- THD *thd= YYTHD;
- Lex_input_stream *lip= thd->m_lip;
- $$= (char*) lip->tok_start;
+ $$= (char*) YYLIP->tok_start;
};
remember_end:
{
- THD *thd= YYTHD;
- Lex_input_stream *lip= thd->m_lip;
- $$=(char*) lip->tok_end;
+ $$=(char*) YYLIP->tok_end;
};
select_item2:
@@ -4593,12 +4662,16 @@ expr:
{
/* X OR Y */
$$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
}
| expr XOR expr %prec XOR
{
/* XOR is a proprietary extension */
$$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| expr and expr %prec AND_SYM
{
@@ -4639,62 +4712,124 @@ expr:
{
/* X AND Y */
$$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
}
| NOT_SYM expr %prec NOT_SYM
- { $$= negate_expression(YYTHD, $2); }
+ {
+ $$= negate_expression(YYTHD, $2);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS TRUE_SYM %prec IS
- { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
+ {
+ $$= new (YYTHD->mem_root) Item_func_istrue($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS not TRUE_SYM %prec IS
- { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
+ {
+ $$= new (YYTHD->mem_root) Item_func_isnottrue($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS FALSE_SYM %prec IS
- { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
+ {
+ $$= new (YYTHD->mem_root) Item_func_isfalse($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS not FALSE_SYM %prec IS
- { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
+ {
+ $$= new (YYTHD->mem_root) Item_func_isnotfalse($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS UNKNOWN_SYM %prec IS
- { $$= new Item_func_isnull($1); }
+ {
+ $$= new Item_func_isnull($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS not UNKNOWN_SYM %prec IS
- { $$= new Item_func_isnotnull($1); }
+ {
+ $$= new Item_func_isnotnull($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri
;
bool_pri:
bool_pri IS NULL_SYM %prec IS
- { $$= new Item_func_isnull($1); }
+ {
+ $$= new Item_func_isnull($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri IS not NULL_SYM %prec IS
- { $$= new Item_func_isnotnull($1); }
+ {
+ $$= new Item_func_isnotnull($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
- { $$= new Item_func_equal($1,$3); }
+ {
+ $$= new Item_func_equal($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri comp_op predicate %prec EQ
- { $$= (*$2)(0)->create($1,$3); }
+ {
+ $$= (*$2)(0)->create($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
- { $$= all_any_subquery_creator($1, $2, $3, $5); }
+ {
+ $$= all_any_subquery_creator($1, $2, $3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| predicate ;
predicate:
bit_expr IN_SYM '(' subselect ')'
{
$$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| bit_expr not IN_SYM '(' subselect ')'
{
THD *thd= YYTHD;
Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
+ if (item == NULL)
+ MYSQL_YYABORT;
$$= negate_expression(thd, item);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| bit_expr IN_SYM '(' expr ')'
{
$$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| bit_expr IN_SYM '(' expr ',' expr_list ')'
{
$6->push_front($4);
$6->push_front($1);
$$= new (YYTHD->mem_root) Item_func_in(*$6);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| bit_expr not IN_SYM '(' expr ')'
{
$$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| bit_expr not IN_SYM '(' expr ',' expr_list ')'
{
@@ -4707,54 +4842,146 @@ predicate:
$$= item;
}
| bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
- { $$= new Item_func_between($1,$3,$5); }
+ {
+ $$= new Item_func_between($1,$3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
{
Item_func_between *item= new Item_func_between($1,$4,$6);
+ if (item == NULL)
+ MYSQL_YYABORT;
item->negate();
$$= item;
}
| bit_expr SOUNDS_SYM LIKE bit_expr
- { $$= new Item_func_eq(new Item_func_soundex($1),
- new Item_func_soundex($4)); }
+ {
+ Item *item1= new Item_func_soundex($1);
+ Item *item4= new Item_func_soundex($4);
+ if ((item1 == NULL) || (item4 == NULL))
+ MYSQL_YYABORT;
+ $$= new Item_func_eq(item1, item4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr LIKE simple_expr opt_escape
- { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
+ {
+ $$= new Item_func_like($1,$3,$4,Lex->escape_used);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr not LIKE simple_expr opt_escape
- { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
- | bit_expr REGEXP bit_expr { $$= new Item_func_regex($1,$3); }
+ {
+ Item *item= new Item_func_like($1,$4,$5, Lex->escape_used);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new Item_func_not(item);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | bit_expr REGEXP bit_expr
+ {
+ $$= new Item_func_regex($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr not REGEXP bit_expr
- { $$= negate_expression(YYTHD, new Item_func_regex($1,$4)); }
+ {
+ Item *item= new Item_func_regex($1,$4);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= negate_expression(YYTHD, item);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr ;
bit_expr:
bit_expr '|' bit_expr %prec '|'
- { $$= new Item_func_bit_or($1,$3); }
+ {
+ $$= new Item_func_bit_or($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '&' bit_expr %prec '&'
- { $$= new Item_func_bit_and($1,$3); }
+ {
+ $$= new Item_func_bit_and($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
- { $$= new Item_func_shift_left($1,$3); }
+ {
+ $$= new Item_func_shift_left($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
- { $$= new Item_func_shift_right($1,$3); }
+ {
+ $$= new Item_func_shift_right($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '+' bit_expr %prec '+'
- { $$= new Item_func_plus($1,$3); }
+ {
+ $$= new Item_func_plus($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '-' bit_expr %prec '-'
- { $$= new Item_func_minus($1,$3); }
+ {
+ $$= new Item_func_minus($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '+' interval_expr interval %prec '+'
- { $$= new Item_date_add_interval($1,$3,$4,0); }
+ {
+ $$= new Item_date_add_interval($1,$3,$4,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '-' interval_expr interval %prec '-'
- { $$= new Item_date_add_interval($1,$3,$4,1); }
+ {
+ $$= new Item_date_add_interval($1,$3,$4,1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '*' bit_expr %prec '*'
- { $$= new Item_func_mul($1,$3); }
+ {
+ $$= new Item_func_mul($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '/' bit_expr %prec '/'
- { $$= new Item_func_div($1,$3); }
+ {
+ $$= new Item_func_div($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '%' bit_expr %prec '%'
- { $$= new Item_func_mod($1,$3); }
+ {
+ $$= new Item_func_mod($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr DIV_SYM bit_expr %prec DIV_SYM
- { $$= new Item_func_int_div($1,$3); }
+ {
+ $$= new Item_func_int_div($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr MOD_SYM bit_expr %prec MOD_SYM
- { $$= new Item_func_mod($1,$3); }
+ {
+ $$= new Item_func_mod($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| bit_expr '^' bit_expr
- { $$= new Item_func_bit_xor($1,$3); }
+ {
+ $$= new Item_func_bit_xor($1,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| simple_expr
;
@@ -4784,67 +5011,118 @@ simple_expr:
simple_ident
| simple_expr COLLATE_SYM ident_or_text %prec NEG
{
- $$= new Item_func_set_collation($1,
- new Item_string($3.str,
- $3.length,
- YYTHD->charset()));
+ Item *item= new Item_string($3.str, $3.length, YYTHD->charset());
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new Item_func_set_collation($1, item);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| literal
| param_marker
| variable
| sum_expr
| simple_expr OR_OR_SYM simple_expr
- { $$= new Item_func_concat($1, $3); }
- | '+' simple_expr %prec NEG { $$= $2; }
- | '-' simple_expr %prec NEG { $$= new Item_func_neg($2); }
- | '~' simple_expr %prec NEG { $$= new Item_func_bit_neg($2); }
- | not2 simple_expr %prec NEG { $$= negate_expression(YYTHD, $2); }
+ {
+ $$= new Item_func_concat($1, $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | '+' simple_expr %prec NEG
+ { $$= $2; }
+ | '-' simple_expr %prec NEG
+ {
+ $$= new Item_func_neg($2);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | '~' simple_expr %prec NEG
+ {
+ $$= new Item_func_bit_neg($2);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | not2 simple_expr %prec NEG
+ {
+ $$= negate_expression(YYTHD, $2);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| '(' subselect ')'
{
$$= new Item_singlerow_subselect($2);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| '(' expr ')' { $$= $2; }
| '(' expr ',' expr_list ')'
{
$4->push_front($2);
$$= new Item_row(*$4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| ROW_SYM '(' expr ',' expr_list ')'
{
$5->push_front($3);
$$= new Item_row(*$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| EXISTS '(' subselect ')'
{
$$= new Item_exists_subselect($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
- | '{' ident expr '}' { $$= $3; }
+ | '{' ident expr '}'
+ { $$= $3; }
| MATCH ident_list_arg AGAINST '(' bit_expr fulltext_options ')'
- { $2->push_front($5);
- Select->add_ftfunc_to_list((Item_func_match*)
- ($$=new Item_func_match(*$2,$6))); }
- | ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
+ {
+ $2->push_front($5);
+ Item_func_match *item= new Item_func_match(*$2,$6);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ Select->add_ftfunc_to_list(item);
+ $$= item;
+ }
+ | ASCII_SYM '(' expr ')'
+ {
+ $$= new Item_func_ascii($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| BINARY simple_expr %prec NEG
{
$$= create_func_cast($2, ITEM_CAST_CHAR, NULL, NULL, &my_charset_bin);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| CAST_SYM '(' expr AS cast_type ')'
{
LEX *lex= Lex;
$$= create_func_cast($3, $5, lex->length, lex->dec, lex->charset);
- if (!$$)
+ if ($$ == NULL)
MYSQL_YYABORT;
}
| CASE_SYM opt_expr when_list opt_else END
- { $$= new Item_func_case(* $3, $2, $4 ); }
+ {
+ $$= new Item_func_case(* $3, $2, $4 );
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CONVERT_SYM '(' expr ',' cast_type ')'
{
$$= create_func_cast($3, $5, Lex->length, Lex->dec, Lex->charset);
- if (!$$)
+ if ($$ == NULL)
MYSQL_YYABORT;
}
| CONVERT_SYM '(' expr USING charset_name ')'
- { $$= new Item_func_conv_charset($3,$5); }
+ {
+ $$= new Item_func_conv_charset($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DEFAULT '(' simple_ident ')'
{
if ($3->is_splocal())
@@ -4855,9 +5133,15 @@ simple_expr:
MYSQL_YYABORT;
}
$$= new Item_default_value(Lex->current_context(), $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| VALUES '(' simple_ident_nospvar ')'
- { $$= new Item_insert_value(Lex->current_context(), $3); }
+ {
+ $$= new Item_insert_value(Lex->current_context(), $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| FUNC_ARG0 '(' ')'
{
if (!$1.symbol->create_func)
@@ -4868,6 +5152,8 @@ simple_expr:
MYSQL_YYABORT;
}
$$= ((Item*(*)(void))($1.symbol->create_func))();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| FUNC_ARG1 '(' expr ')'
{
@@ -4879,6 +5165,8 @@ simple_expr:
MYSQL_YYABORT;
}
$$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| FUNC_ARG2 '(' expr ',' expr ')'
{
@@ -4890,6 +5178,8 @@ simple_expr:
MYSQL_YYABORT;
}
$$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
{
@@ -4901,106 +5191,264 @@ simple_expr:
MYSQL_YYABORT;
}
$$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| ADDDATE_SYM '(' expr ',' expr ')'
- { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);}
+ {
+ $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
- { $$= new Item_date_add_interval($3, $6, $7, 0); }
+ {
+ $$= new Item_date_add_interval($3, $6, $7, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| REPEAT_SYM '(' expr ',' expr ')'
- { $$= new Item_func_repeat($3,$5); }
+ {
+ $$= new Item_func_repeat($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ATAN '(' expr ')'
- { $$= new Item_func_atan($3); }
+ {
+ $$= new Item_func_atan($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ATAN '(' expr ',' expr ')'
- { $$= new Item_func_atan($3,$5); }
+ {
+ $$= new Item_func_atan($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CHAR_SYM '(' expr_list ')'
- { $$= new Item_func_char(*$3); }
+ {
+ $$= new Item_func_char(*$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CHAR_SYM '(' expr_list USING charset_name ')'
- { $$= new Item_func_char(*$3, $5); }
+ {
+ $$= new Item_func_char(*$3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CHARSET '(' expr ')'
- { $$= new Item_func_charset($3); }
+ {
+ $$= new Item_func_charset($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| COALESCE '(' expr_list ')'
- { $$= new Item_func_coalesce(* $3); }
+ {
+ $$= new Item_func_coalesce(* $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| COLLATION_SYM '(' expr ')'
- { $$= new Item_func_collation($3); }
+ {
+ $$= new Item_func_collation($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CONCAT '(' expr_list ')'
- { $$= new Item_func_concat(* $3); }
+ {
+ $$= new Item_func_concat(* $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CONCAT_WS '(' expr ',' expr_list ')'
- { $5->push_front($3); $$= new Item_func_concat_ws(*$5); }
+ {
+ $5->push_front($3);
+ $$= new Item_func_concat_ws(*$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| CONVERT_TZ_SYM '(' expr ',' expr ',' expr ')'
{
if (Lex->add_time_zone_tables_to_query_tables(YYTHD))
MYSQL_YYABORT;
$$= new Item_func_convert_tz($3, $5, $7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| CURDATE optional_braces
- { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
+ {
+ $$= new Item_func_curdate_local();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| CURTIME optional_braces
- { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
+ {
+ $$= new Item_func_curtime_local();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| CURTIME '(' expr ')'
{
$$= new Item_func_curtime_local($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
}
| CURRENT_USER optional_braces
{
$$= new Item_func_current_user(Lex->current_context());
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query= 0;
}
| DATE_ADD_INTERVAL '(' expr ',' interval_expr interval ')'
- { $$= new Item_date_add_interval($3,$5,$6,0); }
+ {
+ $$= new Item_date_add_interval($3,$5,$6,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DATE_SUB_INTERVAL '(' expr ',' interval_expr interval ')'
- { $$= new Item_date_add_interval($3,$5,$6,1); }
+ {
+ $$= new Item_date_add_interval($3,$5,$6,1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DATABASE '(' ')'
{
$$= new Item_func_database();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
}
| DATE_SYM '(' expr ')'
- { $$= new Item_date_typecast($3); }
+ {
+ $$= new Item_date_typecast($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DAY_SYM '(' expr ')'
- { $$= new Item_func_dayofmonth($3); }
+ {
+ $$= new Item_func_dayofmonth($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ELT_FUNC '(' expr ',' expr_list ')'
- { $5->push_front($3); $$= new Item_func_elt(*$5); }
+ {
+ $5->push_front($3);
+ $$= new Item_func_elt(*$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MAKE_SET_SYM '(' expr ',' expr_list ')'
- { $$= new Item_func_make_set($3, *$5); }
+ {
+ $$= new Item_func_make_set($3, *$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ENCRYPT '(' expr ')'
{
$$= new Item_func_encrypt($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->uncacheable(UNCACHEABLE_RAND);
}
- | ENCRYPT '(' expr ',' expr ')' { $$= new Item_func_encrypt($3,$5); }
+ | ENCRYPT '(' expr ',' expr ')'
+ {
+ $$= new Item_func_encrypt($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
- { $$= new Item_func_decode($3,$5.str); }
+ {
+ $$= new Item_func_decode($3,$5.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
- { $$= new Item_func_encode($3,$5.str); }
+ {
+ $$= new Item_func_encode($3,$5.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DES_DECRYPT_SYM '(' expr ')'
- { $$= new Item_func_des_decrypt($3); }
+ {
+ $$= new Item_func_des_decrypt($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DES_DECRYPT_SYM '(' expr ',' expr ')'
- { $$= new Item_func_des_decrypt($3,$5); }
+ {
+ $$= new Item_func_des_decrypt($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DES_ENCRYPT_SYM '(' expr ')'
- { $$= new Item_func_des_encrypt($3); }
+ {
+ $$= new Item_func_des_encrypt($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| DES_ENCRYPT_SYM '(' expr ',' expr ')'
- { $$= new Item_func_des_encrypt($3,$5); }
+ {
+ $$= new Item_func_des_encrypt($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| EXPORT_SET '(' expr ',' expr ',' expr ')'
- { $$= new Item_func_export_set($3, $5, $7); }
+ {
+ $$= new Item_func_export_set($3, $5, $7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| EXPORT_SET '(' expr ',' expr ',' expr ',' expr ')'
- { $$= new Item_func_export_set($3, $5, $7, $9); }
+ {
+ $$= new Item_func_export_set($3, $5, $7, $9);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| EXPORT_SET '(' expr ',' expr ',' expr ',' expr ',' expr ')'
- { $$= new Item_func_export_set($3, $5, $7, $9, $11); }
+ {
+ $$= new Item_func_export_set($3, $5, $7, $9, $11);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| FORMAT_SYM '(' expr ',' NUM ')'
- { $$= new Item_func_format($3,atoi($5.str)); }
+ {
+ $$= new Item_func_format($3,atoi($5.str));
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| FROM_UNIXTIME '(' expr ')'
- { $$= new Item_func_from_unixtime($3); }
+ {
+ $$= new Item_func_from_unixtime($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| FROM_UNIXTIME '(' expr ',' expr ')'
{
- $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
+ Item *item= new Item_func_from_unixtime($3);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new Item_func_date_format (item, $5, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| FIELD_FUNC '(' expr ',' expr_list ')'
- { $5->push_front($3); $$= new Item_func_field(*$5); }
+ {
+ $5->push_front($3);
+ $$= new Item_func_field(*$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| geometry_function
{
#ifdef HAVE_SPATIAL
$$= $1;
+ /* $1 may be NULL, GEOM_NEW not tested for out of memory */
+ if ($$ == NULL)
+ MYSQL_YYABORT;
#else
my_error(ER_FEATURE_DISABLED, MYF(0),
sym_group_geom.name, sym_group_geom.needed_define);
@@ -5008,16 +5456,36 @@ simple_expr:
#endif
}
| GET_FORMAT '(' date_time_type ',' expr ')'
- { $$= new Item_func_get_format($3, $5); }
+ {
+ $$= new Item_func_get_format($3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| HOUR_SYM '(' expr ')'
- { $$= new Item_func_hour($3); }
+ {
+ $$= new Item_func_hour($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| IF '(' expr ',' expr ',' expr ')'
- { $$= new Item_func_if($3,$5,$7); }
+ {
+ $$= new Item_func_if($3,$5,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| INSERT '(' expr ',' expr ',' expr ',' expr ')'
- { $$= new Item_func_insert($3,$5,$7,$9); }
+ {
+ $$= new Item_func_insert($3,$5,$7,$9);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| interval_expr interval '+' expr
/* we cannot put interval before - */
- { $$= new Item_date_add_interval($4,$1,$2,0); }
+ {
+ $$= new Item_date_add_interval($4,$1,$2,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| interval_expr
{
if ($1->type() != Item::ROW_ITEM)
@@ -5026,102 +5494,248 @@ simple_expr:
MYSQL_YYABORT;
}
$$= new Item_func_interval((Item_row *)$1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| LAST_INSERT_ID '(' ')'
{
$$= new Item_func_last_insert_id();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query= 0;
}
| LAST_INSERT_ID '(' expr ')'
{
$$= new Item_func_last_insert_id($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query= 0;
}
| LEFT '(' expr ',' expr ')'
- { $$= new Item_func_left($3,$5); }
+ {
+ $$= new Item_func_left($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| LOCATE '(' expr ',' expr ')'
- { $$= new Item_func_locate($5,$3); }
+ {
+ $$= new Item_func_locate($5,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| LOCATE '(' expr ',' expr ',' expr ')'
- { $$= new Item_func_locate($5,$3,$7); }
+ {
+ $$= new Item_func_locate($5,$3,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| GREATEST_SYM '(' expr ',' expr_list ')'
- { $5->push_front($3); $$= new Item_func_max(*$5); }
+ {
+ $5->push_front($3);
+ $$= new Item_func_max(*$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| LEAST_SYM '(' expr ',' expr_list ')'
- { $5->push_front($3); $$= new Item_func_min(*$5); }
+ {
+ $5->push_front($3);
+ $$= new Item_func_min(*$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| LOG_SYM '(' expr ')'
- { $$= new Item_func_log($3); }
+ {
+ $$= new Item_func_log($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| LOG_SYM '(' expr ',' expr ')'
- { $$= new Item_func_log($3, $5); }
+ {
+ $$= new Item_func_log($3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MASTER_POS_WAIT '(' expr ',' expr ')'
{
$$= new Item_master_pos_wait($3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
- }
+ }
| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
{
$$= new Item_master_pos_wait($3, $5, $7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
}
| MICROSECOND_SYM '(' expr ')'
- { $$= new Item_func_microsecond($3); }
+ {
+ $$= new Item_func_microsecond($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MINUTE_SYM '(' expr ')'
- { $$= new Item_func_minute($3); }
+ {
+ $$= new Item_func_minute($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MOD_SYM '(' expr ',' expr ')'
- { $$ = new Item_func_mod( $3, $5); }
+ {
+ $$= new Item_func_mod( $3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MONTH_SYM '(' expr ')'
- { $$= new Item_func_month($3); }
+ {
+ $$= new Item_func_month($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| NOW_SYM optional_braces
- { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
+ {
+ $$= new Item_func_now_local();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| NOW_SYM '(' expr ')'
- { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
+ {
+ $$= new Item_func_now_local($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| PASSWORD '(' expr ')'
{
$$= YYTHD->variables.old_passwords ?
(Item *) new Item_func_old_password($3) :
(Item *) new Item_func_password($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| OLD_PASSWORD '(' expr ')'
- { $$= new Item_func_old_password($3); }
+ {
+ $$= new Item_func_old_password($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| POSITION_SYM '(' bit_expr IN_SYM expr ')'
- { $$ = new Item_func_locate($5,$3); }
+ {
+ $$= new Item_func_locate($5,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| QUARTER_SYM '(' expr ')'
- { $$ = new Item_func_quarter($3); }
+ {
+ $$= new Item_func_quarter($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| RAND '(' expr ')'
- { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
+ {
+ $$= new Item_func_rand($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->uncacheable(UNCACHEABLE_RAND);
+ }
| RAND '(' ')'
- { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
+ {
+ $$= new Item_func_rand();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->uncacheable(UNCACHEABLE_RAND);
+ }
| REPLACE '(' expr ',' expr ',' expr ')'
- { $$= new Item_func_replace($3,$5,$7); }
+ {
+ $$= new Item_func_replace($3,$5,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| RIGHT '(' expr ',' expr ')'
- { $$= new Item_func_right($3,$5); }
+ {
+ $$= new Item_func_right($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ROUND '(' expr ')'
- { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
- | ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
+ {
+ Item *item= new Item_int((char*)"0",0,1);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new Item_func_round($3, item, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | ROUND '(' expr ',' expr ')'
+ {
+ $$= new Item_func_round($3,$5,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ROW_COUNT_SYM '(' ')'
{
$$= new Item_func_row_count();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query= 0;
}
| SUBDATE_SYM '(' expr ',' expr ')'
- { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);}
+ {
+ $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
- { $$= new Item_date_add_interval($3, $6, $7, 1); }
+ {
+ $$= new Item_date_add_interval($3, $6, $7, 1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SECOND_SYM '(' expr ')'
- { $$= new Item_func_second($3); }
+ {
+ $$= new Item_func_second($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUBSTRING '(' expr ',' expr ',' expr ')'
- { $$= new Item_func_substr($3,$5,$7); }
+ {
+ $$= new Item_func_substr($3,$5,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUBSTRING '(' expr ',' expr ')'
- { $$= new Item_func_substr($3,$5); }
+ {
+ $$= new Item_func_substr($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
- { $$= new Item_func_substr($3,$5,$7); }
+ {
+ $$= new Item_func_substr($3,$5,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUBSTRING '(' expr FROM expr ')'
- { $$= new Item_func_substr($3,$5); }
+ {
+ $$= new Item_func_substr($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
- { $$= new Item_func_substr_index($3,$5,$7); }
+ {
+ $$= new Item_func_substr_index($3,$5,$7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SYSDATE optional_braces
{
if (global_system_variables.sysdate_is_now == 0)
$$= new Item_func_sysdate_local();
else $$= new Item_func_now_local();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
}
| SYSDATE '(' expr ')'
@@ -5129,36 +5743,94 @@ simple_expr:
if (global_system_variables.sysdate_is_now == 0)
$$= new Item_func_sysdate_local($3);
else $$= new Item_func_now_local($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
}
| TIME_SYM '(' expr ')'
- { $$= new Item_time_typecast($3); }
+ {
+ $$= new Item_time_typecast($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TIMESTAMP '(' expr ')'
- { $$= new Item_datetime_typecast($3); }
+ {
+ $$= new Item_datetime_typecast($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TIMESTAMP '(' expr ',' expr ')'
- { $$= new Item_func_add_time($3, $5, 1, 0); }
+ {
+ $$= new Item_func_add_time($3, $5, 1, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
- { $$= new Item_date_add_interval($7,$5,$3,0); }
+ {
+ $$= new Item_date_add_interval($7,$5,$3,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
- { $$= new Item_func_timestamp_diff($5,$7,$3); }
+ {
+ $$= new Item_func_timestamp_diff($5,$7,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' expr ')'
- { $$= new Item_func_trim($3); }
+ {
+ $$= new Item_func_trim($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' LEADING expr FROM expr ')'
- { $$= new Item_func_ltrim($6,$4); }
+ {
+ $$= new Item_func_ltrim($6,$4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' TRAILING expr FROM expr ')'
- { $$= new Item_func_rtrim($6,$4); }
+ {
+ $$= new Item_func_rtrim($6,$4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' BOTH expr FROM expr ')'
- { $$= new Item_func_trim($6,$4); }
+ {
+ $$= new Item_func_trim($6,$4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' LEADING FROM expr ')'
- { $$= new Item_func_ltrim($5); }
+ {
+ $$= new Item_func_ltrim($5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' TRAILING FROM expr ')'
- { $$= new Item_func_rtrim($5); }
+ {
+ $$= new Item_func_rtrim($5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' BOTH FROM expr ')'
- { $$= new Item_func_trim($5); }
+ {
+ $$= new Item_func_trim($5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRIM '(' expr FROM expr ')'
- { $$= new Item_func_trim($5,$3); }
+ {
+ $$= new Item_func_trim($5,$3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| TRUNCATE_SYM '(' expr ',' expr ')'
- { $$= new Item_func_round($3,$5,1); }
+ {
+ $$= new Item_func_round($3,$5,1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ident '.' ident '(' opt_expr_list ')'
{
LEX *lex= Lex;
@@ -5171,6 +5843,8 @@ simple_expr:
$$= new Item_func_sp(Lex->current_context(), name, *$5);
else
$$= new Item_func_sp(Lex->current_context(), name);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
lex->safe_to_cache_query=0;
}
| IDENT_sys '('
@@ -5311,47 +5985,110 @@ simple_expr:
else
$$= new Item_func_sp(Lex->current_context(), name);
}
- lex->safe_to_cache_query=0;
+ lex->safe_to_cache_query=0;
+
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
{
$$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| UNIX_TIMESTAMP '(' ')'
{
$$= new Item_func_unix_timestamp();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->safe_to_cache_query=0;
}
| UNIX_TIMESTAMP '(' expr ')'
- { $$= new Item_func_unix_timestamp($3); }
+ {
+ $$= new Item_func_unix_timestamp($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| USER '(' ')'
- { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
+ {
+ $$= new Item_func_user();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| UTC_DATE_SYM optional_braces
- { $$= new Item_func_curdate_utc(); Lex->safe_to_cache_query=0;}
+ {
+ $$= new Item_func_curdate_utc();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| UTC_TIME_SYM optional_braces
- { $$= new Item_func_curtime_utc(); Lex->safe_to_cache_query=0;}
+ {
+ $$= new Item_func_curtime_utc();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| UTC_TIMESTAMP_SYM optional_braces
- { $$= new Item_func_now_utc(); Lex->safe_to_cache_query=0;}
+ {
+ $$= new Item_func_now_utc();
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->safe_to_cache_query=0;
+ }
| WEEK_SYM '(' expr ')'
{
- $$= new Item_func_week($3,new Item_int((char*) "0",
- YYTHD->variables.default_week_format,1));
+ Item *item= new Item_int((char*) "0",
+ YYTHD->variables.default_week_format,
+ 1);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new Item_func_week($3, item);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| WEEK_SYM '(' expr ',' expr ')'
- { $$= new Item_func_week($3,$5); }
+ {
+ $$= new Item_func_week($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| YEAR_SYM '(' expr ')'
- { $$= new Item_func_year($3); }
+ {
+ $$= new Item_func_year($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| YEARWEEK '(' expr ')'
- { $$= new Item_func_yearweek($3,new Item_int((char*) "0",0,1)); }
+ {
+ Item *item= new Item_int((char*) "0",0,1);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new Item_func_yearweek($3, item);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| YEARWEEK '(' expr ',' expr ')'
- { $$= new Item_func_yearweek($3, $5); }
+ {
+ $$= new Item_func_yearweek($3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| BENCHMARK_SYM '(' ulong_num ',' expr ')'
{
$$=new Item_func_benchmark($3,$5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
}
| EXTRACT_SYM '(' interval FROM expr ')'
- { $$=new Item_extract( $3, $5); };
+ {
+ $$=new Item_extract( $3, $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ ;
geometry_function:
CONTAINS_SYM '(' expr ',' expr ')'
@@ -5427,7 +6164,12 @@ udf_expr_list:
;
udf_expr_list2:
- { Select->expr_list.push_front(new List<Item>); }
+ {
+ List<Item> *list= new List<Item>;
+ if (list == NULL)
+ MYSQL_YYABORT;
+ Select->expr_list.push_front(list);
+ }
udf_expr_list3
{ $$= Select->expr_list.pop(); }
;
@@ -5475,53 +6217,132 @@ udf_expr:
;
sum_expr:
- AVG_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_avg($3); }
+ AVG_SYM '(' in_sum_expr ')'
+ {
+ $$=new Item_sum_avg($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| AVG_SYM '(' DISTINCT in_sum_expr ')'
- { $$=new Item_sum_avg_distinct($4); }
+ {
+ $$=new Item_sum_avg_distinct($4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| BIT_AND '(' in_sum_expr ')'
- { $$=new Item_sum_and($3); }
+ {
+ $$=new Item_sum_and($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| BIT_OR '(' in_sum_expr ')'
- { $$=new Item_sum_or($3); }
+ {
+ $$=new Item_sum_or($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| BIT_XOR '(' in_sum_expr ')'
- { $$=new Item_sum_xor($3); }
+ {
+ $$=new Item_sum_xor($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| COUNT_SYM '(' opt_all '*' ')'
- { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
+ {
+ Item *item= new Item_int((int32) 0L,1);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$=new Item_sum_count(new Item_int((int32) 0L,1));
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| COUNT_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_count($3); }
+ {
+ $$=new Item_sum_count($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| COUNT_SYM '(' DISTINCT
{ Select->in_sum_expr++; }
expr_list
{ Select->in_sum_expr--; }
')'
- { $$=new Item_sum_count_distinct(* $5); }
+ {
+ $$=new Item_sum_count_distinct(* $5);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
- { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
+ {
+ $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MIN_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_min($3); }
+ {
+ $$=new Item_sum_min($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
/*
According to ANSI SQL, DISTINCT is allowed and has
no sence inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
is processed like an ordinary MIN | MAX()
*/
| MIN_SYM '(' DISTINCT in_sum_expr ')'
- { $$=new Item_sum_min($4); }
+ {
+ $$=new Item_sum_min($4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MAX_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_max($3); }
+ {
+ $$=new Item_sum_max($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| MAX_SYM '(' DISTINCT in_sum_expr ')'
- { $$=new Item_sum_max($4); }
+ {
+ $$=new Item_sum_max($4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| STD_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_std($3, 0); }
+ {
+ $$=new Item_sum_std($3, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| VARIANCE_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_variance($3, 0); }
+ {
+ $$=new Item_sum_variance($3, 0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| STDDEV_SAMP_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_std($3, 1); }
+ {
+ $$=new Item_sum_std($3, 1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| VAR_SAMP_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_variance($3, 1); }
+ {
+ $$=new Item_sum_variance($3, 1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUM_SYM '(' in_sum_expr ')'
- { $$=new Item_sum_sum($3); }
+ {
+ $$=new Item_sum_sum($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| SUM_SYM '(' DISTINCT in_sum_expr ')'
- { $$=new Item_sum_sum_distinct($4); }
+ {
+ $$=new Item_sum_sum_distinct($4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| GROUP_CONCAT_SYM '(' opt_distinct
{ Select->in_sum_expr++; }
expr_list opt_gorder_clause
@@ -5532,6 +6353,8 @@ sum_expr:
sel->in_sum_expr--;
$$=new Item_func_group_concat(Lex->current_context(), $3, $5,
sel->gorder_list, $7);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
$5->empty();
};
@@ -5554,12 +6377,16 @@ variable_aux:
ident_or_text SET_VAR expr
{
$$= new Item_func_set_user_var($1, $3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
LEX *lex= Lex;
lex->uncacheable(UNCACHEABLE_RAND);
}
| ident_or_text
{
$$= new Item_func_get_user_var($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
LEX *lex= Lex;
lex->uncacheable(UNCACHEABLE_RAND);
}
@@ -5580,11 +6407,14 @@ opt_distinct:
|DISTINCT { $$ = 1; };
opt_gconcat_separator:
- /* empty */
- {
- $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
- }
- | SEPARATOR_SYM text_string { $$ = $2; };
+ /* empty */
+ {
+ $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | SEPARATOR_SYM text_string { $$ = $2; }
+ ;
opt_gorder_clause:
@@ -5598,6 +6428,8 @@ opt_gorder_clause:
select->gorder_list=
(SQL_LIST*) sql_memdup((char*) &select->order_list,
sizeof(st_sql_list));
+ if (select->gorder_list == NULL)
+ MYSQL_YYABORT;
select->order_list.empty();
};
@@ -5638,7 +6470,12 @@ opt_expr_list:
;
expr_list:
- { Select->expr_list.push_front(new List<Item>); }
+ {
+ List<Item> *list= new List<Item>;
+ if (list == NULL)
+ MYSQL_YYABORT;
+ Select->expr_list.push_front(list);
+ }
expr_list2
{ $$= Select->expr_list.pop(); };
@@ -5651,7 +6488,12 @@ ident_list_arg:
| '(' ident_list ')' { $$= $2; };
ident_list:
- { Select->expr_list.push_front(new List<Item>); }
+ {
+ List<Item> *list= new List<Item>;
+ if (list == NULL)
+ MYSQL_YYABORT;
+ Select->expr_list.push_front(new List<Item>);
+ }
ident_list2
{ $$= Select->expr_list.pop(); };
@@ -5671,6 +6513,8 @@ when_list:
WHEN_SYM expr THEN_SYM expr
{
$$= new List<Item>;
+ if ($$ == NULL)
+ MYSQL_YYABORT;
$$->push_back($2);
$$->push_back($4);
}
@@ -6077,32 +6921,53 @@ key_list_or_empty:
key_usage_list2:
key_usage_list2 ',' ident
- { Select->
- interval_list.push_back(new (YYTHD->mem_root) String((const char*) $3.str, $3.length,
- system_charset_info)); }
+ {
+ String *s= new (YYTHD->mem_root) String((const char*) $3.str,
+ $3.length,
+ system_charset_info);
+ if (s == NULL)
+ MYSQL_YYABORT;
+ Select->interval_list.push_back(s);
+ }
| ident
- { Select->
- interval_list.push_back(new (YYTHD->mem_root) String((const char*) $1.str, $1.length,
- system_charset_info)); }
+ {
+ String *s= new (YYTHD->mem_root) String((const char*) $1.str,
+ $1.length,
+ system_charset_info);
+ if (s == NULL)
+ MYSQL_YYABORT;
+ Select->interval_list.push_back(s);
+ }
| PRIMARY_SYM
- { Select->
- interval_list.push_back(new (YYTHD->mem_root) String("PRIMARY", 7,
- system_charset_info)); };
+ {
+ String *s= new (YYTHD->mem_root) String("PRIMARY", 7,
+ system_charset_info);
+ if (s == NULL)
+ MYSQL_YYABORT;
+ Select->interval_list.push_back(s);
+ }
+ ;
using_list:
ident
{
if (!($$= new List<String>))
MYSQL_YYABORT;
- $$->push_back(new (YYTHD->mem_root)
- String((const char *) $1.str, $1.length,
- system_charset_info));
+ String *s= new (YYTHD->mem_root) String((const char *) $1.str,
+ $1.length,
+ system_charset_info);
+ if (s == NULL)
+ MYSQL_YYABORT;
+ $$->push_back(s);
}
| using_list ',' ident
{
- $1->push_back(new (YYTHD->mem_root)
- String((const char *) $3.str, $3.length,
- system_charset_info));
+ String *s= new (YYTHD->mem_root) String((const char *) $3.str,
+ $3.length,
+ system_charset_info);
+ if (s == NULL)
+ MYSQL_YYABORT;
+ $1->push_back(s);
$$= $1;
};
@@ -6167,7 +7032,12 @@ table_alias:
opt_table_alias:
/* empty */ { $$=0; }
| table_alias ident
- { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); };
+ {
+ $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING));
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ ;
opt_all:
/* empty */
@@ -6218,6 +7088,8 @@ opt_escape:
$$= ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ?
new Item_string("", 0, &my_charset_latin1) :
new Item_string("\\", 1, &my_charset_latin1));
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
;
@@ -6388,9 +7260,24 @@ limit_option:
{
((Item_param *) $1)->limit_clause_param= TRUE;
}
- | ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
- | LONG_NUM { $$= new Item_uint($1.str, $1.length); }
- | NUM { $$= new Item_uint($1.str, $1.length); }
+ | ULONGLONG_NUM
+ {
+ $$= new Item_uint($1.str, $1.length);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | LONG_NUM
+ {
+ $$= new Item_uint($1.str, $1.length);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | NUM
+ {
+ $$= new Item_uint($1.str, $1.length);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
;
delete_limit_clause:
@@ -6443,10 +7330,11 @@ procedure_clause:
lex->proc_list.elements=0;
lex->proc_list.first=0;
lex->proc_list.next= (byte**) &lex->proc_list.first;
- if (add_proc_to_list(lex->thd, new Item_field(&lex->
- current_select->
- context,
- NULL,NULL,$2.str)))
+ Item_field *item= new Item_field(&lex->current_select->context,
+ NULL,NULL,$2.str);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ if (add_proc_to_list(lex->thd, item))
MYSQL_YYABORT;
Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
}
@@ -6465,7 +7353,7 @@ procedure_item:
remember_name expr
{
THD *thd= YYTHD;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
if (add_proc_to_list(thd, $2))
MYSQL_YYABORT;
@@ -6497,13 +7385,20 @@ select_var_ident:
{
LEX *lex=Lex;
if (lex->result)
- ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
+ {
+ my_var *var= new my_var($2,0,0,(enum_field_types)0);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ ((select_dumpvar *)lex->result)->var_list.push_back(var);
+ }
else
+ {
/*
The parser won't create select_result instance only
if it's an EXPLAIN.
*/
DBUG_ASSERT(lex->describe);
+ }
}
| ident_or_text
{
@@ -6517,12 +7412,12 @@ select_var_ident:
}
if (lex->result)
{
- my_var *var;
- ((select_dumpvar *)lex->result)->
- var_list.push_back(var= new my_var($1,1,t->offset,t->type));
+ my_var *var= new my_var($1,1,t->offset,t->type);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ ((select_dumpvar *)lex->result)->var_list.push_back(var);
#ifndef DBUG_OFF
- if (var)
- var->sp= lex->sphead;
+ var->sp= lex->sphead;
#endif
}
else
@@ -6607,11 +7502,13 @@ drop:
| DROP INDEX_SYM ident ON table_ident {}
{
LEX *lex=Lex;
+ Alter_drop *ad= new Alter_drop(Alter_drop::KEY, $3.str);
+ if (ad == NULL)
+ MYSQL_YYABORT;
lex->sql_command= SQLCOM_DROP_INDEX;
lex->alter_info.reset();
lex->alter_info.flags= ALTER_DROP_INDEX;
- lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
- $3.str));
+ lex->alter_info.drop_list.push_back(ad);
if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
TL_OPTION_UPDATING))
MYSQL_YYABORT;
@@ -6636,6 +7533,8 @@ drop:
lex->sql_command = SQLCOM_DROP_FUNCTION;
lex->drop_if_exists= $3;
spname= new sp_name($4, $6, true);
+ if (spname == NULL)
+ MYSQL_YYABORT;
spname->init_qname(thd);
lex->spname= spname;
}
@@ -6655,6 +7554,8 @@ drop:
lex->sql_command = SQLCOM_DROP_FUNCTION;
lex->drop_if_exists= $3;
spname= new sp_name(db, $4, false);
+ if (spname == NULL)
+ MYSQL_YYABORT;
spname->init_qname(thd);
lex->spname= spname;
}
@@ -6869,7 +7770,12 @@ values:
expr_or_default:
expr { $$= $1;}
- | DEFAULT {$$= new Item_default_value(Lex->current_context()); }
+ | DEFAULT
+ {
+ $$= new Item_default_value(Lex->current_context());
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
;
opt_insert_update:
@@ -6987,15 +7893,21 @@ table_wild_list:
table_wild_one:
ident opt_wild opt_table_alias
{
- if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
+ Table_ident *ti= new Table_ident($1);
+ if (ti == NULL)
+ MYSQL_YYABORT;
+ if (!Select->add_table_to_list(YYTHD, ti, $3,
TL_OPTION_UPDATING |
TL_OPTION_ALIAS, Lex->lock_option))
MYSQL_YYABORT;
}
| ident '.' ident opt_wild opt_table_alias
{
+ Table_ident *ti= new Table_ident(YYTHD, $1, $3, 0);
+ if (ti == NULL)
+ MYSQL_YYABORT;
if (!Select->add_table_to_list(YYTHD,
- new Table_ident(YYTHD, $1, $3, 0),
+ ti,
$5,
TL_OPTION_UPDATING |
TL_OPTION_ALIAS,
@@ -7441,8 +8353,12 @@ binlog_from:
wild_and_where:
/* empty */
| LIKE TEXT_STRING_sys
- { Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
- system_charset_info); }
+ {
+ Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
+ system_charset_info);
+ if (Lex->wild == NULL)
+ MYSQL_YYABORT;
+ }
| WHERE expr
{
Select->where= $2;
@@ -7490,7 +8406,14 @@ opt_describe_column:
/* empty */ {}
| text_string { Lex->wild= $1; }
| ident
- { Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info); };
+ {
+ Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
+ $1.length,
+ system_charset_info);
+ if (Lex->wild == NULL)
+ MYSQL_YYABORT;
+ }
+ ;
/* flush things */
@@ -7605,7 +8528,7 @@ load: LOAD DATA_SYM
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
if (lex->sphead)
{
@@ -7647,10 +8570,7 @@ load_data:
}
opt_duplicate INTO
{
- THD *thd= YYTHD;
- LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
- lex->fname_end= lip->ptr;
+ Lex->fname_end= YYLIP->ptr;
}
TABLE_SYM table_ident
{
@@ -7777,7 +8697,11 @@ fields_or_vars:
field_or_var:
simple_ident_nospvar {$$= $1;}
| '@' ident_or_text
- { $$= new Item_user_var_as_out_param($2); }
+ {
+ $$= new Item_user_var_as_out_param($2);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
;
opt_load_data_set_spec:
@@ -7802,9 +8726,14 @@ text_literal:
my_charset_is_ascii_based(cs_con)))
tmp= $1;
else
- thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
+ {
+ if (thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli))
+ MYSQL_YYABORT;
+ }
$$= new Item_string(tmp.str, tmp.length, cs_con,
DERIVATION_COERCIBLE, repertoire);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| NCHAR_STRING
{
@@ -7813,10 +8742,14 @@ text_literal:
DBUG_ASSERT(my_charset_is_ascii_based(national_charset_info));
$$= new Item_string($1.str, $1.length, national_charset_info,
DERIVATION_COERCIBLE, repertoire);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| UNDERSCORE_CHARSET TEXT_STRING
{
$$= new Item_string($2.str, $2.length, Lex->underscore_charset);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
((Item_string*) $$)->set_repertoire_from_value();
}
| text_literal TEXT_STRING_literal
@@ -7838,28 +8771,37 @@ text_literal:
;
text_string:
- TEXT_STRING_literal
- { $$= new (YYTHD->mem_root) String($1.str,$1.length,YYTHD->variables.collation_connection); }
+ TEXT_STRING_literal
+ {
+ $$= new (YYTHD->mem_root) String($1.str,
+ $1.length,
+ YYTHD->variables.collation_connection);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| HEX_NUM
{
Item *tmp= new Item_hex_string($1.str, $1.length);
+ if (tmp == NULL)
+ MYSQL_YYABORT;
/*
it is OK only emulate fix_fields, because we need only
value of constant
*/
- $$= tmp ?
- tmp->quick_fix_field(), tmp->val_str((String*) 0) :
- (String*) 0;
+ tmp->quick_fix_field();
+ $$= tmp->val_str((String*) 0);
}
| BIN_NUM
{
Item *tmp= new Item_bin_string($1.str, $1.length);
+ if (tmp == NULL)
+ MYSQL_YYABORT;
/*
it is OK only emulate fix_fields, because we need only
value of constant
*/
- $$= tmp ? tmp->quick_fix_field(), tmp->val_str((String*) 0) :
- (String*) 0;
+ tmp->quick_fix_field();
+ $$= tmp->val_str((String*) 0);
}
;
@@ -7868,7 +8810,7 @@ param_marker:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
Item_param *item;
if (! lex->parsing_options.allows_variable)
{
@@ -7901,76 +8843,121 @@ literal:
| NULL_SYM
{
$$ = new Item_null();
- YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ YYLIP->next_state= MY_LEX_OPERATOR_OR_IDENT;
+ }
+ | FALSE_SYM
+ {
+ $$= new Item_int((char*) "FALSE",0,1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | TRUE_SYM
+ {
+ $$= new Item_int((char*) "TRUE",1,1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | HEX_NUM
+ {
+ $$= new Item_hex_string($1.str, $1.length);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | BIN_NUM
+ {
+ $$= new Item_bin_string($1.str, $1.length);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
- | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
- | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
- | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
- | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
| UNDERSCORE_CHARSET HEX_NUM
{
Item *tmp= new Item_hex_string($2.str, $2.length);
+ if (tmp == NULL)
+ MYSQL_YYABORT;
/*
it is OK only emulate fix_fieds, because we need only
value of constant
*/
- String *str= tmp ?
- tmp->quick_fix_field(), tmp->val_str((String*) 0) :
- (String*) 0;
- $$= new Item_string(NULL, /* name will be set in select_item */
- str ? str->ptr() : "",
- str ? str->length() : 0,
- Lex->underscore_charset);
- if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE))
+ tmp->quick_fix_field();
+ String *str= tmp->val_str((String*) 0);
+ Item_string *item_str;
+ item_str= new Item_string(NULL, /* name will be set in select_item */
+ str ? str->ptr() : "",
+ str ? str->length() : 0,
+ Lex->underscore_charset);
+ if (!item_str ||
+ !item_str->check_well_formed_result(&item_str->str_value, TRUE))
{
MYSQL_YYABORT;
}
- ((Item_string *) $$)->set_repertoire_from_value();
+ item_str->set_repertoire_from_value();
+ $$= item_str;
}
| UNDERSCORE_CHARSET BIN_NUM
{
Item *tmp= new Item_bin_string($2.str, $2.length);
+ if (tmp == NULL)
+ MYSQL_YYABORT;
/*
it is OK only emulate fix_fieds, because we need only
value of constant
*/
- String *str= tmp ?
- tmp->quick_fix_field(), tmp->val_str((String*) 0) :
- (String*) 0;
- $$= new Item_string(NULL, /* name will be set in select_item */
- str ? str->ptr() : "",
- str ? str->length() : 0,
- Lex->underscore_charset);
- if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE))
+ tmp->quick_fix_field();
+ String *str= tmp->val_str((String*) 0);
+ Item_string *item_str;
+ item_str= new Item_string(NULL, /* name will be set in select_item */
+ str ? str->ptr() : "",
+ str ? str->length() : 0,
+ Lex->underscore_charset);
+ if (!item_str ||
+ !item_str->check_well_formed_result(&item_str->str_value, TRUE))
{
MYSQL_YYABORT;
}
+ $$= item_str;
}
| DATE_SYM text_literal { $$ = $2; }
| TIME_SYM text_literal { $$ = $2; }
| TIMESTAMP text_literal { $$ = $2; };
NUM_literal:
- NUM { int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
- | LONG_NUM { int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
- | ULONGLONG_NUM { $$ = new Item_uint($1.str, $1.length); }
+ NUM
+ {
+ int error;
+ $$ = new Item_int($1.str,
+ (longlong) my_strtoll10($1.str, NULL, &error),
+ $1.length);
+ }
+ | LONG_NUM
+ {
+ int error;
+ $$ = new Item_int($1.str,
+ (longlong) my_strtoll10($1.str, NULL, &error),
+ $1.length);
+ }
+ | ULONGLONG_NUM
+ {
+ $$= new Item_uint($1.str, $1.length);
+ }
| DECIMAL_NUM
- {
- $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
- if (YYTHD->net.report_error)
- {
- MYSQL_YYABORT;
- }
- }
+ {
+ $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
+ if (($$ == NULL) || (YYTHD->net.report_error))
+ {
+ MYSQL_YYABORT;
+ }
+ }
| FLOAT_NUM
- {
- $$ = new Item_float($1.str, $1.length);
- if (YYTHD->net.report_error)
- {
- MYSQL_YYABORT;
- }
- }
- ;
+ {
+ $$= new Item_float($1.str, $1.length);
+ if (($$ == NULL) || (YYTHD->net.report_error))
+ {
+ MYSQL_YYABORT;
+ }
+ }
+ ;
/**********************************************************************
** Creating different items.
@@ -7985,6 +8972,8 @@ table_wild:
{
SELECT_LEX *sel= Select;
$$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
+ if ($$ == NULL)
+ MYSQL_YYABORT;
sel->with_wild++;
}
| ident '.' ident '.' '*'
@@ -7993,6 +8982,8 @@ table_wild:
$$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
CLIENT_NO_SCHEMA ? NullS : $1.str),
$3.str,"*");
+ if ($$ == NULL)
+ MYSQL_YYABORT;
sel->with_wild++;
}
;
@@ -8005,7 +8996,7 @@ simple_ident:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
sp_variable_t *spv;
sp_pcontext *spc = lex->spcont;
if (spc && (spv = spc->find_variable(&$1)))
@@ -8022,11 +9013,12 @@ simple_ident:
lip->tok_start_prev -
lex->sphead->m_tmp_query,
lip->tok_end - lip->tok_start_prev);
+ if (splocal == NULL)
+ MYSQL_YYABORT;
#ifndef DBUG_OFF
- if (splocal)
- splocal->m_sp= lex->sphead;
+ splocal->m_sp= lex->sphead;
#endif
- $$ = (Item*) splocal;
+ $$= splocal;
lex->safe_to_cache_query=0;
}
else
@@ -8036,6 +9028,8 @@ simple_ident:
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
}
| simple_ident_q { $$= $1; }
@@ -8049,6 +9043,8 @@ simple_ident_nospvar:
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| simple_ident_q { $$= $1; }
;
@@ -8120,6 +9116,8 @@ simple_ident_q:
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
}
| '.' ident '.' ident
@@ -8136,6 +9134,8 @@ simple_ident_q:
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| ident '.' ident '.' ident
{
@@ -8157,6 +9157,8 @@ simple_ident_q:
(YYTHD->client_capabilities &
CLIENT_NO_SCHEMA ? NullS : $1.str),
$3.str, $5.str);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
};
@@ -8191,13 +9193,34 @@ field_ident:
| '.' ident { $$=$2;} /* For Delphi */;
table_ident:
- ident { $$=new Table_ident($1); }
- | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
- | '.' ident { $$=new Table_ident($2);} /* For Delphi */
+ ident
+ {
+ $$=new Table_ident($1);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | ident '.' ident
+ {
+ $$=new Table_ident(YYTHD, $1,$3,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | '.' ident
+ {
+ $$=new Table_ident($2); /* For Delphi */
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
;
table_ident_nodb:
- ident { LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); }
+ ident
+ {
+ LEX_STRING db={(char*) any_db,3};
+ $$=new Table_ident(YYTHD, db,$1,0);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
;
IDENT_sys:
@@ -8221,8 +9244,11 @@ IDENT_sys:
$$= $1;
}
else
- thd->convert_string(&$$, system_charset_info,
- $1.str, $1.length, thd->charset());
+ {
+ if (thd->convert_string(&$$, system_charset_info,
+ $1.str, $1.length, thd->charset()))
+ MYSQL_YYABORT;
+ }
}
;
@@ -8233,8 +9259,11 @@ TEXT_STRING_sys:
if (thd->charset_is_system_charset)
$$= $1;
else
- thd->convert_string(&$$, system_charset_info,
- $1.str, $1.length, thd->charset());
+ {
+ if (thd->convert_string(&$$, system_charset_info,
+ $1.str, $1.length, thd->charset()))
+ MYSQL_YYABORT;
+ }
}
;
@@ -8245,8 +9274,11 @@ TEXT_STRING_literal:
if (thd->charset_is_collation_connection)
$$= $1;
else
- thd->convert_string(&$$, thd->variables.collation_connection,
- $1.str, $1.length, thd->charset());
+ {
+ if (thd->convert_string(&$$, thd->variables.collation_connection,
+ $1.str, $1.length, thd->charset()))
+ MYSQL_YYABORT;
+ }
}
;
@@ -8258,8 +9290,11 @@ TEXT_STRING_filesystem:
if (thd->charset_is_character_set_filesystem)
$$= $1;
else
- thd->convert_string(&$$, thd->variables.character_set_filesystem,
- $1.str, $1.length, thd->charset());
+ {
+ if (thd->convert_string(&$$, thd->variables.character_set_filesystem,
+ $1.str, $1.length, thd->charset()))
+ MYSQL_YYABORT;
+ }
}
;
@@ -8269,6 +9304,8 @@ ident:
{
THD *thd= YYTHD;
$$.str= thd->strmake($1.str, $1.length);
+ if ($$.str == NULL)
+ MYSQL_YYABORT;
$$.length= $1.length;
}
;
@@ -8279,6 +9316,8 @@ label_ident:
{
THD *thd= YYTHD;
$$.str= thd->strmake($1.str, $1.length);
+ if ($$.str == NULL)
+ MYSQL_YYABORT;
$$.length= $1.length;
}
;
@@ -8311,8 +9350,7 @@ user:
if (check_string_length(&$$->user,
ER(ER_USERNAME), USERNAME_LENGTH) ||
- check_string_length(&$$->host,
- ER(ER_HOSTNAME), HOSTNAME_LENGTH))
+ check_host_name(&$$->host))
MYSQL_YYABORT;
}
| CURRENT_USER optional_braces
@@ -8631,7 +9669,7 @@ option_type_value:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
if (lex->sphead)
{
@@ -8662,7 +9700,7 @@ option_type_value:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
if (lex->sphead)
{
@@ -8823,29 +9861,50 @@ sys_option_value:
LEX *lex=Lex;
if ($1)
lex->option_type= $1;
- lex->var_list.push_back(new set_var(lex->option_type,
- find_sys_var("tx_isolation"),
- &null_lex_str,
- new Item_int((int32) $5)));
+ Item *item= new Item_int((int32) $5);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ set_var *var= new set_var(lex->option_type,
+ find_sys_var("tx_isolation"),
+ &null_lex_str,
+ item);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ lex->var_list.push_back(var);
}
;
option_value:
'@' ident_or_text equal expr
{
- Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
+ Item_func_set_user_var *item= new Item_func_set_user_var($2,$4);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ set_var_user *var= new set_var_user(item);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ Lex->var_list.push_back(var);
}
| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
{
LEX *lex=Lex;
- lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
+ set_var *var= new set_var($3, $4.var, &$4.base_name, $6);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ lex->var_list.push_back(var);
}
| charset old_or_new_charset_name_or_default
{
THD *thd= YYTHD;
LEX *lex= Lex;
$2= $2 ? $2: global_system_variables.character_set_client;
- lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
+ set_var_collation_client *var;
+ var= new set_var_collation_client($2,
+ thd->variables.collation_database,
+ $2);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ lex->var_list.push_back(var);
}
| NAMES_SYM equal expr
{
@@ -8873,7 +9932,11 @@ option_value:
$3->name, $2->csname);
MYSQL_YYABORT;
}
- lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
+ set_var_collation_client *var;
+ var= new set_var_collation_client($3,$3,$3);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ lex->var_list.push_back(var);
}
| PASSWORD equal text_or_password
{
@@ -8894,11 +9957,17 @@ option_value:
MYSQL_YYABORT;
user->host=null_lex_str;
user->user.str=thd->security_ctx->priv_user;
- thd->lex->var_list.push_back(new set_var_password(user, $3));
+ set_var_password *var= new set_var_password(user, $3);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ thd->lex->var_list.push_back(var);
}
| PASSWORD FOR_SYM user equal text_or_password
{
- Lex->var_list.push_back(new set_var_password($3,$5));
+ set_var_password *var= new set_var_password($3,$5);
+ if (var == NULL)
+ MYSQL_YYABORT;
+ Lex->var_list.push_back(var);
}
;
@@ -9012,11 +10081,15 @@ text_or_password:
Item_func_old_password::alloc(YYTHD, $3.str) :
Item_func_password::alloc(YYTHD, $3.str) :
$3.str;
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
| OLD_PASSWORD '(' TEXT_STRING ')'
{
$$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str) :
$3.str;
+ if ($$ == NULL)
+ MYSQL_YYABORT;
}
;
@@ -9024,9 +10097,24 @@ text_or_password:
set_expr_or_default:
expr { $$=$1; }
| DEFAULT { $$=0; }
- | ON { $$=new Item_string("ON", 2, system_charset_info); }
- | ALL { $$=new Item_string("ALL", 3, system_charset_info); }
- | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
+ | ON
+ {
+ $$=new Item_string("ON", 2, system_charset_info);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | ALL
+ {
+ $$=new Item_string("ALL", 3, system_charset_info);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | BINARY
+ {
+ $$=new Item_string("binary", 6, system_charset_info);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
;
@@ -9127,7 +10215,10 @@ handler:
}
lex->sql_command = SQLCOM_HA_READ;
lex->ha_rkey_mode= HA_READ_KEY_EXACT; /* Avoid purify warnings */
- lex->current_select->select_limit= new Item_int((int32) 1);
+ Item *one= new Item_int((int32) 1);
+ if (one == NULL)
+ MYSQL_YYABORT;
+ lex->current_select->select_limit= one;
lex->current_select->offset_limit= 0;
if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
MYSQL_YYABORT;
@@ -9434,8 +10525,9 @@ grant_user:
{
char *buff=
(char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
- if (buff)
- make_scrambled_password_323(buff, $4.str);
+ if (buff == NULL)
+ MYSQL_YYABORT;
+ make_scrambled_password_323(buff, $4.str);
$1->password.str= buff;
$1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
}
@@ -9443,8 +10535,9 @@ grant_user:
{
char *buff=
(char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
- if (buff)
- make_scrambled_password(buff, $4.str);
+ if (buff == NULL)
+ MYSQL_YYABORT;
+ make_scrambled_password(buff, $4.str);
$1->password.str= buff;
$1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH;
}
@@ -9473,6 +10566,8 @@ column_list_id:
ident
{
String *new_str = new (YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
+ if (new_str == NULL)
+ MYSQL_YYABORT;
List_iterator <LEX_COLUMN> iter(Lex->columns);
class LEX_COLUMN *point;
LEX *lex=Lex;
@@ -9486,7 +10581,12 @@ column_list_id:
if (point)
point->rights |= lex->which_columns;
else
- lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
+ {
+ LEX_COLUMN *col= new LEX_COLUMN (*new_str,lex->which_columns);
+ if (col == NULL)
+ MYSQL_YYABORT;
+ lex->columns.push_back(col);
+ }
}
;
@@ -9900,13 +11000,17 @@ view_list_opt:
view_list:
ident
{
- Lex->view_list.push_back((LEX_STRING*)
- sql_memdup(&$1, sizeof(LEX_STRING)));
+ LEX_STRING *ls= (LEX_STRING*) sql_memdup(&$1, sizeof(LEX_STRING));
+ if (ls == NULL)
+ MYSQL_YYABORT;
+ Lex->view_list.push_back(ls);
}
| view_list ',' ident
{
- Lex->view_list.push_back((LEX_STRING*)
- sql_memdup(&$3, sizeof(LEX_STRING)));
+ LEX_STRING *ls= (LEX_STRING*) sql_memdup(&$3, sizeof(LEX_STRING));
+ if (ls == NULL)
+ MYSQL_YYABORT;
+ Lex->view_list.push_back(ls);
}
;
@@ -9972,7 +11076,7 @@ trigger_tail:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
sp_head *sp;
if (lex->sphead)
@@ -10065,7 +11169,7 @@ sf_tail:
{ /* $5 */
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
sp_head *sp;
lex->stmt_definition_begin= $1;
@@ -10079,6 +11183,8 @@ sf_tail:
/* Order is important here: new - reset - init */
sp= new sp_head();
+ if (sp == NULL)
+ MYSQL_YYABORT;
sp->reset_thd_mem_root(thd);
sp->init(lex);
sp->init_sp_name(thd, lex->spname);
@@ -10090,11 +11196,7 @@ sf_tail:
sp_fdparam_list /* $6 */
')' /* $7 */
{ /* $8 */
- THD *thd= YYTHD;
- LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
-
- lex->sphead->m_param_end= lip->tok_start;
+ Lex->sphead->m_param_end= YYLIP->tok_start;
}
RETURNS_SYM /* $9 */
{ /* $10 */
@@ -10120,7 +11222,7 @@ sf_tail:
{ /* $14 */
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->m_body_begin= lip->tok_start;
@@ -10172,18 +11274,14 @@ sp_tail:
}
'('
{
- THD *thd= YYTHD;
- LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
-
- lex->sphead->m_param_begin= lip->tok_start+1;
+ Lex->sphead->m_param_begin= YYLIP->tok_start+1;
}
sp_pdparam_list
')'
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
lex->sphead->m_param_end= lip->tok_start;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
@@ -10192,7 +11290,7 @@ sp_tail:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= YYLIP;
lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->m_body_begin= lip->tok_start;
diff --git a/sql/stacktrace.c b/sql/stacktrace.c
index ce91d63d3f7..4e6ad68c172 100644
--- a/sql/stacktrace.c
+++ b/sql/stacktrace.c
@@ -261,6 +261,7 @@ void write_core(int sig)
#else /* __WIN__*/
#include <dbghelp.h>
+#include <tlhelp32.h>
/*
Stack tracing on Windows is implemented using Debug Helper library(dbghelp.dll)
@@ -349,6 +350,68 @@ void set_exception_pointers(EXCEPTION_POINTERS *ep)
exception_ptrs = ep;
}
+
+/*
+ Get symbol path - semicolon-separated list of directories to search for debug
+ symbols. We expect PDB in the same directory as corresponding exe or dll,
+ so the path is build from directories of the loaded modules. If environment
+ variable _NT_SYMBOL_PATH is set, it's value appended to the symbol search path
+*/
+static void get_symbol_path(char *path, size_t size)
+{
+ HANDLE hSnap;
+ char *envvar;
+
+ path[0]= '\0';
+ /*
+ Enumerate all modules, and add their directories to the path.
+ Avoid duplicate entries.
+ */
+ hSnap= CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
+ if (hSnap != INVALID_HANDLE_VALUE)
+ {
+ BOOL ret;
+ MODULEENTRY32 mod;
+ mod.dwSize= sizeof(MODULEENTRY32);
+ for (ret= Module32First(hSnap, &mod); ret; ret= Module32Next(hSnap, &mod))
+ {
+ char *module_dir= mod.szExePath;
+ char *p= strrchr(module_dir,'\\');
+ if (!p)
+ {
+ /*
+ Path separator was not found. Not known to happen, if ever happens,
+ will indicate current directory.
+ */
+ module_dir[0]= '.';
+ p= module_dir + 1;
+ }
+ *p++= ';';
+ *p= '\0';
+
+ if (!strstr(path, module_dir))
+ {
+ size_t dir_len = strlen(module_dir);
+ if (size > dir_len)
+ {
+ strncat(path, module_dir, size-1);
+ size -= dir_len;
+ }
+ }
+ }
+ CloseHandle(hSnap);
+ }
+
+ /* Add _NT_SYMBOL_PATH, if present. */
+ envvar= getenv("_NT_SYMBOL_PATH");
+ if(envvar && size)
+ {
+ strncat(path, envvar, size-1);
+ }
+}
+
+#define MAX_SYMBOL_PATH 32768
+
/* Platform SDK in VS2003 does not have definition for SYMOPT_NO_PROMPTS*/
#ifndef SYMOPT_NO_PROMPTS
#define SYMOPT_NO_PROMPTS 0
@@ -365,6 +428,7 @@ void print_stacktrace(gptr unused1, ulong unused2)
int i;
CONTEXT context;
STACKFRAME64 frame={0};
+ static char symbol_path[MAX_SYMBOL_PATH];
if(!exception_ptrs || !init_dbghelp_functions())
return;
@@ -373,7 +437,8 @@ void print_stacktrace(gptr unused1, ulong unused2)
context = *(exception_ptrs->ContextRecord);
/*Initialize symbols.*/
pSymSetOptions(SYMOPT_LOAD_LINES|SYMOPT_NO_PROMPTS|SYMOPT_DEFERRED_LOADS|SYMOPT_DEBUG);
- pSymInitialize(hProcess,NULL,TRUE);
+ get_symbol_path(symbol_path, sizeof(symbol_path));
+ pSymInitialize(hProcess, symbol_path, TRUE);
/*Prepare stackframe for the first StackWalk64 call*/
frame.AddrFrame.Mode= frame.AddrPC.Mode= frame.AddrStack.Mode= AddrModeFlat;
diff --git a/sql/structs.h b/sql/structs.h
index 32bdab0bc15..caa8aae1b89 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -170,7 +170,7 @@ enum SHOW_TYPE
SHOW_UNDEF,
SHOW_LONG, SHOW_LONGLONG, SHOW_INT, SHOW_CHAR, SHOW_CHAR_PTR,
SHOW_DOUBLE_STATUS,
- SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME, SHOW_QUESTION,
+ SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME,
SHOW_LONG_CONST, SHOW_INT_CONST, SHOW_HAVE, SHOW_SYS, SHOW_HA_ROWS,
SHOW_VARS,
SHOW_FLUSHTIME,
diff --git a/sql/table.cc b/sql/table.cc
index 7fe9aa774f3..3abd2c24c94 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2191,7 +2191,7 @@ TABLE_LIST *TABLE_LIST::find_underlying_table(TABLE *table_to_find)
}
/*
- cleunup items belonged to view fields translation table
+ cleanup items belonged to view fields translation table
SYNOPSIS
TABLE_LIST::cleanup_items()
@@ -2637,10 +2637,10 @@ Natural_join_column::Natural_join_column(Field_translator *field_param,
}
-Natural_join_column::Natural_join_column(Field *field_param,
+Natural_join_column::Natural_join_column(Item_field *field_param,
TABLE_LIST *tab)
{
- DBUG_ASSERT(tab->table == field_param->table);
+ DBUG_ASSERT(tab->table == field_param->field->table);
table_field= field_param;
view_field= NULL;
table_ref= tab;
@@ -2668,7 +2668,7 @@ Item *Natural_join_column::create_item(THD *thd)
return create_view_field(thd, table_ref, &view_field->item,
view_field->name);
}
- return new Item_field(thd, &thd->lex->current_select->context, table_field);
+ return table_field;
}
@@ -2679,7 +2679,7 @@ Field *Natural_join_column::field()
DBUG_ASSERT(table_field == NULL);
return NULL;
}
- return table_field;
+ return table_field->field;
}
@@ -2811,7 +2811,7 @@ void Field_iterator_natural_join::next()
cur_column_ref= column_ref_it++;
DBUG_ASSERT(!cur_column_ref || ! cur_column_ref->table_field ||
cur_column_ref->table_ref->table ==
- cur_column_ref->table_field->table);
+ cur_column_ref->table_field->field->table);
}
@@ -2975,7 +2975,7 @@ GRANT_INFO *Field_iterator_table_ref::grant()
*/
Natural_join_column *
-Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
+Field_iterator_table_ref::get_or_create_column_ref(THD *thd, TABLE_LIST *parent_table_ref)
{
Natural_join_column *nj_col;
bool is_created= TRUE;
@@ -2988,7 +2988,11 @@ Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
{
/* The field belongs to a stored table. */
Field *tmp_field= table_field_it.field();
- nj_col= new Natural_join_column(tmp_field, table_ref);
+ Item_field *tmp_item=
+ new Item_field(thd, &thd->lex->current_select->context, tmp_field);
+ if (!tmp_item)
+ return NULL;
+ nj_col= new Natural_join_column(tmp_item, table_ref);
field_count= table_ref->table->s->fields;
}
else if (field_it == &view_field_it)
@@ -3012,7 +3016,7 @@ Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
DBUG_ASSERT(nj_col);
}
DBUG_ASSERT(!nj_col->table_field ||
- nj_col->table_ref->table == nj_col->table_field->table);
+ nj_col->table_ref->table == nj_col->table_field->field->table);
/*
If the natural join column was just created add it to the list of
@@ -3077,7 +3081,7 @@ Field_iterator_table_ref::get_natural_column_ref()
nj_col= natural_join_it.column_ref();
DBUG_ASSERT(nj_col &&
(!nj_col->table_field ||
- nj_col->table_ref->table == nj_col->table_field->table));
+ nj_col->table_ref->table == nj_col->table_field->field->table));
return nj_col;
}
diff --git a/sql/table.h b/sql/table.h
index 5842cc8b1c9..ad578044371 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -18,6 +18,7 @@
class Item; /* Needed by ORDER */
class Item_subselect;
+class Item_field;
class GRANT_TABLE;
class st_select_lex_unit;
class st_select_lex;
@@ -470,7 +471,7 @@ class Natural_join_column: public Sql_alloc
{
public:
Field_translator *view_field; /* Column reference of merge view. */
- Field *table_field; /* Column reference of table or temp view. */
+ Item_field *table_field; /* Column reference of table or temp view. */
TABLE_LIST *table_ref; /* Original base table/view reference. */
/*
True if a common join column of two NATURAL/USING join operands. Notice
@@ -482,7 +483,7 @@ public:
bool is_common;
public:
Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
- Natural_join_column(Field *field_param, TABLE_LIST *tab);
+ Natural_join_column(Item_field *field_param, TABLE_LIST *tab);
const char *name();
Item *create_item(THD *thd);
Field *field();
@@ -657,7 +658,6 @@ struct TABLE_LIST
st_lex_user definer; /* definer of view */
ulonglong file_version; /* version of file's field set */
ulonglong updatable_view; /* VIEW can be updated */
- ulonglong revision; /* revision control number */
ulonglong algorithm; /* 0 any, 1 tmp tables , 2 merging */
ulonglong view_suid; /* view is suid (TRUE dy default) */
ulonglong with_check; /* WITH CHECK OPTION */
@@ -900,7 +900,7 @@ public:
GRANT_INFO *grant();
Item *create_item(THD *thd) { return field_it->create_item(thd); }
Field *field() { return field_it->field(); }
- Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref);
+ Natural_join_column *get_or_create_column_ref(THD *thd, TABLE_LIST *parent_table_ref);
Natural_join_column *get_natural_column_ref();
};
diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc
index 392db9224c3..4ebcf1c50af 100644
--- a/sql/thr_malloc.cc
+++ b/sql/thr_malloc.cc
@@ -21,10 +21,35 @@
extern "C" {
void sql_alloc_error_handler(void)
{
- THD *thd=current_thd;
- if (thd) // QQ; To be removed
- thd->fatal_error(); /* purecov: inspected */
sql_print_error(ER(ER_OUT_OF_RESOURCES));
+
+ THD *thd=current_thd;
+ if (thd)
+ {
+ /*
+ This thread is Out Of Memory.
+ An OOM condition is a fatal error.
+ It should not be caught by error handlers in stored procedures.
+ Also, recording that SQL condition in the condition area could
+ cause more memory allocations, which in turn could raise more
+ OOM conditions, causing recursion in the error handling code itself.
+ As a result, my_error() should not be invoked, and the
+ thread diagnostics area is set to an error status directly.
+ The visible result for a client application will be:
+ - a query fails with an ER_OUT_OF_RESOURCES error,
+ returned in the error packet.
+ - SHOW ERROR/SHOW WARNINGS may be empty.
+ */
+
+ NET *net= &thd->net;
+ thd->fatal_error();
+ if (!net->last_error[0]) // Return only first message
+ {
+ strmake(net->last_error, ER(ER_OUT_OF_RESOURCES),
+ sizeof(net->last_error)-1);
+ net->last_errno= ER_OUT_OF_RESOURCES;
+ }
+ }
}
}
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 709e3b64752..d3d952e3c1e 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -1073,6 +1073,7 @@ Time_zone_system::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
localtime_r(&tmp_t, &tmp_tm);
localtime_to_TIME(tmp, &tmp_tm);
tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
+ adjust_leap_second(tmp);
}
@@ -1157,6 +1158,7 @@ Time_zone_utc::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
gmtime_r(&tmp_t, &tmp_tm);
localtime_to_TIME(tmp, &tmp_tm);
tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
+ adjust_leap_second(tmp);
}
@@ -1260,6 +1262,7 @@ void
Time_zone_db::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
{
::gmt_sec_to_TIME(tmp, t, tz_info);
+ adjust_leap_second(tmp);
}
@@ -2373,6 +2376,25 @@ Time_zone *my_tz_find_with_opening_tz_tables(THD *thd, const String *name)
DBUG_RETURN(tz);
}
+
+/**
+ Convert leap seconds into non-leap
+
+ This function will convert the leap seconds added by the OS to
+ non-leap seconds, e.g. 23:59:59, 23:59:60 -> 23:59:59, 00:00:01 ...
+ This check is not checking for years on purpose : although it's not a
+ complete check this way it doesn't require looking (and having installed)
+ the leap seconds table.
+
+ @param[in,out] broken down time structure as filled in by the OS
+*/
+
+void Time_zone::adjust_leap_second(MYSQL_TIME *t)
+{
+ if (t->second == 60 || t->second == 61)
+ t->second= 59;
+}
+
#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
diff --git a/sql/tztime.h b/sql/tztime.h
index 32a942a26e1..750b8dacbe1 100644
--- a/sql/tztime.h
+++ b/sql/tztime.h
@@ -55,6 +55,9 @@ public:
allocated on MEM_ROOT and should not require destruction.
*/
virtual ~Time_zone() {};
+
+protected:
+ static inline void adjust_leap_second(MYSQL_TIME *t);
};
extern Time_zone * my_tz_UTC;