diff --git a/CMakeLists.txt b/CMakeLists.txt index f838efa71c6..66df4d3124a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ if (ENABLE_FUZZING) # And we don't want to enable coverage for it. message (STATUS "Fuzzing instrumentation enabled") set (FUZZER "libfuzzer") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib++") endif() # Global libraries diff --git a/base/base/CachedFn.h b/base/base/CachedFn.h index 83e02073e1d..ed1dbdbd48c 100644 --- a/base/base/CachedFn.h +++ b/base/base/CachedFn.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "FnTraits.h" @@ -17,7 +18,8 @@ struct CachedFn { private: using Traits = FnTraits; - using Key = typename Traits::DecayedArgs; + using DecayedArgs = TLMap; + using Key = TLChangeRoot; using Result = typename Traits::Ret; std::map cache; // Can't use hashmap as tuples are unhashable by default diff --git a/base/base/FnTraits.h b/base/base/FnTraits.h index d90cb530a09..6b8dc7cd0d2 100644 --- a/base/base/FnTraits.h +++ b/base/base/FnTraits.h @@ -1,8 +1,6 @@ #pragma once -#include -#include -#include +#include "Typelist.h" namespace detail { @@ -16,8 +14,7 @@ struct FnTraits static constexpr bool value = std::is_invocable_r_v; using Ret = R; - using Args = std::tuple; - using DecayedArgs = std::tuple::type...>; + using Args = Typelist; }; template diff --git a/base/base/TypeName.h b/base/base/TypeName.h new file mode 100644 index 00000000000..b3ea47fad5d --- /dev/null +++ b/base/base/TypeName.h @@ -0,0 +1,51 @@ +#pragma once + +#include "Decimal.h" +#include "UUID.h" + +namespace DB +{ +struct Array; +struct Tuple; +struct Map; +struct AggregateFunctionStateData; + +/** + * Obtain type string representation from real type if possible. + * @example TypeName == "UInt8" + */ +template constexpr inline std::string_view TypeName; + +#define TN_MAP(_A) \ + template <> constexpr inline std::string_view TypeName<_A> = #_A; + +TN_MAP(UInt8) +TN_MAP(UInt16) +TN_MAP(UInt32) +TN_MAP(UInt64) +TN_MAP(UInt128) +TN_MAP(UInt256) +TN_MAP(Int8) +TN_MAP(Int16) +TN_MAP(Int32) +TN_MAP(Int64) +TN_MAP(Int128) +TN_MAP(Int256) +TN_MAP(Float32) +TN_MAP(Float64) +TN_MAP(String) +TN_MAP(UUID) +TN_MAP(Decimal32) +TN_MAP(Decimal64) +TN_MAP(Decimal128) +TN_MAP(Decimal256) +TN_MAP(DateTime64) +TN_MAP(Array) +TN_MAP(Tuple) +TN_MAP(Map) + +/// Special case +template <> constexpr inline std::string_view TypeName = "AggregateFunctionState"; + +#undef TN_MAP +} diff --git a/base/base/TypePair.h b/base/base/TypePair.h new file mode 100644 index 00000000000..54f31831241 --- /dev/null +++ b/base/base/TypePair.h @@ -0,0 +1,4 @@ +#pragma once + +template struct TypePair { }; +template struct Id { }; diff --git a/base/base/Typelist.h b/base/base/Typelist.h new file mode 100644 index 00000000000..74abaf9e388 --- /dev/null +++ b/base/base/Typelist.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include +#include "defines.h" +#include "TypePair.h" + +/// General-purpose typelist. Easy on compilation times as it does not use recursion. +template +struct Typelist { static constexpr size_t size = sizeof...(Args); }; + +namespace TLUtils /// In some contexts it's more handy to use functions instead of aliases +{ +template +constexpr Typelist concat(Typelist, Typelist) { return {}; } + +template +constexpr Typelist prepend(Typelist) { return {}; } + +template +constexpr Typelist append(Typelist) { return {}; } + +template class F, class ...Args> +constexpr Typelist...> map(Typelist) { return {}; } + +template class Root, class ...Args> +constexpr Root changeRoot(Typelist) { return {}; } + +template +constexpr void forEach(Typelist, F && f) { (std::forward(f)(Id{}), ...); } +} + +template +using TLConcat = decltype(TLUtils::concat(TLLeft{}, TLRight{})); + +template using TLPrepend = decltype(TLUtils::prepend(Typelist{})); +template using TLAppend = decltype(TLUtils::append(Typelist{})); + +template class F, class Typelist> +using TLMap = decltype(TLUtils::map(Typelist{})); + +template class Root, class Typelist> +using TLChangeRoot = decltype(TLUtils::changeRoot(Typelist{})); diff --git a/base/base/Typelists.h b/base/base/Typelists.h new file mode 100644 index 00000000000..d5d58be96cc --- /dev/null +++ b/base/base/Typelists.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Typelist.h" +#include "extended_types.h" +#include "Decimal.h" +#include "UUID.h" + +namespace DB +{ +using TLIntegral = Typelist; +using TLExtendedIntegral = Typelist; +using TLDecimals = Typelist; + +using TLIntegralWithExtended = TLConcat; + +using TLNumbers = TLConcat; +using TLNumbersWithUUID = TLAppend; +} diff --git a/base/base/UUID.h b/base/base/UUID.h new file mode 100644 index 00000000000..8b1ed16ea2f --- /dev/null +++ b/base/base/UUID.h @@ -0,0 +1,9 @@ +#pragma once + +#include "strong_typedef.h" +#include "extended_types.h" + +namespace DB +{ +using UUID = StrongTypedef; +} diff --git a/docker/packager/other/fuzzer.sh b/docker/packager/other/fuzzer.sh index 1a8b80c3f77..5eec51f9625 100755 --- a/docker/packager/other/fuzzer.sh +++ b/docker/packager/other/fuzzer.sh @@ -16,7 +16,7 @@ cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_C_CO -DENABLE_LIBRARIES=0 -DENABLE_SSL=1 -DUSE_INTERNAL_SSL_LIBRARY=1 -DUSE_UNWIND=ON -DENABLE_EMBEDDED_COMPILER=0 \ -DENABLE_EXAMPLES=0 -DENABLE_UTILS=0 -DENABLE_THINLTO=0 "-DSANITIZE=$SANITIZER" \ -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0 \ - -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. + -DENABLE_CHECK_HEAVY_BUILDS=1 -DGLIBC_COMPATIBILITY=OFF "${CMAKE_FLAGS[@]}" .. FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') diff --git a/docs/en/sql-reference/statements/alter/sample-by.md b/docs/en/sql-reference/statements/alter/sample-by.md index df8ff90f196..21b20be8b78 100644 --- a/docs/en/sql-reference/statements/alter/sample-by.md +++ b/docs/en/sql-reference/statements/alter/sample-by.md @@ -16,5 +16,4 @@ The command changes the [sampling key](../../../engines/table-engines/mergetree- The command is lightweight in the sense that it only changes metadata. The primary key must contain the new sample key. !!! note "Note" - It only works for tables in the [MergeTree](../../../engines/table-engines/mergetree-family/mergetree.md) family (including -[replicated](../../../engines/table-engines/mergetree-family/replication.md) tables). \ No newline at end of file + It only works for tables in the [MergeTree](../../../engines/table-engines/mergetree-family/mergetree.md) family (including [replicated](../../../engines/table-engines/mergetree-family/replication.md) tables). diff --git a/docs/en/sql-reference/statements/select/sample.md b/docs/en/sql-reference/statements/select/sample.md index 2ed0a804736..2405cb0a03c 100644 --- a/docs/en/sql-reference/statements/select/sample.md +++ b/docs/en/sql-reference/statements/select/sample.md @@ -10,7 +10,7 @@ When data sampling is enabled, the query is not performed on all the data, but o Approximated query processing can be useful in the following cases: -- When you have strict timing requirements (like \<100ms) but you can’t justify the cost of additional hardware resources to meet them. +- When you have strict latency requirements (like below 100ms) but you can’t justify the cost of additional hardware resources to meet them. - When your raw data is not accurate, so approximation does not noticeably degrade the quality. - Business requirements target approximate results (for cost-effectiveness, or to market exact results to premium users). diff --git a/src/AggregateFunctions/AggregateFunctionSimpleLinearRegression.cpp b/src/AggregateFunctions/AggregateFunctionSimpleLinearRegression.cpp index 697112dc443..482229233f5 100644 --- a/src/AggregateFunctions/AggregateFunctionSimpleLinearRegression.cpp +++ b/src/AggregateFunctions/AggregateFunctionSimpleLinearRegression.cpp @@ -3,9 +3,6 @@ #include #include -#include - - namespace DB { struct Settings; diff --git a/src/Columns/ColumnDecimal.h b/src/Columns/ColumnDecimal.h index 30e73300a1e..542049c60a6 100644 --- a/src/Columns/ColumnDecimal.h +++ b/src/Columns/ColumnDecimal.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include @@ -86,7 +86,7 @@ private: {} public: - const char * getFamilyName() const override { return TypeName; } + const char * getFamilyName() const override { return TypeName.data(); } TypeIndex getDataType() const override { return TypeId; } bool isNumeric() const override { return false; } diff --git a/src/Columns/ColumnVector.h b/src/Columns/ColumnVector.h index b44126d73bf..eb0c08dcd1d 100644 --- a/src/Columns/ColumnVector.h +++ b/src/Columns/ColumnVector.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace DB @@ -237,7 +237,7 @@ public: data.reserve(n); } - const char * getFamilyName() const override { return TypeName; } + const char * getFamilyName() const override { return TypeName.data(); } TypeIndex getDataType() const override { return TypeId; } MutableColumnPtr cloneResized(size_t size) const override; diff --git a/src/Common/TypeList.h b/src/Common/TypeList.h deleted file mode 100644 index c011f226f87..00000000000 --- a/src/Common/TypeList.h +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace DB -{ - -template -struct TypeList -{ - static constexpr size_t size = 0; - - template - using At = std::nullptr_t; - - template - static void forEach(Func && /*func*/) - { - } -}; - - -template -struct TypeList -{ - using Head = THead; - using Tail = TypeList; - - static constexpr size_t size = 1 + sizeof...(TTail); - - template - using At = typename std::template conditional_t>; - - template - static void ALWAYS_INLINE forEach(Func && func) - { - func.template operator()(); - Tail::template forEach(std::forward(func)); - } -}; - -/// Prepend Type to TypeList -/// Usage: -/// using TypeListWithType = typename AppendToTypeList::Type; -template -struct PrependToTypeList -{ - using Type = typename PrependToTypeList::Type; -}; - -template -struct PrependToTypeList, Types ...> -{ - using Type = TypeList; -}; - -/// Append Type to TypeList -/// Usage: -/// using TypeListWithType = typename AppendToTypeList::Type; -template -struct AppendToTypeList -{ - using Type = typename AppendToTypeList::Type; -}; - -template -struct AppendToTypeList, Types ...> -{ - using Type = TypeList; -}; - -/// Apply TypeList as variadic template argument of Class. -/// Usage: -/// using ClassWithAppliedTypeList = typename ApplyTypeListForClass::Type; -template