Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
Post image 6
Post image 7
Post image 8
Post image 9
1 / 9
0

Postgres SELECT DISTINCT Does Not Scale

Hacker News·about 16 hours ago
#me6pRzQt
Reading 0:00
15s threshold

Recently, there has been no shortage of popular blog posts about how Postgres scales or why you should use it for everything . In this post, we'll do something a little different: describe an issue we had with a Postgres feature that intuitively should scale, but actually doesn't. SELECT DISTINCT is an innocuous-seeming clause that finds all unique values of a column. However, its performance characteristics aren't what you'd expect: no matter how you index your table, no matter how few unique values there are to retrieve, SELECT DISTINCT will always scan every row that matches its predicates. We recently observed this when diagnosing the performance of a Postgres-backed queues workload, where SELECT DISTINCT turned out to be the most expensive query despite appearing to be the simplest and cheapest. In this blog post, we’ll explain what happened, what design decisions in Postgres make SELECT DISTINCT slow, and how to work around it.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More