mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Add ability to pass QueryKind via clickhouse-client/local (useful for debugging)
v2: fix LocalConnection::sendQuery() for Suggest (comes w/o client_info) [1] [1]: https://s3.amazonaws.com/clickhouse-test-reports/37290/7c85175963226ff78eec542efafcff4e650aa0f0/stateless_tests__ubsan__actions_.html Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
parent
54a6aaef62
commit
29a8a00656
@ -34,6 +34,12 @@ CLICKHOUSE_QueryProcessingStage=(
|
|||||||
with_mergeable_state_after_aggregation_and_limit
|
with_mergeable_state_after_aggregation_and_limit
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CLICKHOUSE_QueryKind=(
|
||||||
|
initial_query
|
||||||
|
secondary_query
|
||||||
|
no_query
|
||||||
|
)
|
||||||
|
|
||||||
CLICKHOUSE_Format=(
|
CLICKHOUSE_Format=(
|
||||||
CapnProto
|
CapnProto
|
||||||
PostgreSQLWire
|
PostgreSQLWire
|
||||||
@ -124,6 +130,10 @@ function _complete_for_clickhouse_generic_bin_impl()
|
|||||||
COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryProcessingStage[*]}" -- "$cur") )
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryProcessingStage[*]}" -- "$cur") )
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
|
--query_kind)
|
||||||
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryKind[*]}" -- "$cur") )
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
--send_logs_level)
|
--send_logs_level)
|
||||||
COMPREPLY=( $(compgen -W "${CLICKHOUSE_logs_level[*]}" -- "$cur") )
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_logs_level[*]}" -- "$cur") )
|
||||||
return 1
|
return 1
|
||||||
|
@ -1038,6 +1038,7 @@ void Client::processConfig()
|
|||||||
ClientInfo & client_info = global_context->getClientInfo();
|
ClientInfo & client_info = global_context->getClientInfo();
|
||||||
client_info.setInitialQuery();
|
client_info.setInitialQuery();
|
||||||
client_info.quota_key = config().getString("quota_key", "");
|
client_info.quota_key = config().getString("quota_key", "");
|
||||||
|
client_info.query_kind = query_kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -626,6 +626,7 @@ void LocalServer::processConfig()
|
|||||||
|
|
||||||
ClientInfo & client_info = global_context->getClientInfo();
|
ClientInfo & client_info = global_context->getClientInfo();
|
||||||
client_info.setInitialQuery();
|
client_info.setInitialQuery();
|
||||||
|
client_info.query_kind = query_kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,6 +119,17 @@ namespace ProfileEvents
|
|||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static ClientInfo::QueryKind parseQueryKind(const String & query_kind)
|
||||||
|
{
|
||||||
|
if (query_kind == "initial_query")
|
||||||
|
return ClientInfo::QueryKind::INITIAL_QUERY;
|
||||||
|
if (query_kind == "secondary_query")
|
||||||
|
return ClientInfo::QueryKind::SECONDARY_QUERY;
|
||||||
|
if (query_kind == "no_query")
|
||||||
|
return ClientInfo::QueryKind::NO_QUERY;
|
||||||
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unknown query kind {}", query_kind);
|
||||||
|
}
|
||||||
|
|
||||||
static void incrementProfileEventsBlock(Block & dst, const Block & src)
|
static void incrementProfileEventsBlock(Block & dst, const Block & src)
|
||||||
{
|
{
|
||||||
if (!dst)
|
if (!dst)
|
||||||
@ -2125,6 +2136,7 @@ void ClientBase::init(int argc, char ** argv)
|
|||||||
|
|
||||||
("query,q", po::value<std::string>(), "query")
|
("query,q", po::value<std::string>(), "query")
|
||||||
("stage", po::value<std::string>()->default_value("complete"), "Request query processing up to specified stage: complete,fetch_columns,with_mergeable_state,with_mergeable_state_after_aggregation,with_mergeable_state_after_aggregation_and_limit")
|
("stage", po::value<std::string>()->default_value("complete"), "Request query processing up to specified stage: complete,fetch_columns,with_mergeable_state,with_mergeable_state_after_aggregation,with_mergeable_state_after_aggregation_and_limit")
|
||||||
|
("query_kind", po::value<std::string>()->default_value("initial_query"), "One of initial_query/secondary_query/no_query")
|
||||||
("query_id", po::value<std::string>(), "query_id")
|
("query_id", po::value<std::string>(), "query_id")
|
||||||
("progress", "print progress of queries execution")
|
("progress", "print progress of queries execution")
|
||||||
|
|
||||||
@ -2255,6 +2267,7 @@ void ClientBase::init(int argc, char ** argv)
|
|||||||
server_logs_file = options["server_logs_file"].as<std::string>();
|
server_logs_file = options["server_logs_file"].as<std::string>();
|
||||||
|
|
||||||
query_processing_stage = QueryProcessingStage::fromString(options["stage"].as<std::string>());
|
query_processing_stage = QueryProcessingStage::fromString(options["stage"].as<std::string>());
|
||||||
|
query_kind = parseQueryKind(options["query_kind"].as<std::string>());
|
||||||
profile_events.print = options.count("print-profile-events");
|
profile_events.print = options.count("print-profile-events");
|
||||||
profile_events.delay_ms = options["profile-events-delay-ms"].as<UInt64>();
|
profile_events.delay_ms = options["profile-events-delay-ms"].as<UInt64>();
|
||||||
|
|
||||||
|
@ -256,6 +256,7 @@ protected:
|
|||||||
} profile_events;
|
} profile_events;
|
||||||
|
|
||||||
QueryProcessingStage::Enum query_processing_stage;
|
QueryProcessingStage::Enum query_processing_stage;
|
||||||
|
ClientInfo::QueryKind query_kind;
|
||||||
|
|
||||||
bool fake_drop = false;
|
bool fake_drop = false;
|
||||||
|
|
||||||
|
@ -73,10 +73,14 @@ void LocalConnection::sendQuery(
|
|||||||
const String & query_id,
|
const String & query_id,
|
||||||
UInt64 stage,
|
UInt64 stage,
|
||||||
const Settings *,
|
const Settings *,
|
||||||
const ClientInfo *,
|
const ClientInfo * client_info,
|
||||||
bool,
|
bool,
|
||||||
std::function<void(const Progress &)> process_progress_callback)
|
std::function<void(const Progress &)> process_progress_callback)
|
||||||
{
|
{
|
||||||
|
/// Suggestion comes without client_info.
|
||||||
|
if (client_info)
|
||||||
|
query_context = session.makeQueryContext(*client_info);
|
||||||
|
else
|
||||||
query_context = session.makeQueryContext();
|
query_context = session.makeQueryContext();
|
||||||
query_context->setCurrentQueryId(query_id);
|
query_context->setCurrentQueryId(query_id);
|
||||||
if (send_progress)
|
if (send_progress)
|
||||||
|
44
tests/queries/0_stateless/02303_query_kind.reference
Normal file
44
tests/queries/0_stateless/02303_query_kind.reference
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
clickhouse-client --query_kind secondary_query -q explain plan header=1 select toString(dummy) as dummy from system.one group by dummy
|
||||||
|
Expression ((Projection + Before ORDER BY))
|
||||||
|
Header: dummy String
|
||||||
|
Aggregating
|
||||||
|
Header: toString(dummy) String
|
||||||
|
Expression (Before GROUP BY)
|
||||||
|
Header: toString(dummy) String
|
||||||
|
SettingQuotaAndLimits (Set limits and quota after reading from storage)
|
||||||
|
Header: dummy UInt8
|
||||||
|
ReadFromStorage (SystemOne)
|
||||||
|
Header: dummy UInt8
|
||||||
|
clickhouse-local --query_kind secondary_query -q explain plan header=1 select toString(dummy) as dummy from system.one group by dummy
|
||||||
|
Expression ((Projection + Before ORDER BY))
|
||||||
|
Header: dummy String
|
||||||
|
Aggregating
|
||||||
|
Header: toString(dummy) String
|
||||||
|
Expression (Before GROUP BY)
|
||||||
|
Header: toString(dummy) String
|
||||||
|
SettingQuotaAndLimits (Set limits and quota after reading from storage)
|
||||||
|
Header: dummy UInt8
|
||||||
|
ReadFromStorage (SystemOne)
|
||||||
|
Header: dummy UInt8
|
||||||
|
clickhouse-client --query_kind initial_query -q explain plan header=1 select toString(dummy) as dummy from system.one group by dummy
|
||||||
|
Expression ((Projection + Before ORDER BY))
|
||||||
|
Header: dummy String
|
||||||
|
Aggregating
|
||||||
|
Header: dummy UInt8
|
||||||
|
Expression (Before GROUP BY)
|
||||||
|
Header: dummy UInt8
|
||||||
|
SettingQuotaAndLimits (Set limits and quota after reading from storage)
|
||||||
|
Header: dummy UInt8
|
||||||
|
ReadFromStorage (SystemOne)
|
||||||
|
Header: dummy UInt8
|
||||||
|
clickhouse-local --query_kind initial_query -q explain plan header=1 select toString(dummy) as dummy from system.one group by dummy
|
||||||
|
Expression ((Projection + Before ORDER BY))
|
||||||
|
Header: dummy String
|
||||||
|
Aggregating
|
||||||
|
Header: dummy UInt8
|
||||||
|
Expression (Before GROUP BY)
|
||||||
|
Header: dummy UInt8
|
||||||
|
SettingQuotaAndLimits (Set limits and quota after reading from storage)
|
||||||
|
Header: dummy UInt8
|
||||||
|
ReadFromStorage (SystemOne)
|
||||||
|
Header: dummy UInt8
|
16
tests/queries/0_stateless/02303_query_kind.sh
Executable file
16
tests/queries/0_stateless/02303_query_kind.sh
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
# shellcheck source=../shell_config.sh
|
||||||
|
. "$CUR_DIR"/../shell_config.sh
|
||||||
|
|
||||||
|
function run_query()
|
||||||
|
{
|
||||||
|
echo "clickhouse-client $*"
|
||||||
|
$CLICKHOUSE_CLIENT "$@"
|
||||||
|
|
||||||
|
echo "clickhouse-local $*"
|
||||||
|
$CLICKHOUSE_LOCAL "$@"
|
||||||
|
}
|
||||||
|
run_query --query_kind secondary_query -q "explain plan header=1 select toString(dummy) as dummy from system.one group by dummy"
|
||||||
|
run_query --query_kind initial_query -q "explain plan header=1 select toString(dummy) as dummy from system.one group by dummy"
|
Loading…
Reference in New Issue
Block a user