如何为超字符串查询优化数据库? [英] How do I optimize a database for superstring queries?

查看:87
本文介绍了如何为超字符串查询优化数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在MySQL中有一个数据库表,该表具有包含字符串的列.给定目标字符串,我想查找目标中包含子字符串的所有行,即目标字符串为其列的超字符串的所有行.目前,我正在使用以下查询:

So I have a database table in MySQL that has a column containing a string. Given a target string, I want to find all the rows that have a substring contained in the target, ie all the rows for which the target string is a superstring for the column. At the moment I'm using a query along the lines of:

SELECT * FROM table WHERE 'my superstring' LIKE CONCAT('%', column, '%')

我担心这不会扩展.我目前正在做一些测试,看这是否有问题,但我想知道是否有人对替代方法有任何建议.我已经对MySQL的全文本索引进行了简要介绍,但它似乎也适合于在数据中查找子字符串,而不是查找给定字符串中是否存在数据.

My worry is that this won't scale. I'm currently doing some tests to see if this is a problem but I'm wondering if anyone has any suggestions for an alternative approach. I've had a brief look at MySQL's full-text indexing but that also appears to be geared toward finding a substring in the data, rather than finding out if the data exists in a given string.

推荐答案

看来答案是你没有.这种类型的索引通常不可用,如果要在MySQL数据库中使用它,则需要创建自己的MySQL扩展.我追求的替代方法是在我的应用程序中进行索引.

Well it appears the answer is that you don't. This type of indexing is generally not available and if you want it within your MySQL database you'll need to create your own extensions to MySQL. The alternative I'm pursuing is to do the indexing in my application.

感谢大家的回应!

这篇关于如何为超字符串查询优化数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆