mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #8538 from ClickHouse/get-table-performance-issue
Fixed potential performance issue in "Context::getTable" method
This commit is contained in:
commit
701dde5a12
@ -774,9 +774,7 @@ std::unique_ptr<Exception> Connection::receiveException()
|
||||
{
|
||||
//LOG_TRACE(log_wrapper.get(), "Receiving exception");
|
||||
|
||||
Exception e;
|
||||
readException(e, *in, "Received from " + getDescription());
|
||||
return std::unique_ptr<Exception>{ e.clone() };
|
||||
return std::make_unique<Exception>(readException(*in, "Received from " + getDescription()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -959,7 +959,7 @@ void skipJSONField(ReadBuffer & buf, const StringRef & name_of_field)
|
||||
}
|
||||
|
||||
|
||||
void readException(Exception & e, ReadBuffer & buf, const String & additional_message)
|
||||
Exception readException(ReadBuffer & buf, const String & additional_message)
|
||||
{
|
||||
int code = 0;
|
||||
String name;
|
||||
@ -986,14 +986,12 @@ void readException(Exception & e, ReadBuffer & buf, const String & additional_me
|
||||
if (!stack_trace.empty())
|
||||
out << " Stack trace:\n\n" << stack_trace;
|
||||
|
||||
e = Exception(out.str(), code);
|
||||
return Exception(out.str(), code);
|
||||
}
|
||||
|
||||
void readAndThrowException(ReadBuffer & buf, const String & additional_message)
|
||||
{
|
||||
Exception e;
|
||||
readException(e, buf, additional_message);
|
||||
e.rethrow();
|
||||
readException(buf, additional_message).rethrow();
|
||||
}
|
||||
|
||||
|
||||
|
@ -930,7 +930,7 @@ void skipJSONField(ReadBuffer & buf, const StringRef & name_of_field);
|
||||
* (type is cut to base class, 'message' replaced by 'displayText', and stack trace is appended to 'message')
|
||||
* Some additional message could be appended to exception (example: you could add information about from where it was received).
|
||||
*/
|
||||
void readException(Exception & e, ReadBuffer & buf, const String & additional_message = "");
|
||||
Exception readException(ReadBuffer & buf, const String & additional_message = "");
|
||||
void readAndThrowException(ReadBuffer & buf, const String & additional_message = "");
|
||||
|
||||
|
||||
|
@ -922,21 +922,21 @@ StoragePtr Context::tryGetExternalTable(const String & table_name) const
|
||||
|
||||
StoragePtr Context::getTable(const String & database_name, const String & table_name) const
|
||||
{
|
||||
Exception exc;
|
||||
std::optional<Exception> exc;
|
||||
auto res = getTableImpl(database_name, table_name, &exc);
|
||||
if (!res)
|
||||
throw exc;
|
||||
throw *exc;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
StoragePtr Context::tryGetTable(const String & database_name, const String & table_name) const
|
||||
{
|
||||
return getTableImpl(database_name, table_name, nullptr);
|
||||
return getTableImpl(database_name, table_name, {});
|
||||
}
|
||||
|
||||
|
||||
StoragePtr Context::getTableImpl(const String & database_name, const String & table_name, Exception * exception) const
|
||||
StoragePtr Context::getTableImpl(const String & database_name, const String & table_name, std::optional<Exception> * exception) const
|
||||
{
|
||||
String db;
|
||||
DatabasePtr database;
|
||||
@ -958,7 +958,7 @@ StoragePtr Context::getTableImpl(const String & database_name, const String & ta
|
||||
if (shared->databases.end() == it)
|
||||
{
|
||||
if (exception)
|
||||
*exception = Exception("Database " + backQuoteIfNeed(db) + " doesn't exist", ErrorCodes::UNKNOWN_DATABASE);
|
||||
exception->emplace("Database " + backQuoteIfNeed(db) + " doesn't exist", ErrorCodes::UNKNOWN_DATABASE);
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -969,7 +969,7 @@ StoragePtr Context::getTableImpl(const String & database_name, const String & ta
|
||||
if (!table)
|
||||
{
|
||||
if (exception)
|
||||
*exception = Exception("Table " + backQuoteIfNeed(db) + "." + backQuoteIfNeed(table_name) + " doesn't exist.", ErrorCodes::UNKNOWN_TABLE);
|
||||
exception->emplace("Table " + backQuoteIfNeed(db) + "." + backQuoteIfNeed(table_name) + " doesn't exist.", ErrorCodes::UNKNOWN_TABLE);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ private:
|
||||
|
||||
EmbeddedDictionaries & getEmbeddedDictionariesImpl(bool throw_on_error) const;
|
||||
|
||||
StoragePtr getTableImpl(const String & database_name, const String & table_name, Exception * exception) const;
|
||||
StoragePtr getTableImpl(const String & database_name, const String & table_name, std::optional<Exception> * exception) const;
|
||||
|
||||
SessionKey getSessionKey(const String & session_id) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user