From: Date: October 9 2005 9:05pm Subject: bk commit into 4.0 tree (evgen:1.2155) BUG#7672 List-Archive: http://lists.mysql.com/internals/30841 X-Bug: 7672 Message-Id: <20051009190546.CE16F13EA32@localhost.moonbone.local> Below is the list of changes that have just been committed into a local 4.0 repository of evgen. When evgen does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2155 05/10/09 23:05:44 evgen@stripped +6 -0 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. mysql-test/r/select.result 1.38 05/10/09 23:04:20 evgen@stripped +10 -0 Test case for bug#7672 Unknown column error in order clause mysql-test/t/select.test 1.28 05/10/09 23:03:15 evgen@stripped +9 -0 Test case for bug#7672 Unknown column error in order clause sql/sql_select.cc 1.291 05/10/09 23:01:31 evgen@stripped +6 -0 Fix bug#7672 Unknown column error in order clause sql/sql_lex.h 1.82 05/10/09 23:01:01 evgen@stripped +1 -1 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_lex.cc 1.42 05/10/09 23:00:49 evgen@stripped +1 -0 Fix bug#7672 Unknown column error in order clause sql/item.cc 1.38 05/10/09 23:00:25 evgen@stripped +11 -0 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. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: evgen # Host: moonbone.local # Root: /work/7672-bug-4.0-mysql --- 1.37/sql/item.cc 2004-12-11 19:59:08 +03:00 +++ 1.38/sql/item.cc 2005-10-09 23:00:25 +04:00 @@ -348,7 +348,18 @@ { 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) --- 1.41/sql/sql_lex.cc 2005-04-15 21:20:12 +04:00 +++ 1.42/sql/sql_lex.cc 2005-10-09 23:00:49 +04:00 @@ -154,6 +154,7 @@ lex->slave_thd_opt=0; lex->sql_command=SQLCOM_END; bzero((char *)&lex->mi,sizeof(lex->mi)); + lex->select_lex.is_item_list_lookup= 0; return lex; } --- 1.81/sql/sql_lex.h 2003-07-03 12:55:34 +04:00 +++ 1.82/sql/sql_lex.h 2005-10-09 23:01:01 +04:00 @@ -121,7 +121,7 @@ ignore_index, *ignore_index_ptr; List ftfunc_list; uint in_sum_expr, sort_default; - bool create_refs, braces; + bool create_refs, braces, is_item_list_lookup; st_select_lex *next; } SELECT_LEX; --- 1.290/sql/sql_select.cc 2005-02-01 16:36:44 +03:00 +++ 1.291/sql/sql_select.cc 2005-10-09 23:01:31 +04:00 @@ -6845,8 +6845,14 @@ return 0; } order->in_field_list=0; + /* Allow lookup in select's item_list to find aliased fields */ + thd->lex.select_lex.is_item_list_lookup= 1; if ((*order->item)->fix_fields(thd,tables) || thd->fatal_error) + { + thd->lex.select_lex.is_item_list_lookup= 0; return 1; // Wrong field + } + thd->lex.select_lex.is_item_list_lookup= 0; all_fields.push_front(*order->item); // Add new field to field list order->item=(Item**) all_fields.head_ref(); return 0; --- 1.37/mysql-test/r/select.result 2005-05-16 00:56:44 +04:00 +++ 1.38/mysql-test/r/select.result 2005-10-09 23:04:20 +04:00 @@ -2431,3 +2431,13 @@ COUNT(*) 0 drop table t1; +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; --- 1.27/mysql-test/t/select.test 2005-05-16 00:56:44 +04:00 +++ 1.28/mysql-test/t/select.test 2005-10-09 23:03:15 +04:00 @@ -1983,3 +1983,12 @@ 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;