2011-08-28 05:13:24 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2012-05-09 13:12:38 +00:00
|
|
|
|
#include <DB/Core/QueryProcessingStage.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
#include <DB/Interpreters/Context.h>
|
2013-06-03 10:18:41 +00:00
|
|
|
|
#include <DB/Interpreters/ExpressionAnalyzer.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
#include <DB/DataStreams/IBlockInputStream.h>
|
2012-05-09 13:12:38 +00:00
|
|
|
|
#include <DB/Parsers/ASTSelectQuery.h>
|
2014-01-28 16:45:10 +00:00
|
|
|
|
#include <DB/TableFunctions/ITableFunction.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 13:12:38 +00:00
|
|
|
|
/** Интерпретирует запрос SELECT. Возвращает поток блоков с результатами выполнения запроса до стадии to_stage.
|
2011-08-28 05:13:24 +00:00
|
|
|
|
*/
|
|
|
|
|
class InterpreterSelectQuery
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-04-08 07:31:51 +00:00
|
|
|
|
InterpreterSelectQuery(ASTPtr query_ptr_, const Context & context_, QueryProcessingStage::Enum to_stage_ = QueryProcessingStage::Complete, size_t subquery_depth_ = 0, BlockInputStreamPtr input = nullptr);
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
|
|
InterpreterSelectQuery(ASTPtr query_ptr_, const Context & context_, const Names & required_column_names,
|
2014-04-08 07:31:51 +00:00
|
|
|
|
QueryProcessingStage::Enum to_stage_ = QueryProcessingStage::Complete, size_t subquery_depth_ = 0, BlockInputStreamPtr input = nullptr);
|
2011-08-28 05:13:24 +00:00
|
|
|
|
|
2014-04-08 07:31:51 +00:00
|
|
|
|
InterpreterSelectQuery(ASTPtr query_ptr_, const Context & context_, const Names & required_column_names, const NamesAndTypesList & table_column_names, QueryProcessingStage::Enum to_stage_ = QueryProcessingStage::Complete, size_t subquery_depth_ = 0, BlockInputStreamPtr input = nullptr);
|
2014-02-08 16:49:45 +00:00
|
|
|
|
|
2011-10-30 05:19:41 +00:00
|
|
|
|
/// Выполнить запрос, получить поток блоков для чтения
|
2011-08-28 05:13:24 +00:00
|
|
|
|
BlockInputStreamPtr execute();
|
|
|
|
|
|
2011-10-30 05:19:41 +00:00
|
|
|
|
/** Выполнить запрос, записать результат в нужном формате в buf.
|
|
|
|
|
* BlockInputStreamPtr возвращается, чтобы можно было потом получить информацию о плане выполнения запроса.
|
|
|
|
|
*/
|
|
|
|
|
BlockInputStreamPtr executeAndFormat(WriteBuffer & buf);
|
|
|
|
|
|
2011-08-28 05:13:24 +00:00
|
|
|
|
DataTypes getReturnTypes();
|
2011-10-30 05:19:41 +00:00
|
|
|
|
Block getSampleBlock();
|
2011-08-28 05:13:24 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2013-06-03 10:18:41 +00:00
|
|
|
|
typedef Poco::SharedPtr<ExpressionAnalyzer> ExpressionAnalyzerPtr;
|
|
|
|
|
|
2014-02-08 16:49:45 +00:00
|
|
|
|
void init(BlockInputStreamPtr input, const NamesAndTypesList & table_column_names = NamesAndTypesList());
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
2013-11-13 14:39:48 +00:00
|
|
|
|
/** Из какой таблицы читать. JOIN-ы не поддерживаются.
|
|
|
|
|
*/
|
2012-08-20 19:21:04 +00:00
|
|
|
|
void getDatabaseAndTableNames(String & database_name, String & table_name);
|
|
|
|
|
|
2012-05-09 13:12:38 +00:00
|
|
|
|
/** Выбрать из списка столбцов какой-нибудь, лучше - минимального размера.
|
|
|
|
|
*/
|
|
|
|
|
String getAnyColumn();
|
|
|
|
|
|
|
|
|
|
/// Разные стадии выполнения запроса.
|
2012-05-22 18:32:45 +00:00
|
|
|
|
|
|
|
|
|
/// Вынимает данные из таблицы. Возвращает стадию, до которой запрос был обработан в Storage.
|
2013-06-03 10:18:41 +00:00
|
|
|
|
QueryProcessingStage::Enum executeFetchColumns(BlockInputStreams & streams);
|
|
|
|
|
|
|
|
|
|
void executeWhere( BlockInputStreams & streams, ExpressionActionsPtr expression);
|
2014-02-27 12:49:21 +00:00
|
|
|
|
void executeAggregation( BlockInputStreams & streams, ExpressionActionsPtr expression,
|
|
|
|
|
bool overflow_row, bool final);
|
|
|
|
|
void executeMergeAggregated( BlockInputStreams & streams, bool overflow_row, bool final);
|
|
|
|
|
void executeTotalsAndHaving( BlockInputStreams & streams, bool has_having, ExpressionActionsPtr expression,
|
|
|
|
|
bool overflow_row);
|
2013-06-03 10:18:41 +00:00
|
|
|
|
void executeHaving( BlockInputStreams & streams, ExpressionActionsPtr expression);
|
2014-03-14 08:30:50 +00:00
|
|
|
|
void executeExpression( BlockInputStreams & streams, ExpressionActionsPtr expression);
|
2013-06-03 10:18:41 +00:00
|
|
|
|
void executeOrder( BlockInputStreams & streams);
|
|
|
|
|
void executePreLimit( BlockInputStreams & streams);
|
|
|
|
|
void executeUnion( BlockInputStreams & streams);
|
|
|
|
|
void executeLimit( BlockInputStreams & streams);
|
|
|
|
|
void executeProjection( BlockInputStreams & streams, ExpressionActionsPtr expression);
|
2014-03-28 15:57:06 +00:00
|
|
|
|
void executeDistinct( BlockInputStreams & streams, bool before_order, Names columns);
|
2014-03-04 11:26:55 +00:00
|
|
|
|
void executeSubqueriesInSets( BlockInputStreams & streams, const Sets & sets);
|
2012-05-09 13:12:38 +00:00
|
|
|
|
|
|
|
|
|
|
2011-08-28 05:13:24 +00:00
|
|
|
|
ASTPtr query_ptr;
|
2012-05-09 13:12:38 +00:00
|
|
|
|
ASTSelectQuery & query;
|
2011-08-28 05:13:24 +00:00
|
|
|
|
Context context;
|
2012-08-02 17:33:31 +00:00
|
|
|
|
Settings settings;
|
2012-05-09 13:12:38 +00:00
|
|
|
|
QueryProcessingStage::Enum to_stage;
|
2012-12-25 20:36:35 +00:00
|
|
|
|
size_t subquery_depth;
|
2013-06-03 10:18:41 +00:00
|
|
|
|
ExpressionAnalyzerPtr query_analyzer;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
BlockInputStreams streams;
|
2014-03-19 10:45:13 +00:00
|
|
|
|
|
|
|
|
|
/// Таблица, откуда читать данные, если не подзапрос.
|
|
|
|
|
StoragePtr storage;
|
|
|
|
|
IStorage::TableStructureReadLockPtr table_lock;
|
2012-06-25 03:56:45 +00:00
|
|
|
|
|
|
|
|
|
Logger * log;
|
2011-08-28 05:13:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|