MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / MergeTreeSetIndex

Method MergeTreeSetIndex

src/Interpreters/Set.cpp:662–701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

660}
661
662MergeTreeSetIndex::MergeTreeSetIndex(const Columns & set_elements, std::vector<KeyTuplePositionMapping> && indexes_mapping_)
663 : has_all_keys(set_elements.size() == indexes_mapping_.size()), indexes_mapping(std::move(indexes_mapping_))
664{
665 ::sort(indexes_mapping.begin(), indexes_mapping.end(),
666 [](const KeyTuplePositionMapping & l, const KeyTuplePositionMapping & r)
667 {
668 return std::tie(l.key_index, l.tuple_index) < std::tie(r.key_index, r.tuple_index);
669 });
670
671 /// Deduplicate key columns. This can make the condition weaker, e.g.:
672 /// (x + 1, x + 2) IN (10, 10)
673 /// effectively turns into:
674 /// (x + 1) IN (10)
675 indexes_mapping.erase(std::unique(
676 indexes_mapping.begin(), indexes_mapping.end(),
677 [](const KeyTuplePositionMapping & l, const KeyTuplePositionMapping & r)
678 {
679 return l.key_index == r.key_index;
680 }), indexes_mapping.end());
681
682 size_t tuple_size = indexes_mapping.size();
683 ordered_set.resize(tuple_size);
684
685 for (size_t i = 0; i < tuple_size; ++i)
686 ordered_set[i] = set_elements[indexes_mapping[i].tuple_index];
687
688 Block block_to_sort;
689 SortDescription sort_description;
690 for (size_t i = 0; i < tuple_size; ++i)
691 {
692 String column_name = "_" + toString(i);
693 block_to_sort.insert({ordered_set[i], nullptr, column_name});
694 sort_description.emplace_back(column_name, 1, 1);
695 }
696
697 sortBlock(block_to_sort, sort_description);
698
699 for (size_t i = 0; i < tuple_size; ++i)
700 ordered_set[i] = block_to_sort.getByPosition(i).column;
701}
702
703/** Return the BoolMask where:
704 * 1: the intersection of the set and the range is non-empty

Callers

nothing calls this directly

Calls 11

uniqueFunction · 0.85
sortBlockFunction · 0.85
toStringFunction · 0.70
sortFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
resizeMethod · 0.45
insertMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected