我的db在mysql v5.x上运行.我有一个表格T1有5列,C1列是主键.C1的类型为varchar(20).它包含大约2000行,其值如下:
fxg
axt3
tru56
and so on..
Run Code Online (Sandbox Code Playgroud)
现在我的应用程序的工作是读取输入数据并查找输入数据是否具有类似于表T1中列C1中的起始模式.例如:我的输入可能显示为:
trx879478986
fxg87698x84
784xtr783utr
axt3487ghty
... and so on
Run Code Online (Sandbox Code Playgroud)
所以对于上面的输入,我必须为'fxg87698x84'和'axt3487ghty'返回true,对其他输入则返回false.我使用的查询是:
select 1 from T1 where (? like concat(C1,'%'));
note: the ? is replaced by the input value got from the application.
Run Code Online (Sandbox Code Playgroud)
问题是我的输入很大(在30分钟内处理大约100万条记录),我的查询速度不够快.有关如何重写查询或强制使用索引的任何想法?即使我必须使用不同的对象结构,我也能做到,如果这有帮助的话.所以任何帮助将不胜感激.谢谢.