How to create index for text data type column in mysql efficiently,for a table having more than 10 L rows (each row has 500 chars).
1 Answer
If you are using innodb, you should create a FULLTEXT index.
FULLTEXTindexes are created on text-based columns (CHAR,VARCHAR, orTEXTcolumns) to help speed up queries and DML operations on data contained within those columns, omitting any words that are defined as stopwords.
Please see the MySQL FULLTEXT documentation.
mysql> CREATE TABLE opening_lines (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
opening_line TEXT(500),
author VARCHAR(200),
title VARCHAR(200),
FULLTEXT idx (opening_line)
) ENGINE=InnoDB;
3 Comments
Arunkumar Muthuvel
I'm using mysql 5.5 and engine is innodb. mysql can't provide FULLTEXT idx option in 5.5, what should i do?
Jim Wright
It does exist in 5.5, see docs.
Arunkumar Muthuvel
Full-text indexes can be used only with MyISAM tables. (In MySQL 5.6 and up, they can also be used with InnoDB tables.) Full-text indexes can be created only for CHAR, VARCHAR, or TEXT columns.