2018-05-31 15:54:08 +00:00
|
|
|
#include "QueryThreadLog.h"
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <array>
|
2018-05-31 15:54:08 +00:00
|
|
|
#include <Columns/ColumnFixedString.h>
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Columns/ColumnsNumber.h>
|
2018-05-31 15:54:08 +00:00
|
|
|
#include <DataTypes/DataTypeArray.h>
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <DataTypes/DataTypeDate.h>
|
2021-01-05 10:10:19 +00:00
|
|
|
#include <DataTypes/DataTypeMap.h>
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime64.h>
|
2019-06-15 14:20:32 +00:00
|
|
|
#include <DataTypes/DataTypeFactory.h>
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2018-06-20 17:49:52 +00:00
|
|
|
#include <Interpreters/ProfileEventsExt.h>
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <Interpreters/QueryLog.h>
|
2018-05-31 15:54:08 +00:00
|
|
|
#include <Poco/Net/IPAddress.h>
|
2020-08-18 21:41:01 +00:00
|
|
|
#include <Common/ClickHouseRevision.h>
|
2018-05-31 15:54:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-06-28 11:42:21 +00:00
|
|
|
|
|
|
|
NamesAndTypesList QueryThreadLogElement::getNamesAndTypes()
|
2018-05-31 15:54:08 +00:00
|
|
|
{
|
2020-08-18 21:41:01 +00:00
|
|
|
return {
|
2021-06-28 11:42:21 +00:00
|
|
|
{"event_date", std::make_shared<DataTypeDate>()},
|
|
|
|
{"event_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"event_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
|
|
|
{"query_start_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"query_start_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
|
|
|
{"query_duration_ms", std::make_shared<DataTypeUInt64>()},
|
2020-08-18 21:41:01 +00:00
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
{"read_rows", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"read_bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"written_rows", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"written_bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"memory_usage", std::make_shared<DataTypeInt64>()},
|
|
|
|
{"peak_memory_usage", std::make_shared<DataTypeInt64>()},
|
2020-08-18 21:41:01 +00:00
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
{"thread_name", std::make_shared<DataTypeString>()},
|
|
|
|
{"thread_id", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"master_thread_id", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"current_database", std::make_shared<DataTypeString>()},
|
|
|
|
{"query", std::make_shared<DataTypeString>()},
|
|
|
|
{"normalized_query_hash", std::make_shared<DataTypeUInt64>()},
|
2020-08-18 21:41:01 +00:00
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
{"is_initial_query", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"user", std::make_shared<DataTypeString>()},
|
|
|
|
{"query_id", std::make_shared<DataTypeString>()},
|
|
|
|
{"address", DataTypeFactory::instance().get("IPv6")},
|
|
|
|
{"port", std::make_shared<DataTypeUInt16>()},
|
|
|
|
{"initial_user", std::make_shared<DataTypeString>()},
|
|
|
|
{"initial_query_id", std::make_shared<DataTypeString>()},
|
|
|
|
{"initial_address", DataTypeFactory::instance().get("IPv6")},
|
|
|
|
{"initial_port", std::make_shared<DataTypeUInt16>()},
|
|
|
|
{"initial_query_start_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"initial_query_start_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
|
|
|
{"interface", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"os_user", std::make_shared<DataTypeString>()},
|
|
|
|
{"client_hostname", std::make_shared<DataTypeString>()},
|
|
|
|
{"client_name", std::make_shared<DataTypeString>()},
|
|
|
|
{"client_revision", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"client_version_major", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"client_version_minor", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"client_version_patch", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"http_method", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"http_user_agent", std::make_shared<DataTypeString>()},
|
|
|
|
{"http_referer", std::make_shared<DataTypeString>()},
|
|
|
|
{"forwarded_for", std::make_shared<DataTypeString>()},
|
|
|
|
{"quota_key", std::make_shared<DataTypeString>()},
|
2020-08-18 21:41:01 +00:00
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
{"revision", std::make_shared<DataTypeUInt32>()},
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
{"ProfileEvents", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeUInt64>())},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
NamesAndAliases QueryThreadLogElement::getNamesAndAliases()
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{"ProfileEvents.Names", {std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())}, "mapKeys(ProfileEvents)"},
|
|
|
|
{"ProfileEvents.Values", {std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>())}, "mapValues(ProfileEvents)"}
|
2020-09-04 17:12:17 +00:00
|
|
|
};
|
2018-05-31 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 20:15:18 +00:00
|
|
|
void QueryThreadLogElement::appendToBlock(MutableColumns & columns) const
|
2018-05-31 15:54:08 +00:00
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
2020-04-17 13:26:44 +00:00
|
|
|
columns[i++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType());
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(event_time);
|
2020-09-11 16:51:24 +00:00
|
|
|
columns[i++]->insert(event_time_microseconds);
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(query_start_time);
|
2020-08-18 21:41:01 +00:00
|
|
|
columns[i++]->insert(query_start_time_microseconds);
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(query_duration_ms);
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(read_rows);
|
|
|
|
columns[i++]->insert(read_bytes);
|
|
|
|
columns[i++]->insert(written_rows);
|
|
|
|
columns[i++]->insert(written_bytes);
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(memory_usage);
|
|
|
|
columns[i++]->insert(peak_memory_usage);
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2018-06-01 11:58:17 +00:00
|
|
|
columns[i++]->insertData(thread_name.data(), thread_name.size());
|
2020-02-02 02:27:15 +00:00
|
|
|
columns[i++]->insert(thread_id);
|
|
|
|
columns[i++]->insert(master_thread_id);
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2020-10-30 18:16:10 +00:00
|
|
|
columns[i++]->insertData(current_database.data(), current_database.size());
|
2018-05-31 15:54:08 +00:00
|
|
|
columns[i++]->insertData(query.data(), query.size());
|
2020-12-02 12:08:03 +00:00
|
|
|
columns[i++]->insert(normalized_query_hash);
|
2018-05-31 15:54:08 +00:00
|
|
|
|
|
|
|
QueryLogElement::appendClientInfo(client_info, columns, i);
|
|
|
|
|
2020-09-17 12:15:05 +00:00
|
|
|
columns[i++]->insert(ClickHouseRevision::getVersionRevision());
|
2018-05-31 15:54:08 +00:00
|
|
|
|
|
|
|
if (profile_counters)
|
|
|
|
{
|
2021-01-05 10:10:19 +00:00
|
|
|
auto * column = columns[i++].get();
|
|
|
|
ProfileEvents::dumpToMapColumn(*profile_counters, column, true);
|
2018-05-31 15:54:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
columns[i++]->insertDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|