From f3f84ed8a08a7c19442cdbacc9c23fbc5d38323b Mon Sep 17 00:00:00 2001 From: unknown <evgen@moonbone.local> Date: Sun, 9 Oct 2005 23:05:44 +0400 Subject: Fix bug#7672 Unknown column error in order clause When fixing Item_func_plus in ORDER BY clause field c is searched in all opened tables, but because c is an alias it wasn't found there. This patch adds a flag to select_lex which allows Item_field::fix_fields() to look up in select's item_list to find aliased fields. sql/item.cc: Fix bug#7672 Unknown column error in order clause When fixing fields in ORDER BY clause allow Item_field::fix_fields() to look up items in select's item list to find aliased fields. sql/sql_lex.cc: Fix bug#7672 Unknown column error in order clause sql/sql_lex.h: Fix bug#7672 Unknown column error in order clause Added flag to select_lex allowing Item_field::fix_fields to look up items in select's item list. sql/sql_select.cc: Fix bug#7672 Unknown column error in order clause mysql-test/t/select.test: Test case for bug#7672 Unknown column error in order clause mysql-test/r/select.result: Test case for bug#7672 Unknown column error in order clause --- sql/item.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sql/item.cc') diff --git a/sql/item.cc b/sql/item.cc index 8737cc06bbd..c3845db904c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -348,7 +348,18 @@ bool Item_field::fix_fields(THD *thd,TABLE_LIST *tables) { Field *tmp; if (!(tmp=find_field_in_tables(thd,this,tables))) + { + if (thd->lex.select_lex.is_item_list_lookup) + { + Item** res= find_item_in_list(this, thd->lex.select_lex.item_list); + if (res && *res && (*res)->type() == Item::FIELD_ITEM) + { + set_field((*((Item_field**)res))->field); + return 0; + } + } return 1; + } set_field(tmp); } else if (thd && thd->set_query_id && field->query_id != thd->query_id) -- cgit v1.2.1 From a46e8e230e7aaa4d338364154af514ed342d05f3 Mon Sep 17 00:00:00 2001 From: unknown <evgen@moonbone.local> Date: Thu, 13 Oct 2005 00:58:59 +0400 Subject: select.test, sql_select.cc, sql_lex.cc, item.cc: Bug #7672 after merge fix sql/item.cc: Bug #7672 after merge fix sql/sql_lex.cc: Bug #7672 after merge fix sql/sql_select.cc: Bug #7672 after merge fix mysql-test/t/select.test: Bug #7672 after merge fix --- sql/item.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'sql/item.cc') diff --git a/sql/item.cc b/sql/item.cc index 3c3a6d273fe..8df839baa5c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1760,10 +1760,15 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if ((tmp= find_field_in_tables(thd, this, tables, &where, 0)) == not_found_field) { - if (thd->lex.select_lex.is_item_list_lookup) + /* Look up in current select's item_list to find aliased fields */ + if (thd->lex->current_select->is_item_list_lookup) { - Item** res= find_item_in_list(this, thd->lex.select_lex.item_list); - if (res && *res && (*res)->type() == Item::FIELD_ITEM) + uint counter; + bool not_used; + Item** res= find_item_in_list(this, thd->lex->current_select->item_list, + &counter, REPORT_EXCEPT_NOT_FOUND, + ¬_used); + if (res != not_found_item && (*res)->type() == Item::FIELD_ITEM) { set_field((*((Item_field**)res))->field); return 0; -- cgit v1.2.1