diff --git a/src/Interpreters/RewriteAnyFunctionVisitor.cpp b/src/Interpreters/RewriteAnyFunctionVisitor.cpp index 7d5d204499e..3652f49cdda 100644 --- a/src/Interpreters/RewriteAnyFunctionVisitor.cpp +++ b/src/Interpreters/RewriteAnyFunctionVisitor.cpp @@ -14,7 +14,7 @@ namespace DB namespace { -bool extractIdentifiers(const ASTFunction & func, std::vector & identifiers) +bool extractIdentifiers(const ASTFunction & func, std::unordered_set & identifiers) { for (auto & arg : func.arguments->children) { @@ -30,7 +30,7 @@ bool extractIdentifiers(const ASTFunction & func, std::vector & identi return false; } else if (arg->as()) - identifiers.emplace_back(&arg); + identifiers.emplace(&arg); } return true; @@ -67,7 +67,7 @@ void RewriteAnyFunctionMatcher::visit(const ASTFunction & func, ASTPtr & ast, Da return; } - std::vector identifiers; + std::unordered_set identifiers; /// implicit remove duplicates if (!extractIdentifiers(func, identifiers)) return; diff --git a/tests/queries/0_stateless/01430_fix_any_rewrite_aliases.reference b/tests/queries/0_stateless/01430_fix_any_rewrite_aliases.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/01430_fix_any_rewrite_aliases.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/01430_fix_any_rewrite_aliases.sql b/tests/queries/0_stateless/01430_fix_any_rewrite_aliases.sql new file mode 100644 index 00000000000..0a5a94ba707 --- /dev/null +++ b/tests/queries/0_stateless/01430_fix_any_rewrite_aliases.sql @@ -0,0 +1 @@ +SELECT any(if(if(x, 1, 2) AS a_, a_, 0)) FROM (SELECT 1 AS x);