0
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,它的工作速度也很慢。应该怎么做才能使搜索快速工作?

4

3 回答 3

1

不是 SQLLite 专家,但这些是我从其他数据库的经验中看到的类型。不过你可能需要体验一下。

首先检查您的索引。接下来你真的需要一个通配符作为第一个字符吗?在大多数数据库实现中,这通常会使查询变慢,因为它不允许您在该特定字段上使用索引。我还可以指出,在许多数据库中,UNION 或 UNION ALL 查询比在 WHERE 子句中使用 OR 快得多。

于 2013-08-14T18:00:10.953 回答
0

减少 where 子句的连接和/或条件的数量。您可以将所有数据放入内存并使用 java 将所需的结果集缩减为您想要的。

于 2013-08-14T17:23:32.010 回答
-2

我认为诸如复杂的处理必须在服务器端完成。

于 2013-08-14T17:43:12.497 回答