fix Set index check useless (#6651)

* fixed useless detection

* fixed useless detection

* fix

* fix

* fix
This commit is contained in:
Nikita Vasilev 2019-08-25 01:01:36 +03:00 committed by alexey-milovidov
parent 11effc8576
commit 2dbfabd08c
3 changed files with 27 additions and 23 deletions

View File

@ -405,25 +405,6 @@ bool MergeTreeIndexConditionSet::operatorFromAST(ASTPtr & node) const
return true;
}
static bool checkAtomName(const String & name)
{
static std::set<String> atoms = {
"notEquals",
"equals",
"less",
"greater",
"lessOrEquals",
"greaterOrEquals",
"in",
"notIn",
"like",
"startsWith",
"endsWith",
"multiSearchAny"
};
return atoms.find(name) != atoms.end();
}
bool MergeTreeIndexConditionSet::checkASTUseless(const ASTPtr &node, bool atomic) const
{
if (const auto * func = node->as<ASTFunction>())
@ -439,16 +420,14 @@ bool MergeTreeIndexConditionSet::checkASTUseless(const ASTPtr &node, bool atomic
return checkASTUseless(args[0], atomic) || checkASTUseless(args[1], atomic);
else if (func->name == "not")
return checkASTUseless(args[0], atomic);
else if (!atomic && checkAtomName(func->name))
return checkASTUseless(node, true);
else
return std::any_of(args.begin(), args.end(),
[this, &atomic](const auto & arg) { return checkASTUseless(arg, atomic); });
[this](const auto & arg) { return checkASTUseless(arg, true); });
}
else if (const auto * literal = node->as<ASTLiteral>())
return !atomic && literal->value.get<bool>();
else if (const auto * identifier = node->as<ASTIdentifier>())
return key_columns.find(identifier->getColumnName()) == key_columns.end();
return key_columns.find(identifier->getColumnName()) == std::end(key_columns);
else
return true;
}

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,24 @@
SET allow_experimental_data_skipping_indices = 1;
DROP TABLE IF EXISTS test.set_array;
CREATE TABLE test.set_array
(
primary_key String,
index_array Array(UInt64),
INDEX additional_index_array (index_array) TYPE set(10000) GRANULARITY 1
) ENGINE = MergeTree()
ORDER BY (primary_key);
INSERT INTO test.set_array
select
toString(intDiv(number, 1000000)) as primary_key,
array(number) as index_array
from system.numbers
limit 10000000;
SET max_rows_to_read = 8192;
select count() from test.set_array where has(index_array, 333);
DROP TABLE test.set_array;