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: add force copy ability of class Value; unmatch between IndexScanPhysicalOperator and index_->create_scanner #11

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/server/include/query_engine/parser/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Value
explicit Value(float val);
explicit Value(bool val);
explicit Value(const char *s, int len = 0);
explicit Value(const char *s, int len, bool force);
explicit Value(AttrType attrType);

Value(const Value &other) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class IndexScanPhysicalOperator : public PhysicalOperator
{
if (left_value != nullptr) {
left_value_ = *left_value;
left_null_ = false;
}
if (right_value != nullptr) {
right_value_ = *right_value;
right_null_ = false;
}
}

Expand Down Expand Up @@ -65,5 +67,7 @@ class IndexScanPhysicalOperator : public PhysicalOperator
Value right_value_;
bool left_inclusive_ = false;
bool right_inclusive_ = false;
bool left_null_ = true;
bool right_null_ = true;
std::vector<std::unique_ptr<Expression>> predicates_;
};
27 changes: 27 additions & 0 deletions src/server/query_engine/parser/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,33 @@ Value::Value(const char *s, int len /*= 0*/)
{
set_string(s, len);
}

/**
* force mean Force Copy from s
*/
Value::Value(const char *s, int len, bool force)
{
if(!force) {
set_string(s, len);
} else {
//为规避0带来的截断问题,我们先将其均置为1,并记录其位置以将其复原
char *data_tmp = new char[len];
std::vector<int> places_of_zeros;
for(int i = 0; i < len; i++) {
data_tmp[i] = s[i];
if(s[i] == 0) {
places_of_zeros.push_back(i);
data_tmp[i] = 1;
}
}
set_string(data_tmp, len);
//复原
for(int i = 0; i < places_of_zeros.size(); i++) {
str_value_[places_of_zeros[i]] = 0;
}
delete[] data_tmp;
}
}
Value::Value(AttrType attrType)
{
switch (attrType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ RC IndexScanPhysicalOperator::open(Trx *trx)
return RC::INTERNAL;
}

IndexScanner *index_scanner = index_->create_scanner(left_value_.data(),
left_value_.length(),
const char *left_key = left_null_ ? nullptr : left_value_.data();
const char *right_key = right_null_ ? nullptr : right_value_.data();
IndexScanner *index_scanner = index_->create_scanner(left_key,
left_value_.length(),
left_inclusive_,
right_value_.data(),
right_value_.length(),
right_key,
right_value_.length(),
right_inclusive_);
if(index_scanner == nullptr)
{
Expand Down
5 changes: 4 additions & 1 deletion src/server/storage_engine/recorder/table_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ const IndexMeta *TableMeta::index(const char *name) const
const IndexMeta *TableMeta::find_index_by_field(const char *field) const
{
for (const IndexMeta &index : indexes_) {
if (0 == strcmp(index.field(0), field)) {
// if (0 == strcmp(index.field(0), field)) {
// return &index;
// }
if (0 == strcmp(index.multi_fields(), field)) {
return &index;
}
}
Expand Down