我有一个拥有谷歌分析数据的MySQL表:
CREATE TABLE IF NOT EXISTS `analytics_data` (
`ga_profile_id` int(11) NOT NULL,
`page` varchar(200) NOT NULL,
`source` varchar(150) NOT NULL,
`medium` varchar(50) NOT NULL,
`keyword` varchar(200) NOT NULL,
`bounces` int(11) NOT NULL,
`entrances` int(11) NOT NULL,
`exits` int(11) NOT NULL,
`new_visits` int(11) NOT NULL,
`page_views` int(11) NOT NULL,
`unique_page_views` int(11) NOT NULL,
`time_on_page` int(11) NOT NULL,
`visits` int(11) NOT NULL,
`date` date NOT NULL,
KEY `ga_profile_id` (`ga_profile_id`,`source`,`medium`,`date`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
我有点问,在一定时期内根据权宜分析仪表征(ga_profile_id)计算来访者人数:
SELECT
SUM( `visits` ), ( UNIX_TIMESTAMP( `date` ) - 21600 ) * 1000 AS date
FROM `analytics_data`
WHERE
`date` >= 2011-05-09 AND `date` <= 2011-06-08 AND `ga_profile_id` = [...]
GROUP BY `date`
We have 4.5 million records or so.
<>Index Data:
Type: BTREE
Fields/Cardinality:
ga_profile_id / 100
source / 10196
medium / 10196
date / 149893
EXPLAIN SELECT
- id: 1
- select_type: SIMPLE
- table: analytics_data
- type: ref
- possible_keys: ga_profile_id
- key: ga_profile_id
- ref: const
- rows: 219555
- extra: Using where; Using temporary; Using filesort
Average time for execution: 1 second.
We are on a virtual private server and most queries get executed in .0003 - 0.03 seconds. LONG queries (that I was going to optimize at some point) are generally .3 seconds.
I have tried adjusting the keys, ignoring some, changing some values and nothing seems to be affecting it in a positive way. Considering this is 1 of many queries on a page.
我期待着改变我的记忆——欢迎任何想法。