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
|
|
|
*/
|
2021-04-10 23:33:54 +00:00
|
|
|
class StorageMerge final : public ext::shared_ptr_helper<StorageMerge>, public IStorage, WithContext
|
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:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "Merge"; }
|
|
|
|
|
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; }
|
2020-12-22 16:40:53 +00:00
|
|
|
bool supportsSubcolumns() const override { return true; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
QueryProcessingStage::Enum getQueryProcessingStage(ContextPtr, QueryProcessingStage::Enum /*to_stage*/, SelectQueryInfo &) const override;
|
2018-04-19 14:47:09 +00:00
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2020-06-15 19:08:58 +00:00
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr 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
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void checkAlterIsPossible(const AlterCommands & commands, ContextPtr context) const override;
|
2019-12-26 18:17:05 +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
|
2021-04-10 23:33:54 +00:00
|
|
|
void alter(const AlterCommands & params, ContextPtr context, TableLockHolder & table_lock_holder) override;
|
2014-02-11 18:38:21 +00:00
|
|
|
|
2020-06-17 09:38:47 +00:00
|
|
|
bool mayBenefitFromIndexForIn(
|
2021-04-10 23:33:54 +00:00
|
|
|
const ASTPtr & left_in_operand, ContextPtr query_context, const StorageMetadataPtr & metadata_snapshot) 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 source_database;
|
2020-12-10 20:16:53 +00:00
|
|
|
std::optional<std::unordered_set<String>> source_tables;
|
|
|
|
std::optional<OptimizedRegularExpression> source_table_regexp;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-06-18 16:10:47 +00:00
|
|
|
using StorageWithLockAndName = std::tuple<StoragePtr, TableLockHolder, String>;
|
2019-12-30 18:20:43 +00:00
|
|
|
using StorageListWithLocks = std::list<StorageWithLockAndName>;
|
2017-11-04 03:20:18 +00:00
|
|
|
|
2020-04-09 18:10:27 +00:00
|
|
|
StorageMerge::StorageListWithLocks getSelectedTables(
|
2021-04-12 19:04:26 +00:00
|
|
|
ContextPtr query_context, const ASTPtr & query = nullptr, bool filter_by_virtual_column = false) 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;
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
DatabaseTablesIteratorPtr getDatabaseIterator(ContextPtr context) const;
|
2020-04-27 13:55:30 +00:00
|
|
|
|
2020-04-28 10:38:57 +00:00
|
|
|
NamesAndTypesList getVirtuals() const override;
|
2020-10-08 20:39:24 +00:00
|
|
|
ColumnSizeByName getColumnSizes() const override;
|
2019-06-02 12:11:01 +00:00
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageMerge(
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const String & source_database_,
|
2020-12-10 20:16:53 +00:00
|
|
|
const Strings & source_tables_,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_);
|
2020-12-10 20:16:53 +00:00
|
|
|
|
|
|
|
StorageMerge(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const String & source_database_,
|
|
|
|
const String & source_table_regexp_,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_);
|
2018-09-18 11:09:21 +00:00
|
|
|
|
2020-08-06 12:24:05 +00:00
|
|
|
Pipe createSources(
|
2020-06-16 15:51:29 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2020-06-16 15:51:29 +00:00
|
|
|
const QueryProcessingStage::Enum & processed_stage,
|
2021-04-10 23:33:54 +00:00
|
|
|
UInt64 max_block_size,
|
2020-06-16 15:51:29 +00:00
|
|
|
const Block & header,
|
|
|
|
const StorageWithLockAndName & storage_with_lock,
|
2020-01-31 16:29:40 +00:00
|
|
|
Names & real_column_names,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr modified_context,
|
2020-06-16 15:51:29 +00:00
|
|
|
size_t streams_num,
|
|
|
|
bool has_table_virtual_column,
|
2020-01-31 16:29:40 +00:00
|
|
|
bool concat_streams = false);
|
2018-09-19 10:16:30 +00:00
|
|
|
|
2020-06-16 15:51:29 +00:00
|
|
|
void convertingSourceStream(
|
|
|
|
const Block & header, const StorageMetadataPtr & metadata_snapshot,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context, ASTPtr & query,
|
2020-06-16 15:51:29 +00:00
|
|
|
Pipe & pipe, QueryProcessingStage::Enum processed_stage);
|
2012-05-30 05:53:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|