summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-12-09 16:33:48 +0100
committerSergei Golubchik <serg@mariadb.org>2016-12-09 16:33:48 +0100
commit3e8155c637096da8fd019c42b78746be2bf89944 (patch)
tree7df7880c789de7c32fdd76e862170322afe6117c /sql
parent106664f8e86d694a9898c3e564bb72290f221bd6 (diff)
parent03dabfa84d6bc9a8197c8d9fbe80f2a7f6a5b6ac (diff)
downloadmariadb-git-3e8155c637096da8fd019c42b78746be2bf89944.tar.gz
Merge branch '5.5' into 10.0
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc74
-rw-r--r--sql/item.h2
-rw-r--r--sql/item_func.cc3
-rw-r--r--sql/item_subselect.cc22
-rw-r--r--sql/log.cc17
-rw-r--r--sql/mysqld.cc6
-rw-r--r--sql/rpl_filter.cc3
-rw-r--r--sql/sql_derived.cc2
-rw-r--r--sql/sql_lex.cc22
-rw-r--r--sql/sql_table.cc2
10 files changed, 107 insertions, 46 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 21c8b3f701e..ecdb3a94f7f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -4498,8 +4498,6 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
const char *field_name;
ORDER *found_group= NULL;
int found_match_degree= 0;
- Item_ident *cur_field;
- int cur_match_degree= 0;
char name_buff[SAFE_NAME_LEN+1];
if (find_item->type() == Item::FIELD_ITEM ||
@@ -4524,54 +4522,70 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
{
- if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
+ int cur_match_degree= 0;
+
+ /* SELECT list element with explicit alias */
+ if ((*(cur_group->item))->name &&
+ !(*(cur_group->item))->is_autogenerated_name &&
+ !my_strcasecmp(system_charset_info,
+ (*(cur_group->item))->name, field_name))
+ {
+ ++cur_match_degree;
+ }
+ /* Reference on the field or view/derived field. */
+ else if ((*(cur_group->item))->type() == Item::FIELD_ITEM ||
+ (*(cur_group->item))->type() == Item::REF_ITEM )
{
- cur_field= (Item_ident*) *cur_group->item;
- cur_match_degree= 0;
-
- DBUG_ASSERT(cur_field->field_name != 0);
+ Item_ident *cur_field= (Item_ident*) *cur_group->item;
+ const char *l_db_name= cur_field->db_name;
+ const char *l_table_name= cur_field->table_name;
+ const char *l_field_name= cur_field->field_name;
+
+ DBUG_ASSERT(l_field_name != 0);
if (!my_strcasecmp(system_charset_info,
- cur_field->field_name, field_name))
+ l_field_name, field_name))
++cur_match_degree;
else
continue;
- if (cur_field->table_name && table_name)
+ if (l_table_name && table_name)
{
/* If field_name is qualified by a table name. */
- if (my_strcasecmp(table_alias_charset, cur_field->table_name, table_name))
+ if (my_strcasecmp(table_alias_charset, l_table_name, table_name))
/* Same field names, different tables. */
return NULL;
++cur_match_degree;
- if (cur_field->db_name && db_name)
+ if (l_db_name && db_name)
{
/* If field_name is also qualified by a database name. */
- if (strcmp(cur_field->db_name, db_name))
+ if (strcmp(l_db_name, db_name))
/* Same field names, different databases. */
return NULL;
++cur_match_degree;
}
}
+ }
+ else
+ continue;
- if (cur_match_degree > found_match_degree)
- {
- found_match_degree= cur_match_degree;
- found_group= cur_group;
- }
- else if (found_group && (cur_match_degree == found_match_degree) &&
- ! (*(found_group->item))->eq(cur_field, 0))
- {
- /*
- If the current resolve candidate matches equally well as the current
- best match, they must reference the same column, otherwise the field
- is ambiguous.
- */
- my_error(ER_NON_UNIQ_ERROR, MYF(0),
- find_item->full_name(), current_thd->where);
- return NULL;
- }
+ if (cur_match_degree > found_match_degree)
+ {
+ found_match_degree= cur_match_degree;
+ found_group= cur_group;
+ }
+ else if (found_group && (cur_match_degree == found_match_degree) &&
+ !(*(found_group->item))->eq((*(cur_group->item)), 0))
+ {
+ /*
+ If the current resolve candidate matches equally well as the current
+ best match, they must reference the same column, otherwise the field
+ is ambiguous.
+ */
+ my_error(ER_NON_UNIQ_ERROR, MYF(0),
+ find_item->full_name(), current_thd->where);
+ return NULL;
}
}
@@ -5675,6 +5689,7 @@ String *Item::check_well_formed_result(String *str, bool send_error)
/* Check whether we got a well-formed string */
CHARSET_INFO *cs= str->charset();
uint wlen= str->well_formed_length();
+ null_value= false;
if (wlen < str->length())
{
THD *thd= current_thd;
@@ -9932,4 +9947,3 @@ const char *dbug_print_item(Item *item)
}
#endif /*DBUG_OFF*/
-
diff --git a/sql/item.h b/sql/item.h
index 64870ca15a8..2f8607d8fad 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -3713,7 +3713,7 @@ public:
if (result_type() == ROW_RESULT)
orig_item->bring_value();
}
- virtual bool is_expensive() { return orig_item->is_expensive(); }
+ bool is_expensive() { return orig_item->is_expensive(); }
bool is_expensive_processor(uchar *arg)
{ return orig_item->is_expensive_processor(arg); }
bool check_vcol_func_processor(uchar *arg)
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 9ee1ba4c7a7..c87d4587f4d 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -6653,7 +6653,8 @@ Item_func_sp::init_result_field(THD *thd)
bool Item_func_sp::is_expensive()
{
- return !(m_sp->m_chistics->detistic);
+ return !m_sp->m_chistics->detistic ||
+ current_thd->locked_tables_mode < LTM_LOCK_TABLES;
}
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index e70922bb5d3..cf09b1801cf 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -222,6 +222,7 @@ bool
Item_subselect::select_transformer(JOIN *join)
{
DBUG_ENTER("Item_subselect::select_transformer");
+ DBUG_ASSERT(thd == join->thd);
DBUG_RETURN(false);
}
@@ -592,7 +593,7 @@ bool Item_subselect::is_expensive()
examined_rows+= cur_join->get_examined_rows();
}
-
+ // here we are sure that subquery is optimized so thd is set
return (examined_rows > thd->variables.expensive_subquery_limit);
}
@@ -656,6 +657,7 @@ bool Item_subselect::exec()
subselect_engine *org_engine= engine;
DBUG_ENTER("Item_subselect::exec");
+ DBUG_ASSERT(fixed);
/*
Do not execute subselect in case of a fatal error
@@ -704,6 +706,7 @@ int Item_in_subselect::optimize(double *out_rows, double *cost)
{
int res;
DBUG_ENTER("Item_in_subselect::optimize");
+ DBUG_ASSERT(fixed);
SELECT_LEX *save_select= thd->lex->current_select;
JOIN *join= unit->first_select()->join;
@@ -818,6 +821,7 @@ bool Item_in_subselect::expr_cache_is_needed(THD *thd)
bool Item_in_subselect::exec()
{
DBUG_ENTER("Item_in_subselect::exec");
+ DBUG_ASSERT(fixed);
/*
Initialize the cache of the left predicate operand. This has to be done as
late as now, because Cached_item directly contains a resolved field (not
@@ -872,6 +876,7 @@ table_map Item_subselect::used_tables() const
bool Item_subselect::const_item() const
{
+ DBUG_ASSERT(thd);
return (thd->lex->context_analysis_only ?
FALSE :
forced_const || const_item_cache);
@@ -1065,10 +1070,11 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
DBUG_ENTER("Item_singlerow_subselect::select_transformer");
if (changed)
DBUG_RETURN(false);
+ DBUG_ASSERT(join->thd == thd);
SELECT_LEX *select_lex= join->select_lex;
Query_arena *arena= thd->stmt_arena;
-
+
if (!select_lex->master_unit()->is_union() &&
!select_lex->table_list.elements &&
select_lex->item_list.elements == 1 &&
@@ -1731,6 +1737,7 @@ Item_in_subselect::single_value_transformer(JOIN *join)
{
SELECT_LEX *select_lex= join->select_lex;
DBUG_ENTER("Item_in_subselect::single_value_transformer");
+ DBUG_ASSERT(thd == join->thd);
/*
Check that the right part of the subselect contains no more than one
@@ -1842,9 +1849,9 @@ bool Item_allany_subselect::transform_into_max_min(JOIN *join)
if (!test_strategy(SUBS_MAXMIN_INJECTED | SUBS_MAXMIN_ENGINE))
DBUG_RETURN(false);
Item **place= optimizer->arguments() + 1;
- THD *thd= join->thd;
SELECT_LEX *select_lex= join->select_lex;
Item *subs;
+ DBUG_ASSERT(thd == join->thd);
/*
*/
@@ -1951,6 +1958,7 @@ bool Item_allany_subselect::transform_into_max_min(JOIN *join)
bool Item_in_subselect::fix_having(Item *having, SELECT_LEX *select_lex)
{
bool fix_res= 0;
+ DBUG_ASSERT(thd);
if (!having->fixed)
{
select_lex->having_fix_field= 1;
@@ -2013,6 +2021,7 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
Item **having_item)
{
SELECT_LEX *select_lex= join->select_lex;
+ DBUG_ASSERT(thd == join->thd);
/*
The non-transformed HAVING clause of 'join' may be stored in two ways
during JOIN::optimize: this->tmp_having= this->having; this->having= 0;
@@ -2149,6 +2158,7 @@ Item_in_subselect::row_value_transformer(JOIN *join)
uint cols_num= left_expr->cols();
DBUG_ENTER("Item_in_subselect::row_value_transformer");
+ DBUG_ASSERT(thd == join->thd);
// psergey: duplicated_subselect_card_check
if (select_lex->item_list.elements != cols_num)
@@ -2260,6 +2270,7 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
!select_lex->table_list.elements);
DBUG_ENTER("Item_in_subselect::create_row_in_to_exists_cond");
+ DBUG_ASSERT(thd == join->thd);
*where_item= NULL;
*having_item= NULL;
@@ -2492,6 +2503,7 @@ bool Item_in_subselect::inject_in_to_exists_cond(JOIN *join_arg)
Item *having_item= join_arg->in_to_exists_having;
DBUG_ENTER("Item_in_subselect::inject_in_to_exists_cond");
+ DBUG_ASSERT(thd == join_arg->thd);
if (where_item)
{
@@ -3007,6 +3019,7 @@ Item_in_subselect::select_in_like_transformer(JOIN *join)
bool result;
DBUG_ENTER("Item_in_subselect::select_in_like_transformer");
+ DBUG_ASSERT(thd == join->thd);
/*
IN/SOME/ALL/ANY subqueries aren't support LIMIT clause. Without it
@@ -3217,6 +3230,7 @@ bool Item_in_subselect::setup_mat_engine()
subselect_single_select_engine *select_engine;
DBUG_ENTER("Item_in_subselect::setup_mat_engine");
+ DBUG_ASSERT(thd);
/*
The select_engine (that executes transformed IN=>EXISTS subselects) is
@@ -3255,6 +3269,7 @@ bool Item_in_subselect::setup_mat_engine()
bool Item_in_subselect::init_left_expr_cache()
{
JOIN *outer_join;
+ DBUG_ASSERT(thd);
outer_join= unit->outer_select()->join;
/*
@@ -3281,6 +3296,7 @@ bool Item_in_subselect::init_left_expr_cache()
bool Item_in_subselect::init_cond_guards()
{
+ DBUG_ASSERT(thd);
uint cols_num= left_expr->cols();
if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
{
diff --git a/sql/log.cc b/sql/log.cc
index 8813f56bbd8..cd215822d44 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -289,6 +289,9 @@ public:
{
compute_statistics();
truncate(0);
+ if(cache_log.file != -1)
+ my_chsize(cache_log.file, 0, 0, MYF(MY_WME));
+
changes_to_non_trans_temp_table_flag= FALSE;
incident= FALSE;
before_stmt_pos= MY_OFF_T_UNDEF;
@@ -3275,7 +3278,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name,
if (init_and_set_log_file_name(log_name, new_name, log_type_arg,
io_cache_type_arg))
{
- sql_print_error("MSYQL_BIN_LOG::open failed to generate new file name.");
+ sql_print_error("MYSQL_BIN_LOG::open failed to generate new file name.");
DBUG_RETURN(1);
}
@@ -3302,7 +3305,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name,
}
});
- sql_print_error("MSYQL_BIN_LOG::open failed to sync the index file.");
+ sql_print_error("MYSQL_BIN_LOG::open failed to sync the index file.");
DBUG_RETURN(1);
}
DBUG_EXECUTE_IF("crash_create_non_critical_before_update_index", DBUG_SUICIDE(););
@@ -4324,14 +4327,14 @@ int MYSQL_BIN_LOG::purge_logs(const char *to_log,
if ((error= sync_purge_index_file()))
{
- sql_print_error("MSYQL_BIN_LOG::purge_logs failed to flush register file.");
+ sql_print_error("MYSQL_BIN_LOG::purge_logs failed to flush register file.");
goto err;
}
/* We know how many files to delete. Update index file. */
if ((error=update_log_index(&log_info, need_update_threads)))
{
- sql_print_error("MSYQL_BIN_LOG::purge_logs failed to update the index file");
+ sql_print_error("MYSQL_BIN_LOG::purge_logs failed to update the index file");
goto err;
}
@@ -4341,7 +4344,7 @@ err:
/* Read each entry from purge_index_file and delete the file. */
if (is_inited_purge_index_file() &&
(error= purge_index_entry(thd, reclaimed_space, FALSE)))
- sql_print_error("MSYQL_BIN_LOG::purge_logs failed to process registered files"
+ sql_print_error("MYSQL_BIN_LOG::purge_logs failed to process registered files"
" that would be purged.");
close_purge_index_file();
@@ -4458,7 +4461,7 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *reclaimed_space,
if ((error=reinit_io_cache(&purge_index_file, READ_CACHE, 0, 0, 0)))
{
- sql_print_error("MSYQL_BIN_LOG::purge_index_entry failed to reinit register file "
+ sql_print_error("MYSQL_BIN_LOG::purge_index_entry failed to reinit register file "
"for read");
goto err;
}
@@ -4473,7 +4476,7 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *reclaimed_space,
if (purge_index_file.error)
{
error= purge_index_file.error;
- sql_print_error("MSYQL_BIN_LOG::purge_index_entry error %d reading from "
+ sql_print_error("MYSQL_BIN_LOG::purge_index_entry error %d reading from "
"register file.", error);
goto err;
}
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 00d459d5f91..fda4fab9d26 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5440,6 +5440,12 @@ int mysqld_main(int argc, char **argv)
setbuf(stderr, NULL);
FreeConsole(); // Remove window
}
+
+ if (fileno(stdin) >= 0)
+ {
+ /* Disable CRLF translation (MDEV-9409). */
+ _setmode(fileno(stdin), O_BINARY);
+ }
#endif
/*
diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc
index 28859c2eb85..b992a71e52e 100644
--- a/sql/rpl_filter.cc
+++ b/sql/rpl_filter.cc
@@ -280,6 +280,9 @@ Rpl_filter::parse_filter_rule(const char* spec, Add_filter add)
int status= 0;
char *arg, *ptr, *pstr;
+ if (!spec)
+ return false;
+
if (! (ptr= my_strdup(spec, MYF(MY_WME))))
return true;
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index fdc615d0fae..f2674cb8dab 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -663,6 +663,8 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
unit->derived= derived;
+ derived->fill_me= FALSE;
+
if (!(derived->derived_result= new select_union))
DBUG_RETURN(TRUE); // out of memory
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index db54dd6a8b0..9d5f4cfcb5b 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1101,7 +1101,7 @@ static int lex_one_token(YYSTYPE *yylval, THD *thd)
state= (enum my_lex_states) state_map[c];
break;
case MY_LEX_ESCAPE:
- if (lip->yyGet() == 'N')
+ if (!lip->eof() && lip->yyGet() == 'N')
{ // Allow \N as shortcut for NULL
yylval->lex_str.str=(char*) "\\N";
yylval->lex_str.length=2;
@@ -3482,12 +3482,28 @@ bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
bool st_select_lex::optimize_unflattened_subqueries(bool const_only)
{
- for (SELECT_LEX_UNIT *un= first_inner_unit(); un; un= un->next_unit())
+ SELECT_LEX_UNIT *next_unit= NULL;
+ for (SELECT_LEX_UNIT *un= first_inner_unit();
+ un;
+ un= next_unit ? next_unit : un->next_unit())
{
Item_subselect *subquery_predicate= un->item;
-
+ next_unit= NULL;
+
if (subquery_predicate)
{
+ if (!subquery_predicate->fixed)
+ {
+ /*
+ This subquery was excluded as part of some expression so it is
+ invisible from all prepared expression.
+ */
+ next_unit= un->next_unit();
+ un->exclude_level();
+ if (next_unit)
+ continue;
+ break;
+ }
if (subquery_predicate->substype() == Item_subselect::IN_SUBS)
{
Item_in_subselect *in_subs= (Item_in_subselect*) subquery_predicate;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 3b104b55de2..62dff1b5928 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -666,7 +666,7 @@ static bool read_ddl_log_file_entry(uint entry_no)
bool error= FALSE;
File file_id= global_ddl_log.file_id;
uchar *file_entry_buf= (uchar*)global_ddl_log.file_entry_buf;
- uint io_size= global_ddl_log.io_size;
+ size_t io_size= global_ddl_log.io_size;
DBUG_ENTER("read_ddl_log_file_entry");
mysql_mutex_assert_owner(&LOCK_gdl);