From c9200f28987652fa36200ec180451aefe1e0febc Mon Sep 17 00:00:00 2001 From: ThreeLiu <96512084+liu33333@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:51:31 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=B0=86docker=E7=89=88=E6=9C=AC=E4=BB=8E2?= =?UTF-8?q?2.04=E6=9B=B4=E6=96=B0=E4=B8=BA24.04=20(#486)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 解决问题 Issue Number: #480 Problem: 将docker的Ubuntu版本从22.04更新到24.04,检查了兼容性 ### 更改内容 - Dockerfile 中修改了部分容器构建过程 - /miniob/deps/common/log/backtrace.cpp 中添加了缺少的头文件 --- deps/common/log/backtrace.cpp | 1 + docker/Dockerfile | 97 ++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/deps/common/log/backtrace.cpp b/deps/common/log/backtrace.cpp index d6d614c5b..c8b71bc13 100644 --- a/deps/common/log/backtrace.cpp +++ b/deps/common/log/backtrace.cpp @@ -17,6 +17,7 @@ See the Mulan PSL v2 for more details. */ #include #include #include "common/lang/vector.h" +#include namespace common { diff --git a/docker/Dockerfile b/docker/Dockerfile index e7baaeb13..856ef4408 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,46 +1,51 @@ -# how to use -# use docker build: docker build -t miniob . -# use docker compose: docker compose up -d --build -# make sure docker has been installed -FROM ubuntu:22.04 - -# ENV LANG=en_US.UTF-8 -# locale -RUN apt-get update && apt-get install -y locales apt-utils && rm -rf /var/lib/apt/lists/* \ - && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 -ENV LANG en_US.utf8 - -# dev tools -RUN apt-get update \ - && apt-get install -y build-essential gdb cmake git wget flex texinfo libreadline-dev diffutils bison \ - && apt-get install -y clang-format vim - -# install openssh -RUN apt-get install -y openssh-server - -# init miniob dependencies -RUN git clone https://github.com/oceanbase/miniob /tmp/miniob \ - && cd /tmp/miniob \ - && THIRD_PARTY_INSTALL_PREFIX=/usr/local bash build.sh init \ - && rm -rf /tmp/miniob - -RUN mkdir /var/run/sshd - -# install zsh and on-my-zsh -RUN apt-get install -y zsh \ - && git clone https://gitee.com/mirrors/ohmyzsh.git ~/.oh-my-zsh \ - && cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \ - && sed -i "s/robbyrussell/bira/" ~/.zshrc \ - && usermod --shell /bin/zsh root \ - && echo "export LD_LIBRARY_PATH=/usr/local/lib64:\$LD_LIBRARY_PATH" >> ~/.zshrc - -RUN mkdir -p /root/docker/bin && touch /etc/.firstrun - -# copy starter scripts -COPY bin/* /root/docker/bin/ - -RUN chmod +x /root/docker/bin/* - -WORKDIR /root - -ENTRYPOINT /root/docker/bin/starter.sh +# how to use +# use docker build: docker build -t miniob . +# use docker compose: docker compose up -d --build +# make sure docker has been installed +FROM ubuntu:24.04 + +ENV LANG en_US.utf8 + +RUN apt-get update && apt-get install -y locales apt-utils && rm -rf /var/lib/apt/lists/* \ + && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 + +# Change sources to Aliyun +RUN cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak \ + && echo 'Types: deb' > /etc/apt/sources.list.d/ubuntu.sources \ + && echo 'URIs: http://mirrors.aliyun.com/ubuntu/' >> /etc/apt/sources.list.d/ubuntu.sources \ + && echo 'Suites: noble noble-updates noble-security' >> /etc/apt/sources.list.d/ubuntu.sources \ + && echo 'Components: main restricted universe multiverse' >> /etc/apt/sources.list.d/ubuntu.sources \ + && echo 'Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg' >> /etc/apt/sources.list.d/ubuntu.sources \ + && apt-get update + +RUN apt-get update \ + && apt-get install -y build-essential gdb cmake git wget flex texinfo libreadline-dev diffutils bison \ + && apt-get install -y clang-format vim sudo + +RUN apt-get install -y openssh-server + +# Try cloning from GitHub, if it fails, use cnpmjs.org mirror +RUN git clone https://github.com/oceanbase/miniob /tmp/miniob || \ + git clone https://githubfast.com/oceanbase/miniob /tmp/miniob \ + && cd /tmp/miniob \ + && THIRD_PARTY_INSTALL_PREFIX=/usr/local bash build.sh init \ + && mkdir -p /root/docker/bin \ + && touch /etc/.firstrun \ + && cp docker/bin/* /root/docker/bin/ \ + && rm -rf /tmp/miniob + +RUN mkdir /var/run/sshd + +RUN apt-get install -y zsh \ + && mkdir ~/.oh-my-zsh \ + && git clone https://gitee.com/mirrors/ohmyzsh.git ~/.oh-my-zsh \ + && cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \ + && sed -i "s/robbyrussell/bira/" ~/.zshrc \ + && usermod --shell /bin/zsh root \ + && echo "export LD_LIBRARY_PATH=/usr/local/lib64:\$LD_LIBRARY_PATH" >> ~/.zshrc + +RUN chmod +x /root/docker/bin/* + +WORKDIR /root + +ENTRYPOINT /root/docker/bin/starter.sh From 52cb602d991accdcd44afed297f8e64d6f229784 Mon Sep 17 00:00:00 2001 From: wangyunlai Date: Mon, 18 Nov 2024 13:29:28 +0800 Subject: [PATCH 2/8] fix gitpod bug (#484) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem were solved in this pull request? Issue Number: close #483 Problem: gitpod 环境有问题,找不到libevent。看起来执行sudo命令时失败了。 ### What is changed and how it works? 使用基础镜像oceanbase/miniob,这个镜像也已经构建好了依赖 image --- .gitpod.yml | 13 +++---------- CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 416e840cf..3c19b8a77 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,10 +1,3 @@ -github: - prebuilds: - master: false - branches: false -tasks: - - name: install dependencies - init: | - sudo apt install cmake flex bison texinfo libreadline-dev -y - sudo bash build.sh init - echo -e "\033[32m\nDependency installed successfully\033[0m" +coreDump: + enabled: true +image: oceanbase/miniob:latest diff --git a/CMakeLists.txt b/CMakeLists.txt index 17fb4e41e..7b6f82fa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ MESSAGE(STATUS "This is Project source dir " ${PROJECT_SOURCE_DIR}) MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR}) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) -SET(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${PROJECT_SOURCE_DIR}/deps/3rd/usr/local") +SET(CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/deps/3rd/usr/local;/usr/local;${CMAKE_PREFIX_PATH}") SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) # 设置默认构建类型为 Debug From 297b1f53703efaec261ae8b99877e48ed9b5a02b Mon Sep 17 00:00:00 2001 From: ThreeLiu <96512084+liu33333@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:26:07 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0docker=E4=B8=ADUbuntu?= =?UTF-8?q?=E7=89=88=E6=9C=AC=20(#487)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 注释掉了换源的操作,看看用于构建容器的机器能不能用官方源 我在本地进行了两次测试,第一次502了,第二次成功了 ![Snipaste_2024-11-18_15-41-07](https://github.com/user-attachments/assets/b7383fbd-abb7-4d58-adc1-34a3c539e938) --------- Co-authored-by: wangyunlai --- docker/Dockerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 856ef4408..39e3a541f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,14 +9,14 @@ ENV LANG en_US.utf8 RUN apt-get update && apt-get install -y locales apt-utils && rm -rf /var/lib/apt/lists/* \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 -# Change sources to Aliyun -RUN cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak \ - && echo 'Types: deb' > /etc/apt/sources.list.d/ubuntu.sources \ - && echo 'URIs: http://mirrors.aliyun.com/ubuntu/' >> /etc/apt/sources.list.d/ubuntu.sources \ - && echo 'Suites: noble noble-updates noble-security' >> /etc/apt/sources.list.d/ubuntu.sources \ - && echo 'Components: main restricted universe multiverse' >> /etc/apt/sources.list.d/ubuntu.sources \ - && echo 'Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg' >> /etc/apt/sources.list.d/ubuntu.sources \ - && apt-get update +# # Change sources to Aliyun +# RUN cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak \ +# && echo 'Types: deb' > /etc/apt/sources.list.d/ubuntu.sources \ +# && echo 'URIs: http://mirrors.aliyun.com/ubuntu/' >> /etc/apt/sources.list.d/ubuntu.sources \ +# && echo 'Suites: noble noble-updates noble-security' >> /etc/apt/sources.list.d/ubuntu.sources \ +# && echo 'Components: main restricted universe multiverse' >> /etc/apt/sources.list.d/ubuntu.sources \ +# && echo 'Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg' >> /etc/apt/sources.list.d/ubuntu.sources \ +# && apt-get update RUN apt-get update \ && apt-get install -y build-essential gdb cmake git wget flex texinfo libreadline-dev diffutils bison \ From 4f79f4f515abae2a57883e22950d88742a4992ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BF=90=E6=9D=A5?= Date: Tue, 19 Nov 2024 18:02:59 +0800 Subject: [PATCH 4/8] move common dir to src --- CMakeLists.txt | 4 +- benchmark/CMakeLists.txt | 2 +- deps/CMakeLists.txt | 1 - deps/common/CMakeLists.txt | 38 ---- deps/common/metrics/console_reporter.cpp | 42 ---- deps/common/metrics/console_reporter.h | 30 --- deps/common/metrics/histogram_snapshot.cpp | 122 ----------- deps/common/metrics/histogram_snapshot.h | 76 ------- deps/common/metrics/log_reporter.cpp | 42 ---- deps/common/metrics/metric.h | 34 ---- deps/common/metrics/metrics.cpp | 192 ------------------ deps/common/metrics/metrics.h | 119 ----------- deps/common/metrics/metrics_registry.cpp | 68 ------- deps/common/metrics/metrics_registry.h | 49 ----- deps/common/metrics/reporter.h | 29 --- deps/common/metrics/reservoir.h | 49 ----- deps/common/metrics/sampler.cpp | 55 ----- deps/common/metrics/sampler.h | 44 ---- deps/common/metrics/snapshot.h | 78 ------- deps/common/metrics/timer_snapshot.cpp | 36 ---- deps/common/metrics/timer_snapshot.h | 34 ---- deps/common/metrics/uniform_reservoir.cpp | 118 ----------- deps/common/metrics/uniform_reservoir.h | 59 ------ src/CMakeLists.txt | 4 + src/common/CMakeLists.txt | 19 ++ {deps => src}/common/conf/ini.cpp | 0 {deps => src}/common/conf/ini.h | 0 {deps => src}/common/defs.h | 0 {deps => src}/common/io/io.cpp | 0 {deps => src}/common/io/io.h | 0 {deps => src}/common/lang/algorithm.h | 3 +- {deps => src}/common/lang/array.h | 0 {deps => src}/common/lang/atomic.h | 0 {deps => src}/common/lang/bitmap.cpp | 0 {deps => src}/common/lang/bitmap.h | 0 {deps => src}/common/lang/charconv.h | 0 {deps => src}/common/lang/chrono.h | 0 {deps => src}/common/lang/cmath.h | 0 {deps => src}/common/lang/comparator.cpp | 0 {deps => src}/common/lang/comparator.h | 0 {deps => src}/common/lang/defer.h | 0 {deps => src}/common/lang/deque.h | 0 {deps => src}/common/lang/exception.h | 0 {deps => src}/common/lang/filesystem.h | 0 {deps => src}/common/lang/fstream.h | 0 {deps => src}/common/lang/functional.h | 4 +- .../common/lang/initializer_list.h | 8 +- {deps => src}/common/lang/iomanip.h | 0 {deps => src}/common/lang/ios.h | 4 +- {deps => src}/common/lang/iostream.h | 0 {deps => src}/common/lang/iterator.h | 0 {deps => src}/common/lang/limits.h | 0 {deps => src}/common/lang/list.h | 0 {deps => src}/common/lang/lower_bound.h | 0 {deps => src}/common/lang/lru_cache.h | 0 {deps => src}/common/lang/map.h | 0 {deps => src}/common/lang/memory.h | 0 {deps => src}/common/lang/mutex.cpp | 0 {deps => src}/common/lang/mutex.h | 0 {deps => src}/common/lang/new.h | 0 {deps => src}/common/lang/queue.h | 0 {deps => src}/common/lang/random.h | 0 .../reservoir.cpp => src/common/lang/ranges.h | 14 +- {deps => src}/common/lang/serializable.h | 0 {deps => src}/common/lang/serializer.cpp | 0 {deps => src}/common/lang/serializer.h | 0 {deps => src}/common/lang/set.h | 0 {deps => src}/common/lang/span.h | 0 {deps => src}/common/lang/sstream.h | 0 {deps => src}/common/lang/stdexcept.h | 0 {deps => src}/common/lang/string.cpp | 0 {deps => src}/common/lang/string.h | 3 + {deps => src}/common/lang/string_view.h | 0 {deps => src}/common/lang/system_error.h | 0 {deps => src}/common/lang/thread.h | 0 .../log_reporter.h => src/common/lang/tuple.h | 17 +- {deps => src}/common/lang/unordered_map.h | 0 {deps => src}/common/lang/unordered_set.h | 0 {deps => src}/common/lang/utility.h | 0 {deps => src}/common/lang/vector.h | 0 {deps => src}/common/log/backtrace.cpp | 0 {deps => src}/common/log/backtrace.h | 0 {deps => src}/common/log/log.cpp | 0 {deps => src}/common/log/log.h | 0 {deps => src}/common/math/crc.cpp | 0 {deps => src}/common/math/crc.h | 0 {deps => src}/common/math/integer_generator.h | 0 {deps => src}/common/math/md5.cpp | 0 {deps => src}/common/math/md5.h | 0 .../common/math/random_generator.cpp | 0 {deps => src}/common/math/random_generator.h | 0 {deps => src}/common/math/regex.cpp | 0 {deps => src}/common/math/regex.h | 0 {deps => src}/common/math/simd_util.cpp | 0 {deps => src}/common/math/simd_util.h | 0 {deps => src}/common/mm/debug_new.h | 0 {deps => src}/common/mm/mem_pool.cpp | 0 {deps => src}/common/mm/mem_pool.h | 0 {deps => src}/common/os/os.cpp | 0 {deps => src}/common/os/os.h | 0 {deps => src}/common/os/path.cpp | 0 {deps => src}/common/os/path.h | 0 {deps => src}/common/os/pidfile.cpp | 0 {deps => src}/common/os/pidfile.h | 0 {deps => src}/common/os/process.cpp | 0 {deps => src}/common/os/process.h | 0 {deps => src}/common/os/process_param.cpp | 0 {deps => src}/common/os/process_param.h | 0 {deps => src}/common/os/signal.cpp | 0 {deps => src}/common/os/signal.h | 0 {deps => src}/common/queue/queue.h | 0 {deps => src}/common/queue/simple_queue.h | 0 {deps => src}/common/queue/simple_queue.ipp | 0 src/{observer/common => common/sys}/rc.cpp | 2 +- src/{observer/common => common/sys}/rc.h | 0 {deps => src}/common/thread/runnable.h | 0 .../common/thread/thread_pool_executor.cpp | 0 .../common/thread/thread_pool_executor.h | 0 {deps => src}/common/thread/thread_util.cpp | 0 {deps => src}/common/thread/thread_util.h | 0 {deps => src}/common/time/datetime.cpp | 0 {deps => src}/common/time/datetime.h | 0 {deps => src}/common/time/timeout_info.cpp | 0 {deps => src}/common/time/timeout_info.h | 0 src/observer/CMakeLists.txt | 2 +- src/observer/common/type/char_type.h | 4 +- src/observer/common/type/data_type.h | 2 +- src/observer/common/value.cpp | 8 +- src/observer/net/buffered_writer.cpp | 1 - src/observer/net/communicator.cpp | 2 +- src/observer/net/communicator.h | 2 +- src/observer/net/mysql_communicator.cpp | 1 - ...e_thread_per_connection_thread_handler.cpp | 2 +- src/observer/net/ring_buffer.h | 2 +- src/observer/net/server.cpp | 2 - src/observer/net/sql_task_handler.h | 4 +- src/observer/net/thread_handler.h | 3 +- src/observer/sql/executor/command_executor.h | 2 +- .../sql/executor/create_index_executor.h | 4 +- .../sql/executor/create_table_executor.h | 4 +- .../sql/executor/desc_table_executor.cpp | 6 +- .../sql/executor/desc_table_executor.h | 4 +- src/observer/sql/executor/execute_stage.cpp | 4 - src/observer/sql/executor/execute_stage.h | 2 +- src/observer/sql/executor/help_executor.h | 6 +- .../sql/executor/load_data_executor.cpp | 30 +-- .../sql/executor/load_data_executor.h | 2 +- .../sql/executor/set_variable_executor.cpp | 6 +- .../sql/executor/set_variable_executor.h | 4 +- .../sql/executor/show_tables_executor.h | 10 +- src/observer/sql/executor/sql_result.cpp | 4 +- src/observer/sql/executor/sql_result.h | 15 +- .../sql/executor/trx_begin_executor.h | 4 +- src/observer/sql/executor/trx_end_executor.h | 4 +- .../sql/expr/aggregate_hash_table.cpp | 12 +- src/observer/sql/expr/aggregate_hash_table.h | 24 +-- src/observer/sql/expr/aggregate_state.cpp | 8 +- src/observer/sql/expr/aggregator.h | 4 +- src/observer/sql/expr/arithmetic_operator.hpp | 14 +- src/observer/sql/expr/composite_tuple.h | 6 +- src/observer/sql/expr/expression.cpp | 8 +- src/observer/sql/expr/expression.h | 73 ++++--- src/observer/sql/expr/expression_iterator.h | 11 +- src/observer/sql/expr/expression_tuple.h | 11 +- src/observer/sql/expr/tuple.h | 28 ++- src/observer/sql/expr/tuple_cell.h | 9 +- .../aggregate_vec_physical_operator.cpp | 5 +- .../aggregate_vec_physical_operator.h | 10 +- .../sql/operator/calc_logical_operator.h | 4 +- .../sql/operator/calc_physical_operator.h | 14 +- .../sql/operator/delete_physical_operator.cpp | 2 +- .../sql/operator/delete_physical_operator.h | 6 +- .../operator/explain_physical_operator.cpp | 9 +- .../sql/operator/explain_physical_operator.h | 4 +- .../operator/expr_vec_physical_operator.cpp | 6 +- .../sql/operator/expr_vec_physical_operator.h | 6 +- .../operator/group_by_logical_operator.cpp | 4 +- .../sql/operator/group_by_logical_operator.h | 9 +- .../operator/group_by_physical_operator.cpp | 3 +- .../sql/operator/group_by_physical_operator.h | 13 +- .../operator/group_by_vec_physical_operator.h | 5 +- .../hash_group_by_physical_operator.h | 12 +- .../operator/index_scan_physical_operator.cpp | 8 +- .../operator/index_scan_physical_operator.h | 6 +- .../sql/operator/insert_logical_operator.cpp | 2 +- .../sql/operator/insert_logical_operator.h | 12 +- .../sql/operator/insert_physical_operator.h | 7 +- .../sql/operator/logical_operator.cpp | 2 +- src/observer/sql/operator/logical_operator.h | 13 +- .../sql/operator/physical_operator.cpp | 6 +- src/observer/sql/operator/physical_operator.h | 16 +- .../operator/predicate_logical_operator.cpp | 2 +- .../sql/operator/predicate_logical_operator.h | 2 +- .../operator/predicate_physical_operator.h | 4 +- .../sql/operator/project_logical_operator.h | 9 +- .../sql/operator/project_physical_operator.h | 6 +- .../operator/project_vec_physical_operator.h | 6 +- .../scalar_group_by_physical_operator.h | 6 +- .../operator/string_list_physical_operator.h | 12 +- .../operator/table_get_logical_operator.cpp | 2 +- .../sql/operator/table_get_logical_operator.h | 6 +- .../operator/table_scan_physical_operator.h | 20 +- .../table_scan_vec_physical_operator.h | 20 +- .../comparison_simplification_rule.cpp | 4 +- .../comparison_simplification_rule.h | 4 +- .../conjunction_simplification_rule.cpp | 12 +- .../conjunction_simplification_rule.h | 2 +- .../sql/optimizer/expression_rewriter.h | 11 +- .../sql/optimizer/logical_plan_generator.cpp | 18 +- .../sql/optimizer/logical_plan_generator.h | 23 +-- src/observer/sql/optimizer/optimize_stage.cpp | 1 - src/observer/sql/optimizer/optimize_stage.h | 12 +- .../sql/optimizer/physical_plan_generator.cpp | 10 +- .../sql/optimizer/physical_plan_generator.h | 32 +-- .../optimizer/predicate_pushdown_rewriter.cpp | 22 +- .../optimizer/predicate_pushdown_rewriter.h | 8 +- .../sql/optimizer/predicate_rewrite.cpp | 10 +- .../sql/optimizer/predicate_rewrite.h | 2 +- src/observer/sql/optimizer/rewrite_rule.h | 9 +- src/observer/sql/optimizer/rewriter.cpp | 6 +- src/observer/sql/optimizer/rewriter.h | 8 +- src/observer/sql/parser/expression_binder.cpp | 6 +- src/observer/sql/parser/expression_binder.h | 28 ++- src/observer/sql/parser/parse.cpp | 2 +- src/observer/sql/parser/parse.h | 2 +- src/observer/sql/parser/parse_defs.h | 73 ++++--- src/observer/sql/parser/parse_stage.cpp | 5 +- src/observer/sql/parser/parse_stage.h | 2 +- src/observer/sql/parser/resolve_stage.cpp | 1 - src/observer/sql/parser/resolve_stage.h | 2 +- src/observer/sql/parser/yacc_sql.y | 39 ++-- .../sql/plan_cache/plan_cache_stage.cpp | 1 - .../sql/plan_cache/plan_cache_stage.h | 2 +- .../sql/query_cache/query_cache_stage.cpp | 1 - .../sql/query_cache/query_cache_stage.h | 2 +- src/observer/sql/stmt/calc_stmt.h | 8 +- src/observer/sql/stmt/create_index_stmt.h | 8 +- src/observer/sql/stmt/create_table_stmt.h | 17 +- src/observer/sql/stmt/delete_stmt.cpp | 4 +- src/observer/sql/stmt/desc_table_stmt.h | 10 +- src/observer/sql/stmt/explain_stmt.cpp | 4 +- src/observer/sql/stmt/explain_stmt.h | 4 +- src/observer/sql/stmt/filter_stmt.cpp | 8 +- src/observer/sql/stmt/filter_stmt.h | 12 +- src/observer/sql/stmt/insert_stmt.h | 2 +- src/observer/sql/stmt/load_data_stmt.h | 4 +- src/observer/sql/stmt/select_stmt.h | 17 +- src/observer/sql/stmt/stmt.h | 2 +- src/observer/sql/stmt/update_stmt.h | 2 +- .../storage/buffer/buffer_pool_log.cpp | 2 +- src/observer/storage/buffer/buffer_pool_log.h | 2 +- .../storage/buffer/disk_buffer_pool.h | 2 +- .../storage/buffer/double_write_buffer.cpp | 5 +- .../storage/buffer/double_write_buffer.h | 4 +- src/observer/storage/clog/disk_log_handler.h | 2 +- src/observer/storage/clog/log_buffer.h | 2 +- src/observer/storage/clog/log_entry.cpp | 1 - src/observer/storage/clog/log_entry.h | 2 +- src/observer/storage/clog/log_file.cpp | 2 +- src/observer/storage/clog/log_file.h | 2 +- src/observer/storage/clog/log_handler.h | 2 +- src/observer/storage/clog/log_replayer.h | 5 +- src/observer/storage/common/chunk.h | 4 +- src/observer/storage/common/meta_util.cpp | 2 - src/observer/storage/db/db.cpp | 4 +- src/observer/storage/db/db.h | 2 +- .../storage/default/default_handler.cpp | 3 - src/observer/storage/field/field_meta.cpp | 2 +- src/observer/storage/field/field_meta.h | 2 +- src/observer/storage/index/bplus_tree.cpp | 2 - src/observer/storage/index/bplus_tree_log.h | 2 +- .../storage/index/bplus_tree_log_entry.h | 2 +- src/observer/storage/index/index.h | 2 +- src/observer/storage/index/index_meta.h | 2 +- src/observer/storage/index/latch_memo.h | 4 +- src/observer/storage/persist/persist.h | 2 +- src/observer/storage/record/record.h | 4 +- src/observer/storage/record/record_log.cpp | 2 +- src/observer/storage/record/record_log.h | 2 +- .../storage/table/.table_meta.cpp.swp | Bin 0 -> 20480 bytes src/observer/storage/table/table_meta.cpp | 32 +-- src/observer/storage/table/table_meta.h | 31 ++- src/observer/storage/trx/mvcc_trx_log.h | 4 +- src/observer/storage/trx/trx.cpp | 2 - src/observer/storage/trx/trx.h | 2 +- test/perf/CMakeLists.txt | 13 -- test/perf/client_performance_test.cpp | 128 ------------ tools/CMakeLists.txt | 2 +- unittest/CMakeLists.txt | 4 +- 289 files changed, 626 insertions(+), 2162 deletions(-) delete mode 100644 deps/common/CMakeLists.txt delete mode 100644 deps/common/metrics/console_reporter.cpp delete mode 100644 deps/common/metrics/console_reporter.h delete mode 100644 deps/common/metrics/histogram_snapshot.cpp delete mode 100644 deps/common/metrics/histogram_snapshot.h delete mode 100644 deps/common/metrics/log_reporter.cpp delete mode 100644 deps/common/metrics/metric.h delete mode 100644 deps/common/metrics/metrics.cpp delete mode 100644 deps/common/metrics/metrics.h delete mode 100644 deps/common/metrics/metrics_registry.cpp delete mode 100644 deps/common/metrics/metrics_registry.h delete mode 100644 deps/common/metrics/reporter.h delete mode 100644 deps/common/metrics/reservoir.h delete mode 100644 deps/common/metrics/sampler.cpp delete mode 100644 deps/common/metrics/sampler.h delete mode 100644 deps/common/metrics/snapshot.h delete mode 100644 deps/common/metrics/timer_snapshot.cpp delete mode 100644 deps/common/metrics/timer_snapshot.h delete mode 100644 deps/common/metrics/uniform_reservoir.cpp delete mode 100644 deps/common/metrics/uniform_reservoir.h create mode 100644 src/CMakeLists.txt create mode 100644 src/common/CMakeLists.txt rename {deps => src}/common/conf/ini.cpp (100%) rename {deps => src}/common/conf/ini.h (100%) rename {deps => src}/common/defs.h (100%) rename {deps => src}/common/io/io.cpp (100%) rename {deps => src}/common/io/io.h (100%) rename {deps => src}/common/lang/algorithm.h (93%) rename {deps => src}/common/lang/array.h (100%) rename {deps => src}/common/lang/atomic.h (100%) rename {deps => src}/common/lang/bitmap.cpp (100%) rename {deps => src}/common/lang/bitmap.h (100%) rename {deps => src}/common/lang/charconv.h (100%) rename {deps => src}/common/lang/chrono.h (100%) rename {deps => src}/common/lang/cmath.h (100%) rename {deps => src}/common/lang/comparator.cpp (100%) rename {deps => src}/common/lang/comparator.h (100%) rename {deps => src}/common/lang/defer.h (100%) rename {deps => src}/common/lang/deque.h (100%) rename {deps => src}/common/lang/exception.h (100%) rename {deps => src}/common/lang/filesystem.h (100%) rename {deps => src}/common/lang/fstream.h (100%) rename {deps => src}/common/lang/functional.h (88%) rename deps/common/metrics/reporter.cpp => src/common/lang/initializer_list.h (87%) rename {deps => src}/common/lang/iomanip.h (100%) rename {deps => src}/common/lang/ios.h (89%) rename {deps => src}/common/lang/iostream.h (100%) rename {deps => src}/common/lang/iterator.h (100%) rename {deps => src}/common/lang/limits.h (100%) rename {deps => src}/common/lang/list.h (100%) rename {deps => src}/common/lang/lower_bound.h (100%) rename {deps => src}/common/lang/lru_cache.h (100%) rename {deps => src}/common/lang/map.h (100%) rename {deps => src}/common/lang/memory.h (100%) rename {deps => src}/common/lang/mutex.cpp (100%) rename {deps => src}/common/lang/mutex.h (100%) rename {deps => src}/common/lang/new.h (100%) rename {deps => src}/common/lang/queue.h (100%) rename {deps => src}/common/lang/random.h (100%) rename deps/common/metrics/reservoir.cpp => src/common/lang/ranges.h (68%) rename {deps => src}/common/lang/serializable.h (100%) rename {deps => src}/common/lang/serializer.cpp (100%) rename {deps => src}/common/lang/serializer.h (100%) rename {deps => src}/common/lang/set.h (100%) rename {deps => src}/common/lang/span.h (100%) rename {deps => src}/common/lang/sstream.h (100%) rename {deps => src}/common/lang/stdexcept.h (100%) rename {deps => src}/common/lang/string.cpp (100%) rename {deps => src}/common/lang/string.h (98%) rename {deps => src}/common/lang/string_view.h (100%) rename {deps => src}/common/lang/system_error.h (100%) rename {deps => src}/common/lang/thread.h (100%) rename deps/common/metrics/log_reporter.h => src/common/lang/tuple.h (67%) rename {deps => src}/common/lang/unordered_map.h (100%) rename {deps => src}/common/lang/unordered_set.h (100%) rename {deps => src}/common/lang/utility.h (100%) rename {deps => src}/common/lang/vector.h (100%) rename {deps => src}/common/log/backtrace.cpp (100%) rename {deps => src}/common/log/backtrace.h (100%) rename {deps => src}/common/log/log.cpp (100%) rename {deps => src}/common/log/log.h (100%) rename {deps => src}/common/math/crc.cpp (100%) rename {deps => src}/common/math/crc.h (100%) rename {deps => src}/common/math/integer_generator.h (100%) rename {deps => src}/common/math/md5.cpp (100%) rename {deps => src}/common/math/md5.h (100%) rename {deps => src}/common/math/random_generator.cpp (100%) rename {deps => src}/common/math/random_generator.h (100%) rename {deps => src}/common/math/regex.cpp (100%) rename {deps => src}/common/math/regex.h (100%) rename {deps => src}/common/math/simd_util.cpp (100%) rename {deps => src}/common/math/simd_util.h (100%) rename {deps => src}/common/mm/debug_new.h (100%) rename {deps => src}/common/mm/mem_pool.cpp (100%) rename {deps => src}/common/mm/mem_pool.h (100%) rename {deps => src}/common/os/os.cpp (100%) rename {deps => src}/common/os/os.h (100%) rename {deps => src}/common/os/path.cpp (100%) rename {deps => src}/common/os/path.h (100%) rename {deps => src}/common/os/pidfile.cpp (100%) rename {deps => src}/common/os/pidfile.h (100%) rename {deps => src}/common/os/process.cpp (100%) rename {deps => src}/common/os/process.h (100%) rename {deps => src}/common/os/process_param.cpp (100%) rename {deps => src}/common/os/process_param.h (100%) rename {deps => src}/common/os/signal.cpp (100%) rename {deps => src}/common/os/signal.h (100%) rename {deps => src}/common/queue/queue.h (100%) rename {deps => src}/common/queue/simple_queue.h (100%) rename {deps => src}/common/queue/simple_queue.ipp (100%) rename src/{observer/common => common/sys}/rc.cpp (97%) rename src/{observer/common => common/sys}/rc.h (100%) rename {deps => src}/common/thread/runnable.h (100%) rename {deps => src}/common/thread/thread_pool_executor.cpp (100%) rename {deps => src}/common/thread/thread_pool_executor.h (100%) rename {deps => src}/common/thread/thread_util.cpp (100%) rename {deps => src}/common/thread/thread_util.h (100%) rename {deps => src}/common/time/datetime.cpp (100%) rename {deps => src}/common/time/datetime.h (100%) rename {deps => src}/common/time/timeout_info.cpp (100%) rename {deps => src}/common/time/timeout_info.h (100%) create mode 100644 src/observer/storage/table/.table_meta.cpp.swp delete mode 100644 test/perf/CMakeLists.txt delete mode 100644 test/perf/client_performance_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b6f82fa6..8b45484f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,9 +171,7 @@ MESSAGE(STATUS "CMAKE_CXX_FLAGS is " ${CMAKE_CXX_FLAGS}) # ADD_SUBDIRECTORY(src bin) bin 为目标目录, 可以省略 ADD_SUBDIRECTORY(deps) -ADD_SUBDIRECTORY(src/obclient) -ADD_SUBDIRECTORY(src/observer) -ADD_SUBDIRECTORY(test/perf) +ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(tools) IF (WITH_BENCHMARK) diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 415ccc080..a0d67f3f8 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(benchmark CONFIG REQUIRED) -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/observer) +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/observer) FILE(GLOB_RECURSE ALL_SRC *.cpp) # AUX_SOURCE_DIRECTORY 类似功能 diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index f8398244a..e700945b7 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,5 +1,4 @@ -ADD_SUBDIRECTORY(common) if (WITH_MEMTRACER) ADD_SUBDIRECTORY(memtracer) endif() diff --git a/deps/common/CMakeLists.txt b/deps/common/CMakeLists.txt deleted file mode 100644 index 742ba3de0..000000000 --- a/deps/common/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR}) -MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR}) - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - -FILE(GLOB_RECURSE ALL_SRC *.cpp) - -#SHARED,动态库 -#STATIC,静态库 -ADD_LIBRARY(common STATIC ${ALL_SRC} ) - - -IF(USE_MUSL_LIBC) - MESSAGE(STATUS "musl libc need manually link libexecinfo") - TARGET_LINK_LIBRARIES(common execinfo) -ENDIF(USE_MUSL_LIBC) - -# 编译静态库时,自动会把同名的动态库给删除, 因此需要临时设置一下 -SET_TARGET_PROPERTIES(common PROPERTIES CLEAN_DIRECT_OUTPUT 1) - -SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -# Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制 -# TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类 -# 类型分为RUNTIME/LIBRARY/ARCHIVE, prog -INSTALL(TARGETS common - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) - -# 小心 安装的时候,不要变成include/func.h, 如果这样,第二次安装的时候会变成include/func.h/func.h -# INSTALL(FILES func.h DESTINATION include/) - -FILE(GLOB_RECURSE ALL_HEADER *.h) -FOREACH(F ${ALL_HEADER}) - file(RELATIVE_PATH RELAPATH_HEADER ${PROJECT_SOURCE_DIR} ${F}) # 获取相对路径 - get_filename_component(headDir ${RELAPATH_HEADER} DIRECTORY) - MESSAGE("Install " ${RELAPATH_HEADER} " to " ${CMAKE_INSTALL_PREFIX} "/" common "/include/" ${headDir}) - INSTALL(FILES ${RELAPATH_HEADER} DESTINATION include/${headDir}) -ENDFOREACH(F) diff --git a/deps/common/metrics/console_reporter.cpp b/deps/common/metrics/console_reporter.cpp deleted file mode 100644 index e8abd08ae..000000000 --- a/deps/common/metrics/console_reporter.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "common/metrics/console_reporter.h" - -#include -#include - -#include "common/metrics/metric.h" - -namespace common { - -ConsoleReporter *get_console_reporter() -{ - static ConsoleReporter *instance = new ConsoleReporter(); - - return instance; -} - -void ConsoleReporter::report(const std::string &tag, Metric *metric) -{ - Snapshot *snapshot = metric->get_snapshot(); - - if (snapshot != NULL) { - printf("%s:%s\n", tag.c_str(), snapshot->to_string().c_str()); - } else { - printf("There is no snapshot of %s metrics.", tag.c_str()); - } -} - -} // namespace common \ No newline at end of file diff --git a/deps/common/metrics/console_reporter.h b/deps/common/metrics/console_reporter.h deleted file mode 100644 index 8a03fca9a..000000000 --- a/deps/common/metrics/console_reporter.h +++ /dev/null @@ -1,30 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#ifndef __COMMON_METRICS_CONSOLE_REPORTER_H__ -#define __COMMON_METRICS_CONSOLE_REPORTER_H__ - -#include "common/metrics/reporter.h" - -namespace common { - -class ConsoleReporter : public Reporter -{ -public: - void report(const std::string &tag, Metric *metric); -}; - -ConsoleReporter *get_console_reporter(); -} // namespace common -#endif //__COMMON_METRICS_CONSOLE_REPORTER_H__ diff --git a/deps/common/metrics/histogram_snapshot.cpp b/deps/common/metrics/histogram_snapshot.cpp deleted file mode 100644 index c512b3411..000000000 --- a/deps/common/metrics/histogram_snapshot.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "histogram_snapshot.h" - -#include -#include - -#include -#include -#include - -namespace common { - -HistogramSnapShot::HistogramSnapShot() {} - -HistogramSnapShot::HistogramSnapShot(const std::vector &collection) { set_collection(collection); } - -HistogramSnapShot::~HistogramSnapShot() {} - -void HistogramSnapShot::set_collection(const std::vector &collection) -{ - if (collection.empty()) { - return; - } - - data_ = collection; - std::sort(data_.begin(), data_.end()); -} - -size_t HistogramSnapShot::size() const { return data_.size(); } - -double HistogramSnapShot::get_value(double quantile) -{ - if (quantile > 1.0f) { - quantile = 1.0f; - } - - if (quantile < 0.0f) { - quantile = 0.0f; - } - - if (data_.empty()) { - return 0.0f; - } - - double pos = quantile * (data_.size() + 1); - - if (pos < 1) { - return data_[0]; - } - - if (pos >= data_.size()) { - return data_[data_.size() - 1]; - } - - double lower = data_[(int)pos - 1]; - double upper = data_[(int)pos]; - - return lower + (pos - floor(pos)) * (upper - lower); -} - -double HistogramSnapShot::get_median() { return get_value(0.5f); } - -double HistogramSnapShot::get_75th() { return get_value(0.75f); } - -double HistogramSnapShot::get_90th() { return get_value(0.90f); } - -double HistogramSnapShot::get_95th() { return get_value(0.95f); } -double HistogramSnapShot::get_99th() { return get_value(0.99f); } -double HistogramSnapShot::get_999th() { return get_value(0.999f); } - -double HistogramSnapShot::get_max() -{ - if (data_.empty()) { - return 0.0f; - } - - return static_cast(*data_.rbegin()); -} - -double HistogramSnapShot::get_min() -{ - if (data_.empty()) { - return 0.0f; - } - - return static_cast(*data_.begin()); -} - -double HistogramSnapShot::get_mean() -{ - if (data_.empty()) { - return 0.0f; - } - - return std::accumulate(data_.begin(), data_.end(), (double)0) * 1.0f / data_.size(); -} - -const std::vector &HistogramSnapShot::get_values() { return data_; } - -std::string HistogramSnapShot::to_string() -{ - std::stringstream oss; - oss << "mean:" << get_mean() << ",min:" << get_min() << ",max:" << get_max() << ",median:" << get_median() - << ", 75th:" << get_75th() << ",90th:" << get_90th() << ",99th:" << get_99th() << ",999th:" << get_999th(); - - return oss.str(); -} - -} // namespace common \ No newline at end of file diff --git a/deps/common/metrics/histogram_snapshot.h b/deps/common/metrics/histogram_snapshot.h deleted file mode 100644 index 0fd78e186..000000000 --- a/deps/common/metrics/histogram_snapshot.h +++ /dev/null @@ -1,76 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#ifndef __COMMON_METRICS_HISTOGRAM_SNAPSHOT_H_ -#define __COMMON_METRICS_HISTOGRAM_SNAPSHOT_H_ - -#include -#include - -#include -#include - -#include "common/metrics/snapshot.h" - -namespace common { - -class HistogramSnapShot : public Snapshot -{ -public: - HistogramSnapShot(); - explicit HistogramSnapShot(const std::vector &collection); - virtual ~HistogramSnapShot(); - -public: - void set_collection(const std::vector &collection); - - /** - * Returns the value at the given quantile - * - * @param quantile a given quantile, in {@code [0..1]} - * @return the value in the distribute - */ - double get_value(double quantile); - - /** - * Returns the size of collection in the snapshot - */ - size_t size() const; - - /** - * Returns 50th_percentile. - */ - double get_median(); - - double get_75th(); - double get_90th(); - double get_95th(); - double get_99th(); - double get_999th(); - - double get_max(); - double get_min(); - double get_mean(); - - const std::vector &get_values(); - - std::string to_string(); - -protected: - std::vector data_; -}; - -} // namespace common - -#endif /* __COMMON_METRICS_HISTOGRAM_SNAPSHOT_H_ */ diff --git a/deps/common/metrics/log_reporter.cpp b/deps/common/metrics/log_reporter.cpp deleted file mode 100644 index 8370b7b76..000000000 --- a/deps/common/metrics/log_reporter.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "common/metrics/log_reporter.h" - -#include - -#include "common/log/log.h" -#include "common/metrics/metric.h" - -namespace common { - -LogReporter *get_log_reporter() -{ - static LogReporter *instance = new LogReporter(); - - return instance; -} - -void LogReporter::report(const std::string &tag, Metric *metric) -{ - Snapshot *snapshot = metric->get_snapshot(); - - if (snapshot != NULL) { - LOG_INFO("%s:%s", tag.c_str(), snapshot->to_string().c_str()); - } else { - LOG_WARN("There is no snapshot of %s metrics.", tag.c_str()); - } -} - -} // namespace common \ No newline at end of file diff --git a/deps/common/metrics/metric.h b/deps/common/metrics/metric.h deleted file mode 100644 index d27a8173f..000000000 --- a/deps/common/metrics/metric.h +++ /dev/null @@ -1,34 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#ifndef __COMMON_METRICS_METRIC_H__ -#define __COMMON_METRICS_METRIC_H__ - -#include "common/metrics/snapshot.h" - -namespace common { - -class Metric -{ -public: - virtual void snapshot() = 0; - - virtual Snapshot *get_snapshot() { return snapshot_value_; } - -protected: - Snapshot *snapshot_value_; -}; - -} // namespace common -#endif //__COMMON_METRICS_METRIC_H__ diff --git a/deps/common/metrics/metrics.cpp b/deps/common/metrics/metrics.cpp deleted file mode 100644 index 69bde023e..000000000 --- a/deps/common/metrics/metrics.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/19. -// - -#include "common/metrics/metrics.h" -#include "common/lang/mutex.h" - -namespace common { -Meter::Meter() -{ - struct timeval start_time; - gettimeofday(&start_time, NULL); - - snapshot_tick_ = start_time.tv_sec * 1000000 + start_time.tv_usec; - value_.store(0l); -} - -Meter::~Meter() -{ - if (snapshot_value_ != NULL) { - delete snapshot_value_; - snapshot_value_ = NULL; - } -} - -void Meter::inc(long increase) { value_.fetch_add(increase); } - -void Meter::inc() { inc(1l); } - -void Meter::snapshot() -{ - // lock here - - struct timeval now; - gettimeofday(&now, NULL); - - long now_tick = now.tv_sec * 1000000 + now.tv_usec; - - double temp_value = ((double)value_.exchange(0l)) / ((now_tick - snapshot_tick_) / 1000000); - snapshot_tick_ = now_tick; - - if (snapshot_value_ == NULL) { - snapshot_value_ = new SnapshotBasic(); - } - ((SnapshotBasic *)snapshot_value_)->setValue(temp_value); -} - -SimpleTimer::~SimpleTimer() -{ - if (snapshot_value_ != NULL) { - delete snapshot_value_; - snapshot_value_ = NULL; - } -} - -void SimpleTimer::inc(long increase) -{ - value_.fetch_add(increase); - times_.fetch_add(1); -} - -void SimpleTimer::update(long one) { inc(one); } - -void SimpleTimer::snapshot() -{ - - // lock here - struct timeval now; - gettimeofday(&now, NULL); - - long now_tick = now.tv_sec * 1000000 + now.tv_usec; - - long value_snapshot = value_.exchange(0l); - long times_snapshot = times_.exchange(0l); - - double tps = 0; - double mean = 0; - - if (times_snapshot > 0) { - tps = ((double)times_snapshot) / ((now_tick - snapshot_tick_) / 1000000); - mean = ((double)value_snapshot) / times_snapshot; - } - - snapshot_tick_ = now_tick; - - if (snapshot_value_ == NULL) { - snapshot_value_ = new SimplerTimerSnapshot(); - } - ((SimplerTimerSnapshot *)snapshot_value_)->setValue(mean, tps); -} - -Histogram::Histogram(RandomGenerator &random) : UniformReservoir(random) {} - -Histogram::Histogram(RandomGenerator &random, size_t size) : UniformReservoir(random, size) {} - -Histogram::~Histogram() {} - -void Histogram::snapshot() { UniformReservoir::snapshot(); } - -Timer::Timer(RandomGenerator &random) : UniformReservoir(random) -{ - struct timeval start_time; - gettimeofday(&start_time, NULL); - - snapshot_tick_ = start_time.tv_sec * 1000000 + start_time.tv_usec; - value_.store(0l); -} - -Timer::Timer(RandomGenerator &random, size_t size) : UniformReservoir(random, size) -{ - struct timeval start_time; - gettimeofday(&start_time, NULL); - - snapshot_tick_ = start_time.tv_sec * 1000000 + start_time.tv_usec; - value_.store(0l); -} - -Timer::~Timer() -{ - if (snapshot_value_ == NULL) { - delete snapshot_value_; - snapshot_value_ = NULL; - } -} - -void Timer::update(double ms) -{ - UniformReservoir::update(ms); - value_.fetch_add(1l); -} - -void Timer::snapshot() -{ - if (snapshot_value_ == NULL) { - snapshot_value_ = new TimerSnapshot(); - } - TimerSnapshot *timer_snapshot = (TimerSnapshot *)snapshot_value_; - - struct timeval now; - gettimeofday(&now, NULL); - - long now_tick = now.tv_sec * 1000000 + now.tv_usec; - - double tps = ((double)value_.exchange(0l)) / ((now_tick - snapshot_tick_) / 1000000); - snapshot_tick_ = now_tick; - - MUTEX_LOCK(&mutex); - std::vector output = data; - MUTEX_UNLOCK(&mutex); - - timer_snapshot->set_collection(output); - timer_snapshot->set_tps(tps); -} - -TimerStat::TimerStat(SimpleTimer &other_st) : st_(other_st), start_tick_(0), end_tick_(0) { start(); } - -TimerStat::~TimerStat() -{ - if (end_tick_ == 0) { - end(); - } - - st_.update((end_tick_ - start_tick_) / 1000); -} - -void TimerStat::start() -{ - struct timeval now; - gettimeofday(&now, NULL); - - start_tick_ = now.tv_sec * 1000000 + now.tv_usec; -} - -void TimerStat::end() -{ - struct timeval now; - gettimeofday(&now, NULL); - - end_tick_ = now.tv_sec * 1000000 + now.tv_usec; -} - -} // namespace common \ No newline at end of file diff --git a/deps/common/metrics/metrics.h b/deps/common/metrics/metrics.h deleted file mode 100644 index 781742708..000000000 --- a/deps/common/metrics/metrics.h +++ /dev/null @@ -1,119 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/19. -// - -#ifndef __COMMON_METRICS_METRICS_H__ -#define __COMMON_METRICS_METRICS_H__ - -#include "common/lang/string.h" -#include "common/metrics/metric.h" -#include "common/metrics/snapshot.h" -#include "common/metrics/timer_snapshot.h" -#include "common/metrics/uniform_reservoir.h" -#include - -namespace common { - -class Gauge : public Metric -{ -public: - // user implement snapshot function - void set_snapshot(Snapshot *value) { snapshot_value_ = value; } -}; - -class Counter : public Metric -{ - void set_snapshot(SnapshotBasic *value) { snapshot_value_ = value; } -}; - -class Meter : public Metric -{ -public: - Meter(); - virtual ~Meter(); - - void inc(long increase); - void inc(); - - void snapshot(); - -protected: - std::atomic value_; - long snapshot_tick_; -}; - -// SimpleTimer just get tps and meanvalue -// time unit is ms -class SimpleTimer : public Meter -{ -public: - virtual ~SimpleTimer(); - - void inc(long increase); - - void update(long one); - - void snapshot(); - -protected: - std::atomic times_; -}; - -// Histogram metric is complicated, in normal case , -// please skip us histogram or Timer as more as possible -// try use SimpleTimer to replace them. -// if use histogram , please use sampling method. -class Histogram : public UniformReservoir -{ -public: - Histogram(RandomGenerator &random); - Histogram(RandomGenerator &random, size_t size); - virtual ~Histogram(); - - void snapshot(); -}; - -// timeunit is ms -// Timer = Histogram + Meter -class Timer : public UniformReservoir -{ -public: - Timer(RandomGenerator &random); - Timer(RandomGenerator &random, size_t size); - virtual ~Timer(); - - void snapshot(); - void update(double ms); - -protected: - std::atomic value_; - long snapshot_tick_; -}; -// update ms -class TimerStat -{ -public: - TimerStat(SimpleTimer &st_); - - ~TimerStat(); - void start(); - void end(); - -public: - SimpleTimer &st_; - long start_tick_; - long end_tick_; -}; - -} // namespace common -#endif //__COMMON_METRICS_METRICS_H__ diff --git a/deps/common/metrics/metrics_registry.cpp b/deps/common/metrics/metrics_registry.cpp deleted file mode 100644 index 94bc41d23..000000000 --- a/deps/common/metrics/metrics_registry.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "common/metrics/metrics_registry.h" -#include "common/log/log.h" - -namespace common { - -MetricsRegistry &get_metrics_registry() -{ - static MetricsRegistry instance; - - return instance; -} - -void MetricsRegistry::register_metric(const std::string &tag, Metric *metric) -{ - std::map::iterator it = metrics.find(tag); - if (it != metrics.end()) { - LOG_WARN("%s has been registered!", tag.c_str()); - return; - } - - // metrics[tag] = metric; - metrics.insert(std::pair(tag, metric)); - LOG_INFO("Successfully register metric :%s", tag.c_str()); -} - -void MetricsRegistry::unregister(const std::string &tag) -{ - unsigned int num = metrics.erase(tag); - if (num == 0) { - LOG_WARN("There is no %s metric!", tag.c_str()); - return; - } - LOG_INFO("Successfully remove metric of %s", tag.c_str()); -} - -void MetricsRegistry::snapshot() -{ - std::map::iterator it = metrics.begin(); - for (; it != metrics.end(); it++) { - it->second->snapshot(); - } -} - -void MetricsRegistry::report() -{ - for (std::list::iterator reporterIt = reporters.begin(); reporterIt != reporters.end(); reporterIt++) { - for (std::map::iterator it = metrics.begin(); it != metrics.end(); it++) { - - (*reporterIt)->report(it->first, it->second); - } - } -} - -} // namespace common diff --git a/deps/common/metrics/metrics_registry.h b/deps/common/metrics/metrics_registry.h deleted file mode 100644 index 6632a767c..000000000 --- a/deps/common/metrics/metrics_registry.h +++ /dev/null @@ -1,49 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#ifndef __COMMON_METRICS_METRICS_REGISTRY_H__ -#define __COMMON_METRICS_METRICS_REGISTRY_H__ - -#include -#include -#include - -#include "common/metrics/metric.h" -#include "common/metrics/reporter.h" - -namespace common { - -class MetricsRegistry -{ -public: - MetricsRegistry(){}; - virtual ~MetricsRegistry(){}; - - void register_metric(const std::string &tag, Metric *metric); - void unregister(const std::string &tag); - - void snapshot(); - - void report(); - - void add_reporter(Reporter *reporter) { reporters.push_back(reporter); } - -protected: - std::map metrics; - std::list reporters; -}; - -MetricsRegistry &get_metrics_registry(); -} // namespace common -#endif //__COMMON_METRICS_METRICS_REGISTRY_H__ diff --git a/deps/common/metrics/reporter.h b/deps/common/metrics/reporter.h deleted file mode 100644 index 23660bf4e..000000000 --- a/deps/common/metrics/reporter.h +++ /dev/null @@ -1,29 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/19. -// - -#ifndef __COMMON_METRICS_REPORTER_H__ -#define __COMMON_METRICS_REPORTER_H__ - -#include "common/metrics/metric.h" -#include - -namespace common { - -class Reporter -{ -public: - virtual void report(const std::string &tag, Metric *metric) = 0; -}; -} // namespace common -#endif //__COMMON_METRICS_REPORTER_H__ diff --git a/deps/common/metrics/reservoir.h b/deps/common/metrics/reservoir.h deleted file mode 100644 index 08f32e700..000000000 --- a/deps/common/metrics/reservoir.h +++ /dev/null @@ -1,49 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/19. -// - -#ifndef __COMMON_METRICS_RESERVOIR_H_ -#define __COMMON_METRICS_RESERVOIR_H_ - -#include - -#include "common/math/random_generator.h" -#include "common/metrics/metric.h" -#include "common/metrics/snapshot.h" - -namespace common { - -class Reservoir : public Metric -{ -public: - Reservoir(RandomGenerator &random); - virtual ~Reservoir(); - -public: - virtual size_t size() = 0; - virtual size_t get_count() = 0; - - virtual void update(double one) = 0; - - virtual void reset() = 0; - -protected: - virtual size_t next(size_t range); - -private: - RandomGenerator &random; -}; - -} // namespace common - -#endif /* __COMMON_METRICS_RESERVOIR_H_ */ diff --git a/deps/common/metrics/sampler.cpp b/deps/common/metrics/sampler.cpp deleted file mode 100644 index 41b4a0fe6..000000000 --- a/deps/common/metrics/sampler.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "common/metrics/sampler.h" -#include "common/log/log.h" - -#define RANGE_SIZE 100 - -namespace common { - -Sampler *&get_sampler() -{ - static Sampler *g_sampler = new Sampler(); - - return g_sampler; -} - -Sampler::Sampler() : random_() {} - -Sampler::~Sampler() {} - -bool Sampler::sampling() -{ - int v = random_.next(RANGE_SIZE); - if (v <= ratio_num_) { - return true; - } else { - return false; - } -} - -double Sampler::get_ratio() { return ratio_; } - -void Sampler::set_ratio(double ratio) -{ - if (0 <= ratio && ratio <= 1) { - this->ratio_ = ratio; - ratio_num_ = ratio * RANGE_SIZE; - } else { - LOG_WARN("Invalid ratio :%lf", ratio); - } -} - -} // namespace common diff --git a/deps/common/metrics/sampler.h b/deps/common/metrics/sampler.h deleted file mode 100644 index cdb49fb65..000000000 --- a/deps/common/metrics/sampler.h +++ /dev/null @@ -1,44 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#ifndef __COMMON_METRICS_SAMPLER_H__ -#define __COMMON_METRICS_SAMPLER_H__ - -#include "common/math/random_generator.h" - -namespace common { - -/** - * The most simple sample function - */ -class Sampler -{ -public: - Sampler(); - virtual ~Sampler(); - - bool sampling(); - - void set_ratio(double ratio); - double get_ratio(); - -private: - double ratio_ = 1.0; - int ratio_num_ = 1; - RandomGenerator random_; -}; - -Sampler *&get_sampler(); -} // namespace common -#endif //__COMMON_METRICS_SAMPLER_H__ diff --git a/deps/common/metrics/snapshot.h b/deps/common/metrics/snapshot.h deleted file mode 100644 index 3254b8acf..000000000 --- a/deps/common/metrics/snapshot.h +++ /dev/null @@ -1,78 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#pragma once - -#include "common/lang/string.h" -#include - -namespace common { - -class Snapshot -{ -public: - virtual ~Snapshot(){}; - virtual std::string to_string() = 0; -}; - -template -class SnapshotBasic : public Snapshot -{ -public: - SnapshotBasic() - : value(){ - - }; - - virtual ~SnapshotBasic() {} - - void setValue(T &input) { value = input; } - - std::string to_string() - { - std::string ret; - val_to_str(value, ret); - return ret; - } - -private: - T value; -}; - -class SimplerTimerSnapshot : public Snapshot -{ -public: - SimplerTimerSnapshot() {} - - virtual ~SimplerTimerSnapshot() {} - - void setValue(double mean, double tps) - { - this->mean = mean; - this->tps = tps; - } - - std::string to_string() - { - std::stringstream oss; - oss << "mean:" << mean << ",tps:" << tps; - - return oss.str(); - } - -private: - double mean = 1.0; - double tps = 1.0; -}; -} // namespace common diff --git a/deps/common/metrics/timer_snapshot.cpp b/deps/common/metrics/timer_snapshot.cpp deleted file mode 100644 index 5c49775cf..000000000 --- a/deps/common/metrics/timer_snapshot.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "common/metrics/timer_snapshot.h" -#include - -namespace common { - -TimerSnapshot::TimerSnapshot() {} - -TimerSnapshot::~TimerSnapshot() {} - -double TimerSnapshot::get_tps() { return tps; } - -void TimerSnapshot::set_tps(double tps) { this->tps = tps; } - -std::string TimerSnapshot::to_string() -{ - std::stringstream oss; - - oss << HistogramSnapShot::to_string() << ",tps:" << tps; - - return oss.str(); -} -} // namespace common \ No newline at end of file diff --git a/deps/common/metrics/timer_snapshot.h b/deps/common/metrics/timer_snapshot.h deleted file mode 100644 index 06f2cb2dc..000000000 --- a/deps/common/metrics/timer_snapshot.h +++ /dev/null @@ -1,34 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#pragma once - -#include "common/metrics/histogram_snapshot.h" - -namespace common { -class TimerSnapshot : public HistogramSnapShot -{ -public: - TimerSnapshot(); - virtual ~TimerSnapshot(); - - double get_tps(); - void set_tps(double tps); - - std::string to_string(); - -protected: - double tps = 1.0; -}; -} // namespace common diff --git a/deps/common/metrics/uniform_reservoir.cpp b/deps/common/metrics/uniform_reservoir.cpp deleted file mode 100644 index 2a494e500..000000000 --- a/deps/common/metrics/uniform_reservoir.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// - -#include "common/metrics/uniform_reservoir.h" - -#include - -#include "common/lang/mutex.h" -#include "common/metrics/histogram_snapshot.h" - -namespace common { - -#define DEFAULT_SIZE 1023 - -UniformReservoir::UniformReservoir(RandomGenerator &random) : Reservoir(random), counter(0) -{ - pthread_mutexattr_t mutexatr; - pthread_mutexattr_init(&mutexatr); - pthread_mutexattr_settype(&mutexatr, PTHREAD_MUTEX_RECURSIVE); - - MUTEX_INIT(&mutex, &mutexatr); - - init(DEFAULT_SIZE); -} - -UniformReservoir::UniformReservoir(RandomGenerator &random, size_t size) : Reservoir(random), counter(0) -{ - - pthread_mutexattr_t mutexatr; - pthread_mutexattr_init(&mutexatr); - pthread_mutexattr_settype(&mutexatr, PTHREAD_MUTEX_RECURSIVE); - - MUTEX_INIT(&mutex, &mutexatr); - init(size); -} - -UniformReservoir::~UniformReservoir() -{ - if (snapshot_value_ == NULL) { - delete snapshot_value_; - snapshot_value_ = NULL; - } -} - -void UniformReservoir::init(size_t size) -{ - MUTEX_LOCK(&mutex); - counter = 0; - data.resize(size); - MUTEX_UNLOCK(&mutex); -} - -size_t UniformReservoir::size() -{ - MUTEX_LOCK(&mutex); - size_t size = (counter < data.size()) ? counter : data.size(); - MUTEX_UNLOCK(&mutex); - return size; -} - -size_t UniformReservoir::get_count() -{ - MUTEX_LOCK(&mutex); - size_t ret = counter; - MUTEX_UNLOCK(&mutex); - return ret; -} - -void UniformReservoir::update(double value) -{ - MUTEX_LOCK(&mutex); - size_t count = ++counter; - - if (count < data.size()) { - data[count] = (value); - } else { - size_t rcount = next(data.size()); - data[rcount] = (value); - } - - MUTEX_UNLOCK(&mutex); -} - -void UniformReservoir::snapshot() -{ - MUTEX_LOCK(&mutex); - std::vector output = data; - MUTEX_UNLOCK(&mutex); - - if (snapshot_value_ == NULL) { - snapshot_value_ = new HistogramSnapShot(); - } - ((HistogramSnapShot *)snapshot_value_)->set_collection(output); -} - -void UniformReservoir::reset() -{ - - MUTEX_LOCK(&mutex); - counter = 0; - data.clear(); - - // clear snapshot - MUTEX_UNLOCK(&mutex); -} - -} // namespace common \ No newline at end of file diff --git a/deps/common/metrics/uniform_reservoir.h b/deps/common/metrics/uniform_reservoir.h deleted file mode 100644 index d08790a2a..000000000 --- a/deps/common/metrics/uniform_reservoir.h +++ /dev/null @@ -1,59 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021/4/20. -// -#pragma once - -#include - -#include -#include - -#include "common/metrics/reservoir.h" - -namespace common { - -/** - * A random sampling reservoir of a stream of {@code long}s. Uses Vitter's - * Algorithm R to produce a statistically representative sample. - * - * @see Random Sampling - * with a Reservoir - */ - -class UniformReservoir : public Reservoir -{ -public: - UniformReservoir(RandomGenerator &random); - UniformReservoir(RandomGenerator &random, size_t size); - virtual ~UniformReservoir(); - -public: - size_t size(); // data buffer size - size_t get_count(); // how many items have been insert? - - void update(double one); - void snapshot(); - - void reset(); - -protected: - void init(size_t size); - -protected: - pthread_mutex_t mutex; - size_t counter; // counter is likely to be bigger than data.size() - std::vector data; - RandomGenerator random; -}; - -} // namespace common diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..a0fe77a35 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,4 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +ADD_SUBDIRECTORY(common) +ADD_SUBDIRECTORY(observer) +ADD_SUBDIRECTORY(obclient) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt new file mode 100644 index 000000000..1d93efd55 --- /dev/null +++ b/src/common/CMakeLists.txt @@ -0,0 +1,19 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src) + +FILE(GLOB_RECURSE ALL_SRC *.cpp) + +#SHARED,动态库 +#STATIC,静态库 +ADD_LIBRARY(common STATIC ${ALL_SRC} ) + + +IF(USE_MUSL_LIBC) + MESSAGE(STATUS "musl libc need manually link libexecinfo") + TARGET_LINK_LIBRARIES(common execinfo) +ENDIF(USE_MUSL_LIBC) + +# 编译静态库时,自动会把同名的动态库给删除, 因此需要临时设置一下 +SET_TARGET_PROPERTIES(common PROPERTIES CLEAN_DIRECT_OUTPUT 1) + +SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + diff --git a/deps/common/conf/ini.cpp b/src/common/conf/ini.cpp similarity index 100% rename from deps/common/conf/ini.cpp rename to src/common/conf/ini.cpp diff --git a/deps/common/conf/ini.h b/src/common/conf/ini.h similarity index 100% rename from deps/common/conf/ini.h rename to src/common/conf/ini.h diff --git a/deps/common/defs.h b/src/common/defs.h similarity index 100% rename from deps/common/defs.h rename to src/common/defs.h diff --git a/deps/common/io/io.cpp b/src/common/io/io.cpp similarity index 100% rename from deps/common/io/io.cpp rename to src/common/io/io.cpp diff --git a/deps/common/io/io.h b/src/common/io/io.h similarity index 100% rename from deps/common/io/io.h rename to src/common/io/io.h diff --git a/deps/common/lang/algorithm.h b/src/common/lang/algorithm.h similarity index 93% rename from deps/common/lang/algorithm.h rename to src/common/lang/algorithm.h index c8982daa4..8039152a3 100644 --- a/deps/common/lang/algorithm.h +++ b/src/common/lang/algorithm.h @@ -14,4 +14,5 @@ See the Mulan PSL v2 for more details. */ using std::max; using std::min; -using std::transform; \ No newline at end of file +using std::transform; +using std::swap; diff --git a/deps/common/lang/array.h b/src/common/lang/array.h similarity index 100% rename from deps/common/lang/array.h rename to src/common/lang/array.h diff --git a/deps/common/lang/atomic.h b/src/common/lang/atomic.h similarity index 100% rename from deps/common/lang/atomic.h rename to src/common/lang/atomic.h diff --git a/deps/common/lang/bitmap.cpp b/src/common/lang/bitmap.cpp similarity index 100% rename from deps/common/lang/bitmap.cpp rename to src/common/lang/bitmap.cpp diff --git a/deps/common/lang/bitmap.h b/src/common/lang/bitmap.h similarity index 100% rename from deps/common/lang/bitmap.h rename to src/common/lang/bitmap.h diff --git a/deps/common/lang/charconv.h b/src/common/lang/charconv.h similarity index 100% rename from deps/common/lang/charconv.h rename to src/common/lang/charconv.h diff --git a/deps/common/lang/chrono.h b/src/common/lang/chrono.h similarity index 100% rename from deps/common/lang/chrono.h rename to src/common/lang/chrono.h diff --git a/deps/common/lang/cmath.h b/src/common/lang/cmath.h similarity index 100% rename from deps/common/lang/cmath.h rename to src/common/lang/cmath.h diff --git a/deps/common/lang/comparator.cpp b/src/common/lang/comparator.cpp similarity index 100% rename from deps/common/lang/comparator.cpp rename to src/common/lang/comparator.cpp diff --git a/deps/common/lang/comparator.h b/src/common/lang/comparator.h similarity index 100% rename from deps/common/lang/comparator.h rename to src/common/lang/comparator.h diff --git a/deps/common/lang/defer.h b/src/common/lang/defer.h similarity index 100% rename from deps/common/lang/defer.h rename to src/common/lang/defer.h diff --git a/deps/common/lang/deque.h b/src/common/lang/deque.h similarity index 100% rename from deps/common/lang/deque.h rename to src/common/lang/deque.h diff --git a/deps/common/lang/exception.h b/src/common/lang/exception.h similarity index 100% rename from deps/common/lang/exception.h rename to src/common/lang/exception.h diff --git a/deps/common/lang/filesystem.h b/src/common/lang/filesystem.h similarity index 100% rename from deps/common/lang/filesystem.h rename to src/common/lang/filesystem.h diff --git a/deps/common/lang/fstream.h b/src/common/lang/fstream.h similarity index 100% rename from deps/common/lang/fstream.h rename to src/common/lang/fstream.h diff --git a/deps/common/lang/functional.h b/src/common/lang/functional.h similarity index 88% rename from deps/common/lang/functional.h rename to src/common/lang/functional.h index 4cf782c63..065413f30 100644 --- a/deps/common/lang/functional.h +++ b/src/common/lang/functional.h @@ -14,4 +14,6 @@ See the Mulan PSL v2 for more details. */ using std::equal_to; using std::function; -using std::hash; \ No newline at end of file +using std::hash; +// using std::bind; // conflict with socket::bind +using std::ref; diff --git a/deps/common/metrics/reporter.cpp b/src/common/lang/initializer_list.h similarity index 87% rename from deps/common/metrics/reporter.cpp rename to src/common/lang/initializer_list.h index e020fcf4e..91ea76511 100644 --- a/deps/common/metrics/reporter.cpp +++ b/src/common/lang/initializer_list.h @@ -8,8 +8,8 @@ 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. */ -// -// Created by Longda on 2021/4/19. -// +#pragma once -#include "common/metrics/reporter.h" +#include + +using std::initializer_list; diff --git a/deps/common/lang/iomanip.h b/src/common/lang/iomanip.h similarity index 100% rename from deps/common/lang/iomanip.h rename to src/common/lang/iomanip.h diff --git a/deps/common/lang/ios.h b/src/common/lang/ios.h similarity index 89% rename from deps/common/lang/ios.h rename to src/common/lang/ios.h index e4673e227..57f5fb0f1 100644 --- a/deps/common/lang/ios.h +++ b/src/common/lang/ios.h @@ -13,4 +13,6 @@ See the Mulan PSL v2 for more details. */ #include using std::ios; -using std::ios_base; \ No newline at end of file +using std::ios_base; +using std::streamoff; +using std::streampos; diff --git a/deps/common/lang/iostream.h b/src/common/lang/iostream.h similarity index 100% rename from deps/common/lang/iostream.h rename to src/common/lang/iostream.h diff --git a/deps/common/lang/iterator.h b/src/common/lang/iterator.h similarity index 100% rename from deps/common/lang/iterator.h rename to src/common/lang/iterator.h diff --git a/deps/common/lang/limits.h b/src/common/lang/limits.h similarity index 100% rename from deps/common/lang/limits.h rename to src/common/lang/limits.h diff --git a/deps/common/lang/list.h b/src/common/lang/list.h similarity index 100% rename from deps/common/lang/list.h rename to src/common/lang/list.h diff --git a/deps/common/lang/lower_bound.h b/src/common/lang/lower_bound.h similarity index 100% rename from deps/common/lang/lower_bound.h rename to src/common/lang/lower_bound.h diff --git a/deps/common/lang/lru_cache.h b/src/common/lang/lru_cache.h similarity index 100% rename from deps/common/lang/lru_cache.h rename to src/common/lang/lru_cache.h diff --git a/deps/common/lang/map.h b/src/common/lang/map.h similarity index 100% rename from deps/common/lang/map.h rename to src/common/lang/map.h diff --git a/deps/common/lang/memory.h b/src/common/lang/memory.h similarity index 100% rename from deps/common/lang/memory.h rename to src/common/lang/memory.h diff --git a/deps/common/lang/mutex.cpp b/src/common/lang/mutex.cpp similarity index 100% rename from deps/common/lang/mutex.cpp rename to src/common/lang/mutex.cpp diff --git a/deps/common/lang/mutex.h b/src/common/lang/mutex.h similarity index 100% rename from deps/common/lang/mutex.h rename to src/common/lang/mutex.h diff --git a/deps/common/lang/new.h b/src/common/lang/new.h similarity index 100% rename from deps/common/lang/new.h rename to src/common/lang/new.h diff --git a/deps/common/lang/queue.h b/src/common/lang/queue.h similarity index 100% rename from deps/common/lang/queue.h rename to src/common/lang/queue.h diff --git a/deps/common/lang/random.h b/src/common/lang/random.h similarity index 100% rename from deps/common/lang/random.h rename to src/common/lang/random.h diff --git a/deps/common/metrics/reservoir.cpp b/src/common/lang/ranges.h similarity index 68% rename from deps/common/metrics/reservoir.cpp rename to src/common/lang/ranges.h index 68d4ba0a6..839876e8b 100644 --- a/deps/common/metrics/reservoir.cpp +++ b/src/common/lang/ranges.h @@ -8,16 +8,8 @@ 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. */ -// -// Created by Longda on 2021/4/20. -// +#pragma once -#include "reservoir.h" +#include -using namespace common; - -Reservoir::Reservoir(RandomGenerator &random) : random(random) {} - -Reservoir::~Reservoir() {} - -size_t Reservoir::next(size_t range) { return random.next(range); } +namespace ranges = std::ranges; diff --git a/deps/common/lang/serializable.h b/src/common/lang/serializable.h similarity index 100% rename from deps/common/lang/serializable.h rename to src/common/lang/serializable.h diff --git a/deps/common/lang/serializer.cpp b/src/common/lang/serializer.cpp similarity index 100% rename from deps/common/lang/serializer.cpp rename to src/common/lang/serializer.cpp diff --git a/deps/common/lang/serializer.h b/src/common/lang/serializer.h similarity index 100% rename from deps/common/lang/serializer.h rename to src/common/lang/serializer.h diff --git a/deps/common/lang/set.h b/src/common/lang/set.h similarity index 100% rename from deps/common/lang/set.h rename to src/common/lang/set.h diff --git a/deps/common/lang/span.h b/src/common/lang/span.h similarity index 100% rename from deps/common/lang/span.h rename to src/common/lang/span.h diff --git a/deps/common/lang/sstream.h b/src/common/lang/sstream.h similarity index 100% rename from deps/common/lang/sstream.h rename to src/common/lang/sstream.h diff --git a/deps/common/lang/stdexcept.h b/src/common/lang/stdexcept.h similarity index 100% rename from deps/common/lang/stdexcept.h rename to src/common/lang/stdexcept.h diff --git a/deps/common/lang/string.cpp b/src/common/lang/string.cpp similarity index 100% rename from deps/common/lang/string.cpp rename to src/common/lang/string.cpp diff --git a/deps/common/lang/string.h b/src/common/lang/string.h similarity index 98% rename from deps/common/lang/string.h rename to src/common/lang/string.h index 9bdf4aea3..d7fc1b608 100644 --- a/deps/common/lang/string.h +++ b/src/common/lang/string.h @@ -31,6 +31,9 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/set.h" using std::string; +using std::to_string; +using std::stol; +using std::stof; namespace common { diff --git a/deps/common/lang/string_view.h b/src/common/lang/string_view.h similarity index 100% rename from deps/common/lang/string_view.h rename to src/common/lang/string_view.h diff --git a/deps/common/lang/system_error.h b/src/common/lang/system_error.h similarity index 100% rename from deps/common/lang/system_error.h rename to src/common/lang/system_error.h diff --git a/deps/common/lang/thread.h b/src/common/lang/thread.h similarity index 100% rename from deps/common/lang/thread.h rename to src/common/lang/thread.h diff --git a/deps/common/metrics/log_reporter.h b/src/common/lang/tuple.h similarity index 67% rename from deps/common/metrics/log_reporter.h rename to src/common/lang/tuple.h index 38b26cf55..ba7739538 100644 --- a/deps/common/metrics/log_reporter.h +++ b/src/common/lang/tuple.h @@ -8,21 +8,8 @@ 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. */ -// -// Created by Longda on 2021/4/20. -// - #pragma once -#include "common/metrics/reporter.h" - -namespace common { - -class LogReporter : public Reporter -{ -public: - void report(const std::string &tag, Metric *metric); -}; +#include -LogReporter *get_log_reporter(); -} // namespace common +using std::tuple; diff --git a/deps/common/lang/unordered_map.h b/src/common/lang/unordered_map.h similarity index 100% rename from deps/common/lang/unordered_map.h rename to src/common/lang/unordered_map.h diff --git a/deps/common/lang/unordered_set.h b/src/common/lang/unordered_set.h similarity index 100% rename from deps/common/lang/unordered_set.h rename to src/common/lang/unordered_set.h diff --git a/deps/common/lang/utility.h b/src/common/lang/utility.h similarity index 100% rename from deps/common/lang/utility.h rename to src/common/lang/utility.h diff --git a/deps/common/lang/vector.h b/src/common/lang/vector.h similarity index 100% rename from deps/common/lang/vector.h rename to src/common/lang/vector.h diff --git a/deps/common/log/backtrace.cpp b/src/common/log/backtrace.cpp similarity index 100% rename from deps/common/log/backtrace.cpp rename to src/common/log/backtrace.cpp diff --git a/deps/common/log/backtrace.h b/src/common/log/backtrace.h similarity index 100% rename from deps/common/log/backtrace.h rename to src/common/log/backtrace.h diff --git a/deps/common/log/log.cpp b/src/common/log/log.cpp similarity index 100% rename from deps/common/log/log.cpp rename to src/common/log/log.cpp diff --git a/deps/common/log/log.h b/src/common/log/log.h similarity index 100% rename from deps/common/log/log.h rename to src/common/log/log.h diff --git a/deps/common/math/crc.cpp b/src/common/math/crc.cpp similarity index 100% rename from deps/common/math/crc.cpp rename to src/common/math/crc.cpp diff --git a/deps/common/math/crc.h b/src/common/math/crc.h similarity index 100% rename from deps/common/math/crc.h rename to src/common/math/crc.h diff --git a/deps/common/math/integer_generator.h b/src/common/math/integer_generator.h similarity index 100% rename from deps/common/math/integer_generator.h rename to src/common/math/integer_generator.h diff --git a/deps/common/math/md5.cpp b/src/common/math/md5.cpp similarity index 100% rename from deps/common/math/md5.cpp rename to src/common/math/md5.cpp diff --git a/deps/common/math/md5.h b/src/common/math/md5.h similarity index 100% rename from deps/common/math/md5.h rename to src/common/math/md5.h diff --git a/deps/common/math/random_generator.cpp b/src/common/math/random_generator.cpp similarity index 100% rename from deps/common/math/random_generator.cpp rename to src/common/math/random_generator.cpp diff --git a/deps/common/math/random_generator.h b/src/common/math/random_generator.h similarity index 100% rename from deps/common/math/random_generator.h rename to src/common/math/random_generator.h diff --git a/deps/common/math/regex.cpp b/src/common/math/regex.cpp similarity index 100% rename from deps/common/math/regex.cpp rename to src/common/math/regex.cpp diff --git a/deps/common/math/regex.h b/src/common/math/regex.h similarity index 100% rename from deps/common/math/regex.h rename to src/common/math/regex.h diff --git a/deps/common/math/simd_util.cpp b/src/common/math/simd_util.cpp similarity index 100% rename from deps/common/math/simd_util.cpp rename to src/common/math/simd_util.cpp diff --git a/deps/common/math/simd_util.h b/src/common/math/simd_util.h similarity index 100% rename from deps/common/math/simd_util.h rename to src/common/math/simd_util.h diff --git a/deps/common/mm/debug_new.h b/src/common/mm/debug_new.h similarity index 100% rename from deps/common/mm/debug_new.h rename to src/common/mm/debug_new.h diff --git a/deps/common/mm/mem_pool.cpp b/src/common/mm/mem_pool.cpp similarity index 100% rename from deps/common/mm/mem_pool.cpp rename to src/common/mm/mem_pool.cpp diff --git a/deps/common/mm/mem_pool.h b/src/common/mm/mem_pool.h similarity index 100% rename from deps/common/mm/mem_pool.h rename to src/common/mm/mem_pool.h diff --git a/deps/common/os/os.cpp b/src/common/os/os.cpp similarity index 100% rename from deps/common/os/os.cpp rename to src/common/os/os.cpp diff --git a/deps/common/os/os.h b/src/common/os/os.h similarity index 100% rename from deps/common/os/os.h rename to src/common/os/os.h diff --git a/deps/common/os/path.cpp b/src/common/os/path.cpp similarity index 100% rename from deps/common/os/path.cpp rename to src/common/os/path.cpp diff --git a/deps/common/os/path.h b/src/common/os/path.h similarity index 100% rename from deps/common/os/path.h rename to src/common/os/path.h diff --git a/deps/common/os/pidfile.cpp b/src/common/os/pidfile.cpp similarity index 100% rename from deps/common/os/pidfile.cpp rename to src/common/os/pidfile.cpp diff --git a/deps/common/os/pidfile.h b/src/common/os/pidfile.h similarity index 100% rename from deps/common/os/pidfile.h rename to src/common/os/pidfile.h diff --git a/deps/common/os/process.cpp b/src/common/os/process.cpp similarity index 100% rename from deps/common/os/process.cpp rename to src/common/os/process.cpp diff --git a/deps/common/os/process.h b/src/common/os/process.h similarity index 100% rename from deps/common/os/process.h rename to src/common/os/process.h diff --git a/deps/common/os/process_param.cpp b/src/common/os/process_param.cpp similarity index 100% rename from deps/common/os/process_param.cpp rename to src/common/os/process_param.cpp diff --git a/deps/common/os/process_param.h b/src/common/os/process_param.h similarity index 100% rename from deps/common/os/process_param.h rename to src/common/os/process_param.h diff --git a/deps/common/os/signal.cpp b/src/common/os/signal.cpp similarity index 100% rename from deps/common/os/signal.cpp rename to src/common/os/signal.cpp diff --git a/deps/common/os/signal.h b/src/common/os/signal.h similarity index 100% rename from deps/common/os/signal.h rename to src/common/os/signal.h diff --git a/deps/common/queue/queue.h b/src/common/queue/queue.h similarity index 100% rename from deps/common/queue/queue.h rename to src/common/queue/queue.h diff --git a/deps/common/queue/simple_queue.h b/src/common/queue/simple_queue.h similarity index 100% rename from deps/common/queue/simple_queue.h rename to src/common/queue/simple_queue.h diff --git a/deps/common/queue/simple_queue.ipp b/src/common/queue/simple_queue.ipp similarity index 100% rename from deps/common/queue/simple_queue.ipp rename to src/common/queue/simple_queue.ipp diff --git a/src/observer/common/rc.cpp b/src/common/sys/rc.cpp similarity index 97% rename from src/observer/common/rc.cpp rename to src/common/sys/rc.cpp index 9c2ad88e8..74b28ae7b 100644 --- a/src/observer/common/rc.cpp +++ b/src/common/sys/rc.cpp @@ -12,7 +12,7 @@ See the Mulan PSL v2 for more details. */ // Created by Wangyunlai on 2021/5/14. // -#include "common/rc.h" +#include "common/sys/rc.h" const char *strrc(RC rc) { diff --git a/src/observer/common/rc.h b/src/common/sys/rc.h similarity index 100% rename from src/observer/common/rc.h rename to src/common/sys/rc.h diff --git a/deps/common/thread/runnable.h b/src/common/thread/runnable.h similarity index 100% rename from deps/common/thread/runnable.h rename to src/common/thread/runnable.h diff --git a/deps/common/thread/thread_pool_executor.cpp b/src/common/thread/thread_pool_executor.cpp similarity index 100% rename from deps/common/thread/thread_pool_executor.cpp rename to src/common/thread/thread_pool_executor.cpp diff --git a/deps/common/thread/thread_pool_executor.h b/src/common/thread/thread_pool_executor.h similarity index 100% rename from deps/common/thread/thread_pool_executor.h rename to src/common/thread/thread_pool_executor.h diff --git a/deps/common/thread/thread_util.cpp b/src/common/thread/thread_util.cpp similarity index 100% rename from deps/common/thread/thread_util.cpp rename to src/common/thread/thread_util.cpp diff --git a/deps/common/thread/thread_util.h b/src/common/thread/thread_util.h similarity index 100% rename from deps/common/thread/thread_util.h rename to src/common/thread/thread_util.h diff --git a/deps/common/time/datetime.cpp b/src/common/time/datetime.cpp similarity index 100% rename from deps/common/time/datetime.cpp rename to src/common/time/datetime.cpp diff --git a/deps/common/time/datetime.h b/src/common/time/datetime.h similarity index 100% rename from deps/common/time/datetime.h rename to src/common/time/datetime.h diff --git a/deps/common/time/timeout_info.cpp b/src/common/time/timeout_info.cpp similarity index 100% rename from deps/common/time/timeout_info.cpp rename to src/common/time/timeout_info.cpp diff --git a/deps/common/time/timeout_info.h b/src/common/time/timeout_info.h similarity index 100% rename from deps/common/time/timeout_info.h rename to src/common/time/timeout_info.h diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt index 267344f87..cb4b32e06 100644 --- a/src/observer/CMakeLists.txt +++ b/src/observer/CMakeLists.txt @@ -1,6 +1,6 @@ MESSAGE(STATUS "This is CMAKE_CURRENT_SOURCE_DIR dir " ${CMAKE_CURRENT_SOURCE_DIR}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src/) SET (PARSER_WORKDIR ${CMAKE_CURRENT_SOURCE_DIR}/sql/parser) SET (PARSER_SOURCES ${PARSER_WORKDIR}/lex_sql.cpp ${PARSER_WORKDIR}/yacc_sql.cpp) diff --git a/src/observer/common/type/char_type.h b/src/observer/common/type/char_type.h index a56101438..74dab5092 100644 --- a/src/observer/common/type/char_type.h +++ b/src/observer/common/type/char_type.h @@ -10,7 +10,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/type/data_type.h" /** @@ -33,4 +33,4 @@ class CharType : public DataType int cast_cost(AttrType type) override; RC to_string(const Value &val, string &result) const override; -}; \ No newline at end of file +}; diff --git a/src/observer/common/type/data_type.h b/src/observer/common/type/data_type.h index 7067df4ee..a44a04a08 100644 --- a/src/observer/common/type/data_type.h +++ b/src/observer/common/type/data_type.h @@ -13,7 +13,7 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/array.h" #include "common/lang/memory.h" #include "common/lang/string.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/type/attr_type.h" class Value; diff --git a/src/observer/common/value.cpp b/src/observer/common/value.cpp index b8f04914b..6d83a58fa 100644 --- a/src/observer/common/value.cpp +++ b/src/observer/common/value.cpp @@ -236,7 +236,7 @@ int Value::get_int() const switch (attr_type_) { case AttrType::CHARS: { try { - return (int)(std::stol(value_.pointer_value_)); + return (int)(stol(value_.pointer_value_)); } catch (exception const &ex) { LOG_TRACE("failed to convert string to number. s=%s, ex=%s", value_.pointer_value_, ex.what()); return 0; @@ -264,7 +264,7 @@ float Value::get_float() const switch (attr_type_) { case AttrType::CHARS: { try { - return std::stof(value_.pointer_value_); + return stof(value_.pointer_value_); } catch (exception const &ex) { LOG_TRACE("failed to convert string to float. s=%s, ex=%s", value_.pointer_value_, ex.what()); return 0.0; @@ -294,12 +294,12 @@ bool Value::get_boolean() const switch (attr_type_) { case AttrType::CHARS: { try { - float val = std::stof(value_.pointer_value_); + float val = stof(value_.pointer_value_); if (val >= EPSILON || val <= -EPSILON) { return true; } - int int_val = std::stol(value_.pointer_value_); + int int_val = stol(value_.pointer_value_); if (int_val != 0) { return true; } diff --git a/src/observer/net/buffered_writer.cpp b/src/observer/net/buffered_writer.cpp index e77fa4793..58d189372 100644 --- a/src/observer/net/buffered_writer.cpp +++ b/src/observer/net/buffered_writer.cpp @@ -12,7 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by Wangyunlai on 2023/06/16. // -#include #ifdef __MUSL__ #include #else diff --git a/src/observer/net/communicator.cpp b/src/observer/net/communicator.cpp index a190187a1..7f80d805e 100644 --- a/src/observer/net/communicator.cpp +++ b/src/observer/net/communicator.cpp @@ -21,7 +21,7 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/mutex.h" -RC Communicator::init(int fd, unique_ptr session, const std::string &addr) +RC Communicator::init(int fd, unique_ptr session, const string &addr) { fd_ = fd; session_ = std::move(session); diff --git a/src/observer/net/communicator.h b/src/observer/net/communicator.h index f88665e9d..0d47300cb 100644 --- a/src/observer/net/communicator.h +++ b/src/observer/net/communicator.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/string.h" #include "common/lang/memory.h" diff --git a/src/observer/net/mysql_communicator.cpp b/src/observer/net/mysql_communicator.cpp index 95dd15217..d543f3a52 100644 --- a/src/observer/net/mysql_communicator.cpp +++ b/src/observer/net/mysql_communicator.cpp @@ -13,7 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include #include "common/io/io.h" #include "common/log/log.h" diff --git a/src/observer/net/one_thread_per_connection_thread_handler.cpp b/src/observer/net/one_thread_per_connection_thread_handler.cpp index 91ff69043..ae977f337 100644 --- a/src/observer/net/one_thread_per_connection_thread_handler.cpp +++ b/src/observer/net/one_thread_per_connection_thread_handler.cpp @@ -41,7 +41,7 @@ class Worker RC start() { - thread_ = new thread(std::ref(*this)); + thread_ = new thread(ref(*this)); return RC::SUCCESS; } diff --git a/src/observer/net/ring_buffer.h b/src/observer/net/ring_buffer.h index b2fb58a20..39f241a09 100644 --- a/src/observer/net/ring_buffer.h +++ b/src/observer/net/ring_buffer.h @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ #include -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/vector.h" /** diff --git a/src/observer/net/server.cpp b/src/observer/net/server.cpp index f946de013..53724e2c1 100644 --- a/src/observer/net/server.cpp +++ b/src/observer/net/server.cpp @@ -28,8 +28,6 @@ See the Mulan PSL v2 for more details. */ #include #include -#include - #include "common/ini_setting.h" #include "common/io/io.h" #include "common/lang/mutex.h" diff --git a/src/observer/net/sql_task_handler.h b/src/observer/net/sql_task_handler.h index b296fe356..8c1294ee7 100644 --- a/src/observer/net/sql_task_handler.h +++ b/src/observer/net/sql_task_handler.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "session/session_stage.h" #include "sql/executor/execute_stage.h" #include "sql/optimizer/optimize_stage.h" @@ -52,4 +52,4 @@ class SqlTaskHandler ResolveStage resolve_stage_; /// 解析阶段。将语法树解析成Stmt(statement) OptimizeStage optimize_stage_; /// 优化阶段。将语句优化成执行计划,包含规则优化和物理优化 ExecuteStage execute_stage_; /// 执行阶段 -}; \ No newline at end of file +}; diff --git a/src/observer/net/thread_handler.h b/src/observer/net/thread_handler.h index c5cf0e075..fd876e63d 100644 --- a/src/observer/net/thread_handler.h +++ b/src/observer/net/thread_handler.h @@ -14,8 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include "common/rc.h" +#include "common/sys/rc.h" class Communicator; diff --git a/src/observer/sql/executor/command_executor.h b/src/observer/sql/executor/command_executor.h index 8bb7ef58c..d0114c4c1 100644 --- a/src/observer/sql/executor/command_executor.h +++ b/src/observer/sql/executor/command_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; diff --git a/src/observer/sql/executor/create_index_executor.h b/src/observer/sql/executor/create_index_executor.h index dcc658f51..6a7c54896 100644 --- a/src/observer/sql/executor/create_index_executor.h +++ b/src/observer/sql/executor/create_index_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; @@ -30,4 +30,4 @@ class CreateIndexExecutor virtual ~CreateIndexExecutor() = default; RC execute(SQLStageEvent *sql_event); -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/create_table_executor.h b/src/observer/sql/executor/create_table_executor.h index c4ab9a733..3a7ace584 100644 --- a/src/observer/sql/executor/create_table_executor.h +++ b/src/observer/sql/executor/create_table_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; @@ -29,4 +29,4 @@ class CreateTableExecutor virtual ~CreateTableExecutor() = default; RC execute(SQLStageEvent *sql_event); -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/desc_table_executor.cpp b/src/observer/sql/executor/desc_table_executor.cpp index 3c3ba0ccb..ea993fa51 100644 --- a/src/observer/sql/executor/desc_table_executor.cpp +++ b/src/observer/sql/executor/desc_table_executor.cpp @@ -12,8 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by Wangyunlai on 2023/6/14. // -#include - #include "sql/executor/desc_table_executor.h" #include "common/log/log.h" @@ -55,7 +53,7 @@ RC DescTableExecutor::execute(SQLStageEvent *sql_event) const TableMeta &table_meta = table->table_meta(); for (int i = table_meta.sys_field_num(); i < table_meta.field_num(); i++) { const FieldMeta *field_meta = table_meta.field(i); - oper->append({field_meta->name(), attr_type_to_string(field_meta->type()), std::to_string(field_meta->len())}); + oper->append({field_meta->name(), attr_type_to_string(field_meta->type()), to_string(field_meta->len())}); } sql_result->set_operator(unique_ptr(oper)); @@ -65,4 +63,4 @@ RC DescTableExecutor::execute(SQLStageEvent *sql_event) sql_result->set_state_string("Table not exists"); } return rc; -} \ No newline at end of file +} diff --git a/src/observer/sql/executor/desc_table_executor.h b/src/observer/sql/executor/desc_table_executor.h index 9d4d6544b..7e6a40951 100644 --- a/src/observer/sql/executor/desc_table_executor.h +++ b/src/observer/sql/executor/desc_table_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; @@ -29,4 +29,4 @@ class DescTableExecutor virtual ~DescTableExecutor() = default; RC execute(SQLStageEvent *sql_event); -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/execute_stage.cpp b/src/observer/sql/executor/execute_stage.cpp index 4e61b02a7..f4354b32f 100644 --- a/src/observer/sql/executor/execute_stage.cpp +++ b/src/observer/sql/executor/execute_stage.cpp @@ -12,9 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by Longda on 2021/4/13. // -#include -#include - #include "sql/executor/execute_stage.h" #include "common/log/log.h" @@ -26,7 +23,6 @@ See the Mulan PSL v2 for more details. */ #include "sql/stmt/stmt.h" #include "storage/default/default_handler.h" -using namespace std; using namespace common; RC ExecuteStage::handle_request(SQLStageEvent *sql_event) diff --git a/src/observer/sql/executor/execute_stage.h b/src/observer/sql/executor/execute_stage.h index 356752627..5eca68161 100644 --- a/src/observer/sql/executor/execute_stage.h +++ b/src/observer/sql/executor/execute_stage.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; class SessionEvent; diff --git a/src/observer/sql/executor/help_executor.h b/src/observer/sql/executor/help_executor.h index 57371fd99..c5946aa9b 100644 --- a/src/observer/sql/executor/help_executor.h +++ b/src/observer/sql/executor/help_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "event/session_event.h" #include "event/sql_event.h" #include "sql/executor/sql_result.h" @@ -52,8 +52,8 @@ class HelpExecutor schema.append_cell("Commands"); sql_result->set_tuple_schema(schema); - sql_result->set_operator(std::unique_ptr(oper)); + sql_result->set_operator(unique_ptr(oper)); return RC::SUCCESS; } -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/load_data_executor.cpp b/src/observer/sql/executor/load_data_executor.cpp index c3d6fbe67..29ffecd5d 100644 --- a/src/observer/sql/executor/load_data_executor.cpp +++ b/src/observer/sql/executor/load_data_executor.cpp @@ -41,7 +41,7 @@ RC LoadDataExecutor::execute(SQLStageEvent *sql_event) * @return 成功返回RC::SUCCESS */ RC insert_record_from_file( - Table *table, std::vector &file_values, std::vector &record_values, std::stringstream &errmsg) + Table *table, vector &file_values, vector &record_values, stringstream &errmsg) { const int field_num = record_values.size(); @@ -53,11 +53,11 @@ RC insert_record_from_file( RC rc = RC::SUCCESS; - std::stringstream deserialize_stream; + stringstream deserialize_stream; for (int i = 0; i < field_num && RC::SUCCESS == rc; i++) { const FieldMeta *field = table->table_meta().field(i + sys_field_num); - std::string &file_value = file_values[i]; + string &file_value = file_values[i]; if (field->type() != AttrType::CHARS) { common::strip(file_value); } @@ -78,12 +78,12 @@ RC insert_record_from_file( void LoadDataExecutor::load_data(Table *table, const char *file_name, SqlResult *sql_result) { - std::stringstream result_string; + stringstream result_string; - std::fstream fs; - fs.open(file_name, std::ios_base::in | std::ios_base::binary); + fstream fs; + fs.open(file_name, ios_base::in | ios_base::binary); if (!fs.is_open()) { - result_string << "Failed to open file: " << file_name << ". system error=" << strerror(errno) << std::endl; + result_string << "Failed to open file: " << file_name << ". system error=" << strerror(errno) << endl; sql_result->set_return_code(RC::FILE_NOT_EXIST); sql_result->set_state_string(result_string.str()); return; @@ -94,15 +94,15 @@ void LoadDataExecutor::load_data(Table *table, const char *file_name, SqlResult const int sys_field_num = table->table_meta().sys_field_num(); const int field_num = table->table_meta().field_num() - sys_field_num; - std::vector record_values(field_num); - std::string line; - std::vector file_values; - const std::string delim("|"); + vector record_values(field_num); + string line; + vector file_values; + const string delim("|"); int line_num = 0; int insertion_count = 0; RC rc = RC::SUCCESS; while (!fs.eof() && RC::SUCCESS == rc) { - std::getline(fs, line); + getline(fs, line); line_num++; if (common::is_blank(line.c_str())) { continue; @@ -110,11 +110,11 @@ void LoadDataExecutor::load_data(Table *table, const char *file_name, SqlResult file_values.clear(); common::split_string(line, delim, file_values); - std::stringstream errmsg; + stringstream errmsg; rc = insert_record_from_file(table, file_values, record_values, errmsg); if (rc != RC::SUCCESS) { result_string << "Line:" << line_num << " insert record failed:" << errmsg.str() << ". error:" << strrc(rc) - << std::endl; + << endl; } else { insertion_count++; } @@ -126,7 +126,7 @@ void LoadDataExecutor::load_data(Table *table, const char *file_name, SqlResult long cost_nano = (end_time.tv_sec - begin_time.tv_sec) * 1000000000L + (end_time.tv_nsec - begin_time.tv_nsec); if (RC::SUCCESS == rc) { result_string << strrc(rc) << ". total " << line_num << " line(s) handled and " << insertion_count - << " record(s) loaded, total cost " << cost_nano / 1000000000.0 << " second(s)" << std::endl; + << " record(s) loaded, total cost " << cost_nano / 1000000000.0 << " second(s)" << endl; } sql_result->set_return_code(RC::SUCCESS); sql_result->set_state_string(result_string.str()); diff --git a/src/observer/sql/executor/load_data_executor.h b/src/observer/sql/executor/load_data_executor.h index dc023ba9b..708a6f3ba 100644 --- a/src/observer/sql/executor/load_data_executor.h +++ b/src/observer/sql/executor/load_data_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; class Table; diff --git a/src/observer/sql/executor/set_variable_executor.cpp b/src/observer/sql/executor/set_variable_executor.cpp index b5518a18e..37ad933d7 100644 --- a/src/observer/sql/executor/set_variable_executor.cpp +++ b/src/observer/sql/executor/set_variable_executor.cpp @@ -53,9 +53,9 @@ RC SetVariableExecutor::var_value_to_boolean(const Value &var_value, bool &bool_ bool_value = var_value.get_float() != 0.0; } else if (var_value.attr_type() == AttrType::CHARS) { - std::string true_strings[] = {"true", "on", "yes", "t", "1"}; + string true_strings[] = {"true", "on", "yes", "t", "1"}; - std::string false_strings[] = {"false", "off", "no", "f", "0"}; + string false_strings[] = {"false", "off", "no", "f", "0"}; for (size_t i = 0; i < sizeof(true_strings) / sizeof(true_strings[0]); i++) { if (strcasecmp(var_value.get_string().c_str(), true_strings[i].c_str()) == 0) { @@ -95,4 +95,4 @@ RC SetVariableExecutor::get_execution_mode(const Value &var_value, ExecutionMode } return rc; -} \ No newline at end of file +} diff --git a/src/observer/sql/executor/set_variable_executor.h b/src/observer/sql/executor/set_variable_executor.h index 8af0d2b69..55e45f757 100644 --- a/src/observer/sql/executor/set_variable_executor.h +++ b/src/observer/sql/executor/set_variable_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "event/session_event.h" #include "event/sql_event.h" #include "session/session.h" @@ -36,4 +36,4 @@ class SetVariableExecutor RC var_value_to_boolean(const Value &var_value, bool &bool_value) const; RC get_execution_mode(const Value &var_value, ExecutionMode &execution_mode) const; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/show_tables_executor.h b/src/observer/sql/executor/show_tables_executor.h index 3561faffe..0b6acf6ca 100644 --- a/src/observer/sql/executor/show_tables_executor.h +++ b/src/observer/sql/executor/show_tables_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "event/session_event.h" #include "event/sql_event.h" #include "session/session.h" @@ -40,7 +40,7 @@ class ShowTablesExecutor Db *db = session_event->session()->get_current_db(); - std::vector all_tables; + vector all_tables; db->all_tables(all_tables); TupleSchema tuple_schema; @@ -48,11 +48,11 @@ class ShowTablesExecutor sql_result->set_tuple_schema(tuple_schema); auto oper = new StringListPhysicalOperator; - for (const std::string &s : all_tables) { + for (const string &s : all_tables) { oper->append(s); } - sql_result->set_operator(std::unique_ptr(oper)); + sql_result->set_operator(unique_ptr(oper)); return RC::SUCCESS; } -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/sql_result.cpp b/src/observer/sql/executor/sql_result.cpp index a8b1b8551..939d6ab8a 100644 --- a/src/observer/sql/executor/sql_result.cpp +++ b/src/observer/sql/executor/sql_result.cpp @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #include "sql/executor/sql_result.h" #include "common/log/log.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "session/session.h" #include "storage/trx/trx.h" @@ -75,7 +75,7 @@ RC SqlResult::next_chunk(Chunk &chunk) return rc; } -void SqlResult::set_operator(std::unique_ptr oper) +void SqlResult::set_operator(unique_ptr oper) { ASSERT(operator_ == nullptr, "current operator is not null. Result is not closed?"); operator_ = std::move(oper); diff --git a/src/observer/sql/executor/sql_result.h b/src/observer/sql/executor/sql_result.h index 016cfd179..aed92e26d 100644 --- a/src/observer/sql/executor/sql_result.h +++ b/src/observer/sql/executor/sql_result.h @@ -14,9 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - +#include "common/lang/string.h" +#include "common/lang/memory.h" #include "sql/expr/tuple.h" #include "sql/operator/physical_operator.h" @@ -37,14 +36,14 @@ class SqlResult void set_tuple_schema(const TupleSchema &schema); void set_return_code(RC rc) { return_code_ = rc; } - void set_state_string(const std::string &state_string) { state_string_ = state_string; } + void set_state_string(const string &state_string) { state_string_ = state_string; } - void set_operator(std::unique_ptr oper); + void set_operator(unique_ptr oper); bool has_operator() const { return operator_ != nullptr; } const TupleSchema &tuple_schema() const { return tuple_schema_; } RC return_code() const { return return_code_; } - const std::string &state_string() const { return state_string_; } + const string &state_string() const { return state_string_; } RC open(); RC close(); @@ -53,8 +52,8 @@ class SqlResult private: Session *session_ = nullptr; ///< 当前所属会话 - std::unique_ptr operator_; ///< 执行计划 + unique_ptr operator_; ///< 执行计划 TupleSchema tuple_schema_; ///< 返回的表头信息。可能有也可能没有 RC return_code_ = RC::SUCCESS; - std::string state_string_; + string state_string_; }; diff --git a/src/observer/sql/executor/trx_begin_executor.h b/src/observer/sql/executor/trx_begin_executor.h index a97b8148e..87f3d2d88 100644 --- a/src/observer/sql/executor/trx_begin_executor.h +++ b/src/observer/sql/executor/trx_begin_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "event/session_event.h" #include "event/sql_event.h" #include "session/session.h" @@ -41,4 +41,4 @@ class TrxBeginExecutor return trx->start_if_need(); } -}; \ No newline at end of file +}; diff --git a/src/observer/sql/executor/trx_end_executor.h b/src/observer/sql/executor/trx_end_executor.h index f1208aea3..8a3a08de4 100644 --- a/src/observer/sql/executor/trx_end_executor.h +++ b/src/observer/sql/executor/trx_end_executor.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "event/session_event.h" #include "event/sql_event.h" #include "session/session.h" @@ -46,4 +46,4 @@ class TrxEndExecutor return trx->rollback(); } } -}; \ No newline at end of file +}; diff --git a/src/observer/sql/expr/aggregate_hash_table.cpp b/src/observer/sql/expr/aggregate_hash_table.cpp index cde07fd41..7be3d878c 100644 --- a/src/observer/sql/expr/aggregate_hash_table.cpp +++ b/src/observer/sql/expr/aggregate_hash_table.cpp @@ -51,11 +51,11 @@ RC StandardAggregateHashTable::Scanner::next(Chunk &output_chunk) size_t StandardAggregateHashTable::VectorHash::operator()(const vector &vec) const { - size_t hash = 0; + size_t hash_val = 0; for (const auto &elem : vec) { - hash ^= std::hash()(elem.to_string()); + hash_val ^= hash()(elem.to_string()); } - return hash; + return hash_val; } bool StandardAggregateHashTable::VectorEqual::operator()(const vector &lhs, const vector &rhs) const @@ -180,8 +180,8 @@ template void LinearProbingAggregateHashTable::resize() { capacity_ *= 2; - std::vector new_keys(capacity_); - std::vector new_values(capacity_); + vector new_keys(capacity_); + vector new_values(capacity_); for (size_t i = 0; i < keys_.size(); i++) { auto &key = keys_[i]; @@ -243,4 +243,4 @@ const int LinearProbingAggregateHashTable::DEFAULT_CAPACITY = 16384; template class LinearProbingAggregateHashTable; template class LinearProbingAggregateHashTable; -#endif \ No newline at end of file +#endif diff --git a/src/observer/sql/expr/aggregate_hash_table.h b/src/observer/sql/expr/aggregate_hash_table.h index 89719c9bc..f1e83bbb2 100644 --- a/src/observer/sql/expr/aggregate_hash_table.h +++ b/src/observer/sql/expr/aggregate_hash_table.h @@ -8,12 +8,12 @@ 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 -#include -#include +#pragma once +#include "common/lang/vector.h" +#include "common/lang/unordered_map.h" #include "common/math/simd_util.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/expr/expression.h" /** @@ -54,16 +54,16 @@ class StandardAggregateHashTable : public AggregateHashTable private: struct VectorHash { - std::size_t operator()(const std::vector &vec) const; + size_t operator()(const vector &vec) const; }; struct VectorEqual { - bool operator()(const std::vector &lhs, const std::vector &rhs) const; + bool operator()(const vector &lhs, const vector &rhs) const; }; public: - using StandardHashTable = std::unordered_map, std::vector, VectorHash, VectorEqual>; + using StandardHashTable = unordered_map, vector, VectorHash, VectorEqual>; class Scanner : public AggregateHashTable::Scanner { public: @@ -78,7 +78,7 @@ class StandardAggregateHashTable : public AggregateHashTable StandardHashTable::iterator end_; StandardHashTable::iterator it_; }; - StandardAggregateHashTable(const std::vector aggregations) + StandardAggregateHashTable(const vector aggregations) { for (auto &expr : aggregations) { ASSERT(expr->type() == ExprType::AGGREGATION, "expect aggregate expression"); @@ -97,7 +97,7 @@ class StandardAggregateHashTable : public AggregateHashTable private: /// group by values -> aggregate values StandardHashTable aggr_values_; - std::vector aggr_types_; + vector aggr_types_; }; /** @@ -162,10 +162,10 @@ class LinearProbingAggregateHashTable : public AggregateHashTable static const int EMPTY_KEY; static const int DEFAULT_CAPACITY; - std::vector keys_; - std::vector values_; + vector keys_; + vector values_; int size_ = 0; int capacity_ = 0; AggregateExpr::Type aggregate_type_; }; -#endif \ No newline at end of file +#endif // USE_SIMD diff --git a/src/observer/sql/expr/aggregate_state.cpp b/src/observer/sql/expr/aggregate_state.cpp index 124cb277d..220253544 100644 --- a/src/observer/sql/expr/aggregate_state.cpp +++ b/src/observer/sql/expr/aggregate_state.cpp @@ -8,8 +8,6 @@ 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 - #include "sql/expr/aggregate_state.h" #ifdef USE_SIMD @@ -19,9 +17,9 @@ template void SumState::update(const T *values, int size) { #ifdef USE_SIMD - if constexpr (std::is_same::value) { + if constexpr (is_same::value) { value += mm256_sum_ps(values, size); - } else if constexpr (std::is_same::value) { + } else if constexpr (is_same::value) { value += mm256_sum_epi32(values, size); } #else @@ -32,4 +30,4 @@ void SumState::update(const T *values, int size) } template class SumState; -template class SumState; \ No newline at end of file +template class SumState; diff --git a/src/observer/sql/expr/aggregator.h b/src/observer/sql/expr/aggregator.h index c1af3d659..08a9b8ae3 100644 --- a/src/observer/sql/expr/aggregator.h +++ b/src/observer/sql/expr/aggregator.h @@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */ #pragma once #include "common/value.h" -#include "common/rc.h" +#include "common/sys/rc.h" class Aggregator { @@ -34,4 +34,4 @@ class SumAggregator : public Aggregator public: RC accumulate(const Value &value) override; RC evaluate(Value &result) override; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/expr/arithmetic_operator.hpp b/src/observer/sql/expr/arithmetic_operator.hpp index 2b15e2ef2..e5560703a 100644 --- a/src/observer/sql/expr/arithmetic_operator.hpp +++ b/src/observer/sql/expr/arithmetic_operator.hpp @@ -205,11 +205,11 @@ struct NegateOperator }; template -void compare_operation(T *left, T *right, int n, std::vector &result) +void compare_operation(T *left, T *right, int n, vector &result) { #if defined(USE_SIMD) int i = 0; - if constexpr (std::is_same::value) { + if constexpr (is_same::value) { for (; i <= n - SIMD_WIDTH; i += SIMD_WIDTH) { __m256 left_value, right_value; @@ -232,7 +232,7 @@ void compare_operation(T *left, T *right, int n, std::vector &result) result[i + j] &= mm256_extract_epi32_var_indx(mask, j) ? 1 : 0; } } - } else if constexpr (std::is_same::value) { + } else if constexpr (is_same::value) { for (; i <= n - SIMD_WIDTH; i += SIMD_WIDTH) { __m256i left_value, right_value; @@ -276,7 +276,7 @@ void binary_operator(T *left_data, T *right_data, T *result_data, int size) #if defined(USE_SIMD) int i = 0; - if constexpr (std::is_same::value) { + if constexpr (is_same::value) { for (; i <= size - SIMD_WIDTH; i += SIMD_WIDTH) { __m256 left_value, right_value; @@ -295,7 +295,7 @@ void binary_operator(T *left_data, T *right_data, T *result_data, int size) __m256 result_value = OP::operation(left_value, right_value); _mm256_storeu_ps(&result_data[i], result_value); } - } else if constexpr (std::is_same::value) { + } else if constexpr (is_same::value) { for (; i <= size - SIMD_WIDTH; i += SIMD_WIDTH) { __m256i left_value, right_value; @@ -342,7 +342,7 @@ void unary_operator(T *input, T *result_data, int size) // TODO: optimized with simd template -void compare_result(T *left, T *right, int n, std::vector &result, CompOp op) +void compare_result(T *left, T *right, int n, vector &result, CompOp op) { switch (op) { case CompOp::EQUAL_TO: { @@ -371,4 +371,4 @@ void compare_result(T *left, T *right, int n, std::vector &result, Comp } default: break; } -} \ No newline at end of file +} diff --git a/src/observer/sql/expr/composite_tuple.h b/src/observer/sql/expr/composite_tuple.h index d3e655776..f8883295d 100644 --- a/src/observer/sql/expr/composite_tuple.h +++ b/src/observer/sql/expr/composite_tuple.h @@ -42,9 +42,9 @@ class CompositeTuple : public Tuple RC spec_at(int index, TupleCellSpec &spec) const override; RC find_cell(const TupleCellSpec &spec, Value &cell) const override; - void add_tuple(std::unique_ptr tuple); + void add_tuple(unique_ptr tuple); Tuple &tuple_at(size_t index); private: - std::vector> tuples_; -}; \ No newline at end of file + vector> tuples_; +}; diff --git a/src/observer/sql/expr/expression.cpp b/src/observer/sql/expr/expression.cpp index 1c1aa48c1..92cd84d7a 100644 --- a/src/observer/sql/expr/expression.cpp +++ b/src/observer/sql/expr/expression.cpp @@ -197,7 +197,7 @@ RC ComparisonExpr::get_value(const Tuple &tuple, Value &value) const return rc; } -RC ComparisonExpr::eval(Chunk &chunk, std::vector &select) +RC ComparisonExpr::eval(Chunk &chunk, vector &select) { RC rc = RC::SUCCESS; Column left_column; @@ -230,7 +230,7 @@ RC ComparisonExpr::eval(Chunk &chunk, std::vector &select) } template -RC ComparisonExpr::compare_column(const Column &left, const Column &right, std::vector &result) const +RC ComparisonExpr::compare_column(const Column &left, const Column &right, vector &result) const { RC rc = RC::SUCCESS; @@ -467,7 +467,7 @@ RC ArithmeticExpr::calc_column(const Column &left_column, const Column &right_co RC rc = RC::SUCCESS; const AttrType target_type = value_type(); - column.init(target_type, left_column.attr_len(), std::max(left_column.count(), right_column.count())); + column.init(target_type, left_column.attr_len(), max(left_column.count(), right_column.count())); bool left_const = left_column.column_type() == Column::Type::CONSTANT_COLUMN; bool right_const = right_column.column_type() == Column::Type::CONSTANT_COLUMN; if (left_const && right_const) { @@ -583,4 +583,4 @@ RC AggregateExpr::type_from_string(const char *type_str, AggregateExpr::Type &ty rc = RC::INVALID_ARGUMENT; } return rc; -} \ No newline at end of file +} diff --git a/src/observer/sql/expr/expression.h b/src/observer/sql/expr/expression.h index 7058fda4b..4c1ee0775 100644 --- a/src/observer/sql/expr/expression.h +++ b/src/observer/sql/expr/expression.h @@ -14,9 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - +#include "common/lang/string.h" +#include "common/lang/memory.h" #include "common/value.h" #include "storage/field/field.h" #include "sql/expr/aggregator.h" @@ -109,7 +108,7 @@ class Expression * @brief 表达式的名字,比如是字段名称,或者用户在执行SQL语句时输入的内容 */ virtual const char *name() const { return name_.c_str(); } - virtual void set_name(std::string name) { name_ = name; } + virtual void set_name(string name) { name_ = name; } /** * @brief 表达式在下层算子返回的 chunk 中的位置 @@ -120,7 +119,7 @@ class Expression /** * @brief 用于 ComparisonExpr 获得比较结果 `select`。 */ - virtual RC eval(Chunk &chunk, std::vector &select) { return RC::UNIMPLEMENTED; } + virtual RC eval(Chunk &chunk, vector &select) { return RC::UNIMPLEMENTED; } protected: /** @@ -132,7 +131,7 @@ class Expression int pos_ = -1; private: - std::string name_; + string name_; }; class StarExpr : public Expression @@ -150,13 +149,13 @@ class StarExpr : public Expression const char *table_name() const { return table_name_.c_str(); } private: - std::string table_name_; + string table_name_; }; class UnboundFieldExpr : public Expression { public: - UnboundFieldExpr(const std::string &table_name, const std::string &field_name) + UnboundFieldExpr(const string &table_name, const string &field_name) : table_name_(table_name), field_name_(field_name) {} @@ -171,8 +170,8 @@ class UnboundFieldExpr : public Expression const char *field_name() const { return field_name_.c_str(); } private: - std::string table_name_; - std::string field_name_; + string table_name_; + string field_name_; }; /** @@ -249,7 +248,7 @@ class ValueExpr : public Expression class CastExpr : public Expression { public: - CastExpr(std::unique_ptr child, AttrType cast_type); + CastExpr(unique_ptr child, AttrType cast_type); virtual ~CastExpr(); ExprType type() const override { return ExprType::CAST; } @@ -260,13 +259,13 @@ class CastExpr : public Expression AttrType value_type() const override { return cast_type_; } - std::unique_ptr &child() { return child_; } + unique_ptr &child() { return child_; } private: RC cast(const Value &value, Value &cast_value) const; private: - std::unique_ptr child_; ///< 从这个表达式转换 + unique_ptr child_; ///< 从这个表达式转换 AttrType cast_type_; ///< 想要转换成这个类型 }; @@ -277,7 +276,7 @@ class CastExpr : public Expression class ComparisonExpr : public Expression { public: - ComparisonExpr(CompOp comp, std::unique_ptr left, std::unique_ptr right); + ComparisonExpr(CompOp comp, unique_ptr left, unique_ptr right); virtual ~ComparisonExpr(); ExprType type() const override { return ExprType::COMPARISON; } @@ -289,10 +288,10 @@ class ComparisonExpr : public Expression * @brief 根据 ComparisonExpr 获得 `select` 结果。 * select 的长度与chunk 的行数相同,表示每一行在ComparisonExpr 计算后是否会被输出。 */ - RC eval(Chunk &chunk, std::vector &select) override; + RC eval(Chunk &chunk, vector &select) override; - std::unique_ptr &left() { return left_; } - std::unique_ptr &right() { return right_; } + unique_ptr &left() { return left_; } + unique_ptr &right() { return right_; } /** * 尝试在没有tuple的情况下获取当前表达式的值 @@ -307,12 +306,12 @@ class ComparisonExpr : public Expression RC compare_value(const Value &left, const Value &right, bool &value) const; template - RC compare_column(const Column &left, const Column &right, std::vector &result) const; + RC compare_column(const Column &left, const Column &right, vector &result) const; private: CompOp comp_; - std::unique_ptr left_; - std::unique_ptr right_; + unique_ptr left_; + unique_ptr right_; }; /** @@ -331,7 +330,7 @@ class ConjunctionExpr : public Expression }; public: - ConjunctionExpr(Type type, std::vector> &children); + ConjunctionExpr(Type type, vector> &children); virtual ~ConjunctionExpr() = default; ExprType type() const override { return ExprType::CONJUNCTION; } @@ -340,11 +339,11 @@ class ConjunctionExpr : public Expression Type conjunction_type() const { return conjunction_type_; } - std::vector> &children() { return children_; } + vector> &children() { return children_; } private: Type conjunction_type_; - std::vector> children_; + vector> children_; }; /** @@ -365,7 +364,7 @@ class ArithmeticExpr : public Expression public: ArithmeticExpr(Type type, Expression *left, Expression *right); - ArithmeticExpr(Type type, std::unique_ptr left, std::unique_ptr right); + ArithmeticExpr(Type type, unique_ptr left, unique_ptr right); virtual ~ArithmeticExpr() = default; bool equal(const Expression &other) const override; @@ -388,8 +387,8 @@ class ArithmeticExpr : public Expression Type arithmetic_type() const { return arithmetic_type_; } - std::unique_ptr &left() { return left_; } - std::unique_ptr &right() { return right_; } + unique_ptr &left() { return left_; } + unique_ptr &right() { return right_; } private: RC calc_value(const Value &left_value, const Value &right_value, Value &value) const; @@ -401,8 +400,8 @@ class ArithmeticExpr : public Expression private: Type arithmetic_type_; - std::unique_ptr left_; - std::unique_ptr right_; + unique_ptr left_; + unique_ptr right_; }; class UnboundAggregateExpr : public Expression @@ -415,14 +414,14 @@ class UnboundAggregateExpr : public Expression const char *aggregate_name() const { return aggregate_name_.c_str(); } - std::unique_ptr &child() { return child_; } + unique_ptr &child() { return child_; } RC get_value(const Tuple &tuple, Value &value) const override { return RC::INTERNAL; } AttrType value_type() const override { return child_->value_type(); } private: - std::string aggregate_name_; - std::unique_ptr child_; + string aggregate_name_; + unique_ptr child_; }; class AggregateExpr : public Expression @@ -439,7 +438,7 @@ class AggregateExpr : public Expression public: AggregateExpr(Type type, Expression *child); - AggregateExpr(Type type, std::unique_ptr child); + AggregateExpr(Type type, unique_ptr child); virtual ~AggregateExpr() = default; bool equal(const Expression &other) const override; @@ -455,16 +454,16 @@ class AggregateExpr : public Expression Type aggregate_type() const { return aggregate_type_; } - std::unique_ptr &child() { return child_; } + unique_ptr &child() { return child_; } - const std::unique_ptr &child() const { return child_; } + const unique_ptr &child() const { return child_; } - std::unique_ptr create_aggregator() const; + unique_ptr create_aggregator() const; public: static RC type_from_string(const char *type_str, Type &type); private: Type aggregate_type_; - std::unique_ptr child_; -}; \ No newline at end of file + unique_ptr child_; +}; diff --git a/src/observer/sql/expr/expression_iterator.h b/src/observer/sql/expr/expression_iterator.h index 2ad0298ca..a03095c19 100644 --- a/src/observer/sql/expr/expression_iterator.h +++ b/src/observer/sql/expr/expression_iterator.h @@ -14,15 +14,14 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - -#include "common/rc.h" +#include "common/sys/rc.h" +#include "common/lang/functional.h" +#include "common/lang/memory.h" class Expression; class ExpressionIterator { public: - static RC iterate_child_expr(Expression &expr, std::function &)> callback); -}; \ No newline at end of file + static RC iterate_child_expr(Expression &expr, function &)> callback); +}; diff --git a/src/observer/sql/expr/expression_tuple.h b/src/observer/sql/expr/expression_tuple.h index 21f34fdb7..df9dbe0bd 100644 --- a/src/observer/sql/expr/expression_tuple.h +++ b/src/observer/sql/expr/expression_tuple.h @@ -14,17 +14,16 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - +#include "common/lang/vector.h" #include "sql/expr/tuple.h" #include "common/value.h" -#include "common/rc.h" +#include "common/sys/rc.h" template class ExpressionTuple : public Tuple { public: - ExpressionTuple(const std::vector &expressions) : expressions_(expressions) {} + ExpressionTuple(const vector &expressions) : expressions_(expressions) {} virtual ~ExpressionTuple() = default; void set_tuple(const Tuple *tuple) { child_tuple_ = tuple; } @@ -86,6 +85,6 @@ class ExpressionTuple : public Tuple } private: - const std::vector &expressions_; + const vector &expressions_; const Tuple *child_tuple_ = nullptr; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/expr/tuple.h b/src/observer/sql/expr/tuple.h index 0215602ac..0f20398e7 100644 --- a/src/observer/sql/expr/tuple.h +++ b/src/observer/sql/expr/tuple.h @@ -14,10 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include -#include - #include "common/log/log.h" #include "sql/expr/expression.h" #include "sql/expr/tuple_cell.h" @@ -59,7 +55,7 @@ class TupleSchema const TupleCellSpec &cell_at(int i) const { return cells_[i]; } private: - std::vector cells_; + vector cells_; }; /** @@ -96,9 +92,9 @@ class Tuple */ virtual RC find_cell(const TupleCellSpec &spec, Value &cell) const = 0; - virtual std::string to_string() const + virtual string to_string() const { - std::string str; + string str; const int cell_num = this->cell_num(); for (int i = 0; i < cell_num - 1; i++) { Value cell; @@ -173,7 +169,7 @@ class RowTuple : public Tuple void set_record(Record *record) { this->record_ = record; } - void set_schema(const Table *table, const std::vector *fields) + void set_schema(const Table *table, const vector *fields) { table_ = table; // fix:join当中会多次调用右表的open,open当中会调用set_scheme,从而导致tuple当中会存储 @@ -248,7 +244,7 @@ class RowTuple : public Tuple private: Record *record_ = nullptr; const Table *table_ = nullptr; - std::vector speces_; + vector speces_; }; /** @@ -263,12 +259,12 @@ class ProjectTuple : public Tuple ProjectTuple() = default; virtual ~ProjectTuple() = default; - void set_expressions(std::vector> &&expressions) + void set_expressions(vector> &&expressions) { expressions_ = std::move(expressions); } - auto get_expressions() const -> const std::vector> & { return expressions_; } + auto get_expressions() const -> const vector> & { return expressions_; } void set_tuple(Tuple *tuple) { this->tuple_ = tuple; } @@ -306,7 +302,7 @@ class ProjectTuple : public Tuple } #endif private: - std::vector> expressions_; + vector> expressions_; Tuple *tuple_ = nullptr; }; @@ -321,8 +317,8 @@ class ValueListTuple : public Tuple ValueListTuple() = default; virtual ~ValueListTuple() = default; - void set_names(const std::vector &specs) { specs_ = specs; } - void set_cells(const std::vector &cells) { cells_ = cells; } + void set_names(const vector &specs) { specs_ = specs; } + void set_cells(const vector &cells) { cells_ = cells; } virtual int cell_num() const override { return static_cast(cells_.size()); } @@ -383,8 +379,8 @@ class ValueListTuple : public Tuple } private: - std::vector cells_; - std::vector specs_; + vector cells_; + vector specs_; }; /** diff --git a/src/observer/sql/expr/tuple_cell.h b/src/observer/sql/expr/tuple_cell.h index b9ba210e9..3268f2f29 100644 --- a/src/observer/sql/expr/tuple_cell.h +++ b/src/observer/sql/expr/tuple_cell.h @@ -15,7 +15,6 @@ See the Mulan PSL v2 for more details. */ #pragma once #include "storage/field/field_meta.h" -#include class TupleCellSpec final { @@ -23,7 +22,7 @@ class TupleCellSpec final TupleCellSpec() = default; TupleCellSpec(const char *table_name, const char *field_name, const char *alias = nullptr); explicit TupleCellSpec(const char *alias); - explicit TupleCellSpec(const std::string &alias); + explicit TupleCellSpec(const string &alias); const char *table_name() const { return table_name_.c_str(); } const char *field_name() const { return field_name_.c_str(); } @@ -35,7 +34,7 @@ class TupleCellSpec final } private: - std::string table_name_; - std::string field_name_; - std::string alias_; + string table_name_; + string field_name_; + string alias_; }; diff --git a/src/observer/sql/operator/aggregate_vec_physical_operator.cpp b/src/observer/sql/operator/aggregate_vec_physical_operator.cpp index 710c64721..daec1864a 100644 --- a/src/observer/sql/operator/aggregate_vec_physical_operator.cpp +++ b/src/observer/sql/operator/aggregate_vec_physical_operator.cpp @@ -8,14 +8,13 @@ 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 #include "common/log/log.h" +#include "common/lang/ranges.h" #include "sql/operator/aggregate_vec_physical_operator.h" #include "sql/expr/aggregate_state.h" #include "sql/expr/expression_tuple.h" #include "sql/expr/composite_tuple.h" -using namespace std; using namespace common; AggregateVecPhysicalOperator::AggregateVecPhysicalOperator(vector &&expressions) @@ -109,4 +108,4 @@ RC AggregateVecPhysicalOperator::close() children_[0]->close(); LOG_INFO("close group by operator"); return RC::SUCCESS; -} \ No newline at end of file +} diff --git a/src/observer/sql/operator/aggregate_vec_physical_operator.h b/src/observer/sql/operator/aggregate_vec_physical_operator.h index 143710f94..2dd748a21 100644 --- a/src/observer/sql/operator/aggregate_vec_physical_operator.h +++ b/src/observer/sql/operator/aggregate_vec_physical_operator.h @@ -19,7 +19,7 @@ See the Mulan PSL v2 for more details. */ class AggregateVecPhysicalOperator : public PhysicalOperator { public: - AggregateVecPhysicalOperator(std::vector &&expressions); + AggregateVecPhysicalOperator(vector &&expressions); virtual ~AggregateVecPhysicalOperator() = default; @@ -64,11 +64,11 @@ class AggregateVecPhysicalOperator : public PhysicalOperator } private: - std::vector data_; + vector data_; }; - std::vector aggregate_expressions_; /// 聚合表达式 - std::vector value_expressions_; + vector aggregate_expressions_; /// 聚合表达式 + vector value_expressions_; Chunk chunk_; Chunk output_chunk_; AggregateValues aggr_values_; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/operator/calc_logical_operator.h b/src/observer/sql/operator/calc_logical_operator.h index b993f3e96..d7a0f5207 100644 --- a/src/observer/sql/operator/calc_logical_operator.h +++ b/src/observer/sql/operator/calc_logical_operator.h @@ -14,8 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - #include "sql/operator/logical_operator.h" /** @@ -25,7 +23,7 @@ See the Mulan PSL v2 for more details. */ class CalcLogicalOperator : public LogicalOperator { public: - CalcLogicalOperator(std::vector> &&expressions) { expressions_.swap(expressions); } + CalcLogicalOperator(vector> &&expressions) { expressions_.swap(expressions); } virtual ~CalcLogicalOperator() = default; LogicalOperatorType type() const override { return LogicalOperatorType::CALC; } diff --git a/src/observer/sql/operator/calc_physical_operator.h b/src/observer/sql/operator/calc_physical_operator.h index d7002c823..19a9c55de 100644 --- a/src/observer/sql/operator/calc_physical_operator.h +++ b/src/observer/sql/operator/calc_physical_operator.h @@ -20,7 +20,7 @@ See the Mulan PSL v2 for more details. */ class CalcPhysicalOperator : public PhysicalOperator { public: - CalcPhysicalOperator(std::vector> &&expressions) + CalcPhysicalOperator(vector> &&expressions) : expressions_(std::move(expressions)), tuple_(expressions_) {} @@ -28,8 +28,8 @@ class CalcPhysicalOperator : public PhysicalOperator PhysicalOperatorType type() const override { return PhysicalOperatorType::CALC; } - std::string name() const override { return "CALC"; } - std::string param() const override { return ""; } + string name() const override { return "CALC"; } + string param() const override { return ""; } RC open(Trx *trx) override { return RC::SUCCESS; } RC next() override @@ -57,18 +57,18 @@ class CalcPhysicalOperator : public PhysicalOperator Tuple *current_tuple() override { return &tuple_; } - const std::vector> &expressions() const { return expressions_; } + const vector> &expressions() const { return expressions_; } RC tuple_schema(TupleSchema &schema) const override { - for (const std::unique_ptr &expression : expressions_) { + for (const unique_ptr &expression : expressions_) { schema.append_cell(expression->name()); } return RC::SUCCESS; } private: - std::vector> expressions_; - ExpressionTuple> tuple_; + vector> expressions_; + ExpressionTuple> tuple_; bool emitted_ = false; }; diff --git a/src/observer/sql/operator/delete_physical_operator.cpp b/src/observer/sql/operator/delete_physical_operator.cpp index aaf34dfe3..ea239a9b0 100644 --- a/src/observer/sql/operator/delete_physical_operator.cpp +++ b/src/observer/sql/operator/delete_physical_operator.cpp @@ -23,7 +23,7 @@ RC DeletePhysicalOperator::open(Trx *trx) return RC::SUCCESS; } - std::unique_ptr &child = children_[0]; + unique_ptr &child = children_[0]; RC rc = child->open(trx); if (rc != RC::SUCCESS) { diff --git a/src/observer/sql/operator/delete_physical_operator.h b/src/observer/sql/operator/delete_physical_operator.h index d3c00fbb4..32e67d804 100644 --- a/src/observer/sql/operator/delete_physical_operator.h +++ b/src/observer/sql/operator/delete_physical_operator.h @@ -39,7 +39,7 @@ class DeletePhysicalOperator : public PhysicalOperator Tuple *current_tuple() override { return nullptr; } private: - Table *table_ = nullptr; - Trx *trx_ = nullptr; - std::vector records_; + Table *table_ = nullptr; + Trx *trx_ = nullptr; + vector records_; }; diff --git a/src/observer/sql/operator/explain_physical_operator.cpp b/src/observer/sql/operator/explain_physical_operator.cpp index da5573703..37aa586d4 100644 --- a/src/observer/sql/operator/explain_physical_operator.cpp +++ b/src/observer/sql/operator/explain_physical_operator.cpp @@ -14,7 +14,6 @@ See the Mulan PSL v2 for more details. */ #include "sql/operator/explain_physical_operator.h" #include "common/log/log.h" -#include using namespace std; @@ -32,7 +31,7 @@ void ExplainPhysicalOperator::generate_physical_plan() ss << "OPERATOR(NAME)\n"; int level = 0; - std::vector ends; + vector ends; ends.push_back(true); const auto children_size = static_cast(children_.size()); for (int i = 0; i < children_size - 1; i++) { @@ -84,7 +83,7 @@ Tuple *ExplainPhysicalOperator::current_tuple() { return &tuple_; } * @param ends 表示当前某个层级上的算子,是否已经没有其它的节点,以判断使用什么打印符号 */ void ExplainPhysicalOperator::to_string( - std::ostream &os, PhysicalOperator *oper, int level, bool last_child, std::vector &ends) + ostream &os, PhysicalOperator *oper, int level, bool last_child, vector &ends) { for (int i = 0; i < level - 1; i++) { if (ends[i]) { @@ -103,7 +102,7 @@ void ExplainPhysicalOperator::to_string( } os << oper->name(); - std::string param = oper->param(); + string param = oper->param(); if (!param.empty()) { os << "(" << param << ")"; } @@ -114,7 +113,7 @@ void ExplainPhysicalOperator::to_string( } ends[level + 1] = false; - vector> &children = oper->children(); + vector> &children = oper->children(); const auto size = static_cast(children.size()); for (auto i = 0; i < size - 1; i++) { to_string(os, children[i].get(), level + 1, false /*last_child*/, ends); diff --git a/src/observer/sql/operator/explain_physical_operator.h b/src/observer/sql/operator/explain_physical_operator.h index 73431ddc8..0b965c3c8 100644 --- a/src/observer/sql/operator/explain_physical_operator.h +++ b/src/observer/sql/operator/explain_physical_operator.h @@ -41,11 +41,11 @@ class ExplainPhysicalOperator : public PhysicalOperator } private: - void to_string(std::ostream &os, PhysicalOperator *oper, int level, bool last_child, std::vector &ends); + void to_string(ostream &os, PhysicalOperator *oper, int level, bool last_child, vector &ends); void generate_physical_plan(); private: - std::string physical_plan_; + string physical_plan_; ValueListTuple tuple_; }; diff --git a/src/observer/sql/operator/expr_vec_physical_operator.cpp b/src/observer/sql/operator/expr_vec_physical_operator.cpp index d1babab00..3c871de96 100644 --- a/src/observer/sql/operator/expr_vec_physical_operator.cpp +++ b/src/observer/sql/operator/expr_vec_physical_operator.cpp @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ using namespace std; using namespace common; -ExprVecPhysicalOperator::ExprVecPhysicalOperator(std::vector &&expressions) +ExprVecPhysicalOperator::ExprVecPhysicalOperator(vector &&expressions) { expressions_ = std::move(expressions); } @@ -44,7 +44,7 @@ RC ExprVecPhysicalOperator::next(Chunk &chunk) evaled_chunk_.reset(); if (OB_SUCC(rc = child.next(chunk_))) { for (size_t i = 0; i < expressions_.size(); i++) { - auto column = std::make_unique(); + auto column = make_unique(); expressions_[i]->get_column(chunk_, *column); evaled_chunk_.add_column(std::move(column), i); } @@ -58,4 +58,4 @@ RC ExprVecPhysicalOperator::close() children_[0]->close(); LOG_INFO("close group by operator"); return RC::SUCCESS; -} \ No newline at end of file +} diff --git a/src/observer/sql/operator/expr_vec_physical_operator.h b/src/observer/sql/operator/expr_vec_physical_operator.h index f48db7d56..047c8cb8c 100644 --- a/src/observer/sql/operator/expr_vec_physical_operator.h +++ b/src/observer/sql/operator/expr_vec_physical_operator.h @@ -19,7 +19,7 @@ See the Mulan PSL v2 for more details. */ class ExprVecPhysicalOperator : public PhysicalOperator { public: - ExprVecPhysicalOperator(std::vector &&expressions); + ExprVecPhysicalOperator(vector &&expressions); virtual ~ExprVecPhysicalOperator() = default; @@ -30,7 +30,7 @@ class ExprVecPhysicalOperator : public PhysicalOperator RC close() override; private: - std::vector expressions_; /// 表达式 + vector expressions_; /// 表达式 Chunk chunk_; Chunk evaled_chunk_; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/operator/group_by_logical_operator.cpp b/src/observer/sql/operator/group_by_logical_operator.cpp index c35bbf917..5d86d847c 100644 --- a/src/observer/sql/operator/group_by_logical_operator.cpp +++ b/src/observer/sql/operator/group_by_logical_operator.cpp @@ -12,8 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by WangYunlai on 2024/05/30. // -#include - #include "common/log/log.h" #include "sql/operator/group_by_logical_operator.h" #include "sql/expr/expression.h" @@ -25,4 +23,4 @@ GroupByLogicalOperator::GroupByLogicalOperator(vector> && { group_by_expressions_ = std::move(group_by_exprs); aggregate_expressions_ = std::move(expressions); -} \ No newline at end of file +} diff --git a/src/observer/sql/operator/group_by_logical_operator.h b/src/observer/sql/operator/group_by_logical_operator.h index 888e94788..9e66d1db6 100644 --- a/src/observer/sql/operator/group_by_logical_operator.h +++ b/src/observer/sql/operator/group_by_logical_operator.h @@ -19,8 +19,7 @@ See the Mulan PSL v2 for more details. */ class GroupByLogicalOperator : public LogicalOperator { public: - GroupByLogicalOperator( - std::vector> &&group_by_exprs, std::vector &&expressions); + GroupByLogicalOperator(vector> &&group_by_exprs, vector &&expressions); virtual ~GroupByLogicalOperator() = default; @@ -30,6 +29,6 @@ class GroupByLogicalOperator : public LogicalOperator auto &aggregate_expressions() { return aggregate_expressions_; } private: - std::vector> group_by_expressions_; - std::vector aggregate_expressions_; ///< 输出的表达式,可能包含聚合函数 -}; \ No newline at end of file + vector> group_by_expressions_; + vector aggregate_expressions_; ///< 输出的表达式,可能包含聚合函数 +}; diff --git a/src/observer/sql/operator/group_by_physical_operator.cpp b/src/observer/sql/operator/group_by_physical_operator.cpp index e28aea55c..c925a82b6 100644 --- a/src/observer/sql/operator/group_by_physical_operator.cpp +++ b/src/observer/sql/operator/group_by_physical_operator.cpp @@ -11,7 +11,6 @@ See the Mulan PSL v2 for more details. */ // // Created by WangYunlai on 2024/06/11. // -#include #include "common/log/log.h" #include "sql/operator/group_by_physical_operator.h" @@ -101,4 +100,4 @@ RC GroupByPhysicalOperator::evaluate(GroupValueType &group_value) composite_value_tuple.add_tuple(make_unique(std::move(evaluated_tuple))); return rc; -} \ No newline at end of file +} diff --git a/src/observer/sql/operator/group_by_physical_operator.h b/src/observer/sql/operator/group_by_physical_operator.h index 5c2da57e4..5c7a8f3ef 100644 --- a/src/observer/sql/operator/group_by_physical_operator.h +++ b/src/observer/sql/operator/group_by_physical_operator.h @@ -14,6 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once +#include "common/lang/tuple.h" #include "sql/operator/physical_operator.h" #include "sql/expr/composite_tuple.h" @@ -24,11 +25,11 @@ See the Mulan PSL v2 for more details. */ class GroupByPhysicalOperator : public PhysicalOperator { public: - GroupByPhysicalOperator(std::vector &&expressions); + GroupByPhysicalOperator(vector &&expressions); virtual ~GroupByPhysicalOperator() = default; protected: - using AggregatorList = std::vector>; + using AggregatorList = vector>; /** * @brief 聚合出来的一组数据 * @details @@ -38,7 +39,7 @@ class GroupByPhysicalOperator : public PhysicalOperator * select a, b, sum(a) from t group by a; * 我们需要知道b的值是什么,虽然它不确定。 */ - using GroupValueType = std::tuple; + using GroupValueType = tuple; protected: void create_aggregator_list(AggregatorList &aggregator_list); @@ -52,6 +53,6 @@ class GroupByPhysicalOperator : public PhysicalOperator RC evaluate(GroupValueType &group_value); protected: - std::vector aggregate_expressions_; /// 聚合表达式 - std::vector value_expressions_; /// 计算聚合时的表达式 -}; \ No newline at end of file + vector aggregate_expressions_; /// 聚合表达式 + vector value_expressions_; /// 计算聚合时的表达式 +}; diff --git a/src/observer/sql/operator/group_by_vec_physical_operator.h b/src/observer/sql/operator/group_by_vec_physical_operator.h index e78469b4e..fe00deec7 100644 --- a/src/observer/sql/operator/group_by_vec_physical_operator.h +++ b/src/observer/sql/operator/group_by_vec_physical_operator.h @@ -20,8 +20,7 @@ See the Mulan PSL v2 for more details. */ class GroupByVecPhysicalOperator : public PhysicalOperator { public: - GroupByVecPhysicalOperator( - std::vector> &&group_by_exprs, std::vector &&expressions){}; + GroupByVecPhysicalOperator(vector> &&group_by_exprs, vector &&expressions){}; virtual ~GroupByVecPhysicalOperator() = default; @@ -32,4 +31,4 @@ class GroupByVecPhysicalOperator : public PhysicalOperator RC close() override { return RC::UNIMPLEMENTED; } private: -}; \ No newline at end of file +}; diff --git a/src/observer/sql/operator/hash_group_by_physical_operator.h b/src/observer/sql/operator/hash_group_by_physical_operator.h index c38ae39da..d04319887 100644 --- a/src/observer/sql/operator/hash_group_by_physical_operator.h +++ b/src/observer/sql/operator/hash_group_by_physical_operator.h @@ -28,7 +28,7 @@ class HashGroupByPhysicalOperator : public GroupByPhysicalOperator { public: HashGroupByPhysicalOperator( - std::vector> &&group_by_exprs, std::vector &&expressions); + vector> &&group_by_exprs, vector &&expressions); virtual ~HashGroupByPhysicalOperator() = default; @@ -44,19 +44,19 @@ class HashGroupByPhysicalOperator : public GroupByPhysicalOperator using AggregatorList = GroupByPhysicalOperator::AggregatorList; using GroupValueType = GroupByPhysicalOperator::GroupValueType; /// 聚合出来的一组数据 - using GroupType = std::tuple; + using GroupType = tuple; private: RC find_group(const Tuple &child_tuple, GroupType *&found_group); private: - std::vector> group_by_exprs_; + vector> group_by_exprs_; /// 一组一条数据 /// pair的first是group by 的值列表,second是计算出来的表达式值列表 /// TODO 改成hash/unordered_map - std::vector groups_; + vector groups_; - std::vector::iterator current_group_; + vector::iterator current_group_; bool first_emited_ = false; /// 第一条数据是否已经输出 -}; \ No newline at end of file +}; diff --git a/src/observer/sql/operator/index_scan_physical_operator.cpp b/src/observer/sql/operator/index_scan_physical_operator.cpp index 51bed88f1..97a514a67 100644 --- a/src/observer/sql/operator/index_scan_physical_operator.cpp +++ b/src/observer/sql/operator/index_scan_physical_operator.cpp @@ -115,7 +115,7 @@ Tuple *IndexScanPhysicalOperator::current_tuple() return &tuple_; } -void IndexScanPhysicalOperator::set_predicates(std::vector> &&exprs) +void IndexScanPhysicalOperator::set_predicates(vector> &&exprs) { predicates_ = std::move(exprs); } @@ -124,7 +124,7 @@ RC IndexScanPhysicalOperator::filter(RowTuple &tuple, bool &result) { RC rc = RC::SUCCESS; Value value; - for (std::unique_ptr &expr : predicates_) { + for (unique_ptr &expr : predicates_) { rc = expr->get_value(tuple, value); if (rc != RC::SUCCESS) { return rc; @@ -141,7 +141,7 @@ RC IndexScanPhysicalOperator::filter(RowTuple &tuple, bool &result) return rc; } -std::string IndexScanPhysicalOperator::param() const +string IndexScanPhysicalOperator::param() const { - return std::string(index_->index_meta().name()) + " ON " + table_->name(); + return string(index_->index_meta().name()) + " ON " + table_->name(); } diff --git a/src/observer/sql/operator/index_scan_physical_operator.h b/src/observer/sql/operator/index_scan_physical_operator.h index 902c49f61..1153ade6d 100644 --- a/src/observer/sql/operator/index_scan_physical_operator.h +++ b/src/observer/sql/operator/index_scan_physical_operator.h @@ -32,7 +32,7 @@ class IndexScanPhysicalOperator : public PhysicalOperator PhysicalOperatorType type() const override { return PhysicalOperatorType::INDEX_SCAN; } - std::string param() const override; + string param() const override; RC open(Trx *trx) override; RC next() override; @@ -40,7 +40,7 @@ class IndexScanPhysicalOperator : public PhysicalOperator Tuple *current_tuple() override; - void set_predicates(std::vector> &&exprs); + void set_predicates(vector> &&exprs); private: // 与TableScanPhysicalOperator代码相同,可以优化 @@ -62,5 +62,5 @@ class IndexScanPhysicalOperator : public PhysicalOperator bool left_inclusive_ = false; bool right_inclusive_ = false; - std::vector> predicates_; + vector> predicates_; }; diff --git a/src/observer/sql/operator/insert_logical_operator.cpp b/src/observer/sql/operator/insert_logical_operator.cpp index 09f30e44e..51ad27a2e 100644 --- a/src/observer/sql/operator/insert_logical_operator.cpp +++ b/src/observer/sql/operator/insert_logical_operator.cpp @@ -14,5 +14,5 @@ See the Mulan PSL v2 for more details. */ #include "sql/operator/insert_logical_operator.h" -InsertLogicalOperator::InsertLogicalOperator(Table *table, std::vector values) : table_(table), values_(values) +InsertLogicalOperator::InsertLogicalOperator(Table *table, vector values) : table_(table), values_(values) {} diff --git a/src/observer/sql/operator/insert_logical_operator.h b/src/observer/sql/operator/insert_logical_operator.h index 18d9178ae..ea68f7cb5 100644 --- a/src/observer/sql/operator/insert_logical_operator.h +++ b/src/observer/sql/operator/insert_logical_operator.h @@ -14,8 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - #include "sql/operator/logical_operator.h" #include "sql/parser/parse_defs.h" @@ -26,16 +24,16 @@ See the Mulan PSL v2 for more details. */ class InsertLogicalOperator : public LogicalOperator { public: - InsertLogicalOperator(Table *table, std::vector values); + InsertLogicalOperator(Table *table, vector values); virtual ~InsertLogicalOperator() = default; LogicalOperatorType type() const override { return LogicalOperatorType::INSERT; } Table *table() const { return table_; } - const std::vector &values() const { return values_; } - std::vector &values() { return values_; } + const vector &values() const { return values_; } + vector &values() { return values_; } private: Table *table_ = nullptr; - std::vector values_; -}; \ No newline at end of file + vector values_; +}; diff --git a/src/observer/sql/operator/insert_physical_operator.h b/src/observer/sql/operator/insert_physical_operator.h index ac47a5385..ea1947e97 100644 --- a/src/observer/sql/operator/insert_physical_operator.h +++ b/src/observer/sql/operator/insert_physical_operator.h @@ -16,7 +16,6 @@ See the Mulan PSL v2 for more details. */ #include "sql/operator/physical_operator.h" #include "sql/parser/parse.h" -#include class InsertStmt; @@ -27,7 +26,7 @@ class InsertStmt; class InsertPhysicalOperator : public PhysicalOperator { public: - InsertPhysicalOperator(Table *table, std::vector &&values); + InsertPhysicalOperator(Table *table, vector &&values); virtual ~InsertPhysicalOperator() = default; @@ -40,6 +39,6 @@ class InsertPhysicalOperator : public PhysicalOperator Tuple *current_tuple() override { return nullptr; } private: - Table *table_ = nullptr; - std::vector values_; + Table *table_ = nullptr; + vector values_; }; diff --git a/src/observer/sql/operator/logical_operator.cpp b/src/observer/sql/operator/logical_operator.cpp index d11d6fd1e..8e9f3c3eb 100644 --- a/src/observer/sql/operator/logical_operator.cpp +++ b/src/observer/sql/operator/logical_operator.cpp @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ LogicalOperator::~LogicalOperator() {} -void LogicalOperator::add_child(std::unique_ptr oper) { children_.emplace_back(std::move(oper)); } +void LogicalOperator::add_child(unique_ptr oper) { children_.emplace_back(std::move(oper)); } bool LogicalOperator::can_generate_vectorized_operator(const LogicalOperatorType &type) { bool bool_ret = false; diff --git a/src/observer/sql/operator/logical_operator.h b/src/observer/sql/operator/logical_operator.h index 32fb13cd8..b6dbbd286 100644 --- a/src/observer/sql/operator/logical_operator.h +++ b/src/observer/sql/operator/logical_operator.h @@ -14,9 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - #include "sql/expr/expression.h" /** @@ -55,15 +52,15 @@ class LogicalOperator virtual LogicalOperatorType type() const = 0; - void add_child(std::unique_ptr oper); - auto children() -> std::vector> &{ return children_; } - auto expressions() -> std::vector> &{ return expressions_; } + void add_child(unique_ptr oper); + auto children() -> vector> &{ return children_; } + auto expressions() -> vector> &{ return expressions_; } static bool can_generate_vectorized_operator(const LogicalOperatorType &type); protected: - std::vector> children_; ///< 子算子 + vector> children_; ///< 子算子 ///< 表达式,比如select中的列,where中的谓词等等,都可以使用表达式来表示 ///< 表达式能是一个常量,也可以是一个函数,也可以是一个列,也可以是一个子查询等等 - std::vector> expressions_; + vector> expressions_; }; diff --git a/src/observer/sql/operator/physical_operator.cpp b/src/observer/sql/operator/physical_operator.cpp index fa81906d0..f20904989 100644 --- a/src/observer/sql/operator/physical_operator.cpp +++ b/src/observer/sql/operator/physical_operator.cpp @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #include "sql/operator/physical_operator.h" -std::string physical_operator_type_name(PhysicalOperatorType type) +string physical_operator_type_name(PhysicalOperatorType type) { switch (type) { case PhysicalOperatorType::TABLE_SCAN: return "TABLE_SCAN"; @@ -37,6 +37,6 @@ std::string physical_operator_type_name(PhysicalOperatorType type) } } -std::string PhysicalOperator::name() const { return physical_operator_type_name(type()); } +string PhysicalOperator::name() const { return physical_operator_type_name(type()); } -std::string PhysicalOperator::param() const { return ""; } +string PhysicalOperator::param() const { return ""; } diff --git a/src/observer/sql/operator/physical_operator.h b/src/observer/sql/operator/physical_operator.h index a3b20ed34..32e1cb856 100644 --- a/src/observer/sql/operator/physical_operator.h +++ b/src/observer/sql/operator/physical_operator.h @@ -14,11 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include -#include - -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/expr/tuple.h" class Record; @@ -71,8 +67,8 @@ class PhysicalOperator /** * 这两个函数是为了打印时使用的,比如在explain中 */ - virtual std::string name() const; - virtual std::string param() const; + virtual string name() const; + virtual string param() const; virtual PhysicalOperatorType type() const = 0; @@ -85,10 +81,10 @@ class PhysicalOperator virtual RC tuple_schema(TupleSchema &schema) const { return RC::UNIMPLEMENTED; } - void add_child(std::unique_ptr oper) { children_.emplace_back(std::move(oper)); } + void add_child(unique_ptr oper) { children_.emplace_back(std::move(oper)); } - std::vector> &children() { return children_; } + vector> &children() { return children_; } protected: - std::vector> children_; + vector> children_; }; diff --git a/src/observer/sql/operator/predicate_logical_operator.cpp b/src/observer/sql/operator/predicate_logical_operator.cpp index 3c7fd12b1..e7db87c77 100644 --- a/src/observer/sql/operator/predicate_logical_operator.cpp +++ b/src/observer/sql/operator/predicate_logical_operator.cpp @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #include "sql/operator/predicate_logical_operator.h" -PredicateLogicalOperator::PredicateLogicalOperator(std::unique_ptr expression) +PredicateLogicalOperator::PredicateLogicalOperator(unique_ptr expression) { expressions_.emplace_back(std::move(expression)); } diff --git a/src/observer/sql/operator/predicate_logical_operator.h b/src/observer/sql/operator/predicate_logical_operator.h index 3b2116ce1..565054e9f 100644 --- a/src/observer/sql/operator/predicate_logical_operator.h +++ b/src/observer/sql/operator/predicate_logical_operator.h @@ -24,7 +24,7 @@ See the Mulan PSL v2 for more details. */ class PredicateLogicalOperator : public LogicalOperator { public: - PredicateLogicalOperator(std::unique_ptr expression); + PredicateLogicalOperator(unique_ptr expression); virtual ~PredicateLogicalOperator() = default; LogicalOperatorType type() const override { return LogicalOperatorType::PREDICATE; } diff --git a/src/observer/sql/operator/predicate_physical_operator.h b/src/observer/sql/operator/predicate_physical_operator.h index fbd5b1042..407d11133 100644 --- a/src/observer/sql/operator/predicate_physical_operator.h +++ b/src/observer/sql/operator/predicate_physical_operator.h @@ -26,7 +26,7 @@ class FilterStmt; class PredicatePhysicalOperator : public PhysicalOperator { public: - PredicatePhysicalOperator(std::unique_ptr expr); + PredicatePhysicalOperator(unique_ptr expr); virtual ~PredicatePhysicalOperator() = default; @@ -41,5 +41,5 @@ class PredicatePhysicalOperator : public PhysicalOperator RC tuple_schema(TupleSchema &schema) const override; private: - std::unique_ptr expression_; + unique_ptr expression_; }; diff --git a/src/observer/sql/operator/project_logical_operator.h b/src/observer/sql/operator/project_logical_operator.h index 0d4a2d500..3bd169a9f 100644 --- a/src/observer/sql/operator/project_logical_operator.h +++ b/src/observer/sql/operator/project_logical_operator.h @@ -14,9 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - #include "sql/expr/expression.h" #include "sql/operator/logical_operator.h" #include "storage/field/field.h" @@ -29,11 +26,11 @@ See the Mulan PSL v2 for more details. */ class ProjectLogicalOperator : public LogicalOperator { public: - ProjectLogicalOperator(std::vector> &&expressions); + ProjectLogicalOperator(vector> &&expressions); virtual ~ProjectLogicalOperator() = default; LogicalOperatorType type() const override { return LogicalOperatorType::PROJECTION; } - std::vector> &expressions() { return expressions_; } - const std::vector> &expressions() const { return expressions_; } + vector> &expressions() { return expressions_; } + const vector> &expressions() const { return expressions_; } }; diff --git a/src/observer/sql/operator/project_physical_operator.h b/src/observer/sql/operator/project_physical_operator.h index 603e76572..189328743 100644 --- a/src/observer/sql/operator/project_physical_operator.h +++ b/src/observer/sql/operator/project_physical_operator.h @@ -24,7 +24,7 @@ See the Mulan PSL v2 for more details. */ class ProjectPhysicalOperator : public PhysicalOperator { public: - ProjectPhysicalOperator(std::vector> &&expressions); + ProjectPhysicalOperator(vector> &&expressions); virtual ~ProjectPhysicalOperator() = default; @@ -41,6 +41,6 @@ class ProjectPhysicalOperator : public PhysicalOperator RC tuple_schema(TupleSchema &schema) const override; private: - std::vector> expressions_; - ExpressionTuple> tuple_; + vector> expressions_; + ExpressionTuple> tuple_; }; diff --git a/src/observer/sql/operator/project_vec_physical_operator.h b/src/observer/sql/operator/project_vec_physical_operator.h index c63a1154d..5d3792ffb 100644 --- a/src/observer/sql/operator/project_vec_physical_operator.h +++ b/src/observer/sql/operator/project_vec_physical_operator.h @@ -21,7 +21,7 @@ class ProjectVecPhysicalOperator : public PhysicalOperator { public: ProjectVecPhysicalOperator() {} - ProjectVecPhysicalOperator(std::vector> &&expressions); + ProjectVecPhysicalOperator(vector> &&expressions); virtual ~ProjectVecPhysicalOperator() = default; @@ -33,9 +33,9 @@ class ProjectVecPhysicalOperator : public PhysicalOperator RC tuple_schema(TupleSchema &schema) const override; - std::vector> &expressions() { return expressions_; } + vector> &expressions() { return expressions_; } private: - std::vector> expressions_; + vector> expressions_; Chunk chunk_; }; diff --git a/src/observer/sql/operator/scalar_group_by_physical_operator.h b/src/observer/sql/operator/scalar_group_by_physical_operator.h index 110d965a8..542bf9657 100644 --- a/src/observer/sql/operator/scalar_group_by_physical_operator.h +++ b/src/observer/sql/operator/scalar_group_by_physical_operator.h @@ -23,7 +23,7 @@ See the Mulan PSL v2 for more details. */ class ScalarGroupByPhysicalOperator : public GroupByPhysicalOperator { public: - ScalarGroupByPhysicalOperator(std::vector &&expressions); + ScalarGroupByPhysicalOperator(vector &&expressions); virtual ~ScalarGroupByPhysicalOperator() = default; PhysicalOperatorType type() const override { return PhysicalOperatorType::SCALAR_GROUP_BY; } @@ -35,6 +35,6 @@ class ScalarGroupByPhysicalOperator : public GroupByPhysicalOperator Tuple *current_tuple() override; private: - std::unique_ptr group_value_; + unique_ptr group_value_; bool emitted_ = false; /// 标识是否已经输出过 -}; \ No newline at end of file +}; diff --git a/src/observer/sql/operator/string_list_physical_operator.h b/src/observer/sql/operator/string_list_physical_operator.h index 86ffd3fc4..609238c7f 100644 --- a/src/observer/sql/operator/string_list_physical_operator.h +++ b/src/observer/sql/operator/string_list_physical_operator.h @@ -14,8 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once +#include "common/lang/initializer_list.h" #include "sql/operator/physical_operator.h" -#include /** * @brief 字符串列表物理算子 @@ -35,7 +35,7 @@ class StringListPhysicalOperator : public PhysicalOperator strings_.emplace_back(begin, end); } - void append(std::initializer_list init) { strings_.emplace_back(init); } + void append(initializer_list init) { strings_.emplace_back(init); } template void append(const T &v) @@ -71,8 +71,8 @@ class StringListPhysicalOperator : public PhysicalOperator } const StringList &string_list = *iterator_; - std::vector cells; - for (const std::string &s : string_list) { + vector cells; + for (const string &s : string_list) { Value value(s.c_str()); cells.push_back(value); @@ -82,8 +82,8 @@ class StringListPhysicalOperator : public PhysicalOperator } private: - using StringList = std::vector; - using StringListList = std::vector; + using StringList = vector; + using StringListList = vector; StringListList strings_; StringListList::iterator iterator_; bool started_ = false; diff --git a/src/observer/sql/operator/table_get_logical_operator.cpp b/src/observer/sql/operator/table_get_logical_operator.cpp index 6933c0cd3..e7e68fb9c 100644 --- a/src/observer/sql/operator/table_get_logical_operator.cpp +++ b/src/observer/sql/operator/table_get_logical_operator.cpp @@ -18,7 +18,7 @@ TableGetLogicalOperator::TableGetLogicalOperator(Table *table, ReadWriteMode mod : table_(table), mode_(mode) {} -void TableGetLogicalOperator::set_predicates(std::vector> &&exprs) +void TableGetLogicalOperator::set_predicates(vector> &&exprs) { predicates_ = std::move(exprs); } diff --git a/src/observer/sql/operator/table_get_logical_operator.h b/src/observer/sql/operator/table_get_logical_operator.h index 4551a3717..2e2754211 100644 --- a/src/observer/sql/operator/table_get_logical_operator.h +++ b/src/observer/sql/operator/table_get_logical_operator.h @@ -33,8 +33,8 @@ class TableGetLogicalOperator : public LogicalOperator Table *table() const { return table_; } ReadWriteMode read_write_mode() const { return mode_; } - void set_predicates(std::vector> &&exprs); - auto predicates() -> std::vector> & { return predicates_; } + void set_predicates(vector> &&exprs); + auto predicates() -> vector> & { return predicates_; } private: Table *table_ = nullptr; @@ -44,5 +44,5 @@ class TableGetLogicalOperator : public LogicalOperator // 这里的表达式都是比较简单的比较运算,并且左右两边都是取字段表达式或值表达式 // 不包含复杂的表达式运算,比如加减乘除、或者conjunction expression // 如果有多个表达式,他们的关系都是 AND - std::vector> predicates_; + vector> predicates_; }; diff --git a/src/observer/sql/operator/table_scan_physical_operator.h b/src/observer/sql/operator/table_scan_physical_operator.h index 206ecfd84..1e45e8716 100644 --- a/src/observer/sql/operator/table_scan_physical_operator.h +++ b/src/observer/sql/operator/table_scan_physical_operator.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/operator/physical_operator.h" #include "storage/record/record_manager.h" #include "common/types.h" @@ -32,7 +32,7 @@ class TableScanPhysicalOperator : public PhysicalOperator virtual ~TableScanPhysicalOperator() = default; - std::string param() const override; + string param() const override; PhysicalOperatorType type() const override { return PhysicalOperatorType::TABLE_SCAN; } @@ -42,17 +42,17 @@ class TableScanPhysicalOperator : public PhysicalOperator Tuple *current_tuple() override; - void set_predicates(std::vector> &&exprs); + void set_predicates(vector> &&exprs); private: RC filter(RowTuple &tuple, bool &result); private: - Table *table_ = nullptr; - Trx *trx_ = nullptr; - ReadWriteMode mode_ = ReadWriteMode::READ_WRITE; - RecordFileScanner record_scanner_; - Record current_record_; - RowTuple tuple_; - std::vector> predicates_; // TODO chang predicate to table tuple filter + Table *table_ = nullptr; + Trx *trx_ = nullptr; + ReadWriteMode mode_ = ReadWriteMode::READ_WRITE; + RecordFileScanner record_scanner_; + Record current_record_; + RowTuple tuple_; + vector> predicates_; // TODO chang predicate to table tuple filter }; diff --git a/src/observer/sql/operator/table_scan_vec_physical_operator.h b/src/observer/sql/operator/table_scan_vec_physical_operator.h index 4f10f3d1b..8982055dd 100644 --- a/src/observer/sql/operator/table_scan_vec_physical_operator.h +++ b/src/observer/sql/operator/table_scan_vec_physical_operator.h @@ -10,7 +10,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/operator/physical_operator.h" #include "storage/record/record_manager.h" #include "common/types.h" @@ -28,7 +28,7 @@ class TableScanVecPhysicalOperator : public PhysicalOperator virtual ~TableScanVecPhysicalOperator() = default; - std::string param() const override; + string param() const override; PhysicalOperatorType type() const override { return PhysicalOperatorType::TABLE_SCAN_VEC; } @@ -36,17 +36,17 @@ class TableScanVecPhysicalOperator : public PhysicalOperator RC next(Chunk &chunk) override; RC close() override; - void set_predicates(std::vector> &&exprs); + void set_predicates(vector> &&exprs); private: RC filter(Chunk &chunk); private: - Table *table_ = nullptr; - ReadWriteMode mode_ = ReadWriteMode::READ_WRITE; - ChunkFileScanner chunk_scanner_; - Chunk all_columns_; - Chunk filterd_columns_; - std::vector select_; - std::vector> predicates_; + Table *table_ = nullptr; + ReadWriteMode mode_ = ReadWriteMode::READ_WRITE; + ChunkFileScanner chunk_scanner_; + Chunk all_columns_; + Chunk filterd_columns_; + vector select_; + vector> predicates_; }; diff --git a/src/observer/sql/optimizer/comparison_simplification_rule.cpp b/src/observer/sql/optimizer/comparison_simplification_rule.cpp index 67e9d64ed..99a7655ce 100644 --- a/src/observer/sql/optimizer/comparison_simplification_rule.cpp +++ b/src/observer/sql/optimizer/comparison_simplification_rule.cpp @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ #include "common/log/log.h" #include "sql/expr/expression.h" -RC ComparisonSimplificationRule::rewrite(std::unique_ptr &expr, bool &change_made) +RC ComparisonSimplificationRule::rewrite(unique_ptr &expr, bool &change_made) { RC rc = RC::SUCCESS; @@ -28,7 +28,7 @@ RC ComparisonSimplificationRule::rewrite(std::unique_ptr &expr, bool RC sub_rc = cmp_expr->try_get_value(value); if (sub_rc == RC::SUCCESS) { - std::unique_ptr new_expr(new ValueExpr(value)); + unique_ptr new_expr(new ValueExpr(value)); expr.swap(new_expr); change_made = true; LOG_TRACE("comparison expression is simplified"); diff --git a/src/observer/sql/optimizer/comparison_simplification_rule.h b/src/observer/sql/optimizer/comparison_simplification_rule.h index 45f1c4e4c..f46e70d6e 100644 --- a/src/observer/sql/optimizer/comparison_simplification_rule.h +++ b/src/observer/sql/optimizer/comparison_simplification_rule.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/optimizer/rewrite_rule.h" class LogicalOperator; @@ -31,7 +31,7 @@ class ComparisonSimplificationRule : public ExpressionRewriteRule ComparisonSimplificationRule() = default; virtual ~ComparisonSimplificationRule() = default; - RC rewrite(std::unique_ptr &expr, bool &change_made) override; + RC rewrite(unique_ptr &expr, bool &change_made) override; private: }; diff --git a/src/observer/sql/optimizer/conjunction_simplification_rule.cpp b/src/observer/sql/optimizer/conjunction_simplification_rule.cpp index d60a1b55d..5ba4e4148 100644 --- a/src/observer/sql/optimizer/conjunction_simplification_rule.cpp +++ b/src/observer/sql/optimizer/conjunction_simplification_rule.cpp @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ #include "common/log/log.h" #include "sql/expr/expression.h" -RC try_to_get_bool_constant(std::unique_ptr &expr, bool &constant_value) +RC try_to_get_bool_constant(unique_ptr &expr, bool &constant_value) { if (expr->type() == ExprType::VALUE && expr->value_type() == AttrType::BOOLEANS) { auto value_expr = static_cast(expr.get()); @@ -25,7 +25,7 @@ RC try_to_get_bool_constant(std::unique_ptr &expr, bool &constant_va } return RC::INTERNAL; } -RC ConjunctionSimplificationRule::rewrite(std::unique_ptr &expr, bool &change_made) +RC ConjunctionSimplificationRule::rewrite(unique_ptr &expr, bool &change_made) { RC rc = RC::SUCCESS; if (expr->type() != ExprType::CONJUNCTION) { @@ -35,7 +35,7 @@ RC ConjunctionSimplificationRule::rewrite(std::unique_ptr &expr, boo change_made = false; auto conjunction_expr = static_cast(expr.get()); - std::vector> &child_exprs = conjunction_expr->children(); + vector> &child_exprs = conjunction_expr->children(); // 先看看有没有能够直接去掉的表达式。比如AND时恒为true的表达式可以删除 // 或者是否可以直接计算出当前表达式的值。比如AND时,如果有一个表达式为false,那么整个表达式就是false @@ -54,7 +54,7 @@ RC ConjunctionSimplificationRule::rewrite(std::unique_ptr &expr, boo child_exprs.erase(iter); } else { // always be false - std::unique_ptr child_expr = std::move(child_exprs.front()); + unique_ptr child_expr = std::move(child_exprs.front()); child_exprs.clear(); expr = std::move(child_expr); return rc; @@ -63,7 +63,7 @@ RC ConjunctionSimplificationRule::rewrite(std::unique_ptr &expr, boo // conjunction_type == OR if (constant_value == true) { // always be true - std::unique_ptr child_expr = std::move(child_exprs.front()); + unique_ptr child_expr = std::move(child_exprs.front()); child_exprs.clear(); expr = std::move(child_expr); return rc; @@ -74,7 +74,7 @@ RC ConjunctionSimplificationRule::rewrite(std::unique_ptr &expr, boo } if (child_exprs.size() == 1) { LOG_TRACE("conjunction expression has only 1 child"); - std::unique_ptr child_expr = std::move(child_exprs.front()); + unique_ptr child_expr = std::move(child_exprs.front()); child_exprs.clear(); expr = std::move(child_expr); diff --git a/src/observer/sql/optimizer/conjunction_simplification_rule.h b/src/observer/sql/optimizer/conjunction_simplification_rule.h index d0ba0fb8c..c855f0141 100644 --- a/src/observer/sql/optimizer/conjunction_simplification_rule.h +++ b/src/observer/sql/optimizer/conjunction_simplification_rule.h @@ -29,7 +29,7 @@ class ConjunctionSimplificationRule : public ExpressionRewriteRule ConjunctionSimplificationRule() = default; virtual ~ConjunctionSimplificationRule() = default; - RC rewrite(std::unique_ptr &expr, bool &change_made) override; + RC rewrite(unique_ptr &expr, bool &change_made) override; private: }; diff --git a/src/observer/sql/optimizer/expression_rewriter.h b/src/observer/sql/optimizer/expression_rewriter.h index dbea1055c..3376b1db8 100644 --- a/src/observer/sql/optimizer/expression_rewriter.h +++ b/src/observer/sql/optimizer/expression_rewriter.h @@ -14,9 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - -#include "common/rc.h" +#include "common/lang/memory.h" +#include "common/sys/rc.h" #include "sql/expr/expression.h" #include "sql/operator/logical_operator.h" #include "sql/optimizer/rewrite_rule.h" @@ -27,11 +26,11 @@ class ExpressionRewriter : public RewriteRule ExpressionRewriter(); virtual ~ExpressionRewriter() = default; - RC rewrite(std::unique_ptr &oper, bool &change_made) override; + RC rewrite(unique_ptr &oper, bool &change_made) override; private: - RC rewrite_expression(std::unique_ptr &expr, bool &change_made); + RC rewrite_expression(unique_ptr &expr, bool &change_made); private: - std::vector> expr_rewrite_rules_; + vector> expr_rewrite_rules_; }; diff --git a/src/observer/sql/optimizer/logical_plan_generator.cpp b/src/observer/sql/optimizer/logical_plan_generator.cpp index 8c418b320..de3b60009 100644 --- a/src/observer/sql/optimizer/logical_plan_generator.cpp +++ b/src/observer/sql/optimizer/logical_plan_generator.cpp @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #include "sql/optimizer/logical_plan_generator.h" -#include +#include "common/log/log.h" #include "sql/operator/calc_logical_operator.h" #include "sql/operator/delete_logical_operator.h" @@ -80,7 +80,7 @@ RC LogicalPlanGenerator::create(Stmt *stmt, unique_ptr &logical return rc; } -RC LogicalPlanGenerator::create_plan(CalcStmt *calc_stmt, std::unique_ptr &logical_operator) +RC LogicalPlanGenerator::create_plan(CalcStmt *calc_stmt, unique_ptr &logical_operator) { logical_operator.reset(new CalcLogicalOperator(std::move(calc_stmt->expressions()))); return RC::SUCCESS; @@ -93,7 +93,7 @@ RC LogicalPlanGenerator::create_plan(SelectStmt *select_stmt, unique_ptr table_oper(nullptr); last_oper = &table_oper; - const std::vector &tables = select_stmt->tables(); + const vector
&tables = select_stmt->tables(); for (Table *table : tables) { unique_ptr table_get_oper(new TableGetLogicalOperator(table, ReadWriteMode::READ_ONLY)); @@ -150,8 +150,8 @@ RC LogicalPlanGenerator::create_plan(SelectStmt *select_stmt, unique_ptr &logical_operator) { RC rc = RC::SUCCESS; - std::vector> cmp_exprs; - const std::vector &filter_units = filter_stmt->filter_units(); + vector> cmp_exprs; + const vector &filter_units = filter_stmt->filter_units(); for (const FilterUnit *filter_unit : filter_units) { const FilterObj &filter_obj_left = filter_unit->left(); const FilterObj &filter_obj_right = filter_unit->right(); @@ -283,7 +283,7 @@ RC LogicalPlanGenerator::create_group_by_plan(SelectStmt *select_stmt, unique_pt vector> &group_by_expressions = select_stmt->group_by(); vector aggregate_expressions; vector> &query_expressions = select_stmt->query_expressions(); - function&)> collector = [&](unique_ptr &expr) -> RC { + function&)> collector = [&](unique_ptr &expr) -> RC { RC rc = RC::SUCCESS; if (expr->type() == ExprType::AGGREGATION) { expr->set_pos(aggregate_expressions.size() + group_by_expressions.size()); @@ -293,7 +293,7 @@ RC LogicalPlanGenerator::create_group_by_plan(SelectStmt *select_stmt, unique_pt return rc; }; - function&)> bind_group_by_expr = [&](unique_ptr &expr) -> RC { + function&)> bind_group_by_expr = [&](unique_ptr &expr) -> RC { RC rc = RC::SUCCESS; for (size_t i = 0; i < group_by_expressions.size(); i++) { auto &group_by = group_by_expressions[i]; @@ -310,7 +310,7 @@ RC LogicalPlanGenerator::create_group_by_plan(SelectStmt *select_stmt, unique_pt }; bool found_unbound_column = false; - function&)> find_unbound_column = [&](unique_ptr &expr) -> RC { + function&)> find_unbound_column = [&](unique_ptr &expr) -> RC { RC rc = RC::SUCCESS; if (expr->type() == ExprType::AGGREGATION) { // do nothing @@ -354,4 +354,4 @@ RC LogicalPlanGenerator::create_group_by_plan(SelectStmt *select_stmt, unique_pt std::move(aggregate_expressions)); logical_operator = std::move(group_by_oper); return RC::SUCCESS; -} \ No newline at end of file +} diff --git a/src/observer/sql/optimizer/logical_plan_generator.h b/src/observer/sql/optimizer/logical_plan_generator.h index d02cb1816..e0707deff 100644 --- a/src/observer/sql/optimizer/logical_plan_generator.h +++ b/src/observer/sql/optimizer/logical_plan_generator.h @@ -14,9 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - -#include "common/rc.h" +#include "common/lang/memory.h" +#include "common/sys/rc.h" #include "common/type/attr_type.h" class Stmt; @@ -34,17 +33,17 @@ class LogicalPlanGenerator LogicalPlanGenerator() = default; virtual ~LogicalPlanGenerator() = default; - RC create(Stmt *stmt, std::unique_ptr &logical_operator); + RC create(Stmt *stmt, unique_ptr &logical_operator); private: - RC create_plan(CalcStmt *calc_stmt, std::unique_ptr &logical_operator); - RC create_plan(SelectStmt *select_stmt, std::unique_ptr &logical_operator); - RC create_plan(FilterStmt *filter_stmt, std::unique_ptr &logical_operator); - RC create_plan(InsertStmt *insert_stmt, std::unique_ptr &logical_operator); - RC create_plan(DeleteStmt *delete_stmt, std::unique_ptr &logical_operator); - RC create_plan(ExplainStmt *explain_stmt, std::unique_ptr &logical_operator); + RC create_plan(CalcStmt *calc_stmt, unique_ptr &logical_operator); + RC create_plan(SelectStmt *select_stmt, unique_ptr &logical_operator); + RC create_plan(FilterStmt *filter_stmt, unique_ptr &logical_operator); + RC create_plan(InsertStmt *insert_stmt, unique_ptr &logical_operator); + RC create_plan(DeleteStmt *delete_stmt, unique_ptr &logical_operator); + RC create_plan(ExplainStmt *explain_stmt, unique_ptr &logical_operator); - RC create_group_by_plan(SelectStmt *select_stmt, std::unique_ptr &logical_operator); + RC create_group_by_plan(SelectStmt *select_stmt, unique_ptr &logical_operator); int implicit_cast_cost(AttrType from, AttrType to); -}; \ No newline at end of file +}; diff --git a/src/observer/sql/optimizer/optimize_stage.cpp b/src/observer/sql/optimizer/optimize_stage.cpp index 902c2ce86..afad88905 100644 --- a/src/observer/sql/optimizer/optimize_stage.cpp +++ b/src/observer/sql/optimizer/optimize_stage.cpp @@ -13,7 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include #include "optimize_stage.h" diff --git a/src/observer/sql/optimizer/optimize_stage.h b/src/observer/sql/optimizer/optimize_stage.h index a1b24ecf7..9d69e28c2 100644 --- a/src/observer/sql/optimizer/optimize_stage.h +++ b/src/observer/sql/optimizer/optimize_stage.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "session/session.h" #include "sql/operator/logical_operator.h" #include "sql/operator/physical_operator.h" @@ -47,7 +47,7 @@ class OptimizeStage * @param sql_event 包含SQL信息的事件 * @param logical_operator 生成的逻辑计划 */ - RC create_logical_plan(SQLStageEvent *sql_event, std::unique_ptr &logical_operator); + RC create_logical_plan(SQLStageEvent *sql_event, unique_ptr &logical_operator); /** * @brief 重写逻辑计划 @@ -55,14 +55,14 @@ class OptimizeStage * 规则改写也是一个递归的过程。 * @param logical_operator 要改写的逻辑计划 */ - RC rewrite(std::unique_ptr &logical_operator); + RC rewrite(unique_ptr &logical_operator); /** * @brief 优化逻辑计划 * @details 当前什么都没做。可以增加每个逻辑计划的代价模型,然后根据代价模型进行优化。 * @param logical_operator 需要优化的逻辑计划 */ - RC optimize(std::unique_ptr &logical_operator); + RC optimize(unique_ptr &logical_operator); /** * @brief 根据逻辑计划生成物理计划 @@ -71,8 +71,8 @@ class OptimizeStage * 而物理计划描述怎么做,比如如何从某张表按照什么条件获取什么数据,是否使用索引,使用哪个索引等。 * @param physical_operator 生成的物理计划。通常是一个多叉树的形状,这里就拿着根节点就可以了。 */ - RC generate_physical_plan(std::unique_ptr &logical_operator, - std::unique_ptr &physical_operator, Session *session); + RC generate_physical_plan(unique_ptr &logical_operator, + unique_ptr &physical_operator, Session *session); private: LogicalPlanGenerator logical_plan_generator_; ///< 根据SQL生成逻辑计划 diff --git a/src/observer/sql/optimizer/physical_plan_generator.cpp b/src/observer/sql/optimizer/physical_plan_generator.cpp index 9e946c2d3..1dcba897d 100644 --- a/src/observer/sql/optimizer/physical_plan_generator.cpp +++ b/src/observer/sql/optimizer/physical_plan_generator.cpp @@ -12,8 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by Wangyunlai on 2022/12/14. // -#include - #include "common/log/log.h" #include "sql/expr/expression.h" #include "sql/operator/aggregate_vec_physical_operator.h" @@ -325,7 +323,7 @@ RC PhysicalPlanGenerator::create_plan(JoinLogicalOperator &join_oper, unique_ptr return rc; } -RC PhysicalPlanGenerator::create_plan(CalcLogicalOperator &logical_oper, std::unique_ptr &oper) +RC PhysicalPlanGenerator::create_plan(CalcLogicalOperator &logical_oper, unique_ptr &oper) { RC rc = RC::SUCCESS; @@ -334,7 +332,7 @@ RC PhysicalPlanGenerator::create_plan(CalcLogicalOperator &logical_oper, std::un return rc; } -RC PhysicalPlanGenerator::create_plan(GroupByLogicalOperator &logical_oper, std::unique_ptr &oper) +RC PhysicalPlanGenerator::create_plan(GroupByLogicalOperator &logical_oper, unique_ptr &oper) { RC rc = RC::SUCCESS; @@ -424,7 +422,7 @@ RC PhysicalPlanGenerator::create_vec_plan(ProjectLogicalOperator &project_oper, auto project_operator = make_unique(std::move(project_oper.expressions())); if (child_phy_oper != nullptr) { - std::vector expressions; + vector expressions; for (auto &expr : project_operator->expressions()) { expressions.push_back(expr.get()); } @@ -460,4 +458,4 @@ RC PhysicalPlanGenerator::create_vec_plan(ExplainLogicalOperator &explain_oper, oper = std::move(explain_physical_oper); return rc; -} \ No newline at end of file +} diff --git a/src/observer/sql/optimizer/physical_plan_generator.h b/src/observer/sql/optimizer/physical_plan_generator.h index bac779a04..f9d6c3e05 100644 --- a/src/observer/sql/optimizer/physical_plan_generator.h +++ b/src/observer/sql/optimizer/physical_plan_generator.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/operator/logical_operator.h" #include "sql/operator/physical_operator.h" @@ -40,21 +40,21 @@ class PhysicalPlanGenerator PhysicalPlanGenerator() = default; virtual ~PhysicalPlanGenerator() = default; - RC create(LogicalOperator &logical_operator, std::unique_ptr &oper); - RC create_vec(LogicalOperator &logical_operator, std::unique_ptr &oper); + RC create(LogicalOperator &logical_operator, unique_ptr &oper); + RC create_vec(LogicalOperator &logical_operator, unique_ptr &oper); private: - RC create_plan(TableGetLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(PredicateLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(ProjectLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(InsertLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(DeleteLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(ExplainLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(JoinLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(CalcLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_plan(GroupByLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_vec_plan(ProjectLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_vec_plan(TableGetLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_vec_plan(GroupByLogicalOperator &logical_oper, std::unique_ptr &oper); - RC create_vec_plan(ExplainLogicalOperator &logical_oper, std::unique_ptr &oper); + RC create_plan(TableGetLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(PredicateLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(ProjectLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(InsertLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(DeleteLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(ExplainLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(JoinLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(CalcLogicalOperator &logical_oper, unique_ptr &oper); + RC create_plan(GroupByLogicalOperator &logical_oper, unique_ptr &oper); + RC create_vec_plan(ProjectLogicalOperator &logical_oper, unique_ptr &oper); + RC create_vec_plan(TableGetLogicalOperator &logical_oper, unique_ptr &oper); + RC create_vec_plan(GroupByLogicalOperator &logical_oper, unique_ptr &oper); + RC create_vec_plan(ExplainLogicalOperator &logical_oper, unique_ptr &oper); }; diff --git a/src/observer/sql/optimizer/predicate_pushdown_rewriter.cpp b/src/observer/sql/optimizer/predicate_pushdown_rewriter.cpp index 342218f73..86e9d4d1d 100644 --- a/src/observer/sql/optimizer/predicate_pushdown_rewriter.cpp +++ b/src/observer/sql/optimizer/predicate_pushdown_rewriter.cpp @@ -18,7 +18,7 @@ See the Mulan PSL v2 for more details. */ #include "sql/operator/logical_operator.h" #include "sql/operator/table_get_logical_operator.h" -RC PredicatePushdownRewriter::rewrite(std::unique_ptr &oper, bool &change_made) +RC PredicatePushdownRewriter::rewrite(unique_ptr &oper, bool &change_made) { RC rc = RC::SUCCESS; if (oper->type() != LogicalOperatorType::PREDICATE) { @@ -29,20 +29,20 @@ RC PredicatePushdownRewriter::rewrite(std::unique_ptr &oper, bo return rc; } - std::unique_ptr &child_oper = oper->children().front(); + unique_ptr &child_oper = oper->children().front(); if (child_oper->type() != LogicalOperatorType::TABLE_GET) { return rc; } auto table_get_oper = static_cast(child_oper.get()); - std::vector> &predicate_oper_exprs = oper->expressions(); + vector> &predicate_oper_exprs = oper->expressions(); if (predicate_oper_exprs.size() != 1) { return rc; } - std::unique_ptr &predicate_expr = predicate_oper_exprs.front(); - std::vector> pushdown_exprs; + unique_ptr &predicate_expr = predicate_oper_exprs.front(); + vector> pushdown_exprs; rc = get_exprs_can_pushdown(predicate_expr, pushdown_exprs); if (rc != RC::SUCCESS) { LOG_WARN("failed to get exprs can pushdown. rc=%s", strrc(rc)); @@ -55,7 +55,7 @@ RC PredicatePushdownRewriter::rewrite(std::unique_ptr &oper, bo LOG_TRACE("all expressions of predicate operator were pushdown to table get operator, then make a fake one"); Value value((bool)true); - predicate_expr = std::unique_ptr(new ValueExpr(value)); + predicate_expr = unique_ptr(new ValueExpr(value)); } if (!pushdown_exprs.empty()) { @@ -65,7 +65,7 @@ RC PredicatePushdownRewriter::rewrite(std::unique_ptr &oper, bo return rc; } -bool PredicatePushdownRewriter::is_empty_predicate(std::unique_ptr &expr) +bool PredicatePushdownRewriter::is_empty_predicate(unique_ptr &expr) { bool bool_ret = false; if (!expr) { @@ -89,7 +89,7 @@ bool PredicatePushdownRewriter::is_empty_predicate(std::unique_ptr & * pushdown_exprs 只会增加,不要做清理操作 */ RC PredicatePushdownRewriter::get_exprs_can_pushdown( - std::unique_ptr &expr, std::vector> &pushdown_exprs) + unique_ptr &expr, vector> &pushdown_exprs) { RC rc = RC::SUCCESS; if (expr->type() == ExprType::CONJUNCTION) { @@ -101,7 +101,7 @@ RC PredicatePushdownRewriter::get_exprs_can_pushdown( return rc; } - std::vector> &child_exprs = conjunction_expr->children(); + vector> &child_exprs = conjunction_expr->children(); for (auto iter = child_exprs.begin(); iter != child_exprs.end();) { // 对每个子表达式,判断是否可以下放到table get 算子 // 如果可以的话,就从当前孩子节点中删除他 @@ -121,8 +121,8 @@ RC PredicatePushdownRewriter::get_exprs_can_pushdown( // 如果是比较操作,并且比较的左边或右边是表某个列值,那么就下推下去 auto comparison_expr = static_cast(expr.get()); - std::unique_ptr &left_expr = comparison_expr->left(); - std::unique_ptr &right_expr = comparison_expr->right(); + unique_ptr &left_expr = comparison_expr->left(); + unique_ptr &right_expr = comparison_expr->right(); // 比较操作的左右两边只要有一个是取列字段值的并且另一边也是取字段值或常量,就pushdown if (left_expr->type() != ExprType::FIELD && right_expr->type() != ExprType::FIELD) { return rc; diff --git a/src/observer/sql/optimizer/predicate_pushdown_rewriter.h b/src/observer/sql/optimizer/predicate_pushdown_rewriter.h index 027262309..1231b6690 100644 --- a/src/observer/sql/optimizer/predicate_pushdown_rewriter.h +++ b/src/observer/sql/optimizer/predicate_pushdown_rewriter.h @@ -14,8 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once +#include "common/lang/vector.h" #include "sql/optimizer/rewrite_rule.h" -#include /** * @brief 将一些谓词表达式下推到表数据扫描中 @@ -28,10 +28,10 @@ class PredicatePushdownRewriter : public RewriteRule PredicatePushdownRewriter() = default; virtual ~PredicatePushdownRewriter() = default; - RC rewrite(std::unique_ptr &oper, bool &change_made) override; + RC rewrite(unique_ptr &oper, bool &change_made) override; private: RC get_exprs_can_pushdown( - std::unique_ptr &expr, std::vector> &pushdown_exprs); - bool is_empty_predicate(std::unique_ptr &expr); + unique_ptr &expr, vector> &pushdown_exprs); + bool is_empty_predicate(unique_ptr &expr); }; diff --git a/src/observer/sql/optimizer/predicate_rewrite.cpp b/src/observer/sql/optimizer/predicate_rewrite.cpp index 16d289a5f..7444efd68 100644 --- a/src/observer/sql/optimizer/predicate_rewrite.cpp +++ b/src/observer/sql/optimizer/predicate_rewrite.cpp @@ -15,9 +15,9 @@ See the Mulan PSL v2 for more details. */ #include "sql/optimizer/predicate_rewrite.h" #include "sql/operator/logical_operator.h" -RC PredicateRewriteRule::rewrite(std::unique_ptr &oper, bool &change_made) +RC PredicateRewriteRule::rewrite(unique_ptr &oper, bool &change_made) { - std::vector> &child_opers = oper->children(); + vector> &child_opers = oper->children(); if (child_opers.size() != 1) { return RC::SUCCESS; } @@ -27,12 +27,12 @@ RC PredicateRewriteRule::rewrite(std::unique_ptr &oper, bool &c return RC::SUCCESS; } - std::vector> &expressions = child_oper->expressions(); + vector> &expressions = child_oper->expressions(); if (expressions.size() != 1) { return RC::SUCCESS; } - std::unique_ptr &expr = expressions.front(); + unique_ptr &expr = expressions.front(); if (expr->type() != ExprType::VALUE) { return RC::SUCCESS; } @@ -43,7 +43,7 @@ RC PredicateRewriteRule::rewrite(std::unique_ptr &oper, bool &c auto value_expr = static_cast(expr.get()); bool bool_value = value_expr->get_value().get_boolean(); if (true == bool_value) { - std::vector> grand_child_opers; + vector> grand_child_opers; grand_child_opers.swap(child_oper->children()); child_opers.clear(); for (auto &grand_child_oper : grand_child_opers) { diff --git a/src/observer/sql/optimizer/predicate_rewrite.h b/src/observer/sql/optimizer/predicate_rewrite.h index 658206c01..193742dfa 100644 --- a/src/observer/sql/optimizer/predicate_rewrite.h +++ b/src/observer/sql/optimizer/predicate_rewrite.h @@ -27,5 +27,5 @@ class PredicateRewriteRule : public RewriteRule PredicateRewriteRule() = default; virtual ~PredicateRewriteRule() = default; - RC rewrite(std::unique_ptr &oper, bool &change_made) override; + RC rewrite(unique_ptr &oper, bool &change_made) override; }; diff --git a/src/observer/sql/optimizer/rewrite_rule.h b/src/observer/sql/optimizer/rewrite_rule.h index 7cb860c0a..1961a63e0 100644 --- a/src/observer/sql/optimizer/rewrite_rule.h +++ b/src/observer/sql/optimizer/rewrite_rule.h @@ -14,9 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - -#include "common/rc.h" +#include "common/sys/rc.h" +#include "common/lang/memory.h" class LogicalOperator; class Expression; @@ -30,7 +29,7 @@ class RewriteRule public: virtual ~RewriteRule() = default; - virtual RC rewrite(std::unique_ptr &oper, bool &change_made) = 0; + virtual RC rewrite(unique_ptr &oper, bool &change_made) = 0; }; /** @@ -42,5 +41,5 @@ class ExpressionRewriteRule public: virtual ~ExpressionRewriteRule() = default; - virtual RC rewrite(std::unique_ptr &expr, bool &change_made) = 0; + virtual RC rewrite(unique_ptr &expr, bool &change_made) = 0; }; diff --git a/src/observer/sql/optimizer/rewriter.cpp b/src/observer/sql/optimizer/rewriter.cpp index 8d1cebcee..fcb189b1b 100644 --- a/src/observer/sql/optimizer/rewriter.cpp +++ b/src/observer/sql/optimizer/rewriter.cpp @@ -26,12 +26,12 @@ Rewriter::Rewriter() rewrite_rules_.emplace_back(new PredicatePushdownRewriter); } -RC Rewriter::rewrite(std::unique_ptr &oper, bool &change_made) +RC Rewriter::rewrite(unique_ptr &oper, bool &change_made) { RC rc = RC::SUCCESS; change_made = false; - for (std::unique_ptr &rule : rewrite_rules_) { + for (unique_ptr &rule : rewrite_rules_) { bool sub_change_made = false; rc = rule->rewrite(oper, sub_change_made); @@ -49,7 +49,7 @@ RC Rewriter::rewrite(std::unique_ptr &oper, bool &change_made) return rc; } - std::vector> &child_opers = oper->children(); + vector> &child_opers = oper->children(); for (auto &child_oper : child_opers) { bool sub_change_made = false; rc = this->rewrite(child_oper, sub_change_made); diff --git a/src/observer/sql/optimizer/rewriter.h b/src/observer/sql/optimizer/rewriter.h index 315bb5e8f..e797e8db6 100644 --- a/src/observer/sql/optimizer/rewriter.h +++ b/src/observer/sql/optimizer/rewriter.h @@ -15,8 +15,8 @@ See the Mulan PSL v2 for more details. */ #pragma once #include "sql/optimizer/rewrite_rule.h" -#include -#include +#include "common/lang/memory.h" +#include "common/lang/vector.h" class LogicalOperator; @@ -44,8 +44,8 @@ class Rewriter * @param oper 逻辑计划 * @param change_made 当前是否有重写发生 */ - RC rewrite(std::unique_ptr &oper, bool &change_made); + RC rewrite(unique_ptr &oper, bool &change_made); private: - std::vector> rewrite_rules_; + vector> rewrite_rules_; }; diff --git a/src/observer/sql/parser/expression_binder.cpp b/src/observer/sql/parser/expression_binder.cpp index 2daf85cf5..9000756e4 100644 --- a/src/observer/sql/parser/expression_binder.cpp +++ b/src/observer/sql/parser/expression_binder.cpp @@ -12,14 +12,12 @@ See the Mulan PSL v2 for more details. */ // Created by Wangyunlai on 2024/05/29. // -#include - #include "common/log/log.h" #include "common/lang/string.h" +#include "common/lang/ranges.h" #include "sql/parser/expression_binder.h" #include "sql/expr/expression_iterator.h" -using namespace std; using namespace common; Table *BinderContext::find_table(const char *table_name) const @@ -386,7 +384,7 @@ RC check_aggregate_expression(AggregateExpr &expression) } // 子表达式中不能再包含聚合表达式 - function&)> check_aggregate_expr = [&](unique_ptr &expr) -> RC { + function&)> check_aggregate_expr = [&](unique_ptr &expr) -> RC { RC rc = RC::SUCCESS; if (expr->type() == ExprType::AGGREGATION) { LOG_WARN("aggregate expression cannot be nested"); diff --git a/src/observer/sql/parser/expression_binder.h b/src/observer/sql/parser/expression_binder.h index d52f049c4..103e63c97 100644 --- a/src/observer/sql/parser/expression_binder.h +++ b/src/observer/sql/parser/expression_binder.h @@ -14,8 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - #include "sql/expr/expression.h" class BinderContext @@ -28,10 +26,10 @@ class BinderContext Table *find_table(const char *table_name) const; - const std::vector
&query_tables() const { return query_tables_; } + const vector
&query_tables() const { return query_tables_; } private: - std::vector
query_tables_; + vector
query_tables_; }; /** @@ -44,28 +42,28 @@ class ExpressionBinder ExpressionBinder(BinderContext &context) : context_(context) {} virtual ~ExpressionBinder() = default; - RC bind_expression(std::unique_ptr &expr, std::vector> &bound_expressions); + RC bind_expression(unique_ptr &expr, vector> &bound_expressions); private: RC bind_star_expression( - std::unique_ptr &star_expr, std::vector> &bound_expressions); + unique_ptr &star_expr, vector> &bound_expressions); RC bind_unbound_field_expression( - std::unique_ptr &unbound_field_expr, std::vector> &bound_expressions); + unique_ptr &unbound_field_expr, vector> &bound_expressions); RC bind_field_expression( - std::unique_ptr &field_expr, std::vector> &bound_expressions); + unique_ptr &field_expr, vector> &bound_expressions); RC bind_value_expression( - std::unique_ptr &value_expr, std::vector> &bound_expressions); + unique_ptr &value_expr, vector> &bound_expressions); RC bind_cast_expression( - std::unique_ptr &cast_expr, std::vector> &bound_expressions); + unique_ptr &cast_expr, vector> &bound_expressions); RC bind_comparison_expression( - std::unique_ptr &comparison_expr, std::vector> &bound_expressions); + unique_ptr &comparison_expr, vector> &bound_expressions); RC bind_conjunction_expression( - std::unique_ptr &conjunction_expr, std::vector> &bound_expressions); + unique_ptr &conjunction_expr, vector> &bound_expressions); RC bind_arithmetic_expression( - std::unique_ptr &arithmetic_expr, std::vector> &bound_expressions); + unique_ptr &arithmetic_expr, vector> &bound_expressions); RC bind_aggregate_expression( - std::unique_ptr &aggregate_expr, std::vector> &bound_expressions); + unique_ptr &aggregate_expr, vector> &bound_expressions); private: BinderContext &context_; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/parser/parse.cpp b/src/observer/sql/parser/parse.cpp index 06da1193d..5762452be 100644 --- a/src/observer/sql/parser/parse.cpp +++ b/src/observer/sql/parser/parse.cpp @@ -22,7 +22,7 @@ ParsedSqlNode::ParsedSqlNode() : flag(SCF_ERROR) {} ParsedSqlNode::ParsedSqlNode(SqlCommandFlag _flag) : flag(_flag) {} -void ParsedSqlResult::add_sql_node(std::unique_ptr sql_node) +void ParsedSqlResult::add_sql_node(unique_ptr sql_node) { sql_nodes_.emplace_back(std::move(sql_node)); } diff --git a/src/observer/sql/parser/parse.h b/src/observer/sql/parser/parse.h index a654c7d95..5aaeda3f7 100644 --- a/src/observer/sql/parser/parse.h +++ b/src/observer/sql/parser/parse.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/parser/parse_defs.h" RC parse(const char *st, ParsedSqlResult *sql_result); diff --git a/src/observer/sql/parser/parse_defs.h b/src/observer/sql/parser/parse_defs.h index 9593d57ab..4acbf4ecd 100644 --- a/src/observer/sql/parser/parse_defs.h +++ b/src/observer/sql/parser/parse_defs.h @@ -14,10 +14,9 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include -#include - +#include "common/lang/string.h" +#include "common/lang/vector.h" +#include "common/lang/memory.h" #include "common/value.h" class Expression; @@ -35,8 +34,8 @@ class Expression; */ struct RelAttrSqlNode { - std::string relation_name; ///< relation name (may be NULL) 表名 - std::string attribute_name; ///< attribute name 属性名 + string relation_name; ///< relation name (may be NULL) 表名 + string attribute_name; ///< attribute name 属性名 }; /** @@ -88,10 +87,10 @@ struct ConditionSqlNode struct SelectSqlNode { - std::vector> expressions; ///< 查询的表达式 - std::vector relations; ///< 查询的表 - std::vector conditions; ///< 查询条件,使用AND串联起来多个条件 - std::vector> group_by; ///< group by clause + vector> expressions; ///< 查询的表达式 + vector relations; ///< 查询的表 + vector conditions; ///< 查询条件,使用AND串联起来多个条件 + vector> group_by; ///< group by clause }; /** @@ -100,7 +99,7 @@ struct SelectSqlNode */ struct CalcSqlNode { - std::vector> expressions; ///< calc clause + vector> expressions; ///< calc clause }; /** @@ -110,8 +109,8 @@ struct CalcSqlNode */ struct InsertSqlNode { - std::string relation_name; ///< Relation to insert into - std::vector values; ///< 要插入的值 + string relation_name; ///< Relation to insert into + vector values; ///< 要插入的值 }; /** @@ -120,8 +119,8 @@ struct InsertSqlNode */ struct DeleteSqlNode { - std::string relation_name; ///< Relation to delete from - std::vector conditions; + string relation_name; ///< Relation to delete from + vector conditions; }; /** @@ -130,10 +129,10 @@ struct DeleteSqlNode */ struct UpdateSqlNode { - std::string relation_name; ///< Relation to update - std::string attribute_name; ///< 更新的字段,仅支持一个字段 + string relation_name; ///< Relation to update + string attribute_name; ///< 更新的字段,仅支持一个字段 Value value; ///< 更新的值,仅支持一个字段 - std::vector conditions; + vector conditions; }; /** @@ -144,7 +143,7 @@ struct UpdateSqlNode struct AttrInfoSqlNode { AttrType type; ///< Type of attribute - std::string name; ///< Attribute name + string name; ///< Attribute name size_t length; ///< Length of attribute }; @@ -155,9 +154,9 @@ struct AttrInfoSqlNode */ struct CreateTableSqlNode { - std::string relation_name; ///< Relation name - std::vector attr_infos; ///< attributes - std::string storage_format; ///< storage format + string relation_name; ///< Relation name + vector attr_infos; ///< attributes + string storage_format; ///< storage format }; /** @@ -166,7 +165,7 @@ struct CreateTableSqlNode */ struct DropTableSqlNode { - std::string relation_name; ///< 要删除的表名 + string relation_name; ///< 要删除的表名 }; /** @@ -177,9 +176,9 @@ struct DropTableSqlNode */ struct CreateIndexSqlNode { - std::string index_name; ///< Index name - std::string relation_name; ///< Relation name - std::string attribute_name; ///< Attribute name + string index_name; ///< Index name + string relation_name; ///< Relation name + string attribute_name; ///< Attribute name }; /** @@ -188,8 +187,8 @@ struct CreateIndexSqlNode */ struct DropIndexSqlNode { - std::string index_name; ///< Index name - std::string relation_name; ///< Relation name + string index_name; ///< Index name + string relation_name; ///< Relation name }; /** @@ -199,7 +198,7 @@ struct DropIndexSqlNode */ struct DescTableSqlNode { - std::string relation_name; + string relation_name; }; /** @@ -209,8 +208,8 @@ struct DescTableSqlNode */ struct LoadDataSqlNode { - std::string relation_name; - std::string file_name; + string relation_name; + string file_name; }; /** @@ -220,7 +219,7 @@ struct LoadDataSqlNode */ struct SetVariableSqlNode { - std::string name; + string name; Value value; }; @@ -235,7 +234,7 @@ class ParsedSqlNode; */ struct ExplainSqlNode { - std::unique_ptr sql_node; + unique_ptr sql_node; }; /** @@ -245,7 +244,7 @@ struct ExplainSqlNode */ struct ErrorSqlNode { - std::string error_msg; + string error_msg; int line; int column; }; @@ -314,10 +313,10 @@ class ParsedSqlNode class ParsedSqlResult { public: - void add_sql_node(std::unique_ptr sql_node); + void add_sql_node(unique_ptr sql_node); - std::vector> &sql_nodes() { return sql_nodes_; } + vector> &sql_nodes() { return sql_nodes_; } private: - std::vector> sql_nodes_; ///< 这里记录SQL命令。虽然看起来支持多个,但是当前仅处理一个 + vector> sql_nodes_; ///< 这里记录SQL命令。虽然看起来支持多个,但是当前仅处理一个 }; diff --git a/src/observer/sql/parser/parse_stage.cpp b/src/observer/sql/parser/parse_stage.cpp index 3b32b7882..ec92cb46a 100644 --- a/src/observer/sql/parser/parse_stage.cpp +++ b/src/observer/sql/parser/parse_stage.cpp @@ -13,7 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include #include "parse_stage.h" @@ -32,7 +31,7 @@ RC ParseStage::handle_request(SQLStageEvent *sql_event) RC rc = RC::SUCCESS; SqlResult *sql_result = sql_event->session_event()->sql_result(); - const std::string &sql = sql_event->sql(); + const string &sql = sql_event->sql(); ParsedSqlResult parsed_sql_result; @@ -47,7 +46,7 @@ RC ParseStage::handle_request(SQLStageEvent *sql_event) LOG_WARN("got multi sql commands but only 1 will be handled"); } - std::unique_ptr sql_node = std::move(parsed_sql_result.sql_nodes().front()); + unique_ptr sql_node = std::move(parsed_sql_result.sql_nodes().front()); if (sql_node->flag == SCF_ERROR) { // set error information to event rc = RC::SQL_SYNTAX; diff --git a/src/observer/sql/parser/parse_stage.h b/src/observer/sql/parser/parse_stage.h index a7605618e..6d0706949 100644 --- a/src/observer/sql/parser/parse_stage.h +++ b/src/observer/sql/parser/parse_stage.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; diff --git a/src/observer/sql/parser/resolve_stage.cpp b/src/observer/sql/parser/resolve_stage.cpp index d04337b93..810617058 100644 --- a/src/observer/sql/parser/resolve_stage.cpp +++ b/src/observer/sql/parser/resolve_stage.cpp @@ -13,7 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include #include "resolve_stage.h" diff --git a/src/observer/sql/parser/resolve_stage.h b/src/observer/sql/parser/resolve_stage.h index 9403d1e4e..a049b7951 100644 --- a/src/observer/sql/parser/resolve_stage.h +++ b/src/observer/sql/parser/resolve_stage.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; diff --git a/src/observer/sql/parser/yacc_sql.y b/src/observer/sql/parser/yacc_sql.y index 9e392b620..3cb83c029 100644 --- a/src/observer/sql/parser/yacc_sql.y +++ b/src/observer/sql/parser/yacc_sql.y @@ -4,7 +4,6 @@ #include #include #include -#include #include "common/log/log.h" #include "common/lang/string.h" @@ -22,7 +21,7 @@ string token_name(const char *sql_string, YYLTYPE *llocp) int yyerror(YYLTYPE *llocp, const char *sql_string, ParsedSqlResult *sql_result, yyscan_t scanner, const char *msg) { - std::unique_ptr error_sql_node = std::make_unique(SCF_ERROR); + unique_ptr error_sql_node = make_unique(SCF_ERROR); error_sql_node->error.error_msg = msg; error_sql_node->error.line = llocp->first_line; error_sql_node->error.column = llocp->first_column; @@ -120,14 +119,14 @@ UnboundAggregateExpr *create_aggregate_expression(const char *aggregate_name, Value * value; enum CompOp comp; RelAttrSqlNode * rel_attr; - std::vector * attr_infos; + vector * attr_infos; AttrInfoSqlNode * attr_info; Expression * expression; - std::vector> * expression_list; - std::vector * value_list; - std::vector * condition_list; - std::vector * rel_attr_list; - std::vector * relation_list; + vector> * expression_list; + vector * value_list; + vector * condition_list; + vector * rel_attr_list; + vector * relation_list; char * string; int number; float floats; @@ -188,7 +187,7 @@ UnboundAggregateExpr *create_aggregate_expression(const char *aggregate_name, commands: command_wrapper opt_semicolon //commands or sqls. parser starts here. { - std::unique_ptr sql_node = std::unique_ptr($1); + unique_ptr sql_node = unique_ptr($1); sql_result->add_sql_node(std::move(sql_node)); } ; @@ -304,14 +303,14 @@ create_table_stmt: /*create table 语句的语法解析树*/ create_table.relation_name = $3; free($3); - std::vector *src_attrs = $6; + vector *src_attrs = $6; if (src_attrs != nullptr) { create_table.attr_infos.swap(*src_attrs); delete src_attrs; } create_table.attr_infos.emplace_back(*$5); - std::reverse(create_table.attr_infos.begin(), create_table.attr_infos.end()); + reverse(create_table.attr_infos.begin(), create_table.attr_infos.end()); delete $5; if ($8 != nullptr) { create_table.storage_format = $8; @@ -329,7 +328,7 @@ attr_def_list: if ($3 != nullptr) { $$ = $3; } else { - $$ = new std::vector; + $$ = new vector; } $$->emplace_back(*$2); delete $2; @@ -373,7 +372,7 @@ insert_stmt: /*insert 语句的语法解析树*/ delete $7; } $$->insertion.values.emplace_back(*$6); - std::reverse($$->insertion.values.begin(), $$->insertion.values.end()); + reverse($$->insertion.values.begin(), $$->insertion.values.end()); delete $6; free($3); } @@ -388,7 +387,7 @@ value_list: if ($3 != nullptr) { $$ = $3; } else { - $$ = new std::vector; + $$ = new vector; } $$->emplace_back(*$2); delete $2; @@ -485,7 +484,7 @@ calc_stmt: expression_list: expression { - $$ = new std::vector>; + $$ = new vector>; $$->emplace_back($1); } | expression COMMA expression_list @@ -493,7 +492,7 @@ expression_list: if ($3 != nullptr) { $$ = $3; } else { - $$ = new std::vector>; + $$ = new vector>; } $$->emplace($$->begin(), $1); } @@ -557,7 +556,7 @@ relation: ; rel_list: relation { - $$ = new std::vector(); + $$ = new vector(); $$->push_back($1); free($1); } @@ -565,7 +564,7 @@ rel_list: if ($3 != nullptr) { $$ = $3; } else { - $$ = new std::vector; + $$ = new vector; } $$->insert($$->begin(), $1); @@ -588,7 +587,7 @@ condition_list: $$ = nullptr; } | condition { - $$ = new std::vector; + $$ = new vector; $$->emplace_back(*$1); delete $1; } @@ -682,7 +681,7 @@ explain_stmt: EXPLAIN command_wrapper { $$ = new ParsedSqlNode(SCF_EXPLAIN); - $$->explain.sql_node = std::unique_ptr($2); + $$->explain.sql_node = unique_ptr($2); } ; diff --git a/src/observer/sql/plan_cache/plan_cache_stage.cpp b/src/observer/sql/plan_cache/plan_cache_stage.cpp index 924483ccd..7482fe601 100644 --- a/src/observer/sql/plan_cache/plan_cache_stage.cpp +++ b/src/observer/sql/plan_cache/plan_cache_stage.cpp @@ -13,7 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include #include "plan_cache_stage.h" diff --git a/src/observer/sql/plan_cache/plan_cache_stage.h b/src/observer/sql/plan_cache/plan_cache_stage.h index e359bf22b..e4ea51fca 100644 --- a/src/observer/sql/plan_cache/plan_cache_stage.h +++ b/src/observer/sql/plan_cache/plan_cache_stage.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" /** * @brief 尝试从Plan的缓存中获取Plan,如果没有命中,则执行Optimizer diff --git a/src/observer/sql/query_cache/query_cache_stage.cpp b/src/observer/sql/query_cache/query_cache_stage.cpp index eeb53b6be..ef6ab09f8 100644 --- a/src/observer/sql/query_cache/query_cache_stage.cpp +++ b/src/observer/sql/query_cache/query_cache_stage.cpp @@ -13,7 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include #include "query_cache_stage.h" diff --git a/src/observer/sql/query_cache/query_cache_stage.h b/src/observer/sql/query_cache/query_cache_stage.h index 629c2d173..2ffa3979c 100644 --- a/src/observer/sql/query_cache/query_cache_stage.h +++ b/src/observer/sql/query_cache/query_cache_stage.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" class SQLStageEvent; diff --git a/src/observer/sql/stmt/calc_stmt.h b/src/observer/sql/stmt/calc_stmt.h index d7a1b388c..4b5fcdf54 100644 --- a/src/observer/sql/stmt/calc_stmt.h +++ b/src/observer/sql/stmt/calc_stmt.h @@ -14,9 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/expr/expression.h" #include "sql/stmt/stmt.h" @@ -45,8 +43,8 @@ class CalcStmt : public Stmt } public: - std::vector> &expressions() { return expressions_; } + vector> &expressions() { return expressions_; } private: - std::vector> expressions_; + vector> expressions_; }; diff --git a/src/observer/sql/stmt/create_index_stmt.h b/src/observer/sql/stmt/create_index_stmt.h index 6cd9fbbe4..6d9d42aca 100644 --- a/src/observer/sql/stmt/create_index_stmt.h +++ b/src/observer/sql/stmt/create_index_stmt.h @@ -14,8 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - #include "sql/stmt/stmt.h" struct CreateIndexSqlNode; @@ -29,7 +27,7 @@ class FieldMeta; class CreateIndexStmt : public Stmt { public: - CreateIndexStmt(Table *table, const FieldMeta *field_meta, const std::string &index_name) + CreateIndexStmt(Table *table, const FieldMeta *field_meta, const string &index_name) : table_(table), field_meta_(field_meta), index_name_(index_name) {} @@ -39,7 +37,7 @@ class CreateIndexStmt : public Stmt Table *table() const { return table_; } const FieldMeta *field_meta() const { return field_meta_; } - const std::string &index_name() const { return index_name_; } + const string &index_name() const { return index_name_; } public: static RC create(Db *db, const CreateIndexSqlNode &create_index, Stmt *&stmt); @@ -47,5 +45,5 @@ class CreateIndexStmt : public Stmt private: Table *table_ = nullptr; const FieldMeta *field_meta_ = nullptr; - std::string index_name_; + string index_name_; }; diff --git a/src/observer/sql/stmt/create_table_stmt.h b/src/observer/sql/stmt/create_table_stmt.h index a7c0707e6..4b66f8867 100644 --- a/src/observer/sql/stmt/create_table_stmt.h +++ b/src/observer/sql/stmt/create_table_stmt.h @@ -14,9 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - +#include "common/lang/string.h" +#include "common/lang/vector.h" #include "sql/stmt/stmt.h" class Db; @@ -30,22 +29,22 @@ class CreateTableStmt : public Stmt { public: CreateTableStmt( - const std::string &table_name, const std::vector &attr_infos, StorageFormat storage_format) + const string &table_name, const vector &attr_infos, StorageFormat storage_format) : table_name_(table_name), attr_infos_(attr_infos), storage_format_(storage_format) {} virtual ~CreateTableStmt() = default; StmtType type() const override { return StmtType::CREATE_TABLE; } - const std::string &table_name() const { return table_name_; } - const std::vector &attr_infos() const { return attr_infos_; } + const string &table_name() const { return table_name_; } + const vector &attr_infos() const { return attr_infos_; } const StorageFormat storage_format() const { return storage_format_; } static RC create(Db *db, const CreateTableSqlNode &create_table, Stmt *&stmt); static StorageFormat get_storage_format(const char *format_str); private: - std::string table_name_; - std::vector attr_infos_; + string table_name_; + vector attr_infos_; StorageFormat storage_format_; -}; \ No newline at end of file +}; diff --git a/src/observer/sql/stmt/delete_stmt.cpp b/src/observer/sql/stmt/delete_stmt.cpp index 36f8c1f8b..89dce0db8 100644 --- a/src/observer/sql/stmt/delete_stmt.cpp +++ b/src/observer/sql/stmt/delete_stmt.cpp @@ -43,8 +43,8 @@ RC DeleteStmt::create(Db *db, const DeleteSqlNode &delete_sql, Stmt *&stmt) return RC::SCHEMA_TABLE_NOT_EXIST; } - std::unordered_map table_map; - table_map.insert(std::pair(std::string(table_name), table)); + unordered_map table_map; + table_map.insert(pair(string(table_name), table)); FilterStmt *filter_stmt = nullptr; RC rc = FilterStmt::create( diff --git a/src/observer/sql/stmt/desc_table_stmt.h b/src/observer/sql/stmt/desc_table_stmt.h index c03406e78..9e57a8a67 100644 --- a/src/observer/sql/stmt/desc_table_stmt.h +++ b/src/observer/sql/stmt/desc_table_stmt.h @@ -14,8 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - #include "sql/stmt/stmt.h" class Db; @@ -28,15 +26,15 @@ class Db; class DescTableStmt : public Stmt { public: - DescTableStmt(const std::string &table_name) : table_name_(table_name) {} + DescTableStmt(const string &table_name) : table_name_(table_name) {} virtual ~DescTableStmt() = default; StmtType type() const override { return StmtType::DESC_TABLE; } - const std::string &table_name() const { return table_name_; } + const string &table_name() const { return table_name_; } static RC create(Db *db, const DescTableSqlNode &desc_table, Stmt *&stmt); private: - std::string table_name_; -}; \ No newline at end of file + string table_name_; +}; diff --git a/src/observer/sql/stmt/explain_stmt.cpp b/src/observer/sql/stmt/explain_stmt.cpp index e44b213e0..7efea6a2b 100644 --- a/src/observer/sql/stmt/explain_stmt.cpp +++ b/src/observer/sql/stmt/explain_stmt.cpp @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ #include "common/log/log.h" #include "sql/stmt/stmt.h" -ExplainStmt::ExplainStmt(std::unique_ptr child_stmt) : child_stmt_(std::move(child_stmt)) {} +ExplainStmt::ExplainStmt(unique_ptr child_stmt) : child_stmt_(std::move(child_stmt)) {} RC ExplainStmt::create(Db *db, const ExplainSqlNode &explain, Stmt *&stmt) { @@ -27,7 +27,7 @@ RC ExplainStmt::create(Db *db, const ExplainSqlNode &explain, Stmt *&stmt) return rc; } - std::unique_ptr child_stmt_ptr = std::unique_ptr(child_stmt); + unique_ptr child_stmt_ptr = unique_ptr(child_stmt); stmt = new ExplainStmt(std::move(child_stmt_ptr)); return rc; } diff --git a/src/observer/sql/stmt/explain_stmt.h b/src/observer/sql/stmt/explain_stmt.h index ece21f5d3..3634f07cd 100644 --- a/src/observer/sql/stmt/explain_stmt.h +++ b/src/observer/sql/stmt/explain_stmt.h @@ -23,7 +23,7 @@ See the Mulan PSL v2 for more details. */ class ExplainStmt : public Stmt { public: - ExplainStmt(std::unique_ptr child_stmt); + ExplainStmt(unique_ptr child_stmt); virtual ~ExplainStmt() = default; StmtType type() const override { return StmtType::EXPLAIN; } @@ -33,5 +33,5 @@ class ExplainStmt : public Stmt static RC create(Db *db, const ExplainSqlNode &query, Stmt *&stmt); private: - std::unique_ptr child_stmt_; + unique_ptr child_stmt_; }; diff --git a/src/observer/sql/stmt/filter_stmt.cpp b/src/observer/sql/stmt/filter_stmt.cpp index 44b1d1a1a..aa078bcbb 100644 --- a/src/observer/sql/stmt/filter_stmt.cpp +++ b/src/observer/sql/stmt/filter_stmt.cpp @@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */ #include "sql/stmt/filter_stmt.h" #include "common/lang/string.h" #include "common/log/log.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "storage/db/db.h" #include "storage/table/table.h" @@ -27,7 +27,7 @@ FilterStmt::~FilterStmt() filter_units_.clear(); } -RC FilterStmt::create(Db *db, Table *default_table, std::unordered_map *tables, +RC FilterStmt::create(Db *db, Table *default_table, unordered_map *tables, const ConditionSqlNode *conditions, int condition_num, FilterStmt *&stmt) { RC rc = RC::SUCCESS; @@ -50,7 +50,7 @@ RC FilterStmt::create(Db *db, Table *default_table, std::unordered_map *tables, +RC get_table_and_field(Db *db, Table *default_table, unordered_map *tables, const RelAttrSqlNode &attr, Table *&table, const FieldMeta *&field) { if (common::is_blank(attr.relation_name.c_str())) { @@ -78,7 +78,7 @@ RC get_table_and_field(Db *db, Table *default_table, std::unordered_map *tables, +RC FilterStmt::create_filter_unit(Db *db, Table *default_table, unordered_map *tables, const ConditionSqlNode &condition, FilterUnit *&filter_unit) { RC rc = RC::SUCCESS; diff --git a/src/observer/sql/stmt/filter_stmt.h b/src/observer/sql/stmt/filter_stmt.h index 27017782f..35b3be1ec 100644 --- a/src/observer/sql/stmt/filter_stmt.h +++ b/src/observer/sql/stmt/filter_stmt.h @@ -14,11 +14,11 @@ See the Mulan PSL v2 for more details. */ #pragma once +#include "common/lang/unordered_map.h" +#include "common/lang/vector.h" #include "sql/expr/expression.h" #include "sql/parser/parse_defs.h" #include "sql/stmt/stmt.h" -#include -#include class Db; class Table; @@ -76,15 +76,15 @@ class FilterStmt virtual ~FilterStmt(); public: - const std::vector &filter_units() const { return filter_units_; } + const vector &filter_units() const { return filter_units_; } public: - static RC create(Db *db, Table *default_table, std::unordered_map *tables, + static RC create(Db *db, Table *default_table, unordered_map *tables, const ConditionSqlNode *conditions, int condition_num, FilterStmt *&stmt); - static RC create_filter_unit(Db *db, Table *default_table, std::unordered_map *tables, + static RC create_filter_unit(Db *db, Table *default_table, unordered_map *tables, const ConditionSqlNode &condition, FilterUnit *&filter_unit); private: - std::vector filter_units_; // 默认当前都是AND关系 + vector filter_units_; // 默认当前都是AND关系 }; diff --git a/src/observer/sql/stmt/insert_stmt.h b/src/observer/sql/stmt/insert_stmt.h index 759745cb7..51c162ac8 100644 --- a/src/observer/sql/stmt/insert_stmt.h +++ b/src/observer/sql/stmt/insert_stmt.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/stmt/stmt.h" class Table; diff --git a/src/observer/sql/stmt/load_data_stmt.h b/src/observer/sql/stmt/load_data_stmt.h index 9904e82c1..995d1c525 100644 --- a/src/observer/sql/stmt/load_data_stmt.h +++ b/src/observer/sql/stmt/load_data_stmt.h @@ -14,8 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include - #include "sql/stmt/stmt.h" class Table; @@ -35,5 +33,5 @@ class LoadDataStmt : public Stmt private: Table *table_ = nullptr; - std::string filename_; + string filename_; }; diff --git a/src/observer/sql/stmt/select_stmt.h b/src/observer/sql/stmt/select_stmt.h index cfb048807..9d4c8fd7d 100644 --- a/src/observer/sql/stmt/select_stmt.h +++ b/src/observer/sql/stmt/select_stmt.h @@ -14,10 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include - -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/stmt/stmt.h" #include "storage/field/field.h" @@ -42,15 +39,15 @@ class SelectStmt : public Stmt static RC create(Db *db, SelectSqlNode &select_sql, Stmt *&stmt); public: - const std::vector
&tables() const { return tables_; } + const vector
&tables() const { return tables_; } FilterStmt *filter_stmt() const { return filter_stmt_; } - std::vector> &query_expressions() { return query_expressions_; } - std::vector> &group_by() { return group_by_; } + vector> &query_expressions() { return query_expressions_; } + vector> &group_by() { return group_by_; } private: - std::vector> query_expressions_; - std::vector
tables_; + vector> query_expressions_; + vector
tables_; FilterStmt *filter_stmt_ = nullptr; - std::vector> group_by_; + vector> group_by_; }; diff --git a/src/observer/sql/stmt/stmt.h b/src/observer/sql/stmt/stmt.h index 2d10ff4c8..942a4140c 100644 --- a/src/observer/sql/stmt/stmt.h +++ b/src/observer/sql/stmt/stmt.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/parser/parse_defs.h" class Db; diff --git a/src/observer/sql/stmt/update_stmt.h b/src/observer/sql/stmt/update_stmt.h index 762a80193..28e13268e 100644 --- a/src/observer/sql/stmt/update_stmt.h +++ b/src/observer/sql/stmt/update_stmt.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "sql/stmt/stmt.h" class Table; diff --git a/src/observer/storage/buffer/buffer_pool_log.cpp b/src/observer/storage/buffer/buffer_pool_log.cpp index 63b334b83..b0fb2c961 100644 --- a/src/observer/storage/buffer/buffer_pool_log.cpp +++ b/src/observer/storage/buffer/buffer_pool_log.cpp @@ -93,4 +93,4 @@ RC BufferPoolLogReplayer::replay(const LogEntry &entry) return RC::INTERNAL; } return RC::SUCCESS; -} \ No newline at end of file +} diff --git a/src/observer/storage/buffer/buffer_pool_log.h b/src/observer/storage/buffer/buffer_pool_log.h index 9be20b22e..604c01971 100644 --- a/src/observer/storage/buffer/buffer_pool_log.h +++ b/src/observer/storage/buffer/buffer_pool_log.h @@ -16,7 +16,7 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/string.h" #include "common/types.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "storage/clog/log_replayer.h" class DiskBufferPool; diff --git a/src/observer/storage/buffer/disk_buffer_pool.h b/src/observer/storage/buffer/disk_buffer_pool.h index 9ff02922f..715f66a83 100644 --- a/src/observer/storage/buffer/disk_buffer_pool.h +++ b/src/observer/storage/buffer/disk_buffer_pool.h @@ -31,7 +31,7 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/memory.h" #include "common/lang/unordered_map.h" #include "common/mm/mem_pool.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "storage/buffer/frame.h" #include "storage/buffer/page.h" diff --git a/src/observer/storage/buffer/double_write_buffer.cpp b/src/observer/storage/buffer/double_write_buffer.cpp index 679c4389e..879f7c1e9 100644 --- a/src/observer/storage/buffer/double_write_buffer.cpp +++ b/src/observer/storage/buffer/double_write_buffer.cpp @@ -13,9 +13,6 @@ See the Mulan PSL v2 for more details. */ // #include -#include -#include - #include "storage/buffer/double_write_buffer.h" #include "storage/buffer/disk_buffer_pool.h" #include "common/io/io.h" @@ -109,7 +106,7 @@ RC DiskDoubleWriteBuffer::add_page(DiskBufferPool *bp, PageNum page_num, Page &p int64_t page_cnt = dblwr_pages_.size(); DoubleWritePage *dblwr_page = new DoubleWritePage(bp->id(), page_num, page_cnt, page); - dblwr_pages_.insert(std::pair(key, dblwr_page)); + dblwr_pages_.insert(pair(key, dblwr_page)); LOG_TRACE("insert page into double write buffer. buffer_pool_id:%d,page_num:%d,lsn=%d, dwb size:%d", bp->id(), page_num, page.lsn, static_cast(dblwr_pages_.size())); diff --git a/src/observer/storage/buffer/double_write_buffer.h b/src/observer/storage/buffer/double_write_buffer.h index 5bc64f56a..ce42c96a5 100644 --- a/src/observer/storage/buffer/double_write_buffer.h +++ b/src/observer/storage/buffer/double_write_buffer.h @@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/mutex.h" #include "common/lang/unordered_map.h" #include "common/types.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "storage/buffer/page.h" class DiskBufferPool; @@ -66,7 +66,7 @@ struct DoubleWritePageKeyHash { size_t operator()(const DoubleWritePageKey &key) const { - return std::hash()(key.buffer_pool_id) ^ std::hash()(key.page_num); + return hash()(key.buffer_pool_id) ^ hash()(key.page_num); } }; diff --git a/src/observer/storage/clog/disk_log_handler.h b/src/observer/storage/clog/disk_log_handler.h index 3cb7a996b..ff378df2d 100644 --- a/src/observer/storage/clog/disk_log_handler.h +++ b/src/observer/storage/clog/disk_log_handler.h @@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */ #pragma once #include "common/types.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/vector.h" #include "common/lang/deque.h" #include "common/lang/memory.h" diff --git a/src/observer/storage/clog/log_buffer.h b/src/observer/storage/clog/log_buffer.h index 68046f72e..815af9144 100644 --- a/src/observer/storage/clog/log_buffer.h +++ b/src/observer/storage/clog/log_buffer.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "common/lang/mutex.h" #include "common/lang/vector.h" diff --git a/src/observer/storage/clog/log_entry.cpp b/src/observer/storage/clog/log_entry.cpp index 3d34dad15..0fbf27882 100644 --- a/src/observer/storage/clog/log_entry.cpp +++ b/src/observer/storage/clog/log_entry.cpp @@ -12,7 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by wangyunlai on 2024/01/31 // -#include #include "storage/clog/log_entry.h" #include "common/log/log.h" diff --git a/src/observer/storage/clog/log_entry.h b/src/observer/storage/clog/log_entry.h index a6c9d2a52..d4d2981a3 100644 --- a/src/observer/storage/clog/log_entry.h +++ b/src/observer/storage/clog/log_entry.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "storage/clog/log_module.h" #include "common/lang/vector.h" diff --git a/src/observer/storage/clog/log_file.cpp b/src/observer/storage/clog/log_file.cpp index 18bb0e765..c15d0ac14 100644 --- a/src/observer/storage/clog/log_file.cpp +++ b/src/observer/storage/clog/log_file.cpp @@ -331,7 +331,7 @@ RC LogFileManager::next_file(LogFileWriter &file_writer) lsn = log_files_.rbegin()->first + max_entry_number_per_file_; } - string filename = file_prefix_ + std::to_string(lsn) + file_suffix_; + string filename = file_prefix_ + to_string(lsn) + file_suffix_; filesystem::path file_path = directory_ / filename; log_files_.emplace(lsn, file_path); diff --git a/src/observer/storage/clog/log_file.h b/src/observer/storage/clog/log_file.h index 6d61a212b..f5014d42c 100644 --- a/src/observer/storage/clog/log_file.h +++ b/src/observer/storage/clog/log_file.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "common/lang/map.h" #include "common/lang/functional.h" diff --git a/src/observer/storage/clog/log_handler.h b/src/observer/storage/clog/log_handler.h index f91a10999..141df1537 100644 --- a/src/observer/storage/clog/log_handler.h +++ b/src/observer/storage/clog/log_handler.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "common/lang/functional.h" #include "common/lang/memory.h" diff --git a/src/observer/storage/clog/log_replayer.h b/src/observer/storage/clog/log_replayer.h index a0a5cbc1f..6ef1292a2 100644 --- a/src/observer/storage/clog/log_replayer.h +++ b/src/observer/storage/clog/log_replayer.h @@ -14,8 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include "common/rc.h" +#include "common/sys/rc.h" class LogEntry; @@ -40,4 +39,4 @@ class LogReplayer * @brief 当所有日志回放完成时的回调函数 */ virtual RC on_done() { return RC::SUCCESS; } -}; \ No newline at end of file +}; diff --git a/src/observer/storage/common/chunk.h b/src/observer/storage/common/chunk.h index 8da0d73f9..b32e514c1 100644 --- a/src/observer/storage/common/chunk.h +++ b/src/observer/storage/common/chunk.h @@ -10,7 +10,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/log/log.h" #include "common/lang/memory.h" #include "common/lang/vector.h" @@ -82,4 +82,4 @@ class Chunk // TODO: remove it and support multi-tables, // `columnd_ids` store the ids of child operator that need to be output vector column_ids_; -}; \ No newline at end of file +}; diff --git a/src/observer/storage/common/meta_util.cpp b/src/observer/storage/common/meta_util.cpp index 00f4c5ffb..1d7117dcb 100644 --- a/src/observer/storage/common/meta_util.cpp +++ b/src/observer/storage/common/meta_util.cpp @@ -11,8 +11,6 @@ See the Mulan PSL v2 for more details. */ // Created by wangyunlai.wyl on 2021/5/18. // -#include - #include "storage/common/meta_util.h" using namespace std; diff --git a/src/observer/storage/db/db.cpp b/src/observer/storage/db/db.cpp index 74e9a169c..1c6b9ff61 100644 --- a/src/observer/storage/db/db.cpp +++ b/src/observer/storage/db/db.cpp @@ -16,8 +16,6 @@ See the Mulan PSL v2 for more details. */ #include #include -#include -#include #include "common/lang/string.h" #include "common/log/log.h" @@ -358,7 +356,7 @@ RC Db::flush_meta() return RC::IOERR_WRITE; } - string buffer = std::to_string(check_point_lsn_); + string buffer = to_string(check_point_lsn_); int n = write(fd, buffer.c_str(), buffer.size()); if (n < 0) { LOG_ERROR("Failed to write db meta file. db=%s, file=%s, errno=%s", diff --git a/src/observer/storage/db/db.h b/src/observer/storage/db/db.h index 8eee8943e..ca68d41cb 100644 --- a/src/observer/storage/db/db.h +++ b/src/observer/storage/db/db.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/vector.h" #include "common/lang/string.h" #include "common/lang/unordered_map.h" diff --git a/src/observer/storage/default/default_handler.cpp b/src/observer/storage/default/default_handler.cpp index e310aa916..a6bf2914d 100644 --- a/src/observer/storage/default/default_handler.cpp +++ b/src/observer/storage/default/default_handler.cpp @@ -14,9 +14,6 @@ See the Mulan PSL v2 for more details. */ #include "storage/default/default_handler.h" -#include -#include - #include "common/lang/string.h" #include "common/log/log.h" #include "common/os/path.h" diff --git a/src/observer/storage/field/field_meta.cpp b/src/observer/storage/field/field_meta.cpp index 9be3bf2e2..571861b69 100644 --- a/src/observer/storage/field/field_meta.cpp +++ b/src/observer/storage/field/field_meta.cpp @@ -70,7 +70,7 @@ bool FieldMeta::visible() const { return visible_; } int FieldMeta::field_id() const { return field_id_; } -void FieldMeta::desc(std::ostream &os) const +void FieldMeta::desc(ostream &os) const { os << "field name=" << name_ << ", type=" << attr_type_to_string(attr_type_) << ", len=" << attr_len_ << ", visible=" << (visible_ ? "yes" : "no"); diff --git a/src/observer/storage/field/field_meta.h b/src/observer/storage/field/field_meta.h index 03e9c797c..2166b719f 100644 --- a/src/observer/storage/field/field_meta.h +++ b/src/observer/storage/field/field_meta.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/string.h" #include "sql/parser/parse_defs.h" diff --git a/src/observer/storage/index/bplus_tree.cpp b/src/observer/storage/index/bplus_tree.cpp index 7c7a1103b..d0d48f336 100644 --- a/src/observer/storage/index/bplus_tree.cpp +++ b/src/observer/storage/index/bplus_tree.cpp @@ -13,8 +13,6 @@ See the Mulan PSL v2 for more details. */ // Rewritten by Longda & Wangyunlai // -#include - #include "storage/index/bplus_tree.h" #include "common/lang/lower_bound.h" #include "common/log/log.h" diff --git a/src/observer/storage/index/bplus_tree_log.h b/src/observer/storage/index/bplus_tree_log.h index 35eb45b25..cb59bdf75 100644 --- a/src/observer/storage/index/bplus_tree_log.h +++ b/src/observer/storage/index/bplus_tree_log.h @@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */ #include #include "common/types.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/span.h" #include "common/lang/memory.h" #include "common/lang/vector.h" diff --git a/src/observer/storage/index/bplus_tree_log_entry.h b/src/observer/storage/index/bplus_tree_log_entry.h index 7abdc8bdf..7cdab743e 100644 --- a/src/observer/storage/index/bplus_tree_log_entry.h +++ b/src/observer/storage/index/bplus_tree_log_entry.h @@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */ #pragma once #include "common/types.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/span.h" #include "common/lang/string.h" #include "storage/index/bplus_tree.h" diff --git a/src/observer/storage/index/index.h b/src/observer/storage/index/index.h index 790c34cd4..67bfe9a55 100644 --- a/src/observer/storage/index/index.h +++ b/src/observer/storage/index/index.h @@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */ #include #include -#include "common/rc.h" +#include "common/sys/rc.h" #include "storage/field/field_meta.h" #include "storage/index/index_meta.h" #include "storage/record/record_manager.h" diff --git a/src/observer/storage/index/index_meta.h b/src/observer/storage/index/index_meta.h index 04d10642c..bb9f948b1 100644 --- a/src/observer/storage/index/index_meta.h +++ b/src/observer/storage/index/index_meta.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/string.h" class TableMeta; diff --git a/src/observer/storage/index/latch_memo.h b/src/observer/storage/index/latch_memo.h index f0e0da8b9..b729db542 100644 --- a/src/observer/storage/index/latch_memo.h +++ b/src/observer/storage/index/latch_memo.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/deque.h" #include "common/lang/vector.h" #include "storage/buffer/page.h" @@ -87,4 +87,4 @@ class LatchMemo final DiskBufferPool *buffer_pool_ = nullptr; deque items_; vector disposed_pages_; /// 等待释放的页面 -}; \ No newline at end of file +}; diff --git a/src/observer/storage/persist/persist.h b/src/observer/storage/persist/persist.h index 69befa786..0dde544af 100644 --- a/src/observer/storage/persist/persist.h +++ b/src/observer/storage/persist/persist.h @@ -21,7 +21,7 @@ See the Mulan PSL v2 for more details. */ #include #include -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/string.h" class PersistHandler diff --git a/src/observer/storage/record/record.h b/src/observer/storage/record/record.h index 6749804dd..f3d334c17 100644 --- a/src/observer/storage/record/record.h +++ b/src/observer/storage/record/record.h @@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */ #include #include "common/log/log.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "common/lang/vector.h" #include "common/lang/sstream.h" @@ -86,7 +86,7 @@ struct RIDHash { size_t operator()(const RID &rid) const noexcept { - return std::hash()(rid.page_num) ^ std::hash()(rid.slot_num); + return hash()(rid.page_num) ^ hash()(rid.slot_num); } }; diff --git a/src/observer/storage/record/record_log.cpp b/src/observer/storage/record/record_log.cpp index 3e8a15640..3af38bd07 100644 --- a/src/observer/storage/record/record_log.cpp +++ b/src/observer/storage/record/record_log.cpp @@ -328,4 +328,4 @@ RC RecordLogReplayer::replay_update(DiskBufferPool &buffer_pool, const RecordLog } return rc; -} \ No newline at end of file +} diff --git a/src/observer/storage/record/record_log.h b/src/observer/storage/record/record_log.h index 516328a80..5bf5663b6 100644 --- a/src/observer/storage/record/record_log.h +++ b/src/observer/storage/record/record_log.h @@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */ #include #include "common/types.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/span.h" #include "common/lang/string.h" #include "storage/clog/log_replayer.h" diff --git a/src/observer/storage/table/.table_meta.cpp.swp b/src/observer/storage/table/.table_meta.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..43f31f6549ace40bd9678ea56c73fea8b4201c94 GIT binary patch literal 20480 zcmeI3Ym6jS6~{|a9>OAVMMe2=8D;67ovq%T6~*4!iM=yDOT)bE?%8Es*0QF%dZwhi ztEsBqW!%L_qCoHg_(EJwAkk=yibhCKL5Yv}iozG;6GRX+J|fX*G{(gLIrrAHduEx0 z#1B@7-}ZFf_qpeud(WxM^3DU5Iq^Dur-sjYnkJSfR&IIId74?#v}0y>Wv$^R7^?Ol$Kb=ZfKeMk)0+|Fd31kw;B#=oUlRzecOahq%G6`f7$RvuwS{&J3{{S5pRoCJr#R`AQSHSI2NC-A@$>`g1f+-pa;63 z23`%eg5RE{X^(^7fOms2FbZA(o;Xv}z6rh#9sr*JSAaaY7`zH>0q20fouO&J06zy` z1t-DBz?(o0{PlEAYk~>z8gME2_wzOFY4CmU9q?^%8#oLu1!sd#L%6qsi@}S*xnK+U z9Rem#fXBhNz&F8X!AF1#E&!*2=Ku{ni~!A#!I!{Ea0mD(cq2Fjwt^RdM=_5ymydzt zn%6VC6Ah>9`C`Vl+RZuKmY5WEx<5gG7K^@nozbEcFP9gbQPWcS#ptm7L3VLmxR&2{ zyJDNH$2h$6$R2ThP)%dibQ3jn&5ku#n4TJX!|;4Jm*?WwYa*z*I#n#zmZql4wb~v$ zwYyF0I?FTkUf)|amd(aBIewJigArG!;=?nWO@q^Na!?g2N+TEBWD!kUzn$5I{YGVe zW+69H>wBK%d98lCy@uv(-!|L!Tdk(xn<#?sps2s?=H82&V}i!B_hN5kOg=Vj^$dL! zLfvCAT8`T>eM9U`J)t}-5J8{4{5L)0)=(9d2>#xKD?5-=!*QF2hdxmnPlVyLTAt-| zI*m~z9*gaJh3We)q|w;ql+B_N9$KI$abc5M$=|#tAa8V&b1U^DsUAT)Gl4bA#j=ws=k#n;Kuz1(Ot?!20obtfju8i**I z8G#QszQLr#m25!BQQfq#W4$7&(mIJUh>Kt;V4-@xtCRv0nABfXv6BlTLCQo*l#C1# zP$kSKFM))~#dA5?%F2#cK zv1oh7a@*`)lcV0T2|5lj418i6Y$>_OCu0kCOw{Dn#TmBvDRZAsZCY$&Fn7Dh4a^_y z)x3R3jg|YU6q$T-6c;BQcVZ@3QIl~s8Iv2F=QoQ*@0i)k#kYzv;lOseFc;DGAq5fa zuv|oD;{6i4E@udII+m^;aWZw!&|``G07=KSqYiYU9vwh9Q}|nKsZ${te%fU zOkii?z03{ixSF2S=Bje0p616??qF0ZTktbXSEEwN!5D+mJS>$ahbU8u;j|elHJC;N zHHV`u7Q;W)`6T=u2m%LVw#f2qCa&;EH*5T;hHay}B4#S(*=d|prps5AYq=3M0#fK_ zR+7u3pd8yXFITHCR7?BI#>_%>u2j#BBqjXJ>#3La&6bV%(p)(=BBex<+-&*EbWqxE zQd#YlcDK>)W3L@~3uIQHfArOn*kje-0t_gzPGb6|aiR)oD+()ZXW48USdG4Qou8~o zWobJr1u#4fx2y|hd&O~a`MI-x795Q+-;}Nu3iwY77Td(Z@W!@q zx?+6i_^!gGgW9Qa6>3%&m}*fHi=}G4GPN{Ys*1&>>f%DJtZU^;{qk~El&@N>;*d`HD|3sp zmGbnMsLW5zE=^bF_ltc?buqtC7qgYQO1(TS>I?WezXM0?Dw4~zi(qkFUa5)N!c6^O zsah8Jd$GE3pfZi@3-h8hFGfl=JRK4HO0`ODOdLeR3#b>ltLSj0jK*h>?~u3>OCngO zFx#uX-zydhZM$K0Jsdb4uhG^WcSUb>3oH=GV_ZAr^hL*96V5V((G@0^T@SxnA|W%= zFLF+7BBGCDhrfzbpy#ywV~iOs(v;_AEww%Wh;z|DfG*=S5|%OSb3gkvCy#0?miR!K~n{sA#ES6wpw=EhMHhv zOYOGcG9DZTzEa=RHS+&o2S4>T__O5yFXD?ncfjYr8QcKg4Q9cWU<^DTJP$mAIKaK& zgWv<;YOn=74WIvZa07S;I024>t>8EC`yT_}12=&#H~{_ypZ}lWd*IW+0EfU5sDrKG zZ}9gY0#}18K^dG09)+)e54Z)qA1s0Yz^8u{ybD|lY|sGv!4%jBE(9+J7l0?=<3A4W z244U-fOmlwcsIqkVQe<-KKTxXOmW!A z$uDH?`@O!e3J7>l8ifHu$D&wVv3vu&KSG!sFdU4XjA5LW1e}T{ z$~Xz48i`!9ZEVyvbM;&1@_}DEorAN+SNG;sarwlR>*OYEE%Y z)n&OzsM5qItTx@{AP&jB4rW$`VxoDC&1w)6Vn0vKBiC+ubm*msjOn`O+L#~_3zn*k zqN}yUPjug@`D=(jOAk1gPfa+5aV}ETO4;hRSE70m|KnL7l7quQLAn&g73f2;7@s+W zKez`FgmhK;*WrWBnr~SUs~{(IO2#f}97e(C|1F!wqtq^t0C(CL_+n+ak;>ZObfYbGobYK#X|Fd`*lonNTr zbr~7NTHl^d;gBm#Kv=+9u@UFpF&PwLtIIEyR1iq!WG!P0C@npfFR$BM8W7< zJb*R{Ysdd9uzH2U&q~+r!ULCsu-lFV6)mNtKxkkdIsSf zKB6KtanbIgf{Ax)koP!LEO>F%+7*d$LbS%iUofyk)MTTjvl)XZ;%}aYSVU5!b?xCP ztzjsExHaS%mWxBlmIXP~2*&b8YA06`y#Qfd4;xV$9A;Dokd-}U{$#yL^EVhAGsU-UHUaF>n;@2D`xN;Bol=KLXzc-vVC(cLNW&;6m^UK=FZJgD(S$4|t#h zY;X`PfjT%FoCO|1T;Pk~B=|764ZIy(4^DtrgWcdCh!gxBd z@DTVixCvYXt^_X!F9GKRiYYt-9t3xQ6X0qv3buhiBQEeK@Lg~tpg2Mkl)%ftOTp>j zpNJ3q1NcLy61)@8J%a`)f&U;j^F?qM_yqVkI0P;OkKi7`kHHVX_rb@(Nl*tm zcnA~wAh;iV4cr871eb%e0o@~bFSrTZ2rdJx2c(d^+k`fimnXJSR#>@-4%sA!DIb)7 zaIZ`TkKkmgWD1yrLGg}m= zJ{DN6>$vhjz<+v)(=uzkJm}&8wAz+$iDP&PW4XazPUkobM!LVAbbos(_gAPgJ0`ho zF4iRo%9AmPVIqp^8F6a2<&j686&6j}pOP>62Spb%&!~j$KlOaQj4)!D;h4#$%<;a* z3JzJmVcZ9iJ+*kToTSS&5Y>t~vx5<>SfatPt(2jViU((4uqY=%qk>om6ho6IpGpuF zN?dQ`{A4h2rA&E;p*tuekEo2C7^;YrOdWXC%^i}ER6Y4`m@dmwvfP7r(j^#(rP1lh z)vB{1gmsJ}xapvN~HRtw{jHz|$fHF;xHImGfp3O63k&9gc#QZpJBeLu^i zl9MH;GrCw44kM){-kK*zP9d{FP1)e;T%bMjW^1Zi7TxeF)!L5f-ex4rr6Y~upJ4=o z)JMi^4^#m(SU=tSlFA>e6B7UM_ltcN#9sQqK?Wt zeraPW7uw)5q@$5ql_V@yKSU2tHGbTsPOJ=BP7YgYTGXMW__Y(T3G+2ih3D()AUVRLn#%;&i-F4==e?m literal 0 HcmV?d00001 diff --git a/src/observer/storage/table/table_meta.cpp b/src/observer/storage/table/table_meta.cpp index f87cb894b..2c9b76523 100644 --- a/src/observer/storage/table/table_meta.cpp +++ b/src/observer/storage/table/table_meta.cpp @@ -43,7 +43,7 @@ void TableMeta::swap(TableMeta &other) noexcept std::swap(record_size_, other.record_size_); } -RC TableMeta::init(int32_t table_id, const char *name, const std::vector *trx_fields, +RC TableMeta::init(int32_t table_id, const char *name, const vector *trx_fields, span attributes, StorageFormat storage_format) { if (common::is_blank(name)) { @@ -166,7 +166,7 @@ int TableMeta::index_num() const { return indexes_.size(); } int TableMeta::record_size() const { return record_size_; } -int TableMeta::serialize(std::ostream &ss) const +int TableMeta::serialize(ostream &ss) const { Json::Value table_value; table_value[FIELD_TABLE_ID] = table_id_; @@ -193,7 +193,7 @@ int TableMeta::serialize(std::ostream &ss) const Json::StreamWriterBuilder builder; Json::StreamWriter *writer = builder.newStreamWriter(); - std::streampos old_pos = ss.tellp(); + streampos old_pos = ss.tellp(); writer->write(table_value, &ss); int ret = (int)(ss.tellp() - old_pos); @@ -201,13 +201,13 @@ int TableMeta::serialize(std::ostream &ss) const return ret; } -int TableMeta::deserialize(std::istream &is) +int TableMeta::deserialize(istream &is) { Json::Value table_value; Json::CharReaderBuilder builder; - std::string errors; + string errors; - std::streampos old_pos = is.tellg(); + streampos old_pos = is.tellg(); if (!Json::parseFromStream(builder, is, &table_value, &errors)) { LOG_ERROR("Failed to deserialize table meta. error=%s", errors.c_str()); return -1; @@ -227,7 +227,7 @@ int TableMeta::deserialize(std::istream &is) return -1; } - std::string table_name = table_name_value.asString(); + string table_name = table_name_value.asString(); const Json::Value &fields_value = table_value[FIELD_FIELDS]; if (!fields_value.isArray() || fields_value.size() <= 0) { @@ -246,7 +246,7 @@ int TableMeta::deserialize(std::istream &is) RC rc = RC::SUCCESS; int field_num = fields_value.size(); - std::vector fields(field_num); + vector fields(field_num); for (int i = 0; i < field_num; i++) { FieldMeta &field = fields[i]; @@ -259,7 +259,7 @@ int TableMeta::deserialize(std::istream &is) } auto comparator = [](const FieldMeta &f1, const FieldMeta &f2) { return f1.offset() < f2.offset(); }; - std::sort(fields.begin(), fields.end(), comparator); + sort(fields.begin(), fields.end(), comparator); table_id_ = table_id; storage_format_ = static_cast(storage_format); @@ -280,7 +280,7 @@ int TableMeta::deserialize(std::istream &is) return -1; } const int index_num = indexes_value.size(); - std::vector indexes(index_num); + vector indexes(index_num); for (int i = 0; i < index_num; i++) { IndexMeta &index = indexes[i]; @@ -299,21 +299,21 @@ int TableMeta::deserialize(std::istream &is) int TableMeta::get_serial_size() const { return -1; } -void TableMeta::to_string(std::string &output) const {} +void TableMeta::to_string(string &output) const {} -void TableMeta::desc(std::ostream &os) const +void TableMeta::desc(ostream &os) const { - os << name_ << '(' << std::endl; + os << name_ << '(' << endl; for (const auto &field : fields_) { os << '\t'; field.desc(os); - os << std::endl; + os << endl; } for (const auto &index : indexes_) { os << '\t'; index.desc(os); - os << std::endl; + os << endl; } - os << ')' << std::endl; + os << ')' << endl; } diff --git a/src/observer/storage/table/table_meta.h b/src/observer/storage/table/table_meta.h index 6f438018a..33b94e2f0 100644 --- a/src/observer/storage/table/table_meta.h +++ b/src/observer/storage/table/table_meta.h @@ -14,13 +14,10 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include -#include -#include - #include "common/lang/serializable.h" -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" +#include "common/lang/span.h" #include "storage/field/field_meta.h" #include "storage/index/index_meta.h" @@ -38,8 +35,8 @@ class TableMeta : public common::Serializable void swap(TableMeta &other) noexcept; - RC init(int32_t table_id, const char *name, const std::vector *trx_fields, - std::span attributes, StorageFormat storage_format); + RC init(int32_t table_id, const char *name, const vector *trx_fields, + span attributes, StorageFormat storage_format); RC add_index(const IndexMeta &index); @@ -50,8 +47,8 @@ class TableMeta : public common::Serializable const FieldMeta *field(int index) const; const FieldMeta *field(const char *name) const; const FieldMeta *find_field_by_offset(int offset) const; - auto field_metas() const -> const std::vector *{ return &fields_; } - auto trx_fields() const -> std::span; + auto field_metas() const -> const vector *{ return &fields_; } + auto trx_fields() const -> span; const StorageFormat storage_format() const { return storage_format_; } int field_num() const; // sys field included @@ -65,18 +62,18 @@ class TableMeta : public common::Serializable int record_size() const; public: - int serialize(std::ostream &os) const override; - int deserialize(std::istream &is) override; + int serialize(ostream &os) const override; + int deserialize(istream &is) override; int get_serial_size() const override; - void to_string(std::string &output) const override; - void desc(std::ostream &os) const; + void to_string(string &output) const override; + void desc(ostream &os) const; protected: int32_t table_id_ = -1; - std::string name_; - std::vector trx_fields_; - std::vector fields_; // 包含sys_fields - std::vector indexes_; + string name_; + vector trx_fields_; + vector fields_; // 包含sys_fields + vector indexes_; StorageFormat storage_format_; int record_size_ = 0; diff --git a/src/observer/storage/trx/mvcc_trx_log.h b/src/observer/storage/trx/mvcc_trx_log.h index 4efc298df..0e670228e 100644 --- a/src/observer/storage/trx/mvcc_trx_log.h +++ b/src/observer/storage/trx/mvcc_trx_log.h @@ -14,7 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/types.h" #include "common/lang/string.h" #include "common/lang/unordered_map.h" @@ -161,4 +161,4 @@ class MvccTrxLogReplayer final : public LogReplayer ///< 事务ID到事务的映射。在重做结束后,如果还有未提交的事务,需要回滚。 unordered_map trx_map_; -}; \ No newline at end of file +}; diff --git a/src/observer/storage/trx/trx.cpp b/src/observer/storage/trx/trx.cpp index 14ecfa78c..824eae906 100644 --- a/src/observer/storage/trx/trx.cpp +++ b/src/observer/storage/trx/trx.cpp @@ -12,8 +12,6 @@ See the Mulan PSL v2 for more details. */ // Created by Wangyunlai on 2021/5/24. // -#include - #include "common/lang/string.h" #include "common/log/log.h" #include "storage/field/field.h" diff --git a/src/observer/storage/trx/trx.h b/src/observer/storage/trx/trx.h index 5ff9af011..08396a00b 100644 --- a/src/observer/storage/trx/trx.h +++ b/src/observer/storage/trx/trx.h @@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */ #include #include -#include "common/rc.h" +#include "common/sys/rc.h" #include "common/lang/mutex.h" #include "sql/parser/parse.h" #include "storage/field/field_meta.h" diff --git a/test/perf/CMakeLists.txt b/test/perf/CMakeLists.txt deleted file mode 100644 index b377d35b2..000000000 --- a/test/perf/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ - -#get_filename_component( FileName -# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH -# [CACHE]) -FILE(GLOB_RECURSE ALL_SRC *.cpp) -# AUX_SOURCE_DIRECTORY 类似功能 -FOREACH (F ${ALL_SRC}) - get_filename_component(prjName ${F} NAME_WE) - MESSAGE("Build ${prjName} according to ${F}") - ADD_EXECUTABLE(${prjName} ${F}) - TARGET_LINK_LIBRARIES(${prjName} common pthread dl observer_static) - -ENDFOREACH (F) \ No newline at end of file diff --git a/test/perf/client_performance_test.cpp b/test/perf/client_performance_test.cpp deleted file mode 100644 index 25d2ddc7e..000000000 --- a/test/perf/client_performance_test.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* 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. */ - -// -// Created by Longda on 2021 -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/defs.h" -#include "common/metrics/console_reporter.h" -#include "common/metrics/metrics.h" -#include "common/metrics/metrics_registry.h" - -#define MAX_MEM_BUFFER_SIZE 8192 -#define PORT_DEFAULT 6789 - -using namespace common; - -char *server_host = (char *)"localhost"; -int server_port = PORT_DEFAULT; - -void *test_server(void *param) -{ - Meter *tps_meter = (Meter *)param; - - std::cout << "Begin to connect server. " << std::endl; - int sockfd, sendbytes; - // char send[MAXLINE]; - - char send_buf[MAX_MEM_BUFFER_SIZE] = {0}; - char recv_buf[MAX_MEM_BUFFER_SIZE] = {0}; - snprintf(send_buf, sizeof(send_buf), "%s", "select count(*) from test"); - // char buf[MAXDATASIZE]; - struct hostent *host; - struct sockaddr_in serv_addr; - - if ((host = gethostbyname(server_host)) == NULL) { - perror("gethostbyname"); - exit(1); - } - if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - perror("socket error \n"); - exit(1); - } - - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons((uint16_t)server_port); - serv_addr.sin_addr = *((struct in_addr *)host->h_addr); - bzero(&(serv_addr.sin_zero), 8); - - if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1) { - perror("Failed to connect \n"); - exit(1); - } - - while (true) { - if ((sendbytes = send(sockfd, send_buf, strlen(send_buf) + 1, 0)) == -1) { - perror("send error \n"); - exit(1); - } - - memset(recv_buf, 0, sizeof(recv_buf)); - - int len = recv(sockfd, recv_buf, sizeof(recv_buf), 0); - if (len < 0) { - printf("connection exception\n"); - break; - } - if (len == 0) { - printf("Connection has been closed\n"); - break; - } - - tps_meter->inc(); - } - close(sockfd); - return NULL; -} - -int main(int argc, char *argv[]) -{ - int opt; - extern char *optarg; - while ((opt = getopt(argc, argv, "h:p:")) > 0) { - switch (opt) { - case 'p': server_port = atoi(optarg); break; - case 'h': server_host = optarg; break; - } - } - - MetricsRegistry &metric_registry = get_metrics_registry(); - ConsoleReporter *console_reporter = get_console_reporter(); - metric_registry.add_reporter(console_reporter); - - Meter *tps_meter = new Meter(); - - metric_registry.register_metric("client.sendtps", tps_meter); - - for (int i = 0; i < 8; i++) { - pthread_t pid; - pthread_create(&pid, NULL, test_server, tps_meter); - } - - while (1) { - sleep(60); - metric_registry.snapshot(); - metric_registry.report(); - } - return 0; -} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index d1fbdc5bc..a9990c78b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,6 +1,6 @@ ADD_EXECUTABLE(clog_dump clog_dump.cpp) TARGET_LINK_LIBRARIES(clog_dump observer_static) -TARGET_INCLUDE_DIRECTORIES(clog_dump PRIVATE ${PROJECT_SOURCE_DIR}/src/observer/) +TARGET_INCLUDE_DIRECTORIES(clog_dump PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/observer/) # Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制 # TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类 diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index e4cd54e24..a01e32787 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -5,9 +5,11 @@ find_package(GTest CONFIG REQUIRED) include(GoogleTest) +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src) + ADD_SUBDIRECTORY(common) IF (WITH_MEMTRACER) ADD_SUBDIRECTORY(memtracer) ENDIF (WITH_MEMTRACER) -ADD_SUBDIRECTORY(observer) \ No newline at end of file +ADD_SUBDIRECTORY(observer) From 0936d27235277c84187a8a7b8adb95e99fd77409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BF=90=E6=9D=A5?= Date: Tue, 19 Nov 2024 18:11:44 +0800 Subject: [PATCH 5/8] fix compile bug --- src/common/lang/algorithm.h | 2 +- src/common/lang/string.h | 4 ++-- src/observer/sql/executor/sql_result.h | 8 ++++---- src/observer/sql/expr/aggregate_hash_table.h | 8 ++++---- src/observer/sql/expr/expression.h | 10 +++++----- src/observer/sql/expr/expression_tuple.h | 2 +- src/observer/sql/expr/tuple.h | 15 ++++++--------- .../operator/aggregate_vec_physical_operator.h | 6 +++--- .../sql/operator/calc_physical_operator.h | 6 +++--- .../sql/operator/explain_physical_operator.h | 2 +- .../sql/operator/expr_vec_physical_operator.h | 4 ++-- .../operator/hash_group_by_physical_operator.h | 5 ++--- .../sql/operator/insert_logical_operator.h | 4 ++-- .../sql/operator/project_physical_operator.h | 2 +- .../sql/operator/project_vec_physical_operator.h | 2 +- .../operator/scalar_group_by_physical_operator.h | 2 +- .../sql/operator/string_list_physical_operator.h | 4 ++-- src/observer/sql/optimizer/optimize_stage.h | 4 ++-- .../sql/optimizer/predicate_pushdown_rewriter.h | 3 +-- src/observer/sql/parser/expression_binder.h | 12 ++++-------- src/observer/sql/parser/lex_sql.l | 6 +++--- src/observer/sql/parser/parse_defs.h | 16 ++++++++-------- src/observer/sql/parser/yacc_sql.y | 10 +++++----- src/observer/sql/stmt/create_index_stmt.h | 8 ++++---- src/observer/sql/stmt/create_table_stmt.h | 7 +++---- src/observer/sql/stmt/load_data_stmt.h | 2 +- src/observer/sql/stmt/select_stmt.h | 6 +++--- src/observer/storage/table/table_meta.h | 4 ++-- 28 files changed, 77 insertions(+), 87 deletions(-) diff --git a/src/common/lang/algorithm.h b/src/common/lang/algorithm.h index 8039152a3..539491895 100644 --- a/src/common/lang/algorithm.h +++ b/src/common/lang/algorithm.h @@ -14,5 +14,5 @@ See the Mulan PSL v2 for more details. */ using std::max; using std::min; -using std::transform; using std::swap; +using std::transform; diff --git a/src/common/lang/string.h b/src/common/lang/string.h index d7fc1b608..dafdf7216 100644 --- a/src/common/lang/string.h +++ b/src/common/lang/string.h @@ -30,10 +30,10 @@ See the Mulan PSL v2 for more details. */ #include "common/lang/sstream.h" #include "common/lang/set.h" +using std::stof; +using std::stol; using std::string; using std::to_string; -using std::stol; -using std::stof; namespace common { diff --git a/src/observer/sql/executor/sql_result.h b/src/observer/sql/executor/sql_result.h index aed92e26d..e3ac999d5 100644 --- a/src/observer/sql/executor/sql_result.h +++ b/src/observer/sql/executor/sql_result.h @@ -43,7 +43,7 @@ class SqlResult bool has_operator() const { return operator_ != nullptr; } const TupleSchema &tuple_schema() const { return tuple_schema_; } RC return_code() const { return return_code_; } - const string &state_string() const { return state_string_; } + const string &state_string() const { return state_string_; } RC open(); RC close(); @@ -51,9 +51,9 @@ class SqlResult RC next_chunk(Chunk &chunk); private: - Session *session_ = nullptr; ///< 当前所属会话 + Session *session_ = nullptr; ///< 当前所属会话 unique_ptr operator_; ///< 执行计划 - TupleSchema tuple_schema_; ///< 返回的表头信息。可能有也可能没有 - RC return_code_ = RC::SUCCESS; + TupleSchema tuple_schema_; ///< 返回的表头信息。可能有也可能没有 + RC return_code_ = RC::SUCCESS; string state_string_; }; diff --git a/src/observer/sql/expr/aggregate_hash_table.h b/src/observer/sql/expr/aggregate_hash_table.h index f1e83bbb2..83e4d4168 100644 --- a/src/observer/sql/expr/aggregate_hash_table.h +++ b/src/observer/sql/expr/aggregate_hash_table.h @@ -96,7 +96,7 @@ class StandardAggregateHashTable : public AggregateHashTable private: /// group by values -> aggregate values - StandardHashTable aggr_values_; + StandardHashTable aggr_values_; vector aggr_types_; }; @@ -162,10 +162,10 @@ class LinearProbingAggregateHashTable : public AggregateHashTable static const int EMPTY_KEY; static const int DEFAULT_CAPACITY; - vector keys_; - vector values_; + vector keys_; + vector values_; int size_ = 0; int capacity_ = 0; AggregateExpr::Type aggregate_type_; }; -#endif // USE_SIMD +#endif // USE_SIMD diff --git a/src/observer/sql/expr/expression.h b/src/observer/sql/expr/expression.h index 4c1ee0775..af2710d8b 100644 --- a/src/observer/sql/expr/expression.h +++ b/src/observer/sql/expr/expression.h @@ -266,7 +266,7 @@ class CastExpr : public Expression private: unique_ptr child_; ///< 从这个表达式转换 - AttrType cast_type_; ///< 想要转换成这个类型 + AttrType cast_type_; ///< 想要转换成这个类型 }; /** @@ -309,7 +309,7 @@ class ComparisonExpr : public Expression RC compare_column(const Column &left, const Column &right, vector &result) const; private: - CompOp comp_; + CompOp comp_; unique_ptr left_; unique_ptr right_; }; @@ -342,7 +342,7 @@ class ConjunctionExpr : public Expression vector> &children() { return children_; } private: - Type conjunction_type_; + Type conjunction_type_; vector> children_; }; @@ -399,7 +399,7 @@ class ArithmeticExpr : public Expression RC execute_calc(const Column &left, const Column &right, Column &result, Type type, AttrType attr_type) const; private: - Type arithmetic_type_; + Type arithmetic_type_; unique_ptr left_; unique_ptr right_; }; @@ -464,6 +464,6 @@ class AggregateExpr : public Expression static RC type_from_string(const char *type_str, Type &type); private: - Type aggregate_type_; + Type aggregate_type_; unique_ptr child_; }; diff --git a/src/observer/sql/expr/expression_tuple.h b/src/observer/sql/expr/expression_tuple.h index df9dbe0bd..c70cd4fc2 100644 --- a/src/observer/sql/expr/expression_tuple.h +++ b/src/observer/sql/expr/expression_tuple.h @@ -86,5 +86,5 @@ class ExpressionTuple : public Tuple private: const vector &expressions_; - const Tuple *child_tuple_ = nullptr; + const Tuple *child_tuple_ = nullptr; }; diff --git a/src/observer/sql/expr/tuple.h b/src/observer/sql/expr/tuple.h index 0f20398e7..172ba6077 100644 --- a/src/observer/sql/expr/tuple.h +++ b/src/observer/sql/expr/tuple.h @@ -94,8 +94,8 @@ class Tuple virtual string to_string() const { - string str; - const int cell_num = this->cell_num(); + string str; + const int cell_num = this->cell_num(); for (int i = 0; i < cell_num - 1; i++) { Value cell; cell_at(i, cell); @@ -242,8 +242,8 @@ class RowTuple : public Tuple const Record &record() const { return *record_; } private: - Record *record_ = nullptr; - const Table *table_ = nullptr; + Record *record_ = nullptr; + const Table *table_ = nullptr; vector speces_; }; @@ -259,10 +259,7 @@ class ProjectTuple : public Tuple ProjectTuple() = default; virtual ~ProjectTuple() = default; - void set_expressions(vector> &&expressions) - { - expressions_ = std::move(expressions); - } + void set_expressions(vector> &&expressions) { expressions_ = std::move(expressions); } auto get_expressions() const -> const vector> & { return expressions_; } @@ -303,7 +300,7 @@ class ProjectTuple : public Tuple #endif private: vector> expressions_; - Tuple *tuple_ = nullptr; + Tuple *tuple_ = nullptr; }; /** diff --git a/src/observer/sql/operator/aggregate_vec_physical_operator.h b/src/observer/sql/operator/aggregate_vec_physical_operator.h index 2dd748a21..48c6a0e1b 100644 --- a/src/observer/sql/operator/aggregate_vec_physical_operator.h +++ b/src/observer/sql/operator/aggregate_vec_physical_operator.h @@ -68,7 +68,7 @@ class AggregateVecPhysicalOperator : public PhysicalOperator }; vector aggregate_expressions_; /// 聚合表达式 vector value_expressions_; - Chunk chunk_; - Chunk output_chunk_; - AggregateValues aggr_values_; + Chunk chunk_; + Chunk output_chunk_; + AggregateValues aggr_values_; }; diff --git a/src/observer/sql/operator/calc_physical_operator.h b/src/observer/sql/operator/calc_physical_operator.h index 19a9c55de..bb1d7d6d1 100644 --- a/src/observer/sql/operator/calc_physical_operator.h +++ b/src/observer/sql/operator/calc_physical_operator.h @@ -68,7 +68,7 @@ class CalcPhysicalOperator : public PhysicalOperator } private: - vector> expressions_; - ExpressionTuple> tuple_; - bool emitted_ = false; + vector> expressions_; + ExpressionTuple> tuple_; + bool emitted_ = false; }; diff --git a/src/observer/sql/operator/explain_physical_operator.h b/src/observer/sql/operator/explain_physical_operator.h index 0b965c3c8..8ae0bb0ea 100644 --- a/src/observer/sql/operator/explain_physical_operator.h +++ b/src/observer/sql/operator/explain_physical_operator.h @@ -46,6 +46,6 @@ class ExplainPhysicalOperator : public PhysicalOperator void generate_physical_plan(); private: - string physical_plan_; + string physical_plan_; ValueListTuple tuple_; }; diff --git a/src/observer/sql/operator/expr_vec_physical_operator.h b/src/observer/sql/operator/expr_vec_physical_operator.h index 047c8cb8c..bbd5a9a91 100644 --- a/src/observer/sql/operator/expr_vec_physical_operator.h +++ b/src/observer/sql/operator/expr_vec_physical_operator.h @@ -31,6 +31,6 @@ class ExprVecPhysicalOperator : public PhysicalOperator private: vector expressions_; /// 表达式 - Chunk chunk_; - Chunk evaled_chunk_; + Chunk chunk_; + Chunk evaled_chunk_; }; diff --git a/src/observer/sql/operator/hash_group_by_physical_operator.h b/src/observer/sql/operator/hash_group_by_physical_operator.h index d04319887..1c3919e36 100644 --- a/src/observer/sql/operator/hash_group_by_physical_operator.h +++ b/src/observer/sql/operator/hash_group_by_physical_operator.h @@ -27,8 +27,7 @@ See the Mulan PSL v2 for more details. */ class HashGroupByPhysicalOperator : public GroupByPhysicalOperator { public: - HashGroupByPhysicalOperator( - vector> &&group_by_exprs, vector &&expressions); + HashGroupByPhysicalOperator(vector> &&group_by_exprs, vector &&expressions); virtual ~HashGroupByPhysicalOperator() = default; @@ -58,5 +57,5 @@ class HashGroupByPhysicalOperator : public GroupByPhysicalOperator vector groups_; vector::iterator current_group_; - bool first_emited_ = false; /// 第一条数据是否已经输出 + bool first_emited_ = false; /// 第一条数据是否已经输出 }; diff --git a/src/observer/sql/operator/insert_logical_operator.h b/src/observer/sql/operator/insert_logical_operator.h index ea68f7cb5..1763bcd08 100644 --- a/src/observer/sql/operator/insert_logical_operator.h +++ b/src/observer/sql/operator/insert_logical_operator.h @@ -29,11 +29,11 @@ class InsertLogicalOperator : public LogicalOperator LogicalOperatorType type() const override { return LogicalOperatorType::INSERT; } - Table *table() const { return table_; } + Table *table() const { return table_; } const vector &values() const { return values_; } vector &values() { return values_; } private: - Table *table_ = nullptr; + Table *table_ = nullptr; vector values_; }; diff --git a/src/observer/sql/operator/project_physical_operator.h b/src/observer/sql/operator/project_physical_operator.h index 189328743..6f49fee19 100644 --- a/src/observer/sql/operator/project_physical_operator.h +++ b/src/observer/sql/operator/project_physical_operator.h @@ -41,6 +41,6 @@ class ProjectPhysicalOperator : public PhysicalOperator RC tuple_schema(TupleSchema &schema) const override; private: - vector> expressions_; + vector> expressions_; ExpressionTuple> tuple_; }; diff --git a/src/observer/sql/operator/project_vec_physical_operator.h b/src/observer/sql/operator/project_vec_physical_operator.h index 5d3792ffb..de3f716f6 100644 --- a/src/observer/sql/operator/project_vec_physical_operator.h +++ b/src/observer/sql/operator/project_vec_physical_operator.h @@ -37,5 +37,5 @@ class ProjectVecPhysicalOperator : public PhysicalOperator private: vector> expressions_; - Chunk chunk_; + Chunk chunk_; }; diff --git a/src/observer/sql/operator/scalar_group_by_physical_operator.h b/src/observer/sql/operator/scalar_group_by_physical_operator.h index 542bf9657..9f83a54f8 100644 --- a/src/observer/sql/operator/scalar_group_by_physical_operator.h +++ b/src/observer/sql/operator/scalar_group_by_physical_operator.h @@ -36,5 +36,5 @@ class ScalarGroupByPhysicalOperator : public GroupByPhysicalOperator private: unique_ptr group_value_; - bool emitted_ = false; /// 标识是否已经输出过 + bool emitted_ = false; /// 标识是否已经输出过 }; diff --git a/src/observer/sql/operator/string_list_physical_operator.h b/src/observer/sql/operator/string_list_physical_operator.h index 609238c7f..038aa0bea 100644 --- a/src/observer/sql/operator/string_list_physical_operator.h +++ b/src/observer/sql/operator/string_list_physical_operator.h @@ -70,8 +70,8 @@ class StringListPhysicalOperator : public PhysicalOperator return nullptr; } - const StringList &string_list = *iterator_; - vector cells; + const StringList &string_list = *iterator_; + vector cells; for (const string &s : string_list) { Value value(s.c_str()); diff --git a/src/observer/sql/optimizer/optimize_stage.h b/src/observer/sql/optimizer/optimize_stage.h index 9d69e28c2..83c0f9739 100644 --- a/src/observer/sql/optimizer/optimize_stage.h +++ b/src/observer/sql/optimizer/optimize_stage.h @@ -71,8 +71,8 @@ class OptimizeStage * 而物理计划描述怎么做,比如如何从某张表按照什么条件获取什么数据,是否使用索引,使用哪个索引等。 * @param physical_operator 生成的物理计划。通常是一个多叉树的形状,这里就拿着根节点就可以了。 */ - RC generate_physical_plan(unique_ptr &logical_operator, - unique_ptr &physical_operator, Session *session); + RC generate_physical_plan( + unique_ptr &logical_operator, unique_ptr &physical_operator, Session *session); private: LogicalPlanGenerator logical_plan_generator_; ///< 根据SQL生成逻辑计划 diff --git a/src/observer/sql/optimizer/predicate_pushdown_rewriter.h b/src/observer/sql/optimizer/predicate_pushdown_rewriter.h index 1231b6690..5fbc4510a 100644 --- a/src/observer/sql/optimizer/predicate_pushdown_rewriter.h +++ b/src/observer/sql/optimizer/predicate_pushdown_rewriter.h @@ -31,7 +31,6 @@ class PredicatePushdownRewriter : public RewriteRule RC rewrite(unique_ptr &oper, bool &change_made) override; private: - RC get_exprs_can_pushdown( - unique_ptr &expr, vector> &pushdown_exprs); + RC get_exprs_can_pushdown(unique_ptr &expr, vector> &pushdown_exprs); bool is_empty_predicate(unique_ptr &expr); }; diff --git a/src/observer/sql/parser/expression_binder.h b/src/observer/sql/parser/expression_binder.h index 103e63c97..9a5e7c9cd 100644 --- a/src/observer/sql/parser/expression_binder.h +++ b/src/observer/sql/parser/expression_binder.h @@ -45,16 +45,12 @@ class ExpressionBinder RC bind_expression(unique_ptr &expr, vector> &bound_expressions); private: - RC bind_star_expression( - unique_ptr &star_expr, vector> &bound_expressions); + RC bind_star_expression(unique_ptr &star_expr, vector> &bound_expressions); RC bind_unbound_field_expression( unique_ptr &unbound_field_expr, vector> &bound_expressions); - RC bind_field_expression( - unique_ptr &field_expr, vector> &bound_expressions); - RC bind_value_expression( - unique_ptr &value_expr, vector> &bound_expressions); - RC bind_cast_expression( - unique_ptr &cast_expr, vector> &bound_expressions); + RC bind_field_expression(unique_ptr &field_expr, vector> &bound_expressions); + RC bind_value_expression(unique_ptr &value_expr, vector> &bound_expressions); + RC bind_cast_expression(unique_ptr &cast_expr, vector> &bound_expressions); RC bind_comparison_expression( unique_ptr &comparison_expr, vector> &bound_expressions); RC bind_conjunction_expression( diff --git a/src/observer/sql/parser/lex_sql.l b/src/observer/sql/parser/lex_sql.l index 2e8225b97..ed028d048 100644 --- a/src/observer/sql/parser/lex_sql.l +++ b/src/observer/sql/parser/lex_sql.l @@ -119,7 +119,7 @@ GROUP RETURN_TOKEN(GROUP); BY RETURN_TOKEN(BY); STORAGE RETURN_TOKEN(STORAGE); FORMAT RETURN_TOKEN(FORMAT); -{ID} yylval->string=strdup(yytext); RETURN_TOKEN(ID); +{ID} yylval->cstring=strdup(yytext); RETURN_TOKEN(ID); "(" RETURN_TOKEN(LBRACE); ")" RETURN_TOKEN(RBRACE); @@ -136,8 +136,8 @@ FORMAT RETURN_TOKEN(FORMAT); "-" | "*" | "/" { return yytext[0]; } -\"[^"]*\" yylval->string = strdup(yytext); RETURN_TOKEN(SSS); -'[^']*\' yylval->string = strdup(yytext); RETURN_TOKEN(SSS); +\"[^"]*\" yylval->cstring = strdup(yytext); RETURN_TOKEN(SSS); +'[^']*\' yylval->cstring = strdup(yytext); RETURN_TOKEN(SSS); . LOG_DEBUG("Unknown character [%c]",yytext[0]); return yytext[0]; %% diff --git a/src/observer/sql/parser/parse_defs.h b/src/observer/sql/parser/parse_defs.h index 4acbf4ecd..119237f35 100644 --- a/src/observer/sql/parser/parse_defs.h +++ b/src/observer/sql/parser/parse_defs.h @@ -89,7 +89,7 @@ struct SelectSqlNode { vector> expressions; ///< 查询的表达式 vector relations; ///< 查询的表 - vector conditions; ///< 查询条件,使用AND串联起来多个条件 + vector conditions; ///< 查询条件,使用AND串联起来多个条件 vector> group_by; ///< group by clause }; @@ -131,7 +131,7 @@ struct UpdateSqlNode { string relation_name; ///< Relation to update string attribute_name; ///< 更新的字段,仅支持一个字段 - Value value; ///< 更新的值,仅支持一个字段 + Value value; ///< 更新的值,仅支持一个字段 vector conditions; }; @@ -142,9 +142,9 @@ struct UpdateSqlNode */ struct AttrInfoSqlNode { - AttrType type; ///< Type of attribute - string name; ///< Attribute name - size_t length; ///< Length of attribute + AttrType type; ///< Type of attribute + string name; ///< Attribute name + size_t length; ///< Length of attribute }; /** @@ -220,7 +220,7 @@ struct LoadDataSqlNode struct SetVariableSqlNode { string name; - Value value; + Value value; }; class ParsedSqlNode; @@ -245,8 +245,8 @@ struct ExplainSqlNode struct ErrorSqlNode { string error_msg; - int line; - int column; + int line; + int column; }; /** diff --git a/src/observer/sql/parser/yacc_sql.y b/src/observer/sql/parser/yacc_sql.y index 3cb83c029..786879000 100644 --- a/src/observer/sql/parser/yacc_sql.y +++ b/src/observer/sql/parser/yacc_sql.y @@ -127,15 +127,15 @@ UnboundAggregateExpr *create_aggregate_expression(const char *aggregate_name, vector * condition_list; vector * rel_attr_list; vector * relation_list; - char * string; + char * cstring; int number; float floats; } %token NUMBER %token FLOAT -%token ID -%token SSS +%token ID +%token SSS //非终结符 /** type 定义了各种解析后的结果输出的是什么类型。类型对应了 union 中的定义的成员变量名称 **/ @@ -143,7 +143,7 @@ UnboundAggregateExpr *create_aggregate_expression(const char *aggregate_name, %type condition %type value %type number -%type relation +%type relation %type comp_op %type rel_attr %type attr_def_list @@ -151,7 +151,7 @@ UnboundAggregateExpr *create_aggregate_expression(const char *aggregate_name, %type value_list %type where %type condition_list -%type storage_format +%type storage_format %type rel_list %type expression %type expression_list diff --git a/src/observer/sql/stmt/create_index_stmt.h b/src/observer/sql/stmt/create_index_stmt.h index 6d9d42aca..cbdd8f4d1 100644 --- a/src/observer/sql/stmt/create_index_stmt.h +++ b/src/observer/sql/stmt/create_index_stmt.h @@ -35,9 +35,9 @@ class CreateIndexStmt : public Stmt StmtType type() const override { return StmtType::CREATE_INDEX; } - Table *table() const { return table_; } - const FieldMeta *field_meta() const { return field_meta_; } - const string &index_name() const { return index_name_; } + Table *table() const { return table_; } + const FieldMeta *field_meta() const { return field_meta_; } + const string &index_name() const { return index_name_; } public: static RC create(Db *db, const CreateIndexSqlNode &create_index, Stmt *&stmt); @@ -45,5 +45,5 @@ class CreateIndexStmt : public Stmt private: Table *table_ = nullptr; const FieldMeta *field_meta_ = nullptr; - string index_name_; + string index_name_; }; diff --git a/src/observer/sql/stmt/create_table_stmt.h b/src/observer/sql/stmt/create_table_stmt.h index 4b66f8867..aed632d18 100644 --- a/src/observer/sql/stmt/create_table_stmt.h +++ b/src/observer/sql/stmt/create_table_stmt.h @@ -28,8 +28,7 @@ class Db; class CreateTableStmt : public Stmt { public: - CreateTableStmt( - const string &table_name, const vector &attr_infos, StorageFormat storage_format) + CreateTableStmt(const string &table_name, const vector &attr_infos, StorageFormat storage_format) : table_name_(table_name), attr_infos_(attr_infos), storage_format_(storage_format) {} virtual ~CreateTableStmt() = default; @@ -38,7 +37,7 @@ class CreateTableStmt : public Stmt const string &table_name() const { return table_name_; } const vector &attr_infos() const { return attr_infos_; } - const StorageFormat storage_format() const { return storage_format_; } + const StorageFormat storage_format() const { return storage_format_; } static RC create(Db *db, const CreateTableSqlNode &create_table, Stmt *&stmt); static StorageFormat get_storage_format(const char *format_str); @@ -46,5 +45,5 @@ class CreateTableStmt : public Stmt private: string table_name_; vector attr_infos_; - StorageFormat storage_format_; + StorageFormat storage_format_; }; diff --git a/src/observer/sql/stmt/load_data_stmt.h b/src/observer/sql/stmt/load_data_stmt.h index 995d1c525..1308159b7 100644 --- a/src/observer/sql/stmt/load_data_stmt.h +++ b/src/observer/sql/stmt/load_data_stmt.h @@ -32,6 +32,6 @@ class LoadDataStmt : public Stmt static RC create(Db *db, const LoadDataSqlNode &load_data, Stmt *&stmt); private: - Table *table_ = nullptr; + Table *table_ = nullptr; string filename_; }; diff --git a/src/observer/sql/stmt/select_stmt.h b/src/observer/sql/stmt/select_stmt.h index 9d4c8fd7d..5a736d9d0 100644 --- a/src/observer/sql/stmt/select_stmt.h +++ b/src/observer/sql/stmt/select_stmt.h @@ -40,14 +40,14 @@ class SelectStmt : public Stmt public: const vector
&tables() const { return tables_; } - FilterStmt *filter_stmt() const { return filter_stmt_; } + FilterStmt *filter_stmt() const { return filter_stmt_; } vector> &query_expressions() { return query_expressions_; } vector> &group_by() { return group_by_; } private: vector> query_expressions_; - vector
tables_; - FilterStmt *filter_stmt_ = nullptr; + vector
tables_; + FilterStmt *filter_stmt_ = nullptr; vector> group_by_; }; diff --git a/src/observer/storage/table/table_meta.h b/src/observer/storage/table/table_meta.h index 33b94e2f0..61a6c0dfe 100644 --- a/src/observer/storage/table/table_meta.h +++ b/src/observer/storage/table/table_meta.h @@ -69,12 +69,12 @@ class TableMeta : public common::Serializable void desc(ostream &os) const; protected: - int32_t table_id_ = -1; + int32_t table_id_ = -1; string name_; vector trx_fields_; vector fields_; // 包含sys_fields vector indexes_; - StorageFormat storage_format_; + StorageFormat storage_format_; int record_size_ = 0; }; From 4ad7c20550bc7c314e733c89ab3bcff9268cf655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BF=90=E6=9D=A5?= Date: Tue, 19 Nov 2024 20:07:47 +0800 Subject: [PATCH 6/8] fix compile bug --- src/common/lang/ranges.h | 1 + .../sql/operator/group_by_physical_operator.cpp | 3 ++- src/observer/storage/common/meta_util.cpp | 3 +-- src/observer/storage/index/.bplus_tree.h.swp | Bin 16384 -> 0 bytes 4 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 src/observer/storage/index/.bplus_tree.h.swp diff --git a/src/common/lang/ranges.h b/src/common/lang/ranges.h index 839876e8b..fcc287714 100644 --- a/src/common/lang/ranges.h +++ b/src/common/lang/ranges.h @@ -10,6 +10,7 @@ See the Mulan PSL v2 for more details. */ #pragma once +#include #include namespace ranges = std::ranges; diff --git a/src/observer/sql/operator/group_by_physical_operator.cpp b/src/observer/sql/operator/group_by_physical_operator.cpp index c925a82b6..75301f2b6 100644 --- a/src/observer/sql/operator/group_by_physical_operator.cpp +++ b/src/observer/sql/operator/group_by_physical_operator.cpp @@ -13,6 +13,7 @@ See the Mulan PSL v2 for more details. */ // #include "common/log/log.h" +#include "common/lang/ranges.h" #include "sql/operator/group_by_physical_operator.h" #include "sql/expr/expression_tuple.h" #include "sql/expr/composite_tuple.h" @@ -36,7 +37,7 @@ void GroupByPhysicalOperator::create_aggregator_list(AggregatorList &aggregator_ { aggregator_list.clear(); aggregator_list.reserve(aggregate_expressions_.size()); - ranges::for_each(aggregate_expressions_, [&aggregator_list](Expression *expr) { + std::ranges::for_each(aggregate_expressions_, [&aggregator_list](Expression *expr) { auto *aggregate_expr = static_cast(expr); aggregator_list.emplace_back(aggregate_expr->create_aggregator()); }); diff --git a/src/observer/storage/common/meta_util.cpp b/src/observer/storage/common/meta_util.cpp index 1d7117dcb..267d0adf4 100644 --- a/src/observer/storage/common/meta_util.cpp +++ b/src/observer/storage/common/meta_util.cpp @@ -12,8 +12,7 @@ See the Mulan PSL v2 for more details. */ // #include "storage/common/meta_util.h" - -using namespace std; +#include "common/lang/filesystem.h" string db_meta_file(const char *base_dir, const char *db_name) { diff --git a/src/observer/storage/index/.bplus_tree.h.swp b/src/observer/storage/index/.bplus_tree.h.swp deleted file mode 100644 index 8858137b253ea277e40faf520f61542e4d2667c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3du$ZP9mh9m+O&B!O;J=-shYSFx-<4IcA_dh0?OGw!zE|m>F$8gs#@*c&E2io z+r8}Lz)&c!q>$i10)(_p%tHhy#KyEDX(0|#S|w@KN{!S?{j2}fceYWbKGRC{k$z`q z&psbM?7seJyDL84+nL||cIG>eot+)h%hpEv$b*4S0mt2f@b2md@~8cageT74AsD)D zvEccRqM|8!y1ipQyKT&&sAs6GrDc=0o4RdesK}FxrjZf#v`LLJHAK_W4LMImMa$An zV!EW-reqnE1`6}t#EbV7@DymGz@5VVogK?qqg=HuxTR z6Py9N!49wuYy~BtgD-+FfX{(@!TWaz!h7H%cn(ky1dG7c+XZ0?yaz6TQSb^l2)+z9 zfsMcfDXV?tO6aN9ef%r2A=>|ZxMtl z_%Zkv7y-jzGZ+AI5Cyk^UwudrCcy;w1$YOHfOFt1I0ZHW8GH#u!6TpxypQ(u2QUiG zgC_xNV>`g?gODu(A*N+0TAt`7YRK68;q&`4x@KA=Q;-ePTJ{s?Qh+574_THGM-qz~ zWQmLmsl=~*t|{3<3~JeiM(Sgw!Qr49$!L}94#~h^wN|adm(}pmMs8q{a1wTB@ zN*ZwNxtVLiyp`;{wAk#Uwk=Ww#dvmvpF z>2f#`ESCs|CS}>8L006gfYdZ8%c@NSmM(GKeSYSGkhLtBIFY^?KW$udDI=TKL%c#( z`pW(`E{~fB$HPBXldLRt#b{D_C_}l5$B=04# zA+0PFO1K@$3G(~Oon+~CcMH_%>hsU(spEQ29SiXU`D;yZx)B=Gv{j2&o020weogLM zL6)KOIVo5Zaf4S}mt9{OWiIm)GjnF#Yyg4ftO2ES&Jm@qCitK-Qx#2G=ZwKWGqlvD zUij!TlgW7+WR_a8qMBrSAes33Za&;heeLA-#3Jyik2{FWLuw zS6?_k{+&y(nc8us^28vw!8kSb)xpZi!O89WDkp|2PaT89UvA%d{b+Xn(BvDt{-Xm} zk8H_o*bWArp-#cGLe?_0Zq)L(ujKMlpGtEU>mB)mPcfh2Ul!YVohB*c^v{RPC zv0^u=_sttEA1)m$9>8u?=M{~vu187ky{C=XtfPWmRe{$BsWm%cypil9pzhYb90B2MR4s zEmhgd6r>_8>T_EeG@~0?k)NcZtYHVQF}G>j&gHPpH>;Q%B>r0}>AKor{J1KjjblqN zKS>bFoNa<$P}DUM8E4ELCu?~zXKRi=a>FfZ>6wj*xe%3$&7H848w1Vbd6#6yWJhTT^8PW~3Xr zv(Wot@t8tMA5{ieIQu6gDJHNO75Z#d)<`@V#dDG5bb}zrl(-Lq0Bdx8;Y9c9P=6}a z6^TYt>q#s@dLt>)i*ty?Ly1(RdrdTyAn`Sccq|zX2;oR-bvQx7kHr(=WRlrO`r^?@ zxTg)>raQW(C(^%)bgfB|{#c4cBYlxnxCbK^F8kXf{k;i9hx@|)=v}GRkt9jRdQ(Mcp|no(gX8YKMD1dmQWI*Eu<@yj3nF0I@~x0zpzdq!;vs<-V3|+=bs+ly9(anq+(2aZ`qlu0n(4$jWuiK<34-h?#ry|}8FoKqFm7A@ZYy}<5 z3}m!TCaPi*Q_oo&We6!}SPN$_Dwgi(jn|K&NzljG>>{hME@(2Jjdc+a_%3$>Z*D%b z#Kz`!W7h2h=;Ndt`Es5qn6mjv=d#X@nfmr^QfQG?{KEy?v;s71qmX_l12ML*z6<;6 z*_DW@S1jZ#ms3;)&BhFnkgD=0n#rbAY@dBLAh7p;ig)rK0QUZ0`+j~6@BMFsH^D35 z95?~WAPSa(R`4^d2MmENU^7?+ZU;YdeZI^5dWWZgr+}w`r+}w`r+}w`r+}w`r+}w` zr@+5Y0q5&b8fz%Ex8kPfoMM=kM2l>_A+ZCj} zgQevwDZyYLEyj_Hh((LRAZ&}0ttpS&R4Q2pfBlp;&;fkdK$>1dE>hB(u?>T2mXu?c zEJK>DsxW76MJ#+wUVN=``swkp!HKbv%5(cBF7K%hpWv5MyT-6ojb-cV;XQ1f?eJ)I zaKuf Date: Tue, 19 Nov 2024 20:22:12 +0800 Subject: [PATCH 7/8] mv memtracer to src --- CMakeLists.txt | 4 ++-- benchmark/CMakeLists.txt | 2 +- deps/CMakeLists.txt | 4 ---- src/CMakeLists.txt | 5 ++++- src/common/CMakeLists.txt | 2 +- {deps => src}/memtracer/CMakeLists.txt | 0 {deps => src}/memtracer/allocator.cpp | 0 {deps => src}/memtracer/allocator.h | 0 {deps => src}/memtracer/common.cpp | 0 {deps => src}/memtracer/common.h | 0 {deps => src}/memtracer/memtracer.cpp | 0 {deps => src}/memtracer/memtracer.h | 0 {deps => src}/memtracer/mt_info.cpp | 0 {deps => src}/memtracer/mt_info.h | 0 src/observer/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 2 +- unittest/CMakeLists.txt | 2 -- 17 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 deps/CMakeLists.txt rename {deps => src}/memtracer/CMakeLists.txt (100%) rename {deps => src}/memtracer/allocator.cpp (100%) rename {deps => src}/memtracer/allocator.h (100%) rename {deps => src}/memtracer/common.cpp (100%) rename {deps => src}/memtracer/common.h (100%) rename {deps => src}/memtracer/memtracer.cpp (100%) rename {deps => src}/memtracer/memtracer.h (100%) rename {deps => src}/memtracer/mt_info.cpp (100%) rename {deps => src}/memtracer/mt_info.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b45484f2..8c9e138bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,7 @@ IF (EXISTS /usr/local/lib64) LINK_DIRECTORIES (/usr/local/lib64) ENDIF () -INCLUDE_DIRECTORIES(. ${PROJECT_SOURCE_DIR}/deps /usr/local/include) +INCLUDE_DIRECTORIES(. ${PROJECT_SOURCE_DIR}/deps ${PROJECT_SOURCE_DIR}/src /usr/local/include) IF(WITH_UNIT_TESTS) IF (ENABLE_COVERAGE) @@ -170,7 +170,7 @@ SET(CMAKE_C_FLAGS ${CMAKE_COMMON_FLAGS}) MESSAGE(STATUS "CMAKE_CXX_FLAGS is " ${CMAKE_CXX_FLAGS}) # ADD_SUBDIRECTORY(src bin) bin 为目标目录, 可以省略 -ADD_SUBDIRECTORY(deps) +# ADD_SUBDIRECTORY(deps) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(tools) diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index a0d67f3f8..415ccc080 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(benchmark CONFIG REQUIRED) -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/observer) +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/observer) FILE(GLOB_RECURSE ALL_SRC *.cpp) # AUX_SOURCE_DIRECTORY 类似功能 diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt deleted file mode 100644 index e700945b7..000000000 --- a/deps/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ - -if (WITH_MEMTRACER) - ADD_SUBDIRECTORY(memtracer) -endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0fe77a35..22e716786 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,7 @@ -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(observer) ADD_SUBDIRECTORY(obclient) + +if (WITH_MEMTRACER) + ADD_SUBDIRECTORY(memtracer) +endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 1d93efd55..62c1e2b84 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,4 +1,4 @@ -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) FILE(GLOB_RECURSE ALL_SRC *.cpp) diff --git a/deps/memtracer/CMakeLists.txt b/src/memtracer/CMakeLists.txt similarity index 100% rename from deps/memtracer/CMakeLists.txt rename to src/memtracer/CMakeLists.txt diff --git a/deps/memtracer/allocator.cpp b/src/memtracer/allocator.cpp similarity index 100% rename from deps/memtracer/allocator.cpp rename to src/memtracer/allocator.cpp diff --git a/deps/memtracer/allocator.h b/src/memtracer/allocator.h similarity index 100% rename from deps/memtracer/allocator.h rename to src/memtracer/allocator.h diff --git a/deps/memtracer/common.cpp b/src/memtracer/common.cpp similarity index 100% rename from deps/memtracer/common.cpp rename to src/memtracer/common.cpp diff --git a/deps/memtracer/common.h b/src/memtracer/common.h similarity index 100% rename from deps/memtracer/common.h rename to src/memtracer/common.h diff --git a/deps/memtracer/memtracer.cpp b/src/memtracer/memtracer.cpp similarity index 100% rename from deps/memtracer/memtracer.cpp rename to src/memtracer/memtracer.cpp diff --git a/deps/memtracer/memtracer.h b/src/memtracer/memtracer.h similarity index 100% rename from deps/memtracer/memtracer.h rename to src/memtracer/memtracer.h diff --git a/deps/memtracer/mt_info.cpp b/src/memtracer/mt_info.cpp similarity index 100% rename from deps/memtracer/mt_info.cpp rename to src/memtracer/mt_info.cpp diff --git a/deps/memtracer/mt_info.h b/src/memtracer/mt_info.h similarity index 100% rename from deps/memtracer/mt_info.h rename to src/memtracer/mt_info.h diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt index cb4b32e06..267344f87 100644 --- a/src/observer/CMakeLists.txt +++ b/src/observer/CMakeLists.txt @@ -1,6 +1,6 @@ MESSAGE(STATUS "This is CMAKE_CURRENT_SOURCE_DIR dir " ${CMAKE_CURRENT_SOURCE_DIR}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET (PARSER_WORKDIR ${CMAKE_CURRENT_SOURCE_DIR}/sql/parser) SET (PARSER_SOURCES ${PARSER_WORKDIR}/lex_sql.cpp ${PARSER_WORKDIR}/yacc_sql.cpp) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a9990c78b..d1fbdc5bc 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,6 +1,6 @@ ADD_EXECUTABLE(clog_dump clog_dump.cpp) TARGET_LINK_LIBRARIES(clog_dump observer_static) -TARGET_INCLUDE_DIRECTORIES(clog_dump PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/observer/) +TARGET_INCLUDE_DIRECTORIES(clog_dump PRIVATE ${PROJECT_SOURCE_DIR}/src/observer/) # Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制 # TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类 diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index a01e32787..a3eea7d43 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -5,8 +5,6 @@ find_package(GTest CONFIG REQUIRED) include(GoogleTest) -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src) - ADD_SUBDIRECTORY(common) IF (WITH_MEMTRACER) ADD_SUBDIRECTORY(memtracer) From 9f8ade3d420fc352a1ca4af7f6aeca81243154d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BF=90=E6=9D=A5?= Date: Tue, 19 Nov 2024 20:59:27 +0800 Subject: [PATCH 8/8] clang-format --- src/memtracer/allocator.cpp | 10 +++++----- src/memtracer/memtracer.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/memtracer/allocator.cpp b/src/memtracer/allocator.cpp index e83eccdb5..5eaecb991 100644 --- a/src/memtracer/allocator.cpp +++ b/src/memtracer/allocator.cpp @@ -46,7 +46,7 @@ mt_visible void *calloc(size_t nelem, size_t size) return calloc_buffer; } size_t alloc_size = nelem * size; - void * ptr = malloc(alloc_size); + void *ptr = malloc(alloc_size); if (ptr == NULL) [[unlikely]] { return NULL; } @@ -109,7 +109,7 @@ mt_visible int munmap(void *addr, size_t length) mt_visible char *strdup(const char *s) MT_THROW { size_t len = strlen(s); - char * p = (char *)malloc(len + 1); + char *p = (char *)malloc(len + 1); if (p == NULL) { return NULL; } @@ -120,9 +120,9 @@ mt_visible char *strdup(const char *s) MT_THROW mt_visible char *strndup(const char *s, size_t n) MT_THROW { - const char * end = (const char *)memchr(s, 0, n); + const char *end = (const char *)memchr(s, 0, n); const size_t m = (end != NULL ? (size_t)(end - s) : n); - char * t = (char *)malloc(m + 1); + char *t = (char *)malloc(m + 1); if (t == NULL) return NULL; memcpy(t, s, m); @@ -178,7 +178,7 @@ mt_visible long int syscall(long int __sysno, ...) exit(-1); } #elif defined(__MACH__) -mt_visible void *brk(const void *addr) +mt_visible void *brk(const void *addr) { MEMTRACER_LOG("brk not supported\n"); exit(-1); diff --git a/src/memtracer/memtracer.cpp b/src/memtracer/memtracer.cpp index 3e6810b5d..beafdfd83 100644 --- a/src/memtracer/memtracer.cpp +++ b/src/memtracer/memtracer.cpp @@ -61,7 +61,7 @@ void MemTracer::init() // init memory limit const char *memory_limit_str = std::getenv("MT_MEMORY_LIMIT"); if (memory_limit_str != nullptr) { - char * end; + char *end; unsigned long long value = std::strtoull(memory_limit_str, &end, 10); if (end != memory_limit_str && *end == '\0') { MT.set_memory_limit(static_cast(value)); @@ -73,7 +73,7 @@ void MemTracer::init() // init print_interval const char *print_interval_ms_str = std::getenv("MT_PRINT_INTERVAL_MS"); if (print_interval_ms_str != nullptr) { - char * end; + char *end; unsigned long long value = std::strtoull(print_interval_ms_str, &end, 10); if (end != print_interval_ms_str && *end == '\0') { MT.set_print_interval(static_cast(value)); @@ -148,7 +148,7 @@ void MemTracer::init_hook_funcs_impl() void MemTracer::stat() { const size_t print_interval_ms = MT.print_interval(); - const size_t sleep_interval = 100; // 100 ms + const size_t sleep_interval = 100; // 100 ms while (!MT.is_stop()) { if (REACH_TIME_INTERVAL(print_interval_ms)) { // TODO: optimize the output format