Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
2.1.2
When we adding batched query in form of:
insert ... values (:some_id, (SELECT X from other_table where fk = :some_id))
It seems that result of sub-query somewhere caches, and produces invalid data.
Here's test excerpt which also failing:
@Test
public void testNonCachingBatchUpdate() throws SQLException {
createTable("testNonCachingBatchUpdate1", "col int, val int");
createTable("testNonCachingBatchUpdate2", "col int, val int");
Statement statement = sharedConnection.createStatement();
//add 100 data
StringBuilder sb = new StringBuilder("INSERT INTO testNonCachingBatchUpdate1(col, val) VALUES (0,0), (1,1)");
statement.execute(sb.toString());
try (PreparedStatement preparedStatement = sharedConnection.prepareStatement(
"INSERT INTO testNonCachingBatchUpdate2(col, val) VALUES (?, " +
"(SELECT val FROM testNonCachingBatchUpdate1 where col = ?))"))
{
preparedStatement.setInt(1, 0);
preparedStatement.setInt(2, 0);
preparedStatement.addBatch();
preparedStatement.setInt(1, 1);
preparedStatement.setInt(2, 1);
preparedStatement.addBatch();
int[] results = preparedStatement.executeBatch();
assertEquals(2, results.length);
}
//check results
try (ResultSet rs = statement.executeQuery("SELECT * FROM testNonCachingBatchUpdate2 order by col"))
{
assertTrue(rs.next());
assertEquals(rs.getInt(1), 0);
assertEquals(rs.getInt(2), 0);
assertTrue(rs.next());
assertEquals(rs.getInt(1), 1);
//this fails
assertEquals(rs.getInt(2), 1);
assertFalse(rs.next());
}
}
{"report":{"fcp":687.6000001430511,"ttfb":152.79999995231628,"pageVisibility":"visible","entityId":64168,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"716c20f3-64cc-4e28-818c-92a07abb2134","navigationType":0,"readyForUser":742.1000001430511,"redirectCount":0,"resourceLoadedEnd":451.7999999523163,"resourceLoadedStart":158,"resourceTiming":[{"duration":6.200000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":158,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":158,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":164.20000004768372,"responseStart":0,"secureConnectionStart":0},{"duration":6.099999904632568,"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":158.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":158.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":164.29999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":83.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":158.29999995231628,"connectEnd":158.29999995231628,"connectStart":158.29999995231628,"domainLookupEnd":158.29999995231628,"domainLookupStart":158.29999995231628,"fetchStart":158.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":168,"responseEnd":241.40000009536743,"responseStart":180.5,"secureConnectionStart":158.29999995231628},{"duration":116.09999990463257,"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":158.40000009536743,"connectEnd":158.40000009536743,"connectStart":158.40000009536743,"domainLookupEnd":158.40000009536743,"domainLookupStart":158.40000009536743,"fetchStart":158.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":168,"responseEnd":274.5,"responseStart":188.20000004768372,"secureConnectionStart":158.40000009536743},{"duration":25.59999990463257,"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":158.60000014305115,"connectEnd":158.60000014305115,"connectStart":158.60000014305115,"domainLookupEnd":158.60000014305115,"domainLookupStart":158.60000014305115,"fetchStart":158.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":168.5,"responseEnd":184.20000004768372,"responseStart":181.70000004768372,"secureConnectionStart":158.60000014305115},{"duration":32.5,"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":158.60000014305115,"connectEnd":158.60000014305115,"connectStart":158.60000014305115,"domainLookupEnd":158.60000014305115,"domainLookupStart":158.60000014305115,"fetchStart":158.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":169.70000004768372,"responseEnd":191.10000014305115,"responseStart":190.10000014305115,"secureConnectionStart":158.60000014305115},{"duration":37,"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":158.70000004768372,"connectEnd":158.70000004768372,"connectStart":158.70000004768372,"domainLookupEnd":158.70000004768372,"domainLookupStart":158.70000004768372,"fetchStart":158.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":170.70000004768372,"responseEnd":195.70000004768372,"responseStart":194.79999995231628,"secureConnectionStart":158.70000004768372},{"duration":11.5,"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":158.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":158.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":170.29999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":54,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":158.90000009536743,"connectEnd":158.90000009536743,"connectStart":158.90000009536743,"domainLookupEnd":158.90000009536743,"domainLookupStart":158.90000009536743,"fetchStart":158.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":173.10000014305115,"responseEnd":212.90000009536743,"responseStart":212.10000014305115,"secureConnectionStart":158.90000009536743},{"duration":12.700000047683716,"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":159,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":159,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":171.70000004768372,"responseStart":0,"secureConnectionStart":0},{"duration":58,"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":159.10000014305115,"connectEnd":159.10000014305115,"connectStart":159.10000014305115,"domainLookupEnd":159.10000014305115,"domainLookupStart":159.10000014305115,"fetchStart":159.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":175.60000014305115,"responseEnd":217.10000014305115,"responseStart":215.90000009536743,"secureConnectionStart":159.10000014305115},{"duration":265.60000014305115,"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":178.79999995231628,"connectEnd":178.79999995231628,"connectStart":178.79999995231628,"domainLookupEnd":178.79999995231628,"domainLookupStart":178.79999995231628,"fetchStart":178.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":188.10000014305115,"responseEnd":444.40000009536743,"responseStart":442.10000014305115,"secureConnectionStart":178.79999995231628},{"duration":271.2999999523163,"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":180.5,"connectEnd":180.5,"connectStart":180.5,"domainLookupEnd":180.5,"domainLookupStart":180.5,"fetchStart":180.5,"redirectEnd":0,"redirectStart":0,"requestStart":192.5,"responseEnd":451.7999999523163,"responseStart":444.60000014305115,"secureConnectionStart":180.5},{"duration":211.20000004768372,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":450.7999999523163,"connectEnd":450.7999999523163,"connectStart":450.7999999523163,"domainLookupEnd":450.7999999523163,"domainLookupStart":450.7999999523163,"fetchStart":450.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":631.7999999523163,"responseEnd":662,"responseStart":661.1000001430511,"secureConnectionStart":450.7999999523163},{"duration":108.89999985694885,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":664.1000001430511,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":664.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":773,"responseStart":0,"secureConnectionStart":0},{"duration":132.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":686.7000000476837,"connectEnd":686.7000000476837,"connectStart":686.7000000476837,"domainLookupEnd":686.7000000476837,"domainLookupStart":686.7000000476837,"fetchStart":686.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":785.1000001430511,"responseEnd":818.7999999523163,"responseStart":817.7999999523163,"secureConnectionStart":686.7000000476837}],"fetchStart":0,"domainLookupStart":13,"domainLookupEnd":18,"connectStart":18,"connectEnd":38,"secureConnectionStart":27,"requestStart":38,"responseStart":153,"responseEnd":180,"domLoading":156,"domInteractive":788,"domContentLoadedEventStart":788,"domContentLoadedEventEnd":819,"domComplete":1836,"loadEventStart":1836,"loadEventEnd":1837,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":770.7000000476837},{"name":"bigPipe.sidebar-id.end","time":771.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":771.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":774},{"name":"activityTabFullyLoaded","time":827.6000001430511}],"measures":[],"correlationId":"e10161b98d6e49","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":65,"dbReadsTimeInMs":9,"dbConnsTimeInMs":15,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}