mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 19:42:00 +00:00
use storage uuid instead of table name as a key in storage info because there are can be multiple dropped table with the same name
This commit is contained in:
parent
0ea4b16530
commit
f4e2933f5d
@ -36,6 +36,7 @@ StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & que
|
|||||||
MutableColumnPtr table_column_mut = ColumnString::create();
|
MutableColumnPtr table_column_mut = ColumnString::create();
|
||||||
MutableColumnPtr engine_column_mut = ColumnString::create();
|
MutableColumnPtr engine_column_mut = ColumnString::create();
|
||||||
MutableColumnPtr active_column_mut = ColumnUInt8::create();
|
MutableColumnPtr active_column_mut = ColumnUInt8::create();
|
||||||
|
MutableColumnPtr storage_uuid_column_mut = ColumnUUID::create();
|
||||||
|
|
||||||
const auto access = context->getAccess();
|
const auto access = context->getAccess();
|
||||||
const bool check_access_for_tables = !access->isGranted(AccessType::SHOW_TABLES);
|
const bool check_access_for_tables = !access->isGranted(AccessType::SHOW_TABLES);
|
||||||
@ -47,6 +48,7 @@ StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & que
|
|||||||
if (!storage)
|
if (!storage)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
UUID storage_uuid = storage->getStorageID().uuid;
|
||||||
String database_name = storage->getStorageID().getDatabaseName();
|
String database_name = storage->getStorageID().getDatabaseName();
|
||||||
String table_name = storage->getStorageID().getTableName();
|
String table_name = storage->getStorageID().getTableName();
|
||||||
String engine_name = storage->getName();
|
String engine_name = storage->getName();
|
||||||
@ -63,7 +65,7 @@ StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & que
|
|||||||
if (check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_name))
|
if (check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
storages[std::make_pair(database_name, table_name)] = storage;
|
storages[storage_uuid] = storage;
|
||||||
|
|
||||||
/// Add all combinations of flag 'active'.
|
/// Add all combinations of flag 'active'.
|
||||||
for (UInt64 active : {0, 1})
|
for (UInt64 active : {0, 1})
|
||||||
@ -72,6 +74,7 @@ StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & que
|
|||||||
table_column_mut->insert(table_name);
|
table_column_mut->insert(table_name);
|
||||||
engine_column_mut->insert(engine_name);
|
engine_column_mut->insert(engine_name);
|
||||||
active_column_mut->insert(active);
|
active_column_mut->insert(active);
|
||||||
|
storage_uuid_column_mut->insert(storage_uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +82,7 @@ StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & que
|
|||||||
block_to_filter.insert(ColumnWithTypeAndName(std::move(table_column_mut), std::make_shared<DataTypeString>(), "table"));
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(table_column_mut), std::make_shared<DataTypeString>(), "table"));
|
||||||
block_to_filter.insert(ColumnWithTypeAndName(std::move(engine_column_mut), std::make_shared<DataTypeString>(), "engine"));
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(engine_column_mut), std::make_shared<DataTypeString>(), "engine"));
|
||||||
block_to_filter.insert(ColumnWithTypeAndName(std::move(active_column_mut), std::make_shared<DataTypeUInt8>(), "active"));
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(active_column_mut), std::make_shared<DataTypeUInt8>(), "active"));
|
||||||
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(storage_uuid_column_mut), std::make_shared<DataTypeUUID>(), "uuid"));
|
||||||
|
|
||||||
if (block_to_filter.rows())
|
if (block_to_filter.rows())
|
||||||
{
|
{
|
||||||
@ -90,6 +94,7 @@ StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & que
|
|||||||
database_column = block_to_filter.getByName("database").column;
|
database_column = block_to_filter.getByName("database").column;
|
||||||
table_column = block_to_filter.getByName("table").column;
|
table_column = block_to_filter.getByName("table").column;
|
||||||
active_column = block_to_filter.getByName("active").column;
|
active_column = block_to_filter.getByName("active").column;
|
||||||
|
storage_uuid_column = block_to_filter.getByName("uuid").column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypeDateTime.h>
|
#include <DataTypes/DataTypeDateTime.h>
|
||||||
#include <DataTypes/DataTypeDate.h>
|
#include <DataTypes/DataTypeDate.h>
|
||||||
|
#include <DataTypes/DataTypeUUID.h>
|
||||||
#include <Storages/MergeTree/MergeTreeData.h>
|
#include <Storages/MergeTree/MergeTreeData.h>
|
||||||
#include <Storages/StorageMaterializedMySQL.h>
|
#include <Storages/StorageMaterializedMySQL.h>
|
||||||
#include <Storages/VirtualColumnUtils.h>
|
#include <Storages/VirtualColumnUtils.h>
|
||||||
@ -93,6 +94,7 @@ StoragesInfoStream::StoragesInfoStream(const SelectQueryInfo & query_info, Conte
|
|||||||
MutableColumnPtr table_column_mut = ColumnString::create();
|
MutableColumnPtr table_column_mut = ColumnString::create();
|
||||||
MutableColumnPtr engine_column_mut = ColumnString::create();
|
MutableColumnPtr engine_column_mut = ColumnString::create();
|
||||||
MutableColumnPtr active_column_mut = ColumnUInt8::create();
|
MutableColumnPtr active_column_mut = ColumnUInt8::create();
|
||||||
|
MutableColumnPtr storage_uuid_column_mut = ColumnUUID::create();
|
||||||
|
|
||||||
const auto access = context->getAccess();
|
const auto access = context->getAccess();
|
||||||
const bool check_access_for_tables = !access->isGranted(AccessType::SHOW_TABLES);
|
const bool check_access_for_tables = !access->isGranted(AccessType::SHOW_TABLES);
|
||||||
@ -139,6 +141,7 @@ StoragesInfoStream::StoragesInfoStream(const SelectQueryInfo & query_info, Conte
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
String engine_name = storage->getName();
|
String engine_name = storage->getName();
|
||||||
|
UUID storage_uuid = storage->getStorageID().uuid;
|
||||||
|
|
||||||
#if USE_MYSQL
|
#if USE_MYSQL
|
||||||
if (auto * proxy = dynamic_cast<StorageMaterializedMySQL *>(storage.get()))
|
if (auto * proxy = dynamic_cast<StorageMaterializedMySQL *>(storage.get()))
|
||||||
@ -153,7 +156,7 @@ StoragesInfoStream::StoragesInfoStream(const SelectQueryInfo & query_info, Conte
|
|||||||
if (check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_name))
|
if (check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, database_name, table_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
storages[std::make_pair(database_name, iterator->name())] = storage;
|
storages[storage_uuid] = storage;
|
||||||
|
|
||||||
/// Add all combinations of flag 'active'.
|
/// Add all combinations of flag 'active'.
|
||||||
for (UInt64 active : {0, 1})
|
for (UInt64 active : {0, 1})
|
||||||
@ -161,6 +164,7 @@ StoragesInfoStream::StoragesInfoStream(const SelectQueryInfo & query_info, Conte
|
|||||||
table_column_mut->insert(table_name);
|
table_column_mut->insert(table_name);
|
||||||
engine_column_mut->insert(engine_name);
|
engine_column_mut->insert(engine_name);
|
||||||
active_column_mut->insert(active);
|
active_column_mut->insert(active);
|
||||||
|
storage_uuid_column_mut->insert(storage_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
offsets[i] += 2;
|
offsets[i] += 2;
|
||||||
@ -178,6 +182,7 @@ StoragesInfoStream::StoragesInfoStream(const SelectQueryInfo & query_info, Conte
|
|||||||
block_to_filter.insert(ColumnWithTypeAndName(std::move(table_column_mut), std::make_shared<DataTypeString>(), "table"));
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(table_column_mut), std::make_shared<DataTypeString>(), "table"));
|
||||||
block_to_filter.insert(ColumnWithTypeAndName(std::move(engine_column_mut), std::make_shared<DataTypeString>(), "engine"));
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(engine_column_mut), std::make_shared<DataTypeString>(), "engine"));
|
||||||
block_to_filter.insert(ColumnWithTypeAndName(std::move(active_column_mut), std::make_shared<DataTypeUInt8>(), "active"));
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(active_column_mut), std::make_shared<DataTypeUInt8>(), "active"));
|
||||||
|
block_to_filter.insert(ColumnWithTypeAndName(std::move(storage_uuid_column_mut), std::make_shared<DataTypeUUID>(), "uuid"));
|
||||||
|
|
||||||
if (rows)
|
if (rows)
|
||||||
{
|
{
|
||||||
@ -189,6 +194,7 @@ StoragesInfoStream::StoragesInfoStream(const SelectQueryInfo & query_info, Conte
|
|||||||
database_column = block_to_filter.getByName("database").column;
|
database_column = block_to_filter.getByName("database").column;
|
||||||
table_column = block_to_filter.getByName("table").column;
|
table_column = block_to_filter.getByName("table").column;
|
||||||
active_column = block_to_filter.getByName("active").column;
|
active_column = block_to_filter.getByName("active").column;
|
||||||
|
storage_uuid_column = block_to_filter.getByName("uuid").column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,11 +44,11 @@ public:
|
|||||||
|
|
||||||
info.database = (*database_column)[next_row].get<String>();
|
info.database = (*database_column)[next_row].get<String>();
|
||||||
info.table = (*table_column)[next_row].get<String>();
|
info.table = (*table_column)[next_row].get<String>();
|
||||||
|
UUID storage_uuid = (*storage_uuid_column)[next_row].get<UUID>();
|
||||||
|
|
||||||
auto is_same_table = [&info, this] (size_t row) -> bool
|
auto is_same_table = [&storage_uuid, this] (size_t row) -> bool
|
||||||
{
|
{
|
||||||
return (*database_column)[row].get<String>() == info.database &&
|
return (*storage_uuid_column)[row].get<UUID>() == storage_uuid;
|
||||||
(*table_column)[row].get<String>() == info.table;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// We may have two rows per table which differ in 'active' value.
|
/// We may have two rows per table which differ in 'active' value.
|
||||||
@ -61,7 +61,7 @@ public:
|
|||||||
info.need_inactive_parts = true;
|
info.need_inactive_parts = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.storage = storages.at(std::make_pair(info.database, info.table));
|
info.storage = storages.at(storage_uuid);
|
||||||
|
|
||||||
if (needsLock)
|
if (needsLock)
|
||||||
{
|
{
|
||||||
@ -94,11 +94,12 @@ protected:
|
|||||||
ColumnPtr database_column;
|
ColumnPtr database_column;
|
||||||
ColumnPtr table_column;
|
ColumnPtr table_column;
|
||||||
ColumnPtr active_column;
|
ColumnPtr active_column;
|
||||||
|
ColumnPtr storage_uuid_column;
|
||||||
|
|
||||||
size_t next_row;
|
size_t next_row;
|
||||||
size_t rows;
|
size_t rows;
|
||||||
|
|
||||||
using StoragesMap = std::map<std::pair<String, String>, StoragePtr>;
|
using StoragesMap = std::unordered_map<UUID, StoragePtr>;
|
||||||
StoragesMap storages;
|
StoragesMap storages;
|
||||||
|
|
||||||
bool needsLock = true;
|
bool needsLock = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user