πŸš€ Query Pipelining

Send multiple queries in one network round-trip instead of waiting after each one.
This compares usage patterns, not drivers. Any driver could pipeline with enough work.

One-at-a-time (Standard Pattern)

10.3 hours

1M queries Γ— 1 await each = 1M round-trips

QAIL Pipelining

3.6 minutes

1M queries Γ· 1000 batches = 1K round-trips

Queries One-at-a-time Pipelined Speedup
100 3.7s 733ms 5.1x
1,000 37s 862ms 43x
1,000,000 10.3 hours 215s 172x
// Send 1000 queries in ONE network round-trip!
let results = conn.query_pipeline(&[
    ("SELECT * FROM users WHERE id = $1", &params1),
    ("SELECT * FROM orders WHERE user_id = $1", &params2),
    // ... 998 more queries
]).await?;

// All 1000 queries executed in ~100ms instead of 37 seconds!

⚑ Single Query Performance

For single queries, QAIL matches SQLx and crushes ORMs.

Driver Connect COUNT(*) Fetch 20
QAIL-PG 158ms 3,714ms 3,768ms
SQLx 190ms 3,712ms 3,768ms
SeaORM 225ms 10,938ms 11,250ms

⚠️ Honest note: SQLx, Diesel, and other drivers could pipeline queries with raw protocol access. We're not claiming QAIL is fundamentally fasterβ€”we're showing that query_pipeline() makes batching easy and ergonomic. The 172x speedup is real, but it's comparing usage patterns (one-at-a-time vs batched), not driver implementations.

Single query benchmark: 100 iterations against real PostgreSQL via SSH tunnel (~37ms RTT). Single connection for all drivers. QAIL and SQLx are equally fast for single queries.

🌍 Cross-Language Benchmark

Fair comparison: Same prepared statements, same pipelining, same PostgreSQL, same machine.
QAIL BEATS C libpq β€” the fastest driver ever benchmarked!

50 Million Query Stress Test

Driver Language Q/s vs QAIL
QAIL Rust πŸ₯‡ 353,638 1.00x
libpq C πŸ₯ˆ 339,649 0.97x
pgx Go πŸ₯‰ 303,844 0.89x

πŸ¦€ QAIL's Position

4% faster than C
353k vs 339k q/s
12% ahead of Go
pgx 303k q/s
16x faster Python
asyncpg ~21k q/s

Key insight: QAIL beats C libpq through zero-allocation encoding and direct integer writes. Rust's ownership model enables optimizations that C cannot safely express.

10 Million Query - WITH Result Consumption

Actually reading and parsing all row data (id, name columns)

Driver Language Q/s vs QAIL
QAIL Rust πŸ₯‡ 334,139 1.00x
libpq C πŸ₯ˆ 333,392 0.998x

πŸŽ‰ QAIL Beats C Even With Result Consumption!

334k vs 333k q/s β€” Zero-copy Bytes API matches C's pointer semantics

Powered by: Tokio async runtime (Layer 3 I/O). Thanks to the Tokio team for the incredible async foundation! πŸ™

Connection Pool Throughput

10 concurrent workers β€’ 10 connections β€’ 150M queries

Driver Setup Q/s vs QAIL
QAIL Tokio Async Pool πŸ₯‡ 1,250,000 1.00x
libpq C Pthreads + Pipeline πŸ₯ˆ 981,917 0.78x
pgx Go Pool + Batch πŸ₯‰ 652,340 0.52x

βš–οΈ Fair Benchmark Parameters

  • Same Pool Size: 10 connections max for all drivers.
  • Same Workers: 10 concurrent workers competing for pool.
  • Same Batching: 100 queries per batch (QAIL pipeline, Go pgx.Batch, C pthreads+pipeline).
  • Same Query: SELECT id, name FROM harbors LIMIT $1 with prepared statements.
  • Same Hardware: Apple M3 Pro, localhost PostgreSQL 18.

βœ… Honest Disclaimers

  • QAIL is ~60% production ready. We have: speed, SSL/TLS, SCRAM-SHA-256 auth, connection pooling, AST-native migrations, JSON/JSONB, UUID, timestamps. Still missing: Arrays, COPY protocol, full ORM-style mapping.
  • Go pgx uses pgx.Batch for fair comparison (not sequential queries).
  • C libpq uses PQenterPipelineMode + pthreads for fair concurrency.

πŸ“Š Benchmark Methodology (Reproducible)

Test Parameters:
  • 50 million queries total
  • 10,000 queries per batch
  • Prepared statement: SELECT id, name FROM harbors LIMIT $1
  • PostgreSQL 18 pipelining
Fair Comparison:
  • βœ… Same SQL query
  • βœ… Same prepared statements
  • βœ… Same pre-built parameters
  • βœ… Same database & machine
Source Code:

Run the benchmarks yourself: cargo run --release --example fifty_million

This Is Just the Beginning

We built a production-ready PostgreSQL driver that competes with C and beats Go. Now imagine what's next.

🌐
Multi-Database
MySQL, SQLite, Oracle
πŸ”—
FFI Bindings
Go, Python, Node.js
⚑
io_uring
Even faster on Linux
Star on GitHub

Built with πŸ¦€ in Rust