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 6fc334052f880c38f93be7d5d372c8b4e0404d9d..b2e4f8d62abd038c6c1bbfb598d2a2e13823fc0f 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 0000000000000000000000000000000000000000..0df90f0d2e4d4220314df88a5065cefed462938c --- /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 0000000000000000000000000000000000000000..33c8cee564ba9cbc736f42d657d91d5a28531ebd --- /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 1c9c14cd6a94db1022a0f7018911434141b7c9bf..c939b000ede339a250202caeaa220fcc88c29f52 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 0000000000000000000000000000000000000000..9d8aafb4a5376981cf50aa9a3dedb5cd2d7043d9 --- /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 0000000000000000000000000000000000000000..ccdb872541bcde822285eb7eaa822da0fe49d1ef --- /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 64c96ed7d5880d56570b543cf5bca20402f17c87..22fc67cba00975a6c2da5ca49c68ee1d37c4d064 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 0000000000000000000000000000000000000000..6411e44e7f026d63491e9d8d477c1256b71ac0ef --- /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 0000000000000000000000000000000000000000..d13406cbcf1fb516eb84ac0a31f316fe5b475839 --- /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 19652ea7315a7567b2f36ec364ba5ce678ff3886..64eec76e8746986a51453996966ac7087c38146b 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 } } ],