Mysql count performance on very big tables

前端 未结 6 671
说谎
说谎 2020-11-30 00:29

I have a table with more than 100 millions rows in Innodb.

I have to know if there is more than 5000 rows where the foreign key = 1. I don\'t need the exact number.<

6条回答
  •  遥遥无期
    2020-11-30 01:15

    You don't seem interested in the actual count so give this a try:

    SELECT 1 FROM table WHERE fk = 1 LIMIT 5000, 1
    

    If a row is returned, you have 5000 and more records. I presume the fk column is indexed.

提交回复
热议问题