Commit 4d2a58f8 authored by evgen@moonbone.local's avatar evgen@moonbone.local

Manual merge of bug fix #7672

parents 37aa6efd fb0074a6
......@@ -2737,6 +2737,16 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
1 SIMPLE t2 ref a a 23 test.t1.a 2
DROP TABLE t1, t2;
CREATE TABLE t1 (a INT, b INT);
(SELECT a, b AS c FROM t1) ORDER BY c+1;
a c
(SELECT a, b AS c FROM t1) ORDER BY b+1;
a c
SELECT a, b AS c FROM t1 ORDER BY c+1;
a c
SELECT a, b AS c FROM t1 ORDER BY b+1;
a c
drop table t1;
create table t1 (a int, b int);
create table t2 like t1;
select t1.a from (t1 inner join t2 on t1.a=t2.a) where t2.a=1;
......
......@@ -2069,6 +2069,7 @@ AND FK_firma_id = 2;
drop table t1;
#
#
# Test for Bug#8009, SELECT failed on bigint unsigned when using HEX
#
......@@ -2181,6 +2182,16 @@ select found_rows();
DROP TABLE t1;
#
# Bug 7672 Unknown column error in order clause
#
CREATE TABLE t1 (a INT, b INT);
(SELECT a, b AS c FROM t1) ORDER BY c+1;
(SELECT a, b AS c FROM t1) ORDER BY b+1;
SELECT a, b AS c FROM t1 ORDER BY c+1;
SELECT a, b AS c FROM t1 ORDER BY b+1;
drop table t1;
#
# Bug #13356 assertion failed in resolve_const_item()
#
......
......@@ -3213,6 +3213,22 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
TRUE)) ==
not_found_field)
{
/* Look up in current select's item_list to find aliased fields */
if (thd->lex->current_select->is_item_list_lookup)
{
uint counter;
bool not_used;
Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
&counter, REPORT_EXCEPT_NOT_FOUND,
&not_used);
if (res != not_found_item && (*res)->type() == Item::FIELD_ITEM)
{
set_field((*((Item_field**)res))->field);
return 0;
}
}
/*
If there are outer contexts (outer selects, but current select is
not derived table or view) try to resolve this reference in the
......
......@@ -1133,6 +1133,7 @@ void st_select_lex::init_query()
ref_pointer_array= 0;
select_n_having_items= 0;
subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0;
first_execution= 1;
first_cond_optimization= 1;
parsing_place= NO_MATTER;
......@@ -1165,6 +1166,7 @@ void st_select_lex::init_select()
select_limit= 0; /* denotes the default limit = HA_POS_ERROR */
offset_limit= 0; /* denotes the default offset = 0 */
with_sum_func= 0;
}
/*
......
......@@ -482,6 +482,7 @@ public:
List<Item> item_list; /* list of fields & expressions */
List<String> interval_list, use_index, *use_index_ptr,
ignore_index, *ignore_index_ptr;
bool is_item_list_lookup;
/*
Usualy it is pointer to ftfunc_list_alloc, but in union used to create fake
select_lex for calling mysql_select under results of union
......
......@@ -11950,11 +11950,16 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
We check order_item->fixed because Item_func_group_concat can put
arguments for which fix_fields already was called.
*/
thd->lex->current_select->is_item_list_lookup= 1;
if (!order_item->fixed &&
(order_item->fix_fields(thd, order->item) ||
(order_item= *order->item)->check_cols(1) ||
thd->is_fatal_error))
{
thd->lex->current_select->is_item_list_lookup= 0;
return TRUE; /* Wrong field. */
}
thd->lex->current_select->is_item_list_lookup= 0;
uint el= all_fields.elements;
all_fields.push_front(order_item); /* Add new field to field list. */
......
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