I have a datatable that gets the data from server side, and I want to optimize my table by adding indexes so that the sorting is faster (right now it takes around 7 seconds to sort 60K rows)
My 'copy create statement to clipboard' looks like this:
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` char(128) COLLATE utf8_unicode_ci NOT NULL,
`salt` char(5) COLLATE utf8_unicode_ci NOT NULL,
`joined` int(10) unsigned NOT NULL,
`name` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`surname` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`role` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`photo` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`user_type` int(11) DEFAULT NULL,
`user_owner` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=81634 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
The problem that I'm having is that if I use this:
ALTER TABLE `users` ADD INDEX (`email`, `name`, `surname`, `user_type`) ;
only email is indexed (at least only the email column can be sorted fast). I'm not sure what I can do to add the other indexed columns (or if it's actually going to be good for optimizing it).