5 ms·
Won't SELECT count(*) be super slow? Isn't SELECT Count(some_primary_key) a better idea?
by billyhoffman 12y ago
Won't SELECT count(*) be super slow? Isn't SELECT Count(some_primary_key) a better idea?
- icebraining 12y agoIt should be the same. count(*) only needs to return the number of columns (regardless of its value), so it can use only indexes, while count(column) must only count non-null values. But since the primary is non-null, it should end up taking the same time.
- billyhoffman 12y agoWow, just tested this against a table with some pretty wide columns and ~ 7M rows. They take exactly the same time! I would have thought COUNT() would be like SELECT , but I guess the query planner is smart enough to know what to do. Thanks!
- deleted 12y ago[deleted]