fix: EXPOSED-1048 Return only the rows batchInsert actually inserted - #2877
Open
obabichevjb wants to merge 1 commit into
Open
fix: EXPOSED-1048 Return only the rows batchInsert actually inserted#2877obabichevjb wants to merge 1 commit into
obabichevjb wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary of the change:
batchInsert(ignore = true)no longer returns rows the database skipped on conflict.Detailed description:
Why:
batchInsertdocuments its return as "a list ofResultRowrepresenting data from each newly inserted row", but built one row per submitted argument set regardless of what the database did with it. WhenINSERT IGNORE/ON CONFLICT DO NOTHINGskipped a row, the caller still got it back as if it had been inserted, with no way to tell the difference —batchInsertreturns aList<ResultRow>and discards the statement, soinsertedCountis not reachable.What:
InsertBlockingExecutable(JDBC) andInsertSuspendExecutable(R2DBC) now drop the argument sets the database reported no rows for, before building the result rows.How: The per-entry affected-row counts already existed in both drivers and were being discarded.
executeBatch()returnsList<Int>, already normalised byJdbcPreparedStatementImpl(SUCCESS_NO_INFO → 1,EXECUTE_FAILED → 0). It was being.sum()ed away inexecInsertFunction; it is now captured first.resultSetsCountswas collected insidereturnedValues()and dropped at the return statement. That function now returns a small privateReturnedValuesholder instead of aPair, and is called fromexecuteInternalso the affected count is known before the rows are built.Both drivers then run the same filter:
Two deliberate limits on the scope:
BatchInsertStatementwithisIgnore. A singleinsertIgnorestill reports its submitted values and leavesinsertedCountto say whether the row was inserted — behaviour thattestInsertIgnoreAndGetIdWithPredefinedIdlocks in. TheBatchInsertStatementcheck also excludesBatchUpsertStatementandBatchReplaceStatement, which extend it withignore = false; filtering those would drop rows from an upsert that MySQL reports as affecting 0 rows.execInsertFunctionisprotected openand is in the API dump, so widening its return type to carry the counts would have been a binary-incompatible change. The JDBC counts travel in a private field instead, which also keeps them reachable when theResultSetisnull— the case for aUUIDTablewith no generated columns on H2, MariaDB, SQL Server and Oracle, which is exactly the table shape in the report.Known limitation: telling apart which rows of a partly inserted batch were skipped needs an update count per statement, and the H2 and MariaDB R2DBC drivers send none. On those two, such a batch still returns all of its arguments, as before.
Type of Change
Please mark the relevant options with an "X":
Affected databases:
Oracle and SQL Server are unaffected: neither supports
INSERT IGNORE, and the change is gated behindisIgnore.Related Issues
EXPOSED-1048 https://youtrack.jetbrains.com/issue/EXPOSED-1048