From eba8e273d37f8bae0d0d66403cdfd869fc82fd28 Mon Sep 17 00:00:00 2001 From: gaoriyao Date: Wed, 15 Jun 2022 12:14:24 +0800 Subject: [PATCH] feat(stonedb): formate code with clang-format (#7) --- storage/stonedb/async_tests/main.cc | 49 +- storage/stonedb/base/core/scollectd.h | 2 +- storage/stonedb/base/fmt/format.cpp | 38 +- storage/stonedb/base/fmt/format.h | 296 ++++--- storage/stonedb/base/fmt/ostream.h | 4 +- storage/stonedb/base/fmt/posix.cpp | 4 +- storage/stonedb/base/fmt/posix.h | 2 +- storage/stonedb/base/fmt/printf.h | 33 +- storage/stonedb/base/fmt/time.h | 2 +- storage/stonedb/base/net/posix_stack.cpp | 9 +- storage/stonedb/common/common_definitions.h | 49 +- storage/stonedb/common/compile_opts.h | 18 +- storage/stonedb/common/data_format.cpp | 2 +- storage/stonedb/common/data_format.h | 2 +- storage/stonedb/common/exception.cpp | 2 +- storage/stonedb/common/exception.h | 7 +- storage/stonedb/common/txt_data_format.cpp | 2 +- storage/stonedb/compress/arith_coder.cpp | 48 +- storage/stonedb/compress/arith_coder.h | 2 +- storage/stonedb/compress/basic_data_filt.cpp | 18 +- .../compress/bit_stream_compressor.cpp | 20 +- .../stonedb/compress/bit_stream_compressor.h | 2 +- storage/stonedb/compress/code_stream.h | 12 +- storage/stonedb/compress/defs.h | 4 +- storage/stonedb/compress/dictionary.cpp | 2 +- storage/stonedb/compress/inc_alloc.cpp | 2 +- storage/stonedb/compress/inc_alloc.h | 2 +- storage/stonedb/compress/inc_wgraph.cpp | 8 +- storage/stonedb/compress/lz4.cpp | 177 ++-- storage/stonedb/compress/lz4.h | 6 +- storage/stonedb/compress/num_compressor.h | 78 +- storage/stonedb/compress/part_dict.cpp | 6 +- storage/stonedb/compress/ppm.cpp | 56 +- storage/stonedb/compress/ppm.h | 4 +- storage/stonedb/compress/range_code.h | 8 +- storage/stonedb/compress/suffix_tree.cpp | 14 +- storage/stonedb/compress/text_compressor.cpp | 122 +-- storage/stonedb/compress/top_bit_dict.cpp | 18 +- storage/stonedb/compress/top_bit_dict.h | 6 +- storage/stonedb/compress/word_graph.cpp | 10 +- .../stonedb/core/aggregation_algorithm.cpp | 2 +- storage/stonedb/core/aggregator_advanced.cpp | 6 +- storage/stonedb/core/aggregator_basic.cpp | 6 +- storage/stonedb/core/bin_tools.cpp | 14 +- storage/stonedb/core/blocked_mem_table.cpp | 2 +- storage/stonedb/core/blocked_mem_table.h | 2 +- storage/stonedb/core/cached_buffer.cpp | 8 +- storage/stonedb/core/cached_buffer.h | 4 +- storage/stonedb/core/column_share.cpp | 10 +- storage/stonedb/core/column_type.h | 14 +- storage/stonedb/core/compilation_tools.cpp | 6 +- storage/stonedb/core/compiled_query.cpp | 216 ++--- storage/stonedb/core/compiled_query.h | 12 +- storage/stonedb/core/condition.cpp | 4 +- storage/stonedb/core/condition_encoder.cpp | 245 +++--- storage/stonedb/core/cq_term.h | 14 +- storage/stonedb/core/data_cache.h | 4 +- storage/stonedb/core/data_type.cpp | 22 +- storage/stonedb/core/data_type.h | 28 +- storage/stonedb/core/descriptor.cpp | 795 +++++++++--------- storage/stonedb/core/descriptor.h | 22 +- storage/stonedb/core/dimension_group.cpp | 6 +- storage/stonedb/core/dimension_group.h | 4 +- .../stonedb/core/dimension_group_multiple.cpp | 2 +- .../stonedb/core/dimension_group_virtual.cpp | 2 +- storage/stonedb/core/engine.cpp | 188 +++-- storage/stonedb/core/engine.h | 14 +- storage/stonedb/core/engine_execute.cpp | 18 +- storage/stonedb/core/engine_results.cpp | 6 +- storage/stonedb/core/filter.cpp | 4 +- storage/stonedb/core/filter.h | 4 +- storage/stonedb/core/ftree.cpp | 39 +- storage/stonedb/core/ftree.h | 2 +- storage/stonedb/core/group_distinct_cache.cpp | 6 +- storage/stonedb/core/group_distinct_cache.h | 2 +- storage/stonedb/core/group_distinct_table.cpp | 20 +- storage/stonedb/core/group_distinct_table.h | 10 +- storage/stonedb/core/group_table.cpp | 52 +- storage/stonedb/core/group_table.h | 8 +- storage/stonedb/core/groupby_wrapper.cpp | 108 +-- storage/stonedb/core/groupby_wrapper.h | 4 +- storage/stonedb/core/hash_table.cpp | 2 +- storage/stonedb/core/hash_table.h | 2 +- storage/stonedb/core/index_table.cpp | 14 +- storage/stonedb/core/index_table.h | 2 +- storage/stonedb/core/item_sdbfield.cpp | 18 +- storage/stonedb/core/item_sdbfield.h | 6 +- storage/stonedb/core/joiner.cpp | 31 +- storage/stonedb/core/joiner.h | 11 +- storage/stonedb/core/joiner_general.cpp | 4 +- storage/stonedb/core/joiner_hash.cpp | 22 +- storage/stonedb/core/joiner_hash_table.cpp | 2 +- storage/stonedb/core/joiner_hash_table.h | 2 +- storage/stonedb/core/joiner_mapped.cpp | 16 +- storage/stonedb/core/joiner_sort.cpp | 18 +- storage/stonedb/core/joiner_sort.h | 2 +- storage/stonedb/core/mi_iterator.cpp | 16 +- storage/stonedb/core/mi_iterator.h | 8 +- storage/stonedb/core/mi_new_contents.cpp | 28 +- storage/stonedb/core/mi_new_contents.h | 4 +- storage/stonedb/core/multi_index.cpp | 8 +- storage/stonedb/core/mysql_expression.cpp | 32 +- storage/stonedb/core/mysql_expression.h | 16 +- storage/stonedb/core/pack.h | 2 +- storage/stonedb/core/pack_int.cpp | 68 +- storage/stonedb/core/pack_orderer.cpp | 72 +- storage/stonedb/core/pack_orderer.h | 6 +- storage/stonedb/core/pack_str.cpp | 105 +-- storage/stonedb/core/pack_str.h | 8 +- storage/stonedb/core/parallel_hash_join.cpp | 28 +- storage/stonedb/core/parameterized_filter.cpp | 144 ++-- storage/stonedb/core/parameterized_filter.h | 2 +- storage/stonedb/core/physical_column.h | 7 +- storage/stonedb/core/proxy_hash_joiner.cpp | 16 +- storage/stonedb/core/query.cpp | 429 +++++----- storage/stonedb/core/query.h | 2 +- storage/stonedb/core/query_compile.cpp | 47 +- storage/stonedb/core/query_operator.h | 2 +- storage/stonedb/core/rc_attr.cpp | 8 +- storage/stonedb/core/rc_attr.h | 4 +- storage/stonedb/core/rc_attr_typeinfo.h | 12 +- storage/stonedb/core/rc_mem_table.cpp | 15 +- storage/stonedb/core/rc_mem_table.h | 2 +- storage/stonedb/core/rc_table.cpp | 48 +- storage/stonedb/core/rcattr_exeq_rs.cpp | 369 ++++---- storage/stonedb/core/rcattr_exqp.cpp | 176 ++-- storage/stonedb/core/rough_multi_index.cpp | 43 +- storage/stonedb/core/rough_multi_index.h | 6 +- storage/stonedb/core/rsi_bloom.cpp | 15 +- storage/stonedb/core/rsi_cmap.cpp | 22 +- storage/stonedb/core/rsi_cmap.h | 6 +- storage/stonedb/core/rsi_histogram.cpp | 46 +- storage/stonedb/core/rsi_histogram.h | 6 +- storage/stonedb/core/rsi_index.h | 2 +- storage/stonedb/core/sorter3.cpp | 26 +- storage/stonedb/core/sorter3.h | 2 +- storage/stonedb/core/sorter_wrapper.cpp | 9 +- storage/stonedb/core/table_share.cpp | 6 +- storage/stonedb/core/temp_table.cpp | 24 +- storage/stonedb/core/temp_table.h | 6 +- storage/stonedb/core/temp_table_com.cpp | 4 +- storage/stonedb/core/temp_table_low.cpp | 17 +- .../stonedb/core/temp_table_roughquery.cpp | 49 +- storage/stonedb/core/transaction.cpp | 4 +- .../stonedb/core/value_matching_hashtable.h | 2 +- storage/stonedb/core/value_matching_table.cpp | 4 +- storage/stonedb/core/value_matching_table.h | 2 +- storage/stonedb/core/value_or_null.h | 2 +- storage/stonedb/handler/ha_rcengine.cpp | 34 +- storage/stonedb/handler/ha_rcengine.h | 4 +- storage/stonedb/handler/stonedb_handler.cpp | 125 +-- .../stonedb/handler/stonedb_handler_com.cpp | 146 ++-- storage/stonedb/index/kv_store.cpp | 24 +- storage/stonedb/index/kv_store.h | 4 +- storage/stonedb/index/rc_table_index.cpp | 31 +- storage/stonedb/index/rdb_meta_manager.cpp | 146 ++-- storage/stonedb/index/rdb_meta_manager.h | 16 +- storage/stonedb/index/rdb_utils.h | 2 +- storage/stonedb/loader/load_parser.cpp | 16 +- storage/stonedb/loader/parsing_strategy.cpp | 30 +- storage/stonedb/loader/parsing_strategy.h | 5 +- storage/stonedb/loader/read_buffer.cpp | 181 ++-- storage/stonedb/loader/read_buffer.h | 49 +- storage/stonedb/loader/rejecter.cpp | 8 +- storage/stonedb/mm/heap_policy.h | 4 +- storage/stonedb/mm/huge_heap_policy.cpp | 8 +- storage/stonedb/mm/initializer.h | 2 +- storage/stonedb/mm/memory_block.h | 2 +- storage/stonedb/mm/memory_handling_policy.cpp | 65 +- storage/stonedb/mm/mysql_heap_policy.h | 2 +- storage/stonedb/mm/numa_heap_policy.h | 2 +- storage/stonedb/mm/reference_object.h | 2 +- storage/stonedb/mm/release2q.cpp | 2 +- storage/stonedb/mm/sys_heap_policy.h | 2 +- storage/stonedb/mm/tcm/page_heap.cpp | 32 +- storage/stonedb/mm/tcm/page_heap.h | 4 +- storage/stonedb/mm/tcm/span.h | 2 +- storage/stonedb/mm/tcm_heap_policy.h | 2 +- storage/stonedb/mm/traceable_object.cpp | 28 +- storage/stonedb/mm/traceable_object.h | 4 +- storage/stonedb/system/fet.h | 14 +- storage/stonedb/system/file_system.cpp | 13 +- storage/stonedb/system/io_parameters.h | 22 +- storage/stonedb/system/large_buffer.cpp | 8 +- storage/stonedb/system/large_buffer.h | 2 +- storage/stonedb/system/net_stream.cpp | 3 +- storage/stonedb/types/bstring.cpp | 16 +- storage/stonedb/types/rc_data_types.cpp | 23 +- storage/stonedb/types/rc_data_types.h | 20 +- storage/stonedb/types/rc_datetime.cpp | 28 +- storage/stonedb/types/rc_num.cpp | 38 +- storage/stonedb/types/rc_num.h | 2 +- storage/stonedb/types/rc_value_object.cpp | 5 +- storage/stonedb/types/value_parser4txt.cpp | 12 +- storage/stonedb/types/value_parser4txt.h | 2 +- storage/stonedb/util/log_ctl.cpp | 16 +- storage/stonedb/util/log_ctl.h | 2 +- storage/stonedb/util/mapped_circular_buffer.h | 8 +- storage/stonedb/util/qsort.h | 2 +- storage/stonedb/util/thread_pool.h | 4 +- storage/stonedb/util/timer.cpp | 2 +- storage/stonedb/util/timer.h | 2 +- storage/stonedb/vc/const_column.cpp | 8 +- storage/stonedb/vc/const_expr_column.cpp | 2 +- storage/stonedb/vc/expr_column.cpp | 2 +- storage/stonedb/vc/in_set_column.cpp | 2 +- storage/stonedb/vc/single_column.cpp | 4 +- storage/stonedb/vc/single_column.h | 8 +- storage/stonedb/vc/subselect_column.cpp | 2 +- storage/stonedb/vc/subselect_column.h | 3 +- storage/stonedb/vc/type_cast_column.cpp | 18 +- storage/stonedb/vc/virtual_column_base.cpp | 163 ++-- storage/stonedb/vc/virtual_column_base.h | 6 +- 213 files changed, 3447 insertions(+), 3219 deletions(-) diff --git a/storage/stonedb/async_tests/main.cc b/storage/stonedb/async_tests/main.cc index 5ac2c4965..629e41729 100644 --- a/storage/stonedb/async_tests/main.cc +++ b/storage/stonedb/async_tests/main.cc @@ -26,8 +26,7 @@ class TaskRunner { ~MyTask() noexcept override {} void run() noexcept override { - stonedb::base::print("Established task on cpu %3d\n", - stonedb::base::engine().cpu_id()); + stonedb::base::print("Established task on cpu %3d\n", stonedb::base::engine().cpu_id()); for (int index = 0; index < _count; ++index) { for (int jndex = 0; jndex < index; ++jndex) { *_result += jndex; @@ -48,8 +47,7 @@ class TaskRunner { stonedb::base::future<> Run() { return stonedb::base::sleep(std::chrono::milliseconds(1)).then([this]() { - stonedb::base::print("Established task on cpu %3d\n", - stonedb::base::engine().cpu_id()); + stonedb::base::print("Established task on cpu %3d\n", stonedb::base::engine().cpu_id()); uint64_t count = 0; for (int index = 0; index < _count; ++index) { for (int jndex = 0; jndex < index; ++jndex) { @@ -63,8 +61,7 @@ class TaskRunner { } stonedb::base::future get_result() { - stonedb::base::print("Requests on cpu %2d: %ld\n", - stonedb::base::engine().cpu_id(), _result); + stonedb::base::print("Requests on cpu %2d: %ld\n", stonedb::base::engine().cpu_id(), _result); return stonedb::base::make_ready_future(_result); } @@ -96,21 +93,18 @@ stonedb::base::future RecurseFuture(int *count) { // return sleep(1ms).then([count]{ return RecurseFuture(count); }); } -stonedb::base::future> Recurse( - std::shared_ptr counter, unsigned thd) { +stonedb::base::future> Recurse(std::shared_ptr counter, unsigned thd) { if (*counter == 0) { return stonedb::base::make_ready_future>(true); } int count = (*counter)--; - return stonedb::base::smp::submit_to( - thd, - [count, thd] { - // std::this_thread::sleep_for(1000ms); - stonedb::base::print("Calling on : %d thread counter: %d\n", thd, - count); - test_pool(50000, false); - }) + return stonedb::base::smp::submit_to(thd, + [count, thd] { + // std::this_thread::sleep_for(1000ms); + stonedb::base::print("Calling on : %d thread counter: %d\n", thd, count); + test_pool(50000, false); + }) .then([thd]() { stonedb::base::print("Called completed on : %d thread \n", thd); return stdexp::optional(stdexp::nullopt); @@ -119,8 +113,7 @@ stonedb::base::future> Recurse( void TestPostTask(std::shared_ptr task_executor) { std::chrono::duration total_elapsed = - stonedb::base::steady_clock_type::now() - - stonedb::base::steady_clock_type::now(); + stonedb::base::steady_clock_type::now() - stonedb::base::steady_clock_type::now(); std::chrono::duration max_elapsed = total_elapsed; for (int index = 0; index < 100000; ++index) { auto started = stonedb::base::steady_clock_type::now(); @@ -136,22 +129,19 @@ void TestPostTask(std::shared_ptr task_executor) { auto ave_secs = static_cast(total_elapsed.count() / 100000.0); auto max_secs = static_cast(max_elapsed.count()); - stonedb::base::print("Ave post task time: %fs max post time:%fs\n", ave_secs, - max_secs); + stonedb::base::print("Ave post task time: %fs max post time:%fs\n", ave_secs, max_secs); } void TestSubmit(std::shared_ptr task_executor) { auto ready_future = task_executor->Execute([]() { std::shared_ptr counter(new int(10)); - stonedb::base::future<> parallel_future = stonedb::base::parallel_for_each( - boost::irange(0, stonedb::base::smp::count), - [counter](unsigned c) { - return stonedb::base::repeat_until_value( - std::bind(&Recurse, counter, c)) - .then([](bool) { stonedb::base::print("Repeat completed\n"); }); + stonedb::base::future<> parallel_future = + stonedb::base::parallel_for_each(boost::irange(0, stonedb::base::smp::count), [counter](unsigned c) { + return stonedb::base::repeat_until_value(std::bind(&Recurse, counter, c)).then([](bool) { + stonedb::base::print("Repeat completed\n"); + }); }); - return parallel_future.then( - []() { stonedb::base::print("Parallel completed\n"); }); + return parallel_future.then([]() { stonedb::base::print("Parallel completed\n"); }); }); ready_future.wait(); @@ -176,8 +166,7 @@ void TestSubmitRandom(std::shared_ptr task_executor) { int main(int argc, char **argv) { auto started = stonedb::base::steady_clock_type::now(); std::shared_ptr task_executor(new core::TaskExecutor); - std::future ready_future = - task_executor->Init(std::thread::hardware_concurrency()); + std::future ready_future = task_executor->Init(std::thread::hardware_concurrency()); ready_future.wait(); auto elapsed = stonedb::base::steady_clock_type::now() - started; auto secs = static_cast(elapsed.count() / 1000000000.0); diff --git a/storage/stonedb/base/core/scollectd.h b/storage/stonedb/base/core/scollectd.h index b09ec836d..05f6fc3b3 100644 --- a/storage/stonedb/base/core/scollectd.h +++ b/storage/stonedb/base/core/scollectd.h @@ -682,7 +682,7 @@ class values_impl : public value_list { void add_polled(const type_instance_id &, const shared_ptr &, bool enabled = true); -using notify_function = std::function ; +using notify_function = std::function; template static auto make_type_instance(description d, _Args &&...args) -> values_impl(std::forward<_Args>(args)))...> { diff --git a/storage/stonedb/base/fmt/format.cpp b/storage/stonedb/base/fmt/format.cpp index b8a60412c..9ce1602f0 100644 --- a/storage/stonedb/base/fmt/format.cpp +++ b/storage/stonedb/base/fmt/format.cpp @@ -175,7 +175,7 @@ int safe_strerror(int error_code, char *&buffer, std::size_t buffer_size) FMT_NO void format_error_code(Writer &out, int error_code, StringRef message) FMT_NOEXCEPT { // Report error code making sure that the output fits into - // INLINE_BUFFER_SIZE to avoid dynamic memory allocation and potential + // enumInlineBuffer::INLINE_BUFFER_SIZE to avoid dynamic memory allocation and potential // bad_alloc. out.clear(); static const char SEP[] = ": "; @@ -189,9 +189,10 @@ void format_error_code(Writer &out, int error_code, StringRef message) FMT_NOEXC ++error_code_size; } error_code_size += internal::count_digits(abs_value); - if (message.size() <= internal::INLINE_BUFFER_SIZE - error_code_size) out << message << SEP; + if (message.size() <= static_cast(internal::enumInlineBuffer::INLINE_BUFFER_SIZE) - error_code_size) + out << message << SEP; out << ERROR_STR << error_code; - assert(out.size() <= internal::INLINE_BUFFER_SIZE); + assert(out.size() <= static_cast(internal::enumInlineBuffer::INLINE_BUFFER_SIZE)); } void report_error(FormatFunc func, int error_code, StringRef message) FMT_NOEXCEPT { @@ -314,8 +315,8 @@ FMT_FUNC void WindowsError::init(int err_code, CStringRef format_str, ArgList ar FMT_FUNC void internal::format_windows_error(Writer &out, int error_code, StringRef message) FMT_NOEXCEPT { FMT_TRY { - MemoryBuffer buffer; - buffer.resize(INLINE_BUFFER_SIZE); + MemoryBuffer buffer; + buffer.resize(enumInlineBuffer::INLINE_BUFFER_SIZE); for (;;) { wchar_t *system_message = &buffer[0]; int result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FMT_NULL, error_code, @@ -341,8 +342,8 @@ FMT_FUNC void internal::format_windows_error(Writer &out, int error_code, String FMT_FUNC void format_system_error(Writer &out, int error_code, StringRef message) FMT_NOEXCEPT { FMT_TRY { - internal::MemoryBuffer buffer; - buffer.resize(internal::INLINE_BUFFER_SIZE); + internal::MemoryBuffer(internal::enumInlineBuffer::INLINE_BUFFER_SIZE)> buffer; + buffer.resize(static_cast(internal::enumInlineBuffer::INLINE_BUFFER_SIZE)); for (;;) { char *system_message = &buffer[0]; int result = safe_strerror(error_code, system_message, buffer.size()); @@ -363,14 +364,15 @@ void internal::ArgMap::init(const ArgList &args) { if (!map_.empty()) return; using NamedArg = internal::NamedArg; const NamedArg *named_arg = FMT_NULL; - bool use_values = args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE; + bool use_values = + args.type(static_cast(ArgList::enumMaxPacked::MAX_PACKED_ARGS) - 1) == internal::Arg::Type::NONE; if (use_values) { for (unsigned i = 0; /*nothing*/; ++i) { internal::Arg::Type arg_type = args.type(i); switch (arg_type) { - case internal::Arg::NONE: + case internal::Arg::Type::NONE: return; - case internal::Arg::NAMED_ARG: + case internal::Arg::Type::NAMED_ARG: named_arg = static_cast(args.values_[i].pointer); map_.push_back(Pair(named_arg->name, *named_arg)); break; @@ -380,18 +382,18 @@ void internal::ArgMap::init(const ArgList &args) { } return; } - for (unsigned i = 0; i != ArgList::MAX_PACKED_ARGS; ++i) { + for (unsigned i = 0; i != static_cast(ArgList::enumMaxPacked::MAX_PACKED_ARGS); ++i) { internal::Arg::Type arg_type = args.type(i); - if (arg_type == internal::Arg::NAMED_ARG) { + if (arg_type == internal::Arg::Type::NAMED_ARG) { named_arg = static_cast(args.args_[i].pointer); map_.push_back(Pair(named_arg->name, *named_arg)); } } - for (unsigned i = ArgList::MAX_PACKED_ARGS; /*nothing*/; ++i) { + for (unsigned i = static_cast(ArgList::enumMaxPacked::MAX_PACKED_ARGS); /*nothing*/; ++i) { switch (args.args_[i].type) { - case internal::Arg::NONE: + case internal::Arg::Type::NONE: return; - case internal::Arg::NAMED_ARG: + case internal::Arg::Type::NAMED_ARG: named_arg = static_cast(args.args_[i].pointer); map_.push_back(Pair(named_arg->name, *named_arg)); break; @@ -409,10 +411,10 @@ void internal::FixedBuffer::grow(std::size_t) { FMT_FUNC internal::Arg internal::FormatterBase::do_get_arg(unsigned arg_index, const char *&error) { internal::Arg arg = args_[arg_index]; switch (arg.type) { - case internal::Arg::NONE: + case internal::Arg::Type::NONE: error = "argument index out of range"; break; - case internal::Arg::NAMED_ARG: + case internal::Arg::Type::NAMED_ARG: arg = *static_cast(arg.pointer); break; default: @@ -443,7 +445,7 @@ FMT_FUNC void print(CStringRef format_str, ArgList args) { print(stdout, format_ FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { char escape[] = "\x1b[30m"; - escape[3] = static_cast('0' + c); + escape[3] = static_cast('0' + static_cast(c)); std::fputs(escape, stdout); print(format, args); std::fputs(RESET_COLOR, stdout); diff --git a/storage/stonedb/base/fmt/format.h b/storage/stonedb/base/fmt/format.h index 7311477ba..b813b16ce 100644 --- a/storage/stonedb/base/fmt/format.h +++ b/storage/stonedb/base/fmt/format.h @@ -625,7 +625,7 @@ inline typename MakeUnsigned::Type to_unsigned(Int value) { // The number of characters to store in the MemoryBuffer object itself // to avoid dynamic memory allocation. -enum { INLINE_BUFFER_SIZE = 500 }; +enum class enumInlineBuffer { INLINE_BUFFER_SIZE = 500 }; #if FMT_SECURE_SCL // Use checked iterator to avoid warnings on MSVC. @@ -802,7 +802,7 @@ template class BasicCharTraits { public: #if FMT_SECURE_SCL - using CharPtr = stdext::checked_array_iterator ; + using CharPtr = stdext::checked_array_iterator; #else typedef Char *CharPtr; #endif @@ -892,7 +892,7 @@ template struct IntTraits { // Smallest of uint32_t and uint64_t that is large enough to represent // all values of T. - using MainType = typename TypeSelector::digits <= 32>::Type ; + using MainType = typename TypeSelector::digits <= 32>::Type; }; FMT_API void report_unknown_type(char code, const char *type); @@ -1018,7 +1018,7 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { // It is only provided for Windows since other systems support UTF-8 natively. class UTF8ToUTF16 { private: - MemoryBuffer buffer_; + MemoryBuffer(enumInlineBuffer::INLINE_BUFFER_SIZE)> buffer_; public: FMT_API explicit UTF8ToUTF16(StringRef s); @@ -1032,7 +1032,7 @@ class UTF8ToUTF16 { // It is only provided for Windows since other systems support UTF-8 natively. class UTF16ToUTF8 { private: - MemoryBuffer buffer_; + MemoryBuffer(enumInlineBuffer::INLINE_BUFFER_SIZE)> buffer_; public: UTF16ToUTF8() {} @@ -1080,7 +1080,7 @@ struct Value { CustomValue custom; }; - enum Type { + enum class Type { NONE, NAMED_ARG, // Integer types should go first, @@ -1304,15 +1304,15 @@ class MakeValue : public Arg { #define FMT_MAKE_VALUE_(Type, field, TYPE, rhs) \ MakeValue(Type value) { field = rhs; } \ - static uint64_t type(Type) { return Arg::TYPE; } + static uint64_t type(Type) { return static_cast(TYPE); } #define FMT_MAKE_VALUE(Type, field, TYPE) FMT_MAKE_VALUE_(Type, field, TYPE, value) - FMT_MAKE_VALUE(bool, int_value, BOOL) - FMT_MAKE_VALUE(short, int_value, INT) - FMT_MAKE_VALUE(unsigned short, uint_value, UINT) - FMT_MAKE_VALUE(int, int_value, INT) - FMT_MAKE_VALUE(unsigned, uint_value, UINT) + FMT_MAKE_VALUE(bool, int_value, Arg::Type::BOOL) + FMT_MAKE_VALUE(short, int_value, Arg::Type::INT) + FMT_MAKE_VALUE(unsigned short, uint_value, Arg::Type::UINT) + FMT_MAKE_VALUE(int, int_value, Arg::Type::INT) + FMT_MAKE_VALUE(unsigned, uint_value, Arg::Type::UINT) MakeValue(long value) { // To minimize the number of types we need to deal with, long is @@ -1322,7 +1322,10 @@ class MakeValue : public Arg { else long_long_value = value; } - static uint64_t type(long) { return sizeof(long) == sizeof(int) ? Arg::INT : Arg::LONG_LONG; } + static uint64_t type(long) { + return sizeof(long) == sizeof(int) ? static_cast(Arg::Type::INT) + : static_cast(Arg::Type::LONG_LONG); + } MakeValue(unsigned long value) { if (const_check(sizeof(unsigned long) == sizeof(unsigned))) @@ -1331,48 +1334,52 @@ class MakeValue : public Arg { ulong_long_value = value; } static uint64_t type(unsigned long) { - return sizeof(unsigned long) == sizeof(unsigned) ? Arg::UINT : Arg::ULONG_LONG; + return sizeof(unsigned long) == sizeof(unsigned) ? static_cast(Arg::Type::UINT) + : static_cast(Arg::Type::ULONG_LONG); } - FMT_MAKE_VALUE(LongLong, long_long_value, LONG_LONG) - FMT_MAKE_VALUE(ULongLong, ulong_long_value, ULONG_LONG) - FMT_MAKE_VALUE(float, double_value, DOUBLE) - FMT_MAKE_VALUE(double, double_value, DOUBLE) - FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE) - FMT_MAKE_VALUE(signed char, int_value, INT) - FMT_MAKE_VALUE(unsigned char, uint_value, UINT) - FMT_MAKE_VALUE(char, int_value, CHAR) + FMT_MAKE_VALUE(LongLong, long_long_value, Arg::Type::LONG_LONG) + FMT_MAKE_VALUE(ULongLong, ulong_long_value, Arg::Type::ULONG_LONG) + FMT_MAKE_VALUE(float, double_value, Arg::Type::DOUBLE) + FMT_MAKE_VALUE(double, double_value, Arg::Type::DOUBLE) + FMT_MAKE_VALUE(long double, long_double_value, Arg::Type::LONG_DOUBLE) + FMT_MAKE_VALUE(signed char, int_value, Arg::Type::INT) + FMT_MAKE_VALUE(unsigned char, uint_value, Arg::Type::UINT) + FMT_MAKE_VALUE(char, int_value, Arg::Type::CHAR) #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) MakeValue(typename WCharHelper::Supported value) { int_value = value; } - static uint64_t type(wchar_t) { return Arg::CHAR; } + static uint64_t type(wchar_t) { return static_cast(Arg::Type::CHAR); + } #endif #define FMT_MAKE_STR_VALUE(Type, TYPE) \ MakeValue(Type value) { set_string(value); } \ - static uint64_t type(Type) { return Arg::TYPE; } - - FMT_MAKE_VALUE(char *, string.value, CSTRING) - FMT_MAKE_VALUE(const char *, string.value, CSTRING) - FMT_MAKE_VALUE(signed char *, sstring.value, CSTRING) - FMT_MAKE_VALUE(const signed char *, sstring.value, CSTRING) - FMT_MAKE_VALUE(unsigned char *, ustring.value, CSTRING) - FMT_MAKE_VALUE(const unsigned char *, ustring.value, CSTRING) - FMT_MAKE_STR_VALUE(const std::string &, STRING) - FMT_MAKE_STR_VALUE(StringRef, STRING) - FMT_MAKE_VALUE_(CStringRef, string.value, CSTRING, value.c_str()) + static uint64_t type(Type) { return static_cast(TYPE); \ + } + + FMT_MAKE_VALUE(char *, string.value, Arg::Type::CSTRING) + FMT_MAKE_VALUE(const char *, string.value, Arg::Type::CSTRING) + FMT_MAKE_VALUE(signed char *, sstring.value, Arg::Type::CSTRING) + FMT_MAKE_VALUE(const signed char *, sstring.value, Arg::Type::CSTRING) + FMT_MAKE_VALUE(unsigned char *, ustring.value, Arg::Type::CSTRING) + FMT_MAKE_VALUE(const unsigned char *, ustring.value, Arg::Type::CSTRING) + FMT_MAKE_STR_VALUE(const std::string &, Arg::Type::STRING) + FMT_MAKE_STR_VALUE(StringRef, Arg::Type::STRING) + FMT_MAKE_VALUE_(CStringRef, string.value, Arg::Type::CSTRING, value.c_str()) #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \ MakeValue(typename WCharHelper::Supported value) { set_string(value); } \ - static uint64_t type(Type) { return Arg::TYPE; } + static uint64_t type(Type) { return static_cast(TYPE); \ + } - FMT_MAKE_WSTR_VALUE(wchar_t *, WSTRING) - FMT_MAKE_WSTR_VALUE(const wchar_t *, WSTRING) - FMT_MAKE_WSTR_VALUE(const std::wstring &, WSTRING) - FMT_MAKE_WSTR_VALUE(WStringRef, WSTRING) + FMT_MAKE_WSTR_VALUE(wchar_t *, Arg::Type::WSTRING) + FMT_MAKE_WSTR_VALUE(const wchar_t *, Arg::Type::WSTRING) + FMT_MAKE_WSTR_VALUE(const std::wstring &, Arg::Type::WSTRING) + FMT_MAKE_WSTR_VALUE(WStringRef, Arg::Type::WSTRING) - FMT_MAKE_VALUE(void *, pointer, POINTER) - FMT_MAKE_VALUE(const void *, pointer, POINTER) + FMT_MAKE_VALUE(void *, pointer, Arg::Type::POINTER) + FMT_MAKE_VALUE(const void *, pointer, Arg::Type::POINTER) template MakeValue(const T &value, typename EnableIf::value>::value, int>::type = 0) { @@ -1382,7 +1389,7 @@ class MakeValue : public Arg { template static typename EnableIf::value>::value, uint64_t>::type type(const T &) { - return Arg::CUSTOM; + return static_cast(Arg::Type::CUSTOM); } // Additional template param `Char_` is needed here because make_type always @@ -1398,18 +1405,18 @@ class MakeValue : public Arg { template static uint64_t type(const NamedArg &) { - return Arg::NAMED_ARG; + return static_cast(Arg::Type::NAMED_ARG); } template static uint64_t type(const NamedArgWithType &) { - return Arg::NAMED_ARG; + return static_cast(Arg::Type::NAMED_ARG); } }; template class MakeArg : public Arg { public: - MakeArg() { type = Arg::NONE; } + MakeArg() { type = Arg::Type::NONE; } template MakeArg(const T &value) : Arg(MakeValue(value)) { @@ -1444,15 +1451,19 @@ class ArgMap; /** An argument list. */ class ArgList { private: - // To reduce compiled code size per formatting function call, types of first - // MAX_PACKED_ARGS arguments are passed in the types_ field. + /* + To reduce compiled code size per formatting function call, types of first + MAX_PACKED_ARGS arguments are passed in the types_ field. + */ uint64_t types_; union { - // If the number of arguments is less than MAX_PACKED_ARGS, the argument - // values are stored in values_, otherwise they are stored in args_. - // This is done to reduce compiled code size as storing larger objects - // may require more code (at least on x86-64) even if the same amount of - // data is actually copied to stack. It saves ~10% on the bloat test. + /* + If the number of arguments is less than MAX_PACKED_ARGS, the argument + values are stored in values_, otherwise they are stored in args_. + This is done to reduce compiled code size as storing larger objects + may require more code (at least on x86-64) even if the same amount of + data is actually copied to stack. It saves ~10% on the bloat test. + */ const internal::Value *values_; const internal::Arg *args_; }; @@ -1464,7 +1475,7 @@ class ArgList { public: // Maximum number of arguments with packed types. - enum { MAX_PACKED_ARGS = 16 }; + enum class enumMaxPacked { MAX_PACKED_ARGS = 16 }; ArgList() : types_(0) {} @@ -1477,22 +1488,22 @@ class ArgList { internal::Arg operator[](unsigned index) const { using internal::Arg; Arg arg; - bool use_values = type(MAX_PACKED_ARGS - 1) == Arg::NONE; - if (index < MAX_PACKED_ARGS) { + bool use_values = type(static_cast(enumMaxPacked::MAX_PACKED_ARGS) - 1) == Arg::Type::NONE; + if (index < static_cast(enumMaxPacked::MAX_PACKED_ARGS)) { Arg::Type arg_type = type(index); internal::Value &val = arg; - if (arg_type != Arg::NONE) val = use_values ? values_[index] : args_[index]; + if (arg_type != Arg::Type::NONE) val = use_values ? values_[index] : args_[index]; arg.type = arg_type; return arg; } if (use_values) { // The index is greater than the number of arguments that can be stored // in values, so return a "none" argument. - arg.type = Arg::NONE; + arg.type = Arg::Type::NONE; return arg; } - for (unsigned i = MAX_PACKED_ARGS; i <= index; ++i) { - if (args_[i].type == Arg::NONE) return args_[i]; + for (unsigned i = static_cast(enumMaxPacked::MAX_PACKED_ARGS); i <= index; ++i) { + if (args_[i].type == Arg::Type::NONE) return args_[i]; } return args_[index]; } @@ -1604,45 +1615,45 @@ class ArgVisitor { */ Result visit(const Arg &arg) { switch (arg.type) { - case Arg::NONE: - case Arg::NAMED_ARG: + case Arg::Type::NONE: + case Arg::Type::NAMED_ARG: FMT_ASSERT(false, "invalid argument type"); break; - case Arg::INT: + case Arg::Type::INT: return FMT_DISPATCH(visit_int(arg.int_value)); - case Arg::UINT: + case Arg::Type::UINT: return FMT_DISPATCH(visit_uint(arg.uint_value)); - case Arg::LONG_LONG: + case Arg::Type::LONG_LONG: return FMT_DISPATCH(visit_long_long(arg.long_long_value)); - case Arg::ULONG_LONG: + case Arg::Type::ULONG_LONG: return FMT_DISPATCH(visit_ulong_long(arg.ulong_long_value)); - case Arg::BOOL: + case Arg::Type::BOOL: return FMT_DISPATCH(visit_bool(arg.int_value != 0)); - case Arg::CHAR: + case Arg::Type::CHAR: return FMT_DISPATCH(visit_char(arg.int_value)); - case Arg::DOUBLE: + case Arg::Type::DOUBLE: return FMT_DISPATCH(visit_double(arg.double_value)); - case Arg::LONG_DOUBLE: + case Arg::Type::LONG_DOUBLE: return FMT_DISPATCH(visit_long_double(arg.long_double_value)); - case Arg::CSTRING: + case Arg::Type::CSTRING: return FMT_DISPATCH(visit_cstring(arg.string.value)); - case Arg::STRING: + case Arg::Type::STRING: return FMT_DISPATCH(visit_string(arg.string)); - case Arg::WSTRING: + case Arg::Type::WSTRING: return FMT_DISPATCH(visit_wstring(arg.wstring)); - case Arg::POINTER: + case Arg::Type::POINTER: return FMT_DISPATCH(visit_pointer(arg.pointer)); - case Arg::CUSTOM: + case Arg::Type::CUSTOM: return FMT_DISPATCH(visit_custom(arg.custom)); } return Result(); } }; -enum Alignment { ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC }; +enum class Alignment { ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC }; // Flags. -enum { +enum class enumFlags { SIGN_FLAG = 1, PLUS_FLAG = 2, MINUS_FLAG = 4, @@ -1656,7 +1667,7 @@ struct EmptySpec {}; // A type specifier. template struct TypeSpec : EmptySpec { - Alignment align() const { return ALIGN_DEFAULT; } + Alignment align() const { return Alignment::ALIGN_DEFAULT; } unsigned width() const { return 0; } int precision() const { return -1; } bool flag(unsigned) const { return false; } @@ -1682,7 +1693,8 @@ struct WidthSpec { struct AlignSpec : WidthSpec { Alignment align_; - AlignSpec(unsigned width, wchar_t fill, Alignment align = ALIGN_DEFAULT) : WidthSpec(width, fill), align_(align) {} + AlignSpec(unsigned width, wchar_t fill, Alignment align = Alignment::ALIGN_DEFAULT) + : WidthSpec(width, fill), align_(align) {} Alignment align() const { return align_; } @@ -1882,7 +1894,7 @@ class ArgFormatterBase : public ArgVisitor { FMT_DISALLOW_COPY_AND_ASSIGN(ArgFormatterBase); void write_pointer(const void *p) { - spec_.flags_ = HASH_FLAG; + spec_.flags_ = static_cast(enumFlags::HASH_FLAG); spec_.type_ = 'x'; writer_.write_int(reinterpret_cast(p), spec_); } @@ -1930,21 +1942,22 @@ class ArgFormatterBase : public ArgVisitor { void visit_char(int value) { if (spec_.type_ && spec_.type_ != 'c') { - spec_.flags_ |= CHAR_FLAG; + spec_.flags_ |= static_cast(enumFlags::CHAR_FLAG); writer_.write_int(value, spec_); return; } - if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0) FMT_THROW(FormatError("invalid format specifier for char")); + if (spec_.align_ == Alignment::ALIGN_NUMERIC || spec_.flags_ != 0) + FMT_THROW(FormatError("invalid format specifier for char")); using CharPtr = typename BasicWriter::CharPtr; Char fill = internal::CharTraits::cast(spec_.fill()); CharPtr out = CharPtr(); const unsigned CHAR_SIZE = 1; if (spec_.width_ > CHAR_SIZE) { out = writer_.grow_buffer(spec_.width_); - if (spec_.align_ == ALIGN_RIGHT) { + if (spec_.align_ == Alignment::ALIGN_RIGHT) { std::uninitialized_fill_n(out, spec_.width_ - CHAR_SIZE, fill); out += spec_.width_ - CHAR_SIZE; - } else if (spec_.align_ == ALIGN_CENTER) { + } else if (spec_.align_ == Alignment::ALIGN_CENTER) { out = writer_.fill_padding(out, spec_.width_, internal::const_check(CHAR_SIZE), fill); } else { std::uninitialized_fill_n(out + CHAR_SIZE, spec_.width_ - CHAR_SIZE, fill); @@ -2138,7 +2151,7 @@ inline uint64_t make_type(const T &arg) { return MakeValue>::type(arg); } -template +template (ArgList::enumMaxPacked::MAX_PACKED_ARGS))> struct ArgArray; template @@ -2161,7 +2174,7 @@ struct ArgArray { template struct ArgArray { - typedef Arg Type[N + 1]; // +1 for the list end Arg::NONE + typedef Arg Type[N + 1]; // +1 for the list end Arg::Type::NONE template static Arg make(const T &value) { @@ -2625,10 +2638,10 @@ typename BasicWriter::CharPtr BasicWriter::write_str(const StrChar * if (spec.width() > size) { out = grow_buffer(spec.width()); Char fill = internal::CharTraits::cast(spec.fill()); - if (spec.align() == ALIGN_RIGHT) { + if (spec.align() == Alignment::ALIGN_RIGHT) { std::uninitialized_fill_n(out, spec.width() - size, fill); out += spec.width() - size; - } else if (spec.align() == ALIGN_CENTER) { + } else if (spec.align() == Alignment::ALIGN_CENTER) { out = fill_padding(out, spec.width(), size, fill); } else { std::uninitialized_fill_n(out + size, spec.width() - size, fill); @@ -2683,16 +2696,16 @@ typename BasicWriter::CharPtr BasicWriter::prepare_int_buffer(unsign // is specified. if (prefix_size > 0 && prefix[prefix_size - 1] == '0') --prefix_size; unsigned number_size = prefix_size + internal::to_unsigned(spec.precision()); - AlignSpec subspec(number_size, '0', ALIGN_NUMERIC); + AlignSpec subspec(number_size, '0', Alignment::ALIGN_NUMERIC); if (number_size >= width) return prepare_int_buffer(num_digits, subspec, prefix, prefix_size); buffer_.reserve(width); unsigned fill_size = width - number_size; - if (align != ALIGN_LEFT) { + if (align != Alignment::ALIGN_LEFT) { CharPtr p = grow_buffer(fill_size); std::uninitialized_fill(p, p + fill_size, fill); } CharPtr result = prepare_int_buffer(num_digits, subspec, prefix, prefix_size); - if (align == ALIGN_LEFT) { + if (align == Alignment::ALIGN_LEFT) { CharPtr p = grow_buffer(fill_size); std::uninitialized_fill(p, p + fill_size, fill); } @@ -2706,16 +2719,16 @@ typename BasicWriter::CharPtr BasicWriter::prepare_int_buffer(unsign } CharPtr p = grow_buffer(width); CharPtr end = p + width; - if (align == ALIGN_LEFT) { + if (align == Alignment::ALIGN_LEFT) { std::uninitialized_copy(prefix, prefix + prefix_size, p); p += size; std::uninitialized_fill(p, end, fill); - } else if (align == ALIGN_CENTER) { + } else if (align == Alignment::ALIGN_CENTER) { p = fill_padding(p, width, size, fill); std::uninitialized_copy(prefix, prefix + prefix_size, p); p += size; } else { - if (align == ALIGN_NUMERIC) { + if (align == Alignment::ALIGN_NUMERIC) { if (prefix_size != 0) { p = std::uninitialized_copy(prefix, prefix + prefix_size, p); size -= prefix_size; @@ -2740,8 +2753,8 @@ void BasicWriter::write_int(T value, Spec spec) { prefix[0] = '-'; ++prefix_size; abs_value = 0 - abs_value; - } else if (spec.flag(SIGN_FLAG)) { - prefix[0] = spec.flag(PLUS_FLAG) ? '+' : ' '; + } else if (spec.flag(static_cast(enumFlags::SIGN_FLAG))) { + prefix[0] = spec.flag(static_cast(enumFlags::PLUS_FLAG)) ? '+' : ' '; ++prefix_size; } switch (spec.type()) { @@ -2755,7 +2768,7 @@ void BasicWriter::write_int(T value, Spec spec) { case 'x': case 'X': { UnsignedType n = abs_value; - if (spec.flag(HASH_FLAG)) { + if (spec.flag(static_cast(enumFlags::HASH_FLAG))) { prefix[prefix_size++] = '0'; prefix[prefix_size++] = spec.type_prefix(); } @@ -2774,7 +2787,7 @@ void BasicWriter::write_int(T value, Spec spec) { case 'b': case 'B': { UnsignedType n = abs_value; - if (spec.flag(HASH_FLAG)) { + if (spec.flag(static_cast(enumFlags::HASH_FLAG))) { prefix[prefix_size++] = '0'; prefix[prefix_size++] = spec.type_prefix(); } @@ -2791,7 +2804,7 @@ void BasicWriter::write_int(T value, Spec spec) { } case 'o': { UnsignedType n = abs_value; - if (spec.flag(HASH_FLAG)) prefix[prefix_size++] = '0'; + if (spec.flag(static_cast(enumFlags::HASH_FLAG))) prefix[prefix_size++] = '0'; unsigned num_digits = 0; do { ++num_digits; @@ -2815,7 +2828,8 @@ void BasicWriter::write_int(T value, Spec spec) { break; } default: - internal::report_unknown_type(spec.type(), spec.flag(CHAR_FLAG) ? "char" : "integer"); + internal::report_unknown_type(spec.type(), + spec.flag(static_cast(enumFlags::CHAR_FLAG)) ? "char" : "integer"); break; } } @@ -2857,8 +2871,8 @@ void BasicWriter::write_double(T value, const Spec &spec) { if (internal::FPUtil::isnegative(static_cast(value))) { sign = '-'; value = -value; - } else if (spec.flag(SIGN_FLAG)) { - sign = spec.flag(PLUS_FLAG) ? '+' : ' '; + } else if (spec.flag(static_cast(enumFlags::SIGN_FLAG))) { + sign = spec.flag(static_cast(enumFlags::PLUS_FLAG)) ? '+' : ' '; } if (internal::FPUtil::isnotanumber(value)) { @@ -2898,16 +2912,16 @@ void BasicWriter::write_double(T value, const Spec &spec) { } // Build format string. - enum { MAX_FORMAT_SIZE = 10 }; // longest format: %#-*.*Lg - Char format[MAX_FORMAT_SIZE]; + enum class enumMFS { MAX_FORMAT_SIZE = 10 }; // longest format: %#-*.*Lg + Char format[static_cast(enumMFS::MAX_FORMAT_SIZE)]; Char *format_ptr = format; *format_ptr++ = '%'; unsigned width_for_sprintf = width; - if (spec.flag(HASH_FLAG)) *format_ptr++ = '#'; - if (spec.align() == ALIGN_CENTER) { + if (spec.flag(static_cast(enumFlags::HASH_FLAG))) *format_ptr++ = '#'; + if (spec.align() == Alignment::ALIGN_CENTER) { width_for_sprintf = 0; } else { - if (spec.align() == ALIGN_LEFT) *format_ptr++ = '-'; + if (spec.align() == Alignment::ALIGN_LEFT) *format_ptr++ = '-'; if (width != 0) *format_ptr++ = '*'; } if (spec.precision() >= 0) { @@ -2948,7 +2962,7 @@ void BasicWriter::write_double(T value, const Spec &spec) { } } if (sign) { - if ((spec.align() != ALIGN_RIGHT && spec.align() != ALIGN_DEFAULT) || *start != ' ') { + if ((spec.align() != Alignment::ALIGN_RIGHT && spec.align() != Alignment::ALIGN_DEFAULT) || *start != ' ') { *(start - 1) = sign; sign = 0; } else { @@ -2956,7 +2970,7 @@ void BasicWriter::write_double(T value, const Spec &spec) { } ++n; } - if (spec.align() == ALIGN_CENTER && spec.width() > n) { + if (spec.align() == Alignment::ALIGN_CENTER && spec.width() > n) { width = spec.width(); CharPtr p = grow_buffer(width); std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char)); @@ -3007,7 +3021,7 @@ void BasicWriter::write_double(T value, const Spec &spec) { template > class BasicMemoryWriter : public BasicWriter { private: - internal::MemoryBuffer buffer_; + internal::MemoryBuffer(internal::enumInlineBuffer::INLINE_BUFFER_SIZE), Allocator> buffer_; public: explicit BasicMemoryWriter(const Allocator &alloc = Allocator()) : BasicWriter(buffer_), buffer_(alloc) {} @@ -3133,7 +3147,7 @@ FMT_API void report_windows_error(int error_code, StringRef message) FMT_NOEXCEP #endif -enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; +enum class Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; /** Formats a string and prints it to stdout using ANSI escape sequences @@ -3193,13 +3207,13 @@ class FormatInt { private: // Buffer should be large enough to hold all digits (digits10 + 1), // a sign and a null character. - enum { BUFFER_SIZE = std::numeric_limits::digits10 + 3 }; - mutable char buffer_[BUFFER_SIZE]; + enum class enumFiBs { BUFFER_SIZE = std::numeric_limits::digits10 + 3 }; + mutable char buffer_[static_cast(enumFiBs::BUFFER_SIZE)]; char *str_; // Formats value in reverse and returns the number of digits. char *format_decimal(ULongLong value) { - char *buffer_end = buffer_ + BUFFER_SIZE - 1; + char *buffer_end = buffer_ + static_cast(enumFiBs::BUFFER_SIZE) - 1; while (value >= 100) { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu @@ -3236,7 +3250,9 @@ class FormatInt { explicit FormatInt(ULongLong value) : str_(format_decimal(value)) {} /** Returns the number of characters written to the output buffer. */ - std::size_t size() const { return internal::to_unsigned(buffer_ - str_ + BUFFER_SIZE - 1); } + std::size_t size() const { + return internal::to_unsigned(buffer_ - str_ + static_cast(enumFiBs::BUFFER_SIZE) - 1); + } /** Returns a pointer to the output buffer content. No terminating null @@ -3249,7 +3265,7 @@ class FormatInt { character appended. */ const char *c_str() const { - buffer_[BUFFER_SIZE - 1] = '\0'; + buffer_[static_cast(enumFiBs::BUFFER_SIZE) - 1] = '\0'; return str_; } @@ -3472,7 +3488,7 @@ unsigned parse_nonnegative_int(const Char *&s) { } inline void require_numeric_argument(const Arg &arg, char spec) { - if (arg.type > Arg::LAST_NUMERIC_TYPE) { + if (arg.type > Arg::Type::LAST_NUMERIC_TYPE) { std::string message = fmt::format("format specifier '{}' requires numeric argument", spec); FMT_THROW(fmt::FormatError(message)); } @@ -3482,7 +3498,7 @@ template void check_sign(const Char *&s, const Arg &arg) { char sign = static_cast(*s); require_numeric_argument(arg, sign); - if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) { + if (arg.type == Arg::Type::UINT || arg.type == Arg::Type::ULONG_LONG) { FMT_THROW(FormatError(fmt::format("format specifier '{}' requires signed argument", sign))); } ++s; @@ -3530,7 +3546,7 @@ const Char *BasicFormatter::format(const Char *&format_str, const Char *s = format_str; typename ArgFormatter::SpecType spec; if (*s == ':') { - if (arg.type == Arg::CUSTOM) { + if (arg.type == Arg::Type::CUSTOM) { arg.custom.format(this, arg.custom.value, &s); return s; } @@ -3538,23 +3554,23 @@ const Char *BasicFormatter::format(const Char *&format_str, // Parse fill and alignment. if (Char c = *s) { const Char *p = s + 1; - spec.align_ = ALIGN_DEFAULT; + spec.align_ = Alignment::ALIGN_DEFAULT; do { switch (*p) { case '<': - spec.align_ = ALIGN_LEFT; + spec.align_ = Alignment::ALIGN_LEFT; break; case '>': - spec.align_ = ALIGN_RIGHT; + spec.align_ = Alignment::ALIGN_RIGHT; break; case '=': - spec.align_ = ALIGN_NUMERIC; + spec.align_ = Alignment::ALIGN_NUMERIC; break; case '^': - spec.align_ = ALIGN_CENTER; + spec.align_ = Alignment::ALIGN_CENTER; break; } - if (spec.align_ != ALIGN_DEFAULT) { + if (spec.align_ != Alignment::ALIGN_DEFAULT) { if (p != s) { if (c == '}') break; if (c == '{') FMT_THROW(FormatError("invalid fill character '{'")); @@ -3562,7 +3578,7 @@ const Char *BasicFormatter::format(const Char *&format_str, spec.fill_ = c; } else ++s; - if (spec.align_ == ALIGN_NUMERIC) require_numeric_argument(arg, '='); + if (spec.align_ == Alignment::ALIGN_NUMERIC) require_numeric_argument(arg, '='); break; } } while (--p >= s); @@ -3572,28 +3588,28 @@ const Char *BasicFormatter::format(const Char *&format_str, switch (*s) { case '+': check_sign(s, arg); - spec.flags_ |= SIGN_FLAG | PLUS_FLAG; + spec.flags_ |= static_cast(enumFlags::SIGN_FLAG) | static_cast(enumFlags::PLUS_FLAG); break; case '-': check_sign(s, arg); - spec.flags_ |= MINUS_FLAG; + spec.flags_ |= static_cast(enumFlags::MINUS_FLAG); break; case ' ': check_sign(s, arg); - spec.flags_ |= SIGN_FLAG; + spec.flags_ |= static_cast(enumFlags::SIGN_FLAG); break; } if (*s == '#') { require_numeric_argument(arg, '#'); - spec.flags_ |= HASH_FLAG; + spec.flags_ |= static_cast(enumFlags::HASH_FLAG); ++s; } // Parse zero flag. if (*s == '0') { require_numeric_argument(arg, '0'); - spec.align_ = ALIGN_NUMERIC; + spec.align_ = Alignment::ALIGN_NUMERIC; spec.fill_ = '0'; ++s; } @@ -3607,18 +3623,18 @@ const Char *BasicFormatter::format(const Char *&format_str, if (*s++ != '}') FMT_THROW(FormatError("invalid format string")); ULongLong value = 0; switch (width_arg.type) { - case Arg::INT: + case Arg::Type::INT: if (width_arg.int_value < 0) FMT_THROW(FormatError("negative width")); value = width_arg.int_value; break; - case Arg::UINT: + case Arg::Type::UINT: value = width_arg.uint_value; break; - case Arg::LONG_LONG: + case Arg::Type::LONG_LONG: if (width_arg.long_long_value < 0) FMT_THROW(FormatError("negative width")); value = width_arg.long_long_value; break; - case Arg::ULONG_LONG: + case Arg::Type::ULONG_LONG: value = width_arg.ulong_long_value; break; default: @@ -3640,18 +3656,18 @@ const Char *BasicFormatter::format(const Char *&format_str, if (*s++ != '}') FMT_THROW(FormatError("invalid format string")); ULongLong value = 0; switch (precision_arg.type) { - case Arg::INT: + case Arg::Type::INT: if (precision_arg.int_value < 0) FMT_THROW(FormatError("negative precision")); value = precision_arg.int_value; break; - case Arg::UINT: + case Arg::Type::UINT: value = precision_arg.uint_value; break; - case Arg::LONG_LONG: + case Arg::Type::LONG_LONG: if (precision_arg.long_long_value < 0) FMT_THROW(FormatError("negative precision")); value = precision_arg.long_long_value; break; - case Arg::ULONG_LONG: + case Arg::Type::ULONG_LONG: value = precision_arg.ulong_long_value; break; default: @@ -3662,9 +3678,9 @@ const Char *BasicFormatter::format(const Char *&format_str, } else { FMT_THROW(FormatError("missing precision specifier")); } - if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) { + if (arg.type <= Arg::Type::LAST_INTEGER_TYPE || arg.type == Arg::Type::POINTER) { FMT_THROW(FormatError(fmt::format("precision not allowed in {} format specifier", - arg.type == Arg::POINTER ? "pointer" : "integer"))); + arg.type == Arg::Type::POINTER ? "pointer" : "integer"))); } } diff --git a/storage/stonedb/base/fmt/ostream.h b/storage/stonedb/base/fmt/ostream.h index a04ecfe82..dff42829a 100644 --- a/storage/stonedb/base/fmt/ostream.h +++ b/storage/stonedb/base/fmt/ostream.h @@ -63,7 +63,7 @@ No &operator<<(std::ostream &, int); template struct ConvertToIntImpl { // Convert to int only if T doesn't have an overloaded operator<<. - enum { value = sizeof(convert(get() << get())) == sizeof(No) }; + enum class enumCtiiValue { value = sizeof(convert(get() << get())) == sizeof(No) }; }; // Write the content of w to os. @@ -73,7 +73,7 @@ FMT_API void write(std::ostream &os, Writer &w); // Formats a value. template void format_arg(BasicFormatter &f, const Char *&format_str, const T &value) { - internal::MemoryBuffer buffer; + internal::MemoryBuffer(internal::enumInlineBuffer::INLINE_BUFFER_SIZE)> buffer; internal::FormatBuf format_buf(buffer); std::basic_ostream output(&format_buf); diff --git a/storage/stonedb/base/fmt/posix.cpp b/storage/stonedb/base/fmt/posix.cpp index c5463e35d..bb5644071 100644 --- a/storage/stonedb/base/fmt/posix.cpp +++ b/storage/stonedb/base/fmt/posix.cpp @@ -191,8 +191,8 @@ void File::pipe(File &read_end, File &write_end) { int fds[2] = {}; #ifdef _WIN32 // Make the default pipe capacity same as on Linux 2.6.11+. - enum { DEFAULT_CAPACITY = 65536 }; - int result = FMT_POSIX_CALL(pipe(fds, DEFAULT_CAPACITY, _O_BINARY)); + enum class enumDC { DEFAULT_CAPACITY = 65536 }; + int result = FMT_POSIX_CALL(pipe(fds, enumDC::DEFAULT_CAPACITY, _O_BINARY)); #else // Don't retry as the pipe function doesn't return EINTR. // http://pubs.opengroup.org/onlinepubs/009696799/functions/pipe.html diff --git a/storage/stonedb/base/fmt/posix.h b/storage/stonedb/base/fmt/posix.h index 872f41a4e..2b9611a0d 100644 --- a/storage/stonedb/base/fmt/posix.h +++ b/storage/stonedb/base/fmt/posix.h @@ -183,7 +183,7 @@ class File { public: // Possible values for the oflag argument to the constructor. - enum { + enum class enumOpenFileType { RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only. WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only. RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing. diff --git a/storage/stonedb/base/fmt/printf.h b/storage/stonedb/base/fmt/printf.h index 555e87dfc..ef88ac9a9 100644 --- a/storage/stonedb/base/fmt/printf.h +++ b/storage/stonedb/base/fmt/printf.h @@ -129,22 +129,22 @@ class ArgConverter : public ArgVisitor, void> { if (sizeof(TargetType) <= sizeof(int)) { // Extra casts are used to silence warnings. if (is_signed) { - arg_.type = Arg::INT; + arg_.type = Arg::Type::INT; arg_.int_value = static_cast(static_cast(value)); } else { - arg_.type = Arg::UINT; + arg_.type = Arg::Type::UINT; using Unsigned = typename internal::MakeUnsigned::Type; arg_.uint_value = static_cast(static_cast(value)); } } else { if (is_signed) { - arg_.type = Arg::LONG_LONG; + arg_.type = Arg::Type::LONG_LONG; // glibc's printf doesn't sign extend arguments of smaller types: // std::printf("%lld", -42); // prints "4294967254" // but we don't have to do the same because it's a UB. arg_.long_long_value = static_cast(value); } else { - arg_.type = Arg::ULONG_LONG; + arg_.type = Arg::Type::ULONG_LONG; arg_.ulong_long_value = static_cast::Type>(value); } } @@ -163,7 +163,7 @@ class CharConverter : public ArgVisitor { template void visit_any_int(T value) { - arg_.type = internal::Arg::CHAR; + arg_.type = internal::Arg::Type::CHAR; arg_.int_value = static_cast(value); } }; @@ -186,7 +186,7 @@ class WidthHandler : public ArgVisitor { using UnsignedType = typename internal::IntTraits::MainType; UnsignedType width = static_cast(value); if (internal::is_negative(value)) { - spec_.align_ = ALIGN_LEFT; + spec_.align_ = Alignment::ALIGN_LEFT; width = 0 - width; } unsigned int_max = std::numeric_limits::max(); @@ -251,7 +251,7 @@ class BasicPrintfArgFormatter : public internal::ArgFormatterBase 1) { Char fill = ' '; out = w.grow_buffer(fmt_spec.width_); - if (fmt_spec.align_ != ALIGN_LEFT) { + if (fmt_spec.align_ != Alignment::ALIGN_LEFT) { std::fill_n(out, fmt_spec.width_ - 1, fill); out += fmt_spec.width_ - 1; } else { @@ -332,19 +332,19 @@ void PrintfFormatter::parse_flags(FormatSpec &spec, const Char *&s) { for (;;) { switch (*s++) { case '-': - spec.align_ = ALIGN_LEFT; + spec.align_ = Alignment::ALIGN_LEFT; break; case '+': - spec.flags_ |= SIGN_FLAG | PLUS_FLAG; + spec.flags_ |= static_cast(enumFlags::SIGN_FLAG) | static_cast(enumFlags::PLUS_FLAG); break; case '0': spec.fill_ = '0'; break; case ' ': - spec.flags_ |= SIGN_FLAG; + spec.flags_ |= static_cast(enumFlags::SIGN_FLAG); break; case '#': - spec.flags_ |= HASH_FLAG; + spec.flags_ |= static_cast(enumFlags::HASH_FLAG); break; default: --s; @@ -410,7 +410,7 @@ void PrintfFormatter::format(BasicCStringRef format_str) { write(writer_, start, s - 1); FormatSpec spec; - spec.align_ = ALIGN_RIGHT; + spec.align_ = Alignment::ALIGN_RIGHT; // Parse argument index, flags and width. unsigned arg_index = parse_header(s, spec); @@ -430,10 +430,11 @@ void PrintfFormatter::format(BasicCStringRef format_str) { using internal::Arg; Arg arg = get_arg(s, arg_index); - if (spec.flag(HASH_FLAG) && internal::IsZeroInt().visit(arg)) spec.flags_ &= ~internal::to_unsigned(HASH_FLAG); + if (spec.flag(static_cast(enumFlags::HASH_FLAG)) && internal::IsZeroInt().visit(arg)) + spec.flags_ &= ~internal::to_unsigned(static_cast(enumFlags::HASH_FLAG)); if (spec.fill_ == '0') { - if (arg.type <= Arg::LAST_NUMERIC_TYPE) - spec.align_ = ALIGN_NUMERIC; + if (arg.type <= Arg::Type::LAST_NUMERIC_TYPE) + spec.align_ = Alignment::ALIGN_NUMERIC; else spec.fill_ = ' '; // Ignore '0' flag for non-numeric types. } @@ -480,7 +481,7 @@ void PrintfFormatter::format(BasicCStringRef format_str) { spec.type_ = internal::DefaultType().visit(arg); } - if (arg.type <= Arg::LAST_INTEGER_TYPE) { + if (arg.type <= Arg::Type::LAST_INTEGER_TYPE) { // Normalize type. switch (spec.type_) { case 'i': diff --git a/storage/stonedb/base/fmt/time.h b/storage/stonedb/base/fmt/time.h index 7d2869b17..23c6f9cb6 100644 --- a/storage/stonedb/base/fmt/time.h +++ b/storage/stonedb/base/fmt/time.h @@ -25,7 +25,7 @@ void format_arg(BasicFormatter &f, const char *&format_str, const char *end = format_str; while (*end && *end != '}') ++end; if (*end != '}') FMT_THROW(FormatError("missing '}' in format string")); - internal::MemoryBuffer format; + internal::MemoryBuffer(internal::enumInlineBuffer::INLINE_BUFFER_SIZE)> format; format.append(format_str, end + 1); format[format.size() - 1] = '\0'; Buffer &buffer = f.writer().buffer(); diff --git a/storage/stonedb/base/net/posix_stack.cpp b/storage/stonedb/base/net/posix_stack.cpp index 24c92f474..210b98037 100644 --- a/storage/stonedb/base/net/posix_stack.cpp +++ b/storage/stonedb/base/net/posix_stack.cpp @@ -443,13 +443,18 @@ class posix_udp_channel : public udp_channel_impl { future<> posix_udp_channel::send(ipv4_addr dst, const char *message) { auto len = strlen(message); - return _fd->sendto(make_ipv4_address(dst), message, len).then([len](size_t size STONEDB_UNUSED) { assert(size == len);}); + return _fd->sendto(make_ipv4_address(dst), message, len).then([len](size_t size STONEDB_UNUSED) { + assert(size == len); + }); } future<> posix_udp_channel::send(ipv4_addr dst, packet p) { auto len = p.len(); _send.prepare(dst, std::move(p)); - return _fd->sendmsg(&_send._hdr).then([len](size_t size) { assert(size == len); (void)size;}); + return _fd->sendmsg(&_send._hdr).then([len](size_t size) { + assert(size == len); + (void)size; + }); } udp_channel posix_network_stack::make_udp_channel(ipv4_addr addr) { diff --git a/storage/stonedb/common/common_definitions.h b/storage/stonedb/common/common_definitions.h index a02b1e457..2f7aa6bd0 100644 --- a/storage/stonedb/common/common_definitions.h +++ b/storage/stonedb/common/common_definitions.h @@ -42,23 +42,23 @@ void PushWarning(THD *thd, Sql_condition::enum_warning_level level, uint code, c // Column Type // NOTE: do not change the order of implemented data types! Stored as int(...) // on disk. -enum CT : unsigned char { - STRING, // string treated either as dictionary value or "free" text - VARCHAR, // as above (discerned for compatibility with SQL) - INT, // integer 32-bit +enum class CT : unsigned char { + STRING, // string treated either as dictionary value or "free" text + VARCHAR, // as above (discerned for compatibility with SQL) + INT, // integer 32-bit - NUM, // numerical: decimal, up to DEC(18,18) - DATE, // numerical (treated as integer in YYYYMMDD format) - TIME, // numerical (treated as integer in HHMMSS format) + NUM, // numerical: decimal, up to DEC(18,18) + DATE, // numerical (treated as integer in YYYYMMDD format) + TIME, // numerical (treated as integer in HHMMSS format) BYTEINT, // integer 8-bit SMALLINT, // integer 16-bit - BIN, // free binary (BLOB), no encoding - BYTE, // free binary, fixed size, no encoding - VARBYTE, // free binary, variable size, no encoding - REAL, // double (stored as non-interpreted int64_t, null value is - // NULL_VALUE_64) + BIN, // free binary (BLOB), no encoding + BYTE, // free binary, fixed size, no encoding + VARBYTE, // free binary, variable size, no encoding + REAL, // double (stored as non-interpreted int64_t, null value is + // NULL_VALUE_64) DATETIME, TIMESTAMP, DATETIME_N, @@ -105,12 +105,12 @@ constexpr int64_t SDB_BIGINT_MIN = NULL_VALUE_64; #define DEFAULT_DELIMITER ";" #define DEFAULT_LINE_TERMINATOR "" -enum RSValue : char { +enum class RSValue : char { RS_NONE = 0, // the pack is empty RS_SOME = 1, // the pack is suspected (but may be empty or full) (i.e. - // RS_SOME & RS_ALL = RS_SOME) + // RSValue::RS_SOME & RSValue::RS_ALL = RSValue::RS_SOME) RS_ALL = 2, // the pack is full - RS_UNKNOWN = 3 // the pack was not checked yet (i.e. RS_UNKNOWN & RS_ALL = RS_ALL) + RS_UNKNOWN = 3 // the pack was not checked yet (i.e. RSValue::RS_UNKNOWN & RSValue::RS_ALL = RSValue::RS_ALL) }; /** @@ -121,7 +121,7 @@ enum RSValue : char { Any changes made here must also be reflected in the Descriptor class' interim createQueryOperator() member. */ -enum Operator { +enum class Operator { O_EQ = 0, O_EQ_ALL, O_EQ_ANY, @@ -174,7 +174,7 @@ enum Operator { OPERATOR_ENUM_COUNT }; -enum LogicalOperator { O_AND, O_OR }; +enum class LogicalOperator { O_AND, O_OR }; enum class ColOperation { DELAYED, @@ -209,22 +209,25 @@ class Tribool { // which initializes Tribool as the "unknown" value. // Do not use the enumerator defined below, it is internal only. - enum tribool { TRI_FALSE, TRI_TRUE, TRI_UNKNOWN }; + enum class tribool { TRI_FALSE, TRI_TRUE, TRI_UNKNOWN }; public: - Tribool() { v = TRI_UNKNOWN; } - Tribool(bool b) { v = (b ? TRI_TRUE : TRI_FALSE); } + Tribool() { v = tribool::TRI_UNKNOWN; } + Tribool(bool b) { v = (b ? tribool::TRI_TRUE : tribool::TRI_FALSE); } bool operator==(Tribool sec) { return v == sec.v; } bool operator!=(Tribool sec) { return v != sec.v; } - const Tribool operator!() { return Tribool(v == TRI_TRUE ? TRI_FALSE : (v == TRI_FALSE ? TRI_TRUE : TRI_UNKNOWN)); } + const Tribool operator!() { + return Tribool(v == tribool::TRI_TRUE ? tribool::TRI_FALSE + : (v == tribool::TRI_FALSE ? tribool::TRI_TRUE : tribool::TRI_UNKNOWN)); + } static Tribool And(Tribool a, Tribool b) { if (a == true && b == true) return true; if (a == false || b == false) return false; - return TRI_UNKNOWN; + return tribool::TRI_UNKNOWN; } static Tribool Or(Tribool a, Tribool b) { if (a == true || b == true) return true; - if (a == TRI_UNKNOWN || b == TRI_UNKNOWN) return TRI_UNKNOWN; + if (a == tribool::TRI_UNKNOWN || b == tribool::TRI_UNKNOWN) return tribool::TRI_UNKNOWN; return false; } diff --git a/storage/stonedb/common/compile_opts.h b/storage/stonedb/common/compile_opts.h index 094a11a96..dfff1ba58 100644 --- a/storage/stonedb/common/compile_opts.h +++ b/storage/stonedb/common/compile_opts.h @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ #ifndef STONEDB_COMMON_COMPILE_OPTS_H_ @@ -21,7 +21,7 @@ namespace stonedb { #ifdef __clang__ -//in clang +// in clang #elif __GNUC__ // //__GNUC__ // major @@ -32,13 +32,13 @@ namespace stonedb { #if (__GNUC__ > 4 && __GUNC__ < 7) || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) // C++0x features are only enabled when -std=c++0x or -std=gnu++0x are // passed on the command line, which in turn defines -// __GXX_EXPERIMENTAL_CXX0X__. - #define STONEDB_UNUSED [[gnu::unused]] +// __GXX_EXPERIMENTAL_CXX0X__. +#define STONEDB_UNUSED [[gnu::unused]] #elif __GNUC__ > 7 - //support in c++17 - #define STONEDB__UNUSED [[maybe_unused]] -#else - #define STONEDB_UNUSED __attribute__((unused)) +// support in c++17 +#define STONEDB__UNUSED [[maybe_unused]] +#else +#define STONEDB_UNUSED __attribute__((unused)) #endif #elif _MSC_VER /*usually has the version number in _MSC_VER*/ @@ -49,4 +49,4 @@ namespace stonedb { } // namespace stonedb -#endif // STONEDB_COMMON_COMPILE_OPTS_H_ +#endif // STONEDB_COMMON_COMPILE_OPTS_H_ diff --git a/storage/stonedb/common/data_format.cpp b/storage/stonedb/common/data_format.cpp index c72ffb640..c7e982b58 100644 --- a/storage/stonedb/common/data_format.cpp +++ b/storage/stonedb/common/data_format.cpp @@ -29,7 +29,7 @@ namespace common { int DataFormat::no_formats = 0; -std::map DataFormat::df_map = {{"TXT_VARIABLE", std::make_shared()}}; +std::map DataFormat::df_map = {{"EDF::TRI_UNKNOWN", std::make_shared()}}; DataFormatPtr DataFormat::GetDataFormat(const std::string &name) { auto it = df_map.find(boost::trim_copy(boost::to_upper_copy(name))); diff --git a/storage/stonedb/common/data_format.h b/storage/stonedb/common/data_format.h index f7d4cc325..000cad1bb 100644 --- a/storage/stonedb/common/data_format.h +++ b/storage/stonedb/common/data_format.h @@ -39,7 +39,7 @@ class DataFormat; using DataFormatPtr = std::shared_ptr; // External Data Format -enum EDF { TXT_VARIABLE }; +enum class EDF { TRI_UNKNOWN }; class DataFormat { protected: diff --git a/storage/stonedb/common/exception.cpp b/storage/stonedb/common/exception.cpp index 392ad6d4c..49c97edb4 100644 --- a/storage/stonedb/common/exception.cpp +++ b/storage/stonedb/common/exception.cpp @@ -38,7 +38,7 @@ Exception::Exception(std::string const &msg) : std::runtime_error(msg) { stack_trace += "\n"; } stack_trace += "STACK TRACE END\n"; - STONEDB_LOG(WARN, "Exception: %s.\n%s", msg.c_str(), stack_trace.c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "Exception: %s.\n%s", msg.c_str(), stack_trace.c_str()); } AssertException::AssertException(const char *cond, const char *file, int line, const std::string &msg) diff --git a/storage/stonedb/common/exception.h b/storage/stonedb/common/exception.h index 90ea845f1..36f0de7e7 100644 --- a/storage/stonedb/common/exception.h +++ b/storage/stonedb/common/exception.h @@ -58,7 +58,9 @@ static std::string error_messages[] = { }; inline bool IsError(ErrorCode sdbrc) { return sdbrc == ErrorCode::FAILED; } -inline bool IsWarning(ErrorCode sdbrc) { return sdbrc == ErrorCode::OUT_OF_RANGE || sdbrc == ErrorCode::VALUE_TRUNCATED; } +inline bool IsWarning(ErrorCode sdbrc) { + return sdbrc == ErrorCode::OUT_OF_RANGE || sdbrc == ErrorCode::VALUE_TRUNCATED; +} class SDBError { public: @@ -175,7 +177,8 @@ class DataTypeConversionException : public Exception { DataTypeConversionException(std::string const &msg, int64_t val = NULL_VALUE_64, CT t = CT::UNK) : Exception(msg), value(val), type(t) {} - DataTypeConversionException(SDBError sdberror = ErrorCode::DATACONVERSION, int64_t val = NULL_VALUE_64, CT t = CT::UNK) + DataTypeConversionException(SDBError sdberror = ErrorCode::DATACONVERSION, int64_t val = NULL_VALUE_64, + CT t = CT::UNK) : Exception(sdberror.Message()), value(val), type(t) {} }; diff --git a/storage/stonedb/common/txt_data_format.cpp b/storage/stonedb/common/txt_data_format.cpp index b869340dd..9c2d7188b 100644 --- a/storage/stonedb/common/txt_data_format.cpp +++ b/storage/stonedb/common/txt_data_format.cpp @@ -25,7 +25,7 @@ namespace stonedb { namespace common { -TxtDataFormat::TxtDataFormat() : DataFormat("TXT_VARIABLE", TXT_VARIABLE) {} +TxtDataFormat::TxtDataFormat() : DataFormat("EDF::TRI_UNKNOWN", EDF::TRI_UNKNOWN) {} TxtDataFormat::TxtDataFormat(std::string name, EDF edf) : DataFormat(name, edf) {} diff --git a/storage/stonedb/compress/arith_coder.cpp b/storage/stonedb/compress/arith_coder.cpp index 3de616688..04c6c2d04 100644 --- a/storage/stonedb/compress/arith_coder.cpp +++ b/storage/stonedb/compress/arith_coder.cpp @@ -33,7 +33,7 @@ CprsErr ArithCoder::ScaleRange(BitStream *dest, BaseT s_low, BaseT s_high, BaseT range = (WideT)(high - low) + 1; high = low + (BaseT)((range * s_high) / total - 1); low = low + (BaseT)((range * s_low) / total); - if (high < low) return CPRS_ERR_SUM; + if (high < low) return CprsErr::CPRS_ERR_SUM; for (;;) { // the same MS bits @@ -50,7 +50,7 @@ CprsErr ArithCoder::ScaleRange(BitStream *dest, BaseT s_low, BaseT s_high, BaseT low &= 0x3fff; high |= 0x4000; } else - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; low <<= 1; high <<= 1; @@ -61,7 +61,7 @@ CprsErr ArithCoder::ScaleRange(BitStream *dest, BaseT s_low, BaseT s_high, BaseT template CprsErr ArithCoder::EncodeUniform(BitStream *dest, T val, T maxval, uint bitmax) { DEBUG_ASSERT((val <= maxval) && (val >= 0)); - if (maxval == 0) return CPRS_SUCCESS; + if (maxval == 0) return CprsErr::CPRS_SUCCESS; DEBUG_ASSERT((maxval _SHR_ bitmax) == 0); // encode groups of 'uni_nbit' bits, from the least significant @@ -71,7 +71,7 @@ CprsErr ArithCoder::EncodeUniform(BitStream *dest, T val, T maxval, uint bitmax) while (bitmax > uni_nbit) { v = (BaseT)(val & uni_mask); err = ScaleRange(dest, v, v + (BaseT)1, uni_total); - if (err) return err; + if (static_cast(err)) return err; val >>= uni_nbit; maxval >>= uni_nbit; bitmax -= uni_nbit; @@ -79,9 +79,9 @@ CprsErr ArithCoder::EncodeUniform(BitStream *dest, T val, T maxval, uint bitmax) // encode the most significant group DEBUG_ASSERT(maxval < MAX_TOTAL); err = ScaleRange(dest, (BaseT)val, (BaseT)val + (BaseT)1, (BaseT)maxval + (BaseT)1); - if (err) return err; + if (static_cast(err)) return err; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } // TODO: it was @@ -92,7 +92,7 @@ void ArithCoder::EndCompress(BitStream *dest) { } CprsErr ArithCoder::CompressBytes(BitStream *dest, char *src, int slen, BaseT *sum, BaseT total) { - if (!dest || !src || !sum || (slen < 1) || (total <= 0)) return CPRS_ERR_PAR; + if (!dest || !src || !sum || (slen < 1) || (total <= 0)) return CprsErr::CPRS_ERR_PAR; InitCompress(); @@ -103,15 +103,15 @@ CprsErr ArithCoder::CompressBytes(BitStream *dest, char *src, int slen, BaseT *s c = *(src++); err = ScaleRange(dest, sum[c], sum[c + 1], total); // rescale high and low, send bits to dest - if (err) return err; + if (static_cast(static_cast(err))) return err; } EndCompress(dest); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr ArithCoder::CompressBits(BitStream *dest, BitStream *src, BaseT *sum, BaseT total) { - if (!dest || !src || !sum || (total <= 0)) return CPRS_ERR_PAR; + if (!dest || !src || !sum || (total <= 0)) return CprsErr::CPRS_ERR_PAR; InitCompress(); @@ -122,11 +122,11 @@ CprsErr ArithCoder::CompressBits(BitStream *dest, BitStream *src, BaseT *sum, Ba c = src->GetBit(); err = ScaleRange(dest, sum[c], sum[c + 1], total); // rescale high and low, send bits to dest - if (err) return err; + if (static_cast(static_cast(err))) return err; } EndCompress(dest); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } void ArithCoder::InitDecompress(BitStream *src) { @@ -158,7 +158,7 @@ CprsErr ArithCoder::RemoveSymbol(BitStream *src, BaseT s_low, BaseT s_high, Base low &= 0x3fff; high |= 0x4000; } else - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; low <<= 1; high <<= 1; @@ -168,14 +168,14 @@ CprsErr ArithCoder::RemoveSymbol(BitStream *src, BaseT s_low, BaseT s_high, Base if (src->CanRead()) code |= src->GetBit(); else if (++added > sizeof(BaseT) * 8) - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } } template CprsErr ArithCoder::DecodeUniform(BitStream *src, T &val, T maxval, uint bitmax) { val = 0; - if (maxval == 0) return CPRS_SUCCESS; + if (maxval == 0) return CprsErr::CPRS_SUCCESS; DEBUG_ASSERT((maxval _SHR_ bitmax) == 0); // decode groups of 'uni_nbit' bits, from the least significant @@ -186,7 +186,7 @@ CprsErr ArithCoder::DecodeUniform(BitStream *src, T &val, T maxval, uint bitmax) while (shift + uni_nbit < bitmax) { v = GetCount(uni_total); err = RemoveSymbol(src, v, v + (BaseT)1, uni_total); - if (err) return err; + if (static_cast(err)) return err; DEBUG_ASSERT(shift < 64); val |= (uint64_t)v << shift; shift += uni_nbit; @@ -197,16 +197,16 @@ CprsErr ArithCoder::DecodeUniform(BitStream *src, T &val, T maxval, uint bitmax) DEBUG_ASSERT(total <= MAX_TOTAL); v = GetCount(total); err = RemoveSymbol(src, v, v + (BaseT)1, total); - if (err) return err; + if (static_cast(err)) return err; DEBUG_ASSERT(shift < 64); val |= (uint64_t)v << shift; DEBUG_ASSERT(val <= maxval); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr ArithCoder::DecompressBytes(char *dest, int dlen, BitStream *src, BaseT *sum, BaseT total) { - if (!dest || !src || !sum || (dlen < 1)) return CPRS_ERR_PAR; + if (!dest || !src || !sum || (dlen < 1)) return CprsErr::CPRS_ERR_PAR; BaseT count; int c; @@ -227,14 +227,14 @@ CprsErr ArithCoder::DecompressBytes(char *dest, int dlen, BitStream *src, BaseT // remove the symbol from the input err = RemoveSymbol(src, sum[c], sum[c + 1], total); - if (err) return err; + if (static_cast(static_cast(err))) return err; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr ArithCoder::DecompressBits(BitStream *dest, BitStream *src, BaseT *sum, BaseT total) { - if (!dest || !src || !sum) return CPRS_ERR_PAR; + if (!dest || !src || !sum) return CprsErr::CPRS_ERR_PAR; BaseT count, sum0 = sum[0], sum1 = sum[1]; CprsErr err; @@ -253,10 +253,10 @@ CprsErr ArithCoder::DecompressBits(BitStream *dest, BitStream *src, BaseT *sum, dest->PutBit0(); err = RemoveSymbol(src, sum0, sum1, total); } - if (err) return err; + if (static_cast(static_cast(err))) return err; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } ArithCoder::BaseT ArithCoder::GetCount(BaseT total) { diff --git a/storage/stonedb/compress/arith_coder.h b/storage/stonedb/compress/arith_coder.h index c48fd9145..3766b5a46 100644 --- a/storage/stonedb/compress/arith_coder.h +++ b/storage/stonedb/compress/arith_coder.h @@ -24,7 +24,7 @@ namespace stonedb { namespace compress { -// The functions in ArithCoder throw ErrBufOverrun() or return CPRS_ERR_BUF, +// The functions in ArithCoder throw ErrBufOverrun() or return CprsErr::CPRS_ERR_BUF, // when the buffer is too short (during reading or writing). // // NOTE: cumulative count of symbols ('total') must be smaller than MAX_BaseT / diff --git a/storage/stonedb/compress/basic_data_filt.cpp b/storage/stonedb/compress/basic_data_filt.cpp index 6ccfbff70..90cc42632 100644 --- a/storage/stonedb/compress/basic_data_filt.cpp +++ b/storage/stonedb/compress/basic_data_filt.cpp @@ -85,7 +85,7 @@ template void DataFilt_RLE::Decode(RangeCoder *coder, DataSet *dataset) { uchar ver; coder->DecodeUniShift(ver, 2); - if (ver > 0) throw CPRS_ERR_COR; + if (ver > 0) throw CprsErr::CPRS_ERR_COR; // read cum counts lencnt[0] = 0; @@ -104,7 +104,7 @@ void DataFilt_RLE::Decode(RangeCoder *coder, DataSet *dataset) { coder->Decode(lencnt[len - 1], lencnt[len] - lencnt[len - 1], total); sumlen += (lens[nblk++] = len); } - if (sumlen > merge_nrec) throw CPRS_ERR_COR; + if (sumlen > merge_nrec) throw CprsErr::CPRS_ERR_COR; dataset->nrec = nblk; } template @@ -134,7 +134,7 @@ bool DataFilt_Min::Encode(RangeCoder *coder, DataSet *dataset) { // if(data[i] < minval) minval = data[i]; if ((data[i] < minval) && ((minval = data[i]) == 0)) break; if (minval == 0) return false; - if (minval > dataset->maxval) throw CPRS_ERR_PAR; + if (minval > dataset->maxval) throw CprsErr::CPRS_ERR_PAR; // save 'minval' coder->EncodeUniform(minval, dataset->maxval); @@ -148,7 +148,7 @@ bool DataFilt_Min::Encode(RangeCoder *coder, DataSet *dataset) { template void DataFilt_Min::Decode(RangeCoder *coder, DataSet *dataset) { coder->DecodeUniform(minval, dataset->maxval); - if (minval == 0) throw CPRS_ERR_COR; + if (minval == 0) throw CprsErr::CPRS_ERR_COR; dataset->maxval -= minval; } template @@ -190,7 +190,7 @@ bool DataFilt_GCD::Encode(RangeCoder *coder, DataSet *dataset) { for (uint i = 0; i < nrec; i++) if ((gcd = GCD(gcd, data[i])) == 1) break; if (gcd <= 1) return false; - if (gcd > dataset->maxval) throw CPRS_ERR_PAR; + if (gcd > dataset->maxval) throw CprsErr::CPRS_ERR_PAR; // save coder->EncodeUniform(gcd, dataset->maxval); @@ -204,7 +204,7 @@ bool DataFilt_GCD::Encode(RangeCoder *coder, DataSet *dataset) { template void DataFilt_GCD::Decode(RangeCoder *coder, DataSet *dataset) { coder->DecodeUniform(gcd, dataset->maxval); - if (gcd <= 1) throw CPRS_ERR_COR; + if (gcd <= 1) throw CprsErr::CPRS_ERR_COR; dataset->maxval /= gcd; } template @@ -284,7 +284,7 @@ bool DataFilt_Diff::Encode(RangeCoder *coder, DataSet *dataset) { T last = 0, curr, maxval1 = dataset->maxval + 1; // newmin = newmax = data[0]; - // make full differencing + // make earlyEnd_directive::full differencing for (uint i = 0; i < nrec; i++) { data[i] = (curr = data[i]) - last; if (last > curr) data[i] += maxval1; @@ -299,7 +299,7 @@ template void DataFilt_Diff::Decode(RangeCoder *coder, [[maybe_unused]] DataSet *dataset) { uchar ver; coder->DecodeUniform(ver, (uchar)3); - if (ver > 0) throw CPRS_ERR_COR; + if (ver > 0) throw CprsErr::CPRS_ERR_COR; } template @@ -345,7 +345,7 @@ void DataFilt_Uniform::Decode(RangeCoder *coder, DataSet *dataset) { // read version uchar ver; coder->DecodeUniform(ver, (uchar)3); - if (ver > 0) throw CPRS_ERR_COR; + if (ver > 0) throw CprsErr::CPRS_ERR_COR; T *data = dataset->data; T maxval = dataset->maxval; diff --git a/storage/stonedb/compress/bit_stream_compressor.cpp b/storage/stonedb/compress/bit_stream_compressor.cpp index 1a11a1b7c..4857b7fac 100644 --- a/storage/stonedb/compress/bit_stream_compressor.cpp +++ b/storage/stonedb/compress/bit_stream_compressor.cpp @@ -81,7 +81,7 @@ CprsErr BitstreamCompressor::CompressData(BitStream *dest, BitStream *src, unsig CprsErr err = ac.CompressBits(dest, src, sum, sum[2]); return err; } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } } @@ -105,7 +105,7 @@ CprsErr BitstreamCompressor::Compress(BitStream *dest, BitStream *src, unsigned dest->PutBit1(); dest->PutBit0(); // version indicator } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } // try to differentiate the 'src' stream and check if the compressed data @@ -139,7 +139,7 @@ CprsErr BitstreamCompressor::Compress(BitStream *dest, BitStream *src, unsigned } } } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } CprsErr err = CompressData(dest, src, numbits, num1); @@ -150,19 +150,19 @@ CprsErr BitstreamCompressor::DecompressData(BitStream *dest, BitStream *src, uns unsigned short sum[3]; GetSumTable(sum, numbits - num1, num1); try { - // if(src->GetBit() != 0) return CPRS_ERR_VER; // version + // if(src->GetBit() != 0) return CprsErr::CPRS_ERR_VER; // version // indicator ArithCoder ac; CprsErr err = ac.DecompressBits(dest, src, sum, sum[2]); return err; } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } } CprsErr BitstreamCompressor::Decompress(BitStream *dest, BitStream *src, unsigned int numbits, unsigned int num1) { try { - if ((src->GetBit() == 0) || (src->GetBit() != 0)) return CPRS_ERR_VER; + if ((src->GetBit() == 0) || (src->GetBit() != 0)) return CprsErr::CPRS_ERR_VER; uchar isdiff = src->GetBit(); // is the data differentiated? if (isdiff) { @@ -173,20 +173,20 @@ CprsErr BitstreamCompressor::Decompress(BitStream *dest, BitStream *src, unsigne try { BitStream diff(tab.get(), numbits); CprsErr err = DecompressData(&diff, src, numbits, num1); - if (err != CPRS_SUCCESS) { + if (err != CprsErr::CPRS_SUCCESS) { return err; } diff.Reset(); Integrt(dest, &diff); } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } else return DecompressData(dest, src, numbits, num1); } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } } diff --git a/storage/stonedb/compress/bit_stream_compressor.h b/storage/stonedb/compress/bit_stream_compressor.h index e1b4e274d..08772f3d4 100644 --- a/storage/stonedb/compress/bit_stream_compressor.h +++ b/storage/stonedb/compress/bit_stream_compressor.h @@ -26,7 +26,7 @@ namespace compress { ////////////////////////////////////////////////////////////////////// ////// Bitstream Compressor (optimized by the number of 0 and 1) //// // Compress() and Decompress() return the error identifier (see defs.h). -// This should be checked, especially against the CPRS_ERR_BUF value, +// This should be checked, especially against the CprsErr::CPRS_ERR_BUF value, // which indicates buffer overflow (output buf for Compress, input buf for // Decompress). // diff --git a/storage/stonedb/compress/code_stream.h b/storage/stonedb/compress/code_stream.h index 919108063..45171df18 100644 --- a/storage/stonedb/compress/code_stream.h +++ b/storage/stonedb/compress/code_stream.h @@ -48,7 +48,7 @@ class CoderStream : protected ArithCoder { void InitCompress() { ArithCoder::InitCompress(); } void Encode(BaseT low, BaseT high, BaseT total) { CprsErr err = ArithCoder::ScaleRange(str, low, high, total); - if (err) throw err; + if (static_cast(err)) throw err; } void EndCompress() { ArithCoder::EndCompress(str); } // decompression methods @@ -56,32 +56,32 @@ class CoderStream : protected ArithCoder { BaseT GetCount(BaseT total) { return ArithCoder::GetCount(total); } void Decode(BaseT low, BaseT high, BaseT total) { CprsErr err = ArithCoder::RemoveSymbol(str, low, high, total); - if (err) throw err; + if (static_cast(err)) throw err; } // uniform compression and decompression template void EncodeUniform(T val, T maxval, uint bitmax) { CprsErr err = ArithCoder::EncodeUniform(str, val, maxval, bitmax); - if (err) throw err; + if (static_cast(err)) throw err; } template void EncodeUniform(T val, T maxval) { CprsErr err = ArithCoder::EncodeUniform(str, val, maxval); - if (err) throw err; + if (static_cast(err)) throw err; } template void DecodeUniform(T &val, T maxval, uint bitmax) { CprsErr err = ArithCoder::DecodeUniform(str, val, maxval, bitmax); - if (err) throw err; + if (static_cast(err)) throw err; } template void DecodeUniform(T &val, T maxval) { CprsErr err = ArithCoder::DecodeUniform(str, val, maxval); - if (err) throw err; + if (static_cast(err)) throw err; } }; diff --git a/storage/stonedb/compress/defs.h b/storage/stonedb/compress/defs.h index 3738c6e48..b56e9c337 100644 --- a/storage/stonedb/compress/defs.h +++ b/storage/stonedb/compress/defs.h @@ -21,7 +21,7 @@ #pragma once // Compression and decompression errors -enum CprsErr { +enum class CprsErr { CPRS_SUCCESS = 0, CPRS_ERR_BUF = 1, // buffer overflow error CPRS_ERR_PAR = 2, // bad parameters @@ -33,7 +33,7 @@ enum CprsErr { }; // Attribute types treated specially by compression routines -enum CprsAttrType /*Enum*/ { +enum class CprsAttrType /*Enum*/ { CAT_OTHER = 0, CAT_DATA = 1, CAT_TIME = 2, diff --git a/storage/stonedb/compress/dictionary.cpp b/storage/stonedb/compress/dictionary.cpp index a1312a881..bd3bb6259 100644 --- a/storage/stonedb/compress/dictionary.cpp +++ b/storage/stonedb/compress/dictionary.cpp @@ -128,7 +128,7 @@ void Dictionary::Load(RangeCoder *src, T maxkey) { prevc = c++; keys[i].count = c; keys[i].low = total; - if (total + c > MAXTOTAL) throw CPRS_ERR_COR; + if (total + c > MAXTOTAL) throw CprsErr::CPRS_ERR_COR; for (; c > 0; c--) cnt2val[total++] = i; } diff --git a/storage/stonedb/compress/inc_alloc.cpp b/storage/stonedb/compress/inc_alloc.cpp index 0d396b8da..1d16ffc6d 100644 --- a/storage/stonedb/compress/inc_alloc.cpp +++ b/storage/stonedb/compress/inc_alloc.cpp @@ -67,7 +67,7 @@ void *IncAlloc::_alloc_search(uint size) { if (bsize < size) bsize = size; } void *mem = new char[bsize]; - if (!mem) throw CPRS_ERR_MEM; + if (!mem) throw CprsErr::CPRS_ERR_MEM; blocks.push_back(Block(mem, bsize)); used = size; diff --git a/storage/stonedb/compress/inc_alloc.h b/storage/stonedb/compress/inc_alloc.h index fbf843077..196130c15 100644 --- a/storage/stonedb/compress/inc_alloc.h +++ b/storage/stonedb/compress/inc_alloc.h @@ -28,7 +28,7 @@ namespace stonedb { namespace compress { // Incremental memory allocator. -// May throw CPRS_ERR_MEM. +// May throw CprsErr::CPRS_ERR_MEM. class IncAlloc { static constexpr int FIRSTSIZE = 16384; // default size of the first block static constexpr int ROUNDUP = 4096; // block size will be a multiple of this diff --git a/storage/stonedb/compress/inc_wgraph.cpp b/storage/stonedb/compress/inc_wgraph.cpp index cbfaf52c9..8dddbfd8d 100644 --- a/storage/stonedb/compress/inc_wgraph.cpp +++ b/storage/stonedb/compress/inc_wgraph.cpp @@ -73,7 +73,7 @@ void IncWGraph::Clear() { //------------------------------------------------------------------------------------------- void IncWGraph::Encode(RangeCoder *cod, char **index, const uint *lens, int nrec, uint &packlen) { - if ((nrec < 1) || (nrec > 65536) || (!cod)) throw CPRS_ERR_PAR; + if ((nrec < 1) || (nrec > 65536) || (!cod)) throw CprsErr::CPRS_ERR_PAR; Clear(); Init(); coder = cod; @@ -117,7 +117,7 @@ void IncWGraph::Encode(RangeCoder *cod, char **index, const uint *lens, int nrec } void IncWGraph::Decode(RangeCoder *cod, char **index, const uint *lens, int nrec, char *dest, uint dlen) { - if ((nrec < 1) || (nrec > 65536) || (!cod)) throw CPRS_ERR_PAR; + if ((nrec < 1) || (nrec > 65536) || (!cod)) throw CprsErr::CPRS_ERR_PAR; Clear(); Init(); coder = cod; @@ -251,7 +251,7 @@ void IncWGraph::DecodeRec(ushort rec, uint dlen, bool &repeated) { break; else { if (repeated) { - if (len > dlen) throw CPRS_ERR_BUF; + if (len > dlen) throw CprsErr::CPRS_ERR_BUF; declen = len - restlen; LabelCopy(s, base->endpos - declen, declen); // copy at once all labels passed till now @@ -287,7 +287,7 @@ void IncWGraph::DecodeRec(ushort rec, uint dlen, bool &repeated) { } else if (proj < edge->GetLen()) { // it appears that the record is not a // repetition DEBUG_ASSERT(base != NIL); - if (len > dlen) throw CPRS_ERR_BUF; + if (len > dlen) throw CprsErr::CPRS_ERR_BUF; declen = len - restlen; LabelCopy(s, edge->target->endpos - edgelen + proj - declen, declen); // copy at once all labels passed till now diff --git a/storage/stonedb/compress/lz4.cpp b/storage/stonedb/compress/lz4.cpp index 7f52168ae..be6bc8fe6 100644 --- a/storage/stonedb/compress/lz4.cpp +++ b/storage/stonedb/compress/lz4.cpp @@ -362,14 +362,14 @@ typedef struct { } LZ4_stream_t_internal; -using limitedOutput_directive = enum { notLimited = 0, limitedOutput = 1 }; -using tableType_t = enum { byPtr, byU32, byU16 }; +enum class limitedOutput_directive { notLimited = 0, limitedOutput = 1 }; +enum class tableType_t { byPtr, byU32, byU16 }; -using dict_directive = enum { noDict = 0, withPrefix64k, usingExtDict }; -using dictIssue_directive = enum { noDictIssue = 0, dictSmall } ; +enum class dict_directive { noDict = 0, withPrefix64k, usingExtDict }; +enum class dictIssue_directive { noDictIssue = 0, dictSmall } ; -using endCondition_directive = enum { endOnOutputSize = 0, endOnInputSize = 1 } ; -using earlyEnd_directive = enum { full = 0, partial = 1 } ; +enum class endCondition_directive { endOnOutputSize = 0, endOnInputSize = 1 } ; +enum class earlyEnd_directive { full = 0, partial = 1 } ; /************************************** @@ -385,7 +385,7 @@ int LZ4_sizeofState() { return LZ4_STREAMSIZE; } namespace { U32 LZ4_hashSequence(U32 sequence, tableType_t const tableType) { - if (tableType == byU16) + if (tableType == tableType_t::byU16) return (((sequence) * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1))); else return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG)); @@ -394,7 +394,7 @@ U32 LZ4_hashSequence(U32 sequence, tableType_t const tableType) const U64 prime5bytes = 889523592379ULL; U32 LZ4_hashSequence64(size_t sequence, tableType_t const tableType) { - const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG; + const U32 hashLog = (tableType == tableType_t::byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG; const U32 hashMask = (1<> (40 - hashLog)) & hashMask; } @@ -412,9 +412,9 @@ void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t co { switch (tableType) { - case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } - case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; } - case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; } + case tableType_t::byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } + case tableType_t::byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; } + case tableType_t::byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; } } } @@ -426,8 +426,8 @@ void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, cons const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase) { - if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; } - if (tableType == byU32) { U32* hashTable = (U32*) tableBase; return hashTable[h] + srcBase; } + if (tableType == tableType_t::byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; } + if (tableType == tableType_t::byU32) { U32* hashTable = (U32*) tableBase; return hashTable[h] + srcBase; } { U16* hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */ } @@ -473,21 +473,21 @@ FORCE_INLINE int LZ4_compress_generic( if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ switch(dict) { - case noDict: + case dict_directive::noDict: default: base = (const BYTE*)source; lowLimit = (const BYTE*)source; break; - case withPrefix64k: + case dict_directive::withPrefix64k: base = (const BYTE*)source - dictPtr->currentOffset; lowLimit = (const BYTE*)source - dictPtr->dictSize; break; - case usingExtDict: + case dict_directive::usingExtDict: base = (const BYTE*)source - dictPtr->currentOffset; lowLimit = (const BYTE*)source; break; } - if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if ((tableType == tableType_t::byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ if (inputSize mflimit)) goto _last_literals; match = LZ4_getPositionOnHash(h, ctx, tableType, base); - if (dict==usingExtDict) + if (dict==dict_directive::usingExtDict) { if (match<(const BYTE*)source) { @@ -530,8 +530,8 @@ FORCE_INLINE int LZ4_compress_generic( forwardH = LZ4_hashPosition(forwardIp, tableType); LZ4_putPositionOnHash(ip, h, ctx, tableType, base); - } while ( ((dictIssue==dictSmall) ? (match < lowRefLimit) : 0) - || ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) + } while ( ((dictIssue==dictIssue_directive::dictSmall) ? (match < lowRefLimit) : 0) + || ((tableType==tableType_t::byU16) ? 0 : (match + MAX_DISTANCE < ip)) || (LZ4_read32(match+refDelta) != LZ4_read32(ip)) ); } @@ -542,7 +542,7 @@ FORCE_INLINE int LZ4_compress_generic( /* Encode Literal length */ unsigned litLength = (unsigned)(ip - anchor); token = op++; - if ((outputLimited) && (lz4_unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit))) + if ((static_cast(outputLimited)) && (lz4_unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit))) return 0; /* Check output limit */ if (litLength>=RUN_MASK) { @@ -566,7 +566,7 @@ FORCE_INLINE int LZ4_compress_generic( { unsigned matchLength; - if ((dict==usingExtDict) && (lowLimit==dictionary)) + if ((dict==dict_directive::usingExtDict) && (lowLimit==dictionary)) { const BYTE* limit; match += refDelta; @@ -587,7 +587,7 @@ FORCE_INLINE int LZ4_compress_generic( ip += MINMATCH + matchLength; } - if ((outputLimited) && (lz4_unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > olimit))) + if ((static_cast(outputLimited)) && (lz4_unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > olimit))) return 0; /* Check output limit */ if (matchLength>=ML_MASK) { @@ -610,7 +610,7 @@ FORCE_INLINE int LZ4_compress_generic( /* Test next position */ match = LZ4_getPosition(ip, ctx, tableType, base); - if (dict==usingExtDict) + if (dict==dict_directive::usingExtDict) { if (match<(const BYTE*)source) { @@ -624,7 +624,7 @@ FORCE_INLINE int LZ4_compress_generic( } } LZ4_putPosition(ip, ctx, tableType, base); - if ( ((dictIssue==dictSmall) ? (match>=lowRefLimit) : 1) + if ( ((dictIssue==dictIssue_directive::dictSmall) ? (match>=lowRefLimit) : 1) && (match+MAX_DISTANCE>=ip) && (LZ4_read32(match+refDelta)==LZ4_read32(ip)) ) { token=op++; *token=0; goto _next_match; } @@ -637,7 +637,7 @@ FORCE_INLINE int LZ4_compress_generic( /* Encode Last Literals */ { const size_t lastRun = (size_t)(iend - anchor); - if ((outputLimited) && ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) + if ((static_cast(outputLimited)) && ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */ if (lastRun >= RUN_MASK) { @@ -667,16 +667,16 @@ int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int if (maxOutputSize >= LZ4_compressBound(inputSize)) { if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, 0, limitedOutput_directive::notLimited, tableType_t::byU16, dict_directive::noDict, dictIssue_directive::noDictIssue, acceleration); else - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, 0, limitedOutput_directive::notLimited, LZ4_64bits() ? tableType_t::byU32 : tableType_t::byPtr, dict_directive::noDict, dictIssue_directive::noDictIssue, acceleration); } else { if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, tableType_t::byU16, dict_directive::noDict, dictIssue_directive::noDictIssue, acceleration); else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, LZ4_64bits() ? tableType_t::byU32 : tableType_t::byPtr, dict_directive::noDict, dictIssue_directive::noDictIssue, acceleration); } } @@ -714,9 +714,9 @@ int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int m LZ4_resetStream(&ctx); if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, tableType_t::byU16, dict_directive::noDict, dictIssue_directive::noDictIssue, acceleration); else - return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, LZ4_64bits() ? tableType_t::byU32 : tableType_t::byPtr, dict_directive::noDict, dictIssue_directive::noDictIssue, acceleration); } @@ -752,7 +752,7 @@ int LZ4_compress_destSize_generic( /* Init conditions */ if (targetDstSize < 1) return 0; /* Impossible to store anything */ if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ - if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if ((tableType == tableType_t::byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ if (*srcSizePtrhashTable, byU32, base); + LZ4_putPosition(p, dict->hashTable, tableType_t::byU32, base); p+=3; } @@ -1038,9 +1038,9 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, ch { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, acceleration); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, tableType_t::byU32, dict_directive::withPrefix64k, dictIssue_directive::dictSmall, acceleration); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, acceleration); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, tableType_t::byU32, dict_directive::withPrefix64k, dictIssue_directive::noDictIssue, acceleration); streamPtr->dictSize += (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; return result; @@ -1050,9 +1050,9 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, ch { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, tableType_t::byU32, dict_directive::usingExtDict, dictIssue_directive::dictSmall, acceleration); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput_directive::limitedOutput, tableType_t::byU32, dict_directive::usingExtDict, dictIssue_directive::noDictIssue, acceleration); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; @@ -1072,7 +1072,7 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; LZ4_renormDictT((LZ4_stream_t_internal*)LZ4_dict, smallest); - result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 1); + result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, limitedOutput_directive::notLimited, tableType_t::byU32, dict_directive::usingExtDict, dictIssue_directive::noDictIssue, 1); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; @@ -1111,15 +1111,15 @@ FORCE_INLINE int LZ4_decompress_generic( const char* const source, char* const dest, int inputSize, - int outputSize, /* If endOnInput==endOnInputSize, this value is the max size of Output Buffer. */ - - int endOnInput, /* endOnOutputSize, endOnInputSize */ - int partialDecoding, /* full, partial */ - int targetOutputSize, /* only used if partialDecoding==partial */ - int dict, /* noDict, withPrefix64k, usingExtDict */ - const BYTE* const lowPrefix, /* == dest if dict == noDict */ - const BYTE* const dictStart, /* only if dict==usingExtDict */ - const size_t dictSize /* note : = 0 if noDict */ + int outputSize, /* If endOnInput==endCondition_directive::endOnInputSize, this value is the max size of Output Buffer. */ + + int endOnInput, /* endCondition_directive::endOnOutputSize, endCondition_directive::endOnInputSize */ + int partialDecoding, /* earlyEnd_directive::full, earlyEnd_directive::partial */ + int targetOutputSize, /* only used if partialDecoding==earlyEnd_directive::partial */ + int dict, /* dict_directive::noDict, dict_directive::withPrefix64k, dict_directive::usingExtDict */ + const BYTE* const lowPrefix, /* == dest if dict == dict_directive::noDict */ + const BYTE* const dictStart, /* only if dict==dict_directive::usingExtDict */ + const size_t dictSize /* note : = 0 if dict_directive::noDict */ ) { /* Local Variables */ @@ -1136,7 +1136,7 @@ FORCE_INLINE int LZ4_decompress_generic( const size_t dec32table[] = {4, 1, 2, 1, 4, 4, 4, 4}; const size_t dec64table[] = {0, 0, 0, (size_t)-1, 0, 1, 2, 3}; - const int safeDecode = (endOnInput==endOnInputSize); + const int safeDecode = (endOnInput==static_cast(endCondition_directive::endOnInputSize)); const int checkOffset = ((safeDecode) && (dictSize < (int)(64 KB))); @@ -1211,7 +1211,7 @@ FORCE_INLINE int LZ4_decompress_generic( length += MINMATCH; /* check external dictionary */ - if ((dict==usingExtDict) && (match < lowPrefix)) + if ((dict==static_cast(dict_directive::usingExtDict)) && (match < lowPrefix)) { if (lz4_unlikely(op+length > oend-LASTLITERALS)) goto _output_error; /* doesn't respect parsing restriction */ @@ -1287,17 +1287,28 @@ FORCE_INLINE int LZ4_decompress_generic( int LZ4_decompress_safe(const char* source, char* dest, int compressedSize, int maxDecompressedSize) { - return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, full, 0, noDict, (BYTE*)dest, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, + static_cast(endCondition_directive::endOnInputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::noDict), + (BYTE*)dest, NULL, 0); } int LZ4_decompress_safe_partial(const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize) { - return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, partial, targetOutputSize, noDict, (BYTE*)dest, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, + static_cast(endCondition_directive::endOnInputSize), + static_cast(earlyEnd_directive::partial), targetOutputSize, + static_cast(dict_directive::noDict), (BYTE*)dest, NULL, 0); } int LZ4_decompress_fast(const char* source, char* dest, int originalSize) { - return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)(dest - 64 KB), NULL, 64 KB); + return LZ4_decompress_generic(source, dest, 0, originalSize, + static_cast(endCondition_directive::endOnOutputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::withPrefix64k), + (BYTE*)(dest - 64 KB), NULL, 64 KB); } @@ -1360,8 +1371,10 @@ int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const ch if (lz4sd->prefixEnd == (BYTE*)dest) { result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, - endOnInputSize, full, 0, - usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); + static_cast(endCondition_directive::endOnInputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::usingExtDict), + lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); if (result <= 0) return result; lz4sd->prefixSize += result; lz4sd->prefixEnd += result; @@ -1371,8 +1384,10 @@ int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const ch lz4sd->extDictSize = lz4sd->prefixSize; lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, - endOnInputSize, full, 0, - usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); + static_cast(endCondition_directive::endOnInputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::usingExtDict), + (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); if (result <= 0) return result; lz4sd->prefixSize = result; lz4sd->prefixEnd = (BYTE*)dest + result; @@ -1389,8 +1404,10 @@ int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const ch if (lz4sd->prefixEnd == (BYTE*)dest) { result = LZ4_decompress_generic(source, dest, 0, originalSize, - endOnOutputSize, full, 0, - usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); + static_cast(endCondition_directive::endOnOutputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::usingExtDict), + lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); if (result <= 0) return result; lz4sd->prefixSize += originalSize; lz4sd->prefixEnd += originalSize; @@ -1400,8 +1417,10 @@ int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const ch lz4sd->extDictSize = lz4sd->prefixSize; lz4sd->externalDict = (BYTE*)dest - lz4sd->extDictSize; result = LZ4_decompress_generic(source, dest, 0, originalSize, - endOnOutputSize, full, 0, - usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); + static_cast(endCondition_directive::endOnOutputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::usingExtDict), + (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); if (result <= 0) return result; lz4sd->prefixSize = originalSize; lz4sd->prefixEnd = (BYTE*)dest + originalSize; @@ -1421,14 +1440,22 @@ Advanced decoding functions : FORCE_INLINE int LZ4_decompress_usingDict_generic(const char* source, char* dest, int compressedSize, int maxOutputSize, int safe, const char* dictStart, int dictSize) { if (dictSize==0) - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::noDict), (BYTE*)dest, NULL, 0); if (dictStart+dictSize == dest) { if (dictSize >= (int)(64 KB - 1)) - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0); - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::withPrefix64k), (BYTE*)dest-64 KB, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::noDict), (BYTE*)dest-dictSize, NULL, 0); } - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::usingExtDict), (BYTE*)dest, (const BYTE*)dictStart, dictSize); } int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) @@ -1444,7 +1471,9 @@ int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSi /* debug function */ int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) { - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, + static_cast(endCondition_directive::endOnInputSize), static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::usingExtDict), (BYTE*)dest, (const BYTE*)dictStart, dictSize); } @@ -1504,12 +1533,18 @@ char* LZ4_slideInputBuffer (void* LZ4_Data) int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize) { - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, + static_cast(endCondition_directive::endOnInputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::withPrefix64k), (BYTE*)dest - 64 KB, NULL, 64 KB); } int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int originalSize) { - return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); + return LZ4_decompress_generic(source, dest, 0, originalSize, + static_cast(endCondition_directive::endOnOutputSize), + static_cast(earlyEnd_directive::full), 0, + static_cast(dict_directive::withPrefix64k), (BYTE*)dest - 64 KB, NULL, 64 KB); } #endif /* LZ4_COMMONDEFS_ONLY */ diff --git a/storage/stonedb/compress/lz4.h b/storage/stonedb/compress/lz4.h index d4814f9e8..13a339c60 100644 --- a/storage/stonedb/compress/lz4.h +++ b/storage/stonedb/compress/lz4.h @@ -45,7 +45,7 @@ extern "C" { #endif // defined (__cplusplus) /* - * lz4.h provides block compression functions, and gives full buffer control to programmer. + * lz4.h provides block compression functions, and gives earlyEnd_directive::full buffer control to programmer. * If you need to generate inter-operable compressed data (respecting LZ4 frame specification), * and can let the library handle its own memory, please use lz4frame.h instead. */ @@ -90,12 +90,12 @@ LZ4_compress_default() : As a consequence, 'dest' content is not valid. This function never writes outside 'dest' buffer, nor read outside 'source' buffer. sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE - maxDestSize : full or partial size of buffer 'dest' (which must be already allocated) + maxDestSize : earlyEnd_directive::full or earlyEnd_directive::partial size of buffer 'dest' (which must be already allocated) return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize) or 0 if compression fails LZ4_decompress_safe() : - compressedSize : is the precise full size of the compressed block. + compressedSize : is the precise earlyEnd_directive::full size of the compressed block. maxDecompressedSize : is the size of destination buffer, which must be already allocated. return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize) If destination buffer is not large enough, decoding will stop and output an error code (<0). diff --git a/storage/stonedb/compress/num_compressor.h b/storage/stonedb/compress/num_compressor.h index 334751926..42969c03c 100644 --- a/storage/stonedb/compress/num_compressor.h +++ b/storage/stonedb/compress/num_compressor.h @@ -75,66 +75,67 @@ class NumCompressorBase { // non-templated type-safe compression methods virtual CprsErr Compress([[maybe_unused]] char *dest, [[maybe_unused]] uint &len, [[maybe_unused]] const uchar *src, [[maybe_unused]] uint nrec, [[maybe_unused]] uchar maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Compress([[maybe_unused]] char *dest, [[maybe_unused]] uint &len, [[maybe_unused]] const ushort *src, [[maybe_unused]] uint nrec, [[maybe_unused]] ushort maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Compress([[maybe_unused]] char *dest, [[maybe_unused]] uint &len, [[maybe_unused]] const uint *src, [[maybe_unused]] uint nrec, [[maybe_unused]] uint maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Compress([[maybe_unused]] char *dest, [[maybe_unused]] uint &len, [[maybe_unused]] const uint64_t *src, [[maybe_unused]] uint nrec, - [[maybe_unused]] uint64_t maxval, [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] uint64_t maxval, + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Decompress([[maybe_unused]] uchar *dest, [[maybe_unused]] char *src, [[maybe_unused]] uint len, [[maybe_unused]] uint nrec, [[maybe_unused]] uchar maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Decompress([[maybe_unused]] ushort *dest, [[maybe_unused]] char *src, [[maybe_unused]] uint len, [[maybe_unused]] uint nrec, [[maybe_unused]] ushort maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Decompress([[maybe_unused]] uint *dest, [[maybe_unused]] char *src, [[maybe_unused]] uint len, [[maybe_unused]] uint nrec, [[maybe_unused]] uint maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } virtual CprsErr Decompress([[maybe_unused]] uint64_t *dest, [[maybe_unused]] char *src, [[maybe_unused]] uint len, [[maybe_unused]] uint nrec, [[maybe_unused]] uint64_t maxval, - [[maybe_unused]] CprsAttrType cat = CAT_OTHER) { + [[maybe_unused]] CprsAttrType cat = CprsAttrType::CAT_OTHER) { STONEDB_ERROR("method should not be invoked"); - return CPRS_ERR_OTH; + return CprsErr::CPRS_ERR_OTH; } // non-templated NON-type-safe compression methods - use them carefully! // make sure that you invoke them for object of appropriate type virtual CprsErr Compress(char *dest, uint &len, const void *src, uint nrec, uint64_t maxval, - CprsAttrType cat = CAT_OTHER) = 0; + CprsAttrType cat = CprsAttrType::CAT_OTHER) = 0; virtual CprsErr Decompress(void *dest, char *src, uint len, uint nrec, uint64_t maxval, - CprsAttrType cat = CAT_OTHER) = 0; + CprsAttrType cat = CprsAttrType::CAT_OTHER) = 0; }; // THE NumCompressor (templated) @@ -162,32 +163,35 @@ class NumCompressor : public NumCompressorBase { // 'nrec' must be at most CPRS_MAXREC // 'maxval' - maximum value in the data // Data in 'src' are NOT changed. - CprsErr CompressT(char *dest, uint &len, const T *src, uint nrec, T maxval, CprsAttrType cat = CAT_OTHER); + CprsErr CompressT(char *dest, uint &len, const T *src, uint nrec, T maxval, + CprsAttrType cat = CprsAttrType::CAT_OTHER); // 'len' - the value of 'len' returned from Compress() // 'dest' must be able to hold at least 'nrec' elements of type T - CprsErr DecompressT(T *dest, char *src, uint len, uint nrec, T maxval, CprsAttrType cat = CAT_OTHER); + CprsErr DecompressT(T *dest, char *src, uint len, uint nrec, T maxval, CprsAttrType cat = CprsAttrType::CAT_OTHER); using NumCompressorBase::Compress; using NumCompressorBase::Decompress; - CprsErr Compress(char *dest, uint &len, const T *src, uint nrec, T maxval, CprsAttrType cat = CAT_OTHER) override { + CprsErr Compress(char *dest, uint &len, const T *src, uint nrec, T maxval, + CprsAttrType cat = CprsAttrType::CAT_OTHER) override { MEASURE_FET("NumCompressor::Compress(...)"); return CompressT(dest, len, src, nrec, maxval, cat); } - CprsErr Decompress(T *dest, char *src, uint len, uint nrec, T maxval, CprsAttrType cat = CAT_OTHER) override { + CprsErr Decompress(T *dest, char *src, uint len, uint nrec, T maxval, + CprsAttrType cat = CprsAttrType::CAT_OTHER) override { MEASURE_FET("NumCompressor::Decompress(...)"); return DecompressT(dest, src, len, nrec, maxval, cat); } CprsErr Compress(char *dest, uint &len, const void *src, uint nrec, uint64_t maxval, - CprsAttrType cat = CAT_OTHER) override { + CprsAttrType cat = CprsAttrType::CAT_OTHER) override { MEASURE_FET("NumCompressor::Compress(...)"); return CompressT(dest, len, (T *)src, nrec, (T)maxval, cat); } CprsErr Decompress(void *dest, char *src, uint len, uint nrec, uint64_t maxval, - CprsAttrType cat = CAT_OTHER) override { + CprsAttrType cat = CprsAttrType::CAT_OTHER) override { MEASURE_FET("NumCompressor::Decompress(...)"); return DecompressT((T *)dest, src, len, nrec, (T)maxval, cat); } @@ -246,19 +250,19 @@ void NumCompressor::DumpData(DataSet *ds, uint f) { template CprsErr NumCompressor::CopyCompress(char *dest, uint &len, const T *src, uint nrec) { uint datalen = nrec * sizeof(T); - if (len < 1 + datalen) return CPRS_ERR_BUF; + if (len < 1 + datalen) return CprsErr::CPRS_ERR_BUF; *dest = 0; // ID of copy compression std::memcpy(dest + 1, src, datalen); len = 1 + datalen; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } template CprsErr NumCompressor::CopyDecompress(T *dest, char *src, uint len, uint nrec) { uint datalen = nrec * sizeof(T); - if (len < 1 + datalen) throw CPRS_ERR_BUF; + if (len < 1 + datalen) throw CprsErr::CPRS_ERR_BUF; std::memcpy(dest, src + 1, datalen); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } template @@ -268,8 +272,8 @@ CprsErr NumCompressor::CompressT(char *dest, uint &len, const T *src, uint nr // =0 - copy compression // =1 - current version - if (!dest || !src || (len < 3)) return CPRS_ERR_BUF; - if ((nrec == 0) || (maxval == 0)) return CPRS_ERR_PAR; + if (!dest || !src || (len < 3)) return CprsErr::CPRS_ERR_BUF; + if ((nrec == 0) || (maxval == 0)) return CprsErr::CPRS_ERR_PAR; if (copy_only) return CopyCompress(dest, len, src, nrec); @@ -281,7 +285,7 @@ CprsErr NumCompressor::CompressT(char *dest, uint &len, const T *src, uint nr std::vector buf(src, src + nrec); DataSet dataset = {&buf[0], maxval, nrec}; - CprsErr err = CPRS_SUCCESS; + CprsErr err = CprsErr::CPRS_SUCCESS; try { RangeCoder coder; coder.InitCompress(dest, len, pos); @@ -307,21 +311,21 @@ CprsErr NumCompressor::CompressT(char *dest, uint &len, const T *src, uint nr // if compression failed or the size is bigger than the raw data, use copy // compression - if (err || (pos >= 0.98 * nrec * sizeof(T))) return CopyCompress(dest, len, src, nrec); + if (static_cast(err) || (pos >= 0.98 * nrec * sizeof(T))) return CopyCompress(dest, len, src, nrec); len = pos; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } template CprsErr NumCompressor::DecompressT(T *dest, char *src, uint len, uint nrec, T maxval, [[maybe_unused]] CprsAttrType cat) { - if (!src || (len < 1)) return CPRS_ERR_BUF; - if ((nrec == 0) || (maxval == 0)) return CPRS_ERR_PAR; + if (!src || (len < 1)) return CprsErr::CPRS_ERR_BUF; + if ((nrec == 0) || (maxval == 0)) return CprsErr::CPRS_ERR_PAR; uchar ver = (uchar)src[0]; if (ver == 0) return CopyDecompress(dest, src, len, nrec); - if (len < 3) return CPRS_ERR_BUF; + if (len < 3) return CprsErr::CPRS_ERR_BUF; ushort ID = *(ushort *)(src + 1); uint pos = 3; @@ -350,7 +354,7 @@ CprsErr NumCompressor::DecompressT(T *dest, char *src, uint len, uint nrec, T return err; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } } // namespace compress diff --git a/storage/stonedb/compress/part_dict.cpp b/storage/stonedb/compress/part_dict.cpp index 29878811f..0ea211fef 100644 --- a/storage/stonedb/compress/part_dict.cpp +++ b/storage/stonedb/compress/part_dict.cpp @@ -144,14 +144,14 @@ void PartDict::Load(RangeCoder *coder, T maxval) { prevc = c++; freqval[f].low = low; freqval[f].count = c; - if (low + c > MAXTOTAL) throw CPRS_ERR_COR; + if (low + c > MAXTOTAL) throw CprsErr::CPRS_ERR_COR; for (; c > 0; c--) cnt2val[low++] = f; } // load range of ESC esc_low = low; coder->DecodeUniform(esc_high, MAXTOTAL); - if (esc_low > esc_high) throw CPRS_ERR_COR; + if (esc_low > esc_high) throw CprsErr::CPRS_ERR_COR; esc_usecnt = esc_high - esc_low; } @@ -212,7 +212,7 @@ void PartDict::Decode(RangeCoder *coder, DataSet *dataset) { // read version uchar ver; coder->DecodeUniform(ver, (uchar)7); - if (ver > 0) throw CPRS_ERR_COR; + if (ver > 0) throw CprsErr::CPRS_ERR_COR; // load dictionary Load(coder, dataset->maxval); diff --git a/storage/stonedb/compress/ppm.cpp b/storage/stonedb/compress/ppm.cpp index 78b64f536..d6f3ac063 100644 --- a/storage/stonedb/compress/ppm.cpp +++ b/storage/stonedb/compress/ppm.cpp @@ -30,13 +30,13 @@ FILE *PPM::dump = NULL; bool PPM::printstat = false; PPM::PPM(const Symb *data, int dlen, ModelType mt, PPMParam param, uchar method) { - if ((data == NULL) || (dlen <= 0) || (mt == ModelNull)) return; + if ((data == NULL) || (dlen <= 0) || (mt == ModelType::ModelNull)) return; switch (mt) { - case ModelSufTree: + case ModelType::ModelSufTree: model.reset(new SuffixTree<>(data, dlen)); break; - case ModelWordGraph: + case ModelType::ModelWordGraph: model.reset(new WordGraph(data, dlen, method == 2)); break; default: @@ -54,11 +54,11 @@ CprsErr PPM::CompressArith(char *dest, int &dlen, Symb *src, int slen) { // null PPM model if (!model) { - if (dlen < slen + 1) return CPRS_ERR_BUF; + if (dlen < slen + 1) return CprsErr::CPRS_ERR_BUF; dest[0] = 0; // method: no compression std::memcpy(dest + 1, src, slen); dlen = slen + 1; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } WordGraph *wg = NULL; try { @@ -149,23 +149,23 @@ CprsErr PPM::CompressArith(char *dest, int &dlen, Symb *src, int slen) { std::memcpy(dest + 1, src, slen); clen = slen + 1; } else if (overflow) - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; dlen = clen; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr PPM::DecompressArith(Symb *dest, int dlen, char *src, int slen) { - // if(slen < 1) return CPRS_ERR_BUF; + // if(slen < 1) return CprsErr::CPRS_ERR_BUF; // uchar method = (uchar) src[0]; // //// are the data simply copied, without compression? // if(method == 0) { - // if(dlen != slen - 1) return CPRS_ERR_PAR; + // if(dlen != slen - 1) return CprsErr::CPRS_ERR_PAR; // std::memcpy(dest, src + 1, dlen); - // return CPRS_SUCCESS; + // return CprsErr::CPRS_SUCCESS; //} - // if(method != 1) return CPRS_ERR_VER; + // if(method != 1) return CprsErr::CPRS_ERR_VER; WordGraph *wg = NULL; try { @@ -198,7 +198,7 @@ CprsErr PPM::DecompressArith(Symb *dest, int dlen, char *src, int slen) { len = dlen - i; err = model->Move(c, dest + i, len, rng); - if (err) return err; + if (static_cast(err)) return err; i += len; // model->FindEdgeC(stt, edge, c); @@ -214,17 +214,17 @@ CprsErr PPM::DecompressArith(Symb *dest, int dlen, char *src, int slen) { // len = dlen - i; // err = model->GetLabel(stt, edge, dest + i, len); - // if(err) + // if(static_cast(err)) // return err; // i += len; // model->Move(stt, edge); } } catch (ErrBufOverrun &) { - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr PPM::Compress(char *dest, int &dlen, Symb *src, int slen) { @@ -232,18 +232,18 @@ CprsErr PPM::Compress(char *dest, int &dlen, Symb *src, int slen) { // null PPM model if (!model) { - if (dlen < slen + 1) return CPRS_ERR_BUF; + if (dlen < slen + 1) return CprsErr::CPRS_ERR_BUF; dest[0] = 0; // method: no compression std::memcpy(dest + 1, src, slen); dlen = slen + 1; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } // try { // WordGraph* wg = dynamic_cast(model); // if(wg) wg->insatend = true; //} catch(...){} - if (dlen < 1) return CPRS_ERR_BUF; + if (dlen < 1) return CprsErr::CPRS_ERR_BUF; dest[0] = 2; // compression method: with RangeCoder WordGraph *wg = NULL; @@ -278,7 +278,7 @@ CprsErr PPM::Compress(char *dest, int &dlen, Symb *src, int slen) { coder.EndCompress(); clen = 1 + (int)coder.GetPos(); } catch (CprsErr &e) { - if (e == CPRS_ERR_BUF) + if (e == CprsErr::CPRS_ERR_BUF) overflow = true; else throw; @@ -291,24 +291,24 @@ CprsErr PPM::Compress(char *dest, int &dlen, Symb *src, int slen) { std::memcpy(dest + 1, src, slen); clen = slen + 1; } else if (overflow) - return CPRS_ERR_BUF; + return CprsErr::CPRS_ERR_BUF; dlen = clen; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr PPM::Decompress(Symb *dest, int dlen, char *src, int slen) { - if (slen < 1) return CPRS_ERR_BUF; + if (slen < 1) return CprsErr::CPRS_ERR_BUF; uchar method = (uchar)src[0]; // are the data simply copied, without compression? if (method == 0) { - if (dlen != slen - 1) return CPRS_ERR_PAR; + if (dlen != slen - 1) return CprsErr::CPRS_ERR_PAR; std::memcpy(dest, src + 1, dlen); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } else if (method == 1) return DecompressArith(dest, dlen, src, slen); - if (method != 2) return CPRS_ERR_VER; + if (method != 2) return CprsErr::CPRS_ERR_VER; WordGraph *wg = NULL; try { @@ -336,7 +336,7 @@ CprsErr PPM::Decompress(Symb *dest, int dlen, char *src, int slen) { len = dlen - i; err = model->Move(c, dest + i, len, rng); - if (err) return err; + if (static_cast(err)) return err; i += len; coder.Decode(rng.low, rng.high - rng.low, total); @@ -344,9 +344,9 @@ CprsErr PPM::Decompress(Symb *dest, int dlen, char *src, int slen) { } catch (CprsErr &e) { return e; } - // catch(BufOverException) { return CPRS_ERR_BUF; } + // catch(BufOverException) { return CprsErr::CPRS_ERR_BUF; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } void PPM::PrintInfo(std::ostream &str) { str << "No. of all nodes in the model: " << model->GetNNodes() << std::endl; } diff --git a/storage/stonedb/compress/ppm.h b/storage/stonedb/compress/ppm.h index 974406c9f..59336abd7 100644 --- a/storage/stonedb/compress/ppm.h +++ b/storage/stonedb/compress/ppm.h @@ -35,7 +35,7 @@ class PPM { CprsErr DecompressArith(Symb *dest, int dlen, char *src, int slen); public: - enum ModelType { ModelNull, ModelSufTree, ModelWordGraph }; + enum class ModelType { ModelNull, ModelSufTree, ModelWordGraph }; // enum CoderType { CoderArith, CoderRange }; static FILE *dump; @@ -49,7 +49,7 @@ class PPM { // 'dlen' - max size of 'dest'; upon exit: actual size of 'dest'. // 'dlen' should be at least slen+1 - in this case buffer overflow will never - // occur Otherwise the return value should be checked against CPRS_ERR_BUF. + // occur Otherwise the return value should be checked against CprsErr::CPRS_ERR_BUF. // The last symbol of 'src' must be '\0'. CprsErr Compress(char *dest, int &dlen, Symb *src, int slen); diff --git a/storage/stonedb/compress/range_code.h b/storage/stonedb/compress/range_code.h index 781c1b3b2..b8b6614ae 100644 --- a/storage/stonedb/compress/range_code.h +++ b/storage/stonedb/compress/range_code.h @@ -43,11 +43,11 @@ class RangeCoder { static const uint uni_total = 1u << uni_nbit; uchar InByte() { - if (pos >= stop) throw CPRS_ERR_BUF; + if (pos >= stop) throw CprsErr::CPRS_ERR_BUF; return *pos++; } void OutByte(uchar c) { - if (pos >= stop) throw CPRS_ERR_BUF; + if (pos >= stop) throw CprsErr::CPRS_ERR_BUF; *pos++ = c; } @@ -91,7 +91,7 @@ class RangeCoder { DEBUG_ASSERT(range >= BOT && low + range - 1 >= code && code >= low); uint tmp = (code - low) / (range /= total); DEBUG_ASSERT(tmp < total); - if (tmp >= total) throw CPRS_ERR_COR; + if (tmp >= total) throw CprsErr::CPRS_ERR_COR; return tmp; } @@ -119,7 +119,7 @@ class RangeCoder { #endif DEBUG_ASSERT(range >= BOT && low + range - 1 >= code && code >= low); uint tmp = (code - low) / (range _SHR_ASSIGN_ shift); - if (tmp >= (1u << shift)) throw CPRS_ERR_COR; + if (tmp >= (1u << shift)) throw CprsErr::CPRS_ERR_COR; return tmp; } diff --git a/storage/stonedb/compress/suffix_tree.cpp b/storage/stonedb/compress/suffix_tree.cpp index b64c17f68..d6e0c1292 100644 --- a/storage/stonedb/compress/suffix_tree.cpp +++ b/storage/stonedb/compress/suffix_tree.cpp @@ -641,20 +641,20 @@ template CprsErr SuffixTree::GetLabel(Edge e, Symb *lbl, int &len) { if (e.n == NIL) { len = 0; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } if (e.n == ROOT) { - if (len < 1) return CPRS_ERR_BUF; + if (len < 1) return CprsErr::CPRS_ERR_BUF; *lbl = e.s; len = 1; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } Node &n = GetNode(e.n); - if (len < n.len) return CPRS_ERR_BUF; + if (len < n.len) return CprsErr::CPRS_ERR_BUF; len = n.len; std::memcpy(lbl, data.get() + n.pos, len); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } template @@ -695,10 +695,10 @@ CprsErr SuffixTree::Move(Count c, Symb *str, int &len, Range &rng) Edge e{NIL, 0}; FindEdge(e, c); CprsErr err = GetLabel(e, str, len); - if (err) return err; + if (static_cast(err)) return err; GetRange(state, e, rng); Move(e); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } template class SuffixTree; diff --git a/storage/stonedb/compress/text_compressor.cpp b/storage/stonedb/compress/text_compressor.cpp index 8b15738dd..77c90e6c6 100644 --- a/storage/stonedb/compress/text_compressor.cpp +++ b/storage/stonedb/compress/text_compressor.cpp @@ -92,23 +92,23 @@ void TextCompressor::SetParams(PPMParam &p, int ver, [[maybe_unused]] int lev, i } CprsErr TextCompressor::CompressCopy(char *dest, int &dlen, char *src, int slen) { - if (dlen <= slen) return CPRS_ERR_BUF; + if (dlen <= slen) return CprsErr::CPRS_ERR_BUF; dest[0] = 0; // method: no compression std::memcpy(dest + 1, src, slen); dlen = slen + 1; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::CompressCopy(char *dest, int &dlen, char **index, const uint *lens, int nrec) { dest[0] = 0; // method: no compression int dpos = 1; for (int i = 0; i < nrec; i++) { - if (dpos + lens[i] > (uint)dlen) return CPRS_ERR_BUF; + if (dpos + lens[i] > (uint)dlen) return CprsErr::CPRS_ERR_BUF; std::memcpy(dest + dpos, index[i], lens[i]); dpos += lens[i]; } dlen = dpos; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::DecompressCopy(char *dest, int dlen, char *src, [[maybe_unused]] int slen, char **index, @@ -119,16 +119,16 @@ CprsErr TextCompressor::DecompressCopy(char *dest, int dlen, char *src, [[maybe_ index[i] = dest + sumlen; sumlen += lens[i]; } - if (sumlen > dlen) return CPRS_ERR_BUF; + if (sumlen > dlen) return CprsErr::CPRS_ERR_BUF; std::memcpy(dest, src, sumlen); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } //--------------------------------------------------------------------------------------------------------- CprsErr TextCompressor::CompressPlain(char *dest, int &dlen, char *src, int slen, int ver, int lev) { - if ((dest == NULL) || (src == NULL) || (dlen <= 0) || (slen <= 0)) return CPRS_ERR_PAR; - if ((ver < 0) || (ver > 2) || (lev < 1) || (lev > 9)) return CPRS_ERR_VER; + if ((dest == NULL) || (src == NULL) || (dlen <= 0) || (slen <= 0)) return CprsErr::CPRS_ERR_PAR; + if ((ver < 0) || (ver > 2) || (lev < 1) || (lev > 9)) return CprsErr::CPRS_ERR_VER; if (ver == 0) return CompressCopy(dest, dlen, src, slen); @@ -136,7 +136,7 @@ CprsErr TextCompressor::CompressPlain(char *dest, int &dlen, char *src, int slen dest[0] = (char)ver; dest[1] = (char)lev; int dpos = 2; - CprsErr err = CPRS_SUCCESS; + CprsErr err = CprsErr::CPRS_SUCCESS; // PPM if ((ver == 1) || (ver == 2)) { @@ -149,14 +149,14 @@ CprsErr TextCompressor::CompressPlain(char *dest, int &dlen, char *src, int slen int *dpos_tab = (int *)(dest + dpos); dpos += n * sizeof(int); - PPM::ModelType mt = ((ver == 1) ? PPM::ModelSufTree : PPM::ModelWordGraph); + PPM::ModelType mt = ((ver == 1) ? PPM::ModelType::ModelSufTree : PPM::ModelType::ModelWordGraph); // loop: build next PPM model, compress next part of the data for (int i = 0; i < n; i++) { PPM ppm((uchar *)src, split[i], mt, param); clen = dlen - dpos; err = ppm.Compress(dest + dpos, clen, (uchar *)src + split[i], split[i + 1] - split[i]); - if (err) break; + if (static_cast(err)) break; dpos_tab[i] = dpos; dpos += clen; @@ -164,26 +164,27 @@ CprsErr TextCompressor::CompressPlain(char *dest, int &dlen, char *src, int slen } // is it better to simply copy the source data? - if (((err == CPRS_ERR_BUF) || (dpos >= slen)) && (dlen >= slen + 1)) return CompressCopy(dest, dlen, src, slen); + if (((err == CprsErr::CPRS_ERR_BUF) || (dpos >= slen)) && (dlen >= slen + 1)) + return CompressCopy(dest, dlen, src, slen); dlen = dpos; return err; } CprsErr TextCompressor::DecompressPlain(char *dest, int dlen, char *src, int slen) { - if ((dest == NULL) || (src == NULL) || (dlen <= 0) || (slen <= 0)) return CPRS_ERR_PAR; - if (slen < 2) return CPRS_ERR_BUF; + if ((dest == NULL) || (src == NULL) || (dlen <= 0) || (slen <= 0)) return CprsErr::CPRS_ERR_PAR; + if (slen < 2) return CprsErr::CPRS_ERR_BUF; char ver = src[0], lev = (ver > 0) ? src[1] : 1; int spos = (ver > 0) ? 2 : 1; - if ((ver < 0) || (ver > 2) || (lev < 1) || (lev > 9)) return CPRS_ERR_VER; + if ((ver < 0) || (ver > 2) || (lev < 1) || (lev > 9)) return CprsErr::CPRS_ERR_VER; // are the data simply copied, without compression? if (ver == 0) { - if (dlen != slen - 1) return CPRS_ERR_PAR; + if (dlen != slen - 1) return CprsErr::CPRS_ERR_PAR; std::memcpy(dest, src + 1, dlen); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } PPMParam param; @@ -195,19 +196,19 @@ CprsErr TextCompressor::DecompressPlain(char *dest, int dlen, char *src, int sle parts.resize(n + 1); for (int j = 0; j < n; j++, spos += sizeof(int)) parts[j] = *(int *)(src + spos); parts[n] = slen; - if (parts[n] < parts[n - 1]) return CPRS_ERR_BUF; + if (parts[n] < parts[n - 1]) return CprsErr::CPRS_ERR_BUF; - PPM::ModelType mt = ((ver == 1) ? PPM::ModelSufTree : PPM::ModelWordGraph); + PPM::ModelType mt = ((ver == 1) ? PPM::ModelType::ModelSufTree : PPM::ModelType::ModelWordGraph); CprsErr err; // loop: build next PPM model, decompress next part of the data for (int i = 0; i < n; i++) { PPM ppm((uchar *)dest, split[i], mt, param, (uchar)src[parts[i]]); err = ppm.Decompress((uchar *)dest + split[i], split[i + 1] - split[i], src + parts[i], parts[i + 1] - parts[i]); - if (err) return err; + if (static_cast(err)) return err; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::CompressVer2(char *dest, int &dlen, char **index, const uint *lens, int nrec, int ver, @@ -216,8 +217,8 @@ CprsErr TextCompressor::CompressVer2(char *dest, int &dlen, char **index, const // '0' -> '1' (zero may occur frequently and should be encoded as a // single symbol) '1' -> '2' '1' '2' -> '2' '2' - if ((!dest) || (!index) || (!lens) || (dlen <= 0) || (nrec <= 0)) return CPRS_ERR_PAR; - if (dlen < 5) return CPRS_ERR_BUF; + if ((!dest) || (!index) || (!lens) || (dlen <= 0) || (nrec <= 0)) return CprsErr::CPRS_ERR_PAR; + if (dlen < 5) return CprsErr::CPRS_ERR_BUF; // how much memory to allocate for encoded data int mem = 0, /*stop,*/ i; @@ -304,15 +305,15 @@ CprsErr TextCompressor::CompressVer2(char *dest, int &dlen, char **index, const CprsErr TextCompressor::DecompressVer2(char *dest, int dlen, char *src, int slen, char **index, const uint * /*lens*/, int nrec) { - if ((!dest) || (!src) /*|| (!index) */ || (slen <= 0) || (nrec <= 0)) return CPRS_ERR_PAR; - if (slen < 5) return CPRS_ERR_BUF; + if ((!dest) || (!src) /*|| (!index) */ || (slen <= 0) || (nrec <= 0)) return CprsErr::CPRS_ERR_PAR; + if (slen < 5) return CprsErr::CPRS_ERR_BUF; // is data encoded? - if (src[0] != 1) return CPRS_ERR_VER; + if (src[0] != 1) return CprsErr::CPRS_ERR_VER; int spos = 1; // get size of encoded data - if (slen < spos + 4) return CPRS_ERR_BUF; + if (slen < spos + 4) return CprsErr::CPRS_ERR_BUF; int sdata = *(int *)(src + spos); spos += 4; @@ -320,7 +321,7 @@ CprsErr TextCompressor::DecompressVer2(char *dest, int dlen, char *src, int slen // decompress CprsErr err = DecompressPlain(data.get(), sdata, src + spos, slen - spos); - if (err) { + if (static_cast(err)) { return err; } @@ -338,7 +339,7 @@ CprsErr TextCompressor::DecompressVer2(char *dest, int dlen, char *src, int slen } if (pdst >= dlen) { - err = CPRS_ERR_BUF; + err = CprsErr::CPRS_ERR_BUF; break; } if ((uint)s > 2) @@ -347,27 +348,27 @@ CprsErr TextCompressor::DecompressVer2(char *dest, int dlen, char *src, int slen dest[pdst++] = '\0'; else { if (pdat >= sdata) { - err = CPRS_ERR_OTH; + err = CprsErr::CPRS_ERR_OTH; break; } s = data[pdat++]; if ((s == '\1') || (s == '\2')) dest[pdst++] = s; else { - err = CPRS_ERR_OTH; + err = CprsErr::CPRS_ERR_OTH; break; } } } - if (err) return err; - if (i != PermFirst(nrec)) return CPRS_ERR_OTH; - return CPRS_SUCCESS; + if (static_cast(err)) return err; + if (i != PermFirst(nrec)) return CprsErr::CPRS_ERR_OTH; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::CompressVer4(char *dest, int &dlen, char **index, const uint *lens, int nrec, [[maybe_unused]] int ver, [[maybe_unused]] int lev, uint packlen) { - if ((!dest) || (!index) || (!lens) || (dlen <= 0) || (nrec <= 0) || (packlen <= 0)) return CPRS_ERR_PAR; + if ((!dest) || (!index) || (!lens) || (dlen <= 0) || (nrec <= 0) || (packlen <= 0)) return CprsErr::CPRS_ERR_PAR; int length = 0; int pos = 0; auto srcdata = std::make_unique(packlen); @@ -380,26 +381,26 @@ CprsErr TextCompressor::CompressVer4(char *dest, int &dlen, char **index, const const int cmpBytes = LZ4_compress(srcdata.get(), dest + pos, length); if (cmpBytes <= 0 || cmpBytes > dlen - pos) { - STONEDB_LOG(ERROR, "CompressVer4 error,cmpBytes: %d dlen - pos = %d", cmpBytes, dlen - pos); - return CPRS_ERR_OTH; + STONEDB_LOG(LogCtl_Level::ERROR, "CompressVer4 error,cmpBytes: %d dlen - pos = %d", cmpBytes, dlen - pos); + return CprsErr::CPRS_ERR_OTH; } *(int *)(dest) = (int)cmpBytes; // store size of encoded data dlen = cmpBytes + 4; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::DecompressVer4(char *dest, int dlen, char *src, int slen, char **index, const uint *lens, int nrec) { int spos = 0; - if ((!dest) || (!src) || (slen <= 0) || (nrec <= 0)) return CPRS_ERR_PAR; + if ((!dest) || (!src) || (slen <= 0) || (nrec <= 0)) return CprsErr::CPRS_ERR_PAR; int datalen = *(int *)(src); spos += 4; const int decBytes = LZ4_decompress_safe(src + spos, dest, datalen, dlen); if (decBytes <= 0 || decBytes > dlen) { - STONEDB_LOG(ERROR, "DecompressVer4 error,decBytes: %d dlen = %d", decBytes, dlen); - return CPRS_ERR_OTH; + STONEDB_LOG(LogCtl_Level::ERROR, "DecompressVer4 error,decBytes: %d dlen = %d", decBytes, dlen); + return CprsErr::CPRS_ERR_OTH; } size_t sumlen = 0; @@ -407,11 +408,11 @@ CprsErr TextCompressor::DecompressVer4(char *dest, int dlen, char *src, int slen index[i] = dest + sumlen; sumlen += lens[i]; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::CompressZlib(char *dest, int &dlen, char **index, const uint *lens, int nrec, uint packlen) { - if ((!dest) || (!index) || (!lens) || (dlen <= 4) || (nrec <= 0) || (packlen == 0)) return CPRS_ERR_PAR; + if ((!dest) || (!index) || (!lens) || (dlen <= 4) || (nrec <= 0) || (packlen == 0)) return CprsErr::CPRS_ERR_PAR; uint64_t srclen = 0; std::unique_ptr srcdata(new unsigned char[packlen]); for (int i = 0; i < nrec; i++) { @@ -423,38 +424,39 @@ CprsErr TextCompressor::CompressZlib(char *dest, int &dlen, char **index, const uint64_t destlen = dlen - pos; int ret = compress2(reinterpret_cast(dest + pos), &destlen, srcdata.get(), srclen, Z_DEFAULT_COMPRESSION); if (ret != Z_OK) { - STONEDB_LOG(ERROR, "compress2 failure %d, destlen: %d, srclen %d, packlen %u", ret, destlen, srclen, packlen); - return CPRS_ERR_OTH; + STONEDB_LOG(LogCtl_Level::ERROR, "compress2 failure %d, destlen: %d, srclen %d, packlen %u", ret, destlen, srclen, + packlen); + return CprsErr::CPRS_ERR_OTH; } *(reinterpret_cast(dest)) = static_cast(destlen); dlen = destlen + pos; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::DecompressZlib(char *dest, int dlen, char *src, int slen, char **index, const uint *lens, int nrec) { - if ((!dest) || (!src) || (slen <= 0) || (nrec <= 0)) return CPRS_ERR_PAR; + if ((!dest) || (!src) || (slen <= 0) || (nrec <= 0)) return CprsErr::CPRS_ERR_PAR; uint64_t srclen = *(reinterpret_cast(src)); uint32_t spos = 4; uint64_t destlen = dlen; const int ret = uncompress(reinterpret_cast(dest), &destlen, reinterpret_cast(src + spos), srclen); if (ret != Z_OK) { - STONEDB_LOG(ERROR, "uncompress error: %d, srclen: %d destlen = %d", ret, srclen, dlen); - return CPRS_ERR_OTH; + STONEDB_LOG(LogCtl_Level::ERROR, "uncompress error: %d, srclen: %d destlen = %d", ret, srclen, dlen); + return CprsErr::CPRS_ERR_OTH; } size_t sumlen = 0; for (int i = 0; i < nrec; i++) { index[i] = dest + sumlen; sumlen += lens[i]; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } CprsErr TextCompressor::Compress(char *dest, int &dlen, char **index, const uint *lens, int nrec, uint &packlen, int ver, int lev) { - if ((!dest) || (!index) || (!lens) || (dlen <= 0) || (nrec <= 0)) return CPRS_ERR_PAR; - if ((ver < 0) || (ver > MAXVER) || (lev < 1) || (lev > 9)) return CPRS_ERR_VER; + if ((!dest) || (!index) || (!lens) || (dlen <= 0) || (nrec <= 0)) return CprsErr::CPRS_ERR_PAR; + if ((ver < 0) || (ver > MAXVER) || (lev < 1) || (lev > 9)) return CprsErr::CPRS_ERR_VER; int slen = packlen; @@ -462,7 +464,7 @@ CprsErr TextCompressor::Compress(char *dest, int &dlen, char **index, const uint dest[0] = 0; // not encoded int dpos = 1; - CprsErr err = CPRS_SUCCESS; + CprsErr err = CprsErr::CPRS_SUCCESS; if (ver == 0) { dlen -= dpos; @@ -498,7 +500,7 @@ CprsErr TextCompressor::Compress(char *dest, int &dlen, char **index, const uint } // check if copy compression is better - if (((err == CPRS_ERR_BUF) || (dpos >= slen)) && (dlen >= slen + 2)) { + if (((err == CprsErr::CPRS_ERR_BUF) || (dpos >= slen)) && (dlen >= slen + 2)) { dpos = 1; // leave first byte of the header dlen -= dpos; err = CompressCopy(dest + dpos, dlen, index, lens, nrec); @@ -513,8 +515,8 @@ CprsErr TextCompressor::Compress(char *dest, int &dlen, char **index, const uint CprsErr TextCompressor::Decompress(char *dest, int dlen, char *src, int slen, char **index, const uint *lens, int nrec) { MEASURE_FET("TextCompressor::Decompress(...)"); - if ((!dest) || (!src) || (!index) || (slen <= 0) || (nrec <= 0)) return CPRS_ERR_PAR; - if (slen < 2) return CPRS_ERR_BUF; + if ((!dest) || (!src) || (!index) || (slen <= 0) || (nrec <= 0)) return CprsErr::CPRS_ERR_PAR; + if (slen < 2) return CprsErr::CPRS_ERR_BUF; // old versions if (src[0]) return DecompressVer2(dest, dlen, src, slen, index, lens, nrec); @@ -525,7 +527,7 @@ CprsErr TextCompressor::Decompress(char *dest, int dlen, char *src, int slen, ch if (ver == 0) return DecompressCopy(dest, dlen, src + spos, slen - spos, index, lens, nrec); // Version 3 - if (slen <= spos) return CPRS_ERR_BUF; + if (slen <= spos) return CprsErr::CPRS_ERR_BUF; char lev = src[spos++]; // add lz4 decompress if (ver == 4) @@ -533,13 +535,13 @@ CprsErr TextCompressor::Decompress(char *dest, int dlen, char *src, int slen, ch else if (ver == static_cast(common::PackFmt::ZLIB)) return DecompressZlib(dest, dlen, src + spos, slen - spos, index, lens, nrec); - if ((ver != 3) || (lev < 1) || (lev > 9)) return CPRS_ERR_VER; + if ((ver != 3) || (lev < 1) || (lev > 9)) return CprsErr::CPRS_ERR_VER; // check if 'dlen' is large enough // int sumlen = 0; // for(int i = 0; i < nrec; i++) // sumlen += lens[i]; - // if(sumlen > dlen) return CPRS_ERR_BUF; + // if(sumlen > dlen) return CprsErr::CPRS_ERR_BUF; // decompress with IncWGraph try { @@ -549,7 +551,7 @@ CprsErr TextCompressor::Decompress(char *dest, int dlen, char *src, int slen, ch } catch (CprsErr &e) { return e; } - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } } // namespace compress diff --git a/storage/stonedb/compress/top_bit_dict.cpp b/storage/stonedb/compress/top_bit_dict.cpp index e75cb1c28..90c52c300 100644 --- a/storage/stonedb/compress/top_bit_dict.cpp +++ b/storage/stonedb/compress/top_bit_dict.cpp @@ -106,7 +106,7 @@ uint TopBitDict::FindOptimum(DataSet *dataset, uint nbit, uint &opt_bit, D template inline bool TopBitDict::Insert(Dictionary *dict, T *data, uint nbit, uint bit, uint nrec, uint skiprec) { dict->InitInsert(); - if (topbottom == tbTop) { // top bits + if (topbottom == TopBottom::tbTop) { // top bits uchar bitlow = (uchar)(nbit - bit); DEBUG_ASSERT(bitlow < sizeof(T) * 8); for (uint i = 0; i < nrec; i += skiprec) @@ -138,13 +138,13 @@ bool TopBitDict::Encode(RangeCoder *coder, DataSet *dataset) { coder->EncodeUniform((uchar)0, (uchar)7); // save no. of lower bits - bitlow = (topbottom == tbTop) ? (T)(nbit - bitdict) : (T)bitdict; + bitlow = (topbottom == TopBottom::tbTop) ? (T)(nbit - bitdict) : (T)bitdict; coder->EncodeUniform(bitlow, (T)64); // save dictionary DEBUG_ASSERT(bitlow < sizeof(maxval) * 8); T maxhigh = maxval >> bitlow, maxlow = ((T)1 _SHL_ bitlow) - (T)1; - T dictmax = (topbottom == tbTop) ? maxhigh : maxlow; + T dictmax = (topbottom == TopBottom::tbTop) ? maxhigh : maxlow; dict->Save(coder, dictmax); IFSTAT(uint pos1 = coder->GetPos()); @@ -155,7 +155,7 @@ bool TopBitDict::Encode(RangeCoder *coder, DataSet *dataset) { // encode data DEBUG_ASSERT(bitlow < sizeof(T) * 8); - if (topbottom == tbTop) + if (topbottom == TopBottom::tbTop) for (uint i = 0; i < nrec; i++) { esc = dict->Encode(coder, data[i] >> bitlow); ASSERT(!esc, "TOP encode failed"); @@ -169,7 +169,7 @@ bool TopBitDict::Encode(RangeCoder *coder, DataSet *dataset) { } IFSTAT(codesize[1] = coder->GetPos() - pos1); - dataset->maxval = (topbottom == tbTop) ? maxlow : maxhigh; + dataset->maxval = (topbottom == TopBottom::tbTop) ? maxlow : maxhigh; return true; } @@ -178,7 +178,7 @@ void TopBitDict::Decode(RangeCoder *coder, DataSet *dataset) { // read version uchar ver; coder->DecodeUniform(ver, (uchar)7); - if (ver > 0) throw CPRS_ERR_COR; + if (ver > 0) throw CprsErr::CPRS_ERR_COR; // read no. of lower bits coder->DecodeUniform(bitlow, (T)64); @@ -187,7 +187,7 @@ void TopBitDict::Decode(RangeCoder *coder, DataSet *dataset) { Dictionary *dict = counters; DEBUG_ASSERT(bitlow < sizeof(dataset->maxval) * 8); T maxhigh = dataset->maxval >> bitlow, maxlow = ((T)1 _SHL_ bitlow) - (T)1; - T dictmax = (topbottom == tbTop) ? maxhigh : maxlow; + T dictmax = (topbottom == TopBottom::tbTop) ? maxhigh : maxlow; dict->Load(coder, dictmax); // decode data @@ -199,7 +199,7 @@ void TopBitDict::Decode(RangeCoder *coder, DataSet *dataset) { } maxval_merge = dataset->maxval; - dataset->maxval = (topbottom == tbTop) ? maxlow : maxhigh; + dataset->maxval = (topbottom == TopBottom::tbTop) ? maxlow : maxhigh; } template @@ -207,7 +207,7 @@ void TopBitDict::Merge(DataSet *dataset) { T *data = dataset->data; uint nrec = dataset->nrec; DEBUG_ASSERT(bitlow < sizeof(T) * 8); - if (topbottom == tbTop) + if (topbottom == TopBottom::tbTop) for (uint i = 0; i < nrec; i++) data[i] |= decoded[i] << bitlow; else for (uint i = 0; i < nrec; i++) (data[i] <<= bitlow) |= decoded[i]; diff --git a/storage/stonedb/compress/top_bit_dict.h b/storage/stonedb/compress/top_bit_dict.h index 1e38fcfe2..0d415be52 100644 --- a/storage/stonedb/compress/top_bit_dict.h +++ b/storage/stonedb/compress/top_bit_dict.h @@ -35,7 +35,7 @@ class TopBitDict : public DataFilt { static const uint BITSTEP = 2; static const uint KEYOCCUR = 8; static const double MINPREDICT; - enum TopBottom { tbTop, tbBottom }; // which part of bits is compressed + enum class TopBottom { tbTop, tbBottom }; // which part of bits is compressed private: const TopBottom topbottom; @@ -67,9 +67,9 @@ class TopBitDict : public DataFilt { virtual void LogCompress(FILE *f) { std::fprintf(f, "%u %u", this->codesize[0], this->codesize[1]); } public: - TopBitDict(bool top) : topbottom(top ? tbTop : tbBottom) {} + TopBitDict(bool top) : topbottom(top ? TopBottom::tbTop : TopBottom::tbBottom) {} virtual ~TopBitDict() = default; - char const *GetName() override { return topbottom == tbTop ? (char *)"top" : (char *)"low"; } + char const *GetName() override { return topbottom == TopBottom::tbTop ? (char *)"top" : (char *)"low"; } bool Encode(RangeCoder *coder, DataSet *dataset) override; void Decode(RangeCoder *coder, DataSet *dataset) override; void Merge(DataSet *dataset) override; diff --git a/storage/stonedb/compress/word_graph.cpp b/storage/stonedb/compress/word_graph.cpp index fb70e6c30..ca0a7faee 100644 --- a/storage/stonedb/compress/word_graph.cpp +++ b/storage/stonedb/compress/word_graph.cpp @@ -664,11 +664,11 @@ void WordGraph::FindEdge(PEdge &e, PSEdge &se, Count c) { CprsErr WordGraph::GetLabel(PEdge e, [[maybe_unused]] Symb *lbl, int &len) { if (e == ENIL) { len = 0; - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } // "escape" Edge &edge = GE(e); - if (len < (int)edge.GetLen()) return CPRS_ERR_BUF; + if (len < (int)edge.GetLen()) return CprsErr::CPRS_ERR_BUF; len = (int)edge.GetLen(); // TODO:uncomment ROOT @@ -676,7 +676,7 @@ CprsErr WordGraph::GetLabel(PEdge e, [[maybe_unused]] Symb *lbl, int &len) { // NIL consider separately // else std::memcpy(lbl, data + GN(edge.n).endpos - len, len); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } void WordGraph::GetRange(PEdge e, [[maybe_unused]] PSEdge se, Range &r) { @@ -773,10 +773,10 @@ CprsErr WordGraph::Move(Count c, Symb *str, int &len, Range &rng) { PSEdge se; FindEdge(e, se, c); CprsErr err = GetLabel(e, str, len); - if (err) return err; + if (static_cast(err)) return err; GetRange(e, se, rng); Move(e); - return CPRS_SUCCESS; + return CprsErr::CPRS_SUCCESS; } // TODO: time - use incremental allocator IncAlloc diff --git a/storage/stonedb/core/aggregation_algorithm.cpp b/storage/stonedb/core/aggregation_algorithm.cpp index 2a8c45b0b..6f8c48753 100644 --- a/storage/stonedb/core/aggregation_algorithm.cpp +++ b/storage/stonedb/core/aggregation_algorithm.cpp @@ -828,7 +828,7 @@ void AggregationWorkerEnt::TaskAggrePacks(MIUpdatingIterator *taskIterator, [[ma if (grouping_result == 3 || grouping_result == 4) throw common::NotImplementedException("Aggregation overflow."); cur_tuple += packrow_length; } - STONEDB_LOG(DEBUG, "TaskAggrePacks routine ends. Task id %d", taskIterator->GetTaskNum()); + STONEDB_LOG(LogCtl_Level::DEBUG, "TaskAggrePacks routine ends. Task id %d", taskIterator->GetTaskNum()); } void AggregationWorkerEnt::PrepShardingCopy(MIIterator *mit, GroupByWrapper *gb_sharding, diff --git a/storage/stonedb/core/aggregator_advanced.cpp b/storage/stonedb/core/aggregator_advanced.cpp index 2daf422a5..4cca55f69 100644 --- a/storage/stonedb/core/aggregator_advanced.cpp +++ b/storage/stonedb/core/aggregator_advanced.cpp @@ -193,7 +193,7 @@ void AggregatorGroupConcat::PutAggregatedValue(unsigned char *buf, const types:: std::memcpy(buf + pos, src.c_str(), copylen); // append the separator it->second = it->second + copylen; // update the length of the buffer } else { - STONEDB_LOG(ERROR, + STONEDB_LOG(LogCtl_Level::ERROR, "Internal error for AggregatorGroupConcat: buffer length is " "%d, which beyond threshold %d.", pos, gconcat_maxlen); @@ -209,7 +209,7 @@ types::BString AggregatorGroupConcat::GetValueT(unsigned char *buf) { } int len = (it->second < gconcat_maxlen) ? it->second : gconcat_maxlen; - // STONEDB_LOG(INFO, "GetValueT: buf %s, buf addr %x, len %d", buf, buf, + // STONEDB_LOG(LogCtl_Level::INFO, "GetValueT: buf %s, buf addr %x, len %d", buf, buf, // len); if (len == 0) { types::BString res("", 0); @@ -254,7 +254,7 @@ types::BString AggregatorGroupConcat::GetValueT(unsigned char *buf) { std::ostringstream outbuf_stream; std::copy(vstr.begin(), vstr.end(), std::ostream_iterator(outbuf_stream, si.separator.c_str())); - // STONEDB_LOG(DEBUG, "buf %s, tmpbuf1 %s, pos %d, len %d \n", buf, + // STONEDB_LOG(LogCtl_Level::DEBUG, "buf %s, tmpbuf1 %s, pos %d, len %d \n", buf, // outbuf_stream.str().c_str(), pos, len); types::BString res(outbuf_stream.str().c_str(), len, true); diff --git a/storage/stonedb/core/aggregator_basic.cpp b/storage/stonedb/core/aggregator_basic.cpp index 9302ec755..022415e60 100644 --- a/storage/stonedb/core/aggregator_basic.cpp +++ b/storage/stonedb/core/aggregator_basic.cpp @@ -105,7 +105,8 @@ void AggregatorAvg64::PutAggregatedValue(unsigned char *buf, int64_t v, int64_t stats_updated = false; *((double *)buf) += double(v) * factor; if (!warning_issued && (*((double *)buf) > 9.223372037e+18 || *((double *)buf) < -9.223372037e+18)) { - common::PushWarning(current_tx->Thd(), Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, "Values rounded in average()"); + common::PushWarning(current_tx->Thd(), Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, + "Values rounded in average()"); warning_issued = true; } *((int64_t *)(buf + 8)) += factor; @@ -116,7 +117,8 @@ void AggregatorAvg64::Merge(unsigned char *buf, unsigned char *src_buf) { stats_updated = false; *((double *)buf) += *((double *)src_buf); if (!warning_issued && (*((double *)buf) > 9.223372037e+18 || *((double *)buf) < -9.223372037e+18)) { - common::PushWarning(current_tx->Thd(), Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, "Values rounded in average()"); + common::PushWarning(current_tx->Thd(), Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, + "Values rounded in average()"); warning_issued = true; } *((int64_t *)(buf + 8)) += *((int64_t *)(src_buf + 8)); diff --git a/storage/stonedb/core/bin_tools.cpp b/storage/stonedb/core/bin_tools.cpp index f02a0545c..6aa272c29 100644 --- a/storage/stonedb/core/bin_tools.cpp +++ b/storage/stonedb/core/bin_tools.cpp @@ -106,15 +106,15 @@ int64_t SafeMultiplication(int64_t x, } common::RSValue Or(common::RSValue f, common::RSValue s) { - if (f == common::RS_ALL || s == common::RS_ALL) return common::RS_ALL; - if (f == common::RS_SOME || s == common::RS_SOME) return common::RS_SOME; - return common::RS_NONE; + if (f == common::RSValue::RS_ALL || s == common::RSValue::RS_ALL) return common::RSValue::RS_ALL; + if (f == common::RSValue::RS_SOME || s == common::RSValue::RS_SOME) return common::RSValue::RS_SOME; + return common::RSValue::RS_NONE; } common::RSValue And(common::RSValue f, common::RSValue s) { - if (f == common::RS_ALL && s == common::RS_ALL) return common::RS_ALL; - if (f == common::RS_NONE || s == common::RS_NONE) return common::RS_NONE; - return common::RS_SOME; + if (f == common::RSValue::RS_ALL && s == common::RSValue::RS_ALL) return common::RSValue::RS_ALL; + if (f == common::RSValue::RS_NONE || s == common::RSValue::RS_NONE) return common::RSValue::RS_NONE; + return common::RSValue::RS_SOME; } int64_t MonotonicDouble2Int64(int64_t d) // encode double value (bitwise stored as int64_t) into @@ -290,7 +290,7 @@ uint HashValue(const void *data, for (; i < len; i++) val ^= uint(((char *)data)[i]) + 0x9e3779b9 + (val << 10) + (val >> 2); // in boost... there is "<< 6" here, but it // lead to too many collisions - val ^= (val >> 11) + (val << 21); // more hashing to prevent collisions + val ^= (val >> 11) + (val << 21); // more hashing to prevent collisions return val; } diff --git a/storage/stonedb/core/blocked_mem_table.cpp b/storage/stonedb/core/blocked_mem_table.cpp index 81b7fa487..25616b259 100644 --- a/storage/stonedb/core/blocked_mem_table.cpp +++ b/storage/stonedb/core/blocked_mem_table.cpp @@ -37,7 +37,7 @@ void *MemBlockManager::GetBlock() { p = free_blocks[free_blocks.size() - 1]; free_blocks.pop_back(); } else { - p = alloc(block_size, mm::BLOCK_TEMPORARY); + p = alloc(block_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); current_size += block_size; } used_blocks.insert(p); diff --git a/storage/stonedb/core/blocked_mem_table.h b/storage/stonedb/core/blocked_mem_table.h index 0cc038727..c4f7cda29 100644 --- a/storage/stonedb/core/blocked_mem_table.h +++ b/storage/stonedb/core/blocked_mem_table.h @@ -89,7 +89,7 @@ class MemBlockManager final : public mm::TraceableObject { */ void FreeBlock(void *b); - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } private: std::vector free_blocks; diff --git a/storage/stonedb/core/cached_buffer.cpp b/storage/stonedb/core/cached_buffer.cpp index 192effa8e..be8369835 100644 --- a/storage/stonedb/core/cached_buffer.cpp +++ b/storage/stonedb/core/cached_buffer.cpp @@ -27,7 +27,7 @@ CachedBuffer::CachedBuffer(uint page_size, uint _elem_size, Transaction *conn if (!elem_size) elem_size = sizeof(T); CI_SetDefaultSize(page_size * elem_size); - buf = (T *)alloc(sizeof(T) * (size_t)page_size, mm::BLOCK_TEMPORARY); + buf = (T *)alloc(sizeof(T) * (size_t)page_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); std::memset(buf, 0, sizeof(T) * (size_t)page_size); loaded_page = 0; page_changed = false; @@ -40,7 +40,7 @@ CachedBuffer::CachedBuffer(uint page_size, uint elem_size, Trans size_t buf_size = sizeof(char) * (size_t)page_size * (elem_size + 4); if (buf_size) { - buf = (char *)alloc(buf_size, mm::BLOCK_TEMPORARY); + buf = (char *)alloc(buf_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); std::memset(buf, 0, buf_size); } else buf = NULL; @@ -135,7 +135,7 @@ void CachedBuffer::SetNewPageSize(uint new_page_size) { // inside try{}) page_size = new_page_size; CI_SetDefaultSize(page_size * elem_size); - buf = (T *)rc_realloc(buf, sizeof(T) * (size_t)page_size, mm::BLOCK_TEMPORARY); + buf = (T *)rc_realloc(buf, sizeof(T) * (size_t)page_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); } void CachedBuffer::SetNewPageSize(uint new_page_size) { @@ -146,7 +146,7 @@ void CachedBuffer::SetNewPageSize(uint new_page_size) { page_size = new_page_size; CI_SetDefaultSize(page_size * (elem_size + 4)); size_t buf_size = (size_t)page_size * (elem_size + 4) * sizeof(char); - buf = (char *)rc_realloc(buf, buf_size, mm::BLOCK_TEMPORARY); + buf = (char *)rc_realloc(buf, buf_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); } template class CachedBuffer; diff --git a/storage/stonedb/core/cached_buffer.h b/storage/stonedb/core/cached_buffer.h index 0e31445c5..4ec33a148 100644 --- a/storage/stonedb/core/cached_buffer.h +++ b/storage/stonedb/core/cached_buffer.h @@ -49,7 +49,7 @@ class CachedBuffer : public system::CacheableItem, public mm::TraceableObject { } void Set(uint64_t idx, const T &value); - mm::TO_TYPE TraceableType() const override { return mm::TO_CACHEDBUFFER; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_CACHEDBUFFER; } protected: void LoadPage(uint n); // load page n @@ -80,7 +80,7 @@ class CachedBuffer : public system::CacheableItem, public mm::Tr void Get(types::BString &s, uint64_t idx); void Set(uint64_t idx, const types::BString &value); - mm::TO_TYPE TraceableType() const override { return mm::TO_CACHEDBUFFER; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_CACHEDBUFFER; } protected: void LoadPage(uint n); // load page n diff --git a/storage/stonedb/core/column_share.cpp b/storage/stonedb/core/column_share.cpp index e180a9220..21157a7e5 100644 --- a/storage/stonedb/core/column_share.cpp +++ b/storage/stonedb/core/column_share.cpp @@ -34,7 +34,7 @@ ColumnShare::~ColumnShare() { if (start != nullptr) { if (::munmap(start, common::COL_DN_FILE_SIZE) != 0) { // DO NOT throw in dtor! - STONEDB_LOG(WARN, "Failed to unmap DPN file. Error %d(%s)", errno, std::strerror(errno)); + STONEDB_LOG(LogCtl_Level::WARN, "Failed to unmap DPN file. Error %d(%s)", errno, std::strerror(errno)); } } if (dn_fd >= 0) ::close(dn_fd); @@ -137,7 +137,7 @@ void ColumnShare::scan_dpn(common::TX_ID xid) { start[i].synced = 1; start[i].xmax = common::MAX_XID; if (start[i].local) { - STONEDB_LOG(WARN, "uncommited pack found: %s %d", m_path.c_str(), i); + STONEDB_LOG(LogCtl_Level::WARN, "uncommited pack found: %s %d", m_path.c_str(), i); start[i].local = 0; } if (start[i].addr != DPN_INVALID_ADDR) { @@ -153,11 +153,11 @@ void ColumnShare::scan_dpn(common::TX_ID xid) { auto second = segs.cbegin(); for (auto first = second++; second != segs.cend(); ++first, ++second) { if (second->offset < first->offset + first->len) { - STONEDB_LOG(ERROR, "sorted beg: -------------------"); + STONEDB_LOG(LogCtl_Level::ERROR, "sorted beg: -------------------"); for (auto &it : segs) { - STONEDB_LOG(ERROR, " %u [%ld, %ld]", it.idx, it.offset, it.len); + STONEDB_LOG(LogCtl_Level::ERROR, " %u [%ld, %ld]", it.idx, it.offset, it.len); } - STONEDB_LOG(ERROR, "sorted end: -------------------"); + STONEDB_LOG(LogCtl_Level::ERROR, "sorted end: -------------------"); throw common::DatabaseException("bad DPN index file: " + m_path.string()); } } diff --git a/storage/stonedb/core/column_type.h b/storage/stonedb/core/column_type.h index 771766783..a7c29015b 100644 --- a/storage/stonedb/core/column_type.h +++ b/storage/stonedb/core/column_type.h @@ -26,7 +26,7 @@ namespace core { struct DataType; struct ColumnType { - enum { + enum class enumCT { NOT_NULL = 0, AUTO_INC = 1, BLOOM_FILTER = 2, @@ -42,14 +42,14 @@ struct ColumnType { display_size(ATI::TextSize(t, prec, sc, collation)), collation(collation), fmt(fmt) { - flag[NOT_NULL] = notnull; + flag[static_cast(enumCT::NOT_NULL)] = notnull; internal_size = InternalSize(); } void Initialize(common::CT t, bool notnull, common::PackFmt f, uint prec, int sc, DTCollation collation = DTCollation()) { type = t; - flag[NOT_NULL] = notnull; + flag[static_cast(enumCT::NOT_NULL)] = notnull; fmt = f; precision = prec; scale = sc; @@ -132,11 +132,11 @@ struct ColumnType { void SetFmt(common::PackFmt f) { fmt = f; } unsigned char GetFlag() const { return flag.to_ulong(); } void SetFlag(unsigned char v) { flag = std::bitset::digits>(v); } - bool NotNull() const { return flag[NOT_NULL]; } + bool NotNull() const { return flag[static_cast(enumCT::NOT_NULL)]; } bool Nullable() const { return !NotNull(); } - bool GetAutoInc() const { return flag[AUTO_INC]; } - void SetAutoInc(bool inc) { flag[AUTO_INC] = inc; } - bool HasFilter() const { return flag[BLOOM_FILTER]; } + bool GetAutoInc() const { return flag[static_cast(enumCT::AUTO_INC)]; } + void SetAutoInc(bool inc) { flag[static_cast(enumCT::AUTO_INC)] = inc; } + bool HasFilter() const { return flag[static_cast(enumCT::BLOOM_FILTER)]; } private: common::CT type; diff --git a/storage/stonedb/core/compilation_tools.cpp b/storage/stonedb/core/compilation_tools.cpp index ee6870d68..da6b33b8a 100644 --- a/storage/stonedb/core/compilation_tools.cpp +++ b/storage/stonedb/core/compilation_tools.cpp @@ -62,7 +62,7 @@ int OperationUnmysterify(Item *item, common::ColOperation &oper, bool &distinct, case Item::FUNC_ITEM: case Item::COND_ITEM: case Item::SUBSELECT_ITEM: - case Item_sdbfield::SDBFIELD_ITEM: + case static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM): case Item::FIELD_ITEM: // regular select oper = common::ColOperation::LISTING; /*GROUP_BY : LISTING;*/ break; @@ -115,7 +115,7 @@ int OperationUnmysterify(Item *item, common::ColOperation &oper, bool &distinct, break; case Item_sum::GROUP_CONCAT_FUNC: distinct = ((Item_func_group_concat *)item)->get_distinct(); - STONEDB_LOG(DEBUG, "group_concat distinct %d, sepertator %s, direction %d", distinct, + STONEDB_LOG(LogCtl_Level::DEBUG, "group_concat distinct %d, sepertator %s, direction %d", distinct, ((Item_func_group_concat *)item)->get_separator()->c_ptr(), ((Item_func_group_concat *)item)->direction()); oper = common::ColOperation::GROUP_CONCAT; @@ -176,7 +176,7 @@ void PrintItemTree(Item *item, int indent) { if ((int)type < sizeof(name_of) / sizeof(*name_of)) name = name_of[type]; else - name = "SDBFIELD_ITEM"; + name = "enumSDBFiledItem::SDBFIELD_ITEM"; const char *result = ""; switch (item->result_type()) { diff --git a/storage/stonedb/core/compiled_query.cpp b/storage/stonedb/core/compiled_query.cpp index 98710189d..afe449e1e 100644 --- a/storage/stonedb/core/compiled_query.cpp +++ b/storage/stonedb/core/compiled_query.cpp @@ -114,97 +114,97 @@ void CompiledQuery::CQStep::Print(Query *query) { char b_op[20]; switch (op) { - case common::O_EQ: + case common::Operator::O_EQ: std::strcpy(b_op, "="); break; - case common::O_EQ_ALL: + case common::Operator::O_EQ_ALL: std::strcpy(b_op, "=ALL"); break; - case common::O_EQ_ANY: + case common::Operator::O_EQ_ANY: std::strcpy(b_op, "=ANY"); break; - case common::O_NOT_EQ: + case common::Operator::O_NOT_EQ: std::strcpy(b_op, "<>"); break; - case common::O_NOT_EQ_ALL: + case common::Operator::O_NOT_EQ_ALL: std::strcpy(b_op, "<>ALL"); break; - case common::O_NOT_EQ_ANY: + case common::Operator::O_NOT_EQ_ANY: std::strcpy(b_op, "<>ANY"); break; - case common::O_LESS: + case common::Operator::O_LESS: std::strcpy(b_op, "<"); break; - case common::O_LESS_ALL: + case common::Operator::O_LESS_ALL: std::strcpy(b_op, ""); break; - case common::O_MORE_ALL: + case common::Operator::O_MORE_ALL: std::strcpy(b_op, ">ALL"); break; - case common::O_MORE_ANY: + case common::Operator::O_MORE_ANY: std::strcpy(b_op, ">ANY"); break; - case common::O_LESS_EQ: + case common::Operator::O_LESS_EQ: std::strcpy(b_op, "<="); break; - case common::O_LESS_EQ_ALL: + case common::Operator::O_LESS_EQ_ALL: std::strcpy(b_op, "<=ALL"); break; - case common::O_LESS_EQ_ANY: + case common::Operator::O_LESS_EQ_ANY: std::strcpy(b_op, "<=ANY"); break; - case common::O_MORE_EQ: + case common::Operator::O_MORE_EQ: std::strcpy(b_op, ">="); break; - case common::O_MORE_EQ_ALL: + case common::Operator::O_MORE_EQ_ALL: std::strcpy(b_op, ">=ALL"); break; - case common::O_MORE_EQ_ANY: + case common::Operator::O_MORE_EQ_ANY: std::strcpy(b_op, ">=ANY"); break; - case common::O_IS_NULL: + case common::Operator::O_IS_NULL: std::strcpy(b_op, "IS NULL"); break; - case common::O_NOT_NULL: + case common::Operator::O_NOT_NULL: std::strcpy(b_op, "IS NOT NULL"); break; - case common::O_BETWEEN: + case common::Operator::O_BETWEEN: std::strcpy(b_op, "BETWEEN"); break; - case common::O_IN: + case common::Operator::O_IN: std::strcpy(b_op, "IN"); break; - case common::O_LIKE: + case common::Operator::O_LIKE: std::strcpy(b_op, "LIKE"); break; - case common::O_ESCAPE: + case common::Operator::O_ESCAPE: std::strcpy(b_op, "ESCAPE"); break; - case common::O_EXISTS: + case common::Operator::O_EXISTS: std::strcpy(b_op, "EXISTS"); break; - case common::O_NOT_LIKE: + case common::Operator::O_NOT_LIKE: std::strcpy(b_op, "NOT LIKE"); break; - case common::O_NOT_BETWEEN: + case common::Operator::O_NOT_BETWEEN: std::strcpy(b_op, "NOT BETWEEN"); break; - case common::O_NOT_IN: + case common::Operator::O_NOT_IN: std::strcpy(b_op, "NOT IN"); break; - case common::O_NOT_EXISTS: + case common::Operator::O_NOT_EXISTS: std::strcpy(b_op, "NOT EXISTS"); break; - case common::O_FALSE: + case common::Operator::O_FALSE: std::strcpy(b_op, "FALSE"); break; - case common::O_TRUE: + case common::Operator::O_TRUE: std::strcpy(b_op, "TRUE"); break; default: @@ -267,39 +267,39 @@ void CompiledQuery::CQStep::Print(Query *query) { std::strcpy(b_cop, "[no name yet]"); } - char b_tmpar[20]; // enum TMParameter { TM_DISTINCT, TM_TOP, - // TM_EXISTS, TM_COUNT }; + char b_tmpar[20]; // enum TMParameter { TMParameter::TM_DISTINCT, TMParameter::TM_TOP, + // TMParameter::TM_EXISTS, TM_COUNT }; // // Table Mode switch (tmpar) { - case TM_DISTINCT: + case TMParameter::TM_DISTINCT: std::strcpy(b_tmpar, "DISTINCT"); break; - case TM_TOP: + case TMParameter::TM_TOP: std::strcpy(b_tmpar, "LIMIT"); break; - case TM_EXISTS: + case TMParameter::TM_EXISTS: std::strcpy(b_tmpar, "EXISTS"); break; default: std::strcpy(b_tmpar, "???"); } - char b_jt[20]; // enum JoinType { JO_INNER, JO_LEFT, - // JO_RIGHT, JO_FULL + char b_jt[20]; // enum JoinType { JoinType::JO_INNER, JoinType::JO_LEFT, + // JoinType::JO_RIGHT, JoinType::JO_FULL // }; switch (jt) { - case JO_INNER: + case JoinType::JO_INNER: std::strcpy(b_jt, "INNER"); break; - case JO_LEFT: + case JoinType::JO_LEFT: std::strcpy(b_jt, "LEFT"); break; - case JO_RIGHT: + case JoinType::JO_RIGHT: std::strcpy(b_jt, "RIGHT"); break; - case JO_FULL: + case JoinType::JO_FULL: std::strcpy(b_jt, "FULL"); break; default: @@ -307,15 +307,16 @@ void CompiledQuery::CQStep::Print(Query *query) { } switch (type) { - case TABLE_ALIAS: + case StepType::TABLE_ALIAS: if (alias) std::sprintf(buf, "T:%d = TABLE_ALIAS(T:%d,\"%s\")", N(t1.n), N(t2.n), alias); else std::sprintf(buf, "T:%d = TABLE_ALIAS(T:%d)", N(t1.n), N(t2.n)); break; - case CREATE_CONDS: + case StepType::CREATE_CONDS: if (c2.IsNull()) { - std::sprintf(buf, "C:%d = CREATE_%sCONDS(T:%d,%s,%s,%s,%s)", N(c1.n), n1 == OR_SUBTREE ? "TREE_" : "", N(t1.n), + std::sprintf(buf, "C:%d = CREATE_%sCONDS(T:%d,%s,%s,%s,%s)", N(c1.n), + n1 == static_cast(CondType::OR_SUBTREE) ? "TREE_" : "", N(t1.n), e1.ToString(b1, _countof(b1), t1.n), b_op, e2.ToString(b2, _countof(b2), t1.n), e3.ToString(b3, _countof(b3), t1.n) // n1 == 0 ? "WHERE" : (n1 == 1 ? "HAVING" : (n1 == 2 ? "ON @@ -324,10 +325,10 @@ void CompiledQuery::CQStep::Print(Query *query) { } else std::sprintf(buf, "C:%d = CREATE_CONDS(T:%d, C:%d)", N(c1.n), N(t1.n), N(c2.n)); break; - case AND_F: + case StepType::AND_F: std::sprintf(buf, "C:%d.AND(C:%d)", N(c1.n), N(c2.n)); break; - case OR_F: + case StepType::OR_F: std::sprintf(buf, "C:%d.OR(C:%d)", N(c1.n), N(c2.n)); break; // case NOT_F: @@ -336,22 +337,22 @@ void CompiledQuery::CQStep::Print(Query *query) { // case COPY_F: // std::sprintf(buf,"C:%d = COPY(C:%d)", N(c2.n), N(c1.n)); // break; - case AND_DESC: + case StepType::AND_DESC: std::sprintf(buf, "C:%d.AND(%s,%s,%s,%s)", N(c1.n), e1.ToString(b1, _countof(b1), t1.n), b_op, e2.ToString(b2, _countof(b2), t1.n), e3.ToString(b3, _countof(b3), t1.n)); break; - case OR_DESC: + case StepType::OR_DESC: std::sprintf(buf, "C:%d.OR(%s,%s,%s,%s)", N(c1.n), e1.ToString(b1, _countof(b1), t1.n), b_op, e2.ToString(b2, _countof(b2), t1.n), e3.ToString(b3, _countof(b3), t1.n)); break; - case TMP_TABLE: { + case StepType::TMP_TABLE: { std::sprintf(buf, "T:%d = TMP_TABLE(", N(t1.n)); unsigned int i = 0; for (; i < tables1.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables1[i].n)); std::sprintf(buf + std::strlen(buf), "T:%u)", N(tables1[i].n)); break; } - case CREATE_VC: + case StepType::CREATE_VC: if (mysql_expr.size() == 1) { char s1[200]; std::strncpy(s1, query->GetItemName(mysql_expr[0]->GetItem()).c_str(), 199); @@ -374,13 +375,13 @@ void CompiledQuery::CQStep::Print(Query *query) { else std::sprintf(buf, "VC:%d.%d = CREATE_VC(T:%d,SUBQUERY(T:%d))", N(t1.n), N(a1.n), N(t1.n), N(t2.n)); break; - case T_MODE: + case StepType::T_MODE: std::sprintf(buf, "T:%d.MODE(%s,%ld,%ld)", N(t1.n), b_tmpar, n1, n2); break; - case JOIN_T: + case StepType::JOIN_T: // This step exists but should not be displayed return; - case LEFT_JOIN_ON: { + case StepType::LEFT_JOIN_ON: { std::sprintf(buf, "T:%d.LEFT_JOIN_ON({", N(t1.n)); int i = 0; for (; i < (int)tables1.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables1[i].n)); @@ -390,41 +391,41 @@ void CompiledQuery::CQStep::Print(Query *query) { std::sprintf(buf + std::strlen(buf), "T:%d},C:%d)", N(tables2[i].n), N(c1.n)); break; } - case INNER_JOIN_ON: { + case StepType::INNER_JOIN_ON: { std::sprintf(buf, "T:%d.INNER_JOIN_ON({", N(t1.n)); unsigned int i = 0; for (; i < tables1.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables1[i].n)); std::sprintf(buf + std::strlen(buf), "T:%d},C:%d)", N(tables1[i].n), N(c1.n)); break; } - case ADD_CONDS: + case StepType::ADD_CONDS: std::sprintf(buf, "T:%d.ADD_CONDS(C:%d,%s)", N(t1.n), N(c1.n), n1 == 0 ? "WHERE" : (n1 == 1 ? "HAVING" : "?!?")); break; - case APPLY_CONDS: + case StepType::APPLY_CONDS: std::sprintf(buf, "T:%d.APPLY_CONDS()", N(t1.n)); break; - case ADD_COLUMN: + case StepType::ADD_COLUMN: std::sprintf(buf, "A:%d = T:%d.ADD_COLUMN(%s,%s,\"%s\",\"%s\")", N(a1.n), N(t1.n), e1.ToString(b1, _countof(b1), t1.n), b_cop, (alias) ? alias : "null", n1 ? "DISTINCT" : "ALL"); break; - case ADD_ORDER: + case StepType::ADD_ORDER: std::sprintf(buf, "T:%d.ADD_ORDER(VC:%d.%d,%s)", N(t1.n), N(t1.n), N(a1.n), n1 ? "DESC" : "ASC"); break; - case UNION: + case StepType::UNION: std::sprintf(buf, "T:%d = UNION(T:%d,T:%d,%ld)", N(t1.n), N(t2.n), N(t3.n), n1); break; - case RESULT: + case StepType::RESULT: std::sprintf(buf, "RESULT(T:%d)", N(t1.n)); break; default: std::sprintf(buf, "Unsupported type of CQStep: %d", type); } - STONEDB_LOG(DEBUG, "%s", buf); + STONEDB_LOG(LogCtl_Level::DEBUG, "%s", buf); } void CompiledQuery::TableAlias(TabID &t_out, const TabID &n, const char *name, [[maybe_unused]] int id) { CompiledQuery::CQStep s; - s.type = TABLE_ALIAS; + s.type = StepType::TABLE_ALIAS; s.t1 = t_out = NextTabID(); s.t2 = n; if (name) { @@ -441,7 +442,7 @@ void CompiledQuery::TmpTable(TabID &t_out, const TabID &t1, bool for_subq_in_whe else s.n1 = 0; DEBUG_ASSERT(t1.n < 0 && NoTabs() > 0); - s.type = TMP_TABLE; + s.type = StepType::TMP_TABLE; s.t1 = t_out = NextTabID(); // was s.t2!!! s.tables1.push_back(t1); steps_tmp_tables.push_back(s); @@ -451,25 +452,25 @@ void CompiledQuery::TmpTable(TabID &t_out, const TabID &t1, bool for_subq_in_whe void CompiledQuery::CreateConds(CondID &c_out, const TabID &t1, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3, bool is_or_subtree, char like_esc) { CompiledQuery::CQStep s; - s.type = CREATE_CONDS; + s.type = StepType::CREATE_CONDS; s.c1 = c_out = NextCondID(); s.t1 = t1; s.e1 = e1; s.op = pr; s.e2 = e2; s.e3 = e3; - s.n1 = is_or_subtree ? OR_SUBTREE : 0; + s.n1 = is_or_subtree ? static_cast(CondType::OR_SUBTREE) : 0; s.n2 = like_esc; steps.push_back(s); } void CompiledQuery::CreateConds(CondID &c_out, const TabID &t1, const CondID &c1, bool is_or_subtree) { CompiledQuery::CQStep s; - s.type = CREATE_CONDS; + s.type = StepType::CREATE_CONDS; s.c2 = c1; s.c1 = c_out = NextCondID(); s.t1 = t1; - s.n1 = is_or_subtree ? OR_SUBTREE : 0; + s.n1 = is_or_subtree ? static_cast(CondType::OR_SUBTREE) : 0; steps.push_back(s); } @@ -478,7 +479,7 @@ void CompiledQuery::And(const CondID &c1, const TabID &t, const CondID &c2) { return; } CompiledQuery::CQStep s; - s.type = AND_F; + s.type = StepType::AND_F; s.c1 = c1; s.t1 = t; s.c2 = c2; @@ -490,7 +491,7 @@ void CompiledQuery::Or(const CondID &c1, const TabID &t, const CondID &c2) { return; } CompiledQuery::CQStep s; - s.type = OR_F; + s.type = StepType::OR_F; s.c1 = c1; s.t1 = t; s.c2 = c2; @@ -499,7 +500,7 @@ void CompiledQuery::Or(const CondID &c1, const TabID &t, const CondID &c2) { void CompiledQuery::And(const CondID &c1, const TabID &t, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3) { CompiledQuery::CQStep s; - s.type = AND_DESC; + s.type = StepType::AND_DESC; s.t1 = t; s.c1 = c1; s.e1 = e1; @@ -511,7 +512,7 @@ void CompiledQuery::And(const CondID &c1, const TabID &t, CQTerm e1, common::Ope void CompiledQuery::Or(const CondID &c1, const TabID &t, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3) { CompiledQuery::CQStep s; - s.type = OR_DESC; + s.type = StepType::OR_DESC; s.t1 = t; s.c1 = c1; s.e1 = e1; @@ -525,12 +526,12 @@ void CompiledQuery::Mode(const TabID &t1, TMParameter mode, int64_t n1, int64_t CompiledQuery::CQStep s; if (s.t1.n >= 0) { size_t const alias_ct(100); - s.type = STEP_ERROR; + s.type = StepType::STEP_ERROR; s.alias = new char[alias_ct]; std::strcpy(s.alias, "T_MODE: can't be applied to RCTable"); return; } - s.type = T_MODE; + s.type = StepType::T_MODE; s.t1 = t1; s.tmpar = mode; s.n1 = n1; @@ -540,7 +541,7 @@ void CompiledQuery::Mode(const TabID &t1, TMParameter mode, int64_t n1, int64_t void CompiledQuery::Join(const TabID &t1, const TabID &t2) { for (auto &step : steps) - if (step.type == TMP_TABLE && step.t1 == t1) { + if (step.type == StepType::TMP_TABLE && step.t1 == t1) { step.tables1.push_back(t2); for (auto &it : steps_tmp_tables) { if (it.t1 == t1) { @@ -551,7 +552,7 @@ void CompiledQuery::Join(const TabID &t1, const TabID &t2) { break; } CompiledQuery::CQStep s; - s.type = JOIN_T; + s.type = StepType::JOIN_T; s.t1 = t1; s.t2 = t2; steps.push_back(s); @@ -560,7 +561,7 @@ void CompiledQuery::Join(const TabID &t1, const TabID &t2) { void CompiledQuery::LeftJoinOn(const TabID &temp_table, std::vector &left_tables, std::vector &right_tables, const CondID &cond_id) { CompiledQuery::CQStep s; - s.type = LEFT_JOIN_ON; + s.type = StepType::LEFT_JOIN_ON; s.t1 = temp_table; s.c1 = cond_id; s.tables1 = left_tables; @@ -571,7 +572,7 @@ void CompiledQuery::LeftJoinOn(const TabID &temp_table, std::vector &left void CompiledQuery::InnerJoinOn(const TabID &temp_table, std::vector &left_tables, std::vector &right_tables, const CondID &cond_id) { CompiledQuery::CQStep s; - s.type = INNER_JOIN_ON; + s.type = StepType::INNER_JOIN_ON; s.t1 = temp_table; s.c1 = cond_id; s.tables1 = left_tables; @@ -582,16 +583,16 @@ void CompiledQuery::InnerJoinOn(const TabID &temp_table, std::vector &lef void CompiledQuery::AddConds(const TabID &t1, const CondID &c1, CondType cond_type) { if (c1.IsNull()) return; CompiledQuery::CQStep s; - s.type = ADD_CONDS; + s.type = StepType::ADD_CONDS; s.t1 = t1; s.c1 = c1; - s.n1 = cond_type; + s.n1 = static_cast(cond_type); steps.push_back(s); } void CompiledQuery::ApplyConds(const TabID &t1) { CompiledQuery::CQStep s; - s.type = APPLY_CONDS; + s.type = StepType::APPLY_CONDS; s.t1 = t1; steps.push_back(s); } @@ -600,7 +601,7 @@ void CompiledQuery::AddColumn(AttrID &a_out, const TabID &t1, CQTerm e1, common: bool distinct, SI *si) { DEBUG_ASSERT(t1.n < 0 && NoTabs() > 0); CompiledQuery::CQStep s; - s.type = ADD_COLUMN; + s.type = StepType::ADD_COLUMN; s.a1 = a_out = NextAttrID(t1); s.t1 = t1; s.e1 = e1; @@ -620,7 +621,7 @@ void CompiledQuery::AddColumn(AttrID &a_out, const TabID &t1, CQTerm e1, common: void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, MysqlExpression *expr, const TabID &src_tab) { DEBUG_ASSERT(t1.n < 0 && NoTabs() > 0); CompiledQuery::CQStep s; - s.type = CREATE_VC; + s.type = StepType::CREATE_VC; s.a1 = a_out = NextVCID(t1); s.t1 = t1; s.t2 = src_tab; @@ -631,7 +632,7 @@ void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, MysqlExp void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, const TabID &subquery, bool on_result) { DEBUG_ASSERT(t1.n < 0 && NoTabs() > 0); CompiledQuery::CQStep s; - s.type = CREATE_VC; + s.type = StepType::CREATE_VC; s.a1 = a_out = NextVCID(t1); s.t1 = t1; s.t2 = subquery; @@ -642,7 +643,7 @@ void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, const Ta void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, std::vector &vcs, const AttrID &vc_id) { DEBUG_ASSERT(t1.n < 0 && NoTabs() > 0); CompiledQuery::CQStep s; - s.type = CREATE_VC; + s.type = StepType::CREATE_VC; s.a1 = a_out = NextVCID(t1); s.a2 = vc_id; s.t1 = t1; @@ -654,7 +655,7 @@ void CompiledQuery::CreateVirtualColumn(int &a_out, const TabID &t1, const TabID const AttrID &col_number) { DEBUG_ASSERT(t1.n < 0 && NoTabs() > 0); CompiledQuery::CQStep s; - s.type = CREATE_VC; + s.type = StepType::CREATE_VC; s.a1 = NextVCID(t1); a_out = s.a1.n; s.a2 = col_number; @@ -667,7 +668,7 @@ void CompiledQuery::Add_Order(const TabID &t1, const AttrID &vc, int d) // d=1 for descending { CompiledQuery::CQStep s; - s.type = ADD_ORDER; + s.type = StepType::ADD_ORDER; s.t1 = t1; s.a1 = vc; s.n1 = d; @@ -676,7 +677,7 @@ void CompiledQuery::Add_Order(const TabID &t1, const AttrID &vc, void CompiledQuery::Union(TabID &t_out, const TabID &t2, const TabID &t3, int all) { CompiledQuery::CQStep s; - s.type = UNION; + s.type = StepType::UNION; if (t_out.n != t2.n) s.t1 = t_out = NextTabID(); else @@ -689,7 +690,7 @@ void CompiledQuery::Union(TabID &t_out, const TabID &t2, const TabID &t3, int al void CompiledQuery::Result(const TabID &t1) { CompiledQuery::CQStep s; - s.type = RESULT; + s.type = StepType::RESULT; s.t1 = t1; steps.push_back(s); } @@ -703,10 +704,10 @@ bool CompiledQuery::CountColumnOnly(const TabID &table) { bool count_only = false; for (int i = 0; i < NoSteps(); i++) { step = Step(i); - if (step.type == CompiledQuery::ADD_COLUMN && step.t1 == table && step.cop == common::ColOperation::COUNT && - step.e1.IsNull()) + if (step.type == CompiledQuery::StepType::ADD_COLUMN && step.t1 == table && + step.cop == common::ColOperation::COUNT && step.e1.IsNull()) count_only = true; - if (step.type == CompiledQuery::ADD_COLUMN && step.t1 == table && + if (step.type == CompiledQuery::StepType::ADD_COLUMN && step.t1 == table && (step.cop != common::ColOperation::COUNT || (step.cop == common::ColOperation::COUNT && !step.e1.IsNull()))) { count_only = false; break; @@ -719,10 +720,11 @@ bool CompiledQuery::NoAggregationOrderingAndDistinct(int table) { CompiledQuery::CQStep step; for (int i = 0; i < NoSteps(); i++) { step = Step(i); - if (step.type == CompiledQuery::ADD_ORDER && step.t1.n == table) return false; // exclude ordering - if (step.type == CompiledQuery::ADD_COLUMN && step.t1.n == table && step.cop != common::ColOperation::LISTING) + if (step.type == CompiledQuery::StepType::ADD_ORDER && step.t1.n == table) return false; // exclude ordering + if (step.type == CompiledQuery::StepType::ADD_COLUMN && step.t1.n == table && + step.cop != common::ColOperation::LISTING) return false; // exclude all kinds of aggregations - if (step.type == CompiledQuery::T_MODE && step.t1.n == table && step.tmpar == TM_DISTINCT) + if (step.type == CompiledQuery::StepType::T_MODE && step.t1.n == table && step.tmpar == TMParameter::TM_DISTINCT) return false; // exclude DISTINCT } return true; @@ -732,7 +734,7 @@ int64_t CompiledQuery::FindLimit(int table) { CompiledQuery::CQStep step; for (int i = 0; i < NoSteps(); i++) { step = Step(i); - if (step.type == CompiledQuery::T_MODE && step.t1.n == table && step.tmpar == TM_TOP) + if (step.type == CompiledQuery::StepType::T_MODE && step.t1.n == table && step.tmpar == TMParameter::TM_TOP) return step.n1 + step.n2; // n1 - omitted, n2 - displayed, i.e. either // ...LIMIT n2; or ...LIMIT n1, n2; } @@ -743,7 +745,8 @@ bool CompiledQuery::FindDistinct(int table) { CompiledQuery::CQStep step; for (int i = 0; i < NoSteps(); i++) { step = Step(i); - if (step.type == CompiledQuery::T_MODE && step.t1.n == table && step.tmpar == TM_DISTINCT) return true; + if (step.type == CompiledQuery::StepType::T_MODE && step.t1.n == table && step.tmpar == TMParameter::TM_DISTINCT) + return true; } return false; } @@ -753,7 +756,8 @@ std::set CompiledQuery::GetUsedDims(const TabID &table_id, std::vectorsecond; - if (step.type == CompiledQuery::ADD_COLUMN && step.t1 == table_id && step.e1.vc_id != common::NULL_VALUE_32) { + if (step.type == CompiledQuery::StepType::ADD_COLUMN && step.t1 == table_id && + step.e1.vc_id != common::NULL_VALUE_32) { vcolumn::VirtualColumn *vc = ((TempTable *)ta[-table_id.n - 1].get())->GetVirtualColumn(step.e1.vc_id); if (vc) { auto local = vc->GetDimensions(); @@ -767,7 +771,7 @@ std::set CompiledQuery::GetUsedDims(const TabID &table_id, std::vectorGetVirtualColumn(step.a1.n); if (vc) { @@ -830,7 +834,7 @@ TabID CompiledQuery::FindSourceOfParameter(const TabID &tab_id, const TabID &tmp bool CompiledQuery::IsTempTable(const TabID &t) { for (int i = 0; i < NoSteps(); i++) { - if (Step(i).type == CompiledQuery::TMP_TABLE && Step(i).t1 == t) return true; + if (Step(i).type == CompiledQuery::StepType::TMP_TABLE && Step(i).t1 == t) return true; } return false; } @@ -845,7 +849,7 @@ int CompiledQuery::FindRootTempTable(int tab_id) { bool CompiledQuery::IsResultTable(const TabID &t) { for (int i = 0; i < NoSteps(); i++) { - if (Step(i).type == CompiledQuery::RESULT && Step(i).t1 == t) { + if (Step(i).type == CompiledQuery::StepType::RESULT && Step(i).t1 == t) { return true; } } @@ -854,7 +858,7 @@ bool CompiledQuery::IsResultTable(const TabID &t) { bool CompiledQuery::IsOrderedBy(const TabID &t) { for (int i = 0; i < NoSteps(); i++) { - if (Step(i).type == CompiledQuery::ADD_ORDER && Step(i).t1 == t) { + if (Step(i).type == CompiledQuery::StepType::ADD_ORDER && Step(i).t1 == t) { return true; } } @@ -867,13 +871,13 @@ std::pair CompiledQuery::GetGlobalLimit() { int i; for (i = 0; i < NoSteps(); i++) { - if (Step(i).type == CompiledQuery::RESULT) { + if (Step(i).type == CompiledQuery::StepType::RESULT) { break; } } DEBUG_ASSERT(i < NoSteps()); TabID res = Step(i).t1; - if (i > 0 && Step(i - 1).type == CompiledQuery::T_MODE && Step(i - 1).t1 == res) { + if (i > 0 && Step(i - 1).type == CompiledQuery::StepType::T_MODE && Step(i - 1).t1 == res) { return std::pair(Step(i - 1).n1, Step(i - 1).n2); } return std::pair(0, -1); @@ -881,7 +885,7 @@ std::pair CompiledQuery::GetGlobalLimit() { int CompiledQuery::GetNoDims(const TabID &tab_id) { for (int i = 0; i < NoSteps(); i++) { - if (Step(i).type == CompiledQuery::TMP_TABLE && Step(i).t1 == tab_id) { + if (Step(i).type == CompiledQuery::StepType::TMP_TABLE && Step(i).t1 == tab_id) { return int(Step(i).tables1.size()); } } @@ -890,7 +894,7 @@ int CompiledQuery::GetNoDims(const TabID &tab_id) { TabID CompiledQuery::GetTableOfCond(const CondID &cond_id) { for (int i = 0; i < NoSteps(); i++) { - if (Step(i).type == CompiledQuery::CREATE_CONDS && Step(i).c1 == cond_id) return Step(i).t1; + if (Step(i).type == CompiledQuery::StepType::CREATE_CONDS && Step(i).c1 == cond_id) return Step(i).t1; } return TabID(); } diff --git a/storage/stonedb/core/compiled_query.h b/storage/stonedb/core/compiled_query.h index 4c14f750b..59942ca6d 100644 --- a/storage/stonedb/core/compiled_query.h +++ b/storage/stonedb/core/compiled_query.h @@ -36,7 +36,7 @@ class MysqlExpression; class CompiledQuery final { public: // Definition of one step - enum StepType { + enum class StepType { TABLE_ALIAS, TMP_TABLE, CREATE_CONDS, @@ -67,7 +67,7 @@ class CompiledQuery final { AttrID a1, a2; CondID c1, c2, c3; CQTerm e1, e2, e3; - common::Operator op; // predicate: common::O_EQ, common::O_LESS etc. + common::Operator op; // predicate: common::Operator::O_EQ, common::Operator::O_LESS etc. TMParameter tmpar; // Table Mode Parameter JoinType jt; common::ColOperation cop; @@ -81,7 +81,7 @@ class CompiledQuery final { SI si; CQStep() - : type(TABLE_ALIAS), + : type(StepType::TABLE_ALIAS), t1(common::NULL_VALUE_32), t2(common::NULL_VALUE_32), t3(common::NULL_VALUE_32), @@ -93,9 +93,9 @@ class CompiledQuery final { e1(), e2(), e3(), - op(common::O_EQ), - tmpar(TM_DISTINCT), - jt(JO_INNER), + op(common::Operator::O_EQ), + tmpar(TMParameter::TM_DISTINCT), + jt(JoinType::JO_INNER), cop(common::ColOperation::LISTING), alias(NULL), n1(common::NULL_VALUE_64), diff --git a/storage/stonedb/core/condition.cpp b/storage/stonedb/core/condition.cpp index 13511bc01..d61de3856 100644 --- a/storage/stonedb/core/condition.cpp +++ b/storage/stonedb/core/condition.cpp @@ -35,11 +35,11 @@ void Condition::AddDescriptor(const Descriptor &desc) { descriptors.push_back(de void Condition::Simplify() { int size = int(descriptors.size()); for (int i = 0; i < size; i++) { - if (descriptors[i].op == common::O_OR_TREE) { + if (descriptors[i].op == common::Operator::O_OR_TREE) { DEBUG_ASSERT(descriptors[i].tree); Descriptor desc; do { - if ((descriptors[i].op != common::O_OR_TREE)) break; + if ((descriptors[i].op != common::Operator::O_OR_TREE)) break; desc = descriptors[i].tree->ExtractDescriptor(); if (!desc.IsEmpty()) { descriptors[i].Simplify(true); // true required not to simplify parameters diff --git a/storage/stonedb/core/condition_encoder.cpp b/storage/stonedb/core/condition_encoder.cpp index 1146393b0..91553a568 100644 --- a/storage/stonedb/core/condition_encoder.cpp +++ b/storage/stonedb/core/condition_encoder.cpp @@ -73,86 +73,87 @@ void ConditionEncoder::operator()(Descriptor &desc) { } bool ConditionEncoder::IsTransformationNeeded() { - return desc->encoded == true && !(encoding_done || desc->op == common::O_IS_NULL || desc->op == common::O_NOT_NULL || - desc->op == common::O_FALSE || desc->op == common::O_TRUE); + return desc->encoded == true && + !(encoding_done || desc->op == common::Operator::O_IS_NULL || desc->op == common::Operator::O_NOT_NULL || + desc->op == common::Operator::O_FALSE || desc->op == common::Operator::O_TRUE); } void ConditionEncoder::DescriptorTransformation() { MEASURE_FET("ConditionEncoder::DescriptorTransformation(...)"); - if (desc->op == common::O_IN || desc->op == common::O_NOT_IN) { + if (desc->op == common::Operator::O_IN || desc->op == common::Operator::O_NOT_IN) { DEBUG_ASSERT(dynamic_cast(desc->val1.vc)); return; } - if (desc->op == common::O_EQ_ANY) desc->op = common::O_IN; + if (desc->op == common::Operator::O_EQ_ANY) desc->op = common::Operator::O_IN; - if (desc->op == common::O_NOT_EQ_ALL) desc->op = common::O_NOT_IN; + if (desc->op == common::Operator::O_NOT_EQ_ALL) desc->op = common::Operator::O_NOT_IN; static MIIterator mit(NULL, pack_power); if (desc->val1.IsNull() || (!IsSetOperator(desc->op) && desc->val1.vc && desc->val1.vc->IsConst() && desc->val1.vc->IsNull(mit))) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; desc->null_after_simplify = true; - } else if (desc->op == common::O_BETWEEN && + } else if (desc->op == common::Operator::O_BETWEEN && (desc->val1.IsNull() || (desc->val1.vc->IsConst() && desc->val1.vc->IsNull(mit)) || desc->val2.IsNull() || (desc->val2.vc->IsConst() && desc->val2.vc->IsNull(mit)))) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; desc->null_after_simplify = true; - } else if (desc->op == common::O_NOT_BETWEEN) { // common::O_NOT_BETWEEN may be changed - // to inequalities in case of nulls + } else if (desc->op == common::Operator::O_NOT_BETWEEN) { // common::Operator::O_NOT_BETWEEN may be changed + // to inequalities in case of nulls bool first_null = (desc->val1.IsNull() || (desc->val1.vc->IsConst() && desc->val1.vc->IsNull(mit))); bool second_null = (desc->val2.IsNull() || (desc->val2.vc->IsConst() && desc->val2.vc->IsNull(mit))); if (first_null && second_null) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; desc->null_after_simplify = true; } else if (first_null) { // a NOT BETWEEN null AND 5 <=> a > 5 desc->val1 = desc->val2; desc->val2 = CQTerm(); - desc->op = common::O_MORE; + desc->op = common::Operator::O_MORE; } else if (second_null) { // a NOT BETWEEN 5 AND null <=> a < 5 - desc->op = common::O_LESS; + desc->op = common::Operator::O_LESS; } } if (IsSetAllOperator(desc->op) && (desc->val1.vc)->IsMultival() && static_cast(*desc->val1.vc).NoValues(mit) == 0) - desc->op = common::O_TRUE; + desc->op = common::Operator::O_TRUE; else { - if (desc->op == common::O_EQ_ALL && (desc->val1.vc)->IsMultival()) { + if (desc->op == common::Operator::O_EQ_ALL && (desc->val1.vc)->IsMultival()) { vcolumn::MultiValColumn &mvc = static_cast(*desc->val1.vc); PrepareValueSet(mvc); if (mvc.NoValues(mit) == 0) - desc->op = common::O_TRUE; + desc->op = common::Operator::O_TRUE; else if (mvc.AtLeastNoDistinctValues(mit, 2) == 1 && !mvc.ContainsNull(mit)) { - desc->op = common::O_EQ; + desc->op = common::Operator::O_EQ; desc->val1 = CQTerm(); desc->val1.vc = new vcolumn::ConstColumn(mvc.GetSetMin(mit), mvc.Type()); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); } else - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } - if (desc->op == common::O_NOT_EQ_ANY && (desc->val1.vc)->IsMultival()) { + if (desc->op == common::Operator::O_NOT_EQ_ANY && (desc->val1.vc)->IsMultival()) { vcolumn::MultiValColumn &mvc = static_cast(*desc->val1.vc); PrepareValueSet(mvc); if (mvc.NoValues(mit) == 0) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; return; } int no_distinct = int(mvc.AtLeastNoDistinctValues(mit, 2)); if (no_distinct == 0) - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; else if (no_distinct == 2) { - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; TransformWithRespectToNulls(); return; } else { - desc->op = common::O_NOT_EQ; + desc->op = common::Operator::O_NOT_EQ; desc->val1 = CQTerm(); desc->val1.vc = new vcolumn::ConstColumn(mvc.GetSetMin(mit), mvc.Type()); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); } } - if (desc->op == common::O_FALSE || desc->op == common::O_TRUE) return; + if (desc->op == common::Operator::O_FALSE || desc->op == common::Operator::O_TRUE) return; if (!IsSetOperator(desc->op) && (desc->val1.vc)->IsMultival()) { vcolumn::MultiValColumn &mvc = static_cast(*desc->val1.vc); vcolumn::VirtualColumn *vc = new vcolumn::ConstColumn(mvc.GetValue(mit), mvc.Type()); @@ -166,7 +167,7 @@ void ConditionEncoder::DescriptorTransformation() { void ConditionEncoder::TransformWithRespectToNulls() { MEASURE_FET("ConditionEncoder::TransformWithRespectToNulls(...)"); - if ((desc->op == common::O_IS_NULL || desc->op == common::O_NOT_NULL) && + if ((desc->op == common::Operator::O_IS_NULL || desc->op == common::Operator::O_NOT_NULL) && dynamic_cast(desc->attr.vc)) { desc->encoded = false; return; @@ -175,25 +176,26 @@ void ConditionEncoder::TransformWithRespectToNulls() { bool nulls_only = desc->attr.vc->RoughNullsOnly(); bool nulls_possible = (additional_nulls || desc->attr.vc->NullsPossible()); - if (desc->op == common::O_IS_NULL) { + if (desc->op == common::Operator::O_IS_NULL) { if (!nulls_possible || attr->NoObj() == 0) - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; else if (nulls_only) - desc->op = common::O_TRUE; - } else if (desc->op == common::O_NOT_NULL) { + desc->op = common::Operator::O_TRUE; + } else if (desc->op == common::Operator::O_NOT_NULL) { if (!nulls_possible) - desc->op = common::O_TRUE; + desc->op = common::Operator::O_TRUE; else if (nulls_only) - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } - if ((IsSetAllOperator(desc->op) || desc->op == common::O_NOT_IN) && desc->val1.vc && desc->val1.vc->IsMultival()) { + if ((IsSetAllOperator(desc->op) || desc->op == common::Operator::O_NOT_IN) && desc->val1.vc && + desc->val1.vc->IsMultival()) { vcolumn::MultiValColumn *mvc = static_cast(desc->val1.vc); MIIterator mit(NULL, pack_power); - // Change to common::O_FALSE for non-subselect columns, or non-correlated + // Change to common::Operator::O_FALSE for non-subselect columns, or non-correlated // subselects (otherwise ContainsNulls needs feeding arguments) if (mvc->ContainsNull(mit)) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; desc->null_after_simplify = true; } } @@ -207,7 +209,7 @@ void ConditionEncoder::EncodeConditionOnStringColumn() { TextTransformation(); if (!IsTransformationNeeded()) return; - if (desc->op == common::O_IN || desc->op == common::O_NOT_IN) + if (desc->op == common::Operator::O_IN || desc->op == common::Operator::O_NOT_IN) TransformINs(); else if (!attr->Type().IsLookup()) TransformOtherThanINsOnNotLookup(); @@ -216,7 +218,7 @@ void ConditionEncoder::EncodeConditionOnStringColumn() { } void ConditionEncoder::EncodeConditionOnNumerics() { - if (desc->op == common::O_IN || desc->op == common::O_NOT_IN) + if (desc->op == common::Operator::O_IN || desc->op == common::Operator::O_NOT_IN) TransformINs(); else TransformOtherThanINsOnNumerics(); @@ -233,10 +235,10 @@ void ConditionEncoder::TransformOtherThanINsOnNumerics() { if (desc->val1.vc && (desc->val1.vc)->IsMultival()) { mvc = static_cast(desc->val1.vc); PrepareValueSet(*mvc); // else it was already done above - // common::O_EQ_ANY = common::O_IN processed by other function, - // common::O_NOT_EQ_ANY processed on higher level - if (desc->op == common::O_LESS_ANY || desc->op == common::O_LESS_EQ_ANY || desc->op == common::O_MORE_ALL || - desc->op == common::O_MORE_EQ_ALL) + // common::Operator::O_EQ_ANY = common::Operator::O_IN processed by other function, + // common::Operator::O_NOT_EQ_ANY processed on higher level + if (desc->op == common::Operator::O_LESS_ANY || desc->op == common::Operator::O_LESS_EQ_ANY || + desc->op == common::Operator::O_MORE_ALL || desc->op == common::Operator::O_MORE_EQ_ALL) v1 = attr->EncodeValue64(mvc->GetSetMax(mit).Get(), v1_rounded); // 1-level values else // ANY && MORE or ALL && LESS @@ -278,31 +280,32 @@ void ConditionEncoder::TransformOtherThanINsOnNumerics() { if (v1_rounded) { if (ISTypeOfEqualOperator(desc->op)) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; return; } if (ISTypeOfNotEqualOperator(desc->op)) { - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; return; } - if (ISTypeOfLessOperator(desc->op) && v1 >= 0) desc->op = common::O_LESS_EQ; + if (ISTypeOfLessOperator(desc->op) && v1 >= 0) desc->op = common::Operator::O_LESS_EQ; - if (ISTypeOfLessEqualOperator(desc->op) && v1 < 0) desc->op = common::O_LESS; + if (ISTypeOfLessEqualOperator(desc->op) && v1 < 0) desc->op = common::Operator::O_LESS; - if (ISTypeOfMoreOperator(desc->op) && v1 < 0) desc->op = common::O_MORE_EQ; + if (ISTypeOfMoreOperator(desc->op) && v1 < 0) desc->op = common::Operator::O_MORE_EQ; - if (ISTypeOfMoreEqualOperator(desc->op) && v1 >= 0) desc->op = common::O_MORE; + if (ISTypeOfMoreEqualOperator(desc->op) && v1 >= 0) desc->op = common::Operator::O_MORE; - if ((desc->op == common::O_BETWEEN || desc->op == common::O_NOT_BETWEEN) && v1 >= 0) v1 += 1; + if ((desc->op == common::Operator::O_BETWEEN || desc->op == common::Operator::O_NOT_BETWEEN) && v1 >= 0) v1 += 1; } - if (v2_rounded && (desc->op == common::O_BETWEEN || desc->op == common::O_NOT_BETWEEN) && v2 < 0) v2 -= 1; + if (v2_rounded && (desc->op == common::Operator::O_BETWEEN || desc->op == common::Operator::O_NOT_BETWEEN) && v2 < 0) + v2 -= 1; - if (v1 == common::NULL_VALUE_64 || - (desc->op == common::O_BETWEEN && v2 == common::NULL_VALUE_64)) { // any comparison with null values only - desc->op = common::O_FALSE; + if (v1 == common::NULL_VALUE_64 || (desc->op == common::Operator::O_BETWEEN && + v2 == common::NULL_VALUE_64)) { // any comparison with null values only + desc->op = common::Operator::O_FALSE; return; } @@ -346,10 +349,10 @@ void ConditionEncoder::TransformOtherThanINsOnNumerics() { } desc->sharp = false; - if (ISTypeOfNotEqualOperator(desc->op) || desc->op == common::O_NOT_BETWEEN) - desc->op = common::O_NOT_BETWEEN; + if (ISTypeOfNotEqualOperator(desc->op) || desc->op == common::Operator::O_NOT_BETWEEN) + desc->op = common::Operator::O_NOT_BETWEEN; else - desc->op = common::O_BETWEEN; + desc->op = common::Operator::O_BETWEEN; desc->val1 = CQTerm(); desc->val1.vc = new vcolumn::ConstColumn( @@ -380,21 +383,21 @@ void ConditionEncoder::TransformLIKEsPattern() { if (min_len == 0) { if (esc) { - if (desc->op == common::O_LIKE) - desc->op = common::O_NOT_NULL; + if (desc->op == common::Operator::O_LIKE) + desc->op = common::Operator::O_NOT_NULL; else - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } else { - if (desc->op == common::O_LIKE) - desc->op = common::O_EQ; + if (desc->op == common::Operator::O_LIKE) + desc->op = common::Operator::O_EQ; else - desc->op = common::O_NOT_EQ; + desc->op = common::Operator::O_NOT_EQ; } } else if (min_len > attr->Type().GetPrecision()) { - if (desc->op == common::O_LIKE) - desc->op = common::O_FALSE; + if (desc->op == common::Operator::O_LIKE) + desc->op = common::Operator::O_FALSE; else - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; } else if (attr->Type().IsLookup()) TransformLIKEsIntoINsOnLookup(); else @@ -405,10 +408,10 @@ void ConditionEncoder::TransformLIKEsIntoINsOnLookup() { MEASURE_FET("ConditionEncoder::TransformLIKEsIntoINsOnLookup(...)"); DEBUG_ASSERT(attr->Type().IsLookup()); - if (desc->op == common::O_LIKE) - desc->op = common::O_IN; + if (desc->op == common::Operator::O_LIKE) + desc->op = common::Operator::O_IN; else - desc->op = common::O_NOT_IN; + desc->op = common::Operator::O_NOT_IN; ValueSet valset(desc->table->Getpackpower()); static MIIterator mid(NULL, pack_power); @@ -428,10 +431,10 @@ void ConditionEncoder::TransformLIKEsIntoINsOnLookup() { desc->val1.vc = new vcolumn::InSetColumn(in_type, NULL, valset); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); if (static_cast(*desc->val1.vc).IsEmpty(mid)) { - if (desc->op == common::O_IN) - desc->op = common::O_FALSE; + if (desc->op == common::Operator::O_IN) + desc->op = common::Operator::O_FALSE; else - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; } } @@ -440,7 +443,7 @@ void ConditionEncoder::TransformLIKEs() { TransformLIKEsPattern(); if (!IsTransformationNeeded()) return; - if (attr->Type().IsLookup() && (desc->op == common::O_LIKE || desc->op == common::O_NOT_LIKE)) + if (attr->Type().IsLookup() && (desc->op == common::Operator::O_LIKE || desc->op == common::Operator::O_NOT_LIKE)) TransformLIKEsIntoINsOnLookup(); } @@ -457,10 +460,10 @@ void ConditionEncoder::TransformINsOnLookup() { desc->val1.vc = new vcolumn::InSetColumn(in_type, NULL, valset); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); if (static_cast(*desc->val1.vc).IsEmpty(mid)) { - if (desc->op == common::O_IN) - desc->op = common::O_FALSE; + if (desc->op == common::Operator::O_IN) + desc->op = common::Operator::O_FALSE; else - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; } } @@ -472,17 +475,17 @@ void ConditionEncoder::TransformIntoINsOnLookup() { types::BString s, vs1, vs2; types::RCValueObject vo; if (desc->val1.vc->IsMultival() && static_cast(*desc->val1.vc).NoValues(mit) > 0) { - if ((desc->op == common::O_LESS_ALL || desc->op == common::O_LESS_EQ_ALL) || - (desc->op == common::O_MORE_ANY || desc->op == common::O_MORE_EQ_ANY)) + if ((desc->op == common::Operator::O_LESS_ALL || desc->op == common::Operator::O_LESS_EQ_ALL) || + (desc->op == common::Operator::O_MORE_ANY || desc->op == common::Operator::O_MORE_EQ_ANY)) vo = static_cast(*desc->val1.vc).GetSetMin(mit); - else if ((desc->op == common::O_LESS_ANY || desc->op == common::O_LESS_EQ_ANY) || - (desc->op == common::O_MORE_ALL || desc->op == common::O_MORE_EQ_ALL)) + else if ((desc->op == common::Operator::O_LESS_ANY || desc->op == common::Operator::O_LESS_EQ_ANY) || + (desc->op == common::Operator::O_MORE_ALL || desc->op == common::Operator::O_MORE_EQ_ALL)) vo = static_cast(*desc->val1.vc).GetSetMax(mit); if (vo.Get()) vs1 = vo.Get()->ToBString(); } else if (desc->val1.vc->IsConst()) desc->val1.vc->GetValueString(vs1, mit); - if (desc->op == common::O_BETWEEN || desc->op == common::O_NOT_BETWEEN) { + if (desc->op == common::Operator::O_BETWEEN || desc->op == common::Operator::O_NOT_BETWEEN) { if (desc->val2.vc->IsMultival() && static_cast(*desc->val2.vc).NoValues(mit) > 0) { vo = static_cast(*desc->val2.vc).GetSetMin(mit); if (vo.Get()) vs2 = vo.Get()->ToBString(); @@ -491,7 +494,7 @@ void ConditionEncoder::TransformIntoINsOnLookup() { } if (vs1.IsNull() && vs2.IsNull()) { - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } else { in_type = ColumnType(common::CT::NUM); int cmp1 = 0, cmp2 = 0; @@ -505,7 +508,7 @@ void ConditionEncoder::TransformIntoINsOnLookup() { else cmp1 = s.CompareWith(vs1); - if (desc->op == common::O_BETWEEN || desc->op == common::O_NOT_BETWEEN) { + if (desc->op == common::Operator::O_BETWEEN || desc->op == common::Operator::O_NOT_BETWEEN) { if (utf) cmp2 = CollationStrCmp(desc->GetCollation(), s, vs2); else @@ -515,8 +518,8 @@ void ConditionEncoder::TransformIntoINsOnLookup() { if ((ISTypeOfEqualOperator(desc->op) && cmp1 == 0) || (ISTypeOfNotEqualOperator(desc->op) && cmp1 != 0) || (ISTypeOfLessOperator(desc->op) && cmp1 < 0) || (ISTypeOfMoreOperator(desc->op) && cmp1 > 0) || (ISTypeOfLessEqualOperator(desc->op) && cmp1 <= 0) || (ISTypeOfMoreEqualOperator(desc->op) && cmp1 >= 0) || - ((desc->op == common::O_BETWEEN) && cmp1 >= 0 && cmp2 <= 0) || - ((desc->op == common::O_NOT_BETWEEN) && (cmp1 < 0 || cmp2 > 0))) { + ((desc->op == common::Operator::O_BETWEEN) && cmp1 >= 0 && cmp2 <= 0) || + ((desc->op == common::Operator::O_NOT_BETWEEN) && (cmp1 < 0 || cmp2 > 0))) { if (count1 <= attr->Cardinality() / 2 + 1) vset_positive.Add64(i); count1++; if (single_value_search) { @@ -530,11 +533,11 @@ void ConditionEncoder::TransformIntoINsOnLookup() { } if (count1 <= count0) { - desc->op = common::O_IN; + desc->op = common::Operator::O_IN; desc->val1.vc = new vcolumn::InSetColumn(in_type, NULL, vset_positive /* *vset.release()*/); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); } else { - desc->op = common::O_NOT_IN; + desc->op = common::Operator::O_NOT_IN; desc->val1.vc = new vcolumn::InSetColumn(in_type, NULL, vset_negative /* *vset_n.release() */); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); } @@ -552,10 +555,10 @@ void ConditionEncoder::TextTransformation() { return; } } - if (desc->op == common::O_LIKE || desc->op == common::O_NOT_LIKE) { + if (desc->op == common::Operator::O_LIKE || desc->op == common::Operator::O_NOT_LIKE) { TransformLIKEs(); } else if (attr->Type().IsLookup()) { // lookup - transform into IN (numbers) - if (desc->op == common::O_IN || desc->op == common::O_NOT_IN) + if (desc->op == common::Operator::O_IN || desc->op == common::Operator::O_NOT_IN) TransformINsOnLookup(); else TransformIntoINsOnLookup(); @@ -575,18 +578,20 @@ void ConditionEncoder::TransformINs() { if (no_dis_values == 0) { if (mvc.ContainsNull(mit)) desc->null_after_simplify = true; - if (desc->op == common::O_IN) - desc->op = common::O_FALSE; + if (desc->op == common::Operator::O_IN) + desc->op = common::Operator::O_FALSE; else if (!mvc.ContainsNull(mit)) - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; else - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } else { if (no_dis_values == 1 && !mvc.ContainsNull(mit)) { if (attr->GetPackType() == common::PackType::INT && !attr->Type().IsLookup()) { desc->val2 = CQTerm(); - desc->val2.vc = new vcolumn::ConstColumn( - ValueOrNull(types::RCNum(attr->EncodeValue64(mvc.GetSetMin(mit), sharp), in_type.GetTypeName())), in_type); + desc->val2.vc = + new vcolumn::ConstColumn(ValueOrNull(types::RCNum(attr->EncodeValue64(mvc.GetSetMin(mit), sharp), + static_cast(in_type.GetTypeName()))), + in_type); desc->val2.vc_id = desc->table->AddVirtColumn(desc->val2.vc); } else { desc->val2 = CQTerm(); @@ -595,18 +600,18 @@ void ConditionEncoder::TransformINs() { } if (sharp) { - if (desc->op == common::O_IN) - desc->op = common::O_FALSE; + if (desc->op == common::Operator::O_IN) + desc->op = common::Operator::O_FALSE; else - desc->op = common::O_NOT_NULL; + desc->op = common::Operator::O_NOT_NULL; } else { desc->val1 = desc->val2; - if (desc->op == common::O_IN) - desc->op = common::O_BETWEEN; + if (desc->op == common::Operator::O_IN) + desc->op = common::Operator::O_BETWEEN; else if (!mvc.ContainsNull(mit)) - desc->op = common::O_NOT_BETWEEN; + desc->op = common::Operator::O_NOT_BETWEEN; else - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } } else if (attr->GetPackType() == common::PackType::INT && !mvc.ContainsNull(mit)) { int64_t val_min, val_max; @@ -630,10 +635,10 @@ void ConditionEncoder::TransformINs() { in_type.GetTypeName())), in_type); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); - if (desc->op == common::O_IN) - desc->op = common::O_BETWEEN; + if (desc->op == common::Operator::O_IN) + desc->op = common::Operator::O_BETWEEN; else - desc->op = common::O_NOT_BETWEEN; + desc->op = common::Operator::O_NOT_BETWEEN; } } } @@ -651,13 +656,13 @@ void ConditionEncoder::TransformOtherThanINsOnNotLookup() { if (v1.vc && v1.vc->IsMultival()) { mvc = static_cast(v1.vc); PrepareValueSet(*mvc); // else it was already done above - if (desc->op == common::O_LESS_ANY || desc->op == common::O_LESS_EQ_ANY || desc->op == common::O_MORE_ALL || - desc->op == common::O_MORE_EQ_ALL) { + if (desc->op == common::Operator::O_LESS_ANY || desc->op == common::Operator::O_LESS_EQ_ANY || + desc->op == common::Operator::O_MORE_ALL || desc->op == common::Operator::O_MORE_EQ_ALL) { v1.vc = new vcolumn::ConstColumn(mvc->GetSetMax(mit), mvc->Type()); v1.vc_id = desc->table->AddVirtColumn(v1.vc); } else { - // ASSERT(desc->op != common::O_NOT_BETWEEN, "desc->op should not be - // common::O_NOT_BETWEEN at this point!"); + // ASSERT(desc->op != common::Operator::O_NOT_BETWEEN, "desc->op should not be + // common::Operator::O_NOT_BETWEEN at this point!"); v1.vc = new vcolumn::ConstColumn(mvc->GetSetMin(mit), mvc->Type()); v1.vc_id = desc->table->AddVirtColumn(v1.vc); } @@ -665,8 +670,8 @@ void ConditionEncoder::TransformOtherThanINsOnNotLookup() { if (v2.vc && v2.vc->IsMultival()) { mvc = static_cast(v2.vc); - // ASSERT(desc->op != common::O_NOT_BETWEEN, "desc->op should not be - // common::O_NOT_BETWEEN at this point!"); + // ASSERT(desc->op != common::Operator::O_NOT_BETWEEN, "desc->op should not be + // common::Operator::O_NOT_BETWEEN at this point!"); PrepareValueSet(*mvc); // only for BETWEEN if (IsSetAnyOperator(desc->op)) { @@ -681,7 +686,7 @@ void ConditionEncoder::TransformOtherThanINsOnNotLookup() { if ((v1.IsNull() || (v1.vc && v1.vc->IsMultival() && v1.vc->IsNull(mit))) && (v2.IsNull() || (v2.vc && v2.vc->IsMultival() && v2.vc->IsNull(mit)))) { desc->null_after_simplify = true; - desc->op = common::O_FALSE; + desc->op = common::Operator::O_FALSE; } else { if (v1.vc && v1.vc->IsMultival() && !v1.vc->IsNull(mit)) desc->CoerceColumnType(v1.vc); @@ -702,11 +707,11 @@ void ConditionEncoder::TransformOtherThanINsOnNotLookup() { if (ISTypeOfLessOperator(desc->op) || ISTypeOfMoreOperator(desc->op)) sharp = true; - if (ISTypeOfNotEqualOperator(desc->op) || desc->op == common::O_NOT_BETWEEN) - desc->op = common::O_NOT_BETWEEN; + if (ISTypeOfNotEqualOperator(desc->op) || desc->op == common::Operator::O_NOT_BETWEEN) + desc->op = common::Operator::O_NOT_BETWEEN; else - desc->op = common::O_BETWEEN; // common::O_IN, common::O_LIKE etc. - // excluded earlier + desc->op = common::Operator::O_BETWEEN; // common::Operator::O_IN, common::Operator::O_LIKE etc. + // excluded earlier desc->sharp = sharp; desc->val1 = v1; @@ -725,13 +730,13 @@ void ConditionEncoder::EncodeIfPossible(Descriptor &desc, bool for_rough_query, if (!desc.attr.vc || desc.attr.vc->GetDim() == -1) return; vcolumn::SingleColumn *vcsc = - (desc.attr.vc->IsSingleColumn() ? static_cast(desc.attr.vc) : NULL); + (static_cast(desc.attr.vc->IsSingleColumn()) ? static_cast(desc.attr.vc) : NULL); bool encode_now = false; if (desc.IsType_AttrAttr() && IsSimpleEqualityOperator(desc.op) && vcsc) { // special case: simple operator on two compatible numerical columns vcolumn::SingleColumn *vcsc2 = NULL; - if (desc.val1.vc->IsSingleColumn()) vcsc2 = static_cast(desc.val1.vc); + if (static_cast(desc.val1.vc->IsSingleColumn())) vcsc2 = static_cast(desc.val1.vc); if (vcsc2 == NULL || vcsc->GetVarMap()[0].GetTabPtr()->TableType() != TType::TABLE || vcsc2->GetVarMap()[0].GetTabPtr()->TableType() != TType::TABLE) return; @@ -754,11 +759,11 @@ void ConditionEncoder::EncodeIfPossible(Descriptor &desc, bool for_rough_query, if (vcec == NULL && (vcsc == NULL || vcsc->GetVarMap()[0].GetTabPtr()->TableType() != TType::TABLE)) return; if (vcec != NULL) { encode_now = (vcec->ExactlyOneLookup() && - (desc.op == common::O_IS_NULL || desc.op == common::O_NOT_NULL || + (desc.op == common::Operator::O_IS_NULL || desc.op == common::Operator::O_NOT_NULL || (desc.val1.vc && desc.val1.vc->IsConst() && (desc.val2.vc == NULL || desc.val2.vc->IsConst())))); } else { - encode_now = (desc.IsType_AttrValOrAttrValVal() || desc.IsType_AttrMultiVal() || desc.op == common::O_IS_NULL || - desc.op == common::O_NOT_NULL) && + encode_now = (desc.IsType_AttrValOrAttrValVal() || desc.IsType_AttrMultiVal() || + desc.op == common::Operator::O_IS_NULL || desc.op == common::Operator::O_NOT_NULL) && desc.attr.vc->GetVarMap()[0].GetTabPtr()->TableType() == TType::TABLE && (!for_rough_query || !desc.IsType_Subquery()); } @@ -794,7 +799,7 @@ void ConditionEncoder::LookupExpressionTransformation() { desc->attr.vc = new vcolumn::SingleColumn(col, vcec->GetMultiIndex(), col_desc.var.tab, col_desc.col_ndx, col_desc.GetTabPtr().get(), vcec->GetDim()); desc->attr.vc_id = desc->table->AddVirtColumn(desc->attr.vc); - desc->op = common::O_IN; + desc->op = common::Operator::O_IN; desc->val1.vc = new vcolumn::InSetColumn(in_type, NULL, valset); desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc); desc->encoded = true; @@ -803,7 +808,7 @@ void ConditionEncoder::LookupExpressionTransformation() { desc->attr.vc = new vcolumn::SingleColumn(col, vcec->GetMultiIndex(), col_desc.var.tab, col_desc.col_ndx, col_desc.GetTabPtr().get(), vcec->GetDim()); desc->attr.vc_id = desc->table->AddVirtColumn(desc->attr.vc); - desc->op = common::O_IS_NULL; + desc->op = common::Operator::O_IS_NULL; desc->encoded = true; } else { // both nulls and not-nulls are positive - no single operator // possible diff --git a/storage/stonedb/core/cq_term.h b/storage/stonedb/core/cq_term.h index d733a1fa9..90e21ccac 100644 --- a/storage/stonedb/core/cq_term.h +++ b/storage/stonedb/core/cq_term.h @@ -57,9 +57,17 @@ struct CondID { bool operator==(const CondID &other) const { return (n == other.n) && (!IsNull()); } }; -enum JoinType { JO_INNER, JO_LEFT, JO_RIGHT, JO_FULL }; -enum TMParameter { TM_DISTINCT, TM_TOP, TM_EXISTS }; // Table Mode Parameter -enum CondType { WHERE_COND, HAVING_COND, ON_INNER_FILTER, ON_LEFT_FILTER, ON_RIGHT_FILTER, OR_SUBTREE, AND_SUBTREE }; +enum class JoinType { JO_INNER, JO_LEFT, JO_RIGHT, JO_FULL }; +enum class TMParameter { TM_DISTINCT, TM_TOP, TM_EXISTS }; // Table Mode Parameter +enum class CondType { + WHERE_COND, + HAVING_COND, + ON_INNER_FILTER, + ON_LEFT_FILTER, + ON_RIGHT_FILTER, + OR_SUBTREE, + AND_SUBTREE +}; /** Interpretation of CQTerm depends on which parameters are used. diff --git a/storage/stonedb/core/data_cache.h b/storage/stonedb/core/data_cache.h index 25ce8487f..3232f4be5 100644 --- a/storage/stonedb/core/data_cache.h +++ b/storage/stonedb/core/data_cache.h @@ -96,7 +96,7 @@ class DataCache final { if constexpr (T::ID == COORD_TYPE::PACK) { p->TrackAccess(); // int objnum = c.size(); - // STONEDB_LOG(DEBUG, "PutObject packs objnum %d + // STONEDB_LOG(LogCtl_Level::DEBUG, "PutObject packs objnum %d // (table:%d,pack:%d,clounm:%d)", objnum,pc_table(coord_), // pc_dp(coord_), pc_column(coord_)); } @@ -118,7 +118,7 @@ class DataCache final { if (it != c.end()) { // if (T::ID == COORD_TYPE::PACK) { // int objnum = c.size(); - // STONEDB_LOG(DEBUG, "DropObject packs objnum %d + // STONEDB_LOG(LogCtl_Level::DEBUG, "DropObject packs objnum %d // (table:%d,pack:%d,clounm:%d)", objnum,pc_table(coord_), // pc_dp(coord_), pc_column(coord_)); //} diff --git a/storage/stonedb/core/data_type.cpp b/storage/stonedb/core/data_type.cpp index c0551472b..0081c54a2 100644 --- a/storage/stonedb/core/data_type.cpp +++ b/storage/stonedb/core/data_type.cpp @@ -26,7 +26,7 @@ namespace core { #define MAX(a, b) ((a) > (b) ? (a) : (b)) DataType::DataType(common::CT atype, int prec, int scale, DTCollation collation) : precision(prec) { - valtype = VT_NOTKNOWN; + valtype = ValueType::VT_NOTKNOWN; attrtype = atype; fixscale = scale; fixmax = -1; @@ -34,23 +34,23 @@ DataType::DataType(common::CT atype, int prec, int scale, DTCollation collation) switch (attrtype) { case common::CT::INT: - valtype = VT_FIXED; + valtype = ValueType::VT_FIXED; fixmax = MAX(std::numeric_limits::max(), -SDB_INT_MIN); break; case common::CT::BIGINT: - valtype = VT_FIXED; + valtype = ValueType::VT_FIXED; fixmax = MAX(common::SDB_BIGINT_MAX, -common::SDB_BIGINT_MIN); break; case common::CT::MEDIUMINT: - valtype = VT_FIXED; + valtype = ValueType::VT_FIXED; fixmax = MAX(SDB_MEDIUMINT_MAX, -SDB_MEDIUMINT_MIN); break; case common::CT::SMALLINT: - valtype = VT_FIXED; + valtype = ValueType::VT_FIXED; fixmax = MAX(SDB_SMALLINT_MAX, -SDB_SMALLINT_MIN); break; case common::CT::BYTEINT: - valtype = VT_FIXED; + valtype = ValueType::VT_FIXED; fixmax = MAX(SDB_TINYINT_MAX, -SDB_TINYINT_MIN); break; @@ -60,12 +60,12 @@ DataType::DataType(common::CT atype, int prec, int scale, DTCollation collation) fixmax = common::PLUS_INF_64; else fixmax = QuickMath::power10i(prec) - 1; - valtype = VT_FIXED; + valtype = ValueType::VT_FIXED; break; case common::CT::REAL: case common::CT::FLOAT: - valtype = VT_FLOAT; + valtype = ValueType::VT_FLOAT; break; case common::CT::STRING: @@ -74,7 +74,7 @@ DataType::DataType(common::CT atype, int prec, int scale, DTCollation collation) case common::CT::BYTE: case common::CT::VARBYTE: case common::CT::LONGTEXT: - valtype = VT_STRING; + valtype = ValueType::VT_STRING; break; case common::CT::DATETIME: @@ -82,7 +82,7 @@ DataType::DataType(common::CT atype, int prec, int scale, DTCollation collation) case common::CT::TIME: case common::CT::DATE: case common::CT::YEAR: - valtype = VT_DATETIME; + valtype = ValueType::VT_DATETIME; break; case common::CT::DATETIME_N: @@ -102,7 +102,7 @@ DataType &DataType::operator=(const ColumnType &ct) { *this = DataType(ct.GetTypeName(), ct.GetPrecision(), ct.GetScale(), ct.GetCollation()); - if (valtype == VT_NOTKNOWN) { + if (valtype == ValueType::VT_NOTKNOWN) { char s[128]; std::sprintf(s, "ColumnType (common::CT #%d) is not convertible to a DataType", (int)ct.GetTypeName()); throw common::Exception(s); diff --git a/storage/stonedb/core/data_type.h b/storage/stonedb/core/data_type.h index f792e8f9d..70977fc41 100644 --- a/storage/stonedb/core/data_type.h +++ b/storage/stonedb/core/data_type.h @@ -25,29 +25,29 @@ namespace core { struct ColumnType; // Type of intermediate results of expression evaluation. -// VT_FLOAT - floating-point real number (double) -// VT_FIXED - fixed-point real (decimal) or integer, encoded as int64_t with -// base-10 scale VT_STRING - pointer to character string, accompanied by string -// length VT_DATETIME - date/time value encoded as int64_t, taken from +// ValueType::VT_FLOAT - floating-point real number (double) +// ValueType::VT_FIXED - fixed-point real (decimal) or integer, encoded as int64_t with +// base-10 scale ValueType::VT_STRING - pointer to character string, accompanied by string +// length ValueType::VT_DATETIME - date/time value encoded as int64_t, taken from // types::RCDateTime representation // DataType::attrtype must be set to precisely denote which // date/time type is considered. struct DataType final { - enum ValueType { VT_FLOAT, VT_FIXED, VT_STRING, VT_DATETIME, VT_NOTKNOWN = 255 }; + enum class ValueType { VT_FLOAT, VT_FIXED, VT_STRING, VT_DATETIME, VT_NOTKNOWN = 255 }; ValueType valtype; common::CT attrtype; // storage type of SDB (only for source columns; // otherwise common::CT::UNK) - int fixscale; // base-10 scale of VT_FIXED (no. of decimal digits after + int fixscale; // base-10 scale of ValueType::VT_FIXED (no. of decimal digits after // comma) - int64_t fixmax; // maximum _absolute_ value possible (upper bound) of VT_FIXED; + int64_t fixmax; // maximum _absolute_ value possible (upper bound) of ValueType::VT_FIXED; // fixmax = -1 when upper bound is unknown or doesn't fit in int64_t; // precision of a decimal = QuickMath::precision10(fixmax) - DTCollation collation; // character set of VT_STRING + coercibility + DTCollation collation; // character set of ValueType::VT_STRING + coercibility int precision; DataType() { - valtype = VT_NOTKNOWN; + valtype = ValueType::VT_NOTKNOWN; attrtype = common::CT::UNK; fixscale = 0; fixmax = -1; @@ -57,12 +57,12 @@ struct DataType final { DataType(common::CT atype, int prec = 0, int scale = 0, DTCollation collation = DTCollation()); DataType &operator=(const ColumnType &ct); - bool IsKnown() const { return valtype != VT_NOTKNOWN; } - bool IsFixed() const { return valtype == VT_FIXED; } - bool IsFloat() const { return valtype == VT_FLOAT; } + bool IsKnown() const { return valtype != ValueType::VT_NOTKNOWN; } + bool IsFixed() const { return valtype == ValueType::VT_FIXED; } + bool IsFloat() const { return valtype == ValueType::VT_FLOAT; } bool IsInt() const { return IsFixed() && (fixscale == 0); } - bool IsString() const { return valtype == VT_STRING; } - bool IsDateTime() const { return valtype == VT_DATETIME; } + bool IsString() const { return valtype == ValueType::VT_STRING; } + bool IsDateTime() const { return valtype == ValueType::VT_DATETIME; } }; } // namespace core } // namespace stonedb diff --git a/storage/stonedb/core/descriptor.cpp b/storage/stonedb/core/descriptor.cpp index 7e1a7803c..608973b77 100644 --- a/storage/stonedb/core/descriptor.cpp +++ b/storage/stonedb/core/descriptor.cpp @@ -47,7 +47,7 @@ inline bool IsDescriptorCQTermEqual(const CQTerm &cq_left, const CQTerm &cs_righ } Descriptor::Descriptor() - : lop(common::O_AND), + : lop(common::LogicalOperator::O_AND), sharp(false), encoded(false), done(false), @@ -57,18 +57,18 @@ Descriptor::Descriptor() tree(NULL), left_dims(0), right_dims(0), - rv(common::RS_UNKNOWN), + rv(common::RSValue::RS_UNKNOWN), like_esc('\\'), - desc_t(DT_NOT_KNOWN_YET), + desc_t(DescriptorJoinType::DT_NOT_KNOWN_YET), collation(DTCollation()), null_after_simplify(false) { - op = common::O_UNKNOWN_FUNC; + op = common::Operator::O_UNKNOWN_FUNC; } Descriptor::Descriptor(TempTable *t, int no_dims) // no_dims is a destination number of dimensions // (multiindex may be smaller at this point) - : op(common::O_OR_TREE), - lop(common::O_AND), + : op(common::Operator::O_OR_TREE), + lop(common::LogicalOperator::O_AND), sharp(false), encoded(false), done(false), @@ -78,9 +78,9 @@ Descriptor::Descriptor(TempTable *t, int no_dims) // no_dims is a destination n tree(NULL), left_dims(no_dims), right_dims(no_dims), - rv(common::RS_UNKNOWN), + rv(common::RSValue::RS_UNKNOWN), like_esc('\\'), - desc_t(DT_NOT_KNOWN_YET), + desc_t(DescriptorJoinType::DT_NOT_KNOWN_YET), collation(DTCollation()), null_after_simplify(false) { DEBUG_ASSERT(table); @@ -113,7 +113,7 @@ Descriptor::Descriptor(const Descriptor &desc) { Descriptor::Descriptor(CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3, TempTable *t, int no_dims, char like_escape) - : lop(common::O_AND), + : lop(common::LogicalOperator::O_AND), sharp(false), encoded(false), done(false), @@ -123,8 +123,8 @@ Descriptor::Descriptor(CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3, Tem tree(NULL), left_dims(no_dims), right_dims(no_dims), - rv(common::RS_UNKNOWN), - desc_t(DT_NOT_KNOWN_YET), + rv(common::RSValue::RS_UNKNOWN), + desc_t(DescriptorJoinType::DT_NOT_KNOWN_YET), collation(DTCollation()), null_after_simplify(false) { op = pr; @@ -135,8 +135,8 @@ Descriptor::Descriptor(CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3, Tem } Descriptor::Descriptor(DescTree *sec_tree, TempTable *t, int no_dims) - : op(common::O_OR_TREE), - lop(common::O_AND), + : op(common::Operator::O_OR_TREE), + lop(common::LogicalOperator::O_AND), sharp(false), encoded(false), done(false), @@ -145,9 +145,9 @@ Descriptor::Descriptor(DescTree *sec_tree, TempTable *t, int no_dims) table(t), left_dims(no_dims), right_dims(no_dims), - rv(common::RS_UNKNOWN), + rv(common::RSValue::RS_UNKNOWN), like_esc('\\'), - desc_t(DT_NOT_KNOWN_YET), + desc_t(DescriptorJoinType::DT_NOT_KNOWN_YET), collation(DTCollation()), null_after_simplify(false) { tree = NULL; @@ -157,7 +157,7 @@ Descriptor::Descriptor(DescTree *sec_tree, TempTable *t, int no_dims) Descriptor::Descriptor(TempTable *t, vcolumn::VirtualColumn *v1, common::Operator pr, vcolumn::VirtualColumn *v2, vcolumn::VirtualColumn *v3) - : lop(common::O_AND), + : lop(common::LogicalOperator::O_AND), sharp(false), encoded(false), done(false), @@ -167,9 +167,9 @@ Descriptor::Descriptor(TempTable *t, vcolumn::VirtualColumn *v1, common::Operato tree(NULL), left_dims(0), right_dims(0), - rv(common::RS_UNKNOWN), + rv(common::RSValue::RS_UNKNOWN), like_esc('\\'), - desc_t(DT_NOT_KNOWN_YET), + desc_t(DescriptorJoinType::DT_NOT_KNOWN_YET), collation(DTCollation()), null_after_simplify(false) { attr = CQTerm(); @@ -246,55 +246,57 @@ bool Descriptor::operator<=(const Descriptor &sec) const { if (attr == sec.attr && (!val1.vc || val1.vc->IsConst()) && (!val2.vc || val2.vc->IsConst()) && (!sec.val1.vc || sec.val1.vc->IsConst()) && (!sec.val2.vc || sec.val2.vc->IsConst())) { switch (op) { - case common::O_EQ: - if (sec.op == common::O_BETWEEN && val1.vc->GetValue(dummy_mit) >= sec.val1.vc->GetValue(dummy_mit) && + case common::Operator::O_EQ: + if (sec.op == common::Operator::O_BETWEEN && val1.vc->GetValue(dummy_mit) >= sec.val1.vc->GetValue(dummy_mit) && val1.vc->GetValue(dummy_mit) <= sec.val2.vc->GetValue(dummy_mit)) return true; - if (sec.op == common::O_IN && static_cast(sec.val1.vc) - ->Contains(dummy_mit, *val1.vc->GetValue(dummy_mit).Get()) == true) + if (sec.op == common::Operator::O_IN && + static_cast(sec.val1.vc) + ->Contains(dummy_mit, *val1.vc->GetValue(dummy_mit).Get()) == true) return true; - if ((sec.op == common::O_LESS || sec.op == common::O_LESS_EQ || sec.op == common::O_MORE || - sec.op == common::O_MORE_EQ || sec.op == common::O_EQ) && + if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ || + sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ || + sec.op == common::Operator::O_EQ) && types::RCValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\')) return true; break; - case common::O_LESS_EQ: - if ((sec.op == common::O_LESS || sec.op == common::O_LESS_EQ) && + case common::Operator::O_LESS_EQ: + if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ) && types::RCValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\')) return true; break; - case common::O_MORE_EQ: - if ((sec.op == common::O_MORE || sec.op == common::O_MORE_EQ) && + case common::Operator::O_MORE_EQ: + if ((sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ) && types::RCValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\')) return true; break; - case common::O_LESS: - if ((sec.op == common::O_LESS || sec.op == common::O_LESS_EQ) && + case common::Operator::O_LESS: + if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ) && types::RCValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), - common::O_LESS_EQ, '\\')) + common::Operator::O_LESS_EQ, '\\')) return true; break; - case common::O_MORE: - if ((sec.op == common::O_MORE || sec.op == common::O_MORE_EQ) && + case common::Operator::O_MORE: + if ((sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ) && types::RCValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), - common::O_MORE_EQ, '\\')) + common::Operator::O_MORE_EQ, '\\')) return true; break; - case common::O_BETWEEN: - if (sec.op == common::O_BETWEEN && val1.vc->GetValue(dummy_mit) >= sec.val1.vc->GetValue(dummy_mit) && + case common::Operator::O_BETWEEN: + if (sec.op == common::Operator::O_BETWEEN && val1.vc->GetValue(dummy_mit) >= sec.val1.vc->GetValue(dummy_mit) && val2.vc->GetValue(dummy_mit) <= sec.val2.vc->GetValue(dummy_mit)) return true; - if ((sec.op == common::O_LESS || sec.op == common::O_LESS_EQ) && + if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ) && types::RCValueObject::compare(val2.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\')) return true; - if ((sec.op == common::O_MORE || sec.op == common::O_MORE_EQ) && + if ((sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ) && types::RCValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\')) return true; break; - case common::O_IN: { + case common::Operator::O_IN: { // vcolumn::MultiValColumn* mvc = // static_cast(val1.vc); if( sec.op == - // common::O_EQ && mvc->Contains(dummy_mit, + // common::Operator::O_EQ && mvc->Contains(dummy_mit, // *sec.val1.vc->GetValue(dummy_mit).Get()) == true ) // return true; break; @@ -317,22 +319,23 @@ bool Descriptor::EqualExceptOuter(const Descriptor &sec) { namespace { void SwitchOperator(common::Operator &op) { - if (op == common::O_LESS) - op = common::O_MORE; - else if (op == common::O_MORE) - op = common::O_LESS; - else if (op == common::O_LESS_EQ) - op = common::O_MORE_EQ; - else if (op == common::O_MORE_EQ) - op = common::O_LESS_EQ; + if (op == common::Operator::O_LESS) + op = common::Operator::O_MORE; + else if (op == common::Operator::O_MORE) + op = common::Operator::O_LESS; + else if (op == common::Operator::O_LESS_EQ) + op = common::Operator::O_MORE_EQ; + else if (op == common::Operator::O_MORE_EQ) + op = common::Operator::O_LESS_EQ; } } // namespace void Descriptor::SwitchSides() // change "aa" etc; throw error if // not possible (e.g. between) { - DEBUG_ASSERT(op == common::O_EQ || op == common::O_NOT_EQ || op == common::O_LESS || op == common::O_MORE || - op == common::O_LESS_EQ || op == common::O_MORE_EQ); + DEBUG_ASSERT(op == common::Operator::O_EQ || op == common::Operator::O_NOT_EQ || op == common::Operator::O_LESS || + op == common::Operator::O_MORE || op == common::Operator::O_LESS_EQ || + op == common::Operator::O_MORE_EQ); SwitchOperator(op); CQTerm p = attr; attr = val1; @@ -342,14 +345,15 @@ void Descriptor::SwitchSides() // change "aa" etc; throw error if bool Descriptor::IsType_AttrValOrAttrValVal() const // true if "phys column op val or column between val and val or " { // or "phys_column IS NULL/NOT NULL" - if (attr.vc == NULL || !attr.vc->IsSingleColumn()) return false; - return ((val1.vc && val1.vc->IsConst()) || (op == common::O_IS_NULL || op == common::O_NOT_NULL)) && + if (attr.vc == NULL || !static_cast(attr.vc->IsSingleColumn())) return false; + return ((val1.vc && val1.vc->IsConst()) || + (op == common::Operator::O_IS_NULL || op == common::Operator::O_NOT_NULL)) && (!val2.vc || (val2.vc && val2.vc->IsConst())); } bool Descriptor::IsType_AttrMultiVal() const { - return op != common::O_BETWEEN && op != common::O_NOT_BETWEEN && attr.vc && attr.vc->IsSingleColumn() && val1.vc && - val1.vc->IsMultival() && val1.vc->IsConst(); + return op != common::Operator::O_BETWEEN && op != common::Operator::O_NOT_BETWEEN && attr.vc && + static_cast(attr.vc->IsSingleColumn()) && val1.vc && val1.vc->IsMultival() && val1.vc->IsConst(); } bool Descriptor::IsType_Subquery() { @@ -359,14 +363,14 @@ bool Descriptor::IsType_Subquery() { bool Descriptor::IsType_JoinSimple() const // true if more than one table involved { - DEBUG_ASSERT(desc_t != DT_NOT_KNOWN_YET); - return desc_t == DT_SIMPLE_JOIN; + DEBUG_ASSERT(desc_t != DescriptorJoinType::DT_NOT_KNOWN_YET); + return desc_t == DescriptorJoinType::DT_SIMPLE_JOIN; } bool Descriptor::IsType_AttrAttr() const // true if "column op column" from one table { - if (attr.vc == NULL || val1.vc == NULL || !attr.vc->IsSingleColumn() || !val1.vc->IsSingleColumn() || val2.vc || - IsType_Join()) + if (attr.vc == NULL || val1.vc == NULL || !static_cast(attr.vc->IsSingleColumn()) || + !static_cast(val1.vc->IsSingleColumn()) || val2.vc || IsType_Join()) return false; return true; @@ -375,9 +379,9 @@ bool Descriptor::IsType_AttrAttr() const // true if "column op column" from one bool Descriptor::IsType_STONEDBExpression() const // only columns, constants and STONEDBExpressions { if (attr.vc == NULL) return false; - if ((attr.vc->IsSingleColumn() || attr.vc->IsConst()) && - (val1.vc == NULL || val1.vc->IsSingleColumn() || val1.vc->IsConst()) && - (val2.vc == NULL || val2.vc->IsSingleColumn() || val2.vc->IsConst())) + if ((static_cast(attr.vc->IsSingleColumn()) || attr.vc->IsConst()) && + (val1.vc == NULL || static_cast(val1.vc->IsSingleColumn()) || val1.vc->IsConst()) && + (val2.vc == NULL || static_cast(val2.vc->IsSingleColumn()) || val2.vc->IsConst())) return true; return false; } @@ -387,10 +391,10 @@ void Descriptor::CalculateJoinType() { DimensionVector used_dims(right_dims.Size()); // the most current number of dimensions tree->DimensionUsed(used_dims); if (used_dims.NoDimsUsed() > 1) { - desc_t = DT_COMPLEX_JOIN; + desc_t = DescriptorJoinType::DT_COMPLEX_JOIN; left_dims = used_dims; } else - desc_t = DT_NON_JOIN; + desc_t = DescriptorJoinType::DT_NON_JOIN; return; } std::set tables_a, tables_v1, tables_v2, tables_all; @@ -407,45 +411,45 @@ void Descriptor::CalculateJoinType() { tables_all.insert(tables_v2.begin(), tables_v2.end()); } if (tables_all.size() <= 1) - desc_t = DT_NON_JOIN; + desc_t = DescriptorJoinType::DT_NON_JOIN; else if (tables_a.size() > 1 || tables_v1.size() > 1 || tables_v2.size() > 1 || // 1 BETWEEN a1 AND b1 - (tables_a.size() == 0 && (op == common::O_BETWEEN || op == common::O_NOT_BETWEEN))) - desc_t = DT_COMPLEX_JOIN; + (tables_a.size() == 0 && (op == common::Operator::O_BETWEEN || op == common::Operator::O_NOT_BETWEEN))) + desc_t = DescriptorJoinType::DT_COMPLEX_JOIN; else - desc_t = DT_SIMPLE_JOIN; + desc_t = DescriptorJoinType::DT_SIMPLE_JOIN; } bool Descriptor::IsType_JoinComplex() const { // Make sure to use CalculateJoinType() before - DEBUG_ASSERT(desc_t != DT_NOT_KNOWN_YET); - return desc_t == DT_COMPLEX_JOIN; + DEBUG_ASSERT(desc_t != DescriptorJoinType::DT_NOT_KNOWN_YET); + return desc_t == DescriptorJoinType::DT_COMPLEX_JOIN; } common::RSValue Descriptor::EvaluateRoughlyPack(const MIIterator &mit) { if (IsType_OrTree()) return tree->root->EvaluateRoughlyPack(mit); - common::RSValue r = common::RS_SOME; + common::RSValue r = common::RSValue::RS_SOME; if (attr.vc /*&& !attr.vc->IsConst()*/) r = attr.vc->RoughCheck(mit, *this); - if (rv == common::RS_UNKNOWN) + if (rv == common::RSValue::RS_UNKNOWN) rv = r; - else if (rv == common::RS_NONE && r != common::RS_NONE) - rv = common::RS_SOME; - else if (rv == common::RS_ALL && r != common::RS_ALL) - rv = common::RS_SOME; + else if (rv == common::RSValue::RS_NONE && r != common::RSValue::RS_NONE) + rv = common::RSValue::RS_SOME; + else if (rv == common::RSValue::RS_ALL && r != common::RSValue::RS_ALL) + rv = common::RSValue::RS_SOME; return r; } void Descriptor::Simplify(bool in_having) { MEASURE_FET("Descriptor::Simplify(...)"); static MIIterator const mit(NULL, table->Getpackpower()); - if (op == common::O_FALSE || op == common::O_TRUE) return; + if (op == common::Operator::O_FALSE || op == common::Operator::O_TRUE) return; if (IsType_OrTree()) { common::Tribool res = tree->Simplify(in_having); if (res == true) - op = common::O_TRUE; + op = common::Operator::O_TRUE; else if (res == false) - op = common::O_FALSE; + op = common::Operator::O_FALSE; else if (!tree->root->desc.IsType_OrTree()) { Descriptor new_desc = tree->root->desc; new_desc.left_dims = left_dims; @@ -458,8 +462,8 @@ void Descriptor::Simplify(bool in_having) { bool res = false; if (attr.vc && attr.vc->IsConst() && val1.vc && !val1.vc->IsConst() && - (op == common::O_EQ || op == common::O_NOT_EQ || op == common::O_LESS || op == common::O_LESS_EQ || - op == common::O_MORE || op == common::O_MORE_EQ)) { + (op == common::Operator::O_EQ || op == common::Operator::O_NOT_EQ || op == common::Operator::O_LESS || + op == common::Operator::O_LESS_EQ || op == common::Operator::O_MORE || op == common::Operator::O_MORE_EQ)) { SwitchSides(); } if (Query::IsAllAny(op) && dynamic_cast(val1.vc) == NULL) Query::UnmarkAllAny(op); @@ -475,46 +479,46 @@ void Descriptor::Simplify(bool in_having) { vcolumn::VirtualColumn *v1cc = val1.vc; vcolumn::VirtualColumn *v2cc = val2.vc; - if (op == common::O_BETWEEN && (v1cc->IsNull(mit) || v2cc->IsNull(mit))) { - op = common::O_FALSE; + if (op == common::Operator::O_BETWEEN && (v1cc->IsNull(mit) || v2cc->IsNull(mit))) { + op = common::Operator::O_FALSE; null_after_simplify = true; return; - } else if (op == common::O_NOT_BETWEEN && (v1cc->IsNull(mit) || v2cc->IsNull(mit))) { + } else if (op == common::Operator::O_NOT_BETWEEN && (v1cc->IsNull(mit) || v2cc->IsNull(mit))) { if (v1cc->IsNull(mit) && v2cc->IsNull(mit)) { - op = common::O_FALSE; + op = common::Operator::O_FALSE; null_after_simplify = true; return; } if (v1cc->IsNull(mit)) { // a not between null and x ==> a > x - op = common::O_MORE; + op = common::Operator::O_MORE; val1 = val2; v1cc = v2cc; } else // a not between x and null ==> a < x - op = common::O_LESS; + op = common::Operator::O_LESS; } if (IsSetOperator(op)) { null_after_simplify = IsNull_Set(mit, op); res = CheckSetCondition(mit, op); - op = res ? common::O_TRUE : common::O_FALSE; + op = res ? common::Operator::O_TRUE : common::Operator::O_FALSE; return; } switch (op) { - case common::O_IS_NULL: + case common::Operator::O_IS_NULL: res = acc->IsNull(mit) ? true : false; break; - case common::O_NOT_EXISTS: - case common::O_EXISTS: { + case common::Operator::O_NOT_EXISTS: + case common::Operator::O_EXISTS: { vcolumn::MultiValColumn *mvc = static_cast(attr.vc); res = mvc->CheckExists(mit); - if (op == common::O_NOT_EXISTS) res = !res; + if (op == common::Operator::O_NOT_EXISTS) res = !res; break; } - case common::O_NOT_NULL: + case common::Operator::O_NOT_NULL: res = acc->IsNull(mit) ? false : true; break; - case common::O_BETWEEN: - case common::O_NOT_BETWEEN: { + case common::Operator::O_BETWEEN: + case common::Operator::O_NOT_BETWEEN: { DEBUG_ASSERT(sharp == false); if (acc->IsNull(mit)) { null_after_simplify = true; @@ -530,11 +534,11 @@ void Descriptor::Simplify(bool in_having) { types::RCValueObject rv1 = acc->GetValue(mit); types::RCValueObject rv2 = v1cc->GetValue(mit); types::RCValueObject rv3 = v2cc->GetValue(mit); - res = types::RCValueObject::compare(rv1, rv2, common::O_MORE_EQ, '\\') && - types::RCValueObject::compare(rv1, rv3, common::O_LESS_EQ, '\\'); + res = types::RCValueObject::compare(rv1, rv2, common::Operator::O_MORE_EQ, '\\') && + types::RCValueObject::compare(rv1, rv3, common::Operator::O_LESS_EQ, '\\'); } - if (op == common::O_NOT_BETWEEN && !acc->IsNull(mit)) res = !res; + if (op == common::Operator::O_NOT_BETWEEN && !acc->IsNull(mit)) res = !res; break; } default: { @@ -544,7 +548,7 @@ void Descriptor::Simplify(bool in_having) { if (res == false && (rv1.IsNull() || rv2.IsNull())) null_after_simplify = true; } } - op = res ? common::O_TRUE : common::O_FALSE; + op = res ? common::Operator::O_TRUE : common::Operator::O_FALSE; return; } @@ -572,14 +576,14 @@ char *Descriptor::ToString(char buffer[], size_t buffer_size) { std::unique_ptr operator_object(CreateQueryOperator(op)); switch (operator_object->GetType()) { - case common::O_ESCAPE: - case common::O_EXISTS: - case common::O_NOT_EXISTS: { + case common::Operator::O_ESCAPE: + case common::Operator::O_EXISTS: + case common::Operator::O_NOT_EXISTS: { size_t offset = std::strlen(buffer); AppendString(buffer, buffer_size, "(exists expr.)", 14, offset); break; } - case common::O_OR_TREE: { + case common::Operator::O_OR_TREE: { size_t offset = std::strlen(buffer); AppendString(buffer, buffer_size, "(OR expr.)", 10, offset); // if(tree) { @@ -592,43 +596,43 @@ char *Descriptor::ToString(char buffer[], size_t buffer_size) { //} break; } - case common::O_FALSE: - case common::O_TRUE: + case common::Operator::O_FALSE: + case common::Operator::O_TRUE: AppendConstantToString(buffer, buffer_size, operator_object.get()); break; - case common::O_IS_NULL: - case common::O_NOT_NULL: + case common::Operator::O_IS_NULL: + case common::Operator::O_NOT_NULL: AppendUnaryOperatorToString(buffer, buffer_size, operator_object.get()); break; - case common::O_EQ: - case common::O_EQ_ALL: - case common::O_EQ_ANY: - case common::O_LESS: - case common::O_LESS_ALL: - case common::O_LESS_ANY: - case common::O_MORE: - case common::O_MORE_ALL: - case common::O_MORE_ANY: - case common::O_LESS_EQ: - case common::O_LESS_EQ_ALL: - case common::O_LESS_EQ_ANY: - case common::O_MORE_EQ: - case common::O_MORE_EQ_ALL: - case common::O_MORE_EQ_ANY: - case common::O_NOT_EQ: - case common::O_NOT_EQ_ALL: - case common::O_NOT_EQ_ANY: - case common::O_IN: - case common::O_NOT_IN: - case common::O_LIKE: - case common::O_NOT_LIKE: + case common::Operator::O_EQ: + case common::Operator::O_EQ_ALL: + case common::Operator::O_EQ_ANY: + case common::Operator::O_LESS: + case common::Operator::O_LESS_ALL: + case common::Operator::O_LESS_ANY: + case common::Operator::O_MORE: + case common::Operator::O_MORE_ALL: + case common::Operator::O_MORE_ANY: + case common::Operator::O_LESS_EQ: + case common::Operator::O_LESS_EQ_ALL: + case common::Operator::O_LESS_EQ_ANY: + case common::Operator::O_MORE_EQ: + case common::Operator::O_MORE_EQ_ALL: + case common::Operator::O_MORE_EQ_ANY: + case common::Operator::O_NOT_EQ: + case common::Operator::O_NOT_EQ_ALL: + case common::Operator::O_NOT_EQ_ANY: + case common::Operator::O_IN: + case common::Operator::O_NOT_IN: + case common::Operator::O_LIKE: + case common::Operator::O_NOT_LIKE: AppendBinaryOperatorToString(buffer, buffer_size, operator_object.get()); break; - case common::O_BETWEEN: - case common::O_NOT_BETWEEN: + case common::Operator::O_BETWEEN: + case common::Operator::O_NOT_BETWEEN: AppendTernaryOperatorToString(buffer, buffer_size, operator_object.get()); break; default: @@ -653,42 +657,42 @@ to that effect. \param The common::Operator enumeration of the desired type of query operator. */ const QueryOperator *Descriptor::CreateQueryOperator(common::Operator type) const { - const char *string_rep[common::OPERATOR_ENUM_COUNT] = { - "=", // common::O_EQ - "=ALL", // common::O_EQ_ALL - "=ANY", // common::O_EQ_ANY - "<>", // common::O_NOT_EQ - "<>ALL", // common::O_NOT_EQ_ALL - "<>ANY", // common::O_NOT_EQ_ANY - "<", // common::O_LESS - "", // common::O_MORE - ">ALL", // common::O_MORE_ALL - ">ANY", // common::O_MORE_ANY - "<=", // common::O_LESS_EQ - "<=ALL", // common::O_LESS_EQ_ALL - "<=ANY", // common::O_LESS_EQ_ANY - ">=", // common::O_MORE_EQ - ">=ALL", // common::O_MORE_EQ_ALL - ">=ANY", // common::O_MORE_EQ_ANY - "IS NULL", // common::O_IS_NULL - "IS NOT NULL", // common::O_NOT_NULL - "BET.", // common::O_BETWEEN - "NOT BET.", // common::O_NOT_BETWEEN - "LIKE", // common::O_LIKE - "NOT LIKE", // common::O_NOT_LIKE - "IN", // common::O_IN - "NOT IN", // common::O_NOT_IN - "EXISTS", // common::O_EXISTS - "NOT EXISTS", // common::O_NOT_EXISTS - "FALSE", // common::O_FALSE - "TRUE", // common::O_TRUE - "ESCAPE", // common::O_ESCAPE - "OR TREE" // common::O_OR_TREE + const char *string_rep[static_cast(common::Operator::OPERATOR_ENUM_COUNT)] = { + "=", // common::Operator::O_EQ + "=ALL", // common::Operator::O_EQ_ALL + "=ANY", // common::Operator::O_EQ_ANY + "<>", // common::Operator::O_NOT_EQ + "<>ALL", // common::Operator::O_NOT_EQ_ALL + "<>ANY", // common::Operator::O_NOT_EQ_ANY + "<", // common::Operator::O_LESS + "", // common::Operator::O_MORE + ">ALL", // common::Operator::O_MORE_ALL + ">ANY", // common::Operator::O_MORE_ANY + "<=", // common::Operator::O_LESS_EQ + "<=ALL", // common::Operator::O_LESS_EQ_ALL + "<=ANY", // common::Operator::O_LESS_EQ_ANY + ">=", // common::Operator::O_MORE_EQ + ">=ALL", // common::Operator::O_MORE_EQ_ALL + ">=ANY", // common::Operator::O_MORE_EQ_ANY + "IS NULL", // common::Operator::O_IS_NULL + "IS NOT NULL", // common::Operator::O_NOT_NULL + "BET.", // common::Operator::O_BETWEEN + "NOT BET.", // common::Operator::O_NOT_BETWEEN + "LIKE", // common::Operator::O_LIKE + "NOT LIKE", // common::Operator::O_NOT_LIKE + "IN", // common::Operator::O_IN + "NOT IN", // common::Operator::O_NOT_IN + "EXISTS", // common::Operator::O_EXISTS + "NOT EXISTS", // common::Operator::O_NOT_EXISTS + "FALSE", // common::Operator::O_FALSE + "TRUE", // common::Operator::O_TRUE + "ESCAPE", // common::Operator::O_ESCAPE + "OR TREE" // common::Operator::O_OR_TREE }; - return new QueryOperator(type, string_rep[type]); + return new QueryOperator(type, string_rep[static_cast(type)]); } /** @@ -817,16 +821,16 @@ void Descriptor::EvaluatePackImpl(MIUpdatingIterator &mit) { if (mit.PackrowStarted()) break; } } else { - if (IsType_Subquery() && op != common::O_OR_TREE) { + if (IsType_Subquery() && op != common::Operator::O_OR_TREE) { // pack based optimization of corr. subq. by using RoughQuery - common::Tribool res = RoughCheckSubselectCondition(mit, PACK_BASED); + common::Tribool res = RoughCheckSubselectCondition(mit, SubSelectOptimizationType::PACK_BASED); if (res == false) mit.ResetCurrentPack(); else if (res == common::TRIBOOL_UNKNOWN) { // int true_c = 0, false_c = 0, unkn_c = 0; while (mit.IsValid()) { // row based optimization of corr. subq. by using RoughQuery - res = RoughCheckSubselectCondition(mit, ROW_BASED); + res = RoughCheckSubselectCondition(mit, SubSelectOptimizationType::ROW_BASED); // if(res == false) // false_c++; // else if(res == true) @@ -870,7 +874,7 @@ void Descriptor::UpdateVCStatistics() // Apply all the information from { MEASURE_FET("Descriptor::UpdateVCStatistics(...)"); if (attr.vc == NULL) return; - if (op == common::O_IS_NULL) { + if (op == common::Operator::O_IS_NULL) { attr.vc->SetLocalNullsOnly(true); return; } @@ -880,18 +884,18 @@ void Descriptor::UpdateVCStatistics() // Apply all the information from // (e.g. double between int and int) int64_t v1 = common::NULL_VALUE_64; int64_t v2 = common::NULL_VALUE_64; - if (op == common::O_BETWEEN) { + if (op == common::Operator::O_BETWEEN) { if (val1.vc) v1 = val1.vc->RoughMin(); if (val2.vc) v2 = val2.vc->RoughMax(); - } else if (op == common::O_EQ) { + } else if (op == common::Operator::O_EQ) { if (val1.vc) { v1 = val1.vc->RoughMin(); v2 = val1.vc->RoughMax(); val1.vc->SetLocalMinMax(v1, v2); // apply to both sides } - } else if (op == common::O_LESS || op == common::O_LESS_EQ) { + } else if (op == common::Operator::O_LESS || op == common::Operator::O_LESS_EQ) { if (val1.vc) v2 = val1.vc->RoughMax(); - } else if (op == common::O_MORE || op == common::O_MORE_EQ) { + } else if (op == common::Operator::O_MORE || op == common::Operator::O_MORE_EQ) { if (val1.vc) v1 = val1.vc->RoughMin(); } int v1_scale = val1.vc ? val1.vc->Type().GetScale() : 0; @@ -904,7 +908,7 @@ void Descriptor::UpdateVCStatistics() // Apply all the information from v2_conv = v2_conv.ToDecimal(attr.vc->Type().GetScale()); attr.vc->SetLocalMinMax(v1_conv.ValueInt(), v2_conv.ValueInt()); } - if (op == common::O_IN && val1.vc->IsConst()) { + if (op == common::Operator::O_IN && val1.vc->IsConst()) { vcolumn::MultiValColumn *mv_vc = static_cast(val1.vc); MIDummyIterator mit(1); int64_t v = mv_vc->NoValues(mit); @@ -918,9 +922,9 @@ void Descriptor::UpdateVCStatistics() // Apply all the information from bool Descriptor::CheckCondition_UTF(const MIIterator &mit) { MEASURE_FET("Descriptor::CheckCondition_UTF(...)"); - if (op == common::O_TRUE) + if (op == common::Operator::O_TRUE) return true; - else if (op == common::O_FALSE) + else if (op == common::Operator::O_FALSE) return false; bool result = true; @@ -929,23 +933,24 @@ bool Descriptor::CheckCondition_UTF(const MIIterator &mit) { return CheckCondition(mit); // Assumption: LockSourcePack externally done. - if (op == common::O_EQ) { // fast track for the most common operator + if (op == common::Operator::O_EQ) { // fast track for the most common operator DEBUG_ASSERT(attr.vc && val1.vc && types::RequiresUTFConversions(collation)); if (attr.vc->IsNull(mit) || val1.vc->IsNull(mit)) return false; types::BString s1, s2; attr.vc->GetNotNullValueString(s1, mit); val1.vc->GetNotNullValueString(s2, mit); return CollationStrCmp(collation, s1, s2) == 0; - } else if (op == common::O_NOT_NULL) { + } else if (op == common::Operator::O_NOT_NULL) { if (attr.vc->IsNull(mit)) return false; - } else if (op == common::O_IS_NULL) { + } else if (op == common::Operator::O_IS_NULL) { if (!attr.vc->IsNull(mit)) return false; - } else if (op == common::O_EXISTS || op == common::O_NOT_EXISTS) { + } else if (op == common::Operator::O_EXISTS || op == common::Operator::O_NOT_EXISTS) { DEBUG_ASSERT(dynamic_cast(attr.vc)); vcolumn::SubSelectColumn *sub = static_cast(attr.vc); bool is_nonempty = sub->CheckExists(mit); - if ((op == common::O_EXISTS && !is_nonempty) || (op == common::O_NOT_EXISTS && is_nonempty)) return false; - } else if (op == common::O_BETWEEN || op == common::O_NOT_BETWEEN) { + if ((op == common::Operator::O_EXISTS && !is_nonempty) || (op == common::Operator::O_NOT_EXISTS && is_nonempty)) + return false; + } else if (op == common::Operator::O_BETWEEN || op == common::Operator::O_NOT_BETWEEN) { if (attr.vc->IsNull(mit)) return false; // need to consider three value logic types::BString s1, s2, s3; @@ -962,7 +967,7 @@ bool Descriptor::CheckCondition_UTF(const MIIterator &mit) { val1_res = val1.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(attr_ge_val1); val2_res = val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(attr_le_val2); } - if (op == common::O_BETWEEN) { + if (op == common::Operator::O_BETWEEN) { if (val1_res != true || val2_res != true) return false; } else { if (val1_res != false && val2_res != false) return false; @@ -970,7 +975,7 @@ bool Descriptor::CheckCondition_UTF(const MIIterator &mit) { } else if (IsSetOperator(op)) { DEBUG_ASSERT(attr.vc && dynamic_cast(val1.vc)); return CheckSetCondition_UTF(mit, op); - } else if (op == common::O_LIKE || op == common::O_NOT_LIKE) { + } else if (op == common::Operator::O_LIKE || op == common::Operator::O_NOT_LIKE) { if (attr.vc->IsNull(mit) || val1.vc->IsNull(mit)) return false; types::BString v, pattern; attr.vc->GetNotNullValueString(v, mit); @@ -978,7 +983,7 @@ bool Descriptor::CheckCondition_UTF(const MIIterator &mit) { int x = common::wildcmp(collation, v.val, v.val + v.len, pattern.val, pattern.val + pattern.len, like_esc, '_', '%'); result = (x == 0 ? true : false); - if (op == common::O_LIKE) + if (op == common::Operator::O_LIKE) return result; else return !result; @@ -998,28 +1003,29 @@ bool Descriptor::CheckCondition_UTF(const MIIterator &mit) { bool Descriptor::CheckCondition(const MIIterator &mit) { MEASURE_FET("Descriptor::CheckCondition(...)"); - if (op == common::O_TRUE) + if (op == common::Operator::O_TRUE) return true; - else if (op == common::O_FALSE) + else if (op == common::Operator::O_FALSE) return false; bool result = true; // Assumption: LockSourcePacks externally done. - if (op == common::O_EQ) { // fast track for the most common operator + if (op == common::Operator::O_EQ) { // fast track for the most common operator DEBUG_ASSERT(attr.vc && val1.vc); // nulls checked in operator == if (!(attr.vc->GetValue(mit) == val1.vc->GetValue(mit))) return false; - } else if (op == common::O_NOT_NULL) { + } else if (op == common::Operator::O_NOT_NULL) { if (attr.vc->IsNull(mit)) return false; - } else if (op == common::O_IS_NULL) { + } else if (op == common::Operator::O_IS_NULL) { if (!attr.vc->IsNull(mit)) return false; - } else if (op == common::O_EXISTS || op == common::O_NOT_EXISTS) { + } else if (op == common::Operator::O_EXISTS || op == common::Operator::O_NOT_EXISTS) { DEBUG_ASSERT(dynamic_cast(attr.vc)); vcolumn::SubSelectColumn *sub = static_cast(attr.vc); bool is_nonempty = sub->CheckExists(mit); - if ((op == common::O_EXISTS && !is_nonempty) || (op == common::O_NOT_EXISTS && is_nonempty)) return false; - } else if (op == common::O_BETWEEN || op == common::O_NOT_BETWEEN) { + if ((op == common::Operator::O_EXISTS && !is_nonempty) || (op == common::Operator::O_NOT_EXISTS && is_nonempty)) + return false; + } else if (op == common::Operator::O_BETWEEN || op == common::Operator::O_NOT_BETWEEN) { if (attr.vc->IsNull(mit)) return false; // need to consider three value logic common::Tribool val1_res, val2_res; @@ -1053,7 +1059,7 @@ bool Descriptor::CheckCondition(const MIIterator &mit) { val2_res = val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(rcvo1 <= val2.vc->GetValue(mit, false)); } - if (op == common::O_BETWEEN) { + if (op == common::Operator::O_BETWEEN) { if (val1_res != true || val2_res != true) return false; } else { if (val1_res != false && val2_res != false) return false; @@ -1075,17 +1081,17 @@ bool Descriptor::CheckCondition(const MIIterator &mit) { bool Descriptor::IsNull(const MIIterator &mit) { MEASURE_FET("Descriptor::IsNull(...)"); if (null_after_simplify) return true; - if (op == common::O_TRUE || op == common::O_FALSE) return false; + if (op == common::Operator::O_TRUE || op == common::Operator::O_FALSE) return false; // Assumption: LockSourcePacks externally done. - if (op == common::O_EQ) { + if (op == common::Operator::O_EQ) { DEBUG_ASSERT(attr.vc && val1.vc); if (attr.vc->IsNull(mit) || val1.vc->IsNull(mit)) return true; - } else if (op == common::O_NOT_NULL || op == common::O_IS_NULL) { + } else if (op == common::Operator::O_NOT_NULL || op == common::Operator::O_IS_NULL) { return false; - } else if (op == common::O_EXISTS || op == common::O_NOT_EXISTS) { + } else if (op == common::Operator::O_EXISTS || op == common::Operator::O_NOT_EXISTS) { return false; - } else if (op == common::O_BETWEEN || op == common::O_NOT_BETWEEN) { + } else if (op == common::Operator::O_BETWEEN || op == common::Operator::O_NOT_BETWEEN) { if (attr.vc->IsNull(mit)) return true; // need to consider three value logic common::Tribool val1_res, val2_res; @@ -1134,11 +1140,11 @@ bool Descriptor::IsNull(const MIIterator &mit) { } common::Tribool Descriptor::RoughCheckSubselectCondition(MIIterator &mit, SubSelectOptimizationType sot) { - if (sot == PACK_BASED) return common::TRIBOOL_UNKNOWN; // not implemented + if (sot == SubSelectOptimizationType::PACK_BASED) return common::TRIBOOL_UNKNOWN; // not implemented MEASURE_FET("Descriptor::RoughCheckSubselectCondition(...)"); - if (op == common::O_TRUE) + if (op == common::Operator::O_TRUE) return true; - else if (op == common::O_FALSE) + else if (op == common::Operator::O_FALSE) return false; common::CT attr_t = attr.vc ? attr.vc->TypeName() : common::CT(); @@ -1148,13 +1154,15 @@ common::Tribool Descriptor::RoughCheckSubselectCondition(MIIterator &mit, SubSel (val2.vc && ATI::IsStringType(val2_t))) return common::TRIBOOL_UNKNOWN; - if (op == common::O_EXISTS || op == common::O_NOT_EXISTS) { + if (op == common::Operator::O_EXISTS || op == common::Operator::O_NOT_EXISTS) { DEBUG_ASSERT(dynamic_cast(attr.vc)); vcolumn::SubSelectColumn *sub = static_cast(attr.vc); common::Tribool is_empty = sub->RoughIsEmpty(mit, sot); - if ((op == common::O_EXISTS && is_empty == true) || (op == common::O_NOT_EXISTS && is_empty == false)) + if ((op == common::Operator::O_EXISTS && is_empty == true) || + (op == common::Operator::O_NOT_EXISTS && is_empty == false)) return false; - else if ((op == common::O_EXISTS && is_empty == false) || (op == common::O_NOT_EXISTS && is_empty == true)) + else if ((op == common::Operator::O_EXISTS && is_empty == false) || + (op == common::Operator::O_NOT_EXISTS && is_empty == true)) return true; return common::TRIBOOL_UNKNOWN; } else if (IsSetOperator(op)) { @@ -1162,7 +1170,7 @@ common::Tribool Descriptor::RoughCheckSubselectCondition(MIIterator &mit, SubSel return RoughCheckSetSubSelectCondition(mit, op, sot); } - if (op == common::O_BETWEEN || op == common::O_NOT_BETWEEN) { + if (op == common::Operator::O_BETWEEN || op == common::Operator::O_NOT_BETWEEN) { // TODO: to be implemented // if(attr.vc->IsNull(mit)) // return false; @@ -1172,7 +1180,7 @@ common::Tribool Descriptor::RoughCheckSubselectCondition(MIIterator &mit, SubSel // : common::Tribool(rcvo1 >= val1.vc->GetValue(mit, false)); // common::Tribool val2_res = val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN // : common::Tribool(rcvo1 <= val2.vc->GetValue(mit, false)); if(op == - // common::O_BETWEEN) { + // common::Operator::O_BETWEEN) { // if(val1_res != true || val2_res != true) // return false; //} else { @@ -1209,27 +1217,27 @@ common::Tribool Descriptor::RoughCheckSubselectCondition(MIIterator &mit, SubSel types::RCValueObject v = val->GetValue(mit); DEBUG_ASSERT(attr.vc); // NULLs are checked within operators - if (op == common::O_EQ) { + if (op == common::Operator::O_EQ) { if (v < *rv_min || v > *rv_max) return false; // else if(v == rv_min && v == rv_max) // return true; - } else if (op == common::O_NOT_EQ) { + } else if (op == common::Operator::O_NOT_EQ) { if (v == *rv_min && v == *rv_max) return false; // else if(v < rv_min || v > rv_max) // return true; - } else if (op == common::O_MORE_EQ) { + } else if (op == common::Operator::O_MORE_EQ) { if (v < *rv_min) return false; // else if(v >= rv_max) // return true; - } else if (op == common::O_MORE) { + } else if (op == common::Operator::O_MORE) { if (v <= *rv_min) return false; // else if(v > rv_max) // return true; - } else if (op == common::O_LESS_EQ) { + } else if (op == common::Operator::O_LESS_EQ) { if (v > *rv_max) return false; // else if(v <= rv_min) // return true; - } else if (op == common::O_LESS) { + } else if (op == common::Operator::O_LESS) { if (v >= *rv_max) return false; // else if(v < rv_min) // return true; @@ -1245,7 +1253,7 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o attr.vc->GetValueString(s1, mit); types::RCValueObject aggr; switch (op) { - case common::O_EQ_ALL: + case common::Operator::O_EQ_ALL: for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); it != end; ++it) { types::BString s2 = it->GetString(); // ConvertToBinaryForm(it->GetString(), buf_val1, buf_val1_len, @@ -1253,15 +1261,15 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o if (s1.IsNull() || it->IsNull() || CollationStrCmp(collation, s1, s2) != 0) return false; } break; - case common::O_IN: - case common::O_EQ_ANY: + case common::Operator::O_IN: + case common::Operator::O_EQ_ANY: if (s1.IsNull()) result = false; else result = (mvc->Contains(mit, s1) == true); break; - case common::O_NOT_IN: - case common::O_NOT_EQ_ALL: { + case common::Operator::O_NOT_IN: + case common::Operator::O_NOT_EQ_ALL: { if ((s1.IsNull() && mvc->NoValues(mit) != 0)) { result = false; break; @@ -1271,7 +1279,7 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o result = (res == true); break; } - case common::O_NOT_EQ_ANY: + case common::Operator::O_NOT_EQ_ANY: result = false; if (!s1.IsNull()) { for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); it != end; ++it) { @@ -1281,8 +1289,8 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o } } break; - case common::O_LESS_ALL: - case common::O_LESS_EQ_ALL: + case common::Operator::O_LESS_ALL: + case common::Operator::O_LESS_EQ_ALL: Query::UnmarkAllAny(op); aggr = mvc->GetSetMin(mit); if (mvc->NoValues(mit) == 0) @@ -1291,8 +1299,8 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o !CollationStrCmp(collation, s1, aggr.ToBString(), op)) result = false; break; - case common::O_MORE_ANY: - case common::O_MORE_EQ_ANY: + case common::Operator::O_MORE_ANY: + case common::Operator::O_MORE_EQ_ANY: Query::UnmarkAllAny(op); aggr = mvc->GetSetMin(mit); if (mvc->NoValues(mit) == 0) @@ -1300,8 +1308,8 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o else if (s1.IsNull() || aggr.IsNull() || !CollationStrCmp(collation, s1, aggr.ToBString(), op)) result = false; break; - case common::O_LESS_ANY: - case common::O_LESS_EQ_ANY: + case common::Operator::O_LESS_ANY: + case common::Operator::O_LESS_EQ_ANY: Query::UnmarkAllAny(op); aggr = mvc->GetSetMax(mit); if (mvc->NoValues(mit) == 0) @@ -1309,8 +1317,8 @@ bool Descriptor::CheckSetCondition_UTF(const MIIterator &mit, common::Operator o else if (s1.IsNull() || aggr.IsNull() || !CollationStrCmp(collation, s1, aggr.ToBString(), op)) result = false; break; - case common::O_MORE_ALL: - case common::O_MORE_EQ_ALL: + case common::Operator::O_MORE_ALL: + case common::Operator::O_MORE_EQ_ALL: Query::UnmarkAllAny(op); aggr = mvc->GetSetMax(mit); if (mvc->NoValues(mit) == 0) @@ -1331,9 +1339,9 @@ bool Descriptor::CheckSetCondition(const MIIterator &mit, common::Operator op) { bool result = true; vcolumn::MultiValColumn *mvc = static_cast(val1.vc); if (encoded) { - DEBUG_ASSERT(op == common::O_IN || op == common::O_NOT_IN); + DEBUG_ASSERT(op == common::Operator::O_IN || op == common::Operator::O_NOT_IN); if (attr.vc->IsNull(mit)) { - if (op == common::O_IN) return false; + if (op == common::Operator::O_IN) return false; if (mvc->NoValues(mit) != 0) return false; return true; } @@ -1346,27 +1354,28 @@ bool Descriptor::CheckSetCondition(const MIIterator &mit, common::Operator op) { int64_t val = attr.vc->GetNotNullValueInt64(mit); res = mvc->Contains64(mit, val); } - if (op == common::O_NOT_IN) res = !res; + if (op == common::Operator::O_NOT_IN) res = !res; return (res == true); } types::RCValueObject val = attr.vc->GetValue(mit); types::RCValueObject aggr; switch (op) { - case common::O_EQ_ALL: + case common::Operator::O_EQ_ALL: for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); it != end; ++it) { - if (val.IsNull() || it->IsNull() || !types::RCValueObject::compare(val, it->GetValue(), common::O_EQ, '\\')) + if (val.IsNull() || it->IsNull() || + !types::RCValueObject::compare(val, it->GetValue(), common::Operator::O_EQ, '\\')) return false; } break; - case common::O_IN: - case common::O_EQ_ANY: + case common::Operator::O_IN: + case common::Operator::O_EQ_ANY: if (val.IsNull()) result = false; else result = (mvc->Contains(mit, *val) == true); break; - case common::O_NOT_IN: - case common::O_NOT_EQ_ALL: { + case common::Operator::O_NOT_IN: + case common::Operator::O_NOT_EQ_ALL: { if ((val.IsNull() && mvc->NoValues(mit) != 0)) { result = false; break; @@ -1376,16 +1385,17 @@ bool Descriptor::CheckSetCondition(const MIIterator &mit, common::Operator op) { result = (res == true); break; } - case common::O_NOT_EQ_ANY: + case common::Operator::O_NOT_EQ_ANY: result = false; if (!val.IsNull()) { for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); it != end; ++it) { - if (!it->IsNull() && types::RCValueObject::compare(val, it->GetValue(), common::O_NOT_EQ, '\\')) return true; + if (!it->IsNull() && types::RCValueObject::compare(val, it->GetValue(), common::Operator::O_NOT_EQ, '\\')) + return true; } } break; - case common::O_LESS_ALL: - case common::O_LESS_EQ_ALL: + case common::Operator::O_LESS_ALL: + case common::Operator::O_LESS_EQ_ALL: Query::UnmarkAllAny(op); aggr = mvc->GetSetMin(mit); if (mvc->NoValues(mit) == 0) @@ -1394,8 +1404,8 @@ bool Descriptor::CheckSetCondition(const MIIterator &mit, common::Operator op) { !types::RCValueObject::compare(val, aggr, op, '\\')) result = false; break; - case common::O_MORE_ANY: - case common::O_MORE_EQ_ANY: + case common::Operator::O_MORE_ANY: + case common::Operator::O_MORE_EQ_ANY: Query::UnmarkAllAny(op); aggr = mvc->GetSetMin(mit); if (mvc->NoValues(mit) == 0) @@ -1403,8 +1413,8 @@ bool Descriptor::CheckSetCondition(const MIIterator &mit, common::Operator op) { else if (val.IsNull() || aggr.IsNull() || !types::RCValueObject::compare(val, aggr, op, '\\')) result = false; break; - case common::O_LESS_ANY: - case common::O_LESS_EQ_ANY: + case common::Operator::O_LESS_ANY: + case common::Operator::O_LESS_EQ_ANY: Query::UnmarkAllAny(op); aggr = mvc->GetSetMax(mit); if (mvc->NoValues(mit) == 0) @@ -1412,8 +1422,8 @@ bool Descriptor::CheckSetCondition(const MIIterator &mit, common::Operator op) { else if (val.IsNull() || aggr.IsNull() || !types::RCValueObject::compare(val, aggr, op, '\\')) result = false; break; - case common::O_MORE_ALL: - case common::O_MORE_EQ_ALL: + case common::Operator::O_MORE_ALL: + case common::Operator::O_MORE_EQ_ALL: Query::UnmarkAllAny(op); aggr = mvc->GetSetMax(mit); if (mvc->NoValues(mit) == 0) @@ -1434,7 +1444,7 @@ bool Descriptor::IsNull_Set(const MIIterator &mit, common::Operator op) { DEBUG_ASSERT(IsSetOperator(op)); vcolumn::MultiValColumn *mvc = static_cast(val1.vc); if (encoded) { - DEBUG_ASSERT(op == common::O_IN || op == common::O_NOT_IN); + DEBUG_ASSERT(op == common::Operator::O_IN || op == common::Operator::O_NOT_IN); if (attr.vc->IsNull(mit)) return true; common::Tribool res; if (attr.vc->Type().IsString() && !attr.vc->Type().IsLookup()) { @@ -1450,33 +1460,33 @@ bool Descriptor::IsNull_Set(const MIIterator &mit, common::Operator op) { types::RCValueObject val = attr.vc->GetValue(mit); types::RCValueObject aggr; switch (op) { - case common::O_EQ_ALL: - case common::O_NOT_EQ_ALL: + case common::Operator::O_EQ_ALL: + case common::Operator::O_NOT_EQ_ALL: if (val.IsNull() || mvc->ContainsNull(mit)) return true; break; - case common::O_IN: - case common::O_EQ_ANY: - case common::O_NOT_IN: - case common::O_NOT_EQ_ANY: + case common::Operator::O_IN: + case common::Operator::O_EQ_ANY: + case common::Operator::O_NOT_IN: + case common::Operator::O_NOT_EQ_ANY: if (val.IsNull()) return true; return (mvc->Contains(mit, *val) == common::TRIBOOL_UNKNOWN); - case common::O_LESS_ALL: - case common::O_LESS_EQ_ALL: + case common::Operator::O_LESS_ALL: + case common::Operator::O_LESS_EQ_ALL: aggr = mvc->GetSetMin(mit); if (val.IsNull() || aggr.IsNull() || mvc->ContainsNull(mit)) return true; break; - case common::O_MORE_ANY: - case common::O_MORE_EQ_ANY: + case common::Operator::O_MORE_ANY: + case common::Operator::O_MORE_EQ_ANY: aggr = mvc->GetSetMin(mit); if (val.IsNull() || aggr.IsNull()) return true; break; - case common::O_LESS_ANY: - case common::O_LESS_EQ_ANY: + case common::Operator::O_LESS_ANY: + case common::Operator::O_LESS_EQ_ANY: aggr = mvc->GetSetMax(mit); if (val.IsNull() || aggr.IsNull()) return true; break; - case common::O_MORE_ALL: - case common::O_MORE_EQ_ALL: + case common::Operator::O_MORE_ALL: + case common::Operator::O_MORE_EQ_ALL: aggr = mvc->GetSetMax(mit); if (val.IsNull() || aggr.IsNull() || mvc->ContainsNull(mit)) return true; break; @@ -1508,7 +1518,7 @@ common::Tribool Descriptor::RoughCheckSetSubSelectCondition(const MIIterator &mi common::Tribool rough_is_empty = sub->RoughIsEmpty(mit, sot); switch (op) { - case common::O_EQ_ALL: + case common::Operator::O_EQ_ALL: if (rough_is_empty == true) return true; // op ALL (empty_set) is TRUE else if (rough_is_empty == false && @@ -1517,8 +1527,8 @@ common::Tribool Descriptor::RoughCheckSetSubSelectCondition(const MIIterator &mi // else if(v == rv_min && v == rv_max) // return true; break; - case common::O_IN: - case common::O_EQ_ANY: + case common::Operator::O_IN: + case common::Operator::O_EQ_ANY: if (rough_is_empty == true) return false; // // op ANY (empty_set) is FALSE else if (rough_is_empty == false && @@ -1527,8 +1537,8 @@ common::Tribool Descriptor::RoughCheckSetSubSelectCondition(const MIIterator &mi // else if(v == rv_min && v == rv_max) // return true; break; - // case common::O_NOT_IN: - // case common::O_NOT_EQ_ALL: { + // case common::Operator::O_NOT_IN: + // case common::Operator::O_NOT_EQ_ALL: { // if((val.IsNull() && mvc->NoValues(mit) != 0)) { // result = false; // break; @@ -1538,7 +1548,7 @@ common::Tribool Descriptor::RoughCheckSetSubSelectCondition(const MIIterator &mi // result = (res == true); // break; // } - // case common::O_NOT_EQ_ANY: + // case common::Operator::O_NOT_EQ_ANY: // result = false; // if(!val.IsNull()) { // for(vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end @@ -1546,37 +1556,37 @@ common::Tribool Descriptor::RoughCheckSetSubSelectCondition(const MIIterator &mi // end; ++it) { // if(!it->IsNull() && // types::RCValueObject::compare(val, it->GetValue(), - // common::O_NOT_EQ)) + // common::Operator::O_NOT_EQ)) // return true; // } // } // break; - case common::O_LESS_ALL: - case common::O_LESS_EQ_ALL: + case common::Operator::O_LESS_ALL: + case common::Operator::O_LESS_EQ_ALL: Query::UnmarkAllAny(op); if (rough_is_empty == true) return true; // op ALL (empty_set) is TRUE else if (rough_is_empty == false && !types::RCValueObject::compare(v, *rv_max, op, '\\')) return false; break; - case common::O_MORE_ANY: - case common::O_MORE_EQ_ANY: + case common::Operator::O_MORE_ANY: + case common::Operator::O_MORE_EQ_ANY: Query::UnmarkAllAny(op); if (rough_is_empty == true) return false; // op ANY (empty_set) is FALSE else if (rough_is_empty == false && !types::RCValueObject::compare(v, *rv_min, op, '\\')) return false; break; - case common::O_LESS_ANY: - case common::O_LESS_EQ_ANY: + case common::Operator::O_LESS_ANY: + case common::Operator::O_LESS_EQ_ANY: Query::UnmarkAllAny(op); if (rough_is_empty == true) return false; // op ANY (empty_set) is FALSE else if (rough_is_empty == false && !types::RCValueObject::compare(v, *rv_max, op, '\\')) return false; break; - case common::O_MORE_ALL: - case common::O_MORE_EQ_ALL: + case common::Operator::O_MORE_ALL: + case common::Operator::O_MORE_EQ_ALL: Query::UnmarkAllAny(op); if (rough_is_empty == true) return true; // op ALL (empty_set) is TRUE @@ -1654,11 +1664,11 @@ void Descriptor::CoerceColumnTypes() { bool Descriptor::NullMayBeTrue() // true, if the descriptor may give nontrivial // answer if any of involved dimension is null { - if (op == common::O_IS_NULL || op == common::O_NOT_NULL) return true; + if (op == common::Operator::O_IS_NULL || op == common::Operator::O_NOT_NULL) return true; if (IsType_OrTree()) return tree->NullMayBeTrue(); // t1.a not between t2.b and t1.b - if (op == common::O_NOT_BETWEEN) return true; + if (op == common::Operator::O_NOT_BETWEEN) return true; // TODO: more precise conditions // Examples: // (a is null) = 1 @@ -1669,9 +1679,9 @@ bool Descriptor::NullMayBeTrue() // true, if the descriptor may give nontrivial // f < ALL (1, 2, a) // For now, a simplistic version: any complex case is true. - if (attr.vc && !attr.vc->IsSingleColumn() && !attr.vc->IsConst()) return true; - if (val1.vc && !val1.vc->IsSingleColumn() && !val1.vc->IsConst()) return true; - if (val2.vc && !val2.vc->IsSingleColumn() && !val2.vc->IsConst()) return true; + if (attr.vc && !static_cast(attr.vc->IsSingleColumn()) && !attr.vc->IsConst()) return true; + if (val1.vc && !static_cast(val1.vc->IsSingleColumn()) && !val1.vc->IsConst()) return true; + if (val2.vc && !static_cast(val2.vc->IsSingleColumn()) && !val2.vc->IsConst()) return true; return false; } @@ -1692,9 +1702,9 @@ bool Descriptor::WithoutAttrs() { if (IsType_OrTree()) return tree->WithoutAttrs(); else - return (!attr.vc || attr.vc->IsSingleColumn() != vcolumn::VirtualColumn::SC_ATTR) && - (!val1.vc || val1.vc->IsSingleColumn() != vcolumn::VirtualColumn::SC_ATTR) && - (!val2.vc || val2.vc->IsSingleColumn() != vcolumn::VirtualColumn::SC_ATTR); + return (!attr.vc || attr.vc->IsSingleColumn() != vcolumn::VirtualColumn::single_col_t::SC_ATTR) && + (!val1.vc || val1.vc->IsSingleColumn() != vcolumn::VirtualColumn::single_col_t::SC_ATTR) && + (!val2.vc || val2.vc->IsSingleColumn() != vcolumn::VirtualColumn::single_col_t::SC_ATTR); } bool Descriptor::WithoutTypeCast() { @@ -1723,7 +1733,7 @@ void Descriptor::ClearRoughValues() { if (IsType_OrTree()) tree->root->ClearRoughValues(); else - rv = common::RS_UNKNOWN; + rv = common::RSValue::RS_UNKNOWN; } void Descriptor::RoughAccumulate(MIIterator &mit) { @@ -1735,10 +1745,10 @@ void Descriptor::SimplifyAfterRoughAccumulate() { if (IsType_OrTree()) { if (tree->UseRoughAccumulated()) Simplify(false); } else { - if (rv == common::RS_NONE) - op = common::O_FALSE; - else if (rv == common::RS_ALL) - op = common::O_TRUE; + if (rv == common::RSValue::RS_NONE) + op = common::Operator::O_FALSE; + else if (rv == common::RSValue::RS_ALL) + op = common::Operator::O_TRUE; } } @@ -1754,7 +1764,7 @@ bool Descriptor::CopyDesCond(MIUpdatingIterator &mit) { else pack_type = common::PackType::STR; - if ((op == common::O_IN || op == common::O_NOT_IN)) { + if ((op == common::Operator::O_IN || op == common::Operator::O_NOT_IN)) { vcolumn::MultiValColumn *multival_column = static_cast(val1.vc); if (pack_type == common::PackType::STR) { val1.cond_value.clear(); @@ -1797,7 +1807,7 @@ bool Descriptor::IsleftIndexSearch() const { if (IsType_AttrValOrAttrValVal() && encoded) { auto col = static_cast(attr.vc); if (table && table->NoTables() == 1 && table->GetTableP(0)->TableType() == TType::TABLE && - col->GetPhysical()->ColType() == PhysicalColumn::RCATTR) { + col->GetPhysical()->ColType() == PhysicalColumn::phys_col_t::RCATTR) { auto path = (static_cast(table->GetTableP(0))->Path()); auto indextab = rceng->GetTableIndex(path.replace_extension().string()); uint32_t colid = static_cast(col->GetPhysical())->ColId(); @@ -1826,46 +1836,52 @@ void DescTreeNode::PrepareValueSet(MIIterator &mit) { } bool IsSetOperator(common::Operator op) { - return IsSetAnyOperator(op) || IsSetAllOperator(op) || op == common::O_IN || op == common::O_NOT_IN; + return IsSetAnyOperator(op) || IsSetAllOperator(op) || op == common::Operator::O_IN || + op == common::Operator::O_NOT_IN; } bool IsSetAllOperator(common::Operator op) { - return op == common::O_EQ_ALL || op == common::O_NOT_EQ_ALL || op == common::O_LESS_ALL || op == common::O_MORE_ALL || - op == common::O_LESS_EQ_ALL || op == common::O_MORE_EQ_ALL; + return op == common::Operator::O_EQ_ALL || op == common::Operator::O_NOT_EQ_ALL || + op == common::Operator::O_LESS_ALL || op == common::Operator::O_MORE_ALL || + op == common::Operator::O_LESS_EQ_ALL || op == common::Operator::O_MORE_EQ_ALL; } bool IsSimpleEqualityOperator(common::Operator op) { - return op == common::O_EQ || op == common::O_NOT_EQ || op == common::O_LESS || op == common::O_MORE || - op == common::O_LESS_EQ || op == common::O_MORE_EQ; + return op == common::Operator::O_EQ || op == common::Operator::O_NOT_EQ || op == common::Operator::O_LESS || + op == common::Operator::O_MORE || op == common::Operator::O_LESS_EQ || op == common::Operator::O_MORE_EQ; } bool IsSetAnyOperator(common::Operator op) { - return op == common::O_EQ_ANY || op == common::O_NOT_EQ_ANY || op == common::O_LESS_ANY || op == common::O_MORE_ANY || - op == common::O_LESS_EQ_ANY || op == common::O_MORE_EQ_ANY; + return op == common::Operator::O_EQ_ANY || op == common::Operator::O_NOT_EQ_ANY || + op == common::Operator::O_LESS_ANY || op == common::Operator::O_MORE_ANY || + op == common::Operator::O_LESS_EQ_ANY || op == common::Operator::O_MORE_EQ_ANY; } bool ISTypeOfEqualOperator(common::Operator op) { - return op == common::O_EQ || op == common::O_EQ_ALL || op == common::O_EQ_ANY; + return op == common::Operator::O_EQ || op == common::Operator::O_EQ_ALL || op == common::Operator::O_EQ_ANY; } bool ISTypeOfNotEqualOperator(common::Operator op) { - return op == common::O_NOT_EQ || op == common::O_NOT_EQ_ALL || op == common::O_NOT_EQ_ANY; + return op == common::Operator::O_NOT_EQ || op == common::Operator::O_NOT_EQ_ALL || + op == common::Operator::O_NOT_EQ_ANY; } bool ISTypeOfLessOperator(common::Operator op) { - return op == common::O_LESS || op == common::O_LESS_ALL || op == common::O_LESS_ANY; + return op == common::Operator::O_LESS || op == common::Operator::O_LESS_ALL || op == common::Operator::O_LESS_ANY; } bool ISTypeOfLessEqualOperator(common::Operator op) { - return op == common::O_LESS_EQ || op == common::O_LESS_EQ_ALL || op == common::O_LESS_EQ_ANY; + return op == common::Operator::O_LESS_EQ || op == common::Operator::O_LESS_EQ_ALL || + op == common::Operator::O_LESS_EQ_ANY; } bool ISTypeOfMoreOperator(common::Operator op) { - return op == common::O_MORE || op == common::O_MORE_ALL || op == common::O_MORE_ANY; + return op == common::Operator::O_MORE || op == common::Operator::O_MORE_ALL || op == common::Operator::O_MORE_ANY; } bool ISTypeOfMoreEqualOperator(common::Operator op) { - return op == common::O_MORE_EQ || op == common::O_MORE_EQ_ALL || op == common::O_MORE_EQ_ANY; + return op == common::Operator::O_MORE_EQ || op == common::Operator::O_MORE_EQ_ALL || + op == common::Operator::O_MORE_EQ_ANY; } DescTree::DescTree(CQTerm e1, common::Operator op, CQTerm e2, CQTerm e3, TempTable *t, int no_dims, char like_esc) { @@ -1933,13 +1949,13 @@ void DescTree::Display(DescTreeNode *node) { if (node->right) Display(node->right); std::cout << "------------------------" << std::endl; if (node->left) - std::cout << (node->desc.lop ? "OR" : "AND") << std::endl; + std::cout << (static_cast(node->desc.lop) ? "OR" : "AND") << std::endl; else { char buf[50]; std::cout << node->desc.attr.ToString(buf, 0) << std::endl; std::cout << "........" << std::endl; - if (node->desc.op) - std::cout << node->desc.op << std::endl; + if (static_cast(node->desc.op)) + std::cout << static_cast(node->desc.op) << std::endl; else std::cout << "=" << std::endl; std::cout << "........" << std::endl; @@ -1981,42 +1997,42 @@ common::Tribool DescTreeNode::Simplify(DescTreeNode *&root, bool in_having) { common::Tribool left_res, right_res; if (left) left_res = left->Simplify(root, in_having); if (right) right_res = right->Simplify(root, in_having); - if (desc.op == common::O_OR_TREE) { - common::Tribool res = (desc.lop == common::O_AND ? common::Tribool::And(left_res, right_res) - : common::Tribool::Or(left_res, right_res)); + if (desc.op == common::Operator::O_OR_TREE) { + common::Tribool res = (desc.lop == common::LogicalOperator::O_AND ? common::Tribool::And(left_res, right_res) + : common::Tribool::Or(left_res, right_res)); if (res == true) { - desc.op = common::O_TRUE; + desc.op = common::Operator::O_TRUE; delete left; left = NULL; delete right; right = NULL; } else if (res == false) { - desc.op = common::O_FALSE; + desc.op = common::Operator::O_FALSE; delete left; left = NULL; delete right; right = NULL; - } else if (!left->left && !right->right && desc.lop == common::O_AND) { + } else if (!left->left && !right->right && desc.lop == common::LogicalOperator::O_AND) { bool merged = ParameterizedFilter::TryToMerge(left->desc, right->desc); if (merged) { delete right; right = NULL; res = ReplaceNode(this, left, root); } - } else if (desc.lop == common::O_OR) { - if (left->desc.op == common::O_FALSE) { + } else if (desc.lop == common::LogicalOperator::O_OR) { + if (left->desc.op == common::Operator::O_FALSE) { delete left; left = NULL; res = ReplaceNode(this, right, root); - } else if (left->desc.op == common::O_TRUE) { + } else if (left->desc.op == common::Operator::O_TRUE) { delete right; right = NULL; res = ReplaceNode(this, left, root); - } else if (right->desc.op == common::O_FALSE) { + } else if (right->desc.op == common::Operator::O_FALSE) { delete right; right = NULL; res = ReplaceNode(this, left, root); - } else if (right->desc.op == common::O_TRUE) { + } else if (right->desc.op == common::Operator::O_TRUE) { delete left; left = NULL; res = ReplaceNode(this, right, root); @@ -2026,24 +2042,25 @@ common::Tribool DescTreeNode::Simplify(DescTreeNode *&root, bool in_having) { return res; } desc.Simplify(in_having); - return desc.op == common::O_TRUE ? true : (desc.op == common::O_FALSE ? false : common::TRIBOOL_UNKNOWN); + return desc.op == common::Operator::O_TRUE ? true + : (desc.op == common::Operator::O_FALSE ? false : common::TRIBOOL_UNKNOWN); } common::RSValue DescTreeNode::EvaluateRoughlyPack(const MIIterator &mit) { - if (desc.op == common::O_OR_TREE) { + if (desc.op == common::Operator::O_OR_TREE) { common::RSValue left_res = left->EvaluateRoughlyPack(mit); common::RSValue right_res = right->EvaluateRoughlyPack(mit); common::RSValue r; - if (desc.lop == common::O_AND) + if (desc.lop == common::LogicalOperator::O_AND) r = And(left_res, right_res); else r = Or(left_res, right_res); - if (desc.rv == common::RS_UNKNOWN) + if (desc.rv == common::RSValue::RS_UNKNOWN) desc.rv = r; - else if (desc.rv == common::RS_NONE && r != common::RS_NONE) - desc.rv = common::RS_SOME; - else if (desc.rv == common::RS_ALL && r != common::RS_ALL) - desc.rv = common::RS_SOME; + else if (desc.rv == common::RSValue::RS_NONE && r != common::RSValue::RS_NONE) + desc.rv = common::RSValue::RS_SOME; + else if (desc.rv == common::RSValue::RS_ALL && r != common::RSValue::RS_ALL) + desc.rv = common::RSValue::RS_SOME; return r; } return desc.EvaluateRoughlyPack(mit); @@ -2052,7 +2069,7 @@ common::RSValue DescTreeNode::EvaluateRoughlyPack(const MIIterator &mit) { bool DescTreeNode::CheckCondition(MIIterator &mit) { if (left) { // i.e., not a leaf DEBUG_ASSERT(right); // if left is not empty so should be right - if (desc.lop == common::O_AND) { + if (desc.lop == common::LogicalOperator::O_AND) { if (!left->CheckCondition(mit)) return false; if (!right->CheckCondition(mit)) return false; return true; @@ -2079,7 +2096,7 @@ bool DescTreeNode::IsNull(MIIterator &mit) DEBUG_ASSERT(right); // if left is not empty so should be right bool left_res = left->CheckCondition(mit); bool right_res = right->CheckCondition(mit); - if (desc.lop == common::O_AND) { + if (desc.lop == common::LogicalOperator::O_AND) { if (left_res == true && right_res == false && right->IsNull(mit)) return true; if (left_res == false && right_res == true && left->IsNull(mit)) @@ -2114,35 +2131,35 @@ void DescTreeNode::EvaluatePack(MIUpdatingIterator &mit) { // optimized case if (left) { // i.e., not a leaf DEBUG_ASSERT(right); // if left is not empty so should be right - if (desc.lop == common::O_AND) { - if (left->desc.rv == common::RS_NONE || right->desc.rv == common::RS_NONE) { + if (desc.lop == common::LogicalOperator::O_AND) { + if (left->desc.rv == common::RSValue::RS_NONE || right->desc.rv == common::RSValue::RS_NONE) { mit.ResetCurrentPack(); mit.NextPackrow(); return; } - if (left->desc.rv == common::RS_ALL && right->desc.rv == common::RS_ALL) { + if (left->desc.rv == common::RSValue::RS_ALL && right->desc.rv == common::RSValue::RS_ALL) { mit.NextPackrow(); return; } int pack_start = mit.GetCurPackrow(single_dim); - if (left->desc.rv != common::RS_ALL && mit.IsValid()) left->EvaluatePack(mit); - if (right->desc.rv != common::RS_ALL && mit.RewindToPack(pack_start) && + if (left->desc.rv != common::RSValue::RS_ALL && mit.IsValid()) left->EvaluatePack(mit); + if (right->desc.rv != common::RSValue::RS_ALL && mit.RewindToPack(pack_start) && mit.IsValid()) // otherwise the pack is already empty right->EvaluatePack(mit); return; } else { - if (left->desc.rv == common::RS_NONE && right->desc.rv == common::RS_NONE) { + if (left->desc.rv == common::RSValue::RS_NONE && right->desc.rv == common::RSValue::RS_NONE) { mit.ResetCurrentPack(); mit.NextPackrow(); return; } - if (left->desc.rv == common::RS_ALL || right->desc.rv == common::RS_ALL) { + if (left->desc.rv == common::RSValue::RS_ALL || right->desc.rv == common::RSValue::RS_ALL) { mit.NextPackrow(); return; } - if (left->desc.rv == common::RS_NONE) + if (left->desc.rv == common::RSValue::RS_NONE) right->EvaluatePack(mit); - else if (right->desc.rv == common::RS_NONE) + else if (right->desc.rv == common::RSValue::RS_NONE) left->EvaluatePack(mit); else { int pack_start = mit.GetCurPackrow(single_dim); @@ -2204,7 +2221,7 @@ bool DescTreeNode::NullMayBeTrue() { if (left->NullMayBeTrue() || right->NullMayBeTrue()) return true; // special case: (a1 = 3) OR true // return false only if both sides of OR contain all involved dims - if (desc.lop == common::O_OR) { + if (desc.lop == common::LogicalOperator::O_OR) { DimensionVector dims1(desc.right_dims.Size()); DimensionVector dims2(desc.right_dims.Size()); left->DimensionUsed(dims1); @@ -2226,7 +2243,7 @@ void DescTreeNode::EncodeIfPossible(bool for_rough_query, bool additional_nulls) double DescTreeNode::EvaluateConditionWeight(ParameterizedFilter *p, bool for_or) { if (left && right) { - bool or_here = (desc.lop == common::O_OR); // and: smaller result first; or: bigger result first + bool or_here = (desc.lop == common::LogicalOperator::O_OR); // and: smaller result first; or: bigger result first double e1 = left->EvaluateConditionWeight(p, or_here); double e2 = right->EvaluateConditionWeight(p, or_here); if (e1 > e2) { @@ -2251,28 +2268,28 @@ void DescTreeNode::CollectDescriptor(std::vector> &de bool DescTreeNode::CanBeExtracted(Descriptor &searched_desc) { if (left && right) { - if (desc.lop == common::O_AND) { + if (desc.lop == common::LogicalOperator::O_AND) { if (left->CanBeExtracted(searched_desc)) return true; return right->CanBeExtracted(searched_desc); } else { - DEBUG_ASSERT(desc.lop == common::O_OR); + DEBUG_ASSERT(desc.lop == common::LogicalOperator::O_OR); return (left->CanBeExtracted(searched_desc) && right->CanBeExtracted(searched_desc)); } } else { - return ((parent && parent->desc.lop == common::O_AND && desc <= searched_desc) || - (parent && parent->desc.lop == common::O_OR && desc == searched_desc)); + return ((parent && parent->desc.lop == common::LogicalOperator::O_AND && desc <= searched_desc) || + (parent && parent->desc.lop == common::LogicalOperator::O_OR && desc == searched_desc)); } } // bool DescTreeNode::IsWidestRange(Descriptor& searched_desc) //{ // if(left && right) { -// if(desc.lop == common::O_AND) { +// if(desc.lop == common::LogicalOperator::O_AND) { // if(left->IsWidestRange(searched_desc)) // return true; // return right->IsWidestRange(searched_desc); // } else { -// DEBUG_ASSERT(desc.lop == common::O_OR); +// DEBUG_ASSERT(desc.lop == common::LogicalOperator::O_OR); // return (left->IsWidestRange(searched_desc) && // right->IsWidestRange(searched_desc)); // } @@ -2287,21 +2304,21 @@ void DescTreeNode::ExtractDescriptor(Descriptor &searched_desc, DescTreeNode *&r left->ExtractDescriptor(searched_desc, root); } else { DEBUG_ASSERT(left && right); - if (/*(desc.lop == common::O_AND && left->desc <= searched_desc) || - (desc.lop == common::O_OR && */ + if (/*(desc.lop == common::LogicalOperator::O_AND && left->desc <= searched_desc) || + (desc.lop == common::LogicalOperator::O_OR && */ left->desc == searched_desc /*)*/) { delete left; left = NULL; DescTreeNode *old_right = right; - bool parent_is_or = (desc.lop == common::O_OR); + bool parent_is_or = (desc.lop == common::LogicalOperator::O_OR); ReplaceNode(this, right, root); // if there is no parent and there is single right node // it means that the whole tree should be empty // and extracted descriptor should replace the tree - // we make this tree trivial with one common::O_TRUE node + // we make this tree trivial with one common::Operator::O_TRUE node if (parent_is_or) { old_right->desc = Descriptor(); - old_right->desc.op = common::O_TRUE; + old_right->desc.op = common::Operator::O_TRUE; } else if (old_right->right) { old_right->ExtractDescriptor(searched_desc, root); } @@ -2314,21 +2331,21 @@ void DescTreeNode::ExtractDescriptor(Descriptor &searched_desc, DescTreeNode *&r right->ExtractDescriptor(searched_desc, root); } else { DEBUG_ASSERT(left && right); - if (/*(desc.lop == common::O_AND && right->desc <= searched_desc) || - (desc.lop == common::O_OR &&*/ + if (/*(desc.lop == common::LogicalOperator::O_AND && right->desc <= searched_desc) || + (desc.lop == common::LogicalOperator::O_OR &&*/ right->desc == searched_desc /*)*/) { delete right; right = NULL; DescTreeNode *old_left = left; - bool parent_is_or = (desc.lop == common::O_OR); + bool parent_is_or = (desc.lop == common::LogicalOperator::O_OR); ReplaceNode(this, left, root); // if there is no parent and there is single left node // it means that the whole tree should be empty // and extracted descriptor should replace the tree - // we make this tree trivial with one common::O_TRUE node + // we make this tree trivial with one common::Operator::O_TRUE node if (parent_is_or) { old_left->desc = Descriptor(); - old_left->desc.op = common::O_TRUE; + old_left->desc.op = common::Operator::O_TRUE; } else if (old_left->left) { old_left->ExtractDescriptor(searched_desc, root); } @@ -2352,8 +2369,8 @@ common::Tribool DescTreeNode::ReplaceNode(DescTreeNode *src, DescTreeNode *dst, src->right = NULL; } delete src; - if (dst->desc.op == common::O_FALSE) return false; - if (dst->desc.op == common::O_TRUE) return true; + if (dst->desc.op == common::Operator::O_FALSE) return false; + if (dst->desc.op == common::Operator::O_TRUE) return true; return common::TRIBOOL_UNKNOWN; } @@ -2362,7 +2379,7 @@ void DescTreeNode::RoughAccumulate(MIIterator &mit) { left->RoughAccumulate(mit); right->RoughAccumulate(mit); } else { - if (desc.rv == common::RS_SOME) return; + if (desc.rv == common::RSValue::RS_SOME) return; desc.EvaluateRoughlyPack(mit); // updating desc.rv inside } } @@ -2374,11 +2391,11 @@ bool DescTreeNode::UseRoughAccumulated() { return (res1 || res2); } else { bool res = false; - if (desc.rv == common::RS_NONE) { - desc.op = common::O_FALSE; + if (desc.rv == common::RSValue::RS_NONE) { + desc.op = common::Operator::O_FALSE; res = true; - } else if (desc.rv == common::RS_ALL) { - desc.op = common::O_TRUE; + } else if (desc.rv == common::RSValue::RS_ALL) { + desc.op = common::Operator::O_TRUE; res = true; } return res; @@ -2398,7 +2415,7 @@ void DescTreeNode::MakeSingleColsPrivate(std::vector & left->MakeSingleColsPrivate(virt_cols); right->MakeSingleColsPrivate(virt_cols); } else { - if (desc.attr.vc && desc.attr.vc->IsSingleColumn()) { + if (desc.attr.vc && static_cast(desc.attr.vc->IsSingleColumn())) { size_t i = 0; for (; i < virt_cols.size(); i++) if (virt_cols[i] == desc.attr.vc) break; @@ -2407,7 +2424,7 @@ void DescTreeNode::MakeSingleColsPrivate(std::vector & desc.attr.is_vc_owner = true; virt_cols[i] = desc.attr.vc; } - if (desc.val1.vc && desc.val1.vc->IsSingleColumn()) { + if (desc.val1.vc && static_cast(desc.val1.vc->IsSingleColumn())) { size_t i = 0; for (; i < virt_cols.size(); i++) if (virt_cols[i] == desc.val1.vc) break; @@ -2416,7 +2433,7 @@ void DescTreeNode::MakeSingleColsPrivate(std::vector & desc.val1.is_vc_owner = true; virt_cols[i] = desc.val1.vc; } - if (desc.val2.vc && desc.val2.vc->IsSingleColumn()) { + if (desc.val2.vc && static_cast(desc.val2.vc->IsSingleColumn())) { size_t i = 0; for (; i < virt_cols.size(); i++) if (virt_cols[i] == desc.val2.vc) break; @@ -2464,7 +2481,7 @@ void Descriptor::MClearRoughValues(int taskid) { if (IsType_OrTree()) tree->root->MClearRoughValues(taskid); else - rvs[taskid] = common::RS_UNKNOWN; + rvs[taskid] = common::RSValue::RS_UNKNOWN; } void DescTreeNode::MClearRoughValues(int taskid) { @@ -2477,32 +2494,32 @@ void DescTreeNode::MClearRoughValues(int taskid) { common::RSValue Descriptor::MEvaluateRoughlyPack(const MIIterator &mit, int taskid) { if (IsType_OrTree()) return tree->root->MEvaluateRoughlyPack(mit, taskid); - common::RSValue r = common::RS_SOME; + common::RSValue r = common::RSValue::RS_SOME; if (attr.vc /*&& !attr.vc->IsConst()*/) r = attr.vc->RoughCheck(mit, *this); - if (rvs[taskid] == common::RS_UNKNOWN) + if (rvs[taskid] == common::RSValue::RS_UNKNOWN) rvs[taskid] = r; - else if (rvs[taskid] == common::RS_NONE && r != common::RS_NONE) - rvs[taskid] = common::RS_SOME; - else if (rvs[taskid] == common::RS_ALL && r != common::RS_ALL) - rvs[taskid] = common::RS_SOME; + else if (rvs[taskid] == common::RSValue::RS_NONE && r != common::RSValue::RS_NONE) + rvs[taskid] = common::RSValue::RS_SOME; + else if (rvs[taskid] == common::RSValue::RS_ALL && r != common::RSValue::RS_ALL) + rvs[taskid] = common::RSValue::RS_SOME; return r; } common::RSValue DescTreeNode::MEvaluateRoughlyPack(const MIIterator &mit, int taskid) { - if (desc.op == common::O_OR_TREE) { + if (desc.op == common::Operator::O_OR_TREE) { common::RSValue left_res = left->MEvaluateRoughlyPack(mit, taskid); common::RSValue right_res = right->MEvaluateRoughlyPack(mit, taskid); common::RSValue r; - if (desc.lop == common::O_AND) + if (desc.lop == common::LogicalOperator::O_AND) r = And(left_res, right_res); else r = Or(left_res, right_res); - if (desc.rvs[taskid] == common::RS_UNKNOWN) + if (desc.rvs[taskid] == common::RSValue::RS_UNKNOWN) desc.rvs[taskid] = r; - else if (desc.rvs[taskid] == common::RS_NONE && r != common::RS_NONE) - desc.rvs[taskid] = common::RS_SOME; - else if (desc.rvs[taskid] == common::RS_ALL && r != common::RS_ALL) - desc.rvs[taskid] = common::RS_SOME; + else if (desc.rvs[taskid] == common::RSValue::RS_NONE && r != common::RSValue::RS_NONE) + desc.rvs[taskid] = common::RSValue::RS_SOME; + else if (desc.rvs[taskid] == common::RSValue::RS_ALL && r != common::RSValue::RS_ALL) + desc.rvs[taskid] = common::RSValue::RS_SOME; return r; } return desc.MEvaluateRoughlyPack(mit, taskid); @@ -2526,7 +2543,7 @@ void DescTreeNode::MPrepareToLock(int locked_by, int taskid) { void Descriptor::InitRvs(int value) { parallsize = value; for (int i = 0; i < parallsize + 1; i++) { - rvs.push_back(common::RS_UNKNOWN); + rvs.push_back(common::RSValue::RS_UNKNOWN); } } @@ -2552,7 +2569,7 @@ void DescTreeNode::InitLocks(int value) { void Descriptor::InitParallel(int value, MIIterator &mit) { parallsize = value; for (int i = 0; i < parallsize + 1; i++) { - rvs.push_back(common::RS_UNKNOWN); + rvs.push_back(common::RSValue::RS_UNKNOWN); } if (encoded) { PrepareValueSet(mit); @@ -2579,35 +2596,35 @@ void DescTreeNode::MEvaluatePack(MIUpdatingIterator &mit, int taskid) { // optimized case if (left) { // i.e., not a leaf DEBUG_ASSERT(right); // if left is not empty so should be right - if (desc.lop == common::O_AND) { - if (left->desc.rvs[taskid] == common::RS_NONE || right->desc.rvs[taskid] == common::RS_NONE) { + if (desc.lop == common::LogicalOperator::O_AND) { + if (left->desc.rvs[taskid] == common::RSValue::RS_NONE || right->desc.rvs[taskid] == common::RSValue::RS_NONE) { mit.ResetCurrentPack(); mit.NextPackrow(); return; } - if (left->desc.rvs[taskid] == common::RS_ALL && right->desc.rvs[taskid] == common::RS_ALL) { + if (left->desc.rvs[taskid] == common::RSValue::RS_ALL && right->desc.rvs[taskid] == common::RSValue::RS_ALL) { mit.NextPackrow(); return; } int pack_start = mit.GetCurPackrow(single_dim); - if (left->desc.rvs[taskid] != common::RS_ALL && mit.IsValid()) left->MEvaluatePack(mit, taskid); - if (right->desc.rvs[taskid] != common::RS_ALL && mit.RewindToPack(pack_start) && + if (left->desc.rvs[taskid] != common::RSValue::RS_ALL && mit.IsValid()) left->MEvaluatePack(mit, taskid); + if (right->desc.rvs[taskid] != common::RSValue::RS_ALL && mit.RewindToPack(pack_start) && mit.IsValid()) // otherwise the pack is already empty right->MEvaluatePack(mit, taskid); return; } else { - if (left->desc.rvs[taskid] == common::RS_NONE && right->desc.rvs[taskid] == common::RS_NONE) { + if (left->desc.rvs[taskid] == common::RSValue::RS_NONE && right->desc.rvs[taskid] == common::RSValue::RS_NONE) { mit.ResetCurrentPack(); mit.NextPackrow(); return; } - if (left->desc.rvs[taskid] == common::RS_ALL || right->desc.rvs[taskid] == common::RS_ALL) { + if (left->desc.rvs[taskid] == common::RSValue::RS_ALL || right->desc.rvs[taskid] == common::RSValue::RS_ALL) { mit.NextPackrow(); return; } - if (left->desc.rvs[taskid] == common::RS_NONE) + if (left->desc.rvs[taskid] == common::RSValue::RS_NONE) right->MEvaluatePack(mit, taskid); - else if (right->desc.rvs[taskid] == common::RS_NONE) + else if (right->desc.rvs[taskid] == common::RSValue::RS_NONE) left->MEvaluatePack(mit, taskid); else { int pack_start = mit.GetCurPackrow(single_dim); diff --git a/storage/stonedb/core/descriptor.h b/storage/stonedb/core/descriptor.h index 0421678fa..586564c85 100644 --- a/storage/stonedb/core/descriptor.h +++ b/storage/stonedb/core/descriptor.h @@ -34,12 +34,12 @@ class DescTree; class MIUpdatingIterator; class QueryOperator; -/*! DT_NON_JOIN - 1 dimension condition - * DT_SIMPLE_JOIN - suitable for e.g. hash join - * DT_COMPLEX_JOIN - possibly requires nested loop join +/*! DescriptorJoinType::DT_NON_JOIN - 1 dimension condition + * DescriptorJoinType::DT_SIMPLE_JOIN - suitable for e.g. hash join + * DescriptorJoinType::DT_COMPLEX_JOIN - possibly requires nested loop join */ -enum DescriptorJoinType { DT_NON_JOIN, DT_SIMPLE_JOIN, DT_COMPLEX_JOIN, DT_NOT_KNOWN_YET }; -enum SubSelectOptimizationType { ROW_BASED, PACK_BASED }; +enum class DescriptorJoinType { DT_NON_JOIN, DT_SIMPLE_JOIN, DT_COMPLEX_JOIN, DT_NOT_KNOWN_YET }; +enum class SubSelectOptimizationType { ROW_BASED, PACK_BASED }; class Descriptor { public: @@ -89,9 +89,9 @@ class Descriptor { // and other may be outer void Simplify(bool in_having = false); void SwitchSides(); - bool IsEmpty() const { return op == common::O_UNKNOWN_FUNC; } - bool IsTrue() const { return op == common::O_TRUE; } - bool IsFalse() const { return op == common::O_FALSE; } + bool IsEmpty() const { return op == common::Operator::O_UNKNOWN_FUNC; } + bool IsTrue() const { return op == common::Operator::O_TRUE; } + bool IsFalse() const { return op == common::Operator::O_FALSE; } bool IsSDBItemsEmpty(); bool WithoutAttrs(); bool WithoutTypeCast(); @@ -112,7 +112,7 @@ class Descriptor { void DimensionUsed(DimensionVector &dims); bool IsParameterized() const; bool IsDeterministic() const; - bool IsType_OrTree() const { return op == common::O_OR_TREE; } + bool IsType_OrTree() const { return op == common::Operator::O_OR_TREE; } bool IsType_JoinSimple() const; bool IsType_AttrAttr() const; bool IsType_AttrValOrAttrValVal() const; @@ -126,7 +126,7 @@ class Descriptor { bool IsType_JoinComplex() const; bool IsType_Join() const { return (IsType_JoinSimple() || IsType_JoinComplex()); } bool IsDelayed() const { return delayed; } - bool IsInner() { return right_dims.IsEmpty(); } // join_type == JO_INNER; } + bool IsInner() { return right_dims.IsEmpty(); } // join_type == JoinType::JO_INNER; } bool IsOuter() { return !right_dims.IsEmpty(); } // (IsLeftJoin() || IsRightJoin() || IsFullOuterJoin()); } char *ToString(char buf[], size_t buf_ct); void CoerceColumnTypes(); @@ -182,7 +182,7 @@ class Descriptor { DTCollation collation; public: - bool null_after_simplify; // true if Simplify set common::O_FALSE because of + bool null_after_simplify; // true if Simplify set common::Operator::O_FALSE because of // NULL }; diff --git a/storage/stonedb/core/dimension_group.cpp b/storage/stonedb/core/dimension_group.cpp index bc6b1bd72..bd8c402b0 100644 --- a/storage/stonedb/core/dimension_group.cpp +++ b/storage/stonedb/core/dimension_group.cpp @@ -23,7 +23,7 @@ namespace core { DimensionGroupFilter::DimensionGroupFilter(int dim, int64_t size, uint32_t power) { base_dim = dim; f = new Filter(size, power, true); // all ones - dim_group_type = DG_FILTER; + dim_group_type = DGType::DG_FILTER; no_obj = size; } @@ -37,7 +37,7 @@ DimensionGroupFilter::DimensionGroupFilter(int dim, Filter *f_source, int copy_m f = Filter::ShallowCopy(*f_source); else if (copy_mode == 2) f = f_source; - dim_group_type = DG_FILTER; + dim_group_type = DGType::DG_FILTER; no_obj = f->NoOnes(); } @@ -76,7 +76,7 @@ DimensionGroup::Iterator *DimensionGroupFilter::CopyIterator(DimensionGroup::Ite } DimensionGroupMaterialized::DimensionGroupMaterialized(DimensionVector &dims) { - dim_group_type = DG_INDEX_TABLE; + dim_group_type = DGType::DG_INDEX_TABLE; dims_used = dims; no_dims = dims.Size(); no_obj = 0; diff --git a/storage/stonedb/core/dimension_group.h b/storage/stonedb/core/dimension_group.h index 844e268ff..118a5426a 100644 --- a/storage/stonedb/core/dimension_group.h +++ b/storage/stonedb/core/dimension_group.h @@ -29,9 +29,9 @@ class PackOrderer; class DimensionGroup { public: - enum DGType { DG_FILTER, DG_INDEX_TABLE, DG_VIRTUAL, DG_NOT_KNOWN } dim_group_type; + enum class DGType { DG_FILTER, DG_INDEX_TABLE, DG_VIRTUAL, DG_NOT_KNOWN } dim_group_type; - DimensionGroup() : dim_group_type(DG_NOT_KNOWN), no_obj(0), locks(0) {} + DimensionGroup() : dim_group_type(DGType::DG_NOT_KNOWN), no_obj(0), locks(0) {} virtual DimensionGroup *Clone(bool shallow) = 0; // create a new group with the same (copied) contents virtual ~DimensionGroup() {} int64_t NoTuples() { return no_obj; } diff --git a/storage/stonedb/core/dimension_group_multiple.cpp b/storage/stonedb/core/dimension_group_multiple.cpp index c23190e0c..55b978d73 100644 --- a/storage/stonedb/core/dimension_group_multiple.cpp +++ b/storage/stonedb/core/dimension_group_multiple.cpp @@ -183,7 +183,7 @@ int MultiIndexTable::NoLocks() { // uninvolved scenes. DimensionGroupMultiMaterialized::DimensionGroupMultiMaterialized(int64_t obj, DimensionVector &dims, uint32_t power) : power_(power), dims_used_(dims) { - dim_group_type = DG_INDEX_TABLE; + dim_group_type = DGType::DG_INDEX_TABLE; no_obj = obj; dims_count_ = dims_used_.Size(); dim_tables_.resize(dims_count_); diff --git a/storage/stonedb/core/dimension_group_virtual.cpp b/storage/stonedb/core/dimension_group_virtual.cpp index 717831c0c..10c715a77 100644 --- a/storage/stonedb/core/dimension_group_virtual.cpp +++ b/storage/stonedb/core/dimension_group_virtual.cpp @@ -34,7 +34,7 @@ DimensionGroupVirtual::DimensionGroupVirtual(DimensionVector &dims, int bdim, Fi f = Filter::ShallowCopy(*f_source); else if (copy_mode == 2) f = f_source; - dim_group_type = DG_VIRTUAL; + dim_group_type = DGType::DG_VIRTUAL; no_obj = f->NoOnes(); pack_pos = NULL; // created if needed t = new IndexTable *[no_dims]; diff --git a/storage/stonedb/core/engine.cpp b/storage/stonedb/core/engine.cpp index d779a127c..9a14ee0b4 100644 --- a/storage/stonedb/core/engine.cpp +++ b/storage/stonedb/core/engine.cpp @@ -68,7 +68,7 @@ static int setup_sig_handler() { sigemptyset(&sa.sa_mask); if (sigaction(SIGRTMIN, &sa, NULL) == -1) { - STONEDB_LOG(INFO, "Failed to set up signal handler. error =%d[%s]", errno, std::strerror(errno)); + STONEDB_LOG(LogCtl_Level::INFO, "Failed to set up signal handler. error =%d[%s]", errno, std::strerror(errno)); return 1; } return 0; @@ -99,14 +99,14 @@ fs::path Engine::GetNextDataDir() { auto si = fs::space(s); auto usage = 100 - ((si.available * 100) / si.capacity); if (usage > static_cast(stonedb_sysvar_disk_usage_threshold)) { - STONEDB_LOG(WARN, "disk %s usage %d%%", s.native().c_str(), usage); + STONEDB_LOG(LogCtl_Level::WARN, "disk %s usage %d%%", s.native().c_str(), usage); return true; } return false; }), v.end()); if (v.size() == 0) { - STONEDB_LOG(ERROR, "all data directories usage exceed %d%%", stonedb_sysvar_disk_usage_threshold); + STONEDB_LOG(LogCtl_Level::ERROR, "all data directories usage exceed %d%%", stonedb_sysvar_disk_usage_threshold); throw common::Exception("Disk usage exceeds defined threshold"); } return v[std::rand() % v.size()]; @@ -228,21 +228,23 @@ int Engine::Init(uint engine_slot) { #ifdef FUNCTIONS_EXECUTION_TIMES fet = new FunctionsExecutionTimes(); #endif - STONEDB_LOG(INFO, "StoneDB engine started. "); - STONEDB_LOG(INFO, "StoneDB data directories:"); - STONEDB_LOG(INFO, " {"); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB engine started. "); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB data directories:"); + STONEDB_LOG(LogCtl_Level::INFO, " {"); if (stonedb_data_dirs.empty()) - STONEDB_LOG(INFO, " default"); + STONEDB_LOG(LogCtl_Level::INFO, " default"); else for (auto &dir : stonedb_data_dirs) { auto si = fs::space(dir); - STONEDB_LOG(INFO, " %s capacity/available: %ld/%ld", dir.native().c_str(), si.capacity, si.available); + STONEDB_LOG(LogCtl_Level::INFO, " %s capacity/available: %ld/%ld", dir.native().c_str(), si.capacity, + si.available); } - STONEDB_LOG(INFO, " }"); + STONEDB_LOG(LogCtl_Level::INFO, " }"); - STONEDB_LOG(INFO, "StoneDB thread pool for background load, size = %ld", delay_insert_thread_pool.size()); - STONEDB_LOG(INFO, "StoneDB thread pool for load, size = %ld", load_thread_pool.size()); - STONEDB_LOG(INFO, "StoneDB thread pool for query, size = %ld", query_thread_pool.size()); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB thread pool for background load, size = %ld", + delay_insert_thread_pool.size()); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB thread pool for load, size = %ld", load_thread_pool.size()); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB thread pool for query, size = %ld", query_thread_pool.size()); m_monitor_thread = std::thread([this] { struct job { @@ -253,7 +255,7 @@ int Engine::Init(uint engine_slot) { {60 * 5, []() { STONEDB_LOG( - INFO, + LogCtl_Level::INFO, "Memory: release [%llu %llu %llu %llu] %llu, total " "%llu. (un)freeable %lu/%lu, total alloc/free " "%lu/%lu", @@ -278,7 +280,7 @@ int Engine::Init(uint engine_slot) { } } } - STONEDB_LOG(INFO, "StoneDB monitor thread exiting..."); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB monitor thread exiting..."); }); m_load_thread = std::thread([this] { ProcessDelayedInsert(); }); @@ -290,7 +292,7 @@ int Engine::Init(uint engine_slot) { std::unique_lock lk(cv_mtx); if (cv.wait_for(lk, std::chrono::seconds(3)) == std::cv_status::timeout) HandleDeferredJobs(); } while (!exiting); - STONEDB_LOG(INFO, "StoneDB file purge thread exiting..."); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB file purge thread exiting..."); }); if (setup_sig_handler()) { @@ -313,7 +315,7 @@ void Engine::HandleDeferredJobs() { fs::remove(t.file, ec); // Ignore ENOENT since files might be deleted by 'drop table'. if (ec && ec != std::errc::no_such_file_or_directory) { - STONEDB_LOG(ERROR, "Failed to remove file %s Error:%s", t.file.string().c_str(), ec.message()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to remove file %s Error:%s", t.file.string().c_str(), ec.message()); } } else { gc_tasks.emplace_back(t); @@ -332,7 +334,7 @@ Engine::~Engine() { std::scoped_lock lk(cv_mtx); std::scoped_lock lk_merge(cv_merge_mtx); exiting = true; - STONEDB_LOG(INFO, "StoneDB engine shutting down."); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB engine shutting down."); } cv.notify_all(); cv_merge.notify_all(); @@ -351,16 +353,16 @@ Engine::~Engine() { try { mm::MemoryManagerInitializer::EnsureNoLeakedTraceableObject(); } catch (common::AssertException &e) { - STONEDB_LOG(ERROR, "Memory leak! %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Memory leak! %s", e.what()); } catch (...) { - STONEDB_LOG(ERROR, "Unkown exception caught"); + STONEDB_LOG(LogCtl_Level::ERROR, "Unkown exception caught"); } if (rccontrol.isOn()) mm::MemoryManagerInitializer::deinit(true); else mm::MemoryManagerInitializer::deinit(false); - STONEDB_LOG(INFO, "StoneDB engine destroyed."); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB engine destroyed."); } void Engine::EncodeRecord(const std::string &table_path, int tid, Field **field, size_t col, size_t blobs, @@ -554,7 +556,7 @@ uint32_t Engine::GetNextTableId() { std::scoped_lock lk(seq_mtx); fs::path p = stonedb_data_dir / "stonedb.tid"; if (!fs::exists(p)) { - STONEDB_LOG(INFO, "Creating table id file"); + STONEDB_LOG(LogCtl_Level::INFO, "Creating table id file"); std::ofstream seq_file(p.string()); if (seq_file) seq_file << 0; if (!seq_file) { @@ -583,7 +585,7 @@ std::shared_ptr Engine::GetTableOption(const std::string &table, TA int power = has_pack(form->s->comment); if (power < 5 || power > 16) { - STONEDB_LOG(ERROR, "create table comment: pack size shift(%d) should be >=5 and <= 16"); + STONEDB_LOG(LogCtl_Level::ERROR, "create table comment: pack size shift(%d) should be >=5 and <= 16"); throw common::SyntaxException("Unexpected data pack size."); } @@ -665,7 +667,8 @@ AttributeTypeInfo Engine::GetAttrTypeInfo(const Field &field) { if (const Field_str *fstr = dynamic_cast(&field)) { DTCollation coll(fstr->charset(), fstr->derivation()); if (fmt == common::PackFmt::TRIE && types::IsCaseInsensitive(coll)) { - STONEDB_LOG(ERROR, "TRIE can not work with case-insensitive collation: %s!", coll.collation->name); + STONEDB_LOG(LogCtl_Level::ERROR, "TRIE can not work with case-insensitive collation: %s!", + coll.collation->name); throw common::UnsupportedDataTypeException(); } if (fstr->charset() != &my_charset_bin) @@ -733,7 +736,7 @@ void Engine::CommitTx(THD *thd, bool all) { void Engine::Rollback(THD *thd, bool all, bool force_error_message) { force_error_message = force_error_message || (!all && thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)); - STONEDB_LOG(ERROR, "Roll back query '%s'", thd_query_string(thd)->str); + STONEDB_LOG(LogCtl_Level::ERROR, "Roll back query '%s'", thd_query_string(thd)->str); if (current_tx) { GetTx(thd)->Rollback(thd, force_error_message); ClearTx(thd); @@ -766,7 +769,7 @@ void Engine::DeleteTable(const char *table, [[maybe_unused]] THD *thd) { gc_tasks.remove_if([id](const purge_task &t) -> bool { return static_cast(t.cookie) == id; }); } system::DeleteDirectory(p); - STONEDB_LOG(INFO, "Drop table %s, ID = %u", table, id); + STONEDB_LOG(LogCtl_Level::INFO, "Drop table %s, ID = %u", table, id); } void Engine::TruncateTable(const std::string &table_path, [[maybe_unused]] THD *thd) { @@ -779,7 +782,7 @@ void Engine::TruncateTable(const std::string &table_path, [[maybe_unused]] THD * auto id = tab->GetID(); cache.ReleaseTable(id); filter_cache.RemoveIf([id](const FilterCoordinate &c) { return c[0] == int(id); }); - STONEDB_LOG(INFO, "Truncated table %s, ID = %u", table_path.c_str(), id); + STONEDB_LOG(LogCtl_Level::INFO, "Truncated table %s, ID = %u", table_path.c_str(), id); } void Engine::GetTableIterator(const std::string &table_path, RCTable::Iterator &iter_begin, RCTable::Iterator &iter_end, @@ -918,27 +921,27 @@ void Engine::ClearTx(THD *thd) { int Engine::SetUpCacheFolder(const std::string &cachefolder_path) { if (!fs::exists(cachefolder_path)) { - STONEDB_LOG(INFO, "Cachefolder %s does not exist. Trying to create it.", cachefolder_path.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "Cachefolder %s does not exist. Trying to create it.", cachefolder_path.c_str()); std::error_code ec; fs::create_directories(cachefolder_path, ec); if (ec) { sql_print_error("StoneDB: Can not create folder %s.", cachefolder_path.c_str()); - STONEDB_LOG(ERROR, "DatabaseException: %s", ec.message().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "DatabaseException: %s", ec.message().c_str()); return 1; } } if (!system::IsReadWriteAllowed(cachefolder_path)) { sql_print_error("StoneDB: Can not access cache folder %s.", cachefolder_path.c_str()); - STONEDB_LOG(ERROR, "Can not access cache folder %s", cachefolder_path.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "Can not access cache folder %s", cachefolder_path.c_str()); return 1; } return 0; } std::string get_parameter_name(enum sdb_var_name vn) { - DEBUG_ASSERT(vn >= 0 && vn <= SDB_VAR_LIMIT); - return sdb_var_name_strings[vn]; + DEBUG_ASSERT(static_cast(vn) >= 0 && static_cast(vn) <= static_cast(sdb_var_name::SDB_VAR_LIMIT)); + return sdb_var_name_strings[static_cast(vn)]; } int get_parameter(THD *thd, enum sdb_var_name vn, double &value) { @@ -992,7 +995,7 @@ int get_parameter(THD *thd, enum sdb_var_name vn, longlong &result, std::string if (m_entry->type() == DECIMAL_RESULT) { switch (vn) { - case SDB_ABORT_ON_THRESHOLD: { + case sdb_var_name::SDB_ABORT_ON_THRESHOLD: { double dv; my_bool null_value; my_decimal v; @@ -1009,10 +1012,10 @@ int get_parameter(THD *thd, enum sdb_var_name vn, longlong &result, std::string return 0; } else if (m_entry->type() == INT_RESULT) { switch (vn) { - case SDB_THROTTLE: - case SDB_STONEDBEXPRESSIONS: - case SDB_PARALLEL_AGGR: - case SDB_ABORT_ON_COUNT: + case sdb_var_name::SDB_THROTTLE: + case sdb_var_name::SDB_STONEDBEXPRESSIONS: + case sdb_var_name::SDB_PARALLEL_AGGR: + case sdb_var_name::SDB_ABORT_ON_COUNT: my_bool null_value; result = m_entry->val_int(&null_value); break; @@ -1029,13 +1032,13 @@ int get_parameter(THD *thd, enum sdb_var_name vn, longlong &result, std::string m_entry->val_str(&null_value, &str, NOT_FIXED_DEC); var_data = std::string(str.ptr()); - if (vn == SDB_DATAFORMAT || vn == SDB_REJECT_FILE_PATH) { + if (vn == sdb_var_name::SDB_DATAFORMAT || vn == sdb_var_name::SDB_REJECT_FILE_PATH) { s_result = var_data; - } else if (vn == SDB_PIPEMODE) { + } else if (vn == sdb_var_name::SDB_PIPEMODE) { boost::to_upper(var_data); if (var_data == "SERVER") result = 1; if (var_data == "CLIENT") result = 0; - } else if (vn == SDB_NULL) { + } else if (vn == sdb_var_name::SDB_NULL) { s_result = var_data; } return 0; @@ -1054,7 +1057,7 @@ void Engine::RenameTable([[maybe_unused]] Transaction *trans, const std::string system::RenameFile(stonedb_data_dir / (from + common::STONEDB_EXT), stonedb_data_dir / (to + common::STONEDB_EXT)); RenameRdbTable(from, to); UnregisterMemTable(from, to); - STONEDB_LOG(INFO, "Rename table %s to %s", from.c_str(), to.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "Rename table %s to %s", from.c_str(), to.c_str()); } void Engine::PrepareAlterTable(const std::string &table_path, std::vector &new_cols, @@ -1139,7 +1142,7 @@ static void HandleDelayedLoad(int tid, std::vector> &vec free_root(thd->mem_root, MYF(MY_KEEP_PREALLOC)); if (thd->is_fatal_error) { - STONEDB_LOG(ERROR, "LOAD DATA failed on table '%s'", tab_name.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "LOAD DATA failed on table '%s'", tab_name.c_str()); } thd->release_resources(); remove_global_thread(thd); @@ -1207,7 +1210,7 @@ void Engine::ProcessDelayedInsert() { buffer_recordnum = 0; } } - STONEDB_LOG(INFO, "StoneDB load thread exiting..."); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB load thread exiting..."); } void Engine::ProcessDelayedMerge() { @@ -1260,12 +1263,12 @@ void Engine::ProcessDelayedMerge() { } } } catch (common::Exception &e) { - STONEDB_LOG(ERROR, "delayed merge failed. %s %s", e.what(), e.trace().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "delayed merge failed. %s %s", e.what(), e.trace().c_str()); std::unique_lock lk(cv_merge_mtx); cv_merge.wait_for(lk, std::chrono::milliseconds(stonedb_sysvar_insert_wait_ms)); continue; } catch (...) { - STONEDB_LOG(ERROR, "delayed merge failed."); + STONEDB_LOG(LogCtl_Level::ERROR, "delayed merge failed."); std::unique_lock lk(cv_merge_mtx); cv_merge.wait_for(lk, std::chrono::milliseconds(stonedb_sysvar_insert_wait_ms)); continue; @@ -1278,7 +1281,7 @@ void Engine::ProcessDelayedMerge() { cv_merge.wait_for(lk, std::chrono::milliseconds(stonedb_sysvar_insert_wait_ms)); } } - STONEDB_LOG(INFO, "StoneDB merge thread exiting..."); + STONEDB_LOG(LogCtl_Level::INFO, "StoneDB merge thread exiting..."); } void Engine::LogStat() { @@ -1300,7 +1303,7 @@ void Engine::LogStat() { long sample_time = t.tv_sec; long diff = sample_time - last_sample_time; if (diff == 0) { - STONEDB_LOG(ERROR, "LogStat() called too frequently. last sample time %ld ", last_sample_time); + STONEDB_LOG(LogCtl_Level::ERROR, "LogStat() called too frequently. last sample time %ld ", last_sample_time); return; } query_id_t query_id = global_query_id; @@ -1334,10 +1337,10 @@ void Engine::LogStat() { msg + sql_statement_names[c].str + " " + std::to_string(delta) + "/" + std::to_string(sv.com_stat[c]) + ", "; } msg = msg + "queries " + std::to_string(queries) + "/" + std::to_string(global_query_id); - STONEDB_LOG(INFO, msg.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, msg.c_str()); } - STONEDB_LOG(INFO, + STONEDB_LOG(LogCtl_Level::INFO, "Select: %lu/%lu, Loaded: %lu/%lu(%lu/%lu), dup: %lu/%lu, insert: " "%lu/%lu, failed insert: %lu/%lu, update: " "%lu/%lu", @@ -1349,7 +1352,7 @@ void Engine::LogStat() { stonedb_stat.update - saved.update, stonedb_stat.update); if (stonedb_stat.loaded == saved.loaded && stonedb_stat.delayinsert > saved.delayinsert) { - STONEDB_LOG(ERROR, "No data loaded from insert buffer"); + STONEDB_LOG(LogCtl_Level::ERROR, "No data loaded from insert buffer"); } // update with last minute statistics @@ -1384,7 +1387,7 @@ void Engine::InsertDelayed(const std::string &table_path, int tid, TABLE *table) insert_buffer.Write(utils::MappedCircularBuffer::TAG::INSERT_RECORD, buf.get(), buf_sz); } catch (std::length_error &e) { if (failed++ >= stonedb_sysvar_insert_wait_time / 50) { - STONEDB_LOG(ERROR, "insert buffer is out of space"); + STONEDB_LOG(LogCtl_Level::ERROR, "insert buffer is out of space"); throw e; } std::this_thread::sleep_for(std::chrono::milliseconds(50)); @@ -1425,11 +1428,11 @@ int Engine::InsertRow(const std::string &table_path, [[maybe_unused]] Transactio } return ret; } catch (common::Exception &e) { - STONEDB_LOG(ERROR, "delayed inserting failed. %s %s", e.what(), e.trace().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "delayed inserting failed. %s %s", e.what(), e.trace().c_str()); } catch (std::exception &e) { - STONEDB_LOG(ERROR, "delayed inserting failed. %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "delayed inserting failed. %s", e.what()); } catch (...) { - STONEDB_LOG(ERROR, "delayed inserting failed."); + STONEDB_LOG(LogCtl_Level::ERROR, "delayed inserting failed."); } if (stonedb_sysvar_insert_delayed) { @@ -1511,7 +1514,7 @@ common::SDBError Engine::RunLoader(THD *thd, sql_exchange *ex, TABLE_LIST *table } bool Engine::IsSDBRoute(THD *thd, TABLE_LIST *table_list, SELECT_LEX *selects_list, - int &in_case_of_failure_can_go_to_mysql, int with_insert) { + int &in_case_of_failure_can_go_to_mysql, int with_insert) { in_case_of_failure_can_go_to_mysql = true; if (!table_list) return false; @@ -1542,7 +1545,7 @@ bool Engine::IsSDBRoute(THD *thd, TABLE_LIST *table_list, SELECT_LEX *selects_li if (file) { // it writes to a file longlong param = 0; std::string s_res; - if (!get_parameter(thd, SDB_DATAFORMAT, param, s_res)) { + if (!get_parameter(thd, sdb_var_name::SDB_DATAFORMAT, param, s_res)) { if (boost::iequals(boost::trim_copy(s_res), "MYSQL")) return false; common::DataFormatPtr df = common::DataFormat::GetDataFormat(s_res); @@ -1560,7 +1563,7 @@ bool Engine::IsSDBRoute(THD *thd, TABLE_LIST *table_list, SELECT_LEX *selects_li // it cannot go to MYSQL - it writes to a file, // but the file format is not MYSQL } else // param not set - we assume it is (deprecated: MYSQL) - // common::TXT_VARIABLE + // common::EDF::TRI_UNKNOWN return true; } @@ -1651,40 +1654,40 @@ common::SDBError Engine::GetRejectFileIOParameters(THD &thd, std::unique_ptr= 0.0 && abort_on_threshold < 1.0)) return common::SDBError(common::ErrorCode::WRONG_PARAMETER, - "SDB_ABORT_ON_THRESHOLD parameter value must be in range (0,1)."); + "SDB_ABORT_ON_THRESHOLD parameter value must be in range (0,1)."); if ((abort_on_count != 0 || abort_on_threshold != 0) && reject_file.empty()) return common::SDBError(common::ErrorCode::WRONG_PARAMETER, - "SDB_ABORT_ON_COUNT or SDB_ABORT_ON_THRESHOLD can by only specified with " - "SDB_REJECT_FILE_PATH parameter."); + "SDB_ABORT_ON_COUNT or SDB_ABORT_ON_THRESHOLD can by only specified with " + "SDB_REJECT_FILE_PATH parameter."); if (!reject_file.empty() && fs::exists(reject_file)) return common::SDBError(common::ErrorCode::WRONG_PARAMETER, - "Can not create the reject file, the file already exists."); + "Can not create the reject file, the file already exists."); io_params->SetRejectFile(reject_file, abort_on_count, abort_on_threshold); return common::ErrorCode::SUCCESS; } common::SDBError Engine::GetIOP(std::unique_ptr &io_params, THD &thd, sql_exchange &ex, - TABLE *table, void *arg, bool for_exporter) { + TABLE *table, void *arg, bool for_exporter) { const CHARSET_INFO *cs = ex.cs; bool local_load = for_exporter ? false : (bool)(thd.lex)->local_file; uint value_list_elements = (thd.lex)->value_list.elements; @@ -1713,7 +1716,7 @@ common::SDBError Engine::GetIOP(std::unique_ptr &io_params longlong param = 0; std::string s_res; if (common::DataFormat::GetNoFormats() > 1) { - if (!get_parameter(&thd, SDB_DATAFORMAT, param, s_res)) { + if (!get_parameter(&thd, sdb_var_name::SDB_DATAFORMAT, param, s_res)) { common::DataFormatPtr df = common::DataFormat::GetDataFormat(s_res); if (!df) return common::SDBError(common::ErrorCode::WRONG_PARAMETER, "Unknown value of SDB_DATAFORMAT parameter."); @@ -1724,7 +1727,7 @@ common::SDBError Engine::GetIOP(std::unique_ptr &io_params } else io_mode = common::DataFormat::GetDataFormat(0)->GetId(); - if (!get_parameter(&thd, SDB_NULL, param, s_res)) io_params->SetNullsStr(s_res); + if (!get_parameter(&thd, sdb_var_name::SDB_NULL, param, s_res)) io_params->SetNullsStr(s_res); if (io_params->LoadDelayed()) { std::strcpy(name, ex.file_name); @@ -1757,9 +1760,9 @@ common::SDBError Engine::GetIOP(std::unique_ptr &io_params io_params->SetDelimiter(ex.field_term->ptr()); io_params->SetLineTerminator(ex.line_term->ptr()); if (ex.enclosed->length() == 4 && strcasecmp(ex.enclosed->ptr(), "NULL") == 0) - io_params->SetParameter(system::STRING_QUALIFIER, '\0'); + io_params->SetParameter(system::Parameter::STRING_QUALIFIER, '\0'); else - io_params->SetParameter(system::STRING_QUALIFIER, *ex.enclosed->ptr()); + io_params->SetParameter(system::Parameter::STRING_QUALIFIER, *ex.enclosed->ptr()); } else { if (ex.escaped->alloced_length() != 0) io_params->SetEscapeCharacter(*ex.escaped->ptr()); @@ -1770,50 +1773,51 @@ common::SDBError Engine::GetIOP(std::unique_ptr &io_params if (ex.enclosed->length()) { if (ex.enclosed->length() == 4 && strcasecmp(ex.enclosed->ptr(), "NULL") == 0) - io_params->SetParameter(system::STRING_QUALIFIER, '\0'); + io_params->SetParameter(system::Parameter::STRING_QUALIFIER, '\0'); else - io_params->SetParameter(system::STRING_QUALIFIER, *ex.enclosed->ptr()); + io_params->SetParameter(system::Parameter::STRING_QUALIFIER, *ex.enclosed->ptr()); } } if (io_params->EscapeCharacter() != 0 && io_params->Delimiter().find(io_params->EscapeCharacter()) != std::string::npos) return common::SDBError(common::ErrorCode::WRONG_PARAMETER, - "Field terminator containing the escape character not supported."); + "Field terminator containing the escape character not supported."); if (io_params->EscapeCharacter() != 0 && io_params->StringQualifier() != 0 && io_params->EscapeCharacter() == io_params->StringQualifier()) - return common::SDBError(common::ErrorCode::WRONG_PARAMETER, "The same enclose and escape characters not supported."); + return common::SDBError(common::ErrorCode::WRONG_PARAMETER, + "The same enclose and escape characters not supported."); bool unsupported_syntax = false; if (cs != 0) - io_params->SetParameter(system::CHARSET_INFO_NUMBER, (int)(cs->number)); + io_params->SetParameter(system::Parameter::CHARSET_INFO_NUMBER, (int)(cs->number)); else if (!for_exporter) - io_params->SetParameter(system::CHARSET_INFO_NUMBER, + io_params->SetParameter(system::Parameter::CHARSET_INFO_NUMBER, (int)(thd.variables.collation_database->number)); // default charset if (ex.skip_lines != 0) { unsupported_syntax = true; - io_params->SetParameter(system::SKIP_LINES, (int64_t)ex.skip_lines); + io_params->SetParameter(system::Parameter::SKIP_LINES, (int64_t)ex.skip_lines); } if (ex.line_start != 0 && ex.line_start->length() != 0) { unsupported_syntax = true; - io_params->SetParameter(system::LINE_STARTER, std::string(ex.line_start->ptr())); + io_params->SetParameter(system::Parameter::LINE_STARTER, std::string(ex.line_start->ptr())); } if (local_load && ((thd.lex)->sql_command == SQLCOM_LOAD)) { - io_params->SetParameter(system::LOCAL_LOAD, (int)local_load); + io_params->SetParameter(system::Parameter::LOCAL_LOAD, (int)local_load); } if (value_list_elements != 0) { unsupported_syntax = true; - io_params->SetParameter(system::VALUE_LIST_ELEMENTS, (int64_t)value_list_elements); + io_params->SetParameter(system::Parameter::VALUE_LIST_ELEMENTS, (int64_t)value_list_elements); } if (ex.opt_enclosed) { // unsupported_syntax = true; - io_params->SetParameter(system::OPTIONALLY_ENCLOSED, 1); + io_params->SetParameter(system::Parameter::OPTIONALLY_ENCLOSED, 1); } if (unsupported_syntax) @@ -1849,11 +1853,11 @@ std::shared_ptr Engine::GetTableShare(const TABLE_SHARE *table_share } return it->second; } catch (common::Exception &e) { - STONEDB_LOG(ERROR, "Failed to create table share: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to create table share: %s", e.what()); } catch (std::exception &e) { - STONEDB_LOG(ERROR, "Failed to create table share: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to create table share: %s", e.what()); } catch (...) { - STONEDB_LOG(ERROR, "Failed to create table share"); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to create table share"); } return nullptr; } @@ -1903,11 +1907,11 @@ void Engine::AddMemTable(TABLE *form, std::shared_ptr share) { } return; } catch (common::Exception &e) { - STONEDB_LOG(ERROR, "Failed to create memory table: %s / %s", e.what(), e.trace().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to create memory table: %s / %s", e.what(), e.trace().c_str()); } catch (std::exception &e) { - STONEDB_LOG(ERROR, "Failed to create memory table: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to create memory table: %s", e.what()); } catch (...) { - STONEDB_LOG(ERROR, "Failed to create memory table"); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to create memory table"); } return; } @@ -1977,24 +1981,24 @@ int stonedb_push_data_dir(const char *dir) { try { auto p = fs::path(dir); if (!fs::is_directory(p)) { - STONEDB_LOG(ERROR, "Path %s is not a directory or cannot be accessed.", dir); + STONEDB_LOG(LogCtl_Level::ERROR, "Path %s is not a directory or cannot be accessed.", dir); return 1; } if (fs::space(p).available < 1_GB) { - STONEDB_LOG(ERROR, "StoneDB requires data directory has at least 1G available space!"); + STONEDB_LOG(LogCtl_Level::ERROR, "StoneDB requires data directory has at least 1G available space!"); return 1; } p /= fs::path(STONEDB_DATA_DIR); auto result = std::find(std::begin(stonedb_data_dirs), std::end(stonedb_data_dirs), p); if (result != std::end(stonedb_data_dirs)) { - STONEDB_LOG(WARN, "Path %s specified multiple times as data directory.", dir); + STONEDB_LOG(LogCtl_Level::WARN, "Path %s specified multiple times as data directory.", dir); } else { fs::create_directory(p); stonedb_data_dirs.emplace_back(p); } } catch (fs::filesystem_error &err) { - STONEDB_LOG(ERROR, "Filesystem error %s", err.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Filesystem error %s", err.what()); return 1; } diff --git a/storage/stonedb/core/engine.h b/storage/stonedb/core/engine.h index b52a71d68..dff067314 100644 --- a/storage/stonedb/core/engine.h +++ b/storage/stonedb/core/engine.h @@ -153,7 +153,7 @@ class Engine final { static void ComputeTimeZoneDiffInMinutes(THD *thd, short &sign, short &minutes); static std::string GetTablePath(TABLE *table); static common::SDBError GetIOP(std::unique_ptr &io_params, THD &thd, sql_exchange &ex, - TABLE *table = 0, void *arg = NULL, bool for_exporter = false); + TABLE *table = 0, void *arg = NULL, bool for_exporter = false); static common::SDBError GetRejectFileIOParameters(THD &thd, std::unique_ptr &io_params); static fs::path GetNextDataDir(); @@ -165,7 +165,7 @@ class Engine final { static bool AreConvertible(types::RCDataType &rcitem, enum_field_types my_type, uint length = 0); static bool IsSDBRoute(THD *thd, TABLE_LIST *table_list, SELECT_LEX *selects_list, - int &in_case_of_failure_can_go_to_mysql, int with_insert); + int &in_case_of_failure_can_go_to_mysql, int with_insert); static const char *GetFilename(SELECT_LEX *selects_list, int &is_dumpfile); static std::unique_ptr CreateIOParameters(const std::string &path, void *arg); static std::unique_ptr CreateIOParameters(THD *thd, TABLE *table, void *arg); @@ -306,7 +306,7 @@ class ResultExportSender final : public ResultSender { std::shared_ptr rcbuffer; }; -enum sdb_var_name { +enum class sdb_var_name { SDB_DATAFORMAT, SDB_PIPEMODE, SDB_NULL, @@ -320,10 +320,10 @@ enum sdb_var_name { }; static std::string sdb_var_name_strings[] = {"STONEDB_LOAD_TIMEOUT", "STONEDB_LOAD_DATAFORMAT", - "STONEDB_LOAD_PIPEMODE", "STONEDB_LOAD_NULL", - "STONEDB_LOAD_THROTTLE", "STONEDB_LOAD_STONEDBEXPRESSIONS", - "STONEDB_LOAD_PARALLEL_AGGR", "STONEDB_LOAD_REJECT_FILE", - "STONEDB_LOAD_ABORT_ON_COUNT", "STONEDB_LOAD_ABORT_ON_THRESHOLD"}; + "STONEDB_LOAD_PIPEMODE", "STONEDB_LOAD_NULL", + "STONEDB_LOAD_THROTTLE", "STONEDB_LOAD_STONEDBEXPRESSIONS", + "STONEDB_LOAD_PARALLEL_AGGR", "STONEDB_LOAD_REJECT_FILE", + "STONEDB_LOAD_ABORT_ON_COUNT", "STONEDB_LOAD_ABORT_ON_THRESHOLD"}; std::string get_parameter_name(enum sdb_var_name vn); diff --git a/storage/stonedb/core/engine_execute.cpp b/storage/stonedb/core/engine_execute.cpp index 7315e22dc..d7f7ce7ef 100644 --- a/storage/stonedb/core/engine_execute.cpp +++ b/storage/stonedb/core/engine_execute.cpp @@ -44,7 +44,7 @@ class KillTimer { sev._sigev_un._tid = syscall(SYS_gettid); sev.sigev_value.sival_ptr = thd; if (timer_create(CLOCK_MONOTONIC, &sev, &id)) { - STONEDB_LOG(INFO, "Failed to create timer. error =%d[%s]", errno, std::strerror(errno)); + STONEDB_LOG(LogCtl_Level::INFO, "Failed to create timer. error =%d[%s]", errno, std::strerror(errno)); return; } @@ -52,7 +52,7 @@ class KillTimer { std::memset(&interval, 0, sizeof(interval)); interval.it_value.tv_sec = secs; if (timer_settime(id, 0, &interval, NULL)) { - STONEDB_LOG(INFO, "Failed to set up timer. error =%d[%s]", errno, std::strerror(errno)); + STONEDB_LOG(LogCtl_Level::INFO, "Failed to set up timer. error =%d[%s]", errno, std::strerror(errno)); return; } armed = true; @@ -94,7 +94,7 @@ int Engine::HandleSelect(THD *thd, LEX *lex, select_result *&result, ulong setup } if (lock_tables(thd, thd->lex->query_tables, thd->lex->table_count, 0)) { - STONEDB_LOG(ERROR, "Failed to lock tables for query '%s'", thd_query_string(thd)->str); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to lock tables for query '%s'", thd_query_string(thd)->str); return RCBASE_QUERY_ROUTE; } /* @@ -192,7 +192,7 @@ int Engine::HandleSelect(THD *thd, LEX *lex, select_result *&result, ulong setup "Error: Query syntax not implemented in StoneDB, can " "export " "only to MySQL format (set SDB_DATAFORMAT to 'MYSQL')."; - STONEDB_LOG(ERROR, err_msg); + STONEDB_LOG(LogCtl_Level::ERROR, err_msg); my_message(ER_SYNTAX_ERROR, err_msg, MYF(0)); throw ReturnMeToMySQLWithError(); } @@ -230,7 +230,7 @@ int Engine::HandleSelect(THD *thd, LEX *lex, select_result *&result, ulong setup try { route = Execute(thd, lex, result); if (route == RETURN_QUERY_TO_MYSQL_ROUTE && !in_case_of_failure_can_go_to_mysql) { - STONEDB_LOG(ERROR, + STONEDB_LOG(LogCtl_Level::ERROR, "Error: Query syntax not implemented in StoneDB, can export " "only to MySQL format (set SDB_DATAFORMAT to 'MYSQL')."); my_message(ER_SYNTAX_ERROR, @@ -258,7 +258,7 @@ int Engine::HandleSelect(THD *thd, LEX *lex, select_result *&result, ulong setup res = select_lex->join->error; } if (select_lex->join && Query::IsLOJ(select_lex->join->join_list)) - optimize_after_sdb = 2; // optimize partially (part=4), since part of LOJ + optimize_after_sdb = 2; // optimize partially (part=4), since part of LOJ // optimization was already done res |= (int)thd->is_error(); // the ending of original handle_select(...) */ if (unlikely(res)) { @@ -369,7 +369,7 @@ int Engine::Execute(THD *thd, LEX *lex, select_result *result_output, SELECT_LEX return RETURN_QUERY_TO_MYSQL_ROUTE; } } catch (common::Exception const &x) { - STONEDB_LOG(ERROR, "Query Compile Error: %s", x.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Query Compile Error: %s", x.what()); my_message(ER_UNKNOWN_ERROR, (std::string("StoneDB compile specific error: ") + x.what()).c_str(), MYF(0)); throw ReturnMeToMySQLWithError(); } @@ -389,7 +389,7 @@ int Engine::Execute(THD *thd, LEX *lex, select_result *result_output, SELECT_LEX if (unit_for_union != NULL) { int res = result_output->prepare(unit_for_union->item_list, unit_for_union); if (res) { - STONEDB_LOG(ERROR, "Error: Unsupported UNION"); + STONEDB_LOG(LogCtl_Level::ERROR, "Error: Unsupported UNION"); my_message(ER_UNKNOWN_ERROR, "StoneDB: unsupported UNION", MYF(0)); throw ReturnMeToMySQLWithError(); } @@ -441,7 +441,7 @@ int handle_exceptions(THD *thd, Transaction *cur_connection, bool with_error) { try { std::string msg = "Query terminated with exception: "; msg += thd_query_string(thd)->str; - STONEDB_LOG(INFO, msg); + STONEDB_LOG(LogCtl_Level::INFO, msg); throw; } catch (common::NotImplementedException const &x) { rccontrol.lock(cur_connection->GetThreadID()) << "Switched to MySQL: " << x.what() << system::unlock; diff --git a/storage/stonedb/core/engine_results.cpp b/storage/stonedb/core/engine_results.cpp index d5c88af76..42911dcd3 100644 --- a/storage/stonedb/core/engine_results.cpp +++ b/storage/stonedb/core/engine_results.cpp @@ -380,7 +380,7 @@ void ResultSender::Finalize(TempTable *result_table) { << "\tClientPort:" << thd->peer_port << "\tUser:" << sctx.user << glob_serverInfo << "\tAffectRows:" << affect_rows << "\tResultRows:" << rows_sent << "\tDBName:" << thd->db << "\tCosttime(ms):" << cost_time << "\tSQL:" << thd->query() << system::unlock; - STONEDB_LOG(DEBUG, "Result: %" PRId64 " Costtime(ms): %" PRId64, rows_sent, cost_time); + STONEDB_LOG(LogCtl_Level::DEBUG, "Result: %" PRId64 " Costtime(ms): %" PRId64, rows_sent, cost_time); } void ResultSender::CleanUp() { restore_fields(fields, items_backup); } @@ -472,7 +472,7 @@ void ResultExportSender::Init(TempTable *t) { TABLE_SHARE share; init_field_scan_helpers(thd, tmp_table, share); - std::vector deas = t->GetATIs(iop->GetEDF() != common::TXT_VARIABLE); + std::vector deas = t->GetATIs(iop->GetEDF() != common::EDF::TRI_UNKNOWN); int i = 0; while ((item = li++) != nullptr) { fields_t::value_type ft = guest_field_type(thd, tmp_table, item); @@ -485,7 +485,7 @@ void ResultExportSender::Init(TempTable *t) { if (!rcbuffer->BufOpen(*iop)) throw common::FileException("Unable to open file or named pipe."); rcde = common::DataFormat::GetDataFormat(iop->GetEDF())->CreateDataExporter(*iop); - rcde->Init(rcbuffer, t->GetATIs(iop->GetEDF() != common::TXT_VARIABLE), f, deas); + rcde->Init(rcbuffer, t->GetATIs(iop->GetEDF() != common::EDF::TRI_UNKNOWN), f, deas); } // send to Exporter diff --git a/storage/stonedb/core/filter.cpp b/storage/stonedb/core/filter.cpp index c017c3909..92410ecbc 100644 --- a/storage/stonedb/core/filter.cpp +++ b/storage/stonedb/core/filter.cpp @@ -825,12 +825,12 @@ void Filter::AddNewBlocks(int new_blocks, bool value, int new_no_bits_last) { char *HeapAllocator::malloc(const size_type bytes) { // std::cerr<< (bytes >> 20) << " for Filter\n"; - // return (char*) Instance()->alloc(bytes, mm::BLOCK_TEMPORARY, + // return (char*) Instance()->alloc(bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, // the_filter_block_owner); std::scoped_lock guard(HeapAllocator::mtx); void *r; try { - r = the_filter_block_owner->alloc(bytes, mm::BLOCK_TEMPORARY); + r = the_filter_block_owner->alloc(bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY); } catch (...) { return NULL; } diff --git a/storage/stonedb/core/filter.h b/storage/stonedb/core/filter.h index fc6732dc3..847f523b3 100644 --- a/storage/stonedb/core/filter.h +++ b/storage/stonedb/core/filter.h @@ -43,7 +43,7 @@ class HeapAllocator : public mm::TraceableObject { class TheFilterBlockOwner : public mm::TraceableObject { friend class HeapAllocator; - mm::TO_TYPE TraceableType() const override { return mm::TO_FILTER; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_FILTER; } }; extern TheFilterBlockOwner *the_filter_block_owner; @@ -60,7 +60,7 @@ class Filter final : public mm::TraceableObject { // original), but it ok as the copy uses pools and mutexes from the original static Filter *ShallowCopy(Filter &f); - mm::TO_TYPE TraceableType() const override { return mm::TO_FILTER; }; + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_FILTER; }; // Copying operation std::unique_ptr Clone() const; diff --git a/storage/stonedb/core/ftree.cpp b/storage/stonedb/core/ftree.cpp index 6dbbb2f4b..d6593a7dc 100644 --- a/storage/stonedb/core/ftree.cpp +++ b/storage/stonedb/core/ftree.cpp @@ -36,13 +36,13 @@ FTree::FTree(const FTree &ft) changed(ft.changed), hash_size(ft.hash_size), hdr(ft.hdr) { - mem = (char *)alloc(total_buf_size, mm::BLOCK_TEMPORARY, true); - len = (uint16_t *)alloc(total_dic_size * sizeof(uint16_t), mm::BLOCK_TEMPORARY, true); - value_offset = (uint32_t *)alloc(total_dic_size * sizeof(uint32_t), mm::BLOCK_TEMPORARY, true); + mem = (char *)alloc(total_buf_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); + len = (uint16_t *)alloc(total_dic_size * sizeof(uint16_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); + value_offset = (uint32_t *)alloc(total_dic_size * sizeof(uint32_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (total_buf_size > 0 && (!mem || !len || !value_offset)) { Destroy(); - STONEDB_LOG(ERROR, "FTree, out of memory."); + STONEDB_LOG(LogCtl_Level::ERROR, "FTree, out of memory."); throw common::OutOfMemoryException(); } @@ -50,11 +50,11 @@ FTree::FTree(const FTree &ft) std::memcpy(len, ft.len, hdr.size * sizeof(uint16_t)); std::memcpy(value_offset, ft.value_offset, hdr.size * sizeof(uint32_t)); - if (ft.hash_table) hash_table = (int *)alloc(hash_size * sizeof(int), mm::BLOCK_TEMPORARY, true); + if (ft.hash_table) hash_table = (int *)alloc(hash_size * sizeof(int), mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (ft.hash_table && !hash_table) { Destroy(); - STONEDB_LOG(ERROR, "FTree, out of memory."); + STONEDB_LOG(LogCtl_Level::ERROR, "FTree, out of memory."); throw common::OutOfMemoryException(); } @@ -121,10 +121,10 @@ void FTree::Init(int width) { total_dic_size = 10; // minimal dictionary size total_buf_size = hdr.max_len * 10 + 10; if (mem) dealloc(mem); - mem = (char *)alloc(total_buf_size, mm::BLOCK_TEMPORARY); - if (len == NULL) len = (uint16_t *)alloc(total_dic_size * sizeof(uint16_t), mm::BLOCK_TEMPORARY, true); + mem = (char *)alloc(total_buf_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); + if (len == NULL) len = (uint16_t *)alloc(total_dic_size * sizeof(uint16_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (value_offset == NULL) - value_offset = (uint32_t *)alloc(total_dic_size * sizeof(uint32_t), mm::BLOCK_TEMPORARY, true); + value_offset = (uint32_t *)alloc(total_dic_size * sizeof(uint32_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); std::memset(mem, 0, total_buf_size); last_code = -1; @@ -146,8 +146,9 @@ int FTree::Add(const char *str, size_t sz) { if (total_dic_size < size_t(hdr.size + 1)) { // Enlarge tables, if required int new_dic_size = int((total_dic_size + 10) * 1.2); if (new_dic_size > 536870910) new_dic_size = total_dic_size + 10; - len = (uint16_t *)rc_realloc(len, new_dic_size * sizeof(uint16_t), mm::BLOCK_TEMPORARY); - value_offset = (uint32_t *)rc_realloc(value_offset, new_dic_size * sizeof(uint32_t), mm::BLOCK_TEMPORARY); + len = (uint16_t *)rc_realloc(len, new_dic_size * sizeof(uint16_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY); + value_offset = + (uint32_t *)rc_realloc(value_offset, new_dic_size * sizeof(uint32_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY); if (len == NULL || value_offset == NULL) throw common::OutOfMemoryException("Too many lookup values"); for (int i = total_dic_size; i < new_dic_size; i++) { len[i] = 0; @@ -160,7 +161,7 @@ int FTree::Add(const char *str, size_t sz) { size_t new_buf_size = (total_buf_size + sz + 10) * 1.2; if (new_buf_size > BUF_SIZE_LIMIT) new_buf_size = int64_t(total_buf_size) + sz; if (new_buf_size > BUF_SIZE_LIMIT) throw common::OutOfMemoryException("Too many lookup values"); - mem = (char *)rc_realloc(mem, new_buf_size, mm::BLOCK_TEMPORARY); + mem = (char *)rc_realloc(mem, new_buf_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); std::memset(mem + total_buf_size, 0, new_buf_size - total_buf_size); total_buf_size = int(new_buf_size); } @@ -207,9 +208,9 @@ void FTree::SaveData(const fs::path &p) { } int len_sum = (hdr.size > 0 ? value_offset[hdr.size - 1] + len[hdr.size - 1] : 0); std::memcpy(buf, mem, len_sum); - if (STONEDB_LOGCHECK(DEBUG)) { + if (STONEDB_LOGCHECK(LogCtl_Level::DEBUG)) { if (CheckConsistency() != 0) { - STONEDB_LOG(DEBUG, "FTree CheckConsistency fail"); + STONEDB_LOG(LogCtl_Level::DEBUG, "FTree CheckConsistency fail"); } } } @@ -237,17 +238,17 @@ void FTree::LoadData(const fs::path &p) { buf += sizeof(HDR); if (hdr.ver != DICT_FILE_VERSION) { - STONEDB_LOG(ERROR, "bad dictionary version %d", hdr.ver); + STONEDB_LOG(LogCtl_Level::ERROR, "bad dictionary version %d", hdr.ver); return; } total_dic_size = hdr.size; dealloc(len); - len = (uint16_t *)alloc(total_dic_size * sizeof(uint16_t), mm::BLOCK_TEMPORARY); + len = (uint16_t *)alloc(total_dic_size * sizeof(uint16_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY); dealloc(value_offset); - value_offset = (uint32_t *)alloc(total_dic_size * sizeof(uint32_t), mm::BLOCK_TEMPORARY); + value_offset = (uint32_t *)alloc(total_dic_size * sizeof(uint32_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY); max_value_size = 0; for (int i = 0; i < hdr.size; i++) { @@ -266,7 +267,7 @@ void FTree::LoadData(const fs::path &p) { total_buf_size = len_sum; dealloc(mem); - mem = (char *)alloc(total_buf_size, mm::BLOCK_TEMPORARY); + mem = (char *)alloc(total_buf_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); std::memset(mem, 0, total_buf_size); std::memcpy(mem, buf, len_sum); last_code = -1; @@ -281,7 +282,7 @@ void FTree::InitHash() { hash_size = int(hdr.size < 30 ? 97 : (hdr.size + 10) * 2.5); while (hash_size % 2 == 0 || hash_size % 3 == 0 || hash_size % 5 == 0 || hash_size % 7 == 0) hash_size++; dealloc(hash_table); - hash_table = (int *)alloc(hash_size * sizeof(int), mm::BLOCK_TEMPORARY); // 2 GB max. + hash_table = (int *)alloc(hash_size * sizeof(int), mm::BLOCK_TYPE::BLOCK_TEMPORARY); // 2 GB max. if (hash_table == NULL) throw common::OutOfMemoryException("Too many lookup values"); std::memset(hash_table, 0xFF, diff --git a/storage/stonedb/core/ftree.h b/storage/stonedb/core/ftree.h index fdc27e2dd..e815130d2 100644 --- a/storage/stonedb/core/ftree.h +++ b/storage/stonedb/core/ftree.h @@ -50,7 +50,7 @@ class FTree final : public mm::TraceableObject { int end); // max. value size for an interval of codes int CheckConsistency(); // 0 = dictionary consistent, otherwise corrupted - mm::TO_TYPE TraceableType() const override { return mm::TO_FTREE; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_FTREE; } void Release() override; bool Changed() const { return changed; } diff --git a/storage/stonedb/core/group_distinct_cache.cpp b/storage/stonedb/core/group_distinct_cache.cpp index e7bb07ef4..f90cd7652 100644 --- a/storage/stonedb/core/group_distinct_cache.cpp +++ b/storage/stonedb/core/group_distinct_cache.cpp @@ -49,10 +49,10 @@ void GroupDistinctCache::Initialize() { if (buf_size * width > upper_byte_limit) { buf_size = upper_byte_limit / width; CI_SetDefaultSize(upper_byte_limit); - t = (unsigned char *)alloc(upper_byte_limit, mm::BLOCK_TEMPORARY); + t = (unsigned char *)alloc(upper_byte_limit, mm::BLOCK_TYPE::BLOCK_TEMPORARY); } else t = (unsigned char *)alloc(buf_size * width, - mm::BLOCK_TEMPORARY); // no need to cache on disk + mm::BLOCK_TYPE::BLOCK_TEMPORARY); // no need to cache on disk cur_pos = t; cur_obj = 0; cur_write_pos = t; @@ -129,7 +129,7 @@ void GroupDistinctCache::MarkCurrentAsPreserved() { DEBUG_ASSERT(cur_obj >= cur_write_obj); if (t_write == NULL) { t_write = (unsigned char *)alloc(upper_byte_limit, - mm::BLOCK_TEMPORARY); // switch writing to the new buffer + mm::BLOCK_TYPE::BLOCK_TEMPORARY); // switch writing to the new buffer cur_write_pos = t_write; } if (cur_obj > cur_write_obj) { diff --git a/storage/stonedb/core/group_distinct_cache.h b/storage/stonedb/core/group_distinct_cache.h index dd9da9466..a8939fdc4 100644 --- a/storage/stonedb/core/group_distinct_cache.h +++ b/storage/stonedb/core/group_distinct_cache.h @@ -57,7 +57,7 @@ class GroupDistinctCache : private system::CacheableItem, public mm::TraceableOb void Omit(int64_t obj_to_omit); // move a reading position forward by // obj_to_omit objects - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } private: void Initialize(); diff --git a/storage/stonedb/core/group_distinct_table.cpp b/storage/stonedb/core/group_distinct_table.cpp index 7f2677234..32a52fa87 100644 --- a/storage/stonedb/core/group_distinct_table.cpp +++ b/storage/stonedb/core/group_distinct_table.cpp @@ -133,7 +133,7 @@ void GroupDistinctTable::InitializeBuffers(int64_t max_no_rows) // max_no_rows if (no_rows % 17 == 0) no_rows++; rows_limit = int64_t(no_rows * 0.9); // rows_limit is used to determine whether the table is full - t = (unsigned char *)alloc(total_width * no_rows, mm::BLOCK_TEMPORARY); + t = (unsigned char *)alloc(total_width * no_rows, mm::BLOCK_TYPE::BLOCK_TEMPORARY); // t = new BlockedRowMemStorage(total_width, &mem_mngr, no_rows); input_buffer = (unsigned char *)(new int[total_width / 4 + 1]); // ensure proper memory alignment rccontrol.lock(m_conn->GetThreadID()) << "GroupDistinctTable initialized as Hash(" << no_rows << "), " << group_bytes @@ -153,8 +153,8 @@ GDTResult GroupDistinctTable::Find(int64_t group, int64_t val) // numeric value if (filter_implementation) { val = encoder->ValPutValue64(val); val = group + group_factor * val; - if (f->Get(val)) return GDT_EXISTS; - return GDT_ADDED; // "Added" means "found" here. + if (f->Get(val)) return GDTResult::GDT_EXISTS; + return GDTResult::GBIMODE_AS_TEXT; // "Added" means "found" here. } group += 1; // offset; 0 means empty position std::memmove(input_buffer, (unsigned char *)(&group), group_bytes); @@ -167,9 +167,9 @@ GDTResult GroupDistinctTable::Add(int64_t group, MIIterator &mit) { if (filter_implementation) { int64_t val = encoder->ValEncode(mit); val = group + group_factor * val; - if (f->Get(val)) return GDT_EXISTS; + if (f->Get(val)) return GDTResult::GDT_EXISTS; f->Set(val); - return GDT_ADDED; + return GDTResult::GBIMODE_AS_TEXT; } group += 1; // offset; 0 means empty position std::memmove(input_buffer, (unsigned char *)(&group), group_bytes); @@ -182,9 +182,9 @@ GDTResult GroupDistinctTable::Add(int64_t group, int64_t val) // numeric values if (filter_implementation) { val = encoder->ValPutValue64(val); val = group + group_factor * val; - if (f->Get(val)) return GDT_EXISTS; + if (f->Get(val)) return GDTResult::GDT_EXISTS; f->Set(val); - return GDT_ADDED; + return GDTResult::GBIMODE_AS_TEXT; } group += 1; // offset; 0 means empty position std::memmove(input_buffer, (unsigned char *)(&group), group_bytes); @@ -250,7 +250,7 @@ GDTResult GroupDistinctTable::FindCurrentRow(bool find_only) // find / insert t if (!RowEmpty(p)) { if (std::memcmp(p, input_buffer, total_width) == 0) { // i.e. identical row found - return GDT_EXISTS; + return GDTResult::GDT_EXISTS; } local_no_of_checks++; row += step + local_no_of_checks; @@ -260,10 +260,10 @@ GDTResult GroupDistinctTable::FindCurrentRow(bool find_only) // find / insert t std::memcpy(p, input_buffer, total_width); no_of_occupied++; } - return GDT_ADDED; + return GDTResult::GBIMODE_AS_TEXT; } } while (local_no_of_checks < 8); // search depth - return GDT_FULL; + return GDTResult::GDT_FULL; } void GroupDistinctTable::Clear() // clear the tables diff --git a/storage/stonedb/core/group_distinct_table.h b/storage/stonedb/core/group_distinct_table.h index b84bcf675..85b20997d 100644 --- a/storage/stonedb/core/group_distinct_table.h +++ b/storage/stonedb/core/group_distinct_table.h @@ -26,10 +26,10 @@ namespace stonedb { namespace core { -enum GDTResult { - GDT_ADDED, // value successfully added to a table as a new one - GDT_EXISTS, // value already in table - GDT_FULL // value not found, but cannot add (table full) +enum class GDTResult { + GBIMODE_AS_TEXT, // value successfully added to a table as a new one + GDT_EXISTS, // value already in table + GDT_FULL // value not found, but cannot add (table full) }; static const int64_t zero_const = 0; @@ -71,7 +71,7 @@ class GroupDistinctTable : public mm::TraceableObject { void ValueFromInput(types::BString &); // decode original value from // the current input vector - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } private: GDTResult FindCurrentRow(bool find_only = false); // find / insert the current buffer diff --git a/storage/stonedb/core/group_table.cpp b/storage/stonedb/core/group_table.cpp index 720c38c18..306117154 100644 --- a/storage/stonedb/core/group_table.cpp +++ b/storage/stonedb/core/group_table.cpp @@ -81,7 +81,7 @@ GroupTable::GroupTable(const GroupTable &sec) : mm::TraceableObject(sec) { vc[i] = sec.vc[i]; char vco = 0; - if (sec.vc[i] && sec.vc[i]->IsSingleColumn()) { + if (sec.vc[i] && static_cast(sec.vc[i]->IsSingleColumn())) { vc[i] = CreateVCCopy(sec.vc[i]); if (vc[i] != sec.vc[i]) { // success @@ -134,7 +134,7 @@ void GroupTable::AddAggregatedColumn(vcolumn::VirtualColumn *vc, GT_Aggregation desc.operation = operation; desc.distinct = distinct; desc.collation = in_collation; - if (operation == GT_GROUP_CONCAT) { + if (operation == GT_Aggregation::GT_GROUP_CONCAT) { desc.si = si; } aggregated_desc.push_back(desc); @@ -172,7 +172,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { // Aggregations: // COUNT(...) - if (desc.operation == GT_COUNT || desc.operation == GT_COUNT_NOT_NULL) { + if (desc.operation == GT_Aggregation::GT_COUNT || desc.operation == GT_Aggregation::GT_COUNT_NOT_NULL) { if (desc.max_no_values > 0x7FFFFFFF) aggregator[i] = new AggregatorCount64(desc.max_no_values); else @@ -180,7 +180,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { } else // SUM(...) Note: strings are parsed // to double - if (desc.operation == GT_SUM) { + if (desc.operation == GT_Aggregation::GT_SUM) { if (ATI::IsRealType(desc.type) || ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorSumD; else @@ -188,7 +188,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { } else // AVG(...) Note: strings are parsed // to double - if (desc.operation == GT_AVG) { + if (desc.operation == GT_Aggregation::GT_AVG) { if (ATI::IsRealType(desc.type) || ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorAvgD; else if (desc.type == common::CT::YEAR) @@ -197,7 +197,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { aggregator[i] = new AggregatorAvg64(desc.precision); } else // MIN(...) - if (desc.operation == GT_MIN) { + if (desc.operation == GT_Aggregation::GT_MIN) { if (ATI::IsStringType(desc.type)) { if (types::RequiresUTFConversions(desc.collation)) aggregator[i] = new AggregatorMinT_UTF(desc.size, desc.collation); @@ -211,7 +211,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { aggregator[i] = new AggregatorMin32; } else // MAX(...) - if (desc.operation == GT_MAX) { + if (desc.operation == GT_Aggregation::GT_MAX) { if (ATI::IsStringType(desc.type)) { if (types::RequiresUTFConversions(desc.collation)) aggregator[i] = new AggregatorMaxT_UTF(desc.size, desc.collation); @@ -224,7 +224,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { else aggregator[i] = new AggregatorMax32; } else // LIST - just a first value found - if (desc.operation == GT_LIST) { + if (desc.operation == GT_Aggregation::GT_LIST) { if (ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorListT(desc.size); else if (ATI::IsRealType(desc.type) || (desc.min < -(0x7FFFFFFF) || desc.max > 0x7FFFFFFF)) @@ -233,46 +233,46 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { aggregator[i] = new AggregatorList32; } else // VAR_POP(...) - if (desc.operation == GT_VAR_POP) { + if (desc.operation == GT_Aggregation::GT_VAR_POP) { if (ATI::IsRealType(desc.type) || ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorVarPopD; else aggregator[i] = new AggregatorVarPop64(desc.precision); } else // VAR_SAMP(...) - if (desc.operation == GT_VAR_SAMP) { + if (desc.operation == GT_Aggregation::GT_VAR_SAMP) { if (ATI::IsRealType(desc.type) || ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorVarSampD; else aggregator[i] = new AggregatorVarSamp64(desc.precision); } else // STD_POP(...) - if (desc.operation == GT_STD_POP) { + if (desc.operation == GT_Aggregation::GT_STD_POP) { if (ATI::IsRealType(desc.type) || ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorStdPopD; else aggregator[i] = new AggregatorStdPop64(desc.precision); } else // STD_SAMP(...) - if (desc.operation == GT_STD_SAMP) { + if (desc.operation == GT_Aggregation::GT_STD_SAMP) { if (ATI::IsRealType(desc.type) || ATI::IsStringType(desc.type)) aggregator[i] = new AggregatorStdSampD; else aggregator[i] = new AggregatorStdSamp64(desc.precision); } else // BIT_AND(...) - if (desc.operation == GT_BIT_AND) { + if (desc.operation == GT_Aggregation::GT_BIT_AND) { aggregator[i] = new AggregatorBitAnd; } else // BIT_Or(...) - if (desc.operation == GT_BIT_OR) { + if (desc.operation == GT_Aggregation::GT_BIT_OR) { aggregator[i] = new AggregatorBitOr; } else // BIT_XOR(...) - if (desc.operation == GT_BIT_XOR) { + if (desc.operation == GT_Aggregation::GT_BIT_XOR) { aggregator[i] = new AggregatorBitXor; - } else // GT_GROUP_CONCAT(...) - if (desc.operation == GT_GROUP_CONCAT) { + } else // GT_Aggregation::GT_GROUP_CONCAT(...) + if (desc.operation == GT_Aggregation::GT_GROUP_CONCAT) { aggregator[i] = new AggregatorGroupConcat(desc.si, desc.type); } @@ -336,7 +336,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { max_group_code = encoder[1]->MaxCode() * 256 + encoder[0]->MaxCode(); // wider than one-byte encoders are hard to // interpret, because of endianess swap - // STONEDB_LOG(INFO, "primary_total_size(mem_available) %d, total_width %d, + // STONEDB_LOG(LogCtl_Level::INFO, "primary_total_size(mem_available) %d, total_width %d, // declared_max_no_groups %d", primary_total_size, total_width, // declared_max_no_groups); @@ -363,7 +363,7 @@ void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) { gdistinct[i] = std::make_shared(p_power); gdistinct[i]->InitializeVC(vm_tab->RowNumberScope(), vc[i], desc.max_no_values, distinct_size / no_columns_with_distinct, - (operation[i] != GT_COUNT_NOT_NULL)); // otherwise must be decodable + (operation[i] != GT_Aggregation::GT_COUNT_NOT_NULL)); // otherwise must be decodable distinct_size -= gdistinct[i]->BytesTaken(); no_columns_with_distinct--; } @@ -518,7 +518,7 @@ GDTResult GroupTable::FindDistinctValue(int col, int64_t row, { DEBUG_ASSERT(gdistinct[col]); if (v == common::NULL_VALUE_64) // works also for double - return GDT_EXISTS; // null omitted + return GDTResult::GDT_EXISTS; // null omitted return gdistinct[col]->Find(row, v); } @@ -527,7 +527,7 @@ GDTResult GroupTable::AddDistinctValue(int col, int64_t row, { DEBUG_ASSERT(gdistinct[col]); if (v == common::NULL_VALUE_64) // works also for double - return GDT_EXISTS; // null omitted + return GDTResult::GDT_EXISTS; // null omitted return gdistinct[col]->Add(row, v); } @@ -537,8 +537,8 @@ bool GroupTable::PutAggregatedValue(int col, int64_t row, MIIterator &mit, int64 DEBUG_ASSERT(gdistinct[col]); if (vc[col]->IsNull(mit)) return true; // omit nulls GDTResult res = gdistinct[col]->Add(row, mit); - if (res == GDT_EXISTS) return true; // value found, do not aggregate it again - if (res == GDT_FULL) { + if (res == GDTResult::GDT_EXISTS) return true; // value found, do not aggregate it again + if (res == GDTResult::GDT_FULL) { if (gdistinct[col]->AlreadyFull()) not_full = false; // disable also the main grouping table (if it is a // persistent rejection) @@ -582,8 +582,8 @@ bool GroupTable::PutCachedValue(int col, GroupDistinctCache &cache, { DEBUG_ASSERT(distinct[col]); GDTResult res = gdistinct[col]->AddFromCache(cache.GetCurrentValue()); - if (res == GDT_EXISTS) return true; // value found, do not aggregate it again - if (res == GDT_FULL) { + if (res == GDTResult::GDT_EXISTS) return true; // value found, do not aggregate it again + if (res == GDTResult::GDT_FULL) { if (gdistinct[col]->AlreadyFull()) not_full = false; // disable also the main grouping table (if it is a // persistent rejection) @@ -591,7 +591,7 @@ bool GroupTable::PutCachedValue(int col, GroupDistinctCache &cache, } int64_t row = gdistinct[col]->GroupNoFromInput(); // restore group number unsigned char *p = vm_tab->GetAggregationRow(row) + aggregated_col_offset[col]; - if (operation[col] == GT_COUNT_NOT_NULL) + if (operation[col] == GT_Aggregation::GT_COUNT_NOT_NULL) aggregator[col]->PutAggregatedValue(p, 1); // factor = 1, because we are just after distinct else { if (as_text) { diff --git a/storage/stonedb/core/group_table.h b/storage/stonedb/core/group_table.h index c22130a11..1f74e466d 100644 --- a/storage/stonedb/core/group_table.h +++ b/storage/stonedb/core/group_table.h @@ -33,7 +33,7 @@ namespace core { // GroupTable - a tool for storing values and counters -enum GT_Aggregation { +enum class GT_Aggregation { GT_LIST, // GT_LIST - just store the first value GT_COUNT, GT_COUNT_NOT_NULL, @@ -121,7 +121,7 @@ class GroupTable : public mm::TraceableObject { if (distinct_present) return false; for (auto &ag : aggregated_desc) { - if (ag.operation == GT_GROUP_CONCAT) return false; + if (ag.operation == GT_Aggregation::GT_GROUP_CONCAT) return false; } return true; } @@ -153,7 +153,7 @@ class GroupTable : public mm::TraceableObject { int64_t GetCurrentRow() { return vm_tab->GetCurrentRow(); } void NextRow() { vm_tab->NextRow(); } bool RowValid() { return vm_tab->RowValid(); } - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } private: std::vector input_buffer; @@ -182,7 +182,7 @@ class GroupTable : public mm::TraceableObject { min = common::MINUS_INF_64; max = common::PLUS_INF_64; max_no_values = 0; - operation = GT_LIST; + operation = GT_Aggregation::GT_LIST; distinct = false; size = 0; precision = 0; diff --git a/storage/stonedb/core/groupby_wrapper.cpp b/storage/stonedb/core/groupby_wrapper.cpp index 69b85cc31..d78cc28ff 100644 --- a/storage/stonedb/core/groupby_wrapper.cpp +++ b/storage/stonedb/core/groupby_wrapper.cpp @@ -33,7 +33,7 @@ GroupByWrapper::GroupByWrapper(int a_size, bool distinct, Transaction *conn, uin for (int i = 0; i < attrs_size; i++) { virt_col[i] = nullptr; - input_mode[i] = GBIMODE_NOT_SET; + input_mode[i] = GBInputMode::GBIMODE_NOT_SET; is_lookup[i] = false; attr_mapping[i] = -1; dist_vals[i] = common::NULL_VALUE_64; @@ -110,7 +110,7 @@ void GroupByWrapper::AddGroupingColumn(int attr_no, int orig_attr_no, TempTable: // Not used for grouping columns: is_lookup[attr_no] = false; dist_vals[attr_no] = common::NULL_VALUE_64; - input_mode[attr_no] = GBIMODE_NOT_SET; + input_mode[attr_no] = GBInputMode::GBIMODE_NOT_SET; attr_mapping[orig_attr_no] = attr_no; gt.AddGroupingColumn(virt_col[attr_no]); @@ -142,77 +142,77 @@ void GroupByWrapper::AddAggregatedColumn(int orig_attr_no, TempTable::Attr &a, i switch (a.mode) { case common::ColOperation::SUM: - ag_oper = GT_SUM; + ag_oper = GT_Aggregation::GT_SUM; ag_type = virt_col[attr_no]->TypeName(); ag_prec = virt_col[attr_no]->Type().GetScale(); break; case common::ColOperation::AVG: - ag_oper = GT_AVG; + ag_oper = GT_Aggregation::GT_AVG; ag_type = virt_col[attr_no]->TypeName(); ag_prec = virt_col[attr_no]->Type().GetScale(); break; case common::ColOperation::MIN: - ag_oper = GT_MIN; + ag_oper = GT_Aggregation::GT_MIN; break; case common::ColOperation::MAX: - ag_oper = GT_MAX; + ag_oper = GT_Aggregation::GT_MAX; break; case common::ColOperation::COUNT: if (a.term.IsNull() || (!ag_distinct && virt_col[attr_no]->IsConst())) { if (virt_col[attr_no] && virt_col[attr_no]->IsConst()) { MIIterator dummy(NULL, p_power); if (virt_col[attr_no]->IsNull(dummy)) { - ag_oper = GT_COUNT_NOT_NULL; + ag_oper = GT_Aggregation::GT_COUNT_NOT_NULL; ag_type = virt_col[attr_no]->TypeName(); ag_size = max_size; } else { virt_col[attr_no] = NULL; // forget about constant in count(...), except null - ag_oper = GT_COUNT; + ag_oper = GT_Aggregation::GT_COUNT; } } else { virt_col[attr_no] = NULL; // forget about constant in count(...), except null - ag_oper = GT_COUNT; + ag_oper = GT_Aggregation::GT_COUNT; } } else { - ag_oper = GT_COUNT_NOT_NULL; + ag_oper = GT_Aggregation::GT_COUNT_NOT_NULL; ag_type = virt_col[attr_no]->TypeName(); ag_size = max_size; } break; case common::ColOperation::LISTING: - ag_oper = GT_LIST; + ag_oper = GT_Aggregation::GT_LIST; break; case common::ColOperation::VAR_POP: - ag_oper = GT_VAR_POP; + ag_oper = GT_Aggregation::GT_VAR_POP; ag_type = virt_col[attr_no]->TypeName(); ag_prec = virt_col[attr_no]->Type().GetScale(); break; case common::ColOperation::VAR_SAMP: - ag_oper = GT_VAR_SAMP; + ag_oper = GT_Aggregation::GT_VAR_SAMP; ag_type = virt_col[attr_no]->TypeName(); ag_prec = virt_col[attr_no]->Type().GetScale(); break; case common::ColOperation::STD_POP: - ag_oper = GT_STD_POP; + ag_oper = GT_Aggregation::GT_STD_POP; ag_type = virt_col[attr_no]->TypeName(); ag_prec = virt_col[attr_no]->Type().GetScale(); break; case common::ColOperation::STD_SAMP: - ag_oper = GT_STD_SAMP; + ag_oper = GT_Aggregation::GT_STD_SAMP; ag_type = virt_col[attr_no]->TypeName(); ag_prec = virt_col[attr_no]->Type().GetScale(); break; case common::ColOperation::BIT_AND: - ag_oper = GT_BIT_AND; + ag_oper = GT_Aggregation::GT_BIT_AND; break; case common::ColOperation::BIT_OR: - ag_oper = GT_BIT_OR; + ag_oper = GT_Aggregation::GT_BIT_OR; break; case common::ColOperation::BIT_XOR: - ag_oper = GT_BIT_XOR; + ag_oper = GT_Aggregation::GT_BIT_XOR; break; case common::ColOperation::GROUP_CONCAT: - ag_oper = GT_GROUP_CONCAT; + ag_oper = GT_Aggregation::GT_GROUP_CONCAT; break; default: throw common::NotImplementedException("Aggregation not implemented"); @@ -220,25 +220,26 @@ void GroupByWrapper::AddAggregatedColumn(int orig_attr_no, TempTable::Attr &a, i if (virt_col[attr_no] && virt_col[attr_no]->Type().IsLookup() && !types::RequiresUTFConversions(virt_col[attr_no]->GetCollation()) && - (ag_oper == GT_COUNT || ag_oper == GT_COUNT_NOT_NULL || ag_oper == GT_LIST)) { + (ag_oper == GT_Aggregation::GT_COUNT || ag_oper == GT_Aggregation::GT_COUNT_NOT_NULL || + ag_oper == GT_Aggregation::GT_LIST)) { // lookup for these operations may use codes ag_size = 4; // integer ag_prec = 0; ag_type = common::CT::INT; is_lookup[attr_no] = true; } - if (ag_oper == GT_COUNT) - input_mode[attr_no] = GBIMODE_NO_VALUE; - else if (ag_oper == GT_GROUP_CONCAT) - input_mode[attr_no] = GBIMODE_AS_TEXT; + if (ag_oper == GT_Aggregation::GT_COUNT) + input_mode[attr_no] = GBInputMode::GBIMODE_NO_VALUE; + else if (ag_oper == GT_Aggregation::GT_GROUP_CONCAT) + input_mode[attr_no] = GBInputMode::GBIMODE_AS_TEXT; else input_mode[attr_no] = (ATI::IsStringType(virt_col[attr_no]->TypeName()) && (!is_lookup[attr_no] || types::RequiresUTFConversions(virt_col[attr_no]->GetCollation())) - ? GBIMODE_AS_TEXT - : GBIMODE_AS_INT64); + ? GBInputMode::GBIMODE_AS_TEXT + : GBInputMode::GBIMODE_AS_INT64); - STONEDB_LOG(DEBUG, + STONEDB_LOG(LogCtl_Level::DEBUG, "attr_no %d, input_mode[attr_no] %d, a.alias %s, a.si.separator " "%s, direction %d, ag_type %d, ag_size %d", attr_no, input_mode[attr_no], a.alias, a.si.separator.c_str(), a.si.order, ag_type, ag_size); @@ -289,8 +290,8 @@ bool GroupByWrapper::AggregatePackInOneGroup(int attr_no, MIIterator &mit, int64 auto val_it = val_list.begin(); while (val_it != val_list.end()) { GDTResult res = gt.FindDistinctValue(attr_no, uniform_pos, *val_it); - if (res == GDT_FULL) return false; // no chance to optimize - if (res == GDT_EXISTS) + if (res == GDTResult::GDT_FULL) return false; // no chance to optimize + if (res == GDTResult::GDT_EXISTS) val_it = val_list.erase(val_it); else ++val_it; @@ -396,8 +397,8 @@ void GroupByWrapper::AddAllGroupingConstants(MIIterator &mit) { void GroupByWrapper::AddAllAggregatedConstants(MIIterator &mit) { for (int attr_no = no_grouping_attr; attr_no < no_attr; attr_no++) if (virt_col[attr_no] && virt_col[attr_no]->IsConst()) { - if (mit.NoTuples() > 0 || gt.AttrOper(attr_no) == GT_LIST) { - if (!(gt.AttrOper(attr_no) == GT_COUNT && virt_col[attr_no]->IsNull(mit))) // else left as 0 + if (mit.NoTuples() > 0 || gt.AttrOper(attr_no) == GT_Aggregation::GT_LIST) { + if (!(gt.AttrOper(attr_no) == GT_Aggregation::GT_COUNT && virt_col[attr_no]->IsNull(mit))) // else left as 0 PutAggregatedValue(attr_no, 0, mit); } else PutAggregatedNull(attr_no, 0); @@ -408,7 +409,7 @@ void GroupByWrapper::AddAllCountStar(int64_t row, MIIterator &mit, int64_t val) // set all count(*) values { for (int gr_a = no_grouping_attr; gr_a < no_attr; gr_a++) { - if ((virt_col[gr_a] == NULL || virt_col[gr_a]->IsConst()) && gt.AttrOper(gr_a) == GT_COUNT && + if ((virt_col[gr_a] == NULL || virt_col[gr_a]->IsConst()) && gt.AttrOper(gr_a) == GT_Aggregation::GT_COUNT && !gt.AttrDistinct(gr_a)) { if (virt_col[gr_a] && virt_col[gr_a]->IsNull(mit)) PutAggregatedValueForCount(gr_a, row, 0); @@ -427,8 +428,9 @@ bool GroupByWrapper::AttrMayBeUpdatedByPack(int i, MIIterator &mit) // false, i bool GroupByWrapper::PackWillNotUpdateAggregation(int i, MIIterator &mit) // false, if counters can be changed { // MEASURE_FET("GroupByWrapper::PackWillNotUpdateAggregation(...)"); - DEBUG_ASSERT(input_mode[i] != GBIMODE_NOT_SET); - if (((is_lookup[i] || input_mode[i] == GBIMODE_AS_TEXT) && (gt.AttrOper(i) == GT_MIN || gt.AttrOper(i) == GT_MAX)) || + DEBUG_ASSERT(input_mode[i] != GBInputMode::GBIMODE_NOT_SET); + if (((is_lookup[i] || input_mode[i] == GBInputMode::GBIMODE_AS_TEXT) && + (gt.AttrOper(i) == GT_Aggregation::GT_MIN || gt.AttrOper(i) == GT_Aggregation::GT_MAX)) || virt_col[i] == NULL) return false; @@ -457,8 +459,9 @@ bool GroupByWrapper::PackWillNotUpdateAggregation(int i, MIIterator &mit) // fa bool GroupByWrapper::DataWillNotUpdateAggregation(int i) // false, if counters can be changed { // Identical with PackWillNot...(), but calculated for global statistics - DEBUG_ASSERT(input_mode[i] != GBIMODE_NOT_SET); - if (((is_lookup[i] || input_mode[i] == GBIMODE_AS_TEXT) && (gt.AttrOper(i) == GT_MIN || gt.AttrOper(i) == GT_MAX)) || + DEBUG_ASSERT(input_mode[i] != GBInputMode::GBIMODE_NOT_SET); + if (((is_lookup[i] || input_mode[i] == GBInputMode::GBIMODE_AS_TEXT) && + (gt.AttrOper(i) == GT_Aggregation::GT_MIN || gt.AttrOper(i) == GT_Aggregation::GT_MAX)) || virt_col[i] == NULL) return false; @@ -485,25 +488,25 @@ bool GroupByWrapper::DataWillNotUpdateAggregation(int i) // false, if counters } bool GroupByWrapper::PutAggregatedValueForCount(int gr_a, int64_t pos, int64_t factor) { - DEBUG_ASSERT(gt.AttrOper(gr_a) == GT_COUNT || gt.AttrOper(gr_a) == GT_COUNT_NOT_NULL); + DEBUG_ASSERT(gt.AttrOper(gr_a) == GT_Aggregation::GT_COUNT || gt.AttrOper(gr_a) == GT_Aggregation::GT_COUNT_NOT_NULL); return gt.PutAggregatedValue(gr_a, pos, factor); } bool GroupByWrapper::PutAggregatedValueForMinMax(int gr_a, int64_t pos, int64_t factor) { - DEBUG_ASSERT(gt.AttrOper(gr_a) == GT_MIN || gt.AttrOper(gr_a) == GT_MAX); + DEBUG_ASSERT(gt.AttrOper(gr_a) == GT_Aggregation::GT_MIN || gt.AttrOper(gr_a) == GT_Aggregation::GT_MAX); return gt.PutAggregatedValue(gr_a, pos, factor); } bool GroupByWrapper::PutAggregatedNull(int gr_a, int64_t pos) { - DEBUG_ASSERT(input_mode[gr_a] != GBIMODE_NOT_SET); - return gt.PutAggregatedNull(gr_a, pos, (input_mode[gr_a] == GBIMODE_AS_TEXT)); + DEBUG_ASSERT(input_mode[gr_a] != GBInputMode::GBIMODE_NOT_SET); + return gt.PutAggregatedNull(gr_a, pos, (input_mode[gr_a] == GBInputMode::GBIMODE_AS_TEXT)); return false; } bool GroupByWrapper::PutAggregatedValue(int gr_a, int64_t pos, MIIterator &mit, int64_t factor) { - DEBUG_ASSERT(input_mode[gr_a] != GBIMODE_NOT_SET); - if (input_mode[gr_a] == GBIMODE_NO_VALUE) return gt.PutAggregatedValue(gr_a, pos, factor); - return gt.PutAggregatedValue(gr_a, pos, mit, factor, (input_mode[gr_a] == GBIMODE_AS_TEXT)); + DEBUG_ASSERT(input_mode[gr_a] != GBInputMode::GBIMODE_NOT_SET); + if (input_mode[gr_a] == GBInputMode::GBIMODE_NO_VALUE) return gt.PutAggregatedValue(gr_a, pos, factor); + return gt.PutAggregatedValue(gr_a, pos, mit, factor, (input_mode[gr_a] == GBInputMode::GBIMODE_AS_TEXT)); } types::BString GroupByWrapper::GetValueT(int col, int64_t row) { @@ -558,8 +561,9 @@ void GroupByWrapper::ClearDistinctBuffers() { bool GroupByWrapper::PutCachedValue(int gr_a) // current value from distinct cache { - DEBUG_ASSERT(input_mode[gr_a] != GBIMODE_NOT_SET); - bool added = gt.PutCachedValue(gr_a, distinct_watch.gd_cache[gr_a], (input_mode[gr_a] == GBIMODE_AS_TEXT)); + DEBUG_ASSERT(input_mode[gr_a] != GBInputMode::GBIMODE_NOT_SET); + bool added = + gt.PutCachedValue(gr_a, distinct_watch.gd_cache[gr_a], (input_mode[gr_a] == GBInputMode::GBIMODE_AS_TEXT)); if (!added) distinct_watch.gd_cache[gr_a].MarkCurrentAsPreserved(); return added; } @@ -583,16 +587,16 @@ bool GroupByWrapper::IsCountOnly(int gr_a) // true, if an attribute is count(*) // no attr specified) { if (gr_a != -1) { - return (virt_col[gr_a] == NULL || virt_col[gr_a]->IsConst()) && gt.AttrOper(gr_a) == GT_COUNT && + return (virt_col[gr_a] == NULL || virt_col[gr_a]->IsConst()) && gt.AttrOper(gr_a) == GT_Aggregation::GT_COUNT && !gt.AttrDistinct(gr_a); } bool count_found = false; for (int i = 0; i < no_attr; i++) { // function should return true for e.g.: "SELECT 1, 2, // 'ala', COUNT(*), 5, COUNT(4) FROM ..." - if (gt.AttrOper(i) == GT_COUNT) count_found = true; - if (!((virt_col[i] == NULL || virt_col[i]->IsConst()) && gt.AttrOper(i) == GT_COUNT && - !gt.AttrDistinct(i)) // count(*) or count(const) - && (gt.AttrOper(i) != GT_LIST || !virt_col[i]->IsConst())) // a constant + if (gt.AttrOper(i) == GT_Aggregation::GT_COUNT) count_found = true; + if (!((virt_col[i] == NULL || virt_col[i]->IsConst()) && gt.AttrOper(i) == GT_Aggregation::GT_COUNT && + !gt.AttrDistinct(i)) // count(*) or count(const) + && (gt.AttrOper(i) != GT_Aggregation::GT_LIST || !virt_col[i]->IsConst())) // a constant return false; } return count_found; @@ -607,7 +611,7 @@ bool GroupByWrapper::IsMinOnly() // true, if an attribute is min(column), and if (no_attr != 1) { return false; } - if (gt.AttrOper(0) == GT_MIN && no_grouping_attr == 0 && no_aggregated_attr == 1) { + if (gt.AttrOper(0) == GT_Aggregation::GT_MIN && no_grouping_attr == 0 && no_aggregated_attr == 1) { return true; } return false; @@ -622,7 +626,7 @@ bool GroupByWrapper::IsMaxOnly() // true, if an attribute is max(column), and if (no_attr != 1) { return false; } - if (gt.AttrOper(0) == GT_MAX && no_grouping_attr == 0 && no_aggregated_attr == 1) { + if (gt.AttrOper(0) == GT_Aggregation::GT_MAX && no_grouping_attr == 0 && no_aggregated_attr == 1) { return true; } return false; diff --git a/storage/stonedb/core/groupby_wrapper.h b/storage/stonedb/core/groupby_wrapper.h index 446c48c41..6ddbf54cf 100644 --- a/storage/stonedb/core/groupby_wrapper.h +++ b/storage/stonedb/core/groupby_wrapper.h @@ -136,7 +136,7 @@ class GroupByWrapper final { bool IsMinOnly(); // true, if an attribute is min(column) bool IsMaxOnly(); // true, if an attribute is max(column) bool IsCountDistinctOnly() { - return no_grouping_attr == 0 && no_aggregated_attr == 1 && gt.AttrOper(0) == GT_COUNT_NOT_NULL && + return no_grouping_attr == 0 && no_aggregated_attr == 1 && gt.AttrOper(0) == GT_Aggregation::GT_COUNT_NOT_NULL && gt.AttrDistinct(0); } bool MayBeParallel() const; @@ -185,7 +185,7 @@ class GroupByWrapper final { Transaction *m_conn; private: - enum GBInputMode { + enum class GBInputMode { GBIMODE_NOT_SET, GBIMODE_NO_VALUE, // e.g. count(*) GBIMODE_AS_INT64, diff --git a/storage/stonedb/core/hash_table.cpp b/storage/stonedb/core/hash_table.cpp index e64415683..4403a3e58 100644 --- a/storage/stonedb/core/hash_table.cpp +++ b/storage/stonedb/core/hash_table.cpp @@ -112,7 +112,7 @@ void HashTable::Initialize(int64_t max_table_size, [[maybe_unused]] bool easy_ro rows_lock_.resize(std::min(rows_count_, 10000u)); // No need to cache on disk. - buffer_ = (unsigned char *)alloc(((total_width_ / 4) * rows_count_) * 4, mm::BLOCK_TEMPORARY); + buffer_ = (unsigned char *)alloc(((total_width_ / 4) * rows_count_) * 4, mm::BLOCK_TYPE::BLOCK_TEMPORARY); std::memset(buffer_, 0, total_width_ * rows_count_); } diff --git a/storage/stonedb/core/hash_table.h b/storage/stonedb/core/hash_table.h index 5c46b9e8c..3383bfec3 100644 --- a/storage/stonedb/core/hash_table.h +++ b/storage/stonedb/core/hash_table.h @@ -53,7 +53,7 @@ class HashTable : public mm::TraceableObject { private: // Overridden from mm::TraceableObject: - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } std::vector column_size_; bool for_count_only_ = false; diff --git a/storage/stonedb/core/index_table.cpp b/storage/stonedb/core/index_table.cpp index 4824a5dd4..b6bdbe2a7 100644 --- a/storage/stonedb/core/index_table.cpp +++ b/storage/stonedb/core/index_table.cpp @@ -46,10 +46,10 @@ IndexTable::IndexTable(int64_t _size, int64_t _orig_size, [[maybe_unused]] int m if (size * bytes_per_value < buffer_size_in_bytes) buffer_size_in_bytes = int(size * bytes_per_value); // the whole table in one buffer - buf = (unsigned char *)alloc(buffer_size_in_bytes, mm::BLOCK_TEMPORARY, true); + buf = (unsigned char *)alloc(buffer_size_in_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (!buf) { Unlock(); - STONEDB_LOG(ERROR, "Could not allocate memory for IndexTable, size :%u", buffer_size_in_bytes); + STONEDB_LOG(LogCtl_Level::ERROR, "Could not allocate memory for IndexTable, size :%u", buffer_size_in_bytes); throw common::OutOfMemoryException(); } std::memset(buf, 0, buffer_size_in_bytes); @@ -75,11 +75,11 @@ IndexTable::IndexTable(IndexTable &sec) m_conn(sec.m_conn) { sec.Lock(); CI_SetDefaultSize((int)max_buffer_size_in_bytes); - buf = (unsigned char *)alloc(buffer_size_in_bytes, mm::BLOCK_TEMPORARY, true); + buf = (unsigned char *)alloc(buffer_size_in_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (!buf) { sec.Unlock(); Unlock(); - STONEDB_LOG(ERROR, "Could not allocate memory for IndexTable(sec)!"); + STONEDB_LOG(LogCtl_Level::ERROR, "Could not allocate memory for IndexTable(sec)!"); throw common::OutOfMemoryException(); } int64_t used_size = size; @@ -102,9 +102,9 @@ IndexTable::~IndexTable() { void IndexTable::LoadBlock(int b) { DEBUG_ASSERT(IsLocked()); if (buf == NULL) { // possible after block caching on disk - buf = (unsigned char *)alloc(buffer_size_in_bytes, mm::BLOCK_TEMPORARY, true); + buf = (unsigned char *)alloc(buffer_size_in_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (!buf) { - STONEDB_LOG(ERROR, "Could not allocate memory for IndexTable(LoadBlock)."); + STONEDB_LOG(LogCtl_Level::ERROR, "Could not allocate memory for IndexTable(LoadBlock)."); throw common::OutOfMemoryException(); } } else if (block_changed) @@ -139,7 +139,7 @@ void IndexTable::ExpandTo(int64_t new_size) { else new_buffer_size_in_bytes = max_buffer_size_in_bytes; // TODO: check the rc_alloc status - buf = (unsigned char *)rc_realloc(buf, new_buffer_size_in_bytes, mm::BLOCK_TEMPORARY); + buf = (unsigned char *)rc_realloc(buf, new_buffer_size_in_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY); buffer_size_in_bytes = new_buffer_size_in_bytes; } // else: the table is buffered anyway, so we don't need to do anything diff --git a/storage/stonedb/core/index_table.h b/storage/stonedb/core/index_table.h index a43139ee3..79faeb78c 100644 --- a/storage/stonedb/core/index_table.h +++ b/storage/stonedb/core/index_table.h @@ -109,7 +109,7 @@ class IndexTable : private system::CacheableItem, public mm::TraceableObject { void ExpandTo(int64_t new_size); // mm::TraceableObject functionality - mm::TO_TYPE TraceableType() const override { return mm::TO_INDEXTABLE; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_INDEXTABLE; } private: void LoadBlock(int b); diff --git a/storage/stonedb/core/item_sdbfield.cpp b/storage/stonedb/core/item_sdbfield.cpp index 532d6ae21..f2c4d785b 100644 --- a/storage/stonedb/core/item_sdbfield.cpp +++ b/storage/stonedb/core/item_sdbfield.cpp @@ -65,7 +65,7 @@ void Item_sdbfield::SetType(DataType t) { sdbtype = t; switch (sdbtype.valtype) { - case DataType::VT_FIXED: + case DataType::ValueType::VT_FIXED: if (sdbtype.IsInt()) ivalue = new Item_int(static_cast(0)); else @@ -73,15 +73,15 @@ void Item_sdbfield::SetType(DataType t) { ivalue->unsigned_flag = ifield->unsigned_flag; break; - case DataType::VT_FLOAT: + case DataType::ValueType::VT_FLOAT: ivalue = new Item_float(0.0, NOT_FIXED_DEC); break; - case DataType::VT_STRING: + case DataType::ValueType::VT_STRING: ivalue = new Item_string("", 0, ifield->collation.collation, ifield->collation.derivation); break; - case DataType::VT_DATETIME: + case DataType::ValueType::VT_DATETIME: switch (sdbtype.attrtype) { case common::CT::DATETIME: ivalue = new Item_sdbdatetime(); @@ -116,22 +116,22 @@ const ValueOrNull Item_sdbfield::GetCurrentValue() { return *buf; } void Item_sdbfield::FeedValue() { switch (sdbtype.valtype) { - case DataType::VT_FIXED: + case DataType::ValueType::VT_FIXED: if (sdbtype.IsInt()) ((Item_int *)ivalue)->value = buf->Get64(); else ((Item_sdbdecimal *)ivalue)->Set(buf->Get64()); break; - case DataType::VT_FLOAT: + case DataType::ValueType::VT_FLOAT: ((Item_float *)ivalue)->value = buf->GetDouble(); break; - case DataType::VT_STRING: + case DataType::ValueType::VT_STRING: ((Item_string *)ivalue)->str_value.copy(buf->sp, buf->len, ifield->collation.collation); break; - case DataType::VT_DATETIME: + case DataType::ValueType::VT_DATETIME: ((Item_sdbdatetime_base *)ivalue)->Set(buf->Get64(), sdbtype.attrtype); break; @@ -164,7 +164,7 @@ String *Item_sdbfield::val_str(String *str) { // DBUG_ASSERT(fixed == 1); if ((null_value = buf->null)) return 0; // acceleration - if (sdbtype.valtype == DataType::VT_STRING) { + if (sdbtype.valtype == DataType::ValueType::VT_STRING) { str->copy(buf->sp, buf->len, ifield->collation.collation); return str; } diff --git a/storage/stonedb/core/item_sdbfield.h b/storage/stonedb/core/item_sdbfield.h index 1fcdd595b..5f5989d3c 100644 --- a/storage/stonedb/core/item_sdbfield.h +++ b/storage/stonedb/core/item_sdbfield.h @@ -51,12 +51,12 @@ class Item_sdbfield : public Item_field { // Implementation of MySQL Item interface static_assert(sizeof(Type) >= 2, "invalid type size"); - enum { + enum class enumSDBFiledItem { SDBFIELD_ITEM = 12345 }; // WARNING: it is risky. We are assuming sizeof(enum) >= 2 in a superclass // (Item) - static Type get_sdbitem_type() { return (Type)SDBFIELD_ITEM; } - Type type() const override { return (Type)SDBFIELD_ITEM; } + static Type get_sdbitem_type() { return (Type)enumSDBFiledItem::SDBFIELD_ITEM; } + Type type() const override { return (Type)enumSDBFiledItem::SDBFIELD_ITEM; } bool is_null() override { return buf->IsNull(); } bool is_null_result() override { return buf->IsNull(); } double val_real() override; diff --git a/storage/stonedb/core/joiner.cpp b/storage/stonedb/core/joiner.cpp index 7a78c7f95..e073982fb 100644 --- a/storage/stonedb/core/joiner.cpp +++ b/storage/stonedb/core/joiner.cpp @@ -32,7 +32,7 @@ TwoDimensionalJoiner::TwoDimensionalJoiner(MultiIndex *_mind, // multi-index to : tips(_tips), m_conn(current_tx) { mind = _mind; table = _table; - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; } TwoDimensionalJoiner::~TwoDimensionalJoiner() { @@ -40,41 +40,42 @@ TwoDimensionalJoiner::~TwoDimensionalJoiner() { } JoinAlgType TwoDimensionalJoiner::ChooseJoinAlgorithm([[maybe_unused]] MultiIndex &mind, Condition &cond) { - JoinAlgType join_alg = JTYPE_GENERAL; + JoinAlgType join_alg = JoinAlgType::JTYPE_GENERAL; - if (cond[0].IsType_JoinSimple() && cond[0].op == common::O_EQ) { + if (cond[0].IsType_JoinSimple() && cond[0].op == common::Operator::O_EQ) { if ((cond.Size() == 1) && !stonedb_sysvar_force_hashjoin) - join_alg = JTYPE_MAP; // available types checked inside + join_alg = JoinAlgType::JTYPE_MAP; // available types checked inside else - join_alg = JTYPE_HASH; + join_alg = JoinAlgType::JTYPE_HASH; } else { - if (cond[0].IsType_JoinSimple() && (cond[0].op == common::O_MORE_EQ || cond[0].op == common::O_MORE || - cond[0].op == common::O_LESS_EQ || cond[0].op == common::O_LESS)) - join_alg = JTYPE_SORT; + if (cond[0].IsType_JoinSimple() && + (cond[0].op == common::Operator::O_MORE_EQ || cond[0].op == common::Operator::O_MORE || + cond[0].op == common::Operator::O_LESS_EQ || cond[0].op == common::Operator::O_LESS)) + join_alg = JoinAlgType::JTYPE_SORT; } return join_alg; } JoinAlgType TwoDimensionalJoiner::ChooseJoinAlgorithm(JoinFailure join_result, JoinAlgType prev_type, [[maybe_unused]] size_t desc_size) { - if (join_result == FAIL_1N_TOO_HARD) return JTYPE_HASH; - if (join_result == FAIL_WRONG_SIDES) return prev_type; + if (join_result == JoinFailure::FAIL_1N_TOO_HARD) return JoinAlgType::JTYPE_HASH; + if (join_result == JoinFailure::FAIL_WRONG_SIDES) return prev_type; // the easiest strategy: in case of any problems, use general joiner - return JTYPE_GENERAL; + return JoinAlgType::JTYPE_GENERAL; } std::unique_ptr TwoDimensionalJoiner::CreateJoiner(JoinAlgType join_alg_type, MultiIndex &mind, JoinTips &tips, TempTable *table) { switch (join_alg_type) { - case JTYPE_HASH: + case JoinAlgType::JTYPE_HASH: return CreateHashJoiner(&mind, table, tips); - case JTYPE_SORT: + case JoinAlgType::JTYPE_SORT: return std::unique_ptr(new JoinerSort(&mind, table, tips)); - case JTYPE_MAP: + case JoinAlgType::JTYPE_MAP: return std::unique_ptr(stonedb_sysvar_parallel_mapjoin ? (new JoinerParallelMapped(&mind, table, tips)) : (new JoinerMapped(&mind, table, tips))); - case JTYPE_GENERAL: + case JoinAlgType::JTYPE_GENERAL: return std::unique_ptr(new JoinerGeneral(&mind, table, tips)); default: STONEDB_ERROR("Join algorithm not implemented"); diff --git a/storage/stonedb/core/joiner.h b/storage/stonedb/core/joiner.h index abab0e57b..2ab1dbbdb 100644 --- a/storage/stonedb/core/joiner.h +++ b/storage/stonedb/core/joiner.h @@ -40,13 +40,20 @@ class JoinTips { // t2.c is null" (when c is not null by default) }; -enum JoinAlgType { JTYPE_NONE, JTYPE_SORT, JTYPE_HASH, JTYPE_MIXED, JTYPE_MAP, JTYPE_GENERAL }; +enum class JoinAlgType { JTYPE_NONE, JTYPE_SORT, JTYPE_HASH, JTYPE_MIXED, JTYPE_MAP, JTYPE_GENERAL }; // MIXED - for reporting: more than one algorithm was used class TwoDimensionalJoiner { // abstract class for multiindex-based join // algorithms public: - enum JoinFailure { NOT_FAILED, FAIL_COMPLEX, FAIL_SORTER_TOO_WIDE, FAIL_1N_TOO_HARD, FAIL_HASH, FAIL_WRONG_SIDES }; + enum class JoinFailure { + NOT_FAILED, + FAIL_COMPLEX, + FAIL_SORTER_TOO_WIDE, + FAIL_1N_TOO_HARD, + FAIL_HASH, + FAIL_WRONG_SIDES + }; TwoDimensionalJoiner(MultiIndex *_mind, // multi-index to be updated TempTable *_table, JoinTips &_tips); diff --git a/storage/stonedb/core/joiner_general.cpp b/storage/stonedb/core/joiner_general.cpp index 881f3a91f..bace98060 100644 --- a/storage/stonedb/core/joiner_general.cpp +++ b/storage/stonedb/core/joiner_general.cpp @@ -74,7 +74,7 @@ void JoinerGeneral::ExecuteJoinConditions(Condition &cond) { if (mit.PackrowStarted()) { bool omit_this_packrow = false; for (int i = 0; (i < no_desc && !omit_this_packrow); i++) - if (cond[i].EvaluateRoughlyPack(mit) == common::RS_NONE) omit_this_packrow = true; + if (cond[i].EvaluateRoughlyPack(mit) == common::RSValue::RS_NONE) omit_this_packrow = true; for (int i = 0; i < no_desc; i++) pack_desc_locked[i] = false; // delay locking if (new_mind.NoMoreTuplesPossible()) break; // stop the join if nothing new may be obtained in some @@ -125,7 +125,7 @@ void JoinerGeneral::ExecuteJoinConditions(Condition &cond) { cond[i].UnlockSourcePacks(); cond[i].done = true; } - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; } void JoinerGeneral::ExecuteOuterJoinLoop(Condition &cond, MINewContents &new_mind, DimensionVector &all_dims, diff --git a/storage/stonedb/core/joiner_hash.cpp b/storage/stonedb/core/joiner_hash.cpp index b8d2d0db1..609695125 100644 --- a/storage/stonedb/core/joiner_hash.cpp +++ b/storage/stonedb/core/joiner_hash.cpp @@ -50,7 +50,7 @@ JoinerHash::JoinerHash(MultiIndex *_mind, TempTable *_table, JoinTips &_tips) void JoinerHash::ExecuteJoinConditions(Condition &cond) { MEASURE_FET("JoinerHash::ExecuteJoinConditions(...)"); - why_failed = FAIL_HASH; + why_failed = JoinFailure::FAIL_HASH; std::vector hash_descriptors; // Prepare all descriptor information @@ -60,7 +60,7 @@ void JoinerHash::ExecuteJoinConditions(Condition &cond) { DimensionVector dims_other(mind->NoDimensions()); // dimensions for other conditions, if needed for (uint i = 0; i < cond.Size(); i++) { bool added = false; - if (cond[i].IsType_JoinSimple() && cond[i].op == common::O_EQ) { + if (cond[i].IsType_JoinSimple() && cond[i].op == common::Operator::O_EQ) { if (first_found) { hash_descriptors.push_back(i); added = true; @@ -96,7 +96,7 @@ void JoinerHash::ExecuteJoinConditions(Condition &cond) { } cond_hashed = int(hash_descriptors.size()); if (cond_hashed == 0) { - why_failed = FAIL_HASH; + why_failed = JoinFailure::FAIL_HASH; return; } @@ -177,7 +177,7 @@ void JoinerHash::ExecuteJoinConditions(Condition &cond) { if (traversed_dims.Intersects(matched_dims) || // both materialized - we should rather use a simple // loop !compatible) { // could not prepare common encoding - why_failed = FAIL_HASH; + why_failed = JoinFailure::FAIL_HASH; return; } // prepare columns for traversed dimension numbers in hash table @@ -199,9 +199,9 @@ void JoinerHash::ExecuteJoinConditions(Condition &cond) { InitOuter(cond); ExecuteJoin(); if (too_many_conflicts) - why_failed = FAIL_WRONG_SIDES; + why_failed = JoinFailure::FAIL_WRONG_SIDES; else - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; } void JoinerHash::ExecuteJoin() { @@ -575,8 +575,8 @@ int64_t JoinerHash::SubmitOuterMatched(MIIterator &mit, MINewContents &new_mind) int64_t JoinerHash::NewMatchDim(MINewContents *new_mind1, MIUpdatingIterator *task_mit1, Transaction *ci, JoinerHashTable *hash_table, int *join_tuple, int stonedb_sysvar_jointhreadpool) { JoinerHashTable &tmp_jhash = *hash_table; - STONEDB_LOG(INFO, "NewMatchDim start, taskid %d, stonedb_sysvar_jointhreadpool %d", task_mit1->GetTaskId(), - stonedb_sysvar_jointhreadpool); + STONEDB_LOG(LogCtl_Level::INFO, "NewMatchDim start, taskid %d, stonedb_sysvar_jointhreadpool %d", + task_mit1->GetTaskId(), stonedb_sysvar_jointhreadpool); common::SetMySQLTHD(ci->Thd()); current_tx = ci; for (int i = 0; i < cond_hashed; i++) { @@ -673,7 +673,7 @@ int64_t JoinerHash::NewMatchDim(MINewContents *new_mind1, MIUpdatingIterator *ta types::BString local_max = vc2[i]->GetMaxString(task_mit); if (!local_min.IsNull() && !local_max.IsNull() && tmp_jhash.ImpossibleValues(i, local_min, local_max)) { omit_this_packrow = true; - STONEDB_LOG(DEBUG, "JoinerHash::test omit"); + STONEDB_LOG(LogCtl_Level::DEBUG, "JoinerHash::test omit"); break; } } @@ -719,7 +719,7 @@ int64_t JoinerHash::NewMatchDim(MINewContents *new_mind1, MIUpdatingIterator *ta } } if (no_of_matching_rows > 65536 || no_of_matching_rows < 0) - STONEDB_LOG(DEBUG, "no_of_matching_rows %d", no_of_matching_rows); + STONEDB_LOG(LogCtl_Level::DEBUG, "no_of_matching_rows %d", no_of_matching_rows); joined_tuples += no_of_matching_rows; omit_this_packrow = true; } @@ -795,7 +795,7 @@ int64_t JoinerHash::NewMatchDim(MINewContents *new_mind1, MIUpdatingIterator *ta matching_row++; } if (outer_nulls_only) joined_tuples = 0; // outer tuples added later - STONEDB_LOG(DEBUG, "JoinerHash::test %d,matching_row %d", joined_tuples, matching_row); + STONEDB_LOG(LogCtl_Level::DEBUG, "JoinerHash::test %d,matching_row %d", joined_tuples, matching_row); *join_tuple = joined_tuples; return joined_tuples; } diff --git a/storage/stonedb/core/joiner_hash_table.cpp b/storage/stonedb/core/joiner_hash_table.cpp index 76dedb091..7eec02d90 100644 --- a/storage/stonedb/core/joiner_hash_table.cpp +++ b/storage/stonedb/core/joiner_hash_table.cpp @@ -124,7 +124,7 @@ void JoinerHashTable::Initialize(int64_t max_table_size, bool easy_roughable) { rows_limit = int64_t(no_rows * 0.9); // rows_limit is used to determine whether the table is full t = (unsigned char *)alloc(((total_width / 4) * no_rows) * 4, - mm::BLOCK_TEMPORARY); // no need to cache on disk + mm::BLOCK_TYPE::BLOCK_TEMPORARY); // no need to cache on disk input_buffer.reset(new unsigned char[key_buf_width]); // initialize everything diff --git a/storage/stonedb/core/joiner_hash_table.h b/storage/stonedb/core/joiner_hash_table.h index 19b77ec75..8f0c5394b 100644 --- a/storage/stonedb/core/joiner_hash_table.h +++ b/storage/stonedb/core/joiner_hash_table.h @@ -136,7 +136,7 @@ class JoinerHashTable : public mm::TraceableObject { void ClearAll(); // initialize all - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } private: int no_of_occupied; diff --git a/storage/stonedb/core/joiner_mapped.cpp b/storage/stonedb/core/joiner_mapped.cpp index f658902e8..ae8e5a690 100644 --- a/storage/stonedb/core/joiner_mapped.cpp +++ b/storage/stonedb/core/joiner_mapped.cpp @@ -38,9 +38,9 @@ void JoinerMapped::ExecuteJoinConditions(Condition &cond) { std::vector rownums; rownums.reserve(128); - why_failed = FAIL_1N_TOO_HARD; + why_failed = JoinFailure::FAIL_1N_TOO_HARD; auto &desc(cond[0]); - if (cond.Size() > 1 || !desc.IsType_JoinSimple() || desc.op != common::O_EQ) return; + if (cond.Size() > 1 || !desc.IsType_JoinSimple() || desc.op != common::Operator::O_EQ) return; vcolumn::VirtualColumn *vc1 = desc.attr.vc; vcolumn::VirtualColumn *vc2 = desc.val1.vc; @@ -98,7 +98,7 @@ void JoinerMapped::ExecuteJoinConditions(Condition &cond) { else if (outer_join) { // outer join on keys verified as unique - a trivial // answer new_mind.CommitCountOnly(dim2_size); - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; mind->UnlockAllFromUse(); return; } @@ -199,7 +199,7 @@ void JoinerMapped::ExecuteJoinConditions(Condition &cond) { } mind->UnlockAllFromUse(); - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; } std::unique_ptr JoinerMapped::GenerateFunction(vcolumn::VirtualColumn *vc) { @@ -306,9 +306,9 @@ int64_t JoinerParallelMapped::ExecuteMatchLoop(std::shared_ptr 1 || !desc.IsType_JoinSimple() || desc.op != common::O_EQ) return; + if (cond.Size() > 1 || !desc.IsType_JoinSimple() || desc.op != common::Operator::O_EQ) return; vcolumn::VirtualColumn *vc1 = desc.attr.vc; vcolumn::VirtualColumn *vc2 = desc.val1.vc; @@ -360,7 +360,7 @@ void JoinerParallelMapped::ExecuteJoinConditions(Condition &cond) { else if (outer_join) { // outer join on keys verified as unique - a trivial // answer new_mind->CommitCountOnly(dim2_size); - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; mind->UnlockAllFromUse(); return; } @@ -412,7 +412,7 @@ void JoinerParallelMapped::ExecuteJoinConditions(Condition &cond) { } mind->UnlockAllFromUse(); - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; } void OffsetMapFunction::Fetch(int64_t key_val, std::vector &keys_value) { diff --git a/storage/stonedb/core/joiner_sort.cpp b/storage/stonedb/core/joiner_sort.cpp index ec7465aa0..ff9f375b0 100644 --- a/storage/stonedb/core/joiner_sort.cpp +++ b/storage/stonedb/core/joiner_sort.cpp @@ -29,11 +29,11 @@ JoinerSort::~JoinerSort() { delete outer_filter; } void JoinerSort::ExecuteJoinConditions(Condition &cond) { MEASURE_FET("JoinerSort::ExecuteJoinConditions(...)"); - why_failed = NOT_FAILED; + why_failed = JoinFailure::NOT_FAILED; vcolumn::VirtualColumn *vc1 = cond[0].attr.vc; vcolumn::VirtualColumn *vc2 = cond[0].val1.vc; if (vc1 == NULL || vc2 == NULL) { - why_failed = FAIL_COMPLEX; + why_failed = JoinFailure::FAIL_COMPLEX; return; } else { // Normalize: let vc1 = a smaller table DimensionVector dims1(mind->NoDimensions()); // Initial dimension descriptions @@ -46,8 +46,8 @@ void JoinerSort::ExecuteJoinConditions(Condition &cond) { vc2 = cond[0].val1.vc; } } - bool less = (cond[0].op == common::O_LESS_EQ || cond[0].op == common::O_LESS); - int sharp = ((cond[0].op == common::O_MORE || cond[0].op == common::O_LESS) + bool less = (cond[0].op == common::Operator::O_LESS_EQ || cond[0].op == common::Operator::O_LESS); + int sharp = ((cond[0].op == common::Operator::O_MORE || cond[0].op == common::Operator::O_LESS) ? 0 : 1); // std::memcmp(...) < 0 for sharp, <= 0 for not sharp @@ -65,7 +65,7 @@ void JoinerSort::ExecuteJoinConditions(Condition &cond) { if (dims1.Intersects(dims2) || // both materialized - we should rather use a simple loop !compatible) { // could not prepare common encoding - why_failed = FAIL_COMPLEX; + why_failed = JoinFailure::FAIL_COMPLEX; return; } @@ -82,7 +82,7 @@ void JoinerSort::ExecuteJoinConditions(Condition &cond) { other_cond.push_back(cond[i]); dims_used_in_cond.Plus(dims_sec); } else { - why_failed = FAIL_COMPLEX; // too complex case + why_failed = JoinFailure::FAIL_COMPLEX; // too complex case return; } } @@ -106,8 +106,8 @@ void JoinerSort::ExecuteJoinConditions(Condition &cond) { outer_filter = new Filter(mit1.NoTuples(), mit1.GetPower(), true); sort_encoder.WatchTraversed(); } else { - why_failed = FAIL_COMPLEX; // example: select ... from (t1, t2) left join - // t3 on t1.a < t2.b; + why_failed = JoinFailure::FAIL_COMPLEX; // example: select ... from (t1, t2) left join + // t3 on t1.a < t2.b; return; } outer_nulls_only = true; @@ -493,7 +493,7 @@ void JoinerSortWrapper::InitCache(int64_t no_of_rows) { int64_t max_mem_size = mm::TraceableObject::MaxBufferSize(-1); // -1, because there are two buffers if (cache_bytes * cache_size > max_mem_size) cache_size = max_mem_size / cache_bytes; } - cache = (unsigned char *)alloc(cache_bytes * cache_size, mm::BLOCK_TEMPORARY); + cache = (unsigned char *)alloc(cache_bytes * cache_size, mm::BLOCK_TYPE::BLOCK_TEMPORARY); if (cache == NULL) throw common::OutOfMemoryException(); } } diff --git a/storage/stonedb/core/joiner_sort.h b/storage/stonedb/core/joiner_sort.h index 0432184a4..8c1c8b092 100644 --- a/storage/stonedb/core/joiner_sort.h +++ b/storage/stonedb/core/joiner_sort.h @@ -82,7 +82,7 @@ class JoinerSortWrapper : public mm::TraceableObject { bool count_only); void InitCache(int64_t no_of_rows); // prepare cache table - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } int KeyBytes() { return key_bytes; } int TraverseBytes() { return traverse_bytes; } int MatchBytes() { return match_bytes; } diff --git a/storage/stonedb/core/mi_iterator.cpp b/storage/stonedb/core/mi_iterator.cpp index bc1912c97..7f40e85fa 100644 --- a/storage/stonedb/core/mi_iterator.cpp +++ b/storage/stonedb/core/mi_iterator.cpp @@ -36,7 +36,7 @@ MIIterator::MIIterator() : po(null_order) { next_pack_started = false; one_filter_dim = -1; one_filter_it = NULL; - mii_type = MII_DUMMY; + mii_type = MIIteratorType::MII_DUMMY; TaskId = 0; TasksNum = 1; } @@ -190,7 +190,7 @@ void MIIterator::swap(MIIterator &i) { } void MIIterator::Init(bool lock) { - mii_type = MII_NORMAL; + mii_type = MIIteratorType::MII_NORMAL; bool *dim_group_used = new bool[mind->dim_groups.size()]; for (uint i = 0; i < mind->dim_groups.size(); i++) dim_group_used[i] = false; for (int i = 0; i < no_dims; i++) @@ -229,8 +229,8 @@ void MIIterator::Init(bool lock) { // Create group iterators: other filter-based std::vector> ordering_filters; for (uint i = 0; i < mind->dim_groups.size(); i++) - if (dim_group_used[i] && (mind->dim_groups[i]->Type() == DimensionGroup::DG_FILTER || - mind->dim_groups[i]->Type() == DimensionGroup::DG_VIRTUAL)) // filters first + if (dim_group_used[i] && (mind->dim_groups[i]->Type() == DimensionGroup::DGType::DG_FILTER || + mind->dim_groups[i]->Type() == DimensionGroup::DGType::DG_VIRTUAL)) // filters first ordering_filters.push_back(std::pair(65537 - mind->dim_groups[i]->GetFilter(-1)->DensityWeight(), i)); // -1: the default filter for this group sort(ordering_filters.begin(), @@ -270,7 +270,7 @@ void MIIterator::Init(bool lock) { std::fill(cur_pack, cur_pack + no_dims, -1); // Check the optimized case - if (dg.size() == 1 && dg[0]->Type() == DimensionGroup::DG_FILTER) { + if (dg.size() == 1 && dg[0]->Type() == DimensionGroup::DGType::DG_FILTER) { for (int i = 0; i < no_dims; i++) if (dimensions[i]) { one_filter_dim = i; @@ -533,14 +533,14 @@ bool MIIterator::RewindToPack(const int pack) { } MIIterator::SliceCapability MIIterator::GetSliceCapability() const { - // Default is SliceCapability::kDisable. + // Default is SliceCapability::Type::kDisable. SliceCapability capability; if (one_filter_dim > -1) { - capability.type = SliceCapability::kLinear; + capability.type = SliceCapability::Type::kLinear; one_filter_it->GetSlices(&capability.slices); } else { if (dg.size() == 1) { - if (it[0]->GetSlices(&capability.slices)) capability.type = SliceCapability::kFixed; + if (it[0]->GetSlices(&capability.slices)) capability.type = SliceCapability::Type::kFixed; } } return capability; diff --git a/storage/stonedb/core/mi_iterator.h b/storage/stonedb/core/mi_iterator.h index b05d19af0..d3e54fdb7 100644 --- a/storage/stonedb/core/mi_iterator.h +++ b/storage/stonedb/core/mi_iterator.h @@ -38,7 +38,7 @@ class MIIterator { public: // The splitting capability supported by MIIterator. struct SliceCapability { - enum Type { + enum class Type { kDisable = 0, // Disable splitting into block. kLinear, // Splitting into block with pack or line, the internal iterator // is FilterOnesIterator. @@ -46,7 +46,7 @@ class MIIterator { // the internal iterator is // DimensionGroupMultiMaterialized::DGIterator. }; - Type type = kDisable; + Type type = Type::kDisable; std::vector slices; // Every element is slice size. }; @@ -73,7 +73,7 @@ class MIIterator { MIIterator(); // empty constructor: only for special cases of MIDummyIterator virtual ~MIIterator(); - enum MIIteratorType { MII_NORMAL, MII_DUMMY, MII_LOOKUP }; + enum class MIIteratorType { MII_NORMAL, MII_DUMMY, MII_LOOKUP }; /*! Get the array of row numbers for each dimension in the MultiIndex for the * current position of the iterator. @@ -338,7 +338,7 @@ class MIDummyIterator : public MIIterator { class MILookupIterator : public MIDummyIterator { public: - MILookupIterator() : MIDummyIterator(1) { mii_type = MII_LOOKUP; } + MILookupIterator() : MIDummyIterator(1) { mii_type = MIIteratorType::MII_LOOKUP; } MILookupIterator(const MILookupIterator &sec) : MIDummyIterator(sec) {} void Set(int64_t val) { MIDummyIterator::Set(0, val); } void Invalidate() { valid = false; } diff --git a/storage/stonedb/core/mi_new_contents.cpp b/storage/stonedb/core/mi_new_contents.cpp index a1fdb596d..fadbc77c9 100644 --- a/storage/stonedb/core/mi_new_contents.cpp +++ b/storage/stonedb/core/mi_new_contents.cpp @@ -42,7 +42,7 @@ MINewContents::MINewContents(MultiIndex *m, JoinTips &tips) obj = 0; roughsorter = NULL; f_opt_max_ones = 0; - content_type = MCT_UNSPECIFIED; + content_type = enumMINCType::MCT_UNSPECIFIED; max_filter_val = -1; min_block_shift = 0; pack_power = mind->NoPower(); @@ -82,7 +82,7 @@ void MINewContents::Init(int64_t initial_size) // initialize temporary structur optimized_dim_stay = -1; // filter case only if (optimized_dim_stay != -1) - content_type = MCT_FILTER_FORGET; + content_type = enumMINCType::MCT_FILTER_FORGET; else { // check for Virtual Dimension case for (int dim = 0; dim < no_dims; dim++) { @@ -97,9 +97,9 @@ void MINewContents::Init(int64_t initial_size) // initialize temporary structur } if (optimized_dim_stay != -1 && mind->GetFilter(optimized_dim_stay) == NULL) optimized_dim_stay = -1; // filter case only - if (optimized_dim_stay != -1) content_type = MCT_VIRTUAL_DIM; + if (optimized_dim_stay != -1) content_type = enumMINCType::MCT_VIRTUAL_DIM; } - if (content_type == MCT_UNSPECIFIED) content_type = MCT_MATERIAL; + if (content_type == enumMINCType::MCT_UNSPECIFIED) content_type = enumMINCType::MCT_MATERIAL; for (int dim = 0; dim < no_dims; dim++) if (dim_involved[dim]) mind->LockForGetIndex(dim); // locking for creation @@ -175,7 +175,7 @@ void MINewContents::Commit([[maybe_unused]] int64_t joined_tuples) // commit ch if (f_opt) f_opt->Commit(); // Now all involved groups must be replaced by a new contents - if (content_type == MCT_FILTER_FORGET) { // optimized version: just exchange filters + if (content_type == enumMINCType::MCT_FILTER_FORGET) { // optimized version: just exchange filters DimensionGroupFilter *nf = new DimensionGroupFilter(optimized_dim_stay, f_opt, 2, pack_power); // mode 2: pass Filter ownership to the DimensionGroup @@ -186,9 +186,9 @@ void MINewContents::Commit([[maybe_unused]] int64_t joined_tuples) // commit ch dims_to_forget[optimized_dim_stay] = false; DimensionGroupMaterialized *ng = new DimensionGroupMaterialized(dims_to_forget); // forgotten dimensions mind->dim_groups.push_back(ng); - ng->SetNoObj(1); // set a dummy size 1 for a group containing forgotten - // dimensions only - } else if (content_type == MCT_VIRTUAL_DIM) { // optimized version: virtual dimension group + ng->SetNoObj(1); // set a dummy size 1 for a group containing forgotten + // dimensions only + } else if (content_type == enumMINCType::MCT_VIRTUAL_DIM) { // optimized version: virtual dimension group DimensionGroupVirtual *nv = new DimensionGroupVirtual(dim_involved, optimized_dim_stay, f_opt, 2); // mode 2: pass Filter ownership to the DimensionGroup f_opt = NULL; @@ -246,13 +246,13 @@ void MINewContents::DisableOptimized() { delete f_opt; f_opt = NULL; optimized_dim_stay = -1; - content_type = MCT_MATERIAL; + content_type = enumMINCType::MCT_MATERIAL; } bool MINewContents::CommitPack(int pack) // in case of single filter as a result: set a pack as not // changed (return false if cannot do it) { - if (content_type != MCT_FILTER_FORGET) return false; + if (content_type != enumMINCType::MCT_FILTER_FORGET) return false; Filter *orig_filter = mind->GetFilter(optimized_dim_stay); f_opt->Commit(); if (!f_opt->IsEmpty(pack) || orig_filter == NULL) return false; @@ -264,7 +264,7 @@ void MINewContents::CommitNewTableValues() // set a value (common::NULL_VALUE_6 // object index); if the index is larger than the // current size, enlarge table automatically { - if (content_type == MCT_FILTER_FORGET) { + if (content_type == enumMINCType::MCT_FILTER_FORGET) { int64_t val = new_value[optimized_dim_stay]; if (val == common::NULL_VALUE_64 || (optimized_dim_stay != ignore_repetitions_dim && f_opt->Get(val))) { // repetition or null object found @@ -273,7 +273,7 @@ void MINewContents::CommitNewTableValues() // set a value (common::NULL_VALUE_6 return; } f_opt->Set(val); // not SetDelayed(), because we're checking repetitions by Get() - } else if (content_type == MCT_VIRTUAL_DIM) { + } else if (content_type == enumMINCType::MCT_VIRTUAL_DIM) { int64_t val = new_value[optimized_dim_stay]; if (val == common::NULL_VALUE_64 || val <= max_filter_val) { // can only forward iterate in virtual case // repetition or null object found @@ -284,7 +284,7 @@ void MINewContents::CommitNewTableValues() // set a value (common::NULL_VALUE_6 f_opt->SetDelayed(val); max_filter_val = val; // always forward } - if (content_type != MCT_FILTER_FORGET) { + if (content_type != enumMINCType::MCT_FILTER_FORGET) { if (roughsorter) roughsorter->CommitValues(new_value, obj); // analyze whether to sort roughly the current t_new contents @@ -308,7 +308,7 @@ void MINewContents::CommitNewTableValues() // set a value (common::NULL_VALUE_6 } bool MINewContents::NoMoreTuplesPossible() { - return (content_type == MCT_FILTER_FORGET || content_type == MCT_VIRTUAL_DIM) && + return (content_type == enumMINCType::MCT_FILTER_FORGET || content_type == enumMINCType::MCT_VIRTUAL_DIM) && optimized_dim_stay == ignore_repetitions_dim && f_opt->NoOnes() >= f_opt_max_ones; } } // namespace core diff --git a/storage/stonedb/core/mi_new_contents.h b/storage/stonedb/core/mi_new_contents.h index 7b364d8ae..e4dd57e24 100644 --- a/storage/stonedb/core/mi_new_contents.h +++ b/storage/stonedb/core/mi_new_contents.h @@ -31,7 +31,7 @@ class MultiIndex; // a class to store new (future) contents of multiindex class MINewContents final { public: - enum { MCT_UNSPECIFIED, MCT_MATERIAL, MCT_FILTER_FORGET, MCT_VIRTUAL_DIM } content_type; + enum class enumMINCType { MCT_UNSPECIFIED, MCT_MATERIAL, MCT_FILTER_FORGET, MCT_VIRTUAL_DIM } content_type; MINewContents(MultiIndex *m, JoinTips &tips); ~MINewContents(); @@ -57,7 +57,7 @@ class MINewContents final { // at the end, or changes will be lost void CommitCountOnly(int64_t joined_tuples); - int OptimizedCaseDimension() { return (content_type == MCT_FILTER_FORGET ? optimized_dim_stay : -1); } + int OptimizedCaseDimension() { return (content_type == enumMINCType::MCT_FILTER_FORGET ? optimized_dim_stay : -1); } private: void InitTnew(int dim, int64_t initial_size); // create t_new of proper size diff --git a/storage/stonedb/core/multi_index.cpp b/storage/stonedb/core/multi_index.cpp index 7ab54f114..42548528e 100644 --- a/storage/stonedb/core/multi_index.cpp +++ b/storage/stonedb/core/multi_index.cpp @@ -425,7 +425,7 @@ std::string MultiIndex::Display() { std::vector ind_tab_no; int it_count = 0; for (uint i = 0; i < dim_groups.size(); i++) { - if (dim_groups[i]->Type() == DimensionGroup::DG_INDEX_TABLE) { + if (dim_groups[i]->Type() == DimensionGroup::DGType::DG_INDEX_TABLE) { it_count++; ind_tab_no.push_back(it_count); // calculate a number of a materialized dim. group } else @@ -437,11 +437,11 @@ std::string MultiIndex::Display() { for (int i = 0; i < no_dimensions; i++) { if (!group_for_dim[i]->DimEnabled(i)) s += "-"; - else if (group_for_dim[i]->Type() == DimensionGroup::DG_FILTER) + else if (group_for_dim[i]->Type() == DimensionGroup::DGType::DG_FILTER) s += "f"; - else if (group_for_dim[i]->Type() == DimensionGroup::DG_INDEX_TABLE) + else if (group_for_dim[i]->Type() == DimensionGroup::DGType::DG_INDEX_TABLE) s += (ind_tab_no[group_num_for_dim[i]] > 9 ? 'T' : '0' + ind_tab_no[group_num_for_dim[i]]); - else if (group_for_dim[i]->Type() == DimensionGroup::DG_VIRTUAL) + else if (group_for_dim[i]->Type() == DimensionGroup::DGType::DG_VIRTUAL) s += (GetFilter(i) ? 'F' : 'v'); else s += "?"; diff --git a/storage/stonedb/core/mysql_expression.cpp b/storage/stonedb/core/mysql_expression.cpp index fb7151294..2249928df 100644 --- a/storage/stonedb/core/mysql_expression.cpp +++ b/storage/stonedb/core/mysql_expression.cpp @@ -46,11 +46,11 @@ MysqlExpression::MysqlExpression(Item *item, Item2VarID &item2varid) { } this->item2varid = &item2varid; - this->item = TransformTree(item, FORWARD); + this->item = TransformTree(item, TransformDirection::FORWARD); this->item2varid = NULL; } -MysqlExpression::~MysqlExpression() { TransformTree(item, BACKWARD); } +MysqlExpression::~MysqlExpression() { TransformTree(item, TransformDirection::BACKWARD); } bool MysqlExpression::HandledResultType(Item *item) { // Warning: if result type is DECIMAL and precision and/or scale greater than @@ -96,7 +96,7 @@ bool MysqlExpression::SanityAggregationCheck(Item *item, std::set &field case Item::VARBIN_ITEM: return true; - case Item_sdbfield::SDBFIELD_ITEM: + case static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM): if (has_aggregation) { if (Query::IsAggregationItem(((Item_sdbfield *)item)->OriginalItem())) *has_aggregation = true; } @@ -177,7 +177,7 @@ void MysqlExpression::RemoveUnusedVarID(Item *root) { case Item::FIELD_ITEM: case Item::SUM_FUNC_ITEM: break; - case (Item::Type)Item_sdbfield::SDBFIELD_ITEM: { + case (Item::Type)Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM: { Item_sdbfield *sdbfield = static_cast(root); sdbfield->varID.pop_back(); } break; @@ -228,7 +228,7 @@ Item *MysqlExpression::TransformTree(Item *root, TransformDirection dir) { PrintItemTree("transform tree", root); switch (static_cast(root->type())) { case Item::FIELD_ITEM: { - if (dir == BACKWARD) // already transformed (DAG case) + if (dir == TransformDirection::BACKWARD) // already transformed (DAG case) return root; // dir == FORWARD Item_sdbfield *sdbfield = GetSdbfieldItem(static_cast(root)); @@ -237,7 +237,7 @@ Item *MysqlExpression::TransformTree(Item *root, TransformDirection dir) { return sdbfield; } case Item::SUM_FUNC_ITEM: { - if (dir == BACKWARD) // already transformed (DAG case) + if (dir == TransformDirection::BACKWARD) // already transformed (DAG case) return root; // dir == FORWARD Item_sdbfield *sdbsum = GetSdbfieldItem(static_cast(root)); @@ -246,9 +246,9 @@ Item *MysqlExpression::TransformTree(Item *root, TransformDirection dir) { // (*item2varid)[aggregation]); return sdbsum; } - case (Item::Type)Item_sdbfield::SDBFIELD_ITEM: { + case (Item::Type)Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM: { Item_sdbfield *sdbfield = static_cast(root); - if (dir == FORWARD) { // already transformed (DAG case) + if (dir == TransformDirection::FORWARD) { // already transformed (DAG case) Item_field *ifield = sdbfield->OriginalItem(); // if(!(sdbfield->varID == (*item2varid)[ifield])) { // char err[256]; @@ -280,7 +280,7 @@ Item *MysqlExpression::TransformTree(Item *root, TransformDirection dir) { case Item::FUNC_ITEM: { Item_func *ifunc = static_cast(root); - if (dir == FORWARD && + if (dir == TransformDirection::FORWARD && (dynamic_cast(ifunc) || dynamic_cast(ifunc) || dynamic_cast(ifunc) || dynamic_cast(ifunc) || dynamic_cast(ifunc) || dynamic_cast(ifunc) || @@ -437,11 +437,11 @@ MysqlExpression::StringType MysqlExpression::GetStringType() { if ((item->type() != Item_sdbfield::get_sdbitem_type() && item->field_type() == MYSQL_TYPE_TIME) || (item->type() == Item_sdbfield::get_sdbitem_type() && static_cast(item)->IsAggregation() == false && item->field_type() == MYSQL_TYPE_TIME)) - return STRING_TIME; + return StringType::STRING_TIME; else - return STRING_NORMAL; + return StringType::STRING_NORMAL; } - return STRING_NOTSTRING; + return StringType::STRING_NOTSTRING; } std::shared_ptr MysqlExpression::Evaluate() { @@ -552,10 +552,12 @@ std::shared_ptr MysqlExpression::ItemInt2ValueOrNull(Item *item) { return val; } -bool SameSDBField(Item_sdbfield *const &l, Item_sdbfield *const &r) { return (!(l || r)) || (l && r && ((*l) == (*r))); } +bool SameSDBField(Item_sdbfield *const &l, Item_sdbfield *const &r) { + return (!(l || r)) || (l && r && ((*l) == (*r))); +} bool SameSDBFieldSet(MysqlExpression::sdbfields_cache_t::value_type const &l, - MysqlExpression::sdbfields_cache_t::value_type const &r) { + MysqlExpression::sdbfields_cache_t::value_type const &r) { return l.second.size() == r.second.size() && equal(l.second.begin(), l.second.end(), r.second.begin(), SameSDBField); } @@ -635,7 +637,7 @@ bool operator==(Item const &l_, Item const &r_) { } } } break; - case (Item_sdbfield::SDBFIELD_ITEM): { + case static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM): { Item_sdbfield const *l = static_cast(&l_); Item_sdbfield const *r = static_cast(&r_); same = (*l == *r); diff --git a/storage/stonedb/core/mysql_expression.h b/storage/stonedb/core/mysql_expression.h index 2b422ca12..3aa00baf6 100644 --- a/storage/stonedb/core/mysql_expression.h +++ b/storage/stonedb/core/mysql_expression.h @@ -34,13 +34,13 @@ class Item_sdbfield; class MysqlExpression { public: // map which tells how to replace Item_field's with Item_sdbfield - using Item2VarID = std::map ; - using TypOfVars = std::map; // map of types of variables - using sdbfields_cache_t = std::map> ; - using value_or_null_info_t = std::pair ; - using var_buf_t = std::map>; - using SetOfVars = std::set; // set of IDs of variables occuring in - enum StringType { STRING_NOTSTRING, STRING_TIME, STRING_NORMAL }; + using Item2VarID = std::map; + using TypOfVars = std::map; // map of types of variables + using sdbfields_cache_t = std::map>; + using value_or_null_info_t = std::pair; + using var_buf_t = std::map>; + using SetOfVars = std::set; // set of IDs of variables occuring in + enum class StringType { STRING_NOTSTRING, STRING_TIME, STRING_NORMAL }; MysqlExpression(Item *item, Item2VarID &item2varid); MysqlExpression(const MysqlExpression &) = delete; @@ -91,7 +91,7 @@ class MysqlExpression { static bool HandledFieldType(Item_result type); Item_sdbfield *GetSdbfieldItem(Item_field *); - enum TransformDirection { FORWARD, BACKWARD }; + enum class TransformDirection { FORWARD, BACKWARD }; //! Returns the root of transformed tree. New root may be different than the //! old one! diff --git a/storage/stonedb/core/pack.h b/storage/stonedb/core/pack.h index cb7b48973..81d01d559 100644 --- a/storage/stonedb/core/pack.h +++ b/storage/stonedb/core/pack.h @@ -43,7 +43,7 @@ class Pack : public mm::TraceableObject { public: virtual ~Pack() = default; - mm::TO_TYPE TraceableType() const override { return mm::TO_PACK; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_PACK; } void Release() override; virtual std::unique_ptr Clone(const PackCoordinate &pc) const = 0; diff --git a/storage/stonedb/core/pack_int.cpp b/storage/stonedb/core/pack_int.cpp index eb3589467..0b26d113c 100644 --- a/storage/stonedb/core/pack_int.cpp +++ b/storage/stonedb/core/pack_int.cpp @@ -46,7 +46,7 @@ PackInt::PackInt(const PackInt &apn, const PackCoordinate &pc) : Pack(apn, pc), data.vt = apn.data.vt; if (apn.data.vt > 0) { ASSERT(apn.data.ptr != nullptr); - data.ptr = alloc(data.vt * apn.dpn->nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * apn.dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); std::memcpy(data.ptr, apn.data.ptr, data.vt * apn.dpn->nr); } } @@ -167,7 +167,7 @@ std::unordered_map xf{ void PackInt::ExpandOrShrink(uint64_t maxv, int64_t delta) { auto new_vt = GetValueSize(maxv); if (new_vt != data.vt || delta != 0) { - auto tmp = alloc(new_vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + auto tmp = alloc(new_vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); xf[{data.vt, new_vt}](data.ptr, data.pint8 + (data.vt * dpn->nr), tmp, delta); dealloc(data.ptr); data.ptr = tmp; @@ -192,7 +192,7 @@ void PackInt::UpdateValueFloat(size_t i, const Value &v) { dpn->min_d = d; dpn->max_d = d; data.vt = 8; - data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); std::memset(data.ptr, 0, data.vt * dpn->nr); // ????? SetValD(i, d); } else { @@ -211,7 +211,7 @@ void PackInt::UpdateValueFloat(size_t i, const Value &v) { if (data.empty()) { ASSERT(dpn->Uniform()); data.vt = 8; - data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); for (uint i = 0; i < dpn->nr; i++) SetValD(i, dpn->min_d); } auto oldv = GetValDouble(i); @@ -283,7 +283,7 @@ void PackInt::UpdateValueFixed(size_t i, const Value &v) { dpn->max_i = l; data.vt = 1; - data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); // for fixed number, it is sufficient to simply zero the data std::memset(data.ptr, 0, data.vt * dpn->nr); dpn->nn--; @@ -310,7 +310,7 @@ void PackInt::UpdateValueFixed(size_t i, const Value &v) { new_vt = GetValueSize(dpn->max_i - dpn->min_i); } if (new_vt > data.vt) { - auto tmp = alloc(new_vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + auto tmp = alloc(new_vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); xf[{data.vt, new_vt}](data.ptr, data.pint8 + (data.vt * dpn->nr), tmp, delta); dealloc(data.ptr); data.ptr = tmp; @@ -324,7 +324,7 @@ void PackInt::UpdateValueFixed(size_t i, const Value &v) { if (data.empty()) { ASSERT(dpn->Uniform()); data.vt = GetValueSize(dpn->max_i - dpn->min_i); - data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); std::memset(data.ptr, 0, data.vt * dpn->nr); } auto oldv = GetValInt(i); @@ -385,14 +385,14 @@ void PackInt::LoadValuesDouble(const loader::ValueCache *vc, const std::optional if (dpn->Trivial()) { ASSERT(data.ptr == nullptr); data.vt = sizeof(double); - data.ptr = alloc(data.vt * new_nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * new_nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); if (dpn->Uniform()) { std::fill_n((double *)data.ptr, new_nr, dpn->min_d); } } else { // expanding existing pack data ASSERT(data.ptr != nullptr); - data.ptr = rc_realloc(data.ptr, data.vt * new_nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = rc_realloc(data.ptr, data.vt * new_nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); } dpn->synced = false; @@ -437,7 +437,7 @@ void PackInt::LoadValuesFixed(const loader::ValueCache *vc, const std::optional< if (dpn->Trivial()) { ASSERT(data.ptr == nullptr); - data.ptr = alloc(new_vt * new_nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(new_vt * new_nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); if (dpn->Uniform()) { switch (new_vt) { case 8: @@ -460,7 +460,7 @@ void PackInt::LoadValuesFixed(const loader::ValueCache *vc, const std::optional< } else { // expanding existing pack data ASSERT(data.ptr != nullptr); - auto tmp_ptr = alloc(new_vt * new_nr, mm::BLOCK_UNCOMPRESSED); + auto tmp_ptr = alloc(new_vt * new_nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); xf[{data.vt, new_vt}](data.ptr, data.pint8 + (data.vt * dpn->nr), tmp_ptr, delta); dealloc(data.ptr); data.ptr = tmp_ptr; @@ -504,18 +504,18 @@ void PackInt::LoadDataFromFile(system::Stream *fcurfile) { fcurfile->ReadExact(nulls.get(), NULLS_SIZE); } ASSERT(data.vt * dpn->nr != 0); - data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); fcurfile->ReadExact(data.ptr, data.vt * dpn->nr); dpn->synced = false; } else { - UniquePtr uptr = alloc_ptr(dpn->len + 1, mm::BLOCK_COMPRESSED); + UniquePtr uptr = alloc_ptr(dpn->len + 1, mm::BLOCK_TYPE::BLOCK_COMPRESSED); fcurfile->ReadExact(uptr.get(), dpn->len); dpn->synced = true; { ASSERT(!IsModeNoCompression()); uint *cur_buf = (uint *)uptr.get(); - if (data.ptr == nullptr && data.vt > 0) data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_UNCOMPRESSED); + if (data.ptr == nullptr && data.vt > 0) data.ptr = alloc(data.vt * dpn->nr, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); // decompress nulls @@ -528,10 +528,10 @@ void PackInt::LoadDataFromFile(system::Stream *fcurfile) { else { compress::BitstreamCompressor bsc; CprsErr res = bsc.Decompress((char *)nulls.get(), null_buf_size, (char *)cur_buf + 2, dpn->nr, dpn->nn); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { std::stringstream msg_buf; msg_buf << "Decompression of nulls failed for column " << (pc_column(GetCoordinate().co.pack) + 1) - << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << res << ")."; + << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << static_cast(res) << ")."; throw common::DatabaseException(msg_buf.str()); } } @@ -599,7 +599,8 @@ void PackInt::RemoveNullsAndCompress(compress::NumCompressor &nc, char *t uint64_t &maxv) { mm::MMGuard tmp_data; if (dpn->nn > 0) { - tmp_data = mm::MMGuard((etype *)(alloc((dpn->nr - dpn->nn) * sizeof(etype), mm::BLOCK_TEMPORARY)), *this); + tmp_data = mm::MMGuard( + (etype *)(alloc((dpn->nr - dpn->nn) * sizeof(etype), mm::BLOCK_TYPE::BLOCK_TEMPORARY)), *this); for (uint i = 0, d = 0; i < dpn->nr; i++) { if (!IsNull(i)) tmp_data[d++] = ((etype *)(data.ptr))[i]; } @@ -607,10 +608,10 @@ void PackInt::RemoveNullsAndCompress(compress::NumCompressor &nc, char *t tmp_data = mm::MMGuard((etype *)data.ptr, *this, false); CprsErr res = nc.Compress(tmp_comp_buffer, tmp_cb_len, tmp_data.get(), dpn->nr - dpn->nn, (etype)(maxv)); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { std::stringstream msg_buf; msg_buf << "Compression of numerical values failed for column " << (pc_column(GetCoordinate().co.pack) + 1) - << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << res << ")."; + << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << static_cast(res) << ")."; throw common::InternalException(msg_buf.str()); } } @@ -619,10 +620,10 @@ template void PackInt::DecompressAndInsertNulls(compress::NumCompressor &nc, uint *&cur_buf) { CprsErr res = nc.Decompress(data.ptr, (char *)((cur_buf + 3)), *cur_buf, dpn->nr - dpn->nn, (etype) * (uint64_t *)((cur_buf + 1))); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { std::stringstream msg_buf; msg_buf << "Decompression of numerical values failed for column " << (pc_column(GetCoordinate().co.pack) + 1) - << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << res << ")."; + << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << static_cast(res) << ")."; throw common::DatabaseException(msg_buf.str()); } etype *d = ((etype *)(data.ptr)) + dpn->nr - 1; @@ -661,25 +662,29 @@ std::pair PackInt::Compress() { compress::NumCompressor nc; tmp_cb_len = (dpn->nr - dpn->nn) * sizeof(uchar) + 20; if (tmp_cb_len) - tmp_comp_buffer = mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TEMPORARY), *this); + tmp_comp_buffer = + mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); RemoveNullsAndCompress(nc, tmp_comp_buffer.get(), tmp_cb_len, maxv); } else if (data.vt == 2) { compress::NumCompressor nc; tmp_cb_len = (dpn->nr - dpn->nn) * sizeof(ushort) + 20; if (tmp_cb_len) - tmp_comp_buffer = mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TEMPORARY), *this); + tmp_comp_buffer = + mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); RemoveNullsAndCompress(nc, tmp_comp_buffer.get(), tmp_cb_len, maxv); } else if (data.vt == 4) { compress::NumCompressor nc; tmp_cb_len = (dpn->nr - dpn->nn) * sizeof(uint) + 20; if (tmp_cb_len) - tmp_comp_buffer = mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TEMPORARY), *this); + tmp_comp_buffer = + mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); RemoveNullsAndCompress(nc, tmp_comp_buffer.get(), tmp_cb_len, maxv); } else { compress::NumCompressor nc; tmp_cb_len = (dpn->nr - dpn->nn) * sizeof(uint64_t) + 20; if (tmp_cb_len) - tmp_comp_buffer = mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TEMPORARY), *this); + tmp_comp_buffer = + mm::MMGuard((char *)alloc(tmp_cb_len * sizeof(char), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); RemoveNullsAndCompress(nc, tmp_comp_buffer.get(), tmp_cb_len, maxv); } buffer_size += tmp_cb_len; @@ -690,30 +695,31 @@ std::pair PackInt::Compress() { mm::MMGuard comp_null_buf; if (dpn->nn > 0) { - comp_null_buf = mm::MMGuard((uchar *)alloc((null_buf_size + 2) * sizeof(char), mm::BLOCK_TEMPORARY), *this); + comp_null_buf = + mm::MMGuard((uchar *)alloc((null_buf_size + 2) * sizeof(char), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); uint cnbl = null_buf_size + 1; comp_null_buf[cnbl] = 0xBA; // just checking - buffer overrun compress::BitstreamCompressor bsc; CprsErr res = bsc.Compress((char *)comp_null_buf.get(), null_buf_size, (char *)nulls.get(), dpn->nr, dpn->nn); if (comp_null_buf[cnbl] != 0xBA) { - STONEDB_LOG(ERROR, "buffer overrun by BitstreamCompressor (N f)."); + STONEDB_LOG(LogCtl_Level::ERROR, "buffer overrun by BitstreamCompressor (N f)."); ASSERT(0, "ERROR: buffer overrun by BitstreamCompressor (N f)."); } - if (res == CPRS_SUCCESS) + if (res == CprsErr::CPRS_SUCCESS) SetModeNullsCompressed(); - else if (res == CPRS_ERR_BUF) { + else if (res == CprsErr::CPRS_ERR_BUF) { comp_null_buf = mm::MMGuard((uchar *)nulls.get(), *this, false); null_buf_size = ((dpn->nr + 7) / 8); ResetModeNullsCompressed(); } else { std::stringstream msg_buf; msg_buf << "Compression of nulls failed for column " << (pc_column(GetCoordinate().co.pack) + 1) << ", pack " - << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << res << ")."; + << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << static_cast(res) << ")."; throw common::InternalException(msg_buf.str()); } buffer_size += null_buf_size + 2; } - UniquePtr ptr = alloc_ptr(buffer_size, mm::BLOCK_COMPRESSED); + UniquePtr ptr = alloc_ptr(buffer_size, mm::BLOCK_TYPE::BLOCK_COMPRESSED); uchar *compressed_buf = reinterpret_cast(ptr.get()); std::memset(compressed_buf, 0, buffer_size); cur_buf = (uint *)compressed_buf; diff --git a/storage/stonedb/core/pack_orderer.cpp b/storage/stonedb/core/pack_orderer.cpp index fc250455b..718126b73 100644 --- a/storage/stonedb/core/pack_orderer.cpp +++ b/storage/stonedb/core/pack_orderer.cpp @@ -27,7 +27,7 @@ PackOrderer::PackOrderer() { curvc = 0; ncols = 0; packs.push_back(std::vector()); - otype.push_back(NotSpecified); + otype.push_back(OrderType::NotSpecified); packs_ordered_up_to = 0; packs_passed = 0; } @@ -89,16 +89,16 @@ void PackOrderer::InitOneColumn(vcolumn::VirtualColumn *vc, OrderType ot, common ++ncols; MinMaxType mmt; if (vc->Type().IsFixed() || vc->Type().IsDateTime()) { - mmt = MMT_Fixed; + mmt = MinMaxType::MMT_Fixed; } else - mmt = MMT_String; + mmt = MinMaxType::MMT_String; mmtype.push_back(mmt); otype.push_back(ot); packs.push_back(std::vector()); lastly_left.push_back(true); - prevndx.push_back(INIT_VAL); - curndx.push_back(INIT_VAL); + prevndx.push_back(static_cast(State::INIT_VAL)); + curndx.push_back(static_cast(State::INIT_VAL)); auto &packs_one_col = packs[ncols - 1]; int d = vc->GetDim(); @@ -107,27 +107,27 @@ void PackOrderer::InitOneColumn(vcolumn::VirtualColumn *vc, OrderType ot, common MMTU mid(0); while (mit.IsValid()) { int pack = mit.GetCurPackrow(d); - if (!r_filter || r_filter[pack] != common::RS_NONE) { - if (mmt == MMT_Fixed) { + if (!r_filter || r_filter[pack] != common::RSValue::RS_NONE) { + if (mmt == MinMaxType::MMT_Fixed) { if (vc->GetNoNulls(mit) == mit.GetPackSizeLeft()) { mid.i = common::PLUS_INF_64; } else { int64_t min = vc->GetMinInt64(mit); int64_t max = vc->GetMaxInt64(mit); switch (ot) { - case RangeSimilarity: + case OrderType::RangeSimilarity: mid.i = (min == common::NULL_VALUE_64 ? common::MINUS_INF_64 : (max - min) / 2); break; - case MinAsc: - case MinDesc: - case Covering: + case OrderType::MinAsc: + case OrderType::MinDesc: + case OrderType::Covering: mid.i = min; break; - case MaxAsc: - case MaxDesc: + case OrderType::MaxAsc: + case OrderType::MaxDesc: mid.i = max; break; - case NotSpecified: + case OrderType::NotSpecified: break; } } @@ -152,25 +152,25 @@ void PackOrderer::InitOneColumn(vcolumn::VirtualColumn *vc, OrderType ot, common else natural_order.push_back(false); - if (mmt == MMT_Fixed) { + if (mmt == MinMaxType::MMT_Fixed) { switch (ot) { - case RangeSimilarity: - case MinAsc: - case MaxAsc: + case OrderType::RangeSimilarity: + case OrderType::MinAsc: + case OrderType::MaxAsc: sort(packs_one_col.begin(), packs_one_col.end(), [](const auto &v1, const auto &v2) { return v1.first.i < v2.first.i || (v1.first.i == v2.first.i && v1.second < v2.second); }); break; - case Covering: + case OrderType::Covering: ReorderForCovering(packs_one_col, vc); break; - case MinDesc: - case MaxDesc: + case OrderType::MinDesc: + case OrderType::MaxDesc: sort(packs_one_col.begin(), packs_one_col.end(), [](const auto &v1, const auto &v2) { return v1.first.i > v2.first.i || (v1.first.i == v2.first.i && v1.second < v2.second); }); break; - case NotSpecified: + case OrderType::NotSpecified: break; } } @@ -240,13 +240,13 @@ void PackOrderer::NextPack() { packs_passed++; if (natural_order[curvc]) { // natural order traversing all packs - if (curndx[curvc] < dimsize - 1 && curndx[curvc] != END) + if (curndx[curvc] < dimsize - 1 && curndx[curvc] != static_cast(State::END)) ++curndx[curvc]; else - curndx[curvc] = END; + curndx[curvc] = static_cast(State::END); } else switch (otype[curvc]) { - case RangeSimilarity: { + case OrderType::RangeSimilarity: { if (lastly_left[curvc]) { if (size_t(prevndx[curvc]) < packs[curvc].size() - 1) { lastly_left[curvc] = !lastly_left[curvc]; @@ -257,7 +257,7 @@ void PackOrderer::NextPack() { if (curndx[curvc] > 0) --curndx[curvc]; else - curndx[curvc] = END; + curndx[curvc] = static_cast(State::END); } } else if (prevndx[curvc] > 0) { lastly_left[curvc] = !lastly_left[curvc]; @@ -268,17 +268,17 @@ void PackOrderer::NextPack() { if (size_t(curndx[curvc]) < packs[curvc].size() - 1) ++curndx[curvc]; else - curndx[curvc] = END; + curndx[curvc] = static_cast(State::END); } break; } default: // go along packs from 0 to packs[curvc].size() - 1 - if (curndx[curvc] != END) { + if (curndx[curvc] != static_cast(State::END)) { if (curndx[curvc] < (int)packs[curvc].size() - 1) ++curndx[curvc]; else { - curndx[curvc] = END; + curndx[curvc] = static_cast(State::END); } } break; @@ -294,10 +294,10 @@ PackOrderer &PackOrderer::operator++() { do { NextPack(); - } while (curndx[curvc] != END && + } while (curndx[curvc] != static_cast(State::END) && visited->Get(natural_order[curvc] ? curndx[curvc] : packs[curvc][curndx[curvc]].second)); - if (curndx[curvc] != END) { + if (curndx[curvc] != static_cast(State::END)) { visited->Set(natural_order[curvc] ? curndx[curvc] : packs[curvc][curndx[curvc]].second); } } @@ -313,17 +313,17 @@ void PackOrderer::Rewind() { void PackOrderer::RewindCol() { if (!natural_order[curvc] && packs[curvc].size() == 0) - curndx[curvc] = END; + curndx[curvc] = static_cast(State::END); else - curndx[curvc] = prevndx[curvc] = INIT_VAL; + curndx[curvc] = prevndx[curvc] = static_cast(State::INIT_VAL); } void PackOrderer::RewindToMatch(vcolumn::VirtualColumn *vc, MIIterator &mit) { DEBUG_ASSERT(vc->GetDim() != -1); - DEBUG_ASSERT(otype[curvc] == RangeSimilarity); + DEBUG_ASSERT(otype[curvc] == OrderType::RangeSimilarity); DEBUG_ASSERT(ncols == 1); // not implemented otherwise - if (mmtype[curvc] == MMT_Fixed) { + if (mmtype[curvc] == MinMaxType::MMT_Fixed) { int64_t mid = common::MINUS_INF_64; if (vc->GetNoNulls(mit) != mit.GetPackSizeLeft()) { int64_t min = vc->GetMinInt64(mit); @@ -342,7 +342,7 @@ void PackOrderer::RewindToMatch(vcolumn::VirtualColumn *vc, MIIterator &mit) { // not implemented for strings & doubles/floats curndx[curvc] = 0; - if (packs[curvc].size() == 0 && !natural_order[curvc]) curndx[curvc] = END; + if (packs[curvc].size() == 0 && !natural_order[curvc]) curndx[curvc] = static_cast(State::END); prevndx[curvc] = curndx[curvc]; } } // namespace core diff --git a/storage/stonedb/core/pack_orderer.h b/storage/stonedb/core/pack_orderer.h index 705eaf068..bdc37b922 100644 --- a/storage/stonedb/core/pack_orderer.h +++ b/storage/stonedb/core/pack_orderer.h @@ -27,7 +27,7 @@ namespace stonedb { namespace core { class PackOrderer { public: - enum OrderType { + enum class OrderType { RangeSimilarity, // ... MinAsc, // ascending by pack minimum MinDesc, // descending by pack minimum @@ -37,7 +37,7 @@ class PackOrderer { // domain (MinAsc, then find the next minimally overlapping pack) NotSpecified }; - enum State { INIT_VAL = -1, END = -2 }; + enum class State { INIT_VAL = -1, END = -2 }; struct OrderStat { OrderStat(int n, int o) : neutral(n), ordered(o){}; @@ -98,7 +98,7 @@ class PackOrderer { bool NaturallyOrdered() { return packs_passed >= packs_ordered_up_to; } private: - enum MinMaxType { MMT_Fixed, MMT_Float, MMT_Double, MMT_String }; + enum class MinMaxType { MMT_Fixed, MMT_Float, MMT_Double, MMT_String }; union MMTU { int64_t i; diff --git a/storage/stonedb/core/pack_str.cpp b/storage/stonedb/core/pack_str.cpp index dda81a9f3..df2c05bb8 100644 --- a/storage/stonedb/core/pack_str.cpp +++ b/storage/stonedb/core/pack_str.cpp @@ -47,8 +47,8 @@ PackStr::PackStr(DPN *dpn, PackCoordinate pc, ColumnShare *s) : Pack(dpn, pc, s) data.len_mode = sizeof(uint16_t); try { - data.index = (char **)alloc(sizeof(char *) * (1 << s->pss), mm::BLOCK_UNCOMPRESSED); - data.lens = alloc((data.len_mode * (1 << s->pss)), mm::BLOCK_UNCOMPRESSED); + data.index = (char **)alloc(sizeof(char *) * (1 << s->pss), mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); + data.lens = alloc((data.len_mode * (1 << s->pss)), mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); std::memset(data.lens, 0, data.len_mode * (1 << s->pss)); if (!dpn->NullOnly()) { @@ -66,12 +66,12 @@ PackStr::PackStr(DPN *dpn, PackCoordinate pc, ColumnShare *s) : Pack(dpn, pc, s) PackStr::PackStr(const PackStr &aps, const PackCoordinate &pc) : Pack(aps, pc) { try { data.len_mode = aps.data.len_mode; - data.lens = alloc((data.len_mode * (1 << s->pss)), mm::BLOCK_UNCOMPRESSED); + data.lens = alloc((data.len_mode * (1 << s->pss)), mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); std::memset(data.lens, 0, data.len_mode * (1 << s->pss)); - data.index = (char **)alloc(sizeof(char *) * (1 << s->pss), mm::BLOCK_UNCOMPRESSED); + data.index = (char **)alloc(sizeof(char *) * (1 << s->pss), mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); data.sum_len = aps.data.sum_len; - data.v.push_back({(char *)alloc(data.sum_len + 1, mm::BLOCK_UNCOMPRESSED), data.sum_len, 0}); + data.v.push_back({(char *)alloc(data.sum_len + 1, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), data.sum_len, 0}); for (uint i = 0; i < aps.dpn->nr; i++) { if (aps.IsNull(i)) { @@ -109,7 +109,7 @@ void PackStr::LoadDataFromFile(system::Stream *f) { } void PackStr::Destroy() { - if (state_ == PACK_ARRAY) { + if (state_ == PackStrtate::PACK_ARRAY) { for (auto &it : data.v) { dealloc(it.ptr); } @@ -150,11 +150,11 @@ size_t PackStr::CalculateMaxLen() const { } void PackStr::TransformIntoArray() { - if (state_ == PACK_ARRAY) return; - data.lens = alloc((data.len_mode * (1 << s->pss)), mm::BLOCK_UNCOMPRESSED); - data.index = (char **)alloc(sizeof(char *) * (1 << s->pss), mm::BLOCK_UNCOMPRESSED); + if (state_ == PackStrtate::PACK_ARRAY) return; + data.lens = alloc((data.len_mode * (1 << s->pss)), mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); + data.index = (char **)alloc(sizeof(char *) * (1 << s->pss), mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED); - data.v.push_back({(char *)alloc(data.sum_len + 1, mm::BLOCK_UNCOMPRESSED), data.sum_len, 0}); + data.v.push_back({(char *)alloc(data.sum_len + 1, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), data.sum_len, 0}); for (uint i = 0; i < dpn->nr; i++) { if (IsNull(i)) { @@ -169,7 +169,7 @@ void PackStr::TransformIntoArray() { SetPtrSize(i, nullptr, 0); } } - state_ = PACK_ARRAY; + state_ = PackStrtate::PACK_ARRAY; } void PackStr::UpdateValue(size_t i, const Value &v) { @@ -230,7 +230,7 @@ void PackStr::UpdateValue(size_t i, const Value &v) { void PackStr::LoadValues(const loader::ValueCache *vc) { dpn->synced = false; auto sz = vc->SumarizedSize(); - data.v.push_back({(char *)alloc(sz, mm::BLOCK_UNCOMPRESSED), sz, 0}); + data.v.push_back({(char *)alloc(sz, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), sz, 0}); auto total = vc->NoValues(); @@ -288,7 +288,7 @@ std::pair PackStr::Compress() { mm::MMGuard comp_null_buf; if (dpn->nn > 0) { comp_null_buf_size = ((dpn->nr + 7) / 8); - comp_null_buf = mm::MMGuard((char *)alloc((comp_null_buf_size + 2), mm::BLOCK_TEMPORARY), *this); + comp_null_buf = mm::MMGuard((char *)alloc((comp_null_buf_size + 2), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); uint cnbl = comp_null_buf_size + 1; comp_null_buf[cnbl] = 0xBA; // just checking - buffer overrun @@ -298,20 +298,21 @@ std::pair PackStr::Compress() { if (comp_null_buf[cnbl] != char(0xBA)) { STONEDB_ERROR("buffer overrun by BitstreamCompressor!"); } - if (res == CPRS_SUCCESS) + if (res == CprsErr::CPRS_SUCCESS) SetModeNullsCompressed(); - else if (res == CPRS_ERR_BUF) { + else if (res == CprsErr::CPRS_ERR_BUF) { comp_null_buf = mm::MMGuard((char *)nulls.get(), *this, false); comp_null_buf_size = ((dpn->nr + 7) / 8); ResetModeNullsCompressed(); } else { - throw common::InternalException( - "Compression of nulls failed for column " + std::to_string(pc_column(GetCoordinate().co.pack) + 1) + - ", pack " + std::to_string(pc_dp(GetCoordinate().co.pack) + 1) + " (error " + std::to_string(res) + ")."); + throw common::InternalException("Compression of nulls failed for column " + + std::to_string(pc_column(GetCoordinate().co.pack) + 1) + ", pack " + + std::to_string(pc_dp(GetCoordinate().co.pack) + 1) + " (error " + + std::to_string(static_cast(res)) + ")."); } } - mm::MMGuard nc_buffer((uint *)alloc((1 << s->pss) * sizeof(uint32_t), mm::BLOCK_TEMPORARY), *this); + mm::MMGuard nc_buffer((uint *)alloc((1 << s->pss) * sizeof(uint32_t), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); int onn = 0; uint maxv = 0; @@ -329,20 +330,21 @@ std::pair PackStr::Compress() { if (maxv != 0) { comp_len_buf_size = onn * sizeof(uint) + 28; - comp_len_buf = mm::MMGuard((uint *)alloc(comp_len_buf_size / 4 * sizeof(uint), mm::BLOCK_TEMPORARY), *this); + comp_len_buf = + mm::MMGuard((uint *)alloc(comp_len_buf_size / 4 * sizeof(uint), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); uint tmp_comp_len_buf_size = comp_len_buf_size - 8; compress::NumCompressor nc; CprsErr res = nc.Compress((char *)(comp_len_buf.get() + 2), tmp_comp_len_buf_size, nc_buffer.get(), onn, maxv); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { throw common::InternalException("Compression of lengths of values failed for column " + std::to_string(pc_column(GetCoordinate().co.pack) + 1) + ", pack " + std::to_string(pc_dp(GetCoordinate().co.pack) + 1) + " error " + - std::to_string(res)); + std::to_string(static_cast(res))); } comp_len_buf_size = tmp_comp_len_buf_size + 8; } else { comp_len_buf_size = 8; - comp_len_buf = mm::MMGuard((uint *)alloc(sizeof(uint) * 2, mm::BLOCK_TEMPORARY), *this); + comp_len_buf = mm::MMGuard((uint *)alloc(sizeof(uint) * 2, mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); } *comp_len_buf.get() = comp_len_buf_size; @@ -355,13 +357,13 @@ std::pair PackStr::Compress() { auto dlen = GetCompressBufferSize(data.sum_len); - mm::MMGuard comp_buf((char *)alloc(dlen, mm::BLOCK_TEMPORARY), *this); + mm::MMGuard comp_buf((char *)alloc(dlen, mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); if (data.sum_len) { int objs = (dpn->nr - dpn->nn) - zlo; - mm::MMGuard tmp_index((char **)alloc(objs * sizeof(char *), mm::BLOCK_TEMPORARY), *this); - mm::MMGuard tmp_len((uint *)alloc(objs * sizeof(uint), mm::BLOCK_TEMPORARY), *this); + mm::MMGuard tmp_index((char **)alloc(objs * sizeof(char *), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); + mm::MMGuard tmp_len((uint *)alloc(objs * sizeof(uint), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); int nid = 0; uint packlen = 0; @@ -375,10 +377,10 @@ std::pair PackStr::Compress() { CprsErr res = tc.Compress(comp_buf.get(), dlen, tmp_index.get(), tmp_len.get(), objs, packlen, static_cast(s->ColType().GetFmt())); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { std::stringstream msg_buf; msg_buf << "Compression of string values failed for column " << (pc_column(GetCoordinate().co.pack) + 1) - << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << res << ")."; + << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << static_cast(res) << ")."; throw common::InternalException(msg_buf.str()); } @@ -387,7 +389,7 @@ std::pair PackStr::Compress() { } size_t comp_buf_size = (comp_null_buf_size > 0 ? 2 + comp_null_buf_size : 0) + comp_len_buf_size + 4 + 4 + dlen; - UniquePtr compressed_buf = alloc_ptr(comp_buf_size, mm::BLOCK_COMPRESSED); + UniquePtr compressed_buf = alloc_ptr(comp_buf_size, mm::BLOCK_TYPE::BLOCK_COMPRESSED); uchar *p = reinterpret_cast(compressed_buf.get()); if (dpn->nn > 0) { @@ -413,7 +415,7 @@ std::pair PackStr::Compress() { } void PackStr::CompressTrie() { - DEBUG_ASSERT(state_ == PACK_ARRAY); + DEBUG_ASSERT(state_ == PackStrtate::PACK_ARRAY); marisa::Keyset keyset; std::size_t sum_len = 0; for (uint row = 0; row < dpn->nr; row++) { @@ -428,7 +430,7 @@ void PackStr::CompressTrie() { dpn->len = bufsz; std::ostringstream oss; oss << marisa_trie_; - compressed_data_ = alloc_ptr(bufsz, mm::BLOCK_TEMPORARY); + compressed_data_ = alloc_ptr(bufsz, mm::BLOCK_TYPE::BLOCK_TEMPORARY); char *buf_ptr = (char *)compressed_data_.get(); std::memcpy(buf_ptr, oss.str().data(), oss.str().length()); buf_ptr += oss.str().length(); @@ -453,14 +455,14 @@ void PackStr::CompressTrie() { dealloc(it.ptr); } data.v.clear(); - state_ = PACK_TRIE; + state_ = PackStrtate::PACK_TRIE; } void PackStr::Save() { UniquePtr compressed_buf; if (!ShouldNotCompress()) { if (data.sum_len > common::MAX_CMPR_SIZE) { - STONEDB_LOG(WARN, + STONEDB_LOG(LogCtl_Level::WARN, "pack (%d-%d-%d) size %ld exceeds supported compression " "size, will not be compressed!", pc_table(GetCoordinate().co.pack), pc_column(GetCoordinate().co.pack), pc_dp(GetCoordinate().co.pack), @@ -483,7 +485,7 @@ void PackStr::Save() { f.OpenCreate(s->DataFile()); f.Seek(dpn->addr, SEEK_SET); if (IsModeCompressionApplied()) { - if (state_ == PACK_TRIE) { + if (state_ == PackStrtate::PACK_TRIE) { f.WriteExact(compressed_data_.get(), dpn->len); } else { f.WriteExact(compressed_buf.get(), dpn->len); @@ -518,7 +520,7 @@ void PackStr::SaveUncompressed(system::Stream *f) { void PackStr::LoadCompressed(system::Stream *f) { ASSERT(IsModeCompressionApplied()); - auto compressed_buf = alloc_ptr(dpn->len + 1, mm::BLOCK_COMPRESSED); + auto compressed_buf = alloc_ptr(dpn->len + 1, mm::BLOCK_TYPE::BLOCK_COMPRESSED); f->ReadExact(compressed_buf.get(), dpn->len); dpn->synced = true; @@ -528,7 +530,7 @@ void PackStr::LoadCompressed(system::Stream *f) { //} // uncompress the data - mm::MMGuard tmp_index((char **)alloc(dpn->nr * sizeof(char *), mm::BLOCK_TEMPORARY), *this); + mm::MMGuard tmp_index((char **)alloc(dpn->nr * sizeof(char *), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); char *cur_buf = reinterpret_cast(compressed_buf.get()); @@ -542,10 +544,11 @@ void PackStr::LoadCompressed(system::Stream *f) { else { compress::BitstreamCompressor bsc; CprsErr res = bsc.Decompress((char *)nulls.get(), null_buf_size, cur_buf + 2, dpn->nr, dpn->nn); - if (res != CPRS_SUCCESS) { - throw common::DatabaseException( - "Decompression of nulls failed for column " + std::to_string(pc_column(GetCoordinate().co.pack) + 1) + - ", pack " + std::to_string(pc_dp(GetCoordinate().co.pack) + 1) + " (error " + std::to_string(res) + ")."); + if (res != CprsErr::CPRS_SUCCESS) { + throw common::DatabaseException("Decompression of nulls failed for column " + + std::to_string(pc_column(GetCoordinate().co.pack) + 1) + ", pack " + + std::to_string(pc_dp(GetCoordinate().co.pack) + 1) + " (error " + + std::to_string(static_cast(res)) + ")."); } } cur_buf += (null_buf_size + 2); @@ -564,13 +567,13 @@ void PackStr::LoadCompressed(system::Stream *f) { if (maxv != 0) { compress::NumCompressor nc; - mm::MMGuard cn_ptr((uint *)alloc((1 << s->pss) * sizeof(uint), mm::BLOCK_TEMPORARY), *this); + mm::MMGuard cn_ptr((uint *)alloc((1 << s->pss) * sizeof(uint), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); CprsErr res = nc.Decompress(cn_ptr.get(), (char *)(cur_buf + 8), comp_len_buf_size - 8, dpn->nr - dpn->nn, maxv); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { std::stringstream msg_buf; msg_buf << "Decompression of lengths of std::string values failed for column " << (pc_column(GetCoordinate().co.pack) + 1) << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) - << " (error " << res << ")."; + << " (error " << static_cast(res) << ")."; throw common::DatabaseException(msg_buf.str()); } @@ -597,19 +600,19 @@ void PackStr::LoadCompressed(system::Stream *f) { int objs = dpn->nr - dpn->nn - zlo; if (objs) { - mm::MMGuard tmp_len((uint *)alloc(objs * sizeof(uint), mm::BLOCK_TEMPORARY), *this); + mm::MMGuard tmp_len((uint *)alloc(objs * sizeof(uint), mm::BLOCK_TYPE::BLOCK_TEMPORARY), *this); for (uint tmp_id = 0, id = 0; id < dpn->nr; id++) if (!IsNull(id) && GetSize(id) != 0) tmp_len[tmp_id++] = GetSize(id); if (dlen) { - data.v.push_back({(char *)alloc(data.sum_len, mm::BLOCK_UNCOMPRESSED), data.sum_len, 0}); + data.v.push_back({(char *)alloc(data.sum_len, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), data.sum_len, 0}); compress::TextCompressor tc; CprsErr res = tc.Decompress(data.v.front().ptr, data.sum_len, cur_buf, dlen, tmp_index.get(), tmp_len.get(), objs); - if (res != CPRS_SUCCESS) { + if (res != CprsErr::CPRS_SUCCESS) { std::stringstream msg_buf; msg_buf << "Decompression of std::string values failed for column " << (pc_column(GetCoordinate().co.pack) + 1) - << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << res << ")."; + << ", pack " << (pc_dp(GetCoordinate().co.pack) + 1) << " (error " << static_cast(res) << ")."; throw common::DatabaseException(msg_buf.str()); } } @@ -628,7 +631,7 @@ void PackStr::LoadCompressed(system::Stream *f) { void PackStr::LoadCompressedTrie(system::Stream *f) { ASSERT(IsModeCompressionApplied()); - compressed_data_ = alloc_ptr(dpn->len + 1, mm::BLOCK_COMPRESSED); + compressed_data_ = alloc_ptr(dpn->len + 1, mm::BLOCK_TYPE::BLOCK_COMPRESSED); f->ReadExact(compressed_data_.get(), dpn->len); auto trie_length = dpn->len - (dpn->nr * sizeof(unsigned short)) - 8; marisa_trie_.map(compressed_data_.get(), trie_length); @@ -641,7 +644,7 @@ void PackStr::LoadCompressedTrie(system::Stream *f) { if (ids_array_[row] == 0xffff) SetNull(row); } } - state_ = PACK_TRIE; + state_ = PackStrtate::PACK_TRIE; } types::BString PackStr::GetStringValueTrie(int ono) const { @@ -655,7 +658,7 @@ types::BString PackStr::GetStringValueTrie(int ono) const { types::BString PackStr::GetValueBinary(int ono) const { if (IsNull(ono)) return types::BString(); DEBUG_ASSERT(ono < (int)dpn->nr); - if (state_ == PACK_TRIE) return GetStringValueTrie(ono); + if (state_ == PackStrtate::PACK_TRIE) return GetStringValueTrie(ono); size_t str_size; if (data.len_mode == sizeof(ushort)) str_size = data.lens16[ono]; @@ -672,7 +675,7 @@ void PackStr::LoadUncompressed(system::Stream *f) { f->ReadExact(data.lens, (data.len_mode * (1 << s->pss))); sz -= (data.len_mode * (1 << s->pss)); - data.v.push_back({(char *)alloc(sz + 1, mm::BLOCK_UNCOMPRESSED), sz, 0}); + data.v.push_back({(char *)alloc(sz + 1, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), sz, 0}); f->ReadExact(data.v.back().ptr, sz); data.v.back().pos = sz; data.sum_len = 0; diff --git a/storage/stonedb/core/pack_str.h b/storage/stonedb/core/pack_str.h index 821dd9ea6..f29971dc5 100644 --- a/storage/stonedb/core/pack_str.h +++ b/storage/stonedb/core/pack_str.h @@ -48,7 +48,7 @@ class PackStr final : public Pack { types::BString GetValueBinary(int i) const override; void LoadValues(const loader::ValueCache *vc); - bool IsTrie() const { return state_ == PACK_TRIE; } + bool IsTrie() const { return state_ == PackStrtate::PACK_TRIE; } bool Lookup(const types::BString &pattern, uint16_t &id); bool LikePrefix(const types::BString &pattern, std::size_t prefixlen, std::unordered_set &ids); bool IsNotMatched(int row, uint16_t &id); @@ -115,8 +115,8 @@ class PackStr final : public Pack { SetSize(i, size); } - enum PackStrtate { PACK_ARRAY, PACK_TRIE }; - PackStrtate state_ = PACK_ARRAY; + enum class PackStrtate { PACK_ARRAY, PACK_TRIE }; + PackStrtate state_ = PackStrtate::PACK_ARRAY; marisa::Trie marisa_trie_; UniquePtr compressed_data_; uint16_t *ids_array_; @@ -135,7 +135,7 @@ class PackStr final : public Pack { void *Put(const void *src, size_t length) { if (data.v.empty() || length > data.v.back().capacity()) { auto sz = length * 2; - data.v.push_back({(char *)alloc(sz, mm::BLOCK_UNCOMPRESSED), sz, 0}); + data.v.push_back({(char *)alloc(sz, mm::BLOCK_TYPE::BLOCK_UNCOMPRESSED), sz, 0}); } return data.v.back().put(src, length); } diff --git a/storage/stonedb/core/parallel_hash_join.cpp b/storage/stonedb/core/parallel_hash_join.cpp index ab34f652c..4c4c10df6 100644 --- a/storage/stonedb/core/parallel_hash_join.cpp +++ b/storage/stonedb/core/parallel_hash_join.cpp @@ -228,13 +228,13 @@ void ParallelHashJoiner::ExecuteJoinConditions(Condition &cond) { if (PrepareBeforeJoin(cond)) ExecuteJoin(); - why_failed = too_many_conflicts_ ? FAIL_WRONG_SIDES : NOT_FAILED; + why_failed = too_many_conflicts_ ? JoinFailure::FAIL_WRONG_SIDES : JoinFailure::NOT_FAILED; } void ParallelHashJoiner::ForceSwitchingSides() { force_switching_sides_ = true; } bool ParallelHashJoiner::PrepareBeforeJoin(Condition &cond) { - why_failed = FAIL_HASH; + why_failed = JoinFailure::FAIL_HASH; std::vector hash_descriptors; // Prepare all descriptor information @@ -244,7 +244,7 @@ bool ParallelHashJoiner::PrepareBeforeJoin(Condition &cond) { DimensionVector dims_other(mind->NoDimensions()); // dimensions for other conditions, if needed for (uint i = 0; i < cond.Size(); i++) { bool added = false; - if (cond[i].IsType_JoinSimple() && cond[i].op == common::O_EQ) { + if (cond[i].IsType_JoinSimple() && cond[i].op == common::Operator::O_EQ) { if (first_found) { hash_descriptors.push_back(i); added = true; @@ -280,7 +280,7 @@ bool ParallelHashJoiner::PrepareBeforeJoin(Condition &cond) { } cond_hashed_ = int(hash_descriptors.size()); if (cond_hashed_ == 0) { - why_failed = FAIL_HASH; + why_failed = JoinFailure::FAIL_HASH; return false; } /* @@ -354,7 +354,7 @@ bool ParallelHashJoiner::PrepareBeforeJoin(Condition &cond) { if (traversed_dims_.Intersects(matched_dims_) || !compatible) { // both materialized - we should rather use a simple loop // could not prepare common encoding - why_failed = FAIL_HASH; + why_failed = JoinFailure::FAIL_HASH; return false; } // prepare columns for traversed dimension numbers in hash table @@ -476,7 +476,7 @@ int64_t ParallelHashJoiner::TraverseDim(MIIterator &mit, int64_t *outer_tuples) std::string splitting_type("none"); std::vector task_iterators; MIIterator::SliceCapability slice_capability = mit.GetSliceCapability(); - if (slice_capability.type == MIIterator::SliceCapability::kFixed) { + if (slice_capability.type == MIIterator::SliceCapability::Type::kFixed) { DEBUG_ASSERT(!slice_capability.slices.empty()); splitting_type = "fixed"; size_t slices_size = slice_capability.slices.size(); @@ -487,7 +487,7 @@ int64_t ParallelHashJoiner::TraverseDim(MIIterator &mit, int64_t *outer_tuples) rows_started += slice_capability.slices[index]; task_iterators.push_back(iter); } - } else if ((slice_capability.type == MIIterator::SliceCapability::kLinear) && + } else if ((slice_capability.type == MIIterator::SliceCapability::Type::kLinear) && (availabled_packs > kTraversedPacksPerFragment * 2)) { int64_t origin_size = rows_count; for (int index = 0; index < mind->NoDimensions(); index++) { @@ -556,10 +556,10 @@ int64_t ParallelHashJoiner::TraverseDim(MIIterator &mit, int64_t *outer_tuples) traversed_rows += res.get(i); } catch (std::exception &e) { no_except = false; - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { no_except = false; - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } if (!no_except) { throw common::Exception("Parallel hash join failed."); @@ -676,11 +676,11 @@ bool ParallelHashJoiner::CreateMatchingTasks(MIIterator &mit, int64_t rows_count MIIterator::SliceCapability slice_capability = mit.GetSliceCapability(); for (auto &j : other_cond_) { if (j.IsType_Subquery()) { - slice_capability.type = MIIterator::SliceCapability::kDisable; + slice_capability.type = MIIterator::SliceCapability::Type::kDisable; break; } } - if (slice_capability.type == MIIterator::SliceCapability::kFixed) { + if (slice_capability.type == MIIterator::SliceCapability::Type::kFixed) { DEBUG_ASSERT(!slice_capability.slices.empty()); size_t slices_size = slice_capability.slices.size(); int64_t rows_started = 0; @@ -691,7 +691,7 @@ bool ParallelHashJoiner::CreateMatchingTasks(MIIterator &mit, int64_t rows_count task_iterators->push_back(iter); } *splitting_type = "fixed"; - } else if (slice_capability.type == MIIterator::SliceCapability::kLinear) { + } else if (slice_capability.type == MIIterator::SliceCapability::Type::kLinear) { int packs_count = (int)((rows_count + (1 << pack_power_) - 1) >> pack_power_); for (int index = 0; index < mind->NoDimensions(); index++) { if (matched_dims_[index]) { @@ -792,10 +792,10 @@ int64_t ParallelHashJoiner::MatchDim(MIIterator &mit) { matched_rows += res.get(i); } catch (std::exception &e) { no_except = false; - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { no_except = false; - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } if (!no_except) { throw common::Exception("Parallel hash join failed."); diff --git a/storage/stonedb/core/parameterized_filter.cpp b/storage/stonedb/core/parameterized_filter.cpp index 5d9b4da2e..c5a77c6eb 100644 --- a/storage/stonedb/core/parameterized_filter.cpp +++ b/storage/stonedb/core/parameterized_filter.cpp @@ -106,13 +106,13 @@ void ParameterizedFilter::PrepareRoughMultiIndex() { Filter *f = mind->GetFilter(d); for (int p = 0; p < rough_mind->NoPacks(d); p++) { if (f == NULL) - rough_mind->SetPackStatus(d, p, common::RS_UNKNOWN); + rough_mind->SetPackStatus(d, p, common::RSValue::RS_UNKNOWN); else if (f->IsFull(p)) - rough_mind->SetPackStatus(d, p, common::RS_ALL); + rough_mind->SetPackStatus(d, p, common::RSValue::RS_ALL); else if (f->IsEmpty(p)) - rough_mind->SetPackStatus(d, p, common::RS_NONE); + rough_mind->SetPackStatus(d, p, common::RSValue::RS_NONE); else - rough_mind->SetPackStatus(d, p, common::RS_SOME); + rough_mind->SetPackStatus(d, p, common::RSValue::RS_SOME); } } } @@ -138,7 +138,7 @@ double ParameterizedFilter::EvaluateConditionNonJoinWeight(Descriptor &d, bool f answer_size = col->ApproxAnswerSize(d); if (for_or) answer_size = d.attr.vc->NoTuples() - answer_size; int64_t no_in_values = 1; - if (d.op == common::O_IN || d.op == common::O_NOT_IN) { + if (d.op == common::Operator::O_IN || d.op == common::Operator::O_NOT_IN) { vcolumn::MultiValColumn *iscol = static_cast(d.val1.vc); MIIterator mitor(NULL, d.table->Getpackpower()); no_in_values = iscol->NoValues(mitor); @@ -146,9 +146,10 @@ double ParameterizedFilter::EvaluateConditionNonJoinWeight(Descriptor &d, bool f eval = log(1 + double(answer_size)); // approximate size of the result if (no_in_values > 1) eval += log(double(no_in_values)) * 0.5; // INs are potentially slower (many comparisons needed) - if (col->Type().IsString() && !col->Type().IsLookup()) eval += 0.5; // strings are slower - if (col->Type().IsFloat()) eval += 0.1; // floats are slower - if (d.op == common::O_LIKE || d.op == common::O_NOT_LIKE) eval += 0.2; // these operators need more work + if (col->Type().IsString() && !col->Type().IsLookup()) eval += 0.5; // strings are slower + if (col->Type().IsFloat()) eval += 0.1; // floats are slower + if (d.op == common::Operator::O_LIKE || d.op == common::Operator::O_NOT_LIKE) + eval += 0.2; // these operators need more work // Processing descriptor on PK firstly if (d.IsleftIndexSearch()) eval = 0.001; @@ -158,7 +159,7 @@ double ParameterizedFilter::EvaluateConditionNonJoinWeight(Descriptor &d, bool f // logarithm for common::NULL_VALUE_64 if (!d.encoded) return log(1 + double(2 * no_obj)) + 5; // +5 as a penalty for complex expression - else if (d.op == common::O_EQ) { + else if (d.op == common::Operator::O_EQ) { no_distinct = d.attr.vc->GetApproxDistVals(false); if (no_distinct == 0) no_distinct = 1; no_distinct2 = d.val1.vc->GetApproxDistVals(false); @@ -212,7 +213,7 @@ double ParameterizedFilter::EvaluateConditionJoinWeight(Descriptor &d) { double c_select2 = double(no_obj2) / mind->OrigSize(dim2); double bigger_table_size = (double)std::max(no_obj1, no_obj2); - if (d.op == common::O_EQ) { + if (d.op == common::Operator::O_EQ) { no_distinct1 = d.attr.vc->GetApproxDistVals(false); no_distinct2 = d.val1.vc->GetApproxDistVals(false); if (no_distinct1 >= 0.99 * mind->DimSize(dim1)) { // potentially 1:n join @@ -278,7 +279,7 @@ bool ParameterizedFilter::RoughUpdateMultiIndex() { } for (uint i = 0; i < descriptors.Size(); i++) { if (!descriptors[i].done && !descriptors[i].IsDelayed() && descriptors[i].IsInner() && - descriptors[i].GetJoinType() == DT_NON_JOIN) { + descriptors[i].GetJoinType() == DescriptorJoinType::DT_NON_JOIN) { DimensionVector dims(mind->NoDimensions()); descriptors[i].DimensionUsed(dims); int dim = dims.GetOneDim(); @@ -289,7 +290,7 @@ bool ParameterizedFilter::RoughUpdateMultiIndex() { MIIterator mit(mind, dim, true); while (mit.IsValid()) { int p = mit.GetCurPackrow(dim); - if (p >= 0 && rf[p] != common::RS_NONE) + if (p >= 0 && rf[p] != common::RSValue::RS_NONE) rf[p] = descriptors[i].EvaluateRoughlyPack(mit); // rough values are also accumulated inside mit.NextPackrow(); if (mind->m_conn->Killed()) throw common::KilledException(); @@ -318,9 +319,9 @@ bool ParameterizedFilter::RoughUpdateMultiIndex() { pack_some = 0; pack_all = rough_mind->NoPacks(dim); for (int b = 0; b < pack_all; b++) { - if (rough_mind->GetPackStatus(dim, b) == common::RS_ALL) + if (rough_mind->GetPackStatus(dim, b) == common::RSValue::RS_ALL) pack_full++; - else if (rough_mind->GetPackStatus(dim, b) != common::RS_NONE) + else if (rough_mind->GetPackStatus(dim, b) != common::RSValue::RS_NONE) pack_some++; } @@ -344,7 +345,7 @@ bool ParameterizedFilter::PropagateRoughToMind() { Filter *f = mind->GetUpdatableFilter(i); if (f) { for (int b = 0; b < rough_mind->NoPacks(i); b++) { - if (rough_mind->GetPackStatus(i, b) == common::RS_NONE) f->ResetBlock(b); + if (rough_mind->GetPackStatus(i, b) == common::RSValue::RS_NONE) f->ResetBlock(b); } if (f->IsEmpty()) is_nonempty = false; } @@ -372,9 +373,9 @@ void ParameterizedFilter::RoughUpdateJoins() { } } if (join_or_delayed_present) - rough_mind->MakeDimensionSuspect(); // no common::RS_ALL packs + rough_mind->MakeDimensionSuspect(); // no common::RSValue::RS_ALL packs else if (dims_to_be_suspect.size()) { - for (auto &it : dims_to_be_suspect) rough_mind->MakeDimensionSuspect(it); // no common::RS_ALL packs + for (auto &it : dims_to_be_suspect) rough_mind->MakeDimensionSuspect(it); // no common::RSValue::RS_ALL packs } } @@ -414,16 +415,16 @@ void ParameterizedFilter::RoughMakeProjections(int to_dim, bool update_reduced) vcolumn::VirtualColumn *matched_vc; MIDummyIterator local_mit(mind); if (dim1 == ld.attr.vc->GetDim()) { - po.Init(ld.attr.vc, PackOrderer::RangeSimilarity, rough_mind->GetRSValueTable(ld.attr.vc->GetDim())); + po.Init(ld.attr.vc, PackOrderer::OrderType::RangeSimilarity, rough_mind->GetRSValueTable(ld.attr.vc->GetDim())); matched_vc = ld.val1.vc; } else { - po.Init(ld.val1.vc, PackOrderer::RangeSimilarity, rough_mind->GetRSValueTable(ld.val1.vc->GetDim())); + po.Init(ld.val1.vc, PackOrderer::OrderType::RangeSimilarity, rough_mind->GetRSValueTable(ld.val1.vc->GetDim())); matched_vc = ld.attr.vc; } // for each dim2 pack, check whether it may be joined with anything // nonempty on dim1 for (int p2 = 0; p2 < rough_mind->NoPacks(to_dim); p2++) { - if (rough_mind->GetPackStatus(to_dim, p2) != common::RS_NONE) { + if (rough_mind->GetPackStatus(to_dim, p2) != common::RSValue::RS_NONE) { bool pack_possible = false; local_mit.SetPack(to_dim, p2); @@ -437,12 +438,12 @@ void ParameterizedFilter::RoughMakeProjections(int to_dim, bool update_reduced) // rmind.NoPacks(dim1); p1++) // if(rmind.GetPackStatus(dim1, // p1) - //!= common::RS_NONE) { - if (rough_mind->GetPackStatus(dim1, po.Current()) != common::RS_NONE) { + //!= common::RSValue::RS_NONE) { + if (rough_mind->GetPackStatus(dim1, po.Current()) != common::RSValue::RS_NONE) { local_mit.SetPack(dim1, po.Current()); // set a dummy position, just // for transferring pack number - if (ld.attr.vc->RoughCheck(local_mit, ld) != common::RS_NONE) { + if (ld.attr.vc->RoughCheck(local_mit, ld) != common::RSValue::RS_NONE) { pack_possible = true; break; } @@ -450,7 +451,7 @@ void ParameterizedFilter::RoughMakeProjections(int to_dim, bool update_reduced) ++po; } if (!pack_possible) { - rough_mind->SetPackStatus(to_dim, p2, common::RS_NONE); + rough_mind->SetPackStatus(to_dim, p2, common::RSValue::RS_NONE); total_excluded++; } } @@ -468,7 +469,7 @@ void ParameterizedFilter::RoughMakeProjections(int to_dim, bool update_reduced) Filter *f = mind->GetUpdatableFilter(dim1); if (f) { for (int b = 0; b < rough_mind->NoPacks(dim1); b++) { - if (rough_mind->GetPackStatus(dim1, b) == common::RS_NONE) f->ResetBlock(b); + if (rough_mind->GetPackStatus(dim1, b) == common::RSValue::RS_NONE) f->ResetBlock(b); } } } @@ -569,22 +570,22 @@ void ParameterizedFilter::UpdateJoinCondition(Condition &cond, JoinTips &tips) // Apply conditions int conditions_used = cond.Size(); - JoinAlgType join_alg = JTYPE_NONE; - TwoDimensionalJoiner::JoinFailure join_result = TwoDimensionalJoiner::NOT_FAILED; + JoinAlgType join_alg = JoinAlgType::JTYPE_NONE; + TwoDimensionalJoiner::JoinFailure join_result = TwoDimensionalJoiner::JoinFailure::NOT_FAILED; join_alg = TwoDimensionalJoiner::ChooseJoinAlgorithm(*mind, cond); // Joining itself do { auto joiner = TwoDimensionalJoiner::CreateJoiner(join_alg, *mind, tips, table); - if (join_result == TwoDimensionalJoiner::FAIL_WRONG_SIDES) // the previous result, if any + if (join_result == TwoDimensionalJoiner::JoinFailure::FAIL_WRONG_SIDES) // the previous result, if any joiner->ForceSwitchingSides(); joiner->ExecuteJoinConditions(cond); join_result = joiner->WhyFailed(); - if (join_result != TwoDimensionalJoiner::NOT_FAILED) + if (join_result != TwoDimensionalJoiner::JoinFailure::NOT_FAILED) join_alg = TwoDimensionalJoiner::ChooseJoinAlgorithm(join_result, join_alg, cond.Size()); - } while (join_result != TwoDimensionalJoiner::NOT_FAILED); + } while (join_result != TwoDimensionalJoiner::JoinFailure::NOT_FAILED); for (int i = 0; i < conditions_used; i++) cond.EraseFirst(); // erase the first condition (already used) mind->UpdateNoTuples(); @@ -625,12 +626,13 @@ void ParameterizedFilter::DisplayJoinResults(DimensionVector &all_involved_dims, rccontrol.lock(mind->m_conn->GetThreadID()) << "Tuples after " << buf << "join " << buf_dims - << (join_performed == JTYPE_SORT + << (join_performed == JoinAlgType::JTYPE_SORT ? " [sort]: " - : (join_performed == JTYPE_MAP ? " [map]: " - : (join_performed == JTYPE_HASH - ? " [hash]: " - : (join_performed == JTYPE_GENERAL ? " [loop]: " : " [????]: ")))) + : (join_performed == JoinAlgType::JTYPE_MAP + ? " [map]: " + : (join_performed == JoinAlgType::JTYPE_HASH + ? " [hash]: " + : (join_performed == JoinAlgType::JTYPE_GENERAL ? " [loop]: " : " [????]: ")))) << tuples_after_join << " \t" << mind->Display() << system::unlock; } } @@ -638,7 +640,7 @@ void ParameterizedFilter::DisplayJoinResults(DimensionVector &all_involved_dims, void ParameterizedFilter::RoughSimplifyCondition(Condition &cond) { for (uint i = 0; i < cond.Size(); i++) { Descriptor &desc = cond[i]; - if (desc.op == common::O_FALSE || desc.op == common::O_TRUE || !desc.IsType_OrTree()) continue; + if (desc.op == common::Operator::O_FALSE || desc.op == common::Operator::O_TRUE || !desc.IsType_OrTree()) continue; DimensionVector all_dims(mind->NoDimensions()); // "false" for all dimensions desc.DimensionUsed(all_dims); desc.ClearRoughValues(); @@ -664,17 +666,17 @@ bool ParameterizedFilter::TryToMerge(Descriptor &d1, Descriptor &d2) // true, i // Exceptions: // null NOT IN {empty set} // null < ALL {empty set} etc. - if ((d1.op == common::O_IS_NULL && d2.op != common::O_IS_NULL && !IsSetOperator(d2.op)) || - (d2.op == common::O_IS_NULL && d1.op != common::O_IS_NULL && !IsSetOperator(d1.op))) { - d1.op = common::O_FALSE; + if ((d1.op == common::Operator::O_IS_NULL && d2.op != common::Operator::O_IS_NULL && !IsSetOperator(d2.op)) || + (d2.op == common::Operator::O_IS_NULL && d1.op != common::Operator::O_IS_NULL && !IsSetOperator(d1.op))) { + d1.op = common::Operator::O_FALSE; d1.CalculateJoinType(); return true; } - if (d1.op == common::O_NOT_NULL && !IsSetOperator(d2.op)) { + if (d1.op == common::Operator::O_NOT_NULL && !IsSetOperator(d2.op)) { d1 = d2; return true; } - if (d2.op == common::O_NOT_NULL && !IsSetOperator(d1.op)) return true; + if (d2.op == common::Operator::O_NOT_NULL && !IsSetOperator(d1.op)) return true; } // If a condition is repeated both on outer join list and after WHERE, then // the first one is not needed @@ -749,25 +751,25 @@ void ParameterizedFilter::SyntacticalDescriptorListPreprocessing(bool for_rough_ if (descriptors[i].IsDelayed()) continue; - DEBUG_ASSERT(descriptors[i].lop == common::O_AND); - // if(descriptors[i].lop != common::O_AND && descriptors[i].IsType_Join() && - // (descriptors[i].op == common::O_BETWEEN || descriptors[i].op == - // common::O_NOT_BETWEEN)) + DEBUG_ASSERT(descriptors[i].lop == common::LogicalOperator::O_AND); + // if(descriptors[i].lop != common::LogicalOperator::O_AND && descriptors[i].IsType_Join() && + // (descriptors[i].op == common::Operator::O_BETWEEN || descriptors[i].op == + // common::Operator::O_NOT_BETWEEN)) // throw common::NotImplementedException("This kind of join condition with // OR is not // implemented."); // normalization of descriptor of type 1 between a and b - if (descriptors[i].op == common::O_BETWEEN) { - if (descriptors[i].GetJoinType() != DT_COMPLEX_JOIN && !descriptors[i].IsType_Join() && descriptors[i].attr.vc && - descriptors[i].attr.vc->IsConst()) { + if (descriptors[i].op == common::Operator::O_BETWEEN) { + if (descriptors[i].GetJoinType() != DescriptorJoinType::DT_COMPLEX_JOIN && !descriptors[i].IsType_Join() && + descriptors[i].attr.vc && descriptors[i].attr.vc->IsConst()) { std::swap(descriptors[i].attr.vc, descriptors[i].val1.vc); - descriptors[i].op = common::O_LESS_EQ; + descriptors[i].op = common::Operator::O_LESS_EQ; // now, the second part Descriptor dd(table, mind->NoDimensions()); dd.attr = descriptors[i].val2; descriptors[i].val2.vc = NULL; - dd.op = common::O_MORE_EQ; + dd.op = common::Operator::O_MORE_EQ; dd.val1 = descriptors[i].val1; dd.done = false; dd.left_dims = descriptors[i].left_dims; @@ -778,12 +780,12 @@ void ParameterizedFilter::SyntacticalDescriptorListPreprocessing(bool for_rough_ no_desc++; } else if (descriptors[i].IsType_JoinSimple()) { // normalization of descriptor of type a between 1 and b - descriptors[i].op = common::O_MORE_EQ; + descriptors[i].op = common::Operator::O_MORE_EQ; Descriptor dd(table, mind->NoDimensions()); dd.attr = descriptors[i].attr; dd.val1 = descriptors[i].val2; descriptors[i].val2.vc = NULL; - dd.op = common::O_LESS_EQ; + dd.op = common::Operator::O_LESS_EQ; dd.done = false; dd.left_dims = descriptors[i].left_dims; dd.right_dims = descriptors[i].right_dims; @@ -804,7 +806,7 @@ void ParameterizedFilter::SyntacticalDescriptorListPreprocessing(bool for_rough_ // condition for another column) std::vector added_cond; for (uint i = 0; i < no_desc; i++) { // t1.x == t2.y && t2.y == 5 => t1.x == 5 - if (!descriptors[i].done && descriptors[i].op == common::O_EQ && descriptors[i].IsType_JoinSimple() && + if (!descriptors[i].done && descriptors[i].op == common::Operator::O_EQ && descriptors[i].IsType_JoinSimple() && descriptors[i].IsInner()) { // desc[i] is a joining (eq.) condition for (uint j = 0; j < descriptors.Size(); j++) { @@ -812,8 +814,8 @@ void ParameterizedFilter::SyntacticalDescriptorListPreprocessing(bool for_rough_ // desc[j] is a second condition, non-join if (descriptors[j].attr.vc == descriptors[i].attr.vc) { // the same table and column - if (descriptors[j].op == common::O_EQ) { // t2.y == t1.x && t2.y == 5 change to t1.x - // == 5 && t2.y == 5 + if (descriptors[j].op == common::Operator::O_EQ) { // t2.y == t1.x && t2.y == 5 change to t1.x + // == 5 && t2.y == 5 descriptors[i].attr = descriptors[i].val1; descriptors[i].val1 = descriptors[j].val1; descriptors[i].CalculateJoinType(); @@ -834,8 +836,8 @@ void ParameterizedFilter::SyntacticalDescriptorListPreprocessing(bool for_rough_ } if (descriptors[j].attr.vc == descriptors[i].val1.vc) { // the same as above for val1 // the same table and column - if (descriptors[j].op == common::O_EQ) { // t1.x == t2.y && t2.y == 5 change to t1.x - // == 5 && t2.y == 5 + if (descriptors[j].op == common::Operator::O_EQ) { // t1.x == t2.y && t2.y == 5 change to t1.x + // == 5 && t2.y == 5 descriptors[i].val1 = descriptors[j].val1; descriptors[i].CalculateJoinType(); descriptors[i].CoerceColumnTypes(); @@ -1006,7 +1008,7 @@ void ParameterizedFilter::UpdateMultiIndex(bool count_only, int64_t limit) { rough_mind->ClearLocalDescFilters(); return; } - PropagateRoughToMind(); // exclude common::RS_NONE from mind + PropagateRoughToMind(); // exclude common::RSValue::RS_NONE from mind // count other types of conditions, e.g. joins (i.e. conditions using // attributes from two @@ -1138,7 +1140,7 @@ void ParameterizedFilter::UpdateMultiIndex(bool count_only, int64_t limit) { // for an outer join if (join_desc[0].IsOuter()) { for (uint i = 0; i < descriptors.Size(); i++) { - if (descriptors[i].IsDelayed() && !descriptors[i].done && descriptors[i].op == common::O_IS_NULL && + if (descriptors[i].IsDelayed() && !descriptors[i].done && descriptors[i].op == common::Operator::O_IS_NULL && join_desc[0].right_dims.Get(descriptors[i].attr.vc->GetDim()) && !descriptors[i].attr.vc->NullsPossible()) { for (int j = 0; j < join_desc[0].right_dims.Size(); j++) { @@ -1191,7 +1193,7 @@ void ParameterizedFilter::UpdateMultiIndex(bool count_only, int64_t limit) { join_or_delayed_present = true; } } - if (join_or_delayed_present) rough_mind->MakeDimensionSuspect(); // no common::RS_ALL packs + if (join_or_delayed_present) rough_mind->MakeDimensionSuspect(); // no common::RSValue::RS_ALL packs mind->UpdateNoTuples(); } @@ -1210,11 +1212,11 @@ void ParameterizedFilter::ApplyDescriptor(int desc_number, int64_t limit) // desc_number = -1 => switch off the rough part { Descriptor &desc = descriptors[desc_number]; - if (desc.op == common::O_TRUE) { + if (desc.op == common::Operator::O_TRUE) { desc.done = true; return; } - if (desc.op == common::O_FALSE) { + if (desc.op == common::Operator::O_FALSE) { mind->Empty(); desc.done = true; return; @@ -1246,7 +1248,7 @@ void ParameterizedFilter::ApplyDescriptor(int desc_number, int64_t limit) int pack_all = rough_mind->NoPacks(one_dim); int pack_some = 0; for (int b = 0; b < pack_all; b++) { - if (rough_mind->GetPackStatus(one_dim, b) != common::RS_NONE) pack_some++; + if (rough_mind->GetPackStatus(one_dim, b) != common::RSValue::RS_NONE) pack_some++; } MIUpdatingIterator mit(mind, dims); desc.CopyDesCond(mit); @@ -1320,15 +1322,15 @@ void ParameterizedFilter::ApplyDescriptor(int desc_number, int64_t limit) if (rf && mit.GetCurPackrow(one_dim) >= 0) cur_roughval = rf[mit.GetCurPackrow(one_dim)]; else - cur_roughval = common::RS_SOME; + cur_roughval = common::RSValue::RS_SOME; - if (cur_roughval == common::RS_NONE) { + if (cur_roughval == common::RSValue::RS_NONE) { mit.ResetCurrentPack(); mit.NextPackrow(); - } else if (cur_roughval == common::RS_ALL) { + } else if (cur_roughval == common::RSValue::RS_ALL) { mit.NextPackrow(); } else { - // common::RS_SOME or common::RS_UNKNOWN + // common::RSValue::RS_SOME or common::RSValue::RS_UNKNOWN desc.EvaluatePack(mit); } if (mind->m_conn->Killed()) throw common::KilledException(); @@ -1341,7 +1343,7 @@ void ParameterizedFilter::ApplyDescriptor(int desc_number, int64_t limit) Filter *f = mind->GetFilter(one_dim); for (int p = 0; p < rough_mind->NoPacks(one_dim); p++) if (f->IsEmpty(p)) { - rough_mind->SetPackStatus(one_dim, p, common::RS_NONE); + rough_mind->SetPackStatus(one_dim, p, common::RSValue::RS_NONE); } } desc.UpdateVCStatistics(); @@ -1373,11 +1375,11 @@ void ParameterizedFilter::TaskProcessPacks(MIUpdatingIterator *taskIterator, Tra if (rf && taskIterator->GetCurPackrow(one_dim) >= 0) cur_roughval = rf[taskIterator->GetCurPackrow(one_dim)]; //?D??¦Ì¡À?¡ã¡ã¨¹¨º?¡¤??¨¹?DRS_SOME¡À¨ª¨º?2?¡¤??¨¹?D else - cur_roughval = common::RS_SOME; - if (cur_roughval == common::RS_NONE) { + cur_roughval = common::RSValue::RS_SOME; + if (cur_roughval == common::RSValue::RS_NONE) { taskIterator->ResetCurrentPack(); taskIterator->NextPackrow(); - } else if (cur_roughval == common::RS_ALL) { + } else if (cur_roughval == common::RSValue::RS_ALL) { taskIterator->NextPackrow(); } else { desc.EvaluatePack(*taskIterator); //??¦Ì¡À?¡ã¡ã¨¹???y??¨¬???DD??¡À¨¨¡ã¨¹¨¤¡§?a?1¡ã¨¹¡ê???¨¬???????¡À¨¨ diff --git a/storage/stonedb/core/parameterized_filter.h b/storage/stonedb/core/parameterized_filter.h index 28a1ead7f..8a530eb71 100644 --- a/storage/stonedb/core/parameterized_filter.h +++ b/storage/stonedb/core/parameterized_filter.h @@ -37,7 +37,7 @@ can also store tree of conditions class ParameterizedFilter final { public: - ParameterizedFilter(uint32_t power, CondType filter_type = WHERE_COND); + ParameterizedFilter(uint32_t power, CondType filter_type = CondType::WHERE_COND); ParameterizedFilter(const ParameterizedFilter &); virtual ~ParameterizedFilter(); ParameterizedFilter &operator=(const ParameterizedFilter &pf); diff --git a/storage/stonedb/core/physical_column.h b/storage/stonedb/core/physical_column.h index d121e955b..f04518e6a 100644 --- a/storage/stonedb/core/physical_column.h +++ b/storage/stonedb/core/physical_column.h @@ -34,7 +34,7 @@ class PhysicalColumn : public Column { PhysicalColumn(const PhysicalColumn &phc) : Column(phc), is_unique(phc.is_unique), is_unique_updated(phc.is_unique_updated) {} - enum phys_col_t { ATTR, RCATTR }; + enum class phys_col_t { ATTR, RCATTR }; /*! \brief Get a numeric value from a column * @@ -201,7 +201,8 @@ class PhysicalColumn : public Column { void SetUniqueUpdated(bool updated) { is_unique_updated = updated; } //! shortcut utility function = IsUniqueUpdated && IsUnique common::RSValue IsDistinct() const { - return (IsUniqueUpdated() ? (IsUnique() ? common::RS_ALL : common::RS_NONE) : common::RS_UNKNOWN); + return (IsUniqueUpdated() ? (IsUnique() ? common::RSValue::RS_ALL : common::RSValue::RS_NONE) + : common::RSValue::RS_UNKNOWN); } virtual int64_t RoughMin(Filter *f = NULL, common::RSValue *rf = NULL) = 0; // for numerical: best @@ -267,7 +268,7 @@ class PhysicalColumn : public Column { virtual common::RSValue RoughCheck(int pack1, int pack2, Descriptor &d) = 0; virtual common::RSValue RoughCheckBetween([[maybe_unused]] int pack, [[maybe_unused]] int64_t min, [[maybe_unused]] int64_t max) { - return common::RS_SOME; + return common::RSValue::RS_SOME; } virtual bool TryToMerge(Descriptor &d1, Descriptor &d2) = 0; diff --git a/storage/stonedb/core/proxy_hash_joiner.cpp b/storage/stonedb/core/proxy_hash_joiner.cpp index 2f91d38e4..5edc3ae2d 100644 --- a/storage/stonedb/core/proxy_hash_joiner.cpp +++ b/storage/stonedb/core/proxy_hash_joiner.cpp @@ -55,8 +55,8 @@ class MIIteratorPoller { } slice_type_ = "none"; - if (slice_capability_.type != MIIterator::SliceCapability::kDisable) { - if (slice_capability_.type == MIIterator::SliceCapability::kLinear) { + if (slice_capability_.type != MIIterator::SliceCapability::Type::kDisable) { + if (slice_capability_.type == MIIterator::SliceCapability::Type::kLinear) { if (stonedb_sysvar_async_join_setting.pack_per_step > 0) slice_type_ = base::sprint("per %d packs", stonedb_sysvar_async_join_setting.pack_per_step); else { @@ -75,11 +75,11 @@ class MIIteratorPoller { if (no_more_) return std::shared_ptr(); std::shared_ptr pack_iter; - if (slice_capability_.type != MIIterator::SliceCapability::kDisable) { + if (slice_capability_.type != MIIterator::SliceCapability::Type::kDisable) { size_t actual_pos = cur_pos_; size_t step = 1; int64_t sentry_pos = slice_capability_.slices.size(); - if (slice_capability_.type == MIIterator::SliceCapability::kLinear) { + if (slice_capability_.type == MIIterator::SliceCapability::Type::kLinear) { DEBUG_ASSERT(stonedb_sysvar_async_join_setting.pack_per_step > 0 || stonedb_sysvar_async_join_setting.rows_per_step > 0); // Preferred iterating by pack. @@ -114,7 +114,7 @@ class MIIteratorPoller { } } } else { - DEBUG_ASSERT(slice_capability_.type == MIIterator::SliceCapability::kFixed); + DEBUG_ASSERT(slice_capability_.type == MIIterator::SliceCapability::Type::kFixed); pack_iter.reset(new MIStepIterator(cur_pos_, stonedb_sysvar_async_join_setting.pack_per_step, *miter_)); } @@ -155,7 +155,7 @@ class ProxyHashJoiner::Action { ~Action() = default; bool Init(Condition &cond) { - auto result_defer = base::defer([this] { parent_->why_failed = FAIL_HASH; }); + auto result_defer = base::defer([this] { parent_->why_failed = JoinFailure::FAIL_HASH; }); std::vector hash_descriptors; bool first_found = true; @@ -165,7 +165,7 @@ class ProxyHashJoiner::Action { DimensionVector dims_other(mind_->NoDimensions()); for (uint index = 0; index < cond.Size(); ++index) { bool added = false; - if (cond[index].IsType_JoinSimple() && cond[index].op == common::O_EQ) { + if (cond[index].IsType_JoinSimple() && cond[index].op == common::Operator::O_EQ) { if (first_found) { hash_descriptors.push_back(index); added = true; @@ -321,7 +321,7 @@ class ProxyHashJoiner::Action { auto _ = base::defer([this] { mind_->UnlockAllFromUse(); }); if (too_many_conflicts_) { - parent_->why_failed = FAIL_WRONG_SIDES; + parent_->why_failed = JoinFailure::FAIL_WRONG_SIDES; return; } diff --git a/storage/stonedb/core/query.cpp b/storage/stonedb/core/query.cpp index 3bc884fd2..02227ecf6 100644 --- a/storage/stonedb/core/query.cpp +++ b/storage/stonedb/core/query.cpp @@ -258,7 +258,7 @@ const std::string Query::GetItemName(Item *item) { return "REAL"; case Item::DECIMAL_ITEM: return "DECIMAL"; - case Item_sdbfield::SDBFIELD_ITEM: + case static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM): Item_sdbfield *sdb = static_cast(item); size_t cur_var_id = sdbitems_cur_var_ids[sdb]++; if (cur_var_id >= sdb->varID.size()) cur_var_id = 0; @@ -272,7 +272,7 @@ int Query::GetAddColumnId(const AttrID &vc, const TabID &tmp_table, const common const bool distinct) { for (int i = 0; i < cq->NoSteps(); i++) { CompiledQuery::CQStep *step = &cq->Step(i); - if (step->type == CompiledQuery::ADD_COLUMN && step->t1 == tmp_table && step->e1.vc_id == vc.n && + if (step->type == CompiledQuery::StepType::ADD_COLUMN && step->t1 == tmp_table && step->e1.vc_id == vc.n && step->cop == oper && step->n1 == (distinct ? 1 : 0)) { return step->a1.n; } @@ -283,7 +283,7 @@ int Query::GetAddColumnId(const AttrID &vc, const TabID &tmp_table, const common void Query::CQChangeAddColumnLIST2GROUP_BY(const TabID &tmp_table, int attr) { for (int i = 0; i < cq->NoSteps(); i++) { CompiledQuery::CQStep *step = &cq->Step(i); - if (step->type == CompiledQuery::ADD_COLUMN && step->t1 == tmp_table && step->a1.n == attr && + if (step->type == CompiledQuery::StepType::ADD_COLUMN && step->t1 == tmp_table && step->a1.n == attr && step->cop == common::ColOperation::LISTING) { step->cop = common::ColOperation::GROUP_BY; cq->AddGroupByStep(*step); @@ -294,23 +294,23 @@ void Query::CQChangeAddColumnLIST2GROUP_BY(const TabID &tmp_table, int attr) { void Query::MarkWithAny(common::Operator &op) { switch (op) { - case common::O_EQ: - op = common::O_EQ_ANY; + case common::Operator::O_EQ: + op = common::Operator::O_EQ_ANY; break; - case common::O_NOT_EQ: - op = common::O_NOT_EQ_ANY; + case common::Operator::O_NOT_EQ: + op = common::Operator::O_NOT_EQ_ANY; break; - case common::O_LESS: - op = common::O_LESS_ANY; + case common::Operator::O_LESS: + op = common::Operator::O_LESS_ANY; break; - case common::O_MORE: - op = common::O_MORE_ANY; + case common::Operator::O_MORE: + op = common::Operator::O_MORE_ANY; break; - case common::O_LESS_EQ: - op = common::O_LESS_EQ_ANY; + case common::Operator::O_LESS_EQ: + op = common::Operator::O_LESS_EQ_ANY; break; - case common::O_MORE_EQ: - op = common::O_MORE_EQ_ANY; + case common::Operator::O_MORE_EQ: + op = common::Operator::O_MORE_EQ_ANY; break; default: // ANY can't be added to any other operator @@ -320,23 +320,23 @@ void Query::MarkWithAny(common::Operator &op) { void Query::MarkWithAll(common::Operator &op) { switch (op) { - case common::O_EQ: - op = common::O_EQ_ALL; + case common::Operator::O_EQ: + op = common::Operator::O_EQ_ALL; break; - case common::O_NOT_EQ: - op = common::O_NOT_EQ_ALL; + case common::Operator::O_NOT_EQ: + op = common::Operator::O_NOT_EQ_ALL; break; - case common::O_LESS: - op = common::O_LESS_ALL; + case common::Operator::O_LESS: + op = common::Operator::O_LESS_ALL; break; - case common::O_MORE: - op = common::O_MORE_ALL; + case common::Operator::O_MORE: + op = common::Operator::O_MORE_ALL; break; - case common::O_LESS_EQ: - op = common::O_LESS_EQ_ALL; + case common::Operator::O_LESS_EQ: + op = common::Operator::O_LESS_EQ_ALL; break; - case common::O_MORE_EQ: - op = common::O_MORE_EQ_ALL; + case common::Operator::O_MORE_EQ: + op = common::Operator::O_MORE_EQ_ALL; break; default: // ALL can't be added to any other operator @@ -345,37 +345,39 @@ void Query::MarkWithAll(common::Operator &op) { } bool Query::IsAllAny(common::Operator &op) { - return (op == common::O_EQ_ALL || op == common::O_EQ_ANY || op == common::O_NOT_EQ_ALL || - op == common::O_NOT_EQ_ANY || op == common::O_LESS_ALL || op == common::O_LESS_ANY || - op == common::O_MORE_ALL || op == common::O_MORE_ANY || op == common::O_LESS_EQ_ALL || - op == common::O_LESS_EQ_ANY || op == common::O_MORE_EQ_ALL || op == common::O_MORE_EQ_ANY); + return (op == common::Operator::O_EQ_ALL || op == common::Operator::O_EQ_ANY || + op == common::Operator::O_NOT_EQ_ALL || op == common::Operator::O_NOT_EQ_ANY || + op == common::Operator::O_LESS_ALL || op == common::Operator::O_LESS_ANY || + op == common::Operator::O_MORE_ALL || op == common::Operator::O_MORE_ANY || + op == common::Operator::O_LESS_EQ_ALL || op == common::Operator::O_LESS_EQ_ANY || + op == common::Operator::O_MORE_EQ_ALL || op == common::Operator::O_MORE_EQ_ANY); } void Query::UnmarkAllAny(common::Operator &op) { switch (op) { - case common::O_EQ_ALL: - case common::O_EQ_ANY: - op = common::O_EQ; + case common::Operator::O_EQ_ALL: + case common::Operator::O_EQ_ANY: + op = common::Operator::O_EQ; break; - case common::O_NOT_EQ_ALL: - case common::O_NOT_EQ_ANY: - op = common::O_NOT_EQ; + case common::Operator::O_NOT_EQ_ALL: + case common::Operator::O_NOT_EQ_ANY: + op = common::Operator::O_NOT_EQ; break; - case common::O_LESS_ALL: - case common::O_LESS_ANY: - op = common::O_LESS; + case common::Operator::O_LESS_ALL: + case common::Operator::O_LESS_ANY: + op = common::Operator::O_LESS; break; - case common::O_MORE_ALL: - case common::O_MORE_ANY: - op = common::O_MORE; + case common::Operator::O_MORE_ALL: + case common::Operator::O_MORE_ANY: + op = common::Operator::O_MORE; break; - case common::O_LESS_EQ_ALL: - case common::O_LESS_EQ_ANY: - op = common::O_LESS_EQ; + case common::Operator::O_LESS_EQ_ALL: + case common::Operator::O_LESS_EQ_ANY: + op = common::Operator::O_LESS_EQ; break; - case common::O_MORE_EQ_ALL: - case common::O_MORE_EQ_ANY: - op = common::O_MORE_EQ; + case common::Operator::O_MORE_EQ_ALL: + case common::Operator::O_MORE_EQ_ANY: + op = common::Operator::O_MORE_EQ; break; default: // ALL/ANY can't be removed from any other operator @@ -392,44 +394,44 @@ void Query::ExtractOperatorType(Item *&conds, common::Operator &op, bool &negati Item_func *cond_func = (Item_func *)conds; switch (cond_func->functype()) { case Item_func::BETWEEN: - op = is_there_not ? common::O_NOT_BETWEEN : common::O_BETWEEN; + op = is_there_not ? common::Operator::O_NOT_BETWEEN : common::Operator::O_BETWEEN; break; case Item_func::LIKE_FUNC: - op = is_there_not ? common::O_NOT_LIKE : common::O_LIKE; + op = is_there_not ? common::Operator::O_NOT_LIKE : common::Operator::O_LIKE; like_esc = ((Item_func_like *)cond_func)->escape; break; case Item_func::ISNULL_FUNC: - op = common::O_IS_NULL; + op = common::Operator::O_IS_NULL; break; case Item_func::ISNOTNULL_FUNC: - op = common::O_NOT_NULL; + op = common::Operator::O_NOT_NULL; break; case Item_func::IN_FUNC: - op = is_there_not ? common::O_NOT_IN : common::O_IN; + op = is_there_not ? common::Operator::O_NOT_IN : common::Operator::O_IN; break; case Item_func::EQ_FUNC: // = - op = negative ? common::O_NOT_EQ : common::O_EQ; + op = negative ? common::Operator::O_NOT_EQ : common::Operator::O_EQ; break; case Item_func::NE_FUNC: // <> - op = negative ? common::O_EQ : common::O_NOT_EQ; + op = negative ? common::Operator::O_EQ : common::Operator::O_NOT_EQ; break; case Item_func::LE_FUNC: // <= - op = negative ? common::O_MORE : common::O_LESS_EQ; + op = negative ? common::Operator::O_MORE : common::Operator::O_LESS_EQ; break; case Item_func::GE_FUNC: // >= - op = negative ? common::O_LESS : common::O_MORE_EQ; + op = negative ? common::Operator::O_LESS : common::Operator::O_MORE_EQ; break; case Item_func::GT_FUNC: // > - op = negative ? common::O_LESS_EQ : common::O_MORE; + op = negative ? common::Operator::O_LESS_EQ : common::Operator::O_MORE; break; case Item_func::LT_FUNC: // < - op = negative ? common::O_MORE_EQ : common::O_LESS; + op = negative ? common::Operator::O_MORE_EQ : common::Operator::O_LESS; break; case Item_func::MULT_EQUAL_FUNC: - op = common::O_MULT_EQUAL_FUNC; + op = common::Operator::O_MULT_EQUAL_FUNC; break; case Item_func::NOT_FUNC: - op = common::O_NOT_FUNC; + op = common::Operator::O_NOT_FUNC; break; case Item_func::NOT_ALL_FUNC: { Item_func *cond_func = (Item_func *)conds; @@ -443,10 +445,10 @@ void Query::ExtractOperatorType(Item *&conds, common::Operator &op, bool &negati break; } case Item_func::UNKNOWN_FUNC: - op = common::O_UNKNOWN_FUNC; + op = common::Operator::O_UNKNOWN_FUNC; break; default: - op = common::O_ERROR; // unknown function type + op = common::Operator::O_ERROR; // unknown function type break; } } @@ -485,7 +487,7 @@ vcolumn::VirtualColumn *Query::CreateColumnFromExpression(std::vector(vc)->GetStringType() == MysqlExpression::STRING_TIME && + if (static_cast(vc)->GetStringType() == MysqlExpression::StringType::STRING_TIME && vc->TypeName() != common::CT::TIME) { // common::CT::TIME is already as int64_t vcolumn::TypeCastColumn *tcc = new vcolumn::String2DateTimeCastColumn(vc, ColumnType(common::CT::TIME)); temp_table->AddVirtColumn(vc); @@ -555,7 +557,7 @@ void Query::GetPrecisionScale(Item *item, int &precision, int &scale, bool max_s } TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_unused]] bool display_now) { - if (STONEDB_LOGCHECK(DEBUG)) { + if (STONEDB_LOGCHECK(LogCtl_Level::DEBUG)) { qu.Print(this); } std::vector conds(qu.NoConds()); @@ -606,17 +608,17 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un // Implementation of steps try { switch (step.type) { - case CompiledQuery::TABLE_ALIAS: + case CompiledQuery::StepType::TABLE_ALIAS: ta[-step.t1.n - 1] = t2_ptr; break; - case CompiledQuery::TMP_TABLE: + case CompiledQuery::StepType::TMP_TABLE: DEBUG_ASSERT(step.t1.n < 0); ta[-step.t1.n - 1] = step.n1 ? TempTable::Create(ta[-step.tables1[0].n - 1].get(), step.tables1[0].n, this, true) : TempTable::Create(ta[-step.tables1[0].n - 1].get(), step.tables1[0].n, this); ((TempTable *)ta[-step.t1.n - 1].get())->ReserveVirtColumns(qu.NoVirtualColumns(step.t1)); break; - case CompiledQuery::CREATE_CONDS: + case CompiledQuery::StepType::CREATE_CONDS: DEBUG_ASSERT(step.t1.n < 0); step.e1.vc = (step.e1.vc_id != common::NULL_VALUE_32) ? ((TempTable *)ta[-step.t1.n - 1].get())->GetVirtualColumn(step.e1.vc_id) @@ -627,12 +629,13 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un step.e3.vc = (step.e3.vc_id != common::NULL_VALUE_32) ? ((TempTable *)ta[-step.t1.n - 1].get())->GetVirtualColumn(step.e3.vc_id) : NULL; - if (step.n1 != OR_SUBTREE) { // on result = false + if (step.n1 != static_cast(CondType::OR_SUBTREE)) { // on result = false conds[step.c1.n] = new Condition(); if (step.c2.IsNull()) { conds[step.c1.n]->AddDescriptor( step.e1, step.op, step.e2, step.e3, (TempTable *)ta[-step.t1.n - 1].get(), qu.GetNoDims(step.t1), - (step.op == common::O_LIKE || step.op == common::O_NOT_LIKE) ? char(step.n2) : '\\'); + (step.op == common::Operator::O_LIKE || step.op == common::Operator::O_NOT_LIKE) ? char(step.n2) + : '\\'); } else { DEBUG_ASSERT(conds[step.c2.n]->IsType_Tree()); conds[step.c1.n]->AddDescriptor(static_cast(conds[step.c2.n])->GetTree(), @@ -651,22 +654,23 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un } } break; - case CompiledQuery::AND_F: - case CompiledQuery::OR_F: + case CompiledQuery::StepType::AND_F: + case CompiledQuery::StepType::OR_F: if (!conds[step.c2.n]->IsType_Tree()) { - ASSERT(step.type == CompiledQuery::AND_F); + ASSERT(step.type == CompiledQuery::StepType::AND_F); auto cond2 = conds[step.c2.n]; for (size_t i = 0; i < cond2->Size(); i++) { auto &desc = (*cond2)[i]; if (conds[step.c1.n]->IsType_Tree()) { TempTable *temptb = (TempTable *)ta[-qu.GetTableOfCond(step.c2).n - 1].get(); int no_dims = qu.GetNoDims(qu.GetTableOfCond(step.c2)); - if (desc.op == common::O_OR_TREE) { - static_cast(conds[step.c1.n])->AddTree(common::O_AND, desc.tree, no_dims); + if (desc.op == common::Operator::O_OR_TREE) { + static_cast(conds[step.c1.n]) + ->AddTree(common::LogicalOperator::O_AND, desc.tree, no_dims); } else { static_cast(conds[step.c1.n]) - ->AddDescriptor(common::O_AND, desc.attr, desc.op, desc.val1, desc.val2, temptb, no_dims, - desc.like_esc); + ->AddDescriptor(common::LogicalOperator::O_AND, desc.attr, desc.op, desc.val1, desc.val2, temptb, + no_dims, desc.like_esc); } } else { conds[step.c1.n]->AddDescriptor(desc); @@ -674,7 +678,8 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un } } else if (conds[step.c1.n]->IsType_Tree()) { // on result = false DEBUG_ASSERT(conds[step.c2.n]->IsType_Tree()); - common::LogicalOperator lop = (step.type == CompiledQuery::AND_F ? common::O_AND : common::O_OR); + common::LogicalOperator lop = (step.type == CompiledQuery::StepType::AND_F ? common::LogicalOperator::O_AND + : common::LogicalOperator::O_OR); static_cast(conds[step.c1.n]) ->AddTree(lop, static_cast(conds[step.c2.n])->GetTree(), qu.GetNoDims(step.t1)); } else { @@ -684,9 +689,11 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un qu.GetNoDims(qu.GetTableOfCond(step.c1))); } break; - case CompiledQuery::OR_DESC: - case CompiledQuery::AND_DESC: { - common::LogicalOperator lop = (step.type == CompiledQuery::AND_DESC ? common::O_AND : common::O_OR); + case CompiledQuery::StepType::OR_DESC: + case CompiledQuery::StepType::AND_DESC: { + common::LogicalOperator lop = + (step.type == CompiledQuery::StepType::AND_DESC ? common::LogicalOperator::O_AND + : common::LogicalOperator::O_OR); step.e1.vc = (step.e1.vc_id != common::NULL_VALUE_32) ? ((TempTable *)ta[-step.t1.n - 1].get())->GetVirtualColumn(step.e1.vc_id) : NULL; @@ -700,44 +707,48 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un DEBUG_ASSERT(conds[step.c1.n]); conds[step.c1.n]->AddDescriptor( step.e1, step.op, step.e2, step.e3, (TempTable *)ta[-step.t1.n - 1].get(), qu.GetNoDims(step.t1), - (step.op == common::O_LIKE || step.op == common::O_NOT_LIKE) ? char(step.n2) : '\\'); + (step.op == common::Operator::O_LIKE || step.op == common::Operator::O_NOT_LIKE) ? char(step.n2) + : '\\'); } else static_cast(conds[step.c1.n]) ->AddDescriptor(lop, step.e1, step.op, step.e2, step.e3, (TempTable *)ta[-step.t1.n - 1].get(), qu.GetNoDims(step.t1), - (step.op == common::O_LIKE || step.op == common::O_NOT_LIKE) ? char(step.n2) : '\\'); + (step.op == common::Operator::O_LIKE || step.op == common::Operator::O_NOT_LIKE) + ? char(step.n2) + : '\\'); break; } - case CompiledQuery::T_MODE: + case CompiledQuery::StepType::T_MODE: DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); ((TempTable *)ta[-step.t1.n - 1].get())->SetMode(step.tmpar, step.n1, step.n2); break; - case CompiledQuery::JOIN_T: + case CompiledQuery::StepType::JOIN_T: DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); ((TempTable *)ta[-step.t1.n - 1].get())->JoinT(t2_ptr.get(), step.t2.n, step.jt); break; - case CompiledQuery::ADD_CONDS: { + case CompiledQuery::StepType::ADD_CONDS: { DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); if (step.c1.n == common::NULL_VALUE_32) break; - if (step.n1 != HAVING_COND) conds[step.c1.n]->Simplify(); + if (step.n1 != static_cast(CondType::HAVING_COND)) conds[step.c1.n]->Simplify(); ((TempTable *)ta[-step.t1.n - 1].get())->AddConds(conds[step.c1.n], (CondType)step.n1); break; } - case CompiledQuery::LEFT_JOIN_ON: { + case CompiledQuery::StepType::LEFT_JOIN_ON: { DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); if (step.c1.n == common::NULL_VALUE_32) break; ((TempTable *)ta[-step.t1.n - 1].get())->AddLeftConds(conds[step.c1.n], step.tables1, step.tables2); break; } - case CompiledQuery::INNER_JOIN_ON: { + case CompiledQuery::StepType::INNER_JOIN_ON: { DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); if (step.c1.n == common::NULL_VALUE_32) break; ((TempTable *)ta[-step.t1.n - 1].get())->AddInnerConds(conds[step.c1.n], step.tables1); break; } - case CompiledQuery::APPLY_CONDS: { + case CompiledQuery::StepType::APPLY_CONDS: { int64_t cur_limit = -1; - if (qu.FindDistinct(step.t1.n)) ((TempTable *)ta[-step.t1.n - 1].get())->SetMode(TM_DISTINCT, 0, 0); + if (qu.FindDistinct(step.t1.n)) + ((TempTable *)ta[-step.t1.n - 1].get())->SetMode(TMParameter::TM_DISTINCT, 0, 0); if (qu.NoAggregationOrderingAndDistinct(step.t1.n)) cur_limit = qu.FindLimit(step.t1.n); if (cur_limit != -1 && ((TempTable *)ta[-step.t1.n - 1].get())->GetFilterP()->NoParameterizedDescs()) @@ -765,7 +776,7 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un ->UpdateMultiIndex(qu.CountColumnOnly(step.t1), cur_limit); break; } - case CompiledQuery::ADD_COLUMN: { + case CompiledQuery::StepType::ADD_COLUMN: { DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); CQTerm e(step.e1); if (e.vc_id != common::NULL_VALUE_32) @@ -775,7 +786,7 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un ->AddColumn(e, step.cop, step.alias, step.n1 ? true : false, step.si); break; } - case CompiledQuery::CREATE_VC: { + case CompiledQuery::StepType::CREATE_VC: { DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); TempTable *t = (TempTable *)ta[-step.t1.n - 1].get(); @@ -823,7 +834,7 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un } break; } - case CompiledQuery::ADD_ORDER: { + case CompiledQuery::StepType::ADD_ORDER: { DEBUG_ASSERT(step.t1.n < 0 && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE && step.n1 >= 0 && step.n1 < 2); DEBUG_ASSERT(step.a1.n >= 0 && step.a1.n < qu.NoVirtualColumns(step.t1)); @@ -832,7 +843,7 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un (int)step.n1); // step.n1 = 0 for asc, 1 for desc break; } - case CompiledQuery::UNION: + case CompiledQuery::StepType::UNION: DEBUG_ASSERT(step.t1.n < 0 && step.t2.n < 0 && step.t3.n < 0); DEBUG_ASSERT(ta[-step.t2.n - 1]->TableType() == TType::TEMP_TABLE && (step.t3.n == common::NULL_VALUE_32 || ta[-step.t3.n - 1]->TableType() == TType::TEMP_TABLE)); @@ -857,17 +868,17 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un } } break; - case CompiledQuery::RESULT: + case CompiledQuery::StepType::RESULT: DEBUG_ASSERT(step.t1.n < 0 && static_cast(-step.t1.n - 1) < ta.size() && ta[-step.t1.n - 1]->TableType() == TType::TEMP_TABLE); output_table = (TempTable *)ta[-step.t1.n - 1].get(); break; - case CompiledQuery::STEP_ERROR: + case CompiledQuery::StepType::STEP_ERROR: rccontrol.lock(m_conn->GetThreadID()) << "ERROR in step " << step.alias << system::unlock; break; default: rccontrol.lock(m_conn->GetThreadID()) - << "ERROR: unsupported type of CQStep (" << step.type << ")" << system::unlock; + << "ERROR: unsupported type of CQStep (" << static_cast(step.type) << ")" << system::unlock; } } catch (...) { for (auto &c : conds) delete c; @@ -901,7 +912,8 @@ int Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondT bool ignore_minmax = (dynamic_cast(item_subs) == NULL && dynamic_cast(item_subs) == NULL && negative && item_subs->substype() == Item_subselect::SINGLEROW_SUBS); - subqueries_in_where.emplace_back(tmp_table, item_subs->place() != IN_HAVING && filter_type != HAVING_COND); + subqueries_in_where.emplace_back(tmp_table, + item_subs->place() != IN_HAVING && filter_type != CondType::HAVING_COND); // we need to make a copy of global map with table aliases so that subquery // contains aliases of outer queries and itself but not "parallel" @@ -919,7 +931,7 @@ int Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondT AttrID vc; vc.n = VirtualColumnAlreadyExists(tmp_table, subselect); if (vc.n == common::NULL_VALUE_32) { - cq->CreateVirtualColumn(vc, tmp_table, subselect, filter_type == HAVING_COND ? true : false); + cq->CreateVirtualColumn(vc, tmp_table, subselect, filter_type == CondType::HAVING_COND ? true : false); tab_id2subselect.insert(std::make_pair(tmp_table, std::make_pair(vc.n, subselect))); } if (oper_for_subselect) { @@ -927,13 +939,13 @@ int Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondT dynamic_cast(item_subs) != NULL) { if (negative) { MarkWithAll(*oper_for_subselect); - if (dynamic_cast(item_subs) != NULL && *oper_for_subselect == common::O_IN) - *oper_for_subselect = common::O_EQ_ALL; + if (dynamic_cast(item_subs) != NULL && *oper_for_subselect == common::Operator::O_IN) + *oper_for_subselect = common::Operator::O_EQ_ALL; } else { MarkWithAny(*oper_for_subselect); if (dynamic_cast(item_subs) != NULL && dynamic_cast(item_subs)->all == 1) - *oper_for_subselect = common::O_EQ_ALL; + *oper_for_subselect = common::Operator::O_EQ_ALL; } } else { if (negative) { @@ -949,7 +961,7 @@ int Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondT return res; } - if (filter_type == HAVING_COND) { + if (filter_type == CondType::HAVING_COND) { common::ColOperation oper; bool distinct; if (!OperationUnmysterify(an_arg, oper, distinct, @@ -1017,7 +1029,8 @@ int Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondT } } else if (IsAggregationItem(an_arg)) { DEBUG_ASSERT(expr->GetItem()->type() == Item_sdbfield::get_sdbitem_type()); - int col_num = ((Item_sdbfield *)expr->GetItem())->varID[((Item_sdbfield *)expr->GetItem())->varID.size() - 1].col; + int col_num = + ((Item_sdbfield *)expr->GetItem())->varID[((Item_sdbfield *)expr->GetItem())->varID.size() - 1].col; auto phys_vc = VirtualColumnAlreadyExists(tmp_table, tmp_table, AttrID(-col_num - 1)); if (phys_vc.first == common::NULL_VALUE_32) { phys_vc.first = tmp_table.n; @@ -1107,26 +1120,26 @@ CondID Query::ConditionNumberFromMultipleEquality(Item_equal *conds, const TabID if (!Item2CQTerm(ifield, first_term, tmp_table, filter_type)) return CondID(-1); CondID filter; if (!and_me_filter) - cq->CreateConds(filter, tmp_table, first_term, common::O_EQ, zero_term, CQTerm(), - is_or_subtree || filter_type == HAVING_COND); + cq->CreateConds(filter, tmp_table, first_term, common::Operator::O_EQ, zero_term, CQTerm(), + is_or_subtree || filter_type == CondType::HAVING_COND); else { if (is_or_subtree) - cq->Or(*and_me_filter, tmp_table, first_term, common::O_EQ, zero_term); + cq->Or(*and_me_filter, tmp_table, first_term, common::Operator::O_EQ, zero_term); else - cq->And(*and_me_filter, tmp_table, first_term, common::O_EQ, zero_term); + cq->And(*and_me_filter, tmp_table, first_term, common::Operator::O_EQ, zero_term); } while ((ifield = li++) != nullptr) { if (!Item2CQTerm(ifield, next_term, tmp_table, filter_type)) return CondID(-1); if (!and_me_filter) { if (is_or_subtree) - cq->Or(filter, tmp_table, next_term, common::O_EQ, zero_term); + cq->Or(filter, tmp_table, next_term, common::Operator::O_EQ, zero_term); else - cq->And(filter, tmp_table, next_term, common::O_EQ, zero_term); + cq->And(filter, tmp_table, next_term, common::Operator::O_EQ, zero_term); } else { if (is_or_subtree) - cq->Or(*and_me_filter, tmp_table, next_term, common::O_EQ, zero_term); + cq->Or(*and_me_filter, tmp_table, next_term, common::Operator::O_EQ, zero_term); else - cq->And(*and_me_filter, tmp_table, next_term, common::O_EQ, zero_term); + cq->And(*and_me_filter, tmp_table, next_term, common::Operator::O_EQ, zero_term); } } if (and_me_filter) filter = *and_me_filter; @@ -1160,35 +1173,35 @@ Item *Query::FindOutAboutNot(Item *it, bool &is_there_not) { CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, CondType filter_type, CondID *and_me_filter, bool is_or_subtree, bool negative) { CondID filter; - common::Operator op; /*{ common::O_EQ, common::O_NOT_EQ, common::O_LESS, - common::O_MORE, common::O_LESS_EQ, common::O_MORE_EQ, - common::O_IS_NULL, common::O_NOT_NULL, common::O_BETWEEN, - common::O_LIKE, common::O_IN, common::O_ESCAPE etc...};*/ + common::Operator op; /*{ common::Operator::O_EQ, common::Operator::O_NOT_EQ, common::Operator::O_LESS, + common::Operator::O_MORE, common::Operator::O_LESS_EQ, common::Operator::O_MORE_EQ, + common::Operator::O_IS_NULL, common::Operator::O_NOT_NULL, common::Operator::O_BETWEEN, + common::Operator::O_LIKE, common::Operator::O_IN, common::Operator::O_ESCAPE etc...};*/ char like_esc; Item_in_optimizer *in_opt = NULL; // set if IN expression with subselect ExtractOperatorType(conds, op, negative, like_esc); Item_func *cond_func = (Item_func *)conds; - if (op == common::O_MULT_EQUAL_FUNC) + if (op == common::Operator::O_MULT_EQUAL_FUNC) return ConditionNumberFromMultipleEquality((Item_equal *)conds, tmp_table, filter_type, and_me_filter, is_or_subtree); - else if (op == common::O_NOT_FUNC) { + else if (op == common::Operator::O_NOT_FUNC) { if (cond_func->arg_count != 1 || dynamic_cast(cond_func->arguments()[0]) == NULL) return CondID(-2); return ConditionNumberFromComparison(cond_func->arguments()[0], tmp_table, filter_type, and_me_filter, is_or_subtree, true); - } else if (op == common::O_NOT_ALL_FUNC) { + } else if (op == common::Operator::O_NOT_ALL_FUNC) { if (cond_func->arg_count != 1) return CondID(-1); return ConditionNumberFromComparison(cond_func->arguments()[0], tmp_table, filter_type, and_me_filter, is_or_subtree, dynamic_cast(cond_func) == NULL); - } else if (op == common::O_UNKNOWN_FUNC) { + } else if (op == common::Operator::O_UNKNOWN_FUNC) { in_opt = dynamic_cast(cond_func); if (in_opt == NULL || cond_func->arg_count != 2 || in_opt->arguments()[0]->cols() != 1) return CondID(-2); - op = common::O_IN; - } else if (op == common::O_ERROR) + op = common::Operator::O_IN; + } else if (op == common::Operator::O_ERROR) return CondID(-2); // unknown function type - if ((cond_func->arg_count > 3 && op != common::O_IN && op != common::O_NOT_IN)) + if ((cond_func->arg_count > 3 && op != common::Operator::O_IN && op != common::Operator::O_NOT_IN)) return CondID(-1); // argument count error CQTerm terms[3]; @@ -1198,76 +1211,76 @@ CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, Item **args = cond_func->arguments(); for (uint i = 0; i < cond_func->arg_count; i++) { Item *an_arg = UnRef(args[i]); - if ((op == common::O_IN || op == common::O_NOT_IN) && i > 0) { + if ((op == common::Operator::O_IN || op == common::Operator::O_NOT_IN) && i > 0) { if (i == 1 && in_opt) { if (!Item2CQTerm(an_arg, terms[i], tmp_table, filter_type, negative, *in_opt->get_cache(), &op)) return CondID(-1); if (negative) switch (op) { - case common::O_EQ: - op = common::O_NOT_EQ; + case common::Operator::O_EQ: + op = common::Operator::O_NOT_EQ; break; - case common::O_EQ_ALL: - op = common::O_NOT_IN; + case common::Operator::O_EQ_ALL: + op = common::Operator::O_NOT_IN; break; - case common::O_EQ_ANY: - op = common::O_NOT_EQ_ANY; + case common::Operator::O_EQ_ANY: + op = common::Operator::O_NOT_EQ_ANY; break; - case common::O_NOT_EQ: - op = common::O_EQ; + case common::Operator::O_NOT_EQ: + op = common::Operator::O_EQ; break; - case common::O_NOT_EQ_ALL: - op = common::O_EQ_ALL; + case common::Operator::O_NOT_EQ_ALL: + op = common::Operator::O_EQ_ALL; break; - case common::O_NOT_EQ_ANY: - op = common::O_EQ_ANY; + case common::Operator::O_NOT_EQ_ANY: + op = common::Operator::O_EQ_ANY; break; - case common::O_LESS_EQ: - op = common::O_MORE; + case common::Operator::O_LESS_EQ: + op = common::Operator::O_MORE; break; - case common::O_LESS_EQ_ALL: - op = common::O_MORE_ALL; + case common::Operator::O_LESS_EQ_ALL: + op = common::Operator::O_MORE_ALL; break; - case common::O_LESS_EQ_ANY: - op = common::O_MORE_ANY; + case common::Operator::O_LESS_EQ_ANY: + op = common::Operator::O_MORE_ANY; break; - case common::O_MORE_EQ: - op = common::O_LESS; + case common::Operator::O_MORE_EQ: + op = common::Operator::O_LESS; break; - case common::O_MORE_EQ_ALL: - op = common::O_LESS_ALL; + case common::Operator::O_MORE_EQ_ALL: + op = common::Operator::O_LESS_ALL; break; - case common::O_MORE_EQ_ANY: - op = common::O_LESS_ANY; + case common::Operator::O_MORE_EQ_ANY: + op = common::Operator::O_LESS_ANY; break; - case common::O_MORE: - op = common::O_LESS_EQ; + case common::Operator::O_MORE: + op = common::Operator::O_LESS_EQ; break; - case common::O_MORE_ALL: - op = common::O_LESS_EQ_ALL; + case common::Operator::O_MORE_ALL: + op = common::Operator::O_LESS_EQ_ALL; break; - case common::O_MORE_ANY: - op = common::O_LESS_EQ_ANY; + case common::Operator::O_MORE_ANY: + op = common::Operator::O_LESS_EQ_ANY; break; - case common::O_LESS: - op = common::O_MORE_EQ; + case common::Operator::O_LESS: + op = common::Operator::O_MORE_EQ; break; - case common::O_LESS_ALL: - op = common::O_MORE_EQ_ALL; + case common::Operator::O_LESS_ALL: + op = common::Operator::O_MORE_EQ_ALL; break; - case common::O_LESS_ANY: - op = common::O_MORE_EQ_ANY; + case common::Operator::O_LESS_ANY: + op = common::Operator::O_MORE_EQ_ANY; break; - case common::O_LIKE: - op = common::O_NOT_LIKE; + case common::Operator::O_LIKE: + op = common::Operator::O_NOT_LIKE; break; - case common::O_IN: - op = common::O_NOT_IN; + case common::Operator::O_IN: + op = common::Operator::O_NOT_IN; break; - case common::O_NOT_LIKE: - op = common::O_LIKE; + case common::Operator::O_NOT_LIKE: + op = common::Operator::O_LIKE; break; - case common::O_NOT_IN: - op = common::O_IN; + case common::Operator::O_NOT_IN: + op = common::Operator::O_IN; break; default: return CondID(-1); @@ -1283,7 +1296,7 @@ CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, if (!Item2CQTerm(an_arg, terms[i], tmp_table, filter_type, an_arg->type() == Item::SUBSELECT_ITEM ? negative : false, NULL, &op)) return CondID(-1); - if ((op == common::O_LIKE || op == common::O_NOT_LIKE) && + if ((op == common::Operator::O_LIKE || op == common::Operator::O_NOT_LIKE) && !(an_arg->field_type() == MYSQL_TYPE_VARCHAR || an_arg->field_type() == MYSQL_TYPE_STRING || an_arg->field_type() == MYSQL_TYPE_VAR_STRING || an_arg->field_type() == MYSQL_TYPE_BLOB)) { return CondID(-1); // Argument of LIKE is not a string, return to MySQL. @@ -1291,7 +1304,7 @@ CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, } } - if ((op == common::O_IN || op == common::O_NOT_IN) && !in_opt) { + if ((op == common::Operator::O_IN || op == common::Operator::O_NOT_IN) && !in_opt) { AttrID vc; vc.n = VirtualColumnAlreadyExists(tmp_table, vcs, AttrID(terms[0].vc_id)); if (vc.n == common::NULL_VALUE_32) { @@ -1302,8 +1315,8 @@ CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, } if (!and_me_filter) - cq->CreateConds(filter, tmp_table, terms[0], op, terms[1], terms[2], is_or_subtree || filter_type == HAVING_COND, - like_esc); + cq->CreateConds(filter, tmp_table, terms[0], op, terms[1], terms[2], + is_or_subtree || filter_type == CondType::HAVING_COND, like_esc); else { if (is_or_subtree) cq->Or(*and_me_filter, tmp_table, terms[0], op, terms[1], terms[2]); @@ -1340,13 +1353,13 @@ CondID Query::ConditionNumberFromNaked(Item *conds, const TabID &tmp_table, Cond tab_id2expression.insert(std::make_pair(tmp_table, std::make_pair(vc.n, mysql_expression))); } if (!and_me_filter) - cq->CreateConds(filter, tmp_table, naked_col, common::O_NOT_EQ, CQTerm(vc.n), CQTerm(), - is_or_subtree || filter_type == HAVING_COND); + cq->CreateConds(filter, tmp_table, naked_col, common::Operator::O_NOT_EQ, CQTerm(vc.n), CQTerm(), + is_or_subtree || filter_type == CondType::HAVING_COND); else { if (is_or_subtree) - cq->Or(*and_me_filter, tmp_table, naked_col, common::O_NOT_EQ, CQTerm(vc.n), CQTerm()); + cq->Or(*and_me_filter, tmp_table, naked_col, common::Operator::O_NOT_EQ, CQTerm(vc.n), CQTerm()); else - cq->And(*and_me_filter, tmp_table, naked_col, common::O_NOT_EQ, CQTerm(vc.n), CQTerm()); + cq->And(*and_me_filter, tmp_table, naked_col, common::Operator::O_NOT_EQ, CQTerm(vc.n), CQTerm()); filter = *and_me_filter; } return filter; @@ -1420,7 +1433,7 @@ CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filt while ((item = li++) != nullptr) { if (is_transformed[item] == true) continue; create_or_subtree = true; - CondID res = ConditionNumber(item, tmp_table, filter_type, or_cond.get(), true /*OR_SUBTREE*/); + CondID res = ConditionNumber(item, tmp_table, filter_type, or_cond.get(), true /*CondType::OR_SUBTREE*/); if (res.IsInvalid()) return res; if (!or_cond) or_cond.reset(new CondID(res.n)); } @@ -1438,30 +1451,30 @@ CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filt terms[1] = CQTerm(vc.n); if (!or_cond) { if (and_me_filter && !create_or_subtree) { - cq->And(*and_me_filter, tmp_table, terms[0], common::O_IN, terms[1], CQTerm()); + cq->And(*and_me_filter, tmp_table, terms[0], common::Operator::O_IN, terms[1], CQTerm()); c_id = *and_me_filter; and_me_filter = NULL; } else - cq->CreateConds(c_id, tmp_table, terms[0], common::O_IN, terms[1], CQTerm(), - create_or_subtree || filter_type == HAVING_COND); + cq->CreateConds(c_id, tmp_table, terms[0], common::Operator::O_IN, terms[1], CQTerm(), + create_or_subtree || filter_type == CondType::HAVING_COND); or_cond.reset(new CondID(c_id.n)); } else { - cq->Or(*or_cond, tmp_table, terms[0], common::O_IN, terms[1], CQTerm()); + cq->Or(*or_cond, tmp_table, terms[0], common::Operator::O_IN, terms[1], CQTerm()); c_id = *or_cond; } } else { terms[1] = CQTerm(vcv[0]); if (!or_cond) { if (and_me_filter && !create_or_subtree) { - cq->And(*and_me_filter, tmp_table, terms[0], common::O_EQ, terms[1], CQTerm()); + cq->And(*and_me_filter, tmp_table, terms[0], common::Operator::O_EQ, terms[1], CQTerm()); c_id = *and_me_filter; and_me_filter = NULL; } else - cq->CreateConds(c_id, tmp_table, terms[0], common::O_EQ, terms[1], CQTerm(), - create_or_subtree || filter_type == HAVING_COND); + cq->CreateConds(c_id, tmp_table, terms[0], common::Operator::O_EQ, terms[1], CQTerm(), + create_or_subtree || filter_type == CondType::HAVING_COND); or_cond.reset(new CondID(c_id.n)); } else { - cq->Or(*or_cond, tmp_table, terms[0], common::O_EQ, terms[1], CQTerm()); + cq->Or(*or_cond, tmp_table, terms[0], common::Operator::O_EQ, terms[1], CQTerm()); c_id = *or_cond; } } @@ -1474,8 +1487,8 @@ CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filt cq->And(*and_me_filter, tmp_table, cond_id); else if (and_me_filter && is_or_subtree) cq->Or(*and_me_filter, tmp_table, cond_id); - else if (filter_type != HAVING_COND && create_or_subtree && !is_or_subtree) - cq->CreateConds(cond_id, tmp_table, cond_id, create_or_subtree || filter_type == HAVING_COND); + else if (filter_type != CondType::HAVING_COND && create_or_subtree && !is_or_subtree) + cq->CreateConds(cond_id, tmp_table, cond_id, create_or_subtree || filter_type == CondType::HAVING_COND); break; } case Item_func::XOR_FUNC: // we don't handle xor as yet @@ -1492,13 +1505,13 @@ CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filt CQTerm term; if (!Item2CQTerm(arg, term, tmp_table, filter_type)) return CondID(-1); if (!and_me_filter) - cq->CreateConds(cond_id, tmp_table, term, common::O_NOT_EXISTS, CQTerm(), CQTerm(), - is_or_subtree || filter_type == HAVING_COND); + cq->CreateConds(cond_id, tmp_table, term, common::Operator::O_NOT_EXISTS, CQTerm(), CQTerm(), + is_or_subtree || filter_type == CondType::HAVING_COND); else { if (is_or_subtree) - cq->Or(*and_me_filter, tmp_table, term, common::O_NOT_EXISTS, CQTerm(), CQTerm()); + cq->Or(*and_me_filter, tmp_table, term, common::Operator::O_NOT_EXISTS, CQTerm(), CQTerm()); else - cq->And(*and_me_filter, tmp_table, term, common::O_NOT_EXISTS, CQTerm(), CQTerm()); + cq->And(*and_me_filter, tmp_table, term, common::Operator::O_NOT_EXISTS, CQTerm(), CQTerm()); cond_id = *and_me_filter; } } else if (func_type == Item_func::XOR_FUNC) { @@ -1513,13 +1526,13 @@ CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filt CQTerm term; if (!Item2CQTerm(conds, term, tmp_table, filter_type)) return CondID(-1); if (!and_me_filter) { - cq->CreateConds(cond_id, tmp_table, term, common::O_EXISTS, CQTerm(), CQTerm(), - is_or_subtree || filter_type == HAVING_COND); + cq->CreateConds(cond_id, tmp_table, term, common::Operator::O_EXISTS, CQTerm(), CQTerm(), + is_or_subtree || filter_type == CondType::HAVING_COND); } else { if (is_or_subtree) - cq->Or(*and_me_filter, tmp_table, term, common::O_EXISTS, CQTerm(), CQTerm()); + cq->Or(*and_me_filter, tmp_table, term, common::Operator::O_EXISTS, CQTerm(), CQTerm()); else - cq->And(*and_me_filter, tmp_table, term, common::O_EXISTS, CQTerm(), CQTerm()); + cq->And(*and_me_filter, tmp_table, term, common::Operator::O_EXISTS, CQTerm(), CQTerm()); cond_id = *and_me_filter; } } else if (cond_type == Item::FIELD_ITEM || cond_type == Item::SUM_FUNC_ITEM || cond_type == Item::SUBSELECT_ITEM || @@ -1536,7 +1549,7 @@ int Query::BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, cons PrintItemTree("BuildFiler(), item tree passed in 'conds':", conds); if (is_zero_result) { CondID fi; - cq->CreateConds(fi, tmp_table, CQTerm(), common::O_FALSE, CQTerm(), CQTerm(), false); + cq->CreateConds(fi, tmp_table, CQTerm(), common::Operator::O_FALSE, CQTerm(), CQTerm(), false); cond_id = fi; return RCBASE_QUERY_ROUTE; } @@ -1551,7 +1564,7 @@ int Query::BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, cons CondID res = ConditionNumber(conds, tmp_table, filter_type); if (res.IsInvalid()) return RETURN_QUERY_TO_MYSQL_ROUTE; - if (filter_type == HAVING_COND) { + if (filter_type == CondType::HAVING_COND) { cq->CreateConds(res, tmp_table, res, false); } @@ -1658,22 +1671,22 @@ bool Query::ClearSubselectTransformation(common::Operator &oper_for_subselect, I // set the operation type switch (((Item_func *)cond_removed)->functype()) { case Item_func::EQ_FUNC: - oper_for_subselect = common::O_IN; /*common::Operator::common::O_IN;*/ + oper_for_subselect = common::Operator::O_IN; /*common::Operator::common::Operator::O_IN;*/ break; case Item_func::NE_FUNC: - oper_for_subselect = common::O_NOT_EQ; + oper_for_subselect = common::Operator::O_NOT_EQ; break; case Item_func::LT_FUNC: - oper_for_subselect = common::O_LESS; + oper_for_subselect = common::Operator::O_LESS; break; case Item_func::LE_FUNC: - oper_for_subselect = common::O_LESS_EQ; + oper_for_subselect = common::Operator::O_LESS_EQ; break; case Item_func::GT_FUNC: - oper_for_subselect = common::O_MORE; + oper_for_subselect = common::Operator::O_MORE; break; case Item_func::GE_FUNC: - oper_for_subselect = common::O_MORE_EQ; + oper_for_subselect = common::Operator::O_MORE_EQ; break; default: return false; @@ -1784,10 +1797,12 @@ int Query::BuildCondsIfPossible(Item *conds, CondID &cond_id, const TabID &tmp_t conds = UnRef(conds); if (conds) { CondType filter_type = - (join_type == JO_LEFT ? ON_LEFT_FILTER : (join_type == JO_RIGHT ? ON_RIGHT_FILTER : ON_INNER_FILTER)); + (join_type == JoinType::JO_LEFT + ? CondType::ON_LEFT_FILTER + : (join_type == JoinType::JO_RIGHT ? CondType::ON_RIGHT_FILTER : CondType::ON_INNER_FILTER)); // in case of Right join MySQL changes order of tables. Right must be // switched back to left! - if (filter_type == ON_RIGHT_FILTER) filter_type = ON_LEFT_FILTER; + if (filter_type == CondType::ON_RIGHT_FILTER) filter_type = CondType::ON_LEFT_FILTER; DEBUG_ASSERT(PrefixCheck(conds) != TABLE_YET_UNSEEN_INVOLVED && "Table not yet seen was involved in this condition"); diff --git a/storage/stonedb/core/query.h b/storage/stonedb/core/query.h index a28c3c9b0..4f66d1aa5 100644 --- a/storage/stonedb/core/query.h +++ b/storage/stonedb/core/query.h @@ -65,7 +65,7 @@ class Query final { common::Operator *oper_for_subselect = NULL, bool ignore_minmax = false, bool for_subq_in_where = false); TempTable *Preexecute(CompiledQuery &qu, ResultSender *sender, bool display_now = true); int BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, const TabID &tmp_table, CondType filter_type, - bool is_zero_result = false, JoinType join_type = JO_INNER); + bool is_zero_result = false, JoinType join_type = JoinType::JO_INNER); std::multimap> table_alias2index_ptr; diff --git a/storage/stonedb/core/query_compile.cpp b/storage/stonedb/core/query_compile.cpp index 60a27ddcd..5d5c0e8aa 100644 --- a/storage/stonedb/core/query_compile.cpp +++ b/storage/stonedb/core/query_compile.cpp @@ -110,7 +110,7 @@ int Query::FieldUnmysterify(Item *item, const char *&database_name, const char * Item_field *ifield; switch (static_cast(item->type())) { - case Item_sdbfield::SDBFIELD_ITEM: + case static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM): ifield = dynamic_cast(item)->OriginalItem(); if (IsAggregationItem(ifield)) { Item_sum *is = (Item_sum *)ifield; @@ -118,7 +118,7 @@ int Query::FieldUnmysterify(Item *item, const char *&database_name, const char * Item *tmp_item = UnRef(is->get_arg(0)); if (tmp_item->type() == Item::FIELD_ITEM) ifield = (Item_field *)tmp_item; - else if (static_cast(tmp_item->type()) == static_cast(Item_sdbfield::SDBFIELD_ITEM)) + else if (static_cast(tmp_item->type()) == static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM)) ifield = dynamic_cast(tmp_item)->OriginalItem(); else { return RETURN_QUERY_TO_MYSQL_ROUTE; @@ -138,7 +138,7 @@ int Query::FieldUnmysterify(Item *item, const char *&database_name, const char * if (tmp_item->type() == Item::FIELD_ITEM) ifield = (Item_field *)tmp_item; else if (static_cast(tmp_item->type()) == - static_cast(Item_sdbfield::SDBFIELD_ITEM)) /* *CAUTION* comparision of + static_cast(Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM)) /* *CAUTION* comparision of enumerators from different enums */ ifield = dynamic_cast(tmp_item)->OriginalItem(); @@ -361,7 +361,7 @@ int Query::AddJoins(List &join, TabID &tmp_table, std::vector } else { cq->Join(tmp_table, tab); JoinType join_type = GetJoinTypeAndCheckExpr(join_ptr->outer_join, join_ptr->join_cond()); - // if(join_type == JO_LEFT && join_ptr->join_cond() && + // if(join_type == JoinType::JO_LEFT && join_ptr->join_cond() && // dynamic_cast(join_ptr->join_cond())) // return RETURN_QUERY_TO_MYSQL_ROUTE; CondID cond_id; @@ -414,7 +414,7 @@ int Query::AddFields(List &fields, TabID const &tmp_table, bool const grou item = UnRef(item); continue; } - // if ((UnRef(item)->type() == Item_sdbfield::SDBFIELD_ITEM + // if ((UnRef(item)->type() == Item_sdbfield::enumSDBFiledItem::SDBFIELD_ITEM //|| // UnRef(item)->type() == Item_sdbfield::FIELD_ITEM ) && // IsLocalColumn(UnRef(item), tmp_table) @@ -452,7 +452,7 @@ int Query::AddFields(List &fields, TabID const &tmp_table, bool const grou CQTerm term; AttrID at; if (Item2CQTerm(item, term, tmp_table, - /*group_by_clause ? HAVING_FILTER :*/ WHERE_COND) == RETURN_QUERY_TO_MYSQL_ROUTE) + /*group_by_clause ? HAVING_FILTER :*/ CondType::WHERE_COND) == RETURN_QUERY_TO_MYSQL_ROUTE) return RETURN_QUERY_TO_MYSQL_ROUTE; cq->AddColumn(at, tmp_table, term, common::ColOperation::LISTING, item->item_name.ptr(), distinct); field_alias2num[TabIDColAlias(tmp_table.n, item->item_name.ptr())] = at.n; @@ -503,7 +503,7 @@ int Query::AddGroupByFields(ORDER *group_by, const TabID &tmp_table) { else if (item->type() == Item::SUBSELECT_ITEM) { CQTerm term; AttrID at; - if (Item2CQTerm(item, term, tmp_table, WHERE_COND) == RETURN_QUERY_TO_MYSQL_ROUTE) + if (Item2CQTerm(item, term, tmp_table, CondType::WHERE_COND) == RETURN_QUERY_TO_MYSQL_ROUTE) return RETURN_QUERY_TO_MYSQL_ROUTE; cq->AddColumn(at, tmp_table, term, common::ColOperation::GROUP_BY, 0); // field_alias2num[TabIDColAlias(tmp_table.n, @@ -566,10 +566,10 @@ int Query::AddOrderByFields(ORDER *order_by, TabID const &tmp_table, int const g cq->Add_Order(tmp_table, AttrID(vc.second), (order_by->direction != ORDER::ORDER_ASC)); continue; // we can reuse transformation done in case of HAVING - // result = Item2CQTerm(item, my_term, tmp_table, HAVING_COND); + // result = Item2CQTerm(item, my_term, tmp_table, CondType::HAVING_COND); } else { AttrID at; - result = Item2CQTerm(item, my_term, tmp_table, HAVING_COND); + result = Item2CQTerm(item, my_term, tmp_table, CondType::HAVING_COND); if (item->type() == Item::SUBSELECT_ITEM) { // create a materialized column with subsel results for the ordering cq->AddColumn(at, tmp_table, my_term, common::ColOperation::DELAYED, NULL, false); @@ -585,7 +585,7 @@ int Query::AddOrderByFields(ORDER *order_by, TabID const &tmp_table, int const g } } else { - result = Item2CQTerm(item, my_term, tmp_table, WHERE_COND); + result = Item2CQTerm(item, my_term, tmp_table, CondType::WHERE_COND); vc.second = my_term.vc_id; } if (result != RCBASE_QUERY_ROUTE) return RETURN_QUERY_TO_MYSQL_ROUTE; @@ -972,7 +972,7 @@ int Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_list, SELE if (path2num.find(path) == path2num.end()) { path2num[path] = NoTabs(); AddTable(m_conn->GetTableByPath(path)); - STONEDB_LOG(DEBUG, "add query table: %s", path.c_str()); + STONEDB_LOG(LogCtl_Level::DEBUG, "add query table: %s", path.c_str()); } } } @@ -995,13 +995,13 @@ int Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_list, SELE if (!AddOrderByFields(order, tmp_table, group != NULL || sl->join->select_distinct || aggr_used)) throw CompilationError(); CondID cond_id; - if (!BuildConditions(conds, cond_id, cq, tmp_table, WHERE_COND, zero_result)) throw CompilationError(); + if (!BuildConditions(conds, cond_id, cq, tmp_table, CondType::WHERE_COND, zero_result)) throw CompilationError(); - cq->AddConds(tmp_table, cond_id, WHERE_COND); + cq->AddConds(tmp_table, cond_id, CondType::WHERE_COND); cond_id = CondID(); - if (!BuildConditions(having, cond_id, cq, tmp_table, HAVING_COND)) throw CompilationError(); - cq->AddConds(tmp_table, cond_id, HAVING_COND); + if (!BuildConditions(having, cond_id, cq, tmp_table, CondType::HAVING_COND)) throw CompilationError(); + cq->AddConds(tmp_table, cond_id, CondType::HAVING_COND); cq->ApplyConds(tmp_table); } catch (...) { @@ -1012,8 +1012,8 @@ int Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_list, SELE return RETURN_QUERY_TO_MYSQL_ROUTE; } - if (sl->join->select_distinct) cq->Mode(tmp_table, TM_DISTINCT); - if (!ignore_limit && limit_value >= 0) cq->Mode(tmp_table, TM_TOP, offset_value, limit_value); + if (sl->join->select_distinct) cq->Mode(tmp_table, TMParameter::TM_DISTINCT); + if (!ignore_limit && limit_value >= 0) cq->Mode(tmp_table, TMParameter::TM_TOP, offset_value, limit_value); if (sl == selects_list) { prev_result = tmp_table; @@ -1032,7 +1032,8 @@ int Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_list, SELE if (!AddGlobalOrderByFields(global_order, prev_result, col_count)) return RETURN_QUERY_TO_MYSQL_ROUTE; - if (!ignore_limit && global_limit_value >= 0) cq->Mode(prev_result, TM_TOP, global_offset_value, global_limit_value); + if (!ignore_limit && global_limit_value >= 0) + cq->Mode(prev_result, TMParameter::TM_TOP, global_offset_value, global_limit_value); if (res_tab != NULL) *res_tab = prev_result; @@ -1048,13 +1049,13 @@ JoinType Query::GetJoinTypeAndCheckExpr(uint outer_join, Item *on_expr) { JoinType join_type; if ((outer_join & JOIN_TYPE_LEFT) && (outer_join & JOIN_TYPE_RIGHT)) - join_type = JO_FULL; + join_type = JoinType::JO_FULL; else if (outer_join & JOIN_TYPE_LEFT) - join_type = JO_LEFT; + join_type = JoinType::JO_LEFT; else if (outer_join & JOIN_TYPE_RIGHT) - join_type = JO_RIGHT; + join_type = JoinType::JO_RIGHT; else - join_type = JO_INNER; + join_type = JoinType::JO_INNER; return join_type; } @@ -1064,7 +1065,7 @@ bool Query::IsLOJ(List *join) { List_iterator li(*join); while ((join_ptr = li++) != nullptr) { JoinType join_type = GetJoinTypeAndCheckExpr(join_ptr->outer_join, join_ptr->join_cond()); - if (join_ptr->join_cond() && (join_type == JO_LEFT || join_type == JO_RIGHT)) return true; + if (join_ptr->join_cond() && (join_type == JoinType::JO_LEFT || join_type == JoinType::JO_RIGHT)) return true; } return false; } diff --git a/storage/stonedb/core/query_operator.h b/storage/stonedb/core/query_operator.h index c3afd3a51..cc3b599d7 100644 --- a/storage/stonedb/core/query_operator.h +++ b/storage/stonedb/core/query_operator.h @@ -32,7 +32,7 @@ namespace core { class NotEqualQueryOperator : public QueryOperator { public: - NotEqualQueryOperator():QueryOperator(common::O_NOT_EQ, + NotEqualQueryOperator():QueryOperator(common::Operator::O_NOT_EQ, "<>") {} } diff --git a/storage/stonedb/core/rc_attr.cpp b/storage/stonedb/core/rc_attr.cpp index 2f42379d8..d74e1afde 100644 --- a/storage/stonedb/core/rc_attr.cpp +++ b/storage/stonedb/core/rc_attr.cpp @@ -737,11 +737,11 @@ void RCAttr::LockPackForUse(common::PACK_INDEX pn) { sp = rceng->cache.GetOrFetchObject(get_pc(pn), this); } catch (std::exception &e) { dpn->SetPackPtr(0); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); throw e; } catch (...) { dpn->SetPackPtr(0); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); throw; } @@ -1234,7 +1234,7 @@ void RCAttr::UpdateIfIndex(uint64_t row, uint64_t col, const Value &v) { std::string_view okey(vold.val, vold.size()); common::ErrorCode rc = tab->UpdateIndex(current_tx, nkey, okey, row); if (rc == common::ErrorCode::DUPP_KEY || rc == common::ErrorCode::FAILED) { - STONEDB_LOG(DEBUG, "Duplicate entry: %s for primary key", vnew.data()); + STONEDB_LOG(LogCtl_Level::DEBUG, "Duplicate entry: %s for primary key", vnew.data()); throw common::DupKeyException("Duplicate entry: " + vnew + " for primary key"); } } else { // common::PackType::INT @@ -1244,7 +1244,7 @@ void RCAttr::UpdateIfIndex(uint64_t row, uint64_t col, const Value &v) { std::string_view okey(reinterpret_cast(&vold), sizeof(int64_t)); common::ErrorCode rc = tab->UpdateIndex(current_tx, nkey, okey, row); if (rc == common::ErrorCode::DUPP_KEY || rc == common::ErrorCode::FAILED) { - STONEDB_LOG(DEBUG, "Duplicate entry :%" PRId64 " for primary key", vnew); + STONEDB_LOG(LogCtl_Level::DEBUG, "Duplicate entry :%" PRId64 " for primary key", vnew); throw common::DupKeyException("Duplicate entry: " + std::to_string(vnew) + " for primary key"); } } diff --git a/storage/stonedb/core/rc_attr.h b/storage/stonedb/core/rc_attr.h index 954bd2743..b985c53bb 100644 --- a/storage/stonedb/core/rc_attr.h +++ b/storage/stonedb/core/rc_attr.h @@ -89,7 +89,7 @@ class RCAttr final : public mm::TraceableObject, public PhysicalColumn, public P static void Create(const fs::path &path, const AttributeTypeInfo &ati, uint8_t pss, size_t no_rows); - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } void UpdateData(uint64_t row, Value &v); void UpdateIfIndex(uint64_t row, uint64_t col, const Value &v); void Truncate(); @@ -192,7 +192,7 @@ class RCAttr final : public mm::TraceableObject, public PhysicalColumn, public P void Release() override; int AttrNo() const override { return m_cid; } - phys_col_t ColType() const override { return RCATTR; } + phys_col_t ColType() const override { return phys_col_t::RCATTR; } common::PackType GetPackType() const { return pack_type; } PackOntologicalStatus GetPackOntologicalStatus(int pack_no) override; diff --git a/storage/stonedb/core/rc_attr_typeinfo.h b/storage/stonedb/core/rc_attr_typeinfo.h index 33eb4f44b..8c1e9ae60 100644 --- a/storage/stonedb/core/rc_attr_typeinfo.h +++ b/storage/stonedb/core/rc_attr_typeinfo.h @@ -78,7 +78,7 @@ class ATI { class AttributeTypeInfo { public: - enum { + enum class enumATI { NOT_NULL = 0, AUTO_INC = 1, BLOOM_FILTER = 2, @@ -88,9 +88,9 @@ class AttributeTypeInfo { DTCollation collation = DTCollation(), common::PackFmt fmt = common::PackFmt::DEFAULT, bool filter = false) : attrt(attrt), fmt(fmt), precision(precision), scale(scale), collation(collation) { - flag[NOT_NULL] = notnull; - flag[BLOOM_FILTER] = filter; - flag[AUTO_INC] = auto_inc; + flag[static_cast(enumATI::NOT_NULL)] = notnull; + flag[static_cast(enumATI::BLOOM_FILTER)] = filter; + flag[static_cast(enumATI::AUTO_INC)] = auto_inc; // lookup only applies to string type if (attrt != common::CT::STRING && attrt != common::CT::VARCHAR && Lookup()) fmt = common::PackFmt::DEFAULT; @@ -103,8 +103,8 @@ class AttributeTypeInfo { uint Precision() const { return precision; } ushort Scale() const { return scale; } uint CharLen() const { return precision / collation.collation->mbmaxlen; } - bool NotNull() const { return flag[NOT_NULL]; } - bool AutoInc() const { return flag[AUTO_INC]; } + bool NotNull() const { return flag[static_cast(enumATI::NOT_NULL)]; } + bool AutoInc() const { return flag[static_cast(enumATI::AUTO_INC)]; } void SetCollation(const DTCollation &collation) { this->collation = collation; } void SetCollation(CHARSET_INFO *charset_info) { this->collation.set(charset_info); } DTCollation GetCollation() const { return collation; } diff --git a/storage/stonedb/core/rc_mem_table.cpp b/storage/stonedb/core/rc_mem_table.cpp index 03d804068..1ad443f93 100644 --- a/storage/stonedb/core/rc_mem_table.cpp +++ b/storage/stonedb/core/rc_mem_table.cpp @@ -35,7 +35,7 @@ RCMemTable::RCMemTable(const std::string name, const uint32_t mem_id, const uint size_t entry_pos = 0; index::be_store_index(entry_key + entry_pos, mem_id_); entry_pos += sizeof(uint32_t); - index::be_store_byte(entry_key + entry_pos, kInsert); + index::be_store_byte(entry_key + entry_pos, static_cast(RecordType::kInsert)); entry_pos += sizeof(uchar); rocksdb::Slice entry_slice((char *)entry_key, entry_pos); @@ -43,7 +43,7 @@ RCMemTable::RCMemTable(const std::string name, const uint32_t mem_id, const uint size_t upper_pos = 0; index::be_store_index(upper_key + upper_pos, mem_id_); upper_pos += sizeof(uint32_t); - uchar next_key = kInsert + 1; + uchar next_key = static_cast(RecordType::kInsert) + 1; index::be_store_byte(upper_key + upper_pos, next_key); upper_pos += sizeof(uchar); rocksdb::Slice upper_slice((char *)upper_key, upper_pos); @@ -80,7 +80,8 @@ std::shared_ptr RCMemTable::CreateMemTable(std::shared_ptrGetNextIndexId(); tb_mem = std::make_shared(normalized_name, mem_id, cf_id); kvstore->KVWriteMemTableMeta(tb_mem); - STONEDB_LOG(INFO, "Create RowStore: %s, CF ID: %d, RowStore ID: %u", normalized_name.c_str(), cf_id, mem_id); + STONEDB_LOG(LogCtl_Level::INFO, "Create RowStore: %s, CF ID: %d, RowStore ID: %u", normalized_name.c_str(), cf_id, + mem_id); return tb_mem; } @@ -108,7 +109,7 @@ common::ErrorCode RCMemTable::DropMemTable(std::string table_name) { auto tb_mem = kvstore->FindMemTable(normalized_name); if (!tb_mem) return common::ErrorCode::SUCCESS; - STONEDB_LOG(INFO, "Dropping RowStore: %s, CF ID: %d, RowStore ID: %u", normalized_name.c_str(), + STONEDB_LOG(LogCtl_Level::INFO, "Dropping RowStore: %s, CF ID: %d, RowStore ID: %u", normalized_name.c_str(), tb_mem->GetCFHandle()->GetID(), tb_mem->GetMemID()); return kvstore->KVDelMemTableMeta(normalized_name); } @@ -123,7 +124,7 @@ void RCMemTable::InsertRow(std::unique_ptr buf, uint32_t size) { index::KVTransaction kv_trans; index::be_store_index(key + key_pos, mem_id_); key_pos += sizeof(uint32_t); - index::be_store_byte(key + key_pos, kInsert); + index::be_store_byte(key + key_pos, static_cast(RecordType::kInsert)); key_pos += sizeof(uchar); index::be_store_uint64(key + key_pos, row_id); key_pos += sizeof(uint64_t); @@ -139,7 +140,7 @@ void RCMemTable::Truncate(Transaction *tx) { size_t key_pos = 0; index::be_store_index(entry_key + key_pos, mem_id_); key_pos += sizeof(uint32_t); - index::be_store_byte(entry_key + key_pos, RCMemTable::kInsert); + index::be_store_byte(entry_key + key_pos, static_cast(RCMemTable::RecordType::kInsert)); key_pos += sizeof(uchar); rocksdb::Slice entry_slice((char *)entry_key, key_pos); @@ -147,7 +148,7 @@ void RCMemTable::Truncate(Transaction *tx) { size_t upper_pos = 0; index::be_store_index(upper_key + upper_pos, mem_id_); upper_pos += sizeof(uint32_t); - uchar upkey = RCMemTable::kInsert + 1; + uchar upkey = static_cast(RCMemTable::RecordType::kInsert) + 1; index::be_store_byte(upper_key + upper_pos, upkey); upper_pos += sizeof(uchar); rocksdb::Slice upper_slice((char *)upper_key, upper_pos); diff --git a/storage/stonedb/core/rc_mem_table.h b/storage/stonedb/core/rc_mem_table.h index 0757a6834..d6a95d949 100644 --- a/storage/stonedb/core/rc_mem_table.h +++ b/storage/stonedb/core/rc_mem_table.h @@ -32,7 +32,7 @@ class Transaction; class RCMemTable { public: - enum RecordType { RecordType_min, kSchema, kInsert, kUpdate, kDelete, RecordType_max }; + enum class RecordType { RecordType_min, kSchema, kInsert, kUpdate, kDelete, RecordType_max }; RCMemTable() = default; ~RCMemTable() = default; diff --git a/storage/stonedb/core/rc_table.cpp b/storage/stonedb/core/rc_table.cpp index eed39abfc..230b50729 100644 --- a/storage/stonedb/core/rc_table.cpp +++ b/storage/stonedb/core/rc_table.cpp @@ -87,9 +87,9 @@ void RCTable::CreateNew(const std::shared_ptr &opt) { fs::create_symlink(dir, lnk); RCAttr::Create(lnk, opt->atis[idx], opt->pss, 0); - // STONEDB_LOG(INFO, "Column %zu at %s", idx, dir.c_str()); + // STONEDB_LOG(LogCtl_Level::INFO, "Column %zu at %s", idx, dir.c_str()); } - STONEDB_LOG(INFO, "Create table %s, ID = %u", opt->path.c_str(), tid); + STONEDB_LOG(LogCtl_Level::INFO, "Create table %s, ID = %u", opt->path.c_str(), tid); } void RCTable::Alter(const std::string &table_path, std::vector &new_cols, std::vector &old_cols, @@ -141,7 +141,7 @@ void RCTable::Alter(const std::string &table_path, std::vector &new_col fs::create_directory(dir); fs::create_symlink(dir, column_dir); RCAttr::Create(column_dir, Engine::GetAttrTypeInfo(*new_cols[i]), meta.pss, no_objs); - STONEDB_LOG(INFO, "Add column %s at %s", new_cols[i]->field_name, dir.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "Add column %s at %s", new_cols[i]->field_name, dir.c_str()); } { system::StoneDBFile f; @@ -150,7 +150,7 @@ void RCTable::Alter(const std::string &table_path, std::vector &new_col f.Flush(); } fs::resize_file(tmp_dir / common::TABLE_VERSION_FILE, new_cols.size() * sizeof(common::TX_ID)); - STONEDB_LOG(INFO, "Altered table %s", table_path.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "Altered table %s", table_path.c_str()); } void RCTable::Truncate() { @@ -224,7 +224,7 @@ std::vector RCTable::GetAttributesInfo() { info[j].no_nulls = true; else info[j].no_nulls = false; - info[j].actually_unique = (m_attrs[j]->PhysicalColumn::IsDistinct() == common::RS_ALL); + info[j].actually_unique = (m_attrs[j]->PhysicalColumn::IsDistinct() == common::RSValue::RS_ALL); info[j].uncomp_size = m_attrs[j]->ComputeNaturalSize(); info[j].comp_size = m_attrs[j]->CompressedSize(); } @@ -260,7 +260,7 @@ bool RCTable::Verify() { std::stringstream ss; ss << "Error: columns in table " << m_path.string() << " are inconsistent. No. of records for each column:\n"; for (auto &attr : m_attrs) ss << attr->AttrNo() << " : " << attr->NoObj() << std::endl; - STONEDB_LOG(ERROR, "%s", ss.str().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "%s", ss.str().c_str()); } return !ok; } @@ -282,10 +282,10 @@ void RCTable::CommitVersion() { } } catch (std::exception &e) { no_except = false; - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { no_except = false; - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } } if (!no_except) { @@ -303,7 +303,7 @@ void RCTable::CommitVersion() { fs::create_symlink(v, m_path / common::TABLE_VERSION_FILE_TMP, ec); if (ec) { if (ec == std::errc::file_exists) { - STONEDB_LOG(WARN, "delete leftover tmp version file under %s", m_path.c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "delete leftover tmp version file under %s", m_path.c_str()); fs::remove(m_path / common::TABLE_VERSION_FILE_TMP); } fs::create_symlink(v, m_path / common::TABLE_VERSION_FILE_TMP); @@ -317,7 +317,7 @@ void RCTable::CommitVersion() { if (fs::is_symlink(dir)) dir = fs::canonical(fs::read_symlink(dir), m_path); if (!fs::is_directory(dir)) { - STONEDB_LOG(ERROR, "Not a directory: %s", dir.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "Not a directory: %s", dir.c_str()); continue; } @@ -379,7 +379,7 @@ void RCTable::PostCommit() { } void RCTable::Rollback([[maybe_unused]] common::TX_ID xid, bool) { - STONEDB_LOG(INFO, "roll back table %s.%s", db_name.c_str(), m_path.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "roll back table %s.%s", db_name.c_str(), m_path.c_str()); for (auto &attr : m_attrs) attr->Rollback(); } @@ -414,7 +414,7 @@ void RCTable::DisplayRSI() { ss << std::endl; } ss << "-----------------------------------------------------------" << std::endl; - STONEDB_LOG(DEBUG, "%s", ss.str().c_str()); + STONEDB_LOG(LogCtl_Level::DEBUG, "%s", ss.str().c_str()); } RCTable::Iterator::Iterator(RCTable &table, std::shared_ptr filter) @@ -554,7 +554,7 @@ void RCTable::FillRowByRowid(TABLE *table, int64_t obj) { void RCTable::LoadDataInfile(system::IOParameters &iop) { if (iop.LoadDelayed() && GetID() != iop.TableID()) { throw common::SDBError(common::ErrorCode::DATA_ERROR, "Invalid table ID(" + std::to_string(GetID()) + "/" + - std::to_string(iop.TableID()) + "): " + m_path.string()); + std::to_string(iop.TableID()) + "): " + m_path.string()); } FunctionExecutor fe(std::bind(&RCTable::LockPackInfoForUse, this), std::bind(&RCTable::UnlockPackInfoFromUse, this)); @@ -709,7 +709,7 @@ int RCTable::Insert(TABLE *table) { } if (tab->InsertIndex(current_tx, fields, NoObj()) == common::ErrorCode::DUPP_KEY) { - STONEDB_LOG(INFO, "Insert duplicate key on row %d", NoObj() - 1); + STONEDB_LOG(LogCtl_Level::INFO, "Insert duplicate key on row %d", NoObj() - 1); return HA_ERR_FOUND_DUPP_KEY; } } @@ -754,7 +754,7 @@ uint64_t RCTable::ProceedNormal(system::IOParameters &iop) { if (no_loaded_rows > 0 && mysql_bin_log.is_open()) if (binlog_load_query_log_event(iop) != 0) { - STONEDB_LOG(ERROR, "Write load binlog fail!"); + STONEDB_LOG(LogCtl_Level::ERROR, "Write load binlog fail!"); throw common::FormatException("Write load binlog fail!"); } timer.Print(__PRETTY_FUNCTION__); @@ -1077,7 +1077,8 @@ int RCTable::binlog_insert2load_block(std::vector &vcs, uint case common::CT::TIME_N: case common::CT::UNK: default: - throw common::Exception("Unsupported StoneDB Type " + std::to_string(m_attrs[att]->TypeName())); + throw common::Exception("Unsupported StoneDB Type " + + std::to_string(static_cast(m_attrs[att]->TypeName()))); break; } } @@ -1202,7 +1203,7 @@ class DelayedInsertParser final { } if (index_table->InsertIndex(current_tx, fields, start_row + row_idx) == common::ErrorCode::DUPP_KEY) { - STONEDB_LOG(DEBUG, "Delay insert discard this row for duplicate key"); + STONEDB_LOG(LogCtl_Level::DEBUG, "Delay insert discard this row for duplicate key"); return common::ErrorCode::DUPP_KEY; } return common::ErrorCode::SUCCESS; @@ -1243,7 +1244,7 @@ uint64_t RCTable::ProcessDelayed(system::IOParameters &iop) { if (no_loaded_rows > 0 && mysql_bin_log.is_open()) if (binlog_insert2load_log_event(iop) != 0) { - STONEDB_LOG(ERROR, "Write insert to load binlog fail!"); + STONEDB_LOG(LogCtl_Level::ERROR, "Write insert to load binlog fail!"); throw common::FormatException("Write insert to load binlog fail!"); } @@ -1269,7 +1270,7 @@ int RCTable::MergeMemTable(system::IOParameters &iop) { uint32_t mem_id = m_mem_table->GetMemID(); index::be_store_index(entry_key + key_pos, mem_id); key_pos += sizeof(uint32_t); - index::be_store_byte(entry_key + key_pos, RCMemTable::kInsert); + index::be_store_byte(entry_key + key_pos, static_cast(RCMemTable::RecordType::kInsert)); key_pos += sizeof(uchar); rocksdb::Slice entry_slice((char *)entry_key, key_pos); @@ -1277,7 +1278,7 @@ int RCTable::MergeMemTable(system::IOParameters &iop) { size_t upper_pos = 0; index::be_store_index(upper_key + upper_pos, mem_id); upper_pos += sizeof(uint32_t); - uchar upkey = RCMemTable::kInsert + 1; + uchar upkey = static_cast(RCMemTable::RecordType::kInsert) + 1; index::be_store_byte(upper_key + upper_pos, upkey); upper_pos += sizeof(uchar); rocksdb::Slice upper_slice((char *)upper_key, upper_pos); @@ -1332,17 +1333,18 @@ int RCTable::MergeMemTable(system::IOParameters &iop) { if (no_loaded_rows > 0 && mysql_bin_log.is_open()) if (binlog_insert2load_log_event(iop) != 0) { - STONEDB_LOG(ERROR, "Write insert to load binlog fail!"); + STONEDB_LOG(LogCtl_Level::ERROR, "Write insert to load binlog fail!"); throw common::FormatException("Write insert to load binlog fail!"); } if (t2.tv_sec - t1.tv_sec > 15) { - STONEDB_LOG(WARN, "Latency of rowstore %s larger than 15s, compact manually.", share->Path().c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "Latency of rowstore %s larger than 15s, compact manually.", share->Path().c_str()); kvstore->GetRdb()->CompactRange(rocksdb::CompactRangeOptions(), m_mem_table->GetCFHandle(), nullptr, nullptr); } if ((t3.tv_sec - t2.tv_sec > 15) && index_table) { - STONEDB_LOG(WARN, "Latency of index table %s larger than 15s, compact manually.", share->Path().c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "Latency of index table %s larger than 15s, compact manually.", + share->Path().c_str()); kvstore->GetRdb()->CompactRange(rocksdb::CompactRangeOptions(), index_table->m_rdbkey->get_cf(), nullptr, nullptr); } diff --git a/storage/stonedb/core/rcattr_exeq_rs.cpp b/storage/stonedb/core/rcattr_exeq_rs.cpp index 4af9b336b..329682379 100644 --- a/storage/stonedb/core/rcattr_exeq_rs.cpp +++ b/storage/stonedb/core/rcattr_exeq_rs.cpp @@ -41,10 +41,10 @@ uint Int64StrLen(int64_t x) { // NOTE: similar code is in vcolumn::VirtualColumnBase::DoRoughCheck common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_nulls_possible) { - if (d.op == common::O_FALSE) - return common::RS_NONE; - else if (d.op == common::O_TRUE) - return common::RS_ALL; + if (d.op == common::Operator::O_FALSE) + return common::RSValue::RS_NONE; + else if (d.op == common::Operator::O_TRUE) + return common::RSValue::RS_ALL; // TODO: implement RoughCheck CMAP for utf8 if (GetPackType() == common::PackType::STR && types::RequiresUTFConversions(d.GetCollation()) && d.GetCollation().collation != Type().GetCollation().collation) { @@ -53,40 +53,41 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null // this function should be executed earlier auto const &dpn(get_dpn(pack)); if (dpn.NullOnly()) { // all objects are null - if (d.op == common::O_IS_NULL) - return common::RS_ALL; + if (d.op == common::Operator::O_IS_NULL) + return common::RSValue::RS_ALL; else - return common::RS_NONE; + return common::RSValue::RS_NONE; } } - return common::RS_SOME; + return common::RSValue::RS_SOME; } if (d.IsType_AttrValOrAttrValVal()) { - if (!d.encoded) return common::RS_SOME; + if (!d.encoded) return common::RSValue::RS_SOME; vcolumn::VirtualColumn *vc1 = d.val1.vc; static MIIterator const mit(NULL, pss); LoadPackInfo(); // just in case, although the condition was encoded and // this function should be executed earlier auto const &dpn(get_dpn(pack)); if (dpn.NullOnly()) { // all objects are null - if (d.op == common::O_IS_NULL) - return common::RS_ALL; + if (d.op == common::Operator::O_IS_NULL) + return common::RSValue::RS_ALL; else - return common::RS_NONE; + return common::RSValue::RS_NONE; } - if (d.op == common::O_IS_NULL || d.op == common::O_NOT_NULL) { + if (d.op == common::Operator::O_IS_NULL || d.op == common::Operator::O_NOT_NULL) { if (dpn.nn == 0 && !additional_nulls_possible) { - if (d.op == common::O_IS_NULL) - return common::RS_NONE; + if (d.op == common::Operator::O_IS_NULL) + return common::RSValue::RS_NONE; else - return common::RS_ALL; + return common::RSValue::RS_ALL; } - return common::RS_SOME; - } else if ((d.op == common::O_LIKE || d.op == common::O_NOT_LIKE) && GetPackType() == common::PackType::STR) { + return common::RSValue::RS_SOME; + } else if ((d.op == common::Operator::O_LIKE || d.op == common::Operator::O_NOT_LIKE) && + GetPackType() == common::PackType::STR) { DEBUG_ASSERT(vc1->IsConst()); types::BString pat; vc1->GetValueString(pat, mit); - common::RSValue res = common::RS_SOME; + common::RSValue res = common::RSValue::RS_SOME; // here: check min, max uint pattern_prefix = 0; // e.g. "ab_cd_e%f" -> 7 uint pattern_fixed_prefix = 0; // e.g. "ab_cd_e%f" -> 2 @@ -101,20 +102,20 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null if ((pattern_fixed_prefix > 0) && types::BString(pat.val, pattern_fixed_prefix).LessEqThanMaxUTF(dpn.max_s, Type().GetCollation()) == false) - res = common::RS_NONE; + res = common::RSValue::RS_NONE; - if (pattern_fixed_prefix > GetActualSize(pack)) res = common::RS_NONE; + if (pattern_fixed_prefix > GetActualSize(pack)) res = common::RSValue::RS_NONE; pack_prefix = GetPrefixLength(pack); - if (res == common::RS_SOME && pack_prefix > 0 && + if (res == common::RSValue::RS_SOME && pack_prefix > 0 && pattern_fixed_prefix <= pack_prefix // special case: "xyz%" and the // pack prefix is at least 3 && pattern_fixed_prefix + 1 == pat.len && pat[pattern_fixed_prefix] == '%') { if (d.GetCollation().collation->coll->strnncoll(d.GetCollation().collation, (const uchar *)pat.val, pattern_fixed_prefix, (const uchar *)dpn.min_s, pattern_fixed_prefix, 0) == 0) - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else - res = common::RS_NONE; // prefix and pattern are different + res = common::RSValue::RS_NONE; // prefix and pattern are different } } else { @@ -124,21 +125,21 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null if ((pattern_fixed_prefix > 0) && types::BString(pat.val, pattern_fixed_prefix).LessEqThanMax(dpn.max_s) == false) // val_t==NULL means +/-infty - res = common::RS_NONE; - if (pattern_fixed_prefix > GetActualSize(pack)) res = common::RS_NONE; + res = common::RSValue::RS_NONE; + if (pattern_fixed_prefix > GetActualSize(pack)) res = common::RSValue::RS_NONE; pack_prefix = GetPrefixLength(pack); - if (res == common::RS_SOME && pack_prefix > 0 && + if (res == common::RSValue::RS_SOME && pack_prefix > 0 && pattern_fixed_prefix <= pack_prefix // special case: "xyz%" and the // pack prefix is at least 3 && pattern_fixed_prefix + 1 == pat.len && pat[pattern_fixed_prefix] == '%') { if (std::memcmp(pat.val, dpn.min_s, pattern_fixed_prefix) == 0) // pattern is equal to the prefix - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else - res = common::RS_NONE; // prefix and pattern are different + res = common::RSValue::RS_NONE; // prefix and pattern are different } } - if (res == common::RS_SOME && std::min(pattern_prefix, pack_prefix) < pat.len && + if (res == common::RSValue::RS_SOME && std::min(pattern_prefix, pack_prefix) < pat.len && !types::RequiresUTFConversions(d.GetCollation())) { types::BString pattern_for_cmap; // note that cmap is shifted by a common prefix! if (pattern_prefix > pack_prefix) @@ -151,37 +152,38 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null if (!(pattern_for_cmap.len == 1 && pattern_for_cmap[0] == '%')) { // i.e. "%" => all is matching if (auto sp = GetFilter_CMap()) res = sp->IsLike(pattern_for_cmap, pack, d.like_esc); } else - res = common::RS_ALL; + res = common::RSValue::RS_ALL; } - if (d.op == common::O_NOT_LIKE) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_LIKE) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } - if ((dpn.nn != 0 || additional_nulls_possible) && res == common::RS_ALL) res = common::RS_SOME; + if ((dpn.nn != 0 || additional_nulls_possible) && res == common::RSValue::RS_ALL) res = common::RSValue::RS_SOME; return res; - } else if ((d.op == common::O_IN || d.op == common::O_NOT_IN) && GetPackType() == common::PackType::STR) { + } else if ((d.op == common::Operator::O_IN || d.op == common::Operator::O_NOT_IN) && + GetPackType() == common::PackType::STR) { DEBUG_ASSERT(dynamic_cast(vc1)); vcolumn::MultiValColumn *mvc(static_cast(vc1)); uint pack_prefix = GetPrefixLength(pack); - common::RSValue res = common::RS_SOME; + common::RSValue res = common::RSValue::RS_SOME; if ((mvc->IsConst()) && (mvc->NoValues(mit) > 0 && mvc->NoValues(mit) < 64) && !types::RequiresUTFConversions(d.GetCollation())) { if (auto sp = GetFilter_CMap()) { - res = common::RS_NONE; // TODO: get rid with the iterator below + res = common::RSValue::RS_NONE; // TODO: get rid with the iterator below for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); - (it != end) && (res == common::RS_NONE); ++it) { + (it != end) && (res == common::RSValue::RS_NONE); ++it) { types::BString v1 = it->GetString(); if (pack_prefix <= v1.len) { if (pack_prefix == 0 || std::memcmp(v1.val, dpn.min_s, pack_prefix) == 0) { size_t len = v1.len - pack_prefix; types::BString v(len <= 0 ? "" : v1.val + pack_prefix, (int)len); - if (v1.len == pack_prefix || sp->IsValue(v, v, pack) != common::RS_NONE) + if (v1.len == pack_prefix || sp->IsValue(v, v, pack) != common::RSValue::RS_NONE) // suspected, if any value is possible (due to the prefix or // CMAP) - res = common::RS_SOME; + res = common::RSValue::RS_SOME; } } } @@ -189,26 +191,27 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null } // add bloom filter for in/not in - if (res == common::RS_SOME && (mvc->IsConst()) && (mvc->NoValues(mit) > 0 && mvc->NoValues(mit) < 64)) { + if (res == common::RSValue::RS_SOME && (mvc->IsConst()) && (mvc->NoValues(mit) > 0 && mvc->NoValues(mit) < 64)) { if (auto sp = GetFilter_Bloom()) { - res = common::RS_NONE; + res = common::RSValue::RS_NONE; for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); - (it != end) && (res == common::RS_NONE); ++it) { + (it != end) && (res == common::RSValue::RS_NONE); ++it) { types::BString v = it->GetString(); - if (sp->IsValue(v, v, pack) != common::RS_NONE) res = common::RS_SOME; + if (sp->IsValue(v, v, pack) != common::RSValue::RS_NONE) res = common::RSValue::RS_SOME; } } } - if (d.op == common::O_NOT_IN) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_IN) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } - if (res == common::RS_ALL && (dpn.nn > 0 || additional_nulls_possible)) res = common::RS_SOME; + if (res == common::RSValue::RS_ALL && (dpn.nn > 0 || additional_nulls_possible)) res = common::RSValue::RS_SOME; return res; - } else if ((d.op == common::O_IN || d.op == common::O_NOT_IN) && (GetPackType() == common::PackType::INT)) { + } else if ((d.op == common::Operator::O_IN || d.op == common::Operator::O_NOT_IN) && + (GetPackType() == common::PackType::INT)) { if (vc1->IsConst()) { DEBUG_ASSERT(dynamic_cast(vc1)); vcolumn::MultiValColumn *mvc(static_cast(vc1)); @@ -216,7 +219,7 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null types::RCNum rcn_min = mvc->GetSetMin(mit); types::RCNum rcn_max = mvc->GetSetMax(mit); if (rcn_min.IsNull() || rcn_max.IsNull()) // cannot determine min/max - return common::RS_SOME; + return common::RSValue::RS_SOME; if (Type().IsLookup()) { v1 = rcn_min.GetValueInt64(); v2 = rcn_max.GetValueInt64(); @@ -226,28 +229,28 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null v2 = EncodeValue64(&rcn_max, v2_rounded); } - common::RSValue res = common::RS_SOME; + common::RSValue res = common::RSValue::RS_SOME; if (ATI::IsRealType(TypeName())) return res; // real values not implemented yet if (v1 > dpn.max_i || v2 < dpn.min_i) { - res = common::RS_NONE; // calculate as for common::O_IN and then take - // common::O_NOT_IN into account + res = common::RSValue::RS_NONE; // calculate as for common::Operator::O_IN and then take + // common::Operator::O_NOT_IN into account } else if (dpn.min_i == dpn.max_i) { types::RCValueObject rcvo(ATI::IsDateTimeType(TypeName()) ? types::RCValueObject(types::RCDateTime(dpn.min_i, TypeName())) : types::RCValueObject(types::RCNum(dpn.min_i, Type().GetScale()))); - res = (mvc->Contains(mit, *rcvo) != false) ? common::RS_ALL : common::RS_NONE; + res = (mvc->Contains(mit, *rcvo) != false) ? common::RSValue::RS_ALL : common::RSValue::RS_NONE; } else { if (auto sp = GetFilter_Hist()) res = sp->IsValue(v1, v2, pack, dpn.min_i, dpn.max_i); - if (res == common::RS_ALL) // v1, v2 are just a boundary, not - // continuous interval - res = common::RS_SOME; + if (res == common::RSValue::RS_ALL) // v1, v2 are just a boundary, not + // continuous interval + res = common::RSValue::RS_SOME; } - if (res == common::RS_SOME && (mvc->NoValues(mit) > 0 && mvc->NoValues(mit) < 64)) { + if (res == common::RSValue::RS_SOME && (mvc->NoValues(mit) > 0 && mvc->NoValues(mit) < 64)) { bool v_rounded = false; - res = common::RS_NONE; + res = common::RSValue::RS_NONE; int64_t v; // TODO: get rid with the iterator below for (vcolumn::MultiValColumn::Iterator it = mvc->begin(mit), end = mvc->end(mit); - (it != end) && (res == common::RS_NONE); ++it) { + (it != end) && (res == common::RSValue::RS_NONE); ++it) { if (!Type().IsLookup()) { // otherwise it will be decoded to text v = EncodeValue64(it->GetValue().Get(), v_rounded); } else @@ -255,31 +258,31 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null if (!v_rounded) { auto sp = GetFilter_Hist(); if ((!sp && v <= dpn.max_i && v >= dpn.min_i) || - (sp && sp->IsValue(v, v, pack, dpn.min_i, dpn.max_i) != common::RS_NONE)) { + (sp && sp->IsValue(v, v, pack, dpn.min_i, dpn.max_i) != common::RSValue::RS_NONE)) { // suspected, if any value is possible - res = common::RS_SOME; // note: v_rounded means that this real - // value could not match this pack + res = common::RSValue::RS_SOME; // note: v_rounded means that this real + // value could not match this pack break; } } } } - if (d.op == common::O_NOT_IN) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_IN) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } - if (res == common::RS_ALL && (dpn.nn > 0 || additional_nulls_possible)) res = common::RS_SOME; + if (res == common::RSValue::RS_ALL && (dpn.nn > 0 || additional_nulls_possible)) res = common::RSValue::RS_SOME; return res; } } else if (GetPackType() == common::PackType::STR) { // Note: text operations as // common::PackType::INT calculated as // IN or below - DEBUG_ASSERT(d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN); + DEBUG_ASSERT(d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN); vcolumn::VirtualColumn *vc2 = d.val2.vc; - common::RSValue res = common::RS_SOME; + common::RSValue res = common::RSValue::RS_SOME; uint pack_prefix = GetPrefixLength(pack); uint val_prefix = 0; types::BString vmin; @@ -287,7 +290,7 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null vc1->GetValueString(vmin, mit); vc2->GetValueString(vmax, mit); if (vmin.IsNull() && vmax.IsNull()) // comparing with null - always false - return common::RS_NONE; + return common::RSValue::RS_NONE; while (vmin.val && vmax.val && val_prefix < vmin.len && val_prefix < vmax.len && vmin[val_prefix] == vmax[val_prefix]) val_prefix++; // Common prefix for values. It is a value length in case @@ -295,54 +298,54 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null // check min, max // TODO UTF8: check PREFIX handling if (val_prefix > GetActualSize(pack)) { // value to be found is longer than texts in the pack - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else if ((vmax.val && vmax.GreaterEqThanMinUTF(dpn.min_s, Type().GetCollation()) == false) || (vmin.val && vmin.LessEqThanMaxUTF(dpn.max_s, Type().GetCollation()) == false)) // val_t==NULL means +/-infty - res = common::RS_NONE; + res = common::RSValue::RS_NONE; else if ((vmin.val == NULL || vmin.GreaterEqThanMinUTF(dpn.min_s, Type().GetCollation()) == false) && (vmax.val == NULL || vmax.LessEqThanMaxUTF(dpn.max_s, Type().GetCollation()) == false)) // val_t==NULL means +/-infty - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else if (pack_prefix == GetActualSize(pack) && vmin == vmax) { // exact case for short texts if (vmin.GreaterEqThanMinUTF(dpn.min_s, Type().GetCollation()) && vmin.LessEqThanMaxUTF(dpn.min_s, Type().GetCollation())) - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } - if (res == common::RS_SOME && vmin.len >= pack_prefix && vmax.len >= pack_prefix && + if (res == common::RSValue::RS_SOME && vmin.len >= pack_prefix && vmax.len >= pack_prefix && !types::RequiresUTFConversions(d.GetCollation())) { vmin += pack_prefix; // redefine - shift by a common prefix vmax += pack_prefix; if (auto sp = GetFilter_CMap()) { res = sp->IsValue(vmin, vmax, pack); - if (d.sharp && res == common::RS_ALL) res = common::RS_SOME; // simplified version + if (d.sharp && res == common::RSValue::RS_ALL) res = common::RSValue::RS_SOME; // simplified version } vmin -= pack_prefix; vmax -= pack_prefix; } - if (res == common::RS_SOME) { + if (res == common::RSValue::RS_SOME) { if (auto sp = GetFilter_Bloom()) { res = sp->IsValue(vmin, vmax, pack); } } - if (d.op == common::O_NOT_BETWEEN) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_BETWEEN) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } - if ((dpn.nn != 0 || additional_nulls_possible) && res == common::RS_ALL) { - res = common::RS_SOME; + if ((dpn.nn != 0 || additional_nulls_possible) && res == common::RSValue::RS_ALL) { + res = common::RSValue::RS_SOME; } return res; } else if (GetPackType() == common::PackType::INT) { - DEBUG_ASSERT(d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN); - // common::O_BETWEEN or common::O_NOT_BETWEEN + DEBUG_ASSERT(d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN); + // common::Operator::O_BETWEEN or common::Operator::O_NOT_BETWEEN int64_t v1 = d.val1.vc->GetValueInt64(mit); // 1-level values; note that these // values were already transformed in // EncodeCondition @@ -354,70 +357,77 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null if (v1 == *(int64_t *)&common::MINUS_INF_DBL) v1 = dpn.min_i; if (v2 == *(int64_t *)&common::PLUS_INF_DBL) v2 = dpn.max_i; } - common::RSValue res = RoughCheckBetween(pack, v1, - v2); // calculate as for common::O_BETWEEN and then consider negation - if (d.op == common::O_NOT_BETWEEN) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) { - res = common::RS_ALL; + common::RSValue res = + RoughCheckBetween(pack, v1, + v2); // calculate as for common::Operator::O_BETWEEN and then consider negation + if (d.op == common::Operator::O_NOT_BETWEEN) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) { + res = common::RSValue::RS_ALL; } } - if (res == common::RS_ALL && (dpn.nn != 0 || additional_nulls_possible)) { - res = common::RS_SOME; + if (res == common::RSValue::RS_ALL && (dpn.nn != 0 || additional_nulls_possible)) { + res = common::RSValue::RS_SOME; } return res; } } else { - if (!d.encoded) return common::RS_SOME; - vcolumn::SingleColumn *sc = (d.val1.vc->IsSingleColumn() ? static_cast(d.val1.vc) : NULL); + if (!d.encoded) return common::RSValue::RS_SOME; + vcolumn::SingleColumn *sc = + (static_cast(d.val1.vc->IsSingleColumn()) ? static_cast(d.val1.vc) : NULL); RCAttr *sec = NULL; if (sc) sec = dynamic_cast(sc->GetPhysical()); - if (d.IsType_AttrAttr() && d.op != common::O_BETWEEN && d.op != common::O_NOT_BETWEEN && sec) { - common::RSValue res = common::RS_SOME; + if (d.IsType_AttrAttr() && d.op != common::Operator::O_BETWEEN && d.op != common::Operator::O_NOT_BETWEEN && sec) { + common::RSValue res = common::RSValue::RS_SOME; // special cases, not implemented yet: if ((TypeName() != sec->TypeName() && // Exceptions: !(ATI::IsDateTimeType(TypeName()) && ATI::IsDateTimeType(sec->TypeName())) && !(ATI::IsIntegerType(TypeName()) && ATI::IsIntegerType(sec->TypeName()))) || Type().GetScale() != sec->Type().GetScale() || Type().IsLookup() || sec->Type().IsLookup()) - return common::RS_SOME; + return common::RSValue::RS_SOME; LoadPackInfo(); sec->LoadPackInfo(); auto const &dpn(get_dpn(pack)); auto const &secDpn(sec->get_dpn(pack)); - if (d.op != common::O_IN && d.op != common::O_NOT_IN) { + if (d.op != common::Operator::O_IN && d.op != common::Operator::O_NOT_IN) { if (GetPackType() == common::PackType::INT && !ATI::IsRealType(TypeName())) { int64_t v1min = dpn.min_i; int64_t v1max = dpn.max_i; int64_t v2min = secDpn.min_i; int64_t v2max = secDpn.max_i; - if (v1min >= v2max) { // NOTE: only common::O_MORE, common::O_LESS - // and common::O_EQ are analyzed here, the rest - // of operators will be taken into account - // later (treated as negations) - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (v1min >= v2max) { // NOTE: only common::Operator::O_MORE, common::Operator::O_LESS + // and common::Operator::O_EQ are analyzed here, the rest + // of operators will be taken into account + // later (treated as negations) + if (d.op == common::Operator::O_LESS || + d.op == common::Operator::O_MORE_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (v1min > v2max) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_MORE || d.op == common::Operator::O_LESS_EQ) + res = common::RSValue::RS_ALL; } } if (v1max <= v2min) { - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (d.op == common::Operator::O_MORE || + d.op == common::Operator::O_LESS_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (v1max < v2min) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_LESS || d.op == common::Operator::O_MORE_EQ) + res = common::RSValue::RS_ALL; } } - if (res == common::RS_SOME && - (d.op == common::O_EQ || d.op == common::O_NOT_EQ)) { // the second case will be negated soon + if (res == common::RSValue::RS_SOME && + (d.op == common::Operator::O_EQ || + d.op == common::Operator::O_NOT_EQ)) { // the second case will be negated soon if (v1min == v1max && v2min == v2max) { if (v1min == v2min) - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else if (v1min == v1max) { auto sp2 = sec->GetFilter_Hist(); res = sp2->IsValue(v1min, v1max, pack, v2min, v2max); @@ -430,15 +440,16 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null // check intersection possibility on histograms if (sp && sp2 && (sp->Intersection(pack, v1min, v1max, sp2.get(), pack, v2min, v2max) == false)) - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } } // Now take into account all negations - if (d.op == common::O_NOT_EQ || d.op == common::O_LESS_EQ || d.op == common::O_MORE_EQ) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_EQ || d.op == common::Operator::O_LESS_EQ || + d.op == common::Operator::O_MORE_EQ) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } } else if (GetPackType() == common::PackType::STR) { types::BString v1min(dpn.min_s, Int64StrLen(dpn.min_i), false); @@ -446,38 +457,44 @@ common::RSValue RCAttr::RoughCheck(int pack, Descriptor &d, bool additional_null types::BString v2min(dpn.min_s, Int64StrLen(dpn.min_i), false); types::BString v2max(dpn.max_s, Int64StrLen(dpn.max_i), false); if (CollationStrCmp(d.GetCollation(), v1min, v2max) >= - 0) { // NOTE: only common::O_MORE, common::O_LESS and - // common::O_EQ are analyzed here, the rest of operators + 0) { // NOTE: only common::Operator::O_MORE, common::Operator::O_LESS and + // common::Operator::O_EQ are analyzed here, the rest of operators // will be taken into account later (treated as negations) - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (d.op == common::Operator::O_LESS || + d.op == common::Operator::O_MORE_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (CollationStrCmp(d.GetCollation(), v1min, v2max) > 0) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_MORE || d.op == common::Operator::O_LESS_EQ) + res = common::RSValue::RS_ALL; } } if (CollationStrCmp(d.GetCollation(), v1max, v2min) <= 0) { - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (d.op == common::Operator::O_MORE || + d.op == common::Operator::O_LESS_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (CollationStrCmp(d.GetCollation(), v1max, v2min) < 0) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_LESS || d.op == common::Operator::O_MORE_EQ) + res = common::RSValue::RS_ALL; } } - if (d.op == common::O_NOT_EQ || d.op == common::O_LESS_EQ || d.op == common::O_MORE_EQ) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_EQ || d.op == common::Operator::O_LESS_EQ || + d.op == common::Operator::O_MORE_EQ) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } } } // take nulls into account - if ((dpn.nn != 0 || secDpn.nn != 0 || additional_nulls_possible) && res == common::RS_ALL) res = common::RS_SOME; + if ((dpn.nn != 0 || secDpn.nn != 0 || additional_nulls_possible) && res == common::RSValue::RS_ALL) + res = common::RSValue::RS_SOME; return res; } } - return common::RS_SOME; + return common::RSValue::RS_SOME; } common::RSValue RCAttr::RoughCheck(int pack1, int pack2, Descriptor &d) { @@ -485,12 +502,13 @@ common::RSValue RCAttr::RoughCheck(int pack1, int pack2, Descriptor &d) { vcolumn::VirtualColumn *vc2 = d.val2.vc; // Limitations for now: only the easiest numerical cases - if (vc1 == NULL || vc2 != NULL || d.op != common::O_EQ || pack1 == -1 || pack2 == -1) return common::RS_SOME; + if (vc1 == NULL || vc2 != NULL || d.op != common::Operator::O_EQ || pack1 == -1 || pack2 == -1) + return common::RSValue::RS_SOME; vcolumn::SingleColumn *sc = NULL; - if (vc1->IsSingleColumn()) sc = static_cast(vc1); - if (sc == NULL) return common::RS_SOME; + if (static_cast(vc1->IsSingleColumn())) sc = static_cast(vc1); + if (sc == NULL) return common::RSValue::RS_SOME; RCAttr *sec = dynamic_cast(sc->GetPhysical()); - if (sec == NULL || !Type().IsNumComparable(sec->Type())) return common::RS_SOME; + if (sec == NULL || !Type().IsNumComparable(sec->Type())) return common::RSValue::RS_SOME; LoadPackInfo(); sec->LoadPackInfo(); @@ -499,34 +517,34 @@ common::RSValue RCAttr::RoughCheck(int pack1, int pack2, Descriptor &d) { // return RoughCheckBetween(pack1, *(double*)(&secDpn.min), //*(double*)(&secDpn.max)); common::RSValue r = RoughCheckBetween(pack1, secDpn.min_i, secDpn.max_i); - return r == common::RS_ALL ? common::RS_SOME : r; + return r == common::RSValue::RS_ALL ? common::RSValue::RS_SOME : r; } // check whether any value from the pack may meet the condition "... BETWEEN min // AND max" common::RSValue RCAttr::RoughCheckBetween(int pack, int64_t v1, int64_t v2) { - common::RSValue res = common::RS_SOME; // calculate as for common::O_BETWEEN - // and then consider negation + common::RSValue res = common::RSValue::RS_SOME; // calculate as for common::Operator::O_BETWEEN + // and then consider negation bool is_float = Type().IsFloat(); auto const &dpn(get_dpn(pack)); if (!is_float && (v1 == common::PLUS_INF_64 || v2 == common::MINUS_INF_64)) { - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else if (is_float && (v1 == *(int64_t *)&common::PLUS_INF_DBL || v2 == *(int64_t *)&common::MINUS_INF_DBL)) { - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else if (!is_float && (v1 > dpn.max_i || v2 < dpn.min_i)) { - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else if (is_float && (*(double *)&v1 > dpn.max_d || *(double *)&v2 < dpn.min_d)) { - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else if (!is_float && (v1 <= dpn.min_i && v2 >= dpn.max_i)) { - res = common::RS_ALL; + res = common::RSValue::RS_ALL; } else if (is_float && (*(double *)&v1 <= dpn.min_d && *(double *)&v2 >= dpn.max_d)) { - res = common::RS_ALL; + res = common::RSValue::RS_ALL; } else if ((!is_float && v1 > v2) || (is_float && (*(double *)&v1 > *(double *)&v2))) { - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else { if (auto sp = GetFilter_Hist()) res = sp->IsValue(v1, v2, pack, dpn.min_i, dpn.max_i); - if (res == common::RS_SOME) { + if (res == common::RSValue::RS_SOME) { if (auto sp = GetFilter_Bloom()) { auto vmin = std::to_string(v1); auto vmax = std::to_string(v2); @@ -536,8 +554,8 @@ common::RSValue RCAttr::RoughCheckBetween(int pack, int64_t v1, int64_t v2) { } } } - if (dpn.nn != 0 && res == common::RS_ALL) { - res = common::RS_SOME; + if (dpn.nn != 0 && res == common::RSValue::RS_ALL) { + res = common::RSValue::RS_SOME; } return res; } @@ -556,7 +574,7 @@ int64_t RCAttr::RoughMin(Filter *f, common::RSValue *rf) // f == NULL is treate di.d = DBL_MAX; for (uint p = 0; p < NoPack(); p++) { // minimum of nonempty packs auto const &dpn(get_dpn(p)); - if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RS_NONE)) { + if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RSValue::RS_NONE)) { if (di.d > dpn.min_d) di.i = dpn.min_i; } } @@ -566,7 +584,8 @@ int64_t RCAttr::RoughMin(Filter *f, common::RSValue *rf) // f == NULL is treate res = common::PLUS_INF_64; for (uint p = 0; p < NoPack(); p++) { // minimum of nonempty packs auto const &dpn(get_dpn(p)); - if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RS_NONE) && res > dpn.min_i) res = dpn.min_i; + if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RSValue::RS_NONE) && res > dpn.min_i) + res = dpn.min_i; } if (res == common::PLUS_INF_64) res = common::MINUS_INF_64; // NULLS only } @@ -587,7 +606,7 @@ int64_t RCAttr::RoughMax(Filter *f, common::RSValue *rf) // f == NULL is treate di.d = -(DBL_MAX); for (uint p = 0; p < NoPack(); p++) { // minimum of nonempty packs auto const &dpn(get_dpn(p)); - if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RS_NONE)) { + if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RSValue::RS_NONE)) { if (di.d < dpn.max_d) di.i = dpn.max_i; } } @@ -597,7 +616,8 @@ int64_t RCAttr::RoughMax(Filter *f, common::RSValue *rf) // f == NULL is treate res = common::MINUS_INF_64; for (uint p = 0; p < NoPack(); p++) { // maximum of nonempty packs auto const &dpn(get_dpn(p)); - if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RS_NONE) && res < dpn.max_i) res = dpn.max_i; + if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RSValue::RS_NONE) && res < dpn.max_i) + res = dpn.max_i; } if (res == common::MINUS_INF_64) res = common::PLUS_INF_64; // NULLS only } @@ -627,7 +647,7 @@ std::vector RCAttr::GetListOfDistinctValuesInPack(int pack) { list_vals.push_back(dpn.min_i); list_vals.push_back(dpn.max_i); for (int64_t v = dpn.min_i + 1; v < dpn.max_i; v++) { - if (sp->IsValue(v, v, pack, dpn.min_i, dpn.max_i) != common::RS_NONE) list_vals.push_back(v); + if (sp->IsValue(v, v, pack, dpn.min_i, dpn.max_i) != common::RSValue::RS_NONE) list_vals.push_back(v); } if (NoNulls() > 0) list_vals.push_back(common::NULL_VALUE_64); return list_vals; @@ -674,14 +694,15 @@ uint64_t RCAttr::ApproxDistinctVals(bool incl_nulls, Filter *f, common::RSValue values_present.Reset(); for (uint p = 0; p < NoPack(); p++) { auto const &dpn(get_dpn(p)); - if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RS_NONE) && dpn.min_i <= dpn.max_i) { + if ((f == NULL || !f->IsEmpty(p)) && (rf == NULL || rf[p] != common::RSValue::RS_NONE) && + dpn.min_i <= dpn.max_i) { // dpn.min <= dpn.max is not true e.g. when the pack contains nulls // only if (auto sp = GetFilter_Hist(); sp && sp->ExactMode(dpn.min_i, dpn.max_i)) { values_present.Set(dpn.min_i - cur_min); values_present.Set(dpn.max_i - cur_min); for (int64_t v = dpn.min_i + 1; v < dpn.max_i; v++) - if (sp->IsValue(v, v, p, dpn.min_i, dpn.max_i) != common::RS_NONE) { + if (sp->IsValue(v, v, p, dpn.min_i, dpn.max_i) != common::RSValue::RS_NONE) { values_present.Set(v - cur_min); } } else { // no Histogram or not exact: mark the whole interval @@ -754,7 +775,7 @@ uint64_t RCAttr::ExactDistinctVals(Filter *f) // provide the exact number of di values_present.Set(dpn.min_i - cur_min); values_present.Set(dpn.max_i - cur_min); for (int64_t v = dpn.min_i + 1; v < dpn.max_i; v++) - if (sp->IsValue(v, v, p, dpn.min_i, dpn.max_i) != common::RS_NONE) { + if (sp->IsValue(v, v, p, dpn.min_i, dpn.max_i) != common::RSValue::RS_NONE) { values_present.Set(v - cur_min); } } else { // no Histogram or not exact: cannot calculate exact @@ -969,7 +990,7 @@ void RCAttr::DisplayAttrStats(Filter *f) // filter is for # of objects ss << "----------------------------------------------------------------------" "---------" << std::endl; - STONEDB_LOG(DEBUG, ss.str().c_str()); + STONEDB_LOG(LogCtl_Level::DEBUG, ss.str().c_str()); } } // namespace core } // namespace stonedb diff --git a/storage/stonedb/core/rcattr_exqp.cpp b/storage/stonedb/core/rcattr_exqp.cpp index 4d77324dd..af3b9690a 100644 --- a/storage/stonedb/core/rcattr_exqp.cpp +++ b/storage/stonedb/core/rcattr_exqp.cpp @@ -39,14 +39,14 @@ namespace core { void RCAttr::EvaluatePack(MIUpdatingIterator &mit, int dim, Descriptor &d) { MEASURE_FET("RCAttr::EvaluatePack(...)"); ASSERT(d.encoded, "Descriptor is not encoded!"); - if (d.op == common::O_FALSE) { + if (d.op == common::Operator::O_FALSE) { mit.ResetCurrentPack(); mit.NextPackrow(); - } else if (d.op == common::O_TRUE) + } else if (d.op == common::Operator::O_TRUE) mit.NextPackrow(); - else if (d.op == common::O_NOT_NULL) + else if (d.op == common::Operator::O_NOT_NULL) EvaluatePack_NotNull(mit, dim); - else if (d.op == common::O_IS_NULL) + else if (d.op == common::Operator::O_IS_NULL) EvaluatePack_IsNull(mit, dim); else if (d.val1.vc && !d.val1.vc->IsConst()) { if (GetPackType() == common::PackType::INT) { @@ -56,39 +56,45 @@ void RCAttr::EvaluatePack(MIUpdatingIterator &mit, int dim, Descriptor &d) { EvaluatePack_AttrAttr(mit, dim, d); } else DEBUG_ASSERT(0); // case not implemented - } else if (GetPackType() == common::PackType::INT && (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN)) { + } else if (GetPackType() == common::PackType::INT && + (d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN)) { if (!ATI::IsRealType(TypeName())) EvaluatePack_BetweenInt(mit, dim, d); else EvaluatePack_BetweenReal(mit, dim, d); - } else if (GetPackType() == common::PackType::STR && (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN)) { + } else if (GetPackType() == common::PackType::STR && + (d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN)) { if (types::RequiresUTFConversions(d.GetCollation())) EvaluatePack_BetweenString_UTF(mit, dim, d); else EvaluatePack_BetweenString(mit, dim, d); - } else if (d.op == common::O_LIKE || d.op == common::O_NOT_LIKE) { + } else if (d.op == common::Operator::O_LIKE || d.op == common::Operator::O_NOT_LIKE) { if (types::RequiresUTFConversions(d.GetCollation())) EvaluatePack_Like_UTF(mit, dim, d); else EvaluatePack_Like(mit, dim, d); - } else if (GetPackType() == common::PackType::STR && (d.op == common::O_IN || d.op == common::O_NOT_IN)) { + } else if (GetPackType() == common::PackType::STR && + (d.op == common::Operator::O_IN || d.op == common::Operator::O_NOT_IN)) { if (types::RequiresUTFConversions(d.GetCollation())) EvaluatePack_InString_UTF(mit, dim, d); else EvaluatePack_InString(mit, dim, d); - } else if (GetPackType() == common::PackType::INT && (d.op == common::O_IN || d.op == common::O_NOT_IN)) + } else if (GetPackType() == common::PackType::INT && + (d.op == common::Operator::O_IN || d.op == common::Operator::O_NOT_IN)) EvaluatePack_InNum(mit, dim, d); else DEBUG_ASSERT(0); // case not implemented! } -// TODO: op (common::O_LIKE common::O_IN) +// TODO: op (common::Operator::O_LIKE common::Operator::O_IN) common::ErrorCode RCAttr::EvaluateOnIndex(MIUpdatingIterator &mit, int dim, Descriptor &d, int64_t limit) { common::ErrorCode rv = common::ErrorCode::FAILED; - if (GetPackType() == common::PackType::INT && (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN)) { + if (GetPackType() == common::PackType::INT && + (d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN)) { rv = EvaluateOnIndex_BetweenInt(mit, dim, d, limit); - } else if (GetPackType() == common::PackType::STR && (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN)) { + } else if (GetPackType() == common::PackType::STR && + (d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN)) { if (types::RequiresUTFConversions(d.GetCollation())) rv = EvaluateOnIndex_BetweenString_UTF(mit, dim, d, limit); else @@ -105,7 +111,7 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenInt(MIUpdatingIterator &mit, in int64_t pv1 = d.val1.vc->GetValueInt64(mit); int64_t pv2 = d.val2.vc->GetValueInt64(mit); auto filter = mit.GetMultiIndex()->GetFilter(dim); - if (d.op != common::O_NOT_BETWEEN) filter->Reset(); + if (d.op != common::Operator::O_NOT_BETWEEN) filter->Reset(); std::vector keycols = indextab->KeyCols(); if (keycols.size() > 0 && keycols[0] == ColId()) { @@ -114,7 +120,7 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenInt(MIUpdatingIterator &mit, in std::vector fields; fields.emplace_back((const char *)&pv1, sizeof(int64_t)); - iter.ScanToKey(indextab, fields, common::O_MORE_EQ); + iter.ScanToKey(indextab, fields, common::Operator::O_MORE_EQ); while (iter.IsValid()) { uint64_t row = 0; std::vector vkeys; @@ -122,8 +128,8 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenInt(MIUpdatingIterator &mit, in if (common::ErrorCode::SUCCESS == rv) { int64_t part1 = *(reinterpret_cast(vkeys[0].data())); bool res = part1 > pv2; - if (d.op == common::O_NOT_BETWEEN) { - // If operator is common::O_NOT_BETWEEN, only set 0 to the bit by row, + if (d.op == common::Operator::O_NOT_BETWEEN) { + // If operator is common::Operator::O_NOT_BETWEEN, only set 0 to the bit by row, // limit not use because don't have graceful approach to process the // bit(1) if (!res) @@ -138,13 +144,14 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenInt(MIUpdatingIterator &mit, in ++iter; } else { - STONEDB_LOG(ERROR, "GetCurKV valid! col:[%u]=%I64d, Path:%s", ColId(), pv1, m_share->owner->Path().data()); + STONEDB_LOG(LogCtl_Level::ERROR, "GetCurKV valid! col:[%u]=%I64d, Path:%s", ColId(), pv1, + m_share->owner->Path().data()); break; } } } // Clear packs not in range - if (rv == common::ErrorCode::SUCCESS && d.op != common::O_NOT_BETWEEN) { + if (rv == common::ErrorCode::SUCCESS && d.op != common::Operator::O_NOT_BETWEEN) { while (mit.IsValid()) { if (!filter->GetBlockChangeStatus(mit.GetCurPackrow(dim))) mit.ResetCurrentPack(); mit.NextPackrow(); @@ -164,7 +171,7 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString(MIUpdatingIterator &mit, d.val1.vc->GetValueString(pv1, mit); d.val2.vc->GetValueString(pv2, mit); auto filter = mit.GetMultiIndex()->GetFilter(dim); - if (d.op != common::O_NOT_BETWEEN) filter->Reset(); + if (d.op != common::Operator::O_NOT_BETWEEN) filter->Reset(); std::vector keycols = indextab->KeyCols(); if (keycols.size() > 0 && keycols[0] == ColId()) { @@ -173,7 +180,7 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString(MIUpdatingIterator &mit, std::vector fields; fields.emplace_back(pv1.GetDataBytesPointer(), pv1.size()); - iter.ScanToKey(indextab, fields, (d.sharp ? common::O_MORE : common::O_MORE_EQ)); + iter.ScanToKey(indextab, fields, (d.sharp ? common::Operator::O_MORE : common::Operator::O_MORE_EQ)); while (iter.IsValid()) { uint64_t row = 0; std::vector vkeys; @@ -183,8 +190,8 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString(MIUpdatingIterator &mit, bool res = (d.sharp && ((pv1.IsNull() || pv > pv1) && (pv2.IsNull() || pv < pv2))) || (!d.sharp && ((pv1.IsNull() || pv >= pv1) && (pv2.IsNull() || pv <= pv2))); - if (d.op == common::O_NOT_BETWEEN) { - // If operator is common::O_NOT_BETWEEN, only set 0 to the bit by row, + if (d.op == common::Operator::O_NOT_BETWEEN) { + // If operator is common::Operator::O_NOT_BETWEEN, only set 0 to the bit by row, // limit not use because don't have graceful approach to process the // bit(1) if (res) @@ -199,14 +206,14 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString(MIUpdatingIterator &mit, ++iter; } else { - STONEDB_LOG(ERROR, "GetCurKV valid! col:[%u]=%s, Path:%s", ColId(), pv1.ToString().data(), + STONEDB_LOG(LogCtl_Level::ERROR, "GetCurKV valid! col:[%u]=%s, Path:%s", ColId(), pv1.ToString().data(), m_share->owner->Path().data()); break; } } } // Clear packs not in range - if (rv == common::ErrorCode::SUCCESS && d.op != common::O_NOT_BETWEEN) { + if (rv == common::ErrorCode::SUCCESS && d.op != common::Operator::O_NOT_BETWEEN) { while (mit.IsValid()) { if (!filter->GetBlockChangeStatus(mit.GetCurPackrow(dim))) mit.ResetCurrentPack(); mit.NextPackrow(); @@ -226,7 +233,7 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString_UTF(MIUpdatingIterator & d.val1.vc->GetValueString(pv1, mit); d.val2.vc->GetValueString(pv2, mit); auto filter = mit.GetMultiIndex()->GetFilter(dim); - if (d.op != common::O_NOT_BETWEEN) filter->Reset(); + if (d.op != common::Operator::O_NOT_BETWEEN) filter->Reset(); std::vector keycols = indextab->KeyCols(); if (keycols.size() > 0 && keycols[0] == ColId()) { @@ -234,7 +241,7 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString_UTF(MIUpdatingIterator & index::KeyIterator iter(¤t_tx->KVTrans()); std::vector fields; fields.emplace_back(pv1.GetDataBytesPointer(), pv1.size()); - iter.ScanToKey(indextab, fields, (d.sharp ? common::O_MORE : common::O_MORE_EQ)); + iter.ScanToKey(indextab, fields, (d.sharp ? common::Operator::O_MORE : common::Operator::O_MORE_EQ)); DTCollation coll = d.GetCollation(); while (iter.IsValid()) { uint64_t row = 0; @@ -247,8 +254,8 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString_UTF(MIUpdatingIterator & (!d.sharp && ((pv1.IsNull() || CollationStrCmp(coll, pv, pv1) >= 0) && (pv2.IsNull() || CollationStrCmp(coll, pv, pv2) <= 0))); - if (d.op == common::O_NOT_BETWEEN) { - // If operator is common::O_NOT_BETWEEN, only set 0 to the bit by row, + if (d.op == common::Operator::O_NOT_BETWEEN) { + // If operator is common::Operator::O_NOT_BETWEEN, only set 0 to the bit by row, // limit not use because don't have graceful approach to process the // bit(1) if (res) @@ -263,14 +270,14 @@ common::ErrorCode RCAttr::EvaluateOnIndex_BetweenString_UTF(MIUpdatingIterator & ++iter; } else { - STONEDB_LOG(ERROR, "GetCurKV valid! col:[%u]=%s, Path:%s", ColId(), pv1.ToString().data(), + STONEDB_LOG(LogCtl_Level::ERROR, "GetCurKV valid! col:[%u]=%s, Path:%s", ColId(), pv1.ToString().data(), m_share->owner->Path().data()); break; } } } // Clear packs not in range - if (rv == common::ErrorCode::SUCCESS && d.op != common::O_NOT_BETWEEN) { + if (rv == common::ErrorCode::SUCCESS && d.op != common::Operator::O_NOT_BETWEEN) { while (mit.IsValid()) { if (!filter->GetBlockChangeStatus(mit.GetCurPackrow(dim))) mit.ResetCurrentPack(); mit.NextPackrow(); @@ -400,7 +407,7 @@ void RCAttr::EvaluatePack_Like(MIUpdatingIterator &mit, int dim, Descriptor &d) v.MakePersistent(); res = v.Like(pattern, d.like_esc); } - if (d.op == common::O_NOT_LIKE) res = !res; + if (d.op == common::Operator::O_NOT_LIKE) res = !res; if (!res) mit.ResetCurrent(); } ++mit; @@ -467,7 +474,7 @@ void RCAttr::EvaluatePack_Like_UTF(MIUpdatingIterator &mit, int dim, Descriptor '_', '%'); res = (x == 0 ? true : false); } - if (d.op == common::O_NOT_LIKE) res = !res; + if (d.op == common::Operator::O_NOT_LIKE) res = !res; if (!res) mit.ResetCurrent(); } ++mit; @@ -503,7 +510,7 @@ void RCAttr::EvaluatePack_InString(MIUpdatingIterator &mit, int dim, Descriptor res = multival_column->ContainsString(mit, s); else res = multival_column->Contains(mit, s); - if (d.op == common::O_NOT_IN) res = !res; + if (d.op == common::Operator::O_NOT_IN) res = !res; if (res != true) mit.ResetCurrent(); } if (current_tx->Killed()) throw common::KilledException(); @@ -550,7 +557,7 @@ void RCAttr::EvaluatePack_InString_UTF(MIUpdatingIterator &mit, int dim, Descrip res = multival_column->Contains(mit, vt); } - if (d.op == common::O_NOT_IN) res = !res; + if (d.op == common::Operator::O_NOT_IN) res = !res; if (res != true) mit.ResetCurrent(); } if (current_tx->Killed()) throw common::KilledException(); @@ -586,7 +593,7 @@ void RCAttr::EvaluatePack_InNum(MIUpdatingIterator &mit, int dim, Descriptor &d) : multival_column->IsSetEncoded(TypeName(), ct.GetScale())); common::Tribool res; std::unique_ptr value(ValuePrototype(lookup_to_num).Clone()); - bool not_in = (d.op == common::O_NOT_IN); + bool not_in = (d.op == common::Operator::O_NOT_IN); int arraysize = 0; if (d.val1.cond_numvalue != nullptr) arraysize = d.val1.cond_numvalue->capacity(); if (local_min == local_max) { @@ -692,7 +699,7 @@ void RCAttr::EvaluatePack_BetweenString(MIUpdatingIterator &mit, int dim, Descri // IsNull() below means +/-inf bool res = (d.sharp && ((v1.IsNull() || v > v1) && (v2.IsNull() || v < v2))) || (!d.sharp && ((v1.IsNull() || v >= v1) && (v2.IsNull() || v <= v2))); - if (d.op == common::O_NOT_BETWEEN) res = !res; + if (d.op == common::Operator::O_NOT_BETWEEN) res = !res; if (!res) mit.ResetCurrent(); } ++mit; @@ -750,7 +757,7 @@ void RCAttr::EvaluatePack_BetweenString_UTF(MIUpdatingIterator &mit, int dim, De ((v1.IsNull() || CollationStrCmp(coll, v, v1) > 0) && (v2.IsNull() || CollationStrCmp(coll, v, v2) < 0))) || (!d.sharp && ((v1.IsNull() || CollationStrCmp(coll, v, v1) >= 0) && (v2.IsNull() || CollationStrCmp(coll, v, v2) <= 0))); - if (d.op == common::O_NOT_BETWEEN) res = !res; + if (d.op == common::Operator::O_NOT_BETWEEN) res = !res; if (!res) mit.ResetCurrent(); } ++mit; @@ -794,7 +801,7 @@ void RCAttr::EvaluatePack_BetweenInt(MIUpdatingIterator &mit, int dim, Descripto // Loop without it when packs are nearly full if (stonedb_sysvar_filterevaluation_speedup && filter && filter->NoOnes(pack) > static_cast(1 << (mit.GetPower() - 1))) { - if (d.op == common::O_BETWEEN && !mit.NullsPossibleInPack(dim) && dpn.nn == 0) { + if (d.op == common::Operator::O_BETWEEN && !mit.NullsPossibleInPack(dim) && dpn.nn == 0) { // easy and fast case - no "if"s for (uint32_t n = 0; n < dpn.nr; n++) { auto v = p->GetValInt(n); @@ -808,14 +815,14 @@ void RCAttr::EvaluatePack_BetweenInt(MIUpdatingIterator &mit, int dim, Descripto else { auto v = p->GetValInt(n); bool res = (pv1 <= v && v <= pv2); - if (d.op == common::O_NOT_BETWEEN) res = !res; + if (d.op == common::Operator::O_NOT_BETWEEN) res = !res; if (!res) filter->Reset(pack, n); } } } mit.NextPackrow(); } else { - if (d.op == common::O_BETWEEN && !mit.NullsPossibleInPack(dim) && dpn.nn == 0) { + if (d.op == common::Operator::O_BETWEEN && !mit.NullsPossibleInPack(dim) && dpn.nn == 0) { // easy and fast case - no "if"s do { auto v = p->GetValInt(mit.GetCurInpack(dim)); @@ -831,7 +838,7 @@ void RCAttr::EvaluatePack_BetweenInt(MIUpdatingIterator &mit, int dim, Descripto else { auto v = p->GetValInt(inpack); bool res = (pv1 <= v && v <= pv2); - if (d.op == common::O_NOT_BETWEEN) res = !res; + if (d.op == common::Operator::O_NOT_BETWEEN) res = !res; if (!res) mit.ResetCurrent(); } ++mit; @@ -840,8 +847,8 @@ void RCAttr::EvaluatePack_BetweenInt(MIUpdatingIterator &mit, int dim, Descripto } } else { // local_min==local_max, and in 2-level encoding both are 0 - if (((pv1 > 0 || pv2 < 0) && d.op == common::O_BETWEEN) || - (pv1 <= 0 && pv2 >= 0 && d.op == common::O_NOT_BETWEEN)) { + if (((pv1 > 0 || pv2 < 0) && d.op == common::Operator::O_BETWEEN) || + (pv1 <= 0 && pv2 >= 0 && d.op == common::Operator::O_NOT_BETWEEN)) { mit.ResetCurrentPack(); mit.NextPackrow(); } else @@ -882,7 +889,7 @@ void RCAttr::EvaluatePack_BetweenReal(MIUpdatingIterator &mit, int dim, Descript else { double v = p->GetValDouble(n); bool res = (dv1 <= v && v <= dv2); - if (d.op == common::O_NOT_BETWEEN) res = !res; + if (d.op == common::Operator::O_NOT_BETWEEN) res = !res; if (!res) filter->Reset(pack, n); } } @@ -895,7 +902,7 @@ void RCAttr::EvaluatePack_BetweenReal(MIUpdatingIterator &mit, int dim, Descript else { double v = p->GetValDouble(inpack); bool res = (dv1 <= v && v <= dv2); - if (d.op == common::O_NOT_BETWEEN) res = !res; + if (d.op == common::Operator::O_NOT_BETWEEN) res = !res; if (!res) mit.ResetCurrent(); } ++mit; @@ -903,8 +910,8 @@ void RCAttr::EvaluatePack_BetweenReal(MIUpdatingIterator &mit, int dim, Descript } } else { double uni_val = get_dpn(pack).min_d; - if (((dv1 > uni_val || dv2 < uni_val) && d.op == common::O_BETWEEN) || - (dv1 <= uni_val && dv2 >= uni_val && d.op == common::O_NOT_BETWEEN)) { + if (((dv1 > uni_val || dv2 < uni_val) && d.op == common::Operator::O_BETWEEN) || + (dv1 <= uni_val && dv2 >= uni_val && d.op == common::Operator::O_NOT_BETWEEN)) { mit.ResetCurrentPack(); mit.NextPackrow(); } else @@ -946,22 +953,22 @@ void RCAttr::EvaluatePack_AttrAttr(MIUpdatingIterator &mit, int dim, Descriptor v1 = (pack1_uniform ? 0 : p1->GetValInt(obj_in_pack)) + val1_offset; v2 = (pack2_uniform ? 0 : p2->GetValInt(obj_in_pack)); switch (d.op) { - case common::O_EQ: + case common::Operator::O_EQ: res = (v1 == v2); break; - case common::O_NOT_EQ: + case common::Operator::O_NOT_EQ: res = (v1 != v2); break; - case common::O_LESS: + case common::Operator::O_LESS: res = (v1 < v2); break; - case common::O_LESS_EQ: + case common::Operator::O_LESS_EQ: res = (v1 <= v2); break; - case common::O_MORE: + case common::Operator::O_MORE: res = (v1 > v2); break; - case common::O_MORE_EQ: + case common::Operator::O_MORE_EQ: res = (v1 >= v2); break; default: @@ -1008,22 +1015,22 @@ void RCAttr::EvaluatePack_AttrAttrReal(MIUpdatingIterator &mit, int dim, Descrip double v1 = *((double *)&pv1); double v2 = *((double *)&pv2); switch (d.op) { - case common::O_EQ: + case common::Operator::O_EQ: res = (v1 == v2); break; - case common::O_NOT_EQ: + case common::Operator::O_NOT_EQ: res = (v1 != v2); break; - case common::O_LESS: + case common::Operator::O_LESS: res = (v1 < v2); break; - case common::O_LESS_EQ: + case common::Operator::O_LESS_EQ: res = (v1 <= v2); break; - case common::O_MORE: + case common::Operator::O_MORE: res = (v1 > v2); break; - case common::O_MORE_EQ: + case common::Operator::O_MORE_EQ: res = (v1 >= v2); break; default: @@ -1038,8 +1045,8 @@ void RCAttr::EvaluatePack_AttrAttrReal(MIUpdatingIterator &mit, int dim, Descrip bool RCAttr::IsDistinct(Filter *f) { MEASURE_FET("RCAttr::IsDistinct(...)"); if (ct.IsLookup() && types::RequiresUTFConversions(GetCollation())) return false; - if (PhysicalColumn::IsDistinct() == common::RS_ALL) { // = is_unique_updated && is_unique - if (f == NULL) return (NoNulls() == 0); // no nulls at all, and is_unique => distinct + if (PhysicalColumn::IsDistinct() == common::RSValue::RS_ALL) { // = is_unique_updated && is_unique + if (f == NULL) return (NoNulls() == 0); // no nulls at all, and is_unique => distinct LoadPackInfo(); for (uint b = 0; b < NoPack(); b++) if (!f->IsEmpty(b) && get_dpn(b).nn > 0) // any null in nonempty pack? @@ -1054,16 +1061,16 @@ uint64_t RCAttr::ApproxAnswerSize(Descriptor &d) { ASSERT(d.encoded, "The descriptor is not encoded!"); static MIIterator const mit(NULL, pss); LoadPackInfo(); - if (d.op == common::O_NOT_NULL) return NoObj() - NoNulls(); - if (d.op == common::O_IS_NULL) return NoNulls(); + if (d.op == common::Operator::O_NOT_NULL) return NoObj() - NoNulls(); + if (d.op == common::Operator::O_IS_NULL) return NoNulls(); if (d.val1.vc && !d.val1.vc->IsConst()) { uint64_t no_distinct = ApproxDistinctVals(false, NULL, NULL, false); if (no_distinct == 0) no_distinct = 1; - if (d.op == common::O_EQ) return NoObj() / no_distinct; - if (d.op == common::O_NOT_EQ) return NoObj() - (NoObj() / no_distinct); + if (d.op == common::Operator::O_EQ) return NoObj() / no_distinct; + if (d.op == common::Operator::O_NOT_EQ) return NoObj() - (NoObj() / no_distinct); return (NoObj() - NoNulls()) / 2; // default } - if (d.op == common::O_BETWEEN && d.val1.vc->IsConst() && d.val2.vc->IsConst() && + if (d.op == common::Operator::O_BETWEEN && d.val1.vc->IsConst() && d.val2.vc->IsConst() && GetPackType() == common::PackType::INT) { double res = 0; int64_t val1 = d.val1.vc->GetValueInt64(mit); @@ -1143,8 +1150,8 @@ size_t RCAttr::MaxStringSize(Filter *f) // maximal byte string length in column bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { MEASURE_FET("RCAttr::TryToMerge(...)"); - if ((d1.op != common::O_BETWEEN && d1.op != common::O_NOT_BETWEEN) || - (d2.op != common::O_BETWEEN && d2.op != common::O_NOT_BETWEEN)) + if ((d1.op != common::Operator::O_BETWEEN && d1.op != common::Operator::O_NOT_BETWEEN) || + (d2.op != common::Operator::O_BETWEEN && d2.op != common::Operator::O_NOT_BETWEEN)) return false; if (GetPackType() == common::PackType::INT && d1.val1.vc && d1.val2.vc && d2.val1.vc && d2.val2.vc && d1.val1.vc->IsConst() && d1.val2.vc->IsConst() && d2.val1.vc->IsConst() && d2.val2.vc->IsConst()) { @@ -1154,7 +1161,7 @@ bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { int64_t d2min = d2.val1.vc->GetValueInt64(mit); int64_t d2max = d2.val2.vc->GetValueInt64(mit); if (!ATI::IsRealType(TypeName())) { - if (d1.op == common::O_BETWEEN && d2.op == common::O_BETWEEN) { + if (d1.op == common::Operator::O_BETWEEN && d2.op == common::Operator::O_BETWEEN) { if (d2min > d1min) { std::swap(d1.val1, d2.val1); std::swap(d1min, d2min); @@ -1163,10 +1170,10 @@ bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { std::swap(d1.val2, d2.val2); std::swap(d1max, d2max); } - if (d1min > d1max) d1.op = common::O_FALSE; // disjoint? + if (d1min > d1max) d1.op = common::Operator::O_FALSE; // disjoint? return true; } - if (d1.op == common::O_NOT_BETWEEN && d2.op == common::O_NOT_BETWEEN) { + if (d1.op == common::Operator::O_NOT_BETWEEN && d2.op == common::Operator::O_NOT_BETWEEN) { if (d1min < d2max && d2min < d1max) { if (d2min < d1min) std::swap(d1.val1, d2.val1); if (d2max > d1max) std::swap(d1.val2, d2.val2); @@ -1179,7 +1186,7 @@ bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { double dv1max = *((double *)&d1max); double dv2min = *((double *)&d2min); double dv2max = *((double *)&d2max); - if (d1.op == common::O_BETWEEN && d2.op == common::O_BETWEEN) { + if (d1.op == common::Operator::O_BETWEEN && d2.op == common::Operator::O_BETWEEN) { if (dv2min > dv1min) { std::swap(d1.val1, d2.val1); std::swap(dv2min, dv1min); @@ -1188,10 +1195,10 @@ bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { std::swap(d1.val2, d2.val2); std::swap(dv2max, dv1max); } - if (dv1min > dv1max) d1.op = common::O_FALSE; // disjoint? + if (dv1min > dv1max) d1.op = common::Operator::O_FALSE; // disjoint? return true; } - if (d1.op == common::O_NOT_BETWEEN && d2.op == common::O_NOT_BETWEEN) { + if (d1.op == common::Operator::O_NOT_BETWEEN && d2.op == common::Operator::O_NOT_BETWEEN) { if (dv1min < dv2max && dv2min < dv1max) { if (dv2min < dv1min) std::swap(d1.val1, d2.val1); if (dv2max > dv1max) std::swap(d1.val2, d2.val2); @@ -1209,17 +1216,18 @@ bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { d2.val1.vc->GetValueString(d2min, mit); d2.val2.vc->GetValueString(d2max, mit); DTCollation my_coll = d1.GetCollation(); - if (d1.op == common::O_BETWEEN && d2.op == common::O_BETWEEN) { + if (d1.op == common::Operator::O_BETWEEN && d2.op == common::Operator::O_BETWEEN) { if (types::RequiresUTFConversions(my_coll)) { - if (d1min.IsNull() || CollationStrCmp(my_coll, d2min, d1min, common::O_MORE)) { + if (d1min.IsNull() || CollationStrCmp(my_coll, d2min, d1min, common::Operator::O_MORE)) { std::swap(d1.val1, d2.val1); std::swap(d1min, d2min); } - if (d1max.IsNull() || (!d2max.IsNull() && CollationStrCmp(my_coll, d2max, d1max, common::O_LESS))) { + if (d1max.IsNull() || (!d2max.IsNull() && CollationStrCmp(my_coll, d2max, d1max, common::Operator::O_LESS))) { std::swap(d1.val2, d2.val2); std::swap(d1max, d2max); } - if (CollationStrCmp(my_coll, d1min, d1max, common::O_MORE)) d1.op = common::O_FALSE; // disjoint? + if (CollationStrCmp(my_coll, d1min, d1max, common::Operator::O_MORE)) + d1.op = common::Operator::O_FALSE; // disjoint? } else { if (d1min.IsNull() || d2min > d1min) { // IsNull() means infinity here std::swap(d1.val1, d2.val1); @@ -1229,18 +1237,18 @@ bool RCAttr::TryToMerge(Descriptor &d1, Descriptor &d2) { std::swap(d1.val2, d2.val2); std::swap(d1max, d2max); } - if (d1min > d1max) d1.op = common::O_FALSE; // disjoint? + if (d1min > d1max) d1.op = common::Operator::O_FALSE; // disjoint? } return true; } - if (d1.op == common::O_NOT_BETWEEN && d2.op == common::O_NOT_BETWEEN) { + if (d1.op == common::Operator::O_NOT_BETWEEN && d2.op == common::Operator::O_NOT_BETWEEN) { if (d1min.IsNull() || d1max.IsNull() || d2min.IsNull() || d2max.IsNull()) return false; // should not appear in normal circumstances if (types::RequiresUTFConversions(my_coll)) { - if (CollationStrCmp(my_coll, d1min, d2max, common::O_LESS) && - CollationStrCmp(my_coll, d2min, d1max, common::O_LESS)) { - if (CollationStrCmp(my_coll, d2min, d1min, common::O_LESS)) std::swap(d1.val1, d2.val1); - if (CollationStrCmp(my_coll, d2max, d1max, common::O_MORE)) std::swap(d1.val2, d2.val2); + if (CollationStrCmp(my_coll, d1min, d2max, common::Operator::O_LESS) && + CollationStrCmp(my_coll, d2min, d1max, common::Operator::O_LESS)) { + if (CollationStrCmp(my_coll, d2min, d1min, common::Operator::O_LESS)) std::swap(d1.val1, d2.val1); + if (CollationStrCmp(my_coll, d2max, d1max, common::Operator::O_MORE)) std::swap(d1.val2, d2.val2); return true; } } else { diff --git a/storage/stonedb/core/rough_multi_index.cpp b/storage/stonedb/core/rough_multi_index.cpp index 9515c945d..e0b119296 100644 --- a/storage/stonedb/core/rough_multi_index.cpp +++ b/storage/stonedb/core/rough_multi_index.cpp @@ -33,7 +33,7 @@ RoughMultiIndex::RoughMultiIndex(std::vector no_of_packs) { rf[d] = new common::RSValue[no_packs[d]]; else rf[d] = NULL; - for (int p = 0; p < no_packs[d]; p++) rf[d][p] = common::RS_UNKNOWN; + for (int p = 0; p < no_packs[d]; p++) rf[d][p] = common::RSValue::RS_UNKNOWN; } } @@ -81,10 +81,10 @@ common::RSValue *RoughMultiIndex::GetLocalDescFilter(int dim, int desc_num, bool // prepare a new table. local_desc[dim].push_back(new RFDesc(no_packs[dim], desc_num)); for (int p = 0; p < no_packs[dim]; p++) { - if (rf[dim][p] == common::RS_NONE) // check global dimension filter - (local_desc[dim])[j]->desc_rf[p] = common::RS_NONE; + if (rf[dim][p] == common::RSValue::RS_NONE) // check global dimension filter + (local_desc[dim])[j]->desc_rf[p] = common::RSValue::RS_NONE; else - (local_desc[dim])[j]->desc_rf[p] = common::RS_UNKNOWN; + (local_desc[dim])[j]->desc_rf[p] = common::RSValue::RS_UNKNOWN; } return (local_desc[dim])[j]->desc_rf; } @@ -96,20 +96,20 @@ void RoughMultiIndex::ClearLocalDescFilters() { } } -void RoughMultiIndex::MakeDimensionSuspect(int dim) // common::RS_ALL -> common::RS_SOME for a dimension (or all of - // them) +void RoughMultiIndex::MakeDimensionSuspect(int dim) // common::RSValue::RS_ALL -> common::RSValue::RS_SOME for a + // dimension (or all of them) { for (int d = 0; d < no_dims; d++) if ((dim == d || dim == -1) && rf[d]) { for (int p = 0; p < no_packs[d]; p++) - if (rf[d][p] == common::RS_ALL) rf[d][p] = common::RS_SOME; + if (rf[d][p] == common::RSValue::RS_ALL) rf[d][p] = common::RSValue::RS_SOME; } } void RoughMultiIndex::MakeDimensionEmpty(int dim /*= -1*/) { for (int d = 0; d < no_dims; d++) if ((dim == d || dim == -1) && rf[d]) { - for (int p = 0; p < no_packs[d]; p++) rf[d][p] = common::RS_NONE; + for (int p = 0; p < no_packs[d]; p++) rf[d][p] = common::RSValue::RS_NONE; } } @@ -118,16 +118,17 @@ bool RoughMultiIndex::UpdateGlobalRoughFilter(int dim, int desc_num) { common::RSValue *loc_rs = GetLocalDescFilter(dim, desc_num, true); if (loc_rs == NULL) return true; for (int p = 0; p < no_packs[dim]; p++) { - if (rf[dim][p] == common::RS_UNKNOWN) { // not known yet - get the first - // information available + if (rf[dim][p] == common::RSValue::RS_UNKNOWN) { // not known yet - get the first + // information available rf[dim][p] = loc_rs[p]; - if (rf[dim][p] != common::RS_NONE) any_nonempty = true; - } else if (loc_rs[p] == common::RS_NONE) - rf[dim][p] = common::RS_NONE; - else if (rf[dim][p] != common::RS_NONE) { // else no change + if (rf[dim][p] != common::RSValue::RS_NONE) any_nonempty = true; + } else if (loc_rs[p] == common::RSValue::RS_NONE) + rf[dim][p] = common::RSValue::RS_NONE; + else if (rf[dim][p] != common::RSValue::RS_NONE) { // else no change any_nonempty = true; - if (loc_rs[p] != common::RS_ALL || rf[dim][p] != common::RS_ALL) // else rf[..] remains common::RS_ALL - rf[dim][p] = common::RS_SOME; + if (loc_rs[p] != common::RSValue::RS_ALL || + rf[dim][p] != common::RSValue::RS_ALL) // else rf[..] remains common::RSValue::RS_ALL + rf[dim][p] = common::RSValue::RS_SOME; } } return any_nonempty; @@ -138,7 +139,7 @@ void RoughMultiIndex::UpdateGlobalRoughFilter(int dim, { if (!loc_f) return; for (int p = 0; p < no_packs[dim]; p++) { - if (loc_f->IsEmpty(p)) rf[dim][p] = common::RS_NONE; + if (loc_f->IsEmpty(p)) rf[dim][p] = common::RSValue::RS_NONE; } } @@ -146,8 +147,8 @@ void RoughMultiIndex::UpdateLocalRoughFilters(int dim) // make projection from // given dimensions { for (int p = 0; p < no_packs[dim]; p++) { - if (rf[dim][p] == common::RS_NONE) { - for (uint i = 0; i < local_desc[dim].size(); i++) (local_desc[dim])[i]->desc_rf[p] = common::RS_NONE; + if (rf[dim][p] == common::RSValue::RS_NONE) { + for (uint i = 0; i < local_desc[dim].size(); i++) (local_desc[dim])[i]->desc_rf[p] = common::RSValue::RS_NONE; } } } @@ -161,7 +162,7 @@ void RoughMultiIndex::UpdateReducedDimension() { void RoughMultiIndex::UpdateReducedDimension(int d) { int omitted = 0; for (int i = 0; i < no_packs[d]; i++) - if (rf[d][i] == common::RS_NONE) omitted++; + if (rf[d][i] == common::RSValue::RS_NONE) omitted++; no_empty_packs[d] = omitted; } @@ -170,7 +171,7 @@ std::vector RoughMultiIndex::GetReducedDimensions() { for (int d = 0; d < no_dims; d++) { int omitted = 0; for (int i = 0; i < no_packs[d]; i++) - if (rf[d][i] == common::RS_NONE) omitted++; + if (rf[d][i] == common::RSValue::RS_NONE) omitted++; if (no_empty_packs[d] < omitted) dims.push_back(d); } return dims; diff --git a/storage/stonedb/core/rough_multi_index.h b/storage/stonedb/core/rough_multi_index.h index 75c0680c1..cc6cd9b54 100644 --- a/storage/stonedb/core/rough_multi_index.h +++ b/storage/stonedb/core/rough_multi_index.h @@ -41,8 +41,8 @@ class RoughMultiIndex { /* Example of query processing steps: 1. Add new rough filter (RF) by GetLocalDescFilter for a condition. - Note that it will have common::RS_NONE if global RF is common::CT::NONE. - 2. Update local RF for all non-common::RS_NONE packs. + Note that it will have common::RSValue::RS_NONE if global RF is common::CT::NONE. + 2. Update local RF for all non-common::RSValue::RS_NONE packs. 3. Update global RF by UpdateGlobalRoughFilter, common::CT::NONEto optimize access for next conditions. */ @@ -61,7 +61,7 @@ class RoughMultiIndex { Filter *loc_f); // if the filter is nontrivial, then copy pack status void UpdateLocalRoughFilters(int dim); // make projection from global filters to all local for the // given dimension - void MakeDimensionSuspect(int dim = -1); // common::RS_ALL -> common::RS_SOME + void MakeDimensionSuspect(int dim = -1); // common::RSValue::RS_ALL -> common::RSValue::RS_SOME // for a dimension (or all of them) void MakeDimensionEmpty(int dim = -1); diff --git a/storage/stonedb/core/rsi_bloom.cpp b/storage/stonedb/core/rsi_bloom.cpp index 0dec46773..1c565333c 100644 --- a/storage/stonedb/core/rsi_bloom.cpp +++ b/storage/stonedb/core/rsi_bloom.cpp @@ -40,7 +40,7 @@ RSIndex_Bloom::RSIndex_Bloom(const fs::path &dir, common::TX_ID ver) { // allocate more than requested capacity = (hdr.no_pack / 1024 + 1) * 1024; - bloom_buffers = static_cast(alloc(capacity * sizeof(BF), mm::BLOCK_TEMPORARY)); + bloom_buffers = static_cast(alloc(capacity * sizeof(BF), mm::BLOCK_TYPE::BLOCK_TEMPORARY)); if (hdr.no_pack > 0) { frs_index.ReadExact(bloom_buffers, hdr.no_pack * sizeof(BF)); @@ -66,18 +66,18 @@ common::RSValue RSIndex_Bloom::IsValue(types::BString min_v, types::BString max_ auto &bf = bloom_buffers[pack]; if (bf.len == 0) { // this pack no bloom filter data - return common::RS_SOME; + return common::RSValue::RS_SOME; } Slice key(max_v.val, max_v.size()); // get filter data Slice pack_block(bf.data, bf.len); FilterBlockReader reader(bloom_filter_policy.get(), pack_block); if (!reader.KeyMayMatch(0, key)) { - return common::RS_NONE; + return common::RSValue::RS_NONE; } - return common::RS_SOME; + return common::RSValue::RS_SOME; } else { - return common::RS_SOME; + return common::RSValue::RS_SOME; } } @@ -87,7 +87,8 @@ void RSIndex_Bloom::Update(common::PACK_INDEX pi, DPN &dpn, const PackStr *pack) } if (hdr.no_pack > capacity) { capacity += 1024; - bloom_buffers = static_cast(rc_realloc(bloom_buffers, capacity * sizeof(BF), mm::BLOCK_TEMPORARY)); + bloom_buffers = + static_cast(rc_realloc(bloom_buffers, capacity * sizeof(BF), mm::BLOCK_TYPE::BLOCK_TEMPORARY)); // rclog << lock << "bloom filter capacity increased to " << capacity << // system::unlock; } @@ -102,7 +103,7 @@ void RSIndex_Bloom::Update(common::PACK_INDEX pi, DPN &dpn, const PackStr *pack) Slice block = bloom_builder->Finish(); if (block.size() > sizeof(BF) - 4) { - STONEDB_LOG(WARN, "Bloom len of pack:%d larger than expected", pi); + STONEDB_LOG(LogCtl_Level::WARN, "Bloom len of pack:%d larger than expected", pi); bloom_buffers[pi].len = 0; } else { bloom_buffers[pi].len = block.size(); diff --git a/storage/stonedb/core/rsi_cmap.cpp b/storage/stonedb/core/rsi_cmap.cpp index dde7582ec..5a819014f 100644 --- a/storage/stonedb/core/rsi_cmap.cpp +++ b/storage/stonedb/core/rsi_cmap.cpp @@ -35,7 +35,7 @@ RSIndex_CMap::RSIndex_CMap(const fs::path &dir, common::TX_ID ver) { ASSERT(hdr.no_positions <= MAX_POS); capacity = (hdr.no_pack / 1024 + 1) * 1024; - auto ptr = alloc(capacity * hdr.no_positions * CMAP_BYTES, mm::BLOCK_TEMPORARY); + auto ptr = alloc(capacity * hdr.no_positions * CMAP_BYTES, mm::BLOCK_TYPE::BLOCK_TEMPORARY); cmap_buffers = static_cast(ptr); frs_index.ReadExact(cmap_buffers, hdr.no_pack * hdr.no_positions * CMAP_BYTES); } else { @@ -79,11 +79,11 @@ int RSIndex_CMap::Count(int pack, uint pos) { return d; } -// Results: common::RS_NONE - there is no objects having values +// Results: common::RSValue::RS_NONE - there is no objects having values // between min_v and max_v (including) -// common::RS_SOME - some objects from this pack +// common::RSValue::RS_SOME - some objects from this pack // may have -// values between min_v and max_v common::RS_ALL - +// values between min_v and max_v common::RSValue::RS_ALL - // all objects from this pack do have values between min_v and max_v common::RSValue RSIndex_CMap::IsValue(types::BString min_v, types::BString max_v, int pack) { ASSERT(size_t(pack) < hdr.no_pack); @@ -91,16 +91,16 @@ common::RSValue RSIndex_CMap::IsValue(types::BString min_v, types::BString max_v if (min_v == max_v) { auto size = min_v.size() < hdr.no_positions ? min_v.size() : hdr.no_positions; for (uint pos = 0; pos < size; pos++) { - if (!IsSet(pack, (unsigned char)min_v[pos], pos)) return common::RS_NONE; + if (!IsSet(pack, (unsigned char)min_v[pos], pos)) return common::RSValue::RS_NONE; } - return common::RS_SOME; + return common::RSValue::RS_SOME; } else { // TODO: may be further optimized unsigned char f = 0, l = 255; if (min_v.len > 0) f = (unsigned char)min_v[0]; // min_v.len == 0 usually means -inf if (max_v.len > 0) l = (unsigned char)max_v[0]; - if (f > l || !IsAnySet(pack, f, l, 0)) return common::RS_NONE; - return common::RS_SOME; + if (f > l || !IsAnySet(pack, f, l, 0)) return common::RSValue::RS_NONE; + return common::RSValue::RS_SOME; } } @@ -110,10 +110,10 @@ common::RSValue RSIndex_CMap::IsLike(types::BString pattern, int pack, char esca uint pos = 0; while (pos < pattern.len && pos < hdr.no_positions) { if (p[pos] == '%' || p[pos] == escape_character) break; - if (p[pos] != '_' && !IsSet(pack, p[pos], pos)) return common::RS_NONE; + if (p[pos] != '_' && !IsSet(pack, p[pos], pos)) return common::RSValue::RS_NONE; pos++; } - return common::RS_SOME; + return common::RSValue::RS_SOME; } void RSIndex_CMap::PutValue(const types::BString &v, int pack) { @@ -151,7 +151,7 @@ void RSIndex_CMap::Update(common::PACK_INDEX pi, DPN &dpn, const PackStr *pack) } if (hdr.no_pack > capacity) { capacity += 1024; - auto ptr = rc_realloc(cmap_buffers, capacity * hdr.no_positions * CMAP_BYTES, mm::BLOCK_TEMPORARY); + auto ptr = rc_realloc(cmap_buffers, capacity * hdr.no_positions * CMAP_BYTES, mm::BLOCK_TYPE::BLOCK_TEMPORARY); cmap_buffers = static_cast(ptr); // rclog << lock << "cmap filter capacity increased to " << capacity << // system::unlock; diff --git a/storage/stonedb/core/rsi_cmap.h b/storage/stonedb/core/rsi_cmap.h index 50aaa722f..dc13134b1 100644 --- a/storage/stonedb/core/rsi_cmap.h +++ b/storage/stonedb/core/rsi_cmap.h @@ -42,11 +42,11 @@ class RSIndex_CMap final : public RSIndex { void Create(int64_t _no_obj, int no_pos, int pss); common::RSValue IsValue(types::BString min_v, types::BString max_v, int pack); - // Results: common::RS_NONE - there is no objects having values + // Results: common::RSValue::RS_NONE - there is no objects having values // between min_v and max_v (including) - // common::RS_SOME - some objects from this pack do + // common::RSValue::RS_SOME - some objects from this pack do // have values - // between min_v and max_v common::RS_ALL - all objects + // between min_v and max_v common::RSValue::RS_ALL - all objects // from this pack do have values between min_v and max_v common::RSValue IsLike(types::BString pattern, int pack, char escape_character); int Count(int pack, uint pos); // a number of ones in the pack on a given diff --git a/storage/stonedb/core/rsi_histogram.cpp b/storage/stonedb/core/rsi_histogram.cpp index 241ce4ef0..d1944fe77 100644 --- a/storage/stonedb/core/rsi_histogram.cpp +++ b/storage/stonedb/core/rsi_histogram.cpp @@ -41,7 +41,7 @@ RSIndex_Hist::RSIndex_Hist(const fs::path &dir, common::TX_ID ver) { // allocate more than requested capacity = (hdr.no_pack / 1024 + 1) * 1024; - hist_buffers = static_cast(alloc(capacity * sizeof(BLOCK), mm::BLOCK_TEMPORARY)); + hist_buffers = static_cast(alloc(capacity * sizeof(BLOCK), mm::BLOCK_TYPE::BLOCK_TEMPORARY)); if (hdr.no_pack > 0) { frs_index.ReadExact(hist_buffers, hdr.no_pack * sizeof(BLOCK)); } @@ -88,16 +88,16 @@ int RSIndex_Hist::Count(int pack, int width) { return d; } -// Results: common::RS_NONE - there is no objects having values +// Results: common::RSValue::RS_NONE - there is no objects having values // between min_v and max_v (including) -// common::RS_SOME - some objects from this pack +// common::RSValue::RS_SOME - some objects from this pack // may have -// values between min_v and max_v common::RS_ALL - +// values between min_v and max_v common::RSValue::RS_ALL - // all objects from this pack do have values between min_v and max_v common::RSValue RSIndex_Hist::IsValue(int64_t min_v, int64_t max_v, int pack, int64_t pack_min, int64_t pack_max) { ASSERT(size_t(pack) < hdr.no_pack, std::to_string(pack) + " < " + std::to_string(hdr.no_pack)); - if (IntervalTooLarge(pack_min, pack_max) || IntervalTooLarge(min_v, max_v)) return common::RS_SOME; + if (IntervalTooLarge(pack_min, pack_max) || IntervalTooLarge(min_v, max_v)) return common::RSValue::RS_SOME; int min_bit = 0, max_bit = 0; if (!Fixed()) { // floating point double dmin_v = *(double *)(&min_v); @@ -105,21 +105,22 @@ common::RSValue RSIndex_Hist::IsValue(int64_t min_v, int64_t max_v, int pack, in double dpack_min = *(double *)(&pack_min); double dpack_max = *(double *)(&pack_max); DEBUG_ASSERT(dmin_v <= dmax_v); - if (dmax_v < dpack_min || dmin_v > dpack_max) return common::RS_NONE; - if (dmax_v >= dpack_max && dmin_v <= dpack_min) return common::RS_ALL; - if (dmax_v >= dpack_max || dmin_v <= dpack_min) return common::RS_SOME; // pack_min xor pack_max are present + if (dmax_v < dpack_min || dmin_v > dpack_max) return common::RSValue::RS_NONE; + if (dmax_v >= dpack_max && dmin_v <= dpack_min) return common::RSValue::RS_ALL; + if (dmax_v >= dpack_max || dmin_v <= dpack_min) + return common::RSValue::RS_SOME; // pack_min xor pack_max are present // now we know that (max_vpack_min) and there is only - // common::RS_SOME or common::RS_NONE answer possible + // common::RSValue::RS_SOME or common::RSValue::RS_NONE answer possible double interval_len = (dpack_max - dpack_min) / double(RSI_HIST_BITS); min_bit = int((dmin_v - dpack_min) / interval_len); max_bit = int((dmax_v - dpack_min) / interval_len); } else { DEBUG_ASSERT(min_v <= max_v); - if (max_v < pack_min || min_v > pack_max) return common::RS_NONE; - if (max_v >= pack_max && min_v <= pack_min) return common::RS_ALL; - if (max_v >= pack_max || min_v <= pack_min) return common::RS_SOME; // pack_min xor pack_max are present + if (max_v < pack_min || min_v > pack_max) return common::RSValue::RS_NONE; + if (max_v >= pack_max && min_v <= pack_min) return common::RSValue::RS_ALL; + if (max_v >= pack_max || min_v <= pack_min) return common::RSValue::RS_SOME; // pack_min xor pack_max are present // now we know that (max_vpack_min) and there is only - // common::RS_SOME or common::RS_NONE answer possible + // common::RSValue::RS_SOME or common::RSValue::RS_NONE answer possible if (ExactMode(pack_min, pack_max)) { // exact mode min_bit = int(min_v - pack_min - 1); // translate into [0,...] max_bit = int(max_v - pack_min - 1); @@ -131,12 +132,12 @@ common::RSValue RSIndex_Hist::IsValue(int64_t min_v, int64_t max_v, int pack, in } DEBUG_ASSERT(min_bit >= 0); if (max_bit >= RSI_HIST_BITS) - return common::RS_SOME; // it may happen for extremely large numbers ( - // >2^52 ) + return common::RSValue::RS_SOME; // it may happen for extremely large numbers ( + // >2^52 ) for (int i = min_bit; i <= max_bit; i++) { - if (((*(hist_buffers[pack].data + i / 64) >> (i % 64)) & 0x00000001) != 0) return common::RS_SOME; + if (((*(hist_buffers[pack].data + i / 64) >> (i % 64)) & 0x00000001) != 0) return common::RSValue::RS_SOME; } - return common::RS_NONE; + return common::RSValue::RS_NONE; } bool RSIndex_Hist::Intersection(int pack, int64_t pack_min, int64_t pack_max, RSIndex_Hist *sec, int pack2, @@ -145,10 +146,10 @@ bool RSIndex_Hist::Intersection(int pack, int64_t pack_min, int64_t pack_max, RS if (!Fixed() || !sec->Fixed()) return true; // not implemented - intersection possible if (IntervalTooLarge(pack_min, pack_max) || IntervalTooLarge(pack_min2, pack_max2)) return true; - if (sec->IsValue(pack_min, pack_min, pack2, pack_min2, pack_max2) != common::RS_NONE || - sec->IsValue(pack_max, pack_max, pack2, pack_min2, pack_max2) != common::RS_NONE || - IsValue(pack_min2, pack_min2, pack, pack_min, pack_max) != common::RS_NONE || - IsValue(pack_max2, pack_max2, pack, pack_min, pack_max) != common::RS_NONE) + if (sec->IsValue(pack_min, pack_min, pack2, pack_min2, pack_max2) != common::RSValue::RS_NONE || + sec->IsValue(pack_max, pack_max, pack2, pack_min2, pack_max2) != common::RSValue::RS_NONE || + IsValue(pack_min2, pack_min2, pack, pack_min, pack_max) != common::RSValue::RS_NONE || + IsValue(pack_max2, pack_max2, pack, pack_min, pack_max) != common::RSValue::RS_NONE) return true; // intersection found (extreme values) if (ExactMode(pack_min, pack_max) && ExactMode(pack_min2, pack_max2)) { // exact mode @@ -175,7 +176,8 @@ void RSIndex_Hist::Update(common::PACK_INDEX pi, DPN &dpn, const PackInt *pack) } if (hdr.no_pack > capacity) { capacity += 1024; - hist_buffers = static_cast(rc_realloc(hist_buffers, capacity * sizeof(BLOCK), mm::BLOCK_TEMPORARY)); + hist_buffers = + static_cast(rc_realloc(hist_buffers, capacity * sizeof(BLOCK), mm::BLOCK_TYPE::BLOCK_TEMPORARY)); // rclog << lock << "hist filter capacity increased to " << capacity << // system::unlock; } diff --git a/storage/stonedb/core/rsi_histogram.h b/storage/stonedb/core/rsi_histogram.h index 44781dcb7..a40ae4c73 100644 --- a/storage/stonedb/core/rsi_histogram.h +++ b/storage/stonedb/core/rsi_histogram.h @@ -41,10 +41,10 @@ class RSIndex_Hist final : public RSIndex { // Return true if there is any common value possible for two packs from two // different columns (histograms). - // Results: common::RS_NONE - there is no objects having values between + // Results: common::RSValue::RS_NONE - there is no objects having values between // min_v and max_v (including) - // common::RS_SOME - some objects from this pack do have values - // between min_v and max_v common::RS_ALL - all objects from + // common::RSValue::RS_SOME - some objects from this pack do have values + // between min_v and max_v common::RSValue::RS_ALL - all objects from // this pack do have values between min_v and max_v bool Intersection(int pack, int64_t pack_min, int64_t pack_max, RSIndex_Hist *sec, int pack2, int64_t pack_min2, int64_t pack_max2); diff --git a/storage/stonedb/core/rsi_index.h b/storage/stonedb/core/rsi_index.h index 1a05518d5..4c77d14d0 100644 --- a/storage/stonedb/core/rsi_index.h +++ b/storage/stonedb/core/rsi_index.h @@ -36,7 +36,7 @@ class RSIndex : public mm::TraceableObject { public: RSIndex() = default; virtual ~RSIndex() = default; - mm::TO_TYPE TraceableType() const override { return mm::TO_RSINDEX; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_RSINDEX; } virtual void SaveToFile(common::TX_ID ver) = 0; protected: diff --git a/storage/stonedb/core/sorter3.cpp b/storage/stonedb/core/sorter3.cpp index c6041e7c8..cc4c54030 100644 --- a/storage/stonedb/core/sorter3.cpp +++ b/storage/stonedb/core/sorter3.cpp @@ -59,9 +59,10 @@ SorterOnePass::SorterOnePass(uint _size, uint _key_bytes, uint _total_bytes) bound_queue = NULL; buf_tmp = NULL; if (size > 0) { - buf = (unsigned char *)alloc(size * total_bytes, mm::BLOCK_TEMPORARY, true); + buf = (unsigned char *)alloc(size * total_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (buf == NULL) throw common::OutOfMemoryException(); - bound_queue = (unsigned char **)alloc(bound_queue_size * 2 * sizeof(unsigned char *), mm::BLOCK_TEMPORARY, true); + bound_queue = + (unsigned char **)alloc(bound_queue_size * 2 * sizeof(unsigned char *), mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (bound_queue == NULL) { dealloc(buf); throw common::OutOfMemoryException(); @@ -90,7 +91,7 @@ bool SorterOnePass::PutValue(unsigned char *b) { } bool SorterOnePass::PutValue(Sorter3 *s) { - STONEDB_LOG(WARN, "SorterOnePass PutValue merger, never verified."); + STONEDB_LOG(LogCtl_Level::WARN, "SorterOnePass PutValue merger, never verified."); DEBUG_ASSERT(buf_input_pos < buf_end); already_sorted = false; SorterOnePass *sp = (SorterOnePass *)s; @@ -233,7 +234,7 @@ bool SorterMultiPass::PutValue(unsigned char *b) { } bool SorterMultiPass::PutValue([[maybe_unused]] Sorter3 *s) { - STONEDB_LOG(WARN, "PutValue Stub, should not see it now"); + STONEDB_LOG(LogCtl_Level::WARN, "PutValue Stub, should not see it now"); return true; } @@ -275,7 +276,7 @@ void SorterMultiPass::InitHeap() { if (rows_in_small_buffer < 3) { // extremely rare case: very large data, very small memory rows_in_small_buffer = 3; dealloc(buf); - buf = (unsigned char *)alloc(3 * total_bytes * no_blocks, mm::BLOCK_TEMPORARY, true); + buf = (unsigned char *)alloc(3 * total_bytes * no_blocks, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (buf == NULL) throw common::OutOfMemoryException(); } int standard_buf_size = rows_in_small_buffer * total_bytes; @@ -322,9 +323,9 @@ SorterMultiPass::Keyblock SorterMultiPass::GetFromBlock(int b, bool &reloaded) { SorterCounting::SorterCounting(uint _size, uint _key_bytes, uint _total_bytes) : Sorter3(_size, _key_bytes, _total_bytes) { - buf = (unsigned char *)alloc(size * total_bytes, mm::BLOCK_TEMPORARY, true); + buf = (unsigned char *)alloc(size * total_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (buf == NULL) throw common::OutOfMemoryException(); - buf_output = (unsigned char *)alloc(size * total_bytes, mm::BLOCK_TEMPORARY, true); + buf_output = (unsigned char *)alloc(size * total_bytes, mm::BLOCK_TYPE::BLOCK_TEMPORARY, true); if (buf_output == NULL) { dealloc(buf); throw common::OutOfMemoryException(); @@ -356,7 +357,7 @@ bool SorterCounting::PutValue(unsigned char *b) { } bool SorterCounting::PutValue([[maybe_unused]] Sorter3 *s) { - STONEDB_LOG(WARN, "PutValue Stub, should not see it now"); + STONEDB_LOG(LogCtl_Level::WARN, "PutValue Stub, should not see it now"); return true; } @@ -474,16 +475,17 @@ bool SorterLimit::PutValue(Sorter3 *s) { // not called uint tmp_noobj = sl->GetObjNo(); unsigned char *buf1 = sl->Getbuf(); - STONEDB_LOG(DEBUG, "PutValue: total bytes %d, tmp_noobj %ld ", total_bytes, tmp_noobj); + STONEDB_LOG(LogCtl_Level::DEBUG, "PutValue: total bytes %d, tmp_noobj %ld ", total_bytes, tmp_noobj); if (tmp_noobj) { if (no_obj + tmp_noobj <= size) { std::memcpy(buf + no_obj * total_bytes, buf1, tmp_noobj * total_bytes); no_obj += tmp_noobj; - STONEDB_LOG(DEBUG, "PutValue: no_obj %ld, tmp_noobj %ld, total_bytes %ld buf %s", no_obj, tmp_noobj, total_bytes, - buf); + STONEDB_LOG(LogCtl_Level::DEBUG, "PutValue: no_obj %ld, tmp_noobj %ld, total_bytes %ld buf %s", no_obj, tmp_noobj, + total_bytes, buf); } else { - STONEDB_LOG(ERROR, "error in Putvalue, out of boundary size %d no_obj+tmp_noobj %d", size, no_obj + tmp_noobj); + STONEDB_LOG(LogCtl_Level::ERROR, "error in Putvalue, out of boundary size %d no_obj+tmp_noobj %d", size, + no_obj + tmp_noobj); throw common::OutOfMemoryException("Out of boundary after merge sorters together."); return false; } diff --git a/storage/stonedb/core/sorter3.h b/storage/stonedb/core/sorter3.h index ba867f218..35c2933af 100644 --- a/storage/stonedb/core/sorter3.h +++ b/storage/stonedb/core/sorter3.h @@ -63,7 +63,7 @@ class Sorter3 : public mm::TraceableObject { Memory management For internal use only. */ - mm::TO_TYPE TraceableType() const override { return mm::TO_SORTER; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_SORTER; } int Compress() { return 0; } // the first stage of conserving memory: delete all redundant data diff --git a/storage/stonedb/core/sorter_wrapper.cpp b/storage/stonedb/core/sorter_wrapper.cpp index fcc93dbeb..5ad74f669 100644 --- a/storage/stonedb/core/sorter_wrapper.cpp +++ b/storage/stonedb/core/sorter_wrapper.cpp @@ -211,7 +211,8 @@ void SorterWrapper::SortRoughly(std::vector &po) { int dim = input_cols[rough_sort_by].col->GetDim(); bool asc = (input_cols[rough_sort_by].sort_order > 0); // ascending sort // start with best packs to possibly roughly exclude others - po[dim].Init(input_cols[rough_sort_by].col, (asc ? PackOrderer::MaxAsc : PackOrderer::MinDesc)); + po[dim].Init(input_cols[rough_sort_by].col, + (asc ? PackOrderer::OrderType::MaxAsc : PackOrderer::OrderType::MinDesc)); } } @@ -231,8 +232,8 @@ bool SorterWrapper::InitPackrow(MIIterator &mit) // return true if the packrow } } - STONEDB_LOG(DEBUG, "InitPackrow: no_values_encoded %d, begin to loadpacks scol size %d ", no_values_encoded, - scol.size()); + STONEDB_LOG(LogCtl_Level::DEBUG, "InitPackrow: no_values_encoded %d, begin to loadpacks scol size %d ", + no_values_encoded, scol.size()); // Not excluded: lock packs if (!rceng->query_thread_pool.is_owner()) { utils::result_set res; @@ -263,7 +264,7 @@ bool SorterWrapper::PutValues(MIIterator &mit) { bool SorterWrapper::PutValues(SorterWrapper &sw) { if (s == NULL) return false; // trivial sorter (constant values) no_values_encoded += sw.GetEncodedValNum(); - STONEDB_LOG(DEBUG, "PutValues: no_values_encoded %d \n", no_values_encoded); + STONEDB_LOG(LogCtl_Level::DEBUG, "PutValues: no_values_encoded %d \n", no_values_encoded); return s->PutValue(sw.GetSorter()); } diff --git a/storage/stonedb/core/table_share.cpp b/storage/stonedb/core/table_share.cpp index 9dfe1b89d..db68d285e 100644 --- a/storage/stonedb/core/table_share.cpp +++ b/storage/stonedb/core/table_share.cpp @@ -58,12 +58,12 @@ TableShare::~TableShare() { thr_lock_delete(&thr_lock); if (current.use_count() > 1) - STONEDB_LOG(FATAL, "TableShare still has ref outside by current %ld", current.use_count()); + STONEDB_LOG(LogCtl_Level::FATAL, "TableShare still has ref outside by current %ld", current.use_count()); - if (!write_table.expired()) STONEDB_LOG(FATAL, "TableShare still has ref outside by write table"); + if (!write_table.expired()) STONEDB_LOG(LogCtl_Level::FATAL, "TableShare still has ref outside by write table"); for (auto &t : versions) - if (!t.expired()) STONEDB_LOG(FATAL, "TableShare still has ref outside by old versions"); + if (!t.expired()) STONEDB_LOG(LogCtl_Level::FATAL, "TableShare still has ref outside by old versions"); } std::shared_ptr TableShare::GetSnapshot() { diff --git a/storage/stonedb/core/temp_table.cpp b/storage/stonedb/core/temp_table.cpp index a73eff243..c228d0131 100644 --- a/storage/stonedb/core/temp_table.cpp +++ b/storage/stonedb/core/temp_table.cpp @@ -924,7 +924,7 @@ TempTable::~TempTable() { void TempTable::TranslateBackVCs() { for (int i = 0; i < no_global_virt_cols; i++) - if (virt_cols[i] && virt_cols[i]->IsSingleColumn()) + if (virt_cols[i] && static_cast(virt_cols[i]->IsSingleColumn())) static_cast(virt_cols[i])->TranslateSourceColumns(attr_back_translation); } @@ -994,7 +994,7 @@ std::shared_ptr TempTable::CreateMaterializedCopy(bool translate_orde // TODO: redesign it for more universal solution vcolumn::VirtualColumn *vc = working_copy->virt_cols[i]; if (vc) { - if (vc->IsSingleColumn()) + if (static_cast(vc->IsSingleColumn())) static_cast(vc)->TranslateSourceColumns(attr_translation); else { auto &var_maps = vc->GetVarMap(); @@ -1094,10 +1094,10 @@ uint TempTable::GetDisplayableAttrIndex(uint attr) { void TempTable::AddConds(Condition *cond, CondType type) { MEASURE_FET("TempTable::AddConds(...)"); - if (type == WHERE_COND) { + if (type == CondType::WHERE_COND) { // need to add one by one since where_conds can be non-empty filter.AddConditions(cond); - } else if (type == HAVING_COND) { + } else if (type == CondType::HAVING_COND) { DEBUG_ASSERT((*cond)[0].tree); having_conds.AddDescriptor((*cond)[0].tree, this, (*cond)[0].left_dims.Size()); } else @@ -1121,15 +1121,15 @@ void TempTable::AddLeftConds(Condition *cond, std::vector &left_aliases, void TempTable::SetMode(TMParameter mode, int64_t mode_param1, int64_t mode_param2) { switch (mode) { - case TM_DISTINCT: + case TMParameter::TM_DISTINCT: this->mode.distinct = true; break; - case TM_TOP: + case TMParameter::TM_TOP: this->mode.top = true; this->mode.param1 = mode_param1; // offset this->mode.param2 = mode_param2; // limit break; - case TM_EXISTS: + case TMParameter::TM_EXISTS: this->mode.exists = true; break; default: @@ -1303,9 +1303,9 @@ void TempTable::Union(TempTable *t, int all) { if (first_f.Get(pos)) { for (uint i = 0; i < encoder.size(); i++) encoder[i].Encode(input_buf, first_mit); GDTResult res = dist_table.Add(input_buf); - if (res == GDT_EXISTS) first_mask.ResetDelayed(pos); - if (res != GDT_FULL) // note: if v is omitted here, it will also be - // omitted in sec! + if (res == GDTResult::GDT_EXISTS) first_mask.ResetDelayed(pos); + if (res != GDTResult::GDT_FULL) // note: if v is omitted here, it will also be + // omitted in sec! first_f.ResetDelayed(pos); } ++first_mit; @@ -1317,8 +1317,8 @@ void TempTable::Union(TempTable *t, int all) { if (sec_f.Get(pos)) { for (uint i = 0; i < encoder.size(); i++) encoder[i].Encode(input_buf, sec_mit, sec_vcs[i].get()); GDTResult res = dist_table.Add(input_buf); - if (res == GDT_EXISTS) sec_mask.ResetDelayed(pos); - if (res != GDT_FULL) sec_f.ResetDelayed(pos); + if (res == GDTResult::GDT_EXISTS) sec_mask.ResetDelayed(pos); + if (res != GDTResult::GDT_FULL) sec_f.ResetDelayed(pos); } ++sec_mit; if (m_conn->Killed()) throw common::KilledException(); diff --git a/storage/stonedb/core/temp_table.h b/storage/stonedb/core/temp_table.h index 32c8250b0..13099d982 100644 --- a/storage/stonedb/core/temp_table.h +++ b/storage/stonedb/core/temp_table.h @@ -87,7 +87,7 @@ class TempTable : public JustATable { // filled in } - enum phys_col_t ColType() const override { return ATTR; } + enum phys_col_t ColType() const override { return phys_col_t::ATTR; } //! Use in cases where actual string length is less than declared, before //! materialization of Attr void OverrideStringSize(int size) { @@ -146,11 +146,11 @@ class TempTable : public JustATable { int AttrNo() const override { return -1; } common::RSValue RoughCheck([[maybe_unused]] int pack, [[maybe_unused]] Descriptor &d, [[maybe_unused]] bool additional_nulls_possible) override { - return common::RS_SOME; + return common::RSValue::RS_SOME; } common::RSValue RoughCheck([[maybe_unused]] int pack1, [[maybe_unused]] int pack2, [[maybe_unused]] Descriptor &d) override { - return common::RS_SOME; + return common::RSValue::RS_SOME; } // as far as Attr is not pack oriented the function below should not be // called diff --git a/storage/stonedb/core/temp_table_com.cpp b/storage/stonedb/core/temp_table_com.cpp index 60f5ffa7d..b7845f3e2 100644 --- a/storage/stonedb/core/temp_table_com.cpp +++ b/storage/stonedb/core/temp_table_com.cpp @@ -58,7 +58,7 @@ TempTable::TempTable(JustATable *t, int alias, Query *q) } void TempTable::JoinT(JustATable *t, int alias, JoinType jt) { - if (jt != JO_INNER) throw common::NotImplementedException("left/right/outer join is not implemented."); + if (jt != JoinType::JO_INNER) throw common::NotImplementedException("left/right/outer join is not implemented."); tables.push_back(t); aliases.push_back(alias); @@ -81,7 +81,7 @@ void TempTable::JoinT(JustATable *t, int alias, JoinType jt) { } // namespace core vcolumn::VirtualColumn *CreateVCCopy(vcolumn::VirtualColumn *vc) { - if (vc->IsSingleColumn()) { + if (static_cast(vc->IsSingleColumn())) { return new vcolumn::SingleColumn(*static_cast(vc)); } else if (dynamic_cast(vc)) { return new vcolumn::ExpressionColumn(*static_cast(vc)); diff --git a/storage/stonedb/core/temp_table_low.cpp b/storage/stonedb/core/temp_table_low.cpp index 09f0513af..ecc20c404 100644 --- a/storage/stonedb/core/temp_table_low.cpp +++ b/storage/stonedb/core/temp_table_low.cpp @@ -81,7 +81,7 @@ bool TempTable::OrderByAndMaterialize(std::vector &ord, int64_t // recheck the up threashold for each SortLimit sub-sortedtable if (((packs_no - 1) * ((1 << filter.mind->NoPower()) - 1)) / task_num < (limit + offset)) { task_num = 1; - STONEDB_LOG(INFO, "Beyond uplimit of limit sort, switch to single thread logic. "); + STONEDB_LOG(LogCtl_Level::INFO, "Beyond uplimit of limit sort, switch to single thread logic. "); } total_limit = task_num * (limit + offset); } @@ -144,7 +144,8 @@ bool TempTable::OrderByAndMaterialize(std::vector &ord, int64_t else sorted_table.InitSorter(*(filter.mind), false); if (sorted_table.GetSorter() && std::strcmp(sorted_table.GetSorter()->Name(), "Heap Sort") != 0) { - STONEDB_LOG(DEBUG, "Multi-thread order by is not supported for %s table.", sorted_table.GetSorter()->Name()); + STONEDB_LOG(LogCtl_Level::DEBUG, "Multi-thread order by is not supported for %s table.", + sorted_table.GetSorter()->Name()); task_num = 1; } // Put data @@ -188,7 +189,7 @@ bool TempTable::OrderByAndMaterialize(std::vector &ord, int64_t for (int i = 0; i < task_num; ++i) { int pstart = ((i == 0) ? 0 : mod + i * num); int pend = mod + (i + 1) * num - 1; - STONEDB_LOG(INFO, "create new MIIterator: start pack %d, endpack %d", pstart, pend); + STONEDB_LOG(LogCtl_Level::INFO, "create new MIIterator: start pack %d, endpack %d", pstart, pend); auto &mi = mis.emplace_back(*filter.mind, true); @@ -199,7 +200,7 @@ bool TempTable::OrderByAndMaterialize(std::vector &ord, int64_t mii.RewindToPack(pstart); } - STONEDB_LOG(DEBUG, "table statistic no_dim %d, packs_no %d \n", one_dim, packs_no); + STONEDB_LOG(LogCtl_Level::DEBUG, "table statistic no_dim %d, packs_no %d \n", one_dim, packs_no); // Repeat the same logic to prepare the new sort tables // Note: Don't RoughSort them as it would impact initPack logic // and some rows would be skipped from adding in the sort table @@ -218,7 +219,7 @@ bool TempTable::OrderByAndMaterialize(std::vector &ord, int64_t } } - STONEDB_LOG(DEBUG, + STONEDB_LOG(LogCtl_Level::DEBUG, "SortTable preparation done. row num %d, offset %d, limit %d, " "task_num %d", local_row, offset, limit, task_num); @@ -290,13 +291,13 @@ bool TempTable::OrderByAndMaterialize(std::vector &ord, int64_t sender->Send(iter); ++iter; } - // STONEDB_LOG(DEBUG, "Put sort output - %d rows in sender", local_row); + // STONEDB_LOG(LogCtl_Level::DEBUG, "Put sort output - %d rows in sender", local_row); local_row = 0; } } while (valid && global_row < limit + offset); rccontrol.lock(m_conn->GetThreadID()) << "Sorted end, rows retrieved." << system::unlock; - // STONEDB_LOG(INFO, "OrderByAndMaterialize complete global_row %d, limit %d, + // STONEDB_LOG(LogCtl_Level::INFO, "OrderByAndMaterialize complete global_row %d, limit %d, // offset %d", global_row, limit, offset); return true; } @@ -551,7 +552,7 @@ size_t TempTable::TaskPutValueInST(MIIterator *it, Transaction *ci, SorterWrappe local_row += it->GetPackSizeLeft(); it->NextPackrow(); - STONEDB_LOG(DEBUG, "skip this pack it %x", it); + STONEDB_LOG(LogCtl_Level::DEBUG, "skip this pack it %x", it); continue; } } diff --git a/storage/stonedb/core/temp_table_roughquery.cpp b/storage/stonedb/core/temp_table_roughquery.cpp index edbc1e1c4..b94df73f2 100644 --- a/storage/stonedb/core/temp_table_roughquery.cpp +++ b/storage/stonedb/core/temp_table_roughquery.cpp @@ -68,7 +68,7 @@ void TempTable::RoughAggregateMinMax(vcolumn::VirtualColumn *vc, int64_t &min_va bool double_vals = vc->Type().IsFloat(); MIIterator mit(filter.mind, dim, true); while (mit.IsValid()) { - if (filter.rough_mind->GetPackStatus(dim, mit.GetCurPackrow(dim)) != common::RS_NONE && + if (filter.rough_mind->GetPackStatus(dim, mit.GetCurPackrow(dim)) != common::RSValue::RS_NONE && vc->GetPackOntologicalStatus(mit) != PackOntologicalStatus::NULLS_ONLY) { int64_t v = vc->GetMinInt64(mit); if (v == common::NULL_VALUE_64) @@ -94,9 +94,9 @@ void TempTable::RoughAggregateCount(DimensionVector &dims, int64_t &min_val, int int64_t loc_max = 0; while (mit.IsValid()) { common::RSValue res = filter.rough_mind->GetPackStatus(dim, mit.GetCurPackrow(dim)); - if (res != common::RS_NONE) { + if (res != common::RSValue::RS_NONE) { loc_max += mit.GetPackSizeLeft(); - if (!group_by_present && res == common::RS_ALL) loc_min += mit.GetPackSizeLeft(); + if (!group_by_present && res == common::RSValue::RS_ALL) loc_min += mit.GetPackSizeLeft(); } mit.NextPackrow(); } @@ -139,12 +139,12 @@ void TempTable::RoughAggregateSum(vcolumn::VirtualColumn *vc, int64_t &min_val, no_groups_or_uniform = false; // leave it true only when we are sure the // grouping columns are uniform for this packrow } - if (res != common::RS_NONE && vc->GetPackOntologicalStatus(mit) != PackOntologicalStatus::NULLS_ONLY) { + if (res != common::RSValue::RS_NONE && vc->GetPackOntologicalStatus(mit) != PackOntologicalStatus::NULLS_ONLY) { empty_set = false; success = true; bool nonnegative = false; int64_t v = vc->GetSum(mit, nonnegative); - if (no_groups_or_uniform && res == common::RS_ALL && !distinct_present) { + if (no_groups_or_uniform && res == common::RSValue::RS_ALL && !distinct_present) { if (v == common::NULL_VALUE_64) { // unknown sum success = false; break; @@ -259,7 +259,8 @@ void TempTable::RoughAggregateSum(vcolumn::VirtualColumn *vc, int64_t &min_val, } bool IsTempTableColumn(vcolumn::VirtualColumn *vc) { - vcolumn::SingleColumn *sc = ((vc && vc->IsSingleColumn()) ? static_cast(vc) : NULL); + vcolumn::SingleColumn *sc = + ((vc && static_cast(vc->IsSingleColumn())) ? static_cast(vc) : NULL); return (sc && sc->IsTempTableColumn()); } @@ -270,7 +271,7 @@ void TempTable::RoughAggregate(ResultSender *sender) { filter.mind - multiindex with nontrivial contents, although not necessarily updated by conditions filter.rough_mind - rough multiindex with more up-to-date contents than mind, i.e. a packrow may - exist in mind, but be marked as common::RS_NONE in rough_mind To check a + exist in mind, but be marked as common::RSValue::RS_NONE in rough_mind To check a rough status of a packrow, use both mind and rough_mind. The method does not change mind / rough_mind. @@ -303,11 +304,11 @@ void TempTable::RoughAggregate(ResultSender *sender) { bool local_some = true; // true if no pack is full for (int pack = 0; pack < filter.rough_mind->NoPacks(dim); pack++) { common::RSValue res = filter.rough_mind->GetPackStatus(dim, pack); - if (res != common::RS_NONE) { + if (res != common::RSValue::RS_NONE) { local_empty = false; if (rough_is_empty != false) break; } - if (res == common::RS_ALL) { + if (res == common::RSValue::RS_ALL) { local_some = false; break; } @@ -341,8 +342,9 @@ void TempTable::RoughAggregate(ResultSender *sender) { if (!vc->Type().IsString() && !vc->Type().IsLookup() && vc->GetDim() == 0) { std::vector po(1); po[0].Init(vc, - (asc ? PackOrderer::MaxAsc : PackOrderer::MinDesc), // start with best packs to possibly - // roughly exclude others + (asc ? PackOrderer::OrderType::MaxAsc + : PackOrderer::OrderType::MinDesc), // start with best packs to possibly + // roughly exclude others filter.rough_mind->GetRSValueTable(0)); DimensionVector loc_dims(1); loc_dims[0] = true; @@ -354,7 +356,7 @@ void TempTable::RoughAggregate(ResultSender *sender) { bool cutoff_is_null = false; // true if all values up to limit are NULL for ascending while (mit.IsValid()) { common::RSValue res = filter.rough_mind->GetPackStatus(0, mit.GetCurPackrow(0)); - if (res == common::RS_ALL) { + if (res == common::RSValue::RS_ALL) { // Algorithm for ascending: // - cutoff value is the maximum of the first full data pack which // hit the limit @@ -372,7 +374,7 @@ void TempTable::RoughAggregate(ResultSender *sender) { int64_t local_stat = common::NULL_VALUE_64; while (mit.IsValid()) { common::RSValue res = filter.rough_mind->GetPackStatus(0, mit.GetCurPackrow(0)); - if (res != common::RS_NONE) { + if (res != common::RSValue::RS_NONE) { bool omit = false; if (asc) { local_stat = vc->GetMinInt64(mit); // omit if pack minimum is larger than cutoff @@ -388,7 +390,7 @@ void TempTable::RoughAggregate(ResultSender *sender) { (!double_vals && local_stat < cutoff_value))) omit = true; } - if (omit) filter.rough_mind->SetPackStatus(0, mit.GetCurPackrow(0), common::RS_NONE); + if (omit) filter.rough_mind->SetPackStatus(0, mit.GetCurPackrow(0), common::RSValue::RS_NONE); } mit.NextPackrow(); } @@ -400,10 +402,10 @@ void TempTable::RoughAggregate(ResultSender *sender) { MIIterator mit(filter.mind, filter.mind->NoPower()); while (mit.IsValid()) { if (omit_the_rest) { - filter.rough_mind->SetPackStatus(0, mit.GetCurPackrow(0), common::RS_NONE); + filter.rough_mind->SetPackStatus(0, mit.GetCurPackrow(0), common::RSValue::RS_NONE); } else { common::RSValue res = filter.rough_mind->GetPackStatus(0, mit.GetCurPackrow(0)); - if (res == common::RS_ALL) { + if (res == common::RSValue::RS_ALL) { certain_rows += mit.GetPackSizeLeft(); if (certain_rows >= local_limit) omit_the_rest = true; } @@ -499,10 +501,11 @@ void TempTable::RoughAggregate(ResultSender *sender) { MIIterator mit(filter.mind, dim, true); while (mit.IsValid()) { common::RSValue res = filter.rough_mind->GetPackStatus(dim, mit.GetCurPackrow(dim)); - if (res != common::RS_NONE && vc->GetPackOntologicalStatus(mit) != PackOntologicalStatus::NULLS_ONLY) { + if (res != common::RSValue::RS_NONE && + vc->GetPackOntologicalStatus(mit) != PackOntologicalStatus::NULLS_ONLY) { min_val = UpdateMin(min_val, vc->GetMinInt64(mit), double_vals); max_val = UpdateMax(max_val, vc->GetMaxInt64(mit), double_vals); - if (!skip_counting && !group_by_present && res == common::RS_ALL) { + if (!skip_counting && !group_by_present && res == common::RSValue::RS_ALL) { int64_t exact_val = is_min ? vc->GetMinInt64Exact(mit) : vc->GetMaxInt64Exact(mit); if (exact_val != common::NULL_VALUE_64) relevant_val = is_min ? UpdateMin(relevant_val, exact_val, double_vals) @@ -541,9 +544,9 @@ void TempTable::RoughAggregate(ResultSender *sender) { if (!nulls_only) { while (mit.IsValid()) { common::RSValue res = filter.rough_mind->GetPackStatus(dim, mit.GetCurPackrow(dim)); - if (res != common::RS_NONE) { + if (res != common::RSValue::RS_NONE) { max_val += mit.GetPackSizeLeft(); - if (!group_by_present && res == common::RS_ALL) { + if (!group_by_present && res == common::RSValue::RS_ALL) { int64_t no_nulls = vc->GetNoNulls(mit); if (no_nulls != common::NULL_VALUE_64) { min_val += mit.GetPackSizeLeft() - no_nulls; @@ -575,9 +578,9 @@ void TempTable::RoughAggregate(ResultSender *sender) { int64_t loc_max = 0; while (mit.IsValid()) { common::RSValue res = filter.rough_mind->GetPackStatus(dim, mit.GetCurPackrow(dim)); - if (res != common::RS_NONE) loc_max += mit.GetPackSizeLeft(); - if (res == common::RS_ALL && !group_by_present) min_count_star += mit.GetPackSizeLeft(); - if (res != common::RS_ALL) all_only = false; + if (res != common::RSValue::RS_NONE) loc_max += mit.GetPackSizeLeft(); + if (res == common::RSValue::RS_ALL && !group_by_present) min_count_star += mit.GetPackSizeLeft(); + if (res != common::RSValue::RS_ALL) all_only = false; mit.NextPackrow(); } max_count_star = diff --git a/storage/stonedb/core/transaction.cpp b/storage/stonedb/core/transaction.cpp index 1a13c993d..715956475 100644 --- a/storage/stonedb/core/transaction.cpp +++ b/storage/stonedb/core/transaction.cpp @@ -84,7 +84,7 @@ void Transaction::Commit([[maybe_unused]] THD *thd) { } void Transaction::Rollback([[maybe_unused]] THD *thd, bool force_error_message) { - STONEDB_LOG(INFO, "rollback transaction %s.", tid.ToString().c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "rollback transaction %s.", tid.ToString().c_str()); std::shared_lock rlock(drop_rename_mutex); if (m_modified_tables.size()) { @@ -92,7 +92,7 @@ void Transaction::Rollback([[maybe_unused]] THD *thd, bool force_error_message) const char *message = "StoneDB storage engine has encountered an unexpected error. " "The current transaction has been rolled back."; - STONEDB_LOG(ERROR, "%s", message); + STONEDB_LOG(LogCtl_Level::ERROR, "%s", message); my_message(ER_XA_RBROLLBACK, message, MYF(0)); } } diff --git a/storage/stonedb/core/value_matching_hashtable.h b/storage/stonedb/core/value_matching_hashtable.h index 6651d1278..d41f8d8c2 100644 --- a/storage/stonedb/core/value_matching_hashtable.h +++ b/storage/stonedb/core/value_matching_hashtable.h @@ -55,7 +55,7 @@ class ValueMatching_HashTable : public mm::TraceableObject, public ValueMatching bool IsOnePass() override { return one_pass; } int64_t ByteSize() override; int64_t RowNumberScope() override { return max_no_rows; } - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } protected: // Definition of the internal structures: diff --git a/storage/stonedb/core/value_matching_table.cpp b/storage/stonedb/core/value_matching_table.cpp index 88a79a2ce..6398b72bc 100644 --- a/storage/stonedb/core/value_matching_table.cpp +++ b/storage/stonedb/core/value_matching_table.cpp @@ -129,7 +129,7 @@ ValueMatching_LookupTable::ValueMatching_LookupTable(ValueMatching_LookupTable & } else occupied_table = NULL; - t = (unsigned char *)alloc(total_width * max_no_rows, mm::BLOCK_TEMPORARY); + t = (unsigned char *)alloc(total_width * max_no_rows, mm::BLOCK_TYPE::BLOCK_TEMPORARY); t_aggr = t + input_buffer_width; std::memcpy(t, sec.t, total_width * max_no_rows); } @@ -155,7 +155,7 @@ void ValueMatching_LookupTable::Init(int64_t max_group_code, int _total_width, i max_no_rows = max_group_code + 1; // easy case: the row number is just the coded value - t = (unsigned char *)alloc(total_width * max_no_rows, mm::BLOCK_TEMPORARY); + t = (unsigned char *)alloc(total_width * max_no_rows, mm::BLOCK_TYPE::BLOCK_TEMPORARY); t_aggr = t + input_buffer_width; // initialize structures diff --git a/storage/stonedb/core/value_matching_table.h b/storage/stonedb/core/value_matching_table.h index fe6e75248..520098dc9 100644 --- a/storage/stonedb/core/value_matching_table.h +++ b/storage/stonedb/core/value_matching_table.h @@ -164,7 +164,7 @@ class ValueMatching_LookupTable : public mm::TraceableObject, public ValueMatchi bool IsOnePass() override { return true; } int64_t ByteSize() override { return (total_width + sizeof(int)) * max_no_rows; } int64_t RowNumberScope() override { return max_no_rows; } - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } protected: unsigned char *t; // common buffer for grouping values and results of aggregations diff --git a/storage/stonedb/core/value_or_null.h b/storage/stonedb/core/value_or_null.h index ada40abc6..30e75507c 100644 --- a/storage/stonedb/core/value_or_null.h +++ b/storage/stonedb/core/value_or_null.h @@ -97,7 +97,7 @@ class ValueOrNull final { private: int64_t x; // 8-byte value of an expression; interpreted as int64_t or double char *sp = nullptr; // != 0 if string value assigned - uint len = 0; // string length; used only for VT_STRING + uint len = 0; // string length; used only for ValueType::VT_STRING bool string_owner = false; // if true, destructor must deallocate sp bool null; diff --git a/storage/stonedb/handler/ha_rcengine.cpp b/storage/stonedb/handler/ha_rcengine.cpp index 69d72bf72..51cbe1972 100644 --- a/storage/stonedb/handler/ha_rcengine.cpp +++ b/storage/stonedb/handler/ha_rcengine.cpp @@ -25,18 +25,18 @@ namespace stonedb { namespace dbhandler { -enum SDBEngineReturnValues { LD_Successed = 100, LD_Failed = 101, LD_Continue = 102 }; +enum class SDBEngineReturnValues { LD_Successed = 100, LD_Failed = 101, LD_Continue = 102 }; void SDB_UpdateAndStoreColumnComment(TABLE *table, int field_id, Field *source_field, int source_field_id, - CHARSET_INFO *cs) { + CHARSET_INFO *cs) { try { rceng->UpdateAndStoreColumnComment(table, field_id, source_field, source_field_id, cs); } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s.", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } } @@ -72,7 +72,7 @@ bool SDB_SetStatementAllowed(THD *thd, LEX *lex) { } int SDB_HandleSelect(THD *thd, LEX *lex, select_result *&result, ulong setup_tables_done_option, int &res, - int &optimize_after_sdb, int &sdb_free_join, int with_insert) { + int &optimize_after_sdb, int &sdb_free_join, int with_insert) { int ret = RCBASE_QUERY_ROUTE; try { // handle_select_ret is introduced here because in case of some exceptions @@ -91,33 +91,33 @@ Either restructure the query with supported syntax, or enable the MySQL core::Qu ret = handle_select_ret; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "HandleSelect Error: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "HandleSelect Error: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } return ret; } int SDB_LoadData(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg, char *errmsg, int len, int &errcode) { common::SDBError sdb_error; - int ret = LD_Failed; + int ret = static_cast(SDBEngineReturnValues::LD_Failed); - if (!core::Engine::IsSDBTable(table_list->table)) return LD_Continue; + if (!core::Engine::IsSDBTable(table_list->table)) return static_cast(SDBEngineReturnValues::LD_Continue); try { sdb_error = rceng->RunLoader(thd, ex, table_list, arg); if (sdb_error.GetErrorCode() != common::ErrorCode::SUCCESS) { - STONEDB_LOG(ERROR, "RunLoader Error: %s", sdb_error.Message().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RunLoader Error: %s", sdb_error.Message().c_str()); } else { - ret = LD_Successed; + ret = static_cast(SDBEngineReturnValues::LD_Successed); } } catch (std::exception &e) { sdb_error = common::SDBError(common::ErrorCode::UNKNOWN_ERROR, e.what()); - STONEDB_LOG(ERROR, "RunLoader Error: %s", sdb_error.Message().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RunLoader Error: %s", sdb_error.Message().c_str()); } catch (...) { sdb_error = common::SDBError(common::ErrorCode::UNKNOWN_ERROR, "An unknown system exception error caught."); - STONEDB_LOG(ERROR, "RunLoader Error: %s", sdb_error.Message().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RunLoader Error: %s", sdb_error.Message().c_str()); } std::strncpy(errmsg, sdb_error.Message().c_str(), len - 1); errmsg[len - 1] = '\0'; @@ -129,13 +129,13 @@ int SDB_LoadData(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg, bool stonedb_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg) { char sdbmsg[256]; int sdberrcode; - switch (SDB_LoadData(thd, ex, table_list, arg, sdbmsg, 256, sdberrcode)) { - case LD_Continue: + switch (static_cast(SDB_LoadData(thd, ex, table_list, arg, sdbmsg, 256, sdberrcode))) { + case SDBEngineReturnValues::LD_Continue: return true; - case LD_Failed: + case SDBEngineReturnValues::LD_Failed: my_message(sdberrcode, sdbmsg, MYF(0)); [[fallthrough]]; - case LD_Successed: + case SDBEngineReturnValues::LD_Successed: return false; default: my_message(sdberrcode, sdbmsg, MYF(0)); diff --git a/storage/stonedb/handler/ha_rcengine.h b/storage/stonedb/handler/ha_rcengine.h index 20f4014d7..59c29a3e9 100644 --- a/storage/stonedb/handler/ha_rcengine.h +++ b/storage/stonedb/handler/ha_rcengine.h @@ -23,12 +23,12 @@ namespace stonedb { namespace dbhandler { void SDB_UpdateAndStoreColumnComment(TABLE *table, int field_id, Field *source_field, int source_field_id, - CHARSET_INFO *cs); + CHARSET_INFO *cs); bool SDB_SetStatementAllowed(THD *thd, LEX *lex); int SDB_HandleSelect(THD *thd, LEX *lex, select_result *&result_output, ulong setup_tables_done_option, int &res, - int &optimize_after_sdb, int &sdb_free_join, int with_insert = false); + int &optimize_after_sdb, int &sdb_free_join, int with_insert = false); bool stonedb_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg); } // namespace dbhandler diff --git a/storage/stonedb/handler/stonedb_handler.cpp b/storage/stonedb/handler/stonedb_handler.cpp index b86f6c9f9..b7f8ee6bb 100644 --- a/storage/stonedb/handler/stonedb_handler.cpp +++ b/storage/stonedb/handler/stonedb_handler.cpp @@ -276,10 +276,10 @@ int StonedbHandler::external_lock(THD *thd, int lock_type) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "StoneDB internal error", MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s.", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } // destroy the tx on failure @@ -422,24 +422,24 @@ int StonedbHandler::write_row([[maybe_unused]] uchar *buf) { } catch (common::OutOfMemoryException &e) { DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT); } catch (common::DatabaseException &e) { - STONEDB_LOG(ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); } catch (common::FormatException &e) { - STONEDB_LOG(ERROR, "An exception is caught in Engine::InsertRow: %s Row: %ld, field %u.", e.what(), e.m_row_no, - e.m_field_no); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s Row: %ld, field %u.", e.what(), + e.m_row_no, e.m_field_no); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); } catch (common::FileException &e) { - STONEDB_LOG(ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); } catch (common::Exception &e) { - STONEDB_LOG(ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); } @@ -499,18 +499,18 @@ int StonedbHandler::update_row(const uchar *old_data, uchar *new_data) { rceng->IncStonedbStatUpdate(); DBUG_RETURN(0); } catch (common::DatabaseException &e) { - STONEDB_LOG(ERROR, "Update exception: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Update exception: %s.", e.what()); } catch (common::FileException &e) { - STONEDB_LOG(ERROR, "Update exception: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Update exception: %s.", e.what()); } catch (common::DupKeyException &e) { ret = HA_ERR_FOUND_DUPP_KEY; - STONEDB_LOG(ERROR, "Update exception: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Update exception: %s.", e.what()); } catch (common::Exception &e) { - STONEDB_LOG(ERROR, "Update exception: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Update exception: %s.", e.what()); } catch (std::exception &e) { - STONEDB_LOG(ERROR, "Update exception: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Update exception: %s.", e.what()); } catch (...) { - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); } @@ -555,10 +555,10 @@ int StonedbHandler::rename_table(const char *from, const char *to) { return 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } return 1; } @@ -644,10 +644,10 @@ int StonedbHandler::info(uint flag) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -687,13 +687,13 @@ int StonedbHandler::open(const char *name, [[maybe_unused]] int mode, [[maybe_un ret = 0; } catch (common::Exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Error from StoneDB engine", MYF(0)); - STONEDB_LOG(ERROR, "A stonedb exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "A stonedb exception is caught: %s", e.what()); } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } info(HA_STATUS_CONST); @@ -737,7 +737,7 @@ int StonedbHandler::fill_row_by_id([[maybe_unused]] uchar *buf, uint64_t rowid) } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } DBUG_RETURN(rc); } @@ -777,7 +777,7 @@ int StonedbHandler::index_read([[maybe_unused]] uchar *buf, [[maybe_unused]] con } } else if (find_flag == HA_READ_AFTER_KEY || find_flag == HA_READ_KEY_OR_NEXT) { auto iter = current_tx->KVTrans().KeyIter(); - common::Operator op = (find_flag == HA_READ_AFTER_KEY) ? common::O_MORE : common::O_MORE_EQ; + common::Operator op = (find_flag == HA_READ_AFTER_KEY) ? common::Operator::O_MORE : common::Operator::O_MORE_EQ; iter->ScanToKey(index, keys, op); uint64_t rowid; iter->GetRowid(rowid); @@ -786,18 +786,18 @@ int StonedbHandler::index_read([[maybe_unused]] uchar *buf, [[maybe_unused]] con } else { // not support HA_READ_PREFIX_LAST_OR_PREV HA_READ_PREFIX_LAST rc = HA_ERR_WRONG_COMMAND; - STONEDB_LOG(ERROR, "Error: index_read not support prefix search"); + STONEDB_LOG(LogCtl_Level::ERROR, "Error: index_read not support prefix search"); } } else { // other index not support rc = HA_ERR_WRONG_INDEX; - STONEDB_LOG(ERROR, "Error: index_read only support primary key"); + STONEDB_LOG(LogCtl_Level::ERROR, "Error: index_read only support primary key"); } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } DBUG_RETURN(rc); @@ -821,7 +821,7 @@ int StonedbHandler::index_next([[maybe_unused]] uchar *buf) { } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } DBUG_RETURN(rc); } @@ -844,7 +844,7 @@ int StonedbHandler::index_prev([[maybe_unused]] uchar *buf) { } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } DBUG_RETURN(rc); } @@ -873,7 +873,7 @@ int StonedbHandler::index_first([[maybe_unused]] uchar *buf) { } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } DBUG_RETURN(rc); } @@ -902,7 +902,7 @@ int StonedbHandler::index_last([[maybe_unused]] uchar *buf) { } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } DBUG_RETURN(rc); } @@ -946,7 +946,7 @@ int StonedbHandler::rnd_init(bool scan) { } catch (common::Exception const &e) { rccontrol << system::lock << "Error in push-down execution, push-down execution aborted: " << e.what() << system::unlock; - STONEDB_LOG(ERROR, "An exception is caught in push-down execution: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught in push-down execution: %s", e.what()); } m_query.reset(); m_cq.reset(); @@ -967,10 +967,10 @@ int StonedbHandler::rnd_init(bool scan) { if (table_ptr != NULL) blob_buffers.resize(table_ptr->NoDisplaybleAttrs()); } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -1004,10 +1004,10 @@ int StonedbHandler::rnd_next(uchar *buf) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -1068,10 +1068,10 @@ int StonedbHandler::rnd_pos(uchar *buf, uchar *pos) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -1103,10 +1103,10 @@ int StonedbHandler::start_stmt(THD *thd, thr_lock_type lock_type) { } } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } return 0; } @@ -1145,10 +1145,10 @@ int StonedbHandler::delete_table(const char *name) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -1187,14 +1187,14 @@ int StonedbHandler::create(const char *name, TABLE *table_arg, [[maybe_unused]] } catch (common::UnsupportedDataTypeException &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); } catch (fs::filesystem_error &e) { - STONEDB_LOG(ERROR, "filesystem_error on table creation '%s'", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "filesystem_error on table creation '%s'", e.what()); fs::remove_all(std::string(name) + common::STONEDB_EXT); } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(1); @@ -1205,10 +1205,10 @@ int StonedbHandler::truncate() { try { rceng->TruncateTable(m_table_name, ha_thd()); } catch (std::exception &e) { - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); ret = 1; } catch (...) { - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); ret = 1; } @@ -1283,10 +1283,10 @@ char *StonedbHandler::update_table_comment(const char *comment) { ret = str; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } return ret; @@ -1329,7 +1329,7 @@ int StonedbHandler::set_cond_iter() { } catch (common::Exception const &e) { rccontrol << system::lock << "Error in push-down execution, push-down execution aborted: " << e.what() << system::unlock; - STONEDB_LOG(ERROR, "Error in push-down execution, push-down execution aborted: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Error in push-down execution, push-down execution aborted: %s", e.what()); } m_query.reset(); m_cq.reset(); @@ -1388,11 +1388,11 @@ const Item *StonedbHandler::cond_push(const Item *a_cond) { std::unique_ptr tmp_cq(new core::CompiledQuery(*m_cq)); core::CondID cond_id; - if (!m_query->BuildConditions(cond, cond_id, tmp_cq.get(), m_tmp_table, core::WHERE_COND, false)) { + if (!m_query->BuildConditions(cond, cond_id, tmp_cq.get(), m_tmp_table, core::CondType::WHERE_COND, false)) { m_query.reset(); return a_cond; } - tmp_cq->AddConds(m_tmp_table, cond_id, core::WHERE_COND); + tmp_cq->AddConds(m_tmp_table, cond_id, core::CondType::WHERE_COND); tmp_cq->ApplyConds(m_tmp_table); m_cq.reset(tmp_cq.release()); // reset table_new_iter with push condition @@ -1400,10 +1400,10 @@ const Item *StonedbHandler::cond_push(const Item *a_cond) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } return ret; } @@ -1424,10 +1424,10 @@ int StonedbHandler::reset() { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -1453,9 +1453,9 @@ bool StonedbHandler::inplace_alter_table(TABLE *altered_table, Alter_inplace_inf return false; } } catch (std::exception &e) { - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Unable to inplace alter table", MYF(0)); @@ -1466,14 +1466,14 @@ bool StonedbHandler::inplace_alter_table(TABLE *altered_table, Alter_inplace_inf bool StonedbHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit) { if (!commit) { - STONEDB_LOG(INFO, "Alter table failed : %s%s", m_table_name.c_str(), " rollback"); + STONEDB_LOG(LogCtl_Level::INFO, "Alter table failed : %s%s", m_table_name.c_str(), " rollback"); return true; } if (ha_alter_info->handler_flags == STONEDB_SUPPORTED_ALTER_COLUMN_NAME) { return false; } if ((ha_alter_info->handler_flags & ~STONEDB_SUPPORTED_ALTER_ADD_DROP_ORDER)) { - STONEDB_LOG(INFO, "Altered table not support type %lu", ha_alter_info->handler_flags); + STONEDB_LOG(LogCtl_Level::INFO, "Altered table not support type %lu", ha_alter_info->handler_flags); return true; } fs::path tmp_dir(m_table_name + ".tmp"); @@ -1497,12 +1497,13 @@ bool StonedbHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_ auto search = s.find(target); if (search == s.end()) { fs::remove_all(target); - STONEDB_LOG(INFO, "removing %s", target.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "removing %s", target.c_str()); } } fs::remove_all(bak_dir); } catch (fs::filesystem_error &e) { - STONEDB_LOG(ERROR, "file system error: %s %s|%s", e.what(), e.path1().string().c_str(), e.path2().string().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "file system error: %s %s|%s", e.what(), e.path1().string().c_str(), + e.path2().string().c_str()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Failed to commit alter table", MYF(0)); return true; } diff --git a/storage/stonedb/handler/stonedb_handler_com.cpp b/storage/stonedb/handler/stonedb_handler_com.cpp index e9ec4a678..75a3bdeed 100644 --- a/storage/stonedb/handler/stonedb_handler_com.cpp +++ b/storage/stonedb/handler/stonedb_handler_com.cpp @@ -79,10 +79,10 @@ int rcbase_rollback([[maybe_unused]] handlerton *hton, THD *thd, bool all) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception error is caught: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception error is caught: %s.", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -98,10 +98,10 @@ int rcbase_close_connection(handlerton *hton, THD *thd) { ret = 0; } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception error is caught: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception error is caught: %s.", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -129,25 +129,25 @@ int rcbase_commit([[maybe_unused]] handlerton *hton, THD *thd, bool all) { try { rceng->Rollback(thd, all, true); if (!error_message.empty()) { - STONEDB_LOG(ERROR, "%s", error_message.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "%s", error_message.c_str()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), error_message.c_str(), MYF(0)); } } catch (std::exception &e) { if (!error_message.empty()) { - STONEDB_LOG(ERROR, "%s", error_message.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "%s", error_message.c_str()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), error_message.c_str(), MYF(0)); } my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), (std::string("Failed to rollback transaction. Error: ") + e.what()).c_str(), MYF(0)); - STONEDB_LOG(ERROR, "Failed to rollback transaction. Error: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to rollback transaction. Error: %s.", e.what()); } catch (...) { if (!error_message.empty()) { - STONEDB_LOG(ERROR, "%s", error_message.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "%s", error_message.c_str()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), error_message.c_str(), MYF(0)); } my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Failed to rollback transaction. Unknown error.", MYF(0)); - STONEDB_LOG(ERROR, "Failed to rollback transaction. Unknown error."); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to rollback transaction. Unknown error."); } } @@ -216,7 +216,7 @@ int rcbase_init_func(void *p) { rceng = new core::Engine(); ret = rceng->Init(total_ha); { - STONEDB_LOG(INFO, + STONEDB_LOG(LogCtl_Level::INFO, "\n" "------------------------------------------------------------" "----------------------------------" @@ -242,10 +242,10 @@ int rcbase_init_func(void *p) { } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); - STONEDB_LOG(ERROR, "An exception error is caught: %s.", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception error is caught: %s.", e.what()); } catch (...) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } DBUG_RETURN(ret); @@ -662,7 +662,7 @@ void resolve_async_join_settings(const std::string &settings) { stonedb_sysvar_async_join_setting.traverse_slices = boost::lexical_cast(splits_vec[2]); stonedb_sysvar_async_join_setting.match_slices = boost::lexical_cast(splits_vec[3]); } catch (...) { - STONEDB_LOG(ERROR, "Failed resolve async join settings"); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed resolve async join settings"); } } } @@ -675,63 +675,63 @@ void async_join_update([[maybe_unused]] MYSQL_THD thd, [[maybe_unused]] struct s } static struct st_mysql_sys_var *sdb_showvars[] = {MYSQL_SYSVAR(bg_load_threads), - MYSQL_SYSVAR(cachinglevel), - MYSQL_SYSVAR(compensation_start), - MYSQL_SYSVAR(control_trace), - MYSQL_SYSVAR(data_distribution_policy), - MYSQL_SYSVAR(disk_usage_threshold), - MYSQL_SYSVAR(distinct_cache_size), - MYSQL_SYSVAR(filterevaluation_speedup), - MYSQL_SYSVAR(global_debug_level), - MYSQL_SYSVAR(groupby_speedup), - MYSQL_SYSVAR(hugefiledir), - MYSQL_SYSVAR(index_cache_size), - MYSQL_SYSVAR(index_search), - MYSQL_SYSVAR(enable_rowstore), - MYSQL_SYSVAR(ini_allowmysqlquerypath), - MYSQL_SYSVAR(ini_cachefolder), - MYSQL_SYSVAR(ini_cachereleasethreshold), - MYSQL_SYSVAR(ini_cachesizethreshold), - MYSQL_SYSVAR(ini_controlquerylog), - MYSQL_SYSVAR(ini_knlevel), - MYSQL_SYSVAR(ini_pushdown), - MYSQL_SYSVAR(ini_servermainheapsize), - MYSQL_SYSVAR(ini_threadpoolsize), - MYSQL_SYSVAR(ini_usemysqlimportexportdefaults), - MYSQL_SYSVAR(insert_buffer_size), - MYSQL_SYSVAR(insert_cntthreshold), - MYSQL_SYSVAR(insert_delayed), - MYSQL_SYSVAR(insert_max_buffered), - MYSQL_SYSVAR(insert_numthreshold), - MYSQL_SYSVAR(insert_wait_ms), - MYSQL_SYSVAR(insert_wait_time), - MYSQL_SYSVAR(join_disable_switch_side), - MYSQL_SYSVAR(enable_histogram_cmap_bloom), - MYSQL_SYSVAR(join_parallel), - MYSQL_SYSVAR(join_splitrows), - MYSQL_SYSVAR(load_threads), - MYSQL_SYSVAR(lookup_max_size), - MYSQL_SYSVAR(max_execution_time), - MYSQL_SYSVAR(minmax_speedup), - MYSQL_SYSVAR(mm_hardlimit), - MYSQL_SYSVAR(mm_largetempratio), - MYSQL_SYSVAR(mm_largetemppool_threshold), - MYSQL_SYSVAR(mm_policy), - MYSQL_SYSVAR(mm_releasepolicy), - MYSQL_SYSVAR(orderby_speedup), - MYSQL_SYSVAR(parallel_filloutput), - MYSQL_SYSVAR(parallel_mapjoin), - MYSQL_SYSVAR(qps_log), - MYSQL_SYSVAR(query_threads), - MYSQL_SYSVAR(refresh_sys_stonedb), - MYSQL_SYSVAR(session_debug_level), - MYSQL_SYSVAR(sync_buffers), - MYSQL_SYSVAR(trigger_error), - MYSQL_SYSVAR(async_join), - MYSQL_SYSVAR(force_hashjoin), - MYSQL_SYSVAR(start_async), - MYSQL_SYSVAR(result_sender_rows), - NULL}; + MYSQL_SYSVAR(cachinglevel), + MYSQL_SYSVAR(compensation_start), + MYSQL_SYSVAR(control_trace), + MYSQL_SYSVAR(data_distribution_policy), + MYSQL_SYSVAR(disk_usage_threshold), + MYSQL_SYSVAR(distinct_cache_size), + MYSQL_SYSVAR(filterevaluation_speedup), + MYSQL_SYSVAR(global_debug_level), + MYSQL_SYSVAR(groupby_speedup), + MYSQL_SYSVAR(hugefiledir), + MYSQL_SYSVAR(index_cache_size), + MYSQL_SYSVAR(index_search), + MYSQL_SYSVAR(enable_rowstore), + MYSQL_SYSVAR(ini_allowmysqlquerypath), + MYSQL_SYSVAR(ini_cachefolder), + MYSQL_SYSVAR(ini_cachereleasethreshold), + MYSQL_SYSVAR(ini_cachesizethreshold), + MYSQL_SYSVAR(ini_controlquerylog), + MYSQL_SYSVAR(ini_knlevel), + MYSQL_SYSVAR(ini_pushdown), + MYSQL_SYSVAR(ini_servermainheapsize), + MYSQL_SYSVAR(ini_threadpoolsize), + MYSQL_SYSVAR(ini_usemysqlimportexportdefaults), + MYSQL_SYSVAR(insert_buffer_size), + MYSQL_SYSVAR(insert_cntthreshold), + MYSQL_SYSVAR(insert_delayed), + MYSQL_SYSVAR(insert_max_buffered), + MYSQL_SYSVAR(insert_numthreshold), + MYSQL_SYSVAR(insert_wait_ms), + MYSQL_SYSVAR(insert_wait_time), + MYSQL_SYSVAR(join_disable_switch_side), + MYSQL_SYSVAR(enable_histogram_cmap_bloom), + MYSQL_SYSVAR(join_parallel), + MYSQL_SYSVAR(join_splitrows), + MYSQL_SYSVAR(load_threads), + MYSQL_SYSVAR(lookup_max_size), + MYSQL_SYSVAR(max_execution_time), + MYSQL_SYSVAR(minmax_speedup), + MYSQL_SYSVAR(mm_hardlimit), + MYSQL_SYSVAR(mm_largetempratio), + MYSQL_SYSVAR(mm_largetemppool_threshold), + MYSQL_SYSVAR(mm_policy), + MYSQL_SYSVAR(mm_releasepolicy), + MYSQL_SYSVAR(orderby_speedup), + MYSQL_SYSVAR(parallel_filloutput), + MYSQL_SYSVAR(parallel_mapjoin), + MYSQL_SYSVAR(qps_log), + MYSQL_SYSVAR(query_threads), + MYSQL_SYSVAR(refresh_sys_stonedb), + MYSQL_SYSVAR(session_debug_level), + MYSQL_SYSVAR(sync_buffers), + MYSQL_SYSVAR(trigger_error), + MYSQL_SYSVAR(async_join), + MYSQL_SYSVAR(force_hashjoin), + MYSQL_SYSVAR(start_async), + MYSQL_SYSVAR(result_sender_rows), + NULL}; } // namespace dbhandler } // namespace stonedb @@ -745,8 +745,8 @@ mysql_declare_plugin(stonedb){ stonedb::dbhandler::rcbase_init_func, /* Plugin Init */ stonedb::dbhandler::rcbase_done_func, /* Plugin Deinit */ 0x0001 /* 0.1 */, - stonedb::dbhandler::statusvars, /* status variables */ + stonedb::dbhandler::statusvars, /* status variables */ stonedb::dbhandler::sdb_showvars, /* system variables */ - NULL, /* config options */ - 0 /* flags for plugin */ + NULL, /* config options */ + 0 /* flags for plugin */ } mysql_declare_plugin_end; diff --git a/storage/stonedb/index/kv_store.cpp b/storage/stonedb/index/kv_store.cpp index f0254a2d2..4d0417b11 100644 --- a/storage/stonedb/index/kv_store.cpp +++ b/storage/stonedb/index/kv_store.cpp @@ -46,7 +46,7 @@ void KVStore::Init() { // get column family names from manfest file rocksdb::Status status = rocksdb::DB::ListColumnFamilies(db_option, rocksdb_datadir, &cf_names); if (!status.ok() && status.subcode() == rocksdb::Status::kNone) { - STONEDB_LOG(INFO, "First init rocksdb, create default cloum family"); + STONEDB_LOG(LogCtl_Level::INFO, "First init rocksdb, create default cloum family"); cf_names.push_back(DEFAULT_CF_NAME); } @@ -109,7 +109,7 @@ void KVStore::AsyncDropData() { cv_drop.wait_for(lk, std::chrono::seconds(5 * 60)); std::vector del_index_ids; - dict_manager.get_ongoing_index(del_index_ids, DDL_DROP_INDEX_ONGOING); + dict_manager.get_ongoing_index(del_index_ids, MetaType::DDL_DROP_INDEX_ONGOING); for (auto d : del_index_ids) { rocksdb::CompactRangeOptions options; options.bottommost_level_compaction = rocksdb::BottommostLevelCompaction::kForce; @@ -124,22 +124,22 @@ void KVStore::AsyncDropData() { DBUG_ASSERT(cfh); rocksdb::Status status = rocksdb::DeleteFilesInRange(rdb->GetBaseDB(), cfh, &range.start, &range.limit); if (!status.ok()) { - STONEDB_LOG(ERROR, "RocksDB: delete file range fail, status: %s ", status.ToString().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: delete file range fail, status: %s ", status.ToString().c_str()); if (status.IsShutdownInProgress()) { break; } } status = rdb->CompactRange(options, cfh, &range.start, &range.limit); if (!status.ok()) { - STONEDB_LOG(ERROR, "RocksDB: Compact range index fail, status: %s ", status.ToString().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Compact range index fail, status: %s ", status.ToString().c_str()); if (status.IsShutdownInProgress()) { break; } } } - dict_manager.finish_indexes(del_index_ids, DDL_DROP_INDEX_ONGOING); + dict_manager.finish_indexes(del_index_ids, MetaType::DDL_DROP_INDEX_ONGOING); } - STONEDB_LOG(INFO, "KVStore drop Table thread exiting..."); + STONEDB_LOG(LogCtl_Level::INFO, "KVStore drop Table thread exiting..."); } common::ErrorCode KVStore::KVWriteTableMeta(std::shared_ptr tbl) { @@ -149,7 +149,7 @@ common::ErrorCode KVStore::KVWriteTableMeta(std::shared_ptr tbl) { std::shared_ptr defer(nullptr, [this](...) { dict_manager.unlock(); }); ddl_manager.put_and_write(tbl, batch); if (!dict_manager.commit(batch)) { - STONEDB_LOG(ERROR, "Commit table metadata fail!"); + STONEDB_LOG(LogCtl_Level::ERROR, "Commit table metadata fail!"); return common::ErrorCode::FAILED; } return common::ErrorCode::SUCCESS; @@ -181,7 +181,7 @@ common::ErrorCode KVStore::KVRenameTableMeta(const std::string &s_name, const st dict_manager.lock(); std::shared_ptr defer(nullptr, [this](...) { dict_manager.unlock(); }); if (!ddl_manager.rename(s_name, d_name, batch)) { - STONEDB_LOG(ERROR, "rename table %s not exsit", s_name.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "rename table %s not exsit", s_name.c_str()); return common::ErrorCode::FAILED; } @@ -198,7 +198,7 @@ common::ErrorCode KVStore::KVWriteMemTableMeta(std::shared_ptr std::shared_ptr defer(nullptr, [this](...) { dict_manager.unlock(); }); ddl_manager.put_mem(tb_mem, batch); if (!dict_manager.commit(batch)) { - STONEDB_LOG(ERROR, "Commit memory table metadata fail!"); + STONEDB_LOG(LogCtl_Level::ERROR, "Commit memory table metadata fail!"); return common::ErrorCode::FAILED; } return common::ErrorCode::SUCCESS; @@ -231,7 +231,7 @@ common::ErrorCode KVStore::KVRenameMemTableMeta(std::string s_name, std::string dict_manager.lock(); std::shared_ptr defer(nullptr, [this](...) { dict_manager.unlock(); }); if (!ddl_manager.rename_mem(s_name, d_name, batch)) { - STONEDB_LOG(ERROR, "rename table %s failed", s_name.c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "rename table %s failed", s_name.c_str()); return common::ErrorCode::FAILED; } @@ -243,7 +243,7 @@ common::ErrorCode KVStore::KVRenameMemTableMeta(std::string s_name, std::string bool KVStore::KVDeleteKey(rocksdb::WriteOptions &wopts, rocksdb::ColumnFamilyHandle *cf, rocksdb::Slice &key) { rocksdb::Status s = rdb->Delete(wopts, cf, key); if (!s.ok()) { - STONEDB_LOG(ERROR, "Rdb delete key fail: %s", s.ToString().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "Rdb delete key fail: %s", s.ToString().c_str()); return false; } @@ -253,7 +253,7 @@ bool KVStore::KVDeleteKey(rocksdb::WriteOptions &wopts, rocksdb::ColumnFamilyHan bool KVStore::KVWriteBatch(rocksdb::WriteOptions &wopts, rocksdb::WriteBatch *batch) { const rocksdb::Status s = rdb->GetBaseDB()->Write(wopts, batch); if (!s.ok()) { - STONEDB_LOG(ERROR, "Rdb write batch fail: %s", s.ToString().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "Rdb write batch fail: %s", s.ToString().c_str()); return false; } return true; diff --git a/storage/stonedb/index/kv_store.h b/storage/stonedb/index/kv_store.h index ea50cef96..37d98cb87 100644 --- a/storage/stonedb/index/kv_store.h +++ b/storage/stonedb/index/kv_store.h @@ -49,7 +49,9 @@ class KVStore final { uint GetNextIndexId() { return ddl_manager.get_and_update_next_number(&dict_manager); } rocksdb::ColumnFamilyHandle *GetCfHandle(std::string &cf_name) { return cf_manager.get_or_create_cf(rdb, cf_name); } rocksdb::ColumnFamilyHandle *GetCfHandleByID(const uint32_t id) { return cf_manager.get_cf_by_id(id); } - bool indexdroping(GlobalId &index) { return dict_manager.is_drop_index_ongoing(index, DDL_DROP_INDEX_ONGOING); } + bool indexdroping(GlobalId &index) { + return dict_manager.is_drop_index_ongoing(index, MetaType::DDL_DROP_INDEX_ONGOING); + } // kv table meta operation std::shared_ptr FindTable(std::string &name) { return ddl_manager.find(name); } common::ErrorCode KVWriteTableMeta(std::shared_ptr tbl); diff --git a/storage/stonedb/index/rc_table_index.cpp b/storage/stonedb/index/rc_table_index.cpp index fa27186d2..69edc61f6 100644 --- a/storage/stonedb/index/rc_table_index.cpp +++ b/storage/stonedb/index/rc_table_index.cpp @@ -58,8 +58,11 @@ void create_rdbkey(TABLE *table, uint i, std::shared_ptr &new_key_def, r } const char *const key_name = table->key_info[i].name; - uchar index_type = (i == table->s->primary_key) ? INDEX_TYPE_PRIMARY : INDEX_TYPE_SECONDARY; - uint16_t index_ver = (key_info->actual_key_parts > 1) ? INDEX_INFO_VERSION_COLS : INDEX_INFO_VERSION_INITIAL; + uchar index_type = (i == table->s->primary_key) ? static_cast(enumIndexType::INDEX_TYPE_PRIMARY) + : static_cast(enumIndexType::INDEX_TYPE_SECONDARY); + uint16_t index_ver = (key_info->actual_key_parts > 1) + ? static_cast(enumIndexInfo::INDEX_INFO_VERSION_COLS) + : static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL); new_key_def = std::make_shared(index_id, i, cf_handle, index_ver, index_type, false, key_name, vcols); } @@ -91,12 +94,12 @@ RCTableIndex::RCTableIndex(const std::string &name, TABLE *table) { std::string fullname; if (!NormalizeName(name, fullname)) { - STONEDB_LOG(WARN, "normalize tablename %s fail!", name.c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "normalize tablename %s fail!", name.c_str()); return; } m_tbl = kvstore->FindTable(fullname); if (m_tbl == nullptr) { - STONEDB_LOG(WARN, "find table %s fail!", fullname.c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "find table %s fail!", fullname.c_str()); return; } m_keyid = table->s->primary_key; @@ -128,7 +131,7 @@ common::ErrorCode RCTableIndex::CreateIndexTable(const std::string &name, TABLE } if (table->s->keys > 1) { - STONEDB_LOG(WARN, "Table :%s have other keys except primary key, only use primary key!", name.data()); + STONEDB_LOG(LogCtl_Level::WARN, "Table :%s have other keys except primary key, only use primary key!", name.data()); } // Create table/key descriptions and put them into the data dictionary @@ -160,7 +163,7 @@ common::ErrorCode RCTableIndex::RefreshIndexTable(const std::string &name) { } m_tbl = kvstore->FindTable(fullname); if (m_tbl == nullptr) { - STONEDB_LOG(WARN, "table %s init ddl error", fullname.c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "table %s init ddl error", fullname.c_str()); return common::ErrorCode::FAILED; } m_rdbkey = m_tbl->m_rdbkeys[m_keyid]; @@ -216,7 +219,7 @@ common::ErrorCode RCTableIndex::CheckUniqueness(core::Transaction *tx, const roc } if (!s.ok() && !s.IsNotFound()) { - STONEDB_LOG(ERROR, "RockDb read fail:%s", s.ToString().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RockDb read fail:%s", s.ToString().c_str()); return common::ErrorCode::FAILED; } @@ -241,7 +244,7 @@ common::ErrorCode RCTableIndex::InsertIndex(core::Transaction *tx, std::vectorKVTrans().Put(cf, {(const char *)key.ptr(), key.length()}, {(const char *)value.ptr(), value.length()}); if (!s.ok()) { - STONEDB_LOG(ERROR, "RockDb: insert key fail!"); + STONEDB_LOG(LogCtl_Level::ERROR, "RockDb: insert key fail!"); rc = common::ErrorCode::FAILED; } return rc; @@ -261,7 +264,7 @@ common::ErrorCode RCTableIndex::UpdateIndex(core::Transaction *tx, std::string_v const auto cf = m_rdbkey->get_cf(); tx->KVTrans().Delete(cf, {(const char *)packkey.ptr(), packkey.length()}); } else { - STONEDB_LOG(WARN, "RockDb: don't have the key for update!"); + STONEDB_LOG(LogCtl_Level::WARN, "RockDb: don't have the key for update!"); } rc = InsertIndex(tx, nfields, row); return rc; @@ -282,7 +285,7 @@ common::ErrorCode RCTableIndex::GetRowByKey(core::Transaction *tx, std::vectorm_index_ver > INDEX_INFO_VERSION_INITIAL) { + if (m_rdbkey->m_index_ver > static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) { uint16_t packlen; reader.read_uint16(&packlen); reader.read(packlen); @@ -304,15 +307,15 @@ void KeyIterator::ScanToKey(std::shared_ptr tab, std::vector(trans->GetIterator(rdbkey->get_cf(), true)); switch (op) { - case common::O_EQ: //== + case common::Operator::O_EQ: //== iter->Seek(key_slice); if (!iter->Valid() || !rdbkey->value_matches_prefix(iter->key(), key_slice)) valid = false; break; - case common::O_MORE_EQ: //'>=' + case common::Operator::O_MORE_EQ: //'>=' iter->Seek(key_slice); if (!iter->Valid() || !rdbkey->covers_key(iter->key())) valid = false; break; - case common::O_MORE: //'>' + case common::Operator::O_MORE: //'>' iter->Seek(key_slice); if (!iter->Valid() || rdbkey->value_matches_prefix(iter->key(), key_slice)) { if (rdbkey->m_is_reverse) { @@ -324,7 +327,7 @@ void KeyIterator::ScanToKey(std::shared_ptr tab, std::vectorValid() || !rdbkey->covers_key(iter->key())) valid = false; break; default: - STONEDB_LOG(ERROR, "key not support this op:%d", op); + STONEDB_LOG(LogCtl_Level::ERROR, "key not support this op:%d", op); valid = false; break; } diff --git a/storage/stonedb/index/rdb_meta_manager.cpp b/storage/stonedb/index/rdb_meta_manager.cpp index 2007d391b..f314603b6 100644 --- a/storage/stonedb/index/rdb_meta_manager.cpp +++ b/storage/stonedb/index/rdb_meta_manager.cpp @@ -126,7 +126,7 @@ int RdbKey::unpack_field_number(StringReader &key, std::string &field, uchar fla void RdbKey::pack_field_string(StringWriter &info, StringWriter &key, std::string_view &field) { // version compatible - if (m_index_ver == INDEX_INFO_VERSION_INITIAL) { + if (m_index_ver == static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) { key.write((const uchar *)field.data(), field.length()); return; } @@ -136,26 +136,26 @@ void RdbKey::pack_field_string(StringWriter &info, StringWriter &key, std::strin size_t copy_len = std::min(CHUNKSIZE - 1, data.remain_len()); pad_bytes = CHUNKSIZE - 1 - copy_len; key.write((const uchar *)data.read(copy_len), copy_len); - uint separator = 0; + Separator separator; if (pad_bytes) { key.write((const uchar *)SPACE.data(), pad_bytes); - separator = EQ_SPACES; + separator = Separator::EQ_SPACES; } else { int cmp = 0; size_t bytes = std::min(CHUNKSIZE - 1, data.remain_len()); if (bytes > 0) cmp = memcmp(data.current_ptr(), SPACE.data(), bytes); if (cmp < 0) { - separator = LE_SPACES; + separator = Separator::LE_SPACES; } else if (cmp > 0) { - separator = GE_SPACES; + separator = Separator::GE_SPACES; } else { // It turns out all the rest are spaces. - separator = EQ_SPACES; + separator = Separator::EQ_SPACES; } } - key.write_uint8(separator); // last segment + key.write_uint8(static_cast(separator)); // last segment - if (separator == EQ_SPACES) break; + if (separator == Separator::EQ_SPACES) break; } // pack info only save pad bytes len of last chunk info.write_uint16(pad_bytes); @@ -166,7 +166,7 @@ int RdbKey::unpack_field_string(StringReader &key, StringReader &info, std::stri const char *ptr; uint16_t pad_bytes = 0; // version compatible - if (m_index_ver == INDEX_INFO_VERSION_INITIAL) { + if (m_index_ver == static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) { field.append(key.current_ptr(), key.remain_len()); return 0; } @@ -177,13 +177,14 @@ int RdbKey::unpack_field_string(StringReader &key, StringReader &info, std::stri size_t used_bytes; const char last_byte = ptr[CHUNKSIZE - 1]; - if (last_byte == EQ_SPACES) { + if (last_byte == static_cast(Separator::EQ_SPACES)) { // this is the last segment if (pad_bytes > (CHUNKSIZE - 1)) return -1; used_bytes = (CHUNKSIZE - 1) - pad_bytes; finished = true; } else { - if (last_byte != LE_SPACES && last_byte != GE_SPACES) return -1; + if (last_byte != static_cast(Separator::LE_SPACES) && last_byte != static_cast(Separator::GE_SPACES)) + return -1; used_bytes = CHUNKSIZE - 1; } @@ -205,7 +206,7 @@ void RdbKey::pack_key(StringWriter &key, std::vector &fields, info.clear(); key.write_uint32(m_indexnr); // version compatible - if (m_index_ver > INDEX_INFO_VERSION_INITIAL) info.write_uint16(0); + if (m_index_ver > static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) info.write_uint16(0); size_t pos = info.length(); for (uint i = 0; i < fields.size(); i++) { @@ -247,7 +248,7 @@ void RdbKey::pack_key(StringWriter &key, std::vector &fields, } // version compatible - if (m_index_ver > INDEX_INFO_VERSION_INITIAL) { + if (m_index_ver > static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) { // process packinfo len size_t len = info.length() - pos; info.write_uint16_at(0, len); @@ -260,7 +261,7 @@ common::ErrorCode RdbKey::unpack_key(StringReader &key, StringReader &value, std key.read_uint32(&index_number); // version compatible - if (m_index_ver > INDEX_INFO_VERSION_INITIAL) value.read_uint16(&info_len); + if (m_index_ver > static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) value.read_uint16(&info_len); for (auto &col : m_cols) { std::string field; @@ -284,7 +285,7 @@ common::ErrorCode RdbKey::unpack_key(StringReader &key, StringReader &value, std case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_NEWDECIMAL: { if (unpack_field_number(key, field, col.col_flag) < 0) { - STONEDB_LOG(ERROR, "unpack numeric field failed!"); + STONEDB_LOG(LogCtl_Level::ERROR, "unpack numeric field failed!"); return common::ErrorCode::FAILED; } } break; @@ -298,7 +299,7 @@ common::ErrorCode RdbKey::unpack_key(StringReader &key, StringReader &value, std case MYSQL_TYPE_STRING: { // case sensitive for character if (unpack_field_string(key, value, field) < 0) { - STONEDB_LOG(ERROR, "unpack string field failed!"); + STONEDB_LOG(LogCtl_Level::ERROR, "unpack string field failed!"); return common::ErrorCode::FAILED; } } break; @@ -321,7 +322,7 @@ RdbTable::~RdbTable() { m_rdbkeys.clear(); } // Put table definition DDL entry. Actual write is done at DICTManager::commit void RdbTable::put_dict(DICTManager *dict, rocksdb::WriteBatch *const batch, uchar *const key, size_t keylen) { StringWriter value; - value.write_uint16(DDL_VERSION); + value.write_uint16(static_cast(enumVersion::DDL_VERSION)); for (auto &kd : m_rdbkeys) { uchar flags = (kd->m_is_reverse ? REVERSE_CF_FLAG : 0); @@ -352,7 +353,7 @@ void RdbTable::set_name(const std::string &name) { m_fullname = name; size_t dotpos = name.find('.'); if (dotpos == std::string::npos) { - STONEDB_LOG(ERROR, "table name :%s format wrong", name.data()); + STONEDB_LOG(LogCtl_Level::ERROR, "table name :%s format wrong", name.data()); return; } m_dbname = name.substr(0, dotpos); @@ -363,7 +364,7 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { m_dict = dict; m_cf = cf_manager; uchar ddl_entry[INDEX_NUMBER_SIZE]; - be_store_index(ddl_entry, DDL_INDEX); + be_store_index(ddl_entry, static_cast(MetaType::DDL_INDEX)); std::shared_ptr it = m_dict->new_iterator(); uint max_index_id = 0; @@ -377,7 +378,7 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { if (key.size() >= INDEX_NUMBER_SIZE && memcmp(key.data(), ddl_entry, INDEX_NUMBER_SIZE)) break; if (key.size() <= INDEX_NUMBER_SIZE) { - STONEDB_LOG(ERROR, "RocksDB: Table_store: key has length %d (corruption)", (int)key.size()); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Table_store: key has length %d (corruption)", (int)key.size()); return false; } std::shared_ptr tdef = std::make_shared(key, INDEX_NUMBER_SIZE); @@ -385,7 +386,7 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { // read the DDLs. const int real_val_size = val.size() - VERSION_SIZE; if (real_val_size % sizeof(GlobalId) > 0) { - STONEDB_LOG(ERROR, "RocksDB: Table_store: invalid keylist for table %s", tdef->fullname().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Table_store: invalid keylist for table %s", tdef->fullname().c_str()); return false; } @@ -393,11 +394,11 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { ptr = reinterpret_cast(val.data()); const int version = be_read_uint16(&ptr); - if (version != DDL_VERSION) { - STONEDB_LOG(ERROR, + if (version != static_cast(enumVersion::DDL_VERSION)) { + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: DDL ENTRY Version was not expected.Expected: %d, " "Actual: %d", - DDL_VERSION, version); + static_cast(enumVersion::DDL_VERSION), version); return false; } ptr_end = ptr + real_val_size; @@ -409,15 +410,15 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { uchar index_type = 0; std::vector vcols; if (!m_dict->get_index_info(gl_index_id, index_ver, index_type, vcols)) { - STONEDB_LOG(ERROR, + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Could not get INDEXINFO for Index Number " "(%u,%u), table %s", gl_index_id.cf_id, gl_index_id.index_id, tdef->fullname().c_str()); return false; } if (max_index_id < gl_index_id.index_id) { - STONEDB_LOG(ERROR, - "RocksDB: Found MAX_INDEX_ID %u, but also found larger " + STONEDB_LOG(LogCtl_Level::ERROR, + "RocksDB: Found MetaType::MAX_INDEX_ID %u, but also found larger " "index %u from INDEXINFO.", max_index_id, gl_index_id.index_id); return false; @@ -425,14 +426,14 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { // In some abnormal condition, gl_index_id.cf_id(CF Number) is greater // than 0 like 3 or 4 just log it and set the CF to 0. if (gl_index_id.cf_id != 0) { - STONEDB_LOG(ERROR, + STONEDB_LOG(LogCtl_Level::ERROR, "StoneDB-RocksDB: Could not get Column Family Flags for CF " "Number %d, table %s", gl_index_id.cf_id, tdef->fullname().c_str()); gl_index_id.cf_id = 0; } if (!m_dict->get_cf_flags(gl_index_id.cf_id, flags)) { - STONEDB_LOG(ERROR, + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Could not get Column Family Flags for CF Number " "%d, table %s", gl_index_id.cf_id, tdef->fullname().c_str()); @@ -449,7 +450,7 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { // create memory table std::scoped_lock guard(m_mem_lock); uchar mem_table_entry[INDEX_NUMBER_SIZE]; - be_store_index(mem_table_entry, DDL_MEMTABLE); + be_store_index(mem_table_entry, static_cast(MetaType::DDL_MEMTABLE)); const rocksdb::Slice mem_table_entry_slice((char *)mem_table_entry, INDEX_NUMBER_SIZE); for (it->Seek(mem_table_entry_slice); it->Valid(); it->Next()) { const rocksdb::Slice key = it->key(); @@ -463,11 +464,11 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { const uchar *ptr = reinterpret_cast(val.data()); const int version = be_read_uint16(&ptr); - if (version != DDL_VERSION) { - STONEDB_LOG(ERROR, + if (version != static_cast(enumVersion::DDL_VERSION)) { + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: DDL MEMTABLE ENTRY Version was not expected or " "currupt.Expected: %d, Actual: %d", - DDL_VERSION, version); + static_cast(enumVersion::DDL_VERSION), version); return false; } @@ -475,16 +476,16 @@ bool DDLManager::init(DICTManager *const dict, CFManager *const cf_manager) { const uint32_t memtable_id = be_read_uint32(&ptr); std::string table_name = std::string(key.data() + INDEX_NUMBER_SIZE, key.size() - INDEX_NUMBER_SIZE); if (max_index_id < memtable_id) { - STONEDB_LOG(ERROR, "RocksDB: Found MAX_MEM_ID %u, but also found larger memtable id %u.", max_index_id, - memtable_id); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Found MAX_MEM_ID %u, but also found larger memtable id %u.", + max_index_id, memtable_id); return false; } std::shared_ptr tb_mem = std::make_shared(table_name, memtable_id, cf_id); m_mem_hash[table_name] = tb_mem; } - if (max_index_id < END_DICT_INDEX_ID) { - max_index_id = END_DICT_INDEX_ID; + if (max_index_id < static_cast(MetaType::END_DICT_INDEX_ID)) { + max_index_id = static_cast(MetaType::END_DICT_INDEX_ID); } m_sequence.init(max_index_id + 1); @@ -505,7 +506,7 @@ std::shared_ptr DDLManager::find(const std::string &table_name) { // on-disk data dictionary. void DDLManager::put_and_write(std::shared_ptr tbl, rocksdb::WriteBatch *const batch) { StringWriter key; - key.write_uint32(DDL_INDEX); + key.write_uint32(static_cast(MetaType::DDL_INDEX)); const std::string &dbname_tablename = tbl->fullname(); key.write((uchar *)dbname_tablename.data(), dbname_tablename.length()); @@ -527,7 +528,7 @@ void DDLManager::remove(std::shared_ptr tbl, rocksdb::WriteBatch *cons uchar buf[FN_LEN * 2 + INDEX_NUMBER_SIZE]; uint pos = 0; - be_store_index(buf, DDL_INDEX); + be_store_index(buf, static_cast(MetaType::DDL_INDEX)); pos += INDEX_NUMBER_SIZE; const std::string &dbname_tablename = tbl->fullname(); @@ -553,7 +554,7 @@ bool DDLManager::rename(const std::string &from, const std::string &to, rocksdb: // Create a new key StringWriter key; - key.write_uint32(DDL_INDEX); + key.write_uint32(static_cast(MetaType::DDL_INDEX)); const std::string &dbname_tablename = new_rec->fullname(); key.write((uchar *)dbname_tablename.data(), dbname_tablename.length()); @@ -562,7 +563,7 @@ bool DDLManager::rename(const std::string &from, const std::string &to, rocksdb: new_rec->put_dict(m_dict, batch, key.ptr(), key.length()); put(new_rec); } else { - STONEDB_LOG(WARN, "Rename table:%s have no cf_definition", from.data()); + STONEDB_LOG(LogCtl_Level::WARN, "Rename table:%s have no cf_definition", from.data()); } return true; } @@ -592,11 +593,11 @@ void DDLManager::put_mem(std::shared_ptr tb_mem, rocksdb::Writ StringWriter key; std::string table_name = tb_mem->FullName(); - key.write_uint32(DDL_MEMTABLE); + key.write_uint32(static_cast(MetaType::DDL_MEMTABLE)); key.write((const uchar *)table_name.c_str(), table_name.size()); StringWriter value; - value.write_uint16(DDL_VERSION); + value.write_uint16(static_cast(enumVersion::DDL_VERSION)); value.write_uint32(tb_mem->GetCFHandle()->GetID()); value.write_uint32(tb_mem->GetMemID()); @@ -609,7 +610,7 @@ void DDLManager::remove_mem(std::shared_ptr tb_mem, rocksdb::W StringWriter key; const std::string &table_name = tb_mem->FullName(); - key.write_uint32(DDL_MEMTABLE); + key.write_uint32(static_cast(MetaType::DDL_MEMTABLE)); key.write((const uchar *)table_name.c_str(), table_name.size()); m_dict->delete_key(batch, {(const char *)key.ptr(), key.length()}); @@ -623,7 +624,7 @@ bool DDLManager::rename_mem(std::string &from, std::string &to, rocksdb::WriteBa std::scoped_lock guard(m_mem_lock); StringWriter skey; - skey.write_uint32(DDL_MEMTABLE); + skey.write_uint32(static_cast(MetaType::DDL_MEMTABLE)); skey.write((const uchar *)from.c_str(), from.size()); std::string origin_value; @@ -631,7 +632,7 @@ bool DDLManager::rename_mem(std::string &from, std::string &to, rocksdb::WriteBa m_dict->delete_key(batch, {(const char *)skey.ptr(), skey.length()}); StringWriter dkey; - dkey.write_uint32(DDL_MEMTABLE); + dkey.write_uint32(static_cast(MetaType::DDL_MEMTABLE)); dkey.write((const uchar *)to.c_str(), to.size()); m_dict->put_key(batch, {(const char *)dkey.ptr(), dkey.length()}, origin_value); @@ -650,7 +651,7 @@ bool DICTManager::init(rocksdb::DB *const rdb_dict, CFManager *const cf_manager) if (m_system_cfh == nullptr) return false; - be_store_index(m_max_index, MAX_INDEX_ID); + be_store_index(m_max_index, static_cast(MetaType::MAX_INDEX_ID)); return true; } @@ -688,14 +689,14 @@ bool DICTManager::commit(rocksdb::WriteBatch *const batch, const bool &sync) con rocksdb::Status s = m_db->Write(options, batch); bool res = s.ok(); if (!res) { - STONEDB_LOG(ERROR, "DICTManager::commit error"); + STONEDB_LOG(LogCtl_Level::ERROR, "DICTManager::commit error"); } batch->Clear(); return res; } void DICTManager::dump_index_id(StringWriter &id, MetaType dict_type, const GlobalId &gl_index_id) const { - id.write_uint32(dict_type); + id.write_uint32(static_cast(dict_type)); id.write_uint32(gl_index_id.cf_id); id.write_uint32(gl_index_id.index_id); } @@ -712,13 +713,13 @@ void DICTManager::save_index_info(rocksdb::WriteBatch *batch, uint16_t index_ver uint32_t cf_id, std::vector &cols) const { StringWriter dumpid; GlobalId gl_index_id = {cf_id, index_id}; - dump_index_id(dumpid, INDEX_INFO, gl_index_id); + dump_index_id(dumpid, MetaType::INDEX_INFO, gl_index_id); StringWriter value; value.write_uint16(index_ver); value.write_uint8(index_type); - if (index_ver > INDEX_INFO_VERSION_INITIAL) { + if (index_ver > static_cast(enumIndexInfo::INDEX_INFO_VERSION_INITIAL)) { value.write_uint32(cols.size()); for (auto &col : cols) { value.write_uint16(col.col_no); @@ -737,36 +738,36 @@ void DICTManager::add_cf_flags(rocksdb::WriteBatch *const batch, const uint32_t const uint32_t &cf_flags) const { ASSERT(batch != nullptr, "batch is NULL"); StringWriter key; - key.write_uint32(CF_INFO); + key.write_uint32(static_cast(MetaType::CF_INFO)); key.write_uint32(cf_id); StringWriter value; - value.write_uint16(CF_VERSION); + value.write_uint16(static_cast(enumVersion::CF_VERSION)); value.write_uint32(cf_flags); batch->Put(m_system_cfh, {(char *)key.ptr(), key.length()}, {(char *)value.ptr(), value.length()}); } void DICTManager::delete_index_info(rocksdb::WriteBatch *batch, const GlobalId &gl_index_id) const { - delete_with_prefix(batch, INDEX_INFO, gl_index_id); + delete_with_prefix(batch, MetaType::INDEX_INFO, gl_index_id); } -// Get INDEX_INFO from cf __system__ +// Get MetaType::INDEX_INFO from cf __system__ bool DICTManager::get_index_info(const GlobalId &gl_index_id, uint16_t &index_ver, uchar &index_type, std::vector &cols) const { bool found = false; bool error = false; std::string value; StringWriter dumpid; - dump_index_id(dumpid, INDEX_INFO, gl_index_id); + dump_index_id(dumpid, MetaType::INDEX_INFO, gl_index_id); const rocksdb::Status &status = get_value({(char *)dumpid.ptr(), dumpid.length()}, &value); if (status.ok()) { StringReader reader(value); reader.read_uint16(&index_ver); - switch (index_ver) { - case INDEX_INFO_VERSION_INITIAL: { + switch (static_cast(index_ver)) { + case enumIndexInfo::INDEX_INFO_VERSION_INITIAL: { uchar type; uchar flag; reader.read_uint8(&index_type); @@ -777,7 +778,7 @@ bool DICTManager::get_index_info(const GlobalId &gl_index_id, uint16_t &index_ve found = true; break; } - case INDEX_INFO_VERSION_COLS: { + case enumIndexInfo::INDEX_INFO_VERSION_COLS: { uint32_t cols_sz = 0; reader.read_uint8(&index_type); reader.read_uint32(&cols_sz); @@ -796,7 +797,7 @@ bool DICTManager::get_index_info(const GlobalId &gl_index_id, uint16_t &index_ve } } if (error) { - STONEDB_LOG(ERROR, "RocksDB: Found invalid key version number (%u, %u) ", index_ver, index_type); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Found invalid key version number (%u, %u) ", index_ver, index_type); } return found; } @@ -804,7 +805,7 @@ bool DICTManager::get_cf_flags(const uint32_t &cf_id, uint32_t &cf_flags) const bool found = false; std::string value; StringWriter key; - key.write_uint32(CF_INFO); + key.write_uint32(static_cast(MetaType::CF_INFO)); key.write_uint32(cf_id); const rocksdb::Status status = get_value({reinterpret_cast(key.ptr()), key.length()}, &value); @@ -813,7 +814,7 @@ bool DICTManager::get_cf_flags(const uint32_t &cf_id, uint32_t &cf_flags) const uint16_t version = 0; StringReader reader(value); reader.read_uint16(&version); - if (version == CF_VERSION) { + if (version == static_cast(enumVersion::CF_VERSION)) { reader.read_uint32(&cf_flags); found = true; } @@ -835,7 +836,7 @@ void DICTManager::add_drop_table(std::vector> &keys, roc void DICTManager::add_drop_index(const std::vector &gl_index_ids, rocksdb::WriteBatch *const batch) const { for (const auto &gl_index_id : gl_index_ids) { delete_index_info(batch, gl_index_id); - start_ongoing_index(batch, gl_index_id, DDL_DROP_INDEX_ONGOING); + start_ongoing_index(batch, gl_index_id, MetaType::DDL_DROP_INDEX_ONGOING); } } @@ -848,7 +849,7 @@ bool DICTManager::get_max_index_id(uint32_t *const index_id) const { uint16_t version = 0; StringReader reader({value.data(), value.length()}); reader.read_uint16(&version); - if (version == MAX_INDEX_ID_VERSION) { + if (version == static_cast(enumVersion::MAX_INDEX_ID_VERSION)) { reader.read_uint32(index_id); found = true; } @@ -860,12 +861,13 @@ bool DICTManager::update_max_index_id(rocksdb::WriteBatch *const batch, const ui uint32_t old_index_id = -1; if (get_max_index_id(&old_index_id)) { if (old_index_id > index_id) { - STONEDB_LOG(ERROR, "RocksDB: Found max index id %u but trying to update to %u.", old_index_id, index_id); + STONEDB_LOG(LogCtl_Level::ERROR, "RocksDB: Found max index id %u but trying to update to %u.", old_index_id, + index_id); return true; } } StringWriter value; - value.write_uint16(MAX_INDEX_ID_VERSION); + value.write_uint16(static_cast(enumVersion::MAX_INDEX_ID_VERSION)); value.write_uint32(index_id); batch->Put(m_system_cfh, {(char *)m_max_index, INDEX_NUMBER_SIZE}, {(char *)value.ptr(), value.length()}); @@ -874,8 +876,8 @@ bool DICTManager::update_max_index_id(rocksdb::WriteBatch *const batch, const ui void DICTManager::get_ongoing_index(std::vector &ids, MetaType dd_type) const { uchar index_buf[INDEX_NUMBER_SIZE]; - be_store_uint32(index_buf, dd_type); - uint32_t upper_type = dd_type + 1; + be_store_uint32(index_buf, static_cast(dd_type)); + uint32_t upper_type = static_cast(dd_type) + 1; uchar upper_buf[INDEX_NUMBER_SIZE]; be_store_uint32(upper_buf, upper_type); rocksdb::Slice upper_slice((char *)upper_buf, INDEX_NUMBER_SIZE); @@ -887,7 +889,7 @@ void DICTManager::get_ongoing_index(std::vector &ids, MetaType dd_type rocksdb::Slice key = it->key(); const uchar *const ptr = (const uchar *)key.data(); - if (key.size() != INDEX_NUMBER_SIZE * 3 || be_to_uint32(ptr) != dd_type) { + if (key.size() != INDEX_NUMBER_SIZE * 3 || be_to_uint32(ptr) != static_cast(dd_type)) { break; } GlobalId index_id; @@ -902,10 +904,10 @@ void DICTManager::start_ongoing_index(rocksdb::WriteBatch *const batch, const Gl dump_index_id(dumpid, dd_type, id); StringWriter value; // version as needed - if (dd_type == DDL_DROP_INDEX_ONGOING) { - value.write_uint16(DROP_INDEX_ONGOING_VERSION); + if (dd_type == MetaType::DDL_DROP_INDEX_ONGOING) { + value.write_uint16(static_cast(enumVersion::DROP_INDEX_ONGOING_VERSION)); } else { - value.write_uint16(CREATE_INDEX_ONGOING_VERSION); + value.write_uint16(static_cast(enumVersion::CREATE_INDEX_ONGOING_VERSION)); } batch->Put(m_system_cfh, {(char *)dumpid.ptr(), dumpid.length()}, {(char *)value.ptr(), value.length()}); diff --git a/storage/stonedb/index/rdb_meta_manager.h b/storage/stonedb/index/rdb_meta_manager.h index 3e0ce312f..96d673fa1 100644 --- a/storage/stonedb/index/rdb_meta_manager.h +++ b/storage/stonedb/index/rdb_meta_manager.h @@ -54,7 +54,7 @@ constexpr int REVERSE_CF_FLAG = 0x1; constexpr int INDEX_NUMBER_SIZE = 0x4; constexpr int VERSION_SIZE = 0x2; -enum MetaType { +enum class MetaType { DDL_INDEX = 1, INDEX_INFO, CF_INFO, @@ -64,7 +64,7 @@ enum MetaType { END_DICT_INDEX_ID = 255 }; -enum { +enum class enumVersion { DDL_VERSION = 1, CF_VERSION = 1, MAX_INDEX_ID_VERSION = 1, @@ -72,12 +72,12 @@ enum { CREATE_INDEX_ONGOING_VERSION = 1, }; -enum { +enum class enumIndexInfo { INDEX_INFO_VERSION_INITIAL = 1, INDEX_INFO_VERSION_COLS = 2, }; -enum { INDEX_TYPE_PRIMARY = 1, INDEX_TYPE_SECONDARY, INDEX_TYPE_HIDDEN_PRIMARY }; +enum class enumIndexType { INDEX_TYPE_PRIMARY = 1, INDEX_TYPE_SECONDARY, INDEX_TYPE_HIDDEN_PRIMARY }; class RdbKey { public: @@ -214,19 +214,19 @@ class DDLManager { /* Meta description -------------------------------------------------------------- - Type: DDL_INDEX + Type: MetaType::DDL_INDEX key: 0x01(4B)+dbname.tablename value : version, {cf_id, index_id}*n_indexes_of_the_table -------------------------------------------------------------- - Type: INDEX_INFO + Type: MetaType::INDEX_INFO key: 0x2(4B) + cf_id(4B)+ index_id(4B) value: version(2B), index_type(1B), coltype(1B), unsignedflag(1B) -------------------------------------------------------------- - Type: MAX_INDEX_ID + Type: MetaType::MAX_INDEX_ID key: 0x7(4B) value : index_id(4B) --------------------------------------------------------------- - Type: CF_INFO + Type: MetaType::CF_INFO key: 0x3(4B)+ cf_id value : version, {is_reverse_cf, is_auto_cf (deprecated), is_per_partition_cf} --------------------------------------------------------------- diff --git a/storage/stonedb/index/rdb_utils.h b/storage/stonedb/index/rdb_utils.h index 6f80fc523..38ecb1a52 100644 --- a/storage/stonedb/index/rdb_utils.h +++ b/storage/stonedb/index/rdb_utils.h @@ -30,7 +30,7 @@ namespace stonedb { namespace index { -enum Separator { LE_SPACES = 1, EQ_SPACES, GE_SPACES }; +enum class Separator { LE_SPACES = 1, EQ_SPACES, GE_SPACES }; constexpr uint INTSIZE = 8; constexpr uint CHUNKSIZE = 9; diff --git a/storage/stonedb/loader/load_parser.cpp b/storage/stonedb/loader/load_parser.cpp index f17fa199f..d6b811cc5 100644 --- a/storage/stonedb/loader/load_parser.cpp +++ b/storage/stonedb/loader/load_parser.cpp @@ -25,8 +25,8 @@ namespace stonedb { namespace loader { -LoadParser::LoadParser(RCAttrPtrVect_t &attrs, const system::IOParameters &iop, - uint packsize, std::unique_ptr &f) +LoadParser::LoadParser(RCAttrPtrVect_t &attrs, const system::IOParameters &iop, uint packsize, + std::unique_ptr &f) : attrs(attrs), start_time(types::RCDateTime::GetCurrent().GetInt64()), ioparam(iop), @@ -173,7 +173,7 @@ int LoadParser::ProcessInsertIndex(std::shared_ptr tab, std } if (tab->InsertIndex(current_tx, fields, no_obj + no_rows) == common::ErrorCode::DUPP_KEY) { - STONEDB_LOG(INFO, "Load discard this row for duplicate key"); + STONEDB_LOG(LogCtl_Level::INFO, "Load discard this row for duplicate key"); return HA_ERR_FOUND_DUPP_KEY; } @@ -182,10 +182,10 @@ int LoadParser::ProcessInsertIndex(std::shared_ptr tab, std int LoadParser::binlog_loaded_block(const char *buf_start, const char *buf_end) { LOAD_FILE_INFO *lf_info = nullptr; - uint block_len =0; + uint block_len = 0; - lf_info = static_cast (ioparam.GetLogInfo()); - uchar* buffer = reinterpret_cast (const_cast(buf_start)); + lf_info = static_cast(ioparam.GetLogInfo()); + uchar *buffer = reinterpret_cast(const_cast(buf_start)); uint max_event_size = lf_info->thd->variables.max_allowed_packet; if (lf_info == nullptr) return -1; @@ -193,7 +193,6 @@ int LoadParser::binlog_loaded_block(const char *buf_start, const char *buf_end) for (block_len = (uint)(buf_end - buf_start); block_len > 0; buffer += std::min(block_len, max_event_size), block_len -= std::min(block_len, max_event_size)) { - if (lf_info->wrote_create_file) { Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer, std::min(block_len, max_event_size), lf_info->log_delayed); @@ -201,8 +200,7 @@ int LoadParser::binlog_loaded_block(const char *buf_start, const char *buf_end) } else { Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db, buffer, std::min(block_len, max_event_size), lf_info->log_delayed); - if (mysql_bin_log.write_event(&b)) - return -1; + if (mysql_bin_log.write_event(&b)) return -1; lf_info->wrote_create_file = 1; } diff --git a/storage/stonedb/loader/parsing_strategy.cpp b/storage/stonedb/loader/parsing_strategy.cpp index 101079317..4ee9fb491 100644 --- a/storage/stonedb/loader/parsing_strategy.cpp +++ b/storage/stonedb/loader/parsing_strategy.cpp @@ -54,11 +54,13 @@ ParsingStrategy::ParsingStrategy(const system::IOParameters &iop, std::vectorThd(), Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, err_msg.str().c_str()); } + uint reserved = (uint)value_size * ati.CharsetInfo()->mbmaxlen; char *buf = reinterpret_cast(buffer.Prepare(reserved)); size_t new_size = 0; @@ -414,6 +426,7 @@ void ParsingStrategy::GetValue(const char *value_ptr, size_t value_size, ushort buf[new_size] = value_ptr[j]; new_size++; } + if (ati.CharsetInfo() != cs_info) { // convert between charsets uint errors = 0; @@ -426,6 +439,7 @@ void ParsingStrategy::GetValue(const char *value_ptr, size_t value_size, ushort new_size = copy_and_convert(buf, reserved, ati.CharsetInfo(), tmpbuf, new_size, cs_info, &errors); } } + // check the value length size_t char_len = ati.CharsetInfo()->cset->numchars(ati.CharsetInfo(), buf, buf + new_size); if (char_len > ati.CharLen()) throw common::FormatException(0, col); diff --git a/storage/stonedb/loader/parsing_strategy.h b/storage/stonedb/loader/parsing_strategy.h index b6d77637f..2f17b1787 100644 --- a/storage/stonedb/loader/parsing_strategy.h +++ b/storage/stonedb/loader/parsing_strategy.h @@ -51,6 +51,7 @@ class ParsingStrategy final { std::string enclose_eol; std::string tablename; std::string dbname; + kmp_next_t kmp_next_delimiter; kmp_next_t kmp_next_enclose_delimiter; kmp_next_t kmp_next_eol; @@ -61,11 +62,13 @@ class ParsingStrategy final { void GuessUnescapedEOL(const char *ptr, const char *buf_end); void GuessUnescapedEOLWithEnclose(const char *ptr, const char *const buf_end); + bool SearchUnescapedPattern(const char *&ptr, const char *const buf_end, const std::string &pattern, const std::vector &kmp_next); - enum SearchResult { PATTERN_FOUND, END_OF_BUFFER, END_OF_LINE }; + enum class SearchResult { PATTERN_FOUND, END_OF_BUFFER, END_OF_LINE }; SearchResult SearchUnescapedPatternNoEOL(const char *&ptr, const char *const buf_end, const std::string &pattern, const std::vector &kmp_next); + void GetEOL(const char *const buf, const char *const buf_end); void GetValue(const char *const value_ptr, size_t value_size, ushort col, ValueCache &value); }; diff --git a/storage/stonedb/loader/read_buffer.cpp b/storage/stonedb/loader/read_buffer.cpp index aaf501d96..e5075ac45 100644 --- a/storage/stonedb/loader/read_buffer.cpp +++ b/storage/stonedb/loader/read_buffer.cpp @@ -22,117 +22,121 @@ namespace stonedb { namespace loader { -ReadBuffer::ReadBuffer(int num, int requested_size) : size(requested_size), bufs(num) { - thd = current_tx->Thd(); +ReadBuffer::ReadBuffer(int num, int requested_size) : size_(requested_size), bufs_(num) { + thd_ = current_tx->Thd(); - for (auto &b : bufs) { - b = std::unique_ptr(new char[size]); + for (auto &b : bufs_) { + b = std::unique_ptr(new char[size_]); + memset(b.get(), 0x0, size_); } - curr_buf_no = 0; - buf = bufs[curr_buf_no].get(); - curr_buf2_no = 1; - buf2 = bufs[curr_buf2_no].get(); + curr_buf_no_ = 0; + buf_ = bufs_[curr_buf_no_].get(); + curr_buf2_no_ = 1; + buf2_ = bufs_[curr_buf2_no_].get(); - buf_used = 0; - buf_incomplete = false; - bytes_in_read_thread_buffer = 0; - stop_reading_thread = true; + buf_used_ = 0; + buf_incomplete_ = false; + bytes_in_read_thread_buffer_ = 0; + stop_reading_thread_ = true; } ReadBuffer::~ReadBuffer() { - if (read_thread.joinable()) { - read_mutex.lock(); - stop_reading_thread = true; - read_mutex.unlock(); - read_thread.join(); + if (read_thread_.joinable()) { + read_mutex_.lock(); + stop_reading_thread_ = true; + read_mutex_.unlock(); + read_thread_.join(); } - if (ib_stream) ib_stream->Close(); + if (ib_stream_) ib_stream_->Close(); } bool ReadBuffer::BufOpen(std::unique_ptr &s) { - ib_stream = std::move(s); + ib_stream_ = std::move(s); - auto r = Read(buf + buf_used, size); + auto r = Read(buf_ + buf_used_, size_); if (r == -1) { - ib_stream->Close(); - buf_incomplete = false; + ib_stream_->Close(); + buf_incomplete_ = false; return false; } - if (r == size) { + + if (r == size_) { if (!StartReadingThread()) { return false; } - buf_incomplete = true; + buf_incomplete_ = true; } else { - ib_stream->Close(); - buf_incomplete = false; + ib_stream_->Close(); + buf_incomplete_ = false; } - buf_used += r; + + buf_used_ += r; return true; } bool ReadBuffer::StartReadingThread() { - if (!read_thread_buffer) { - read_thread_buffer = std::unique_ptr(new char[size]); - if (!read_thread_buffer) { - STONEDB_LOG(ERROR, "out of memory (%d bytes failed). (42)", size); + if (!read_thread_buffer_) { + read_thread_buffer_ = std::unique_ptr(new char[size_]); + if (!read_thread_buffer_) { + STONEDB_LOG(LogCtl_Level::ERROR, "out of memory (%d bytes failed). (42)", size_); return false; } } - bytes_in_read_thread_buffer = 0; - stop_reading_thread = false; - read_thread = std::thread(std::bind(&ReadBuffer::ReadThread, this)); + bytes_in_read_thread_buffer_ = 0; + + stop_reading_thread_ = false; + read_thread_ = std::thread(std::bind(&ReadBuffer::ReadThread, this)); return true; } int ReadBuffer::BufFetch(int unused_bytes) { - int to_read = size; + int to_read = size_; { - std::scoped_lock guard(read_mutex); + std::scoped_lock guard(read_mutex_); - if (bytes_in_read_thread_buffer == -1) { - ib_stream->Close(); - buf_incomplete = false; + if (bytes_in_read_thread_buffer_ == -1) { + ib_stream_->Close(); + buf_incomplete_ = false; throw common::FileException("Unable to read from the input file."); } - if ((!ib_stream->IsOpen() && bytes_in_read_thread_buffer == 0) || to_read == unused_bytes) return 0; + if ((!ib_stream_->IsOpen() && bytes_in_read_thread_buffer_ == 0) || to_read == unused_bytes) return 0; - for (int i = 0; i < unused_bytes; i++) buf2[i] = *(buf + ((buf_used - unused_bytes) + i)); + for (int i = 0; i < unused_bytes; i++) buf2_[i] = *(buf_ + ((buf_used_ - unused_bytes) + i)); to_read -= unused_bytes; - int to_read_from_th_buf = std::min(to_read, bytes_in_read_thread_buffer); + int to_read_from_th_buf = std::min(to_read, bytes_in_read_thread_buffer_); - std::memcpy(buf2 + unused_bytes, read_thread_buffer.get(), to_read_from_th_buf); + std::memcpy(buf2_ + unused_bytes, read_thread_buffer_.get(), to_read_from_th_buf); - for (int i = 0; i < bytes_in_read_thread_buffer - to_read_from_th_buf; i++) - read_thread_buffer[i] = read_thread_buffer[i + to_read_from_th_buf]; + for (int i = 0; i < bytes_in_read_thread_buffer_ - to_read_from_th_buf; i++) + read_thread_buffer_[i] = read_thread_buffer_[i + to_read_from_th_buf]; - bytes_in_read_thread_buffer -= to_read_from_th_buf; + bytes_in_read_thread_buffer_ -= to_read_from_th_buf; unused_bytes += to_read_from_th_buf; to_read -= to_read_from_th_buf; - buf_used = unused_bytes; - if (ib_stream->IsOpen()) { + buf_used_ = unused_bytes; + if (ib_stream_->IsOpen()) { ushort no_steps = 0; int r = 0; while (no_steps < 15 && to_read > 0) { try { - r = ib_stream->Read(buf2 + unused_bytes, to_read); + r = ib_stream_->Read(buf2_ + unused_bytes, to_read); } catch (common::DatabaseException &) { r = -1; } if (r != -1) { - buf_used += r; + buf_used_ += r; if (r == 0) { - ib_stream->Close(); - buf_incomplete = false; + ib_stream_->Close(); + buf_incomplete_ = false; break; } else { - buf_incomplete = true; + buf_incomplete_ = true; } if (r != to_read) { unused_bytes += r; @@ -141,19 +145,19 @@ int ReadBuffer::BufFetch(int unused_bytes) { break; } else { no_steps++; - STONEDB_LOG(WARN, "Reading from the input file error: %s", std::strerror(errno)); + STONEDB_LOG(LogCtl_Level::WARN, "Reading from the input file error: %s", std::strerror(errno)); std::this_thread::sleep_for(std::chrono::milliseconds(500 + no_steps * 500)); } } if (r == -1) { - ib_stream->Close(); - buf_incomplete = false; + ib_stream_->Close(); + buf_incomplete_ = false; throw common::FileException("Unable to read from the input file."); } } } UseNextBuf(); - return buf_used; + return buf_used_; } int ReadBuffer::Read(char *buffer, int bytes_to_read) { @@ -167,7 +171,7 @@ int ReadBuffer::Read(char *buffer, int bytes_to_read) { bool do_stop = false; while (!do_stop) { try { - read_b = ib_stream->Read(buffer + bytes_read, std::min(bytes_to_read, requested_size - bytes_read)); + read_b = ib_stream_->Read(buffer + bytes_read, std::min(bytes_to_read, requested_size - bytes_read)); } catch (common::DatabaseException &) { read_b = -1; } @@ -184,10 +188,10 @@ int ReadBuffer::Read(char *buffer, int bytes_to_read) { } void ReadBuffer::ReadThread() { - common::SetMySQLTHD(thd); + common::SetMySQLTHD(thd_); int to_read = 0; - int to_read_in_one_loop = size / 2; + int to_read_in_one_loop = size_ / 2; bool do_sleep = false; bool do_stop = false; @@ -196,74 +200,73 @@ void ReadBuffer::ReadThread() { while (!do_stop) { no_read_bytes = 0; { - std::scoped_lock guard(read_mutex); - if (!buf_incomplete || !ib_stream->IsOpen() || stop_reading_thread) { + std::scoped_lock guard(read_mutex_); + if (!buf_incomplete_ || !ib_stream_->IsOpen() || stop_reading_thread_) { break; } - if (bytes_in_read_thread_buffer != size) { + if (bytes_in_read_thread_buffer_ != size_) { to_read = to_read_in_one_loop; - if (size - bytes_in_read_thread_buffer < to_read_in_one_loop) to_read = size - bytes_in_read_thread_buffer; + if (size_ - bytes_in_read_thread_buffer_ < to_read_in_one_loop) to_read = size_ - bytes_in_read_thread_buffer_; ushort no_steps = 0; while (no_steps < 15 && to_read > 0) { try { - no_read_bytes = ib_stream->Read(read_thread_buffer.get() + bytes_in_read_thread_buffer, to_read); + no_read_bytes = ib_stream_->Read(read_thread_buffer_.get() + bytes_in_read_thread_buffer_, to_read); } catch (common::DatabaseException &) { no_read_bytes = -1; } + if (no_read_bytes == -1) { no_steps++; - STONEDB_LOG(WARN, "Reading from the input file error: %s", std::strerror(errno)); + STONEDB_LOG(LogCtl_Level::WARN, "Reading from the input file error: %s", std::strerror(errno)); std::this_thread::sleep_for(std::chrono::milliseconds(500 + no_steps * 500)); do_stop = true; } else { do_stop = false; - bytes_in_read_thread_buffer += no_read_bytes; + bytes_in_read_thread_buffer_ += no_read_bytes; if (no_read_bytes != 0) - buf_incomplete = true; + buf_incomplete_ = true; else { - ib_stream->Close(); - buf_incomplete = false; + ib_stream_->Close(); + buf_incomplete_ = false; do_stop = true; } break; } - } + } // while if (no_read_bytes == -1) { - bytes_in_read_thread_buffer = -1; + bytes_in_read_thread_buffer_ = -1; do_stop = true; } - } + } // if - if (bytes_in_read_thread_buffer == size) - do_sleep = true; - else - do_sleep = false; + (bytes_in_read_thread_buffer_ == size_) ? do_sleep = true : do_sleep = false; } - if (do_sleep) std::this_thread::sleep_for(std::chrono::milliseconds(20)); - if (no_read_bytes != -1) std::this_thread::sleep_for(std::chrono::milliseconds(20)); - } + + if (do_sleep || no_read_bytes != -1) std::this_thread::sleep_for(std::chrono::milliseconds(20)); + } // while (!do_stop) + return; } void ReadBuffer::UseNextBuf() { - int tmp = curr_buf2_no; - curr_buf2_no = FindUnusedBuf(); - buf2 = bufs[curr_buf2_no].get(); // to be loaded with data - curr_buf_no = tmp; - buf = bufs[curr_buf_no].get(); // to be parsed + int tmp = curr_buf2_no_; + curr_buf2_no_ = FindUnusedBuf(); + buf2_ = bufs_[curr_buf2_no_].get(); // to be loaded with data + curr_buf_no_ = tmp; + buf_ = bufs_[curr_buf_no_].get(); // to be parsed } int ReadBuffer::FindUnusedBuf() { - std::unique_lock lk(mtx); + std::unique_lock lk(mtx_); while (true) { - for (size_t i = 0; i < bufs.size(); i++) { - if (int(i) != curr_buf2_no) { // not used and not just loaded + for (size_t i = 0; i < bufs_.size(); i++) { + if (int(i) != curr_buf2_no_) { // not used and not just loaded return i; } } - cv.wait(lk); + cv_.wait(lk); } return -1; } diff --git a/storage/stonedb/loader/read_buffer.h b/storage/stonedb/loader/read_buffer.h index 77a1db11a..6524bec1f 100644 --- a/storage/stonedb/loader/read_buffer.h +++ b/storage/stonedb/loader/read_buffer.h @@ -36,34 +36,33 @@ class ReadBuffer final : public mm::TraceableObject { bool BufOpen(std::unique_ptr &s); int BufFetch(int unused_bytes); // load the next data block into buffer - int BufSize() const { return buf_used; } - char *Buf() const { return buf; } + int BufSize() const { return buf_used_; } + char *Buf() const { return buf_; } int Read(char *buffer, int bytes_to_read); - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } private: - int buf_used; // number of bytes loaded or reserved so far - char *buf; // current buf in bufs - int size; - int curr_buf_no; // buf = bufs + currBufNo - char *buf2; // buf to be used next - int curr_buf2_no; - int bytes_in_read_thread_buffer; - bool buf_incomplete; - - std::vector> bufs; - std::unique_ptr read_thread_buffer; - - std::unique_ptr ib_stream; - - std::mutex read_mutex; - - std::mutex mtx; - std::condition_variable cv; - - std::thread read_thread; - bool stop_reading_thread; - THD *thd; + int buf_used_; // number of bytes loaded or reserved so far + char *buf_; // current buf in bufs + int size_; + int curr_buf_no_; // buf_ = bufs_ + currBufNo + char *buf2_; // buf to be used next + int curr_buf2_no_; + int bytes_in_read_thread_buffer_; + bool buf_incomplete_; + + std::vector> bufs_; + std::unique_ptr read_thread_buffer_; + std::unique_ptr ib_stream_; + + std::mutex read_mutex_; + + std::mutex mtx_; + std::condition_variable cv_; + + std::thread read_thread_; + bool stop_reading_thread_; + THD *thd_; void ReadThread(); void UseNextBuf(); diff --git a/storage/stonedb/loader/rejecter.cpp b/storage/stonedb/loader/rejecter.cpp index 84c4401bf..5c950e908 100644 --- a/storage/stonedb/loader/rejecter.cpp +++ b/storage/stonedb/loader/rejecter.cpp @@ -40,10 +40,10 @@ void Rejecter::ConsumeBadRow(char const *ptr, int64_t size, int64_t row_no, int } writer->WriteExact(ptr, (uint)size); } - STONEDB_LOG(WARN, "Loading file error, row %ld, around:", row_no); - STONEDB_LOG(WARN, "---------------------------------------------\n"); - STONEDB_LOG(WARN, "%s", ptr); - STONEDB_LOG(WARN, "---------------------------------------------"); + STONEDB_LOG(LogCtl_Level::WARN, "Loading file error, row %ld, around:", row_no); + STONEDB_LOG(LogCtl_Level::WARN, "---------------------------------------------\n"); + STONEDB_LOG(LogCtl_Level::WARN, "%s", ptr); + STONEDB_LOG(LogCtl_Level::WARN, "---------------------------------------------"); if (abort_on_threshold > 0) { if (row_no > packrow_size) diff --git a/storage/stonedb/mm/heap_policy.h b/storage/stonedb/mm/heap_policy.h index dfc258a39..425657ecc 100644 --- a/storage/stonedb/mm/heap_policy.h +++ b/storage/stonedb/mm/heap_policy.h @@ -23,11 +23,11 @@ namespace stonedb { namespace mm { -enum HEAP_STATUS { HEAP_SUCCESS, HEAP_OUT_OF_MEMORY, HEAP_CORRUPTED, HEAP_ERROR }; +enum class HEAP_STATUS { HEAP_SUCCESS, HEAP_OUT_OF_MEMORY, HEAP_CORRUPTED, HEAP_ERROR }; class HeapPolicy { public: - HeapPolicy(size_t s) : m_size(s), m_stonedb(HEAP_ERROR) {} + HeapPolicy(size_t s) : m_size(s), m_stonedb(HEAP_STATUS::HEAP_ERROR) {} virtual ~HeapPolicy() {} virtual void *alloc(size_t size) = 0; virtual void dealloc(void *mh) = 0; diff --git a/storage/stonedb/mm/huge_heap_policy.cpp b/storage/stonedb/mm/huge_heap_policy.cpp index 565935b01..4383bca7f 100644 --- a/storage/stonedb/mm/huge_heap_policy.cpp +++ b/storage/stonedb/mm/huge_heap_policy.cpp @@ -31,7 +31,7 @@ HugeHeap::HugeHeap(std::string hugedir, size_t size) : TCMHeap(0) { m_heap_frame = NULL; // convert size from MB to B and make it a multiple of 2MB m_size = 1_MB * (size & ~0x1); - m_stonedb = HEAP_ERROR; + m_stonedb = HEAP_STATUS::HEAP_ERROR; m_fd = -1; if (!hugedir.empty() && size > 0) { @@ -42,7 +42,7 @@ HugeHeap::HugeHeap(std::string hugedir, size_t size) : TCMHeap(0) { std::strcat(m_hugefilename, pidtext); m_fd = open(m_hugefilename, O_CREAT | O_RDWR, 0700); if (m_fd < 0) { - m_stonedb = HEAP_OUT_OF_MEMORY; + m_stonedb = HEAP_STATUS::HEAP_OUT_OF_MEMORY; rccontrol << system::lock << "Memory Manager Error: Unable to create hugepage file: " << m_hugefilename << system::unlock; return; @@ -53,7 +53,7 @@ HugeHeap::HugeHeap(std::string hugedir, size_t size) : TCMHeap(0) { m_heap_frame = (char *)mmap(NULL, m_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, m_fd, 0); if (m_heap_frame == MAP_FAILED) { unlink(m_hugefilename); - m_stonedb = HEAP_OUT_OF_MEMORY; + m_stonedb = HEAP_STATUS::HEAP_OUT_OF_MEMORY; rccontrol << system::lock << "Memory Manager Error: hugepage file mmap error: " << std::strerror(errno) << system::unlock; return; @@ -64,7 +64,7 @@ HugeHeap::HugeHeap(std::string hugedir, size_t size) : TCMHeap(0) { // manage the region as a normal 4k pagesize heap m_heap.RegisterArea(m_heap_frame, m_size >> kPageShift); m_size = size; - m_stonedb = HEAP_SUCCESS; + m_stonedb = HEAP_STATUS::HEAP_SUCCESS; } } diff --git a/storage/stonedb/mm/initializer.h b/storage/stonedb/mm/initializer.h index a81459953..c4e17996c 100644 --- a/storage/stonedb/mm/initializer.h +++ b/storage/stonedb/mm/initializer.h @@ -45,7 +45,7 @@ class MemoryManagerInitializer : public TraceableObject { } static void EnsureNoLeakedTraceableObject() { m_MemHandling->EnsureNoLeakedTraceableObject(); } - TO_TYPE TraceableType() const override { return TO_INITIALIZER; } + TO_TYPE TraceableType() const override { return TO_TYPE::TO_INITIALIZER; } private: MemoryManagerInitializer(size_t comp_size, size_t uncomp_size, std::string hugedir = "", int hugesize = 0) diff --git a/storage/stonedb/mm/memory_block.h b/storage/stonedb/mm/memory_block.h index 6c687cc82..d7a904300 100644 --- a/storage/stonedb/mm/memory_block.h +++ b/storage/stonedb/mm/memory_block.h @@ -21,7 +21,7 @@ namespace stonedb { namespace mm { -enum BLOCK_TYPE : char { +enum class BLOCK_TYPE : char { BLOCK_FREE, BLOCK_COMPRESSED, BLOCK_UNCOMPRESSED, diff --git a/storage/stonedb/mm/memory_handling_policy.cpp b/storage/stonedb/mm/memory_handling_policy.cpp index 864245a6c..55f63fb2a 100644 --- a/storage/stonedb/mm/memory_handling_policy.cpp +++ b/storage/stonedb/mm/memory_handling_policy.cpp @@ -80,8 +80,8 @@ MemoryHandling::MemoryHandling([[maybe_unused]] size_t comp_heap_size, size_t un lt_size = 0; } - STONEDB_LOG(INFO, "Adjusted Main Heap size = %ld", adj_mh_size); - STONEDB_LOG(INFO, "Adjusted LT Heap size = %ld", lt_size); + STONEDB_LOG(LogCtl_Level::INFO, "Adjusted Main Heap size = %ld", adj_mh_size); + STONEDB_LOG(LogCtl_Level::INFO, "Adjusted LT Heap size = %ld", lt_size); // Which heaps to use if (hpolicy == "system") { @@ -161,18 +161,18 @@ void *MemoryHandling::alloc(size_t size, BLOCK_TYPE type, TraceableObject *owner ASSERT(size < (size_t)(1 << 31), "Oversized alloc request!"); // choose appropriate heap for this request switch (type) { - case BLOCK_TEMPORARY: + case BLOCK_TYPE::BLOCK_TEMPORARY: // Disable huge_heap check as // 1. it cann't work // 2. it is hardcoded off - // if (m_huge_heap->getHeapStatus() == HEAP_SUCCESS) + // if (m_huge_heap->getHeapStatus() == HEAP_STATUS::HEAP_SUCCESS) // heap = m_huge_heap; if ((m_large_temp != NULL) && (size >= (stonedb_sysvar_mm_large_threshold * 1_MB))) switch (owner->TraceableType()) { - case TO_SORTER: - case TO_CACHEDBUFFER: - case TO_INDEXTABLE: - case TO_TEMPORARY: + case TO_TYPE::TO_SORTER: + case TO_TYPE::TO_CACHEDBUFFER: + case TO_TYPE::TO_INDEXTABLE: + case TO_TYPE::TO_TEMPORARY: heap = m_large_temp; break; default: @@ -222,11 +222,11 @@ void *MemoryHandling::alloc(size_t size, BLOCK_TYPE type, TraceableObject *owner m_alloc_blocks++; m_alloc_size += bsize; if (owner != NULL) - if (owner->TraceableType() == TO_PACK) { + if (owner->TraceableType() == TO_TYPE::TO_PACK) { m_alloc_pack_size += bsize; m_alloc_pack++; } else { - // I want this for type = BLOCK_TEMPORARY but will take this for now + // I want this for type = BLOCK_TYPE::BLOCK_TEMPORARY but will take this for now m_alloc_temp_size += bsize; m_alloc_temp++; } @@ -273,7 +273,7 @@ void MemoryHandling::dealloc(void *mh, TraceableObject *owner) { m_free_blocks++; m_free_size += bsize; if (owner != NULL) - if (owner->TraceableType() == TO_PACK) { + if (owner->TraceableType() == TO_TYPE::TO_PACK) { m_free_pack_size += bsize; m_free_pack++; } else { @@ -317,7 +317,7 @@ bool MemoryHandling::ReleaseMemory(size_t size, [[maybe_unused]] TraceableObject for (auto &it : m_objs) { if (it.first == NULL) continue; - if (it.first->IsLocked() || it.first->TraceableType() != TO_PACK) continue; + if (it.first->IsLocked() || it.first->TraceableType() != TO_TYPE::TO_PACK) continue; for (auto &mit : *it.second) { if (mit.second == m_system) { @@ -341,7 +341,7 @@ bool MemoryHandling::ReleaseMemory(size_t size, [[maybe_unused]] TraceableObject auto it = m_objs.begin(); while (it != m_objs.end()) { if ( (*it).first != NULL ) - if ((*it).first->TraceableType() == TO_PACK && (*it).first->IsLocked() == false) { + if ((*it).first->TraceableType() == TO_TYPE::TO_PACK && (*it).first->IsLocked() == false) { if ( (*it).first->IsPrefetchUnused() ) (*it).first->clearPrefetchUnused(); else @@ -381,16 +381,16 @@ void MemoryHandling::ReportLeaks() { size += it2.second->getBlockSize(it2.first); } } - if (blocks > 0) STONEDB_LOG(WARN, "%d memory block(s) leaked total size = %ld", blocks, size); + if (blocks > 0) STONEDB_LOG(LogCtl_Level::WARN, "%d memory block(s) leaked total size = %ld", blocks, size); } void MemoryHandling::EnsureNoLeakedTraceableObject() { bool error_found = false; for (auto it : m_objs) { - if (it.first->IsLocked() && (it.first->NoLocks() > 1 || it.first->TraceableType() == TO_PACK)) { + if (it.first->IsLocked() && (it.first->NoLocks() > 1 || it.first->TraceableType() == TO_TYPE::TO_PACK)) { error_found = true; - STONEDB_LOG(ERROR, "Object @[%ld] locked too many times. Object type: %d, no. locks: %d", long(it.first), - int(it.first->TraceableType()), int(it.first->NoLocks())); + STONEDB_LOG(LogCtl_Level::ERROR, "Object @[%ld] locked too many times. Object type: %d, no. locks: %d", + long(it.first), int(it.first->TraceableType()), int(it.first->NoLocks())); } } ASSERT(!error_found, "Objects locked too many times found."); @@ -449,10 +449,11 @@ void MemoryHandling::HeapHistogram(std::ostream &out) { unsigned packs_locked = 0; SimpleHist main_heap("Main Heap Total"), huge_heap("Huge Heap Total"), system_heap("System Heap Total"), - large_temp("Large Temporary Heap"), packs("TO_PACK objects"), sorter("TO_SORTER objects"), - cbit("TO_CACHEDBUFFER+TO_INDEXTABLE objects"), filter("TO_FILTER+TO_MULTIFILTER2 objects"), - rsisplice("TO_RSINDEX+TO_SPLICE objects"), temp("TO_TEMPORARY objects"), ftree("TO_FTREE objects"), - other("other objects"); + large_temp("Large Temporary Heap"), packs("TO_TYPE::TO_PACK objects"), sorter("TO_TYPE::TO_SORTER objects"), + cbit("TO_TYPE::TO_CACHEDBUFFER+TO_TYPE::TO_INDEXTABLE objects"), + filter("TO_TYPE::TO_FILTER+TO_TYPE::TO_MULTIFILTER2 objects"), + rsisplice("TO_TYPE::TO_RSINDEX+TO_TYPE::TO_SPLICE objects"), temp("TO_TYPE::TO_TEMPORARY objects"), + ftree("TO_TYPE::TO_FTREE objects"), other("other objects"); std::unordered_map used_blocks; @@ -467,31 +468,31 @@ void MemoryHandling::HeapHistogram(std::ostream &out) { for (auto it : m_objs) { SimpleHist *block_type; - if (it.first->TraceableType() == TO_PACK && it.first->IsLocked()) packs_locked++; + if (it.first->TraceableType() == TO_TYPE::TO_PACK && it.first->IsLocked()) packs_locked++; switch (it.first->TraceableType()) { - case TO_PACK: + case TO_TYPE::TO_PACK: block_type = &packs; break; - case TO_SORTER: + case TO_TYPE::TO_SORTER: block_type = &sorter; break; - case TO_CACHEDBUFFER: - case TO_INDEXTABLE: + case TO_TYPE::TO_CACHEDBUFFER: + case TO_TYPE::TO_INDEXTABLE: block_type = &cbit; break; - case TO_FILTER: - case TO_MULTIFILTER2: + case TO_TYPE::TO_FILTER: + case TO_TYPE::TO_MULTIFILTER2: block_type = &filter; break; - case TO_RSINDEX: - case TO_SPLICE: + case TO_TYPE::TO_RSINDEX: + case TO_TYPE::TO_SPLICE: block_type = &rsisplice; break; - case TO_TEMPORARY: + case TO_TYPE::TO_TEMPORARY: block_type = &temp; break; - case TO_FTREE: + case TO_TYPE::TO_FTREE: block_type = &ftree; break; default: diff --git a/storage/stonedb/mm/mysql_heap_policy.h b/storage/stonedb/mm/mysql_heap_policy.h index 96d53e270..83a4bd94e 100644 --- a/storage/stonedb/mm/mysql_heap_policy.h +++ b/storage/stonedb/mm/mysql_heap_policy.h @@ -32,7 +32,7 @@ class MySQLHeap : public HeapPolicy { /* allocate memory block of size [size] and for data of type [type] - type != BLOCK_FREE + type != BLOCK_TYPE::BLOCK_FREE */ void *alloc(size_t size) override; void dealloc(void *mh) override; diff --git a/storage/stonedb/mm/numa_heap_policy.h b/storage/stonedb/mm/numa_heap_policy.h index 69ffac17f..96e8f4745 100644 --- a/storage/stonedb/mm/numa_heap_policy.h +++ b/storage/stonedb/mm/numa_heap_policy.h @@ -22,7 +22,7 @@ class NUMAHeap : public HeapPolicy { /* allocate memory block of size [size] and for data of type [type] - type != BLOCK_FREE + type != BLOCK_TYPE::BLOCK_FREE */ void *alloc(size_t size); void dealloc(void *mh); diff --git a/storage/stonedb/mm/reference_object.h b/storage/stonedb/mm/reference_object.h index 2f7ada600..b6b848f9c 100644 --- a/storage/stonedb/mm/reference_object.h +++ b/storage/stonedb/mm/reference_object.h @@ -24,7 +24,7 @@ class ReferenceObject : public TraceableObject { m_coord.co.rcattr = r; } ReferenceObject(core::TOCoordinate &r) : TraceableObject() { m_coord = r; } - TO_TYPE TraceableType() const override { return TO_REFERENCE; } + TO_TYPE TraceableType() const override { return TO_TYPE::TO_REFERENCE; } }; } // namespace mm diff --git a/storage/stonedb/mm/release2q.cpp b/storage/stonedb/mm/release2q.cpp index c4aad4331..6bc9bcb17 100644 --- a/storage/stonedb/mm/release2q.cpp +++ b/storage/stonedb/mm/release2q.cpp @@ -28,7 +28,7 @@ namespace stonedb { namespace mm { void Release2Q::Access(TraceableObject *o) { - // ASSERT(o->TraceableType() == TO_PACK, "Access wrong type"); + // ASSERT(o->TraceableType() == TO_TYPE::TO_PACK, "Access wrong type"); if (!o->IsTracked()) { auto it = A1outLookup.find(o->GetCoordinate()); if (it != A1outLookup.end()) { diff --git a/storage/stonedb/mm/sys_heap_policy.h b/storage/stonedb/mm/sys_heap_policy.h index 04f6f6d4c..91490e4aa 100644 --- a/storage/stonedb/mm/sys_heap_policy.h +++ b/storage/stonedb/mm/sys_heap_policy.h @@ -31,7 +31,7 @@ class SystemHeap : public HeapPolicy { /* allocate memory block of size [size] and for data of type [type] - type != BLOCK_FREE + type != BLOCK_TYPE::BLOCK_FREE */ void *alloc(size_t size) override; void dealloc(void *mh) override; diff --git a/storage/stonedb/mm/tcm/page_heap.cpp b/storage/stonedb/mm/tcm/page_heap.cpp index 14522aaef..849e90d8a 100644 --- a/storage/stonedb/mm/tcm/page_heap.cpp +++ b/storage/stonedb/mm/tcm/page_heap.cpp @@ -55,13 +55,13 @@ Span *PageHeap::New(Length n) { Span *ll = &free_[s].normal; // If we're lucky, ll is non-empty, meaning it has a suitable span. if (!DLL_IsEmpty(ll)) { - ASSERT(ll->next->location == Span::ON_NORMAL_FREELIST); + ASSERT(ll->next->location == static_cast(Span::enumSpanType::ON_NORMAL_FREELIST)); return Carve(ll->next, n); } // Alternatively, maybe there's a usable returned span. ll = &free_[s].returned; if (!DLL_IsEmpty(ll)) { - ASSERT(ll->next->location == Span::ON_RETURNED_FREELIST); + ASSERT(ll->next->location == static_cast(Span::enumSpanType::ON_RETURNED_FREELIST)); return Carve(ll->next, n); } // Still no luck, so keep looking in larger classes. @@ -89,7 +89,7 @@ Span *PageHeap::AllocLarge(Length n) { if ((best == NULL) || (span->length < best->length) || ((span->length == best->length) && (span->start < best->start))) { best = span; - ASSERT(best->location == Span::ON_NORMAL_FREELIST); + ASSERT(best->location == static_cast(Span::enumSpanType::ON_NORMAL_FREELIST)); } } } @@ -100,7 +100,7 @@ Span *PageHeap::AllocLarge(Length n) { if ((best == NULL) || (span->length < best->length) || ((span->length == best->length) && (span->start < best->start))) { best = span; - ASSERT(best->location == Span::ON_RETURNED_FREELIST); + ASSERT(best->location == static_cast(Span::enumSpanType::ON_RETURNED_FREELIST)); } } } @@ -110,10 +110,10 @@ Span *PageHeap::AllocLarge(Length n) { Span *PageHeap::Carve(Span *span, Length n) { ASSERT(n > 0); - ASSERT(span->location != Span::IN_USE); + ASSERT(span->location != static_cast(Span::enumSpanType::IN_USE)); const int old_location = span->location; RemoveFromFreeList(span); - span->location = Span::IN_USE; + span->location = static_cast(Span::enumSpanType::IN_USE); Event(span, 'A', n); const int extra = int(span->length - n); @@ -133,14 +133,14 @@ Span *PageHeap::Carve(Span *span, Length n) { void PageHeap::Delete(Span *span) { ASSERT(Check()); - ASSERT(span->location == Span::IN_USE); + ASSERT(span->location == static_cast(Span::enumSpanType::IN_USE)); ASSERT(span->length > 0); ASSERT(GetDescriptor(span->start) == span); ASSERT(GetDescriptor(span->start + span->length - 1) == span); const Length n = span->length; span->sizeclass = 0; span->sample = 0; - span->location = Span::ON_NORMAL_FREELIST; + span->location = static_cast(Span::enumSpanType::ON_NORMAL_FREELIST); Event(span, 'D', span->length); MergeIntoFreeList(span); // Coalesces if possible IncrementalScavenge(n); @@ -148,7 +148,7 @@ void PageHeap::Delete(Span *span) { } void PageHeap::MergeIntoFreeList(Span *span) { - ASSERT(span->location != Span::IN_USE); + ASSERT(span->location != static_cast(Span::enumSpanType::IN_USE)); // Coalesce -- we guarantee that "p" != 0, so no bounds checking // necessary. We do not bother resetting the stale pagemap @@ -187,9 +187,9 @@ void PageHeap::MergeIntoFreeList(Span *span) { } void PageHeap::PrependToFreeList(Span *span) { - ASSERT(span->location != Span::IN_USE); + ASSERT(span->location != static_cast(Span::enumSpanType::IN_USE)); SpanList *list = (span->length < kMaxPages) ? &free_[span->length] : &large_; - if (span->location == Span::ON_NORMAL_FREELIST) { + if (span->location == static_cast(Span::enumSpanType::ON_NORMAL_FREELIST)) { stats_.free_bytes += (span->length << kPageShift); DLL_Prepend(&list->normal, span); } else { @@ -199,8 +199,8 @@ void PageHeap::PrependToFreeList(Span *span) { } void PageHeap::RemoveFromFreeList(Span *span) { - ASSERT(span->location != Span::IN_USE); - if (span->location == Span::ON_NORMAL_FREELIST) { + ASSERT(span->location != static_cast(Span::enumSpanType::IN_USE)); + if (span->location == static_cast(Span::enumSpanType::ON_NORMAL_FREELIST)) { stats_.free_bytes -= (span->length << kPageShift); } else { stats_.unmapped_bytes -= (span->length << kPageShift); @@ -243,12 +243,12 @@ void PageHeap::IncrementalScavenge(Length n) { Length PageHeap::ReleaseLastNormalSpan(SpanList *slist) { Span *s = slist->normal.prev; - ASSERT(s->location == Span::ON_NORMAL_FREELIST); + ASSERT(s->location == static_cast(Span::enumSpanType::ON_NORMAL_FREELIST)); RemoveFromFreeList(s); const Length n = s->length; // TCMalloc_SystemRelease(reinterpret_cast(s->start << kPageShift), // static_cast(s->length << kPageShift)); - s->location = Span::ON_RETURNED_FREELIST; + s->location = static_cast(Span::enumSpanType::ON_RETURNED_FREELIST); MergeIntoFreeList(s); // Coalesces if possible. return n; } @@ -280,7 +280,7 @@ Length PageHeap::ReleaseAtLeastNPages(Length num_pages) { void PageHeap::RegisterSizeClass(Span *span, size_t sc) { // Associate span object with all interior pages as well - ASSERT(span->location == Span::IN_USE); + ASSERT(span->location == static_cast(Span::enumSpanType::IN_USE)); ASSERT(GetDescriptor(span->start) == span); ASSERT(GetDescriptor(span->start + span->length - 1) == span); Event(span, 'C', sc); diff --git a/storage/stonedb/mm/tcm/page_heap.h b/storage/stonedb/mm/tcm/page_heap.h index f4891bc12..8a9c8f1b7 100644 --- a/storage/stonedb/mm/tcm/page_heap.h +++ b/storage/stonedb/mm/tcm/page_heap.h @@ -54,7 +54,7 @@ namespace tcm { template class MapSelector { public: - using Type = TCMalloc_PageMap3 ; + using Type = TCMalloc_PageMap3; }; // ------------------------------------------------------------------------- @@ -170,7 +170,7 @@ class PageHeap final { std::list system_alloc_list; // REQUIRES: span->length >= n - // REQUIRES: span->location != IN_USE + // REQUIRES: span->location != enumSpanType::IN_USE // Remove span from its free list, and move any leftover part of // span into appropriate free lists. Also update "span" to have // length exactly "n" and mark it as non-free so it can be returned diff --git a/storage/stonedb/mm/tcm/span.h b/storage/stonedb/mm/tcm/span.h index 5a6943c38..99898a9bb 100644 --- a/storage/stonedb/mm/tcm/span.h +++ b/storage/stonedb/mm/tcm/span.h @@ -61,7 +61,7 @@ struct Span { #endif // What freelist the span is on: IN_USE if on none, or normal or returned - enum { IN_USE, ON_NORMAL_FREELIST, ON_RETURNED_FREELIST }; + enum class enumSpanType { IN_USE, ON_NORMAL_FREELIST, ON_RETURNED_FREELIST }; }; #ifdef SPAN_HISTORY diff --git a/storage/stonedb/mm/tcm_heap_policy.h b/storage/stonedb/mm/tcm_heap_policy.h index ba02209a9..0e391e919 100644 --- a/storage/stonedb/mm/tcm_heap_policy.h +++ b/storage/stonedb/mm/tcm_heap_policy.h @@ -93,7 +93,7 @@ class TCMHeap : public HeapPolicy { /* allocate memory block of size [size] and for data of type [type] - type != BLOCK_FREE + type != BLOCK_TYPE::BLOCK_FREE */ void *alloc(size_t size) override; void dealloc(void *mh) override; diff --git a/storage/stonedb/mm/traceable_object.cpp b/storage/stonedb/mm/traceable_object.cpp index abbbeb991..3106fb2f8 100644 --- a/storage/stonedb/mm/traceable_object.cpp +++ b/storage/stonedb/mm/traceable_object.cpp @@ -38,10 +38,10 @@ std::atomic_size_t TraceableObject::globalUnFreeable; // static const char *TypeName(TO_TYPE tt) // { // static const char *arr[] = { -// "TO_PACK", "TO_SORTER", "TO_CACHEDBUFFER", "TO_FILTER", -// "TO_MULTIFILTER2", "TO_INDEXTABLE", "TO_RSINDEX", "TO_TEMPORARY", -// "TO_FTREE", "TO_SPLICE", "TO_INITIALIZER", "TO_DEPENDENT", -// "TO_REFERENCE", "TO_DATABLOCK", +// "TO_TYPE::TO_PACK", "TO_TYPE::TO_SORTER", "TO_TYPE::TO_CACHEDBUFFER", "TO_TYPE::TO_FILTER", +// "TO_TYPE::TO_MULTIFILTER2", "TO_TYPE::TO_INDEXTABLE", "TO_TYPE::TO_RSINDEX", "TO_TYPE::TO_TEMPORARY", +// "TO_TYPE::TO_FTREE", "TO_TYPE::TO_SPLICE", "TO_TYPE::TO_INITIALIZER", "TO_TYPE::TO_DEPENDENT", +// "TO_TYPE::TO_REFERENCE", "TO_TYPE::TO_DATABLOCK", // // }; // return arr[tt]; @@ -56,7 +56,7 @@ void *TraceableObject::alloc(size_t size, BLOCK_TYPE type, bool nothrow) { if (addr != NULL) { size_t s = Instance()->rc_msize(addr, this); m_sizeAllocated += s; - if (!IsLocked() && TraceableType() == TO_PACK) + if (!IsLocked() && TraceableType() == TO_TYPE::TO_PACK) globalFreeable += s; else globalUnFreeable += s; @@ -70,7 +70,7 @@ void TraceableObject::dealloc(void *ptr) { s = Instance()->rc_msize(ptr, this); Instance()->dealloc(ptr, this); m_sizeAllocated -= s; - if (!IsLocked() && TraceableType() == TO_PACK) + if (!IsLocked() && TraceableType() == TO_TYPE::TO_PACK) globalFreeable -= s; else globalUnFreeable -= s; @@ -85,7 +85,7 @@ void *TraceableObject::rc_realloc(void *ptr, size_t size, BLOCK_TYPE type) { size_t s = Instance()->rc_msize(addr, this); m_sizeAllocated += s; m_sizeAllocated -= s1; - if (!IsLocked() && TraceableType() == TO_PACK) { + if (!IsLocked() && TraceableType() == TO_TYPE::TO_PACK) { globalFreeable += s; globalFreeable -= s1; } else { @@ -132,7 +132,7 @@ TraceableObject::~TraceableObject() { void TraceableObject::Lock() { MEASURE_FET("TraceableObject::Lock"); - if (TraceableType() == TO_PACK) { + if (TraceableType() == TO_TYPE::TO_PACK) { std::scoped_lock locking_guard(m_locking_mutex); clearPrefetchUnused(); if (!IsLocked()) { @@ -156,7 +156,7 @@ void TraceableObject::Lock() { } void TraceableObject::SetNoLocks(int n) { - if (TraceableType() == TO_PACK) { + if (TraceableType() == TO_TYPE::TO_PACK) { std::scoped_lock locking_guard(m_locking_mutex); clearPrefetchUnused(); if (!IsLocked()) { @@ -184,11 +184,11 @@ void TraceableObject::Unlock() { std::scoped_lock locking_guard(m_locking_mutex); m_lock_count--; if (m_lock_count < 0) { - STONEDB_LOG(ERROR, "Internal error: An object unlocked too many times in memory manager."); + STONEDB_LOG(LogCtl_Level::ERROR, "Internal error: An object unlocked too many times in memory manager."); DEBUG_ASSERT(!"Internal error: An object unlocked too many times in memory manager."); m_lock_count = 0; } - if (!IsLocked() && TraceableType() == TO_PACK) { + if (!IsLocked() && TraceableType() == TO_TYPE::TO_PACK) { globalUnFreeable -= m_sizeAllocated; globalFreeable += m_sizeAllocated; } @@ -215,7 +215,7 @@ void TraceableObject::UnlockAndResetPack(std::shared_ptr &pack) { void TraceableObject::DestructionLock() { std::scoped_lock locking_guard(m_locking_mutex); - if (!IsLocked() && TraceableType() == TO_PACK) { + if (!IsLocked() && TraceableType() == TO_TYPE::TO_PACK) { globalUnFreeable += m_sizeAllocated; globalFreeable -= m_sizeAllocated; } @@ -225,8 +225,8 @@ void TraceableObject::DestructionLock() { int TraceableObject::MemorySettingsScale() { return rceng->getResourceManager()->GetMemoryScale(); } void TraceableObject::deinitialize(bool detect_leaks) { - if (TraceableType() != TO_INITIALIZER) { - STONEDB_ERROR("TraceableType() not equals 'TO_INITIALIZER'"); + if (TraceableType() != TO_TYPE::TO_INITIALIZER) { + STONEDB_ERROR("TraceableType() not equals 'TO_TYPE::TO_INITIALIZER'"); return; } diff --git a/storage/stonedb/mm/traceable_object.h b/storage/stonedb/mm/traceable_object.h index ffcaa99fb..9a4882436 100644 --- a/storage/stonedb/mm/traceable_object.h +++ b/storage/stonedb/mm/traceable_object.h @@ -36,7 +36,7 @@ class MemoryHandling; namespace mm { -enum TO_TYPE { +enum class TO_TYPE { TO_PACK = 0, TO_SORTER, TO_CACHEDBUFFER, @@ -129,7 +129,7 @@ class TraceableObject { void *alloc(size_t size, BLOCK_TYPE type, bool nothrow = false); void dealloc(void *ptr); - void *rc_realloc(void *ptr, size_t size, BLOCK_TYPE type = BLOCK_FIXED); + void *rc_realloc(void *ptr, size_t size, BLOCK_TYPE type = BLOCK_TYPE::BLOCK_FIXED); size_t rc_msize(void *ptr); void deinitialize(bool detect_leaks); diff --git a/storage/stonedb/system/fet.h b/storage/stonedb/system/fet.h index 6a7fb0f5b..8c4b9d247 100644 --- a/storage/stonedb/system/fet.h +++ b/storage/stonedb/system/fet.h @@ -106,7 +106,7 @@ class FunctionsExecutionTimes { private: void Clear() { times->clear(); } void Print() { - STONEDB_LOG(INFO, + STONEDB_LOG(LogCtl_Level::INFO, "***** Function Execution Times " "************************************************************"); std::priority_queue, SortEntryLess> sq; @@ -115,16 +115,16 @@ class FunctionsExecutionTimes { while (!sq.empty()) { std::sprintf(str, "%-60s \t%6llu \t%8.2fs", sq.top().n.c_str(), sq.top().e.call, sq.top().e.time / 1000000.0); - STONEDB_LOG(INFO, "%s", str); + STONEDB_LOG(LogCtl_Level::INFO, "%s", str); sq.pop(); } - STONEDB_LOG(INFO, "Number of distinct Data Packs loads: %u", (uint)count_distinct_dp_loads.size()); - STONEDB_LOG(INFO, "Number of distinct Data Packs decompressions: %u", + STONEDB_LOG(LogCtl_Level::INFO, "Number of distinct Data Packs loads: %u", (uint)count_distinct_dp_loads.size()); + STONEDB_LOG(LogCtl_Level::INFO, "Number of distinct Data Packs decompressions: %u", (uint)count_distinct_dp_decompressions.size()); - STONEDB_LOG(INFO, "Size of DP read from disk: %fMB", ((double)NoBytesReadByDPs / 1_MB)); - STONEDB_LOG(INFO, "Size of uncompressed DPs: %fMB", ((double)SizeOfUncompressedDP / 1_MB)); - STONEDB_LOG(INFO, + STONEDB_LOG(LogCtl_Level::INFO, "Size of DP read from disk: %fMB", ((double)NoBytesReadByDPs / 1_MB)); + STONEDB_LOG(LogCtl_Level::INFO, "Size of uncompressed DPs: %fMB", ((double)SizeOfUncompressedDP / 1_MB)); + STONEDB_LOG(LogCtl_Level::INFO, "**************************************************************" "***********" "******************"); diff --git a/storage/stonedb/system/file_system.cpp b/storage/stonedb/system/file_system.cpp index e6ecbf9d8..8eb07b22a 100644 --- a/storage/stonedb/system/file_system.cpp +++ b/storage/stonedb/system/file_system.cpp @@ -40,11 +40,11 @@ int ClearDirectory(std::string const &path) { fs::remove_all(p); } } catch (fs::filesystem_error &e) { - STONEDB_LOG(ERROR, "Failed to ClearDirectory(%s). filesystem_error: %s %s %s", path.c_str(), e.what(), + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to ClearDirectory(%s). filesystem_error: %s %s %s", path.c_str(), e.what(), e.path1().native().c_str(), e.path2().native().c_str()); return 1; } catch (std::exception &e) { - STONEDB_LOG(ERROR, "Failed to ClearDirectory(%s). error: %s", path.c_str(), e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to ClearDirectory(%s). error: %s", path.c_str(), e.what()); return 1; } return 0; @@ -63,13 +63,14 @@ void DeleteDirectory(std::string const &path) { // ingore error because the target might be under 'path' and thus have // been removed fs::remove_all(t, ec); - if (ec && ec != std::errc::no_such_file_or_directory) STONEDB_LOG(ERROR, "Failed to delete %s", t.c_str()); + if (ec && ec != std::errc::no_such_file_or_directory) + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to delete %s", t.c_str()); } } catch (fs::filesystem_error &e) { - STONEDB_LOG(ERROR, "Failed to delete directory(%s). filesystem_error: %s %s %s", path.c_str(), e.what(), - e.path1().native().c_str(), e.path2().native().c_str()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to delete directory(%s). filesystem_error: %s %s %s", path.c_str(), + e.what(), e.path1().native().c_str(), e.path2().native().c_str()); } catch (std::exception &e) { - STONEDB_LOG(ERROR, "Failed to delete directory(%s). error: %s", path.c_str(), e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "Failed to delete directory(%s). error: %s", path.c_str(), e.what()); } } diff --git a/storage/stonedb/system/io_parameters.h b/storage/stonedb/system/io_parameters.h index c0d511d05..fbc812188 100644 --- a/storage/stonedb/system/io_parameters.h +++ b/storage/stonedb/system/io_parameters.h @@ -28,7 +28,7 @@ namespace stonedb { namespace system { -enum Parameter { +enum class Parameter { PIPEMODE, STRING_QUALIFIER, CHARSET_INFO_NUMBER, @@ -53,19 +53,19 @@ class IOParameters { void SetLineTerminator(const std::string &lineTerminator_) { line_terminator = lineTerminator_; } void SetParameter(Parameter param, int value) { switch (param) { - case STRING_QUALIFIER: + case Parameter::STRING_QUALIFIER: string_qualifier = (char)value; break; - case CHARSET_INFO_NUMBER: + case Parameter::CHARSET_INFO_NUMBER: charset_info_number = value; break; - case LOCAL_LOAD: + case Parameter::LOCAL_LOAD: local_load = value; break; - case OPTIONALLY_ENCLOSED: + case Parameter::OPTIONALLY_ENCLOSED: opt_enclosed = value; break; - case LOCK_OPTION: + case Parameter::LOCK_OPTION: lock_option = value; break; default: @@ -76,13 +76,13 @@ class IOParameters { void SetParameter(Parameter param, const std::string &value) { switch (param) { - case LINE_STARTER: + case Parameter::LINE_STARTER: line_starter = value; break; - case LINE_TERMINATOR: + case Parameter::LINE_TERMINATOR: line_terminator = value; break; - case CHARSETS_INDEX_FILE: + case Parameter::CHARSETS_INDEX_FILE: charsets_dir = value; break; default: @@ -93,10 +93,10 @@ class IOParameters { void SetParameter(Parameter param, int64_t value) { switch (param) { - case SKIP_LINES: + case Parameter::SKIP_LINES: skip_lines = value; break; - case VALUE_LIST_ELEMENTS: + case Parameter::VALUE_LIST_ELEMENTS: value_list_elements = value; break; default: diff --git a/storage/stonedb/system/large_buffer.cpp b/storage/stonedb/system/large_buffer.cpp index 1ff236dfb..e29bef35a 100644 --- a/storage/stonedb/system/large_buffer.cpp +++ b/storage/stonedb/system/large_buffer.cpp @@ -69,12 +69,12 @@ bool LargeBuffer::BufOpen(const IOParameters &iop) { } void LargeBuffer::BufFlush() { - if (buf_used > size) STONEDB_LOG(ERROR, "LargeBuffer error: Buffer overrun (Flush)"); + if (buf_used > size) STONEDB_LOG(LogCtl_Level::ERROR, "LargeBuffer error: Buffer overrun (Flush)"); if (flush_thread.joinable()) { flush_thread.join(); } if (failed) { - STONEDB_LOG(ERROR, "Write operation to file or pipe failed."); + STONEDB_LOG(LogCtl_Level::ERROR, "Write operation to file or pipe failed."); throw common::FileException("Write operation to file or pipe failed."); } flush_thread = std::thread(std::bind(&LargeBuffer::BufFlushThread, this, ib_stream.get(), buf, buf_used, &failed)); @@ -108,7 +108,7 @@ void LargeBuffer::BufClose() // close the buffer; warning: does not flush data buf_used = 0; if (buf[size + 1] != D_OVERRUN_GUARDIAN) { - STONEDB_LOG(WARN, "buffer overrun detected in LargeBuffer::BufClose."); + STONEDB_LOG(LogCtl_Level::WARN, "buffer overrun detected in LargeBuffer::BufClose."); DEBUG_ASSERT(0); } } @@ -120,7 +120,7 @@ void LargeBuffer::FlushAndClose() { char *LargeBuffer::BufAppend(unsigned int len) { if ((int)len > size) { - STONEDB_LOG(ERROR, "Error: LargeBuffer buffer overrun (BufAppend)"); + STONEDB_LOG(LogCtl_Level::ERROR, "Error: LargeBuffer buffer overrun (BufAppend)"); return NULL; } int buf_pos = buf_used; diff --git a/storage/stonedb/system/large_buffer.h b/storage/stonedb/system/large_buffer.h index 3572a1cf2..1c11d5b02 100644 --- a/storage/stonedb/system/large_buffer.h +++ b/storage/stonedb/system/large_buffer.h @@ -48,7 +48,7 @@ class LargeBuffer final : public mm::TraceableObject { DEBUG_ASSERT(n >= 0 && n <= buf_used); return buf + n; } - mm::TO_TYPE TraceableType() const override { return mm::TO_TEMPORARY; } + mm::TO_TYPE TraceableType() const override { return mm::TO_TYPE::TO_TEMPORARY; } int WriteIfNonzero(uchar c) { if (c != 0) { char *ptr = BufAppend(1); diff --git a/storage/stonedb/system/net_stream.cpp b/storage/stonedb/system/net_stream.cpp index 8d58c9428..e26cc13f3 100644 --- a/storage/stonedb/system/net_stream.cpp +++ b/storage/stonedb/system/net_stream.cpp @@ -67,7 +67,8 @@ size_t NetStream::Read(void *buf, size_t count) { if (len == packet_error) { opened = false; std::chrono::duration diff = std::chrono::system_clock::now() - start; - STONEDB_LOG(INFO, "Failed to read from network: %s. Used %f seconds", std::strerror(errno), diff.count()); + STONEDB_LOG(LogCtl_Level::INFO, "Failed to read from network: %s. Used %f seconds", std::strerror(errno), + diff.count()); return copied; } if (len == 0) { diff --git a/storage/stonedb/types/bstring.cpp b/storage/stonedb/types/bstring.cpp index f4886c1f8..958867777 100644 --- a/storage/stonedb/types/bstring.cpp +++ b/storage/stonedb/types/bstring.cpp @@ -75,7 +75,7 @@ BString::~BString() { BString &BString::operator=(const RCDataType &rcdt) { if (this == &rcdt) return *this; - if (rcdt.GetValueType() == STRING_TYPE) + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) *this = (BString &)rcdt; else STONEDB_ERROR("bad cast"); @@ -384,7 +384,7 @@ bool BString::IsNullOrEmpty() const { return ((len == 0 || null) ? true : false) bool BString::operator==(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == STRING_TYPE) return CompareWith((BString &)rcdt) == 0; + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return CompareWith((BString &)rcdt) == 0; return CompareWith(rcdt.ToBString()) == 0; } @@ -395,31 +395,31 @@ bool BString::operator==(const BString &rcs) const { bool BString::operator<(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == STRING_TYPE) return CompareWith((BString &)rcdt) < 0; + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return CompareWith((BString &)rcdt) < 0; return CompareWith(rcdt.ToBString()) < 0; } bool BString::operator>(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == STRING_TYPE) return CompareWith((BString &)rcdt) > 0; + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return CompareWith((BString &)rcdt) > 0; return CompareWith(rcdt.ToBString()) > 0; } bool BString::operator>=(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == STRING_TYPE) return CompareWith((BString &)rcdt) >= 0; + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return CompareWith((BString &)rcdt) >= 0; return CompareWith(rcdt.ToBString()) >= 0; } bool BString::operator<=(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == STRING_TYPE) return CompareWith((BString &)rcdt) <= 0; + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return CompareWith((BString &)rcdt) <= 0; return CompareWith(rcdt.ToBString()) <= 0; } bool BString::operator!=(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return true; - if (rcdt.GetValueType() == STRING_TYPE) return CompareWith((BString &)rcdt) != 0; + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return CompareWith((BString &)rcdt) != 0; return CompareWith(rcdt.ToBString()) != 0; } @@ -456,7 +456,7 @@ size_t BString::RoundUpTo8Bytes(const DTCollation &dt) const { next_char_len = dt.collation->cset->mbcharlen(dt.collation, (uchar)val[useful_len + pos]); if (next_char_len == 0) { - STONEDB_LOG(WARN, "RoundUpTo8Bytes() detect non-UTF8 character"); + STONEDB_LOG(LogCtl_Level::WARN, "RoundUpTo8Bytes() detect non-UTF8 character"); next_char_len = 1; } diff --git a/storage/stonedb/types/rc_data_types.cpp b/storage/stonedb/types/rc_data_types.cpp index b99eacaf7..d597499cb 100644 --- a/storage/stonedb/types/rc_data_types.cpp +++ b/storage/stonedb/types/rc_data_types.cpp @@ -34,7 +34,7 @@ bool RCDataType::AreComperable(const RCDataType &rcdt1, const RCDataType &rcdt2) bool RCDataType::compare(const RCDataType &rcdt1, const RCDataType &rcdt2, common::Operator op, char like_esc) { // DEBUG_ASSERT(RCDataType::AreComperable(rcdt1, rcdt2)); - if (op == common::O_LIKE || op == common::O_NOT_LIKE) { + if (op == common::Operator::O_LIKE || op == common::Operator::O_NOT_LIKE) { if (rcdt1.IsNull() || rcdt2.IsNull()) return false; BString x, y; BString *rcbs1 = dynamic_cast(const_cast(&rcdt1)); @@ -48,16 +48,17 @@ bool RCDataType::compare(const RCDataType &rcdt1, const RCDataType &rcdt2, commo rcbs2 = &y; } bool res = rcbs1->Like(*rcbs2, like_esc); - if (op == common::O_LIKE) + if (op == common::Operator::O_LIKE) return res; else return !res; } else if (!rcdt1.IsNull() && !rcdt2.IsNull() && - (((op == common::O_EQ) && rcdt1 == rcdt2) || (op == common::O_NOT_EQ && rcdt1 != rcdt2) || - (op == common::O_LESS && rcdt1 < rcdt2) || - (op == common::O_LESS_EQ && (rcdt1 < rcdt2 || rcdt1 == rcdt2)) || - (op == common::O_MORE && (!(rcdt1 < rcdt2) && rcdt1 != rcdt2)) || - (op == common::O_MORE_EQ && (!(rcdt1 < rcdt2) || rcdt1 == rcdt2)))) + (((op == common::Operator::O_EQ) && rcdt1 == rcdt2) || + (op == common::Operator::O_NOT_EQ && rcdt1 != rcdt2) || + (op == common::Operator::O_LESS && rcdt1 < rcdt2) || + (op == common::Operator::O_LESS_EQ && (rcdt1 < rcdt2 || rcdt1 == rcdt2)) || + (op == common::Operator::O_MORE && (!(rcdt1 < rcdt2) && rcdt1 != rcdt2)) || + (op == common::Operator::O_MORE_EQ && (!(rcdt1 < rcdt2) || rcdt1 == rcdt2)))) return true; return false; } @@ -120,12 +121,12 @@ bool RCDataType::ToReal(const RCDataType &in, RCNum &out) { ValueTypeEnum RCDataType::GetValueType(common::CT attr_type) { if (core::ATI::IsNumericType(attr_type)) - return NUMERIC_TYPE; + return ValueTypeEnum::NUMERIC_TYPE; else if (core::ATI::IsDateTimeType(attr_type)) - return DATE_TIME_TYPE; + return ValueTypeEnum::DATE_TIME_TYPE; else if (core::ATI::IsStringType(attr_type)) - return STRING_TYPE; - return NULL_TYPE; + return ValueTypeEnum::STRING_TYPE; + return ValueTypeEnum::NULL_TYPE; } } // namespace types } // namespace stonedb diff --git a/storage/stonedb/types/rc_data_types.h b/storage/stonedb/types/rc_data_types.h index d66f38be7..e7b284290 100644 --- a/storage/stonedb/types/rc_data_types.h +++ b/storage/stonedb/types/rc_data_types.h @@ -119,7 +119,7 @@ union DT { } }; -enum ValueTypeEnum { NULL_TYPE, DATE_TIME_TYPE, NUMERIC_TYPE, STRING_TYPE }; +enum class ValueTypeEnum { NULL_TYPE, DATE_TIME_TYPE, NUMERIC_TYPE, STRING_TYPE }; class RCDataType { public: @@ -273,7 +273,7 @@ class BString : public ValueBasic { bool persistent; public: - const static ValueTypeEnum value_type = STRING_TYPE; + const static ValueTypeEnum value_type = ValueTypeEnum::STRING_TYPE; }; class RCDateTime : public ValueBasic { @@ -375,7 +375,7 @@ class RCDateTime : public ValueBasic { static RCDateTime GetCurrent(); public: - const static ValueTypeEnum value_type = DATE_TIME_TYPE; + const static ValueTypeEnum value_type = ValueTypeEnum::DATE_TIME_TYPE; }; class RCValueObject { @@ -406,7 +406,7 @@ class RCValueObject { bool IsNull() const; common::CT Type() const { return value.get() ? value->Type() : common::CT::UNK; } - ValueTypeEnum GetValueType() const { return value.get() ? value->GetValueType() : NULL_TYPE; } + ValueTypeEnum GetValueType() const { return value.get() ? value->GetValueType() : ValueTypeEnum::NULL_TYPE; } BString ToBString() const; // operator RCDataType*() { return value.get(); } RCDataType *Get() const { return value.get(); } @@ -470,17 +470,17 @@ static bool inline CollationStrCmp(DTCollation coll, const BString &s1, const BS int res = coll.collation->coll->strnncoll(coll.collation, (const uchar *)s1.val, s1.len, (const uchar *)s2.val, s2.len, 0); switch (op) { - case common::O_EQ: + case common::Operator::O_EQ: return (res == 0); - case common::O_NOT_EQ: + case common::Operator::O_NOT_EQ: return (res != 0); - case common::O_MORE: + case common::Operator::O_MORE: return (res > 0); - case common::O_MORE_EQ: + case common::Operator::O_MORE_EQ: return (res >= 0); - case common::O_LESS: + case common::Operator::O_LESS: return (res < 0); - case common::O_LESS_EQ: + case common::Operator::O_LESS_EQ: return (res <= 0); default: ASSERT(false, "OPERATOR NOT IMPLEMENTED"); diff --git a/storage/stonedb/types/rc_datetime.cpp b/storage/stonedb/types/rc_datetime.cpp index 12914dd49..e3ade0f17 100644 --- a/storage/stonedb/types/rc_datetime.cpp +++ b/storage/stonedb/types/rc_datetime.cpp @@ -120,7 +120,7 @@ RCDateTime &RCDateTime::operator=(const RCDateTime &rcv) { } RCDateTime &RCDateTime::operator=(const RCDataType &rcv) { - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) *this = (RCDateTime &)rcv; else { STONEDB_ERROR("bad cast"); @@ -310,7 +310,7 @@ common::ErrorCode RCDateTime::Parse(const int64_t &v, RCDateTime &rcv, common::C return common::ErrorCode::SUCCESS; if (sign == 1 && at == common::CT::TIMESTAMP && IsCorrectSDBTimestamp(short(rcv.dt.year), short(rcv.dt.month), short(rcv.dt.day), short(rcv.dt.hour), - short(rcv.dt.minute), short(rcv.dt.second))) + short(rcv.dt.minute), short(rcv.dt.second))) return common::ErrorCode::SUCCESS; } else STONEDB_ERROR("type not supported"); @@ -505,9 +505,9 @@ RCDateTime RCDateTime::GetCurrent() { bool RCDateTime::operator==(const RCDataType &rcv) const { if (!AreComparable(at, rcv.Type()) || IsNull() || rcv.IsNull()) return false; - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return compare((RCDateTime &)rcv) == 0; - else if (rcv.GetValueType() == NUMERIC_TYPE) { + else if (rcv.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) { return compare((RCNum &)rcv) == 0; } return false; @@ -515,45 +515,45 @@ bool RCDateTime::operator==(const RCDataType &rcv) const { bool RCDateTime::operator<(const RCDataType &rcv) const { if (!AreComparable(at, rcv.Type()) || IsNull() || rcv.IsNull()) return false; - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return compare((RCDateTime &)rcv) < 0; - else if (rcv.GetValueType() == NUMERIC_TYPE) + else if (rcv.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return compare((RCNum &)rcv) < 0; return false; } bool RCDateTime::operator>(const RCDataType &rcv) const { if (!AreComparable(at, rcv.Type()) || IsNull() || rcv.IsNull()) return false; - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return compare((RCDateTime &)rcv) > 0; - else if (rcv.GetValueType() == NUMERIC_TYPE) + else if (rcv.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return compare((RCNum &)rcv) > 0; return false; } bool RCDateTime::operator>=(const RCDataType &rcv) const { if (!AreComparable(at, rcv.Type()) || IsNull() || rcv.IsNull()) return false; - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return compare((RCDateTime &)rcv) >= 0; - else if (rcv.GetValueType() == NUMERIC_TYPE) + else if (rcv.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return compare((RCNum &)rcv) >= 0; return false; } bool RCDateTime::operator<=(const RCDataType &rcv) const { if (!AreComparable(at, rcv.Type()) || IsNull() || rcv.IsNull()) return false; - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return compare((RCDateTime &)rcv) <= 0; - else if (rcv.GetValueType() == NUMERIC_TYPE) + else if (rcv.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return compare((RCNum &)rcv) <= 0; return false; } bool RCDateTime::operator!=(const RCDataType &rcv) const { if (!AreComparable(at, rcv.Type()) || IsNull() || rcv.IsNull()) return false; - if (rcv.GetValueType() == DATE_TIME_TYPE) + if (rcv.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return compare((RCDateTime &)rcv) != 0; - else if (rcv.GetValueType() == NUMERIC_TYPE) + else if (rcv.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return compare((RCNum &)rcv) != 0; return false; } diff --git a/storage/stonedb/types/rc_num.cpp b/storage/stonedb/types/rc_num.cpp index b2f588c42..90117bddf 100644 --- a/storage/stonedb/types/rc_num.cpp +++ b/storage/stonedb/types/rc_num.cpp @@ -100,7 +100,7 @@ RCNum &RCNum::operator=(const RCNum &rcn) { } RCNum &RCNum::operator=(const RCDataType &rcdt) { - if (rcdt.GetValueType() == NUMERIC_TYPE) + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) *this = (RCNum &)rcdt; else { RCNum rcn1; @@ -251,54 +251,54 @@ RCNum::operator double() const { bool RCNum::operator==(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == NUMERIC_TYPE) return (compare((RCNum &)rcdt) == 0); - if (rcdt.GetValueType() == DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) == 0); - if (rcdt.GetValueType() == STRING_TYPE) return (rcdt == this->ToBString()); + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return (compare((RCNum &)rcdt) == 0); + if (rcdt.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) == 0); + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return (rcdt == this->ToBString()); STONEDB_ERROR("Bad cast inside RCNum"); return false; } bool RCNum::operator!=(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == NUMERIC_TYPE) return (compare((RCNum &)rcdt) != 0); - if (rcdt.GetValueType() == DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) != 0); - if (rcdt.GetValueType() == STRING_TYPE) return (rcdt != this->ToBString()); + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return (compare((RCNum &)rcdt) != 0); + if (rcdt.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) != 0); + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return (rcdt != this->ToBString()); STONEDB_ERROR("Bad cast inside RCNum"); return false; } bool RCNum::operator<(const RCDataType &rcdt) const { if (IsNull() || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == NUMERIC_TYPE) return (compare((RCNum &)rcdt) < 0); - if (rcdt.GetValueType() == DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) < 0); - if (rcdt.GetValueType() == STRING_TYPE) return (this->ToBString() < rcdt); + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return (compare((RCNum &)rcdt) < 0); + if (rcdt.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) < 0); + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return (this->ToBString() < rcdt); STONEDB_ERROR("Bad cast inside RCNum"); return false; } bool RCNum::operator>(const RCDataType &rcdt) const { if (IsNull() || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == NUMERIC_TYPE) return (compare((RCNum &)rcdt) > 0); - if (rcdt.GetValueType() == DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) > 0); - if (rcdt.GetValueType() == STRING_TYPE) return (this->ToBString() > rcdt); + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return (compare((RCNum &)rcdt) > 0); + if (rcdt.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) > 0); + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return (this->ToBString() > rcdt); STONEDB_ERROR("Bad cast inside RCNum"); return false; } bool RCNum::operator<=(const RCDataType &rcdt) const { if (IsNull() || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == NUMERIC_TYPE) return (compare((RCNum &)rcdt) <= 0); - if (rcdt.GetValueType() == DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) <= 0); - if (rcdt.GetValueType() == STRING_TYPE) return (this->ToBString() <= rcdt); + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return (compare((RCNum &)rcdt) <= 0); + if (rcdt.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) <= 0); + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return (this->ToBString() <= rcdt); STONEDB_ERROR("Bad cast inside RCNum"); return false; } bool RCNum::operator>=(const RCDataType &rcdt) const { if (null || rcdt.IsNull()) return false; - if (rcdt.GetValueType() == NUMERIC_TYPE) return (compare((RCNum &)rcdt) >= 0); - if (rcdt.GetValueType() == DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) >= 0); - if (rcdt.GetValueType() == STRING_TYPE) return (this->ToBString() >= rcdt); + if (rcdt.GetValueType() == ValueTypeEnum::NUMERIC_TYPE) return (compare((RCNum &)rcdt) >= 0); + if (rcdt.GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return (compare((RCDateTime &)rcdt) >= 0); + if (rcdt.GetValueType() == ValueTypeEnum::STRING_TYPE) return (this->ToBString() >= rcdt); STONEDB_ERROR("Bad cast inside RCNum"); return false; } diff --git a/storage/stonedb/types/rc_num.h b/storage/stonedb/types/rc_num.h index daeee785e..6b4375122 100644 --- a/storage/stonedb/types/rc_num.h +++ b/storage/stonedb/types/rc_num.h @@ -103,7 +103,7 @@ class RCNum : public ValueBasic { common::CT attrt; public: - const static ValueTypeEnum value_type = NUMERIC_TYPE; + const static ValueTypeEnum value_type = ValueTypeEnum::NUMERIC_TYPE; }; } // namespace types } // namespace stonedb diff --git a/storage/stonedb/types/rc_value_object.cpp b/storage/stonedb/types/rc_value_object.cpp index a9ca35570..7f7b8bbfa 100644 --- a/storage/stonedb/types/rc_value_object.cpp +++ b/storage/stonedb/types/rc_value_object.cpp @@ -117,14 +117,15 @@ RCDataType &RCValueObject::operator*() const { return value.get() ? *value.get() RCValueObject::operator RCNum &() const { if (IsNull()) return RCNum::NullValue(); - if (GetValueType() == NUMERIC_TYPE || GetValueType() == DATE_TIME_TYPE) return static_cast(*value); + if (GetValueType() == ValueTypeEnum::NUMERIC_TYPE || GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) + return static_cast(*value); STONEDB_ERROR("Bad cast in RCValueObject::RCNum&()"); return static_cast(*value); } RCValueObject::operator RCDateTime &() const { if (IsNull()) return RCDateTime::NullValue(); - if (GetValueType() == DATE_TIME_TYPE) return static_cast(*value); + if (GetValueType() == ValueTypeEnum::DATE_TIME_TYPE) return static_cast(*value); STONEDB_ERROR("Bad cast in RCValueObject::RCDateTime&()"); return static_cast(*value); } diff --git a/storage/stonedb/types/value_parser4txt.cpp b/storage/stonedb/types/value_parser4txt.cpp index 6c86e9ccf..80936a909 100644 --- a/storage/stonedb/types/value_parser4txt.cpp +++ b/storage/stonedb/types/value_parser4txt.cpp @@ -671,12 +671,12 @@ common::ErrorCode ValueParserForText::ParseDateTimeOrTimestamp(const BString &rc if (!EatWhiteSigns(buf, buflen) && !system::EatDTSeparators(buf, buflen)) { if ((at == common::CT::DATETIME && RCDateTime::IsCorrectSDBDatetime((short)year, month, day, RCDateTime::GetSpecialValue(at).Hour(), - RCDateTime::GetSpecialValue(at).Minute(), - RCDateTime::GetSpecialValue(at).Second())) || + RCDateTime::GetSpecialValue(at).Minute(), + RCDateTime::GetSpecialValue(at).Second())) || (at == common::CT::TIMESTAMP && RCDateTime::IsCorrectSDBTimestamp((short)year, month, day, RCDateTime::GetSpecialValue(at).Hour(), - RCDateTime::GetSpecialValue(at).Minute(), - RCDateTime::GetSpecialValue(at).Second()))) + RCDateTime::GetSpecialValue(at).Minute(), + RCDateTime::GetSpecialValue(at).Second()))) rcv = RCDateTime((short)year, month, day, RCDateTime::GetSpecialValue(at).Hour(), RCDateTime::GetSpecialValue(at).Minute(), RCDateTime::GetSpecialValue(at).Second(), at); return common::ErrorCode::OUT_OF_RANGE; @@ -738,7 +738,7 @@ common::ErrorCode ValueParserForText::ParseDateTimeOrTimestamp(const BString &rc try { if (at == common::CT::DATETIME) { if (RCDateTime::IsCorrectSDBDatetime((short)year, (short)month, (short)day, (short)hour, (short)minute, - (short)second)) { + (short)second)) { rcv = RCDateTime((short)year, (short)month, (short)day, (short)hour, (short)minute, (short)second, at); return sdbrc; } else { @@ -749,7 +749,7 @@ common::ErrorCode ValueParserForText::ParseDateTimeOrTimestamp(const BString &rc } } else if (at == common::CT::TIMESTAMP) { if (RCDateTime::IsCorrectSDBTimestamp((short)year, (short)month, (short)day, (short)hour, (short)minute, - (short)second)) { + (short)second)) { // convert to UTC MYSQL_TIME myt; std::memset(&myt, 0, sizeof(MYSQL_TIME)); diff --git a/storage/stonedb/types/value_parser4txt.h b/storage/stonedb/types/value_parser4txt.h index 9d44b1c96..64804c5ce 100644 --- a/storage/stonedb/types/value_parser4txt.h +++ b/storage/stonedb/types/value_parser4txt.h @@ -53,7 +53,7 @@ class ValueParserForText { return std::bind(&ParseDateTimeAdapter, std::placeholders::_1, std::placeholders::_2, at.Type()); default: - STONEDB_ERROR("type not supported:" + std::to_string(at.Type())); + STONEDB_ERROR("type not supported:" + std::to_string(static_cast(at.Type()))); break; } return NULL; diff --git a/storage/stonedb/util/log_ctl.cpp b/storage/stonedb/util/log_ctl.cpp index 2f13483f0..a30c3f441 100644 --- a/storage/stonedb/util/log_ctl.cpp +++ b/storage/stonedb/util/log_ctl.cpp @@ -26,9 +26,9 @@ namespace stonedb { namespace logger { // NOTICE: the order must be align with enum LogCtl_Level -static const char *level_str[] = {"", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"}; +static const char *level_str[] = {"", "LogCtl_Level::FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"}; -static const char *get_level_str(LogCtl_Level level) { return level_str[level]; } +static const char *get_level_str(LogCtl_Level level) { return level_str[static_cast(level)]; } } // namespace logger static system::Channel stonedblog(true); @@ -39,7 +39,7 @@ namespace utils { logger::LogCtl_Level LogCtl::GetSessionLevel() { if (current_tx == nullptr) { stonedblog << system::lock << "ERROR" << __PRETTY_FUNCTION__ << " current_tx invalid" << system::unlock; - return logger::DISABLED; + return logger::LogCtl_Level::DISABLED; } return static_cast(current_tx->DebugLevel()); } @@ -58,7 +58,7 @@ bool LogCtl::LogEnabled(logger::LogCtl_Level level) { } return ((current_tx->DebugLevel() >= level ) || (stonedb_sysvar_global_debug_level >= level)); #else - return stonedb_sysvar_global_debug_level >= level; + return stonedb_sysvar_global_debug_level >= static_cast(level); #endif } @@ -107,16 +107,16 @@ void stonedb_log(enum loglevel mysql_level, const char *buffer, [[maybe_unused]] // mapping mysql log level to stonedb log level switch (mysql_level) { case ERROR_LEVEL: - level = logger::ERROR; + level = logger::LogCtl_Level::ERROR; break; case WARNING_LEVEL: - level = logger::WARN; + level = logger::LogCtl_Level::WARN; break; case INFORMATION_LEVEL: - level = logger::WARN; + level = logger::LogCtl_Level::WARN; break; default: - level = logger::ERROR; + level = logger::LogCtl_Level::ERROR; break; } utils::LogCtl::LogMsg(level, "MYSQL", 0, buffer); diff --git a/storage/stonedb/util/log_ctl.h b/storage/stonedb/util/log_ctl.h index afb00d494..ec508e337 100644 --- a/storage/stonedb/util/log_ctl.h +++ b/storage/stonedb/util/log_ctl.h @@ -23,7 +23,7 @@ namespace stonedb { namespace logger { -enum LogCtl_Level { DISABLED = 0, FATAL = 1, ERROR = 2, WARN = 3, INFO = 4, DEBUG = 5, TRACE = 6 }; +enum class LogCtl_Level { DISABLED = 0, FATAL = 1, ERROR = 2, WARN = 3, INFO = 4, DEBUG = 5, TRACE = 6 }; } // namespace logger namespace utils { // a class help to check debug switch and print debug msg diff --git a/storage/stonedb/util/mapped_circular_buffer.h b/storage/stonedb/util/mapped_circular_buffer.h index e0aef5152..e16754d6b 100644 --- a/storage/stonedb/util/mapped_circular_buffer.h +++ b/storage/stonedb/util/mapped_circular_buffer.h @@ -63,19 +63,19 @@ class MappedCircularBuffer { throw std::invalid_argument("failed to truncate " + file + ". error " + std::to_string(errno) + ": " + std::strerror(errno)); } - STONEDB_LOG(INFO, "created delayed buffer file %s with size %ldMB", file.c_str(), buf_size / 1_MB); + STONEDB_LOG(LogCtl_Level::INFO, "created delayed buffer file %s with size %ldMB", file.c_str(), buf_size / 1_MB); } else { // file already exists if (sb.st_size == static_cast(FileSize())) { file_exists = true; - STONEDB_LOG(INFO, "use delayed buffer file %s with size %ldMB", file.c_str(), buf_size / 1_MB); + STONEDB_LOG(LogCtl_Level::INFO, "use delayed buffer file %s with size %ldMB", file.c_str(), buf_size / 1_MB); } else { // for now just drop the old file. TODO: handle resize if (::ftruncate(fd, 0) == -1 || ::ftruncate(fd, FileSize()) == -1) { throw std::invalid_argument("failed to truncate " + file + ". error " + std::to_string(errno) + ": " + std::strerror(errno)); } - STONEDB_LOG(WARN, "old buffer file (size %ldM) purged!!! ", sb.st_size / 1_MB); + STONEDB_LOG(LogCtl_Level::WARN, "old buffer file (size %ldM) purged!!! ", sb.st_size / 1_MB); } } MapFile(file); @@ -199,7 +199,7 @@ class MappedCircularBuffer { throw std::runtime_error("failed to mmap file " + file + ". error " + std::to_string(errno) + ": " + std::strerror(errno)); } - STONEDB_LOG(INFO, "insert buffer address %p", start_addr); + STONEDB_LOG(LogCtl_Level::INFO, "insert buffer address %p", start_addr); } void GetStat() { if (hdr->read_offset == hdr->write_offset) { diff --git a/storage/stonedb/util/qsort.h b/storage/stonedb/util/qsort.h index 836b87301..ea880ac2c 100644 --- a/storage/stonedb/util/qsort.h +++ b/storage/stonedb/util/qsort.h @@ -18,7 +18,7 @@ #define STONEDB_UTIL_QSORT_H_ #pragma once -using comp_func_ib = int (*) (const void *, const void *); +using comp_func_ib = int (*)(const void *, const void *); inline void __ib_swap_local(char *a, char *b, int len) { for (int j = 0; j < len; j++) { diff --git a/storage/stonedb/util/thread_pool.h b/storage/stonedb/util/thread_pool.h index 2159eb450..cc368771f 100644 --- a/storage/stonedb/util/thread_pool.h +++ b/storage/stonedb/util/thread_pool.h @@ -123,10 +123,10 @@ class result_set final { result.get(); } catch (std::exception &e) { no_except = false; - STONEDB_LOG(ERROR, "An exception is caught: %s", e.what()); + STONEDB_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); } catch (...) { no_except = false; - STONEDB_LOG(ERROR, "An unknown system exception error caught."); + STONEDB_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } if (!no_except) { throw common::Exception("Parallel worker run failed."); diff --git a/storage/stonedb/util/timer.cpp b/storage/stonedb/util/timer.cpp index 8e64c4ba2..f56a731bb 100644 --- a/storage/stonedb/util/timer.cpp +++ b/storage/stonedb/util/timer.cpp @@ -24,7 +24,7 @@ namespace utils { void Timer::DoPrint(const std::string &msg) const { using namespace std::chrono; auto diff = duration_cast>(high_resolution_clock::now() - start); - STONEDB_LOG(INFO, "Timer %f seconds: %s", diff.count(), msg.c_str()); + STONEDB_LOG(LogCtl_Level::INFO, "Timer %f seconds: %s", diff.count(), msg.c_str()); } } // namespace utils } // namespace stonedb diff --git a/storage/stonedb/util/timer.h b/storage/stonedb/util/timer.h index 69725a510..1ba16d431 100644 --- a/storage/stonedb/util/timer.h +++ b/storage/stonedb/util/timer.h @@ -30,7 +30,7 @@ class Timer { Timer() = default; void Print(const std::string &msg) const { - if (STONEDB_LOGCHECK(DEBUG)) DoPrint(msg); + if (STONEDB_LOGCHECK(LogCtl_Level::DEBUG)) DoPrint(msg); } private: diff --git a/storage/stonedb/vc/const_column.cpp b/storage/stonedb/vc/const_column.cpp index afbef8a24..46209a27c 100644 --- a/storage/stonedb/vc/const_column.cpp +++ b/storage/stonedb/vc/const_column.cpp @@ -60,21 +60,21 @@ ConstColumn::ConstColumn(const types::RCValueObject &v, const core::ColumnType & value = core::ValueOrNull(v.ToBString()); ct.SetPrecision(value.StrLen()); } else if (c.IsNumeric() && !c.IsDateTime()) { - if (v.GetValueType() == types::NUMERIC_TYPE) + if (v.GetValueType() == types::ValueTypeEnum::NUMERIC_TYPE) value = core::ValueOrNull(static_cast(v)); - else if (v.GetValueType() == types::STRING_TYPE) { + else if (v.GetValueType() == types::ValueTypeEnum::STRING_TYPE) { types::RCNum rcn; if (c.IsFloat()) types::RCNum::ParseReal(v.ToBString(), rcn, c.GetTypeName()); else types::RCNum::ParseNum(v.ToBString(), rcn); value = rcn; - } else if (v.GetValueType() == types::NULL_TYPE) + } else if (v.GetValueType() == types::ValueTypeEnum::NULL_TYPE) value = core::ValueOrNull(); else throw common::DataTypeConversionException(common::ErrorCode::DATACONVERSION); } else { - DEBUG_ASSERT(v.GetValueType() == types::DATE_TIME_TYPE); + DEBUG_ASSERT(v.GetValueType() == types::ValueTypeEnum::DATE_TIME_TYPE); // TODO: if it is non-date-time a proper conversion should be done here value = core::ValueOrNull(static_cast(v)); } diff --git a/storage/stonedb/vc/const_expr_column.cpp b/storage/stonedb/vc/const_expr_column.cpp index cfc67941b..a06003919 100644 --- a/storage/stonedb/vc/const_expr_column.cpp +++ b/storage/stonedb/vc/const_expr_column.cpp @@ -131,7 +131,7 @@ void ConstExpressionColumn::DoEvaluatePack([[maybe_unused]] core::MIUpdatingIter common::RSValue ConstExpressionColumn::DoRoughCheck([[maybe_unused]] const core::MIIterator &mit, [[maybe_unused]] core::Descriptor &d) { - return common::RS_SOME; // not implemented + return common::RSValue::RS_SOME; // not implemented } types::BString ConstExpressionColumn::DecodeValue_S([[maybe_unused]] int64_t code) { diff --git a/storage/stonedb/vc/expr_column.cpp b/storage/stonedb/vc/expr_column.cpp index e2fb71aa2..01a2ba13b 100644 --- a/storage/stonedb/vc/expr_column.cpp +++ b/storage/stonedb/vc/expr_column.cpp @@ -93,7 +93,7 @@ void ExpressionColumn::SetParamTypes(core::MysqlExpression::TypOfVars *types) { bool ExpressionColumn::FeedArguments(const core::MIIterator &mit) { bool diff = first_eval; - if (mit.Type() == core::MIIterator::MII_LOOKUP) { + if (mit.Type() == core::MIIterator::MIIteratorType::MII_LOOKUP) { core::MILookupIterator *mit_lookup = (core::MILookupIterator *)(&mit); FeedLookupArguments(*mit_lookup); first_eval = false; diff --git a/storage/stonedb/vc/in_set_column.cpp b/storage/stonedb/vc/in_set_column.cpp index b52a078aa..acd606b90 100644 --- a/storage/stonedb/vc/in_set_column.cpp +++ b/storage/stonedb/vc/in_set_column.cpp @@ -288,7 +288,7 @@ bool InSetColumn::DoCopyCond(const core::MIIterator &mit, types::CondArray &cond types::BString s; it->GetValueString(s, mit); if (s.IsNull()) { - STONEDB_LOG(WARN, "DoCopyCond condition is NULL"); + STONEDB_LOG(LogCtl_Level::WARN, "DoCopyCond condition is NULL"); condition.clear(); success = false; break; diff --git a/storage/stonedb/vc/single_column.cpp b/storage/stonedb/vc/single_column.cpp index edeb25dc8..f3130672d 100644 --- a/storage/stonedb/vc/single_column.cpp +++ b/storage/stonedb/vc/single_column.cpp @@ -171,13 +171,13 @@ common::RSValue SingleColumn::DoRoughCheck(const core::MIIterator &mit, core::De if (mit.GetCurPackrow(dim) >= 0) { // check whether isn't it a join SingleColumn *sc = NULL; - if (d.val1.vc && d.val1.vc->IsSingleColumn()) sc = static_cast(d.val1.vc); + if (d.val1.vc && static_cast(d.val1.vc->IsSingleColumn())) sc = static_cast(d.val1.vc); if (sc && sc->dim != dim) // Pack2Pack rough check return col->RoughCheck(mit.GetCurPackrow(dim), mit.GetCurPackrow(sc->dim), d); else // One-dim rough check return col->RoughCheck(mit.GetCurPackrow(dim), d, mit.NullsPossibleInPack(dim)); } else - return common::RS_SOME; + return common::RSValue::RS_SOME; } void SingleColumn::DisplayAttrStats() { col->DisplayAttrStats(mind->GetFilter(dim)); } diff --git a/storage/stonedb/vc/single_column.h b/storage/stonedb/vc/single_column.h index 36e7e93b1..e478b432b 100644 --- a/storage/stonedb/vc/single_column.h +++ b/storage/stonedb/vc/single_column.h @@ -51,7 +51,7 @@ class SingleColumn : public VirtualColumn { core::PhysicalColumn *GetPhysical() const { return col; } bool IsConst() const override { return false; } single_col_t IsSingleColumn() const override { - return col->ColType() == core::PhysicalColumn::ATTR ? SC_ATTR : SC_RCATTR; + return col->ColType() == core::PhysicalColumn::phys_col_t::ATTR ? single_col_t::SC_ATTR : single_col_t::SC_RCATTR; } char *ToString(char p_buf[], size_t buf_ct) const override; virtual void TranslateSourceColumns(std::map &); @@ -60,13 +60,13 @@ class SingleColumn : public VirtualColumn { } int64_t GetNotNullValueInt64(const core::MIIterator &mit) override { return col->GetNotNullValueInt64(mit[dim]); } bool IsDistinctInTable() override { return col->IsDistinct(mind->GetFilter(dim)); } - bool IsTempTableColumn() const { return col->ColType() == core::PhysicalColumn::ATTR; } + bool IsTempTableColumn() const { return col->ColType() == core::PhysicalColumn::phys_col_t::ATTR; } void GetTextStat(types::TextStat &s) override { col->GetTextStat(s, mind->GetFilter(dim)); } bool CanCopy() const override { - return (col->ColType() != core::PhysicalColumn::ATTR); + return (col->ColType() != core::PhysicalColumn::phys_col_t::ATTR); } // cannot copy core::TempTable, as it may be paged bool IsThreadSafe() override { - return (col->ColType() != core::PhysicalColumn::ATTR); + return (col->ColType() != core::PhysicalColumn::phys_col_t::ATTR); } // TODO: for ATTR check if not materialized and not buffered protected: diff --git a/storage/stonedb/vc/subselect_column.cpp b/storage/stonedb/vc/subselect_column.cpp index 7281b12c9..e152a70c6 100644 --- a/storage/stonedb/vc/subselect_column.cpp +++ b/storage/stonedb/vc/subselect_column.cpp @@ -378,7 +378,7 @@ void SubSelectColumn::PrepareSubqResult(const core::MIIterator &mit, bool exists } subq->SuspendDisplay(); try { - if (exists_only) subq->SetMode(core::TM_EXISTS); + if (exists_only) subq->SetMode(core::TMParameter::TM_EXISTS); subq->Materialize(cor); } catch (...) { subq->ResumeDisplay(); diff --git a/storage/stonedb/vc/subselect_column.h b/storage/stonedb/vc/subselect_column.h index 6199103d5..132a29234 100644 --- a/storage/stonedb/vc/subselect_column.h +++ b/storage/stonedb/vc/subselect_column.h @@ -63,7 +63,8 @@ class SubSelectColumn : public MultiValColumn { } types::BString DoGetString() const override { return record[0].ToBString(); } types::RCNum DoGetRCNum() const override { - if (record[0].GetValueType() == types::NUMERIC_TYPE || record[0].GetValueType() == types::DATE_TIME_TYPE) + if (record[0].GetValueType() == types::ValueTypeEnum::NUMERIC_TYPE || + record[0].GetValueType() == types::ValueTypeEnum::DATE_TIME_TYPE) return static_cast(record[0]); STONEDB_ERROR("Bad cast in RCValueObject::RCNum&()"); return static_cast(record[0]); diff --git a/storage/stonedb/vc/type_cast_column.cpp b/storage/stonedb/vc/type_cast_column.cpp index c3629c7b8..40ccf143f 100644 --- a/storage/stonedb/vc/type_cast_column.cpp +++ b/storage/stonedb/vc/type_cast_column.cpp @@ -96,7 +96,7 @@ int64_t String2NumCastColumn::DoGetValueInt64(const core::MIIterator &mit) { std::string s = "Truncated incorrect numeric value: \'"; s += rs.ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); } if (rc == common::ErrorCode::OUT_OF_RANGE && rcn.GetValueInt64() > 0) return -1; } else if (ct.IsFixed()) { @@ -105,14 +105,14 @@ int64_t String2NumCastColumn::DoGetValueInt64(const core::MIIterator &mit) { std::string s = "Truncated incorrect numeric value: \'"; s += rs.ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); } } else { if (types::RCNum::Parse(rs, rcn) != common::ErrorCode::SUCCESS) { std::string s = "Truncated incorrect numeric value: \'"; s += rs.ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); } } return rcn.GetValueInt64(); @@ -248,7 +248,7 @@ int64_t String2DateTimeCastColumn::DoGetValueInt64(const core::MIIterator &mit) std::string s = "Incorrect datetime value: \'"; s += rbs.ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); return common::NULL_VALUE_64; } /* else if(common::IsWarning(res)) { std::string s = "Incorrect Date/Time value: "; @@ -276,7 +276,7 @@ void String2DateTimeCastColumn::DoGetValueString(types::BString &rbs, const core std::string s = "Incorrect datetime value: \'"; s += rbs.ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); rbs = types::BString(); return; } /* else if(common::IsWarning(res)) { @@ -306,7 +306,7 @@ types::RCValueObject String2DateTimeCastColumn::DoGetValue(const core::MIIterato std::string s = "Incorrect datetime value: \'"; s += rbs.ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); // return types::RCDateTime(); } return rcdt; @@ -358,7 +358,7 @@ Num2DateTimeCastColumn::Num2DateTimeCastColumn(VirtualColumn *from, core::Column std::string s = "Incorrect datetime value: \'"; s += rcv.ToBString().ToString(); s += "\'"; - STONEDB_LOG(WARN, "Num2DateTimeCast %s", s.c_str()); + STONEDB_LOG(LogCtl_Level::WARN, "Num2DateTimeCast %s", s.c_str()); } if (TypeName() == common::CT::TIMESTAMP) { // needs to convert value to UTC @@ -401,7 +401,7 @@ types::RCValueObject Num2DateTimeCastColumn::DoGetValue(const core::MIIterator & std::string s = "Incorrect datetime value: \'"; s += r.ToBString().ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); return types::RCDateTime(); } return rcdt; @@ -423,7 +423,7 @@ int64_t Num2DateTimeCastColumn::DoGetValueInt64(const core::MIIterator &mit) { std::string s = "Incorrect datetime value: \'"; s += r.ToBString().ToString(); s += "\'"; - common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); + common::PushWarning(ConnInfo()->Thd(), Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, s.c_str()); return common::NULL_VALUE_64; } return rcdt.GetInt64(); diff --git a/storage/stonedb/vc/virtual_column_base.cpp b/storage/stonedb/vc/virtual_column_base.cpp index 6c8071070..2e829265b 100644 --- a/storage/stonedb/vc/virtual_column_base.cpp +++ b/storage/stonedb/vc/virtual_column_base.cpp @@ -211,40 +211,41 @@ int64_t VirtualColumnBase::DecodeValueAsDouble(int64_t code) { common::RSValue VirtualColumnBase::DoRoughCheck(const core::MIIterator &mit, core::Descriptor &d) { // default implementation - if (d.op == common::O_FALSE) return common::RS_NONE; - if (d.op == common::O_TRUE) return common::RS_ALL; + if (d.op == common::Operator::O_FALSE) return common::RSValue::RS_NONE; + if (d.op == common::Operator::O_TRUE) return common::RSValue::RS_ALL; bool nulls_possible = NullsPossible(); - if (d.op == common::O_IS_NULL || d.op == common::O_NOT_NULL) { + if (d.op == common::Operator::O_IS_NULL || d.op == common::Operator::O_NOT_NULL) { if (GetNoNulls(mit) == mit.GetPackSizeLeft()) { // nulls only - if (d.op == common::O_IS_NULL) - return common::RS_ALL; + if (d.op == common::Operator::O_IS_NULL) + return common::RSValue::RS_ALL; else - return common::RS_NONE; + return common::RSValue::RS_NONE; } if (!nulls_possible) { - if (d.op == common::O_IS_NULL) - return common::RS_NONE; + if (d.op == common::Operator::O_IS_NULL) + return common::RSValue::RS_NONE; else - return common::RS_ALL; + return common::RSValue::RS_ALL; } - return common::RS_SOME; + return common::RSValue::RS_SOME; } - common::RSValue res = common::RS_SOME; - if (d.val1.vc == NULL || ((d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN) && d.val2.vc == NULL)) - return common::RS_SOME; // irregular descriptor - cannot use VirtualColumn - // rough statistics - // In all other situations: common::RS_NONE for nulls only + common::RSValue res = common::RSValue::RS_SOME; + if (d.val1.vc == NULL || + ((d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN) && d.val2.vc == NULL)) + return common::RSValue::RS_SOME; // irregular descriptor - cannot use VirtualColumn + // rough statistics + // In all other situations: common::RSValue::RS_NONE for nulls only if (GetNoNulls(mit) == mit.GetPackSizeLeft() || (!d.val1.vc->IsMultival() && (d.val1.vc->GetNoNulls(mit) == mit.GetPackSizeLeft() || (d.val2.vc && !d.val2.vc->IsMultival() && d.val2.vc->GetNoNulls(mit) == mit.GetPackSizeLeft())))) - return common::RS_NONE; - if (d.op == common::O_LIKE || d.op == common::O_NOT_LIKE || d.val1.vc->IsMultival() || + return common::RSValue::RS_NONE; + if (d.op == common::Operator::O_LIKE || d.op == common::Operator::O_NOT_LIKE || d.val1.vc->IsMultival() || (d.val2.vc && d.val2.vc->IsMultival())) - return common::RS_SOME; + return common::RSValue::RS_SOME; if (Type().IsString()) { - if (types::RequiresUTFConversions(d.GetCollation())) return common::RS_SOME; + if (types::RequiresUTFConversions(d.GetCollation())) return common::RSValue::RS_SOME; types::BString vamin = GetMinString(mit); types::BString vamax = GetMaxString(mit); types::BString v1min = d.val1.vc->GetMinString(mit); @@ -253,32 +254,36 @@ common::RSValue VirtualColumnBase::DoRoughCheck(const core::MIIterator &mit, cor types::BString v2max = (d.val2.vc ? d.val2.vc->GetMaxString(mit) : types::BString()); if (vamin.IsNull() || vamax.IsNull() || v1min.IsNull() || v1max.IsNull() || (d.val2.vc && (v2min.IsNull() || v2max.IsNull()))) - return common::RS_SOME; + return common::RSValue::RS_SOME; // Note: rough string values are not suitable to ensuring equality. Only // inequalities are processed. - if (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN) { // the second case will be negated soon + if (d.op == common::Operator::O_BETWEEN || + d.op == common::Operator::O_NOT_BETWEEN) { // the second case will be negated soon if (vamin > v1max && vamax < v2min) - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else if (vamin > v2max || vamax < v1min) - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else { - if (vamin > v1max) { // NOTE: only common::O_MORE, common::O_LESS and - // common::O_EQ are analyzed here, the rest of operators + if (vamin > v1max) { // NOTE: only common::Operator::O_MORE, common::Operator::O_LESS and + // common::Operator::O_EQ are analyzed here, the rest of operators // will be taken into account later (treated as negations) - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ || d.op == common::O_LESS || d.op == common::O_MORE_EQ) - res = common::RS_NONE; - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ || d.op == common::Operator::O_LESS || + d.op == common::Operator::O_MORE_EQ) + res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_MORE || d.op == common::Operator::O_LESS_EQ) res = common::RSValue::RS_ALL; } if (vamax < v1min) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ || d.op == common::O_MORE || d.op == common::O_LESS_EQ) - res = common::RS_NONE; - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ || d.op == common::Operator::O_MORE || + d.op == common::Operator::O_LESS_EQ) + res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_LESS || d.op == common::Operator::O_MORE_EQ) res = common::RSValue::RS_ALL; } } } else { if (!Type().IsNumComparable(d.val1.vc->Type()) || - ((d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN) && !Type().IsNumComparable(d.val2.vc->Type()))) - return common::RS_SOME; // non-numerical or non-comparable + ((d.op == common::Operator::O_BETWEEN || d.op == common::Operator::O_NOT_BETWEEN) && + !Type().IsNumComparable(d.val2.vc->Type()))) + return common::RSValue::RS_SOME; // non-numerical or non-comparable int64_t vamin = GetMinInt64(mit); int64_t vamax = GetMaxInt64(mit); @@ -289,36 +294,39 @@ common::RSValue VirtualColumnBase::DoRoughCheck(const core::MIIterator &mit, cor if (vamin == common::NULL_VALUE_64 || vamax == common::NULL_VALUE_64 || v1min == common::NULL_VALUE_64 || v1max == common::NULL_VALUE_64 || (d.val2.vc && (v2min == common::NULL_VALUE_64 || v2max == common::NULL_VALUE_64))) - return common::RS_SOME; + return common::RSValue::RS_SOME; if (!Type().IsFloat()) { - if (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN) { // the second case will be negated soon + if (d.op == common::Operator::O_BETWEEN || + d.op == common::Operator::O_NOT_BETWEEN) { // the second case will be negated soon if (vamin >= v1max && vamax <= v2min) - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else if (vamin > v2max || vamax < v1min) - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else { - if (vamin >= v1max) { // NOTE: only common::O_MORE, common::O_LESS and - // common::O_EQ are analyzed here, the rest of operators + if (vamin >= v1max) { // NOTE: only common::Operator::O_MORE, common::Operator::O_LESS and + // common::Operator::O_EQ are analyzed here, the rest of operators // will be taken into account later (treated as negations) - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (d.op == common::Operator::O_LESS || + d.op == common::Operator::O_MORE_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (vamin > v1max) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_MORE || d.op == common::Operator::O_LESS_EQ) res = common::RSValue::RS_ALL; } } if (vamax <= v1min) { - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (d.op == common::Operator::O_MORE || + d.op == common::Operator::O_LESS_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (vamax < v1min) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_LESS || d.op == common::Operator::O_MORE_EQ) res = common::RSValue::RS_ALL; } } - if (res == common::RS_SOME && (d.op == common::O_EQ || d.op == common::O_NOT_EQ) && vamin == v1max && - vamax == v1min) - res = common::RS_ALL; + if (res == common::RSValue::RS_SOME && (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) && + vamin == v1max && vamax == v1min) + res = common::RSValue::RS_ALL; } } else { double vamind = (vamin == common::MINUS_INF_64 ? common::MINUS_INF_DBL : *(double *)&vamin); @@ -328,49 +336,52 @@ common::RSValue VirtualColumnBase::DoRoughCheck(const core::MIIterator &mit, cor double v2mind = (v2min == common::MINUS_INF_64 ? common::MINUS_INF_DBL : *(double *)&v2min); double v2maxd = (v2max == common::PLUS_INF_64 ? common::PLUS_INF_DBL : *(double *)&v2max); - if (d.op == common::O_BETWEEN || d.op == common::O_NOT_BETWEEN) { // the second case will be negated soon + if (d.op == common::Operator::O_BETWEEN || + d.op == common::Operator::O_NOT_BETWEEN) { // the second case will be negated soon if (vamind >= v1maxd && vamaxd <= v2mind) - res = common::RS_ALL; + res = common::RSValue::RS_ALL; else if (vamind > v2maxd || vamaxd < v1mind) - res = common::RS_NONE; + res = common::RSValue::RS_NONE; } else { - if (vamind >= v1maxd) { // NOTE: only common::O_MORE, common::O_LESS - // and common::O_EQ are analyzed here, the rest - // of operators will be taken into account - // later (treated as negations) - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (vamind >= v1maxd) { // NOTE: only common::Operator::O_MORE, common::Operator::O_LESS + // and common::Operator::O_EQ are analyzed here, the rest + // of operators will be taken into account + // later (treated as negations) + if (d.op == common::Operator::O_LESS || + d.op == common::Operator::O_MORE_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (vamind > v1maxd) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_MORE || d.op == common::Operator::O_LESS_EQ) res = common::RSValue::RS_ALL; } } if (vamaxd <= v1mind) { - if (d.op == common::O_MORE || d.op == common::O_LESS_EQ) // the second case will be negated soon - res = common::RS_NONE; + if (d.op == common::Operator::O_MORE || + d.op == common::Operator::O_LESS_EQ) // the second case will be negated soon + res = common::RSValue::RS_NONE; if (vamaxd < v1mind) { - if (d.op == common::O_EQ || d.op == common::O_NOT_EQ) res = common::RS_NONE; - if (d.op == common::O_LESS || d.op == common::O_MORE_EQ) res = common::RS_ALL; + if (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) res = common::RSValue::RS_NONE; + if (d.op == common::Operator::O_LESS || d.op == common::Operator::O_MORE_EQ) res = common::RSValue::RS_ALL; } } - if (res == common::RS_SOME && (d.op == common::O_EQ || d.op == common::O_NOT_EQ) && vamind == v1maxd && - vamaxd == v1mind) - res = common::RS_ALL; + if (res == common::RSValue::RS_SOME && (d.op == common::Operator::O_EQ || d.op == common::Operator::O_NOT_EQ) && + vamind == v1maxd && vamaxd == v1mind) + res = common::RSValue::RS_ALL; } } } // reverse negations - if (d.op == common::O_NOT_EQ || d.op == common::O_LESS_EQ || d.op == common::O_MORE_EQ || - d.op == common::O_NOT_BETWEEN) { - if (res == common::RS_ALL) - res = common::RS_NONE; - else if (res == common::RS_NONE) - res = common::RS_ALL; + if (d.op == common::Operator::O_NOT_EQ || d.op == common::Operator::O_LESS_EQ || + d.op == common::Operator::O_MORE_EQ || d.op == common::Operator::O_NOT_BETWEEN) { + if (res == common::RSValue::RS_ALL) + res = common::RSValue::RS_NONE; + else if (res == common::RSValue::RS_NONE) + res = common::RSValue::RS_ALL; } // check nulls - if (res == common::RS_ALL && + if (res == common::RSValue::RS_ALL && (nulls_possible || d.val1.vc->NullsPossible() || (d.val2.vc && d.val2.vc->NullsPossible()))) - res = common::RS_SOME; + res = common::RSValue::RS_SOME; return res; } } // namespace vcolumn diff --git a/storage/stonedb/vc/virtual_column_base.h b/storage/stonedb/vc/virtual_column_base.h index 0a4f6afad..462d35e4f 100644 --- a/storage/stonedb/vc/virtual_column_base.h +++ b/storage/stonedb/vc/virtual_column_base.h @@ -70,7 +70,7 @@ class VirtualColumnBase : public core::Column { VirtualColumnBase(core::ColumnType const &col_type, core::MultiIndex *mind); VirtualColumnBase(VirtualColumn const &vc); - enum single_col_t { SC_NOT = 0, SC_ATTR, SC_RCATTR }; + enum class single_col_t { SC_NOT = 0, SC_ATTR, SC_RCATTR }; virtual ~VirtualColumnBase(){}; @@ -379,9 +379,9 @@ class VirtualColumnBase : public core::Column { virtual bool IsConst() const = 0; /*! \brief Returns not zero if the virtual column is an interface to a single - * physical column, otherwise SC_ATTR or SC_RCATTR \return single_col_t + * physical column, otherwise single_col_t::SC_ATTR or single_col_t::SC_RCATTR \return single_col_t */ - virtual single_col_t IsSingleColumn() const { return SC_NOT; } + virtual single_col_t IsSingleColumn() const { return single_col_t::SC_NOT; } /*! \brief Returns true if the virtual column is a set (multival), false * otherwise \return bool */