A bit cleaner fix.

This commit is contained in:
Nikolai Kochetov 2023-01-27 12:37:23 +00:00
parent b05838cc32
commit b716e2d754

View File

@ -739,12 +739,9 @@ KeyCondition::KeyCondition(
, single_point(single_point_)
, strict(strict_)
{
for (size_t i = 0, size = key_column_names.size(); i < size; ++i)
{
const auto & name = key_column_names[i];
for (const auto & name : key_column_names)
if (!key_columns.contains(name))
key_columns[name] = i;
}
key_columns[name] = key_columns.size();
auto filter_node = buildFilterNode(query, additional_filter_asts);
@ -807,12 +804,9 @@ KeyCondition::KeyCondition(
, single_point(single_point_)
, strict(strict_)
{
for (size_t i = 0, size = key_column_names.size(); i < size; ++i)
{
const auto & name = key_column_names[i];
for (const auto & name : key_column_names)
if (!key_columns.contains(name))
key_columns[name] = i;
}
key_columns[name] = key_columns.size();
if (!filter_dag)
{
@ -1848,10 +1842,9 @@ KeyCondition::Description KeyCondition::getDescription() const
if (rpn_stack.size() != 1)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected stack size in KeyCondition::checkInRange");
/// column_index -> {column_name, is_used_flag}
std::map<size_t, std::pair<std::string_view, bool>> key_names;
std::map<size_t, std::string_view> key_names;
for (const auto & key : key_columns)
key_names[key.second] = {key.first, false};
key_names[key.second] = key.first;
WriteBufferFromOwnString buf;
@ -1862,15 +1855,13 @@ KeyCondition::Description KeyCondition::getDescription() const
{
case Node::Type::Leaf:
{
key_names[node->element->key_column].second = true; // key is used.
/// Note: for condition with double negation, like `not(x not in set)`,
/// we can replace it to `x in set` here.
/// But I won't do it, because `cloneASTWithInversionPushDown` already push down `not`.
/// So, this seem to be impossible for `can_be_true` tree.
if (node->negate)
buf << "not(";
buf << node->element->toString(key_names[node->element->key_column].first, true);
buf << node->element->toString(key_names[node->element->key_column], true);
if (node->negate)
buf << ")";
break;
@ -1901,11 +1892,8 @@ KeyCondition::Description KeyCondition::getDescription() const
describe(rpn_stack.front().can_be_true.get());
description.condition = std::move(buf.str());
for (auto && [_, v] : key_names)
{
if (v.second)
description.used_keys.emplace_back(v.first);
}
for (auto && [_, name] : key_names)
description.used_keys.emplace_back(name);
return description;
}