Merge pull request #55353 from ClickHouse/fix-garbage-2

Fix trash optimization (up to a certain extent)
This commit is contained in:
Alexey Milovidov 2023-10-09 02:42:56 +02:00 committed by GitHub
commit b619d07baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 18 deletions

View File

@ -204,26 +204,41 @@ inline ASTs & getFunctionOperands(const ASTFunction * or_function)
bool LogicalExpressionsOptimizer::isLowCardinalityEqualityChain(const std::vector<ASTFunction *> & functions) const bool LogicalExpressionsOptimizer::isLowCardinalityEqualityChain(const std::vector<ASTFunction *> & functions) const
{ {
if (functions.size() > 1) if (functions.size() <= 1)
return false;
if (!functions[0])
return false;
/// Check if the identifier has LowCardinality type.
auto & first_operands = getFunctionOperands(functions.at(0));
if (first_operands.empty())
return false;
if (!first_operands[0])
return false;
const auto * identifier = first_operands.at(0)->as<ASTIdentifier>();
if (!identifier)
return false;
auto pos = IdentifierSemantic::getMembership(*identifier);
if (!pos)
pos = IdentifierSemantic::chooseTableColumnMatch(*identifier, tables_with_columns, true);
if (!pos)
return false;
if (*pos >= tables_with_columns.size())
return false;
if (auto data_type_and_name = tables_with_columns.at(*pos).columns.tryGetByName(identifier->shortName()))
{ {
/// Check if identifier is LowCardinality type if (typeid_cast<const DataTypeLowCardinality *>(data_type_and_name->type.get()))
auto & first_operands = getFunctionOperands(functions[0]); return true;
const auto * identifier = first_operands[0]->as<ASTIdentifier>();
if (identifier)
{
auto pos = IdentifierSemantic::getMembership(*identifier);
if (!pos)
pos = IdentifierSemantic::chooseTableColumnMatch(*identifier, tables_with_columns, true);
if (pos)
{
if (auto data_type_and_name = tables_with_columns[*pos].columns.tryGetByName(identifier->shortName()))
{
if (typeid_cast<const DataTypeLowCardinality *>(data_type_and_name->type.get()))
return true;
}
}
}
} }
return false; return false;
} }

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,3 @@
SELECT *
FROM merge('system', '^one$') AS one
WHERE (one.dummy = 0) OR (one.dummy = 1);