From: kgeorge Date: June 6 2007 2:54pm Subject: bk commit into 5.0 tree (gkodinov:1.2506) BUG#28701 List-Archive: http://lists.mysql.com/commits/28216 X-Bug: 28701 Message-Id: <20070606145447.6302011910B6@macbook.gmz> 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-06-06 17:54:14+03:00, gkodinov@stripped +3 -0 Bug #28701: Views don't have indexes. So they can't take index hints. Added a check and disabled the usage of hints for views. mysql-test/r/view.result@stripped, 2007-06-06 17:54:00+03:00, gkodinov@stripped +12 -1 Bug #28701: test case mysql-test/t/view.test@stripped, 2007-06-06 17:54:01+03:00, gkodinov@stripped +21 -1 Bug #28701: test case sql/sql_view.cc@stripped, 2007-06-06 17:54:03+03:00, gkodinov@stripped +9 -0 Bug #28701: disable usage of hints for views # 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: macbook.gmz # Root: /Users/kgeorge/mysql/work/B28701-5.0-opt --- 1.205/mysql-test/r/view.result 2007-06-01 00:40:46 +03:00 +++ 1.206/mysql-test/r/view.result 2007-06-06 17:54:00 +03:00 @@ -612,7 +612,7 @@ drop table t1; create table t1 (a int, b int); create view v1 as select a, sum(b) from t1 group by a; select b from v1 use index (some_index) where b=1; -ERROR HY000: Key 'some_index' doesn't exist in table 'v1' +ERROR HY000: Incorrect usage of USE INDEX and VIEW drop view v1; drop table t1; create table t1 (col1 char(5),col2 char(5)); @@ -3455,4 +3455,15 @@ a1 c 2 0 DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1 USE KEY(non_existant); +ERROR HY000: Incorrect usage of USE INDEX and VIEW +SELECT * FROM v1 FORCE KEY(non_existant); +ERROR HY000: Incorrect usage of FORCE INDEX and VIEW +SELECT * FROM v1 IGNORE KEY(non_existant); +ERROR HY000: Incorrect usage of IGNORE INDEX and VIEW +DROP VIEW v1; +DROP TABLE t1; End of 5.0 tests. --- 1.186/mysql-test/t/view.test 2007-06-01 00:40:47 +03:00 +++ 1.187/mysql-test/t/view.test 2007-06-06 17:54:01 +03:00 @@ -506,7 +506,7 @@ drop table t1; # create table t1 (a int, b int); create view v1 as select a, sum(b) from t1 group by a; --- error 1176 +--error ER_WRONG_USAGE select b from v1 use index (some_index) where b=1; drop view v1; drop table t1; @@ -3319,5 +3319,25 @@ SELECT * FROM t1; DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; + + +# +# Bug #28701: SELECTs from VIEWs completely ignore USE/FORCE KEY, allowing +# invalid statements +# + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW v1 AS SELECT * FROM t1; +--error ER_WRONG_USAGE +SELECT * FROM v1 USE KEY(non_existant); +--error ER_WRONG_USAGE +SELECT * FROM v1 FORCE KEY(non_existant); +--error ER_WRONG_USAGE +SELECT * FROM v1 IGNORE KEY(non_existant); + +DROP VIEW v1; +DROP TABLE t1; + --echo End of 5.0 tests. --- 1.113/sql/sql_view.cc 2007-06-01 00:22:20 +03:00 +++ 1.114/sql/sql_view.cc 2007-06-06 17:54:03 +03:00 @@ -918,6 +918,15 @@ bool mysql_make_view(THD *thd, File_pars DBUG_RETURN(0); } + if (table->use_index || table->ignore_index) + { + my_error(ER_WRONG_USAGE, MYF(0), + table->ignore_index ? "IGNORE INDEX" : + (table->force_index ? "FORCE INDEX" : "USE INDEX"), + "VIEW"); + DBUG_RETURN(TRUE); + } + /* check loop via view definition */ for (TABLE_LIST *precedent= table->referencing_view; precedent;