搜索查询的最佳方式是什么?

时间:2013-08-16 12:06:36

标签: android sqlite indexing query-optimization inner-join

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

enter image description here

我正在拿桌子:入口,r_ele,k_ele,感觉,加入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 ";

1 个答案:

答案 0 :(得分:0)

如果你有一个大型数据库并且动态地进行了很多连接,那么性能肯定会很慢。我有一个类似的问题。我解决它的方法是通过在应用程序初始化时连接相应的表来创建包含所需列的临时表。

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

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