v.21.9New Feature

Add functions to return current query's initial query ID, closes #23682

Add functions that return (initial_)query_id of the current query. This closes #23682. #26410 (Alexey Boykov).
Added new functions to return the query_id and initial_query_id of the current running query in ClickHouse.

Why it matters

This feature allows users to retrieve the unique identifier of the current query being executed, which helps in tracking, logging, and debugging queries more effectively. Access to initial_query_id provides insight into the original query in cases where queries are internally reprocessed or forwarded.

How to use it

Users can call the new functions query_id() and initial_query_id() directly in their SQL queries to obtain the respective query IDs, for example:

SELECT query_id(), initial_query_id() FROM system.one;