How to use coverage index?
Do you know what a coverage index is ? This is an index containing all the columns that you need for your query. So for
select url from weixin_kol_status where created_at>'2015-12-11 00:00:00' and created_at<'2015-12-11 23:59:59';
the minimum coverage index will be something like
KEY `idx_created_url` (`created_at`, `url`)
And for
select url from weixin_kol_status where userid in ('...') and created_at>'2015-12-11 00:00:00' and created_at<'2015-12-11 23:59:59';
minimum coverage index may be
KEY `idx_created_user_url` (`created_at`, `userid`, `url`)
which will also cover the first request or
KEY `idx_user_created_url` (`userid`, `created_at`, `url`)
which will not work for the first request, but may be better off optimizing the second.
You may need to write url(512) instead of url . VARCHAR column is not well indexed. If you made a mistake in the fact that the indexed values ββare too wide, you can not use the coverage index with this query.
A coverage index is useful because it can respond to everything from the index in memory without accessing a table on disk. Since memory is faster than a disk, this results in faster query. Of course, if your index is unloaded, you still have to load it from disk. Therefore, if you are connected with memory, this may not help.
Please note that the query will use only one index for each table, therefore, separate indexes for each column will not cover any query. You need a composite index that will cover all the necessary columns at once.
As a side note, I think your > and < should be >= and <= respectively. It probably won't make much difference, but you seem to be missing two seconds a day.