MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:igor Date:July 5 2007 4:12am
Subject:bk commit into 5.0 tree (igor:1.2519) BUG#29392
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor 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-07-04 21:12:07-07:00, igor@stripped +3 -0
  Fixed bug #29392.
  This bug may manifest itself for select queries over a multi-table view
  that includes an ORDER BY clause in its definition. If the select list of 
  the query contains references to the same view column with different
  aliases the names of the columns in the result output will be nevertheless
  the same, coinciding with one of the alias.
  
  The bug happened because the method Item_ref::get_tmp_table_item that
  was inherited by the class Item_direct_view_ref ignored the fact that
  the name of the view column reference must be inherited by the fields
  of the temporary table that was created in order to get the result rows
  sorted.

  mysql-test/r/view.result@stripped, 2007-07-04 21:11:57-07:00, igor@stripped +47 -0
    Added a test case for bug #29392.

  mysql-test/t/view.test@stripped, 2007-07-04 21:11:57-07:00, igor@stripped +55 -0
    Added a test case for bug #29392.

  sql/item.h@stripped, 2007-07-04 21:11:57-07:00, igor@stripped +6 -0
    Fixed bug #29392.
    This bug may manifest itself for select queries over a multi-table view
    that includes an ORDER BY clause in its definition. If the select list of 
    the query contains references to the same view column with different
    aliases the names of the columns in the result output will be nevertheless
    the same, coinciding with one of the alias.
    
    The bug happened because the method Item_ref::get_tmp_table_item that
    was inherited by the class Item_direct_view_ref ignored the fact that
    the name of the view column reference must be inherited by the fields
    of the temporary table that was created in order to get the result rows
    sorted.
    
    Fixed by providing a proper implementation of the get_tmp_table_item 
    method for the Item_direct_view_ref class.

diff -Nrup a/mysql-test/r/view.result b/mysql-test/r/view.result
--- a/mysql-test/r/view.result	2007-06-20 12:43:10 -07:00
+++ b/mysql-test/r/view.result	2007-07-04 21:11:57 -07:00
@@ -3500,4 +3500,51 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	4	Using where
 DROP VIEW v1;
 DROP TABLE t1;
+CREATE TABLE t1 (
+person_id int NOT NULL PRIMARY KEY,
+username varchar(40) default NULL,
+status_flg char(1) NOT NULL default 'A'
+);
+CREATE TABLE t2 (
+person_role_id int NOT NULL auto_increment PRIMARY KEY,
+role_id int NOT NULL,
+person_id int NOT NULL,
+INDEX idx_person_id (person_id),
+INDEX idx_role_id (role_id)
+);
+CREATE TABLE t3 (
+role_id int NOT NULL auto_increment PRIMARY KEY,
+role_name varchar(100) default NULL,
+app_name varchar(40) NOT NULL,
+INDEX idx_app_name(app_name)
+);
+CREATE VIEW v1 AS 
+SELECT profile.person_id AS person_id
+FROM t1 profile, t2 userrole, t3 role
+WHERE userrole.person_id = profile.person_id AND
+role.role_id = userrole.role_id AND
+profile.status_flg = 'A'
+  ORDER BY profile.person_id,role.app_name,role.role_name;
+INSERT INTO  t1 VALUES
+(6,'Sw','A'), (-1136332546,'ols','e'), (0,'    *\n','0'),
+(-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0');
+INSERT INTO t2 VALUES
+(1,3,6),(2,4,7),(3,5,8),(4,6,9),(5,1,6),(6,1,7),(7,1,8),(8,1,9),(9,1,10);
+INSERT INTO t3 VALUES 
+(1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'),
+(3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'),
+(5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'),
+(7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'),
+(9,'RTOS_DCFSPOS_SUPERVISOR','RTOS');
+EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	profile	const	PRIMARY	PRIMARY	4	const	1	Using temporary; Using filesort
+1	SIMPLE	userrole	ref	idx_person_id,idx_role_id	idx_person_id	4	const	2	
+1	SIMPLE	role	eq_ref	PRIMARY	PRIMARY	4	test.userrole.role_id	1	
+SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
+a	b
+6	6
+6	6
+DROP VIEW v1;
+DROP TABLE t1,t2,t3;
 End of 5.0 tests.
diff -Nrup a/mysql-test/t/view.test b/mysql-test/t/view.test
--- a/mysql-test/t/view.test	2007-06-20 12:43:10 -07:00
+++ b/mysql-test/t/view.test	2007-07-04 21:11:57 -07:00
@@ -3348,4 +3348,59 @@ EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a
 DROP VIEW v1;
 DROP TABLE t1;
 
+#
+# Bug #29392: SELECT over a multi-table view with ORDER BY  
+#             selecting the same view column with two different aliases  
+#
+
+CREATE TABLE t1 (
+  person_id int NOT NULL PRIMARY KEY,
+  username varchar(40) default NULL,
+  status_flg char(1) NOT NULL default 'A'
+);
+
+CREATE TABLE t2 (
+  person_role_id int NOT NULL auto_increment PRIMARY KEY,
+  role_id int NOT NULL,
+  person_id int NOT NULL,
+  INDEX idx_person_id (person_id),
+  INDEX idx_role_id (role_id)
+);
+
+CREATE TABLE t3 (
+  role_id int NOT NULL auto_increment PRIMARY KEY,
+  role_name varchar(100) default NULL,
+  app_name varchar(40) NOT NULL,
+  INDEX idx_app_name(app_name)
+);
+
+CREATE VIEW v1 AS 
+SELECT profile.person_id AS person_id
+  FROM t1 profile, t2 userrole, t3 role
+    WHERE userrole.person_id = profile.person_id AND
+          role.role_id = userrole.role_id AND
+          profile.status_flg = 'A'
+  ORDER BY profile.person_id,role.app_name,role.role_name;
+
+INSERT INTO  t1 VALUES
+ (6,'Sw','A'), (-1136332546,'ols','e'), (0,'    *\n','0'),
+ (-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0');
+
+INSERT INTO t2 VALUES
+  (1,3,6),(2,4,7),(3,5,8),(4,6,9),(5,1,6),(6,1,7),(7,1,8),(8,1,9),(9,1,10);
+
+INSERT INTO t3 VALUES 
+  (1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'),
+  (3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'),
+  (5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'),
+  (7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'),
+  (9,'RTOS_DCFSPOS_SUPERVISOR','RTOS');
+ 
+EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
+SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
+
+DROP VIEW v1;
+DROP TABLE t1,t2,t3;
+
 --echo End of 5.0 tests.
+
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2007-06-20 00:18:42 -07:00
+++ b/sql/item.h	2007-07-04 21:11:57 -07:00
@@ -1983,6 +1983,12 @@ public:
 
   bool fix_fields(THD *, Item **);
   bool eq(const Item *item, bool binary_cmp) const;
+  Item *get_tmp_table_item(THD *thd)
+  {
+    Item *item= Item_ref::get_tmp_table_item(thd);
+    item->name= name;
+    return item;
+  }
   virtual Ref_Type ref_type() { return VIEW_REF; }
 };
 
Thread
bk commit into 5.0 tree (igor:1.2519) BUG#29392igor5 Jul