Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: Fix TiFlash system tables cannot query in Keyspace Mode #9370

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions dbms/src/Interpreters/InterpreterSelectQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,19 @@ void InterpreterSelectQuery::getAndLockStorageWithSchemaVersion(const String & d
// always sync schema first and then read table
const String qualified_name = database_name + "." + table_name;

bool need_sync_schema = true;
if (database_name == "system")
need_sync_schema = false;
else if (database_name.empty() && context.getCurrentDatabase() == "system")
need_sync_schema = false;

{
auto start_time = Clock::now();
// Since InterpreterSelectQuery will only be trigger while using ClickHouse client,
// and we do not support keyspace feature for ClickHouse interface,
// we could use nullspace id here safely.
context.getTMTContext().getSchemaSyncerManager()->syncSchemas(context, NullspaceID);
if (need_sync_schema)
context.getTMTContext().getSchemaSyncerManager()->syncSchemas(context, NullspaceID);
auto storage_tmp = context.getTable(database_name, table_name);
auto managed_storage = std::dynamic_pointer_cast<IManageableStorage>(storage_tmp);
if (!managed_storage
Expand All @@ -243,10 +249,11 @@ void InterpreterSelectQuery::getAndLockStorageWithSchemaVersion(const String & d
return;
}

context.getTMTContext().getSchemaSyncerManager()->syncTableSchema(
context,
NullspaceID,
managed_storage->getTableInfo().id);
if (need_sync_schema)
context.getTMTContext().getSchemaSyncerManager()->syncTableSchema(
context,
NullspaceID,
managed_storage->getTableInfo().id);
auto schema_sync_cost
= std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_time).count();
LOG_DEBUG(log, "Table {} schema sync cost {}ms.", qualified_name, schema_sync_cost);
Expand Down