Posted 15 days ago. Visible to the public. Repeats. Linked content.

Heads up: counting may be slow in PostgreSQL

The linked article points out that COUNT queries might be unexpectetly slow in psql.
If you just need to know "are there any records" use any? or present? instead. The latter uses SELECT 1 AS one FROM ... LIMIT 1 under the hood.

In short: Replace foo.count > 0 with foo.any?

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Michael Leimstädtner
Last edit:
7 days ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Michael Leimstädtner to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more