Skip to content

Instantly share code, notes, and snippets.

@tom-clickhouse
Created August 27, 2023 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom-clickhouse/05f40f98dbcc6b28be6de3f96668f37b to your computer and use it in GitHub Desktop.
Save tom-clickhouse/05f40f98dbcc6b28be6de3f96668f37b to your computer and use it in GitHub Desktop.
WITH
'default' AS db_name,
'wikistat' AS table_name,
(SELECT uuid FROM system.tables WHERE database = db_name and name = table_name) AS table_id,
(SELECT min(event_time) FROM system.part_log WHERE table_uuid = table_id) AS start_time,
(
SELECT event_time
FROM clusterAllReplicas(default, system.query_log)
WHERE
has(tables, db_name || '.' || table_name)
AND length(tables) = 1
AND is_initial_query
AND query_kind = 'Insert'
AND type = 'QueryFinish'
ORDER BY event_time_microseconds DESC
LIMIT 1
) AS insert_end_time
SELECT sum(CurrentMetric_Merge) AS merges
FROM clusterAllReplicas(default, system.metric_log)
WHERE event_time >= start_time AND event_time <= insert_end_time
SETTINGS skip_unavailable_shards = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment