Skip to content

Commit

Permalink
add unimplement pax storage and vectorized execution (oceanbase#425)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Issue Number: close oceanbase#409 close oceanbase#410 close oceanbase#411

Problem:
pax storage and vectorized execution.
for vldb summer school 2024.

### What is changed and how it works?
first we implement the pax storage, batch iterator, aggregator, group by and some simd functions , and then remove some key functions. We use unittest and some test cases to check players' code.
  • Loading branch information
nautaa authored Jul 2, 2024
1 parent 0eafadb commit 509e37b
Show file tree
Hide file tree
Showing 296 changed files with 11,028 additions and 3,490 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OPTION(ENABLE_COVERAGE "Enable unittest coverage" OFF)
OPTION(ENABLE_NOPIE "Enable no pie" OFF)
OPTION(CONCURRENCY "Support concurrency operations" OFF)
OPTION(STATIC_STDLIB "Link std library static or dynamic, such as libgcc, libstdc++, libasan" OFF)
OPTION(USE_SIMD "Use SIMD" OFF)

MESSAGE(STATUS "HOME dir: $ENV{HOME}")
#SET(ENV{变量名} 值)
Expand All @@ -42,12 +43,19 @@ ELSE()
ENDIF(WIN32)

# This is for clangd plugin for vscode
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall -Werror")
# mute sign-compare error in lex/yacc
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall -Werror -Wno-error=sign-compare")
IF (ENABLE_NOPIE)
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -no-pie")
ADD_LINK_OPTIONS(-no-pie)
ENDIF (ENABLE_NOPIE)

# Requires support for avx2
IF(USE_SIMD)
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -mavx2")
ADD_DEFINITIONS(-DUSE_SIMD)
ENDIF(USE_SIMD)

IF(DEBUG)
MESSAGE(STATUS "DEBUG has been set as TRUE ${DEBUG}")
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O0 -g -DDEBUG ")
Expand Down
95 changes: 95 additions & 0 deletions benchmark/aggregate_hash_table_performance_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

#include <benchmark/benchmark.h>

#include "common/lang/memory.h"
#include "common/lang/vector.h"
#include "sql/expr/aggregate_hash_table.h"

class AggregateHashTableBenchmark : public benchmark::Fixture
{
public:
void SetUp(const ::benchmark::State &state) override
{
unique_ptr<Column> column1 = make_unique<Column>(AttrType::INTS, 4);
unique_ptr<Column> column2 = make_unique<Column>(AttrType::INTS, 4);
for (int i = 0; i < state.range(0); i++) {
int key = i % 8;
column1->append_one((char *)&key);
column2->append_one((char *)&i);
}
group_chunk_.add_column(std::move(column1), 0);
aggr_chunk_.add_column(std::move(column2), 0);
}

void TearDown(const ::benchmark::State &state) override
{
group_chunk_.reset();
aggr_chunk_.reset();
}

protected:
Chunk group_chunk_;
Chunk aggr_chunk_;
};

class DISABLED_StandardAggregateHashTableBenchmark : public AggregateHashTableBenchmark
{
public:
void SetUp(const ::benchmark::State &state) override
{

AggregateHashTableBenchmark::SetUp(state);
AggregateExpr aggregate_expr(AggregateExpr::Type::SUM, nullptr);
vector<Expression *> aggregate_exprs;
aggregate_exprs.push_back(&aggregate_expr);
standard_hash_table_ = make_unique<StandardAggregateHashTable>(aggregate_exprs);
}

protected:
unique_ptr<AggregateHashTable> standard_hash_table_;
};

BENCHMARK_DEFINE_F(DISABLED_StandardAggregateHashTableBenchmark, Aggregate)(benchmark::State &state)
{
for (auto _ : state) {
standard_hash_table_->add_chunk(group_chunk_, aggr_chunk_);
}
}

BENCHMARK_REGISTER_F(DISABLED_StandardAggregateHashTableBenchmark, Aggregate)->Arg(16)->Arg(1024)->Arg(8192);

#ifdef USE_SIMD
class DISABLED_LinearProbingAggregateHashTableBenchmark : public AggregateHashTableBenchmark
{
public:
void SetUp(const ::benchmark::State &state) override
{

AggregateHashTableBenchmark::SetUp(state);
linear_probing_hash_table_ = make_unique<LinearProbingAggregateHashTable<int>>(AggregateExpr::Type::SUM);
}

protected:
unique_ptr<AggregateHashTable> linear_probing_hash_table_;
};

BENCHMARK_DEFINE_F(DISABLED_LinearProbingAggregateHashTableBenchmark, Aggregate)(benchmark::State &state)
{
for (auto _ : state) {
linear_probing_hash_table_->add_chunk(group_chunk_, aggr_chunk_);
}
}

BENCHMARK_REGISTER_F(DISABLED_LinearProbingAggregateHashTableBenchmark, Aggregate)->Arg(16)->Arg(1024)->Arg(8192);
#endif

BENCHMARK_MAIN();
100 changes: 100 additions & 0 deletions benchmark/arithmetic_operator_performance_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

#include <benchmark/benchmark.h>

#include "sql/expr/arithmetic_operator.hpp"

class DISABLED_ArithmeticBenchmark : public benchmark::Fixture
{
public:
void SetUp(const ::benchmark::State &state) override
{
int size = state.range(0);
left_ = (float *)malloc(size * sizeof(float));
right_ = (float *)malloc(size * sizeof(float));
result_ = (float *)malloc(size * sizeof(float));

for (int i = 0; i < size; ++i) {
left_[i] = 1.0f;
right_[i] = 0.5f;
result_[i] = 0.0f;
}
}

void TearDown(const ::benchmark::State &state) override
{
free(left_);
left_ = nullptr;
free(right_);
right_ = nullptr;
free(result_);
result_ = nullptr;
}

protected:
float *left_ = nullptr;
float *right_ = nullptr;
float *result_ = nullptr;
};

BENCHMARK_DEFINE_F(DISABLED_ArithmeticBenchmark, Add)(benchmark::State &state)
{
for (auto _ : state) {
binary_operator<false, false, float, AddOperator>(left_, right_, result_, state.range(0));
}
}

BENCHMARK_REGISTER_F(DISABLED_ArithmeticBenchmark, Add)->Arg(10)->Arg(1000)->Arg(10000);

BENCHMARK_DEFINE_F(DISABLED_ArithmeticBenchmark, Sub)(benchmark::State &state)
{
for (auto _ : state) {
binary_operator<false, false, float, SubtractOperator>(left_, right_, result_, state.range(0));
}
}

BENCHMARK_REGISTER_F(DISABLED_ArithmeticBenchmark, Sub)->Arg(10)->Arg(1000)->Arg(10000);

#ifdef USE_SIMD
static void DISABLED_benchmark_sum_simd(benchmark::State &state)
{
int size = state.range(0);
std::vector<int> data(state.range(0), 1);
for (auto _ : state) {
mm256_sum_epi32(data.data(), size);
}
}

BENCHMARK(DISABLED_benchmark_sum_simd)->RangeMultiplier(2)->Range(1 << 10, 1 << 12);
#endif

static int sum_scalar(const int *data, int size)
{
int sum = 0;
for (int i = 0; i < size; i++) {
sum += data[i];
}
return sum;
}

static void DISABLED_benchmark_sum_scalar(benchmark::State &state)
{
int size = state.range(0);
std::vector<int> data(size, 1);
for (auto _ : state) {
int res = sum_scalar(data.data(), size);
benchmark::DoNotOptimize(res);
}
}

BENCHMARK(DISABLED_benchmark_sum_scalar)->RangeMultiplier(2)->Range(1 << 10, 1 << 12);

BENCHMARK_MAIN();
4 changes: 2 additions & 2 deletions benchmark/bplus_tree_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ See the Mulan PSL v2 for more details. */
//
#include <benchmark/benchmark.h>
#include <inttypes.h>
#include <stdexcept>

#include "common/lang/stdexcept.h"
#include "common/log/log.h"
#include "common/math/integer_generator.h"
#include "storage/buffer/disk_buffer_pool.h"
Expand Down Expand Up @@ -71,7 +71,7 @@ class BenchmarkBase : public Fixture
const char *filename = btree_filename.c_str();

RC rc = handler_.create(
log_handler_, bpm_, filename, INTS, sizeof(int32_t) /*attr_len*/, internal_max_size, leaf_max_size);
log_handler_, bpm_, filename, AttrType::INTS, sizeof(int32_t) /*attr_len*/, internal_max_size, leaf_max_size);
if (rc != RC::SUCCESS) {
throw runtime_error("failed to create btree handler");
}
Expand Down
Loading

0 comments on commit 509e37b

Please sign in to comment.