mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 16:50:48 +00:00
Fix segfault in arrayExists AST optimization
This commit is contained in:
parent
abc48a0b73
commit
4b764f7b65
@ -2,6 +2,7 @@
|
||||
#include <Parsers/ASTFunction.h>
|
||||
#include <Parsers/ASTIdentifier.h>
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ASTTablesInSelectQuery.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -76,4 +77,22 @@ void RewriteArrayExistsFunctionMatcher::visit(const ASTFunction & func, ASTPtr &
|
||||
}
|
||||
}
|
||||
|
||||
bool RewriteArrayExistsFunctionMatcher::needChildVisit(const ASTPtr & ast, const ASTPtr & child)
|
||||
{
|
||||
/// SELECT ... JOIN ... ON arrayExists(x -> x = 1, arr)
|
||||
/// A JOIN on expression is invalid, ignore it to avoid segmentation fault
|
||||
|
||||
if (auto * join = ast->as<ASTTableJoin>())
|
||||
{
|
||||
if (auto * func = child->as<ASTFunction>())
|
||||
{
|
||||
if (func->name == "arrayExists")
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
|
||||
static void visit(ASTPtr & ast, Data &);
|
||||
static void visit(const ASTFunction &, ASTPtr & ast, Data &);
|
||||
static bool needChildVisit(const ASTPtr &, const ASTPtr &) { return true; }
|
||||
static bool needChildVisit(const ASTPtr & ast, const ASTPtr & child);
|
||||
};
|
||||
|
||||
using RewriteArrayExistsFunctionVisitor = InDepthNodeVisitor<RewriteArrayExistsFunctionMatcher, false>;
|
||||
|
@ -0,0 +1,2 @@
|
||||
CREATE TABLE 02834_t (id UInt64, arr Array(UInt64)) ENGINE = MergeTree ORDER BY id;
|
||||
WITH subquery AS (SELECT []) SELECT t.* FROM 02834_t AS t JOIN subquery ON arrayExists(x -> x = 1, t.arr); -- { serverError INVALID_JOIN_ON_EXPRESSION }
|
Loading…
Reference in New Issue
Block a user