sqlite查询优化

发布于 2024-07-27 14:27:25 字数 336 浏览 4 评论 0原文

查询

SELECT * FROM Table WHERE Path LIKE 'geo-Africa-Egypt-%'

可以优化为:

SELECT * FROM Table WHERE Path >= 'geo-Africa-Egypt-' AND Path < 'geo-Africa-Egypt-zzz' 

但是如何做到这一点:

select * from foodDb where Food LIKE '%apples%";

如何优化?

The query

SELECT * FROM Table WHERE Path LIKE 'geo-Africa-Egypt-%'

can be optimized as:

SELECT * FROM Table WHERE Path >= 'geo-Africa-Egypt-' AND Path < 'geo-Africa-Egypt-zzz' 

But how can be this done:

select * from foodDb where Food LIKE '%apples%";

how this can be optimized?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离鸿 2024-08-03 14:27:25

一种选择是冗余数据。 如果您要大量查询某个列中间出现的某些固定字符串集,请添加另一列,其中包含是否可以在另一列中找到特定字符串的信息。

对于任意但仍可标记的字符串,另一种选择是创建一个字典表,其中包含标记(例如 apples)以及对标记出现的实际表的外键引用。

一般来说,sqlite 在设计上不太擅长全文搜索。

One option is redundant data. If you're querying a lot for some fixed set of strings occuring in the middle of some column, add another column that contains the information whether a particular string can be found in the other column.

Another option, for arbitrary but still tokenizable strings is to create a dictionary table where you have the tokens (e.g. apples) and foreign key references to the actual table where the token occurs.

In general, sqlite is by design not very good at full text searches.

↘人皮目录ツ 2024-08-03 14:27:25

如果它更快的话我会感到惊讶,但你可以尝试 GLOB 而不是 LIKE 并进行比较;

SELECT * FROM foodDb WHERE Food GLOB '*apples*'; 

It would surprise me if it was faster, but you could try GLOB instead of LIKE and compare;

SELECT * FROM foodDb WHERE Food GLOB '*apples*'; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文