当前位置:网站首页>[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 .
边栏推荐
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
- CADD course learning (8) -- virtual screening of Compound Library
- Recommendation system (IX) PNN model (product based neural networks)
- In depth MySQL transactions, stored procedures and triggers
- P2648 make money
- 查询mysql数据库中各表记录数大小
- tengine 内核参数
- Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
- C. The third problem
- E. Best Pair
猜你喜欢

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

综合能力测评系统

Fundamentals of SQL database operation

绑定在游戏对象上的脚本的执行顺序

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

Execution order of scripts bound to game objects
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/be/8710605c8da8d1553af974f0dc46bc.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package

Stable Huawei micro certification, stable Huawei cloud database service practice

Easyrecovery靠谱不收费的数据恢复电脑软件

Slow SQL fetching and analysis of MySQL database
随机推荐
Python book learning notes - Chapter 09 section 01 create and use classes
牛顿插值法
[disassembly] a visual air fryer. By the way, analyze the internal circuit
Web components series (VII) -- life cycle of custom components
Sentinel sliding window traffic statistics
pd. to_ numeric
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Several important classes in unity
Stack and queue
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
R note prophet
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
Lambda expression learning
Brief tutorial for soft exam system architecture designer | general catalog
SharedPreferences 源码分析
Knowledge consolidation source code implementation 3: buffer ringbuffer
IDEA编译JSP页面生成的class文件路径
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
What is the difference between gateway address and IP address in tcp/ip protocol?