0

我有很大的 SQLite 数据库(45MB)。我使用 INNER JOIN 从不同的表中获取数据。但是,它的工作非常缓慢。也许这取决于我正在测试的手机(三星 Galaxy Ace)。应该怎么做才能使查询非常快?a)为表创建索引 b)创建新表,其中将包括我需要的表 c)您推荐的其他方式

在此处输入图像描述

我正在使用表格:entry、r_ele、k_ele、sense、gloss with JOIN。

query = "SELECT" + " e.id AS _id," + " ke.id AS ke_id,"
                + " ke.fk as ke_fk," + " ke.value as ke_value,"
                + " re.id AS ke_id," + " re.fk as re_fk,"
                + " re.value as re_value," + " s.id AS  s_id,"
                + " s.fk as s_fk," + " g.id AS g_id," + " g.fk as g_fk,"
                + " g.lang," + " g.value as g_value" + " FROM entry e"
                + "     INNER JOIN k_ele ke ON e.id = ke.fk"
                + "     INNER JOIN r_ele re ON e.id = re.fk"
                + "     INNER JOIN sense s ON e.id = s.fk"
                + "     INNER JOIN gloss g ON s.id = g.fk"
                + " WHERE g.lang IS NULL AND g.value like '"
                + lookingFor + "%'  GROUP BY g.value LIMIT 5 ";
4

1 回答 1

0

如果您有一个大数据库并且在运行中执行了这么多连接,那么性能肯定会很慢。我有一个类似的问题。我解决它的方法是通过在应用程序初始化时加入相应的表来创建具有所需列的临时表。

如果您的数据是动态的,您还需要在需要时更新临时表中的数据。但是如果更改数据的大小不是很大,更新不会真正产生任何性能问题。

创建临时表的好处是较长的操作只存在一次,并且在启动时。

于 2013-08-16T15:29:06.870 回答