forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support showing query digest in SHOW PROCESS LIST
Summary: Add a new show_query_digest session var so that SHOW PROCESSLIST and I_S.PROCESSLIST shows query digest instead of original query. This is needed to ensure privacy / leaking PII when our tooling dumps out the queries. Note this feature requires sql_stats_control to be on so that parser will generate digest tokens as part of tokenization. Without sql_stats_control, it'll just show `<digest_missing: sql_stats_control required>`, instead of original query string, for obvious privacy reasons. We have it in our production (at least in places where it matters) so this should be a fine requirement. The implementation took a bit longer than expected mostly because CSET_STRING / LEX_STRING / String types in MySQL are rather difficult to work with, especially if you want to avoid unnecessary allocation and have correct const-ness when converting between them, so I changed CSET_STRING in thd_info to be just regular `char *` which are much easier. Reference Patch: facebook@898d2fd Porting Notes: sql_stats_control are no longer required in 8.0. Reviewed By: luqun Differential Revision: D26264225
- Loading branch information
Showing
9 changed files
with
331 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
SET @show_query_digest_save = @@show_query_digest; | ||
SET show_query_digest=1; | ||
SELECT GET_LOCK('t', 1000); | ||
GET_LOCK('t', 1000) | ||
1 | ||
SET NAMES latin1; | ||
SELECT 1+2, "abc", GET_LOCK('t',1000) AS 'abc';; | ||
SHOW PROCESSLIST; | ||
Id User Host db Command Time State Info Tid | ||
### event_scheduler ### NULL Daemon ### ### NULL ### | ||
### root ### test Query ### ### SELECT ? + ?, ... , `GET_LOCK` (...) AS ? ### | ||
### root ### test Query ### ### SHOW PROCESSLIST ### | ||
SELECT INFO FROM INFORMATION_SCHEMA.PROCESSLIST WHERE ID != CONNECTION_ID(); | ||
INFO | ||
NULL | ||
SELECT 1+2, "abc", GET_LOCK('t',1000) AS 'abc' | ||
SELECT RELEASE_LOCK('t'); | ||
RELEASE_LOCK('t') | ||
1 | ||
1+2 abc abc | ||
3 abc 1 | ||
SET show_query_digest=@show_query_digest_save; |
83 changes: 83 additions & 0 deletions
83
mysql-test/suite/sys_vars/r/show_query_digest_basic.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
SET @session_start_value = @@session.show_query_digest; | ||
SELECT @session_start_value; | ||
@session_start_value | ||
0 | ||
SET @@session.show_query_digest = 0; | ||
SET @@session.show_query_digest = DEFAULT; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 | ||
SET @@session.show_query_digest = 1; | ||
SET @@session.show_query_digest = DEFAULT; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 | ||
SET show_query_digest = 1; | ||
SELECT @@show_query_digest; | ||
@@show_query_digest | ||
1 | ||
SELECT session.show_query_digest; | ||
ERROR 42S02: Unknown table 'session' in field list | ||
SELECT local.show_query_digest; | ||
ERROR 42S02: Unknown table 'local' in field list | ||
SET session show_query_digest = 0; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 | ||
SET @@session.show_query_digest = 0; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 | ||
SET @@session.show_query_digest = 1; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
1 | ||
SET @@session.show_query_digest = -1; | ||
ERROR 42000: Variable 'show_query_digest' can't be set to the value of '-1' | ||
SET @@session.show_query_digest = 2; | ||
ERROR 42000: Variable 'show_query_digest' can't be set to the value of '2' | ||
SET @@session.show_query_digest = "T"; | ||
ERROR 42000: Variable 'show_query_digest' can't be set to the value of 'T' | ||
SET @@session.show_query_digest = "Y"; | ||
ERROR 42000: Variable 'show_query_digest' can't be set to the value of 'Y' | ||
SET @@global.show_query_digest = 1; | ||
SELECT @@global.show_query_digest; | ||
@@global.show_query_digest | ||
1 | ||
SET @@global.show_query_digest = 0; | ||
SELECT count(VARIABLE_VALUE) FROM performance_schema.global_variables WHERE VARIABLE_NAME='show_query_digest'; | ||
count(VARIABLE_VALUE) | ||
1 | ||
SELECT IF(@@session.show_query_digest, "ON", "OFF") = VARIABLE_VALUE | ||
FROM performance_schema.session_variables | ||
WHERE VARIABLE_NAME='show_query_digest'; | ||
IF(@@session.show_query_digest, "ON", "OFF") = VARIABLE_VALUE | ||
1 | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
1 | ||
SELECT VARIABLE_VALUE | ||
FROM performance_schema.session_variables | ||
WHERE VARIABLE_NAME='show_query_digest'; | ||
VARIABLE_VALUE | ||
ON | ||
SET @@session.show_query_digest = OFF; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 | ||
SET @@session.show_query_digest = ON; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
1 | ||
SET @@session.show_query_digest = TRUE; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
1 | ||
SET @@session.show_query_digest = FALSE; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 | ||
SET @@session.show_query_digest = @session_start_value; | ||
SELECT @@session.show_query_digest; | ||
@@session.show_query_digest | ||
0 |
135 changes: 135 additions & 0 deletions
135
mysql-test/suite/sys_vars/t/show_query_digest_basic.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
####################### mysql-test\t\show_query_digest_basic.test ############### | ||
# # | ||
# Variable Name: show_query_digest # | ||
# Scope: SESSION # | ||
# Access Type: Dynamic # | ||
# Data Type: boolean # | ||
# Default Value: # | ||
# Valid Values: 0,1 # | ||
# # | ||
# Description: Test Cases of Dynamic System Variable show_query_digest # | ||
# that checks the behavior of this variable in the following ways# | ||
# * Default Value # | ||
# * Valid & Invalid values # | ||
# * Scope & Access method # | ||
# * Data Integrity # | ||
# # | ||
############################################################################### | ||
|
||
--source include/load_sysvars.inc | ||
|
||
|
||
############################################################################## | ||
# Saving initial value of show_query_digest in a temporary variable # | ||
############################################################################## | ||
|
||
SET @session_start_value = @@session.show_query_digest; | ||
SELECT @session_start_value; | ||
|
||
######################################################################## | ||
# Display the DEFAULT value of show_query_digest # | ||
######################################################################## | ||
|
||
SET @@session.show_query_digest = 0; | ||
SET @@session.show_query_digest = DEFAULT; | ||
SELECT @@session.show_query_digest; | ||
|
||
SET @@session.show_query_digest = 1; | ||
SET @@session.show_query_digest = DEFAULT; | ||
SELECT @@session.show_query_digest; | ||
|
||
|
||
############################################################################# | ||
# Check if show_query_digest can be accessed with and without @@ sign # | ||
############################################################################# | ||
|
||
SET show_query_digest = 1; | ||
SELECT @@show_query_digest; | ||
|
||
--Error ER_UNKNOWN_TABLE | ||
SELECT session.show_query_digest; | ||
|
||
--Error ER_UNKNOWN_TABLE | ||
SELECT local.show_query_digest; | ||
|
||
SET session show_query_digest = 0; | ||
SELECT @@session.show_query_digest; | ||
|
||
|
||
######################################################################## | ||
# change the value of show_query_digest to a valid value # | ||
######################################################################## | ||
|
||
SET @@session.show_query_digest = 0; | ||
SELECT @@session.show_query_digest; | ||
SET @@session.show_query_digest = 1; | ||
SELECT @@session.show_query_digest; | ||
|
||
|
||
########################################################################### | ||
# Change the value of show_query_digest to invalid value # | ||
########################################################################### | ||
|
||
--Error ER_WRONG_VALUE_FOR_VAR | ||
SET @@session.show_query_digest = -1; | ||
--Error ER_WRONG_VALUE_FOR_VAR | ||
SET @@session.show_query_digest = 2; | ||
--Error ER_WRONG_VALUE_FOR_VAR | ||
SET @@session.show_query_digest = "T"; | ||
--Error ER_WRONG_VALUE_FOR_VAR | ||
SET @@session.show_query_digest = "Y"; | ||
|
||
########################################################################### | ||
# Test if accessing global show_query_digest gives error # | ||
########################################################################### | ||
|
||
SET @@global.show_query_digest = 1; | ||
SELECT @@global.show_query_digest; | ||
SET @@global.show_query_digest = 0; | ||
|
||
######################################################################### | ||
# Check if the value in GLOBAL Table contains variable value # | ||
######################################################################### | ||
|
||
SELECT count(VARIABLE_VALUE) FROM performance_schema.global_variables WHERE VARIABLE_NAME='show_query_digest'; | ||
|
||
######################################################################### | ||
# Check if the value in GLOBAL Table matches value in variable # | ||
######################################################################### | ||
|
||
SELECT IF(@@session.show_query_digest, "ON", "OFF") = VARIABLE_VALUE | ||
FROM performance_schema.session_variables | ||
WHERE VARIABLE_NAME='show_query_digest'; | ||
SELECT @@session.show_query_digest; | ||
SELECT VARIABLE_VALUE | ||
FROM performance_schema.session_variables | ||
WHERE VARIABLE_NAME='show_query_digest'; | ||
|
||
################################################################### | ||
# Check if ON and OFF values can be used on variable # | ||
################################################################### | ||
|
||
SET @@session.show_query_digest = OFF; | ||
SELECT @@session.show_query_digest; | ||
SET @@session.show_query_digest = ON; | ||
SELECT @@session.show_query_digest; | ||
|
||
################################################################### | ||
# Check if TRUE and FALSE values can be used on variable # | ||
################################################################### | ||
|
||
SET @@session.show_query_digest = TRUE; | ||
SELECT @@session.show_query_digest; | ||
SET @@session.show_query_digest = FALSE; | ||
SELECT @@session.show_query_digest; | ||
|
||
############################## | ||
# Restore initial value # | ||
############################## | ||
|
||
SET @@session.show_query_digest = @session_start_value; | ||
SELECT @@session.show_query_digest; | ||
|
||
############################################################### | ||
# END OF show_query_digest TESTS # | ||
############################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# SHOW PROCESSLIST with show_query_digest=1 | ||
# | ||
SET @show_query_digest_save = @@show_query_digest; | ||
SET show_query_digest=1; | ||
|
||
SELECT GET_LOCK('t', 1000); | ||
--connect (con1,localhost,root,,) | ||
--connection con1 | ||
SET NAMES latin1; | ||
--send SELECT 1+2, "abc", GET_LOCK('t',1000) AS 'abc'; | ||
--connection default | ||
# Make sure con1 has switched from "SET NAMES" to "SELECT GET_LOCK" | ||
let $wait_timeout= 10; | ||
let $wait_condition= SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%GET_LOCK%' AND ID != CONNECTION_ID(); | ||
--source include/wait_condition.inc | ||
--replace_column 1 ### 3 ### 6 ### 7 ### 9 ### 10 ### 11 ### 12 ### | ||
--replace_result 'Query attributes' 'Query' | ||
--sorted_result | ||
SHOW PROCESSLIST; | ||
--sorted_result | ||
SELECT INFO FROM INFORMATION_SCHEMA.PROCESSLIST WHERE ID != CONNECTION_ID(); | ||
SELECT RELEASE_LOCK('t'); | ||
--connection con1 | ||
--reap | ||
--disconnect con1 | ||
--source include/wait_until_disconnected.inc | ||
--connection default | ||
|
||
SET show_query_digest=@show_query_digest_save; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.