gpt4 book ai didi

MySQL:大数据读取速度慢

转载 作者:行者123 更新时间:2023-11-29 08:07:07 26 4
gpt4 key购买 nike

我有一个非常大的表,有 17,044,833 行,大小为 6.4 GB。我正在运行下面的简单查询,大约需要 5 秒。有什么想法可以进行哪些优化来提高此查询的速度吗?

SELECT 
`stat_date`,
SUM(`adserver_impr`),
SUM(`adserver_clicks`)
FROM `dfp_stats` WHERE
`stat_date` >= '2014-02-01'
AND
`stat_date` <= '2014-02-28'

MySQL 配置:

key_buffer              = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
innodb_buffer_pool_size = 10G

服务器:

Memory: 48GB     
Disk: 480GB

更新

原始查询:

EXPLAIN
SELECT
DS.`stat_date` 'DATE',
DC.`name` COUNTRY,
DA.`name` ADVERTISER,
DOX.`id` ORDID,
DOX.`name` ORDNAME,
DLI.`id` LIID,
DLI.`name` LINAME,
DLI.`is_ron` ISRON,
DOX.`is_direct` ISDIRECT,
DSZ.`size` LISIZE,
PUBSITE.`id` SITEID,

SUM(DS.`adserver_impr`) 'DFPIMPR',
SUM(DS.`adserver_clicks`) 'DFPCLCKS',
SUM(DS.`adserver_rev`) 'DFPREV'

FROM `dfp_stats` DS
LEFT JOIN `dfp_adunit1` AD1 ON AD1.`id` = DS.`dfp_adunit1_id`
LEFT JOIN `dfp_adunit2` AD2 ON AD2.`id` = DS.`dfp_adunit2_id`
LEFT JOIN `dfp_adunit3` AD3 ON AD3.`id` = DS.`dfp_adunit3_id`
LEFT JOIN `dfp_orders` DOX ON DOX.`id` = DS.`dfp_order_id`
LEFT JOIN `dfp_advertisers` DA ON DA.`id` = DOX.`dfp_advertiser_id`
LEFT JOIN `dfp_lineitems` DLI ON DLI.`id` = DS.`dfp_lineitem_id`
LEFT JOIN `dfp_countries` DC ON DC.`id` = DS.`dfp_country_id`
LEFT JOIN `dfp_creativesize` DSZ ON DSZ.`id` = DS.`dfp_creativesize_id`
LEFT JOIN `pubsites` PUBSITE
ON AD1.`pubsite_id` = PUBSITE.`id`
OR AD2.`pubsite_id` = PUBSITE.`id`

WHERE
DS.`stat_date` >= '2014-02-01'
AND DS.`stat_date` <= '2014-02-28'
AND PUBSITE.`id` = 6
GROUP BY DLI.`id`,DS.`stat_date`;

解释结果:(这是添加覆盖索引后的结果)

http://i.stack.imgur.com/vhVeB.png

最佳答案

如果还没有,您可能需要对 stat_date 字段建立索引以加快查找速度。语法如下:

ALTER TABLE TABLE_NAME ADD INDEX (COLUMN_NAME);

在此处了解有关索引和优化的更多信息:https://dev.mysql.com/doc/refman/5.5/en/optimization-indexes.html

关于MySQL:大数据读取速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22488826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com