Loading mysql-test/r/view.result +12 −1 Original line number Diff line number Diff line Loading @@ -625,7 +625,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)); Loading Loading @@ -3562,4 +3562,15 @@ table_name is_updatable v1 NO drop view v1; drop table t1; 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. mysql-test/t/view.test +20 −1 Original line number Diff line number Diff line Loading @@ -510,7 +510,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; Loading Loading @@ -3415,5 +3415,24 @@ select table_name, is_updatable from information_schema.views drop view v1; drop table t1; # # 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. sql/sql_view.cc +9 −0 Original line number Diff line number Diff line Loading @@ -925,6 +925,15 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, 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; Loading Loading
mysql-test/r/view.result +12 −1 Original line number Diff line number Diff line Loading @@ -625,7 +625,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)); Loading Loading @@ -3562,4 +3562,15 @@ table_name is_updatable v1 NO drop view v1; drop table t1; 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.
mysql-test/t/view.test +20 −1 Original line number Diff line number Diff line Loading @@ -510,7 +510,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; Loading Loading @@ -3415,5 +3415,24 @@ select table_name, is_updatable from information_schema.views drop view v1; drop table t1; # # 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.
sql/sql_view.cc +9 −0 Original line number Diff line number Diff line Loading @@ -925,6 +925,15 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, 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; Loading