# Faster PostgreSQL Counting

DevFeed: [Faster PostgreSQL Counting](<https://devfeed.tech/articles/faster-postgresql-counting-21473.md>)

Original publisher: [Read original article](<https://begriffs.com/posts/2016-10-12-count-performance.html>)

Published: 2016-10-12T00:00:00Z

Content type: article

Language: en

Sources: [Joe Nelson](<https://devfeed.tech/sources/joe-nelson.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Database](<https://devfeed.tech/topics/database.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [Statistics](<https://devfeed.tech/topics/statistics.md>), [Caching](<https://devfeed.tech/topics/caching.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [benchmark](<https://devfeed.tech/tags/benchmark.md>), [blog](<https://devfeed.tech/tags/blog.md>), [compare](<https://devfeed.tech/tags/compare.md>), [distributed](<https://devfeed.tech/tags/distributed.md>), [extension](<https://devfeed.tech/tags/extension.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [speed](<https://devfeed.tech/tags/speed.md>), [statistics](<https://devfeed.tech/tags/statistics.md>), [techniques](<https://devfeed.tech/tags/techniques.md>)

## AI overview

This article examines how PostgreSQL optimizes row counting. It compares exact and estimated counts, duplicate and distinct counts, whole-table and filtered counts, and the speed and resource costs of different techniques. It also introduces parallel counting with the Citus PostgreSQL extension in a distributed database.

## Source excerpt

2016-10-12 (Cross-posted on the Citus Data blog.) Everybody counts, but not always quickly. This article is a close look into how PostgreSQL optimizes counting. If you know the tricks there are ways to count rows orders of magnitude faster than you do already. The problem is actually underdescribed - there are several variations of counting, each with its own methods. First think whether you need an exact count or whether an estimate suffices.