我有 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)?如果我创建索引,它是否会在每次搜索时创建索引?
请提出您的意见或建议。谢谢你。