List:Internals« Previous MessageNext Message »
From:eugene Date:September 28 2005 12:57am
Subject:bk commit into 4.0 tree (evgen:1.2156) BUG#7672
View as plain text  
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.2156 05/09/28 02:57:33 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 lex which allows Item_field::fix_fields() to look
  up in select's item_list to find aliased fields.

  mysql-test/t/select.test
    1.28 05/09/28 02:53:11 evgen@stripped +9 -0
    Test case for bug#7672 Unknown column error in order clause

  mysql-test/r/select.result
    1.38 05/09/28 02:52:46 evgen@stripped +10 -0
    Test case for bug#7672 Unknown column error in order clause

  sql/sql_select.cc
    1.291 05/09/28 02:52:00 evgen@stripped +6 -0
    Fix bug#7672 Unknown column error in order clause

  sql/sql_lex.h
    1.82 05/09/28 02:51:27 evgen@stripped +1 -1
    Fix bug#7672 Unknown column error in order clause
    Added flag to lex allowing Item_field::fix_fields to look up items in select's item
list.

  sql/sql_lex.cc
    1.42 05/09/28 02:50:07 evgen@stripped +1 -0
     Fix bug#7672 Unknown column error in order clause

  sql/item.cc
    1.38 05/09/28 02:49:07 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-09-28 02:49:07 +04:00
@@ -348,7 +348,18 @@
   {
     Field *tmp;
     if (!(tmp=find_field_in_tables(thd,this,tables)))
+    {
+      if (thd->lex.item_list_lookup)
+      {
+        Item** res= find_item_in_list(this, thd->lex.select_lex.item_list);
+        if ((*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-09-28 02:50:07 +04:00
@@ -154,6 +154,7 @@
   lex->slave_thd_opt=0;
   lex->sql_command=SQLCOM_END;
   bzero((char *)&lex->mi,sizeof(lex->mi));
+  lex->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-09-28 02:51:27 +04:00
@@ -180,7 +180,7 @@
   uint grant,grant_tot_col,which_columns, union_option;
   thr_lock_type lock_option;
   bool	drop_primary, drop_if_exists, drop_temporary, local_file, olap;
-  bool  in_comment,ignore_space,verbose,simple_alter;
+  bool  in_comment,ignore_space,verbose,simple_alter, item_list_lookup;
   uint slave_thd_opt;
 } LEX;
 

--- 1.290/sql/sql_select.cc	2005-02-01 16:36:44 +03:00
+++ 1.291/sql/sql_select.cc	2005-09-28 02:52:00 +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.item_list_lookup= 1;
   if ((*order->item)->fix_fields(thd,tables) || thd->fatal_error)
+  {
+    thd->lex.item_list_lookup= 0;
     return 1;					// Wrong field
+  }
+  thd->lex.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-09-28 02:52:46 +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-09-28 02:53:11 +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;
Thread
bk commit into 4.0 tree (evgen:1.2156) BUG#7672eugene28 Sep