惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
IT之家
IT之家
博客园 - 聂微东
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
美团技术团队
S
Secure Thoughts
N
News | PayPal Newsroom
L
LINUX DO - 最新话题
腾讯CDC
Application and Cybersecurity Blog
Application and Cybersecurity Blog
雷峰网
雷峰网
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
T
Tailwind CSS Blog
月光博客
月光博客
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News: Ask HN
Hacker News: Ask HN
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
S
Security @ Cisco Blogs
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
S
Security Affairs
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
T
Tor Project blog
O
OpenAI News
L
Lohrmann on Cybersecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 每天进步多一点

MySQL5.7实现row_number()和over()函数 C#学习相关系列之Linq用法---group和join相关用法 linq group by having 实现 常用知识-T-SQL优化 mysql窗口函数、Mysql分析函数 MySQL系列三(定位慢SQL、索引优化、SQL优化)Using filesort MySQL 内存相关参数设置 MySQL COALESCE 函数使用详解 SQL性能优化指南:如何优化MySQL多表join场景 MySQL内部临时表(Using temporary)案例详解及优化解决方法 cookie操作类(加密,获取,删除) MySql 5.7 索引不存在则创建,存在则忽略 SQL SERVER年月周日超止时间 数据抽取的常见理论方法 ETL系列-数据抽取(Extract) 常用时间sql语句 数据库运维:mysql 数据库迁移方法-mysqldump 了解MySQL中的JSON_ARRAYAGG和JSON_OBJECT函数 MySQL的IFNULL()、ISNULL()、NULLIF()函数用法说明 如何看懂explain工具信息,使用explain工具来分析索引
mysql 如何查看sql语句执行时间和效率
每天进步多一点 · 2025-10-31 · via 博客园 - 每天进步多一点

查看执行时间
1 show profiles;
2 show variables;查看profiling 是否是on状态;
3 如果是off,则 set profiling = 1;
4 执行自己的sql语句;
5 show profiles;就可以查到sql语句的执行时间;

查看操作了多少行
在sql语句前面加上 explain就可以了;

explain select * from event;  
+—-+————-+——-+——+—————+——+———+——+——+——-+  
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |  
+—-+————-+——-+——+—————+——+———+——+——+——-+  
| 1 | SIMPLE | event | ALL | NULL | NULL | NULL | NULL | 13 | |  
+—-+————-+——-+——+—————+——+———+——+——+——-+  
1 row in set (0.00 sec) 

各个属性的含义

id

select查询的序列号

select_type

select查询的类型,主要是区别普通查询和联合查询、子查询之类的复杂查询。

table

输出的行所引用的表。

type

联合查询所使用的类型。

type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是:

system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL

一般来说,得保证查询至少达到range级别,最好能达到ref。

possible_keys

指出MySQL能使用哪个索引在该表中找到行。如果是空的,没有相关的索引。这时要提高性能,可通过检验WHERE子句,看是否引用某些字段,或者检查字段不是适合索引。

key

显示MySQL实际决定使用的键。如果没有索引被选择,键是NULL。

key_len

显示MySQL决定使用的键长度。如果键是NULL,长度就是NULL。文档提示特别注意这个值可以得出一个多重主键里mysql实际使用了哪一部分。

ref

显示哪个字段或常数与key一起被使用。

rows

这个数表示mysql要遍历多少数据才能找到,在innodb上是不准确的。

Extra

如果是Only index,这意味着信息只用索引树中的信息检索出的,这比扫描整个表要快。

如果是where used,就是使用上了where限制。

如果是impossible where 表示用不着where,一般就是没查出来啥。