![](/img/trans.png)
[英]Slow query after migrating from MySQL 5.7 to MARIADB 10.6. Execution plan index problem
[英]Concurrent query execution is slow in MySQL 5.7
MySQL 5.7 中的并发查询执行速度很慢。
当我只运行下面的查询时,它需要 - 5.28sec
select pkid,lastname
from Table1
where pkid in (select fkid from Table2)
order by 2 desc limit 10;
但是如果我同时触发同一个查询 10 次,每个查询大约需要 11 秒。 我不确定为什么会发生,即使我的 innodb_thread_concurrency 是 10。
并发执行统计 - no_of_queries 与 each_query_time:
1 time - 5.3sec
5 time - 7.8sec
10 times - 11sec
变量:
max_connections - 1500
innodb_thread_concurrency - 10
中央处理器 - 16 核
有人可以指导我在这里缺少什么。
注意:这不是查询优化。 我的问题是并发查询执行速度很慢。 只是为了显示单独执行单个查询与同时执行相同查询 10/5 项之间的区别,我使用了这个查询。
解释
{
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "1541542.63"
},
"ordering_operation": {
"using_temporary_table": true,
"using_filesort": true,
"cost_info": {
"sort_cost": "1.00"
},
"nested_loop": [
{
"table": {
"table_name": "Table2",
"access_type": "index",
"possible_keys": [
"Table2_FK4_IDX"
],
"key": "Table2_FK4_IDX",
"used_key_parts": [
"FKID"
],
"key_length": "9",
"rows_examined_per_scan": 1246072,
"rows_produced_per_join": 732208,
"filtered": "58.76",
"using_index": true,
"loosescan": true,
"cost_info": {
"read_cost": "2586.21",
"eval_cost": "146441.71",
"prefix_cost": "149027.92",
"data_read_per_join": "2G"
},
"used_columns": [
"TABLE2ID",
"FKID"
],
"attached_condition": "(`db1234`.`Table2`.`FKID` is not null)"
}
},
{
"table": {
"table_name": "Table1",
"access_type": "eq_ref",
"possible_keys": [
"PRIMARY"
],
"key": "PRIMARY",
"used_key_parts": [
"PKID"
],
"key_length": "8",
"ref": [
"db1234.Table2.FKID"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 1,
"filtered": "100.00",
"cost_info": {
"read_cost": "1246072.00",
"eval_cost": "0.20",
"prefix_cost": "1541541.63",
"data_read_per_join": "19K"
},
"used_columns": [
"PKID",
"LASTNAME"
]
}
}
]
}
}
}
查询正在争夺资源来做同样的事情。 他们互相干扰。
也许如果您使用exists
编写查询并拥有正确的索引,那么整个事情会更快:
select t1.pkid, t1.lastname
from Table1 t1
where exists (select 1 from table2 t2 where t2.fkid = t1.pkid)
order by 2 desc
limit 10;
您肯定需要table2(fkid)
上的索引(尽管您可以通过 MySQL 中的foreign key
声明免费获得它)。 可能比table1(lastname desc, pkid)
上的索引也有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.