Sorry for the quick follow-up, but I’ve just run a quick test that does an EXPLAIN QUERY PLAN for every statement that gets compiled, in an empty database, and confirmed that the query plan comes out wrong right from the start:
SELECT revs.doc_id, sequence, docid, revid, json, deleted FROM revs, docs WHERE sequence>? AND current!=0 AND deleted=0 AND revs.doc_id = docs.doc_id ORDER BY revs.doc_id, deleted, revid DESC 0 0 0 SCAN TABLE revs USING INDEX revs_by_docid_revid 0 1 1 SEARCH TABLE docs USING INTEGER PRIMARY KEY (rowid=?) Another query gets it wrong too: SELECT sequence, revs.doc_id, docid, revid, deleted FROM revs, docs WHERE sequence > ? AND current=1 AND revs.doc_id = docs.doc_id ORDER BY revs.doc_id, deleted, revid DESC 0 0 0 SCAN TABLE revs USING COVERING INDEX revs_current 0 1 1 SEARCH TABLE docs USING INTEGER PRIMARY KEY (rowid=?) 0 0 0 USE TEMP B-TREE FOR RIGHT PART OF ORDER BY This is with SQLite 3.16.0. —Jens _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users