ClickHouse/src/Interpreters/ExecuteScalarSubqueriesVisitor.h

55 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
2019-10-19 20:36:35 +00:00
#include <Core/Block.h>
#include <Interpreters/Context_fwd.h>
#include <Interpreters/InDepthNodeVisitor.h>
#include <Common/typeid_cast.h>
namespace DB
{
class ASTSubquery;
class ASTFunction;
struct ASTTableExpression;
/** Replace subqueries that return exactly one row
* ("scalar" subqueries) to the corresponding constants.
*
* If the subquery returns more than one column, it is replaced by a tuple of constants.
*
* Features
*
* A replacement occurs during query analysis, and not during the main runtime.
* This means that the progress indicator will not work during the execution of these requests,
* and also such queries can not be aborted.
*
* But the query result can be used for the index in the table.
*
* Scalar subqueries are executed on the request-initializer server.
* The request is sent to remote servers with already substituted constants.
*/
class ExecuteScalarSubqueriesMatcher
{
public:
2019-02-22 15:45:47 +00:00
using Visitor = InDepthNodeVisitor<ExecuteScalarSubqueriesMatcher, true>;
2021-06-01 12:20:52 +00:00
struct Data : public WithContext
{
size_t subquery_depth;
2019-10-19 20:36:35 +00:00
Scalars & scalars;
Scalars & local_scalars;
bool only_analyze;
};
static bool needChildVisit(ASTPtr & node, const ASTPtr &);
2019-02-22 13:33:56 +00:00
static void visit(ASTPtr & ast, Data & data);
private:
static void visit(const ASTSubquery & subquery, ASTPtr & ast, Data & data);
2019-02-22 13:33:56 +00:00
static void visit(const ASTFunction & func, ASTPtr & ast, Data & data);
};
2019-02-22 15:45:47 +00:00
using ExecuteScalarSubqueriesVisitor = ExecuteScalarSubqueriesMatcher::Visitor;
}