For the select:
INDEX(a, d)
First column(s), namely a
, in index should be compared "= constant".
Then comes one range, namely d > ...
.
The other stuff is hard to index because of OR
. However, it is all the same variable: e=1 OR e=5 OR e=6 OR e=8 OR e=15
, which is equivalent to e IN (1, 5, 6, 8, 15)
. So, this is better:
INDEX(a, e, d)
This is because the optimizer (in 5.6) can "leapfrog" through the index for e
. That is, after all the '=' columns, and before the one 'range', you have one 'IN'.
This is a "covering" index:
INDEX(a, e, d, c)
It may be even better. There is a tradeoff between the bulkiness and the "covering". It is not easy to predict whether it will be better; furthermore it may be better for some values and worse for others. This will be 320 bytes versus 20.
(Note: the columns in this index, and the others, must be in the order given.)
more.
For the INSERT
LOAD DATA
is probably the best. However if the number of rows in the LOAD
are too many, it may have an adverse impact on the SELECTs
. Also very good is batched INSERTs
of 100-1000 rows per batch.
VARBINARY
That is probably a packed MD5 or IPv6? It may as well be BINARY(16)
? It does not hurt the indexing as much as some people say.
InnoDB
Of course, use InnoDB, not MyISAM.