mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 02:52:13 +00:00
Select query in metadata
This commit is contained in:
parent
eaaef83742
commit
31abbe5dbd
@ -79,7 +79,7 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
|
||||
|
||||
StoragePtr inner_table = materialized_view->getTargetTable();
|
||||
auto inner_table_id = inner_table->getStorageID();
|
||||
query = materialized_view->getSelectQuery().inner_query;
|
||||
query = dependent_metadata_snapshot->getSelectQuery().inner_query;
|
||||
|
||||
std::unique_ptr<ASTInsertQuery> insert = std::make_unique<ASTInsertQuery>();
|
||||
insert->table_id = inner_table_id;
|
||||
|
@ -308,7 +308,7 @@ InterpreterSelectQuery::InterpreterSelectQuery(
|
||||
/// Allow push down and other optimizations for VIEW: replace with subquery and rewrite it.
|
||||
ASTPtr view_table;
|
||||
if (view)
|
||||
view->replaceWithSubquery(getSelectQuery(), view_table);
|
||||
view->replaceWithSubquery(getSelectQuery(), view_table, metadata_snapshot);
|
||||
|
||||
syntax_analyzer_result = SyntaxAnalyzer(*context).analyzeSelect(
|
||||
query_ptr, SyntaxAnalyzerResult(source_header.getNamesAndTypesList(), storage),
|
||||
|
@ -319,14 +319,4 @@ NamesAndTypesList IStorage::getVirtuals() const
|
||||
return {};
|
||||
}
|
||||
|
||||
const SelectQueryDescription & IStorage::getSelectQuery() const
|
||||
{
|
||||
return metadata->select;
|
||||
}
|
||||
|
||||
bool IStorage::hasSelectQuery() const
|
||||
{
|
||||
return metadata->select.select_query != nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -138,9 +138,6 @@ public:
|
||||
public: /// thread-unsafe part. lockStructure must be acquired
|
||||
|
||||
const ColumnsDescription & getColumns() const; /// returns combined set of columns
|
||||
/// Select query for *View storages.
|
||||
const SelectQueryDescription & getSelectQuery() const;
|
||||
bool hasSelectQuery() const;
|
||||
|
||||
StorageInMemoryMetadata getInMemoryMetadata() const { return *metadata; }
|
||||
StorageMetadataPtr getInMemoryMetadataPtr() const { return metadata; }
|
||||
|
@ -400,5 +400,14 @@ ASTPtr StorageInMemoryMetadata::getSettingsChanges() const
|
||||
return settings_changes->clone();
|
||||
return nullptr;
|
||||
}
|
||||
const SelectQueryDescription & StorageInMemoryMetadata::getSelectQuery() const
|
||||
{
|
||||
return select;
|
||||
}
|
||||
|
||||
bool StorageInMemoryMetadata::hasSelectQuery() const
|
||||
{
|
||||
return select.select_query != nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -173,6 +173,10 @@ struct StorageInMemoryMetadata
|
||||
/// Storage settings
|
||||
ASTPtr getSettingsChanges() const;
|
||||
bool hasSettingsChanges() const { return settings_changes != nullptr; }
|
||||
|
||||
/// Select query for *View storages.
|
||||
const SelectQueryDescription & getSelectQuery() const;
|
||||
bool hasSelectQuery() const;
|
||||
};
|
||||
|
||||
using StorageMetadataPtr = std::shared_ptr<StorageInMemoryMetadata>;
|
||||
|
@ -165,7 +165,7 @@ static void executeDropQuery(ASTDropQuery::Kind kind, Context & global_context,
|
||||
void StorageMaterializedView::drop()
|
||||
{
|
||||
auto table_id = getStorageID();
|
||||
const auto & select_query = getSelectQuery();
|
||||
const auto & select_query = getInMemoryMetadataPtr()->getSelectQuery();
|
||||
if (!select_query.select_table_id.empty())
|
||||
DatabaseCatalog::instance().removeDependency(select_query.select_table_id, table_id);
|
||||
|
||||
@ -209,13 +209,14 @@ void StorageMaterializedView::alter(
|
||||
lockStructureExclusively(table_lock_holder, context.getCurrentQueryId(), context.getSettingsRef().lock_acquire_timeout);
|
||||
auto table_id = getStorageID();
|
||||
StorageInMemoryMetadata new_metadata = getInMemoryMetadata();
|
||||
StorageInMemoryMetadata old_metadata = getInMemoryMetadata();
|
||||
params.apply(new_metadata, context);
|
||||
|
||||
/// start modify query
|
||||
if (context.getSettingsRef().allow_experimental_alter_materialized_view_structure)
|
||||
{
|
||||
const auto & new_select = new_metadata.select;
|
||||
const auto & old_select = getSelectQuery();
|
||||
const auto & old_select = old_metadata.getSelectQuery();
|
||||
|
||||
DatabaseCatalog::instance().updateDependency(old_select.select_table_id, table_id, new_select.select_table_id, table_id);
|
||||
|
||||
@ -268,6 +269,7 @@ void StorageMaterializedView::mutate(const MutationCommands & commands, const Co
|
||||
void StorageMaterializedView::renameInMemory(const StorageID & new_table_id)
|
||||
{
|
||||
auto old_table_id = getStorageID();
|
||||
auto metadata_snapshot = getInMemoryMetadataPtr();
|
||||
bool from_atomic_to_atomic_database = old_table_id.hasUUID() && new_table_id.hasUUID();
|
||||
|
||||
if (has_inner_table && tryGetTargetTable() && !from_atomic_to_atomic_database)
|
||||
@ -293,14 +295,15 @@ void StorageMaterializedView::renameInMemory(const StorageID & new_table_id)
|
||||
}
|
||||
|
||||
IStorage::renameInMemory(new_table_id);
|
||||
const auto & select_query = getSelectQuery();
|
||||
const auto & select_query = metadata_snapshot->getSelectQuery();
|
||||
// TODO Actually we don't need to update dependency if MV has UUID, but then db and table name will be outdated
|
||||
DatabaseCatalog::instance().updateDependency(select_query.select_table_id, old_table_id, select_query.select_table_id, getStorageID());
|
||||
}
|
||||
|
||||
void StorageMaterializedView::shutdown()
|
||||
{
|
||||
const auto & select_query = getSelectQuery();
|
||||
auto metadata_snapshot = getInMemoryMetadataPtr();
|
||||
const auto & select_query = metadata_snapshot->getSelectQuery();
|
||||
/// Make sure the dependency is removed after DETACH TABLE
|
||||
if (!select_query.select_table_id.empty())
|
||||
DatabaseCatalog::instance().removeDependency(select_query.select_table_id, getStorageID());
|
||||
|
@ -63,7 +63,7 @@ Pipes StorageView::read(
|
||||
{
|
||||
Pipes pipes;
|
||||
|
||||
ASTPtr current_inner_query = getSelectQuery().inner_query;
|
||||
ASTPtr current_inner_query = metadata_snapshot->getSelectQuery().inner_query;
|
||||
|
||||
if (query_info.view_query)
|
||||
{
|
||||
|
@ -30,9 +30,9 @@ public:
|
||||
size_t max_block_size,
|
||||
unsigned num_streams) override;
|
||||
|
||||
void replaceWithSubquery(ASTSelectQuery & select_query, ASTPtr & view_name) const
|
||||
void replaceWithSubquery(ASTSelectQuery & select_query, ASTPtr & view_name, const StorageMetadataPtr & metadata_snapshot) const
|
||||
{
|
||||
replaceWithSubquery(select_query, getSelectQuery().inner_query->clone(), view_name);
|
||||
replaceWithSubquery(select_query, metadata_snapshot->getSelectQuery().inner_query->clone(), view_name);
|
||||
}
|
||||
|
||||
static void replaceWithSubquery(ASTSelectQuery & outer_query, ASTPtr view_query, ASTPtr & view_name);
|
||||
|
Loading…
Reference in New Issue
Block a user