提交 924ee711 编写于 作者: M Mars Liu

on tree

上级 7e2cfb8f
{
"node_id": "mysql-5b582c1fda1f47a481bda193dc22a828",
"node_id": "mysql-5ad1d51a05444926ab17e9868e02415b",
"keywords": [],
"children": [],
"export": [],
......
{
"node_id": "mysql-75854dcb83984276b11cca6f5a39a18c",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-1f86031fd0414f67b5e37e9fce981397",
"keywords": ["drop"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-d3611482eecd4055816df4b1dd9ff90d",
"keywords": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "backup.md",
"notebook_enable": false,
"exercise_id": "fddaa23fdd8343b184d563f08c13eff0"
}
\ No newline at end of file
# 高可靠备份
你的团队有一个非常重要的业务数据库,希望在需要时,可以重建它在一周内任意某个时间点的状态。下列规划中不必要的是:
1. 对 WAL 日志建立备份,按时间保留所有的 WAL 文件作为增量备份
2. 每天做一次冷备
3. 需要重现时,用离目标时间点最近的前一次冷备恢复一个数据库节点,启动为 standby 状态,用对应的 wal 恢复。
4. 建立流备份节点
5. 每天非高峰期将数据库离线,完整复制一份数据区目录
## 答案
```
4, 5
```
## 选项
### A
```
1, 2
```
### B
```
3
```
### C
```
以上所有工作都需要,没有多余项
```
### D
```
2, 4
```
\ No newline at end of file
{
"node_id": "mysql-64d1c4fd8bc845d4900dfdfe1fea4cb9",
"keywords": [
"standby",
"热备份",
"高可用",
"流复制"
],
"children": [],
"export": [
"standby.json",
"backup.json"
],
"keywords_must": [
"standby"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "standby.md",
"notebook_enable": false,
"exercise_id": "3f75060041014897af51ae8fc56a9c65"
}
\ No newline at end of file
# standby
关于 PG Standby,错误的是:
## 答案
复制节点需要有主节点的超级用户权限。
## 选项
### A
Hot standby 是通过同步 WAL 实现的。
### B
从节点处于制度状态
### C
可以设置从节点切换为主节点的超时阈值
### D
从节点会保持与主节点的数据和结构一致
### E
从节点不需要和主节点保持长连接
### F
从节点不需要和主节点硬件环境一致
\ No newline at end of file
{
"node_id": "mysql-f00ed1bb1dac4cbebb090e6423aaa8a1",
"keywords": [
"standby",
"高可用",
"流复制",
"wal"
],
"children": [],
"export": [
"stream.json"
],
"keywords_must": [
"流式复制",
"流复制"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "stream.md",
"notebook_enable": false,
"exercise_id": "ffc0e766b5dd440fa8e136fc19494b56"
}
\ No newline at end of file
# 流式复制
关于流式复制,错误的是:
## 答案
流式复制的主节点损坏,会导致订阅节点也损坏。
## 选项
### A
订阅数据流的需要特定的复制角色
### B
订阅节点可以作为只读的从节点,提供读写分离
### C
主节点崩溃,子节点会将自己切换为独立工作状态
### D
节点间传输的是 wal 数据流
### E
主从节点的硬件配置可以不一致
### F
可以配置多级订阅
### G
可以多个从节点订阅一个主节点
\ No newline at end of file
{
"node_id": "mysql-a788c4767113412b811eee21ad298404",
"keywords": [
"外部数据连接",
"fdw"
],
"children": [],
"export": [
"fdw.json"
],
"keywords_must": [
"外部数据连接",
"fdw"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "fdw.md",
"notebook_enable": false,
"exercise_id": "5a72d037bbac49b88b3b17864335b29d"
}
\ No newline at end of file
# 外部数据源
RDVD 公司有一个 Oracle 数据库和一个PG数据库,现在需要每天汇总一次 PG 中的订单表和 oracle 中的客户信息表,从中生成一份
报表。现在你想在尽量不增加冗余数据的前提下,在PG服务上每天执行一次简单的查询任务来生成报表,那么应该:
## 答案
* 在 PG 数据库建立一个 fdw 数据源,连接 Oracle 数据库
* 在 PG 服务器中建立一个视图, 对客户信息表进行的查询变成一个 PG 查询
* 基于客户信息视图和订单表生成每日报表
## 选项
### 异构平台无法直接复制,且复制节点会影响功能
* 设置 PG 为 Oracle 的复制节点
* 订阅 Oracle 的变更流
### 不可靠的方法
* 用一个定时任务复制 Oracle 中的客户信息变更
* 写入 PG 数据库
### 低效且占用空间
* 在 PG 服务器上建一个同构的客户表
* 在 Oracle 服务器上写一个触发器
* 将客户信息写入 PostgreSQL 数据库
\ No newline at end of file
{
"node_id": "mysql-6c50f07505954be1b61cf0bf6365536d",
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "mysql-5b21eb9eb2f446288d80c6bd65a6416f",
"keywords": ["index"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-db7153c698e8442eb5f71e8ec2f2e6cd",
"keywords": ["unique"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-aa2a0a0cc22a47ac89cdcc9b56951a02",
"keywords": [
"gis",
"地理信息"
],
"children": [],
"export": [
"gis.json"
],
"keywords_must": [
"gis",
"几何"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "gis.md",
"notebook_enable": false,
"exercise_id": "3ea8a37e3cc540de85f3ecee269adc47"
}
\ No newline at end of file
# 邻近查找
我们有一个简化的表结构如下:
```postgresql
create table city
(
id serial8,
city text,
poi point
);
create index idx_tbl_point on city using gist (poi) with (buffering = on);
```
要查找给定的点位于哪个城市,或者离哪个城市最近,应该是下列哪一项?
## 答案
```postgresql
select city, poi <-> point($1, $2) dist
from city
where poi <-> point($1, $2) < 100
order by poi <-> point($1, $2)
limit 1;
```
## 选项
### A
```postgresql
select city, poi <-> point($1, $2) dist
from city
where poi <-> point($1, $2) < 100
order by poi <-> point($1, $2) desc
limit 1;
```
### B
```postgresql
select *, poi <-> point($1, $2) dist
from city
where poi <-> point($1, $2) < 100
limit 1;
```
### C
```postgresql
select *, poi - point($1, $2) dist
from city
where poi - point($1, $2) < 100
order by poi - point($1, $2)
limit 1;
```
### D
```postgresql
select *, abs(poi - point($1, $2)) dist
from city
where abs(poi - point($1, $2)) < 100
order by abs(poi - point($1, $2))
limit 1;
```
\ No newline at end of file
{
"node_id": "mysql-811d683bd15b4e0ab91c3507199acfbb",
"keywords": [
"json",
"jsonb"
],
"children": [],
"export": [
"json.json",
"match.json",
"tags.json"
],
"keywords_must": [
"json",
"jsonb"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "json.md",
"notebook_enable": false,
"exercise_id": "0ccc11bb1a0847309c3d196024bebc41"
}
\ No newline at end of file
# JSON 和 JSONB 类型
关于 JSON 和 JSONB 类型,哪句话是错的?
## 答案
JSON 就是 文本类型的封装,JSONB 是 JSON 的二进制压缩格式,JSON 和 JSONB 的功能与 TEXT 类型一样。
## 选项
### A
JSONB 是推荐的 JSON 字段类型,更为高效。
### B
JSONB 可以通过 GIST 倒排索引优化对内部结构的查询。
### C
PostgreSQL JSON 和 JSONB 支持 JSON PATH表达式
### D
JSONB 和 文本可以有效兼容
### E
JSON 和 JSONB 与其它类型一样,不能部分修改,只能作为整体插入或更新
{
"type": "code_options",
"author": "ccat",
"source": "match.md",
"notebook_enable": false,
"exercise_id": "44a335429a10417da1133cfbcaca3e24"
}
\ No newline at end of file
# 匹配
表 book 的 meta 有类似如下结构:
```json
{
"author": [
"Mars Liu",
"Milly Lee"
],
"ISBN": "xxxx-xxxx-xxxxxx",
"version": 1
}
```
该字段有 gist 索引。
如果我们想高效率的找到所有作者包含 Jim Gray 的书,应该如何查询?
## 答案
```postgresql
select * from book where meta @> '{"author": ["Jim Gray"]}'::jsonb;
```
## 选项
### A
```postgresql
select * from book where meta @> '["Jim Gray"]'::jsonb;
```
### A
```postgresql
select * from book where 'Jim Gray' in meta;
```
### B
```postgresql
select * from book where meta::text like '%Jim Gray%';
```
### C
```postgresql
select * from book having meta @> 'Jim Gray'
```
### D
```postgresql
select * from book where 'Jim Gray' in (meta #>> 'author');
```
{
"type": "code_options",
"author": "ccat",
"source": "tags.md",
"notebook_enable": false,
"exercise_id": "d2a6e1d752af4358bd1055d5b6377443"
}
\ No newline at end of file
# 标签
现有一个表 sku:
```postgresql
create table sku(
id serial primary key ,
name text,
meta jsonb default '{}'::jsonb,
tags jsonb default '[]'::jsonb
)
```
我们希望查找包含所有给定tag的商品,那么查询应该是:
## 答案
```postgresql
select id, name, meta, tags from sku where tags @> $1;
```
## 选项
### A
```postgresql
select id, name, meta, tags from sku where tags = $1;
```
### B
```postgresql
select id, name, meta, tags from sku where tags::text = $1;
```
### C
```postgresql
select id, name, meta, tags from sku where $1 in tags;
```
### D
```postgresql
select id, name, meta, tags from sku where tags in $1;
```
{
"node_id": "mysql-0f54b3fe17b04a59a2eed504aa280bbe",
"keywords": [
"函数",
"过程",
"function",
"produce"
],
"children": [],
"export": [
"distinct.json"
],
"keywords_must": [
"聚合函数",
"json函数",
[
"数组",
"函数"
],
""
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "distinct.md",
"notebook_enable": false,
"exercise_id": "cc79e0c25a79496b943fe3cf9a706464"
}
\ No newline at end of file
# 去重
下列函数中,有一个实现了合并两个 jsonb 对象并对其去重,是哪一项?
## 答案
```postgresql
create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as
$$
select jsonb_agg(distinct (value))
from jsonb_array_elements(a || b)
$$ language sql
```
## 选项
### A
```postgresql
create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as
$$
select a || b
$$ language sql
```
### B
```postgresql
create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as
$$ return jsonb_agg(distinct(value)) from jsonb_array_elements(a||b)
$$
language sql
```
### C
```postgresql
create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as
$$ return next jsonb_agg(distinct(value)) from jsonb_array_elements(a||b)
$$
language sql
```
### D
```postgresql
create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as
$$
select a + b;
$$ language sql
```
\ No newline at end of file
{
"node_id": "mysql-f715af01120d4fe0be0a633776f6d261",
"keywords": [
"视图",
"view"
],
"children": [],
"export": [
"view.json"
],
"keywords_must": [
"视图",
"view"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "view.md",
"notebook_enable": false,
"exercise_id": "2c4e09ba5fa549c2a6bc0e7f73bacb3c"
}
\ No newline at end of file
# 视图
SmartMarket 公司的数据分析师,每天要执行一个固定的复杂查询,生成每日报表。我们准备将其创建为视图,这能够解决:
1. 简化查询
2. 降低查询时死锁的风险
3. 大幅优化查询性能
4. 限制权限
## 答案
1, 4
## 选项
### A
1. 2, 3, 4
### B
1, 2, 3
### C
2, 3
### D
3, 4
\ No newline at end of file
{
"node_id": "mysql-ed11f5b80bef4dbd86b5e1c5a091413d",
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "mysql-3574b2e5c9ca475789d9d582d7726906",
"keywords": ["show status"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-a42f617d4eb54aabbc649bdde4485117",
"keywords": ["explain"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-f0b12126dd3e4be09010a308a822bc32",
"keywords": ["show profile"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-626f1ca763b344558b3a5eefdb4885a2",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-4d5cfac3820648ffbe0b382898d9cf26",
"keywords": ["subquery"],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-310130dd922d4e2b832891cc0e157cbf",
"keywords": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
......@@ -62,6 +62,16 @@
"node_id": "mysql-c6fb4b9d5c13492289fd14d06911c1e5",
"keywords": [],
"children": [
{
"数据库编码": {
"node_id": "mysql-401a4084d56c4123afa3ced3aa0e5e98",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
},
{
"安装": {
"node_id": "mysql-95d0b7e5493e478f85ca49a77a13d194",
......@@ -374,7 +384,9 @@
{
"DISTINCT": {
"node_id": "mysql-153ce0dadc824af98de199f193c8c75c",
"keywords": [],
"keywords": [
"distinct"
],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
......@@ -679,57 +691,36 @@
"keywords": [],
"children": [
{
"集群和复制": {
"node_id": "mysql-6c50f07505954be1b61cf0bf6365536d",
"生成列": {
"node_id": "mysql-d3611482eecd4055816df4b1dd9ff90d",
"keywords": [],
"children": [
{
"standby": {
"node_id": "mysql-64d1c4fd8bc845d4900dfdfe1fea4cb9",
"keywords": [
"standby",
"热备份",
"高可用",
"流复制"
],
"创建生成列": {
"node_id": "mysql-5ad1d51a05444926ab17e9868e02415b",
"keywords": [],
"children": [],
"keywords_must": [
"standby"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
},
{
"流式复制集群": {
"node_id": "mysql-f00ed1bb1dac4cbebb090e6423aaa8a1",
"keywords": [
"standby",
"高可用",
"流复制",
"wal"
],
"修改生成列": {
"node_id": "mysql-75854dcb83984276b11cca6f5a39a18c",
"keywords": [],
"children": [],
"keywords_must": [
"流式复制",
"流复制"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
},
{
"fdw": {
"node_id": "mysql-a788c4767113412b811eee21ad298404",
"keywords": [
"外部数据连接",
"fdw"
],
"删除生成列": {
"node_id": "mysql-1f86031fd0414f67b5e37e9fce981397",
"keywords": [],
"children": [],
"keywords_must": [
"外部数据连接",
"fdw"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
......@@ -741,77 +732,26 @@
}
},
{
"高级数据类型": {
"node_id": "mysql-ed11f5b80bef4dbd86b5e1c5a091413d",
"索引": {
"node_id": "mysql-5b56965051d342849d665acb5f55a734",
"keywords": [],
"children": [
{
"几何类型和GIS": {
"node_id": "mysql-aa2a0a0cc22a47ac89cdcc9b56951a02",
"keywords": [
"gis",
"地理信息"
],
"children": [],
"keywords_must": [
"gis",
"几何"
],
"keywords_forbid": [],
"group": 0
}
},
{
"JSON和JSONB": {
"node_id": "mysql-811d683bd15b4e0ab91c3507199acfbb",
"keywords": [
"json",
"jsonb"
],
"children": [],
"keywords_must": [
"json",
"jsonb"
],
"keywords_forbid": [],
"group": 0
}
},
{
"函数": {
"node_id": "mysql-0f54b3fe17b04a59a2eed504aa280bbe",
"keywords": [
"函数",
"过程",
"function",
"produce"
],
"普通索引": {
"node_id": "mysql-5b21eb9eb2f446288d80c6bd65a6416f",
"keywords": [],
"children": [],
"keywords_must": [
"聚合函数",
"json函数",
[
"数组",
"函数"
],
""
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
},
{
"视图": {
"node_id": "mysql-f715af01120d4fe0be0a633776f6d261",
"keywords": [
"视图",
"view"
],
"唯一索引": {
"node_id": "mysql-db7153c698e8442eb5f71e8ec2f2e6cd",
"keywords": [],
"children": [],
"keywords_must": [
"视图",
"view"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
......@@ -1026,8 +966,8 @@
"keywords": [],
"children": [
{
"数据库编码": {
"node_id": "mysql-401a4084d56c4123afa3ced3aa0e5e98",
"视图的维护": {
"node_id": "mysql-95a29a6a448849029d548393bbdf283e",
"keywords": [],
"children": [],
"keywords_must": [],
......@@ -1036,8 +976,8 @@
}
},
{
"索引": {
"node_id": "mysql-5b56965051d342849d665acb5f55a734",
"物化视图": {
"node_id": "mysql-9e6db7d333c348c99d943774664792a7",
"keywords": [],
"children": [],
"keywords_must": [],
......@@ -1046,8 +986,29 @@
}
},
{
"JSON": {
"node_id": "mysql-5b582c1fda1f47a481bda193dc22a828",
"触发器的维护": {
"node_id": "mysql-72119f005a874aa2a67095952040f45f",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
},
{
"查询优化": {
"node_id": "mysql-310130dd922d4e2b832891cc0e157cbf",
"keywords": [],
"children": [
{
" SHOW STATUS": {
"node_id": "mysql-3574b2e5c9ca475789d9d582d7726906",
"keywords": [],
"children": [],
"keywords_must": [],
......@@ -1056,8 +1017,20 @@
}
},
{
"视图的维护": {
"node_id": "mysql-95a29a6a448849029d548393bbdf283e",
" EXPLAIN": {
"node_id": "mysql-a42f617d4eb54aabbc649bdde4485117",
"keywords": [
"explain"
],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
}
},
{
" SHOW PROFILE": {
"node_id": "mysql-f0b12126dd3e4be09010a308a822bc32",
"keywords": [],
"children": [],
"keywords_must": [],
......@@ -1066,8 +1039,8 @@
}
},
{
"物化视图": {
"node_id": "mysql-9e6db7d333c348c99d943774664792a7",
" PT-QUERY-DIGEST分析查询": {
"node_id": "mysql-626f1ca763b344558b3a5eefdb4885a2",
"keywords": [],
"children": [],
"keywords_must": [],
......@@ -1076,8 +1049,8 @@
}
},
{
"触发器的维护": {
"node_id": "mysql-72119f005a874aa2a67095952040f45f",
"子查询优化": {
"node_id": "mysql-4d5cfac3820648ffbe0b382898d9cf26",
"keywords": [],
"children": [],
"keywords_must": [],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册