当前位置:网站首页>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 > all
Note: (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.
边栏推荐
猜你喜欢
随机推荐
【Metaverse系列一】元宇宙的奥秘
阿里二面:没有 accept,能建立 TCP 连接吗?
【GAMES101】作业6 加速结构
【mysql】SIGN(x)函数
Adobe是什么?
一加Ace值得买吗?用实力诠释性能的强大
新特性解读 | MySQL 8.0 在线调整 REDO
为何微博又双叒叕崩溃了?
并查集模板及思想
JVM参数设置
云图说丨初识华为云微服务引擎CSE
目标检测-YOLOv3理论讲解
出海,是泡泡玛特的“解药”吗?
软件测试<进阶篇-->测试分类>
phoenix创建映射表和创建索引、删除索引
【engine】RtcSyncCallback回调、回调容器RtcCallbackContainer及MediaPacketSenderImpl 中回调使用
isNotBlank与isNotEmpty
LeetCode·72.编辑距离·动态规划
一个域名对应多个IP地址
ASP.NET Core依赖注入之旅:3.Service Locator和依赖注入