Skip to content

Commit

Permalink
Merge branch 'dev_layer2_merge' into layer2_hcg
Browse files Browse the repository at this point in the history
  • Loading branch information
CaesarYangs committed May 6, 2024
2 parents c8b57e2 + 40ba160 commit e327e09
Show file tree
Hide file tree
Showing 30 changed files with 1,741 additions and 914 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: build

on:
push:
branches: [ "main" , "dev_cy"]
branches: [ "main" , "*"]
pull_request:
branches: [ "main" ]

Expand Down
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
OPTION(ENABLE_ASAN "Enable build with address sanitizer" ON)
OPTION(ENABLE_TSAN "Build with thread sanitizer" OFF)
OPTION(ENABLE_UBSAN "Build with undefined behavior sanitizer" OFF)
OPTION(WITH_UNIT_TESTS "Compile miniob with unit tests" ON)
OPTION(WITH_UNIT_TESTS "Compile miniob with unit tests" OFF)
OPTION(WITH_BENCHMARK "Compile benchmark" OFF)
OPTION(ENABLE_COVERAGE "Enable unittest coverage" OFF)
OPTION(CONCURRENCY "Support concurrency operations" OFF)
Expand All @@ -39,7 +39,8 @@ ELSE()
ENDIF(WIN32)

# This is for clangd plugin for vscode
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall -Werror")
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall")
# SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall -Werror")
IF(DEBUG)
MESSAGE(STATUS "DEBUG has been set as TRUE ${DEBUG}")
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O0 -g -DDEBUG ")
Expand Down Expand Up @@ -151,7 +152,7 @@ IF (WITH_BENCHMARK)
ADD_SUBDIRECTORY(benchmark)
ENDIF(WITH_BENCHMARK)

IF(WITH_UNIT_TESTS)
ADD_SUBDIRECTORY(unittest)
ENDIF(WITH_UNIT_TESTS)
# IF(WITH_UNIT_TESTS)
# ADD_SUBDIRECTORY(unittest)
# ENDIF(WITH_UNIT_TESTS)

2 changes: 2 additions & 0 deletions deps/common/lang/comparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ See the Mulan PSL v2 for more details. */
//

#include "common/defs.h"
#include "common/log/log.h"
#include <algorithm>
#include <string.h>

Expand All @@ -22,6 +23,7 @@ int compare_int(void *arg1, void *arg2)
{
int v1 = *(int *)arg1;
int v2 = *(int *)arg2;
LOG_DEBUG("[[[compare_int]]] value1:%d, value2:%d",v1,v2);
if (v1 > v2) {
return 1;
} else if (v1 < v2) {
Expand Down
103 changes: 102 additions & 1 deletion deps/common/lang/lower_bound.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,107 @@ ForwardIterator lower_bound(
return first;
}

template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator lower_bound_v2_advanced(ForwardIterator first, ForwardIterator last, const T &val, Compare comp,
bool *_found = nullptr, bool is_unique = true)
{
bool found = false;
ForwardIterator iter;
const auto count = std::distance(first, last);
auto last_count = count;
while (last_count > 0) {
iter = first;
auto step = last_count / 2;
std::advance(iter, step);
LOG_DEBUG("[[[I'm Here Here]]]");
int result = comp(*iter, val, is_unique);
if (0 == result) {
first = iter;
found = true;
break;
}
if (result < 0) {
first = ++iter;
last_count -= step + 1;
} else {
last_count = step;
}
}

if (_found) {
*_found = found;
}
return first;
}

// 以下两种方案都不行。为什么不行:没有理解索引,B+树索引真正的本质;错在哪了:应该在找到对应的页面后,在那个小块内进行检索,而不是全盘检索,那样还不如直接O(n)简单呢,也就是为什么要用B+树
template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator lower_bound_v2(ForwardIterator first, ForwardIterator last, const T &val, Compare comp,
bool *_found = nullptr, const std::vector<FieldMeta> &key_field_meta = {})
{
bool found = false;
ForwardIterator iter;
const auto count = std::distance(first, last);
auto last_count = count;
while (last_count > 0) {
iter = first;
auto step = last_count / 2;
std::advance(iter, step);
int result = comp(*iter, val); // 按照RID寻找
int unique_res = comp(*iter, val, key_field_meta); // 按照record value寻找
if (0 == result || unique_res == 0) {
first = iter;
found = true;
break;
}
if (result < 0) {
first = ++iter;
last_count -= step + 1;
} else {
last_count = step;
}
}

if (_found) {
*_found = found;
}
return first;
}

template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator lower_bound_with_record(ForwardIterator first, ForwardIterator last, const T &val, Compare comp,
bool *_found = nullptr, const std::vector<FieldMeta> &key_field_meta = {})
{
LOG_DEBUG("[[[[[[[[[[[[[I am here too]]]]]]]]]]]]]");
bool found = false;
ForwardIterator iter;
const auto count = std::distance(first, last);
auto last_count = count;
while (last_count > 0) {
iter = first;
auto step = last_count / 2;
std::advance(iter, step);
int result = comp(*iter, val, key_field_meta);
LOG_DEBUG("[[[[[[[[[[[[[found found found]]]]]]]]]]]]] %d",result);
if (0 == result) {
first = iter;
found = true;
break;
}
if (result < 0) {
first = ++iter;
last_count -= step + 1;
} else {
last_count = step;
}
}

if (_found) {
*_found = found;
}
return first;
}

template <typename T>
class Comparator
{
Expand Down Expand Up @@ -111,7 +212,7 @@ class BinaryIterator
BinaryIterator operator++(int)
{
BinaryIterator tmp(*this);
this-> operator++();
this->operator++();
return tmp;
}
BinaryIterator &operator--() { return this->operator+=(-1); }
Expand Down
4 changes: 2 additions & 2 deletions src/observer/sql/executor/create_index_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RC CreateIndexExecutor::execute(SQLStageEvent *sql_event)

CreateIndexStmt *create_index_stmt = static_cast<CreateIndexStmt *>(stmt);

Trx *trx = session->current_trx();
Trx *trx = session->current_trx(); // 从session对象中获取当前事务
Table *table = create_index_stmt->table();
return table->create_index(trx, create_index_stmt->field_meta(), create_index_stmt->index_name().c_str());
return table->create_index(trx, create_index_stmt->is_unique(), create_index_stmt->field_metas(), create_index_stmt->index_name().c_str()); //根据Multi-index进行改造, create_index stmt由此进行调用,作为重要的参数传递进去
}
Loading

0 comments on commit e327e09

Please sign in to comment.