I have a hot question about mysql ...
The idea here is to select the n last records from the table, filtering by the property (possibly from another table). It's simple.
At this point you want to answer:
let n = 10
SELECT * FROM huge_table JOIN another_table ON another_table.id = huge_table.another_table_id AND another_table.some_interesting_property ORDER BY huge_table.id DESC LIMIT 10
Without the JOIN, which is OK, mysql reads the index from the end and changes 10 elements, the runtime is negligible. When connected, the runtime becomes dependent on the size of the table and in many cases is not insignificant, an explanation indicating that mysql: "Use where: use index ; use temporary; use filesort "
The MySQL documentation ( http://dev.mysql.com/doc/refman/5.1/en/order-by-optimization.html ) states:
"You are joining many tables, and the columns in ORDER BY are not all from the first mutable table, which is used to retrieve the rows. (This is the first table in the EXPLAIN output, which does not have the type of joining constants.)"
explaining why MySQL cannot use the index to solve my ORDER BY, preferring huge file sorting ...
My question is: is it OK to use ORDER BY ... LIMIT 10 to get the latest items? Do you really do this by choosing the last 10 cards in an increasing ordered deck of cards? Personally, I just pick 10 from the bottom ...
I tried many possibilities, but it all ended up coming to the conclusion that I really quickly asked for the first 10 elements and slowly asked for the last 10 reasons for the ORDER BY clause.
Can I quickly select "Select last 10"? Where am I mistaken?