当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
mysql之数据库账户管理与优化
双指针/滑动窗口问题
一加Ace值得买吗?用实力诠释性能的强大
TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践
opencv 直方图比较
sphinx coreseek的安装和php下使用
高效的组织信息共享知识库是一种宝贵的资源
“LaMDA 存在种族歧视,谷歌的 AI 伦理不过是‘遮羞布’!”
融云「音视频架构实践」技术专场【内含完整PPT】
软考 --- 软件工程(1)概念、开发模型
sphinx error connection to 127.0.0.1:9312 failed (errno=0, msg=)
【LeetCode】899. 有序队列
“vite”和“vite预览”有什么区别?
一键进入华为云会议,长期免费值得所有开发团队有一套【华为云至简致远】
【Metaverse系列一】元宇宙的奥秘
Web3的开源为何会如此受到人们喜爱?
405. Convert a Number to Hexadecimal
【技术白皮书】第一章:OCR智能文字识别新发展——深度学习的文本信息抽取
一个域名对应多个IP地址
被误解的 MVC 和被神化的 MVVM(二)