Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1954

why must i specify an index in query? (9 replies)

$
0
0
SELECT * FROM users LEFT JOIN (SELECT * FROM userHits) tx1 ON tx1.id=(SELECT id FROM userHits USE INDEX(userId) WHERE userId=users.id ORDER BY id DESC LIMIT 1);

0.91 seconds


SELECT * FROM users LEFT JOIN (SELECT * FROM userHits) tx1 ON tx1.id=(SELECT id FROM userHits WHERE userId=users.id ORDER BY id DESC LIMIT 1);

~15 seconds


**I realize the cardinality is low (its at 2), which is why MySQL isn't using it, but if a cardinality of 2 speeds up a query by 15x it seems sensible that it should use all indexes even if the cardinality is low. **

Can I configure this in my.cnf to force all indexes be used? Is there a way around this besides specifying the index in the query?


These are all innodb tables, so I thought it best to be in this forum. Excuse me if I was wrong.

Thanks!

Viewing all articles
Browse latest Browse all 1954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>