SQLite: COUNT slow on big tables

前端 未结 8 2104
不知归路
不知归路 2021-02-02 07:43

I\'m having a performance problem in SQLite with a SELECT COUNT(*) on a large tables.

As I didn\'t yet receive a usable answer and I did some further testing, I edited m

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 08:08

    Do not count the stars, count the records! Or in other language, never issue

    SELECT COUNT(*) FROM tablename;

    use

    SELECT COUNT(ROWID) FROM tablename;

    Call EXPLAIN QUERY PLAN for both to see the difference. Make sure you have an index in place containing all columns mentioned in the WHERE clause.

提交回复
热议问题