Skip to content

Commit 6389d2a

Browse files
nautaaevtroublehnwyllmm6607changchunCopilot
authored
Vldbss 2025(merge on demand) (#581)
### What problem were solved in this pull request? this PR is used to trig CI --------- Co-authored-by: evtrouble <105802875+evtrouble@users.noreply.github.com> Co-authored-by: wangyunlai <hnwyllmm@126.com> Co-authored-by: 6607changchun <84566142+6607changchun@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b759445 commit 6389d2a

File tree

71 files changed

+1990
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1990
-175
lines changed

.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ MacroBlockBegin: "
8181
END_CATCH_ERROR$"
8282
...
8383

84-

benchmark/pax_storage_concurrency_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class BenchmarkBase : public Fixture
117117
table_meta_->fields_[1].attr_len_ = 11;
118118
table_meta_->fields_[1].field_id_ = 1;
119119
handler_ = new RecordFileHandler(StorageFormat::PAX_FORMAT);
120-
rc = handler_->init(*buffer_pool_, log_handler_, table_meta_);
120+
rc = handler_->init(*buffer_pool_, log_handler_, table_meta_, nullptr);
121121
if (rc != RC::SUCCESS) {
122122
LOG_WARN("failed to init record file handler. rc=%s", strrc(rc));
123123
throw runtime_error("failed to init record file handler");

benchmark/record_manager_concurrency_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class BenchmarkBase : public Fixture
106106
}
107107

108108
handler_ = new RecordFileHandler(StorageFormat::ROW_FORMAT);
109-
rc = handler_->init(*buffer_pool_, log_handler_, nullptr);
109+
rc = handler_->init(*buffer_pool_, log_handler_, nullptr, nullptr);
110110
if (rc != RC::SUCCESS) {
111111
LOG_WARN("failed to init record file handler. rc=%s", strrc(rc));
112112
throw runtime_error("failed to init record file handler");

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function do_init
7878
git -C "deps/3rd/libevent" checkout 112421c8fa4840acd73502f2ab6a674fc025de37 || return
7979
# git submodule update --remote "deps/3rd/libevent" || return
8080
git -C "deps/3rd/jsoncpp" checkout 1.9.6 || return
81+
8182
current_dir=$PWD
8283

8384
MAKE_COMMAND="make --silent"
481 KB
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: 如何新增一种数据类型
3+
---
4+
5+
> 本文介绍如何新增一种数据类型。
6+
MiniOB 的数据类型系统采用分层设计,实现集中在[path](../../../src/observer/common)文件夹下,核心组件包括:
7+
1. Value 类:统一数据操作接口
8+
路径:src/observer/common/value.h
9+
作用:封装实际数据值,提供类型无关的操作方法
10+
2. Type 工具类:特定类型的操作实现
11+
路径:src/observer/common/type/
12+
作用:每种数据类型对应一个工具类,实现具体运算逻辑
13+
14+
以下示例展示 MiniOB 如何处理整数类型数据:
15+
```cpp
16+
// 假设解析器识别到整数 "1"
17+
int val = 1;
18+
Value value(val); // 封装为 Value 对象
19+
// 执行加法运算
20+
Value result;
21+
Value::add(value, value, result); // 调用加法接口
22+
// Value::add 方法内部会根据类型调用对应工具类
23+
// 对于 INT 类型,实际调用代码位于:
24+
// src/observer/common/type/integer_type.cpp
25+
```
26+
27+
# 若要新增一种数据类型(如 DATE),建议按以下步骤开发:
28+
1. 在 src/observer/common/type/attr_type.h 中添加新的类型枚举以及对应类型名
29+
2. 在 src/observer/common/type/data_type.cpp 中添加新的类型实例
30+
3. 在 src/observer/common/type/ 文件夹下,参照现有工具类,实现 DateType 工具类
31+
4. 在 Value 类中增加类型处理逻辑,支持date类型的分发,储存date类型值
32+
5. 必要情况下还需要增加新的词法规则(lex_sql.l)以及语法规则(yacc_sql.y),支持新类型关键字

docs/docs/design/miniob-realtime-analytic.md

Lines changed: 522 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
如图[image](images/miniob-sql-execution-process.png)
2+
3+
PlantUML时序图使用 https://www.plantuml.com/plantuml 生成
4+
代码如下:
5+
```cpp
6+
@startuml
7+
title SQL 执行流程时序图\n
8+
9+
skinparam sequence {
10+
ArrowColor #003366
11+
LifeLineBorderColor #003366
12+
LifeLineBackgroundColor #F0F8FF
13+
ParticipantBorderColor #003366
14+
ParticipantBackgroundColor #E6F7FF
15+
ParticipantFontColor #003366
16+
NoteBackgroundColor #FFF2E6
17+
NoteBorderColor #FFA940
18+
BoxPadding 20
19+
}
20+
21+
actor 客户端 as Client
22+
participant "Server" as Server
23+
participant "TaskHandler" as TaskHandler
24+
participant "SessionStage" as Session
25+
participant "ParseStage" as Parser
26+
participant "ResolveStage" as Resolver
27+
participant "OptimizeStage" as Optimizer
28+
participant "ExecuteStage" as Executor
29+
participant "ResultHandler" as Result
30+
31+
autonumber "<b>[000]"
32+
33+
Client -> Server: SQL命令(网络请求)
34+
note right: 1. 客户端发送SQL到服务器端口\n - 建立TCP连接\n - 传输SQL文本
35+
activate Server
36+
37+
Server -> TaskHandler: handle_event(communicator)
38+
activate TaskHandler
39+
note right: 2. 任务处理器初始化\n - 创建事件对象\n - 绑定通信器\n - 准备处理环境
40+
41+
TaskHandler -> Session: handle_request2(event)
42+
activate Session
43+
Session --> TaskHandler: 会话就绪
44+
deactivate Session
45+
note right Session: 3. 会话管理\n - 用户身份验证\n - 设置数据库上下文\n - 维护会话状态
46+
47+
group "SQL处理核心 (责任链模式)"
48+
TaskHandler -> Parser: handle_request(sql_event)
49+
activate Parser
50+
group "ParseStage.handle_request"
51+
Parser -> Parser: parse(sql.c_str())
52+
note right: 4.1 启动SQL解析\n - 准备解析环境
53+
Parser -> Parser: yylex_init_extra()
54+
note right: 4.2 初始化词法扫描器\n - 分配扫描器资源\n - 设置字符串缓冲区
55+
Parser -> Parser: yyparse(scanner)
56+
note right: 4.3 语法解析核心\n - Flex词法分析\n - Bison语法分析\n - 生成AST节点树
57+
Parser -> Parser: yylex_destroy()
58+
note right: 4.4 释放扫描器资源\n - 清理词法分析状态
59+
Parser --> TaskHandler: 返回AST
60+
end
61+
deactivate Parser
62+
note right: 5. 解析完成\n - 输出抽象语法树(AST)\n - 支持SELECT/INSERT等语句结构
63+
64+
TaskHandler -> Resolver: handle_request(sql_event)
65+
activate Resolver
66+
group "ResolveStage.handle_request"
67+
Resolver -> Resolver: Stmt::create_stmt()
68+
note right: 6.1 语句转换入口\n - 根据AST节点类型分发
69+
Resolver -> Resolver: 递归处理节点
70+
note right: 6.2 深度遍历语法树\n - 处理子表达式\n - 构建完整语句结构
71+
Resolver -> Resolver: 创建具体Stmt对象
72+
note right: 6.3 生成可执行语句\n - SelectStmt\n - InsertStmt\n - UpdateStmt等
73+
Resolver --> TaskHandler: 返回Stmt
74+
end
75+
deactivate Resolver
76+
note right: 7. 转换完成\n - AST→可执行Stmt对象\n - 完成语义分析
77+
78+
TaskHandler -> Optimizer: handle_request(sql_event)
79+
activate Optimizer
80+
group "OptimizeStage.handle_request"
81+
Optimizer -> Optimizer: create_logical_plan()
82+
note right: 8.1 创建初始逻辑计划\n - 扫描算子\n - 连接算子\n - 投影算子
83+
Optimizer -> Optimizer: logical_plan_generator.create()
84+
note right: 8.2 生成逻辑算子树\n - 递归处理Stmt对象
85+
86+
group "重写规则应用"
87+
Optimizer -> Optimizer: ComparisonSimplificationRule.rewrite()
88+
note right: 9.1 比较表达式简化\n 例: 1=1true\n 常量折叠优化
89+
Optimizer -> Optimizer: ConjunctionSimplificationRule.rewrite()
90+
note right: 9.2 连接表达式简化\n 例: false AND expr → false\n 短路逻辑优化
91+
Optimizer -> Optimizer: PredicateRewriteRule.rewrite()
92+
note right: 9.3 谓词重写\n 删除恒真表达式\n 简化条件结构
93+
Optimizer -> Optimizer: PredicatePushdownRewriter.rewrite()
94+
note right: 9.4 谓词下推\n 将过滤条件下推至扫描层\n 减少中间结果集
95+
end
96+
97+
Optimizer -> Optimizer: optimize()
98+
note right: 10. 基于代价优化\n - 选择最优连接顺序\n - 索引选择\n - 访问路径优化
99+
100+
Optimizer -> Optimizer: generate_physical_plan()
101+
alt 向量模型
102+
Optimizer -> Optimizer: physical_plan_generator.create_vec()
103+
note right: 11.1 向量化执行计划\n - 批量处理(1024行/批)\n - 列式内存布局\n - 现代OLAP优化
104+
else 火山模型
105+
Optimizer -> Optimizer: physical_plan_generator.create()
106+
note right: 11.2 迭代式执行计划\n - 逐行处理\n - next()接口模型\n - 传统OLTP优化
107+
end
108+
Optimizer --> TaskHandler: 返回执行计划
109+
end
110+
deactivate Optimizer
111+
note right: 12. 优化完成\n - 生成物理执行计划\n - 准备执行环境
112+
113+
TaskHandler -> Executor: handle_request(sql_event)
114+
activate Executor
115+
group "ExecuteStage.handle_request"
116+
alt 有物理算子(DML)
117+
Executor -> Executor: handle_request_with_physical_operator()
118+
note right: 13.1 DML执行路径\n - SELECT: 执行查询\n - INSERT: 插入数据\n - DELETE: 删除数据
119+
Executor --> TaskHandler: DML结果
120+
else 无物理算子(DDL)
121+
Executor -> Executor: command_executor.execute()
122+
note right: 13.2 DDL执行路径\n - CREATE TABLE\n - CREATE INDEX\n - ALTER TABLE
123+
Executor --> TaskHandler: DDL结果
124+
end
125+
end
126+
deactivate Executor
127+
note right: 14. 执行完成\n - 数据变更生效\n - 查询结果就绪
128+
end
129+
130+
TaskHandler -> Result: write_result(event)
131+
activate Result
132+
133+
group "ResultHandler处理"
134+
alt 无结果集(DDL/更新)
135+
Result -> Result: write_result_internal()
136+
note right: 15.1 简单结果处理\n - 操作状态(成功/失败)\n - 影响行数统计
137+
Result --> Client: 状态码
138+
else 有结果集(查询)
139+
Result -> Result: sql_result->open()
140+
note right: 15.2 初始化结果集\n - 准备数据缓冲区\n - 获取表头信息
141+
Result -> Result: 打印表头
142+
note right: 15.3 输出列信息\n - 列名\n - 数据类型\n - 列宽
143+
144+
alt 向量模型
145+
Result -> Result: write_chunk_result()
146+
note right: 16.1 向量化结果返回\n - 批量传输数据块\n - 高效网络利用\n - 减少序列化开销
147+
Result --> Client: 批量数据
148+
else 火山模型
149+
Result -> Result: write_tuple_result()
150+
note right: 16.2 迭代式结果返回\n - 逐行获取数据\n - 流式传输模式
151+
loop 逐行处理
152+
Result --> Client: 单行数据
153+
end
154+
end
155+
end
156+
end
157+
158+
Result --> TaskHandler: 完成
159+
deactivate Result
160+
161+
TaskHandler --> Server: 处理完成
162+
deactivate TaskHandler
163+
164+
Server --> Client: 最终确认
165+
deactivate Server
166+
note right: 17. 完整流程结束\n - 释放所有资源\n - 维护连接状态\n - 准备接收下一条SQL
167+
168+
@enduml
169+
```

docs/docs/how_to_build.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,32 @@ git config --global core.autocrlf false
160160
关于该问题的更多细节,请参考[问题来源](https://ask.oceanbase.com/t/topic/35604437/7)
161161
关于该问题的进一步分析,请参考[Linux系统下执行sudo命令环境变量失效现象](https://zhuanlan.zhihu.com/p/669332689)
162162
也可以将cmake所在路径添加到sudo的PATH变量中来解决上述问题,请参考[sudo命令下环境变量实效的解决方法](https://www.cnblogs.com/xiao-xiaoyang/p/17444600.html)
163+
164+
165+
### 3. Could not find a package configuration file provided by "Libevent"
166+
在执行build.sh脚本时,遇到下面的错误
167+
![cmake error](images/miniob-build-libevent.png)
168+
169+
通常是因为cmake版本原因(版本太高?)导致libevent在init阶段没有编译成功。
170+
171+
***解决方法:***
172+
173+
[text](../../deps/3rd/libevent/CMakeLists.txt) 中将cmake的最低版本设置
174+
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
175+
改为
176+
cmake_minimum_required(VERSION 3.1...3.8 FATAL_ERROR)
177+
之后重新执行
178+
```bash
179+
sudo bash build.sh init
180+
```
181+
182+
如果你成功解决libevent的问题,你大概率会遇到另一个错误:
183+
![cmake error](images/miniob-build-jsoncpp.png)
184+
需要在[text](../../deps/3rd/jsoncpp/jsoncppConfig.cmake.in)中将cmake策略
185+
cmake_policy(VERSION 3.0)
186+
改为
187+
cmake_policy(VERSION 3.0...3.8)
188+
之后重新执行
189+
```bash
190+
sudo bash build.sh init
191+
```
78.6 KB
Loading

0 commit comments

Comments
 (0)