diff --git a/mysql-test/r/analyze_format_json.result b/mysql-test/r/analyze_format_json.result index 1c24531715cc64278d393590b140f36e1679e95b..0f747068ebb4c0e33b29b70fa92203e5c9ca9083 100644 --- a/mysql-test/r/analyze_format_json.result +++ b/mysql-test/r/analyze_format_json.result @@ -143,6 +143,7 @@ ANALYZE "attached_condition": "(tbl2.b < 60)" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "r_filtered": 100 } @@ -180,6 +181,7 @@ ANALYZE "attached_condition": "(tbl2.b < 60)" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "(tbl1.c > tbl2.c)", "r_filtered": 15.833 diff --git a/mysql-test/r/analyze_stmt_privileges2.result b/mysql-test/r/analyze_stmt_privileges2.result new file mode 100644 index 0000000000000000000000000000000000000000..3dded4bc7cc8ed1dc4fd2aea3440269fb06d7e1e --- /dev/null +++ b/mysql-test/r/analyze_stmt_privileges2.result @@ -0,0 +1,5234 @@ +CREATE DATABASE privtest_db; +CREATE TABLE privtest_db.t1 (a INT, b VARCHAR(3)) ENGINE=MyISAM; +CREATE TABLE privtest_db.t2 (a INT, b VARCHAR(3)) ENGINE=MyISAM; +CREATE VIEW privtest_db.v1 AS SELECT a, b FROM privtest_db.t1 WHERE b IS NOT NULL; +CREATE VIEW privtest_db.v2 AS SELECT * FROM privtest_db.v1 WHERE a > 0; +INSERT INTO privtest_db.t2 VALUES (1,'foo'), (2,'bar'), (3,'qux'); +GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost'; +connect con1,localhost,privtest,,privtest_db; + +######################################################################### +# Underlying table permission tests +# (we modify permissions on the base table, keeping ALL on views) +######################################################################### + +connection default; +GRANT ALL ON privtest_db.v1 TO 'privtest'@'localhost'; +GRANT ALL ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + +#======================================================================== +# Test: No permissions on the table +#======================================================================== + +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Cannot run query, EXPLAIN, ANALYZE on the table +# because the query itself cannot be executed +#------------------------------------------------------------------------ +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SELECT on the table +#======================================================================== + +connection default; +GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Can only run SELECT, EXPLAIN SELECT, ANALYZE SELECT +#------------------------------------------------------------------------ +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1; +a b +10 NULL +10 NULL +10 NULL +10 NULL +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 +ANALYZE SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 100.00 +SELECT * FROM t1 WHERE a = 10; +a b +10 NULL +10 NULL +10 NULL +10 NULL +EXPLAIN SELECT * FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE SELECT * FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 100.00 Using where +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 60.00 Using where +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 60.00 Using where +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 0.00 Using where +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 24.00 100.00 50.00 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 24.00 100.00 50.00 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 Using where +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 24.00 100.00 0.00 Using where +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where +ANALYZE DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where +ANALYZE DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where + +#======================================================================== +# Test: Grant INSERT on the table +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Can only run INSERT, EXPLAIN INSERT, ANALYZE INSERT +#------------------------------------------------------------------------ +INSERT INTO t1 (a) VALUES (10); +EXPLAIN INSERT INTO t1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO t1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO t1 SELECT * FROM t2; +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant UPDATE on the table +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Can only run UPDATE, EXPLAIN UPDATE, ANALYZE UPDATE +# when the UPDATE does not read any columns. UPDATEs which +# read columns fail with ER_COLUMNACCESS_DENIED_ERROR +#------------------------------------------------------------------------ +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = 10; +EXPLAIN UPDATE t1 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 +ANALYZE UPDATE t1 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 100.00 +UPDATE t1 SET a = a + 1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +ANALYZE UPDATE t1 SET a = a + 1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant DELETE on the table +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Can only run DELETE, EXPLAIN DELETE, ANALYZE DELETE +# when the DELETE does not read any columns. DELETEs which +# read columns fail with ER_COLUMNACCESS_DENIED_ERROR +#------------------------------------------------------------------------ +# Note: ANALYZE DELETE FROM t1 USING t1, t2 ... fails due to MDEV-7043 +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1; +EXPLAIN DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 Deleting all rows +ANALYZE DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 NULL NULL NULL Deleting all rows +DELETE FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +ANALYZE DELETE FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it would have revealed the structure of the table) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant DELETE, SELECT(a) on the table +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT SELECT(a), DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Can run DELETE, EXPLAIN DELETE, ANALYZE DELETE +#------------------------------------------------------------------------ +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1; +EXPLAIN DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 Deleting all rows +ANALYZE DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 NULL NULL NULL Deleting all rows +DELETE FROM t1 WHERE a = 10; +EXPLAIN DELETE FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where +ANALYZE DELETE FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1 0.00 100.00 100.00 Using where +DELETE FROM t1 USING t1, t2; +EXPLAIN DELETE FROM t1 USING t1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE DELETE FROM t1 USING t1, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run everything: SELECT access to the column `a` +# in the underlying table is enough to show EXPLAIN +# (that's how it works now) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where +ANALYZE UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 16.00 100.00 75.00 Using where +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where +ANALYZE UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 16.00 100.00 75.00 Using where +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 16.00 100.00 0.00 Using where +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run everything: SELECT access to the column `a` +# in the underlying table is enough to show EXPLAIN +# (that's how it works now) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 60.00 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 60.00 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 0.00 Using where +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where + +#======================================================================== +# Test: Grant SELECT, INSERT, UPDATE, DELETE on the table +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the table +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO t1 (a) VALUES (10); +EXPLAIN INSERT INTO t1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO t1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO t1 SELECT * FROM t2; +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO t1 (a) VALUES (10); +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO t1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO t1 SELECT * FROM t2; +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE t1 SET a = 10; +EXPLAIN UPDATE t1 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 +ANALYZE UPDATE t1 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 24.00 100.00 100.00 +UPDATE t1 SET a = a + 1; +EXPLAIN UPDATE t1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 +ANALYZE UPDATE t1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 24.00 100.00 100.00 +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 Using where +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 24 24.00 100.00 0.00 Using where +DELETE FROM t1; +EXPLAIN DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 Deleting all rows +ANALYZE DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 NULL NULL NULL Deleting all rows +DELETE FROM t1 WHERE a = 10; +EXPLAIN DELETE FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where +ANALYZE DELETE FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1 0.00 100.00 100.00 Using where +DELETE FROM t1 USING t1, t2; +EXPLAIN DELETE FROM t1 USING t1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE DELETE FROM t1 USING t1, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t1; +a b +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found +ANALYZE SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +ANALYZE SELECT * FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where +ANALYZE UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 16.00 100.00 75.00 Using where +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where +ANALYZE UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 16.00 100.00 75.00 Using where +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 16 16.00 100.00 0.00 Using where +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +ANALYZE SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run everything +#------------------------------------------------------------------------ +# Note: some queries are commented due to MDEV-7034 +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 60.00 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 60.00 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 Using where +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 100.00 0.00 Using where +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where + +######################################################################### +# Inner view permission tests +# (we modify permissions on the inner view, keeping ALL the rest) +######################################################################### + + +#======================================================================== +# Test: No permissions on the inner view +#======================================================================== + +connection default; +GRANT ALL ON privtest_db.t1 TO 'privtest'@'localhost'; +GRANT ALL ON privtest_db.v2 TO 'privtest'@'localhost'; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Cannot run anything +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SHOW VIEW on the inner view +#======================================================================== + +connection default; +GRANT SHOW VIEW ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Cannot run anything +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (that's how it works now) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SELECT on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run SELECT, but not EXPLAIN SELECT or ANALYZE SELECT +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SELECT, SHOW VIEW on the inner view +#======================================================================== + + +#------------------------------------------------------------------------ +# Test: SELECT + SHOW VIEW privileges allow ANALYZE SELECT for the inner +# view, and ANALYZE <anything> for the outer view +#------------------------------------------------------------------------ + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT, SHOW VIEW ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run SELECT, EXPLAIN SELECT, ANALYZE SELECT +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 Using where +ANALYZE SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 14.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 Using where +ANALYZE SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 14.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 14 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 14 14.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 30 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 30 30.00 100.00 40.00 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 30 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 30 30.00 100.00 40.00 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 30 Using where +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 30 30.00 100.00 0.00 Using where +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where +ANALYZE DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where +ANALYZE DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where + +#======================================================================== +# Test: Grant INSERT on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT INSERT ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run INSERT, but not EXPLAIN INSERT or ANALYZE INSERT +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant UPDATE on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT UPDATE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run UPDATE which does not read any columns, but not +# but not EXPLAIN UPDATE or ANALYZE UPDATE +# because the query plan cannot be shown +# (it could have revealed the structure of the view). +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant UPDATE, SELECT(a) on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT(a), UPDATE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run UPDATE, but not EXPLAIN or ANALYZE for it +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SELECT, UPDATE on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT, UPDATE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run the UPDATE and SELECT queries, but not EXPLAIN +# or ANALYZE because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant DELETE on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run DELETE which does not read any columns, +# but not EXPLAIN DELETE or ANALYZE DELETE +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (it could have revealed the structure of the inner view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant DELETE, SHOW VIEW on the inner view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SHOW VIEW, DELETE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run DELETE, EXPLAIN DELETE, UPDATE DELETE +# which don't read any columns +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE INSERT INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v1' +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 29 Using where +ANALYZE DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 29 29.00 100.00 0.00 Using where +DELETE FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v1' +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v1' +ANALYZE DELETE FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v1' +DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v1' +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run the queries, but not EXPLAIN or ANALYZE +# because the query plan cannot be shown +# (that's how it works now) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SELECT, INSERT, UPDATE, DELETE, SHOW VIEW +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT, INSERT, UPDATE, DELETE, SHOW VIEW ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v1 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 47 Using where +ANALYZE UPDATE v1 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 47 47.00 100.00 25.53 Using where +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 47 Using where +ANALYZE UPDATE v1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 47 47.00 100.00 25.53 Using where +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 47 Using where +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 47 47.00 100.00 0.00 Using where +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 Using where +ANALYZE DELETE FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 Using where +ANALYZE DELETE FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 Using where +ANALYZE DELETE FROM v1 USING v1, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 Using where +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where +SELECT * FROM v1; +a b +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 Using where +ANALYZE SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 Using where +ANALYZE SELECT * FROM v1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 35 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 51 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 51 51.00 100.00 23.53 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 51 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 51 51.00 100.00 23.53 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 51 Using where +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 51 51.00 100.00 0.00 Using where +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where + +######################################################################### +# Outer view permission tests +# (we modify permissions on the outer view, keeping ALL the rest) +######################################################################### + + +#======================================================================== +# Test: No permissions on the outer view +#======================================================================== + +connection default; +GRANT ALL ON privtest_db.t1 TO 'privtest'@'localhost'; +GRANT ALL ON privtest_db.v1 TO 'privtest'@'localhost'; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Cannot run anything +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant SHOW VIEW on the outer view +#======================================================================== + +connection default; +GRANT SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Cannot run anything +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant SHOW VIEW, SELECT(a) on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT(a), SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run SELECT, EXPLAIN SELECT and ANALYZE SELECT +# when only `a` column is involved +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +SELECT a FROM v2; +a +EXPLAIN SELECT a FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE SELECT a FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT a FROM v2 WHERE a = 10; +a +EXPLAIN SELECT a FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE SELECT a FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant SELECT on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run SELECT, but not EXPLAIN SELECT or ANALYZE SELECT +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SHOW VIEW, SELECT on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT, SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run SELECT, EXPLAIN SELECT, ANALYZE SELECT +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where + +#======================================================================== +# Test: Grant INSERT on the outer view +#======================================================================== + + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT INSERT ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run INSERT, but not EXPLAIN INSERT or ANALYZE INSERT +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant UPDATE on the outer view +#======================================================================== + + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT UPDATE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run UPDATE which does not read any columns, +# but not EXPLAIN UPDATE or ANALYZE UPDATE +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2 SET a = a + 1; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant UPDATE, SHOW VIEW on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SHOW VIEW, UPDATE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the inner view +# Expectation: Can run UPDATE, EXPLAIN UPDATE, ANALYZE UPDATE +# which do not read any columns +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 43 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 43 43.00 100.00 6.98 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 43 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 43 43.00 100.00 6.98 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v2' +DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant DELETE on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run DELETE which does not read any columns, +# but not EXPLAIN DELETE or ANALYZE DELETE +# because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 'v2' +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 'v2' + +#======================================================================== +# Test: Grant DELETE, SELECT on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT, DELETE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run DELETE and SELECT, but not EXPLAIN or ANALYZE +# for them because the query plan cannot be shown +# (it could have revealed the structure of the view) +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE INSERT INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 (a) VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = 10; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +ANALYZE UPDATE v2 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 'v2' +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a = 10; +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ERROR HY000: ANALYZE/EXPLAIN/SHOW can not be issued; lacking privileges for underlying table + +#======================================================================== +# Test: Grant SELECT, INSERT, UPDATE, DELETE, SHOW VIEW on the outer view +#======================================================================== + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT, INSERT, UPDATE, DELETE, SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; +#------------------------------------------------------------------------ +# I/R/U/D/S on the outer view +# Expectation: Can run everything +#------------------------------------------------------------------------ +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE INSERT INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE INSERT INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +ANALYZE REPLACE INTO v2 (a) VALUES (10); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +ANALYZE REPLACE INTO v2 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 56 Using where +ANALYZE UPDATE v2 SET a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 56 56.00 100.00 21.43 Using where +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 56 Using where +ANALYZE UPDATE v2 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 56 56.00 100.00 21.43 Using where +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 56 Using where +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 56 56.00 100.00 0.00 Using where +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 Using where +ANALYZE DELETE FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 Using where +ANALYZE DELETE FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where +SELECT * FROM v2; +a b +EXPLAIN SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 Using where +ANALYZE SELECT * FROM v2; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a = 10; +a b +EXPLAIN SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 Using where +ANALYZE SELECT * FROM v2 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +a b +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ALL NULL NULL NULL NULL 44 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 Using where +disconnect con1; +connection default; +DROP USER 'privtest'@localhost; +USE test; +DROP DATABASE privtest_db; diff --git a/mysql-test/r/explain_json.result b/mysql-test/r/explain_json.result index c9203d50d80c1633f06417262c86301db071fcb2..1d3f8e82718cbac47f6f7dd43329143fa3402927 100644 --- a/mysql-test/r/explain_json.result +++ b/mysql-test/r/explain_json.result @@ -365,6 +365,7 @@ EXPLAIN "attached_condition": "(tbl2.b < 5)" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "(tbl2.a = tbl1.a)" } @@ -627,6 +628,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL" } } @@ -660,6 +662,7 @@ EXPLAIN "first_match": "t2" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "((t1.b = t2.b) and (t1.a = t2.a))" } @@ -696,6 +699,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "((t1.b = t2.b) and (t1.a = t2.a))" } @@ -808,6 +812,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "((t2.b <> outer_t1.a) and trigcond(((<cache>(outer_t1.a) = t1.a) or isnull(t1.a))))" } @@ -858,6 +863,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "(tbl2.b = tbl1.b)" } diff --git a/mysql-test/r/explain_json_format_partitions.result b/mysql-test/r/explain_json_format_partitions.result new file mode 100644 index 0000000000000000000000000000000000000000..6a133ff114949978a9e03eb0278a3e22187aedd3 --- /dev/null +++ b/mysql-test/r/explain_json_format_partitions.result @@ -0,0 +1,83 @@ +create table t2(a int); +insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 ( +a int not null +) partition by key(a); +insert into t1 select a from t2; +explain partitions select * from t1 where a in (2,3,4); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where +explain format=json select * from t1 where a in (2,3,4); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t1", + "partitions": ["p0"], + "access_type": "ALL", + "rows": 10, + "filtered": 100, + "attached_condition": "(t1.a in (2,3,4))" + } + } +} +analyze format=json select * from t1 where a in (2,3,4); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "partitions": ["p0"], + "access_type": "ALL", + "r_loops": 1, + "rows": 10, + "r_rows": 10, + "r_total_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 30, + "attached_condition": "(t1.a in (2,3,4))" + } + } +} +analyze format=json update t1 set a=a+10 where a in (2,3,4); +ANALYZE +{ + "query_block": { + "select_id": 1, + "table": { + "update": 1, + "table_name": "t1", + "partitions": ["p0"], + "access_type": "ALL", + "rows": 10, + "r_rows": 3, + "r_filtered": 100, + "using_io_buffer": 1, + "r_total_time_ms": "REPLACED", + "attached_condition": "(t1.a in (2,3,4))" + } + } +} +analyze format=json delete from t1 where a in (20,30,40); +ANALYZE +{ + "query_block": { + "select_id": 1, + "table": { + "delete": 1, + "table_name": "t1", + "partitions": ["p0"], + "access_type": "ALL", + "rows": 10, + "r_rows": 10, + "r_filtered": 0, + "r_total_time_ms": "REPLACED", + "attached_condition": "(t1.a in (20,30,40))" + } + } +} +drop table t1,t2; diff --git a/mysql-test/suite/rpl/r/rpl_gtid_until.result b/mysql-test/suite/rpl/r/rpl_gtid_until.result index d86b5cac78c6ba4c72be95f2ffa086759ed0c44e..c23faecc67415e6151d768ff14eb001e5fc7573d 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_until.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_until.result @@ -44,14 +44,14 @@ a 1 2 include/stop_slave.inc -START SLAVE UNTIL master_gtid_pos = "1-10-100,2-20-200"; +START SLAVE UNTIL master_gtid_pos = "1-10-100,2-20-200,0-1-300"; include/wait_for_slave_to_start.inc Using_Gtid = 'Current_Pos' Until_Condition = 'Gtid' +INSERT INTO t1 VALUES (3); +DELETE FROM t1 WHERE a=3; include/stop_slave.inc -include/start_slave.inc *** Test UNTIL condition in an earlier binlog than the start GTID. *** -include/stop_slave.inc SET gtid_domain_id = 1; INSERT INTO t1 VALUES (3); SET gtid_domain_id = 2; diff --git a/mysql-test/suite/rpl/t/rpl_gtid_until.test b/mysql-test/suite/rpl/t/rpl_gtid_until.test index 4dde7da38a51e726f5623ae28fd0157d80c7b0c1..20d4510ccc8904d9f8414ea282003ce4837fb30f 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_until.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_until.test @@ -73,19 +73,29 @@ SELECT * FROM t1 ORDER BY a; # Test showing the UNTIL condition in SHOW SLAVE STATUS. --source include/stop_slave.inc -START SLAVE UNTIL master_gtid_pos = "1-10-100,2-20-200"; +START SLAVE UNTIL master_gtid_pos = "1-10-100,2-20-200,0-1-300"; --source include/wait_for_slave_to_start.inc --let $status_items= Using_Gtid,Until_Condition --source include/show_slave_status.inc # Clear the UNTIL condition. +# Note that we need to wait for a transaction to get through from the master. +# Otherwise the IO thread may still be in get_master_version_and_clock() +# (wait_for_slave_to_start.inc returns as soon as the IO thread is connected), +# and we can get test failures from warnings in the log about IO thread being +# killed in the middle of setting @@gtid_strict_mode or similar (MDEV-7940). +--connection server_1 +INSERT INTO t1 VALUES (3); +DELETE FROM t1 WHERE a=3; +--save_master_pos + +--connection server_2 +--sync_with_master --source include/stop_slave.inc ---source include/start_slave.inc --echo *** Test UNTIL condition in an earlier binlog than the start GTID. *** --connection server_2 ---source include/stop_slave.inc --connection server_1 SET gtid_domain_id = 1; diff --git a/mysql-test/t/analyze_stmt_privileges2.test b/mysql-test/t/analyze_stmt_privileges2.test new file mode 100644 index 0000000000000000000000000000000000000000..6fcdb7d439930cc92ac39f171528f5bd3a85de44 --- /dev/null +++ b/mysql-test/t/analyze_stmt_privileges2.test @@ -0,0 +1,5400 @@ +################################################################################ +# The test ensures that permission checks are applied correctly to +# ANALYZE INSERT/REPLACE/UPDATE/DELETE/SELECT (I/R/U/D/S further in the test) +# when it's executed on a table or on a view. +# ANALYZE <query> should require both permissions needed to execute the <query>, +# and permissions needed to acquire query plan (to execute EXPLAIN <query>). +# Thus, additionally execution of the query and EXPLAIN is checked. +# See MDEV-406, MDEV-6382 +# +# Disclaimer: the goal of this test is to check permissions for ANALYZE against +# permissions for the query and EXPLAIN. +# The expected result for queries and EXPLAINs is mostly empirical. +# In many cases the current behavior is obscure and questionable, +# but unless it is obviously wrong, the expected result is adjusted +# to match it. +# In cases when the behavior is really wrong, the adjustments +# come with comments which point at the issues in the bug tracker. +# Search for 'MDEV' to find all of them. +################################################################################ + +-- source include/not_embedded.inc + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +--enable_connect_log + +CREATE DATABASE privtest_db; + +# t1 is the main base table on which we'll perform DML +# v1 is an "inner" view which selects from the base table +# v2 is an "outer" view which selects from the inner view +# t2 is an additional table for queries like INSERT .. SELECT +# and multi-table UPDATEs/DELETEs + +CREATE TABLE privtest_db.t1 (a INT, b VARCHAR(3)) ENGINE=MyISAM; +CREATE TABLE privtest_db.t2 (a INT, b VARCHAR(3)) ENGINE=MyISAM; +CREATE VIEW privtest_db.v1 AS SELECT a, b FROM privtest_db.t1 WHERE b IS NOT NULL; +CREATE VIEW privtest_db.v2 AS SELECT * FROM privtest_db.v1 WHERE a > 0; + +INSERT INTO privtest_db.t2 VALUES (1,'foo'), (2,'bar'), (3,'qux'); + +GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost'; + +connect(con1,localhost,privtest,,privtest_db); + +--echo +--echo ######################################################################### +--echo # Underlying table permission tests +--echo # (we modify permissions on the base table, keeping ALL on views) +--echo ######################################################################### +--echo + +connection default; +GRANT ALL ON privtest_db.v1 TO 'privtest'@'localhost'; +GRANT ALL ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + +--echo +--echo #======================================================================== +--echo # Test: No permissions on the table +--echo #======================================================================== +--echo + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Cannot run query, EXPLAIN, ANALYZE on the table +--echo # because the query itself cannot be executed +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + +INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT on the table +--echo #======================================================================== +--echo + +connection default; +GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Can only run SELECT, EXPLAIN SELECT, ANALYZE SELECT +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +SELECT * FROM t1; +EXPLAIN SELECT * FROM t1; +ANALYZE SELECT * FROM t1; + +SELECT * FROM t1 WHERE a = 10; +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ANALYZE SELECT * FROM t1 WHERE a = 10; + +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +EXPLAIN SELECT * FROM v1; +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +# Commented due to MDEV-7034 (assertion failure) +# EXPLAIN DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Commented due to MDEV-7034 (assertion failure) +# EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant INSERT on the table +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Can only run INSERT, EXPLAIN INSERT, ANALYZE INSERT +--echo #------------------------------------------------------------------------ + +INSERT INTO t1 (a) VALUES (10); +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ANALYZE INSERT INTO t1 (a) VALUES (10); + +INSERT INTO t1 SELECT * FROM t2; +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + +INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant UPDATE on the table +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Can only run UPDATE, EXPLAIN UPDATE, ANALYZE UPDATE +--echo # when the UPDATE does not read any columns. UPDATEs which +--echo # read columns fail with ER_COLUMNACCESS_DENIED_ERROR +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +UPDATE t1 SET a = 10; +EXPLAIN UPDATE t1 SET a = 10; +ANALYZE UPDATE t1 SET a = 10; + +--error ER_COLUMNACCESS_DENIED_ERROR +UPDATE t1 SET a = a + 1; +--error ER_COLUMNACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = a + 1; +--error ER_COLUMNACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = a + 1; + +--error ER_COLUMNACCESS_DENIED_ERROR +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_COLUMNACCESS_DENIED_ERROR +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_COLUMNACCESS_DENIED_ERROR +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + +INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant DELETE on the table +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Can only run DELETE, EXPLAIN DELETE, ANALYZE DELETE +--echo # when the DELETE does not read any columns. DELETEs which +--echo # read columns fail with ER_COLUMNACCESS_DENIED_ERROR +--echo #------------------------------------------------------------------------ +--echo # Note: ANALYZE DELETE FROM t1 USING t1, t2 ... fails due to MDEV-7043 + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +DELETE FROM t1; +EXPLAIN DELETE FROM t1; +ANALYZE DELETE FROM t1; + +--error ER_COLUMNACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a = 10; +--error ER_COLUMNACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 WHERE a = 10; +--error ER_COLUMNACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 WHERE a = 10; + +# Unexpected errors due to MDEV-7043 (expected all three to succeed) +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2; + +# Unexpected error code due to MDEV-7043 +#--error ER_COLUMNACCESS_DENIED_ERROR +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it would have revealed the structure of the table) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant DELETE, SELECT(a) on the table +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT SELECT(a), DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Can run DELETE, EXPLAIN DELETE, ANALYZE DELETE +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +DELETE FROM t1; +EXPLAIN DELETE FROM t1; +ANALYZE DELETE FROM t1; + +DELETE FROM t1 WHERE a = 10; +EXPLAIN DELETE FROM t1 WHERE a = 10; +ANALYZE DELETE FROM t1 WHERE a = 10; + +DELETE FROM t1 USING t1, t2; +EXPLAIN DELETE FROM t1 USING t1, t2; +ANALYZE DELETE FROM t1 USING t1, t2; + +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run everything: SELECT access to the column `a` +--echo # in the underlying table is enough to show EXPLAIN +--echo # (that's how it works now) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +EXPLAIN SELECT * FROM v1; +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run everything: SELECT access to the column `a` +--echo # in the underlying table is enough to show EXPLAIN +--echo # (that's how it works now) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +EXPLAIN DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT, INSERT, UPDATE, DELETE on the table +--echo #======================================================================== +--echo + + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the table +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO t1 (a) VALUES (10); +EXPLAIN INSERT INTO t1 (a) VALUES (10); +ANALYZE INSERT INTO t1 (a) VALUES (10); + +INSERT INTO t1 SELECT * FROM t2; +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ANALYZE INSERT INTO t1 SELECT * FROM t2; + +REPLACE INTO t1 (a) VALUES (10); +EXPLAIN REPLACE INTO t1 (a) VALUES (10); +ANALYZE REPLACE INTO t1 (a) VALUES (10); + +REPLACE INTO t1 SELECT * FROM t2; +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ANALYZE REPLACE INTO t1 SELECT * FROM t2; + +UPDATE t1 SET a = 10; +EXPLAIN UPDATE t1 SET a = 10; +ANALYZE UPDATE t1 SET a = 10; + +UPDATE t1 SET a = a + 1; +EXPLAIN UPDATE t1 SET a = a + 1; +ANALYZE UPDATE t1 SET a = a + 1; + +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ANALYZE UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; + +DELETE FROM t1; +EXPLAIN DELETE FROM t1; +ANALYZE DELETE FROM t1; + +DELETE FROM t1 WHERE a = 10; +EXPLAIN DELETE FROM t1 WHERE a = 10; +ANALYZE DELETE FROM t1 WHERE a = 10; + +DELETE FROM t1 USING t1, t2; +EXPLAIN DELETE FROM t1 USING t1, t2; +ANALYZE DELETE FROM t1 USING t1, t2; + +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ANALYZE DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; + +SELECT * FROM t1; +EXPLAIN SELECT * FROM t1; +ANALYZE SELECT * FROM t1; + +SELECT * FROM t1 WHERE a = 10; +EXPLAIN SELECT * FROM t1 WHERE a = 10; +ANALYZE SELECT * FROM t1 WHERE a = 10; + +SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +EXPLAIN SELECT * FROM v1; +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ +--echo # Note: some queries are commented due to MDEV-7034 + +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo ######################################################################### +--echo # Inner view permission tests +--echo # (we modify permissions on the inner view, keeping ALL the rest) +--echo ######################################################################### +--echo + + +--echo +--echo #======================================================================== +--echo # Test: No permissions on the inner view +--echo #======================================================================== +--echo + +connection default; +GRANT ALL ON privtest_db.t1 TO 'privtest'@'localhost'; +GRANT ALL ON privtest_db.v2 TO 'privtest'@'localhost'; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Cannot run anything +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant SHOW VIEW on the inner view +--echo #======================================================================== +--echo + +connection default; +GRANT SHOW VIEW ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Cannot run anything +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (that's how it works now) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run SELECT, but not EXPLAIN SELECT or ANALYZE SELECT +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +# Strange error code due to MDEV-7033 +# --error ER_TABLEACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT, SHOW VIEW on the inner view +--echo #======================================================================== +--echo + +--echo +--echo #------------------------------------------------------------------------ +--echo # Test: SELECT + SHOW VIEW privileges allow ANALYZE SELECT for the inner +--echo # view, and ANALYZE <anything> for the outer view +--echo #------------------------------------------------------------------------ +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT, SHOW VIEW ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run SELECT, EXPLAIN SELECT, ANALYZE SELECT +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +EXPLAIN SELECT * FROM v1; +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant INSERT on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT INSERT ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run INSERT, but not EXPLAIN INSERT or ANALYZE INSERT +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant UPDATE on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT UPDATE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run UPDATE which does not read any columns, but not +--echo # but not EXPLAIN UPDATE or ANALYZE UPDATE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view). +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +# Wrong result due to MDEV-7042 +#--error ER_COLUMNACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +# Strange error code due to MDEV-7042 +#--error ER_COLUMNACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_COLUMNACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +# Strange error code due to MDEV-7033, MDEV-7042 +#--error ER_COLUMNACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant UPDATE, SELECT(a) on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT(a), UPDATE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run UPDATE, but not EXPLAIN or ANALYZE for it +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT, UPDATE on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT, UPDATE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run the UPDATE and SELECT queries, but not EXPLAIN +--echo # or ANALYZE because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant DELETE on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run DELETE which does not read any columns, +--echo # but not EXPLAIN DELETE or ANALYZE DELETE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1; + +--error ER_COLUMNACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +# Strange error code due to MDEV-7033 +#--error ER_COLUMNACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v1 WHERE a = 10; + +# Unexpected error due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the inner view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant DELETE, SHOW VIEW on the inner view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SHOW VIEW, DELETE ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run DELETE, EXPLAIN DELETE, UPDATE DELETE +--echo # which don't read any columns +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ANALYZE DELETE FROM v1; + +--error ER_COLUMNACCESS_DENIED_ERROR +DELETE FROM v1 WHERE a = 10; +--error ER_COLUMNACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 WHERE a = 10; +--error ER_COLUMNACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 WHERE a = 10; + +# Unexpected error due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v1 USING v1, t2; +# Unexpected error due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2; +# Unexpected error due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2; + +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run the queries, but not EXPLAIN or ANALYZE +--echo # because the query plan cannot be shown +--echo # (that's how it works now) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT, INSERT, UPDATE, DELETE, SHOW VIEW +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v1 FROM 'privtest'@'localhost'; +GRANT SELECT, INSERT, UPDATE, DELETE, SHOW VIEW ON privtest_db.v1 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v1 (a) VALUES (10); +EXPLAIN INSERT INTO v1 (a) VALUES (10); +ANALYZE INSERT INTO v1 (a) VALUES (10); + +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ANALYZE INSERT INTO v1 SELECT * FROM t2; + +REPLACE INTO v1 (a) VALUES (10); +EXPLAIN REPLACE INTO v1 (a) VALUES (10); +ANALYZE REPLACE INTO v1 (a) VALUES (10); + +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ANALYZE REPLACE INTO v1 SELECT * FROM t2; + +UPDATE v1 SET a = 10; +EXPLAIN UPDATE v1 SET a = 10; +ANALYZE UPDATE v1 SET a = 10; + +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1 SET a = a + 1; +ANALYZE UPDATE v1 SET a = a + 1; + +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ANALYZE UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; + +DELETE FROM v1; +EXPLAIN DELETE FROM v1; +ANALYZE DELETE FROM v1; + +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ANALYZE DELETE FROM v1 WHERE a = 10; + +DELETE FROM v1 USING v1, t2; +EXPLAIN DELETE FROM v1 USING v1, t2; +ANALYZE DELETE FROM v1 USING v1, t2; + +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ANALYZE DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; + +SELECT * FROM v1; +EXPLAIN SELECT * FROM v1; +ANALYZE SELECT * FROM v1; + +SELECT * FROM v1 WHERE a = 10; +EXPLAIN SELECT * FROM v1 WHERE a = 10; +ANALYZE SELECT * FROM v1 WHERE a = 10; + +SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + + +--echo +--echo ######################################################################### +--echo # Outer view permission tests +--echo # (we modify permissions on the outer view, keeping ALL the rest) +--echo ######################################################################### +--echo + +--echo +--echo #======================================================================== +--echo # Test: No permissions on the outer view +--echo #======================================================================== +--echo + +connection default; +GRANT ALL ON privtest_db.t1 TO 'privtest'@'localhost'; +GRANT ALL ON privtest_db.v1 TO 'privtest'@'localhost'; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Cannot run anything +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant SHOW VIEW on the outer view +--echo #======================================================================== +--echo + +connection default; +GRANT SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Cannot run anything +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SHOW VIEW, SELECT(a) on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT(a), SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run SELECT, EXPLAIN SELECT and ANALYZE SELECT +--echo # when only `a` column is involved +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT a FROM v2; +EXPLAIN SELECT a FROM v2; +ANALYZE SELECT a FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT a FROM v2 WHERE a = 10; +EXPLAIN SELECT a FROM v2 WHERE a = 10; +ANALYZE SELECT a FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run SELECT, but not EXPLAIN SELECT or ANALYZE SELECT +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +# Strange error code due to MDEV-7033, MDEV-7042 +# --error ER_TABLEACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant SHOW VIEW, SELECT on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT, SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run SELECT, EXPLAIN SELECT, ANALYZE SELECT +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant INSERT on the outer view +--echo #======================================================================== +--echo +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT INSERT ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run INSERT, but not EXPLAIN INSERT or ANALYZE INSERT +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +--echo +--echo #======================================================================== +--echo # Test: Grant UPDATE on the outer view +--echo #======================================================================== +--echo +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT UPDATE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run UPDATE which does not read any columns, +--echo # but not EXPLAIN UPDATE or ANALYZE UPDATE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = 10; + +# Wrong result due to MDEV-7042 +# --error ER_COLUMNACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +# Strange error code due to MDEV-7042 +#--error ER_COLUMNACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_COLUMNACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +# Strange error code due to MDEV-7042 +# --error ER_COLUMNACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant UPDATE, SHOW VIEW on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SHOW VIEW, UPDATE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the inner view +--echo # Expectation: Can run UPDATE, EXPLAIN UPDATE, ANALYZE UPDATE +--echo # which do not read any columns +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +# Wrong result due to MDEV-7042 +# --error ER_COLUMNACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +# Wrong result due to MDEV-7042 +# --error ER_COLUMNACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +# Wrong result due to MDEV-7042 +# --error ER_COLUMNACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_COLUMNACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_COLUMNACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_COLUMNACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant DELETE on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run DELETE which does not read any columns, +--echo # but not EXPLAIN DELETE or ANALYZE DELETE +--echo # because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +--error ER_COLUMNACCESS_DENIED_ERROR +DELETE FROM v2 WHERE a = 10; +# Strange error code due to MDEV-7042, MDEV-7033 +# --error ER_COLUMNACCESS_DENIED_ERROR +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +# Unexpected error due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2; +# Unexpected error code due to MDEV-7043 +# --error ER_VIEW_NO_EXPLAIN +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2; +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2; + +# Unexpected error due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Unexpected error code due to MDEV-7043 +# --error ER_VIEW_NO_EXPLAIN +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Unexpected error code due to MDEV-7043 +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant DELETE, SELECT on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT, DELETE ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run DELETE and SELECT, but not EXPLAIN or ANALYZE +--echo # for them because the query plan cannot be shown +--echo # (it could have revealed the structure of the view) +--echo #------------------------------------------------------------------------ + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +--error ER_TABLEACCESS_DENIED_ERROR +REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = 10; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = 10; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +EXPLAIN UPDATE v2 SET a = a + 1; +--error ER_TABLEACCESS_DENIED_ERROR +ANALYZE UPDATE v2 SET a = a + 1; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +# Strange error code due to MDEV-7033 +--error ER_VIEW_NO_EXPLAIN +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +--error ER_VIEW_NO_EXPLAIN +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a = 10; +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +--error ER_VIEW_NO_EXPLAIN +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + +--echo +--echo #======================================================================== +--echo # Test: Grant SELECT, INSERT, UPDATE, DELETE, SHOW VIEW on the outer view +--echo #======================================================================== +--echo + +connection default; +REVOKE ALL PRIVILEGES ON privtest_db.v2 FROM 'privtest'@'localhost'; +GRANT SELECT, INSERT, UPDATE, DELETE, SHOW VIEW ON privtest_db.v2 TO 'privtest'@'localhost'; +connection con1; + + +--echo #------------------------------------------------------------------------ +--echo # I/R/U/D/S on the outer view +--echo # Expectation: Can run everything +--echo #------------------------------------------------------------------------ + +INSERT INTO v2 (a) VALUES (10); +EXPLAIN INSERT INTO v2 (a) VALUES (10); +ANALYZE INSERT INTO v2 (a) VALUES (10); + +INSERT INTO v2 SELECT * FROM t2; +# Commented due to MDEV-7034 +EXPLAIN INSERT INTO v2 SELECT * FROM t2; +ANALYZE INSERT INTO v2 SELECT * FROM t2; + +REPLACE INTO v2 (a) VALUES (10); +EXPLAIN REPLACE INTO v2 (a) VALUES (10); +ANALYZE REPLACE INTO v2 (a) VALUES (10); + +REPLACE INTO v2 SELECT * FROM t2; +EXPLAIN REPLACE INTO v2 SELECT * FROM t2; +ANALYZE REPLACE INTO v2 SELECT * FROM t2; + +UPDATE v2 SET a = 10; +EXPLAIN UPDATE v2 SET a = 10; +ANALYZE UPDATE v2 SET a = 10; + +UPDATE v2 SET a = a + 1; +EXPLAIN UPDATE v2 SET a = a + 1; +ANALYZE UPDATE v2 SET a = a + 1; + +UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +EXPLAIN UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; +ANALYZE UPDATE v2, t2 SET v2.a = v2.a + 1 WHERE v2.a = t2.a; + +DELETE FROM v2; +EXPLAIN DELETE FROM v2; +ANALYZE DELETE FROM v2; + +DELETE FROM v2 WHERE a = 10; +EXPLAIN DELETE FROM v2 WHERE a = 10; +ANALYZE DELETE FROM v2 WHERE a = 10; + +DELETE FROM v2 USING v2, t2; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2; +ANALYZE DELETE FROM v2 USING v2, t2; + +DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +# Commented due to MDEV-7034 +# EXPLAIN DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; +ANALYZE DELETE FROM v2 USING v2, t2 WHERE v2.a = t2.a; + +SELECT * FROM v2; +EXPLAIN SELECT * FROM v2; +ANALYZE SELECT * FROM v2; + +SELECT * FROM v2 WHERE a = 10; +EXPLAIN SELECT * FROM v2 WHERE a = 10; +ANALYZE SELECT * FROM v2 WHERE a = 10; + +SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); +ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); + + +################################################################################################ +disconnect con1; +connection default; + +DROP USER 'privtest'@localhost; +USE test; +DROP DATABASE privtest_db; + +--source include/wait_until_count_sessions.inc + + diff --git a/mysql-test/t/explain_json_format_partitions.test b/mysql-test/t/explain_json_format_partitions.test new file mode 100644 index 0000000000000000000000000000000000000000..f3567797019adeb5245c12120764c84c1b2e89cc --- /dev/null +++ b/mysql-test/t/explain_json_format_partitions.test @@ -0,0 +1,17 @@ + +--source include/have_partition.inc +create table t2(a int); +insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 ( + a int not null +) partition by key(a); +insert into t1 select a from t2; +explain partitions select * from t1 where a in (2,3,4); +explain format=json select * from t1 where a in (2,3,4); +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json select * from t1 where a in (2,3,4); +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json update t1 set a=a+10 where a in (2,3,4); +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json delete from t1 where a in (20,30,40); +drop table t1,t2; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index b149747649e8fa2a8d98042066307d69ceb1d255..b72f552441ba95329403590d9cbefbb2d77dec3b 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -121,7 +121,8 @@ void Update_plan::save_explain_data_intern(MEM_ROOT *mem_root, partition_info *part_info; if ((part_info= table->part_info)) { - make_used_partitions_str(part_info, &explain->used_partitions); + make_used_partitions_str(mem_root, part_info, &explain->used_partitions, + explain->used_partitions_list); explain->used_partitions_set= true; } else diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 3c1ebc288ab21e335ccb02d36f527633d6ab278c..89df39c180caba1165da54c555687f9d065e16c3 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -37,6 +37,18 @@ Explain_query::Explain_query(THD *thd_arg, MEM_ROOT *root) : { } +static void print_json_array(Json_writer *writer, + const char *title, String_list &list) +{ + List_iterator_fast<char> it(list); + const char *name; + writer->add_member(title).start_array(); + while ((name= it++)) + writer->add_str(name); + writer->end_array(); +} + + Explain_query::~Explain_query() { @@ -1276,17 +1288,9 @@ void add_json_keyset(Json_writer *writer, const char *elem_name, String_list *keyset) { if (!keyset->is_empty()) - { - List_iterator_fast<char> it(*keyset); - const char *name; - writer->add_member(elem_name).start_array(); - while ((name= it++)) - writer->add_str(name); - writer->end_array(); - } + print_json_array(writer, elem_name, *keyset); } - /* @param fs_tracker Normally NULL. When not NULL, it means that the join tab used filesort. @@ -1345,7 +1349,10 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->add_member("table").start_object(); writer->add_member("table_name").add_str(table_name); - // partitions + + if (used_partitions_set) + print_json_array(writer, "partitions", used_partitions_list); + writer->add_member("access_type").add_str(join_type_str[type]); add_json_keyset(writer, "possible_keys", &possible_keys); @@ -1374,14 +1381,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, parts_list= &key.key_parts_list; if (parts_list && !parts_list->is_empty()) - { - List_iterator_fast<char> it(*parts_list); - const char *name; - writer->add_member("used_key_parts").start_array(); - while ((name= it++)) - writer->add_str(name); - writer->end_array(); - } + print_json_array(writer, "used_key_parts", *parts_list); if (quick_info && !quick_info->is_basic()) { @@ -1392,14 +1392,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, /* `ref` */ if (!ref_list.is_empty()) - { - List_iterator_fast<char> it(ref_list); - const char *str; - writer->add_member("ref").start_array(); - while ((str= it++)) - writer->add_str(str); - writer->end_array(); - } + print_json_array(writer, "ref", ref_list); /* r_loops (not present in tabular output) */ if (is_analyze) @@ -1480,6 +1473,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->end_object(); // "block-nl-join" writer->add_member("buffer_type").add_str(bka_type.incremental? "incremental":"flat"); + writer->add_member("buffer_size").add_size(bka_type.join_buffer_size); writer->add_member("join_type").add_str(bka_type.join_alg); if (bka_type.mrr_type.length()) writer->add_member("mrr_type").add_str(bka_type.mrr_type); @@ -1673,13 +1667,8 @@ void Explain_quick_select::print_json(Json_writer *writer) writer->add_member("range").start_object(); writer->add_member("key").add_str(range.get_key_name()); - - List_iterator_fast<char> it(range.key_parts_list); - const char *name; - writer->add_member("used_key_parts").start_array(); - while ((name= it++)) - writer->add_str(name); - writer->end_array(); + + print_json_array(writer, "used_key_parts", range.key_parts_list); writer->end_object(); } @@ -1990,6 +1979,10 @@ void Explain_update::print_explain_json(Explain_query *query, writer->add_member("delete").add_ll(1); writer->add_member("table_name").add_str(table_name); + + if (used_partitions_set) + print_json_array(writer, "partitions", used_partitions_list); + writer->add_member("access_type").add_str(join_type_str[jtype]); if (!possible_keys.is_empty()) diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 2513e03cf1cdfa48c96c336b4c0f99ddcf11acdf..61720ca8d766caea0fc9e9d9a7e47a0e6e461ee3 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -51,6 +51,9 @@ it into the slow query log. */ +#ifndef SQL_EXPLAIN_INCLUDED +#define SQL_EXPLAIN_INCLUDED + class String_list: public List<char> { public: @@ -471,6 +474,8 @@ class EXPLAIN_BKA_TYPE public: EXPLAIN_BKA_TYPE() : join_alg(NULL) {} + size_t join_buffer_size; + bool incremental; /* @@ -609,6 +614,7 @@ public: /* id and 'select_type' are cared-of by the parent Explain_select */ StringBuffer<32> table_name; StringBuffer<32> used_partitions; + String_list used_partitions_list; // valid with ET_USING_MRR StringBuffer<32> mrr_type; StringBuffer<32> firstmatch_table_name; @@ -732,6 +738,7 @@ public: const char *select_type; StringBuffer<32> used_partitions; + String_list used_partitions_list; bool used_partitions_set; bool impossible_where; @@ -842,3 +849,4 @@ public: }; +#endif //SQL_EXPLAIN_INCLUDED diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index cec0755c9b0359139ab68b7d77864ea017274986..23357ac871d3dd57dc972670109f87f7976f00d2 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2582,6 +2582,8 @@ void JOIN_CACHE::save_explain_data(EXPLAIN_BKA_TYPE *explain) { explain->incremental= MY_TEST(prev_cache); + explain->join_buffer_size= get_join_buffer_size(); + switch (get_join_alg()) { case BNL_JOIN_ALG: explain->join_alg= "BNL"; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 555ee2a3f40a72df1efde6d67ab1e798fff78825..a930e983dd67258875b2091299ccc8f104b22844 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -68,6 +68,7 @@ // mysql_*_alter_copy_data #include "opt_range.h" // store_key_image_to_rec #include "sql_alter.h" // Alter_table_ctx +#include "sql_select.h" #include <algorithm> using std::max; @@ -7290,8 +7291,10 @@ void mem_alloc_error(size_t size) /** Return comma-separated list of used partitions in the provided given string. + @param mem_root Where to allocate following list @param part_info Partitioning info @param[out] parts The resulting list of string to fill + @param[out] used_partitions_list result list to fill Generate a list of used partitions (from bits in part_info->read_partitions bitmap), and store it into the provided String object. @@ -7302,7 +7305,10 @@ void mem_alloc_error(size_t size) that was written or locked. */ -void make_used_partitions_str(partition_info *part_info, String *parts_str) +void make_used_partitions_str(MEM_ROOT *alloc, + partition_info *part_info, + String *parts_str, + String_list &used_partitions_list) { parts_str->length(0); partition_element *pe; @@ -7321,6 +7327,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) { if (parts_str->length()) parts_str->append(','); + uint index= parts_str->length(); parts_str->append(head_pe->partition_name, strlen(head_pe->partition_name), system_charset_info); @@ -7328,6 +7335,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) parts_str->append(pe->partition_name, strlen(pe->partition_name), system_charset_info); + used_partitions_list.append_str(alloc, parts_str->ptr() + index); } partition_id++; } @@ -7341,6 +7349,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) { if (parts_str->length()) parts_str->append(','); + used_partitions_list.append_str(alloc, pe->partition_name); parts_str->append(pe->partition_name, strlen(pe->partition_name), system_charset_info); } diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 5da132661c99d67d911bbe32bf436aeb4b1e6dab..ff6596fffaaa2cb9067dd54ff4aa31702a13553b 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -74,6 +74,7 @@ typedef struct { uint32 end_part; } part_id_range; +class String_list; struct st_partition_iter; #define NOT_A_PARTITION_ID UINT_MAX32 @@ -114,7 +115,9 @@ bool mysql_unpack_partition(THD *thd, char *part_buf, TABLE *table, bool is_create_table_ind, handlerton *default_db_type, bool *work_part_info_used); -void make_used_partitions_str(partition_info *part_info, String *parts_str); +void make_used_partitions_str(MEM_ROOT *mem_root, + partition_info *part_info, String *parts_str, + String_list &used_partitions_list); uint32 get_list_array_idx_for_endpoint(partition_info *part_info, bool left_endpoint, bool include_endpoint); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e7c2e91a15c5c3a5fd4af2ba8085610fc798b519..a49d5b05bdd94f682e5957544cb17644d048c743 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -23503,8 +23503,9 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab partition_info *part_info; if (!table->derived_select_number && (part_info= table->part_info)) - { - make_used_partitions_str(part_info, &eta->used_partitions); + { //TODO: all thd->mem_root here should be fixed + make_used_partitions_str(thd->mem_root, part_info, &eta->used_partitions, + eta->used_partitions_list); eta->used_partitions_set= true; } else diff --git a/sql/sql_update.cc b/sql/sql_update.cc index cf6a0f0f1401d1460e6e33f1a2a00683a0026740..830d26fd62e2ffc49a4393767ec60ef494b415bb 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -517,7 +517,7 @@ int mysql_update(THD *thd, */ if (thd->lex->describe) goto produce_explain_and_leave; - explain= query_plan.save_explain_update_data(thd->mem_root, thd); + explain= query_plan.save_explain_update_data(query_plan.mem_root, thd); ANALYZE_START_TRACKING(&explain->command_tracker); @@ -1052,7 +1052,7 @@ produce_explain_and_leave: We come here for various "degenerate" query plans: impossible WHERE, no-partitions-used, impossible-range, etc. */ - query_plan.save_explain_update_data(thd->mem_root, thd); + query_plan.save_explain_update_data(query_plan.mem_root, thd); emit_explain_and_leave: int err2= thd->lex->explain->send_explain(thd);