2012-05-30 05:53:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/OptimizedRegularExpression.h>
|
|
|
|
#include <Storages/IStorage.h>
|
2014-01-10 13:24:50 +00:00
|
|
|
|
2012-05-30 05:53:09 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** A table that represents the union of an arbitrary number of other tables.
|
|
|
|
* All tables must have the same structure.
|
2012-05-30 05:53:09 +00:00
|
|
|
*/
|
2017-06-06 18:36:13 +00:00
|
|
|
class StorageMerge : public ext::shared_ptr_helper<StorageMerge>, public IStorage
|
2012-05-30 05:53:09 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "Merge"; }
|
|
|
|
std::string getTableName() const override { return name; }
|
|
|
|
|
2017-06-15 14:07:31 +00:00
|
|
|
bool isRemote() const override;
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// The check is delayed to the read method. It checks the support of the tables used.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool supportsSampling() const override { return true; }
|
|
|
|
bool supportsPrewhere() const override { return true; }
|
|
|
|
bool supportsFinal() const override { return true; }
|
|
|
|
bool supportsIndexForIn() const override { return true; }
|
|
|
|
|
2017-12-25 21:57:29 +00:00
|
|
|
NameAndTypePair getColumn(const String & column_name) const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool hasColumn(const String & column_name) const override;
|
|
|
|
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum getQueryProcessingStage(const Context &) const override;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-07-15 03:48:36 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2017-06-02 15:54:39 +00:00
|
|
|
unsigned num_streams) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
void drop() override {}
|
2017-12-01 21:13:25 +00:00
|
|
|
void rename(const String & /*new_path_to_db*/, const String & /*new_database_name*/, const String & new_table_name) override { name = new_table_name; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// you need to add and remove columns in the sub-tables manually
|
|
|
|
/// the structure of sub-tables is not checked
|
2019-03-05 10:12:20 +00:00
|
|
|
void alter(
|
|
|
|
const AlterCommands & params, const String & database_name, const String & table_name,
|
2019-03-07 20:52:25 +00:00
|
|
|
const Context & context, TableStructureWriteLockHolder & table_lock_holder) override;
|
2014-02-11 18:38:21 +00:00
|
|
|
|
2019-02-27 18:26:24 +00:00
|
|
|
bool mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, const Context & query_context) const override;
|
2018-03-16 09:00:04 +00:00
|
|
|
|
2012-05-30 05:53:09 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
String name;
|
|
|
|
String source_database;
|
|
|
|
OptimizedRegularExpression table_name_regexp;
|
2019-01-04 12:10:00 +00:00
|
|
|
Context global_context;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-03-07 18:04:47 +00:00
|
|
|
using StorageListWithLocks = std::list<std::pair<StoragePtr, TableStructureReadLockHolder>>;
|
2017-11-04 03:20:18 +00:00
|
|
|
|
2019-02-27 18:26:24 +00:00
|
|
|
StorageListWithLocks getSelectedTables(const String & query_id) const;
|
2017-11-04 03:20:18 +00:00
|
|
|
|
2019-02-27 18:26:24 +00:00
|
|
|
StorageMerge::StorageListWithLocks getSelectedTables(const ASTPtr & query, bool has_virtual_column, bool get_lock, const String & query_id) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-07-05 19:56:51 +00:00
|
|
|
template <typename F>
|
|
|
|
StoragePtr getFirstTable(F && predicate) const;
|
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageMerge(
|
|
|
|
const std::string & name_,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const String & source_database_,
|
|
|
|
const String & table_name_regexp_,
|
|
|
|
const Context & context_);
|
2018-09-18 11:09:21 +00:00
|
|
|
|
|
|
|
Block getQueryHeader(const Names & column_names, const SelectQueryInfo & query_info,
|
|
|
|
const Context & context, QueryProcessingStage::Enum processed_stage);
|
|
|
|
|
|
|
|
BlockInputStreams createSourceStreams(const SelectQueryInfo & query_info, const QueryProcessingStage::Enum & processed_stage,
|
2019-02-10 16:55:12 +00:00
|
|
|
const UInt64 max_block_size, const Block & header, const StoragePtr & storage,
|
2019-03-07 18:04:47 +00:00
|
|
|
const TableStructureReadLockHolder & struct_lock, Names & real_column_names,
|
2018-09-20 05:40:06 +00:00
|
|
|
Context & modified_context, size_t streams_num, bool has_table_virtual_column,
|
|
|
|
bool concat_streams = false);
|
2018-09-19 10:16:30 +00:00
|
|
|
|
2018-09-20 05:40:06 +00:00
|
|
|
void convertingSourceStream(const Block & header, const Context & context, ASTPtr & query,
|
|
|
|
BlockInputStreamPtr & source_stream, QueryProcessingStage::Enum processed_stage);
|
2012-05-30 05:53:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|