Type:
Task
Priority:
Minor
Resolution:
Fixed
Affects Version/s:
1.1.8
Environment:
Long network delay between client and server.
Sprint:
Sprint connector/j 1.3.0
CONJ-99 introduced support for the rewriteBatchedStatements=true JDBC URL parameter. This rewrites batched prepared statements into a single statement, when using PreparedStatement.addBatch() & executeBatch().
This works fine for INSERT statements which do not specify an ON DUPLICATE KEY UPDATE clause. However for statements which do, the generated SQL cannot be parsed because the ON DUPLICATE ... clause is repeated for each set of values. E.g. for a prepared statement such as:
prep.sql
INSERT INTO my_table (pkey, col1) VALUES (?, ?) ON DUPLICATE KEY UPDATE col1 = VALUES(col1)
after setting the parameters multiple times and calling addBatch() then executeBatch(), the generated SQL looks like this:
gen.sql
INSERT INTO my_table (pkey, col1) VALUES (1, 'a') ON DUPLICATE KEY UPDATE col1 = VALUES(col1),(2,'b') ON DUPLICATE KEY UPDATE col1 = VALUES(col1), ...
I've written a small patch with a test case to duplicate the issue, along with a suggested fix. The test will fail against 1.1.8 but should pass with the suggested fix.
{"report":{"fcp":846.3999999761581,"ttfb":202.29999995231628,"pageVisibility":"visible","entityId":50225,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"5adcab74-cb9f-4ef6-a0f5-ed3b05ac63dc","navigationType":0,"readyForUser":925.1000000238419,"redirectCount":0,"resourceLoadedEnd":567.2000000476837,"resourceLoadedStart":207.79999995231628,"resourceTiming":[{"duration":48.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":207.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":207.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":256.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":49,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":208,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":208,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":257,"responseStart":0,"secureConnectionStart":0},{"duration":251.20000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":208.29999995231628,"connectEnd":208.29999995231628,"connectStart":208.29999995231628,"domainLookupEnd":208.29999995231628,"domainLookupStart":208.29999995231628,"fetchStart":208.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":262.60000002384186,"responseEnd":459.5,"responseStart":283.60000002384186,"secureConnectionStart":208.29999995231628},{"duration":358.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":208.5,"connectEnd":208.5,"connectStart":208.5,"domainLookupEnd":208.5,"domainLookupStart":208.5,"fetchStart":208.5,"redirectEnd":0,"redirectStart":0,"requestStart":262.89999997615814,"responseEnd":567.2000000476837,"responseStart":284.89999997615814,"secureConnectionStart":208.5},{"duration":84.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":208.60000002384186,"connectEnd":208.60000002384186,"connectStart":208.60000002384186,"domainLookupEnd":208.60000002384186,"domainLookupStart":208.60000002384186,"fetchStart":208.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":263.10000002384186,"responseEnd":293.10000002384186,"responseStart":288,"secureConnectionStart":208.60000002384186},{"duration":84.60000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":208.79999995231628,"connectEnd":208.79999995231628,"connectStart":208.79999995231628,"domainLookupEnd":208.79999995231628,"domainLookupStart":208.79999995231628,"fetchStart":208.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":263.39999997615814,"responseEnd":293.39999997615814,"responseStart":289.2999999523163,"secureConnectionStart":208.79999995231628},{"duration":84.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":209,"connectEnd":209,"connectStart":209,"domainLookupEnd":209,"domainLookupStart":209,"fetchStart":209,"redirectEnd":0,"redirectStart":0,"requestStart":263.60000002384186,"responseEnd":293.2999999523163,"responseStart":288.60000002384186,"secureConnectionStart":209},{"duration":53,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":209.10000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":209.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":262.10000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":88.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":209.29999995231628,"connectEnd":209.29999995231628,"connectStart":209.29999995231628,"domainLookupEnd":209.29999995231628,"domainLookupStart":209.29999995231628,"fetchStart":209.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":266.7000000476837,"responseEnd":297.7000000476837,"responseStart":294.2000000476837,"secureConnectionStart":209.29999995231628},{"duration":56.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":209.39999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":209.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":265.5,"responseStart":0,"secureConnectionStart":0},{"duration":89.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":209.60000002384186,"connectEnd":209.60000002384186,"connectStart":209.60000002384186,"domainLookupEnd":209.60000002384186,"domainLookupStart":209.60000002384186,"fetchStart":209.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":268,"responseEnd":299.10000002384186,"responseStart":295.2999999523163,"secureConnectionStart":209.60000002384186},{"duration":348.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":215.39999997615814,"connectEnd":215.39999997615814,"connectStart":215.39999997615814,"domainLookupEnd":215.39999997615814,"domainLookupStart":215.39999997615814,"fetchStart":215.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":303,"responseEnd":564.2000000476837,"responseStart":556.7000000476837,"secureConnectionStart":215.39999997615814},{"duration":349.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":215.39999997615814,"connectEnd":215.39999997615814,"connectStart":215.39999997615814,"domainLookupEnd":215.39999997615814,"domainLookupStart":215.39999997615814,"fetchStart":215.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":341.89999997615814,"responseEnd":565.1000000238419,"responseStart":560.2000000476837,"secureConnectionStart":215.39999997615814},{"duration":146.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":603.7000000476837,"connectEnd":603.7000000476837,"connectStart":603.7000000476837,"domainLookupEnd":603.7000000476837,"domainLookupStart":603.7000000476837,"fetchStart":603.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":715.3999999761581,"responseEnd":750.2999999523163,"responseStart":749.7000000476837,"secureConnectionStart":603.7000000476837}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":19,"responseStart":202,"responseEnd":213,"domLoading":206,"domInteractive":1021,"domContentLoadedEventStart":1021,"domContentLoadedEventEnd":1069,"domComplete":1634,"loadEventStart":1634,"loadEventEnd":1635,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":997.3999999761581},{"name":"bigPipe.sidebar-id.end","time":998.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":998.3999999761581},{"name":"bigPipe.activity-panel-pipe-id.end","time":1000.2999999523163},{"name":"activityTabFullyLoaded","time":1086.1000000238419}],"measures":[],"correlationId":"4d49d73a1fb8f9","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":110,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
adding test case that handle different possibilities :
/**
* CONJ-141 : Batch Statement Rewrite: Support for ON DUPLICATE KEY
* @throws SQLException
*/
tmpConnection = openNewConnection(connURI, props);
Statement st = tmpConnection.createStatement();
sqlInsert.addBatch();
sqlInsert.addBatch();
sqlInsert.addBatch();
sqlInsert.executeBatch();
}
}
Resulting query send to database :
INSERT INTO t3_dupp(col1, pkey,col2,col3,col4) VALUES (9, 1, 5, 2, 8),(9, 2, 5, 5, 8),(9, 7, 5, 6, 8) ON DUPLICATE KEY UPDATE pkey=pkey+10