I have a table with columns like this:
| seqid | bigint(20) | NO | PRI | 0 |
| Time | timestamp | NO | PRI | CURRENT_TIMESTAMP |
| DevId | text | YES | MUL | NULL |
The table has partitioning enabled by value of Time column, and index length of DevId covers full length of every possible value.
Right now the table has 250M+ rows (may grow to 400M+), and ~18K to ~20K distinct DevIds.
When I try to run a query like:
select * from TABLE where DevId='00:1F:23:31:44:48'
It took 30 to 90 seconds for query, and another 30 to 90 seconds to fetch the ~20000 records. The output of explain shows something like this:
+----+-------------+------+-------------+---------+-------+------+-------------+
| id | select_type | type | key | key_len | ref | rows | Extra |
+----+-------------+------+-------------+---------+-------+------+-------------+
| 1 | SIMPLE | ref | DevID_IDX | 387 | const |21042 | Using where |
+----+-------------+------+-------------+---------+-------+------+-------------+
There are several things make me wonder:
Why the key_len is 387? I know MySQL uses more bytes for UTF-8 encoded tables, but 387 is way too long for the values. (All of them are 17 digits)
Why MySQL needs 30 to 90 seconds to fetch the index records? I know MySQL has a 16KB page size and secondary index records are stored in the leaf node of BTree and each page may be 1/2 to 15/16 full only. That means it may needs to seek for 30 or 40 pages from disk. 90 seconds definitely looks too long for that.
Is innodb one file per table option going to help? Any other way to improve the search speed? Our goal was several seconds for single query with device id and time constraint.
Thanks in advance for any suggestion.