This commit is contained in:
Roman Peshkurov 2015-10-08 17:54:12 +03:00
commit 6c317a3e1e
11 changed files with 596 additions and 461 deletions

View File

@ -98,15 +98,15 @@ struct AggregateFunctionUniqExactData<String>
template <typename T, HyperLogLogMode mode>
struct BaseUniqCombinedData
{
using Key = UInt64;
using Key = UInt32;
using Set = CombinedCardinalityEstimator<
Key,
HashSet<Key, DefaultHash<Key>, HashTableGrower<> >,
HashSet<Key, TrivialHash, HashTableGrower<> >,
16,
14,
17,
DefaultHash<Key>,
UInt64,
TrivialHash,
UInt32,
HyperLogLogBiasEstimator<UniqCombinedBiasData>,
mode
>;
@ -195,6 +195,33 @@ template <> struct AggregateFunctionUniqTraits<Float64>
}
};
/** Хэш-функция для uniqCombined.
*/
template <typename T> struct AggregateFunctionUniqCombinedTraits
{
static UInt32 hash(T x) { return static_cast<UInt32>(intHash64(x)); }
};
template <> struct AggregateFunctionUniqCombinedTraits<Float32>
{
static UInt32 hash(Float32 x)
{
UInt64 res = 0;
memcpy(reinterpret_cast<char *>(&res), reinterpret_cast<char *>(&x), sizeof(x));
return static_cast<UInt32>(intHash64(res));
}
};
template <> struct AggregateFunctionUniqCombinedTraits<Float64>
{
static UInt32 hash(Float64 x)
{
UInt64 res = 0;
memcpy(reinterpret_cast<char *>(&res), reinterpret_cast<char *>(&x), sizeof(x));
return static_cast<UInt32>(intHash64(res));
}
};
/** Структура для делегации работы по добавлению одного элемента в агрегатные функции uniq.
* Используется для частичной специализации для добавления строк.
*/
@ -204,7 +231,27 @@ struct OneAdder;
template <typename T, typename Data>
struct OneAdder<T, Data, typename std::enable_if<
std::is_same<Data, AggregateFunctionUniqUniquesHashSetData>::value ||
std::is_same<Data, AggregateFunctionUniqHLL12Data<T> >::value ||
std::is_same<Data, AggregateFunctionUniqHLL12Data<T> >::value>::type>
{
template <typename T2 = T>
static void addOne(Data & data, const IColumn & column, size_t row_num,
typename std::enable_if<!std::is_same<T2, String>::value>::type * = nullptr)
{
const auto & value = static_cast<const ColumnVector<T2> &>(column).getData()[row_num];
data.set.insert(AggregateFunctionUniqTraits<T2>::hash(value));
}
template <typename T2 = T>
static void addOne(Data & data, const IColumn & column, size_t row_num,
typename std::enable_if<std::is_same<T2, String>::value>::type * = nullptr)
{
StringRef value = column.getDataAt(row_num);
data.set.insert(CityHash64(value.data, value.size));
}
};
template <typename T, typename Data>
struct OneAdder<T, Data, typename std::enable_if<
std::is_same<Data, AggregateFunctionUniqCombinedRawData<T> >::value ||
std::is_same<Data, AggregateFunctionUniqCombinedLinearCountingData<T> >::value ||
std::is_same<Data, AggregateFunctionUniqCombinedBiasCorrectedData<T> >::value ||
@ -215,7 +262,7 @@ struct OneAdder<T, Data, typename std::enable_if<
typename std::enable_if<!std::is_same<T2, String>::value>::type * = nullptr)
{
const auto & value = static_cast<const ColumnVector<T2> &>(column).getData()[row_num];
data.set.insert(AggregateFunctionUniqTraits<T2>::hash(value));
data.set.insert(AggregateFunctionUniqCombinedTraits<T2>::hash(value));
}
template <typename T2 = T>

View File

@ -27,7 +27,7 @@ namespace DB
*/
struct UniqCombinedBiasData
{
using InterpolatedData = std::array<double, 178>;
using InterpolatedData = std::array<double, 200>;
static double getThreshold();
/// Оценки количества уникальных значений по алгоритму HyperLogLog без применения каких-либо поправок.

View File

@ -9,6 +9,7 @@
#include <DB/IO/ReadHelpers.h>
#include <DB/IO/WriteHelpers.h>
#include <DB/Core/Defines.h>
#include <DB/Core/ErrorCodes.h>
#include <cmath>
#include <cstring>
@ -569,71 +570,54 @@ private:
}
}
template <HyperLogLogMode mode2 = mode>
inline double fixRawEstimate(double raw_estimate,
typename std::enable_if<(mode2 == HyperLogLogMode::Raw)
|| ((mode2 == HyperLogLogMode::BiasCorrected)
&& BiasEstimator::isTrivial())>::type * = nullptr) const
double fixRawEstimate(double raw_estimate) const
{
return raw_estimate;
}
template <HyperLogLogMode mode2 = mode>
inline double fixRawEstimate(double raw_estimate,
typename std::enable_if<(mode2 == HyperLogLogMode::LinearCounting)>::type * = nullptr) const
{
return applyLinearCorrection(raw_estimate);
}
template <HyperLogLogMode mode2 = mode>
inline double fixRawEstimate(double raw_estimate,
typename std::enable_if<(mode2 == HyperLogLogMode::BiasCorrected)
&& !BiasEstimator::isTrivial()>::type * = nullptr) const
{
return applyBiasCorrection(raw_estimate);
}
template <HyperLogLogMode mode2 = mode>
double fixRawEstimate(double raw_estimate,
typename std::enable_if<(mode2 == HyperLogLogMode::FullFeatured)>::type * = nullptr) const
{
static constexpr bool fix_big_cardinalities = std::is_same<HashValueType, UInt32>::value;
static constexpr double pow2_32 = 4294967296.0;
double fixed_estimate;
if (fix_big_cardinalities && (raw_estimate > (pow2_32 / 30.0)))
fixed_estimate = -pow2_32 * log(1.0 - raw_estimate / pow2_32);
else
fixed_estimate = applyCorrection(raw_estimate);
return fixed_estimate;
}
template <bool is_trivial = BiasEstimator::isTrivial()>
inline double applyCorrection(double raw_estimate, typename std::enable_if<is_trivial>::type * = nullptr) const
{
double fixed_estimate;
if (raw_estimate <= (2.5 * bucket_count))
if ((mode == HyperLogLogMode::Raw) || ((mode == HyperLogLogMode::BiasCorrected) && BiasEstimator::isTrivial()))
return raw_estimate;
else if (mode == HyperLogLogMode::LinearCounting)
return applyLinearCorrection(raw_estimate);
else if ((mode == HyperLogLogMode::BiasCorrected) && !BiasEstimator::isTrivial())
return applyBiasCorrection(raw_estimate);
else if (mode == HyperLogLogMode::FullFeatured)
{
/// Поправка в случае маленкой оценки.
fixed_estimate = applyLinearCorrection(raw_estimate);
static constexpr bool fix_big_cardinalities = std::is_same<HashValueType, UInt32>::value;
static constexpr double pow2_32 = 4294967296.0;
double fixed_estimate;
if (fix_big_cardinalities && (raw_estimate > (pow2_32 / 30.0)))
fixed_estimate = -pow2_32 * log(1.0 - raw_estimate / pow2_32);
else
fixed_estimate = applyCorrection(raw_estimate);
return fixed_estimate;
}
else
fixed_estimate = raw_estimate;
return fixed_estimate;
throw Poco::Exception("Internal error", DB::ErrorCodes::LOGICAL_ERROR);
}
template <bool is_trivial = BiasEstimator::isTrivial()>
inline double applyCorrection(double raw_estimate, typename std::enable_if<!is_trivial>::type * = nullptr) const
inline double applyCorrection(double raw_estimate) const
{
double fixed_estimate = applyBiasCorrection(raw_estimate);
double linear_estimate = applyLinearCorrection(fixed_estimate);
double fixed_estimate;
if (linear_estimate < BiasEstimator::getThreshold())
fixed_estimate = linear_estimate;
if (BiasEstimator::isTrivial())
{
if (raw_estimate <= (2.5 * bucket_count))
{
/// Поправка в случае маленкой оценки.
fixed_estimate = applyLinearCorrection(raw_estimate);
}
else
fixed_estimate = raw_estimate;
}
else
{
fixed_estimate = applyBiasCorrection(raw_estimate);
double linear_estimate = applyLinearCorrection(fixed_estimate);
if (linear_estimate < BiasEstimator::getThreshold())
fixed_estimate = linear_estimate;
}
return fixed_estimate;
}

View File

@ -386,23 +386,16 @@ public:
throw Exception("Second argument for function '" + getName() + "' must be Set; found " + column_set_ptr->getName(),
ErrorCodes::ILLEGAL_COLUMN);
/// Столбцы, которые проверяются на принадлежность множеству.
ColumnNumbers left_arguments;
Block block_of_key_columns;
/// Первый аргумент может быть tuple или одиночным столбцом.
const ColumnTuple * tuple = typeid_cast<const ColumnTuple *>(&*block.getByPosition(arguments[0]).column);
if (tuple)
{
/// Находим в блоке столбцы из tuple.
const Block & tuple_elems = tuple->getData();
size_t tuple_size = tuple_elems.columns();
for (size_t i = 0; i < tuple_size; ++i)
left_arguments.push_back(block.getPositionByName(tuple_elems.getByPosition(i).name));
}
block_of_key_columns = tuple->getData();
else
left_arguments.push_back(arguments[0]);
block_of_key_columns.insert(block.getByPosition(arguments[0]));
column_set->getData()->execute(block, left_arguments, result, negative);
block.getByPosition(result).column = column_set->getData()->execute(block_of_key_columns, negative);
}
};

View File

@ -288,10 +288,10 @@ public:
// Возвращает false, если превышено какое-нибудь ограничение, и больше не нужно вставлять.
bool insertFromBlock(const Block & block, bool create_ordered_set = false);
/** Для указанных столбцов блока проверить принадлежность их значений множеству.
/** Для столбцов блока проверить принадлежность их значений множеству.
* Записать результат в столбец в позиции result.
*/
void execute(Block & block, const ColumnNumbers & arguments, size_t result, bool negative) const;
ColumnPtr execute(const Block & block, bool negative) const;
std::string describe() const
{

View File

@ -120,7 +120,7 @@ struct Settings
M(SettingUInt64, merge_tree_max_rows_to_use_cache, (1024 * 1024)) \
\
/** Распределять чтение из MergeTree по потокам равномерно, обеспечивая стабильное среднее время исполнения каждого потока в пределах одного чтения. */ \
M(SettingBool, merge_tree_uniform_read_distribution, false) \
M(SettingBool, merge_tree_uniform_read_distribution, true) \
\
/** Минимальная длина выражения expr = x1 OR ... expr = xN для оптимизации */ \
M(SettingUInt64, optimize_min_equality_disjunction_chain_length, 3) \

View File

@ -8,373 +8,417 @@ namespace
const UniqCombinedBiasData::InterpolatedData raw_estimates =
{
700.0
,3850.0
,7350.0
,10850.0
,14350.0
,89003.5714
,103764.30343333333
,105572.1915
,109252.46533333334
,112638.20573333332
,116094.29566666669
,119619.81926666666
,123214.92233333334
,126469.06656666666
,130196.15093333334
,133566.85673333335
,136991.63890000002
,140470.0118666667
,144000.91686666667
,147585.44463333333
,151222.7466
,154447.75893333333
,158181.68399999998
,161492.41386666667
,164840.6352
,168713.9904
,172143.82656666666
,175611.2078
,179116.94873333335
,182658.0355
,186236.36723333332
,189332.1009
,192976.1847
,196654.62706666664
,199835.39103333335
,203575.92429999998
,206808.87086666666
,210611.72886666664
,213896.25913333334
,217759.63066666664
,221096.10933333333
,224456.31466666667
,227839.0366333333
,231242.72576666667
,235239.98256666667
,238688.95070000002
,242158.17593333332
,245649.42926666664
,249158.9859666667
,252689.67179999998
,256241.95376666667
,259214.9391666667
,262798.3925666667
,266399.8345666667
,270018.35863333335
,273653.1149
,276696.7119
,280366.51476666663
,284051.95540000004
,287133.5254333333
,290847.31173333334
,294579.5226
,297698.64109999995
,301454.39253333333
,305223.59123333334
,308375.3184666667
,312170.06
,315342.02996666665
,319162.8188666667
,322356.3565666666
,326199.5866
,329412.83396666666
,332634.3235666667
,336510.7596333333
,339747.7330333333
,343643.0385666667
,346896.77420000004
,350157.6729666667
,354079.3932333334
,357354.5196333334
,360638.3034333333
,364588.47873333335
,367886.05706666666
,371189.98006666667
,375161.95876666665
,378478.6737666666
,381801.6619
,385130.9645
,389131.7460333333
,392471.6233333333
,395817.1175
,399165.1003333333
,402518.7819333333
,406549.7624333333
,409916.016
,413289.0218666666
,416661.9977333333
,420040.4257333334
,424099.3186333333
,427485.4292000001
,430876.4814666666
,434269.4718
,437665.82826666674
,441066.7185
,444469.97226666665
,448561.9376666667
,451974.73750000005
,455389.1112
,458808.5816666667
,462230.8184666667
,465656.9889
,469081.3269
,472512.4878
,475944.4204333333
,480065.7132666667
,483502.04110000003
,486939.5075666667
,490379.7868333334
,493818.5365333333
,497259.08013333334
,500705.3513
,504155.6234666666
,507606.65499999997
,511060.7448666667
,514517.4004
,517973.35829999996
,521431.3761666666
,524891.7097333333
,529044.7593
,532507.0878999999
,535971.5070333333
,539436.2416999999
,542903.1470333333
,546370.3423
,549837.6947999999
,553307.0003666667
,556775.3770333333
,560247.6308333334
,563721.0700333334
,567196.7586333333
,570669.8439666666
,574146.018
,577622.2794666667
,581098.3862333334
,584575.8826666666
,588055.1468000001
,591538.0234
,595018.0103000001
,598504.5469333333
,601992.5697666666
,605475.5452
,608959.4645
,612444.0261
,615929.6436
,619412.3877333334
,622903.4263999999
,626391.3657333333
,629876.7359333333
,633364.2825999999
,636855.2673666667
,640344.4321000001
,643836.5543666667
,647327.3073999999
,650818.3525666667
,654312.2421666667
,657807.0899666668
,661301.4443666666
,664794.1040333334
,668288.1969666666
,671781.0196666667
,675272.7522333333
,678766.9045999999
,682259.3583666667
,685747.8148333334
,689238.7994666666
,692732.0478333334
,696224.6407
,700069.9224
99791.8496
,101386.91930000001
,105450.95623333333
,108128.01393333334
,110851.10286666667
,113620.01383333335
,116434.98796666665
,119295.74893333332
,122202.58199999998
,124783.45270000001
,127775.84493333333
,130432.03390000002
,133122.13506666667
,136239.7482
,139004.69996666667
,141803.40813333335
,144228.62236666665
,147089.61343333335
,149984.35636666667
,152912.8223666667
,155449.4413666667
,158440.23733333332
,161029.4043
,164080.25746666666
,166720.31723333334
,169384.27826666666
,172521.4491666667
,175235.4233
,177971.46556666668
,180730.04403333334
,183510.69883333333
,186313.77773333332
,189138.67343333332
,191985.62490000002
,194853.55733333333
,197259.4243333333
,200165.33826666666
,203093.2792
,205550.0133666667
,208515.49296666667
,211500.27113333336
,214002.73933333336
,217022.66503333332
,219554.61286666666
,222611.62203333332
,225172.43516666666
,228261.63369999998
,230849.9269333333
,233450.9665
,236588.48176666666
,239217.14506666665
,241858.01729999995
,245040.88769999996
,247707.505
,250385.32816666667
,253072.74516666666
,255772.3767333333
,259026.62416666665
,261750.1933
,264484.4988666667
,267229.4741
,269983.9762
,272747.6032
,275521.9937
,278306.35263333336
,281100.67233333335
,283902.65756666666
,286716.28403333336
,289537.95599999995
,292368.9353666667
,295207.7315
,298055.9653333333
,300911.9654666667
,303204.35336666665
,306077.9537333333
,308958.00193333335
,311845.22890000005
,314741.81600000005
,317644.8173333333
,319972.31696666667
,322888.63776666665
,325811.89053333335
,328741.73743333324
,331091.32163333334
,334034.29806666664
,336984.6469666666
,339939.86216666666
,342309.7939
,345278.14656666666
,348252.3204333333
,350635.0094666667
,353618.8034000001
,356610.7431333333
,359005.6872333333
,362005.8481
,365011.9431333333
,367422.15616666665
,370439.9724666667
,373460.6025
,375879.31826666667
,378908.1752
,381335.98703333334
,384373.7107666666
,387416.2068333333
,389852.7087666667
,392901.8697
,395343.33469999995
,398401.5141333333
,400851.9174
,403917.6844666666
,406371.6598333334
,409440.80490000005
,412517.26203333336
,414981.9741666666
,418063.8305
,420530.6776
,423616.6512666666
,426088.72699999996
,429181.1127666666
,431657.64166666666
,434757.3337
,437235.97023333336
,440338.2023666667
,442823.12679999997
,445932.7757666667
,448419.81309999997
,451533.39386666665
,454026.96746666665
,457147.8259333333
,459643.8253666666
,462140.6687333334
,465264.5323
,467767.3770333333
,470899.63109999994
,473406.5693999999
,476540.8793333333
,479051.11850000004
,482189.9576
,484701.15849999996
,487836.66456666664
,490348.32859999995
,492863.5349666667
,496009.21856666665
,498525.42956666666
,501674.7545333333
,504197.08666666667
,507345.7158333334
,509865.2856
,512385.7114666667
,515538.75786666665
,518061.9924333333
,521216.2575333333
,523741.7463333334
,526898.6196333334
,529426.4153666666
,531957.1346999999
,535122.4158
,537654.0189
,540820.3046333335
,543353.1055
,545886.3092666665
,549053.4182666666
,551588.0846666667
,554757.5437333334
,557292.4032000001
,559828.7957
,562997.8541333332
,565534.2980666666
,568709.6649999999
,571249.7172666666
,573790.0703666667
,576966.0044666667
,579505.9694666667
,582682.2277
,585223.6823
,587764.2020666667
,590940.0571666666
,593483.1912666665
,596026.3725
,599205.4451
,601746.4072333333
,604921.6576333332
,607463.0489333333
,610007.9545333334
,613191.4748666667
,615738.8463666667
,618922.8917333334
,621470.0042333334
,624017.6801333333
,627203.1910333333
,629749.1271666667
,632298.0367666667
,635482.3311666666
,638030.0856333333
,641214.3490333334
,643760.2273333333
,646307.8729
,649497.0210000001
,652049.6203333334
,654923.103
};
const UniqCombinedBiasData::InterpolatedData biases =
{
0.0
,0.0
,0.0
,0.0
,0.0
,71153.5714
,85214.30343333333
,83522.1915
,80202.46533333334
,77288.20573333332
,74444.29566666667
,71669.81926666667
,68964.92233333334
,66619.06656666666
,64046.15093333333
,61816.85673333333
,59641.6389
,57520.01186666667
,55450.91686666667
,53435.44463333334
,51472.74659999999
,49797.75893333333
,47931.68399999999
,46342.41386666667
,44790.6352
,43063.9904
,41593.82656666667
,40161.2078
,38766.94873333333
,37408.035500000005
,36086.36723333333
,34982.1009
,33726.184700000005
,32504.627066666664
,31485.391033333333
,30325.924299999995
,29358.870866666668
,28261.72886666667
,27346.259133333337
,26309.630666666668
,25446.109333333337
,24606.31466666666
,23789.036633333333
,22992.725766666666
,22089.98256666667
,21338.9507
,20608.175933333332
,19899.429266666673
,19208.985966666663
,18539.6718
,17891.95376666667
,17364.939166666667
,16748.392566666666
,16149.834566666666
,15568.358633333331
,15003.114899999995
,14546.711900000004
,14016.51476666668
,13501.955399999997
,13083.52543333332
,12597.311733333336
,12129.522600000006
,11748.641100000008
,11304.392533333332
,10873.59123333334
,10525.318466666678
,10120.059999999998
,9792.029966666674
,9412.818866666668
,9106.356566666664
,8749.58660000001
,8462.833966666678
,8184.323566666659
,7860.759633333325
,7597.733033333323
,7293.038566666665
,7046.774200000004
,6807.672966666675
,6529.393233333336
,6304.519633333344
,6088.30343333332
,5838.4787333333325
,5636.057066666661
,5439.980066666671
,5211.958766666658
,5028.673766666664
,4851.661899999996
,4680.964499999992
,4481.746033333319
,4321.623333333322
,4167.117500000012
,4015.1003333333356
,3868.781933333337
,3699.762433333332
,3566.0159999999937
,3439.021866666648
,3311.9977333333422
,3190.4257333333276
,3049.3186333333238
,2935.4291999999937
,2826.4814666666593
,2719.4717999999993
,2615.8282666666782
,2516.7184999999977
,2419.972266666669
,2311.9376666666744
,2224.7374999999884
,2139.1111999999944
,2058.581666666665
,1980.8184666666687
,1906.9888999999966
,1831.3268999999952
,1762.4878000000026
,1694.420433333328
,1615.7132666666682
,1552.0410999999924
,1489.507566666677
,1429.7868333333365
,1368.536533333332
,1309.0801333333268
,1255.35129999999
,1205.6234666666617
,1156.6549999999988
,1110.744866666675
,1067.4004000000034
,1023.3583000000023
,981.3761666666638
,941.7097333333513
,894.7593000000148
,857.0879000000035
,821.5070333333375
,786.2416999999745
,753.1470333333127
,720.3422999999797
,687.6947999999975
,657.0003666666647
,625.3770333333329
,597.6308333333387
,571.0700333333225
,546.7586333333165
,519.8439666666478
,496.0180000000012
,472.2794666666693
,448.386233333343
,425.8826666666816
,405.1468000000071
,388.0233999999861
,368.01030000002356
,354.54693333333125
,342.5697666666626
,325.5452000000126
,309.4644999999825
,294.0261000000173
,279.64360000001034
,262.38773333333666
,253.42639999999665
,241.36573333333945
,226.7359333333443
,214.28259999999622
,205.26736666667662
,194.43210000001514
,186.55436666666841
,177.30740000001
,168.35256666666828
,162.24216666668266
,157.0899666666713
,151.44436666666297
,144.1040333333464
,138.19696666668946
,131.01966666666945
,122.7522333333424
,116.90459999998954
,109.35836666667213
,97.81483333332774
,88.7994666666491
,82.04783333333519
,74.64070000000841
,69.92240000003949
83406.8496
,84682.41930000001
,83634.45623333333
,81199.51393333334
,78810.60286666667
,76467.51383333335
,74170.48796666665
,71919.24893333334
,69714.082
,67821.95270000001
,65702.34493333333
,63885.5339
,62102.63506666666
,60108.2482
,58400.199966666674
,56725.90813333334
,55317.122366666656
,53705.113433333325
,52126.856366666674
,50582.32236666667
,49284.94136666667
,47802.73733333333
,46557.904299999995
,45135.75746666667
,43941.817233333335
,42771.77826666667
,41435.949166666665
,40315.9233
,39217.96556666667
,38142.54403333333
,37089.19883333333
,36058.277733333336
,35049.17343333334
,34062.1249
,33096.05733333334
,32306.924333333332
,31378.83826666667
,30472.7792
,29734.513366666666
,28865.99296666667
,28016.77113333333
,27324.23933333333
,26510.165033333327
,25847.112866666674
,25070.122033333333
,24435.935166666663
,23691.133699999995
,23084.426933333332
,22490.466500000006
,21793.981766666664
,21227.645066666664
,20673.517299999996
,20022.387699999996
,19494.005
,18976.828166666663
,18469.24516666666
,17973.876733333327
,17394.124166666665
,16922.693300000003
,16461.998866666672
,16011.974100000001
,15571.476200000005
,15140.103200000012
,14719.493699999992
,14308.852633333338
,13908.172333333341
,13515.15756666667
,13133.78403333333
,12760.455999999986
,12396.435366666663
,12040.231499999994
,11693.465333333335
,11354.465466666676
,11090.853366666668
,10769.453733333328
,10454.501933333328
,10146.728900000007
,9848.316
,9556.31733333334
,9327.816966666656
,9049.137766666672
,8777.390533333344
,8512.237433333328
,8305.821633333331
,8053.79806666668
,7809.146966666663
,7569.362166666669
,7383.2939
,7156.646566666673
,6935.8204333333315
,6762.50946666667
,6551.303400000004
,6348.243133333327
,6187.18723333332
,5992.348100000003
,5803.44313333333
,5657.656166666672
,5480.472466666678
,5306.102499999989
,5168.818266666669
,5002.675199999988
,4874.487033333319
,4717.210766666666
,4564.70683333333
,4445.208766666678
,4299.36970000001
,4184.834699999997
,4048.0141333333354
,3942.4174000000057
,3813.1844666666584
,3711.159833333329
,3585.304899999998
,3466.7620333333325
,3375.4741666666523
,3262.3304999999914
,3173.1775999999954
,3064.151266666653
,2980.226999999994
,2877.6127666666675
,2798.141666666663
,2702.8336999999883
,2625.4702333333166
,2532.7023666666646
,2461.626799999998
,2376.275766666678
,2307.313100000019
,2225.89386666668
,2163.4674666666738
,2089.325933333341
,2029.3253666666667
,1970.1687333333346
,1899.032300000011
,1845.8770333333425
,1783.1310999999987
,1734.0693999999978
,1673.3793333333258
,1627.618499999992
,1571.457600000004
,1526.6585000000002
,1467.1645666666639
,1422.8285999999982
,1382.0349666666687
,1332.7185666666676
,1292.9295666666683
,1247.2545333333353
,1213.5866666666698
,1167.2158333333402
,1130.785599999993
,1095.21146666667
,1053.2578666666716
,1020.4924333333329
,979.7575333333225
,949.2463333333241
,911.1196333333113
,882.9153666666631
,857.6347000000145
,827.915800000017
,803.5189000000051
,774.8046333333477
,751.6055000000051
,728.8092666666489
,700.9182666666651
,679.5846666666524
,654.0437333333539
,632.9032000000007
,613.2956999999975
,587.3541333333123
,567.7980666666408
,548.164999999979
,532.2172666666642
,516.5703666666523
,497.5044666666848
,481.4694666666522
,462.72769999998854
,448.1823000000052
,432.7020666666601
,413.5571666666656
,400.69126666665153
,387.8724999999977
,371.94510000001173
,356.90723333331215
,337.1576333333117
,322.54893333330983
,311.4545333333469
,299.97486666667584
,291.3463666666842
,280.39173333333264
,271.5042333333404
,263.1801333333521
,253.69103333332654
,243.62716666665315
,236.53676666668616
,225.83116666666078
,217.58563333332617
,206.84903333332235
,196.72733333332386
,188.37289999997788
,182.52100000000792
,179.12033333334452
,177.1030000000028
};
}
double UniqCombinedBiasData::getThreshold()
{
return 176000;
return 177700;
}
const UniqCombinedBiasData::InterpolatedData & UniqCombinedBiasData::getRawEstimates()

View File

@ -375,7 +375,9 @@ std::string ExpressionAction::toString() const
switch (type)
{
case ADD_COLUMN:
ss << "ADD " << result_name << " " << result_type->getName() << " " << added_column->getName();
ss << "ADD " << result_name << " "
<< (result_type ? result_type->getName() : "(no type)") << " "
<< (added_column ? added_column->getName() : "(no column)");
break;
case REMOVE_COLUMN:
@ -387,7 +389,9 @@ std::string ExpressionAction::toString() const
break;
case APPLY_FUNCTION:
ss << "FUNCTION " << result_name << " " << result_type->getName() << " = " << function->getName() << "(";
ss << "FUNCTION " << result_name << " "
<< (result_type ? result_type->getName() : "(no type)") << " = "
<< (function ? function->getName() : "(no function)") << "(";
for (size_t i = 0; i < argument_names.size(); ++i)
{
if (i)
@ -456,9 +460,9 @@ void ExpressionActions::checkLimits(Block & block) const
std::stringstream list_of_non_const_columns;
for (size_t i = 0, size = block.columns(); i < size; ++i)
if (!block.getByPosition(i).column->isConst())
list_of_non_const_columns << (i == 0 ? "" : ", ") << block.getByPosition(i).name;
list_of_non_const_columns << "\n" << block.getByPosition(i).name;
throw Exception("Too many temporary non-const columns: " + list_of_non_const_columns.str()
throw Exception("Too many temporary non-const columns:" + list_of_non_const_columns.str()
+ ". Maximum: " + toString(limits.max_temporary_non_const_columns),
ErrorCodes::TOO_MUCH_TEMPORARY_NON_CONST_COLUMNS);
}
@ -628,8 +632,6 @@ std::string ExpressionActions::getSmallestColumn(const NamesAndTypesList & colum
void ExpressionActions::finalize(const Names & output_columns)
{
// std::cerr << "finalize\n";
NameSet final_columns;
for (size_t i = 0; i < output_columns.size(); ++i)
{
@ -756,13 +758,66 @@ void ExpressionActions::finalize(const Names & output_columns)
}
}
for (int i = static_cast<int>(sample_block.columns()) - 1; i >= 0; --i)
/* std::cerr << "\n";
for (const auto & action : actions)
std::cerr << action.toString() << "\n";
std::cerr << "\n";*/
/// Удаление ненужных временных столбцов.
/// Если у столбца после выполнения функции refcount = 0, то его можно удалить.
std::map<String, int> columns_refcount;
for (const auto & name : final_columns)
++columns_refcount[name];
for (const auto & action : actions)
{
const std::string & name = sample_block.getByPosition(i).name;
if (!final_columns.count(name))
add(ExpressionAction::removeColumn(name));
if (!action.source_name.empty())
++columns_refcount[action.source_name];
for (const auto & name : action.argument_names)
++columns_refcount[name];
for (const auto & name : action.prerequisite_names)
++columns_refcount[name];
}
Actions new_actions;
new_actions.reserve(actions.size());
for (const auto & action : actions)
{
new_actions.push_back(action);
auto process = [&] (const String & name)
{
auto refcount = --columns_refcount[name];
if (refcount <= 0)
{
new_actions.push_back(ExpressionAction::removeColumn(name));
if (sample_block.has(name))
sample_block.erase(name);
}
};
if (!action.source_name.empty())
process(action.source_name);
for (const auto & name : action.argument_names)
process(name);
for (const auto & name : action.prerequisite_names)
process(name);
}
actions.swap(new_actions);
/* std::cerr << "\n";
for (const auto & action : actions)
std::cerr << action.toString() << "\n";
std::cerr << "\n";*/
optimize();
checkLimits(sample_block);
}

View File

@ -478,12 +478,17 @@ void Set::createFromAST(DataTypes & types, ASTPtr node, const Context & context,
}
void Set::execute(Block & block, const ColumnNumbers & arguments, size_t result, bool negative) const
ColumnPtr Set::execute(const Block & block, bool negative) const
{
ColumnUInt8 * c_res = new ColumnUInt8;
block.getByPosition(result).column = c_res;
ColumnUInt8::Container_t & vec_res = c_res->getData();
vec_res.resize(block.getByPosition(arguments[0]).column->size());
size_t num_key_columns = block.columns();
if (0 == num_key_columns)
throw Exception("Logical error: no columns passed to Set::execute method.", ErrorCodes::LOGICAL_ERROR);
ColumnUInt8 * p_res = new ColumnUInt8;
ColumnPtr res = p_res;
ColumnUInt8::Container_t & vec_res = p_res->getData();
vec_res.resize(block.getByPosition(0).column->size());
Poco::ScopedReadRWLock lock(rwlock);
@ -494,19 +499,19 @@ void Set::execute(Block & block, const ColumnNumbers & arguments, size_t result,
memset(&vec_res[0], 1, vec_res.size());
else
memset(&vec_res[0], 0, vec_res.size());
return;
return res;
}
DataTypeArray * array_type = typeid_cast<DataTypeArray *>(&*block.getByPosition(arguments[0]).type);
const DataTypeArray * array_type = typeid_cast<const DataTypeArray *>(&*block.getByPosition(0).type);
if (array_type)
{
if (data_types.size() != 1 || arguments.size() != 1)
if (data_types.size() != 1 || num_key_columns != 1)
throw Exception("Number of columns in section IN doesn't match.", ErrorCodes::NUMBER_OF_COLUMNS_DOESNT_MATCH);
if (array_type->getNestedType()->getName() != data_types[0]->getName())
throw Exception(std::string() + "Types in section IN don't match: " + data_types[0]->getName() + " on the right, " + array_type->getNestedType()->getName() + " on the left.", ErrorCodes::TYPE_MISMATCH);
IColumn * in_column = &*block.getByPosition(arguments[0]).column;
const IColumn * in_column = &*block.getByPosition(0).column;
/// Константный столбец слева от IN поддерживается не напрямую. Для этого, он сначала материализуется.
ColumnPtr materialized_column;
@ -516,24 +521,26 @@ void Set::execute(Block & block, const ColumnNumbers & arguments, size_t result,
in_column = materialized_column.get();
}
if (ColumnArray * col = typeid_cast<ColumnArray *>(in_column))
if (const ColumnArray * col = typeid_cast<const ColumnArray *>(in_column))
executeArray(col, vec_res, negative);
else
throw Exception("Unexpected array column type: " + in_column->getName(), ErrorCodes::ILLEGAL_COLUMN);
}
else
{
if (data_types.size() != arguments.size())
if (data_types.size() != num_key_columns)
throw Exception("Number of columns in section IN doesn't match.", ErrorCodes::NUMBER_OF_COLUMNS_DOESNT_MATCH);
/// Запоминаем столбцы, с которыми будем работать. Также проверим, что типы данных правильные.
ConstColumnPlainPtrs key_columns(arguments.size());
for (size_t i = 0; i < arguments.size(); ++i)
ConstColumnPlainPtrs key_columns(num_key_columns);
for (size_t i = 0; i < num_key_columns; ++i)
{
key_columns[i] = block.getByPosition(arguments[i]).column;
key_columns[i] = block.getByPosition(i).column;
if (data_types[i]->getName() != block.getByPosition(arguments[i]).type->getName())
throw Exception("Types of column " + toString(i + 1) + " in section IN don't match: " + data_types[i]->getName() + " on the right, " + block.getByPosition(arguments[i]).type->getName() + " on the left.", ErrorCodes::TYPE_MISMATCH);
if (data_types[i]->getName() != block.getByPosition(i).type->getName())
throw Exception("Types of column " + toString(i + 1) + " in section IN don't match: "
+ data_types[i]->getName() + " on the right, " + block.getByPosition(i).type->getName() + " on the left.",
ErrorCodes::TYPE_MISMATCH);
}
/// Константные столбцы слева от IN поддерживается не напрямую. Для этого, они сначала материализуется.
@ -549,6 +556,8 @@ void Set::execute(Block & block, const ColumnNumbers & arguments, size_t result,
executeOrdinary(key_columns, vec_res, negative);
}
return res;
}

View File

@ -0,0 +1,2 @@
SET max_temporary_non_const_columns = 10;
SELECT number + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS x FROM system.numbers LIMIT 1;