Repository navigation
perf(import): read transaction state only when it can move, and transfer rows off the main actor - #4602
Merged
Conversation
…fer rows off the main actor Inside the import's transaction, a row batch or a plain DML statement that succeeds no longer reads the session's transaction state, which SQL Server answers with a probe query. The column mapping is resolved once per field layout, and Table Transfer's row loop runs in a @Concurrent function with the row count throttled to the sheet.
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.
Summary
Fewer transaction state reads. Inside the import's own transaction, a row batch, a clearing
DELETEor a plainINSERT,UPDATE,DELETEor read statement that succeeds no longer reads the session's transaction state after it. SQL Server answers that read with a probe query, so a SQL file import paid two round trips per statement. The state is still read after:BEGIN,COMMIT, DDL,SET,CALL);COMMIT,TRAN,EXEC,GO,END, ...);Statements sent together follow the same rule.
Mapping resolved once. The column mapping is resolved into a plan once per field layout, instead of lowercasing, grouping and sorting each row's field names again.
Table Transfer off the main actor. The row loop (a dictionary per row, coercion, mapping, INSERT text) runs in a
@concurrentfunction. Each batch posts its count to a stream that keeps only the newest; the sheet takes one at most every 100 ms, and gets the exact total before the commit and when each table ends.Not in this PR: the bulk-load path (
COPY,LOAD DATA LOCAL), batching under Skip and Continue, the read-ahead producer and positional rows. The issue comment lists them.Reviewed by an independent Claude reviewer in a fresh session, given only the diff, since the Codex reviewer is at its usage limit. Its two findings are fixed here: a progress count that could sit behind during a slow batch, and the catalog read above.
Test plan
ImportTransactionStateReadTests: 50 INSERTs and five row batches inside the transaction read no state; an INSERT outside one reads it;COMMIT,BEGIN, DDL,CALL, a T-SQL unit withCOMMIT TRANSACTIONandSET autocommiteach read it; statements sent together read it only when one can move it; the word scan matches whole words in any case and skipstransactions,go_live,'committed'and'aborted'.ImportRowWriterMappingPlanTests: rows with the same fields in another order map alike, and a row with other fields gets its own mapping.TransferRowCountTests: the sheet hears the newest count, and the total counts every batch.verify.sh testover the import, row writer, sink adapter, manual commit, native dump and Table Transfer suites: 276 executed, 276 passed.Closes #4554