π 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)
1M queries Γ 1 await each = 1M round-trips
QAIL Pipelining
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", ¶ms1),
("SELECT * FROM orders WHERE user_id = $1", ¶ms2),
// ... 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
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 $1with 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)
- 50 million queries total
- 10,000 queries per batch
- Prepared statement:
SELECT id, name FROM harbors LIMIT $1 - PostgreSQL 18 pipelining
- β Same SQL query
- β Same prepared statements
- β Same pre-built parameters
- β Same database & machine
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.
Built with π¦ in Rust