开发者

iphone sqlite query optimization

I am currently using this sqlite query in my application. Two tables are used in this query.....

UPDATE table1 set visited = (SELECT COUNT(DISTINCT table1.itemId) from 'table2' WHERE table2.itemId = table1.itemId AND table2.sessionId ='eyoge2avao');

It is working correct.... My problem is it is taking around 10 seconds to execute this query and retrieve the result..... Don't know what to do... Almost all other process are in right way.. So it seems the problem is with 开发者_开发知识库this query formation...

Plz someone help with how to optimize this query....

Regards, Brian


Make sure you have indexes on the following (combinations of) fields:

  • table1.itemId (This will speed up the DISTINCT clause, since the itemId will already be in the correct order).

  • table2.itemId, table2.sessionId This will speed up the WHERE clause of your SELECT statement.

How many rows are there in these tables?


Aso try doing an EXPLAIN on your SELECT command to see if it gives you any helpful advice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜