mirror of
https://github.com/MariaDB/server.git
synced 2025-08-18 16:31:36 +02:00

Remove one of the major sources of race condiitons in mariadb-test. Normally, mariadb_close() sends COM_QUIT to the server and immediately disconnects. In mariadb-test it means the test can switch to another connection and sends queries to the server before the server even started parsing the COM_QUIT packet and these queries can see the connection as fully active, as it didn't reach dispatch_command yet. This is a major source of instability in tests and many - but not all, still less than a half - tests employ workarounds. The correct one is a pair count_sessions.inc/wait_until_count_sessions.inc. Also very popular was wait_until_disconnected.inc, which was completely useless, because it verifies that the connection is closed, and after disconnect it always is, it didn't verify whether the server processed COM_QUIT. Sadly the placebo was as widely used as the real thing. Let's fix this by making mariadb-test `disconnect` command _to wait_ for the server to confirm. This makes almost all workarounds redundant. In some cases count_sessions.inc/wait_until_count_sessions.inc is still needed, though, as only `disconnect` command is changed: * after external tools, like `exec $MYSQL` * after failed `connect` command * replication, after `STOP SLAVE` * Federated/CONNECT/SPIDER/etc after `DROP TABLE` and also in some XA tests, because an XA transaction is dissociated from the THD very late, after the server has closed the client connection. Collateral cleanups: fix comments, remove some redundant statements: * DROP IF EXISTS if nothing is known to exist * DROP table/view before DROP DATABASE * REVOKE privileges before DROP USER etc
260 lines
7.3 KiB
Text
260 lines
7.3 KiB
Text
#
|
|
# Privilege-specific tests for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
|
|
#
|
|
|
|
# Grant tests not performed with embedded server
|
|
--source include/not_embedded.inc
|
|
--source include/default_optimizer_switch.inc
|
|
|
|
set GLOBAL sql_mode="";
|
|
set LOCAL sql_mode="";
|
|
|
|
CREATE DATABASE privtest_db;
|
|
|
|
CREATE TABLE privtest_db.t1 (a INT);
|
|
CREATE TABLE privtest_db.t2 (a INT);
|
|
INSERT INTO privtest_db.t2 VALUES (1), (2), (3);
|
|
|
|
GRANT USAGE ON *.* TO 'privtest'@'localhost';
|
|
GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost';
|
|
|
|
connect(con1,localhost,privtest,,);
|
|
connection con1;
|
|
--source include/default_optimizer_switch.inc
|
|
|
|
USE privtest_db;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN INSERT INTO t1 VALUES (10);
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
INSERT INTO t1 VALUES (10);
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN INSERT INTO t1 SELECT * FROM t2;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
INSERT INTO t1 SELECT * FROM t2;
|
|
|
|
connection default;
|
|
GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
EXPLAIN INSERT INTO t1 VALUES (10);
|
|
INSERT INTO t1 VALUES (10);
|
|
|
|
EXPLAIN INSERT INTO t1 SELECT * FROM t2;
|
|
INSERT INTO t1 SELECT * FROM t2;
|
|
|
|
|
|
connection default;
|
|
REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN REPLACE INTO t1 VALUES (10);
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
REPLACE INTO t1 VALUES (10);
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
REPLACE INTO t1 SELECT * FROM t2;
|
|
|
|
connection default;
|
|
GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN REPLACE INTO t1 VALUES (10);
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
REPLACE INTO t1 VALUES (10);
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
REPLACE INTO t1 SELECT * FROM t2;
|
|
|
|
connection default;
|
|
REVOKE INSERT ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN REPLACE INTO t1 VALUES (10);
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
REPLACE INTO t1 VALUES (10);
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
REPLACE INTO t1 SELECT * FROM t2;
|
|
|
|
connection default;
|
|
GRANT INSERT, DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
EXPLAIN REPLACE INTO t1 VALUES (10);
|
|
REPLACE INTO t1 VALUES (10);
|
|
|
|
EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
|
|
REPLACE INTO t1 SELECT * FROM t2;
|
|
|
|
connection default;
|
|
REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN UPDATE t1 SET a = a + 1;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
UPDATE t1 SET a = a + 1;
|
|
|
|
--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
|
|
UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_COLUMNACCESS_DENIED_ERROR
|
|
EXPLAIN UPDATE t1 SET a = a + 1;
|
|
--error ER_COLUMNACCESS_DENIED_ERROR
|
|
UPDATE t1 SET a = a + 1;
|
|
|
|
--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
|
|
UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
REVOKE UPDATE ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN UPDATE t1 SET a = a + 1;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
UPDATE t1 SET a = a + 1;
|
|
|
|
--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
|
|
UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
GRANT UPDATE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
EXPLAIN UPDATE t1 SET a = a + 1;
|
|
UPDATE t1 SET a = a + 1;
|
|
|
|
EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
|
|
UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN DELETE FROM t1 WHERE a = 10;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
DELETE FROM t1 WHERE a = 10;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_COLUMNACCESS_DENIED_ERROR
|
|
EXPLAIN DELETE FROM t1 WHERE a = 10;
|
|
--error ER_COLUMNACCESS_DENIED_ERROR
|
|
DELETE FROM t1 WHERE a = 10;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN DELETE FROM t1 WHERE a = 10;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
DELETE FROM t1 WHERE a = 10;
|
|
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
--error ER_TABLEACCESS_DENIED_ERROR
|
|
DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
|
|
connection default;
|
|
REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
GRANT DELETE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
EXPLAIN DELETE FROM t1 WHERE a = 10;
|
|
DELETE FROM t1 WHERE a = 10;
|
|
|
|
EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
|
|
|
|
# Views
|
|
|
|
connection default;
|
|
REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
|
|
CREATE VIEW privtest_db.v1 (a) AS SELECT a FROM privtest_db.t1;
|
|
GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.v1 TO 'privtest'@'localhost';
|
|
connection con1;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN SELECT * FROM v1;
|
|
SELECT * FROM v1;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN INSERT INTO v1 VALUES (10);
|
|
INSERT INTO v1 VALUES (10);
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN INSERT INTO v1 SELECT * FROM t2;
|
|
INSERT INTO v1 SELECT * FROM t2;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN REPLACE INTO v1 VALUES (10);
|
|
REPLACE INTO v1 VALUES (10);
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN REPLACE INTO v1 SELECT * FROM t2;
|
|
REPLACE INTO v1 SELECT * FROM t2;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN UPDATE v1 SET a = a + 1;
|
|
UPDATE v1 SET a = a + 1;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
|
|
UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN DELETE FROM v1 WHERE a = 10;
|
|
DELETE FROM v1 WHERE a = 10;
|
|
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
|
|
DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
|
|
|
|
connection default;
|
|
disconnect con1;
|
|
|
|
DROP USER 'privtest'@localhost;
|
|
USE test;
|
|
DROP DATABASE privtest_db;
|
|
|
|
set GLOBAL sql_mode=default;
|
|
set LOCAL sql_mode=default;
|