Reputation: 105
We have a PosgtreSQL DB table with lots of data. I wonder what type of query is faster / has a better performance and why?
select * from table
select count (*) from table
Upvotes: 1
Views: 1416
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