diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-06-18 12:40:53 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-06-18 15:43:59 +0300 |
commit | 0121d5a790983c08dabedc66e70f862e47f7c8c7 (patch) | |
tree | 5a3912526fd63ed6c1886240724c9116a6ac7577 /sql | |
parent | 63027a5763b2b9550979366f9e7488b2d9328cc0 (diff) | |
parent | c55de8d40bba29503773a6a56d6f13f19ca7e339 (diff) | |
download | mariadb-git-0121d5a790983c08dabedc66e70f862e47f7c8c7.tar.gz |
Merge 10.2 into 10.3
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 10 | ||||
-rw-r--r-- | sql/field.h | 17 | ||||
-rw-r--r-- | sql/item.cc | 11 | ||||
-rw-r--r-- | sql/item_sum.cc | 4 | ||||
-rw-r--r-- | sql/item_windowfunc.cc | 6 | ||||
-rw-r--r-- | sql/sp_rcontext.cc | 6 | ||||
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.h | 5 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
9 files changed, 52 insertions, 10 deletions
diff --git a/sql/field.cc b/sql/field.cc index 6fbe92e76fe..88b23028d09 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -3347,6 +3347,16 @@ longlong Field_new_decimal::val_int(void) } +ulonglong Field_new_decimal::val_uint(void) +{ + ASSERT_COLUMN_MARKED_FOR_READ; + longlong i; + my_decimal decimal_value; + my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), true, &i); + return i; +} + + my_decimal* Field_new_decimal::val_decimal(my_decimal *decimal_value) { ASSERT_COLUMN_MARKED_FOR_READ; diff --git a/sql/field.h b/sql/field.h index 2079c90037a..69e53087478 100644 --- a/sql/field.h +++ b/sql/field.h @@ -825,9 +825,14 @@ public: } virtual double val_real(void)=0; virtual longlong val_int(void)=0; + /* + Get ulonglong representation. + Negative values are truncated to 0. + */ virtual ulonglong val_uint(void) { - return (ulonglong) val_int(); + longlong nr= val_int(); + return nr < 0 ? 0 : (ulonglong) nr; } virtual bool val_bool(void)= 0; virtual my_decimal *val_decimal(my_decimal *); @@ -1671,6 +1676,8 @@ public: bool eq_def(const Field *field) const; Copy_func *get_copy_func(const Field *from) const { + if (unsigned_flag && from->cmp_type() == DECIMAL_RESULT) + return do_field_decimal; return do_field_int; } int save_in_field(Field *to) @@ -1965,6 +1972,7 @@ public: int store_decimal(const my_decimal *); double val_real(void); longlong val_int(void); + ulonglong val_uint(void); my_decimal *val_decimal(my_decimal *); String *val_str(String*, String *); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); @@ -2011,6 +2019,11 @@ public: int store_decimal(const my_decimal *); my_decimal *val_decimal(my_decimal *); bool val_bool() { return val_int() != 0; } + ulonglong val_uint() + { + longlong nr= val_int(); + return nr < 0 && !unsigned_flag ? 0 : (ulonglong) nr; + } int store_time_dec(const MYSQL_TIME *ltime, uint dec); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); virtual const Type_limits_int *type_limits_int() const= 0; @@ -4047,6 +4060,8 @@ public: } Copy_func *get_copy_func(const Field *from) const { + if (from->cmp_type() == DECIMAL_RESULT) + return do_field_decimal; return do_field_int; } int save_in_field(Field *to) { return to->store(val_int(), true); } diff --git a/sql/item.cc b/sql/item.cc index dac68d1a4c7..65a9fdf46c5 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5585,9 +5585,11 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) in the SELECT clause of Q. - Search for a column named col_ref_i [in table T_j] in the GROUP BY clause of Q. - - If found different columns with the same name in GROUP BY and SELECT - - issue a warning and return the GROUP BY column, - - otherwise + - If found different columns with the same name in GROUP BY and SELECT: + - if the condition that uses this column name is pushed down into + the HAVING clause return the SELECT column + - else issue a warning and return the GROUP BY column. + - Otherwise - if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error - else return the found SELECT column. @@ -5626,7 +5628,8 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) /* Check if the fields found in SELECT and GROUP BY are the same field. */ if (group_by_ref && (select_ref != not_found_item) && - !((*group_by_ref)->eq(*select_ref, 0))) + !((*group_by_ref)->eq(*select_ref, 0)) && + (!select->having_fix_field_for_pushed_cond)) { ambiguous_fields= TRUE; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, diff --git a/sql/item_sum.cc b/sql/item_sum.cc index a47f3ad941d..0e506cc26f2 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -72,14 +72,14 @@ size_t Item_sum::ram_limitation(THD *thd) bool Item_sum::init_sum_func_check(THD *thd) { SELECT_LEX *curr_sel= thd->lex->current_select; - if (!curr_sel->name_visibility_map) + if (curr_sel && !curr_sel->name_visibility_map) { for (SELECT_LEX *sl= curr_sel; sl; sl= sl->context.outer_select()) { curr_sel->name_visibility_map|= (1 << sl-> nest_level); } } - if (!(thd->lex->allow_sum_func & curr_sel->name_visibility_map)) + if (!curr_sel || !(thd->lex->allow_sum_func & curr_sel->name_visibility_map)) { my_message(ER_INVALID_GROUP_FUNC_USE, ER_THD(thd, ER_INVALID_GROUP_FUNC_USE), MYF(0)); diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index a7f8ef09f08..66c4f5be665 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -86,9 +86,9 @@ Item_window_func::fix_fields(THD *thd, Item **ref) { DBUG_ASSERT(fixed == 0); - enum_parsing_place place= thd->lex->current_select->context_analysis_place; - - if (!(place == SELECT_LIST || place == IN_ORDER_BY)) + if (!thd->lex->current_select || + (thd->lex->current_select->context_analysis_place != SELECT_LIST && + thd->lex->current_select->context_analysis_place != IN_ORDER_BY)) { my_error(ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION, MYF(0)); return true; diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 6166d1d9615..997f2abe053 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -851,9 +851,15 @@ int sp_cursor::fetch(THD *thd, List<sp_variable> *vars, bool error_on_no_data) result.set_spvar_list(vars); + DBUG_ASSERT(!thd->is_error()); + /* Attempt to fetch one row */ if (server_side_cursor->is_open()) + { server_side_cursor->fetch(1); + if (thd->is_error()) + return -1; // e.g. data type conversion failed + } /* If the cursor was pointing after the last row, the fetch will diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 39cf4cd1e46..cb6edc4a788 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2255,6 +2255,7 @@ void st_select_lex::init_query() cond_pushed_into_where= cond_pushed_into_having= 0; olap= UNSPECIFIED_OLAP_TYPE; having_fix_field= 0; + having_fix_field_for_pushed_cond= 0; context.select_lex= this; context.init(); /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 77e477b7cb4..8ea9a551a65 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1064,6 +1064,11 @@ public: bool automatic_brackets; /* dummy select for INTERSECT precedence */ /* TRUE when having fix field called in processing of this SELECT */ bool having_fix_field; + /* + TRUE when fix field is called for a new condition pushed into the + HAVING clause of this SELECT + */ + bool having_fix_field_for_pushed_cond; /* List of references to fields referenced from inner selects */ List<Item_outer_ref> inner_refs_list; /* Number of Item_sum-derived objects in this SELECT */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 52041cca0d6..54bb877ea2f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1655,9 +1655,11 @@ JOIN::optimize_inner() if (having) { select_lex->having_fix_field= 1; + select_lex->having_fix_field_for_pushed_cond= 1; if (having->fix_fields(thd, &having)) DBUG_RETURN(1); select_lex->having_fix_field= 0; + select_lex->having_fix_field_for_pushed_cond= 0; } } |