summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/event_db_repository.cc15
-rw-r--r--sql/field.cc15
-rw-r--r--sql/filesort.cc2
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/item.cc41
-rw-r--r--sql/item_subselect.cc19
-rw-r--r--sql/item_timefunc.cc5
-rw-r--r--sql/mysqld.cc110
-rw-r--r--sql/signal_handler.cc2
-rw-r--r--sql/sp_head.cc22
-rw-r--r--sql/sql_base.cc16
-rw-r--r--sql/sql_connect.cc13
-rw-r--r--sql/sql_delete.cc5
-rw-r--r--sql/sql_lex.cc6
-rw-r--r--sql/sql_load.cc14
-rw-r--r--sql/sql_parse.cc17
-rw-r--r--sql/sql_parse.h1
-rw-r--r--sql/sql_select.cc25
-rw-r--r--sql/sql_select.h6
-rw-r--r--sql/sql_table.cc10
-rw-r--r--sql/sql_trigger.cc3
-rw-r--r--sql/sql_udf.cc6
-rw-r--r--sql/sql_update.cc11
-rw-r--r--sql/sql_yacc.yy8
-rw-r--r--sql/sys_vars.cc1
-rw-r--r--sql/sys_vars.ic2
-rw-r--r--sql/table.cc13
-rw-r--r--sql/table.h3
28 files changed, 193 insertions, 200 deletions
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index ba782a19f8c..3afd2659a29 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -18,6 +18,7 @@
#include "sql_priv.h"
#include "unireg.h"
#include "sql_base.h" // close_thread_tables
+#include "sql_parse.h"
#include "event_db_repository.h"
#include "key.h" // key_copy
#include "sql_db.h" // get_default_db_collation
@@ -701,19 +702,17 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
restore_record(table, s->default_values); // Get default values for fields
- if (system_charset_info->cset->
- numchars(system_charset_info, parse_data->dbname.str,
- parse_data->dbname.str + parse_data->dbname.length) >
- table->field[ET_FIELD_DB]->char_length())
+ if (check_string_char_length(&parse_data->dbname, 0,
+ table->field[ET_FIELD_DB]->char_length(),
+ system_charset_info, 1))
{
my_error(ER_TOO_LONG_IDENT, MYF(0), parse_data->dbname.str);
goto end;
}
- if (system_charset_info->cset->
- numchars(system_charset_info, parse_data->name.str,
- parse_data->name.str + parse_data->name.length) >
- table->field[ET_FIELD_NAME]->char_length())
+ if (check_string_char_length(&parse_data->name, 0,
+ table->field[ET_FIELD_NAME]->char_length(),
+ system_charset_info, 1))
{
my_error(ER_TOO_LONG_IDENT, MYF(0), parse_data->name.str);
goto end;
diff --git a/sql/field.cc b/sql/field.cc
index b909d14ec8f..58def13f5f3 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1345,12 +1345,15 @@ void Field_num::prepend_zeros(String *value) const
int diff;
if ((diff= (int) (field_length - value->length())) > 0)
{
- bmove_upp((uchar*) value->ptr()+field_length,
- (uchar*) value->ptr()+value->length(),
- value->length());
- bfill((uchar*) value->ptr(),diff,'0');
- value->length(field_length);
- (void) value->c_ptr_quick(); // Avoid warnings in purify
+ const bool error= value->realloc(field_length);
+ if (!error)
+ {
+ bmove_upp((uchar*) value->ptr()+field_length,
+ (uchar*) value->ptr()+value->length(),
+ value->length());
+ bfill((uchar*) value->ptr(),diff,'0');
+ value->length(field_length);
+ }
}
}
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 917b9de6038..23674b937fc 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -1639,7 +1639,7 @@ int merge_buffers(Sort_param *param, IO_CACHE *from_file,
if (!(error= (int) read_to_buffer(from_file, buffpek,
rec_length)))
{
- queue_remove(&queue,0);
+ (void) queue_remove_top(&queue);
reuse_freed_buff(&queue, buffpek, rec_length);
}
else if (error == -1)
diff --git a/sql/handler.cc b/sql/handler.cc
index 802364cb6e5..af06427ff19 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -4517,7 +4517,7 @@ void handler::get_dynamic_partition_info(PARTITION_STATS *stat_info,
stat_info->update_time= stats.update_time;
stat_info->check_time= stats.check_time;
stat_info->check_sum= 0;
- if (table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_OLD_CHECKSUM))
+ if (table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM))
stat_info->check_sum= checksum();
return;
}
diff --git a/sql/item.cc b/sql/item.cc
index 015f5591c5d..2e7bc8e20c0 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1133,7 +1133,8 @@ Item *Item_cache::safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
if (conv == example)
return this;
Item_cache *cache;
- if (!conv || !(cache= new (thd->mem_root) Item_cache_str(thd, conv)))
+ if (!conv || conv->fix_fields(current_thd, (Item **) NULL) ||
+ !(cache= new (thd->mem_root) Item_cache_str(thd, conv)))
return NULL; // Safe conversion is not possible, or OEM
cache->setup(thd, conv);
cache->fixed= false; // Make Item::fix_fields() happy
@@ -2679,6 +2680,44 @@ void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref)
depended_from= NULL;
if (context)
{
+ bool need_change= false;
+ /*
+ Suppose there are nested selects:
+
+ select_id=1
+ select_id=2
+ select_id=3 <----+
+ select_id=4 -+
+ select_id=5 --+
+
+ Suppose, pullout operation has moved anything that had select_id=4 or 5
+ in to select_id=3.
+
+ If this Item_field had a name resolution context pointing into select_lex
+ with id=4 or id=5, it needs a new name resolution context.
+
+ However, it could also be that this object is a part of outer reference:
+ Item_ref(Item_field(field in select with select_id=1))).
+ - The Item_ref object has a context with select_id=5, and so needs a new
+ name resolution context.
+ - The Item_field object has a context with select_id=1, and doesn't need
+ a new name resolution context.
+
+ So, the following loop walks from Item_field's current context upwards.
+ If we find that the select we've been pulled out to is up there, we
+ create the new name resolution context. Otherwise, we don't.
+ */
+ for (Name_resolution_context *ct= context; ct; ct= ct->outer_context)
+ {
+ if (new_parent == ct->select_lex)
+ {
+ need_change= true;
+ break;
+ }
+ }
+ if (!need_change)
+ return;
+
Name_resolution_context *ctx= new Name_resolution_context();
if (context->select_lex == new_parent)
{
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 98f7c470037..3157d666e9b 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1,5 +1,5 @@
-/* Copyright (c) 2002, 2015, Oracle and/or its affiliates.
- Copyright (c) 2010, 2015, MariaDB
+/* Copyright (c) 2002, 2016, Oracle and/or its affiliates.
+ Copyright (c) 2010, 2016, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -3511,9 +3511,14 @@ bool subselect_union_engine::is_executed() const
bool subselect_union_engine::no_rows()
{
/* Check if we got any rows when reading UNION result from temp. table: */
- return MY_TEST(!(unit->fake_select_lex ?
- unit->fake_select_lex->join->send_records :
- ((select_union_direct *)(unit->get_union_result()))
+ if (unit->fake_select_lex)
+ {
+ JOIN *join= unit->fake_select_lex->join;
+ if (join)
+ return MY_TEST(!join->send_records);
+ return false;
+ }
+ return MY_TEST(!(((select_union_direct *)(unit->get_union_result()))
->send_records));
}
@@ -4897,9 +4902,9 @@ bool subselect_hash_sj_engine::init(List<Item> *tmp_columns, uint subquery_id)
result= result_sink;
/*
- If the subquery has blobs, or the total key lenght is bigger than
+ If the subquery has blobs, or the total key length is bigger than
some length, or the total number of key parts is more than the
- allowed maximum (currently MAX_REF_PARTS == 16), then the created
+ allowed maximum (currently MAX_REF_PARTS == 32), then the created
index cannot be used for lookups and we can't use hash semi
join. If this is the case, delete the temporary table since it
will not be used, and tell the caller we failed to initialize the
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index ff13e707ac4..49bf8036ea1 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -426,7 +426,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
{
if (!my_isspace(&my_charset_latin1,*val))
{
- make_truncated_value_warning(current_thd,
+ make_truncated_value_warning(current_thd,
Sql_condition::WARN_LEVEL_WARN,
val_begin, length,
cached_timestamp_type, NullS);
@@ -711,7 +711,7 @@ static bool get_interval_info(const char *str,uint length,CHARSET_INFO *cs,
{
longlong value;
const char *start= str;
- for (value=0; str != end && my_isdigit(cs, *str) ; str++)
+ for (value= 0; str != end && my_isdigit(cs, *str); str++)
value= value*10 + *str - '0';
msec_length= 6 - (str - start);
values[i]= value;
@@ -1464,6 +1464,7 @@ void Item_temporal_func::fix_length_and_dec()
time can get us to return NULL.
*/
maybe_null= 1;
+
if (decimals)
{
if (decimals == NOT_FIXED_DEC)
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index adb1b273b80..d540cc03d2a 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -130,10 +130,7 @@ extern "C" { // Because of SCO 3.2V4.2
#include <sysent.h>
#endif
#ifdef HAVE_PWD_H
-#include <pwd.h> // For getpwent
-#endif
-#ifdef HAVE_GRP_H
-#include <grp.h>
+#include <pwd.h> // For struct passwd
#endif
#include <my_net.h>
@@ -483,9 +480,7 @@ ulong opt_binlog_rows_event_max_size;
my_bool opt_master_verify_checksum= 0;
my_bool opt_slave_sql_verify_checksum= 1;
const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NullS};
-#ifdef HAVE_INITGROUPS
volatile sig_atomic_t calling_initgroups= 0; /**< Used in SIGSEGV handler. */
-#endif
uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
uint mysqld_extra_port;
uint mysqld_port_timeout;
@@ -2331,59 +2326,18 @@ static void set_ports()
static struct passwd *check_user(const char *user)
{
-#if !defined(__WIN__)
- struct passwd *tmp_user_info;
- uid_t user_id= geteuid();
+ myf flags= 0;
+ if (global_system_variables.log_warnings)
+ flags|= MY_WME;
+ if (!opt_bootstrap && !opt_help)
+ flags|= MY_FAE;
- // Don't bother if we aren't superuser
- if (user_id)
- {
- if (user)
- {
- /* Don't give a warning, if real user is same as given with --user */
- /* purecov: begin tested */
- tmp_user_info= getpwnam(user);
- if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
- global_system_variables.log_warnings)
- sql_print_warning(
- "One can only use the --user switch if running as root\n");
- /* purecov: end */
- }
- return NULL;
- }
- if (!user)
- {
- if (!opt_bootstrap && !opt_help)
- {
- sql_print_error("Fatal error: Please consult the Knowledge Base "
- "to find out how to run mysqld as root!\n");
- unireg_abort(1);
- }
- return NULL;
- }
- /* purecov: begin tested */
- if (!strcmp(user,"root"))
- return NULL; // Avoid problem with dynamic libraries
+ struct passwd *tmp_user_info= my_check_user(user, MYF(flags));
- if (!(tmp_user_info= getpwnam(user)))
- {
- // Allow a numeric uid to be used
- const char *pos;
- for (pos= user; my_isdigit(mysqld_charset,*pos); pos++) ;
- if (*pos) // Not numeric id
- goto err;
- if (!(tmp_user_info= getpwuid(atoi(user))))
- goto err;
- }
+ if (!tmp_user_info && my_errno==EINVAL && (flags & MY_FAE))
+ unireg_abort(1);
return tmp_user_info;
- /* purecov: end */
-
-err:
- sql_print_error("Fatal error: Can't change to run as user '%s' ; Please check that the user exists!\n",user);
- unireg_abort(1);
-#endif
- return NULL;
}
static inline void allow_coredumps()
@@ -2400,10 +2354,6 @@ static inline void allow_coredumps()
static void set_user(const char *user, struct passwd *user_info_arg)
{
- /* purecov: begin tested */
-#if !defined(__WIN__)
- DBUG_ASSERT(user_info_arg != 0);
-#ifdef HAVE_INITGROUPS
/*
We can get a SIGSEGV when calling initgroups() on some systems when NSS
is configured to use LDAP and the server is statically linked. We set
@@ -2411,22 +2361,11 @@ static void set_user(const char *user, struct passwd *user_info_arg)
output a specific message to help the user resolve this problem.
*/
calling_initgroups= 1;
- initgroups((char*) user, user_info_arg->pw_gid);
+ int res= my_set_user(user, user_info_arg, MYF(MY_WME));
calling_initgroups= 0;
-#endif
- if (setgid(user_info_arg->pw_gid) == -1)
- {
- sql_perror("setgid");
+ if (res)
unireg_abort(1);
- }
- if (setuid(user_info_arg->pw_uid) == -1)
- {
- sql_perror("setuid");
- unireg_abort(1);
- }
allow_coredumps();
-#endif
- /* purecov: end */
}
@@ -4475,19 +4414,24 @@ static int init_common_variables()
default_charset_info= default_collation;
}
/* Set collactions that depends on the default collation */
- global_system_variables.collation_server= default_charset_info;
- global_system_variables.collation_database= default_charset_info;
- global_system_variables.collation_connection= default_charset_info;
- global_system_variables.character_set_results= default_charset_info;
- if (default_charset_info->mbminlen > 1)
- {
- global_system_variables.character_set_client= &my_charset_latin1;
- sql_print_warning("Cannot use %s as character_set_client, %s will be used instead",
- default_charset_info->csname,
- global_system_variables.character_set_client->csname);
+ global_system_variables.collation_server= default_charset_info;
+ global_system_variables.collation_database= default_charset_info;
+ if (is_supported_parser_charset(default_charset_info))
+ {
+ global_system_variables.collation_connection= default_charset_info;
+ global_system_variables.character_set_results= default_charset_info;
+ global_system_variables.character_set_client= default_charset_info;
}
else
- global_system_variables.character_set_client= default_charset_info;
+ {
+ sql_print_warning("'%s' can not be used as client character set. "
+ "'%s' will be used as default client character set.",
+ default_charset_info->csname,
+ my_charset_latin1.csname);
+ global_system_variables.collation_connection= &my_charset_latin1;
+ global_system_variables.character_set_results= &my_charset_latin1;
+ global_system_variables.character_set_client= &my_charset_latin1;
+ }
if (!(character_set_filesystem=
get_charset_by_csname(character_set_filesystem_name,
diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc
index 6593c3f3dbc..76af7733fb9 100644
--- a/sql/signal_handler.cc
+++ b/sql/signal_handler.cc
@@ -156,7 +156,7 @@ extern "C" sig_handler handle_fatal_signal(int sig)
if (opt_stack_trace)
{
- my_safe_printf_stderr("Thread pointer: 0x%p\n", thd);
+ my_safe_printf_stderr("Thread pointer: %p\n", thd);
my_safe_printf_stderr("%s",
"Attempting backtrace. You can use the following "
"information to find out\n"
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 29427c3834a..58f5082ab14 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -542,12 +542,8 @@ check_routine_name(LEX_STRING *ident)
my_error(ER_SP_WRONG_NAME, MYF(0), ident->str);
return TRUE;
}
- if (check_string_char_length(ident, 0, NAME_CHAR_LEN,
- system_charset_info, 1))
- {
- my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str);
+ if (check_ident_length(ident))
return TRUE;
- }
return FALSE;
}
@@ -3129,23 +3125,23 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
thd->query_length()) <= 0)
{
res= m_lex_keeper.reset_lex_and_exec_core(thd, nextp, FALSE, this);
+ bool log_slow= !res && thd->enable_slow_log;
- if (thd->get_stmt_da()->is_eof())
- {
- /* Finalize server status flags after executing a statement. */
+ /* Finalize server status flags after executing a statement. */
+ if (log_slow || thd->get_stmt_da()->is_eof())
thd->update_server_status();
+ if (thd->get_stmt_da()->is_eof())
thd->protocol->end_statement();
- }
query_cache_end_of_result(thd);
mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_STATUS,
- thd->get_stmt_da()->is_error() ?
- thd->get_stmt_da()->sql_errno() : 0,
- command_name[COM_QUERY].str);
+ thd->get_stmt_da()->is_error() ?
+ thd->get_stmt_da()->sql_errno() : 0,
+ command_name[COM_QUERY].str);
- if (!res && unlikely(thd->enable_slow_log))
+ if (log_slow)
log_slow_statement(thd);
}
else
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index e3f755be7ae..860a2c52ab5 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -8761,9 +8761,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
/* Update virtual fields*/
thd->abort_on_warning= FALSE;
if (vcol_table && vcol_table->vfield &&
- update_virtual_fields(thd, vcol_table,
- vcol_table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_WRITE))
+ update_virtual_fields(thd, vcol_table, VCOL_UPDATE_FOR_WRITE))
goto err;
thd->abort_on_warning= save_abort_on_warning;
thd->no_errors= save_no_errors;
@@ -8882,9 +8880,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields,
if (item_field && item_field->field && table && table->vfield)
{
DBUG_ASSERT(table == item_field->field->table);
- result= update_virtual_fields(thd, table,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_WRITE);
+ result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE);
}
}
}
@@ -8972,9 +8968,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
/* Update virtual fields*/
thd->abort_on_warning= FALSE;
if (table->vfield &&
- update_virtual_fields(thd, table,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_WRITE))
+ update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE))
goto err;
thd->abort_on_warning= abort_on_warning_saved;
DBUG_RETURN(thd->is_error());
@@ -9028,9 +9022,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, Field **ptr,
{
DBUG_ASSERT(table == (*ptr)->table);
if (table->vfield)
- result= update_virtual_fields(thd, table,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_WRITE);
+ result= update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE);
}
return result;
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index 80ac420937a..7befde1c1f3 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2007, 2013, Oracle and/or its affiliates.
- Copyright (c) 2008, 2014, SkySQL Ab.
+ Copyright (c) 2008, 2016, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -789,6 +789,7 @@ void update_global_user_stats(THD *thd, bool create_user, time_t now)
bool thd_init_client_charset(THD *thd, uint cs_number)
{
+ SV *gv=&global_system_variables;
CHARSET_INFO *cs;
/*
Use server character set and collation if
@@ -799,12 +800,10 @@ bool thd_init_client_charset(THD *thd, uint cs_number)
if (!opt_character_set_client_handshake ||
!(cs= get_charset(cs_number, MYF(0))))
{
- thd->variables.character_set_client=
- global_system_variables.character_set_client;
- thd->variables.collation_connection=
- global_system_variables.collation_connection;
- thd->variables.character_set_results=
- global_system_variables.character_set_results;
+ DBUG_ASSERT(is_supported_parser_charset(gv->character_set_client));
+ thd->variables.character_set_client= gv->character_set_client;
+ thd->variables.collation_connection= gv->collation_connection;
+ thd->variables.character_set_results= gv->character_set_results;
}
else
{
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 5b8896aa37f..c1011410970 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -572,9 +572,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
{
explain->tracker.on_record_read();
if (table->vfield)
- update_virtual_fields(thd, table,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_READ);
+ update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ);
thd->inc_examined_row_count(1);
// thd->is_error() is tested to disallow delete row on error
if (!select || select->skip_record(thd) > 0)
@@ -1343,4 +1341,3 @@ bool multi_delete::send_eof()
}
return 0;
}
-
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 19281f44771..bc0b88a7be7 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -4509,6 +4509,12 @@ bool st_select_lex::is_merged_child_of(st_select_lex *ancestor)
{
continue;
}
+
+ if (sl->master_unit()->derived &&
+ sl->master_unit()->derived->is_merged_derived())
+ {
+ continue;
+ }
all_merged= FALSE;
break;
}
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 630c1e0d21e..231d45b9016 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -1464,7 +1464,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
if (!(buffer=(uchar*) my_malloc(buff_length+1,MYF(MY_WME | MY_THREAD_SPECIFIC))))
- error=1; /* purecov: inspected */
+ error= 1; /* purecov: inspected */
else
{
end_of_buff=buffer+buff_length;
@@ -1724,7 +1724,7 @@ int READ_INFO::read_field()
** We come here if buffer is too small. Enlarge it and continue
*/
if (!(new_buffer=(uchar*) my_realloc((char*) buffer,buff_length+1+IO_SIZE,
- MYF(MY_WME | MY_THREAD_SPECIFIC))))
+ MYF(MY_WME | MY_THREAD_SPECIFIC))))
return (error=1);
to=new_buffer + (to-buffer);
buffer=new_buffer;
@@ -1960,15 +1960,7 @@ int READ_INFO::read_value(int delim, String *val)
for (chr= GET; my_tospace(chr) != delim && chr != my_b_EOF;)
{
#ifdef USE_MB
- uint ml= my_mbcharlen(read_charset, chr);
- if (ml == 0)
- {
- chr= my_b_EOF;
- val->length(0);
- return chr;
- }
-
- if (ml > 1)
+ if (my_mbcharlen(read_charset, chr) > 1)
{
DBUG_PRINT("read_xml",("multi byte"));
int i, ml= my_mbcharlen(read_charset, chr);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 4f630b68264..033e88aa6e1 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -5470,11 +5470,8 @@ end_with_restore_list:
}
case SQLCOM_SHOW_CREATE_TRIGGER:
{
- if (lex->spname->m_name.length > NAME_LEN)
- {
- my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
+ if (check_ident_length(&lex->spname->m_name))
goto error;
- }
#ifdef WITH_WSREP
if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd)) goto error;
@@ -9101,6 +9098,18 @@ bool check_string_char_length(LEX_STRING *str, uint err_msg,
return TRUE;
}
+
+bool check_ident_length(LEX_STRING *ident)
+{
+ if (check_string_char_length(ident, 0, NAME_CHAR_LEN, system_charset_info, 1))
+ {
+ my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str);
+ return 1;
+ }
+ return 0;
+}
+
+
C_MODE_START
/*
diff --git a/sql/sql_parse.h b/sql/sql_parse.h
index 7a67df55ac3..c50090a95cc 100644
--- a/sql/sql_parse.h
+++ b/sql/sql_parse.h
@@ -76,6 +76,7 @@ bool check_string_byte_length(LEX_STRING *str, uint err_msg,
bool check_string_char_length(LEX_STRING *str, uint err_msg,
uint max_char_length, CHARSET_INFO *cs,
bool no_error);
+bool check_ident_length(LEX_STRING *ident);
CHARSET_INFO* merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl);
CHARSET_INFO *find_bin_collation(CHARSET_INFO *cs);
bool check_host_name(LEX_STRING *str);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 3f06ec846d4..f299e863bf2 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -787,10 +787,15 @@ JOIN::prepare(Item ***rref_pointer_array,
if (mixed_implicit_grouping && tbl->table)
tbl->table->maybe_null= 1;
}
+
+ uint real_og_num= og_num;
+ if (skip_order_by &&
+ select_lex != select_lex->master_unit()->global_parameters())
+ real_og_num+= select_lex->order_list.elements;
if ((wild_num && setup_wild(thd, tables_list, fields_list, &all_fields,
wild_num)) ||
- select_lex->setup_ref_array(thd, og_num) ||
+ select_lex->setup_ref_array(thd, real_og_num) ||
setup_fields(thd, (*rref_pointer_array), fields_list, MARK_COLUMNS_READ,
&all_fields, 1) ||
setup_without_group(thd, (*rref_pointer_array), tables_list,
@@ -13071,9 +13076,12 @@ COND *Item_cond_and::build_equal_items(THD *thd,
COND_EQUAL cond_equal;
cond_equal.upper_levels= inherited;
+ if (check_stack_overrun(thd, STACK_MIN_SIZE, NULL))
+ return this; // Fatal error flag is set!
+
List<Item> eq_list;
List<Item> *cond_args= argument_list();
-
+
List_iterator<Item> li(*cond_args);
Item *item;
@@ -13083,7 +13091,7 @@ COND *Item_cond_and::build_equal_items(THD *thd,
that are subject to substitution by multiple equality items and
removing each such predicate from the conjunction after having
found/created a multiple equality whose inference the predicate is.
- */
+ */
while ((item= li++))
{
/*
@@ -17899,7 +17907,7 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
join->join_tab[join->top_join_tab_count - 1].next_select= end_select;
join_tab=join->join_tab+join->const_tables;
}
- join->send_records=0;
+ join->duplicate_rows= join->send_records=0;
if (join->table_count == join->const_tables)
{
/*
@@ -19438,7 +19446,12 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
int error;
/* result < 0 if row was not accepted and should not be counted */
if ((error= join->result->send_data(*join->fields)))
- DBUG_RETURN(error < 0 ? NESTED_LOOP_OK : NESTED_LOOP_ERROR);
+ {
+ if (error > 0)
+ DBUG_RETURN(NESTED_LOOP_ERROR);
+ // error < 0 => duplicate row
+ join->duplicate_rows++;
+ }
}
++join->send_records;
@@ -19580,7 +19593,7 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
if (error < 0)
{
/* Duplicate row, don't count */
- join->send_records--;
+ join->duplicate_rows++;
error= 0;
}
}
diff --git a/sql/sql_select.h b/sql/sql_select.h
index dfa96f1c81c..50168f6592c 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1071,6 +1071,10 @@ public:
(if sql_calc_found_rows is used, LIMIT is ignored)
*/
ha_rows select_limit;
+ /*
+ Number of duplicate rows found in UNION.
+ */
+ ha_rows duplicate_rows;
/**
Used to fetch no more than given amount of rows per one
fetch operation of server side cursor.
@@ -1347,7 +1351,7 @@ public:
sort_and_group= 0;
first_record= 0;
do_send_rows= 1;
- send_records= 0;
+ duplicate_rows= send_records= 0;
found_records= 0;
fetch_limit= HA_POS_ERROR;
join_examined_rows= 0;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 836e2bda70c..ebbec8c4c83 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3489,7 +3489,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
sql_field->pack_length= dup_field->pack_length;
sql_field->key_length= dup_field->key_length;
sql_field->decimals= dup_field->decimals;
- sql_field->create_length_to_internal_length();
sql_field->unireg_check= dup_field->unireg_check;
/*
We're making one field from two, the result field will have
@@ -3499,6 +3498,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
if (!(sql_field->flags & NOT_NULL_FLAG))
null_fields--;
sql_field->flags= dup_field->flags;
+ sql_field->create_length_to_internal_length();
sql_field->interval= dup_field->interval;
sql_field->vcol_info= dup_field->vcol_info;
sql_field->stored_in_db= dup_field->stored_in_db;
@@ -3625,12 +3625,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp);
DBUG_RETURN(TRUE);
}
- if (check_string_char_length(&key->name, 0, NAME_CHAR_LEN,
- system_charset_info, 1))
- {
- my_error(ER_TOO_LONG_IDENT, MYF(0), key->name.str);
+ if (check_ident_length(&key->name))
DBUG_RETURN(TRUE);
- }
key_iterator2.rewind ();
if (key->type != Key::FOREIGN_KEY)
{
@@ -4142,7 +4138,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
if (thd->variables.sql_mode & MODE_NO_ZERO_DATE &&
- !sql_field->def &&
+ !sql_field->def && !sql_field->vcol_info &&
is_timestamp_type(sql_field->sql_type) &&
(sql_field->flags & NOT_NULL_FLAG) &&
(type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD))
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 7a61279fc9c..7514d2af739 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -2298,6 +2298,9 @@ void Table_triggers_list::mark_fields_used(trg_event_type event)
bitmap_set_bit(trigger_table->read_set, trg_field->field_idx);
if (trg_field->get_settable_routine_parameter())
bitmap_set_bit(trigger_table->write_set, trg_field->field_idx);
+ if (trigger_table->field[trg_field->field_idx]->vcol_info)
+ trigger_table->mark_virtual_col(trigger_table->
+ field[trg_field->field_idx]);
}
}
}
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 0b294b5af8c..aa4859b6639 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -500,12 +500,8 @@ int mysql_create_function(THD *thd,udf_func *udf)
my_message(ER_UDF_NO_PATHS, ER_THD(thd, ER_UDF_NO_PATHS), MYF(0));
DBUG_RETURN(1);
}
- if (check_string_char_length(&udf->name, 0, NAME_CHAR_LEN,
- system_charset_info, 1))
- {
- my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name.str);
+ if (check_ident_length(&udf->name))
DBUG_RETURN(1);
- }
tables.init_one_table(STRING_WITH_LEN("mysql"), STRING_WITH_LEN("func"),
"func", TL_WRITE);
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 04aea060543..5ccc2384b84 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -640,9 +640,7 @@ int mysql_update(THD *thd,
{
explain->buf_tracker.on_record_read();
if (table->vfield)
- update_virtual_fields(thd, table,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_READ);
+ update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ);
thd->inc_examined_row_count(1);
if (!select || (error= select->skip_record(thd)) > 0)
{
@@ -758,9 +756,7 @@ int mysql_update(THD *thd,
{
explain->tracker.on_record_read();
if (table->vfield)
- update_virtual_fields(thd, table,
- table->triggers ? VCOL_UPDATE_ALL :
- VCOL_UPDATE_FOR_READ);
+ update_virtual_fields(thd, table, VCOL_UPDATE_FOR_READ);
thd->inc_examined_row_count(1);
if (!select || select->skip_record(thd) > 0)
{
@@ -2437,8 +2433,7 @@ int multi_update::do_updates()
if (table->default_field && (error= table->update_default_fields()))
goto err2;
if (table->vfield &&
- update_virtual_fields(thd, table,
- (table->triggers ? VCOL_UPDATE_ALL : VCOL_UPDATE_FOR_WRITE)))
+ update_virtual_fields(thd, table, VCOL_UPDATE_FOR_WRITE))
goto err2;
if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK)
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index e7db46d1c85..09dda0809de 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -5086,6 +5086,8 @@ part_name:
{
partition_info *part_info= Lex->part_info;
partition_element *p_elem= part_info->curr_part_elem;
+ if (check_ident_length(&$1))
+ MYSQL_YYABORT;
p_elem->partition_name= $1.str;
}
;
@@ -5369,7 +5371,11 @@ sub_part_definition:
sub_name:
ident_or_text
- { Lex->part_info->curr_part_elem->partition_name= $1.str; }
+ {
+ if (check_ident_length(&$1))
+ MYSQL_YYABORT;
+ Lex->part_info->curr_part_elem->partition_name= $1.str;
+ }
;
opt_part_options:
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index bb349e78724..1690bc40e33 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -639,6 +639,7 @@ static bool check_cs_client(sys_var *self, THD *thd, set_var *var)
if (check_charset_not_null(self, thd, var))
return true;
+ // Currently, UCS-2 cannot be used as a client character set
if (!is_supported_parser_charset((CHARSET_INFO *)(var->save_result.ptr)))
return true;
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic
index 334dd318643..cbc10c85351 100644
--- a/sql/sys_vars.ic
+++ b/sql/sys_vars.ic
@@ -1247,7 +1247,7 @@ public:
if (var->value->result_type() == STRING_RESULT)
{
- if (!(res=var->value->val_str(&str)))
+ if (!(res=var->value->val_str_ascii(&str)))
return true;
else
{
diff --git a/sql/table.cc b/sql/table.cc
index 686b3569a97..8f93f8ae286 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -6872,11 +6872,9 @@ bool is_simple_order(ORDER *order)
@details
The function computes the values of the virtual columns of the table and
stores them in the table record buffer.
- If vcol_update_mode is set to VCOL_UPDATE_ALL then all virtual column are
- computed. Otherwise, only fields from vcol_set are computed: all of them,
- if vcol_update_mode is set to VCOL_UPDATE_FOR_WRITE, and, only those with
- the stored_in_db flag set to false, if vcol_update_mode is equal to
- VCOL_UPDATE_FOR_READ.
+ Only fields from vcol_set are computed: all of them, if vcol_update_mode is
+ set to VCOL_UPDATE_FOR_WRITE, and, only those with the stored_in_db flag
+ set to false, if vcol_update_mode is equal to VCOL_UPDATE_FOR_READ.
@retval
0 Success
@@ -6898,9 +6896,8 @@ int update_virtual_fields(THD *thd, TABLE *table,
{
vfield= (*vfield_ptr);
DBUG_ASSERT(vfield->vcol_info && vfield->vcol_info->expr_item);
- if ((bitmap_is_set(table->vcol_set, vfield->field_index) &&
- (vcol_update_mode == VCOL_UPDATE_FOR_WRITE || !vfield->stored_in_db)) ||
- vcol_update_mode == VCOL_UPDATE_ALL)
+ if (bitmap_is_set(table->vcol_set, vfield->field_index) &&
+ (vcol_update_mode == VCOL_UPDATE_FOR_WRITE || !vfield->stored_in_db))
{
/* Compute the actual value of the virtual fields */
error= vfield->vcol_info->expr_item->save_in_field(vfield, 0);
diff --git a/sql/table.h b/sql/table.h
index 093c357e575..876f496a312 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -317,8 +317,7 @@ enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
enum enum_vcol_update_mode
{
VCOL_UPDATE_FOR_READ= 0,
- VCOL_UPDATE_FOR_WRITE,
- VCOL_UPDATE_ALL
+ VCOL_UPDATE_FOR_WRITE
};
class Filesort_info