Ula
Ula

Reputation: 105

Count vs select query performance in PostgreSQL

We have a PosgtreSQL DB table with lots of data. I wonder what type of query is faster / has a better performance and why?

  1. select * from table
  2. select count (*) from table

Upvotes: 1

Views: 1416

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522817

While both queries do iterate over the entire table, the first query will perform generally much worse at an application level versus the second one. This is because the select * query will need to send the entire table across the network to the application which is executing the query. The count(*) query, on the other hand, only needs to send across a single integer count.

Upvotes: 3

Related Questions