I have a long query like this:
SELECT field1, field2, ... FROM tambe WHERE (rowid NOT IN (some 60000 rowids));
The query can be potentially executed multiple times, so I save its results in a temporary table.
CREATE TEMPORARY TABLE IF NOT EXISTS cach开发者_开发百科e AS SELECT field1, field2, ... FROM tambe WHERE (rowid NOT IN (some 60000 rowids));
This way I don't have to select the actual data every time, but it is still quite a bit slower than it could be. I suspect it is the time it takes to parse the query that is slowing it down.
Is there a way to encapsulate the long query in a kind of IF (CASE) statement so that the SQLite parser would completely ignore it?
IF cache NOT EXISTS (...) END IF;
Thanks.
Selecting by rowid doesn't appear to use an index. Using an expression like id NOT IN (some 60000 ids)
almost certainly won't use an index.
I think your best bet is probably going to be doing a select on a candidate key that's indexed. You might get acceptable performance by doing nothing more than that.
精彩评论