I have following table. I don’t know whether defining of additional keys should cause reduction in server speed or not?
In other words, if I define 10 or more keys to any MySQL table, will my query speed be raised or not? Also, is it recommended (adding more keys to table)?
CREATE TABLE IF NOT EXISTS `xxx` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`intval1` int(11) DEFAULT NULL,
`intval2` int(11) DEFAULT NULL,
`intval3` int(11) DEFAULT NULL,
`intval4` int(11) DEFAULT NULL,
`intval5` int(11) DEFAULT NULL,
`intval6` int(11) DEFAULT NULL,
`intval7` int(11) DEFAULT NULL,
`intval8` int(11) DEFAULT NULL,
`intval9` int(11) DEFAULT NULL,
`intval10` int(11) DEFAULT NULL,
`intval11` int(11) DEFAULT NULL,
`intval12` int(11) DEFAULT NULL,
`intval13` int(11) DEFAULT NULL,
`intval14` int(11) DEFAULT NULL,
`intval15` int(11) DEFAULT NULL,
`intval16` int(11) DEFAULT NULL,
`intval17` int(11) DEFAULT NULL,
`intval18` int(11) DEFAULT NULL,
`intval19` int(11) DEFAULT NULL,
`intval20` int(11) DEFAULT NULL
)
Any index you add will slow down inserts and updates of values in the indexed columns because the index(es) will need to be updated. (This might be offset by speed-up on updates that use a WHERE clause.)
Otherwise, the only way to answer your question is to know what queries will be issued against the table. If a query will require MySQL to look up rows by value of
idand/orintval1, then an index onintval2won’t speed up anything.Generally, you should only index columns that help with your queries. For further information, check out the MySQL manual section on Optimization and Indexes.