Skip to content

perf(import): read transaction state only when it can move, and transfer rows off the main actor - #4602

Merged
datlechin merged 2 commits into
mainfrom
perf/import-bulk-rows
Nov 26, 2026
Merged

datlechin merged 2 commits into
mainfrom
perf/import-bulk-rows

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Fewer transaction state reads. Inside the import's own transaction, a row batch, a clearing DELETE or a plain INSERT, UPDATE, DELETE or 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:

    • a failure;
    • a statement led by any other keyword (BEGIN, COMMIT, DDL, SET, CALL);
    • a statement whose text holds a word that can end or hand off a transaction (COMMIT, TRAN, EXEC, GO, END, ...);
    • a catalog read, which can swallow its own error after PostgreSQL has aborted the transaction;
    • every call made outside a transaction, where Oracle, MySQL with autocommit off and implicit transactions open one at the first write.

    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 @concurrent function. 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

  • New 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 with COMMIT TRANSACTION and SET autocommit each read it; statements sent together read it only when one can move it; the word scan matches whole words in any case and skips transactions, go_live, 'committed' and 'aborted'.
  • New ImportRowWriterMappingPlanTests: rows with the same fields in another order map alike, and a row with other fields gets its own mapping.
  • New TransferRowCountTests: the sheet hears the newest count, and the total counts every batch.
  • verify.sh test over the import, row writer, sink adapter, manual commit, native dump and Table Transfer suites: 276 executed, 276 passed.

Closes #4554

…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.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 04:22
@datlechin
datlechin merged commit 68b47a8 into main Nov 26, 2026
11 checks passed
@datlechin
datlechin deleted the perf/import-bulk-rows branch November 27, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(import): bulk-load rows with COPY and LOAD DATA, and batch when skipping errors

1 participant