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

Method explainEstimate

src/Processors/QueryPlan/QueryPlan.cpp:938–987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

936}
937
938void QueryPlan::explainEstimate(MutableColumns & columns) const
939{
940 checkInitialized();
941
942 struct EstimateCounters
943 {
944 std::string database_name;
945 std::string table_name;
946 UInt64 parts = 0;
947 UInt64 rows = 0;
948 UInt64 marks = 0;
949 };
950
951 using CountersPtr = std::shared_ptr<EstimateCounters>;
952 std::unordered_map<std::string, CountersPtr> counters;
953 using processNodeFuncType = std::function<void(const Node * node)>;
954 processNodeFuncType process_node = [&counters, &process_node] (const Node * node)
955 {
956 if (!node)
957 return;
958 if (const auto * step = dynamic_cast<ReadFromMergeTree*>(node->step.get()))
959 {
960 const auto & id = step->getStorageID();
961 auto key = id.database_name + "." + id.table_name;
962 auto it = counters.find(key);
963 if (it == counters.end())
964 {
965 it = counters.insert({key, std::make_shared<EstimateCounters>(id.database_name, id.table_name)}).first;
966 }
967 it->second->parts += step->getSelectedParts();
968 it->second->rows += step->getSelectedRows();
969 it->second->marks += step->getSelectedMarks();
970 }
971 for (const auto * child : node->children)
972 process_node(child);
973 };
974 process_node(root);
975
976 for (const auto & counter : counters)
977 {
978 size_t index = 0;
979 const auto & database_name = counter.second->database_name;
980 const auto & table_name = counter.second->table_name;
981 columns[index++]->insertData(database_name.c_str(), database_name.size());
982 columns[index++]->insertData(table_name.c_str(), table_name.size());
983 columns[index++]->insert(counter.second->parts);
984 columns[index++]->insert(counter.second->rows);
985 columns[index++]->insert(counter.second->marks);
986 }
987}
988
989// static void validatePlan(QueryPlan::Node * root, QueryPlan::Nodes & nodes)
990// {

Callers 1

executeImplMethod · 0.80

Calls 11

checkInitializedFunction · 0.85
getSelectedPartsMethod · 0.80
getSelectedRowsMethod · 0.80
getSelectedMarksMethod · 0.80
getMethod · 0.45
getStorageIDMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
insertDataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected