ClickHouse/src/Storages/StorageMerge.h

92 lines
3.5 KiB
C++
Raw Normal View History

2012-05-30 05:53:09 +00:00
#pragma once
2017-06-06 17:18:32 +00:00
#include <ext/shared_ptr_helper.h>
#include <Common/OptimizedRegularExpression.h>
#include <Storages/IStorage.h>
#include <Interpreters/Context.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
*/
class StorageMerge final : public ext::shared_ptr_helper<StorageMerge>, public IStorage
2012-05-30 05:53:09 +00:00
{
2019-08-26 19:07:29 +00:00
friend struct ext::shared_ptr_helper<StorageMerge>;
2012-05-30 05:53:09 +00:00
public:
std::string getName() const override { return "Merge"; }
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.
bool supportsSampling() const override { return true; }
bool supportsPrewhere() const override { return true; }
bool supportsFinal() const override { return true; }
bool supportsIndexForIn() const override { return true; }
2019-05-21 11:24:32 +00:00
/// Consider columns coming from the underlying tables
NameAndTypePair getColumn(const String & column_name) const override;
bool hasColumn(const String & column_name) const override;
QueryProcessingStage::Enum getQueryProcessingStage(const Context &, const ASTPtr &) const override;
Pipes read(
const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
2017-06-02 15:54:39 +00:00
unsigned num_streams) override;
2019-12-26 18:17:05 +00:00
void checkAlterIsPossible(const AlterCommands & commands, const Settings & /* settings */) override;
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-12-26 18:17:05 +00:00
void alter(const AlterCommands & params, const Context & context, TableStructureWriteLockHolder & table_lock_holder) override;
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:
String source_database;
OptimizedRegularExpression table_name_regexp;
Context global_context;
2019-12-30 18:20:43 +00:00
using StorageWithLockAndName = std::tuple<StoragePtr, TableStructureReadLockHolder, String>;
using StorageListWithLocks = std::list<StorageWithLockAndName>;
StorageListWithLocks getSelectedTables(const String & query_id) const;
2019-12-30 18:20:43 +00:00
StorageMerge::StorageListWithLocks getSelectedTables(const ASTPtr & query, bool has_virtual_column, const String & query_id) const;
template <typename F>
StoragePtr getFirstTable(F && predicate) const;
DatabaseTablesIteratorPtr getDatabaseIterator() const;
protected:
StorageMerge(
2019-12-04 16:06:55 +00:00
const StorageID & table_id_,
const ColumnsDescription & columns_,
const String & source_database_,
const String & table_name_regexp_,
const Context & context_);
Block getQueryHeader(const Names & column_names, const SelectQueryInfo & query_info,
const Context & context, QueryProcessingStage::Enum processed_stage);
Pipes createSources(
const SelectQueryInfo & query_info, const QueryProcessingStage::Enum & processed_stage,
const UInt64 max_block_size, const Block & header, const StorageWithLockAndName & storage_with_lock,
Names & real_column_names,
2020-02-26 14:13:41 +00:00
const std::shared_ptr<Context> & modified_context, size_t streams_num, bool has_table_virtual_column,
bool concat_streams = false);
void convertingSourceStream(const Block & header, const Context & context, ASTPtr & query,
Pipe & pipe, QueryProcessingStage::Enum processed_stage);
2012-05-30 05:53:09 +00:00
};
}