Mysql count performance on very big tables

前端 未结 6 673
说谎
说谎 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:23

    Finally the fastest was to query the first X rows using C# and counting the rows number.

    My application is treating the data in batches. The amount of time between two batches are depending the number of rows who need to be treated

    SELECT pk FROM table WHERE fk = 1 LIMIT X
    

    I got the result in 0.9 seconds.

    Thanks all for your ideas!

提交回复
热议问题