提交 ea9b0488 编写于 作者: M Mars Liu

profile and explain

上级 0f811a0f
{
"node_id": "mysql-3574b2e5c9ca475789d9d582d7726906",
"keywords": ["show status"],
"keywords": [
"show status"
],
"children": [],
"export": [],
"export": [
"show_status.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"group": 2
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "show_status.md",
"notebook_enable": false,
"exercise_id": "889fd9ebeda74ba2a4c90ee0d6c13f0d"
}
\ No newline at end of file
# SHOW STATUS
Goods 数据库近期在每日高峰时段很慢,Joe 想初步的查看一下数据库的工作状态,他应该执行:
## 答案
```mysql
show global status;
```
## 选项
### A
```mysql
show status;
```
### B
```mysql
show session status;
```
### C
```mysql
show local status;
```
{
"node_id": "mysql-f0b12126dd3e4be09010a308a822bc32",
"keywords": ["show profile"],
"keywords": [
"show profile"
],
"children": [],
"export": [],
"export": [
"show_profile.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"group": 2
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "show_profile.md",
"notebook_enable": false,
"exercise_id": "c785a28bb1474b1c8b9f3fab908041bf"
}
\ No newline at end of file
# SHOW PROFILE
数据分析组的几个分析查询很慢,希望 Joe 提供帮助,他准备查看一下这几条查询的 Profile 信息,应该:
1. 执行`SET SESSION profiling = 1;`打开 profile
2. 执行查询后,根据 `show profiles`找到要剖分的查询id
3. 执行 `SHOW PROFILE FOR QUERY xxx;` 查看剖分信息
4. 执行`SET SESSION profiling = 0;`关闭 profile
## 答案
```
1, 2, 3, 4
```
## 选项
### A
```
2, 3
```
### B
```
1, 2, 3
```
### C
```
2, 3, 4
```
\ No newline at end of file
{
"node_id": "mysql-a42f617d4eb54aabbc649bdde4485117",
"keywords": ["explain"],
"keywords": [
"explain",
"explain analyze"
],
"children": [],
"export": [],
"export": [
"explain.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"group": 2
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "explain.md",
"notebook_enable": false,
"exercise_id": "590a05e39b854e83b081d1984aef191a"
}
\ No newline at end of file
# EXPLAIN
Joe 从交易服务中发现了一些高频查询和慢查询,例如
```mysql
with recursive r(id) as (select id
from orders
where id = $1
union
select d.id
from orders as d
join r on d.id = r.id + 1)
select orders.id, content
from orders
join r on orders.id = r.id;
```
,他应该从何入手分析优化?
## 答案
在测试库使用
```mysql
explain with recursive r(id) as (select id
from orders
where id = $1
union
select d.id
from orders as d
join r on d.id = r.id + 1)
select orders.id, content
from orders
join r on orders.id = r.id;
```
进行剖分,对于需要了解详细执行计划的使用
```mysql
explain analyze with recursive r(id) as (select id
from orders
where id = 100
union
select d.id
from orders as d
join r on d.id = r.id + 1)
select orders.id
from orders
join r on orders.id = r.id;
```
进行详细分析。
## 选项
### A
对查询设计的字段加索引
### B
备份数据库,删除重建
### C
使用
```mysql
analyze with recursive r(id) as (select id
from orders
where id = 100
union
select d.id
from orders as d
join r on d.id = r.id + 1)
select orders.id
from orders
join r on orders.id = r.id;
```
进行剖分。
\ No newline at end of file
......@@ -2048,31 +2048,32 @@
"children": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"group": 2
}
},
{
" EXPLAIN": {
"node_id": "mysql-a42f617d4eb54aabbc649bdde4485117",
" SHOW PROFILE": {
"node_id": "mysql-f0b12126dd3e4be09010a308a822bc32",
"keywords": [
"explain"
"show profile"
],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"group": 2
}
},
{
" SHOW PROFILE": {
"node_id": "mysql-f0b12126dd3e4be09010a308a822bc32",
" EXPLAIN": {
"node_id": "mysql-a42f617d4eb54aabbc649bdde4485117",
"keywords": [
"show profile"
"explain",
"explain analyze"
],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"group": 2
}
}
],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册