1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| with query_tmp AS ( SELECT user, query_duration_ms, normalized_query_hash, tables, read_rows, memory_usage, event_time FROM clusterAllReplicas(xxx, system.query_log) PREWHERE (event_time >= (now() - toIntervalHour(1))) AND hasAny(databases, ['xxx', 'xxx']) AND query_duration_ms > 20000 ORDER BY query_duration_ms DESC LIMIT 200 ) INSERT INTO data_mock_dev.clickhouse_query_log_metrics_count(data_day,normalized_query_hash, tables , query_total ,avg_duration_ms) select toStartOfInterval(event_time, INTERVAL 1 HOUR) AS data_day , normalized_query_hash,tables, count(*) query_total, avg(query_duration_ms) avg_duration_ms from query_tmp group by data_day , normalized_query_hash , tables order by query_total desc , avg_duration_ms desc
|