提交 8a515490 编写于 作者: M Mars Liu

upgrade to performance

上级 4b9bba94
...@@ -43,5 +43,5 @@ select dept, min(salary) from employee; ...@@ -43,5 +43,5 @@ select dept, min(salary) from employee;
### D ### D
```mysql ```mysql
select sum(total) from orders having deal and unit_price > 1000; select dept, min(total) from employee;
``` ```
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "avg.md",
"notebook_enable": false,
"exercise_id": "c6ff6b73f6844327b71b6b0630fedcaa"
}
\ No newline at end of file
# 平均值练习
Joe 想要得到 employee 表
```mysql
create table employee
(
id serial primary key,
name varchar(256),
dept varchar(256),
salary decimal(12, 4)
);
```
中每个部门的平均工资信息,这条查询应该怎么写?
## 答案
```mysql
select dept, avg(salary) from employee group by dept;
```
## 选项
### A
```mysql
select dept, avg(salary) from employee;
```
### B
```mysql
select dept, avg(salary) from employee;
```
### C
```mysql
select dept, avg(salary) from employee;
```
### D
```mysql
select dept, avg(salary) from employee ;
```
\ No newline at end of file
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
"node_id": "mysql-11462fccf9d24d17a372d5c60af90f54", "node_id": "mysql-11462fccf9d24d17a372d5c60af90f54",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"keywords_must": [ "avg.json"
["mysql", "平均值"],
["mysql", "avg"]
], ],
"keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
} }
\ No newline at end of file
{
"node_id": "mysql-769c096b229842239e2ba2f8d1c768d3",
"keywords": ["连接复用", "连接池"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-d7b339f2b2434e3fbd3721b7cd1abc1a",
"keywords": ["performance", "application", "io"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-8973ee6a0cb045b7bcf623b4e5757baa",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-7f86d4e58a514a44bce09a19595f9cab",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-402ec368b74f4c33b33c812e9f762d3a",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-288d4606c1ae4f49a0ab79212bc0ff2b",
"keywords": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 2
}
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
"node_id": "mysql-3e4c837b471c454c90bfbc32445f2780", "node_id": "mysql-3e4c837b471c454c90bfbc32445f2780",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"slack.json"
],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "slack.md",
"notebook_enable": false,
"exercise_id": "d62e33f550494f849f87b62acdcf9d0a"
}
\ No newline at end of file
# 反范式设计
反范式优化的主要动机和思路是:
1. 通过适当增加冗余字段,减少连接查询的次数和复杂度
2. 对于经常发生的聚合计算,如果对实时正确性要求不高,可以缓存中间结果,减少实时的聚合计算压力
3. 用适度的写冗余,换取读操作的大幅优化
4. 适当的放宽索引,可以优化局限于少数字段的查询性能
## 答案
全部都是
## 选项
### A
全部都不对
### B
```
1, 2, 3
```
### C
```
2, 3, 4
```
### D
```
2, 3
```
### E
```
3, 4
```
\ No newline at end of file
{
"node_id": "mysql-06bc5338054a40fc90b24333ee2b9125",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{ {
"node_id": "mysql-fbcc654d6a86452aa349d2ed6003adb6", "node_id": "mysql-fbcc654d6a86452aa349d2ed6003adb6",
"keywords": [], "keywords": ["show profile"],
"children": [], "children": [],
"export": [], "export": [],
"keywords_must": [], "keywords_must": [],
......
{
"type": "code_options",
"author": null,
"source": "bulk_insert.md",
"notebook_enable": false,
"exercise_id": "936ee1ecbd4a4b9aa795fa537e24f659"
}
\ No newline at end of file
# 批量写入
Joe 需要为数据组准备一个离线数据库,这个数据库的数据量很大。
下面这些措施中有哪些可以帮助 Joe 更快的写入这些数据?
1. 使用`ALTER TABLE t_table_name DISABLE KEYS;`禁用索引,完成工作后用`ALTER TABLE t_table_name ENABLE KEYS;`启用索引
2. 使用`SET UNIQUE_CHECKS = 0;`禁用唯一性检查,完成工作后用`SET UNIQUE_CHECKS = 1;`恢复唯一性检查
3. 使用`SET foreign_key_checks = 0;`禁用外键检查,完成工作后`SET foreign_key_checks = 1;`恢复外键检查
4. 使用`insert values(...),(...),(...)...`批量插入数据
5. 使用`LOAD DATA INFILE ‘data_file_path’ INTO TABLE table_name;`批量导入数据
6. 对 InnoDB 表使用 `SET autocommit = 0;` 禁用自动事务,完成工作后用 `SET autocommit = 1;`
## 答案
全部都对
## 选项
### A
```
1, 2, 3, 4, 5
```
### B
```
2, 3, 4, 5
```
### C
```
2, 3, 4, 6
```
### D
```
1, 2, 3, 4
```
### D
```
3, 4, 5, 6
```
### E
```
3, 4
```
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
"node_id": "mysql-4e93793f51a24f0eb00f7824ecc8929b", "node_id": "mysql-4e93793f51a24f0eb00f7824ecc8929b",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"bulk_insert.json"
],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
......
{ {
"node_id": "mysql-ff4222264013437da2214ff77ca92961", "node_id": "mysql-ff4222264013437da2214ff77ca92961",
"keywords": [], "keywords": ["delete", "performance", "优化", "删除"],
"children": [], "children": [],
"export": [], "export": [
"performance_delete.json"
],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
......
{
"type": "code_options",
"author": null,
"source": "performance_delete.md",
"notebook_enable": false,
"exercise_id": "105bda06ce03418aaad1422b61767cb6"
}
\ No newline at end of file
# 快速删除
Joe 需要删除数据分析库中 orders 表的数据,orders按时间分区,因为是分析部门离线使用,不需要考虑并发,下列哪些操作可以更快的删除这些数据?
1. 使用 `truncate from orders`;
2. 可以执行 `ALTER TABLE orders DROP PARTITION partition_name;` 删除指定分区
3. 去掉唯一约束然后 `delete from orders where 1=1`
4. 使用可写游标,一次一万行滚动删除
5. `drop table orders` 删除后重建
## 答案
```
1, 2, 5
```
## 选项
### A
全部选项都可以
### B
```
1, 2, 3, 4
```
### C
```
3, 4
```
### D
```
2, 3
```
### E
```
2, 3, 4
```
\ No newline at end of file
{
"node_id": "mysql-f2a76883814745b9979541ed4117754f",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
"node_id": "mysql-6d4f4d7aecfb4546a8163256859562e1", "node_id": "mysql-6d4f4d7aecfb4546a8163256859562e1",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"configuration.json"
],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
......
{
"type": "code_options",
"author": null,
"source": "configuration.md",
"notebook_enable": false,
"exercise_id": "b90270843de54822a1556cb47ca49394"
}
\ No newline at end of file
# 配置项优化
Joe 要帮助开发部优化交易数据库的性能,下面哪些优化是可能有帮助的?
1. 适当增大MySQL的最大连接数 max_connections, 提高并发响应能力。
2. 适当增大 table_cache,提高同时打开表的个数。此参数需根据业务需要有节制的上调
3. 适当增大 table_open_cache,提高数据表的缓存数量。
4. 适当调整 innodb_buffer_pool_size:此配置项决定着InnoDB存储引擎的数据表的数据和索引数据的最大缓冲区大小。一般可以分配80%的物理内存。
5. 适当增加 innodb_log_buffer_size,减少频繁的日志写操作。
6. 如果存在较多的排序操作,调整 sort_buffer_size:排序缓冲区的大小。
7. read_buffer_size:数据表的读缓冲区。适当增加此配置项的值,能够提高MySQL的并发读能力。
8. back_log:如果MySQL服务器需要在短时间内处理大量的连接请求,则可以适当增大此配置项的值。
9. thread_cache_size:MySQL缓存的数据库服务线程的最大线程数。当有大量客户端连接MySQL时,可以适当增大此配置项的值。
10. innodb_lock_wait_timeout:InnoDB存储引擎等待行锁的时间,默认值为50ms。对于实时要求高的应用,可以将此配置项的值适当调小。
## 答案
全部都是
## 选项
### A
```
1, 2, 3, 4, 5
```
### B
```
1, 2, 3, 4, 5, 6, 7, 8
```
### C
```
1, 2, 3, 4, 5, 6, 7, 8
```
### D
```
4, 5, 6, 7, 8
```
{ {
"node_id": "mysql-36d638345c1949f7bb032baf8d9f996e", "node_id": "mysql-36d638345c1949f7bb032baf8d9f996e",
"keywords": [], "keywords": [
"performance",
"performance schema",
"优化"
],
"children": [], "children": [],
"export": [], "export": [
"performance_schema.json"
],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
......
{
"type": "code_options",
"author": null,
"source": "performance_delete.md",
"notebook_enable": false,
"exercise_id": "cea8e3db523b4f1fb9a502e1d9c27d7b"
}
\ No newline at end of file
# # Performance Schema
Joe 为交易库开启了 Performance Schema 配置。那么对于交易数据库的优化,哪些是他应该关注的?
1.`performance_schema.events_waits_current` 活跃线程的执行操作
2.`performance_schema.file_summary_by_event_name` 获取被频繁使用的文件,特别是经常需要等待的文件
3.`performance.events_statements_summary_by_diges` 获取 MySQL 的统计信息
## 答案
所有都是。
## 选项
### A
所有都不是,performance_schema 中不包含这些信息,它们来自 Sys 数据库。
### B
```
1, 2
```
### C
```
2, 3
```
\ No newline at end of file
{
"node_id": "mysql-4a1bb52626b04dabac78af8eafea868e",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
"node_id": "mysql-3d5c8647b1674de18c8348454d16fee5", "node_id": "mysql-3d5c8647b1674de18c8348454d16fee5",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"sys.json"
],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": [],
"group": 0 "group": 0
......
{
"type": "code_options",
"author": null,
"source": "sys.md",
"notebook_enable": false,
"exercise_id": "ed53fabf084c4ceb99952f5196412b49"
}
\ No newline at end of file
# Sys 数据库
Joe 计划从交易数据库服务器的 sys 系统库获取一些优化线索,下列哪些操作是他需要关注的?
1. 通过 `SELECT * FROM sys.schema_unused_indexes` 找到未使用的索引
2. 通过 `SELECT * FROM sys.schema_redundant_indexes` 找到冗余索引
3. 通过 `SELECT * FROM sys.user_summary` 观察每用户资源消耗
4. 通过 `SELECT * FROM sys.host_summary` 观察每连接消耗
提示:交易数据库仅由DBA和应用程序连接,应用程序使用大量相同配置和登录信息的连接访
问数据库,交易系统访问数据库时,希望尽可能的快速、高并发、每个查询的时间尽可能短。
## 答案
```
1, 2, 4
```
## 选项
### A
所有都是
### B
```
3
```
### C
```
1, 3, 4
```
### C
```
2, 3, 4
```
\ No newline at end of file
{
"node_id": "mysql-715cc1f656df4b099d952145a53dd006",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册