mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Merge pull request #58195 from Unalian/feat-58127
Add InitialQuery event
This commit is contained in:
commit
b9d3ae3b0a
@ -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") \
|
||||
|
@ -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>() ||
|
||||
|
@ -0,0 +1,6 @@
|
||||
Local situation
|
||||
Initial Query Difference: 1
|
||||
Query Difference: 1
|
||||
Distributed situation
|
||||
Initial Query Difference: 1
|
||||
Query Difference: 3
|
53
tests/queries/0_stateless/02950_distributed_initial_query_event.sh
Executable file
53
tests/queries/0_stateless/02950_distributed_initial_query_event.sh
Executable 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"
|
Loading…
Reference in New Issue
Block a user