Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
2.4.0
When INSERT ... ON DUPLICATE KEY UPDATE statement updated a row, the ResultSet returned from getGeneratedKeys() contains two rows.
Here is a failing test case (I wrote it in MultiTest).
@Test
public void shouldDuplicateKeyUpdateNotReturnExtraRows() throws Throwable {
try (Connection con = openNewConnection(connUri, new Properties())) {
try (Statement stmt = con.createStatement()) {
stmt.execute( "truncate table testMultiGeneratedKey" );
}
try (PreparedStatement pstmt = con.prepareStatement(
"INSERT INTO testMultiGeneratedKey (id, text) VALUES (?, ?) "
+ "ON DUPLICATE KEY UPDATE text = VALUES(text)" ,
Statement.RETURN_GENERATED_KEYS)) {
// Insert a row.
pstmt.setInt( 1 , 1 );
pstmt.setString( 2 , "initial" );
assertEquals( 1 , pstmt.executeUpdate());
try (ResultSet rs = pstmt.getGeneratedKeys()) {
assertTrue(rs.next());
assertEquals( 1 , rs.getInt( 1 ));
assertFalse(rs.next());
}
// Update the row.
pstmt.setInt( 1 , 1 );
pstmt.setString( 2 , "updated" );
assertEquals( 2 , pstmt.executeUpdate());
try (ResultSet rs = pstmt.getGeneratedKeys()) {
assertTrue(rs.next());
assertEquals( 1 , rs.getInt( 1 ));
assertFalse(rs.next());
}
}
}
}
getGeneratedKeys() ultimately calls org.mariadb.jdbc.internal.com.read.dao.CmdInformationSingle.getGeneratedKeys(Protocol) .
In this method, updateCount is used as the size of returned result set, however, updateCount is 2 when INSERT ... ON DUPLICATE KEY UPDATE statement updated a row according to the doc .
relates to
CONJ-706
getGeneratedKey implementation correction for multiple result for one query
Closed
Transition
Time In Source Status
Execution Times
Open
Closed
166d 23h 19m
1
{"report":{"fcp":810.3999998569489,"ttfb":150.39999985694885,"pageVisibility":"visible","entityId":75432,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"54f69673-d971-42ec-86a3-4b12ca47d6f4","navigationType":0,"readyForUser":872.3999998569489,"redirectCount":0,"resourceLoadedEnd":1048.5999999046326,"resourceLoadedStart":168,"resourceTiming":[{"duration":118.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":168,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":168,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":286.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":214,"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":168.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":168.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":382.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":222.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":168.39999985694885,"connectEnd":168.39999985694885,"connectStart":168.39999985694885,"domainLookupEnd":168.39999985694885,"domainLookupStart":168.39999985694885,"fetchStart":168.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":168.39999985694885,"responseEnd":391.09999990463257,"responseStart":391.09999990463257,"secureConnectionStart":168.39999985694885},{"duration":247.5,"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":168.5,"connectEnd":168.5,"connectStart":168.5,"domainLookupEnd":168.5,"domainLookupStart":168.5,"fetchStart":168.5,"redirectEnd":0,"redirectStart":0,"requestStart":168.5,"responseEnd":416,"responseStart":416,"secureConnectionStart":168.5},{"duration":251.09999990463257,"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":168.59999990463257,"connectEnd":168.59999990463257,"connectStart":168.59999990463257,"domainLookupEnd":168.59999990463257,"domainLookupStart":168.59999990463257,"fetchStart":168.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":168.59999990463257,"responseEnd":419.69999980926514,"responseStart":419.69999980926514,"secureConnectionStart":168.59999990463257},{"duration":251.70000004768372,"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":168.69999980926514,"connectEnd":168.69999980926514,"connectStart":168.69999980926514,"domainLookupEnd":168.69999980926514,"domainLookupStart":168.69999980926514,"fetchStart":168.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":168.69999980926514,"responseEnd":420.39999985694885,"responseStart":420.39999985694885,"secureConnectionStart":168.69999980926514},{"duration":252.09999990463257,"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":168.79999995231628,"connectEnd":168.79999995231628,"connectStart":168.79999995231628,"domainLookupEnd":168.79999995231628,"domainLookupStart":168.79999995231628,"fetchStart":168.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":168.79999995231628,"responseEnd":420.89999985694885,"responseStart":420.89999985694885,"secureConnectionStart":168.79999995231628},{"duration":252.70000004768372,"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":168.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":168.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":421.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":252.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":169,"connectEnd":169,"connectStart":169,"domainLookupEnd":169,"domainLookupStart":169,"fetchStart":169,"redirectEnd":0,"redirectStart":0,"requestStart":169,"responseEnd":421.59999990463257,"responseStart":421.59999990463257,"secureConnectionStart":169},{"duration":253.09999990463257,"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":169.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":169.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":422.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":253.09999990463257,"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":169.29999995231628,"connectEnd":169.29999995231628,"connectStart":169.29999995231628,"domainLookupEnd":169.29999995231628,"domainLookupStart":169.29999995231628,"fetchStart":169.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":169.29999995231628,"responseEnd":422.39999985694885,"responseStart":422.39999985694885,"secureConnectionStart":169.29999995231628},{"duration":553.6000001430511,"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":174.39999985694885,"connectEnd":174.39999985694885,"connectStart":174.39999985694885,"domainLookupEnd":174.39999985694885,"domainLookupStart":174.39999985694885,"fetchStart":174.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":174.39999985694885,"responseEnd":728,"responseStart":727.8999998569489,"secureConnectionStart":174.39999985694885},{"duration":874.2000000476837,"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":174.39999985694885,"connectEnd":174.39999985694885,"connectStart":174.39999985694885,"domainLookupEnd":174.39999985694885,"domainLookupStart":174.39999985694885,"fetchStart":174.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":174.39999985694885,"responseEnd":1048.5999999046326,"responseStart":1048.5999999046326,"secureConnectionStart":174.39999985694885},{"duration":343.2000000476837,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":617.0999999046326,"connectEnd":617.0999999046326,"connectStart":617.0999999046326,"domainLookupEnd":617.0999999046326,"domainLookupStart":617.0999999046326,"fetchStart":617.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":617.0999999046326,"responseEnd":960.2999999523163,"responseStart":960.2999999523163,"secureConnectionStart":617.0999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":11,"responseStart":150,"responseEnd":173,"domLoading":166,"domInteractive":1098,"domContentLoadedEventStart":1098,"domContentLoadedEventEnd":1132,"domComplete":1438,"loadEventStart":1438,"loadEventEnd":1439,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1083.6999998092651},{"name":"bigPipe.sidebar-id.end","time":1084.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1084.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1085.5},{"name":"activityTabFullyLoaded","time":1142.2999999523163}],"measures":[],"correlationId":"b0b7efd055f4cd","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":69,"dbReadsTimeInMs":12,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}