Mysql索引类型创建错误导致SQL查询缓慢
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,索引类型创建错误导致SQL查询缓慢通过pt-query-digest分析发现这条语句%95都需要15S以上# Query 2: 0.00 QPS, 0.01x concurrency, ID 0xB0
千家信息网最后更新 2026年11月01日Mysql索引类型创建错误导致SQL查询缓慢索引类型创建错误导致SQL查询缓慢
通过pt-query-digest分析发现这条语句%95都需要15S以上
# Query 2: 0.00 QPS, 0.01x concurrency, ID 0xB0328811156CFA43 at byte 28152292
# This item is included in the report because it matches --limit.
# Scores: V/M = 1.67
# Time range: 2017-01-17 20:02:15 to 2017-03-02 14:48:20
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 7 2669
# Exec time 22 24668s 3s 20s 9s 15s 4s 9s
# Lock time 2 655ms 117us 1ms 245us 348us 68us 224us
# Rows sent 0 2.61k 1 1 1 1 0 1
# Rows examine 9 40.04M 9.46k 20.30k 15.36k 19.40k 3.60k 15.96k
# Rows affecte 0 0 0 0 0 0 0 0
# Bytes sent 0 172.03k 66 66 66 66 0 66
# Query size 2 560.39k 215 215 215 215 0 215
# String:
# Databases ebiz_kly
# Hosts 10.111.124.41
# Last errno 0
# Users ebiz_kly
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s ################################################################
# 10s+ ########################################################
# Tables
# SHOW TABLE STATUS FROM `ebiz_kly` LIKE 'ORDER_INFO'\G
# SHOW CREATE TABLE `ebiz_kly`.`ORDER_INFO`\G
# SHOW TABLE STATUS FROM `ebiz_kly` LIKE 'ORDER_CHECK'\G
# SHOW CREATE TABLE `ebiz_kly`.`ORDER_CHECK`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT count(1) from (
SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
WHERE a.DELETED = '0'
GROUP BY a.id
ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
) as t\G
手动执行查看计划
+----+-------------+------------+------+------------------+------+---------+------+----------+----------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+------+------------------+------+---------+------+----------+----------------------------------------------------+
| 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 26682118 | NULL |
| 2 | DERIVED | b | ALL | ORDER_NO | NULL | NULL | NULL | 5182 | Using temporary; Using filesort |
| 2 | DERIVED | a | ALL | PRIMARY,ORDER_NO | NULL | NULL | NULL | 5149 | Using where; Using join buffer (Block Nested Loop)
order_info 跟order_check join 竟然这么多返回行
两张表的数据,每张表才5000多条
查看两张表(ORDER_INFO,ORDER_CHECK)字段ORDER_NO竟然是full text index
修改索引类型发现只要0.3了.
system@localhost 17:45: [ebiz_kly]> SELECT count(1) from (
-> SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
->
-> WHERE a.DELETED = '0'
-> GROUP BY a.id
-> ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
->
-> ) as t\G
*************************** 1. row ***************************
count(1): 5205
1 row in set (0.28 sec)
查询执行计划
system@localhost 17:45: [ebiz_kly]> explain SELECT count(1) from (
-> SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
->
-> WHERE a.DELETED = '0'
-> GROUP BY a.id
-> ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
->
-> ) as t;
+----+-------------+------------+-------+-------------------+-----------+---------+---------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+-------------------+-----------+---------+---------------------+------+----------------------------------------------+
| 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 5157 | NULL |
| 2 | DERIVED | a | index | PRIMARY,idx_oi_on | PRIMARY | 8 | NULL | 5157 | Using where; Using temporary; Using filesort |
| 2 | DERIVED | b | ref | idx_oc_on | idx_oc_on | 768 | ebiz_kly.a.ORDER_NO | 1 | Using where |
差距很明显了
官方文档相关解决
全文索引
InnoDB FULLTEXT Indexes
FULLTEXT indexes are created on text-based columns (CHAR, VARCHAR, or TEXT columns) to help speed up queries and DML operations on data contained within those columns,
omitting any words that are defined as stopwords.
InnoDB FULLTEXT indexes have an inverted index design. Inverted indexes store a list of words, and for each word, a list of documents that the word appears in. To support
proximity search, position information for each word is also stored, as a byte offset.
全文索引创建基于文本的列(char,varchar,或文本列)来帮助加快对包含在这些列的数据查询和DML操作,主要支持
关于全文索引解释,阿里月报相关资料
http://mysql.taobao.org/monthly/2015/10/01/
通过pt-query-digest分析发现这条语句%95都需要15S以上
# Query 2: 0.00 QPS, 0.01x concurrency, ID 0xB0328811156CFA43 at byte 28152292
# This item is included in the report because it matches --limit.
# Scores: V/M = 1.67
# Time range: 2017-01-17 20:02:15 to 2017-03-02 14:48:20
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 7 2669
# Exec time 22 24668s 3s 20s 9s 15s 4s 9s
# Lock time 2 655ms 117us 1ms 245us 348us 68us 224us
# Rows sent 0 2.61k 1 1 1 1 0 1
# Rows examine 9 40.04M 9.46k 20.30k 15.36k 19.40k 3.60k 15.96k
# Rows affecte 0 0 0 0 0 0 0 0
# Bytes sent 0 172.03k 66 66 66 66 0 66
# Query size 2 560.39k 215 215 215 215 0 215
# String:
# Databases ebiz_kly
# Hosts 10.111.124.41
# Last errno 0
# Users ebiz_kly
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s ################################################################
# 10s+ ########################################################
# Tables
# SHOW TABLE STATUS FROM `ebiz_kly` LIKE 'ORDER_INFO'\G
# SHOW CREATE TABLE `ebiz_kly`.`ORDER_INFO`\G
# SHOW TABLE STATUS FROM `ebiz_kly` LIKE 'ORDER_CHECK'\G
# SHOW CREATE TABLE `ebiz_kly`.`ORDER_CHECK`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT count(1) from (
SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
WHERE a.DELETED = '0'
GROUP BY a.id
ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
) as t\G
手动执行查看计划
+----+-------------+------------+------+------------------+------+---------+------+----------+----------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+------+------------------+------+---------+------+----------+----------------------------------------------------+
| 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 26682118 | NULL |
| 2 | DERIVED | b | ALL | ORDER_NO | NULL | NULL | NULL | 5182 | Using temporary; Using filesort |
| 2 | DERIVED | a | ALL | PRIMARY,ORDER_NO | NULL | NULL | NULL | 5149 | Using where; Using join buffer (Block Nested Loop)
order_info 跟order_check join 竟然这么多返回行
两张表的数据,每张表才5000多条
查看两张表(ORDER_INFO,ORDER_CHECK)字段ORDER_NO竟然是full text index
修改索引类型发现只要0.3了.
system@localhost 17:45: [ebiz_kly]> SELECT count(1) from (
-> SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
->
-> WHERE a.DELETED = '0'
-> GROUP BY a.id
-> ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
->
-> ) as t\G
*************************** 1. row ***************************
count(1): 5205
1 row in set (0.28 sec)
查询执行计划
system@localhost 17:45: [ebiz_kly]> explain SELECT count(1) from (
-> SELECT a.* from ORDER_INFO a LEFT JOIN ORDER_CHECK b ON a.ORDER_NO=b.ORDER_NO
->
-> WHERE a.DELETED = '0'
-> GROUP BY a.id
-> ORDER BY a.CREATE_TIME DESC, a.MODIFIED_TIME DESC
->
-> ) as t;
+----+-------------+------------+-------+-------------------+-----------+---------+---------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+-------------------+-----------+---------+---------------------+------+----------------------------------------------+
| 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 5157 | NULL |
| 2 | DERIVED | a | index | PRIMARY,idx_oi_on | PRIMARY | 8 | NULL | 5157 | Using where; Using temporary; Using filesort |
| 2 | DERIVED | b | ref | idx_oc_on | idx_oc_on | 768 | ebiz_kly.a.ORDER_NO | 1 | Using where |
差距很明显了
官方文档相关解决
全文索引
InnoDB FULLTEXT Indexes
FULLTEXT indexes are created on text-based columns (CHAR, VARCHAR, or TEXT columns) to help speed up queries and DML operations on data contained within those columns,
omitting any words that are defined as stopwords.
InnoDB FULLTEXT indexes have an inverted index design. Inverted indexes store a list of words, and for each word, a list of documents that the word appears in. To support
proximity search, position information for each word is also stored, as a byte offset.
全文索引创建基于文本的列(char,varchar,或文本列)来帮助加快对包含在这些列的数据查询和DML操作,主要支持
关于全文索引解释,阿里月报相关资料
http://mysql.taobao.org/monthly/2015/10/01/
索引
查询
全文
类型
数据
文本
缓慢
错误
明显
多条
字段
官方
差距
手动
数据查询
文档
月报
语句
资料
阿里
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
江苏根荣互联网科技
中关村互联网科技集团
凡科互联网科技
北京互联网络科技有限公司
互联网科技论文
百单互联网科技有限公司
互联网科技网站
互联网科技股有哪些
互联网金融监管科技
居家互联网科技有限公司
广西拼得多互联网科技有限公司
卫星互联网科技股票
现代科技和互联网有关系吗
互联网科技项目计划书材料类
玉溪互联网科技怎么选
深圳市罗太互联网科技有限公司
工业互联网展湾科技股份有限公司
工业互联网科技成果转化
互联网科技大佬云集
瑞安市蟠桃会互联网科技有限公司
互联网新科技
中国互联网科技工作委员会毛军
润盈互联网科技
联恩商钥互联网科技有限公司
昭通云南众福互联网科技有限公司
民营互联网公司国防科技
互联网科技圈年度人物
西安左小互联网科技有限公司
互联网科技博主张洲
中国主要互联网科技公司