Commit 815c607d authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-4879 - Merge test cases for new CREATE TEMPORARY TABLE privilege model

- merged test cases for MySQL bug#27480
- fixed that LOCK TABLES was unable to open temporary table
  (covered by grant2 test, merged appropriate code from 5.6)
- commented lines that cause server crash in merge test, reported
  MDEV-5042 (not relevant to bug#27480)
parent 8b5938a1
This diff is collapsed.
......@@ -121,3 +121,60 @@ View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t_select_priv`.`a` AS `a`,`t_select_priv`.`b` AS `b` from `t_select_priv` latin1 latin1_swedish_ci
drop database mysqltest_db1;
drop user mysqltest_u1@localhost;
#
# Additional coverage for refactoring which is made as part
# of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
# to allow temp table operations".
#
# Check that for statements like CHECK/REPAIR and OPTIMIZE TABLE
# privileges for all tables involved are checked before processing
# any tables. Doing otherwise, i.e. checking privileges for table
# right before processing it might result in lost results for tables
# which were processed by the time when table for which privileges
# are insufficient are discovered.
#
call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*mysqltest_u1 Checking table");
drop database if exists mysqltest_db1;
create database mysqltest_db1;
# Create tables which we are going to CHECK/REPAIR.
create table mysqltest_db1.t1 (a int, key(a)) engine=myisam;
create table mysqltest_db1.t2 (b int);
insert into mysqltest_db1.t1 values (1), (2);
insert into mysqltest_db1.t2 values (1);
# Create user which will try to do this.
create user mysqltest_u1@localhost;
grant insert, select on mysqltest_db1.t1 to mysqltest_u1@localhost;
# Corrupt t1 by replacing t1.MYI with a corrupt + unclosed one created
# by doing: 'create table t1 (a int key(a))'
# head -c1024 t1.MYI > corrupt_t1.MYI
flush table mysqltest_db1.t1;
# Switching to connection 'con1'.
check table mysqltest_db1.t1;
Table Op Msg_type Msg_text
mysqltest_db1.t1 check warning 1 client is using or hasn't closed the table properly
mysqltest_db1.t1 check error Size of indexfile is: 1024 Should be: 2048
mysqltest_db1.t1 check warning Size of datafile is: 14 Should be: 7
mysqltest_db1.t1 check error Corrupt
# The below statement should fail before repairing t1.
# Otherwise info about such repair will be missing from its result-set.
repair table mysqltest_db1.t1, mysqltest_db1.t2;
ERROR 42000: SELECT, INSERT command denied to user 'mysqltest_u1'@'localhost' for table 't2'
# The same is true for CHECK TABLE statement.
check table mysqltest_db1.t1, mysqltest_db1.t2;
ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't2'
check table mysqltest_db1.t1;
Table Op Msg_type Msg_text
mysqltest_db1.t1 check warning Table is marked as crashed
mysqltest_db1.t1 check warning 1 client is using or hasn't closed the table properly
mysqltest_db1.t1 check error Size of indexfile is: 1024 Should be: 2048
mysqltest_db1.t1 check warning Size of datafile is: 14 Should be: 7
mysqltest_db1.t1 check error Corrupt
repair table mysqltest_db1.t1;
Table Op Msg_type Msg_text
mysqltest_db1.t1 repair warning Number of rows changed from 1 to 2
mysqltest_db1.t1 repair status OK
# Clean-up.
# Switching to connection 'default'.
drop database mysqltest_db1;
drop user mysqltest_u1@localhost;
......@@ -3826,3 +3826,90 @@ test.m1 repair error Corrupt
drop tables m1, t1, t4;
drop view t3;
End of 5.5 tests
#
# Additional coverage for refactoring which is made as part
# of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
# to allow temp table operations".
#
# Check that prelocking works correctly for various variants of
# merge tables.
drop table if exists t1, t2, m1;
drop function if exists f1;
create table t1 (j int);
insert into t1 values (1);
create function f1() returns int return (select count(*) from m1);
create temporary table t2 (a int) engine=myisam;
insert into t2 values (1);
create temporary table m1 (a int) engine=merge union=(t2);
select f1() from t1;
f1()
1
drop tables t2, m1;
create table t2 (a int) engine=myisam;
insert into t2 values (1);
create table m1 (a int) engine=merge union=(t2);
select f1() from t1;
f1()
1
drop table m1;
create temporary table m1 (a int) engine=merge union=(t2);
select f1() from t1;
f1()
1
drop tables t1, t2, m1;
drop function f1;
#
# Check that REPAIR/CHECK and CHECKSUM statements work correctly
# for various variants of merge tables.
create table t1 (a int) engine=myisam;
insert into t1 values (1);
create table m1 (a int) engine=merge union=(t1);
check table m1;
Table Op Msg_type Msg_text
test.m1 check status OK
repair table m1;
Table Op Msg_type Msg_text
test.m1 repair note The storage engine for the table doesn't support repair
checksum table m1;
Table Checksum
test.m1 3459908756
drop tables t1, m1;
create temporary table t1 (a int) engine=myisam;
insert into t1 values (1);
create temporary table m1 (a int) engine=merge union=(t1);
check table m1;
Table Op Msg_type Msg_text
test.m1 check status OK
repair table m1;
Table Op Msg_type Msg_text
test.m1 repair note The storage engine for the table doesn't support repair
checksum table m1;
Table Checksum
test.m1 3459908756
drop tables t1, m1;
create table t1 (a int) engine=myisam;
insert into t1 values (1);
create temporary table m1 (a int) engine=merge union=(t1);
check table m1;
Table Op Msg_type Msg_text
test.m1 check status OK
repair table m1;
Table Op Msg_type Msg_text
test.m1 repair note The storage engine for the table doesn't support repair
checksum table m1;
Table Checksum
test.m1 3459908756
drop tables t1, m1;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS m1;
DROP TRIGGER IF EXISTS trg1;
DROP TABLE IF EXISTS q1;
DROP TABLE IF EXISTS q2;
CREATE TABLE t1(a INT);
CREATE TABLE m1(a INT) ENGINE = MERGE UNION (q1, q2);
CREATE TRIGGER trg1 BEFORE DELETE ON t1
FOR EACH ROW
INSERT INTO m1 VALUES (1);
DROP TRIGGER trg1;
DROP TABLE t1;
DROP TABLE m1;
......@@ -2502,3 +2502,43 @@ drop procedure if exists p_verify_reprepare_count;
drop procedure if exists p1;
drop function if exists f1;
drop view if exists v1, v2;
#
# Additional coverage for refactoring which was made as part of work
# on bug '27480: Extend CREATE TEMPORARY TABLES privilege to allow
# temp table operations'.
#
# Check that we don't try to pre-open temporary tables for the elements
# from prelocking list, as this can lead to unwarranted ER_CANT_REOPEN
# errors.
DROP TABLE IF EXISTS t1, tm;
CREATE TABLE t1 (a INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
SET @a:= (SELECT COUNT(*) FROM t1);
# Prelocking list for the below statement should
# contain t1 twice - once for the INSERT and once
# SELECT from the trigger.
PREPARE stmt1 FROM 'INSERT INTO t1 VALUES (1)';
EXECUTE stmt1;
# Create temporary table which will shadow t1.
CREATE TEMPORARY TABLE t1 (b int);
# The below execution of statement should not fail with ER_CANT_REOPEN
# error. Instead stmt1 should be auto-matically reprepared and succeed.
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
DROP TEMPORARY TABLE t1;
DROP TABLE t1;
#
# Also check that we properly reset table list elements from UNION
# clause of CREATE TABLE and ALTER TABLE statements.
#
CREATE TEMPORARY TABLE t1 (i INT);
PREPARE stmt2 FROM 'CREATE TEMPORARY TABLE tm (i INT) ENGINE=MERGE UNION=(t1)';
EXECUTE stmt2;
DROP TEMPORARY TABLE tm;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
PREPARE stmt3 FROM 'ALTER TABLE tm UNION=(t1)';
EXECUTE stmt3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;
DROP TEMPORARY TABLES tm, t1;
......@@ -243,3 +243,51 @@ CREATE TEMPORARY TABLE bug48067.t1 (c1 int);
DROP DATABASE bug48067;
DROP TEMPORARY table bug48067.t1;
End of 5.1 tests
#
# Test that admin statements work for temporary tables.
#
DROP TABLE IF EXISTS t1,t2;
CREATE TEMPORARY TABLE t1(a INT);
CREATE TEMPORARY TABLE t2(b INT);
CREATE TEMPORARY TABLE t3(c INT);
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
ANALYZE TABLE t1, t2, t3;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
test.t3 analyze status OK
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
CHECK TABLE t1, t2, t3;
Table Op Msg_type Msg_text
test.t1 check status OK
test.t2 check status OK
test.t3 check status OK
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
CHECKSUM TABLE t1, t2, t3;
Table Checksum
test.t1 xxx
test.t2 xxx
test.t3 xxx
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
OPTIMIZE TABLE t1, t2, t3;
Table Op Msg_type Msg_text
test.t1 optimize status OK
test.t2 optimize status OK
test.t3 optimize status OK
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
REPAIR TABLE t1, t2, t3;
Table Op Msg_type Msg_text
test.t1 repair status OK
test.t2 repair status OK
test.t3 repair status OK
DROP TABLES t1, t2, t3;
......@@ -1803,4 +1803,90 @@ a b
4 40
HANDLER t1 CLOSE;
DROP TABLE t1;
#
# Additional coverage for refactoring which is made as part
# of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
# to allow temp table operations".
#
# Check that DDL on temporary table properly closes HANDLER cursors
# for this table belonging to the same connection.
CREATE TEMPORARY TABLE t1 AS SELECT 1 AS f1;
# -- CREATE TABLE
HANDLER t1 OPEN;
CREATE TEMPORARY TABLE IF NOT EXISTS t1 SELECT 1 AS f1;
Warnings:
Note 1050 Table 't1' already exists
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- REPAIR TABLE
HANDLER t1 OPEN;
REPAIR TABLE t1;
Table Op Msg_type Msg_text
test.t1 repair status OK
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- ANALYZE TABLE
HANDLER t1 OPEN;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- OPTIMIZE TABLE
HANDLER t1 OPEN;
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- CHECK TABLE
HANDLER t1 OPEN;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- ALTER TABLE
HANDLER t1 OPEN;
ALTER TABLE t1 ADD COLUMN b INT;
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- CREATE INDEX
HANDLER t1 OPEN;
CREATE INDEX b ON t1 (b);
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- DROP INDEX
HANDLER t1 OPEN;
DROP INDEX b ON t1;
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- TRUNCATE TABLE
HANDLER t1 OPEN;
TRUNCATE TABLE t1;
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- DROP TABLE
HANDLER t1 OPEN;
DROP TABLE t1;
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
CREATE TEMPORARY TABLE t1(a INT, b INT, INDEX i(a));
set global keycache1.key_cache_block_size=2048;
set global keycache1.key_buffer_size=1*1024*1024;
set global keycache1.key_buffer_size=1024*1024;
# -- CACHE INDEX
HANDLER t1 OPEN;
CACHE INDEX t1 IN keycache1;
Table Op Msg_type Msg_text
test.t1 assign_to_keycache status OK
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
# -- LOAD INDEX
HANDLER t1 OPEN;
LOAD INDEX INTO CACHE t1;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
End of 5.1 tests
......@@ -79,4 +79,93 @@ HANDLER t1 CLOSE;
DROP TABLE t1;
--echo #
--echo # Additional coverage for refactoring which is made as part
--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
--echo # to allow temp table operations".
--echo #
--echo # Check that DDL on temporary table properly closes HANDLER cursors
--echo # for this table belonging to the same connection.
CREATE TEMPORARY TABLE t1 AS SELECT 1 AS f1;
--echo # -- CREATE TABLE
HANDLER t1 OPEN;
CREATE TEMPORARY TABLE IF NOT EXISTS t1 SELECT 1 AS f1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- REPAIR TABLE
HANDLER t1 OPEN;
REPAIR TABLE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- ANALYZE TABLE
HANDLER t1 OPEN;
ANALYZE TABLE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- OPTIMIZE TABLE
HANDLER t1 OPEN;
OPTIMIZE TABLE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- CHECK TABLE
HANDLER t1 OPEN;
CHECK TABLE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- ALTER TABLE
HANDLER t1 OPEN;
ALTER TABLE t1 ADD COLUMN b INT;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- CREATE INDEX
HANDLER t1 OPEN;
CREATE INDEX b ON t1 (b);
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- DROP INDEX
HANDLER t1 OPEN;
DROP INDEX b ON t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- TRUNCATE TABLE
HANDLER t1 OPEN;
TRUNCATE TABLE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- DROP TABLE
HANDLER t1 OPEN;
DROP TABLE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
CREATE TEMPORARY TABLE t1(a INT, b INT, INDEX i(a));
set global keycache1.key_cache_block_size=2048;
set global keycache1.key_buffer_size=1*1024*1024;
set global keycache1.key_buffer_size=1024*1024;
--echo # -- CACHE INDEX
HANDLER t1 OPEN;
CACHE INDEX t1 IN keycache1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo # -- LOAD INDEX
HANDLER t1 OPEN;
LOAD INDEX INTO CACHE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
--echo End of 5.1 tests
......@@ -114,4 +114,18 @@ Note 1050 Table 'v1' already exists
include/show_binlog_events.inc
DROP VIEW v1;
DROP TABLE t1, t2;
#
# Test case which has failed on assertion after refactoring which was
# made as part of fix for bug #27480 "Extend CREATE TEMPORARY TABLES
# privilege to allow temp table operations".
#
CREATE TEMPORARY TABLE t1 (id int);
CREATE TABLE IF NOT EXISTS t2 LIKE t1;
# The below statement should succeed with warning and
# should not crash due to failing assertion.
CREATE TABLE IF NOT EXISTS t2 LIKE t1;
Warnings:
Note 1050 Table 't2' already exists
# Clean-up.
DROP TABLE t1, t2;
include/rpl_end.inc
......@@ -173,4 +173,21 @@ DROP VIEW v1;
DROP TABLE t1, t2;
--echo #
--echo # Test case which has failed on assertion after refactoring which was
--echo # made as part of fix for bug #27480 "Extend CREATE TEMPORARY TABLES
--echo # privilege to allow temp table operations".
--echo #
CREATE TEMPORARY TABLE t1 (id int);
CREATE TABLE IF NOT EXISTS t2 LIKE t1;
--echo # The below statement should succeed with warning and
--echo # should not crash due to failing assertion.
CREATE TABLE IF NOT EXISTS t2 LIKE t1;
--echo # Clean-up.
DROP TABLE t1, t2;
sync_slave_with_master;
connection master;
--source include/rpl_end.inc
This diff is collapsed.
......@@ -142,3 +142,62 @@ connection default;
disconnect con1;
drop database mysqltest_db1;
drop user mysqltest_u1@localhost;
--echo #
--echo # Additional coverage for refactoring which is made as part
--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
--echo # to allow temp table operations".
--echo #
--echo # Check that for statements like CHECK/REPAIR and OPTIMIZE TABLE
--echo # privileges for all tables involved are checked before processing
--echo # any tables. Doing otherwise, i.e. checking privileges for table
--echo # right before processing it might result in lost results for tables
--echo # which were processed by the time when table for which privileges
--echo # are insufficient are discovered.
--echo #
call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*mysqltest_u1 Checking table");
--disable_warnings
drop database if exists mysqltest_db1;
--enable_warnings
let $MYSQLD_DATADIR = `SELECT @@datadir`;
create database mysqltest_db1;
--echo # Create tables which we are going to CHECK/REPAIR.
create table mysqltest_db1.t1 (a int, key(a)) engine=myisam;
create table mysqltest_db1.t2 (b int);
insert into mysqltest_db1.t1 values (1), (2);
insert into mysqltest_db1.t2 values (1);
--echo # Create user which will try to do this.
create user mysqltest_u1@localhost;
grant insert, select on mysqltest_db1.t1 to mysqltest_u1@localhost;
connect (con1,localhost,mysqltest_u1,,);
connection default;
--echo # Corrupt t1 by replacing t1.MYI with a corrupt + unclosed one created
--echo # by doing: 'create table t1 (a int key(a))'
--echo # head -c1024 t1.MYI > corrupt_t1.MYI
flush table mysqltest_db1.t1;
--remove_file $MYSQLD_DATADIR/mysqltest_db1/t1.MYI
--copy_file std_data/corrupt_t1.MYI $MYSQLD_DATADIR/mysqltest_db1/t1.MYI
--echo # Switching to connection 'con1'.
connection con1;
check table mysqltest_db1.t1;
--echo # The below statement should fail before repairing t1.
--echo # Otherwise info about such repair will be missing from its result-set.
--error ER_TABLEACCESS_DENIED_ERROR
repair table mysqltest_db1.t1, mysqltest_db1.t2;
--echo # The same is true for CHECK TABLE statement.
--error ER_TABLEACCESS_DENIED_ERROR
check table mysqltest_db1.t1, mysqltest_db1.t2;
check table mysqltest_db1.t1;
repair table mysqltest_db1.t1;
--echo # Clean-up.
disconnect con1;
--source include/wait_until_disconnected.inc
--echo # Switching to connection 'default'.
connection default;
drop database mysqltest_db1;
drop user mysqltest_u1@localhost;
......@@ -2873,6 +2873,86 @@ drop view t3;
--echo End of 5.5 tests
--echo #
--echo # Additional coverage for refactoring which is made as part
--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
--echo # to allow temp table operations".
--echo #
--echo # Check that prelocking works correctly for various variants of
--echo # merge tables.
--disable_warnings
drop table if exists t1, t2, m1;
drop function if exists f1;
--enable_warnings
create table t1 (j int);
insert into t1 values (1);
create function f1() returns int return (select count(*) from m1);
create temporary table t2 (a int) engine=myisam;
insert into t2 values (1);
create temporary table m1 (a int) engine=merge union=(t2);
select f1() from t1;
drop tables t2, m1;
create table t2 (a int) engine=myisam;
insert into t2 values (1);
create table m1 (a int) engine=merge union=(t2);
select f1() from t1;
drop table m1;
create temporary table m1 (a int) engine=merge union=(t2);
select f1() from t1;
drop tables t1, t2, m1;
drop function f1;
--echo #
--echo # Check that REPAIR/CHECK and CHECKSUM statements work correctly
--echo # for various variants of merge tables.
create table t1 (a int) engine=myisam;
insert into t1 values (1);
create table m1 (a int) engine=merge union=(t1);
check table m1;
repair table m1;
checksum table m1;
drop tables t1, m1;
create temporary table t1 (a int) engine=myisam;
insert into t1 values (1);
create temporary table m1 (a int) engine=merge union=(t1);
check table m1;
repair table m1;
checksum table m1;
drop tables t1, m1;
create table t1 (a int) engine=myisam;
insert into t1 values (1);
create temporary table m1 (a int) engine=merge union=(t1);
check table m1;
repair table m1;
checksum table m1;
drop tables t1, m1;
# Check effect of Bug#27480-preliminary patch:
# a merge-table with non-existing children, opened from a prelocked list.
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS m1;
DROP TRIGGER IF EXISTS trg1;
DROP TABLE IF EXISTS q1;
DROP TABLE IF EXISTS q2;
--enable_warnings
CREATE TABLE t1(a INT);
CREATE TABLE m1(a INT) ENGINE = MERGE UNION (q1, q2);
CREATE TRIGGER trg1 BEFORE DELETE ON t1
FOR EACH ROW
INSERT INTO m1 VALUES (1);
# Uncomment the following to lines when MDEV-5042 is fixed.
#--error ER_WRONG_MRG_TABLE
#DELETE FROM t1;
DROP TRIGGER trg1;
DROP TABLE t1;
DROP TABLE m1;
--disable_result_log
--disable_query_log
eval set global storage_engine=$default;
......
......@@ -2216,3 +2216,46 @@ drop procedure if exists p1;
drop function if exists f1;
drop view if exists v1, v2;
--enable_warnings
--echo #
--echo # Additional coverage for refactoring which was made as part of work
--echo # on bug '27480: Extend CREATE TEMPORARY TABLES privilege to allow
--echo # temp table operations'.
--echo #
--echo # Check that we don't try to pre-open temporary tables for the elements
--echo # from prelocking list, as this can lead to unwarranted ER_CANT_REOPEN
--echo # errors.
--disable_warnings ONCE
DROP TABLE IF EXISTS t1, tm;
CREATE TABLE t1 (a INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
SET @a:= (SELECT COUNT(*) FROM t1);
--echo # Prelocking list for the below statement should
--echo # contain t1 twice - once for the INSERT and once
--echo # SELECT from the trigger.
PREPARE stmt1 FROM 'INSERT INTO t1 VALUES (1)';
EXECUTE stmt1;
--echo # Create temporary table which will shadow t1.
CREATE TEMPORARY TABLE t1 (b int);
--echo # The below execution of statement should not fail with ER_CANT_REOPEN
--echo # error. Instead stmt1 should be auto-matically reprepared and succeed.
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
DROP TEMPORARY TABLE t1;
DROP TABLE t1;
--echo #
--echo # Also check that we properly reset table list elements from UNION
--echo # clause of CREATE TABLE and ALTER TABLE statements.
--echo #
CREATE TEMPORARY TABLE t1 (i INT);
PREPARE stmt2 FROM 'CREATE TEMPORARY TABLE tm (i INT) ENGINE=MERGE UNION=(t1)';
EXECUTE stmt2;
DROP TEMPORARY TABLE tm;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
PREPARE stmt3 FROM 'ALTER TABLE tm UNION=(t1)';
EXECUTE stmt3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;
DROP TEMPORARY TABLES tm, t1;
......@@ -276,3 +276,46 @@ DROP DATABASE bug48067;
DROP TEMPORARY table bug48067.t1;
--echo End of 5.1 tests
--echo #
--echo # Test that admin statements work for temporary tables.
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
CREATE TEMPORARY TABLE t1(a INT);
CREATE TEMPORARY TABLE t2(b INT);
CREATE TEMPORARY TABLE t3(c INT);
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
ANALYZE TABLE t1, t2, t3;
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
CHECK TABLE t1, t2, t3;
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
--replace_column 2 xxx
CHECKSUM TABLE t1, t2, t3;
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
OPTIMIZE TABLE t1, t2, t3;
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (11), (12), (13);
INSERT INTO t3 VALUES (101), (102), (103);
REPAIR TABLE t1, t2, t3;
DROP TABLES t1, t2, t3;
......@@ -121,6 +121,7 @@
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
static void sql_kill(THD *thd, longlong id, killed_state state, killed_type type);
static void sql_kill_user(THD *thd, LEX_USER *user, killed_state state);
static bool lock_tables_precheck(THD *thd, TABLE_LIST *tables);
static bool execute_show_status(THD *, TABLE_LIST *);
static bool execute_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
......@@ -3728,8 +3729,7 @@ case SQLCOM_PREPARE:
if (open_temporary_tables(thd, all_tables))
goto error;
if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables,
FALSE, UINT_MAX, FALSE))
if (lock_tables_precheck(thd, all_tables))
goto error;
thd->variables.option_bits|= OPTION_TABLE_LOCK;
......@@ -7900,6 +7900,35 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
}
/**
Check privileges for LOCK TABLES statement.
@param thd Thread context.
@param tables List of tables to be locked.
@retval FALSE - Success.
@retval TRUE - Failure.
*/
static bool lock_tables_precheck(THD *thd, TABLE_LIST *tables)
{
TABLE_LIST *first_not_own_table= thd->lex->first_not_own_table();
for (TABLE_LIST *table= tables; table != first_not_own_table && table;
table= table->next_global)
{
if (is_temporary_table(table))
continue;
if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, table,
FALSE, 1, FALSE))
return TRUE;
}
return FALSE;
}
/**
negate given expression.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment