简体   繁体   English

MySQL快速搜索varchar列中的匹配项

[英]MySQL fast search for match in varchar column

I am relatively new to sql, so it's possible I'm doing something stupid. 我对sql比较新,所以我可能会做一些愚蠢的事情。

Anyway, I have a Dictionary table with a VARCHAR(255) word column. 无论如何,我有一个带有VARCHAR(255)字列的Dictionary表。 I have loaded a dictionary text file into this table. 我已将字典文本文件加载到此表中。 What is the most effective way to check if some VARCHAR(255) is in the dictionary? 检查某些VARCHAR(255)是否在字典中的最有效方法是什么? Currently I am doing this: 目前我这样做:

CREATE TABLE Dictionary
(
word CHAR(255) NOT NULL UNIQUE
);

LOAD DATA LOCAL INFILE 'E:/dictionary.txt'
INTO TABLE Dictionary
LINES TERMINATED BY '\n'
(word);

In a procedure, I'm doing 在一个程序中,我正在做

DECLARE currentWord VARCHAR(255);
...
IF EXISTS(SELECT word FROM Dictionary WHERE word=currentWord) THEN
...

This is taking quite a while. 这需要一段时间。 What should I do differently to speed this up? 我应该采取哪些不同的措施加快速度呢?

Add a key on the word field as Satya mentioned. 如Satya所述,在单词字段上添加一个键。 Here's the syntax: 这是语法:

ALTER TABLE Dictionary ADD KEY `word` (`word`);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM