1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
--echo #
--echo # Bug#34134794: SQL_MODE with ANSI_QUOTES affects events created
--echo # without ANSI_QUOTES
--echo #
--echo
# This test is an example for wrapping LogErr() in a DBUG_EXECUTE_IF()
# to conditionally log debug information to performance_schema.error_log
# (using the error-symbol ER_CONDITIONAL_DEBUG and SYSTEM_LEVEL priority).
#
# This can come in handy in situations like this where we're interested
# in internals that we can't query using SQL, and/or where we want info
# not from the current session, but from a different thread, like an EVENT.
#
# Keep in mind that the error log is just that -- an error log, not a
# debug log, so this method should be used sparingly, and logging of
# debug info should always be disabled by default.
# Needs "debug" -- our logging is wrapped in a DBUG_EXECUTE_IF().
--source include/have_debug.inc
# Let's have performance_schema.error_log to ourselves.
--source include/not_parallel.inc
# Make session and performance_schema.error_log use the same time-zone.
SET @@session.time_zone=@@global.log_timestamps;
# Find error-number for the error symbol ER_CONDITIONAL_DEBUG we'll be using
# (and normalize to symbol in .result file).
--let $err_code= convert_error(ER_CONDITIONAL_DEBUG)
--replace_regex /=.*/=ER_CONDITIONAL_DEBUG/
--eval SET @err_code=CONCAT("MY-",LPAD($err_code,6,"0"));
# Get the timestamp of the latest entry in performance_schema.error_log.
# This will exclude log entries from earlier tests / --repeat=...
#
# (We could also do something like
#
# SELECT logged INTO @latest_timestamp
# FROM performance_schema.error_log
# ORDER BY logged DESC
# LIMIT 1;
#
# but the status variable "Error_log_latest_write" tracks the exact info
# we want, so the below is the canonical form.)
#
# By way of explanation, the variable provides an integer count of
# microseconds (for lack of a suitable time/data type in SHOW),
# while the column `logged` in performance_schema.error_log uses
# a TIMESTAMP (which is the reason we made sure above that timezones
# will agree). Thus, we divide the microsecond count by 1000000 to
# get a float-value of seconds.
SELECT FROM_UNIXTIME(VARIABLE_VALUE/1000000)
INTO @pfs_errlog_latest
FROM performance_schema.global_status
WHERE VARIABLE_NAME LIKE "Error_log_latest_write";
# Set some variables.
# NOTE: As in this .test the interesting things happen in a separate
# event-thread, we need to set the global variables where normally
# we would choose the session ones.
# Enable logging of quoted queries on EVENT execution
# (to confirm the type of quoting compliant with the SQL-mode active at
# the event's creation is used).
SET @@global.debug="+d,log_event_query_string";
# The following statements are specific to this test-case.
# If you use this file as a guide to develop your own
# debug-logging-to-error-log test case, your SQL code
# goes below.
#
# You'll probably wish to take a look further below however
# where we read what we logged from the performance_schema
# table, error_log.
# Set SQL-mode.
SET @@SESSION.sql_mode = '';
SET @@GLOBAL.sql_mode = '';
# Create a table that our EVENT can log its sql_mode to.
CREATE SCHEMA s;
CREATE TABLE s.modes (time TIMESTAMP, sess VARCHAR(256), glob VARCHAR (256));
--echo # Create event.
CREATE EVENT s.ev
ON SCHEDULE EVERY 1 SECOND
ON COMPLETION PRESERVE
ENABLE
DO
INSERT INTO s.modes VALUES (now(), @@SESSION.sql_mode, @@GLOBAL.sql_mode);
# Wait for event to fire.
let $wait_condition=
SELECT COUNT(*)>0 FROM s.modes;
--source include/wait_condition.inc
# Show rows in error log that are of ER_CONDITIONAL_DEBUG type
# (and were logged after this .test started).
--echo
--echo # Show debug entry for execution while global ANSI_QUOTES was disabled.
SELECT data
FROM performance_schema.error_log
WHERE error_code=@err_code
AND logged>@pfs_errlog_latest
ORDER BY logged ASC LIMIT 1;
--echo
--echo # Show any errors that were thrown. We expect none.
SELECT prio,error_code,data
FROM performance_schema.error_log
WHERE data LIKE "Event Scheduler: %"
AND logged>@pfs_errlog_latest
LIMIT 3;
# Save timestamp.
# Below, we'll only want to see errors thrown after we enabled ANSI_QUOTES.
SELECT FROM_UNIXTIME(VARIABLE_VALUE/1000000)
INTO @pfs_errlog_latest
FROM performance_schema.global_status
WHERE VARIABLE_NAME LIKE "Error_log_latest_write";
--echo # Change SQL-mode.
SET @@GLOBAL.sql_mode = 'ANSI_QUOTES';
# Empty the table the event logs to.
TRUNCATE s.modes;
# Wait for event to run after sql_mode changed.
let $wait_condition=
SELECT COUNT(*)>0 FROM s.modes;
--source include/wait_condition.inc
--echo
--echo # Show debug entry for execution while global ANSI_QUOTES was enabled.
--echo # Without patch for Bug#34134794, we shown sql_mode should be global
--echo # (i.e., it should contain ANSI_QUOTES). With the patch, the sql_mode
--echo # at create-time (without ANSI_QUOTES) should be shown.
SELECT data
FROM performance_schema.error_log
WHERE error_code=@err_code
AND logged>@pfs_errlog_latest
ORDER BY logged ASC LIMIT 1;
--echo
--echo # Show any errors that were thrown after ANSI_QUOTES was enabled.
--echo #
--echo # Without patch for Bug#34134794, we expect some or all of:
--echo # ER_EVENT_ERROR_DURING_COMPILATION
--echo # ER_EVENT_MESSAGE_STACK
--echo # ER_EVENT_EXECUTION_FAILED
--echo #
--echo # With patch, we expect none of the above.
SELECT prio,error_code,data
FROM performance_schema.error_log
WHERE data LIKE "Event Scheduler: %"
AND logged>@pfs_errlog_latest
LIMIT 3;
DROP EVENT s.ev;
SET @@SESSION.sql_mode = 'ANSI_QUOTES';
--echo # Create event while ANSI_QUOTES is active in session.
CREATE EVENT s.ev
ON SCHEDULE EVERY 1 SECOND
ON COMPLETION PRESERVE
ENABLE
DO
INSERT INTO s.modes VALUES (now(), @@SESSION.sql_mode, @@GLOBAL.sql_mode);
# Empty the table the event logs to.
TRUNCATE s.modes;
# Wait for event to run after sql_mode changed.
let $wait_condition=
SELECT COUNT(*)>0 FROM s.modes;
--source include/wait_condition.inc
--echo
--echo # Show debug entry for execution of event created with ANSI_QUOTES.
SELECT data
FROM performance_schema.error_log
WHERE error_code=@err_code
ORDER BY logged DESC LIMIT 1;
# Clean up.
SET @@GLOBAL.sql_mode = DEFAULT;
DROP SCHEMA s;
# Turn off debug-logging.
SET @@global.debug="-d,log_event_query_string";
# EOF
|