mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Miscellaneous #1853
This commit is contained in:
parent
777b4404bd
commit
953ab16cde
@ -505,23 +505,23 @@ void Set::executeArray(const ColumnArray * key_column, ColumnUInt8::Container &
|
||||
}
|
||||
}
|
||||
|
||||
bool MergeTreeSetIndex::PKTuplePositionMapping::operator< (const PKTuplePositionMapping & other) const
|
||||
{
|
||||
return std::forward_as_tuple(pk_index, tuple_index) < std::forward_as_tuple(other.pk_index, other.tuple_index);
|
||||
}
|
||||
|
||||
MergeTreeSetIndex::MergeTreeSetIndex(const SetElements & set_elements, std::vector<PKTuplePositionMapping> && index_mapping_)
|
||||
: ordered_set(),
|
||||
indexes_mapping(std::move(index_mapping_))
|
||||
{
|
||||
std::sort(indexes_mapping.begin(), indexes_mapping.end());
|
||||
std::sort(indexes_mapping.begin(), indexes_mapping.end(),
|
||||
[](const PKTuplePositionMapping & l, const PKTuplePositionMapping & r)
|
||||
{
|
||||
return std::forward_as_tuple(l.pk_index, l.tuple_index) < std::forward_as_tuple(r.pk_index, r.tuple_index);
|
||||
});
|
||||
|
||||
std::unique(
|
||||
indexes_mapping.begin(), indexes_mapping.end(),
|
||||
[](const PKTuplePositionMapping & l, const PKTuplePositionMapping & r)
|
||||
{
|
||||
return l.pk_index == r.pk_index;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
for (size_t i = 0; i < set_elements.size(); ++i)
|
||||
{
|
||||
@ -553,14 +553,12 @@ BoolMask MergeTreeSetIndex::mayBeTrueInRange(const std::vector<Range> & key_rang
|
||||
for (size_t i = 0; i < indexes_mapping.size(); ++i)
|
||||
{
|
||||
std::optional<Range> new_range = PKCondition::applyMonotonicFunctionsChainToRange(
|
||||
key_ranges[indexes_mapping[i].pk_index],
|
||||
indexes_mapping[i].functions,
|
||||
indexes_mapping[i].data_type);
|
||||
key_ranges[indexes_mapping[i].pk_index],
|
||||
indexes_mapping[i].functions,
|
||||
indexes_mapping[i].data_type);
|
||||
|
||||
if (!new_range)
|
||||
{
|
||||
return {true, true};
|
||||
}
|
||||
|
||||
/** A range that ends in (x, y, ..., +inf) exclusive is the same as a range
|
||||
* that ends in (x, y, ..., -inf) inclusive and vice versa for the left bound.
|
||||
@ -568,37 +566,31 @@ BoolMask MergeTreeSetIndex::mayBeTrueInRange(const std::vector<Range> & key_rang
|
||||
if (new_range->left_bounded)
|
||||
{
|
||||
if (!new_range->left_included)
|
||||
{
|
||||
invert_left_infinities = true;
|
||||
}
|
||||
|
||||
left_point.push_back(FieldWithInfinity(new_range->left));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invert_left_infinities)
|
||||
{
|
||||
left_point.push_back(FieldWithInfinity::getPlusinfinity());
|
||||
} else {
|
||||
else
|
||||
left_point.push_back(FieldWithInfinity::getMinusInfinity());
|
||||
}
|
||||
}
|
||||
|
||||
if (new_range->right_bounded)
|
||||
{
|
||||
if (!new_range->right_included)
|
||||
{
|
||||
invert_right_infinities = true;
|
||||
}
|
||||
|
||||
right_point.push_back(FieldWithInfinity(new_range->right));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invert_right_infinities)
|
||||
{
|
||||
right_point.push_back(FieldWithInfinity::getMinusInfinity());
|
||||
} else {
|
||||
else
|
||||
right_point.push_back(FieldWithInfinity::getPlusinfinity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,8 +602,8 @@ BoolMask MergeTreeSetIndex::mayBeTrueInRange(const std::vector<Range> & key_rang
|
||||
auto left_lower = std::lower_bound(ordered_set.begin(), ordered_set.end(), left_point);
|
||||
auto right_lower = std::lower_bound(ordered_set.begin(), ordered_set.end(), right_point);
|
||||
return {left_lower != right_lower
|
||||
|| (left_lower != ordered_set.end() && *left_lower == left_point)
|
||||
|| (right_lower != ordered_set.end() && *right_lower == right_point), true};
|
||||
|| (left_lower != ordered_set.end() && *left_lower == left_point)
|
||||
|| (right_lower != ordered_set.end() && *right_lower == right_point), true};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -164,19 +164,19 @@ class IFunction;
|
||||
using FunctionPtr = std::shared_ptr<IFunction>;
|
||||
|
||||
/// Class for mayBeTrueInRange function.
|
||||
class MergeTreeSetIndex {
|
||||
class MergeTreeSetIndex
|
||||
{
|
||||
public:
|
||||
/** Mapping for tuple positions from Set::set_elements to
|
||||
* position of pk index and data type of this pk column
|
||||
* and functions chain applied to this column.
|
||||
*/
|
||||
struct PKTuplePositionMapping {
|
||||
struct PKTuplePositionMapping
|
||||
{
|
||||
size_t tuple_index;
|
||||
size_t pk_index;
|
||||
std::vector<FunctionPtr> functions;
|
||||
DataTypePtr data_type;
|
||||
|
||||
bool operator< (const PKTuplePositionMapping & other) const;
|
||||
};
|
||||
|
||||
MergeTreeSetIndex(const SetElements & set_elements, std::vector<PKTuplePositionMapping> && indexes_mapping_);
|
||||
|
@ -220,6 +220,7 @@ FieldWithInfinity FieldWithInfinity::getMinusInfinity()
|
||||
{
|
||||
return FieldWithInfinity(Type::MINUS_INFINITY);
|
||||
}
|
||||
|
||||
FieldWithInfinity FieldWithInfinity::getPlusinfinity()
|
||||
{
|
||||
return FieldWithInfinity(Type::PLUS_INFINITY);
|
||||
|
@ -190,7 +190,8 @@ public:
|
||||
class FieldWithInfinity
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
enum Type
|
||||
{
|
||||
MINUS_INFINITY = -1,
|
||||
NORMAL = 0,
|
||||
PLUS_INFINITY = 1
|
||||
|
Loading…
Reference in New Issue
Block a user