Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong index in cell_at() of JoinTuple and redundant species when calling open() repeatedly #16

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/server/include/query_engine/structor/tuple/join_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class JoinedTuple : public Tuple
RC cell_at(int index, Value &value) const override
{
const int left_cell_num = left_->cell_num();
if (index > 0 && index < left_cell_num) {
if (index >= 0 && index < left_cell_num) {
return left_->cell_at(index, value);
}

Expand All @@ -68,4 +68,4 @@ class JoinedTuple : public Tuple
private:
Tuple *left_ = nullptr;
Tuple *right_ = nullptr;
};
};
1 change: 1 addition & 0 deletions src/server/include/query_engine/structor/tuple/row_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RowTuple : public Tuple
{
table_ = table;
table_alias_ = table_alias;
species_.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加一些注释来解释这个代码的含义吧 什么时候需要

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里直接 clear 是不是会造成内存泄漏,其实可以考虑把 species_ 换成 vector<unique_ptr<FieldExpr>>,用 RAII 管理内存?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里直接 clear 是不是会造成内存泄漏,其实可以考虑把 species_ 换成 vector<unique_ptr<FieldExpr>>,用 RAII 管理内存?

确实会,但你这个是小众场景,引入一个智能指针是不是没必要?
你可以手动维护一下指针的释放,然后判断一下如果species_不为空,再做对应的操作

this->species_.reserve(fields->size());
for (const FieldMeta &field : *fields) {
species_.push_back(new FieldExpr(table, &field));
Expand Down