MySQL Forums
Forum List  »  Optimizer & Parser

Re: Create index for period of time
Posted by: Rick James
Date: August 08, 2009 09:08PM

The EXPLAIN is not quite telling the truth. When it has a 'range', it usually declares 'rows' to be the number of rows in the table.

Since it says "Using index", it is not touching the actual data.

You are vague on the indexes you have.

If you have (id, timestamp), then it is actually scanning the entire index. This is because the index is useless except that it is smaller than the data. In this case, suggest you add
INDEX (timestamp)

If you have two separate indexes: (id) and (timestamp), then it is doing things very efficiently. Then, the only improvement would be to create a summary table and query it.

key_len=8 -- this could be an INT (id) + a TIMESTAMP.
Or it could be a DATETIME.

You mentioned partitioning by month -- do you mean that the table is PARTITION?

To assist in analyzing slow SELECTs, please provide
* SHOW CREATE TABLE tbl\G -- so I don't have to guess
* SHOW TABLE STATUS LIKE 'tbl'\G -- to see the size
and surround them with [ code ] and [ / code ]

Options: ReplyQuote


Subject
Views
Written By
Posted
3400
July 28, 2009 12:17AM
Re: Create index for period of time
2387
August 08, 2009 09:08PM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

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.