2
为什么这个简单的查询在 MySQL 8.0.25 这么慢?
source link: https://www.v2ex.com/t/880186
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
有一张简单的表 t ,总共 11 个字段 ,关键字段如下:
- id int64 自增主键
- a char(36) NOT NULL
- b char(36) NOT NULL
- c char(36) NULL
除主键索引之外,还有两个索引:
- UNIQUE INDEX (a)
- INDEX (b)
现在有一个简单的查询
SELECT * FROM t WHERE b = ? AND c IS NOT NULL AND id > ? LIMIT 32 ORDER BY id ;
在表有大几千万条数据,并且 WHERE 匹配到的行数很多的时候,同样的数据在 MySQL 5.7.x 版本查询非常快,1s 以内,但是在另外一台 MySQL 8.0.25 上就要二十几秒,可能是什么原因呢?
第 1 条附言 · 7 小时 25 分钟前
explain 的结果
[
{
"id": 1,
"select_type": "SIMPLE",
"table": "t",
"partitions": null,
"type": "range",
"possible_keys": "b",
"key": "b",
"key_len": 152,
"ref": null,
"rows": 1519240,
"filtered": 10,
"Extra": "Using index condition; Using where"
}
]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK