Skip to content

perf(sql): pipeline LOCAL CSV parsing with bounded workers - #33571

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/load-local-production
Dec 2, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/load-local-production

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #31727. Latest investigation and validation summary.

What this PR does / why we need it:

LOAD DATA LOCAL currently parses and materializes its single upload stream serially. Add an opt-in bounded worker pipeline: a lightweight coordinator frames complete CSV records, workers parse and materialize chunks using the current columnLoader, and the consumer publishes batches in input order. The MySQL upload stream and statement transaction remain unchanged.

SET SESSION local_csv_workers = 16 enables up to 16 workers, capped by session max_dop, GOMAXPROCS and existing query/CN scratch admission. The default is 0 (serial). Initial support is uncompressed LOCAL CSV with supported boundary grammar and at most 64 ordinary scalar columns; unsupported inputs stay serial. Large or uncertain records transfer the entire unpublished span to the authoritative serial parser. Scratch reservations, fixed ring credits, captured ingress cancellation, worker joining and handoff cleanup bound the new ownership paths. Reject a missing typed LOCAL ingress before wrapping it.

The production implementation uses current main's columnLoader/vector APIs. The historical generic spool optimization is excluded. Design and ownership details are in docs/design/20261201-load-local-csv-pipeline.md.

Validation

Original implementation validation at ae697026dae250498aeecfe3694314eecc06ded9.

  • All csvparser/external/crt owning packages pass normal and race checks, with focused revalidation after mechanism corrections; 671 bounded lifecycle race repetitions pass.
  • Differential parser, record-limit/EOF/BOM parity, ordered publication, source errors, replay, budget refusal/release, full-ring close and actual upload-pipe cancellation pass.
  • Frontend setting and existing executable/plain/prepared EXPLAIN controls pass; incremental lint reports 0 issues.
  • New distributed SQL regression passes 23/23, comparing all fixture columns using NULL-safe equality and checking session defaults/max_dop fallback.
  • Public SQL checks pass: exact quoted/NULL/BOM values, 2 MiB record fallback, late-error rollback/connection reuse, KILL QUERY, disconnect and concurrent imports. No storage-write fault injection is claimed.

Performance

On host 36 (AMD 5900X, 24 logical CPUs), the same current binary imported the same fully resident 7,775,727,688-byte TPC-H lineitem input, 59,986,052 rows, into fresh instances:

Mode Elapsed
Serial LOCAL, workers=0 140.86 s
Parallel LOCAL, admitted workers=16 18.26 s
Server LOAD 17.11 s

Parallel LOCAL is 7.71x faster than serial and 6.7% slower than server LOAD in this controlled observation. Full-column/correlated-row fingerprints and five TPC-H aggregates agree. This is one observation per mode using the same binary, not a separate clean-base binary comparison or a rerun of the historical full workload campaign. Tiny host-wide swap events occurred; test cgroups had swap disabled. Checksums provide probabilistic equivalence.

A 10-second optimized CPU profile attributes 0.94% cumulative CPU to ScanRecordBoundary. Worker materialization and sink writing dominate sampled CPU; cumulative shares overlap and are not wall-time bottleneck fractions. Two-row import medians were 18.72/22.45 ms (serial/parallel); a 5 MiB/s upload was 1.972/1.974 s. Default-off avoids assigning startup overhead to all small imports. Wide/TEXT and compressed workloads are outside this optimization.

Integrated gpt-6-astra medium design/final review approved the tested candidate with no remaining material blockers. Remote services were restored and health checked. Hosted CI results are pending at publication.

Repair validation

Rebased on official main@89cb66148d1c53ee2e4686b8cc8af52c7e7b7fca. The repair at 09606ccc3c58f71e18f9d4e24992b09d933d46cc completes six license headers and resolves two static-analysis findings by using reflection for the worker size assertions and matching the existing CSVParser receiver name.

  • Passed locally on Darwin/arm64 with repository CGo libraries. The repository-wide license-header check and the final PR-file header check passed. go vet and make static-check-selected passed for csvparser, external, crt and frontend.
  • The mo-cgo-test -race -count=1 package runs passed for csvparser, external and crt. The focused frontend race run passed 31 tests covering the session setting, EXPLAIN admission, LOCAL upload lifecycle and early rollback. External, crt and frontend results carry over from repair revision d3032e221395000bc754832da42d8ca666a3e407 because the intervening edits only adjusted csvparser receiver names and a test assertion implementation.
  • The original Linux/arm64 SCA run failed the header gate. The original Linux/x64 coverage worker timed out downloading Python before running UT. The worker evidence is recorded in #28652.
  • The performance table and SQL BVT above describe the original implementation run. This repair did not rerun either workload.

SCA follow-up

  • The Linux/arm64 job at 09606ccc3c58f71e18f9d4e24992b09d933d46cc passed the full license check, then stopped at the Makefile error-policy gate. The fix at 01882df74b5570bbd95539533fdeeb1e4b461468 uses MatrixOne error constructors for the LOCAL CSV framer and worker, and adds a regression for invalid chunk bounds. The test fails against the previous worker implementation and passes with the fix. Failed job
  • New local evidence on Darwin/arm64: make err-check, make static-check-analysis with the repository's local PR selector, and go vet passed. The CGo race runs passed for csvparser and the focused LOCAL CSV external cases, including serial replay and upload-source error propagation.
  • Reused the implementation's prior SQL BVT and performance evidence. The final Linux/arm64 CI result is pending.

CI refresh on latest main

  • Rebased onto official main 5b42e69ad5b608ca099aad87bdb8b7f78a58d73a at 0cd05e7500c800722aa54752ef01d999f0158f16. The PR patch is byte-for-byte identical to the patch at 033effc031926eb8844f2305daec19e8f17a07c6. The new base changes the UT runner's batch order and race test filters.
  • Locally, bash -n passed for both changed runner scripts, and go test -count=1 -run '^TestRaceInventory(Partition|CostLayoutScope|PreservesRunnableRootsAndStress)$' ./optools passed all three tests. The error-policy check, PR-file license headers and artifact check also passed.
  • The previous head's shared build, both coverage groups and both BVT jobs passed. SCA and x86 UT failed during action setup before checkout. The new hosted CI run will exercise the updated base. Previous run · Runner evidence

CI refresh after #33552

  • Rebased onto official main 409d8c483f5d87436f689ce39e4c296b69e0f09b at 01007c7893d1e23200b6429dc7dbffb2594ef823. The PR patch matches 0cd05e7500c800722aa54752ef01d999f0158f16 byte-for-byte. The new base changes shared plan/API definitions and table-dump behavior.
  • The repository CGo wrapper passed targeted LOCAL CSV, upload lifecycle and EXPLAIN race tests in external, crt and frontend. go vet passed for those packages. make err-check, PR-file license headers, git diff --check, and the artifact guard also passed. Earlier parser and benchmark evidence is reused.
  • The prior run's SCA job timed out in GitHub Actions setup before checkout. Shared build, both coverage groups and both BVT jobs passed on that head. Hosted CI will validate the rebased head. Prior run · Runner evidence

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@iamlinjunhong
iamlinjunhong force-pushed the codex/load-local-production branch from ae69702 to 09606cc Compare December 1, 2026 07:20
@mergify

mergify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as acbd597 at 11:51 UTC

1 h 24 min in the queue, 1 h 23 min of it CI.

So far

  • ✅ Entered the queue Wed 2 Dec, 10:28 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 11:51 · acbd597 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit acbd597 into matrixorigin:main Dec 2, 2026
32 of 33 checks passed

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants