mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
Use map for QueryKindAmounts
This commit is contained in:
parent
ae7e5691b8
commit
a8c83dce14
@ -505,38 +505,33 @@ ProcessList::UserInfo ProcessList::getUserInfo(bool get_profile_events) const
|
||||
return per_user_infos;
|
||||
}
|
||||
|
||||
void ProcessList::increaseQueryKindAmount(const IAST::QueryKind & query_kind) const
|
||||
void ProcessList::increaseQueryKindAmount(const IAST::QueryKind & query_kind)
|
||||
{
|
||||
if (query_kind == IAST::QueryKind::Insert)
|
||||
query_kind_amounts->insert++;
|
||||
else if (query_kind == IAST::QueryKind::Select)
|
||||
query_kind_amounts->select++;
|
||||
auto found = query_kind_amounts.find(query_kind);
|
||||
if (found == query_kind_amounts.end())
|
||||
query_kind_amounts[query_kind] = 1;
|
||||
else
|
||||
found->second += 1;
|
||||
}
|
||||
|
||||
void ProcessList::decreaseQueryKindAmount(const IAST::QueryKind & query_kind) const
|
||||
void ProcessList::decreaseQueryKindAmount(const IAST::QueryKind & query_kind)
|
||||
{
|
||||
if (!(query_kind == IAST::QueryKind::Insert || query_kind == IAST::QueryKind::Select))
|
||||
return;
|
||||
|
||||
QueryAmount amount = getQueryKindAmount(query_kind);
|
||||
if (amount == 0)
|
||||
{
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong query kind amount: decrease to negative on '{}'", query_kind, amount);
|
||||
}
|
||||
if (query_kind == IAST::QueryKind::Insert)
|
||||
query_kind_amounts->insert--;
|
||||
else if (query_kind == IAST::QueryKind::Select)
|
||||
query_kind_amounts->select--;
|
||||
auto found = query_kind_amounts.find(query_kind);
|
||||
/// TODO: we could just rebuild the map, as we have saved all query_kind.
|
||||
if (found == query_kind_amounts.end())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong query kind amount: decrease before increase on '{}'", query_kind);
|
||||
else if (found->second == 0)
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong query kind amount: decrease to negative on '{}'", query_kind, found->second);
|
||||
else
|
||||
found->second -= 1;
|
||||
}
|
||||
|
||||
ProcessList::QueryAmount ProcessList::getQueryKindAmount(const IAST::QueryKind & query_kind) const
|
||||
{
|
||||
if (query_kind == IAST::QueryKind::Insert)
|
||||
return query_kind_amounts->insert;
|
||||
else if (query_kind == IAST::QueryKind::Select)
|
||||
return query_kind_amounts->select;
|
||||
else
|
||||
auto found = query_kind_amounts.find(query_kind);
|
||||
if (found == query_kind_amounts.end())
|
||||
return 0;
|
||||
return found->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -271,11 +271,7 @@ public:
|
||||
/// User -> queries
|
||||
using UserToQueries = std::unordered_map<String, ProcessListForUser>;
|
||||
|
||||
struct QueryKindAmounts
|
||||
{
|
||||
QueryAmount insert;
|
||||
QueryAmount select;
|
||||
};
|
||||
using QueryKindAmounts = std::unordered_map<IAST::QueryKind, QueryAmount>;
|
||||
|
||||
protected:
|
||||
friend class ProcessListEntry;
|
||||
@ -306,10 +302,10 @@ protected:
|
||||
size_t max_select_queries_amount = 0;
|
||||
|
||||
/// amount of queries by query kind.
|
||||
QueryKindAmounts * query_kind_amounts = new QueryKindAmounts{0, 0};
|
||||
QueryKindAmounts query_kind_amounts;
|
||||
|
||||
void increaseQueryKindAmount(const IAST::QueryKind & query_kind) const;
|
||||
void decreaseQueryKindAmount(const IAST::QueryKind & query_kind) const;
|
||||
void increaseQueryKindAmount(const IAST::QueryKind & query_kind);
|
||||
void decreaseQueryKindAmount(const IAST::QueryKind & query_kind);
|
||||
QueryAmount getQueryKindAmount(const IAST::QueryKind & query_kind) const;
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user