首页 > 解决方案 > CoreData:相同查询的不同执行时间

问题描述

我正在使用 CoreData 在具有 35 个属性(所有字符串)的表中存储大约 250.000 行数据,此时它们都没有被索引。当我在没有其他应用程序运行的情况下启动应用程序并执行以下查询时,多次启动的获取执行时间不同。

1)CoreData: sql: SELECT t0.ZBP_Q, COUNT( t0.ZNOF_LAY) FROM ZVEH t0 GROUP BY t0.ZBP_Q CoreData: annotation: sql connection fetch time: 0.4265s CoreData: annotation: total fetch execution time: 0.4266s for 15 rows.

2)CoreData: sql: SELECT t0.ZBP_Q, COUNT( t0.ZNOF_LAY) FROM ZVEH t0 GROUP BY t0.ZBP_Q CoreData: annotation: sql connection fetch time: 9.9614s CoreData: annotation: total fetch execution time: 9.9615s for 15 rows.

首先,0.4266s 对于 15 行来说似乎很长,不是吗?但是,为什么应用程序在完全相同的条件下执行完全相同的查询需要大约 10 秒才能再次启动?以及如何确保每次启动的 0.4266 秒? 似乎应用程序随机需要很长时间或非常快(我对 0.4266 秒很好)。

标签: swiftcore-datasqlite

解决方案


推荐阅读