Answer
Thequery_log table in the system database keeps track of all your queries, including:
- how much memory the query consumed, and
- how much CPU time was needed
The
initial_query_id represents the ID of the initial query for distributed query execution launched from the node receiving the request. The query_id contains the ID of the child query executed on a different node. See this article for more details.youtube (see the YouTube dislikes dataset):
initial_query_id VS query_id
Note that in a clustered ClickHouse environment (like ClickHouse Cloud)initial_query_id represents the ID of the initial query for distributed query execution launched from the node receiving the request;
then query_id field will contain the ID of the child query executed on a different node.
Distributed execution is not the only source of differing
query_id valuesA single query can also spawn internal sub-queries that are logged with their own query_id and is_initial_query = 0 — most commonly the internal queries ClickHouse runs to evaluate views. These internal identifiers are assigned by ClickHouse and may not follow the same format as the one reported to your client; for view-related steps you may see query_id values that include a label such as queryView.... When you want the query exactly as you submitted it, filter on is_initial_query = 1 (or query_id = initial_query_id). This is server-side behaviour of query_log and is the same from any client, including the Cloud SQL Console.query_id to the above query we pin our search around initial_query_id = a7262fa2-bd8b-4b51-a359-621ccf282417 and hostname():
query_id != initial_query_id condition to the WHERE clause:
query_id = initial_query_id will return only the queries executed on the local node where the distributed query was first thrown at: