is SELECT COUNT(*) expensive?

后端 未结 7 1794
小蘑菇
小蘑菇 2021-01-13 00:16

Do you think it\'s a good idea to count entries from a really big table (like 50K rows) on each page load?

SELECT COUNT(*) FROM table

Right

7条回答
  •  青春惊慌失措
    2021-01-13 01:00

    count(*) is O(n) so it's performance is related to the number of records in the table, 50k is not a lot at all, so i think it is fine on an admin page. When you get into the millions count(*) certainly does become expensive.

提交回复
热议问题