当前位置:网站首页>Execution plan of mysql
Execution plan of mysql
2022-08-03 17:39:00 【Bugxiu_fu】
1. What is an execution plan?
Use the EXPLAIN keyword to simulate the optimizer executing SQL query statements, so as to know how MYSQL processes your SQL statements.
Execution planning process (best understood with the diagram)
The browser (client) sends a request. Before executing the database query, it finds the connection pool (recycling), connects with the database driver, finds the mysql service after obtaining the connection, then the connection pool finds the query cache, and then parses it, find the parse tree parsing, generate a new parse tree after preprocessing, query the optimizer after the new parse tree, execute sql, find the data file through the engine, read the data, return it to the cache, and finally return it to the user.
Some optimizers: (understand)
CBO: Cost-based optimizer, look at which index, and count the index according to the cost value.
RBO: Rule-based optimizer, with indexes using indexes.Then all tables with indexes will go through the index in any case
Second, the values and parameters of the execution plan
Code
explain(select * from t_users id=1unionselect * from t_users id=2);Running Results
- select_type: category, mainly used to distinguish complex queries (union) such as ordinary queries, union queries, sub-queries, etc.
simple: a simple select query without subqueries or unions
primary: The query contains any complex subparts, the outermost query is marked
derived: The subquery is used in the from list, the table is used as the query condition, and the subquery is also calculated
union: Included in the subquery of the from clause, a temporary table will be generated when the subquery occurs
- paritiions: If the table data volume is large, set the partition conditions.
- possible_keys: possible keys (indexes)
- key: the index actually used
- key_len: length of key used (bytes)
- ref: Shows which field or constant is used with the key
- rows: how much data to traverse to find
- type: is a more important indicator, the result value is (performance) in order from best to worst
system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > index_subquery > range > index > allNote: (marked in red means that the system has gone to the index)
system: There is only one row in the table (equal to the system table);
const means that it is found once by index;
eq_ref: one-dimensional record;
ref: non-unique index scan;
range: retrieve only rows in a given range
all: full table scan
index: index coverage (scan all)
null: execute without even accessing the table or index;
- Extra: Indicates important extra information that doesn't fit in other columns
Using index: Covering the index to avoid accessing the table.
Using temporary: sorting temporary table
Using where: filter after retrieval
How to optimize the performance of myql?
The server checks the query cache first, and if it hits the cache, it immediately returns the result stored in the cache.Otherwise go to the next stage.
If a column is indexed, try to avoid using the null value, because its value is more complex and it is not easy to create an index.
边栏推荐
猜你喜欢

星巴克输血赶不上流血

A complete detailed tutorial on building intranet penetration ngrok (with pictures and truth)

Description of the functional scenario of "collective storage and general governance" in the data center

多表查询最值

JVS低代码移动端接入方案

uniapp 切换 history 路由模

SkyWalking概要介绍

CAD如何自定义快捷键

数据万象内容审核 — 共建安全互联网,专项开展“清朗”直播整治行动

Detailed explanation of setting HiSilicon MMZ memory and OS memory
随机推荐
JS中对象数组用sort按属性排序
isNotBlank与isNotEmpty
Promise的 简单使用
云图说丨初识华为云微服务引擎CSE
工程仪器设备在线监测管理系统常见问题和注意事项
阿里二面:没有 accept,能建立 TCP 连接吗?
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
mysql之数据库账户管理与优化
分享 14 个你必须知道的 JS 函数
CC2530_ZigBee+HUAWEI CLOUD IOT: Design your own cold chain acquisition system
401. Binary Watch
新“妖股”13个交易日暴涨320倍,市值3100亿美元超阿里
每周推荐短视频:为了填补学习资源的空缺,作者专门写了本书?
【JS】利用JS给删除按钮添加提示框
ASP.NET Core依赖注入之旅:3.Service Locator和依赖注入
【mysql】SIGN(x)函数
软件测试<进阶篇-->测试分类>
#yyds干货盘点# 面试必刷TOP101:两个链表的第一个公共结点
sibling component communication context
掌握Redis的Sentinel哨兵原理,可助你拿到25k的offer

