Login or Sign up

SQLite Optimizing Query

Posted by: tigerz on Aug. 3, 2009

今天研究了一下 SQLite 查询优化的问题,搜索到了这篇文章: http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html

在最近的一个项目LycheeMap中的一个查询语句中加了“LIMIT 1”, 查询的速度马上有明显的提高. 看来 LIMIT n 意味着找到 n 个符合条件的记录就停止查询, 速度自然比没加要好很多.

5.4. Use LIMIT and OFFSET

Sometimes you only need to check to see if there is at least one record that matches some criterion. SQLite doesn't implement the EXISTS keyword, but you can obtain the same result with LIMIT 1.

还有: 5.3. Order subqueries so smaller results are returned first If a query filters by multiple criteria, move the test to the front (left) which has the fewest results. A test which uses an index generally shouldn't be moved behind (to the right of) one which does. 跟我猜想一致.

Comments on This Post:

Please Login (or Sign Up) to leave a comment