diff options
author | unknown <jimw@mysql.com> | 2005-10-12 16:07:16 -0700 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2005-10-12 16:07:16 -0700 |
commit | 62002fdc00aa1995a8df5457beaccf2183065369 (patch) | |
tree | 833513fb35bf0d313d8afc6d342221715167064a /sql | |
parent | ce48949ef9fd4fba5f4090ffef26b4169d20c79f (diff) | |
parent | d68f16e215f433b07b1ecf83f0296fdcaae50e65 (diff) | |
download | mariadb-git-62002fdc00aa1995a8df5457beaccf2183065369.tar.gz |
Merge bk-internal:/home/bk/mysql-4.1
into mysql.com:/home/jimw/my/mysql-4.1-clean
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.cc | 15 | ||||
-rw-r--r-- | sql/sql_lex.cc | 2 | ||||
-rw-r--r-- | sql/sql_lex.h | 1 | ||||
-rw-r--r-- | sql/sql_select.cc | 5 |
4 files changed, 23 insertions, 0 deletions
diff --git a/sql/item.cc b/sql/item.cc index 7419bc173d5..d284af2b9f1 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1760,6 +1760,21 @@ 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) { + /* 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, + ¬_used); + if (res != not_found_item && (*res)->type() == Item::FIELD_ITEM) + { + set_field((*((Item_field**)res))->field); + return 0; + } + } + /* We can't find table field in table list of current select, consequently we have to find it in outer subselect(s). diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 8636b6542fc..16641ad6dd5 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1083,6 +1083,7 @@ void st_select_lex::init_query() prep_where= 0; subquery_in_having= explicit_limit= 0; parsing_place= NO_MATTER; + is_item_list_lookup= 0; } void st_select_lex::init_select() @@ -1109,6 +1110,7 @@ void st_select_lex::init_select() select_limit= HA_POS_ERROR; offset_limit= 0; with_sum_func= 0; + } /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 8d919f12563..47908ba8685 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -426,6 +426,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 diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0d9cab6a36b..f72d897e22d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8348,11 +8348,16 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, 'it' reassigned in if condition because fix_field can change it. */ + thd->lex->current_select->is_item_list_lookup= 1; if (!it->fixed && (it->fix_fields(thd, tables, order->item) || (it= *order->item)->check_cols(1) || thd->is_fatal_error)) + { + thd->lex->current_select->is_item_list_lookup= 0; return 1; // Wrong field + } + thd->lex->current_select->is_item_list_lookup= 0; uint el= all_fields.elements; all_fields.push_front(it); // Add new field to field list ref_pointer_array[el]= it; |