简体   繁体   中英

Reversed table index in MySQL isn't detected

I've been persistently trying to speed up a MySQL query that involves an ORDER BY on a complex query. I've exhausted several options, and have gotten pretty close -- I've found the best solution to be implementing a pseudo-reverse index on the table in question.

I basically emulated the advice on this post (including variations using the id instead of publish date, using a joint index, etc): http://www.igvita.com/2007/08/20/pseudo-reverse-indexes-in-mysql/

and successfully added the extra column, populated it, added an index, but the query

SELECT * FROM products USE INDEX (index_reverse_created);

doesn't seem to work. Inserting a random word or a regular column in place of the index name throws an error, so I realize it successfully detects the index.

Further inspection, using EXPLAIN SELECT *..., however, shows this:

http://i44.tinypic.com/2aes304.png

The peculiar part is (NULL) for both possible_keys and key .

SHOW INDEX FROM products yields this:

http://i41.tinypic.com/fvvdl1.png

And that seems like a healthy set of indices.

And altogether, I'm stumped. Seems like the index is there, but something goes wrong when trying to actually use it.

Your index will be used when there is where, order by, group by clauses in your query. You wrote plain, simple query without any additional query and mysql will use fullscan and read data consequently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM