Commit f3a56a17 authored by unknown's avatar unknown
Browse files

SHOW STATUS does not anymore change local status variables (except...

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
parent cd3fa2ee
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ Variable_name Value
Qcache_hits	0
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	5
Qcache_not_cached	0
select "user1";
user1
user1
@@ -72,7 +72,7 @@ Variable_name Value
Qcache_hits	0
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	9
Qcache_not_cached	1
select * from t1;
a	b	c
1	1	1
@@ -85,7 +85,7 @@ Variable_name Value
Qcache_hits	1
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	12
Qcache_not_cached	1
select a from t1 ;
a
1
@@ -98,7 +98,7 @@ Variable_name Value
Qcache_hits	2
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	15
Qcache_not_cached	1
select c from t1;
c
1
@@ -111,7 +111,7 @@ Variable_name Value
Qcache_hits	3
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	18
Qcache_not_cached	1
show grants for current_user();
Grants for @localhost
GRANT USAGE ON *.* TO ''@'localhost'
@@ -144,7 +144,7 @@ Variable_name Value
Qcache_hits	7
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	22
Qcache_not_cached	2
select "user3";
user3
user3
@@ -168,7 +168,7 @@ Variable_name Value
Qcache_hits	7
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	30
Qcache_not_cached	7
select "user4";
user4
user4
@@ -198,7 +198,7 @@ Variable_name Value
Qcache_hits	8
show status like "Qcache_not_cached";
Variable_name	Value
Qcache_not_cached	34
Qcache_not_cached	8
set names binary;
delete from mysql.user where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
delete from mysql.db where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
+2 −0
Original line number Diff line number Diff line
@@ -199,6 +199,8 @@ select table_name, column_name, privileges from information_schema.columns
where table_schema = 'mysqltest' and table_name = 'v1';
table_name	column_name	privileges
v1	c	select
explain select * from v1;
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
drop view v1, mysqltest.v1;
drop tables mysqltest.t4, mysqltest.t1, t2, t3, t5;
drop database mysqltest;
+1 −0
Original line number Diff line number Diff line
@@ -1050,6 +1050,7 @@ Qcache_hits 1
drop table t1;
create table t1 (a int);
insert into t1 values (1),(2);
drop procedure if exists p1;
CREATE PROCEDURE `p1`()
begin
Declare c1 cursor for select a from t1;
+50 −0
Original line number Diff line number Diff line
@@ -23,6 +23,32 @@ select 1;
show status like 'last_query_cost';
Variable_name	Value
Last_query_cost	0.000000
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;
a
6
6
6
6
6
show status like 'last_query_cost';
Variable_name	Value
Last_query_cost	12.084449
show status like 'last_query_cost';
Variable_name	Value
Last_query_cost	12.084449
select 1;
1
1
show status like 'last_query_cost';
Variable_name	Value
Last_query_cost	0.000000
drop table t1;
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name	Value
@@ -43,3 +69,27 @@ SHOW STATUS LIKE 'max_used_connections';
Variable_name	Value
Max_used_connections	5
SET GLOBAL thread_cache_size=@save_thread_cache_size;
show status like 'com_show_status';
Variable_name	Value
Com_show_status	3
show status like 'hand%write%';
Variable_name	Value
Handler_write	0
show status like '%tmp%';
Variable_name	Value
Created_tmp_disk_tables	0
Created_tmp_files	0
Created_tmp_tables	0
show status like 'hand%write%';
Variable_name	Value
Handler_write	0
show status like '%tmp%';
Variable_name	Value
Created_tmp_disk_tables	0
Created_tmp_files	0
Created_tmp_tables	0
show status like 'com_show_status';
Variable_name	Value
Com_show_status	8
rnd_diff	tmp_table_diff
20	8
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ d
show status like "created_tmp%tables";
Variable_name	Value
Created_tmp_disk_tables	0
Created_tmp_tables	2
Created_tmp_tables	1
drop table t1;
create temporary table v1 as select 'This is temp. table' A;
create view v1 as select 'This is view' A;
Loading