hn.today

Programming at Light Speed: Building the Gravity Query Engine

pgrust.com19 points10 comments
Screenshot of Programming at Light Speed: Building the Gravity Query Engine

Gravity is the JIT query engine introduced in pgrust v0.4-beta, built to turn analytical SQL into machine code close to the hardware’s practical speed limit. Rather than incrementally tuning an existing executor, its developers first established a ceiling: hand-optimized, multithreaded Rust programs running directly over pgrust’s columnar storage. Those programs ran about four times faster than existing analytical databases, becoming a performance target for the engine. Gravity’s runtime compiler aims to come within 20% of that baseline while retaining Postgres’s SQL dialect and type system.

Compilation proceeds from a standard Postgres plan through a pipeline graph and a Lisp-like intermediate representation to target assembly. Pipelines fuse scans, filters, projections, and aggregation, while the IR lets the compiler apply query-specific optimizations such as inlining, late materialization, and register allocation. The engine compiles queries in under a millisecond and, across analytical workloads, runs within 10-20% of the hand-written Rust baseline. On ClickBench it reaches up to three times ClickHouse’s speed; against pgrust’s Volcano row executor on the same data, it is 102 times faster cold and 499 times faster hot. Because optimizations can fail on less obvious query forms or types, the team catalogued them and built a fuzzer to check that they apply across varied query shapes and Postgres types.

Read on pgrust.com10 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Shaun Thomas: Burnt Toast

Shaun Thomas: Burnt Toast

PostgreSQL’s TOAST storage made the table much smaller, and counting or scanning rows was faster than with the larger uncompressed table. But reading a field inside every toasted value required far more buffer reads, showing that TOAST can trade space savings for slower access to large values. (pgedge.com)

Jepsen: ParticleDB 1.1.4

Jepsen: ParticleDB 1.1.4

Jepsen found 96 bugs in ParticleDB versions 1.1.4 through 1.1.18.11.rc-22, including crashes, data loss, and serious transaction anomalies. Most issues were fixed, but committed writes could still disappear and serializable transactions still had anomalies; Orkes says a later release resolves the remaining problems. (jepsen.io)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.