Search code examples
clickhouse

How to retrieve the number of rows processed in a clickhouse query statement?


In this Doc, clickhouse not only shows the result of a query, but also the number of rows processed.

enter image description here

But when I use clickhouse client, I could not get the number of rows processed.

enter image description here

How to get it?


Solution

  • not exactly the same effect that you want, but you can use --send-logs-level debug parameter when launching clickhouse client:

    ch :) select * from audit.logs where actor_id='373';
    
    SELECT *
    FROM audit.logs
    WHERE actor_id = '373'
    
    Query id: cd687787-9e04-4cc6-8fe6-7f6981397cc4
    
    [9aae324dd352] 2024.05.15 15:28:45.959813 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> executeQuery: (from 127.0.0.1:36514) select * from audit.logs where actor_id='373'; (stage: Complete)
    [9aae324dd352] 2024.05.15 15:28:45.960487 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> InterpreterSelectQuery: MergeTreeWhereOptimizer: condition "actor_id = '373'" moved to PREWHERE
    [9aae324dd352] 2024.05.15 15:28:45.961485 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> audit.logs (e564b12e-6d1f-44d5-abfe-6a85fd88aaf8) (SelectExecutor): Key condition: unknown
    [9aae324dd352] 2024.05.15 15:28:45.963353 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> audit.logs (e564b12e-6d1f-44d5-abfe-6a85fd88aaf8) (SelectExecutor): Index `actor_id_idx` has dropped 5/9 granules.
    [9aae324dd352] 2024.05.15 15:28:45.963404 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> audit.logs (e564b12e-6d1f-44d5-abfe-6a85fd88aaf8) (SelectExecutor): Selected 6/6 parts by partition key, 1 parts by primary key, 9/9 marks by primary key, 4 marks to read from 1 ranges
    ┌───────────timestamp─┬─action────────┬─actor_id─┬─actor_type─┬─actor_ip─────┬─target_id─┬─target_type─┬─details───┬─metadata─┐
    │ 2024-05-15 14:53:37 │ order_paid    │ 373      │ employee   │ 172.16.17.32 │           │             │ {'a':'d'} │ {}       │
    │ 2024-05-15 15:27:47 │ order_created │ 373      │ user       │              │           │             │ {'a':'d'} │ {}       │
    │ 2024-05-15 15:27:48 │ order_paid    │ 373      │ employee   │ 172.16.17.32 │           │             │ {'b':'d'} │ {}       │
    ...
    
    [9aae324dd352] 2024.05.15 15:28:45.981813 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> executeQuery: Read 28345 rows, 1.89 MiB in 0.022096 sec., 1282811.3685734975 rows/sec., 85.50 MiB/sec.
    [9aae324dd352] 2024.05.15 15:28:45.981996 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> MemoryTracker: Peak memory usage (for query): 297.84 KiB.
    [9aae324dd352] 2024.05.15 15:28:45.982020 [ 38 ] {cd687787-9e04-4cc6-8fe6-7f6981397cc4} <Debug> TCPHandler: Processed in 0.022632627 sec.