Skip to content

feat: add scalable SQL execution paths - #70

Open
HelgeSverre wants to merge 2 commits into
kwhorne:mainfrom
HelgeSverre:agent/sql-features-and-bulk-performance
Open

feat: add scalable SQL execution paths#70
HelgeSverre wants to merge 2 commits into
kwhorne:mainfrom
HelgeSverre:agent/sql-features-and-bulk-performance

Conversation

@HelgeSverre

@HelgeSverre HelgeSverre commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add scalable SQL execution paths for composite index ranges, correlated EXISTS, selective indexed joins, spill-backed DISTINCT, incremental window aggregation, bulk loading, and populated-table ADD PRIMARY KEY
  • preserve atomic DDL rewrites with serializable validation while bounding rewrite memory
  • fix exact window aggregation above 2^53 and avoid floating-point prefix cancellation
  • make large DISTINCT byte-bounded, spill-capable, cancellation-aware, and safe for async runtime workers
  • preserve mixed-numeric DISTINCT equality and create result spill files with owner-only permissions on Unix

Review follow-up

The adversarial review identified correctness and resource-safety gaps in the original implementation. This update adds regression coverage and fixes for:

  • lossy f64 prefix subtraction in window SUM/AVG
  • unbounded memory during ALTER TABLE ... ADD PRIMARY KEY
  • row-count-only DISTINCT memory accounting
  • synchronous DISTINCT spill work on Tokio workers
  • mixed numeric representations surviving DISTINCT
  • overly permissive DISTINCT result spill files

Implicit ALTER transactions now skip unnecessary per-key checkpoint logging because the entire private transaction can be discarded on failure. Explicit user transactions retain checkpoints and statement rollback semantics.

Performance

Release builds on the same Apple Silicon host, identical schemas/data, alternating execution order, five warmups, and 20-100 measured samples. Values are median client-observed latency.

Review fixes: before vs after

Workload Before After Change
DISTINCT spill, 50k rows / 1k groups 28.58 ms 28.27 ms -1.1%
Integer RANGE window, 5k rows 4.36 ms 4.39 ms +0.7%
Float cumulative window, 10k rows 3.29 ms 3.67 ms +11.6%
ADD PRIMARY KEY, 20k rows + secondary index 216.36 ms 208.75 ms -3.5%

The floating-window regression test initially exposed a 3.66 ms to 2,378 ms slowdown from frame rescanning. A range-sum tree restored bounded evaluation; the final 3.67 ms result retains exact singleton-frame behavior.

ElyraSQL vs MySQL 8.0.33

Workload MySQL ElyraSQL Relative
PK point lookup 0.111 ms 0.140 ms ElyraSQL 26% slower
DISTINCT, 50k rows / 1k groups 10.50 ms 14.22 ms ElyraSQL 35% slower
Integer RANGE window, 5k rows 4.20 ms 3.87 ms ElyraSQL 8% faster
Float cumulative window, 10k rows 3.34 ms 3.65 ms ElyraSQL 9% slower
ADD PRIMARY KEY, 20k rows + secondary index 45.34 ms 208.75 ms ElyraSQL 4.6x slower

Profiling shows the remaining ADD PRIMARY KEY gap is dominated by atomic redb validation and individual key removal/insertion. A storage-level atomic bulk/range-rewrite primitive is intentionally deferred to a follow-up PR.

Verification

  • cargo test --workspace --all-targets — 407 tests passed
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check
  • targeted wire tests for ALTER atomicity, concurrent insert rejection, and DISTINCT behavior

@HelgeSverre
HelgeSverre marked this pull request as ready for review August 9, 2026 17:54
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.

1 participant