List:Commits« Previous MessageNext Message »
From:kgeorge Date:April 20 2007 9:49am
Subject:bk commit into 5.0 tree (gkodinov:1.2457) BUG#27786
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-04-20 10:49:45+03:00, gkodinov@stripped +4 -0
  Bug #27786:
  When merging views into the enclosing statement
  the ORDER BY clause of the view is merged to the
  parent's ORDER BY clause.
  However when the VIEW is merged into an UNION
  branch the ORDER BY should be ignored. 
  Use of ORDER BY for individual SELECT statements
  implies nothing about the order in which the rows
  appear in the final result because UNION by default
  produces unordered set of rows.
  Fixed by ignoring the ORDER BY clause from the merge
  view when expanded in an UNION branch.

  mysql-test/r/view.result@stripped, 2007-04-20 10:49:44+03:00, gkodinov@stripped +35 -0
    Bug #27786: test case

  mysql-test/t/view.test@stripped, 2007-04-20 10:49:44+03:00, gkodinov@stripped +16 -0
    Bug #27786: test case

  sql/sql_lex.h@stripped, 2007-04-20 10:49:44+03:00, gkodinov@stripped +8 -0
    Bug #27786: add a is_union() inlined function
    Returns true if the unit represents an UNION.

  sql/sql_view.cc@stripped, 2007-04-20 10:49:44+03:00, gkodinov@stripped +7 -2
    Bug #27786: ignore ORDER BY in mergeable views when in UNION context

# 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/B27786-5.0-opt

--- 1.241/sql/sql_lex.h	2007-03-08 19:29:58 +02:00
+++ 1.242/sql/sql_lex.h	2007-04-20 10:49:44 +03:00
@@ -468,6 +468,7 @@ public:
   bool change_result(select_subselect *result, select_subselect *old_result);
   void set_limit(st_select_lex *values);
   void set_thd(THD *thd_arg) { thd= thd_arg; }
+  inline bool is_union (); 
 
   friend void lex_start(THD *thd, uchar *buf, uint length);
   friend int subselect_union_engine::exec();
@@ -699,6 +700,13 @@ public:
   void cleanup_all_joins(bool full);
 };
 typedef class st_select_lex SELECT_LEX;
+
+
+inline bool st_select_lex_unit::is_union ()
+{ 
+  return first_select()->next_select() && 
+    first_select()->next_select()->linkage == UNION_TYPE;
+}
 
 #define ALTER_ADD_COLUMN	1
 #define ALTER_DROP_COLUMN	2

--- 1.198/mysql-test/r/view.result	2007-04-12 21:20:46 +03:00
+++ 1.199/mysql-test/r/view.result	2007-04-20 10:49:44 +03:00
@@ -3319,4 +3319,39 @@ lgid	clid
 2	YES
 DROP VIEW v1;
 DROP table t1,t2;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
+SELECT * FROM t1 UNION SELECT * FROM v1;
+a
+1
+2
+3
+EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	
+2	UNION	t1	ALL	NULL	NULL	NULL	NULL	3	
+NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
+SELECT * FROM v1 UNION SELECT * FROM t1;
+a
+1
+2
+3
+EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	
+2	UNION	t1	ALL	NULL	NULL	NULL	NULL	3	
+NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
+SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
+a
+1
+2
+3
+EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	
+2	UNION	t1	ALL	NULL	NULL	NULL	NULL	3	
+NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	Using filesort
+DROP VIEW v1;
+DROP TABLE t1;
 End of 5.0 tests.

--- 1.181/mysql-test/t/view.test	2007-04-12 21:19:34 +03:00
+++ 1.182/mysql-test/t/view.test	2007-04-20 10:49:44 +03:00
@@ -3205,4 +3205,20 @@ SELECT * FROM v1;
 DROP VIEW v1;
 DROP table t1,t2;
 
+#
+# Bug#27786: Inconsistent Operation Performing UNION On View With ORDER BY 
+#
+CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2),(3);
+CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
+
+SELECT * FROM t1 UNION SELECT * FROM v1;
+EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
+SELECT * FROM v1 UNION SELECT * FROM t1;
+EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
+SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
+EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
+
+DROP VIEW v1;
+DROP TABLE t1;
+
 --echo End of 5.0 tests.

--- 1.107/sql/sql_view.cc	2007-03-22 22:12:41 +02:00
+++ 1.108/sql/sql_view.cc	2007-04-20 10:49:44 +03:00
@@ -1263,13 +1263,18 @@ bool mysql_make_view(THD *thd, File_pars
         unit->slave= save_slave; // fix include_down initialisation
       }
 
+      /* 
+        We can safely ignore the VIEW's ORDER BY if we merge into union 
+        branch, as order is not important there.
+      */
+      if (!table->select_lex->master_unit()->is_union())
+       
table->select_lex->order_list.push_back(&lex->select_lex.order_list);
       /*
 	This SELECT_LEX will be linked in global SELECT_LEX list
 	to make it processed by mysql_handle_derived(),
 	but it will not be included to SELECT_LEX tree, because it
 	will not be executed
-      */
-      table->select_lex->order_list.push_back(&lex->select_lex.order_list);
+      */ 
       goto ok;
     }
 
Thread
bk commit into 5.0 tree (gkodinov:1.2457) BUG#27786kgeorge20 Apr