Android SQLite Select query speed Android SQLite Select query speed sqlite sqlite

Android SQLite Select query speed


Try not using nested SELECT statments, instead see if you can use JOIN.

Example:

SELECT * FROM Songs AS s1 JOIN Songs AS s2 ON s1.KEY_ID = s2.KEY_ID WHERE length (s2.KEY_SONGPATH) >= " + strLength + ") AND s1.KEY_SONGPATH LIKE '" + currentDir + "%'


Don't use a subquery; it doesn't make anything faster because it still has to do the same checks.

Dont use LENGTH(column) >= value because it isn't faster than the LIKE check, and cannot be indexed.

To speed up the LIKE, put an index on the KEY_ID column.Because LIKE is case-insensitive by default, you have to use COLLATE NOCASE when creating the index(see the CREATE INDEX documentation).