Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit e945542

Browse files
committed
Add input variable validation to the diagnostics() routine
1 parent ce6df80 commit e945542

File tree

3 files changed

+57
-26
lines changed

3 files changed

+57
-26
lines changed

mysql-test/suite/sysschema/r/pr_diagnostics.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ SET GLOBAL show_compatibility_56 = @tmp_show_compatibility_56,
1111
SET @sys.debug = 'OFF',
1212
@sys.diagnostics.allow_i_s_tables = 'OFF',
1313
@sys.diagnostics.include_raw = 'OFF';
14+
CALL sys.diagnostics(0, 0, 'full');
15+
summary
16+
Disabled 1 thread
17+
ERROR 45000: in_max_runtime must be greater than 0
18+
CALL sys.diagnostics(2, 0, 'full');
19+
ERROR 45000: in_interval must be greater than 0
20+
CALL sys.diagnostics(1, 2, 'full');
21+
ERROR 45000: in_max_runtime must be greater than or equal to in_interval

mysql-test/suite/sysschema/t/pr_diagnostics.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ SET @sys.debug = 'OFF',
3535
@sys.diagnostics.allow_i_s_tables = 'OFF',
3636
@sys.diagnostics.include_raw = 'OFF';
3737
--enable_result_log
38+
39+
# Check input variable validation
40+
-- error S45000
41+
CALL sys.diagnostics(0, 0, 'full');
42+
-- error S45000
43+
CALL sys.diagnostics(2, 0, 'full');
44+
-- error S45000
45+
CALL sys.diagnostics(1, 2, 'full');

procedures/diagnostics.sql

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ CREATE DEFINER='root'@'localhost' PROCEDURE diagnostics (
5757
5858
in_max_runtime (INT UNSIGNED):
5959
The maximum time to keep collecting data.
60-
Use NULL to get the default which is 60 seconds.
60+
Use NULL to get the default which is 60 seconds, otherwise enter a value greater than 0.
6161
in_interval (INT UNSIGNED):
6262
How long to sleep between data collections.
63-
Use NULL to get the default which is 30 seconds.
63+
Use NULL to get the default which is 30 seconds, otherwise enter a value greater than 0.
6464
in_auto_config (ENUM(''current'', ''medium'', ''full''))
6565
Automatically enable Performance Schema instruments and consumers.
6666
NOTE: The more that are enabled, the more impact on the performance.
@@ -149,35 +149,26 @@ BEGIN
149149
ORDER BY table_name;
150150
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
151151

152-
-- Some metrics variables doesn't make sense in delta and rate calculations even if they are numeric
153-
-- as they really are more like settings or "current" status.
154-
SET v_no_delta_names = CONCAT('s%{COUNT}.Variable_name NOT IN (',
155-
'''innodb_buffer_pool_pages_total'', ',
156-
'''innodb_page_size'', ',
157-
'''last_query_cost'', ',
158-
'''last_query_partial_plans'', ',
159-
'''qcache_total_blocks'', ',
160-
'''slave_last_heartbeat'', ',
161-
'''ssl_ctx_verify_depth'', ',
162-
'''ssl_ctx_verify_mode'', ',
163-
'''ssl_session_cache_size'', ',
164-
'''ssl_verify_depth'', ',
165-
'''ssl_verify_mode'', ',
166-
'''ssl_version'', ',
167-
'''buffer_flush_lsn_avg_rate'', ',
168-
'''buffer_flush_pct_for_dirty'', ',
169-
'''buffer_flush_pct_for_lsn'', ',
170-
'''buffer_pool_pages_total'', ',
171-
'''lock_row_lock_time_avg'', ',
172-
'''lock_row_lock_time_max'', ',
173-
'''innodb_page_size''',
174-
')');
175-
176152
-- Do not track the current thread - no reason to clutter the output
177153
SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();
178154
IF (v_this_thread_enabled = 'YES') THEN
179155
CALL sys.ps_setup_disable_thread(CONNECTION_ID());
180156
END IF;
157+
158+
-- Check options are sane
159+
IF (in_max_runtime < in_interval) THEN
160+
SIGNAL SQLSTATE '45000'
161+
SET MESSAGE_TEXT = 'in_max_runtime must be greater than or equal to in_interval';
162+
END IF;
163+
IF (in_max_runtime = 0) THEN
164+
SIGNAL SQLSTATE '45000'
165+
SET MESSAGE_TEXT = 'in_max_runtime must be greater than 0';
166+
END IF;
167+
IF (in_interval = 0) THEN
168+
SIGNAL SQLSTATE '45000'
169+
SET MESSAGE_TEXT = 'in_interval must be greater than 0';
170+
END IF;
171+
181172
-- Set configuration options
182173
IF (@sys.diagnostics.allow_i_s_tables IS NULL) THEN
183174
SET @sys.diagnostics.allow_i_s_tables = sys.sys_get_config('diagnostics.allow_i_s_tables', 'OFF');
@@ -198,6 +189,30 @@ BEGIN
198189
SET sql_log_bin = 0;
199190
END IF;
200191

192+
-- Some metrics variables doesn't make sense in delta and rate calculations even if they are numeric
193+
-- as they really are more like settings or "current" status.
194+
SET v_no_delta_names = CONCAT('s%{COUNT}.Variable_name NOT IN (',
195+
'''innodb_buffer_pool_pages_total'', ',
196+
'''innodb_page_size'', ',
197+
'''last_query_cost'', ',
198+
'''last_query_partial_plans'', ',
199+
'''qcache_total_blocks'', ',
200+
'''slave_last_heartbeat'', ',
201+
'''ssl_ctx_verify_depth'', ',
202+
'''ssl_ctx_verify_mode'', ',
203+
'''ssl_session_cache_size'', ',
204+
'''ssl_verify_depth'', ',
205+
'''ssl_verify_mode'', ',
206+
'''ssl_version'', ',
207+
'''buffer_flush_lsn_avg_rate'', ',
208+
'''buffer_flush_pct_for_dirty'', ',
209+
'''buffer_flush_pct_for_lsn'', ',
210+
'''buffer_pool_pages_total'', ',
211+
'''lock_row_lock_time_avg'', ',
212+
'''lock_row_lock_time_max'', ',
213+
'''innodb_page_size''',
214+
')');
215+
201216
IF (in_auto_config <> 'current') THEN
202217
IF (@sys.debug = 'ON') THEN
203218
SELECT CONCAT('Updating Performance Schema configuration to ', in_auto_config) AS 'Debug';

0 commit comments

Comments
 (0)