List:Commits« Previous MessageNext Message »
From:kgeorge Date:May 10 2006 4:12pm
Subject:bk commit into 5.0 tree (gkodinov:1.2130) BUG#7549
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
  1.2130 06/05/10 19:12:01 gkodinov@stripped +6 -0
  BUG#7549: Missing error message for invalid view selection with subquery.
  
  When a view statement is compiled on CREATE VIEW time, most of the 
  optimizations should not be done. Finding the right optimization 
  for a subquery is one of them.
  Unfortunately the optimizer is resolving the column references of 
  the left expression of IN subqueries in the process of deciding 
  witch optimization to use. So a separate member function must 
  be introduced for that case in Item_subselect : check the 
  validity of the left expression (in the case of IN subqueries, 
  or any other expressions in addition to the subquery) in
  CREATE VIEW mode. 

  sql/sql_select.cc
    1.416 06/05/10 19:11:55 gkodinov@stripped +8 -0
    called the virtual functions for subqueries in views

  sql/item_subselect.h
    1.77 06/05/10 19:11:55 gkodinov@stripped +3 -0
    added the virtual function

  sql/item_subselect.cc
    1.124 06/05/10 19:11:55 gkodinov@stripped +7 -0
    defined the fuction : calls the fix_fields for the left expression

  mysql-test/t/subselect.test
    1.117 06/05/10 19:11:55 gkodinov@stripped +15 -0
    test case

  mysql-test/r/view.result
    1.155 06/05/10 19:11:55 gkodinov@stripped +1 -1
    chnaged explain due to column being resolved

  mysql-test/r/subselect.result
    1.141 06/05/10 19:11:55 gkodinov@stripped +8 -0
    test case

# 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:	rakia.gmz
# Root:	/home/kgeorge/mysql/5.0/B7549

--- 1.415/sql/sql_select.cc	2006-05-10 09:38:30 +03:00
+++ 1.416/sql/sql_select.cc	2006-05-10 19:11:55 +03:00
@@ -382,6 +382,14 @@
       }
     }
   }
+  else
+  {
+    Item_subselect *subselect;
+    /* Is it subselect? */
+    if ((subselect= select_lex->master_unit()->item)
+        && subselect->check_fields(thd))
+      goto err;
+  }
 
   if (having && having->with_sum_func)
     having->split_sum_func2(thd, ref_pointer_array, all_fields,

--- 1.140/mysql-test/r/subselect.result	2006-05-04 05:38:29 +03:00
+++ 1.141/mysql-test/r/subselect.result	2006-05-10 19:11:55 +03:00
@@ -3169,3 +3169,11 @@
 insert into t2 values (2, 1), (1, 0);
 delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
 drop table t1, t2;
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
+ERROR 42S22: Unknown column 'no_such_column' in 'order clause'
+CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1);
+ERROR 42S22: Unknown column 'no_such_column' in 'where clause'
+SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
+ERROR 42S22: Unknown column 'no_such_column' in 'IN/ALL/ANY subquery'
+DROP TABLE t1;

--- 1.154/mysql-test/r/view.result	2006-04-26 11:13:11 +03:00
+++ 1.155/mysql-test/r/view.result	2006-05-10 19:11:55 +03:00
@@ -706,7 +706,7 @@
 create view v2 as select a from t2 where a in (select a from v1);
 show create view v2;
 View	Create View
-v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where `a` in (select `v1`.`a` AS `a` from `v1`)
+v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where `t2`.`a` in (select `v1`.`a` AS `a` from `v1`)
 drop view v2, v1;
 drop table t1, t2;
 CREATE VIEW `v 1` AS select 5 AS `5`;

--- 1.116/mysql-test/t/subselect.test	2006-03-23 16:09:27 +02:00
+++ 1.117/mysql-test/t/subselect.test	2006-05-10 19:11:55 +03:00
@@ -2085,3 +2085,18 @@
 insert into t2 values (2, 1), (1, 0);
 delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
 drop table t1, t2;
+
+#
+# Bug #7549: Missing error message for invalid view selection with subquery
+#
+
+CREATE TABLE t1 (a INT);
+
+--error 1054
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
+--error 1054
+CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1);
+--error 1054
+SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
+
+DROP TABLE t1;

--- 1.123/sql/item_subselect.cc	2006-04-28 13:06:51 +03:00
+++ 1.124/sql/item_subselect.cc	2006-05-10 19:11:55 +03:00
@@ -1351,6 +1351,13 @@
 }
 
 
+bool Item_in_subselect::check_fields(THD *thd)
+{
+  return !left_expr->fixed &&
+    left_expr->fix_fields(thd, &left_expr);
+}
+
+
 Item_subselect::trans_res
 Item_allany_subselect::select_transformer(JOIN *join)
 {

--- 1.76/sql/item_subselect.h	2006-02-15 18:33:15 +02:00
+++ 1.77/sql/item_subselect.h	2006-05-10 19:11:55 +03:00
@@ -92,6 +92,8 @@
     return null_value;
   }
   bool fix_fields(THD *thd, Item **ref);
+  /* fix_fields in view prepare mode : check validity of cols */
+  virtual bool check_fields(THD *thd) { return 0; };
   virtual bool exec();
   virtual void fix_length_and_dec();
   table_map used_tables() const;
@@ -258,6 +260,7 @@
   void top_level_item() { abort_on_null=1; }
   bool test_limit(st_select_lex_unit *unit);
   void print(String *str);
+  bool check_fields(THD *thd);
 
   friend class Item_ref_null_helper;
   friend class Item_is_not_null_test;
Thread
bk commit into 5.0 tree (gkodinov:1.2130) BUG#7549kgeorge10 May