iPhone SQLite查询优化
我目前正在我的应用程序中使用这个 sqlite 查询。此查询中使用了两个表......
UPDATE table1 set visited = (SELECT COUNT(DISTINCT table1.itemId) from 'table2' WHERE table2.itemId = table1.itemId AND table2.sessionId ='eyoge2avao');
它工作正常......我的问题是执行此查询并检索结果大约需要 10 秒......不知道该怎么办。 ..几乎所有其他过程都以正确的方式进行..所以看来问题出在这个查询的形成上...
请有人帮助如何优化这个查询....
问候, 布莱恩
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您在以下字段(组合)上有索引:
table1.itemId
(这将加快 DISTINCT 子句的速度,因为 itemId 已经处于正确的顺序)。
table2.itemId
,table2.sessionId
这将加快 SELECT 语句的 WHERE 子句的速度。
这些表中有多少行?
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 尝试对您的 SELECT 命令执行 EXPLAIN ,看看它是否为您提供任何有用的建议。
Aso try doing an EXPLAIN on your SELECT command to see if it gives you any helpful advice.