mysql性能低下
几天前我的mysql非常慢,一些sql查询不再工作,我不知道这个问题是从哪里来的 OS:Centos MySQL:5.7-InnoDB MySQL-V:mysql性能低下,mysql,innodb,Mysql,Innodb,几天前我的mysql非常慢,一些sql查询不再工作,我不知道这个问题是从哪里来的 OS:Centos MySQL:5.7-InnoDB MySQL-V: mysql版本14.14发行版5.7.28,适用于Linux(x86_64),使用EditLine包装器 这是我的问题 SELECT BTCountry.id, BTCountry.name, BTCountry.code, BTCountry.last_data_from, BTCountry.year_last_da
mysql版本14.14发行版5.7.28,适用于Linux(x86_64),使用EditLine包装器
这是我的问题
SELECT
BTCountry.id,
BTCountry.name,
BTCountry.code,
BTCountry.last_data_from,
BTCountry.year_last_data_from AS current_year,
(SELECT
SUM(cantidad) AS subCount
FROM
`krakente_marketpins`.`bt_countries` AS `subBTCountry`
INNER JOIN `krakente_marketpins`.`bus_trucks` AS `subBusTruck`
ON (
`subBusTruck`.`pais_mercado_id` = `subBTCountry`.`id`
)
WHERE `subBusTruck`.`pais_mercado_id` = `BTCountry`.`id`
AND `subBusTruck`.`year_data_from` =
`subBTCountry`.`year_last_data_from`
AND `subBusTruck`.month_data_from <= `subBTCountry`.`month_last_data_from`) AS ytd,
(SELECT
SUM(cantidad) AS subCount
FROM
`krakente_marketpins`.`bt_countries` AS `subBTCountry`
INNER JOIN `krakente_marketpins`.`bus_trucks` AS `subBusTruck`
ON (
`subBusTruck`.`pais_mercado_id` = `subBTCountry`.`id`
)
WHERE `subBusTruck`.`pais_mercado_id` = `BTCountry`.`id`
AND `subBusTruck`.`year_data_from` = `subBTCountry`.`year_last_data_from` - 1
AND `subBusTruck`.`month_data_from` <= `subBTCountry`.`month_last_data_from`) AS last_year
FROM
bt_countries AS BTCountry
INNER JOIN `krakente_marketpins`.`bus_trucks` AS `BusTruck`
ON (
`BusTruck`.`pais_mercado_id` = `BTCountry`.`id`
)
WHERE `pais_mercado_id` IN (
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12'
)
AND mercado_id = ('1')
GROUP BY `BTCountry`.`id`
ORDER BY `ytd` DESC
我之前说过,查询在几天前就开始工作了,但突然间,这不再工作了
另一方面,我有多个wp站点,这些站点突然变得非常慢,我认为它也来自mysql,因为如果我进入一个没有sql的站点,该站点工作正常
我可以从哪里开始检查
编辑
它的解释问题
这几乎是伪代码,但是,我打赌您可以在只传递一次数据的同时进行聚合。因为已经对数据进行了分组,所以不需要在select中再进行两次子查询
SELECT
BTCountry.id,
BTCountry.name,
BTCountry.code,
BTCountry.last_data_from,
BTCountry.year_last_data_from AS current_year,
ytd = SUM(CASE WHEN BusTruck.year_data_from = bt_countries.year_last_data_from - 1 AND bus_trucks.month_data_from <= bt_countries.month_last_data_from THEN cantidad ELSE NULL END),
last_year = SUM(CASE WHEN BusTruck.year_data_from = bt_countries.year_last_data_from AND bus_trucks.month_data_from <= bt_countries.month_last_data_from THEN cantidad ELSE NULL END)
FROM
bt_countries AS BTCountry
INNER JOIN krakente_marketpins.bus_trucks AS BusTruck ON BusTruck.pais_mercado_id =BTCountry.id
WHERE
pais_mercado_id IN (
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12'
)
AND mercado_id = ('1')
GROUP
BYBTCountry.id,
BTCountry.name,
BTCountry.code,
BTCountry.last_data_from,
BTCountry.year_last_data_from
ORDER
BYytd
DESC
选择
BTCountry.id,
BTCountry.name,
BTCountry.code,
BTCountry.last_数据来自,
BTCountry.year\u上一个\u数据\u来自当前\u年,
年初至今=总和(当BusTruck.year\u data\u from=bt\u countries.year\u last\u data\u from-1和bus\u trucks.month\u data\u from这是一个非常庞大的查询时,首先要在当前的SELECT查询中运行EXPLAIN SELECT…
。查看是否可以识别任何明显的瓶颈。使用EXPLAIN
查看查询执行计划。典型的性能方面的问题是MySQL没有使用合适的索引,但是SQL性能比提供合适的索引要深刻得多。我忘了,我用解释查询更新了这个问题,我在pic中添加了它,因为我不知道如何使它成为tabletry executinganalyze table krakente_marketpins.bt_countries,krakente_marketpins.bus_trucks
然后重新尝试您的查询。分析说可以,但查询仍然是无限加载的,我忘了在localhost中使用10.1.38-MariaDB-源代码分发正确地提到此查询工作
谢谢!我仍然不明白我的查询是如何工作的,突然查询崩溃了!@hansz请发布一篇帖子)显示创建表格bt_国家;和B)显示创建表格bus_卡车;C)解释SELECT(Ross Bush查询),这样我们就可以通过减少用于结果的行来看到改进。谢谢
SELECT
BTCountry.id,
BTCountry.name,
BTCountry.code,
BTCountry.last_data_from,
BTCountry.year_last_data_from AS current_year,
ytd = SUM(CASE WHEN BusTruck.year_data_from = bt_countries.year_last_data_from - 1 AND bus_trucks.month_data_from <= bt_countries.month_last_data_from THEN cantidad ELSE NULL END),
last_year = SUM(CASE WHEN BusTruck.year_data_from = bt_countries.year_last_data_from AND bus_trucks.month_data_from <= bt_countries.month_last_data_from THEN cantidad ELSE NULL END)
FROM
bt_countries AS BTCountry
INNER JOIN krakente_marketpins.bus_trucks AS BusTruck ON BusTruck.pais_mercado_id =BTCountry.id
WHERE
pais_mercado_id IN (
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12'
)
AND mercado_id = ('1')
GROUP
BYBTCountry.id,
BTCountry.name,
BTCountry.code,
BTCountry.last_data_from,
BTCountry.year_last_data_from
ORDER
BYytd
DESC