Skip to content

Commit

Permalink
fix: wrong index in cell_at() of JoinTuple and redundant species when…
Browse files Browse the repository at this point in the history
… calling open() repeatedly (#16)

bug 1:  join tuple cannot be visited by cell_at() at position 0
bug 2: row tuple's schema will be double or triple initialized when
trying to reopen table scanner
  • Loading branch information
GuoKaku authored May 7, 2024
1 parent 1cfb3b5 commit a4537c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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;
};
};
16 changes: 12 additions & 4 deletions src/server/include/query_engine/structor/tuple/row_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ class RowTuple : public Tuple
RowTuple() = default;
virtual ~RowTuple()
{
for (FieldExpr *spec : species_) {
delete spec;
}
species_.clear();
_clear_species();
}

const TupleType tuple_type() const override { return RowTuple_Type; }
Expand All @@ -36,11 +33,22 @@ class RowTuple : public Tuple
this->bitmap_.init(record->data() + null_filed_meta->offset(), null_filed_meta->len());
}

void _clear_species(){
if(!species_.empty()){
for(auto& field_expr : species_){
delete field_expr; //clear()前先释放目前的fields
}
species_.clear();
}
}


void set_schema(const Table *table, const std::string &table_alias, const std::vector<FieldMeta> *fields)
{
table_ = table;
table_alias_ = table_alias;
this->species_.reserve(fields->size());
_clear_species(); //reopen时防止sepcies_就会积累多套重复的fields。
for (const FieldMeta &field : *fields) {
species_.push_back(new FieldExpr(table, &field));
species_[species_.size() - 1]->set_field_table_alias(table_alias);
Expand Down

0 comments on commit a4537c0

Please sign in to comment.