diff options
-rw-r--r-- | mysql-test/r/func_group.result | 9 | ||||
-rw-r--r-- | mysql-test/t/func_group.test | 13 | ||||
-rw-r--r-- | sql/item.cc | 5 | ||||
-rw-r--r-- | sql/item_windowfunc.cc | 2 | ||||
-rw-r--r-- | sql/sql_lex.h | 1 | ||||
-rw-r--r-- | sql/sql_select.cc | 33 |
6 files changed, 44 insertions, 19 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index cb97ea298a0..c4e991e8cbe 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -2447,3 +2447,12 @@ DROP TABLE t1; # # End of 10.1 tests # +# +# MDEV-13064: assertion `n < m_size' fails in Item::split_sum_func2() +# +create table t1 (i int) engine=MyISAM; +insert into t1 value (1),(2); +select count(*)+sleep(0) from t1; +count(*)+sleep(0) +2 +drop table t1; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 1e75099a1fe..8bbc9e6a040 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -1691,3 +1691,16 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # MDEV-13064: assertion `n < m_size' fails in Item::split_sum_func2() +--echo # + +create table t1 (i int) engine=MyISAM; +insert into t1 value (1),(2); + +select count(*)+sleep(0) from t1; + +drop table t1; + + diff --git a/sql/item.cc b/sql/item.cc index 8db5cfc6442..df615b5ace9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -490,8 +490,7 @@ Item::Item(THD *thd): command => we should check thd->lex->current_select on zero (thd->lex can be uninitialised) */ - if (thd->lex->current_select && - thd->stmt_arena->is_stmt_prepare_or_first_sp_execute()) + if (thd->lex->current_select) { enum_parsing_place place= thd->lex->current_select->parsing_place; @@ -5513,7 +5512,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) SELECT_LEX *select= thd->lex->current_select; thd->change_item_tree(reference, - select->parsing_place == IN_GROUP_BY && + select->context_analysis_place == IN_GROUP_BY && alias_name_used ? *rf->ref : rf); /* diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 59a22c63ed5..27b007201c5 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -71,7 +71,7 @@ Item_window_func::fix_fields(THD *thd, Item **ref) { DBUG_ASSERT(fixed == 0); - enum_parsing_place place= thd->lex->current_select->parsing_place; + enum_parsing_place place= thd->lex->current_select->context_analysis_place; if (!(place == SELECT_LIST || place == IN_ORDER_BY)) { diff --git a/sql/sql_lex.h b/sql/sql_lex.h index face3bcc378..0c55ffc5892 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -855,6 +855,7 @@ public: /* reserved for exists 2 in */ uint select_n_reserved; enum_parsing_place parsing_place; /* where we are parsing expression */ + enum_parsing_place context_analysis_place; /* where we are in prepare */ bool with_sum_func; /* sum function indicator */ ulong table_join_options; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4c64cf29467..6c56f0115ca 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -648,17 +648,15 @@ setup_without_group(THD *thd, Ref_ptr_array ref_pointer_array, thd->lex->allow_sum_func|= (nesting_map)1 << select->nest_level; - save_place= thd->lex->current_select->parsing_place; - thd->lex->current_select->parsing_place= IN_ORDER_BY; + save_place= thd->lex->current_select->context_analysis_place; + thd->lex->current_select->context_analysis_place= IN_ORDER_BY; res= res || setup_order(thd, ref_pointer_array, tables, fields, all_fields, order); - thd->lex->current_select->parsing_place= save_place; - thd->lex->allow_sum_func&= ~((nesting_map)1 << select->nest_level); - save_place= thd->lex->current_select->parsing_place; - thd->lex->current_select->parsing_place= IN_GROUP_BY; + thd->lex->allow_sum_func&= ~((nesting_map)1 << select->nest_level); + thd->lex->current_select->context_analysis_place= IN_GROUP_BY; res= res || setup_group(thd, ref_pointer_array, tables, fields, all_fields, group, hidden_group_fields); - thd->lex->current_select->parsing_place= save_place; + thd->lex->current_select->context_analysis_place= save_place; thd->lex->allow_sum_func|= (nesting_map)1 << select->nest_level; res= res || setup_windows(thd, ref_pointer_array, tables, fields, all_fields, win_specs, win_funcs); @@ -712,6 +710,7 @@ JOIN::prepare(TABLE_LIST *tables_init, if (select_lex->handle_derived(thd->lex, DT_PREPARE)) DBUG_RETURN(1); + thd->lex->current_select->context_analysis_place= NO_MATTER; thd->lex->current_select->is_item_list_lookup= 1; /* If we have already executed SELECT, then it have not sense to prevent @@ -801,12 +800,13 @@ JOIN::prepare(TABLE_LIST *tables_init, ref_ptrs= ref_ptr_array_slice(0); - enum_parsing_place save_place= thd->lex->current_select->parsing_place; - thd->lex->current_select->parsing_place= SELECT_LIST; + enum_parsing_place save_place= + thd->lex->current_select->context_analysis_place; + thd->lex->current_select->context_analysis_place= SELECT_LIST; if (setup_fields(thd, ref_ptrs, fields_list, MARK_COLUMNS_READ, &all_fields, 1)) DBUG_RETURN(-1); - thd->lex->current_select->parsing_place= save_place; + thd->lex->current_select->context_analysis_place= save_place; if (setup_without_group(thd, ref_ptrs, tables_list, select_lex->leaf_tables, fields_list, @@ -22235,14 +22235,16 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, List<Item> &fields, List<Item> &all_fields, ORDER *order, bool from_window_spec) { - enum_parsing_place parsing_place= thd->lex->current_select->parsing_place; + enum_parsing_place context_analysis_place= + thd->lex->current_select->context_analysis_place; thd->where="order clause"; for (; order; order=order->next) { if (find_order_in_list(thd, ref_pointer_array, tables, order, fields, all_fields, FALSE, from_window_spec)) return 1; - if ((*order->item)->with_window_func && parsing_place != IN_ORDER_BY) + if ((*order->item)->with_window_func && + context_analysis_place != IN_ORDER_BY) { my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0)); return 1; @@ -22284,7 +22286,8 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, List<Item> &fields, List<Item> &all_fields, ORDER *order, bool *hidden_group_fields, bool from_window_spec) { - enum_parsing_place parsing_place= thd->lex->current_select->parsing_place; + enum_parsing_place context_analysis_place= + thd->lex->current_select->context_analysis_place; *hidden_group_fields=0; ORDER *ord; @@ -22300,14 +22303,14 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables, all_fields, TRUE, from_window_spec)) return 1; (*ord->item)->marker= UNDEF_POS; /* Mark found */ - if ((*ord->item)->with_sum_func && parsing_place == IN_GROUP_BY) + if ((*ord->item)->with_sum_func && context_analysis_place == IN_GROUP_BY) { my_error(ER_WRONG_GROUP_FIELD, MYF(0), (*ord->item)->full_name()); return 1; } if ((*ord->item)->with_window_func) { - if (parsing_place == IN_GROUP_BY) + if (context_analysis_place == IN_GROUP_BY) my_error(ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION, MYF(0)); else my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0)); |