1
0
mirror of https://github.com/MariaDB/server.git synced 2025-05-05 16:59:35 +03:00
mariadb/mysql-test/suite/sys_vars/t/max_statement_time_basic.test
Monty cc8aed3eb7 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 11:37:36 +03:00

218 lines
9.0 KiB
Plaintext

####################### mysql-test\t\max_statement_time_basic.test ###############
# #
# Variable Name: max_statement_time #
# Scope: GLOBAL | SESSION #
# Access Type: Dynamic #
# Data Type: numeric #
# Default Value:10 #
# Min Value: 1 #
# #
# #
# Creation Date: 2012-12-30 #
# Author: Monty #
# #
# Description: Test Cases of Dynamic System Variable max_statement_time #
# that checks the behavior of this variable in the following ways#
# * Default Value #
# * Valid & Invalid values #
# * Scope & Access method #
# * Data Integrity #
# #
# Reference: https://kb.askmonty.org/en/how-to-limittimeout-queries/ #
# server-system-variables.html #
# #
###############################################################################
--source include/load_sysvars.inc
############################################################
# START OF max_statement_time TESTS #
############################################################
#############################################################
# Save initial value #
#############################################################
SET @start_global_value = @@global.max_statement_time;
SELECT @start_global_value;
SET @start_session_value = @@session.max_statement_time;
SELECT @start_session_value;
--echo '#--------------------FN_DYNVARS_068_01-------------------------#'
###############################################################
# Display the DEFAULT value of max_statement_time #
###############################################################
SET @@global.max_statement_time = 100;
SET @@global.max_statement_time = DEFAULT;
SELECT @@global.max_statement_time;
SET @@session.max_statement_time = 200;
SET @@session.max_statement_time = DEFAULT;
SELECT @@session.max_statement_time;
--echo '#--------------------FN_DYNVARS_068_02-------------------------#'
###############################################################
# Check the DEFAULT value of max_statement_time #
###############################################################
SET @@global.max_statement_time = DEFAULT;
SELECT @@global.max_statement_time = 0;
SET @@session.max_statement_time = DEFAULT;
SELECT @@session.max_statement_time = 0;
--echo '#--------------------FN_DYNVARS_068_03-------------------------#'
#########################################################################
# Change the value of max_statement_time to a valid value for GLOBAL Scope #
#########################################################################
SET @@global.max_statement_time = 0;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = 0.123456;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = 60020;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = 31536000;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = 65536;
SELECT @@global.max_statement_time;
--echo '#--------------------FN_DYNVARS_068_04-------------------------#'
##########################################################################
# Change the value of max_statement_time to a valid value for SESSION Scope #
##########################################################################
SET @@session.max_statement_time = 0;
SELECT @@session.max_statement_time;
SET @@session.max_statement_time = 1;
SELECT @@session.max_statement_time;
SET @@session.max_statement_time = 50050;
SELECT @@session.max_statement_time;
SET @@session.max_statement_time = 31536000;
SELECT @@session.max_statement_time;
SET @@session.max_statement_time = 65550;
SELECT @@session.max_statement_time;
--echo '#------------------FN_DYNVARS_068_05-----------------------#'
########################################################
# Change the value of max_statement_time to an invalid value #
########################################################
SET @@global.max_statement_time = 100000000000;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = -1;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = 65530.34;
SELECT @@global.max_statement_time;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.max_statement_time = test;
SELECT @@global.max_statement_time;
SET @@session.max_statement_time = 100000000000;
SELECT @@session.max_statement_time;
SET @@session.max_statement_time = -2;
SELECT @@session.max_statement_time;
SET @@session.max_statement_time = 65530.34;
SELECT @@session.max_statement_time;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.max_statement_time = test;
SELECT @@session.max_statement_time;
--echo '#------------------FN_DYNVARS_068_06-----------------------#'
####################################################################
# Check if the value in GLOBAL Table matches value in variable #
####################################################################
SELECT @@global.max_statement_time = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='max_statement_time';
--echo '#------------------FN_DYNVARS_068_07-----------------------#'
####################################################################
# Check if the value in SESSION Table matches value in variable #
####################################################################
SELECT @@session.max_statement_time = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='max_statement_time';
--echo '#------------------FN_DYNVARS_068_08-----------------------#'
####################################################################
# Check if TRUE and FALSE values can be used on variable #
####################################################################
SET @@global.max_statement_time = TRUE;
SELECT @@global.max_statement_time;
SET @@global.max_statement_time = FALSE;
SELECT @@global.max_statement_time;
--echo '#---------------------FN_DYNVARS_001_09----------------------#'
#################################################################################
# Check if accessing variable with and without GLOBAL point to same variable #
#################################################################################
SET @@global.max_statement_time = 10;
SELECT @@max_statement_time = @@global.max_statement_time;
--echo '#---------------------FN_DYNVARS_001_10----------------------#'
########################################################################################################
# Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable #
########################################################################################################
SET @@max_statement_time = 100;
SELECT @@max_statement_time = @@local.max_statement_time;
SELECT @@local.max_statement_time = @@session.max_statement_time;
--echo '#---------------------FN_DYNVARS_001_11----------------------#'
##########################################################################
# Check if max_statement_time can be accessed with and without @@ sign #
##########################################################################
SET max_statement_time = 1;
SELECT @@max_statement_time;
--Error ER_UNKNOWN_TABLE
SELECT local.max_statement_time;
--Error ER_UNKNOWN_TABLE
SELECT session.max_statement_time;
--Error ER_BAD_FIELD_ERROR
SELECT max_statement_time = @@session.max_statement_time;
--echo #
--echo # Check that one can use max_statement_time as a field
--echo #
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1 (a int, max_statement_time int);
drop table t1;
####################################
# Restore initial value #
####################################
SET @@global.max_statement_time = @start_global_value;
SELECT @@global.max_statement_time;
SET @@session.max_statement_time = @start_session_value;
SELECT @@session.max_statement_time;
####################################################
# END OF max_statement_time TESTS #
####################################################