---
title: "What would Postgres do?"
description: "Neki, PlanetScale's sharded Postgres, is tested differentially against vanilla Postgres as an oracle."
url: "https://swe.quest/articles/what-would-postgres-do-3a4a6dfd0e326e8f"
canonical: "https://planetscale.com/blog/what-would-postgres-do"
source: "PlanetScale"
published: "2026-12-02"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 12
tags: ["postgres","testing","query-engines","distributed-databases"]
---

# What would Postgres do?

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-12-02, 12 min read, Deep dive. Original: [https://planetscale.com/blog/what-would-postgres-do](https://planetscale.com/blog/what-would-postgres-do)

## Summary

Neki, PlanetScale's sharded Postgres, is tested differentially against vanilla Postgres as an oracle. Because its query planner behaves as a pure function of statistics, query and shard topology, the team sweeps fake statistics with bisection to enumerate plan variants and checks that every variant from both the deep and fast planners returns identical results. The same queries are also run under deliberately bad sharding topologies and across simple and extended protocol modes with text, binary and mixed result formats. Around 37,000 plan variants run in CI, and the approach caught a nested-loop plan that re-evaluated a volatile CTE, alongside more than 70 bugs found by query fuzzing.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)

## Prerequisites

- SQL query planning ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- database sharding ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- Postgres wire protocol ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

Neki, PlanetScale, PostgreSQL, differential testing, Picasso diagram, TPC-H, fuzzing

## Related posts

- [Building a faster, lazier router for Postgres](https://swe.quest/articles/building-a-faster-lazier-router-for-postgres-bc9a70ce219128ed.md): PlanetScale · 2026-10-01 · Hard · 15 min read · PostgreSQL, Distributed databases, Performance engineering, Go, Query engines
  Neki, PlanetScale's Postgres sharding router, cuts per-query overhead by keeping PostgreSQL wire-protocol bytes intact and decoding only as much as each query requires.
- [You should shard your database](https://swe.quest/articles/you-should-shard-your-database-12cdc70ed1f6d2d7.md): PgDog · 2025-11-13 · Medium · 7 min read · PostgreSQL, Distributed databases, Scaling, Query engines
  Sharding Postgres early avoids the operational pain of large single instances, illustrated by an outage where stale planner statistics caused a 300 GB table to be sequentially scanned.
- [Sequences and other volatiles in Neki](https://swe.quest/articles/sequences-and-other-volatiles-in-neki-867c9857ecacbacb.md): PlanetScale · 2026-10-14 · Hard · 14 min read · Query engines, PostgreSQL, Distributed databases, SQL
  Neki, PlanetScale's sharded Postgres, implements Postgres sequences by classifying sequence operations like nextval() as router-only, with an authoritative shard hosting all sequences so values are never duplicated across shards.
- [How Figma’s databases team lived to tell the scale](https://swe.quest/articles/how-figma-s-databases-team-lived-to-tell-the-scale-5117114294b188fe.md): Figma · 2024-03-14 · Medium · 19 min read · PostgreSQL, Distributed databases, Scaling, Query engines
  Figma horizontally sharded its RDS Postgres stack after vertical partitioning ran out of room.
- [PostgreSQL Stories: From slow query to fast—via stats](https://swe.quest/articles/postgresql-stories-from-slow-query-to-fast-via-stats-ac7001ab0fde8224.md): Render · 2024-05-14 · Medium · 13 min read · PostgreSQL, Query engines, Performance engineering, Debugging
  A simple LIMIT 1 join between a ~100k-row postgres\_dbs table and a ~90M-row events table ran for hours.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
