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

feat(stonedb): Improve the readability of stonedb(#11) #27

Merged
merged 4 commits into from
Jun 19, 2022
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
4 changes: 3 additions & 1 deletion storage/stonedb/common/common_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ constexpr double MINUS_INF_DBL = DBL_MAX * -1;
constexpr int64_t PLUS_INF_64 = 0x7FFFFFFFFFFFFFFFULL;
constexpr int64_t MINUS_INF_64 = 0x8000000000000000ULL;
constexpr int64_t NULL_VALUE_64 = 0x8000000000000001ULL;
constexpr int NULL_VALUE_32 = 0x80000000;
constexpr int32_t NULL_VALUE_32 = 0x80000000;
constexpr short NULL_VALUE_SH = -32768;
constexpr char NULL_VALUE_C = -128;
constexpr uint32_t NULL_VALUE_U = 0xFFFFFFFC;
constexpr int64_t MAX_ROW_NUMBER = 0x00007FFFFFFFFFFFULL; // 2^47 - 1

constexpr int64_t SDB_BIGINT_MAX = PLUS_INF_64 - 1;
constexpr int64_t SDB_BIGINT_MIN = NULL_VALUE_64;

Expand All @@ -96,6 +97,7 @@ constexpr int64_t SDB_BIGINT_MIN = NULL_VALUE_64;
#define SDB_TINYINT_MIN (-127)
#define SDB_SMALLINT_MAX ((1 << 15) - 1)
#define SDB_SMALLINT_MIN (-((1 << 15) - 1))

#define PACK_INVALID 0
#define FIELD_MAXLENGTH 65535
#define SHORT_MAX 65535
Expand Down
2 changes: 1 addition & 1 deletion storage/stonedb/core/column_bin_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ColumnBinEncoder::~ColumnBinEncoder() {
bool ColumnBinEncoder::PrepareEncoder(vcolumn::VirtualColumn *_vc, vcolumn::VirtualColumn *_vc2) {
if (_vc == NULL) return false;
bool nulls_possible = false;
if (!ignore_nulls) nulls_possible = _vc->NullsPossible() || (_vc2 != NULL && _vc2->NullsPossible());
if (!ignore_nulls) nulls_possible = _vc->IsNullsPossible() || (_vc2 != NULL && _vc2->IsNullsPossible());
vc = _vc;
ColumnType vct = vc->Type();
ColumnType vct2 = _vc2 ? _vc2->Type() : ColumnType();
Expand Down
4 changes: 2 additions & 2 deletions storage/stonedb/core/condition_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void ConditionEncoder::TransformWithRespectToNulls() {
return;
}

bool nulls_only = desc->attr.vc->RoughNullsOnly();
bool nulls_possible = (additional_nulls || desc->attr.vc->NullsPossible());
bool nulls_only = desc->attr.vc->IsRoughNullsOnly();
bool nulls_possible = (additional_nulls || desc->attr.vc->IsNullsPossible());

if (desc->op == common::Operator::O_IS_NULL) {
if (!nulls_possible || attr->NoObj() == 0)
Expand Down
5 changes: 3 additions & 2 deletions storage/stonedb/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include <sys/syscall.h>

#include <ctime>
#include <signal.h>
#include <time.h>

#include "compilation_tools.h"
#include "core/compiled_query.h"
Expand All @@ -30,6 +30,7 @@

namespace stonedb {
namespace core {

int optimize_select(THD *thd, TABLE_LIST *tables, uint wild_num, List<Item> &fields, Item *conds, uint og_num,
ORDER *order, ORDER *group, Item *having, ulong select_options, select_result *result,
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex, int &optimize_after_sdb, int &free_join);
Expand Down
8 changes: 4 additions & 4 deletions storage/stonedb/core/groupby_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ bool GroupByWrapper::AggregatePackInOneGroup(int attr_no, MIIterator &mit, int64
int64_t factor) {
bool no_omitted = (rows_in_pack == mit.GetPackSizeLeft());
bool aggregated_roughly = false;
if (virt_col[attr_no] && virt_col[attr_no]->GetNoNulls(mit) == mit.GetPackSizeLeft() &&
if (virt_col[attr_no] && virt_col[attr_no]->GetNumOfNulls(mit) == mit.GetPackSizeLeft() &&
gt.AttrAggregator(attr_no)->IgnoreNulls())
return true; // no operation needed - the pack is ignored
if (!gt.AttrAggregator(attr_no)->PackAggregationDistinctIrrelevant() && gt.AttrDistinct(attr_no) &&
Expand Down Expand Up @@ -342,7 +342,7 @@ bool GroupByWrapper::AggregatePackInOneGroup(int attr_no, MIIterator &mit, int64
if (gt.AttrAggregator(attr_no)->PackAggregationNeedsSize())
gt.AttrAggregator(attr_no)->SetAggregatePackNoObj(SafeMultiplication(rows_in_pack, factor));
if (gt.AttrAggregator(attr_no)->PackAggregationNeedsNotNulls() && virt_col[attr_no]) {
int64_t no_nulls = virt_col[attr_no]->GetNoNulls(mit);
int64_t no_nulls = virt_col[attr_no]->GetNumOfNulls(mit);
if (no_nulls == common::NULL_VALUE_64)
return false; // aggregation no longer possible
else
Expand Down Expand Up @@ -441,7 +441,7 @@ bool GroupByWrapper::PackWillNotUpdateAggregation(int i, MIIterator &mit) // fa
gt.UpdateAttrStats(i); // Warning: slow if there is a lot of groups involved

// Statistics of data pack:
if (virt_col[i]->GetNoNulls(mit) == mit.GetPackSizeLeft()) return true; // nulls only - omit pack
if (virt_col[i]->GetNumOfNulls(mit) == mit.GetPackSizeLeft()) return true; // nulls only - omit pack

if (gt.AttrAggregator(i)->PackAggregationNeedsMin()) {
int64_t i_min = virt_col[i]->GetMinInt64(mit);
Expand Down Expand Up @@ -472,7 +472,7 @@ bool GroupByWrapper::DataWillNotUpdateAggregation(int i) // false, if counters
gt.UpdateAttrStats(i); // Warning: slow if there is a lot of groups involved

// Statistics of the whole data:
if (virt_col[i]->RoughNullsOnly()) return true; // nulls only - omit pack
if (virt_col[i]->IsRoughNullsOnly()) return true; // nulls only - omit pack

if (gt.AttrAggregator(i)->PackAggregationNeedsMin()) {
int64_t i_min = virt_col[i]->RoughMin();
Expand Down
4 changes: 2 additions & 2 deletions storage/stonedb/core/joiner_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ int64_t JoinerHash::MatchDim(MINewContents &new_mind, MIIterator &mit) {
omit_this_packrow = true;
break;
}
if (other_cond_exist || local_min != local_max || vc2[i]->NullsPossible()) {
if (other_cond_exist || local_min != local_max || vc2[i]->IsNullsPossible()) {
packrow_uniform = false;
}
}
Expand Down Expand Up @@ -687,7 +687,7 @@ int64_t JoinerHash::NewMatchDim(MINewContents *new_mind1, MIUpdatingIterator *ta
omit_this_packrow = true;
break;
}
if (other_cond_exist || local_min != local_max || vc2[i]->NullsPossible()) {
if (other_cond_exist || local_min != local_max || vc2[i]->IsNullsPossible()) {
packrow_uniform = false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions storage/stonedb/core/joiner_mapped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void JoinerMapped::ExecuteJoinConditions(Condition &cond) {
}
int64_t local_min = common::MINUS_INF_64;
int64_t local_max = common::PLUS_INF_64;
if (vc2->GetNoNulls(mit) == mit.GetPackSizeLeft()) {
if (vc2->GetNumOfNulls(mit) == mit.GetPackSizeLeft()) {
omit_this_packrow = true;
} else {
local_min = vc2->GetMinInt64(mit);
Expand All @@ -129,7 +129,7 @@ void JoinerMapped::ExecuteJoinConditions(Condition &cond) {
}
}
packrows_matched++;
bool roughly_all = (vc2->GetNoNulls(mit) == 0 && map_function->CertainValues(local_min, local_max));
bool roughly_all = (vc2->GetNumOfNulls(mit) == 0 && map_function->CertainValues(local_min, local_max));
if (single_filter_dim != -1 && roughly_all) {
if (new_mind.CommitPack(mit.GetCurPackrow(single_filter_dim))) { // processed as a pack
joined_tuples += mit.GetPackSizeLeft();
Expand Down Expand Up @@ -247,7 +247,7 @@ int64_t JoinerParallelMapped::ExecuteMatchLoop(std::shared_ptr<MultiIndexBuilder
vc->UnlockSourcePacks();
throw common::KilledException();
}
if (vc->GetNoNulls(mit) == mit.GetPackSizeLeft()) {
if (vc->GetNumOfNulls(mit) == mit.GetPackSizeLeft()) {
omit_this_packrow = true;
} else {
if (map_function->ImpossibleValues(vc->GetMinInt64(mit), vc->GetMaxInt64(mit))) {
Expand Down Expand Up @@ -432,7 +432,7 @@ bool OffsetMapFunction::Init(vcolumn::VirtualColumn *vc, MIIterator &mit) {
key_table_max == common::PLUS_INF_64 || key_table_max == common::NULL_VALUE_64)
return false;
int64_t span = key_table_max - key_table_min + 1;
if (span < 0 || size_t(span) > 32_MB || (span < mit.NoTuples() && !vc->NullsPossible())) return false;
if (span < 0 || size_t(span) > 32_MB || (span < mit.NoTuples() && !vc->IsNullsPossible())) return false;

key_status.resize(span, 255);

Expand Down Expand Up @@ -513,4 +513,4 @@ bool MultiMapsFunction::Init(vcolumn::VirtualColumn *vc, MIIterator &mit) {
return true;
}
} // namespace core
} // namespace stonedb
} // namespace stonedb
4 changes: 2 additions & 2 deletions storage/stonedb/core/joiner_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ bool JoinerSortWrapper::PackPossible(vcolumn::VirtualColumn *v, MIIterator &mit)
// Note: we are always checking "traversed < matched" condition. If ">" is
// needed, we are encoding values as for decreasing order. Assuming v is
// "matched" (the second) virtual column
if (!watch_matched && v->GetNoNulls(mit) == mit.GetPackSizeLeft()) return false;
if (!watch_matched && v->GetNumOfNulls(mit) == mit.GetPackSizeLeft()) return false;
if (min_traversed == NULL || v->Type().IsLookup())
return true;
else if (v->Type().IsString()) {
Expand Down Expand Up @@ -534,4 +534,4 @@ int64_t JoinerSortWrapper::GetOuterIndex(int cache_position,
return ind_value;
}
} // namespace core
} // namespace stonedb
} // namespace stonedb
8 changes: 4 additions & 4 deletions storage/stonedb/core/pack_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void PackInt::LoadValuesDouble(const loader::ValueCache *vc, const std::optional
}
auto new_min = std::min(vc->MinDouble(), dpn->min_d);
auto new_max = std::max(vc->MaxDouble(), dpn->max_d);
auto new_nr = dpn->nr + vc->NoValues();
auto new_nr = dpn->nr + vc->NumOfValues();
if (dpn->Trivial()) {
ASSERT(data.ptr == nullptr);
data.vt = sizeof(double);
Expand All @@ -397,7 +397,7 @@ void PackInt::LoadValuesDouble(const loader::ValueCache *vc, const std::optional

dpn->synced = false;

for (size_t i = 0; i < vc->NoValues(); i++) {
for (size_t i = 0; i < vc->NumOfValues(); i++) {
if (!vc->IsNull(i)) {
AppendValue(*(uint64_t *)vc->GetDataBytesPointer(i));
} else {
Expand Down Expand Up @@ -429,7 +429,7 @@ void PackInt::LoadValuesFixed(const loader::ValueCache *vc, const std::optional<
auto new_min = std::min(vc->MinInt(), dpn->min_i);
auto new_max = std::max(vc->MaxInt(), dpn->max_i);
auto new_vt = GetValueSize(new_max - new_min);
auto new_nr = dpn->nr + vc->NoValues();
auto new_nr = dpn->nr + vc->NumOfValues();

ASSERT(new_vt >= data.vt);

Expand Down Expand Up @@ -470,7 +470,7 @@ void PackInt::LoadValuesFixed(const loader::ValueCache *vc, const std::optional<

dpn->synced = false;

for (size_t i = 0; i < vc->NoValues(); i++) {
for (size_t i = 0; i < vc->NumOfValues(); i++) {
if (vc->NotNull(i)) {
AppendValue(*(uint64_t *)vc->GetDataBytesPointer(i) - new_min);
} else {
Expand Down
4 changes: 2 additions & 2 deletions storage/stonedb/core/pack_orderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void PackOrderer::InitOneColumn(vcolumn::VirtualColumn *vc, OrderType ot, common
int pack = mit.GetCurPackrow(d);
if (!r_filter || r_filter[pack] != common::RSValue::RS_NONE) {
if (mmt == MinMaxType::MMT_Fixed) {
if (vc->GetNoNulls(mit) == mit.GetPackSizeLeft()) {
if (vc->GetNumOfNulls(mit) == mit.GetPackSizeLeft()) {
mid.i = common::PLUS_INF_64;
} else {
int64_t min = vc->GetMinInt64(mit);
Expand Down Expand Up @@ -325,7 +325,7 @@ void PackOrderer::RewindToMatch(vcolumn::VirtualColumn *vc, MIIterator &mit) {

if (mmtype[curvc] == MinMaxType::MMT_Fixed) {
int64_t mid = common::MINUS_INF_64;
if (vc->GetNoNulls(mit) != mit.GetPackSizeLeft()) {
if (vc->GetNumOfNulls(mit) != mit.GetPackSizeLeft()) {
int64_t min = vc->GetMinInt64(mit);
int64_t max = vc->GetMaxInt64(mit);
mid = (max - min) / 2;
Expand Down
6 changes: 3 additions & 3 deletions storage/stonedb/core/pack_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void PackStr::LoadValues(const loader::ValueCache *vc) {
auto sz = vc->SumarizedSize();
data.v.push_back({(char *)alloc(sz, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), sz, 0});

auto total = vc->NoValues();
auto total = vc->NumOfValues();

TransformIntoArray();

Expand All @@ -255,7 +255,7 @@ void PackStr::LoadValues(const loader::ValueCache *vc) {
}

// update min/max/maxlen in DPN, if there is non-null values loaded
if (vc->NoValues() > vc->NoNulls()) {
if (vc->NumOfValues() > vc->NumOfNulls()) {
types::BString min_s;
types::BString max_s;
uint maxlen;
Expand Down Expand Up @@ -715,4 +715,4 @@ bool PackStr::IsNotMatched(int row, const std::unordered_set<uint16_t> &ids) {
return ids.find(ids_array_[row]) == ids.end();
}
} // namespace core
} // namespace stonedb
} // namespace stonedb
4 changes: 2 additions & 2 deletions storage/stonedb/core/parallel_hash_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ int64_t ParallelHashJoiner::AsyncMatchDim(MatchTaskParams *params) {
omit_this_packrow = true;
break;
}
if (other_cond_exist_ || local_min != local_max || vc2_[index]->NullsPossible()) {
if (other_cond_exist_ || local_min != local_max || vc2_[index]->IsNullsPossible()) {
packrow_uniform = false;
}
}
Expand Down Expand Up @@ -1185,4 +1185,4 @@ std::unique_ptr<TwoDimensionalJoiner> CreateHashJoiner(MultiIndex *multi_index,
return std::unique_ptr<TwoDimensionalJoiner>(joiner);
}
} // namespace core
} // namespace stonedb
} // namespace stonedb
2 changes: 1 addition & 1 deletion storage/stonedb/core/parameterized_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ void ParameterizedFilter::UpdateMultiIndex(bool count_only, int64_t limit) {
for (uint i = 0; i < descriptors.Size(); i++) {
if (descriptors[i].IsDelayed() && !descriptors[i].done && descriptors[i].op == common::Operator::O_IS_NULL &&
join_desc[0].right_dims.Get(descriptors[i].attr.vc->GetDim()) &&
!descriptors[i].attr.vc->NullsPossible()) {
!descriptors[i].attr.vc->IsNullsPossible()) {
for (int j = 0; j < join_desc[0].right_dims.Size(); j++) {
if (join_desc[0].right_dims[j] == true) join_tips.null_only[j] = true;
}
Expand Down
4 changes: 2 additions & 2 deletions storage/stonedb/core/physical_column.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ class PhysicalColumn : public Column {
* Special case: GetNoNulls(-1) gives a total number of nulls.
* Value common::NULL_VALUE_64 means 'cannot determine'.
*/
virtual int64_t GetNoNulls(int pack) = 0;
virtual int64_t GetNumOfNulls(int pack) = 0;

/*!
* \brief return true if sure that the column contains nulls only
*/
virtual bool RoughNullsOnly() const = 0;
virtual bool IsRoughNullsOnly() const = 0;

//! \brief Get the sum of values in the datapack identified by \e pack
virtual int64_t GetSum(int pack, bool &nonnegative) = 0;
Expand Down
24 changes: 12 additions & 12 deletions storage/stonedb/core/rc_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ types::RCDataType &RCAttr::GetValueData(size_t obj, types::RCDataType &value, bo
return value;
}

int64_t RCAttr::GetNoNulls(int pack) {
int64_t RCAttr::GetNumOfNulls(int pack) {
LoadPackInfo();
if (pack == -1) return NoNulls();
if (pack == -1) return NumOfNulls();
return get_dpn(pack).nn;
}

Expand Down Expand Up @@ -831,8 +831,8 @@ void RCAttr::LoadData(loader::ValueCache *nvs, Transaction *conn_info) {

if (!get_dpn(pi).Trivial()) get_pack(pi)->Save();

hdr.nr += nvs->NoValues();
hdr.nn += (Type().NotNull() ? 0 : nvs->NoNulls());
hdr.nr += nvs->NumOfValues();
hdr.nn += (Type().NotNull() ? 0 : nvs->NumOfNulls());
hdr.natural_size += nvs->SumarizedSize();
}

Expand All @@ -847,8 +847,8 @@ void RCAttr::LoadDataPackN(size_t pi, loader::ValueCache *nvs) {
}

auto &dpn = get_dpn(pi);
auto load_values = nvs->NoValues();
size_t load_nulls = nv.has_value() ? 0 : nvs->NoNulls();
auto load_values = nvs->NumOfValues();
size_t load_nulls = nv.has_value() ? 0 : nvs->NumOfNulls();

// nulls only
if (load_nulls == load_values && (dpn.nr == 0 || dpn.NullOnly())) {
Expand Down Expand Up @@ -895,7 +895,7 @@ void RCAttr::LoadDataPackN(size_t pi, loader::ValueCache *nvs) {
}

// update global column statistics
if (nvs->NoNulls() != nvs->NoValues()) {
if (nvs->NumOfNulls() != nvs->NumOfValues()) {
if (NoObj() == 0) {
SetMinInt64(dpn.min_i);
SetMaxInt64(dpn.max_i);
Expand All @@ -916,8 +916,8 @@ void RCAttr::LoadDataPackN(size_t pi, loader::ValueCache *nvs) {
void RCAttr::LoadDataPackS(size_t pi, loader::ValueCache *nvs) {
auto &dpn(get_dpn(pi));

auto load_nulls = Type().NotNull() ? 0 : nvs->NoNulls();
auto cnt = nvs->NoValues();
auto load_nulls = Type().NotNull() ? 0 : nvs->NumOfNulls();
auto cnt = nvs->NumOfValues();

// no need to store any values - uniform package
if (load_nulls == cnt && (dpn.nr == 0 || dpn.NullOnly())) {
Expand Down Expand Up @@ -1062,7 +1062,7 @@ void RCAttr::CompareAndSetCurrentMax(const types::BString &tstmp, types::BString
}

types::BString RCAttr::MinS(Filter *f) {
if (f->IsEmpty() || !ATI::IsStringType(TypeName()) || NoObj() == 0 || NoObj() == NoNulls()) return types::BString();
if (f->IsEmpty() || !ATI::IsStringType(TypeName()) || NoObj() == 0 || NoObj() == NumOfNulls()) return types::BString();
types::BString min;
bool set = false;
if (f->NoBlocks() != NoPack())
Expand Down Expand Up @@ -1095,7 +1095,7 @@ types::BString RCAttr::MinS(Filter *f) {
}

types::BString RCAttr::MaxS(Filter *f) {
if (f->IsEmpty() || !ATI::IsStringType(TypeName()) || NoObj() == 0 || NoObj() == NoNulls()) return types::BString();
if (f->IsEmpty() || !ATI::IsStringType(TypeName()) || NoObj() == 0 || NoObj() == NumOfNulls()) return types::BString();

types::BString max;
if (f->NoBlocks() != NoPack())
Expand Down Expand Up @@ -1250,4 +1250,4 @@ void RCAttr::UpdateIfIndex(uint64_t row, uint64_t col, const Value &v) {
}
}
} // namespace core
} // namespace stonedb
} // namespace stonedb
6 changes: 3 additions & 3 deletions storage/stonedb/core/rc_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class RCAttr final : public mm::TraceableObject, public PhysicalColumn, public P
int64_t CompressedSize() const { return hdr.compressed_size; };
uint32_t Nopackpower() const { return pss; }
uint64_t NoObj() const { return hdr.nr; }
uint64_t NoNulls() const { return hdr.nn; }
uint64_t NumOfNulls() const { return hdr.nn; }
uint NoPack() const { return m_idx.size(); }
int64_t GetMinInt64() const { return hdr.min; }
void SetMinInt64(int64_t a_imin) { hdr.min = a_imin; }
Expand All @@ -224,8 +224,8 @@ class RCAttr final : public mm::TraceableObject, public PhysicalColumn, public P
types::RCValueObject GetValue(int64_t obj, bool lookup_to_num = false) override;
types::RCDataType &GetValueData(size_t obj, types::RCDataType &value, bool lookup_to_num = false);

int64_t GetNoNulls(int pack) override;
bool RoughNullsOnly() const override { return hdr.nr == hdr.nn; }
int64_t GetNumOfNulls(int pack) override;
bool IsRoughNullsOnly() const override { return hdr.nr == hdr.nn; }
size_t GetNoValues(int pack) const { return get_dpn(pack).nr; }
int64_t GetSum(int pack, bool &nonnegative) override;
size_t GetActualSize(int pack);
Expand Down
Loading