I’ve got a user table keyed on an auto-increment int column that looks something like this:
CREATE TABLE `user_def` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) NOT NULL,
`date_created` datetime NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name_UNIQUE` (`user_name`),
) ENGINE=MyISAM
Are there any practical performance advantages to using a DESC index (primary key) rather than the default ASC?
My suspicion / reasoning is as follows:
I’m assuming that more recent users are going to be more active (i.e. accessing the table more often), therefore making the index more efficient.
Is my understanding correct?
Updated Answer for MySQL 8.0
As noted by Kazimieras Aliulis in the comments, support for descending indexes is being added in MySQL 8.0:
Original Answer for Earlier Versions
DESCindexing is not currently implemented in MySQL… the engine ignores the provided sort and always usesASC:For another RBDMS that does implement this feature, such as SQL Server, the
DESCspecification is only beneficial when sorting by compound indexes… and won’t have an impact on the lookup time for newly created users versus older users.