提交 ae2cc175 编写于 作者: A Alexey Milovidov

Fixed potential performance issue in "Context::getTable" method

上级 b6870e09
......@@ -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();
}
......
......@@ -939,7 +939,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,7 +922,7 @@ 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;
......@@ -932,11 +932,11 @@ StoragePtr Context::getTable(const String & database_name, const String & table_
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册