简体   繁体   中英

How to Improve a MySQL Query on a 1 Million Record Table

I have a 1 million record MySQL table with 7 columns. I have a primary key and a fulltext index column. The table stands for a dictionary (size on disk ~300 MB).

The columns are:

    'id', 'int(11)', 'NO', 'PRI', NULL, 'auto_increment'
    'writtenForm', 'varchar(255)' - Fulltext index
    'languageIdentifier', 'varchar(255)'
    'partOfSpeech', 'varchar(255)'
    '_index', 'int(11)'
    'writtenText', 'longtext'
    'lexiconid', 'varchar(255)'

When I run this query:

select * from tablename where writtenForm = 'herstellen'

I get the results in 4,5 seconds. For me is way too much, as this table is simple, the query has no joins and I run it locally on my PC.

I have noticed that the fulltext index has no collation. Might this be a problem? If yes, please let me know how to add collation to an index.

I have also noticed that any alteration I bring to the table itself (add column, drop column) takes more than 5 minutes (last column drop took around 15).

Since you're using = and not a fulltext search, could you:

a) Remove the fulltext index and replace it with a regular index

or

b) Add a regular index alongside the fulltext index

I suspect your query is doing a full table scan and not using the fulltext index because you're not actually doing a MATCH fulltext search

MySQL Workbench also includes a Visual Explain diagram to help with such matters. For additional information, see the related tutorial titled Using Visual Explain to improve query performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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