MYSQL查询中成千上万条记录的性能非常慢

问题描述 投票:0回答:2
id    market_id      date          keyword                 sku            a             b         c  
1        1        2019-01-01    some text for this      QAB-XU-VV        3.1           2.4       3.5
2        2        2019-01-02    some text for text      ABC-XA-VV        2.1           4.1       1.2

这是表A的一个实例

`id` : `int primary key auto increment`
`market_id` : `int(4)`  `INDEX`
`date` : `date`   `INDEX`
`keyword`: `varchar(191)` `utf8_general_ci`
`sku`: `varchar(191)` INDEX `utf8_general_ci`
`a, b, c` : `float` 

我需要这样查询

SELECT
  sku,
  keyword,
  market_id,
  SUM(a),
  SUM(b),
  SUM(c),
FROM A
WHERE market_id = 2 AND date BETWEEN '2020-01-01' and '2020-02-02'
GROUP BY sku, keyword;

预计该查询大约有十万条记录。此查询需要5分钟以上。因此我使用了LIMITOFFSET,但没有任何改进。

请帮助我。谢谢。

更新:

这显示EXPLAIN结果。enter image description here

mysql sql performance mysql-slow-query-log
2个回答
4
投票

1
投票
通常
© www.soinside.com 2019 - 2024. All rights reserved.