gpt4 book ai didi

mysql - 在 mysql 中索引非常长的文件路径的最佳方法

转载 作者:太空宇宙 更新时间:2023-11-04 09:47:41 25 4
gpt4 key购买 nike

给定以下文件路径,存储在 mysql 数据库中:

.//.git/refs/remotes/origin/HEAD
.//.git/refs/tags
.//__init__.py
.//__init__.pyc
.//forms.py
.//forms.pyc
.//models.py
.//models.pyc
.//settings.py
.//settings.pyc
.//static
.//static/css
.//static/css/all.css
.//static/images
.//static/images/bg.png
.//static/images/favicon.ico
.//static/images/pds-header-logo.png
.//static/images/pds-logo.png
.//static/images/revolver.png
.//static/js
.//static/js/all.js
.//templates
.//templates/base.html
.//templates/default.html
.//templates/overview.html
.//urls.py
.//urls.pyc
.//views.py
.//views.pyc
.//wsgi.py
.//wsgi.pyc

有人需要能够搜索路径。例如,如果用户搜索“static”,它将返回路径中带有“static”的结果:

.//static
.//static/css
.//static/css/all.css
.//static/images
.//static/images/bg.png
.//static/images/favicon.ico
.//static/images/pds-header-logo.png
.//static/images/pds-logo.png
.//static/images/revolver.png
.//static/js
.//static/js/all.js

我目前的搜索是这样的:

`SELECT path FROM files WHERE path LIKE '%search%';`

有没有办法索引此列/改进此搜索(删除 LIKE %%),因为我可能在此系统上有超过 1M 的文件路径。请注意,文件路径可能超过 200 个字符。

最佳答案

你不能。通配符搜索不会使用索引。
如果你索引文件路径,你只能最好地支持像

这样的查询
/static/images/%

给定你的场景,如果你想允许通配符搜索,
最好的办法是将目录分解为多个关键字:

static
images
revolver
.png

然后将每个关键字存储到关键字表中,
并建立关系。

当你执行通配符搜索时,实际上是搜索关键字表。

关于mysql - 在 mysql 中索引非常长的文件路径的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14507369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com