This does look to be a legitimate bug. This would apply to any character
set where charset_info_st field escape_with_backslash_is_dangerous is
true, which currently is: big5, cp932, gbk, sjis.
The problem here is that string parameters coming from prepared
statements are being converted into 0xHHHH form indiscriminately in
append_query_string, which is producing the string to be binlogged for
statement-based replication. While that works okay for insertion of
strings into string fields, it causes the
conversion-from-string-to-integer which is happening on the master for
insertion of a string into an integer field to not be happening on the
slave, since 0xHHHH form is more properly an integer than a string.
This can be captured by setting a breakpoint at str_to_hex and running
this test case:
DROP TABLE IF EXISTS t;
|
CREATE TABLE t (id INT NOT NULL AUTO_INCREMENT, a INT, PRIMARY KEY(id));
|
SET NAMES gbk;
|
PREPARE STMT FROM 'INSERT INTO t (a) VALUES (?)';
|
SET @a = '1';
|
EXECUTE STMT USING @a;
|
Using SHOW BINLOG EVENTS shows that the problem is from the server (binlogging) side:
Log_name: 0.000001
|
Pos: 450
|
Event_type: Query
|
Server_id: 1
|
End_log_pos: 544
|
Info: use `test`; INSERT INTO t (a) VALUES (0x31)
|
0xHHHH is a MySQL extension. It's a hybrid thing.
It can behave as a number and a string depending on context.
Binary log could use the X'HHHH' notation instead:
INSERT INTO t1 VALUES (a) VALUES (X'31');
which is an SQL standard thing, and which must always be a string.
However, it seems the behaviour of X'HHHH' and of 0xHHHH
is exactly the same, and X'HHHH' can also act as a number:
drop table if exists t1;
|
create table t1 (id int);
|
insert into t1 values (x'31'),(0x31),(concat(0x31));
|
select * from t1;
|
+------+
|
| id |
|
+------+
|
| 49 | <-- wrong
|
| 49 | <-- ok
|
| 1 | <-- ok
|
+------+
|
Proposed fix:
1. Fix X'HHHH' to work always as string.
2. Fix binlog to use X'HHHH'
{"report":{"fcp":1314.2999997138977,"ttfb":339.8999996185303,"pageVisibility":"visible","entityId":24046,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"b43dd1b1-3773-4223-8591-b48a4ed53573","navigationType":0,"readyForUser":1446.7999997138977,"redirectCount":0,"resourceLoadedEnd":987.3999996185303,"resourceLoadedStart":347.5,"resourceTiming":[{"duration":196.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":347.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":347.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":544.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":215.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":347.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":347.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":563.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":508.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":348,"connectEnd":348,"connectStart":348,"domainLookupEnd":348,"domainLookupStart":348,"fetchStart":348,"redirectEnd":0,"redirectStart":0,"requestStart":570.3999996185303,"responseEnd":856.0999999046326,"responseStart":587.3999996185303,"secureConnectionStart":348},{"duration":639.1999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":348.19999980926514,"connectEnd":348.19999980926514,"connectStart":348.19999980926514,"domainLookupEnd":348.19999980926514,"domainLookupStart":348.19999980926514,"fetchStart":348.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":570.7999997138977,"responseEnd":987.3999996185303,"responseStart":590.0999999046326,"secureConnectionStart":348.19999980926514},{"duration":245.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":348.3999996185303,"connectEnd":348.3999996185303,"connectStart":348.3999996185303,"domainLookupEnd":348.3999996185303,"domainLookupStart":348.3999996185303,"fetchStart":348.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":571.5,"responseEnd":594.1999998092651,"responseStart":592.2999997138977,"secureConnectionStart":348.3999996185303},{"duration":245.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":348.59999990463257,"connectEnd":348.59999990463257,"connectStart":348.59999990463257,"domainLookupEnd":348.59999990463257,"domainLookupStart":348.59999990463257,"fetchStart":348.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":571.1999998092651,"responseEnd":594,"responseStart":591.2999997138977,"secureConnectionStart":348.59999990463257},{"duration":245.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":348.7999997138977,"connectEnd":348.7999997138977,"connectStart":348.7999997138977,"domainLookupEnd":348.7999997138977,"domainLookupStart":348.7999997138977,"fetchStart":348.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":572,"responseEnd":594.3999996185303,"responseStart":593.1999998092651,"secureConnectionStart":348.7999997138977},{"duration":215.2999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":564.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":248.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":349.09999990463257,"connectEnd":349.09999990463257,"connectStart":349.09999990463257,"domainLookupEnd":349.09999990463257,"domainLookupStart":349.09999990463257,"fetchStart":349.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":573.5999999046326,"responseEnd":598,"responseStart":596.1999998092651,"secureConnectionStart":349.09999990463257},{"duration":217.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":349.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":349.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":566.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":264.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":349.3999996185303,"connectEnd":349.3999996185303,"connectStart":349.3999996185303,"domainLookupEnd":349.3999996185303,"domainLookupStart":349.3999996185303,"fetchStart":349.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":574,"responseEnd":613.6999998092651,"responseStart":597.3999996185303,"secureConnectionStart":349.3999996185303},{"duration":616.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":350.2999997138977,"connectEnd":350.2999997138977,"connectStart":350.2999997138977,"domainLookupEnd":350.2999997138977,"domainLookupStart":350.2999997138977,"fetchStart":350.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":753,"responseEnd":966.7999997138977,"responseStart":954.0999999046326,"secureConnectionStart":350.2999997138977},{"duration":615.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":353.19999980926514,"connectEnd":353.19999980926514,"connectStart":353.19999980926514,"domainLookupEnd":353.19999980926514,"domainLookupStart":353.19999980926514,"fetchStart":353.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":880.1999998092651,"responseEnd":969.0999999046326,"responseStart":960.7999997138977,"secureConnectionStart":353.19999980926514},{"duration":194.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":990.2999997138977,"connectEnd":990.2999997138977,"connectStart":990.2999997138977,"domainLookupEnd":990.2999997138977,"domainLookupStart":990.2999997138977,"fetchStart":990.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1151.1999998092651,"responseEnd":1184.8999996185303,"responseStart":1184.2999997138977,"secureConnectionStart":990.2999997138977},{"duration":283.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1262.7999997138977,"connectEnd":1262.7999997138977,"connectStart":1262.7999997138977,"domainLookupEnd":1262.7999997138977,"domainLookupStart":1262.7999997138977,"fetchStart":1262.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1513.5999999046326,"responseEnd":1545.8999996185303,"responseStart":1544.5999999046326,"secureConnectionStart":1262.7999997138977}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":134,"responseStart":340,"responseEnd":347,"domLoading":343,"domInteractive":1509,"domContentLoadedEventStart":1509,"domContentLoadedEventEnd":1555,"domComplete":2130,"loadEventStart":2130,"loadEventEnd":2131,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1488.7999997138977},{"name":"bigPipe.sidebar-id.end","time":1489.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1489.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.end","time":1490.7999997138977},{"name":"activityTabFullyLoaded","time":1574.8999996185303}],"measures":[],"correlationId":"db17837495d898","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":95,"dbReadsTimeInMs":10,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
A patch sent for review.