MySQL Forums
Forum List  »  Optimizer & Parser

Re: Select last row that is less than or equal to a date
Posted by: David Marcus
Date: January 26, 2013 09:35AM

Thank you, Rick. I tried it with and without the limit. See below. It
looks like MySQL is finding the one record by finding it in the index,
so it is doing a good job. Is that correct? Are the 9
Handler_read_rnd_next's from reading the index?

SHOW SESSION STATUS LIKE 'Handler%';
"Variable_name","Value"
"Handler_commit","0"
"Handler_delete","0"
"Handler_discover","0"
"Handler_prepare","0"
"Handler_read_first","0"
"Handler_read_key","0"
"Handler_read_last","0"
"Handler_read_next","0"
"Handler_read_prev","0"
"Handler_read_rnd","0"
"Handler_read_rnd_next","2"
"Handler_rollback","0"
"Handler_savepoint","0"
"Handler_savepoint_rollback","0"
"Handler_update","0"
"Handler_write","1"

select * from History where HistoryPlayer = 59161 and HistoryDate <= '2012-01-01' order by HistoryDate desc limit 0,1;

SHOW SESSION STATUS LIKE 'Handler%';
"Variable_name","Value"
"Handler_commit","0"
"Handler_delete","0"
"Handler_discover","0"
"Handler_prepare","0"
"Handler_read_first","0"
"Handler_read_key","1"
"Handler_read_last","0"
"Handler_read_next","0"
"Handler_read_prev","0"
"Handler_read_rnd","0"
"Handler_read_rnd_next","11"
"Handler_rollback","0"
"Handler_savepoint","0"
"Handler_savepoint_rollback","0"
"Handler_update","0"
"Handler_write","9"

select * from History where HistoryPlayer = 59161 and HistoryDate <= '2012-01-01' order by HistoryDate desc

SHOW SESSION STATUS LIKE 'Handler%';
"Variable_name","Value"
"Handler_commit","0"
"Handler_delete","0"
"Handler_discover","0"
"Handler_prepare","0"
"Handler_read_first","0"
"Handler_read_key","2"
"Handler_read_last","0"
"Handler_read_next","0"
"Handler_read_prev","71"
"Handler_read_rnd","0"
"Handler_read_rnd_next","20"
"Handler_rollback","0"
"Handler_savepoint","0"
"Handler_savepoint_rollback","0"
"Handler_update","0"
"Handler_write","17"

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Select last row that is less than or equal to a date
1885
January 26, 2013 09:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.