Merge pull request #58195 from Unalian/feat-58127

Add InitialQuery event
This commit is contained in:
Alexey Milovidov 2024-02-13 23:51:03 +01:00 committed by GitHub
commit b9d3ae3b0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 1 deletions

View File

@ -8,6 +8,7 @@
M(Query, "Number of queries to be interpreted and potentially executed. Does not include queries that failed to parse or were rejected due to AST size limits, quota limits or limits on the number of simultaneously running queries. May include internal queries initiated by ClickHouse itself. Does not count subqueries.") \
M(SelectQuery, "Same as Query, but only for SELECT queries.") \
M(InsertQuery, "Same as Query, but only for INSERT queries.") \
M(InitialQuery, "Same as Query, but only counts initial queries (see is_initial_query).")\
M(QueriesWithSubqueries, "Count queries with all subqueries") \
M(SelectQueriesWithSubqueries, "Count SELECT queries with all subqueries") \
M(InsertQueriesWithSubqueries, "Count INSERT queries with all subqueries") \

View File

@ -65,6 +65,7 @@
namespace ProfileEvents
{
extern const Event Query;
extern const Event InitialQuery;
extern const Event QueriesWithSubqueries;
extern const Event SelectQuery;
extern const Event InsertQuery;
@ -94,7 +95,8 @@ void InterpreterFactory::registerInterpreter(const std::string & name, CreatorFn
InterpreterFactory::InterpreterPtr InterpreterFactory::get(ASTPtr & query, ContextMutablePtr context, const SelectQueryOptions & options)
{
ProfileEvents::increment(ProfileEvents::Query);
if (context->getClientInfo().query_kind == ClientInfo::QueryKind::INITIAL_QUERY)
ProfileEvents::increment(ProfileEvents::InitialQuery);
/// SELECT and INSERT query will handle QueriesWithSubqueries on their own.
if (!(query->as<ASTSelectQuery>() ||
query->as<ASTSelectWithUnionQuery>() ||

View File

@ -0,0 +1,6 @@
Local situation
Initial Query Difference: 1
Query Difference: 1
Distributed situation
Initial Query Difference: 1
Query Difference: 3

View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Tags:no-parallel,shard
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
# CREATE TABLE local (x UInt8) Engine=Memory;
# CREATE TABLE distributed ON CLUSTER cluster (p Date, i Int32) ENGINE = Distributed(test_cluster_two_shards, currentDatabase(), x)
$CLICKHOUSE_CLIENT -n -q "
DROP TABLE IF EXISTS local;
DROP TABLE IF EXISTS distributed;
CREATE TABLE local (x UInt8) Engine=Memory;
CREATE TABLE distributed AS local ENGINE = Distributed(test_cluster_two_shards, currentDatabase(), local, x);
INSERT INTO distributed SELECT number FROM numbers(10);
SYSTEM FLUSH DISTRIBUTED distributed;
"
echo "Local situation"
# before SELECT * FROM local
query_countI=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'InitialQuery'")
query_countQ=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'Query'")
# Execute SELECT * FROM local
$CLICKHOUSE_CLIENT -q "SELECT * FROM local" > /dev/null
# Counts after SELECT * FROM local
After_query_countI=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'InitialQuery'")
After_query_countQ=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'Query'")
# Calculate the differences
Initial_query_diff=$(($After_query_countI-$query_countI-2))
query_diff=$(($After_query_countQ-$query_countQ-2))
echo "Initial Query Difference: $Initial_query_diff"
echo "Query Difference: $query_diff"
echo "Distributed situation"
# before SELECT * FROM distributed
query_countI=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'InitialQuery'")
query_countQ=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'Query'")
# Execute SELECT * FROM distributed
$CLICKHOUSE_CLIENT -q "SELECT * FROM distributed SETTINGS prefer_localhost_replica = 0" > /dev/null
# Counts after SELECT * FROM distributed
After_query_countI=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'InitialQuery'")
After_query_countQ=$($CLICKHOUSE_CLIENT -q "SELECT value FROM system.events WHERE event = 'Query'")
# Calculate the differences
Initial_query_diff=$(($After_query_countI-$query_countI-2))
query_diff=$(($After_query_countQ-$query_countQ-2))
echo "Initial Query Difference: $Initial_query_diff"
echo "Query Difference: $query_diff"