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 re.value like '" + hiragana
+ "%' OR g.value like '" + lookingFor
+ "%' OR g.value like '%" + strSpace + lookingFor
+ "%' GROUP BY s.id LIMIT 5 ";
此查询从SQLite数据库获取数据,并将获取的数据放入listview。即使我已经使用LIMIT 5,它的工作速度也很慢。为了使搜索工作更快,应该做些什么?
答案 0 :(得分:1)
不是SQLLite专家,但这些是我从其他数据库的经验中看到的类型。你可能需要体验一下。
首先检查您的索引。接下来你真的需要一个通配符作为第一个字符吗?这通常会使大多数数据库实现中的查询变慢,因为它不允许您在该特定字段上使用索引。我还可以指出,在许多数据库中,UNION或UNION ALL查询比在WHERE clasue中使用OR要快得多。
答案 1 :(得分:0)
减少where子句的连接数和/或条件。您可以将所有数据放入内存并使用java将所需的结果集减少到您想要的结果集。
答案 2 :(得分:-2)
我认为复杂的处理必须在服务器端完成。