mariadb/mysql-test/main/max_statement_time.test

237 lines
5 KiB
Text
Raw Normal View History

MDEV 4427: query timeouts Added MAX_STATEMENT_TIME user variable to automaticly kill queries after a given time limit has expired. - Added timer functions based on pthread_cond_timedwait - Added kill_handlerton() to signal storage engines about kill/timeout - Added support for GRANT ... MAX_STATEMENT_TIME=# - Copy max_statement_time to current user, if stored in mysql.user - Added status variable max_statement_time_exceeded - Added KILL_TIMEOUT - Removed digest hash from performance schema tests as they change all the time. - Updated test results that changed because of the new user variables or new fields in mysql.user This functionallity is inspired by work done by Davi Arnaut at twitter. Test case is copied from Davi's work. Documentation can be found at https://kb.askmonty.org/en/how-to-limittimeout-queries/ mysql-test/r/mysqld--help.result: Updated for new help message mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/sys_vars/r/max_statement_time_basic.result: Added testing of max_statement_time mysql-test/suite/sys_vars/t/max_statement_time_basic.test: Added testing of max_statement_time mysql-test/t/max_statement_time.test: Added testing of max_statement_time mysys/CMakeLists.txt: Added thr_timer mysys/my_init.c: mysys/mysys_priv.h: Added new mutex and condition variables Added new mutex and condition variables mysys/thr_timer.c: Added timer functions based on pthread_cond_timedwait() This can be compiled with HAVE_TIMER_CREATE to benchmark agains timer_create()/timer_settime() sql/lex.h: Added MAX_STATEMENT_TIME sql/log_event.cc: Safety fix (timeout should be threated as an interrupted query) sql/mysqld.cc: Added support for timers Added status variable max_statement_time_exceeded sql/share/errmsg-utf8.txt: Added ER_QUERY_TIMEOUT sql/signal_handler.cc: Added support for KILL_TIMEOUT sql/sql_acl.cc: Added support for GRANT ... MAX_STATEMENT_TIME=# Copy max_statement_time to current user sql/sql_class.cc: Added timer functionality to THD. Added thd_kill_timeout() sql/sql_class.h: Added timer functionality to THD. Added KILL_TIMEOUT Added max_statement_time variable in similar manner as long_query_time was done. sql/sql_connect.cc: Added handling of max_statement_time_exceeded sql/sql_parse.cc: Added starting and stopping timers for queries. sql/sql_show.cc: Added max_statement_time_exceeded for user/connects status in MariaDB 10.0 sql/sql_yacc.yy: Added support for GRANT ... MAX_STATEMENT_TIME=# syntax, to be enabled in 10.0 sql/structs.h: Added max_statement_time user resource sql/sys_vars.cc: Added max_statement_time variables mysql-test/suite/roles/create_and_drop_role_invalid_user_table.test Removed test as we require all fields in mysql.user table. scripts/mysql_system_tables.sql scripts/mysql_system_tables_data.sql scripts/mysql_system_tables_fix.sql Updated mysql.user with new max_statement_time field
2014-10-07 10:37:36 +02:00
#
# Test behavior of MAX_STATEMENT_TIME.
# We can't do this under valgrind as valgrind interferes with thread scheduling
MDEV 4427: query timeouts Added MAX_STATEMENT_TIME user variable to automaticly kill queries after a given time limit has expired. - Added timer functions based on pthread_cond_timedwait - Added kill_handlerton() to signal storage engines about kill/timeout - Added support for GRANT ... MAX_STATEMENT_TIME=# - Copy max_statement_time to current user, if stored in mysql.user - Added status variable max_statement_time_exceeded - Added KILL_TIMEOUT - Removed digest hash from performance schema tests as they change all the time. - Updated test results that changed because of the new user variables or new fields in mysql.user This functionallity is inspired by work done by Davi Arnaut at twitter. Test case is copied from Davi's work. Documentation can be found at https://kb.askmonty.org/en/how-to-limittimeout-queries/ mysql-test/r/mysqld--help.result: Updated for new help message mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/sys_vars/r/max_statement_time_basic.result: Added testing of max_statement_time mysql-test/suite/sys_vars/t/max_statement_time_basic.test: Added testing of max_statement_time mysql-test/t/max_statement_time.test: Added testing of max_statement_time mysys/CMakeLists.txt: Added thr_timer mysys/my_init.c: mysys/mysys_priv.h: Added new mutex and condition variables Added new mutex and condition variables mysys/thr_timer.c: Added timer functions based on pthread_cond_timedwait() This can be compiled with HAVE_TIMER_CREATE to benchmark agains timer_create()/timer_settime() sql/lex.h: Added MAX_STATEMENT_TIME sql/log_event.cc: Safety fix (timeout should be threated as an interrupted query) sql/mysqld.cc: Added support for timers Added status variable max_statement_time_exceeded sql/share/errmsg-utf8.txt: Added ER_QUERY_TIMEOUT sql/signal_handler.cc: Added support for KILL_TIMEOUT sql/sql_acl.cc: Added support for GRANT ... MAX_STATEMENT_TIME=# Copy max_statement_time to current user sql/sql_class.cc: Added timer functionality to THD. Added thd_kill_timeout() sql/sql_class.h: Added timer functionality to THD. Added KILL_TIMEOUT Added max_statement_time variable in similar manner as long_query_time was done. sql/sql_connect.cc: Added handling of max_statement_time_exceeded sql/sql_parse.cc: Added starting and stopping timers for queries. sql/sql_show.cc: Added max_statement_time_exceeded for user/connects status in MariaDB 10.0 sql/sql_yacc.yy: Added support for GRANT ... MAX_STATEMENT_TIME=# syntax, to be enabled in 10.0 sql/structs.h: Added max_statement_time user resource sql/sys_vars.cc: Added max_statement_time variables mysql-test/suite/roles/create_and_drop_role_invalid_user_table.test Removed test as we require all fields in mysql.user table. scripts/mysql_system_tables.sql scripts/mysql_system_tables_data.sql scripts/mysql_system_tables_fix.sql Updated mysql.user with new max_statement_time field
2014-10-07 10:37:36 +02:00
#
--source include/not_embedded.inc
--source include/have_innodb.inc
--source include/have_sequence.inc
--source include/not_valgrind.inc
MDEV 4427: query timeouts Added MAX_STATEMENT_TIME user variable to automaticly kill queries after a given time limit has expired. - Added timer functions based on pthread_cond_timedwait - Added kill_handlerton() to signal storage engines about kill/timeout - Added support for GRANT ... MAX_STATEMENT_TIME=# - Copy max_statement_time to current user, if stored in mysql.user - Added status variable max_statement_time_exceeded - Added KILL_TIMEOUT - Removed digest hash from performance schema tests as they change all the time. - Updated test results that changed because of the new user variables or new fields in mysql.user This functionallity is inspired by work done by Davi Arnaut at twitter. Test case is copied from Davi's work. Documentation can be found at https://kb.askmonty.org/en/how-to-limittimeout-queries/ mysql-test/r/mysqld--help.result: Updated for new help message mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/sys_vars/r/max_statement_time_basic.result: Added testing of max_statement_time mysql-test/suite/sys_vars/t/max_statement_time_basic.test: Added testing of max_statement_time mysql-test/t/max_statement_time.test: Added testing of max_statement_time mysys/CMakeLists.txt: Added thr_timer mysys/my_init.c: mysys/mysys_priv.h: Added new mutex and condition variables Added new mutex and condition variables mysys/thr_timer.c: Added timer functions based on pthread_cond_timedwait() This can be compiled with HAVE_TIMER_CREATE to benchmark agains timer_create()/timer_settime() sql/lex.h: Added MAX_STATEMENT_TIME sql/log_event.cc: Safety fix (timeout should be threated as an interrupted query) sql/mysqld.cc: Added support for timers Added status variable max_statement_time_exceeded sql/share/errmsg-utf8.txt: Added ER_QUERY_TIMEOUT sql/signal_handler.cc: Added support for KILL_TIMEOUT sql/sql_acl.cc: Added support for GRANT ... MAX_STATEMENT_TIME=# Copy max_statement_time to current user sql/sql_class.cc: Added timer functionality to THD. Added thd_kill_timeout() sql/sql_class.h: Added timer functionality to THD. Added KILL_TIMEOUT Added max_statement_time variable in similar manner as long_query_time was done. sql/sql_connect.cc: Added handling of max_statement_time_exceeded sql/sql_parse.cc: Added starting and stopping timers for queries. sql/sql_show.cc: Added max_statement_time_exceeded for user/connects status in MariaDB 10.0 sql/sql_yacc.yy: Added support for GRANT ... MAX_STATEMENT_TIME=# syntax, to be enabled in 10.0 sql/structs.h: Added max_statement_time user resource sql/sys_vars.cc: Added max_statement_time variables mysql-test/suite/roles/create_and_drop_role_invalid_user_table.test Removed test as we require all fields in mysql.user table. scripts/mysql_system_tables.sql scripts/mysql_system_tables_data.sql scripts/mysql_system_tables_fix.sql Updated mysql.user with new max_statement_time field
2014-10-07 10:37:36 +02:00
--echo
--echo # Test the MAX_STATEMENT_TIME option.
--echo
SET @@MAX_STATEMENT_TIME=2;
select @@max_statement_time;
SELECT SLEEP(1);
SELECT SLEEP(3);
SET @@MAX_STATEMENT_TIME=0;
SELECT SLEEP(1);
SHOW STATUS LIKE "max_statement_time_exceeded";
CREATE TABLE t1 (a INT, b VARCHAR(300)) engine=myisam;
INSERT INTO t1 VALUES (1, 'string');
--disable_result_log
--disable_query_log
SET @@MAX_STATEMENT_TIME=2;
SET @@MAX_STATEMENT_TIME=0.1;
WHILE (! $mysql_errno)
{
SET @@MAX_STATEMENT_TIME=0;
INSERT INTO t1 SELECT * FROM t1;
SET @@MAX_STATEMENT_TIME=0.1;
--error 0,ER_STATEMENT_TIMEOUT
SELECT COUNT(*) FROM t1 WHERE b LIKE '%z%';
}
SET @@MAX_STATEMENT_TIME=0;
--enable_query_log
--enable_result_log
eval SELECT $mysql_errno;
--echo
--echo # Test the MAX_STATEMENT_TIME option with SF (should have no effect).
--echo
DELIMITER |;
CREATE PROCEDURE p1()
BEGIN
declare tmp int;
SET @@MAX_STATEMENT_TIME=0.0001;
SELECT COUNT(*) INTO tmp FROM t1 WHERE b LIKE '%z%';
SET @@MAX_STATEMENT_TIME=0;
END|
CREATE PROCEDURE p2()
BEGIN
SET @@MAX_STATEMENT_TIME=5;
END|
DELIMITER ;|
SELECT @@MAX_STATEMENT_TIME;
CALL p1();
CALL p2();
SELECT @@MAX_STATEMENT_TIME;
SET @@MAX_STATEMENT_TIME=0;
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP TABLE t1;
--echo
--echo # MAX_STATEMENT_TIME account resource
--echo
set statement sql_mode="" for
MDEV 4427: query timeouts Added MAX_STATEMENT_TIME user variable to automaticly kill queries after a given time limit has expired. - Added timer functions based on pthread_cond_timedwait - Added kill_handlerton() to signal storage engines about kill/timeout - Added support for GRANT ... MAX_STATEMENT_TIME=# - Copy max_statement_time to current user, if stored in mysql.user - Added status variable max_statement_time_exceeded - Added KILL_TIMEOUT - Removed digest hash from performance schema tests as they change all the time. - Updated test results that changed because of the new user variables or new fields in mysql.user This functionallity is inspired by work done by Davi Arnaut at twitter. Test case is copied from Davi's work. Documentation can be found at https://kb.askmonty.org/en/how-to-limittimeout-queries/ mysql-test/r/mysqld--help.result: Updated for new help message mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/sys_vars/r/max_statement_time_basic.result: Added testing of max_statement_time mysql-test/suite/sys_vars/t/max_statement_time_basic.test: Added testing of max_statement_time mysql-test/t/max_statement_time.test: Added testing of max_statement_time mysys/CMakeLists.txt: Added thr_timer mysys/my_init.c: mysys/mysys_priv.h: Added new mutex and condition variables Added new mutex and condition variables mysys/thr_timer.c: Added timer functions based on pthread_cond_timedwait() This can be compiled with HAVE_TIMER_CREATE to benchmark agains timer_create()/timer_settime() sql/lex.h: Added MAX_STATEMENT_TIME sql/log_event.cc: Safety fix (timeout should be threated as an interrupted query) sql/mysqld.cc: Added support for timers Added status variable max_statement_time_exceeded sql/share/errmsg-utf8.txt: Added ER_QUERY_TIMEOUT sql/signal_handler.cc: Added support for KILL_TIMEOUT sql/sql_acl.cc: Added support for GRANT ... MAX_STATEMENT_TIME=# Copy max_statement_time to current user sql/sql_class.cc: Added timer functionality to THD. Added thd_kill_timeout() sql/sql_class.h: Added timer functionality to THD. Added KILL_TIMEOUT Added max_statement_time variable in similar manner as long_query_time was done. sql/sql_connect.cc: Added handling of max_statement_time_exceeded sql/sql_parse.cc: Added starting and stopping timers for queries. sql/sql_show.cc: Added max_statement_time_exceeded for user/connects status in MariaDB 10.0 sql/sql_yacc.yy: Added support for GRANT ... MAX_STATEMENT_TIME=# syntax, to be enabled in 10.0 sql/structs.h: Added max_statement_time user resource sql/sys_vars.cc: Added max_statement_time variables mysql-test/suite/roles/create_and_drop_role_invalid_user_table.test Removed test as we require all fields in mysql.user table. scripts/mysql_system_tables.sql scripts/mysql_system_tables_data.sql scripts/mysql_system_tables_fix.sql Updated mysql.user with new max_statement_time field
2014-10-07 10:37:36 +02:00
GRANT USAGE ON *.* TO user1@localhost WITH MAX_STATEMENT_TIME 1.005;
--echo # con1
connect(con1,localhost,user1,,test,,);
SELECT @@max_statement_time;
disconnect con1;
--echo # restart and reconnect
connection default;
source include/restart_mysqld.inc;
set @global.userstat=1;
connect(con1,localhost,user1,,test,,);
SELECT @@global.max_statement_time,@@session.max_statement_time;
select sleep(100);
SHOW STATUS LIKE "max_statement_time_exceeded";
disconnect con1;
connection default;
show grants for user1@localhost;
--disable_parsing
select max_user_timeouts from information_schema.user_statistics where user="user1";
--enable_parsing
set @global.userstat=0;
DROP USER user1@localhost;
--echo
--echo # MAX_STATEMENT_TIME status variables.
--echo
flush status;
SET @@max_statement_time=0;
SELECT CONVERT(VARIABLE_VALUE, UNSIGNED) INTO @time_exceeded
FROM INFORMATION_SCHEMA.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'max_statement_time_exceeded';
SET @@max_statement_time=0.5;
SELECT SLEEP(2);
SHOW STATUS LIKE '%timeout%';
SET @@max_statement_time=0;
--echo # Ensure that the counters for:
--echo # - statements that exceeded their maximum execution time
--echo # are incremented.
SELECT 1 AS STATUS FROM INFORMATION_SCHEMA.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'max_statement_time_exceeded'
AND CONVERT(VARIABLE_VALUE, UNSIGNED) > @time_exceeded;
--echo
--echo # Check that the appropriate error status is set.
--echo
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);
START TRANSACTION;
SELECT * FROM t1 FOR UPDATE;
connect (con1,localhost,root,,test,,);
SET @@SESSION.max_statement_time = 0.5;
--error ER_STATEMENT_TIMEOUT
UPDATE t1 SET a = 2;
SHOW WARNINGS;
disconnect con1;
connection default;
ROLLBACK;
DROP TABLE t1;
--echo
--echo # Test interaction with lock waits.
--echo
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);
connect (con1,localhost,root,,test,,);
SET @@SESSION.max_statement_time= 0.5;
connection default;
LOCK TABLES t1 WRITE;
connection con1;
SELECT @@SESSION.max_statement_time;
--error ER_STATEMENT_TIMEOUT
LOCK TABLES t1 READ;
connection default;
UNLOCK TABLES;
BEGIN;
SELECT * FROM t1;
connection con1;
--error ER_STATEMENT_TIMEOUT
ALTER TABLE t1 ADD COLUMN b INT;
connection default;
ROLLBACK;
SELECT GET_LOCK('lock', 1);
connection con1;
SELECT GET_LOCK('lock', 1);
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;
select sleep(2);
end |
delimiter ;|
set max_statement_time = 0.001;
--error ER_STATEMENT_TIMEOUT
call pr();
set max_statement_time = 0;
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;
select sleep(2);
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;
#
# MDEV-16615 ASAN SEGV in handler::print_error or server crash after error upon CREATE TABLE
#
SET max_statement_time= 1;
--error ER_STATEMENT_TIMEOUT
CREATE TABLE t ENGINE=InnoDB SELECT * FROM seq_1_to_50000;