use qualified dictionary name in query log

This commit is contained in:
Eduard Karacharov 2024-05-09 11:06:31 +03:00
parent eedef6d826
commit a365c36e9d
5 changed files with 25 additions and 14 deletions

View File

@ -108,7 +108,7 @@ Columns:
- `used_aggregate_function_combinators` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `aggregate functions combinators`, which were used during query execution.
- `used_database_engines` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `database engines`, which were used during query execution.
- `used_data_type_families` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `data type families`, which were used during query execution.
- `used_dictionaries` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `dictionaries`, which were used during query execution.
- `used_dictionaries` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `dictionaries`, which were used during query execution. For dictionaries configured using an XML file this is the name of the dictionary, and for dictionaries created by an SQL statement, the canonical name is the fully qualified object name.
- `used_formats` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `formats`, which were used during query execution.
- `used_functions` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `functions`, which were used during query execution.
- `used_storages` ([Array(String)](../../sql-reference/data-types/array.md)) — Canonical names of `storages`, which were used during query execution.

View File

@ -69,6 +69,15 @@ public:
return dictionary_id.getNameForLogs();
}
/// Returns fully qualified unquoted dictionary name
std::string getQualifiedName() const
{
std::lock_guard lock{mutex};
if (dictionary_id.database_name.empty())
return dictionary_id.table_name;
return dictionary_id.database_name + "." + dictionary_id.table_name;
}
StorageID getDictionaryID() const
{
std::lock_guard lock{mutex};

View File

@ -77,21 +77,23 @@ void ExternalDictionariesLoader::updateObjectFromConfigWithoutReloading(IExterna
ExternalDictionariesLoader::DictPtr ExternalDictionariesLoader::getDictionary(const std::string & dictionary_name, ContextPtr local_context) const
{
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name, local_context->getCurrentDatabase());
auto dictionary = std::static_pointer_cast<const IDictionary>(load(resolved_dictionary_name));
if (local_context->hasQueryContext() && local_context->getSettingsRef().log_queries)
local_context->getQueryContext()->addQueryFactoriesInfo(Context::QueryLogFactories::Dictionary, resolved_dictionary_name);
local_context->getQueryContext()->addQueryFactoriesInfo(Context::QueryLogFactories::Dictionary, dictionary->getQualifiedName());
return std::static_pointer_cast<const IDictionary>(load(resolved_dictionary_name));
return dictionary;
}
ExternalDictionariesLoader::DictPtr ExternalDictionariesLoader::tryGetDictionary(const std::string & dictionary_name, ContextPtr local_context) const
{
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name, local_context->getCurrentDatabase());
auto dictionary = std::static_pointer_cast<const IDictionary>(tryLoad(resolved_dictionary_name));
if (local_context->hasQueryContext() && local_context->getSettingsRef().log_queries)
local_context->getQueryContext()->addQueryFactoriesInfo(Context::QueryLogFactories::Dictionary, resolved_dictionary_name);
if (local_context->hasQueryContext() && local_context->getSettingsRef().log_queries && dictionary)
local_context->getQueryContext()->addQueryFactoriesInfo(Context::QueryLogFactories::Dictionary, dictionary->getQualifiedName());
return std::static_pointer_cast<const IDictionary>(tryLoad(resolved_dictionary_name));
return dictionary;
}

View File

@ -1,4 +1,4 @@
simple_with_analyzer 1
nested_with_analyzer 1
simple_without_analyzer 1
nested_without_analyzer 1
simple_with_analyzer ['default.03148_dictionary']
nested_with_analyzer ['default.03148_dictionary']
simple_without_analyzer ['default.03148_dictionary']
nested_without_analyzer ['default.03148_dictionary']

View File

@ -21,7 +21,7 @@ FORMAT Null;
SYSTEM FLUSH LOGS;
SELECT 'simple_with_analyzer', length(used_dictionaries) as used_dictionaries_qty
SELECT log_comment, used_dictionaries
FROM system.query_log
WHERE current_database = currentDatabase()
AND type = 'QueryFinish'
@ -40,7 +40,7 @@ FORMAT Null;
SYSTEM FLUSH LOGS;
SELECT 'nested_with_analyzer', length(used_dictionaries) as used_dictionaries_qty
SELECT log_comment, used_dictionaries
FROM system.query_log
WHERE current_database = currentDatabase()
AND type = 'QueryFinish'
@ -56,7 +56,7 @@ FORMAT Null;
SYSTEM FLUSH LOGS;
SELECT 'simple_without_analyzer', length(used_dictionaries) as used_dictionaries_qty
SELECT log_comment, used_dictionaries
FROM system.query_log
WHERE current_database = currentDatabase()
AND type = 'QueryFinish'
@ -75,7 +75,7 @@ FORMAT Null;
SYSTEM FLUSH LOGS;
SELECT 'nested_without_analyzer', length(used_dictionaries) as used_dictionaries_qty
SELECT log_comment, used_dictionaries
FROM system.query_log
WHERE current_database = currentDatabase()
AND type = 'QueryFinish'