Reputation: 15934
I need to index most of the columns in one of my tables because it is being used for log searching by users with lots of filters.
This same table has about 2-3 inserts per second. I know indexing affects inserts on a table so will this be a problem?
I am using the latest version of MySQL (?) with PHP 5.
Thanks.
Upvotes: 1
Views: 258
Reputation: 76567
There are a few tricks you can use to speed up inserts
Index definition
Inserts
ALTER TABLE ... DISABLE KEYS
before the bulk insert and ALTER TABLE ... ENABLE KEYS
after the bulk insert. This will delay the update of all non unique indexes until after all the inserts are done.LOAD DATA INFILE
; it's the fastest insert mechanism MySQL has. Maintenance
SHOW INDEX
on your tables to check the stats and look for opportunities for improvement. OPTIMIZE TABLE
periodically on your MyISAM, InnoDB and Archive tables.Choice of engine
Check out the answers to the following questions on SO:
How to optimize mysql indexes so that INSERT operations happen quickly on a large table with frequent writes and reads?
are MySQL INSERT statements slower in huge tables?
Mysql InnoDB performance optimization and indexing
Upvotes: 4
Reputation: 11581
If you only got 2-3 INSERTs per second, there is will be no problem with your indexes (unless there is a FULLTEXT index).
Upvotes: 0
Reputation: 24988
All I can suggest is to try it and see how it affects performance. Ensure that you only index those columns that will be used in searches, and only include more than one column in the index if "it makes sense" to do so - remember that in order for an index to be useable, the first column must be referenced in a WHERE, JOIN...ON clause, or ORDER BY - any latter columns mentioned in the index will not be used unless this condition is met.
Upvotes: 2