我被告知插入带有索引的表格很慢。有没有办法绕过删除索引或创建/插入没有索引的表格,然后重新创建索引以简单地告诉mysql忽略插入的索引并在之后重新索引?
答案 0 :(得分:0)
Short answer:
Indexes are usually worth a lot for SELECTs
, while costing only a little during INSERTs
. Don't turn them off.
Long answer:
The advice you were given applies only in some obscure case.
When initially loading a very large table, it is sometimes better to have no indexes (except PRIMARY KEY
, in the case of InnoDB) while loading, then add all the indexes at once.
Once the table is populated, turning of the indexes (for adding more rows) is almost never practical.
An index on a "flag" (true/false, M/F, yes/no/maybe) column is almost never used. DROP
it.
If you have "indexed every column", then I have choice 4-letter words for you. Most of your indexes will never be used.
If you have never built a "composite" index -- that is an index with more than one column in it -- then your indexes may not be as good as needed.
That is, having a "few" indexes is good.