ClickHouse/dbms/include/DB/Interpreters/InJoinSubqueriesPreprocessor.h

51 lines
1.4 KiB
C++
Raw Normal View History

2015-09-18 13:36:10 +00:00
#pragma once
2017-01-03 07:37:29 +00:00
#include <string>
#include <DB/Core/Types.h>
#include <DB/Interpreters/SettingsCommon.h>
2015-09-18 13:36:10 +00:00
namespace DB
{
2017-01-03 07:37:29 +00:00
class IAST;
class IStorage;
class ASTSelectQuery;
class Context;
2015-09-18 13:36:10 +00:00
/** Scheme of operation:
*
* If "main" table in a query is distributed enough (thus, have at least two shards),
* and there are non-GLOBAL subqueries in IN or JOIN,
* and in that subqueries, there is a table
* (in any nesting level in that subquery or in more deep subqueries),
* that exist on local server and (according to information on local server) is also distributed enough
* then, according to setting 'distributed_product_mode',
* either
* - throw an exception;
* - or add GLOBAL to top subquery;
* - or replace database and table name in subquery to remote database and table name,
* as Distributed storage on local server knows it.
*
* Do not recursively preprocess subqueries, as it will be done by calling code.
*/
2015-09-18 13:36:10 +00:00
2017-01-03 07:37:29 +00:00
class InJoinSubqueriesPreprocessor
2015-09-18 13:36:10 +00:00
{
public:
2017-01-03 07:37:29 +00:00
InJoinSubqueriesPreprocessor(const Context & context) : context(context) {}
void process(ASTSelectQuery * query) const;
2015-09-18 13:36:10 +00:00
2017-01-03 07:37:29 +00:00
/// These methods could be overriden for the need of the unit test.
virtual bool hasAtLeastTwoShards(const IStorage & table) const;
virtual std::pair<std::string, std::string> getRemoteDatabaseAndTableName(const IStorage & table) const;
virtual ~InJoinSubqueriesPreprocessor() {}
2015-09-18 13:36:10 +00:00
private:
const Context & context;
};
2017-01-03 07:37:29 +00:00
2015-09-18 13:36:10 +00:00
}