Better count performance with SELECT COUNT(*) than with SELECT COUNT(id) #11879
Unanswered
Huluti
asked this question in
Support Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
Small question about counts performance with doctrine and postgresql.
Doctrine doesn't permit to do:
->select('COUNT(*)')
=> [Syntax Error] line 0, col 13: Error: Expected Literal, got '*'Only
->select('COUNT(l)')
or->select('COUNT(l.id)')
So the final query is
SELECT COUNT(l.id)
...But I have an example where "*" seems to be much better than "l.id":
explain analyze SELECT COUNT(l.id) FROM link l WHERE l.team_id = 10190 AND l.folder_id = 298
=>
explain analyze SELECT COUNT(*) FROM link l WHERE l.team_id = 10190 AND l.folder_id = 298
=>
Do you know if it's normal? Does there is a way to use * with doctrine ?
ChatGPT (i know not 100% sure) says this:
pgexplain links:
Query 1 => https://www.pgexplain.dev/plan/44bf4e9a-5813-46ba-a39a-333d61e5c400
Query 2 = https://www.pgexplain.dev/plan/cab820cc-686c-4a3c-ac46-65fd620d6efb
Thanks in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions