MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:kgeorge Date:March 6 2007 4:46pm
Subject:bk commit into 5.0 tree (gkodinov:1.2432) BUG#26661
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge 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@stripped, 2007-03-06 18:45:57+02:00, gkodinov@stripped +4 -0
  Bug #26661: The optimizer uses a special 
  "fake" st_select_lex as a current select
  when resolving ORDER BY and LIMIT for a
  UNION (sub)query. This temporary structure
  doesn't have Item_subselect descendant so
  it cannot resolve the fields in ORDER BY
  correctly.
  Fixed by making a dummy subquery class
  to resolve items in ORDER BY of the UNION and
  remove it right after so it doesn't interfere
  with the rest of the subquery code.

  mysql-test/r/subselect3.result@stripped, 2007-03-06 18:45:55+02:00, gkodinov@stripped +11 -0
    Bug #26661: test case

  mysql-test/t/subselect3.test@stripped, 2007-03-06 18:45:55+02:00, gkodinov@stripped +12 -0
    Bug #26661: test case

  sql/item_subselect.h@stripped, 2007-03-06 18:45:56+02:00, gkodinov@stripped +1 -1
    Bug #26661: dummy subquery class type

  sql/sql_union.cc@stripped, 2007-03-06 18:45:56+02:00, gkodinov@stripped +22 -0
    Bug #26661: use dummy subquery class type
    to resolve items in ORDER BY of the UNION and
    remove it right after so it doesn't interfere
    with the rest of the subquery code.

# 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:	gkodinov
# Host:	magare.gmz
# Root:	/home/kgeorge/mysql/work/B26661-5.0-opt

--- 1.139/sql/sql_union.cc	2007-02-26 14:57:42 +02:00
+++ 1.140/sql/sql_union.cc	2007-03-06 18:45:56 +02:00
@@ -410,6 +410,19 @@
 }
 
 
+/* fake class in UNIONS to handle resolution of ORDER BY */
+class Item_fake_subselect: public Item_subselect
+{
+public:
+  subs_type substype() { return FAKE_SUBS; };
+  Item_fake_subselect () : Item_subselect() { engine= NULL; };
+  double val_real() { DBUG_ASSERT(0); return 0; };
+  longlong val_int() { DBUG_ASSERT(0); return 0; };
+  String* val_str(String*) { DBUG_ASSERT(0); return NULL; };
+  my_decimal* val_decimal(my_decimal*) { DBUG_ASSERT(0); return NULL; };
+};
+
+
 bool st_select_lex_unit::exec()
 {
   SELECT_LEX *lex_select_save= thd->lex->current_select;
@@ -550,6 +563,13 @@
 	  allocation.
 	*/
 	fake_select_lex->item_list= item_list;
+
+        /*
+          Fake st_select_lex should have item for correct resolution of 
+          fields in ORDER BY
+        */
+        if (!item)
+          item= new Item_fake_subselect();
       }
       else
       {
@@ -573,6 +593,8 @@
                             result, this, fake_select_lex);
 
       fake_select_lex->table_list.empty();
+      if (item && item->substype() == Item_subselect::FAKE_SUBS)
+        item= NULL;
       if (!saved_error)
       {
 	thd->limit_found_rows = (ulonglong)table->file->records + add_rows;

--- 1.87/sql/item_subselect.h	2007-02-21 13:05:00 +02:00
+++ 1.88/sql/item_subselect.h	2007-03-06 18:45:56 +02:00
@@ -64,7 +64,7 @@
 
   enum trans_res {RES_OK, RES_REDUCE, RES_ERROR};
   enum subs_type {UNKNOWN_SUBS, SINGLEROW_SUBS,
-		  EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS};
+		  EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS, FAKE_SUBS};
 
   Item_subselect();
 

--- 1.5/mysql-test/r/subselect3.result	2007-02-21 21:59:51 +02:00
+++ 1.6/mysql-test/r/subselect3.result	2007-03-06 18:45:55 +02:00
@@ -645,3 +645,14 @@
 2	2	0
 3	3	1
 drop table t1,t2;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+SELECT a FROM 
+(SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY unknown_column) AS test;
+ERROR 42S22: Unknown column 'unknown_column' in 'order clause'
+SELECT a FROM 
+(SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY a) AS test;
+a
+1
+2
+DROP TABLE t1;

--- 1.5/mysql-test/t/subselect3.test	2007-01-27 03:10:42 +02:00
+++ 1.6/mysql-test/t/subselect3.test	2007-03-06 18:45:55 +02:00
@@ -489,3 +489,15 @@
 
 drop table t1,t2;
 
+#
+# Bug #26661: SELECT with UNION kills the daemon
+#
+CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2);
+
+--error ER_BAD_FIELD_ERROR
+SELECT a FROM 
+ (SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY unknown_column) AS test;
+SELECT a FROM 
+ (SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY a) AS test;
+
+DROP TABLE t1;
Thread
bk commit into 5.0 tree (gkodinov:1.2432) BUG#26661kgeorge6 Mar