diff options
Diffstat (limited to 'mysql-test/t')
94 files changed, 8266 insertions, 253 deletions
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index ab1fb4e4c54..8a4ad35765c 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -1697,3 +1697,19 @@ INSERT INTO t1 SELECT a.* FROM t1 a, t1 b, t1 c, t1 d, t1 e; ALTER TABLE t1 MODIFY i FLOAT; DROP TABLE t1; +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-7816 ALTER with DROP INDEX and ADD INDEX .. COMMENT='comment2' ignores the new comment +--echo # +CREATE TABLE t1(a INT); +CREATE INDEX i1 ON t1(a) COMMENT 'comment1'; +ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2'; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # Start of 10.1 tests +--echo # diff --git a/mysql-test/t/alter_table_online.test b/mysql-test/t/alter_table_online.test index be8037abe11..20dbfe9c46a 100644 --- a/mysql-test/t/alter_table_online.test +++ b/mysql-test/t/alter_table_online.test @@ -7,7 +7,7 @@ drop table if exists t1,t2,t3; --enable_warnings # -# Test of things that can be done online +# Test of things that can not be done online # create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b')); @@ -24,6 +24,13 @@ alter online table t1 comment "new comment"; --error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 rename to t2; +# No OPs + +alter online table t1 algorithm=INPLACE, lock=NONE; +alter online table t1; +alter table t1 algorithm=INPLACE; +alter table t1 lock=NONE; + drop table t1; # diff --git a/mysql-test/t/analyze_format_json.test b/mysql-test/t/analyze_format_json.test index 7f7ea3d806e..816d83a62f0 100644 --- a/mysql-test/t/analyze_format_json.test +++ b/mysql-test/t/analyze_format_json.test @@ -9,30 +9,144 @@ create table t0 (a int); INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); --echo # r_filtered=30%, because 3 rows match: 0,1,2 +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t0 where a<3; create table t1 (a int, b int, c int, key(a)); insert into t1 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze select * from t0, t1 where t1.a=t0.a and t0.a > 9; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t0, t1 where t1.a=t0.a and t0.a > 9; analyze select * from t0, t1 where t1.a=t0.a and t1.b<4; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t0, t1 where t1.a=t0.a and t1.b<4; analyze select * from t1 tbl1, t1 tbl2 where tbl1.b<2 and tbl2.b>5; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c; drop table t1; drop table t0; + +--echo # +--echo # MDEV-7674: ANALYZE shows r_rows=0 +--echo # + +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t2 (a int, key(a)); +insert into t2 values (0),(1); + +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json select * from t1 straight_join t2 force index(a) where t2.a=t1.a; + +drop table t1,t2; + +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +--echo # +--echo # MDEV-7679: ANALYZE crashes when printing WHERE when no default db +--echo # + +select database(); +connect (con1,localhost,root,,*NO-ONE*); +connection con1; +select database(); +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json select * from test.t1 where t1.a<5; +disconnect con1; +connection default; +drop table t1; + + +--echo # +--echo # MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print +--echo # the r_total_time_ms +--echo # + +create table t2(a int); +insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t3(a int); +insert into t3 select A.a + B.a* 10 + C.a * 100 from t2 A, t2 B, t2 C; + +create table t1 (pk int primary key); +insert into t1 select a from t3; +alter table t1 add b int; + +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +update t1 set b=pk; + +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +select * from t1 where pk < 10 and b > 4; + +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +delete from t1 where pk < 10 and b > 4; + +drop table t1, t3, t2; + +--echo # +--echo # MDEV-7833:ANALYZE FORMAT=JSON and Range checked for each record +--echo # +create table t3(a int); +insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t4(a int); +insert into t4 select A.a + B.a* 10 + C.a * 100 from t3 A, t3 B, t3 C; + +create table t1 (lb1 int, rb1 int, lb2 int, rb2 int, c1 int, c2 int); + +insert into t1 values (1,2,10,20,15,15); +insert into t1 values (3,5,10,20,15,15); +insert into t1 values (10,20,10,20,15,15); +insert into t1 values (10,20,1,2,15,15); +insert into t1 values (10,20,10,20,1,3); + +create table t2 (key1 int, key2 int, key3 int, key4 int, col1 int, + key(key1), key(key2), key(key3), key(key4)); +insert into t2 select a,a,a,a,a from t3; +insert into t2 select 15,15,15,15,15 from t4; + +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +select * from t1, t2 where (t2.key1 between t1.lb1 and t1.rb1) and + (t2.key2 between t1.lb2 and t1.rb2) and + (t2.key3=t1.c1 OR t2.key4=t1.c2); + +drop table t1,t2,t3,t4; + +--echo # +--echo # MDEV-7904: ANALYZE FORMAT=JSON SELECT .. UNION SELECT doesn't print r_rows for union output +--echo # +create table t0 (a int); +INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (a int); +INSERT INTO t1 select * from t0; + +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json (select * from t1 tbl1 where a<5) union (select * from t1 tbl2 where a in (2,3)); + +drop table t0, t1; + + diff --git a/mysql-test/t/analyze_stmt.test b/mysql-test/t/analyze_stmt.test index 4da16cf6474..d02139fe0c8 100644 --- a/mysql-test/t/analyze_stmt.test +++ b/mysql-test/t/analyze_stmt.test @@ -244,3 +244,32 @@ create table t1(a int); prepare stmt from "analyze select * from t1"; execute stmt; drop table t1; + +--echo # +--echo # MDEV-7674: ANALYZE shows r_rows=0 +--echo # + +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t2 (a int, key(a)); +insert into t2 values (0),(1); + +analyze select * from t1 straight_join t2 force index(a) where t2.a=t1.a; + +drop table t1,t2; + +--echo # +--echo # MDEV-8063: Unconditional ANALYZE DELETE does not delete rows +--echo # + +create table t1 (i int); +insert into t1 values (1),(2); +analyze delete from t1; +select * from t1; + +insert into t1 values (1),(2); +explain delete from t1; +select * from t1; + +drop table t1; diff --git a/mysql-test/t/analyze_stmt_orderby.test b/mysql-test/t/analyze_stmt_orderby.test new file mode 100644 index 00000000000..baddef3566c --- /dev/null +++ b/mysql-test/t/analyze_stmt_orderby.test @@ -0,0 +1,73 @@ + +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1(a int); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; + +create table t2 ( + a int, + b int, + key (a) +); + +insert into t2 select A.a*1000 + B.a, A.a*1000 + B.a from t0 A, t1 B; + +--echo # +--echo # Try an UPDATE that uses filesort: +--echo # +explain +update t2 set b=b+1 order by b limit 5; +explain format=json +update t2 set b=b+1 order by b limit 5; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +update t2 set b=b+1 order by b limit 5; + +--echo # +--echo # Try an UPDATE that uses buffering: +--echo # +explain +update t2 set a=a+1 where a<10; +explain format=json +update t2 set a=a+1 where a<10; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +update t2 set a=a+1 where a<10; + +--echo # +--echo # Try a DELETE that uses filesort: +--echo # +explain +delete from t2 order by b limit 5; +explain format=json +delete from t2 order by b limit 5; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ /"r_buffer_size": "[^"]+"/"r_buffer_size": "REPLACED"/ +analyze format=json +delete from t2 order by b limit 5; + +--echo # +--echo # Try a SELECT with QEP in form: filesort { tmp_table { join } } +--echo # +explain +select * from t0,t2 where t2.a=t0.a order by t2.b limit 4; +explain format=json +select * from t0,t2 where t2.a=t0.a order by t2.b limit 4; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json +select * from t0,t2 where t2.a=t0.a order by t2.b limit 4; + + +--echo # +--echo # Try a SELECT with QEP in form: join { filesort { table0 }, table2 } +--echo # +explain +select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; +explain format=json +select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ /"r_buffer_size": "[^"]+"/"r_buffer_size": "REPLACED"/ +analyze format=json +select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; + +drop table t2; +drop table t0, t1; diff --git a/mysql-test/t/analyze_stmt_privileges.test b/mysql-test/t/analyze_stmt_privileges.test new file mode 100644 index 00000000000..9dd8f274fce --- /dev/null +++ b/mysql-test/t/analyze_stmt_privileges.test @@ -0,0 +1,49 @@ +# Analyze <statement> privilege checks testcase. +--source include/not_embedded.inc + +--echo # +--echo # MDEV-7025 and MDEV-7027 ANALYZE SELECT/INSERT/UPDATE/DELETE from a +--echo # view does not check access permissions on the underlying table +--echo # +--enable_connect_log +create database db; +use db; +create table t1 (i int, c varchar(8)); +insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux'); +create view v1 as select * from t1 where i > 1; +grant ALL on db.v1 to u1@localhost; + +--connect (con1,localhost,u1,,) + +--error ER_TABLEACCESS_DENIED_ERROR +select * from db.t1; +--error ER_TABLEACCESS_DENIED_ERROR +explain select * from db.t1; +--error ER_TABLEACCESS_DENIED_ERROR +analyze select * from db.t1; + +--sorted_result +select * from db.v1; +--error ER_VIEW_NO_EXPLAIN +explain select * from db.v1; +--error ER_VIEW_NO_EXPLAIN +analyze select * from db.v1; + +UPDATE db.v1 SET i = 5; +--error ER_VIEW_NO_EXPLAIN +explain UPDATE db.v1 SET i = 5; +--error ER_VIEW_NO_EXPLAIN +analyze UPDATE db.v1 SET i = 5; + +DELETE FROM db.v1 WHERE i = 5; +--error ER_VIEW_NO_EXPLAIN +explain DELETE FROM db.v1 WHERE i = 5; +--error ER_VIEW_NO_EXPLAIN +analyze DELETE FROM db.v1 WHERE i = 5; + + +--disconnect con1 +--connection default + +drop user u1@localhost; +drop database db; diff --git a/mysql-test/t/analyze_stmt_privileges2.test b/mysql-test/t/analyze_stmt_privileges2.test new file mode 100644 index 00000000000..6fcdb7d4399 --- /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/blackhole.test b/mysql-test/t/blackhole.test index 32d7d70200a..7f394e0f846 100644 --- a/mysql-test/t/blackhole.test +++ b/mysql-test/t/blackhole.test @@ -17,6 +17,16 @@ SELECT 1 FROM t1 WHERE a = ANY (SELECT a FROM t2); DROP TABLE t1, t2; +# +# Bug#19786309 - CRASH IN UNLOCK TABLES AFTER LOCKING AND TRUNCATING TEMPORARY TABLE. +# +create temporary table t1 (a int) engine=blackhole; +lock table t1 write; +truncate table t1; +select * from t1; +unlock tables; +drop temporary table t1; + --echo End of 5.5 tests --echo # diff --git a/mysql-test/t/bootstrap.test b/mysql-test/t/bootstrap.test index 2c6040af7a1..97376eb7412 100644 --- a/mysql-test/t/bootstrap.test +++ b/mysql-test/t/bootstrap.test @@ -60,3 +60,32 @@ SELECT 'bug' as '' FROM INFORMATION_SCHEMA.ENGINES WHERE engine='innodb' and SUPPORT='YES'; --echo End of 5.5 tests + +--source include/not_windows_embedded.inc +--source include/have_example_plugin.inc +# +# Check that --bootstrap can install and uninstall plugins +# +let $PLUGIN_DIR=`select @@plugin_dir`; +--write_file $MYSQLTEST_VARDIR/tmp/install_plugin.sql +install soname 'ha_example'; +uninstall plugin unusable; +EOF +--exec $MYSQLD_BOOTSTRAP_CMD --plugin-dir=$PLUGIN_DIR < $MYSQLTEST_VARDIR/tmp/install_plugin.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +--remove_file $MYSQLTEST_VARDIR/tmp/install_plugin.sql + +# +# Check that installed plugins are *not* automatically loaded in --bootstrap +# +--write_file $MYSQLTEST_VARDIR/tmp/bootstrap_plugins.sql +use test; +create table t1(a int) engine=example; +EOF +--exec $MYSQLD_BOOTSTRAP_CMD --plugin-dir=$PLUGIN_DIR < $MYSQLTEST_VARDIR/tmp/bootstrap_plugins.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +--remove_file $MYSQLTEST_VARDIR/tmp/bootstrap_plugins.sql +flush tables; +show create table t1; +drop table t1; +--replace_result .dll .so +select * from mysql.plugin; +truncate table mysql.plugin; diff --git a/mysql-test/t/bug46261-master.opt b/mysql-test/t/bug46261-master.opt deleted file mode 100644 index 5699a3387b8..00000000000 --- a/mysql-test/t/bug46261-master.opt +++ /dev/null @@ -1 +0,0 @@ ---skip-grant-tables diff --git a/mysql-test/t/bug46261.test b/mysql-test/t/bug46261.test deleted file mode 100644 index 9d8eecf3d52..00000000000 --- a/mysql-test/t/bug46261.test +++ /dev/null @@ -1,16 +0,0 @@ ---source include/not_embedded.inc ---source include/have_example_plugin.inc - ---echo # ---echo # Bug#46261 Plugins can be installed with --skip-grant-tables ---echo # - ---replace_regex /\.dll/.so/ ---error ER_OPTION_PREVENTS_STATEMENT -eval INSTALL PLUGIN example SONAME '$HA_EXAMPLE_SO'; - ---replace_regex /\.dll/.so/ ---error ER_OPTION_PREVENTS_STATEMENT -eval UNINSTALL PLUGIN example; - ---echo End of 5.1 tests diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 4d57a5a110a..30c93f58e2f 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1622,12 +1622,18 @@ END ; | INSERT INTO t1 (pk, int_key) SELECT `pk` , `int_key` FROM B ; --delimiter | ---error ER_NOT_SUPPORTED_YET +--error ER_TRG_ALREADY_EXISTS CREATE TRIGGER f BEFORE INSERT ON t1 FOR EACH ROW BEGIN UPDATE A SET `pk`=1 WHERE `pk`=0 ; END ;| +--error ER_NOT_SUPPORTED_YET +CREATE TRIGGER f1 BEFORE INSERT ON t1 FOR EACH ROW +BEGIN + UPDATE A SET `pk`=1 WHERE `pk`=0 ; +END ;| + --delimiter ; DROP TABLE t1; diff --git a/mysql-test/t/create_drop_binlog.test b/mysql-test/t/create_drop_binlog.test index b757a8bf994..775c7bec12a 100644 --- a/mysql-test/t/create_drop_binlog.test +++ b/mysql-test/t/create_drop_binlog.test @@ -127,6 +127,35 @@ CREATE OR REPLACE EVENT ev1 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE IF EXISTS t SELECT EVENT_NAME, EVENT_DEFINITION FROM INFORMATION_SCHEMA.EVENTS; DROP EVENT ev1; DROP EVENT IF EXISTS ev1; + +--replace_column 1 # 2 # 5 # +--replace_regex /xid=[0-9]+/xid=XX/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ /Server.ver.*/VER/ +SHOW BINLOG EVENTS; +RESET MASTER; + +CREATE TABLE t1 (a INT); +CREATE OR REPLACE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=10; +CREATE OR REPLACE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=11; +DROP TRIGGER tr1; +CREATE TRIGGER IF NOT EXISTS tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=20; +CREATE TRIGGER IF NOT EXISTS tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=21; +DROP TRIGGER IF EXISTS tr1; +DROP TRIGGER IF EXISTS tr1; +DROP TABLE t1; + +--replace_column 1 # 2 # 5 # +--replace_regex /xid=[0-9]+/xid=XX/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ /Server.ver.*/VER/ +SHOW BINLOG EVENTS; +RESET MASTER; + + +CREATE TABLE t1(a INT, b INT); +CREATE TABLE IF NOT EXISTS t1(a INT, b INT); +CREATE OR REPLACE INDEX i1 ON t1(a); +CREATE OR REPLACE INDEX i1 ON t1(a); +CREATE OR REPLACE INDEX i1 ON t1(a,b); +CREATE OR REPLACE INDEX i1 ON t1(a,b); +DROP TABLE t1; --replace_column 1 # 2 # 5 # --replace_regex /xid=[0-9]+/xid=XX/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ /Server.ver.*/VER/ SHOW BINLOG EVENTS; diff --git a/mysql-test/t/create_drop_index.test b/mysql-test/t/create_drop_index.test new file mode 100644 index 00000000000..4c861266325 --- /dev/null +++ b/mysql-test/t/create_drop_index.test @@ -0,0 +1,16 @@ +CREATE TABLE t1(a INT, b INT); +CREATE INDEX IF NOT EXISTS i1 ON t1(a); +SHOW CREATE TABLE t1; +DROP INDEX IF EXISTS i1 ON t1; +SHOW CREATE TABLE t1; +DROP INDEX IF EXISTS i1 ON t1; +SHOW CREATE TABLE t1; + +CREATE OR REPLACE INDEX i1 ON t1(a); +SHOW CREATE TABLE t1; +CREATE OR REPLACE INDEX i1 ON t1(a,b); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--error ER_WRONG_USAGE +CREATE OR REPLACE INDEX IF NOT EXISTS i1 ON t1(b,a); diff --git a/mysql-test/t/create_drop_trigger.test b/mysql-test/t/create_drop_trigger.test new file mode 100644 index 00000000000..a8afc8716d6 --- /dev/null +++ b/mysql-test/t/create_drop_trigger.test @@ -0,0 +1,31 @@ +CREATE DATABASE db1; +USE db1; +CREATE TABLE t1 (val INT); +CREATE TRIGGER IF NOT EXISTS val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val; +SET @sum=0; +INSERT INTO t1 VALUES (10), (20), (30); +SELECT @sum; + +--error ER_NOT_SUPPORTED_YET +CREATE TRIGGER IF NOT EXISTS val_sum_new BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val; + +CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + 1 + NEW.val; + +--error ER_WRONG_USAGE +CREATE OR REPLACE TRIGGER IF NOT EXISTS val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 2 + NEW.val; +SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum'; + +CREATE OR REPLACE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 3 + NEW.val; +SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum'; + +--error ER_TRG_ALREADY_EXISTS +CREATE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 4 + NEW.val; +SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum'; + +--echo # Clearing up +DROP TRIGGER IF EXISTS val_sum; +SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum'; +DROP TRIGGER IF EXISTS val_sum; + +DROP TABLE t1; +DROP DATABASE db1; diff --git a/mysql-test/t/create_or_replace.test b/mysql-test/t/create_or_replace.test index 9e37950dbef..3e37910380c 100644 --- a/mysql-test/t/create_or_replace.test +++ b/mysql-test/t/create_or_replace.test @@ -21,8 +21,6 @@ INSERT INTO t2 VALUES(1),(2),(3); --error ER_WRONG_USAGE CREATE OR REPLACE TABLE IF NOT EXISTS t1 (a int); ---error ER_WRONG_USAGE -create or replace trigger trg before insert on t1 for each row set @a:=1; # check that we don't try to create a log table in use --error ER_BAD_LOG_STATEMENT diff --git a/mysql-test/t/ctype_big5.test b/mysql-test/t/ctype_big5.test index 5c0bdff4633..46bb29514ff 100644 --- a/mysql-test/t/ctype_big5.test +++ b/mysql-test/t/ctype_big5.test @@ -121,7 +121,7 @@ DROP TEMPORARY TABLE head, tail; SHOW CREATE TABLE t1; SELECT COUNT(*) FROM t1; UPDATE t1 SET a=unhex(code) ORDER BY code; -SELECT COUNT(*) FROM t1 WHERE a<>''; +SELECT COUNT(*) FROM t1 WHERE a<>'?'; # # Display all characters that have upper or lower case mapping. # diff --git a/mysql-test/t/ctype_binary.test b/mysql-test/t/ctype_binary.test index 4a2646d1db5..3d3f90b444b 100644 --- a/mysql-test/t/ctype_binary.test +++ b/mysql-test/t/ctype_binary.test @@ -20,5 +20,10 @@ SET NAMES binary; --source include/ctype_like_cond_propagation.inc --echo # +--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +--echo # +SELECT _binary 0x7E, _binary X'7E', _binary B'01111110'; + +--echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/ctype_cp932_binlog_stm.test b/mysql-test/t/ctype_cp932_binlog_stm.test index 304c9f5d05c..1b92006c949 100644 --- a/mysql-test/t/ctype_cp932_binlog_stm.test +++ b/mysql-test/t/ctype_cp932_binlog_stm.test @@ -99,7 +99,7 @@ DROP TEMPORARY TABLE head, tail; SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; SELECT COUNT(*) FROM t1; -SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=1; +SELECT COUNT(*) FROM t1 WHERE a<>'?' AND OCTET_LENGTH(a)=1; SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=2; # # Display all characters that have upper or lower case mapping. diff --git a/mysql-test/t/ctype_create.test b/mysql-test/t/ctype_create.test index 060c09a0459..61fc5292094 100644 --- a/mysql-test/t/ctype_create.test +++ b/mysql-test/t/ctype_create.test @@ -105,3 +105,39 @@ ALTER DATABASE DEFAULT CHARACTER SET latin2; ALTER DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa DEFAULT CHARACTER SET latin2; --error 1102 ALTER DATABASE `` DEFAULT CHARACTER SET latin2; +USE test; + +--echo # +--echo # Start of 10.0 tests +--echo # + +--echo # +--echo # MDEV-7387 Alter table xxx CHARACTER SET utf8, CONVERT TO CHARACTER SET latin1 should fail +--echo # +--error ER_CONFLICTING_DECLARATIONS +CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET DEFAULT, CHARACTER SET utf8; +--error ER_CONFLICTING_DECLARATIONS +CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8, CHARACTER SET DEFAULT; +CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8, CHARACTER SET utf8; +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET DEFAULT, CHARACTER SET DEFAULT; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, b VARCHAR(10) CHARACTER SET utf8); +--error ER_CONFLICTING_DECLARATIONS +ALTER TABLE t1 CONVERT TO CHARACTER SET utf8, CHARACTER SET latin1; +--error ER_CONFLICTING_DECLARATIONS +ALTER TABLE t1 CONVERT TO CHARACTER SET utf8, CHARACTER SET DEFAULT; +--error ER_CONFLICTING_DECLARATIONS +ALTER TABLE t1 CONVERT TO CHARACTER SET latin1, CHARACTER SET utf8; +--error ER_CONFLICTING_DECLARATIONS +ALTER TABLE t1 CONVERT TO CHARACTER SET latin1, CHARACTER SET DEFAULT; +--error ER_CONFLICTING_DECLARATIONS +ALTER TABLE t1 CONVERT TO CHARACTER SET DEFAULT, CHARACTER SET utf8; +--error ER_CONFLICTING_DECLARATIONS +ALTER TABLE t1 CONVERT TO CHARACTER SET DEFAULT, CHARACTER SET latin1; +DROP TABLE t1; + +--echo # +--echo # End of 10.0 tests +--echo # diff --git a/mysql-test/t/ctype_eucjpms.test b/mysql-test/t/ctype_eucjpms.test index 49ca81850ed..2dd806ed027 100644 --- a/mysql-test/t/ctype_eucjpms.test +++ b/mysql-test/t/ctype_eucjpms.test @@ -446,6 +446,7 @@ SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; SELECT COUNT(*) FROM t1; SELECT COUNT(*) FROM t1 WHERE a<>''; +SELECT COUNT(*) FROM t1 WHERE a<>'' AND a<>'?'; SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=2; SELECT * FROM t1 WHERE CHAR_LENGTH(a)=2; SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=3; diff --git a/mysql-test/t/ctype_euckr.test b/mysql-test/t/ctype_euckr.test index 155b8ebed00..33b3e96cba8 100644 --- a/mysql-test/t/ctype_euckr.test +++ b/mysql-test/t/ctype_euckr.test @@ -95,8 +95,8 @@ WHERE t11.a >= 0x81 AND t11.a <= 0xFE AND t12.a >= 0x41 AND t12.a <= 0xFE ORDER BY t11.a, t12.a; --enable_warnings -SELECT s as bad_code FROM t2 WHERE a='' ORDER BY s; -DELETE FROM t2 WHERE a=''; +SELECT s as bad_code FROM t2 WHERE a='?' ORDER BY s; +DELETE FROM t2 WHERE a='?'; ALTER TABLE t2 ADD u VARCHAR(1) CHARACTER SET utf8, ADD a2 VARCHAR(1) CHARACTER SET euckr; --disable_warnings UPDATE t2 SET u=a, a2=u; @@ -145,7 +145,7 @@ ORDER BY head, tail; DROP TEMPORARY TABLE head, tail; SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; -SELECT COUNT(*) FROM t1 WHERE a<>''; +SELECT COUNT(*) FROM t1 WHERE a<>'?'; # # Display all characters that have upper or lower case mapping. # diff --git a/mysql-test/t/ctype_filename.test b/mysql-test/t/ctype_filename.test index 436ccfc4f2e..bb1b25619c6 100644 --- a/mysql-test/t/ctype_filename.test +++ b/mysql-test/t/ctype_filename.test @@ -19,3 +19,9 @@ drop table com1; create table `clock$` (a int); drop table `clock$`; + +--echo # +--echo # MDEV-7677 my_charset_handler_filename has a wrong "ismbchar" member +--echo # +SET NAMES utf8; +SELECT @a:=CONVERT('aя' USING filename) AS `@a`, BINARY @a, REVERSE(@a), HEX(@a), HEX(REVERSE(@a)); diff --git a/mysql-test/t/ctype_gb2312.test b/mysql-test/t/ctype_gb2312.test index e3dd448f54c..3ca6941705c 100644 --- a/mysql-test/t/ctype_gb2312.test +++ b/mysql-test/t/ctype_gb2312.test @@ -69,7 +69,7 @@ ORDER BY head, tail; DROP TEMPORARY TABLE head, tail; SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; -SELECT COUNT(*) FROM t1 WHERE a<>''; +SELECT COUNT(*) FROM t1 WHERE a<>'?'; # # Display all characters that have upper or lower case mapping. # diff --git a/mysql-test/t/ctype_gbk.test b/mysql-test/t/ctype_gbk.test index d44009b6109..07e73cdf745 100644 --- a/mysql-test/t/ctype_gbk.test +++ b/mysql-test/t/ctype_gbk.test @@ -104,7 +104,7 @@ ORDER BY head, tail; DROP TEMPORARY TABLE head, tail; SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; -SELECT COUNT(*) FROM t1 WHERE a<>''; +SELECT COUNT(*) FROM t1 WHERE a<>'?'; # # Display all characters that have upper or lower case mapping. # @@ -203,3 +203,235 @@ SET NAMES gbk; --echo # --echo # End of 10.0 tests --echo # + + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-6566 Different INSERT behaviour on bad bytes with and without character set conversion +--echo # + +CREATE TABLE t1 ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + b VARBINARY(16), + type SET('ascii','bad','head','tail','mb2','unassigned') +); +INSERT INTO t1 (b, type) VALUES (0x40, 'ascii,tail'); +INSERT INTO t1 (b, type) VALUES (0x80, 'tail'); +INSERT INTO t1 (b, type) VALUES (0x81, 'head,tail'); +INSERT INTO t1 (b, type) VALUES (0xFF, 'bad'); +INSERT INTO t1 (b, type) VALUES (0xA140, 'mb2,unassigned'); +INSERT INTO t1 (b, type) VALUES (0xA1A3, 'mb2'); +INSERT INTO t1 (b, type) VALUES (0xFE40, 'mb2'); +CREATE TABLE t2 AS SELECT + CONCAT(t1.b,t2.b) AS b, + t1.type AS type1, + t2.type AS type2, + CONCAT('[',t1.type,'][',t2.type,']') AS comment +FROM t1, t1 t2; + +CREATE TABLE t3 +( + b VARBINARY(16), + c VARCHAR(16) CHARACTER SET gbk, + comment VARCHAR(128) +); +--echo # +--echo # A combination of two valid characters, should give no warnings +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE + (FIND_IN_SET('ascii',type1) OR FIND_IN_SET('mb2',type1)) AND + (FIND_IN_SET('ascii',type2) OR FIND_IN_SET('mb2',type2)) +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Sequences that start with a tail or a bad byte, +--echo # or end with a bad byte, all should be fixed. +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE type1='tail' OR type1='bad' OR type2='bad' +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Sequences that start with an ASCII or an MB2 character, +--echo # followed by a non-ASCII tail, all should be fixed. +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE (FIND_IN_SET('mb2',type1) OR FIND_IN_SET('ascii',type1)) + AND (FIND_IN_SET('tail',type2) AND NOT FIND_IN_SET('ascii',type2)) +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Other sequences +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t3; +DROP TABLE t3; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT + CONCAT(t1.b,t2.b,t3.b) AS b, + t1.type AS type1, + t2.type AS type2, + t3.type AS type3, + CONCAT('[',t1.type,'][',t2.type,'][',t3.type,']') AS comment +FROM t1, t1 t2,t1 t3; +SELECT COUNT(*) FROM t2; + +CREATE TABLE t3 +( + b VARBINARY(16), + c VARCHAR(16) CHARACTER SET gbk, + comment VARCHAR(128) +); + +--echo # +--echo # A combination of three valid characters, should give no warnings +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE + (FIND_IN_SET('ascii',type1) OR FIND_IN_SET('mb2',type1)) AND + (FIND_IN_SET('ascii',type2) OR FIND_IN_SET('mb2',type2)) AND + (FIND_IN_SET('ascii',type3) OR FIND_IN_SET('mb2',type3)) +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Sequences that start with a tail or a bad byte, +--echo # or have a bad byte, all should be fixed. +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE type1='tail' OR type1='bad' OR type2='bad' OR type3='bad' +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Sequences that start with an ASCII or an MB2 character, +--echo # followed by a pure non-ASCII tail, all should be fixed. +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE (FIND_IN_SET('mb2',type1) OR FIND_IN_SET('ascii',type1)) + AND type2='tail' +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Sequences that consist of two ASCII or MB2 characters, +--echo # followed by a pure non-ASCII tail, all should be fixed. +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE (FIND_IN_SET('mb2',type1) OR FIND_IN_SET('ascii',type1)) AND + (FIND_IN_SET('mb2',type2) OR FIND_IN_SET('ascii',type2)) AND + type3='tail' +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + + +--echo # +--echo # Sequences that consist of two MB2 characters, +--echo # followed by a non-ASCII head or tail, all should be fixed. +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE FIND_IN_SET('mb2',type1) AND FIND_IN_SET('mb2',type2) + AND NOT FIND_IN_SET('ascii',type3) + AND NOT FIND_IN_SET('mb2',type3) +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + + +--echo # +--echo # Sequences that consist of head + tail + MB2 should go without warnings +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE FIND_IN_SET('head',type1) + AND FIND_IN_SET('tail',type2) + AND FIND_IN_SET('mb2',type3) +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + +--echo # +--echo # Sequences that consist of (ascii or mb2) + head + tail should go without warnings +--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 +WHERE (FIND_IN_SET('ascii',type1) OR FIND_IN_SET('mb2',type1)) + AND FIND_IN_SET('head',type2) + AND FIND_IN_SET('tail',type3) +ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; +DELETE FROM t2 WHERE b IN (SELECT b FROM t3); +DELETE FROM t3; + + +#--echo # +#--echo # Other sequences +#--echo # +INSERT INTO t3 (b,c,comment) SELECT b,b,comment FROM t2 ORDER BY b; +SELECT COUNT(*) FROM t3; +SELECT HEX(c),comment FROM t3 WHERE b=c ORDER BY b; +SELECT HEX(c),HEX(b),comment FROM t3 WHERE b<>c ORDER BY b; + +DROP TABLE t3; +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # END OF MDEV-6566 Different INSERT behaviour on bad bytes with and without character set conversion +--echo # + +--echo # +--echo # MDEV-7661 Unexpected result for: CAST(0xHHHH AS CHAR CHARACTER SET xxx) for incorrect byte sequences +--echo # +SELECT HEX(CAST(0xA341 AS CHAR CHARACTER SET gb2312)); +SELECT HEX(CONVERT(CAST(0xA341 AS CHAR CHARACTER SET gb2312) USING utf8)); + + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test index 336d8ca761d..aeaad2cc026 100644 --- a/mysql-test/t/ctype_latin1.test +++ b/mysql-test/t/ctype_latin1.test @@ -241,5 +241,10 @@ SELECT HEX(a),a FROM t1; DROP TABLE t1; --echo # +--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +--echo # +SELECT _latin1 0x7E, _latin1 X'7E', _latin1 B'01111110'; + +--echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/ctype_sjis.test b/mysql-test/t/ctype_sjis.test index ae110b20cb2..2777cf6a035 100644 --- a/mysql-test/t/ctype_sjis.test +++ b/mysql-test/t/ctype_sjis.test @@ -145,7 +145,7 @@ DROP TEMPORARY TABLE head, tail; SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; SELECT COUNT(*) FROM t1; -SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=1; +SELECT COUNT(*) FROM t1 WHERE a<>'?' AND OCTET_LENGTH(a)=1; SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=2; # # Display all characters that have upper or lower case mapping. diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test index 95008d83a38..5e8195e4718 100644 --- a/mysql-test/t/ctype_uca.test +++ b/mysql-test/t/ctype_uca.test @@ -507,6 +507,17 @@ select * from t1 where c1 = '=> dž'; select * from t1 where concat(c1) = '=> dž'; drop table t1; + +--echo # +--echo # MDEV-7649 wrong result when comparing utf8 column with an invalid literal +--echo # + +SET NAMES utf8 COLLATE utf8_unicode_ci; +--let ENGINE=MyISAM +--source include/ctype_utf8_ilseq.inc +--let ENGINE=HEAP +--source include/ctype_utf8_ilseq.inc + --echo # --echo # End of 5.5 tests --echo # diff --git a/mysql-test/t/ctype_uca_innodb.test b/mysql-test/t/ctype_uca_innodb.test new file mode 100644 index 00000000000..cb6caff4a03 --- /dev/null +++ b/mysql-test/t/ctype_uca_innodb.test @@ -0,0 +1,25 @@ +# +# Tests for UCA collations with InnoDB +# + +let collation=utf8_unicode_ci; +--source include/have_collation.inc +--source include/have_innodb.inc + + +--echo # +--echo # Start of 5.5 tests +--echo # + + +--echo # +--echo # MDEV-7649 wrong result when comparing utf8 column with an invalid literal +--echo # + +SET NAMES utf8 COLLATE utf8_unicode_ci; +--let ENGINE=InnoDB +--source include/ctype_utf8_ilseq.inc + +--echo # +--echo # End of 5.5 tests +--echo # diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index 1dee393b90b..6e5b0850eca 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -925,5 +925,13 @@ select collation(cast("a" as char(10) unicode binary)); select collation(cast("a" as char(10) binary unicode)); --echo # +--echo # MDEV-8222 "string_field LIKE int_const" returns a wrong result in case of UCS2 +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARSET ucs2); +INSERT INTO t1 VALUES ('1'); +SELECT * FROM t1 WHERE a LIKE 1; +DROP TABLE t1; + +--echo # --echo # End of 10.1 tests --echo # diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test index 48dc0e63058..94fc7ffe4c0 100644 --- a/mysql-test/t/ctype_ujis.test +++ b/mysql-test/t/ctype_ujis.test @@ -1276,7 +1276,7 @@ SHOW CREATE TABLE t1; UPDATE t1 SET a=unhex(code) ORDER BY code; SELECT COUNT(*) FROM t1; -SELECT COUNT(*) FROM t1 WHERE a<>''; +SELECT COUNT(*) FROM t1 WHERE a<>'?'; SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=2; SELECT COUNT(*) FROM t1 WHERE a<>'' AND OCTET_LENGTH(a)=3; # diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 1e9047cca8e..dba00e96491 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1616,6 +1616,26 @@ UNION ALL SELECT 'a' AS id, REPEAT('bla bla', 100) AS body) t1; --echo # +--echo # MDEV-7814 Assertion `args[0]->fixed' fails in Item_func_conv_charset::Item_func_conv_charset +--echo # +CREATE TABLE t1(a CHAR(1) CHARACTER SET latin1, b INT NOT NULL); +CREATE TABLE t2(a CHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci, b INT NOT NULL); +SELECT (SELECT t2.a FROM t2 WHERE t2.a=t1.a) AS aa, b, COUNT(b) FROM t1 GROUP BY aa; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-7649 wrong result when comparing utf8 column with an invalid literal +--echo # + +SET NAMES utf8 COLLATE utf8_general_ci; +--let ENGINE=InnoDB +--source include/ctype_utf8_ilseq.inc +--let ENGINE=MyISAM +--source include/ctype_utf8_ilseq.inc +--let ENGINE=HEAP +--source include/ctype_utf8_ilseq.inc + +--echo # --echo # End of 5.5 tests --echo # @@ -1744,6 +1764,11 @@ EXECUTE stmt USING @b,@b; DEALLOCATE PREPARE stmt; DROP TABLE t1; +--echo # +--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +--echo # +SELECT _utf8 0x7E, _utf8 X'7E', _utf8 B'01111110'; + let $ctype_unescape_combinations=selected; --source include/ctype_unescape.inc @@ -1751,3 +1776,19 @@ let $ctype_unescape_combinations=selected; --echo # --echo # End of 10.0 tests --echo # + + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-6572 "USE dbname" with a bad sequence erroneously connects to a wrong database +--echo # +SET NAMES utf8; +--error ER_INVALID_CHARACTER_STRING +SELECT * FROM `test😁😁test`; + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test index 7a3c67bb417..55909d6a6c8 100644 --- a/mysql-test/t/ctype_utf8mb4.test +++ b/mysql-test/t/ctype_utf8mb4.test @@ -1832,7 +1832,66 @@ set @@collation_connection=utf8mb4_bin; --echo # End of 5.6 tests --echo # +--echo # +--echo # Start of 10.0 tests +--echo # + +--echo # +--echo # MDEV-6566 Different INSERT behaviour on bad bytes with and without character set conversion +--echo # + +--echo # +--echo # This test sets session character set to 3-byte utf8, +--echo # but then sends a 4-byte sequence (which is wrong for 3-byte utf8). +--echo # It should be replaced to four question marks: '????' in both columns +--echo # (i.e. four unknown bytes are replaced to four question marks), +--echo # then the rest of the string should be stored, so we get 'a ???? b'. +--echo # +SET NAMES utf8; +CREATE TABLE t1 ( + a VARCHAR(32) CHARACTER SET utf8mb4, + b VARCHAR(32) CHARACTER SET utf8 +); +INSERT INTO t1 SELECT 'a 😁 b', 'a 😁 b'; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # This test sets session character set to 4-byte utf8, +--echo # then normally sends a 4-byte sequence. +--echo # It should be stored AS IS into the utf8mb4 column (a), +--echo # and should be replaced to a single question mark in the utf8 column (b) +--echo # (i.e. one character that cannot be converted is replaced to one question mark). +--echo # + +SET NAMES utf8mb4; +CREATE TABLE t1 ( + a VARCHAR(32) CHARACTER SET utf8mb4, + b VARCHAR(32) CHARACTER SET utf8 +); +INSERT INTO t1 SELECT 'a 😁 b', 'a 😁 b'; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.0 tests +--echo # --echo # --echo # End of tests --echo # + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-6572 "USE dbname" with a bad sequence erroneously connects to a wrong database +--echo # +SET NAMES utf8mb4; +--error ER_INVALID_CHARACTER_STRING +SELECT * FROM `test😁😁test`; + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test index b719cb83448..6904d9bb242 100644 --- a/mysql-test/t/default.test +++ b/mysql-test/t/default.test @@ -166,3 +166,18 @@ drop table t1, t2; --echo End of 5.0 tests. +--echo # +--echo # Start of 10.1 tests +--echo # + +# Using DEFAULT(col) in WHERE condition +CREATE TABLE t1 (a INT DEFAULT 100, b INT DEFAULT NULL); +INSERT INTO t1 VALUES (); +SELECT * FROM t1 WHERE DEFAULT(a); +SELECT * FROM t1 WHERE DEFAULT(b); +DROP TABLE IF EXISTS t1; + + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index 61ae3695a1f..ddce7f55292 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -492,5 +492,17 @@ update t1 set balance=(select sum(balance) from (SELECT balance FROM t1 where ac set optimizer_switch=@save_derived_optimizer_switch_bug; drop table t1; - set optimizer_switch=@save_derived_optimizer_switch; + +--echo # +--echo # MDEV-6892: WHERE does not apply +--echo # +create table t1 (id int); +create table t2 (id int); +insert into t1 values(1),(2),(3); +insert into t2 values(4),(5),(6); +#explain extended +select x.id, message from (select id from t1) x left join +(select id, 1 as message from t2) y on x.id=y.id +where coalesce(message,0) <> 0; +drop table t1,t2; diff --git a/mysql-test/t/enforce_storage_engine.test b/mysql-test/t/enforce_storage_engine.test new file mode 100644 index 00000000000..83deac07fe0 --- /dev/null +++ b/mysql-test/t/enforce_storage_engine.test @@ -0,0 +1,73 @@ +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +SET SESSION enforce_storage_engine=MyISAM; +select @@session.enforce_storage_engine; +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=Memory; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=MyISAM; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION'; +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=MyISAM; +SHOW CREATE TABLE t1; +INSERT INTO t1 values (1,'abba'); + +--error 1286 +CREATE TABLE t2 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=Memory; + +SET SESSION sql_mode=''; + +SET SESSION enforce_storage_engine=MyISAM; +select @@session.enforce_storage_engine; +select * from t1; +drop table t1; + +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--error 1286 +SET SESSION enforce_storage_engine=FooBar; + +select @@session.enforce_storage_engine; + +--source include/add_anonymous_users.inc + +connect (con1,localhost,user_1,,); +connection con1; +--error 1227 +SET SESSION enforce_storage_engine=MyISAM; +disconnect con1; + +connection default; + +--source include/delete_anonymous_users.inc + +SET SESSION enforce_storage_engine=NULL; + +SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION'; +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=Memory; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=MyISAM; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--error 1228 +SET GLOBAL enforce_storage_engine=NULL; diff --git a/mysql-test/t/enforce_storage_engine_opt.opt b/mysql-test/t/enforce_storage_engine_opt.opt new file mode 100644 index 00000000000..9f09b57e395 --- /dev/null +++ b/mysql-test/t/enforce_storage_engine_opt.opt @@ -0,0 +1 @@ +--enforce-storage-engine=myisam diff --git a/mysql-test/t/enforce_storage_engine_opt.test b/mysql-test/t/enforce_storage_engine_opt.test new file mode 100644 index 00000000000..82cc4117cdb --- /dev/null +++ b/mysql-test/t/enforce_storage_engine_opt.test @@ -0,0 +1,6 @@ +create table t1 (c1 int primary key auto_increment, c2 varchar(10)) engine=memory; +show create table t1; +set session sql_mode='no_engine_substitution'; +--error 1286 +create table t2 (c1 int primary key auto_increment, c2 varchar(10)) engine=memory; +drop table t1; diff --git a/mysql-test/t/error_simulation-master.opt b/mysql-test/t/error_simulation-master.opt new file mode 100644 index 00000000000..c9f8d7bd0c0 --- /dev/null +++ b/mysql-test/t/error_simulation-master.opt @@ -0,0 +1 @@ +--tmpdir=$MYSQLTEST_VARDIR/tmp diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 58ead1e3ced..7c343ed6566 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -1,4 +1,5 @@ -- source include/have_debug.inc +--source include/not_embedded.inc # # Bug #28499: crash for grouping query when tmp_table_size is too small @@ -112,3 +113,38 @@ DROP TABLE t1,t2; --echo # --echo # End of 5.1 tests --echo # + + +--echo # +--echo # BUG#11747548:DETECT ORPHAN TEMP-POOL FILES, AND HANDLE GRACEFULLY. +--echo # + +--echo #Set up. +CREATE TABLE pid_table(pid_no INT); +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES (1), (2); + +--echo #Create MYD and MYI files for intrinsic temp table. +--let $pid_file=`SELECT @@pid_file` +--replace_result $pid_file pid_file +--eval LOAD DATA LOCAL INFILE '$pid_file' INTO TABLE pid_table +--let $temp_file= `SELECT CONCAT('#sql_', LCASE(HEX(pid_no)), '_0') FROM pid_table` +--write_file $MYSQLTEST_VARDIR/tmp/$temp_file.MYD +EOF +--write_file $MYSQLTEST_VARDIR/tmp/$temp_file.MYI +EOF +--write_file $MYSQLTEST_VARDIR/tmp/$temp_file.MAD +EOF +--write_file $MYSQLTEST_VARDIR/tmp/$temp_file.MAI +EOF + +--echo #Reports an error since the temp file already exists. +--replace_regex /.*Can't create\/write *.*/Can't create or write to file/ +#--error 1 +SELECT a FROM t1 ORDER BY rand(1); + +--echo #With patch, the query executes successfully. +SELECT a FROM t1 ORDER BY rand(1); + +--echo #cleanup +DROP TABLE t1, pid_table; diff --git a/mysql-test/t/explain_json.test b/mysql-test/t/explain_json.test index 7fc1f568cec..3e6f34b854b 100644 --- a/mysql-test/t/explain_json.test +++ b/mysql-test/t/explain_json.test @@ -200,3 +200,82 @@ INSERT INTO t2 VALUES (3),(4); EXPLAIN FORMAT=JSON SELECT * FROM t1 WHERE a <> ALL ( SELECT b FROM t2 ); DROP TABLE t1, t2; +--echo # +--echo # MDEV-7927: Server crashes in in Time_and_counter_tracker::incr_loops +--echo # +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +EXPLAIN SELECT * FROM t1 WHERE 3 IN ( SELECT 4 UNION SELECT 5 ); +DROP TABLE t1; + + +--echo # +--echo # MDEV-7860: EXPLAIN FORMAT=JSON crashes for loose scan query +--echo # + +create table t2(a int); +insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int, c int, d int, key(a,b,c)); +insert into t1 select A.a, B.a, C.a, D.a from t2 A, t2 B, t2 C, t2 D; +explain select count(distinct b) from t1 group by a; +explain format=json select count(distinct b) from t1 group by a; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ +analyze format=json select count(distinct b) from t1 group by a; +drop table t1,t2; + +--echo # +--echo # Try both variants of LooseScan (data/queries borrowed from group_min_max.test) +--echo # + +create table t1 ( + a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(248) default ' ' +); + +insert into t1 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'), +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'); + +create index idx_t1_0 on t1 (a1); +create index idx_t1_1 on t1 (a1,a2,b,c); +create index idx_t1_2 on t1 (a1,a2,b); +analyze table t1; + +explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); +explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); + +explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); +explain format=json select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); + +drop table t1; + + 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 00000000000..f3567797019 --- /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/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test index f05373c312e..e36fd518b61 100644 --- a/mysql-test/t/explain_non_select.test +++ b/mysql-test/t/explain_non_select.test @@ -197,4 +197,14 @@ select 'OK'; drop function f1; drop table t1; +--echo # +--echo # MDEV-7038: Assertion `status_var.memory_used == 0' failed in THD::~THD() +--echo # on disconnect after executing EXPLAIN for multi-table UPDATE +--echo # +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +EXPLAIN UPDATE v1, mysql.user SET v1.a = v1.a + 1; +DROP TABLE t1; +DROP VIEW v1; diff --git a/mysql-test/t/file_contents.test b/mysql-test/t/file_contents.test index 7592cb9420d..4734a0294f0 100644 --- a/mysql-test/t/file_contents.test +++ b/mysql-test/t/file_contents.test @@ -36,7 +36,7 @@ if ($dir_bin eq '/usr/') { # Slackware $dir_docs = glob "$dir_bin/doc/mariadb-[0-9]*" unless -d $dir_docs; } else { - # tar.gz package, Windows, or developer work (in BZR) + # tar.gz package, Windows, or developer work (in git) $dir_docs = $dir_bin; if(-d "$dir_docs/docs") { $dir_docs = "$dir_docs/docs"; # package @@ -49,8 +49,7 @@ $found_revision = "No line 'revision-id: .....' in $dir_docs/INFO_SRC"; open(I_SRC,"<","$dir_docs/INFO_SRC") or print "Cannot open 'INFO_SRC' in '$dir_docs' (starting from bindir '$dir_bin')\n"; while(defined ($line = <I_SRC>)) { if ($line =~ m|^MariaDB source \d+\.\d\.\d+|) {$found_version = "Found MariaDB version number";} - if ($line =~ m|^revision-id: .*@.*-2\d{13}-\w+$|) {$found_revision = "Found revision id";} - if ($line =~ m|^commit: \w{40}$|) {$found_revision = "Found revision id";} + if ($line =~ m|^commit: \w{40}$|) {$found_revision = "Found GIT revision id";} } close I_SRC; print "INFO_SRC: $found_version / $found_revision\n"; diff --git a/mysql-test/t/filesort_bad_i_s-7585.test b/mysql-test/t/filesort_bad_i_s-7585.test new file mode 100644 index 00000000000..daf70acdd52 --- /dev/null +++ b/mysql-test/t/filesort_bad_i_s-7585.test @@ -0,0 +1,14 @@ +# +# MDEV-7585 Assertion `thd->is_error() || kill_errno || thd->killed == ABORT_QUERY' failed in ha_rows filesort +# +SET sql_mode=STRICT_TRANS_TABLES; + +CREATE TABLE t0 (i INT) ENGINE=MyISAM; +CREATE VIEW v1 AS SELECT * FROM t0; +CREATE VIEW v2 AS SELECT * FROM v1; +DROP VIEW IF EXISTS v1; + +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +INSERT INTO t1 SELECT TABLE_ROWS FROM information_schema.tables ORDER BY TABLE_ROWS; +DROP VIEW v2; +DROP TABLE t1, t0; diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 7643676ea61..42a30760a86 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -803,3 +803,21 @@ create table t1 (a char(1) character set utf8); insert into t1 values ('a'),('b'); select 1 from t1 where a in (select group_concat(a) from t1); drop table t1; + +# +# MDEV-7820 Server crashes in in my_strcasecmp_utf8 on subquery in ORDER BY clause of GROUP_CONCAT +# +CREATE TABLE t1 (f1 VARCHAR(10)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('a'),('b'); + +CREATE TABLE t2 (f2 VARCHAR(10)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('c'); + +CREATE TABLE t3 (f3 VARCHAR(10)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('d'),('e'); + +SELECT GROUP_CONCAT( f2 ORDER BY ( f2 IN ( SELECT f1 FROM t1 WHERE f1 <= f2 ) ) ) AS field +FROM ( SELECT * FROM t2 ) AS sq2, t3 +ORDER BY field; + +drop table t3, t2, t1; diff --git a/mysql-test/t/func_like.test b/mysql-test/t/func_like.test index bc64504c742..aab3c7fe43b 100644 --- a/mysql-test/t/func_like.test +++ b/mysql-test/t/func_like.test @@ -143,3 +143,26 @@ SELECT '' LIKE '1' ESCAPE COUNT(1); --echo # SELECT 'a' LIKE REPEAT('',0); SELECT 'a' LIKE EXTRACTVALUE('bar','qux'); + +--echo # +--echo # End of 10.0 tests +--echo # + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-8257 Erroneous "Impossible where" when mixing decimal comparison and LIKE +--echo # +CREATE TABLE t1 (a DECIMAL(8,2)); +INSERT INTO t1 VALUES (10),(20); +SELECT * FROM t1 WHERE a=10.0; +SELECT * FROM t1 WHERE a LIKE 10.00; +SELECT * FROM t1 WHERE a=10.0 AND a LIKE 10.00; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10.0 AND a LIKE 10.00; +DROP TABLE t1; + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index 2679874ddff..2d05d35bb13 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -5,10 +5,6 @@ # Spatial objects # ---disable_warnings -DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; ---enable_warnings - CREATE TABLE gis_point (fid INTEGER NOT NULL PRIMARY KEY, g POINT); CREATE TABLE gis_line (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING); CREATE TABLE gis_polygon (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON); @@ -1377,6 +1373,7 @@ insert into t1 values(geomfromtext("POINT(0 0)")); insert into t1 values(geomfromtext("POINT(0 9.2233720368548e18)")); insert into t1 values(geomfromtext("POINT(0 9.2233720368548e18)")); select equals(`a`,convert(`a` using utf8)) from `t1`; +select equals(`a`,left(`a`,23)) from `t1`; drop table t1; --echo # @@ -1443,6 +1440,19 @@ create table t1 (pt point); insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))')); drop table t1; +# +# MDEV-7516 Assertion `!cur_p->event' failed in Gcalc_scan_iterator::arrange_event(int, int) +# +SELECT st_astext(ST_Buffer(ST_PolygonFromText('POLYGON((3 5, 2 4, 2 5, 3 5))'), -100)); + +# +# MDEV-7779 View definition changes upon creation +# +CREATE VIEW v1 AS SELECT POINT(1,1) AS p; +SHOW CREATE VIEW v1; +SELECT ASTEXT(p) FROM v1; +DROP VIEW v1; + --echo End of 5.5 tests SHOW CREATE TABLE information_schema.geometry_columns; @@ -1458,3 +1468,46 @@ create table t1(g GEOMETRY(9,4) REF_SYSTEM_ID=101, pt POINT(8,2), pg GEOMETRY RE SELECT SRID from information_schema.geometry_columns WHERE G_TABLE_NAME='t1'; drop table t1; +-- echo # Expect an int(1) column to be created +CREATE TABLE t1 AS SELECT CONTAINS(NULL, NULL); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +--echo # +--echo # MDEV-7334 valgrind warning "unitialized bytes" in 10.1. +--echo # +CREATE TABLE t1 ( + gp point, + ln linestring, + pg polygon, + mp multipoint, + mln multilinestring, + mpg multipolygon, + gc geometrycollection, + gm geometry +); +ALTER TABLE t1 ADD fid INT NOT NULL; +select SRID from information_schema.geometry_columns where F_TABLE_NAME='t1'; +drop table t1; + +--echo # +--echo # MDEV-7510 GIS: IsRing returns false for a primitive triangle. +--echo # +select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,0 0)')); +select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,-10 -10, 0 -10, 0 0)')); + +--echo # +--echo # MDEV-7514 GIS: PointOnSurface returns NULL instead of the point. +--echo # +SELECT ST_GEOMETRYTYPE(ST_PointOnSurface(ST_PolyFromText('POLYGON((-70.916 42.1002,-70.9468 42.0946,-70.9754 42.0875,-70.9749 42.0879,-70.9759 42.0897,-70.916 42.1002))'))); + +--echo # +--echo # MDEV-7529 GIS: ST_Relate returns unexpected results for POINT relations +--echo # +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'T*F**FFF*') AS equals; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'T*****FF*') AS contains; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'T*F**F***') AS within; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(1 1)'),'FF*FF****') as disjoint; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'FF*FF****') as disjoint; + diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 4b1cb82d0f9..dfb7f28ab28 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1515,6 +1515,17 @@ let $query= SELECT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b; --echo DROP TABLE t1; + +# +# Bug#19880368 : GROUP_CONCAT CRASHES AFTER DUMP_LEAF_KEY +# +create table t1 (a int, b int); +insert into t1 values (1,11), (1,12), (2,22),(2,23), (4,44),(4,45); +create table t2 (c int, d int); +insert into t2 values (1,11), (1,12), (2,22),(2,23), (4,44),(4,45); +select distinct a,sum(b), (select d from t2 where c=a order by max(b) limit 1) from t1 group by a order by max(b); +drop table t1, t2; + --echo # --echo # LP bug#993726 Wrong result from a query with ALL subquery predicate in WHERE --echo # diff --git a/mysql-test/t/group_by_innodb.test b/mysql-test/t/group_by_innodb.test index 75ee3d0802a..e072a94fada 100644 --- a/mysql-test/t/group_by_innodb.test +++ b/mysql-test/t/group_by_innodb.test @@ -85,4 +85,44 @@ a.oid=b.oid WHERE a.oidGroup=1 GROUP BY a.oid; DROP TABLE t1, t2; +--echo # +--echo # MDEV-7193: Incorrect Query Result (MySQL Bug 68897) in MariaDB 10.0.14 +--echo # (fixed by MDEV-5719) +--echo # + +CREATE TABLE `t1` ( + `param` int(11) NOT NULL, + `idx` int(11) NOT NULL, + `text` varchar(255) default NULL, + PRIMARY KEY (`param`,`idx`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO `t1` (`param`, `idx`, `text`) VALUES +(1, 0, 'select'), +(1, 1, 'Kabel mit Stecker 5-polig'), +(1, 2, 'Kabel ohne Stecker'), +(2, 0, 'number'), +(2, 1, '22'), +(2, 2, '25'); +CREATE TABLE `t2` ( + `id` int PRIMARY KEY +); + +INSERT INTO t2 VALUES (1),(2),(3),(4); +SELECT t2.id AS id, T.text AS xtext,GROUP_CONCAT(T3.text) AS optionen +FROM t2 +LEFT JOIN t1 AS T ON(T.param=t2.id AND T.idx=0 ) +LEFT JOIN t1 AS T3 ON(T3.param=t2.id AND T3.idx>0 ) +GROUP BY t2.id +ORDER BY id ASC; + +SELECT t2.id AS id, T.text AS xtext,GROUP_CONCAT(T3.text) AS optionen +FROM t2 +LEFT JOIN t1 AS T ON(T.param=t2.id AND T.idx=0 ) +LEFT JOIN t1 AS T3 ON(T3.param=t2.id AND T3.idx>0 ) +GROUP BY t2.id +ORDER BY id DESC; + +DROP TABLE t1, t2; + --echo # End of tests diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test index 8c9be0ca8db..47d551f8241 100644 --- a/mysql-test/t/group_min_max.test +++ b/mysql-test/t/group_min_max.test @@ -1524,3 +1524,39 @@ DROP TABLE t1; --echo # End of 10.0 tests --echo # + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-6990 GROUP_MIN_MAX optimization is not applied in some cases when it could +--echo # +CREATE TABLE t1 (id INT NOT NULL, a DATE, KEY(id,a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,'2001-01-01'); +INSERT INTO t1 VALUES (1,'2001-01-02'); +INSERT INTO t1 VALUES (1,'2001-01-03'); +INSERT INTO t1 VALUES (1,'2001-01-04'); +INSERT INTO t1 VALUES (2,'2001-01-01'); +INSERT INTO t1 VALUES (2,'2001-01-02'); +INSERT INTO t1 VALUES (2,'2001-01-03'); +INSERT INTO t1 VALUES (2,'2001-01-04'); +INSERT INTO t1 VALUES (3,'2001-01-01'); +INSERT INTO t1 VALUES (3,'2001-01-02'); +INSERT INTO t1 VALUES (3,'2001-01-03'); +INSERT INTO t1 VALUES (3,'2001-01-04'); +INSERT INTO t1 VALUES (4,'2001-01-01'); +INSERT INTO t1 VALUES (4,'2001-01-02'); +INSERT INTO t1 VALUES (4,'2001-01-03'); +INSERT INTO t1 VALUES (4,'2001-01-04'); +EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='2001-01-04' GROUP BY id; +EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104.0 GROUP BY id; +EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id; +SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='2001-01-04' GROUP BY id; +SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104.0 GROUP BY id; +SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id; +DROP TABLE t1; + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index cd6a4c9d328..0f6be0b0ec6 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -694,6 +694,41 @@ DROP TABLE t1; --echo End of 5.3 tests --echo # +--echo # Bug MDEV-7301: Unknown column quoted with backticks in HAVING clause when using function. +--echo # Bug#16221433 MYSQL REJECTS QUERY DUE TO BAD RESOLUTION OF NAMES IN HAVING; VIEW UNREADABLE +--echo # + +CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `title` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8; + +INSERT INTO `t1` VALUES ('1', 'Just for fun'); +INSERT INTO `t1` VALUES ('2', 'Wait until a sunhine'); +INSERT INTO `t1` VALUES ('3', 'Take a new turn'); + +SELECT `id`, SHA1(`title`) AS `column_1` +FROM `t1` +HAVING `column_1` LIKE '8%'; + +--echo expected 1 row(s) returned + +SELECT `id`, SHA1(`title`) AS `column_1` +FROM `t1` +HAVING UPPER(column_1) LIKE '8%'; + +--echo expected -- 1 row(s) returned + +SELECT `id`, SHA1(`title`) AS `column_1` +FROM `t1` +HAVING UPPER(`column_1`) LIKE '8%'; + +--echo expected -- 1 row(s) returned not ER_BAD_FIELD_ERROR + +drop table t1; + +--echo # --echo # Bug mdev-5160: two-way join with HAVING over the second table --echo # @@ -708,4 +743,3 @@ SELECT * FROM t1 JOIN t2 ON c1 = c2 HAVING c2 > 'a' ORDER BY c2 LIMIT 1; DROP TABLE t1,t2; --echo End of 10.0 tests - diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 1f3d2c551e6..cd98bf3aa5c 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1827,6 +1827,23 @@ drop view v1; --echo # Clean-up. drop database mysqltest; +--echo # +--echo # Test for bug #16869534 - "QUERYING SUBSET OF COLUMNS DOESN'T USE TABLE +--echo # CACHE; OPENED_TABLES INCREASES" +--echo # +--disable_result_log +SELECT * FROM INFORMATION_SCHEMA.TABLES; +--enable_result_log +SELECT VARIABLE_VALUE INTO @val1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE + VARIABLE_NAME LIKE 'Opened_tables'; +--disable_result_log +SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES; +--enable_result_log +--echo # The below SELECT query should give same output as above SELECT query. +SELECT VARIABLE_VALUE INTO @val2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE + VARIABLE_NAME LIKE 'Opened_tables'; +--echo # The below select should return '1' +SELECT @val1 = @val2; --echo # --echo # End of 5.5 tests diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test index 0e4610b9f54..7d873c555f6 100644 --- a/mysql-test/t/join_cache.test +++ b/mysql-test/t/join_cache.test @@ -3848,6 +3848,18 @@ set join_buffer_space_limit=default; drop table t1; +--echo # +--echo # MDEV-6687: Assertion `0' failed in Protocol::end_statement on query +--echo # +SET join_cache_level = 3; +--echo # The following should have +--echo # - table order PROFILING,user, +--echo # - table user accessed with hash_ALL: +explain +SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user WHERE password_expired = PAGE_FAULTS_MINOR; + +set join_cache_level=default; + # The following command must be the last one the file # this must be the last command in the file set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/t/log_errchk.test b/mysql-test/t/log_errchk.test index e4bc6a841dd..2808458e9f1 100644 --- a/mysql-test/t/log_errchk.test +++ b/mysql-test/t/log_errchk.test @@ -6,7 +6,8 @@ # Bug#14757009 : WHEN THE GENERAL_LOG IS A SOCKET AND THE READER GOES AWAY, # MYSQL QUITS WORKING. # -call mtr.add_suppression("Could not use"); +# MDEV-6870 Not possible to use FIFO file as a general_log file +# --let $gen_log_file= $MYSQLTEST_VARDIR/tmp/general_log.fifo --let $slow_query_log_file= $MYSQLTEST_VARDIR/tmp/slow_log.fifo @@ -15,10 +16,9 @@ call mtr.add_suppression("Could not use"); --exec mkfifo $gen_log_file --exec mkfifo $slow_query_log_file ---echo # Case 1: Setting fife file to general_log_file and slow_query_log_file +--echo # Case 1: Setting fifo file to general_log_file and slow_query_log_file --echo # system variable. -# Only regular files can be set to general log. Setting fifo file to general log -# reports an error. +# Setting fifo file to general log reports an error because the other end is closed --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error ER_WRONG_VALUE_FOR_VAR --eval SET GLOBAL general_log_file="$gen_log_file"; @@ -38,11 +38,12 @@ call mtr.add_suppression("Could not use"); --exec echo "restart: --general-log-file=$gen_log_file --slow-query-log-file=$slow_query_log_file" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --source include/wait_until_connected_again.inc -# With fix error should be reported in the error log file if file is not a -# regular file. +# Error 6 is reported, because the other end is closed +call mtr.add_suppression("Could not use .* for logging \\(error 6\\)"); +call mtr.add_suppression("File '.*' not found \\(Errcode: 6 "); --perl my $file= $ENV{'GREP_FILE'}; - my $pattern= "Turning logging off for the whole duration"; + my $pattern= "for logging \\(error 6\\)\\. Turning logging off for the whole duration"; open(FILE, "$file") or die("Unable to open $file: $!\n"); my $count = 0; while (<FILE>) { diff --git a/mysql-test/t/log_tables.test b/mysql-test/t/log_tables.test index 1a32ca8aaee..28f6e6dd829 100644 --- a/mysql-test/t/log_tables.test +++ b/mysql-test/t/log_tables.test @@ -727,7 +727,8 @@ CREATE TABLE `db_17876.slow_log_data` ( `insert_id` int(11) default NULL, `server_id` int(11) default NULL, `sql_text` mediumtext, - `thread_id` bigint(21) unsigned default NULL + `thread_id` bigint(21) unsigned default NULL, + `rows_affected` int(11) default NULL ); CREATE TABLE `db_17876.general_log_data` ( diff --git a/mysql-test/t/max_statement_time.test b/mysql-test/t/max_statement_time.test index 0356d3caa49..d994f04be83 100644 --- a/mysql-test/t/max_statement_time.test +++ b/mysql-test/t/max_statement_time.test @@ -187,3 +187,36 @@ disconnect con1; connection default; SELECT RELEASE_LOCK('lock'); DROP TABLE t1; + +--echo # +--echo # MDEV-7011:MAX_STATEMENT_TIME has no effect in a procedure after +--echo # a previous successful statement +--echo # +create table t1 (i int); +insert into t1 values (1),(2),(3),(4); +insert into t1 select a.* from t1 a, t1 b, t1 c, t1 d, t1 e, t1 f, t1 g; +delimiter |; +create procedure pr() + begin + select 1; + select sql_no_cache * from t1 where i > 5; + select sql_no_cache * from t1 where i > 5; + end | +delimiter ;| +set max_statement_time = 0.001; +--error ER_STATEMENT_TIMEOUT +call pr(); +drop procedure pr; +delimiter |; +create procedure pr() + begin + select sql_no_cache * from t1 where i > 5; + select sql_no_cache * from t1 where i > 5; + end | +delimiter ;| +set max_statement_time = 0.001; +--error ER_STATEMENT_TIMEOUT +call pr(); +set max_statement_time = 0; +drop procedure pr; +drop table t1; diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index 4f8736f0c2d..c013938416e 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -849,6 +849,212 @@ update t1 join v3 using (id) set t1.a=0; drop view v1, v2, v3; drop table t2, t3, t1; +--echo # +--echo # MDEV-7613: MariaDB 5.5.40 server crash on update table left join +--echo # with a view +--echo # + +CREATE TABLE `t1` ( + `f1` varchar(6) COLLATE latin1_general_ci DEFAULT NULL, + `f2` varchar(6) COLLATE latin1_general_ci DEFAULT NULL, + `f3` varchar(7) COLLATE latin1_general_ci DEFAULT NULL, + `f4` varchar(15) COLLATE latin1_general_ci DEFAULT NULL, + `f5` datetime DEFAULT NULL, + `f6` varchar(2) COLLATE latin1_general_ci DEFAULT NULL, + `f7` varchar(2) COLLATE latin1_general_ci DEFAULT NULL, + `ff1` int(1) DEFAULT NULL, + `ff2` int(1) DEFAULT NULL, + `ff3` int(1) DEFAULT NULL, + `ff4` int(1) DEFAULT NULL, + `ff5` int(1) DEFAULT NULL, + `ff6` int(1) DEFAULT NULL, + `ff7` int(1) DEFAULT NULL, + `ff8` int(2) DEFAULT NULL, + `ff9` int(1) DEFAULT NULL, + `ff10` int(1) DEFAULT NULL, + `ff11` int(1) DEFAULT NULL, + `ff12` int(1) DEFAULT NULL, + `ff13` int(1) DEFAULT NULL, + `ff14` int(1) DEFAULT NULL, + `ff15` int(1) DEFAULT NULL, + `f8` varchar(70) COLLATE latin1_general_ci DEFAULT NULL, + `f9` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, + `f10` varchar(50) COLLATE latin1_general_ci NOT NULL, + `f11` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, + `f12` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `f13` text COLLATE latin1_general_ci, + `f14` time DEFAULT NULL, + `f15` varchar(30) COLLATE latin1_general_ci DEFAULT NULL, + `fg1` int(11) DEFAULT NULL, + `fg2` int(11) DEFAULT NULL, + `fg3` int(11) DEFAULT NULL, + `fg4` int(11) DEFAULT NULL, + `fg5` int(11) DEFAULT NULL, + `fg6` int(11) DEFAULT NULL, + `fg7` int(11) DEFAULT NULL, + `fg9` int(11) DEFAULT NULL, + `fg10` int(11) DEFAULT NULL, + `fg11` int(11) DEFAULT NULL, + `fg12` int(11) DEFAULT NULL, + `fg13` int(11) DEFAULT NULL, + `fg14` int(11) DEFAULT NULL, + `fg15` int(11) DEFAULT NULL, + `f16` double DEFAULT NULL, + `f17` double DEFAULT NULL, + `f18` int(11) DEFAULT NULL, + `f19` int(11) DEFAULT NULL, + `f20` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `f21` int(11) DEFAULT NULL, + `f22` int(11) DEFAULT NULL, + `f23` int(11) DEFAULT NULL, + `f24` double DEFAULT NULL, + `f25` int(11) DEFAULT NULL, + `f26` double DEFAULT NULL, + `f27` int(11) DEFAULT NULL, + `f28` int(11) DEFAULT NULL, + `f29` double DEFAULT NULL, + `f30` int(11) DEFAULT NULL, + `f31` double DEFAULT NULL, + `PZ` double DEFAULT NULL, + `f32` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, + `f33` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, + `f34` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, + `f35` varchar(30) COLLATE latin1_general_ci DEFAULT NULL, + `f36` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, + `f37` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, + `f20_2` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, + `f38` varchar(30) COLLATE latin1_general_ci DEFAULT NULL COMMENT 'Email = E-Mail / Whitemail = Brief', + `insert_ts` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`f10`), + KEY `f5_f12` (`f5`,`f12`), + KEY `f5_f20` (`f5`,`f20`), + KEY `f5_f33` (`f5`,`f33`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci ROW_FORMAT=COMPACT; + +INSERT INTO `t1` VALUES ('2011/2','201105','2011/19','gstfbnfr','2011-05-06 +00:00:00','gg','Ag',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,0,'','','','','','','21:56:28','',0,0,0,0,0,0,0,0,0,0,0,0,0,0,NULL,NULL,0,0,'Dffgult',1,0,0,NULL,0,NULL,0,0,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'ggggil',NULL),('2008/4','200812','2008/50','hgckbgfx','2008-12-08 +00:00:00','gg','Ag',2,NULL,2,1,1,1,1,24,1,NULL,1,1,1,2,0,'gusschlifßlich +zugg +gflffonifrfn','88.77.79.214','10001614','fg-gtgggggdgtfn','fg-gtgggggdgtfn','birgit.tfrpfllf@gggx.df','11:55:21',NULL,1,0,1,1,1,1,1,1,0,1,1,1,0,0,NULL,NULL,0,4,'ffrtrgg',1,6,10,1.66666666666667,4,1,10,14,1.4,1,NULL,NULL,'out',NULL,NULL,'49','ggobilcogg','k.A.',NULL,'ggggil',NULL),('2008/4','200812','2008/51','hgckbgfx','2008-12-15 +00:00:00','gg','Ag',4,5,5,4,5,5,5,NULL,4,5,1,1,1,4,0,'gusschlifßlich zugg +gflffonifrfn','79.197.185.64','10001686','fg-gtgggggdgtfn','fg-gtgggggdgtfn','kgtjg@swfftys.df','09:28:42',NULL,1,1,1,1,1,1,1,1,1,1,1,1,0,0,NULL,NULL,0,5,'ffrtrgg',1,7,11,4.71428571428571,16,1.2,12,49,4.08111111111111,1,NULL,NULL,'out',NULL,NULL,'49','ggobilcogg','k.A.',NULL,'ggggil',NULL),('2008/4','200812','2008/50','nufchti','2008-12-08 +00:00:00','gg','Ag',4,1,1,5,5,5,5,12,4,5,1,1,2,1,0,'gusschlifßlich zugg +gflffonifrfn','89.54.151.216','10001700','fg-gtgggggdgtfn','fg-gtgggggdgtfn','H_K2006@frffnft.df','16:41:45',NULL,1,1,1,1,1,1,1,1,1,1,1,1,0,0,NULL,NULL,0,5,'ffrtrgg',1,7,10,4.28571428571429,11,2.6,12,41,1.58111111111111,1,NULL,NULL,'ffrtrgg +Bgckofficf 5','vb5','Nufchtfr, +Iris','49','ggobilcogg','grfurt','Intfrn','ggggil',NULL),('2008/4','200812','2008/50','junghdro','2008-12-11 +00:00:00','Do','Ag',2,2,5,5,4,4,2,72,2,5,2,2,1,1,0,'gusschlifßlich zugg +gflffonifrfn','84.61.20.216','10001849','fg-ggriff','fg-ggriff','schofnf-glftfr@grcor.df','20:18:05',NULL,1,1,1,1,1,1,1,1,1,1,1,1,0,0,NULL,NULL,0,5,'ffrtrgg',1,7,24,1.42857142857141,12,2.4,12,16,1,1,NULL,NULL,'ffrtrgg +Bgckofficf 5','vb5','Junghfinrich, +Dorothfg','49','ggobilcogg','grfurt','Intfrn','ggggil',NULL),('2008/4','200812','2008/50','fbflktj','2008-12-08 +00:00:00','gg','Ag',4,2,2,5,1,1,1,24,NULL,NULL,NULL,NULL,NULL,0,0,'Kgggfrg +bzw. DigiCggg +Funktion','217.84.62.6','10001888','fg-Kündigungfn','fg-Kündigungfn','f.frofschkf@gggx.df','21:05:59',NULL,1,1,1,1,1,1,1,0,0,0,0,0,0,0,NULL,NULL,0,0,'ffrtrgg',1,7,16,2.28571428571429,0,NULL,7,16,2.28571428571429,0,NULL,NULL,'out',NULL,'gbfl, +Kgtjg','49','ggobilcogg','k.A.','gxtfrn','ggggil',NULL),('2008/4','200812','2008/50','gltggggri','2008-12-09 +00:00:00','Di','Ag',4,1,1,4,2,1,2,16,1,2,2,2,2,2,0,'gusschlifßlich zugg +gflffonifrfn','81.171.157.211','10001988','fg-gtgggggdgtfn','fg-gtgggggdgtfn','bistfr@nftcolognf.df','11:07:54',NULL,1,1,1,1,1,1,1,1,1,1,1,1,0,0,NULL,NULL,0,5,'ffrtrgg',1,7,21,1,11,2.2,12,12,2.66666666666667,1,NULL,NULL,'out',NULL,NULL,'49','ggobilcogg','k.A.','gxtfrn','ggggil',NULL),('2008/4','200812','2008/50','ggufllfsg','2008-12-09 +00:00:00','Di','Ag',2,2,2,2,1,1,2,12,2,2,2,1,1,2,0,'ggobilfs +Intfrnft','62.154.142.186','10002097','fg-gtgggggdgtfn','fg-gtgggggdgtfn','norbfrtwfdlich@fgggil.df','09:42:11',NULL,1,1,1,1,1,1,1,1,1,1,1,1,0,0,NULL,NULL,0,5,'ffrtrgg',1,7,12,1.71428571428571,8,1.6,12,20,1.66666666666667,1,NULL,NULL,'ffrtrgg +Bgckofficf 1','vb1','Mufllfr, +ggbinf','49','ggobilcogg','grfurt','Intfrn','ggggil',NULL),('2008/4','200812','2008/50','wggnfg','2008-12-09 +00:00:00','Di','Ag',5,5,5,5,5,5,5,12,5,5,5,5,5,5,0,'gls grsgtz für +Ffstnftz','85.180.141.246','10002127','fg-Kündigungfn','fg-Kündigungfn','rfinhgrt.gdolph@yghoo.df','17:44:11',NULL,1,1,1,1,1,1,1,1,1,1,1,1,0,0,NULL,NULL,0,5,'ffrtrgg',1,7,15,5,25,5,12,60,5,1,NULL,NULL,'ffrtrgg +Bgckofficf 1','vb1','Wggnfr, +Annftt','49','ggobilcogg','grfurt','Intfrn','ggggil',NULL),('2008/4','200812','2008/50','schubrbf','2008-12-10 +00:00:00','Mi','Ag',1,2,NULL,2,1,2,1,24,NULL,NULL,NULL,NULL,NULL,0,0,'Kgggfrg +bzw. DigiCggg +Funktion','91.40.98.242','10002160','fg-gtgggggdgtfn','fg-gtgggggdgtfn','olgf.lifb@gggx.nft','18:18:25',NULL,1,1,0,1,1,1,1,0,0,0,0,0,0,0,NULL,NULL,0,0,'ffrtrgg',1,6,11,1.81111111111111,0,NULL,6,11,1.81111111111111,0,NULL,NULL,'out',NULL,NULL,'49','ggobilcogg','k.A.','gxtfrn','ggggil',NULL); + +CREATE TABLE `t2` ( + `ft1` datetime DEFAULT NULL, + `ft2` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `ft3` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `ft4` varchar(255) COLLATE latin1_general_ci NOT NULL DEFAULT '', + `ft5` varchar(255) COLLATE latin1_general_ci NOT NULL DEFAULT '', + `ft6` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `ft6_2` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `ft7` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `ft8` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `ft9` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + `ft10` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, + PRIMARY KEY (`ft4`,`ft5`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; + +INSERT INTO `t2` VALUES ('2013-03-13 00:00:00','2013-03-13 00:00:00','9999-12-31 00:00:00','#','extern FP f32 2','Default','Intern','DEFAULT',NULL,NULL,NULL),('2013-03-13 00:00:00','2013-03-13 00:00:00','9999-12-31 00:00:00','#','extern FP f32 3','Default','Intern','DEFAULT',NULL,NULL,NULL); + +CREATE TABLE `t3` ( + `fe1` int(10) NOT NULL DEFAULT '0', + `fe2` char(50) COLLATE latin1_general_ci DEFAULT 'nn', + `f34` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `fe3` double DEFAULT NULL, + `fe4` double DEFAULT NULL, + `fe5` char(4) COLLATE latin1_general_ci DEFAULT NULL, + `f32` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `fe6` int(3) DEFAULT '0', + `fe7` char(1) COLLATE latin1_general_ci DEFAULT NULL, + `ft6` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `f33` char(4) COLLATE latin1_general_ci DEFAULT NULL COMMENT 'virtuelle f33s', + `fe8` char(4) COLLATE latin1_general_ci DEFAULT NULL COMMENT 'aus dem ADS', + `f37` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `fe9` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `fe10` int(5) DEFAULT '0', + `fe11` int(10) DEFAULT '0', + `fe12` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `fe13` double DEFAULT NULL, + `fe14` char(50) COLLATE latin1_general_ci DEFAULT NULL, + `fe15` date DEFAULT NULL, + `fe16` date DEFAULT NULL, + `fe17` int(10) DEFAULT '0', + `fe18` date NOT NULL DEFAULT '0000-00-00', + `ft3` date NOT NULL DEFAULT '0000-00-00', + PRIMARY KEY (`fe1`), + KEY `fe2` (`fe2`,`fe18`,`ft3`), + KEY `f33` (`f33`), + KEY `fe8` (`fe8`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci ROW_FORMAT=COMPACT COMMENT='CustomerService und Outsourcer Userinformationen'; + +INSERT INTO `t3` VALUES (1,'aabggn','gab, glgna',0,NULL,NULL,'gxtgrn D gnd g +gggsbgrg',0,NULL,'gxtgrn','dsa','dsa','gggsbgrg','0',91611,0,'0',0,'agsggschigdgn','2014-08-11','2014-09-05',0,'2011-01-01','2014-08-11'),(4,'aabigr','gab, +Iggr',0,NULL,NULL,'gxtgrn D gnd g +gggsbgrg',0,NULL,'gxtgrn','dsa','dsa','gggsbgrg','0',0,0,'0',0,'agsggschigdgn','2014-08-11','2014-09-05',0,'2012-10-01','2014-08-11'),(7,'abgcrist','gbg, +ghristggna',15182,1,'ja','ggshilfg gxtgrn 1',1,NULL,'gg +galgs','ag1','ag1','grfgrt','0',11941,0,'0',0,'agsggschigdgn','2014-01-11',NULL,11802051,'1900-01-01','2010-06-10'),(8,'abgcrist','gbg, +ghristggna',15182,1,'ja','Zgntralg gftgr galgs Bgtrgggng 1',1,NULL,'gg +galgs','sb1','sb1','grfgrt','0',11941,0,'0',0,'agsggschigdgn','2014-01-11',NULL,11802051,'2010-07-01','2012-08-11'),(9,'abgcrist','gbg, +ghristggna',15182,1,'ja','galgs Inbggnd 2',1,NULL,'gg +galgs','si2','si2','grfgrt','0',11941,0,'0',0,'agsggschigdgn','2014-01-11',NULL,11802051,'2012-09-01','2014-01-11'),(10,'abgcgr','gbg, +ggrnglgg',14962,1,NULL,'galgs Ogtbggnd 1',1,NULL,'gg +galgs','sg1','sg1','grfgrt','0',12401,0,'abgcrn',1,NULL,NULL,NULL,11800647,'1900-01-01','2010-11-10'),(11,'abgcgr','gbg, +ggrnglgg',14962,1,NULL,'galgs Ogtbggnd 1',1,NULL,'gg +galgs','sg1','sg1','grfgrt','0',12401,0,'abgcrn',1,NULL,NULL,NULL,11800647,'2010-12-01','2011-08-11'),(12,'abgcgr','gbg, +ggrnglgg',14962,1,NULL,'galgs Ogtbggnd 2',1,NULL,'gg +galgs','sg2','sg2','grfgrt','0',12401,0,'abgcrn',1,NULL,NULL,NULL,11800647,'2011-09-01','2012-01-11'),(13,'abgcgr','gbg, +ggrnglgg',14962,0.75,NULL,'galgs Ogtbggnd 2',1,NULL,'gg +galgs','sg2','sg2','grfgrt','0',12401,0,'abgcrn',1,NULL,NULL,'2011-09-11',11800647,'2012-02-01','2011-08-11'),(14,'rgghrsgr','gbg, +gigrid',14781,1,'ja','Fgrdgrgngsmanaggmgnt 1',1,NULL,'gg +Zahlgng','fm1','fm1','grfgrt','0',12141,0,'0',1,NULL,NULL,NULL,11010781,'1900-01-01','2012-08-11'); + +CREATE ALGORITHM=MERGE +DEFINER=`root`@`localhost` SQL SECURITY DEFINER +VIEW `v1` AS select `t1a`.`ft1` AS `ft1`,`t1a`.`ft2` AS `ft2`,`t1a`.`ft3` AS `ft3`,`t1a`.`ft4` AS `ft4`,`t1a`.`ft5` AS `ft5`,`t1a`.`ft6` AS `ft6`,`t1a`.`ft6_2` AS `ft6_2`,`t1a`.`ft7` AS `ft7`,`t1a`.`ft8` AS `ft8`,`t1a`.`ft9` AS `ft9`,`t1a`.`ft10` AS `ft10` from `t2` `t1a` where (if((`t1a`.`ft10` = 'virtuell'),0,1) = 1); + +CREATE ALGORITHM=UNDEFINED +DEFINER=`root`@`localhost` SQL SECURITY DEFINER +VIEW `v2` AS select distinct `t1b`.`fe2` AS `fe2`,min(`t1b`.`fe18`) AS `fe18`,max(`t1b`.`ft3`) AS `ft3` from `t3` `t1b` where ((`t1b`.`fe2` <> '') and (curdate() >= `t1b`.`fe18`)) group by `t1b`.`fe2`; + +CREATE ALGORITHM=UNDEFINED +DEFINER=`root`@`localhost` SQL SECURITY DEFINER +VIEW `v3` AS select `t1c`.`fe2` AS `fe2`,`t1c`.`f34` AS `f34`,`t1c`.`f33` AS `f33`,`t1c`.`f32` AS `f32`,`t1c`.`f37` AS `f37`,`t1c`.`fe10` AS `fe10`,if((`tov`.`ft6` in ('klarmobil','callmobile')),`tov`.`ft9`,`tov`.`ft6`) AS `ft6_1`,`tov`.`ft6_2` AS `ft6_2`,`ua`.`fe18` AS `fe18`,`ua`.`ft3` AS `ft3` from ((`t3` `t1c` left join `v2` `ua` on((`t1c`.`fe2` = `ua`.`fe2`))) left join `v1` `tov` on((`t1c`.`fe8` = `tov`.`ft4`))) where (`t1c`.`ft3` = `ua`.`ft3`) group by `t1c`.`fe2`,`t1c`.`f34`,`t1c`.`f33`,`t1c`.`f32` order by `t1c`.`f34`; + +UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01'; + +--echo #MDEV-8018: main.multi_update fails with --ps-protocol +prepare stmt1 from "UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01'"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +drop view v3,v2,v1; +drop table t1,t2,t3; --echo end of 5.5 tests diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index 2b4b1e69ab6..c328ab19ffd 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -608,5 +608,29 @@ EOF # --exec $MYSQL -t -N -e "SELECT 'a' union select 'aaaaaaaaaaaaaaaaa'" +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-6572 "USE dbname" with a bad sequence erroneously connects to a wrong database +--echo # + +--echo # +--echo # End of 10.1 tests +--echo # + +--error 1 +--exec $MYSQL --default-character-set=utf8 -e "select 1" "test😁 " 2>&1 +--error 1 +--exec $MYSQL --default-character-set=binary -e "select 1" "test😁 " 2>&1 +--write_file $MYSQLTEST_VARDIR/tmp/mdev-6572.sql +SET NAMES utf8; +USE test😁 ; +EOF +--error 1 +--exec $MYSQL --default-character-set=utf8 < $MYSQLTEST_VARDIR/tmp/mdev-6572.sql 2>&1 +--remove_file $MYSQLTEST_VARDIR/tmp/mdev-6572.sql + --echo --echo End of tests diff --git a/mysql-test/t/mysql_upgrade_view.test b/mysql-test/t/mysql_upgrade_view.test new file mode 100644 index 00000000000..e222afa89fe --- /dev/null +++ b/mysql-test/t/mysql_upgrade_view.test @@ -0,0 +1,133 @@ +-- source include/have_log_bin.inc + +set sql_log_bin=0; +--disable_warnings +drop table if exists t1,v1,v2,v3,v4,v1badcheck; +drop view if exists t1,v1,v2,v3,v4,v1badcheck; +--enable_warnings + +create table t1(a int); +create table kv(k varchar(30) NOT NULL PRIMARY KEY,v varchar(50)); + +let $MYSQLD_DATADIR= `select @@datadir`; + +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1badcheck.frm $MYSQLD_DATADIR/test/v1badcheck.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm + +flush tables; + +check view v1; +check view v1badcheck; +check view v2; +check view v3; + +check view v1 for upgrade; +check view v1badcheck for upgrade; +check view v2 for upgrade; +check view v3 for upgrade; + +--replace_result $MYSQLTEST_VARDIR var +--exec $MYSQL_UPGRADE --force 2>&1 + +# "Phase 1/4: Fixing views" expected (without from_mysql) + +show create view v1; +show create view v2; +show create view v3; + +# Now force a mariadb version to be added + +set sql_log_bin=1; +REPAIR VIEW v1,v2; +REPAIR VIEW v1badcheck; +REPAIR NO_WRITE_TO_BINLOG VIEW v3; +set sql_log_bin=0; + +--source include/show_binlog_events.inc + +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +eval LOAD DATA INFILE '$MYSQLD_DATADIR/test/v1.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '='; +SELECT k,v from kv where k in ('md5','algorithm'); +SELECT k from kv where k ='mariadb-version'; +truncate table kv; + +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +eval LOAD DATA INFILE '$MYSQLD_DATADIR/test/v2.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '='; +SELECT k,v from kv where k in ('md5','algorithm'); +SELECT k from kv where k ='mariadb-version'; +truncate table kv; + +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +eval LOAD DATA INFILE '$MYSQLD_DATADIR/test/v3.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '='; +SELECT k,v from kv where k in ('md5','algorithm'); +SELECT k from kv where k ='mariadb-version'; +truncate table kv; + +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +eval LOAD DATA INFILE '$MYSQLD_DATADIR/test/v1badcheck.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '='; +SELECT k,v from kv where k in ('md5','algorithm'); +SELECT k from kv where k ='mariadb-version'; +truncate table kv; + +--disable_warnings +drop view if exists v1,v2,v3,v1badcheck; +--enable_warnings + +# Make it look like a MySQL directory now + +rename table mysql.event to mysql.ev_bk; +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.MYI $MYSQLD_DATADIR/mysql/event.MYI +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.MYD $MYSQLD_DATADIR/mysql/event.MYD +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.frm $MYSQLD_DATADIR/mysql/event.frm + +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm + +flush tables; + +create algorithm=temptable view v4 as select a from t1; +show create view v1; +show create view v2; +show create view v3; +show create view v4; + +# here we test the fixing views from mysql to occur +--replace_result $MYSQLTEST_VARDIR var +--exec $MYSQL_UPGRADE --force 2>&1 + +flush tables; +show create view v1; +show create view v2; +show create view v3; +show create view v4; + +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +eval LOAD DATA INFILE '$MYSQLD_DATADIR/test/v1.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '='; +SELECT k,v from kv where k in ('md5','algorithm'); +SELECT k from kv where k ='mariadb-version'; +truncate table kv; + +--disable_warnings +drop view if exists v1,v2,v3; +--enable_warnings + +# back to mariadb default +drop table mysql.event; +rename table mysql.ev_bk to mysql.event; + +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm +--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm + +# check of binlog and mixing tables (with table specific options) and views +--exec $MYSQL_CHECK --repair --write-binlog --process-tables --use-frm --process-views=UPGRADE_FROM_MYSQL test 2>&1 + +--source include/show_binlog_events.inc + +drop table if exists kv; +drop view v1,v2,v3,v4; +drop table t1; + diff --git a/mysql-test/t/mysqladmin.test b/mysql-test/t/mysqladmin.test index c04c8d50f3c..2580db88456 100644 --- a/mysql-test/t/mysqladmin.test +++ b/mysql-test/t/mysqladmin.test @@ -45,3 +45,9 @@ EOF --exec $MYSQLADMIN --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/cnf_file -uroot -S $MASTER_MYSOCK -P $MASTER_MYPORT ping 2>&1 --remove_file $MYSQLTEST_VARDIR/tmp/cnf_file + +# +# MDEV-7883 Segmentation failure when running mysqladmin -u root -p +# +--error 1 +--exec $MYSQLADMIN -u root -p 2>&1 > /dev/null diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index 4af17490488..65a45b9a21c 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -850,5 +850,25 @@ DROP TABLE t2; DROP TABLE t1; --echo # +--echo # MDEV-7759 NULLIF(x,y) is not equal to CASE WHEN x=y THEN NULL ELSE x END +--echo # +CREATE TABLE t1 (a YEAR); +INSERT INTO t1 VALUES (2010),(2020); +SELECT * FROM t1 WHERE a=2010 AND NULLIF(10.1,a) IS NULL; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND NULLIF(10.1,a) IS NULL; +SELECT * FROM t1 WHERE a=2010 AND CASE WHEN 10.1=a THEN NULL ELSE 10.1 END IS NULL; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND CASE WHEN 10.1=a THEN NULL ELSE 10.1 END IS NULL; +DROP TABLE t1; + +--echo # Two warnings expected +CREATE TABLE t1 AS SELECT + NULLIF(TIMESTAMP'2001-01-01 00:00:00',1) AS a, + CASE WHEN TIMESTAMP'2001-01-01 00:00:00'=1 THEN NULL + ELSE TIMESTAMP'2001-01-01 00:00:00' + END AS b; +DROP TABLE t1; + + +--echo # --echo # End of 10.1 tests --echo # diff --git a/mysql-test/t/openssl_1.test b/mysql-test/t/openssl_1.test index bee0e2cc720..e36f106a5be 100644 --- a/mysql-test/t/openssl_1.test +++ b/mysql-test/t/openssl_1.test @@ -15,15 +15,15 @@ insert into t1 values (5); grant select on test.* to ssl_user1@localhost require SSL; grant select on test.* to ssl_user2@localhost require cipher "DHE-RSA-AES256-SHA"; -grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/ST=Uppsala/O=MySQL AB"; -grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=SE/ST=Uppsala/O=MySQL AB" ISSUER "/C=SE/ST=Uppsala/L=Uppsala/O=MySQL AB"; +grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client"; +grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client" ISSUER "/CN=cacert/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB"; grant select on test.* to ssl_user5@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "xxx"; flush privileges; connect (con1,localhost,ssl_user1,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT --error ER_ACCESS_DENIED_ERROR -connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=RC4-SHA); +connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=AES256-SHA); connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); connect (con3,localhost,ssl_user3,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); connect (con4,localhost,ssl_user4,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); @@ -222,8 +222,6 @@ DROP TABLE t1; # Common ciphers to openssl and yassl --exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=DHE-RSA-AES256-SHA --exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=EDH-RSA-DES-CBC3-SHA ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=EDH-RSA-DES-CBC-SHA ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=RC4-SHA --disable_query_log --disable_result_log diff --git a/mysql-test/t/partition_innodb_plugin.test b/mysql-test/t/partition_innodb_plugin.test index 8044ae9ec5c..fd6e60c27fb 100644 --- a/mysql-test/t/partition_innodb_plugin.test +++ b/mysql-test/t/partition_innodb_plugin.test @@ -149,11 +149,11 @@ UPDATE `t``\""e` SET a = 4 WHERE a = 22; # NOTE: replace_regex is very slow on match copy/past '(.*)' regex's # on big texts, removing a lot of text before + after makes it much faster. #/.*in (.*) trx.*/\1/ ---replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // +--replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* // SHOW ENGINE InnoDB STATUS; set @old_sql_mode = @@sql_mode; set sql_mode = 'ANSI_QUOTES'; ---replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // +--replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* // SHOW ENGINE InnoDB STATUS; set @@sql_mode = @old_sql_mode; --echo # con1 diff --git a/mysql-test/t/processlist.test b/mysql-test/t/processlist.test index a8f8a4ed64c..4734c75c8d3 100644 --- a/mysql-test/t/processlist.test +++ b/mysql-test/t/processlist.test @@ -50,3 +50,23 @@ select command, time < 5 from information_schema.processlist where id != connect disconnect con1; set debug_sync='reset'; + +connection default; + + +--echo # +--echo # 10.1 tests +--echo # + +--echo # +--echo # MDEV-7807 information_schema.processlist truncates queries with binary strings +--echo # + +SET NAMES utf8; +--vertical_results +SELECT INFO, INFO_BINARY, 'xxx😎yyy' AS utf8mb4_string FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%xxx%yyy%'; +--horizontal_results + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test index 8ea0f2db9b7..d0f397697d5 100644 --- a/mysql-test/t/read_only.test +++ b/mysql-test/t/read_only.test @@ -30,6 +30,7 @@ set global read_only=0; connection con1; create table t1 (a int); +create trigger trg1 before insert on t1 for each row set @a:=1; insert into t1 values(1); @@ -56,6 +57,9 @@ create table t3 (a int); --error ER_OPTION_PREVENTS_STATEMENT insert into t1 values(1); +--error ER_OPTION_PREVENTS_STATEMENT +drop trigger trg1; + # if a statement, after parse stage, looks like it will update a # non-temp table, it will be rejected, even if at execution it would # have turned out that 0 rows would be updated diff --git a/mysql-test/t/repair.test b/mysql-test/t/repair.test index 5b78a352863..a6df0dc5979 100644 --- a/mysql-test/t/repair.test +++ b/mysql-test/t/repair.test @@ -210,3 +210,12 @@ repair table t1 use_frm; select count(*) from t1; check table t1; drop table t1; + +# +# MDEV-8115 mysql_upgrade crashes the server with REPAIR VIEW +# +create table t1 (a blob); +create view v1 as select * from t1; +repair view v1; +drop view v1; +drop table t1; diff --git a/mysql-test/t/selectivity.test b/mysql-test/t/selectivity.test index 77ee5f49bef..c46ff69295f 100644 --- a/mysql-test/t/selectivity.test +++ b/mysql-test/t/selectivity.test @@ -942,5 +942,34 @@ set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivit drop table t0,t1,t2; +--echo # +--echo # Bug mdev-7316: a conjunct in WHERE with selectivity == 0 +--echo # + +CREATE TABLE t1 (a varchar(16), b int, PRIMARY KEY(a), KEY(b)) ENGINE=INNODB; +INSERT INTO t1 VALUES + ('USAChinese',10), ('USAEnglish',20), ('USAFrench',30); + +CREATE TABLE t2 (i int) ENGINE=INNODB; +INSERT INTO t2 VALUES + (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(1),(2),(3),(4); + +ANALYZE TABLE t1, t2; + +set use_stat_tables='preferably'; +set optimizer_use_condition_selectivity=3; + +EXPLAIN EXTENDED +SELECT * FROM t1, t2 + WHERE a <> 'USARussian' AND b IS NULL; + +SELECT * FROM t1, t2 + WHERE a <> 'USARussian' AND b IS NULL; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + + set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/t/selectivity_innodb.test b/mysql-test/t/selectivity_innodb.test index 5674cb5c006..d6a77eac600 100644 --- a/mysql-test/t/selectivity_innodb.test +++ b/mysql-test/t/selectivity_innodb.test @@ -80,6 +80,36 @@ select * from t1 where col2 != true; drop table t1; --echo # +--echo # MDEV-7413: optimizer_use_condition_selectivity > 2 crashes 10.0.15+maria-1~wheezy +--echo # + +CREATE TABLE t1 ( + parent_id int, + child_group_id int, + child_user_id int, + KEY (parent_id,child_group_id,child_user_id) +) ENGINE=InnoDB; + +CREATE TABLE t2 ( + id int, + lower_group_name varchar(255), + directory_id int(20), + UNIQUE KEY (directory_id) +) ENGINE=InnoDB; + +CREATE TABLE t3 (id int) ENGINE=InnoDB; + +insert into t1 values (1,1,1),(2,2,2); +insert into t2 values (10,'foo',10),(20,'bar',20); +insert into t3 values (101),(102); +set use_stat_tables = PREFERABLY, optimizer_use_condition_selectivity = 3; + +select * from t1, t2, t3 +where t1.child_user_id=t3.id and t1.child_group_id is null and t2.lower_group_name='foo' and t1.parent_id=t2.id and t2.directory_id=10; + +drop table t1,t2,t3; + +--echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/set_statement.test b/mysql-test/t/set_statement.test index 6421317935a..13c6d08818b 100644 --- a/mysql-test/t/set_statement.test +++ b/mysql-test/t/set_statement.test @@ -987,38 +987,73 @@ set global general_log=0; set statement lock_wait_timeout=1 for select @@lock_wait_timeout; set global general_log=@save_general_log; +--echo # MDEV-7006 MDEV-7007: SET statement and slow log + +set @save_long_query_time= @@long_query_time; +set @save_slow_query_log= @@slow_query_log; +set @save_log_output= @@log_output; + +set statement long_query_time=default for select @@long_query_time; +set statement log_slow_filter=default for select @@log_slow_filter; +set statement log_slow_verbosity=default for select @@log_slow_verbosity; +set statement log_slow_rate_limit=default for select @@log_slow_rate_limit; +set statement slow_query_log=default for select @@slow_query_log; + +truncate table mysql.slow_log; +set slow_query_log= 1; +set global log_output='TABLE'; + +select sql_text from mysql.slow_log; +set @@long_query_time=0.01; +--echo #should be written +select sleep(0.1); +set @@long_query_time=@save_long_query_time; +select sql_text from mysql.slow_log; +--echo #--- +--echo #should be written +set statement long_query_time=0.01 for select sleep(0.1); +select sql_text from mysql.slow_log; +--echo #--- +set @@long_query_time=0.01; +--echo #should NOT be written +set statement slow_query_log=0 for select sleep(0.1); +set @@long_query_time=@save_long_query_time; +select sql_text from mysql.slow_log; +--echo #--- +--echo #should NOT be written +set statement long_query_time=0.01,log_slow_filter='full_scan' for select sleep(0.1); +select sql_text from mysql.slow_log; +--echo #--- +--echo #should NOT be written +set statement long_query_time=0.01,log_slow_rate_limit=9999 for select sleep(0.1); +select sql_text from mysql.slow_log; +--echo #--- +--echo #should NOT be written +set statement long_query_time=0.01,min_examined_row_limit=50 for select sleep(0.1); +select sql_text from mysql.slow_log; +--echo #--- +# +# log_slow_verbosity is impossible to check because results are not written +# in TABLE mode +# + +set global log_output= @save_log_output; +set @@slow_query_log= @save_slow_query_log; +set @@long_query_time= @save_long_query_time; + + # # Prohibited Variables # --error ER_SET_STATEMENT_NOT_SUPPORTED set statement autocommit=default for select 1; --error ER_SET_STATEMENT_NOT_SUPPORTED -set statement gtid_domain_id=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED set statement tx_isolation=default for select 1; --error ER_SET_STATEMENT_NOT_SUPPORTED -set statement rand_seed1=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement rand_seed2=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED set statement skip_replication=default for select 1; --error ER_SET_STATEMENT_NOT_SUPPORTED -set statement last_insert_id=1 for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED set statement sql_log_off=default for select 1; --error ER_SET_STATEMENT_NOT_SUPPORTED -set statement long_query_time=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement log_slow_filter=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement log_slow_verbosity=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement log_slow_rate_limit=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement slow_query_log=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement min_examined_row_limit=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED set statement character_set_client=default for select 1; --error ER_SET_STATEMENT_NOT_SUPPORTED set statement character_set_connection=default for select 1; @@ -1068,3 +1103,31 @@ execute stmt1; deallocate prepare stmt1; drop table t1; set @@old_passwords=@save_old_passwords; + +--echo # +--echo #MDEV-6951:Erroneous SET STATEMENT produces two identical errors +--echo # + +--error ER_UNKNOWN_SYSTEM_VARIABLE +set statement non_existing=1 for select 1; +show errors; + +--echo # +--echo # MDEV-6954: SET STATEMENT rand_seedX = ...FOR ... makes +--echo # the next rand() to return 0 +--echo # +set @rnd=1; +let $1=10; +--disable_query_log +--echo # test that rand() is not always 0 after restoring rand_seed, rand_seed2... +while ($1) +{ + --disable_result_log + set statement rand_seed1=1, rand_seed2=1 for select 1; + --enable_result_log + set @rnd= rand()=0 and @rnd; + dec $1; +} +--enable_query_log +--echo # @rnd should be 0 +select @rnd; diff --git a/mysql-test/t/set_statement_notembedded.test b/mysql-test/t/set_statement_notembedded.test index b0021de51ee..7bb8f5e1aab 100644 --- a/mysql-test/t/set_statement_notembedded.test +++ b/mysql-test/t/set_statement_notembedded.test @@ -10,8 +10,4 @@ SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(3); SHOW STATUS LIKE "max_statement_time_exceeded"; SELECT @@MAX_STATEMENT_TIME; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement default_master_connection=default for select 1; ---error ER_SET_STATEMENT_NOT_SUPPORTED -set statement default_master_connection=default for select 1; diff --git a/mysql-test/t/set_statement_notembedded_binlog.test b/mysql-test/t/set_statement_notembedded_binlog.test new file mode 100644 index 00000000000..62c351ed6f7 --- /dev/null +++ b/mysql-test/t/set_statement_notembedded_binlog.test @@ -0,0 +1,87 @@ +--source include/have_log_bin.inc +--source include/not_embedded.inc + +--disable_warnings +drop table if exists t1; +drop view if exists t1; +--enable_warnings + +--echo # +--echo # MDEV-6948: SET STATEMENT gtid_domain_id = ... FOR has no effect +--echo # (same for gtid_seq_no and server_id) +--echo # +reset master; +create table t1 (i int); +set gtid_domain_id = 10; +insert into t1 values (1),(2); +set statement gtid_domain_id = 20 for insert into t1 values (3),(4); + +--replace_column 1 x 2 x 3 x 4 x 5 x +show binlog events limit 5,5; + +drop table t1; + +reset master; +SET @a=11; + +create table t1 (a int not null auto_increment, c int, d int, primary key (a)); +create table t2 (b int); +insert into t2 values (1),(2); + +DELIMITER |; +CREATE function f1() returns int +BEGIN + SET STATEMENT last_insert_id=@a for insert into t1 values (NULL, @a, + last_insert_id()); + SET @a:=@a*100+13; + return @a; +end| +DELIMITER ;| + + +call mtr.add_suppression("Unsafe statement written to the binary log using"); +select f1() from t2; + +--replace_column 1 x 2 x 3 x 4 x 5 x +show binlog events limit 16, 100; + +select * from t1; + +drop function f1; +drop table t1,t2; + + +reset master; +SET @a=11; + +create table t1 (a int not null auto_increment, c int, d int, primary key (a)); +create table t2 (b int); +insert into t2 values (1),(2); + +DELIMITER |; +CREATE function f1() returns int +BEGIN + SET @save= @@last_insert_id; + SET session last_insert_id=@a; + insert into t1 values (NULL, @a, last_insert_id()); + SET session last_insert_id=@save; + SET @a:=@a*100+13; + return @a; +end| +DELIMITER ;| + +select f1() from t2; + +--replace_column 1 x 2 x 3 x 4 x 5 x +show binlog events limit 13, 100; + +select * from t1; + +drop function f1; +drop table t1,t2; + +reset master; +set statement last_insert_id = 112 for create table t1 as select last_insert_id(); +--replace_column 1 x 2 x 3 x 4 x 5 x +show binlog events limit 4,1; +drop table t1; diff --git a/mysql-test/t/show_grants_with_plugin-7985.test b/mysql-test/t/show_grants_with_plugin-7985.test new file mode 100644 index 00000000000..9c05cb2e06d --- /dev/null +++ b/mysql-test/t/show_grants_with_plugin-7985.test @@ -0,0 +1,161 @@ +--source include/not_embedded.inc +--enable_connect_log +call mtr.add_suppression("password and an authentication plugin"); + +--echo # +--echo # Create a user with mysql_native_password plugin. +--echo # The user has no password or auth_string set. +--echo # + +create user u1; +GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password; +select user, host, password, plugin, authentication_string from mysql.user where user = 'u1'; + +--echo # +--echo # The user's grants should show no password at all. +--echo # +show grants for u1; +--echo # +--echo # Test to see if connecting with no password is succesful. +--echo # +--connect (con1, localhost, u1,,) +show grants; +--disconnect con1 + +--connection default +--echo # +--echo # Test after flushing privileges. +--echo # +flush privileges; +--connect (con1, localhost, u1,,) +show grants; +--disconnect con1 + +--connection default +--echo # +--echo # Now add a mysql_native password string in authentication_string. +--echo # +# Password string is SOMETHING +GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password +USING '*7AFEFD08B6B720E781FB000CAA418F54FA662626'; +select user, host, password, plugin, authentication_string from mysql.user where user = 'u1'; +--echo # +--echo # Test to see if connecting with password is succesful. +--echo # +--connect (con1, localhost, u1,'SOMETHING',) +show grants; +--disconnect con1 + +--connection default +--echo # +--echo # Test after flushing privileges. +--echo # +flush privileges; +--connect (con1, localhost, u1,'SOMETHING',) +show grants; +--disconnect con1 +--connection default + +--echo # +--echo # Now we also set a password for the user. +--echo # +set password for u1 = PASSWORD('SOMETHINGELSE'); +select user, host, password, plugin, authentication_string from mysql.user where user = 'u1'; + +--echo # +--echo # Here we should use the password field, as that primes over +--echo # the authentication_string field. +--echo # +show grants for u1; + +--echo # +--echo # Logging in with the user's password should work. +--echo # +--connect (con1, localhost, u1,'SOMETHINGELSE',) +show grants; +--disconnect con1 +--connection default +--echo # +--echo # Reload privileges and test logging in again. +--echo # +flush privileges; +show grants for u1; +--echo # +--echo # Here we connect via the user's password again. +--echo # +--connect (con1, localhost, u1,'SOMETHINGELSE',) +show grants; +--disconnect con1 +--connection default + +--echo # +--echo # Now we remove the authentication plugin password, flush privileges and +--echo # try again. +--echo # +update mysql.user set authentication_string = '' where user='u1'; +select user, host, password, plugin, authentication_string from mysql.user where user = 'u1'; +flush privileges; +show grants for u1; +--echo # +--echo # Here we connect via the user's password. +--echo # +--connect (con1, localhost, u1,'SOMETHINGELSE',) +select user, host, password, plugin, authentication_string from mysql.user where user = 'u1'; +--disconnect con1 +--connection default + +--echo # +--echo # Try and set a wrong auth_string password, with mysql_native_password. +--echo # Make sure it fails. +--echo # +--error ER_PASSWD_LENGTH +GRANT USAGE ON *.* TO u1 IDENTIFIED VIA mysql_native_password USING 'asd'; +--echo # +--echo # Now set a correct password. +--echo # +GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password +USING '*7AFEFD08B6B720E781FB000CAA418F54FA662626'; +show grants for u1; + +--echo # +--echo # Test if the user can now use that password instead. +--echo # +--connect (con1, localhost, u1,'SOMETHING',) +show grants; +--disconnect con1 + +--echo # +--echo # Test if the user can now use that password instead, after flushing privileges; +--echo # +--connection default +flush privileges; + +--connect (con1, localhost, u1,'SOMETHING',) +show grants; +--disconnect con1 +--connection default + +--echo # +--echo # Clear all passwords from the user. +--echo # +set password for u1 = ''; +select user, host, password, plugin, authentication_string from mysql.user where user = 'u1'; + +--echo # +--echo # Test no password connect. +--echo # +--connect (con1, localhost, u1,,) +show grants; +--disconnect con1 +--connection default + +--echo # +--echo # Test no password connect, after flushing privileges. +--echo # +flush privileges; +--connect (con1, localhost, u1,,) +show grants; +--disconnect con1 +--connection default + +drop user u1; diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test index 52bbce6c484..6e19fd885e3 100644 --- a/mysql-test/t/sp-destruct.test +++ b/mysql-test/t/sp-destruct.test @@ -277,3 +277,11 @@ DROP DATABASE db1; --echo # Restore mysql.proc DROP TABLE mysql.proc; RENAME TABLE proc_backup TO mysql.proc; + +# +# BUG#19875331 - HANDLE_FATAL_SIGNAL 11 IN STRMAKE +# +create database mysqltest1; +create procedure mysqltest1.foo() select "foo"; +update mysql.proc set name='' where db='mysqltest1'; +drop database mysqltest1; diff --git a/mysql-test/t/sp-innodb.test b/mysql-test/t/sp-innodb.test index 228ab42544d..23715166a02 100644 --- a/mysql-test/t/sp-innodb.test +++ b/mysql-test/t/sp-innodb.test @@ -43,3 +43,120 @@ CALL p1(); drop procedure p1; drop table t1,t2; + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +--echo +--echo # +--echo # BUG 16041903: CONTINUE HANDLER NOT INVOKED +--echo # IN A STORED FUNCTION AFTER A LOCK WAIT TIMEOUT +--echo # + +--echo +--echo # Save and set lock wait timeout +SET @lock_wait_timeout_saved= @@lock_wait_timeout; +SET @innodb_lock_wait_timeout_saved= @@innodb_lock_wait_timeout; +SET @@lock_wait_timeout= 1; +SET @@innodb_lock_wait_timeout= 1; + +--echo +--echo # Create a function with exit handler: +DELIMITER //; +CREATE FUNCTION f1() RETURNS VARCHAR(20) +BEGIN + DECLARE EXIT HANDLER FOR SQLSTATE '42S02' RETURN 'No such table'; + INSERT INTO no_such_table VALUES (1); +END// + +--echo +--echo # Create a function calling f1(): +CREATE FUNCTION f2() RETURNS VARCHAR(20) +BEGIN + RETURN f1(); +END// + +--echo +--echo # Create a function provoking deadlock: +CREATE FUNCTION f3() RETURNS VARCHAR(20) +BEGIN + UPDATE t1 SET i= 1 WHERE i= 1; + RETURN 'Will never get here'; +END// + +--echo +--echo # Create a function calling f3, to create +--echo # a deadlock indirectly: +CREATE FUNCTION f4() RETURNS VARCHAR(20) +BEGIN + RETURN f3(); +END// +DELIMITER ;// + +--echo +--echo # Open another connection, create and initialize a table +--echo # to be used for provoking deadlock, put a lock on the table: +connect (con1,localhost,root,,); +CREATE TABLE t1 (i INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +SET AUTOCOMMIT= 0; +UPDATE t1 SET i=1 WHERE i=1; + +--echo +--echo # On the default connection, do an update to provoke a +--echo # deadlock, then call the function with handler. This case +--echo # fails without the patch (with error ER_NO_SUCH_TABLE): +--connection default +SET AUTOCOMMIT= 0; +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET i=1 WHERE i=1; +SELECT f1() AS 'f1():'; + +--echo +--echo # Provoke another deadlock, then call the function with +--echo # handler indirectly. This case fails without the patch +--echo # (with error ER_NO_SUCH_TABLE): +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET i= 1 WHERE i= 1; +SELECT f2() AS 'f2():'; + +--echo +--echo # Provoke yet another deadlock, but now from within a function, +--echo # then call the function with handler. This succeeds even +--echo # without the patch because is_fatal_sub_stmt_error is reset +--echo # in restore_sub_stmt after the failing function has been +--echo # executed. The test case is included anyway for better coverage: +--error ER_LOCK_WAIT_TIMEOUT +SELECT f3() AS 'f3():'; +SELECT f1() AS 'f1():'; + +--echo # Provoke yet another deadlock, but now from within a function, +--echo # calling another function, then call the function with handler. +--echo # This succeeds even without the patch because +--echo # is_fatal_sub_stmt_error is reset in restore_sub_stmt after +--echo # the failing function has been executed. The test case is +--echo # included anyway for better coverage: +--error ER_LOCK_WAIT_TIMEOUT +SELECT f4() AS 'f4():'; +SELECT f1() AS 'f1():'; + +--echo +--echo # Disconnect, drop functions and table: +--disconnect con1 +DROP FUNCTION f4; +DROP FUNCTION f3; +DROP FUNCTION f2; +DROP FUNCTION f1; +DROP TABLE t1; + +--echo +--echo # Reset lock wait timeouts +SET @@lock_wait_timeout= @lock_wait_timeout_saved; +SET @@innodb_lock_wait_timeout= @innodb_lock_wait_timeout_saved; + +--echo # +--echo # BUG 16041903: End of test case +--echo # + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test index 42a3dd193c4..2a24ab3d005 100644 --- a/mysql-test/t/sp_notembedded.test +++ b/mysql-test/t/sp_notembedded.test @@ -462,6 +462,26 @@ DROP EVENT teste_bug11763507; --echo # ------------------------------------------------------------------ # +# A case of SHOW GRANTS +# (creating a new procedure changes the password) +# +grant create routine on test.* to foo1@localhost identified by 'foo'; +update mysql.user set password = replace(password, '*', '-') where user='foo1'; +--connect (foo,localhost,foo1,foo) +show grants; +--connection default +flush privileges; +--connection foo +show grants; +create procedure spfoo() select 1; +show grants; + +--connection default +--disconnect foo +drop procedure spfoo; +drop user foo1@localhost; + +# # Restore global concurrent_insert value. Keep in the end of the test file. # diff --git a/mysql-test/t/ssl.test b/mysql-test/t/ssl.test index 988a9d6c056..0d14ad82692 100644 --- a/mysql-test/t/ssl.test +++ b/mysql-test/t/ssl.test @@ -25,11 +25,14 @@ SHOW STATUS LIKE 'Ssl_server_not_after'; --replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA SHOW STATUS LIKE 'Ssl_cipher'; +# +# MDEV-7697 Client reports ERROR 2006 (MySQL server has gone away) or ERROR 2013 (Lost connection to MySQL server during query) while executing AES* functions under SSL +# +select aes_decrypt('MySQL','adf'); +select 'still connected?'; + connection default; disconnect ssl_con; # Wait till all disconnects are completed --source include/wait_until_count_sessions.inc - -## This test file is for testing encrypted communication only, not other -## encryption routines that the SSL library happens to provide! diff --git a/mysql-test/t/ssl_timeout.test b/mysql-test/t/ssl_timeout.test new file mode 100644 index 00000000000..0d96b3f6601 --- /dev/null +++ b/mysql-test/t/ssl_timeout.test @@ -0,0 +1,21 @@ +--source include/have_ssl_communication.inc + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +--echo # connect with read timeout so SLEEP() should timeout +connect (ssl_con,localhost,root,,,,,SSL read_timeout=5); + +--echo # Check ssl turned on +--replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA +SHOW STATUS LIKE 'Ssl_cipher'; + +# --error CR_SERVER_LOST +--error 2013 +SELECT SLEEP(600); + +connection default; +disconnect ssl_con; + +# Wait till all disconnects are completed +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index 2c60e5645c3..c989cb22558 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2693,5 +2693,16 @@ SET join_cache_level=@tmp_mdev5059; set optimizer_switch=@tmp_os_mdev5059; DROP TABLE t1,t2,t3,t4; +--echo # +--echo # MDEV-7911: crash in Item_cond::eval_not_null_tables +--echo # + +create table t1(a int); +insert into t1 values(1),(2),(3),(null); +--error ER_CANT_AGGREGATE_2COLLATIONS +explain +select 1 from t1 where _cp932 "1" in (select '1' from t1); +drop table t1; + # The following command must be the last one the file set optimizer_switch=@subselect_sj_tmp; diff --git a/mysql-test/t/subselect_sj2.test b/mysql-test/t/subselect_sj2.test index a82baf095c1..0bf9c6d9d10 100644 --- a/mysql-test/t/subselect_sj2.test +++ b/mysql-test/t/subselect_sj2.test @@ -1320,5 +1320,76 @@ SELECT * FROM t1 WHERE id in (select distinct id_agente from t2); DROP TABLE t1, t2; +--echo # +--echo # MDEV-7474: Semi-Join's DuplicateWeedout strategy skipped for some values of optimizer_search_depth +--echo # + +CREATE TABLE t1 ( + t1id BIGINT(20) NOT NULL, + code VARCHAR(20), + PRIMARY KEY (t1id) +) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + +CREATE TABLE t2 ( + t2id BIGINT(20) NOT NULL, + t1idref BIGINT(20) NOT NULL, + code VARCHAR(20), + PRIMARY KEY (t2id), + INDEX FK_T2_T1Id (t1idref), + CONSTRAINT FK_T2_T1Id FOREIGN KEY (t1idref) REFERENCES t1 (t1id) +) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + +CREATE TABLE t3 ( + t3idref BIGINT(20) NOT NULL, + t2idref BIGINT(20) NOT NULL, + sequencenumber INT(10) NOT NULL, + PRIMARY KEY (t3idref, t2idref), + INDEX FK_T3_T2Id (t2idref), + CONSTRAINT FK_T3_T2Id FOREIGN KEY (t2idref) REFERENCES t2 (t2id) +) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + +# Load up dummy data (needed to reproduce issue) +INSERT INTO t1 (t1id) VALUES (100001),(100017),(100018),(100026),(100027),(100028),(100029),(100030), +(100031),(100032),(100033),(100034),(100035),(100036),(100037),(100038),(100040),(100041),(100042), +(100043),(100044),(100045),(100046),(100047); + +INSERT IGNORE INTO t2 (t2id, t1idref) SELECT t1id, t1id FROM t1; + +# Now the test Data +INSERT IGNORE INTO t1 VALUES (200001, 'a'); +INSERT IGNORE INTO t2 (t2id, t1idref) VALUES (200011, 200001),(200012, 200001),(200013, 200001); +INSERT IGNORE INTO t3 VALUES (1, 200011, 1), (1, 200012, 2), (1, 200013, 3); + +set @tmp7474= @@optimizer_search_depth; +SET SESSION optimizer_search_depth = 1; + +let $query= +SELECT SQL_NO_CACHE +T2_0_.t1idref, +T2_0_.t2id +FROM + t2 T2_0_ +WHERE + T2_0_.t1idref IN ( + SELECT + T1_1_.t1id + FROM + t3 T3_0_ + INNER JOIN + t2 T2_1_ + ON T3_0_.t2idref=T2_1_.t2id + INNER JOIN + t1 T1_1_ + ON T2_1_.t1idref=T1_1_.t1id + WHERE + T3_0_.t3idref= 1 +); + +eval $query; +eval explain $query; + +drop table t3,t2,t1; +set optimizer_search_depth=@tmp7474; + --echo # This must be the last in the file: set optimizer_switch=@subselect_sj2_tmp; diff --git a/mysql-test/t/subselect_sj_mat.test b/mysql-test/t/subselect_sj_mat.test index 912e9d5befd..c34c805f90c 100644 --- a/mysql-test/t/subselect_sj_mat.test +++ b/mysql-test/t/subselect_sj_mat.test @@ -1843,3 +1843,45 @@ drop database mysqltest4; --echo # End of 5.5 tests +--echo # +--echo # MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +--echo # +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; + +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; + +create table t3 as select * from t2 limit 1; + +--echo # The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); + +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +--echo # Sequential reads: +--echo # 1K is read from t1 +--echo # 4K is read from t2 +--echo # 1K groups is read from the tmp. table +--echo # +--echo # Lookups: +--echo # 4K lookups in group by table +--echo # 1K lookups in temp.table +--echo # +--echo # Writes: +--echo # 2x 1K writes to temporary tables (grouping table and subquery materialization table +--echo # +--echo # The point is that neither counter should be in the millions (this +--echo # will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; + +drop table t0,t1,t2,t3; diff --git a/mysql-test/t/system_mysql_db_fix40123.test b/mysql-test/t/system_mysql_db_fix40123.test deleted file mode 100644 index fd1212d4ce6..00000000000 --- a/mysql-test/t/system_mysql_db_fix40123.test +++ /dev/null @@ -1,82 +0,0 @@ -# Embedded server doesn't support external clients ---source include/not_embedded.inc ---source include/have_innodb.inc - -# Don't run this test if $MYSQL_FIX_PRIVILEGE_TABLES isn't set -# to the location of mysql_fix_privilege_tables.sql -if (!$MYSQL_FIX_PRIVILEGE_TABLES) -{ - skip Test need MYSQL_FIX_PRIVILEGE_TABLES; -} - -# -# This is the test for mysql_fix_privilege_tables -# It checks that a system tables from mysql 4.1.23 -# can be upgraded to current system table format -# -# Note: If this test fails, don't be confused about the errors reported -# by mysql-test-run This shows warnings generated by -# mysql_fix_system_tables which should be ignored. -# Instead, concentrate on the errors in r/system_mysql_db.reject - --- disable_result_log --- disable_query_log - -use test; - -# create system tables as in mysql-4.1.23 -# created by executing "./mysql_create_system_tables real ." - -set storage_engine=myisam; -CREATE TABLE db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; -INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); -INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); - -CREATE TABLE host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; - - -CREATE TABLE user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; -INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); -INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); - -CREATE TABLE func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions'; - - -CREATE TABLE tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges'; -CREATE TABLE columns_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges'; - -CREATE TABLE help_topic ( help_topic_id int unsigned not null, name varchar(64) not null, help_category_id smallint unsigned not null, description text not null, example text not null, url varchar(128) not null, primary key (help_topic_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help topics'; -CREATE TABLE help_category ( help_category_id smallint unsigned not null, name varchar(64) not null, parent_category_id smallint unsigned null, url varchar(128) not null, primary key (help_category_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help categories'; -CREATE TABLE help_relation ( help_topic_id int unsigned not null references help_topic, help_keyword_id int unsigned not null references help_keyword, primary key (help_keyword_id, help_topic_id) ) engine=MyISAM CHARACTER SET utf8 comment='keyword-topic relation'; -CREATE TABLE help_keyword ( help_keyword_id int unsigned not null, name varchar(64) not null, primary key (help_keyword_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; - -CREATE TABLE time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY Name (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; - -CREATE TABLE time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY TzId (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; - -CREATE TABLE time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; - -CREATE TABLE time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; - -CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; - -# Run the mysql_fix_privilege_tables.sql using "mysql --force" ---exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES - --- enable_query_log --- enable_result_log - -# Dump the tables that should be compared --- source include/system_db_struct.inc - --- disable_query_log - -# Drop all tables created by this test -DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, proxies_priv, innodb_index_stats, innodb_table_stats, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos; - --- enable_query_log - -# check that we dropped all system tables -show tables; - -# End of 4.1 tests diff --git a/mysql-test/t/system_mysql_db_fix50030.test b/mysql-test/t/system_mysql_db_fix50030.test deleted file mode 100644 index c3e7dd7b9b1..00000000000 --- a/mysql-test/t/system_mysql_db_fix50030.test +++ /dev/null @@ -1,89 +0,0 @@ -# Embedded server doesn't support external clients ---source include/not_embedded.inc ---source include/have_innodb.inc - -# Don't run this test if $MYSQL_FIX_PRIVILEGE_TABLES isn't set -# to the location of mysql_fix_privilege_tables.sql -if (!$MYSQL_FIX_PRIVILEGE_TABLES) -{ - skip Test needs MYSQL_FIX_PRIVILEGE_TABLES; -} - -# -# This is the test for mysql_fix_privilege_tables -# It checks that a system tables from mysql 5.0.30 -# can be upgraded to current system table format -# -# Note: If this test fails, don't be confused about the errors reported -# by mysql-test-run This shows warnings generated by -# mysql_fix_system_tables which should be ignored. -# Instead, concentrate on the errors in r/system_mysql_db.reject - --- disable_result_log --- disable_query_log - -use test; - -# create system tables as in mysql-5.0.30 -# created by executing "./mysql_create_system_tables real ." - -set storage_engine=myisam; -CREATE TABLE db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; -INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N'); -INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N'); - -CREATE TABLE host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; - -CREATE TABLE user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; -INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); -INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0, 0); - -CREATE TABLE func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions'; - -CREATE TABLE tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges'; - -CREATE TABLE columns_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges'; - -CREATE TABLE help_topic ( help_topic_id int unsigned not null, name char(64) not null, help_category_id smallint unsigned not null, description text not null, example text not null, url char(128) not null, primary key (help_topic_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help topics'; -CREATE TABLE help_category ( help_category_id smallint unsigned not null, name char(64) not null, parent_category_id smallint unsigned null, url char(128) not null, primary key (help_category_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help categories'; -CREATE TABLE help_relation ( help_topic_id int unsigned not null references help_topic, help_keyword_id int unsigned not null references help_keyword, primary key (help_keyword_id, help_topic_id) ) engine=MyISAM CHARACTER SET utf8 comment='keyword-topic relation'; -CREATE TABLE help_keyword ( help_keyword_id int unsigned not null, name char(64) not null, primary key (help_keyword_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; - -CREATE TABLE time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY Name (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; - -CREATE TABLE time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY TzId (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; - -CREATE TABLE time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; - -CREATE TABLE time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; - -CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; - -CREATE TABLE proc ( db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum('CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA' ) DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob DEFAULT '' NOT NULL, returns char(64) DEFAULT '' NOT NULL, body longblob DEFAULT '' NOT NULL, definer char(77) collate utf8_bin DEFAULT '' NOT NULL, created timestamp, modified timestamp, sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'NOT_USED', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE' ) DEFAULT '' NOT NULL, comment char(64) collate utf8_bin DEFAULT '' NOT NULL, PRIMARY KEY (db,name,type) ) engine=MyISAM character set utf8 comment='Stored Procedures'; - -CREATE TABLE procs_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Routine_name char(64) binary DEFAULT '' NOT NULL, Routine_type enum('FUNCTION','PROCEDURE') NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY (Host,Db,User,Routine_name,Routine_type), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Procedure privileges'; - -CREATE TABLE servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(64) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(64) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner char(64) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) CHARACTER SET utf8 comment='MySQL Foreign Servers table'; - -INSERT INTO servers VALUES ('test','localhost','test','root','', 0,'','mysql','root'); - -# Run the mysql_fix_privilege_tables.sql using "mysql --force" ---exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES - --- enable_query_log --- enable_result_log - -# Dump the tables that should be compared --- source include/system_db_struct.inc - --- disable_query_log - -# Drop all tables created by this test -DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, proxies_priv, innodb_index_stats, innodb_table_stats, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos; - --- enable_query_log - -# check that we dropped all system tables -show tables; - -# End of 4.1 tests diff --git a/mysql-test/t/table_elim.test b/mysql-test/t/table_elim.test index 0d42dca57b7..24f48206013 100644 --- a/mysql-test/t/table_elim.test +++ b/mysql-test/t/table_elim.test @@ -610,3 +610,34 @@ SELECT t1.alpha3 FROM t1 LEFT JOIN ( t2 LEFT JOIN t3 ON t2.t3_code = t3.code ) DROP TABLE t1, t2, t3; SET optimizer_switch=@save_optimizer_switch; + +--echo # +--echo # MDEV-7893: table_elimination works wrong with on computed expression and compound unique key +--echo # (just a testcase) +CREATE TABLE t1 ( + PostID int(10) unsigned NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO t1 (PostID) VALUES (1), (2); + +CREATE TABLE t2 ( + VoteID int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, + EntityID int(10) unsigned NOT NULL, + UserID int(10) unsigned NOT NULL, + UNIQUE KEY EntityID (EntityID,UserID) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO t2 (EntityID, UserID) VALUES (1, 30), (2, 30); + +SELECT t1.*, T.Voted as Voted +FROM +t1 LEFT JOIN ( + SELECT 1 AS Voted, EntityID + FROM t2 + WHERE t2.UserID = '20' ) AS T + ON T.EntityID = t1.PostID +WHERE t1.PostID='1' +LIMIT 1; + +DROP TABLE t1,t2; + diff --git a/mysql-test/t/table_keyinfo-6838.test b/mysql-test/t/table_keyinfo-6838.test new file mode 100644 index 00000000000..5f4c9f44f86 --- /dev/null +++ b/mysql-test/t/table_keyinfo-6838.test @@ -0,0 +1,18 @@ +# Test case for MDEV-6838. +# Due to incorrect key_length computation, this usecase failed with the error +# Using too big key for internal temp table. + +CREATE TABLE t1 (i INT, state VARCHAR(997)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,'Louisiana'),(9,'Maine'); + +CREATE TABLE t2 (state VARCHAR(997), j INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('Louisiana',9),('Alaska',5); +INSERT INTO t2 SELECT t2.* FROM t2 JOIN t2 AS t3 JOIN t2 AS t4 JOIN t2 AS t5 JOIN t2 AS t6; + +SET @@max_heap_table_size= 16384; +set @@optimizer_switch='derived_merge=OFF'; +set @@optimizer_switch='extended_keys=ON'; + +SELECT * FROM t1 AS t1_1 LEFT JOIN ( t1 AS t1_2 INNER JOIN (SELECT * FROM t2) v2 ON t1_2.i = j ) ON t1_1.state = v2.state LIMIT 1; + +DROP TABLE t1, t2; diff --git a/mysql-test/t/tmp_table_count-7586.test b/mysql-test/t/tmp_table_count-7586.test new file mode 100644 index 00000000000..e7bac127815 --- /dev/null +++ b/mysql-test/t/tmp_table_count-7586.test @@ -0,0 +1,56 @@ +# MDEV-7586 regression test. +# Test if created_tmp_tables status variable is correctly incremented. +--source include/have_perfschema.inc +--source include/not_embedded.inc + +create table t2 (a int); +insert into t2 values (1),(2),(3); +create view v2 as select a from t2; + +flush status; +select * from v2; +show status like '%Created_tmp%'; + +explain select * from v2; + +select * from (select * from t2) T1; +show status like '%Created_tmp%'; + +explain select * from (select * from t2) T1; + + +drop view v2; +drop table t2; + + +--disable_ps_protocol + +CREATE TABLE t1(a int); +INSERT INTO t1 values(1),(2); +CREATE TABLE t2(a int); +INSERT INTO t2 values(1),(2); + +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +truncate table performance_schema.events_statements_history_long; +flush status; +CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +--echo # Performance schema should be the same as "Created_tmp_tables" variable below +select sum(created_tmp_tables) from performance_schema.events_statements_history_long; +show status like '%Created_tmp%'; +drop table t3; + +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a); +truncate table performance_schema.events_statements_history_long; +flush status; +CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a); +--echo # Performance schema should be the same as "Created_tmp_tables" variable below +select sum(created_tmp_tables) from performance_schema.events_statements_history_long; +show status like '%Created_tmp%'; + +drop table t1,t2,t3; + +truncate table performance_schema.events_statements_history_long; +flush status; +--echo # Performance schema should be the same as "Created_tmp_tables" variable below +select sum(created_tmp_tables) from performance_schema.events_statements_history_long; +show status like '%Created_tmp%'; diff --git a/mysql-test/t/trigger-trans.test b/mysql-test/t/trigger-trans.test index 82bee7aa224..c17202055e1 100644 --- a/mysql-test/t/trigger-trans.test +++ b/mysql-test/t/trigger-trans.test @@ -2,6 +2,9 @@ # (or just InnoDB storage engine) --source include/have_innodb.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + --disable_warnings drop table if exists t1; --enable_warnings @@ -182,3 +185,54 @@ insert into t1 values ( 654, 'a'), ( 654, 'b'), ( 654, 'c'), select * from t2 order by b; drop trigger t1_after_insert; drop table t1,t2; + +--echo # +--echo #Bug#19683834 SOME INNODB ERRORS CAUSES STORED FUNCTION +--echo # AND TRIGGER HANDLERS TO BE IGNORED + +--echo #Code fixed in Bug#16041903 +--enable_connect_log + +CREATE TABLE t1 (id int unsigned PRIMARY KEY, val int DEFAULT 0) +ENGINE=InnoDB; +INSERT INTO t1 (id) VALUES (1), (2); + +CREATE TABLE t2 (id int PRIMARY KEY); +CREATE TABLE t3 LIKE t2; + +# Trigger with continue handler for ER_DUP_ENTRY(1062) +DELIMITER //; +CREATE TRIGGER bef_insert BEFORE INSERT ON t2 FOR EACH ROW +BEGIN + DECLARE CONTINUE HANDLER FOR 1062 BEGIN END; + INSERT INTO t3 (id) VALUES (NEW.id); + INSERT INTO t3 (id) VALUES (NEW.id); +END// +DELIMITER ;// + +# Transaction 1: Grab locks on t1 +START TRANSACTION; +UPDATE t1 SET val = val + 1; + +# Transaction 2: +--connect (con2,localhost,root,,test,,) +SET SESSION innodb_lock_wait_timeout = 2; +# Trigger lock timeout (1205) +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET val = val + 1; + +# This insert should go through, as the continue handler should +# handle ER_DUP_ENTRY, even after ER_LOCK_WAIT_TIMEOUT (Bug#16041903) +INSERT INTO t2 (id) VALUES (1); + +# Cleanup +disconnect con2; +--source include/wait_until_disconnected.inc +connection default; + +DROP TABLE t3, t2, t1; + +--disable_connect_log + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index 4a1a3a6167c..384dd6cdec5 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -2237,8 +2237,10 @@ drop table if exists t1; create table t1 (i int, j int); create trigger t1_bi before insert on t1 for each row begin end; ---error ER_NOT_SUPPORTED_YET +--error ER_TRG_ALREADY_EXISTS create trigger t1_bi before insert on t1 for each row begin end; +--error ER_NOT_SUPPORTED_YET +create trigger t1_bi2 before insert on t1 for each row begin end; drop trigger t1_bi; --error ER_TRG_DOES_NOT_EXIST drop trigger t1_bi; diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test index 77ce8c595ca..a12b221dc38 100644 --- a/mysql-test/t/type_timestamp.test +++ b/mysql-test/t/type_timestamp.test @@ -492,4 +492,48 @@ drop function f1; set timestamp=0; SET time_zone=DEFAULT; +--echo # +--echo # MDEV-7778 impossible create copy of table, if table contain default value for timestamp field +--echo # + +SET sql_mode="NO_ZERO_DATE"; +CREATE TABLE t1 ( + ts timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +); +CREATE TABLE t2 AS SELECT * from t1 LIMIT 0; +SHOW CREATE TABLE t1; +SHOW CREATE TABLE t2; +DROP TABLE t1,t2; +SET sql_mode=DEFAULT; + +--echo # +--echo # MDEV-8082 ON UPDATE is not preserved by CREATE TABLE .. SELECT +--echo # +CREATE TABLE t1 ( + vc VARCHAR(10) NOT NULL DEFAULT 'test', + ts timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP +); +CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 0; +SHOW CREATE TABLE t1; +SHOW CREATE TABLE t2; +DROP TABLE t1,t2; + + --echo End of 10.0 tests + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-7831 Bad warning for DATE_ADD(timestamp_column, INTERVAL 10 SECOND) +--echo # +CREATE TABLE t1 (a TIMESTAMP); +INSERT INTO t1 VALUES ('0000-00-00 00:00:00'); +SELECT DATE_ADD(a, INTERVAL 10 SECOND) FROM t1; +DROP TABLE t1; + + +--echo # +--echo # End of 10.1 tests +--echo # diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test index 528d26d6f86..cc09069508f 100644 --- a/mysql-test/t/type_varchar.test +++ b/mysql-test/t/type_varchar.test @@ -240,6 +240,42 @@ SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1; EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1; DROP TABLE IF EXISTS t1,t2; + +--echo # +--echo # MDEV-6989 BINARY and COLLATE xxx_bin comparisions are not used for optimization in some cases +--echo # +CREATE TABLE t1 (c1 VARCHAR(20) CHARACTER SET latin1, PRIMARY KEY(c1)); +INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'); +SELECT * FROM t1 WHERE c1=BINARY 'a'; +EXPLAIN SELECT * FROM t1 WHERE c1=BINARY 'a'; +SELECT * FROM t1 WHERE c1=_latin1'a' COLLATE latin1_bin; +EXPLAIN SELECT * FROM t1 WHERE c1=_latin1'a' COLLATE latin1_bin; +DROP TABLE t1; + +CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin); +INSERT INTO t1 VALUES ('a'); +CREATE TABLE t2 (c1 VARCHAR(10) CHARACTER SET latin1, PRIMARY KEY(c1)); +INSERT INTO t2 VALUES ('a'),('b'); +SELECT * FROM t1, t2 WHERE t1.c1=t2.c1; +EXPLAIN SELECT * FROM t1, t2 WHERE t1.c1=t2.c1; +ALTER TABLE t1 MODIFY c1 VARBINARY(10); +SELECT * FROM t1, t2 WHERE t1.c1=t2.c1; +EXPLAIN SELECT * FROM t1, t2 WHERE t1.c1=t2.c1; +DROP TABLE t1, t2; + +CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin); +INSERT INTO t1 VALUES ('a'),('c'); +CREATE TABLE t2 (c1 VARCHAR(10) CHARACTER SET latin1, PRIMARY KEY(c1)); +INSERT INTO t2 VALUES ('a'),('b'); +SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1); +--echo # t2 should be eliminated +EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1); +ALTER TABLE t1 MODIFY c1 VARBINARY(10); +SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1); +--echo # t2 should be eliminated +EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1); +DROP TABLE t1,t2; + --echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/uniques_crash-7912.test b/mysql-test/t/uniques_crash-7912.test new file mode 100644 index 00000000000..8dc82f8f540 --- /dev/null +++ b/mysql-test/t/uniques_crash-7912.test @@ -0,0 +1,26 @@ +# +# MDEV-7912 +# +# multitable delete with wrongly set sort_buffer_size crashes in merge_buffers + +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/windows.inc + +call mtr.add_suppression("Out of memory"); + +set sql_mode=""; +--disable_warnings +drop table if exists t1,t2; +create table `t1` (`a` datetime not null) engine=InnoDB; +create table `t2` (`a` int not null) engine=innodb; +replace into t1 values (),(); +insert into t2 values(0); +set session sort_buffer_size = 1024*1024*1024*1024; +#Either fail with EE_OUTOFMEMORY, or succeed +--error 0 , 5 +delete d2 from t2 as d1, t1 as d2 where d1.a <=> d2.a; +--enable_warnings + +drop table t2; +drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index ae78d5504cf..84d7da548b2 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5345,6 +5345,28 @@ create view v1 as select 1; drop view v1; +--echo # +--echo # MDEV-7260: Crash in get_best_combination when executing multi-table +--echo # UPDATE with nested views +--echo # + +CREATE TABLE `t1` (`id` bigint(20)); + +INSERT INTO `t1` VALUES (1),(2); + +CREATE TABLE `t2` (`id` bigint(20)); + +CREATE TABLE `t3` (`id` bigint(20), `flag` tinyint(4)); + +create view v1 as select id from t1; + +create view v2 as select t2.* from (t2 left join v1 using (id)); + +update t3 left join v2 using (id) set flag=flag+1; + +drop view v2, v1; +drop table t1, t2, t3; + --echo # ----------------------------------------------------------------- --echo # -- End of 5.5 tests. --echo # ----------------------------------------------------------------- diff --git a/mysql-test/t/view_alias.test b/mysql-test/t/view_alias.test index b155ba6c2a9..09d707296bb 100644 --- a/mysql-test/t/view_alias.test +++ b/mysql-test/t/view_alias.test @@ -90,3 +90,12 @@ eval CREATE VIEW v1 AS $query; DROP VIEW v1; DROP TABLE t1, t2; + +# +# MDEV-7482 VIEW containing INTERVAL(...) +# +create view v1 as select interval(55,10) as my_col; +show create view v1; +select * from v1; +drop view v1; + diff --git a/mysql-test/t/xa_sync.test b/mysql-test/t/xa_sync.test new file mode 100644 index 00000000000..8a995c4a184 --- /dev/null +++ b/mysql-test/t/xa_sync.test @@ -0,0 +1,46 @@ +--source include/have_debug_sync.inc + +--echo # +--echo # MDEV-7793 - Race condition between XA COMMIT/ROLLBACK and disconnect +--echo # +--echo # Note that this test is meaningful only with valgrind. +let $op= XA COMMIT 'xatest'; +let $i= 2; +while ($i) +{ + connect con1, localhost, root; + connect con2, localhost, root; + + connection con1; + XA START 'xatest'; + XA END 'xatest'; + XA PREPARE 'xatest'; + + connection con2; + SET debug_sync='xa_after_search SIGNAL parked WAIT_FOR go'; + send_eval $op; + + connection default; + SET debug_sync='now WAIT_FOR parked'; + disconnect con1; + disable_query_log; + echo # Waiting for thread to get deleted; + while (`SELECT VARIABLE_VALUE!=2 FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='max_used_connections'`) + { + real_sleep 0.1; + FLUSH STATUS; + } + enable_query_log; + SET debug_sync='now SIGNAL go'; + + connection con2; + --error ER_XAER_NOTA + reap; + disconnect con2; + + connection default; + SET debug_sync='RESET'; + + let $op= XA ROLLBACK 'xatest'; + dec $i; +} |