'SQLite Cursor freezes for about 10 seconds at first call

I have 10 mb database and this code:

cursor = mDatabase.query(CitySQLiteHelper.TABLE_CITIES, ALL_COLUMNS, null, null, null, null, "name DESC", "20");
if (cursor.getCount() > 0) {
//
}

Execution freezes for about 10 seconds at the if statement. I tried getCount and moveToFirst - it freezes in both cases. Query and all the calls to the cursor (getString() etc) after the first call work fine. Why?

Update: Schema

sqlite> .schema cities
CREATE TABLE cities (region text, name text, latitude float, longitude float);
sqlite> select count(*) from cities;
130070


Solution 1:[1]

As suggested in a comment, I created unique index and this helped.

Solution 2:[2]

You are simply trying to read many megabytes of data when you first read from the DB. Subsequent database access will benefit from caching. If your database is stored on the SD card, try moving it to internal storage. Otherwise, try doing an initial read from the database on app startup (in a background thread) to "prime" it for later speedy access.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 General Grievance
Solution 2 Graham Borland