当前位置:网站首页>[HBZ sharing] how to locate slow queries in cloud database
[HBZ sharing] how to locate slow queries in cloud database
2022-07-06 04:21:00 【hbz-】
How to configure Mysql The slow query
1. Query slow log related information :SHOW VARIABLES LIKE '%query%'
2. Open slow logging file :set global slow_query_log = 'ON'
3. The file name of the slow log :slow_query_log_file
4. Configure the slow query time :set global long_query_time = 1 // Modify slow query time 1s, That is, the query exceeds 1s It is recorded in the slow query log
5. Be careful : After modifying the slow query time , Remember to reconnect to take effect
How to locate slow queries
- adopt EXPLAIN Query whether the statement is indexed , If you don't leave the index, it means you have left the full table scan
- Be careful : The production environment generally does not allow this , The production environment usually passes through the automation platform , From the visual interface
EXPLAIN How to use ?
- Usage mode :EXPLAIN SELECT * FROM test WHERE age = 10
EXPLAIN Medium Type Field meaning
- type = all: Direct full table scanning data , Extremely inefficient
- type = index: Need to optimize , Although it is also the index , But express Full table scanning 【 Indexes 】 file , Not scanning data
- type = range:sql The minimum satisfaction condition is range, Query only rows in a given range , Use an index to select rows
- type = ref: Generally, this level is required , When the field is added with a general index , And the condition happens to be this field , That was ref type , For example, use name = ‘hbz’ This condition , and name Created a normal index , At this point ref
- type = eq_ref: Through primary key or Unique index Association table The query is eq_ref, Except for const The best result
- type = const: High performance level , Index according to the primary key id look for , It's usually const, No need to optimize
Mysql Why should the best left prefix rule be followed in joint indexing ?
- The union index will take precedence over the prefix
- If the order of association is name, age, position
- give an example :
// The order :name, age, postion --> Because the condition is in the order of joint index , So it triggers ref Index level
SQL: SELECT name, age FROM people WHERE name = 'hbz' and age = 21 and positon = 'tetst'
// Only name --> Because the condition is prefixed name, So it triggers ref Index level
SQL: SELECT name, age FROM people WHERE name = 'hbz'
// Only name, position --> Because the condition is prefixed name, So it triggers ref Index level
SQL: SELECT name, age FROM people WHERE name = 'hbz' and positon = 'tetst'
// Only position, No, name --> Because there is no prefix name, So the index will not be triggered
SQL: SELECT name, age FROM people WHERE positon = 'tetst'
// Yes name, But it is inconsistent with the joint index order --> There are conditions name Field , So the index will be triggered , Although not in order , however mysql The bottom layer will put name Put optimization ahead
SQL: SELECT name, age FROM people WHERE positon = 'tetst' and name = 'hbz'
- in summary , The so-called leftmost prefix rule , Namely , If where With name, Then the index must be taken ,name It doesn't matter where the order of , because mysql The bottom layer will be optimized , hold name Put it at the front . But if not name, Other field order pairs of the joint index cannot be indexed . This is called the best prefix rule , The beginning field of the union index must exist .
边栏推荐
- Knowledge consolidation source code implementation 3: buffer ringbuffer
- Mixed development of QML and QWidget (preliminary exploration)
- Stable Huawei micro certification, stable Huawei cloud database service practice
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
- Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
- Recommendation | recommendation of 9 psychotherapy books
- . Net interprocess communication
- Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
- Fedora/rehl installation semanage
- Class A, B, C networks and subnet masks in IPv4
猜你喜欢
Recommendation | recommendation of 9 psychotherapy books
Data processing methods - smote series and adasyn
1291_Xshell日志中增加时间戳的功能
Fedora/REHL 安装 semanage
Execution order of scripts bound to game objects
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
Mlapi series - 04 - network variables and network serialization [network synchronization]
食品行业仓储条码管理系统解决方案
Fundamentals of SQL database operation
How does computer nail adjust sound
随机推荐
Record an excel xxE vulnerability
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
深入浅出node模板解析错误escape is not a function
【leetcode】22. bracket-generating
10个 Istio 流量管理 最常用的例子,你知道几个?
Basic knowledge of binary tree, BFC, DFS
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
Data processing methods - smote series and adasyn
2327. 知道秘密的人数(递推)
CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Codeforces Round #770 (Div. 2) B. Fortune Telling
Query the number and size of records in each table in MySQL database
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Several important classes in unity
lora网关以太网传输
拉格朗日插值法
[Zhao Yuqiang] deploy kubernetes cluster with binary package