From ea9b0488a14f84fdd7b05c4b207330394808a5be Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Wed, 8 Jun 2022 00:10:35 +0800 Subject: [PATCH] profile and explain --- .../1. SHOW STATUS/config.json" | 10 ++- .../1. SHOW STATUS/show_status.json" | 7 ++ .../1. SHOW STATUS/show_status.md" | 30 +++++++ .../2. SHOW PROFILE/config.json" | 10 ++- .../2. SHOW PROFILE/show_profile.json" | 7 ++ .../2. SHOW PROFILE/show_profile.md" | 34 ++++++++ .../3. EXPLAIN/config.json" | 11 ++- .../3. EXPLAIN/explain.json" | 7 ++ .../3. EXPLAIN/explain.md" | 81 +++++++++++++++++++ data/tree.json | 19 ++--- 10 files changed, 198 insertions(+), 18 deletions(-) create mode 100644 "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" rename "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. SHOW PROFILE/config.json" => "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/config.json" (55%) create mode 100644 "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.md" rename "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. EXPLAIN/config.json" => "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/config.json" (52%) create mode 100644 "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/config.json" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/config.json" index 6fc3340..b2e4f8d 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/config.json" +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/config.json" @@ -1,9 +1,13 @@ { "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 diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.json" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.json" new file mode 100644 index 0000000..0df90f0 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "show_status.md", + "notebook_enable": false, + "exercise_id": "889fd9ebeda74ba2a4c90ee0d6c13f0d" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" new file mode 100644 index 0000000..33c8cee --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" @@ -0,0 +1,30 @@ +# SHOW STATUS + +Goods 数据库近期在每日高峰时段很慢,Joe 想初步的查看一下数据库的工作状态,他应该执行: + +## 答案 + +```mysql +show global status; +``` + +## 选项 + +### A + +```mysql +show status; +``` + + +### B + +```mysql +show session status; +``` + +### C + +```mysql +show local status; +``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. SHOW PROFILE/config.json" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/config.json" similarity index 55% rename from "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. SHOW PROFILE/config.json" rename to "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/config.json" index 1c9c14c..c939b00 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. SHOW PROFILE/config.json" +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/config.json" @@ -1,9 +1,13 @@ { "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 diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.json" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.json" new file mode 100644 index 0000000..9d8aafb --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "show_profile.md", + "notebook_enable": false, + "exercise_id": "c785a28bb1474b1c8b9f3fab908041bf" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.md" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.md" new file mode 100644 index 0000000..ccdb872 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. SHOW PROFILE/show_profile.md" @@ -0,0 +1,34 @@ +# 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 diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. EXPLAIN/config.json" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/config.json" similarity index 52% rename from "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. EXPLAIN/config.json" rename to "data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/config.json" index 64c96ed..22fc67c 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/2. EXPLAIN/config.json" +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/config.json" @@ -1,9 +1,14 @@ { "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 diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.json" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.json" new file mode 100644 index 0000000..6411e44 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "explain.md", + "notebook_enable": false, + "exercise_id": "590a05e39b854e83b081d1984aef191a" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" new file mode 100644 index 0000000..d13406c --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/7.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" @@ -0,0 +1,81 @@ +# 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 diff --git a/data/tree.json b/data/tree.json index 19652ea..64eec76 100644 --- a/data/tree.json +++ b/data/tree.json @@ -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 } } ], -- GitLab