我一直在阅读很多很好的答案,在这个网站上的时间不同的问题,但这是我第一次发布。所以提前感谢您的帮助。mySQL查询优化浏览跟踪器
这里是我的问题:
我有一个MySQL的表跟踪访问不同的网站,我们有。这是表格结构:
create table navigation_base (
uid int(11) NOT NULL,
date datetime not null,
dia date not null,
ip int(4) unsigned not null default 0,
session_id int unsigned not null,
cliente smallint unsigned not null default 0,
campaign mediumint unsigned not null default 0,
trackcookie int unsigned not null,
adgroup int unsigned not null default 0,
PRIMARY KEY (uid)
) ENGINE=MyISAM;
此表格有答案。 7000万行(平均每天110,000)。
在我们创建的索引与下面的命令该表:
alter table navigation_base add index dia_cliente_campaign_ip (dia,cliente,campaign,ip);
alter table navigation_base add index dia_cliente_campaign_ip_session (dia,cliente,campaign,ip,session_id);
alter table navigation_base add index dia_cliente_campaign_ip_session_trackcookie (dia,cliente,campaign,ip,session_id,trackcookie);
,我们使用此表来获得由客户,天,活动用下面的查询分组访客统计:
select
dia,
navigation_base.campaign,
navigation_base.cliente,
count(distinct ip) as visitas,
count(ip) as paginas_vistas,
count(distinct session_id) as sesiones,
count(distinct trackcookie) as cookies
from navigation_base where
(dia between '2017-01-01' and '2017-01-31')
group by dia,cliente,campaign order by NULL
即使创建了这些索引,一个月的响应时间也相对较慢;在我们的服务器上约3秒钟。
有没有加快这些查询的一些方法?
在此先感谢。
嗨。谢谢你快速的回复。前段时间尝试分区,但没有帮助。不过我会再试一次。我所做的只是创建一个包含一个月数据的表格,因为这可能与某个分区类似。 Te查询时间在大表和小表中相同。问候。 –
我看到了你试过指标无分区的好处。单独的桌子也不会更好。认为它是这样的:有多少_rows_需要读(包括传入了行),以满足查询。所有三种情况的答案都是一样的。 –