Skip to content
Tech News
← Back to articles

Postgres SELECT DISTINCT scans full result set despite indexing, DBOS finds

read original more articles
GoKawiil Brief

DBOS engineers debugging a Postgres-backed queue system found that SELECT DISTINCT was their most expensive query, even though it appeared simplest. They discovered that Postgres always scans every row matching a query's predicates when computing DISTINCT values, regardless of indexing or how few unique values exist, making it a poor fit for finding active partitions in a queue workload.

Why It Matters

GoKawiil's interpretation of the reporting above, not reported fact.

This suggests a broader gap between how developers intuitively expect indexed queries to behave and how Postgres actually executes them, which could lead teams to unknowingly build slow, expensive operations into performance-critical paths like queue processing. The finding implies that engineers relying on SELECT DISTINCT for uniqueness lookups at scale may need alternative query patterns or workarounds to avoid unnecessary full scans.

Key Takeaways

Source: dbos.dev, 2026-09-24

Published there as: “Postgres SELECT DISTINCT Does Not Scale”

Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.