0

For example I need to get a count of some particular data that is stored in table 1 and make joins to check some connections with table 2, and all I need is to count(*)

does using COUNT(id) is faster than COUNT(*), as far as I know MYISAM tables already have cached the count on the inner engine, but when I do operations like WHERE, JOIN, that cache doesn't work anymore right? or should I create a procedure or function in order to make it faster? will it be faster?

Skrudox
  • 839
  • 4
  • 9
  • 14
  • Count(id) is not the same as count(*) - unless you have an id for every row. count(id) will count every non null id in the result set count(*) will count every row in the result set. – P.Salmon Jun 29 '18 at 07:24

1 Answers1

0

Count(1) will be better choice it will be faster than count(*)

Gaj
  • 888
  • 5
  • 5
  • Do you have a reference that backs up this assertion? – P.Salmon Jun 29 '18 at 09:40
  • It’s basic common rule. If you use * then dB has to check all the available columns and then count but if you use number constant then dB won’t check table structure, index etc so it will be faster – Gaj Jun 29 '18 at 09:45
  • Hmm. Heres a reference which refutes that http://pretius.com/oracle-count-or-count1-that-is-the-question/ and here's another https://stackoverflow.com/questions/1221559/count-vs-count1-sql-server – P.Salmon Jun 29 '18 at 09:45