Commit cf4a6abe authored by Igor Babaev's avatar Igor Babaev

Fixed the bug mdev-13064.

This is another attempt to fix the bug mdev-12992.
This patch introduces st_select_lex::context_analysis_place for
the place in SELECT where context analysis is currently performed.
It's similar to st_select_lex::parsing_place, but it is used at
the preparation stage.
parent f73507e6
......@@ -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;
......@@ -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;
......@@ -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);
/*
......
......@@ -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))
{
......
......@@ -855,6 +855,7 @@ class st_select_lex: public st_select_lex_node
/* 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;
......
......@@ -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));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment