我的餐桌有约.121,246,211行.记录是简单的页面印象信息.
这是架构:
create table stat_page
(
id int auto_increment primary key,
pageId int not null,
timestamp int not null
)
collate = utf8_unicode_ci;
create index pageIdIndex
on stat_page (pageId);
create index timestampIndex
on stat_page (timestamp);
Run Code Online (Sandbox Code Playgroud)
此查询需要15秒:
select count(*)
from stat_page
where `timestamp` > 1543622400;
Run Code Online (Sandbox Code Playgroud)
此查询需要将近7分钟:
select count(*)
from stat_page
where `timestamp` > 1543622400
and pageId = 87;
Run Code Online (Sandbox Code Playgroud)
我以为我把正确的东西编入索引; 桌子太大了?有没有人建议如何更快地从这个表中获取信息?
以下索引将改善该查询的性能:
create index ix1 on stat_page (pageId, timestamp);
Run Code Online (Sandbox Code Playgroud)
此查询受益于此"复合"索引.
| 归档时间: |
|
| 查看次数: |
64 次 |
| 最近记录: |