0

我有 SQLite 数据库表。搜索时非常慢。找到合适的词需要 20-30 秒。原因是我在查询中使用(我必须)加入和 2-3 个 WHERE 子句。

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";

这是表之间的关系: 在此处输入图像描述

我已阅读有关索引(主要,唯一)的信息。我知道索引时排序值。我的问题是如何创建(我不是在谈论为 id 创建 PRIMARY UNIQUE INDEX,我是在谈论将进行搜索的不是 id 列)并使用该索引来加速搜索查询?以编程方式或在应用程序中(SQLite Expert Professional)?如果我创建索引,它是否会在每次搜索时创建索引?

请提出您的意见或建议。谢谢你。

4

1 回答 1

0

LIKE 在任何情况下都非常慢并且不使用索引(如果我错了,请纠正我)。如果您的目标是进行全文搜索,请查看 SQLite 的 FTS3 功能。那里有很多样本。例如:FTS3 博客

于 2013-08-18T16:54:51.647 回答