当前位置:网站首页>[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 .
边栏推荐
- Lambda expression learning
- Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
- 查询mysql数据库中各表记录数大小
- JVM garbage collector concept
- 我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
- Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
- Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
- 2/13 review Backpack + monotonic queue variant
- How to execute an SQL statement in MySQL
- 软考 系统架构设计师 简明教程 | 总目录
猜你喜欢

About some basic DP -- those things about coins (the basic introduction of DP)

How does technology have the ability to solve problems perfectly

图应用详解
![[tomato assistant installation]](/img/06/672a616d4fc2a43b83054eb1057628.jpg)
[tomato assistant installation]

关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解

Certbot failed to update certificate solution

What is the difference between gateway address and IP address in tcp/ip protocol?

IDEA编译JSP页面生成的class文件路径

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server

综合能力测评系统
随机推荐
1008 circular right shift of array elements (20 points)
2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
HotSpot VM
Lambda expression learning
729. My schedule I (set or dynamic open point segment tree)
绑定在游戏对象上的脚本的执行顺序
[tomato assistant installation]
CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
综合能力测评系统
【HBZ分享】ArrayList的增删慢查询快的原因
Several important classes in unity
Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
Basic knowledge of binary tree, BFC, DFS
After learning classes and objects, I wrote a date class
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
How does computer nail adjust sound
Practical development of member management applet 06 introduction to life cycle function and user-defined method
Fundamentals of SQL database operation