8 ms·
if i had to guess COUNT(*) may load everything per row datawise vs using a index. but I'd have to run tests to confirm =)
by jatone 5y ago
if i had to guess COUNT(*) may load everything per row datawise vs using a index. but I'd have to run tests to confirm =)
- cube2222 5y agoI do think the parent thinks that. But it's simply not true based on my research. COUNT(*) doesn't need any actual data from the rows, so I'm wondering if there's something else. First result in Google confirms that at least for Postgres: https://www.citusdata.com/blog/2016/10/12/count-performance/ https://www.citusdata.com/blog/2016/10/12/count-performance/ Another one from stackoverflow: https://stackoverflow.com/questions/2710621/count-vs-count1-vs-countpk-which-is-better https://stackoverflow.com/questions/2710621/count-vs-count1-... with a citation: > Don't be fooled by those advising that when using * in COUNT, it fetches entire row from your table, saying that * is slow. The * on SELECT COUNT(*) and SELECT * has no bearing to each other, they are entirely different thing, they just share a common token, i.e. *.
- jatone 5y agoyeah I didn't really believe it, just didn't feel like doing the effort of researching it because in reality its never come up in practice for me. which hinted at it not being a real problem anymore.