
我使用的是 Microsoft SQL Server, 假设不考虑通配符,数据库Hostname列建了索引,并存了一些域名:
假设现在有这么个域名 www.sub.test.com, 我应该查询数据库获得 test.com 和 sub.test.com
查询Hostname列时,like '%test.com',这样的写法是无法命中索引的,只有%放在末尾才能命中文本列的索引。
所以我存储了另一列 ReversedHostname ,把域名反转存储。SQL 查询时把要查询的域名也反转,然后 Where 语句这么写
WHERE Reverse(要查询的域名) like ReversedHostname + '.%' 但是实践证明这也不能命中索引。
只有这样的查询
Where ReversedHostname like 'moc.tset.%' 才能命中索引。
1 beck123 230 天前 把 www.sub.test.com 拆开,变成 test.com ,sub.test.com ,www.sub.test.com 然后去 IN('test.com','sub.test.com', 'www.sub.test.com') |
2 laminux29 230 天前 直接 es 不香嘛? es 专为高性能搜索而生,它的次时代索引,对这些传统关系型数据库来说,简直是降维打击。 |
3 cogear OP @a1010795186 我去,好思路! |
4 opengps 230 天前 force index |
5 kingcanfish 230 天前 你换个思路,com.test.sub.www 这样存 , 写个函数转换下顺序不就可以了 |
6 meiyiliya 230 天前 |
7 llsquaer 230 天前 有点像梯子软件的域名匹配啊。参考下 clash 的匹配算法不一定要用数据库 |
8 meshell 230 天前 6 楼正确 |
9 cogear OP |
10 AlphaXM 229 天前 最近在研究 bind-dlz,这是 DNS 服务器 Bind9 的一个扩展模块,支持从数据库查询 dns 记录。附上链接 https://bind-dlz.sourceforge.net/mysql_example.html |
11 cheng6563 228 天前 WHERE Reverse(要查询的域名) 你这也没反转过来存啊... |