mariadb/mysql-test/t/status.test
unknown f3a56a17da SHOW STATUS does not anymore change local status variables (except com_show_status). Global status variables are still updated.
SHOW STATUS are not anymore put in slow query log because of no index usage.

Implemntation done by removing orig_sql_command and moving logic of SHOW STATUS to mysql_excute_command()
This simplifies code and allows us to remove some if statements all over the code.

Upgraded uc_update_queries[] to sql_command_flags and added more bitmaps to better categorize commands.
This allowed some overall simplifaction when testing sql_command.

Fixes bugs:
Bug#10210: running SHOW STATUS increments counters it shouldn't
Bug#19764: SHOW commands end up in the slow log as table scans


mysql-test/r/grant_cache.result:
  Fixed results after SHOW STATUS doesn't anymore affect status variables
mysql-test/r/information_schema.result:
  Added extra test to cover more code
mysql-test/r/query_cache.result:
  Remove resuts from previous tests
mysql-test/r/status.result:
  Added more tests for testing of last_query_cost and how SHOW STATUS affects status variables.
  (Bug#10210)
mysql-test/r/temp_table.result:
  Fixed results after SHOW STATUS doesn't anymore affect status variables
mysql-test/r/union.result:
  Fixed results after SHOW STATUS is not logged to slow query log
  (Bug#19764)
mysql-test/t/events_microsec.test:
  Disable warnings at init
mysql-test/t/information_schema.test:
  Added extra test to cover more code
mysql-test/t/query_cache.test:
  Remove resuts from previous tests
mysql-test/t/status.test:
  Added more tests for testing of last_query_cost and how SHOW STATUS affects status variables.
  (Bug #10210)
sql/mysql_priv.h:
  Added 'sql_command_flags'
sql/sql_class.cc:
  New function add_diff_to_status(), used to update global status variables when using SHOW STATUS
sql/sql_class.h:
  New function 'fill_information_schema_tables()'
  (One could not anymore use fill_derived_tables() for this as only_view_structures() is not relevant for information schema tables)
  Added defines for bit flags in sql_command_flags[]
sql/sql_lex.cc:
  Remove orig_sql_command
sql/sql_lex.h:
  Remove orig_sql_command
sql/sql_parse.cc:
  Rename uc_update_queries -> sql_command_flags.
  Enhanced 'sql_command_flags' to better classify SQL commands
  uc_update_queries[] != 0 is changed to (sql_command_flags[] & CF_CHANGES_DATA)
  lex->orig_sql_command == SQLCOM_END is changed to (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0)
  
  Simplify incrementing of thd->status_var.com_stat[] as we don't have to do special handling for SHOW commands.
  
  Split SQLCOM_SELECT handling in mysql_execute_command() to a separate function.
  Added special handling of SHOW STATUS commands in mysql_execute_command() and call common SQLCOM_SELECT handling.
  These changes allows us to easily fix that we save and restore status variables during execution of a SHOW STATUS command.
  Don't log SHOW STATUS commands to slow query log.
  
  This fixes Bug#10210 and Bug#19764 without adding additional 'if' code.
  (The new code is faster than the original as we now have fewer if's than before)
sql/sql_prepare.cc:
  Clean up prepare-check handling of SQLCOM commands by using sql_command_flags[]
  This simplifes code and ensures that code works even if someone forgets to put a new status commands into the switch statement.
sql/sql_select.cc:
  Remove special handling of SHOW STATUS.
  (This is now done in SQLCOM_SHOW_STATUS part in mysql_execute_command())
sql/sql_show.cc:
  Remove orig_sql_command
  Only change sql_command during 'open_normal_and_derived_tables()' (for views) and not for the full duration of generating data.
  Changed 'show status' to use thd->initial_status_var to ensure that the current statement is not affecting the to-be-used values.
  Use thd->fill_information_schema_tables() instead of 'thd->fill_derived_tables()' as the later wrongly checks the value of sql_command.
sql/sql_yacc.yy:
  Remove usage of orig_sql_command.
  One side effect of this is that we need to test for cursors if the current command is a SELECT or a SHOW command.
sql/structs.h:
  Updated comment
2006-06-20 13:20:32 +03:00

180 lines
5.2 KiB
Text

# This test doesn't work with the embedded version as this code
# assumes that one query is running while we are doing queries on
# a second connection.
# This would work if mysqltest run would be threaded and handle each
# connection in a separate thread.
#
--source include/not_embedded.inc
# PS causes different statistics
--disable_ps_protocol
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
flush status;
show status like 'Table_lock%';
connection con1;
SET SQL_LOG_BIN=0;
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1(n int) engine=myisam;
insert into t1 values(1);
connection con2;
lock tables t1 read;
unlock tables;
lock tables t1 read;
connection con1;
--send
update t1 set n = 3;
connection con2;
sleep 0.5;
unlock tables;
connection con1;
reap;
show status like 'Table_lock%';
drop table t1;
disconnect con2;
disconnect con1;
connection default;
# End of 4.1 tests
#
# last_query_cost
#
select 1;
show status like 'last_query_cost';
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
select * from t1 where a=6;
show status like 'last_query_cost';
# Ensure value dosn't change by second status call
show status like 'last_query_cost';
select 1;
show status like 'last_query_cost';
drop table t1;
#
# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS
# if connections are cached
#
#
# The first suggested fix from the bug report was chosen
# (see http://bugs.mysql.com/bug.php?id=15933):
#
# a) On flushing the status, set max_used_connections to
# threads_connected, not to 0.
#
# b) Check if it is necessary to increment max_used_connections when
# taking a thread from the cache as well as when creating new threads
#
# Wait for at most $disconnect_timeout seconds for disconnects to finish.
let $disconnect_timeout = 10;
# Wait for any previous disconnects to finish.
FLUSH STATUS;
--disable_query_log
--disable_result_log
eval SET @wait_left = $disconnect_timeout;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`;
while ($wait_more)
{
sleep 1;
FLUSH STATUS;
SET @wait_left = @wait_left - 1;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`;
}
--enable_query_log
--enable_result_log
# Prerequisite.
SHOW STATUS LIKE 'max_used_connections';
# Save original setting.
SET @save_thread_cache_size=@@thread_cache_size;
SET GLOBAL thread_cache_size=3;
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
disconnect con2;
# Check that max_used_connections still reflects maximum value.
SHOW STATUS LIKE 'max_used_connections';
# Check that after flush max_used_connections equals to current number
# of connections. First wait for previous disconnect to finish.
FLUSH STATUS;
--disable_query_log
--disable_result_log
eval SET @wait_left = $disconnect_timeout;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`;
while ($wait_more)
{
sleep 1;
FLUSH STATUS;
SET @wait_left = @wait_left - 1;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`;
}
--enable_query_log
--enable_result_log
# Check that we don't count disconnected thread any longer.
SHOW STATUS LIKE 'max_used_connections';
# Check that max_used_connections is updated when cached thread is
# reused...
connect (con2,localhost,root,,);
SHOW STATUS LIKE 'max_used_connections';
# ...and when new thread is created.
connect (con3,localhost,root,,);
SHOW STATUS LIKE 'max_used_connections';
# Restore original setting.
connection default;
SET GLOBAL thread_cache_size=@save_thread_cache_size;
disconnect con3;
disconnect con2;
disconnect con1;
# End of 5.0 tests
#
# Ensure that SHOW STATUS only changes global status variables
#
connect (con1,localhost,root,,);
let $rnd_next = `show global status like 'handler_read_rnd_next'`;
let $tmp_table = `show global status like 'Created_tmp_tables'`;
show status like 'com_show_status';
show status like 'hand%write%';
show status like '%tmp%';
show status like 'hand%write%';
show status like '%tmp%';
show status like 'com_show_status';
let $rnd_next2 = `show global status like 'handler_read_rnd_next'`;
let $tmp_table2 = `show global status like 'Created_tmp_tables'`;
--disable_query_log
eval select substring_index('$rnd_next2',0x9,-1)-substring_index('$rnd_next',0x9,-1) as rnd_diff, substring_index('$tmp_table2',0x9,-1)-substring_index('$tmp_table',0x9,-1) as tmp_table_diff;
--enable_query_log
# End of 5.1 tests