SELECT `performance_schema` . `events_statements_summary_by_digest` . `DIGEST_TEXT` AS `query` , `performance_schema` . `events_statements_summary_by_digest` . `SCHEMA_NAME` AS `db` , `performance_schema` . `events_statements_summary_by_digest` . `COUNT_STAR` AS `exec_count` , `performance_schema` . `events_statements_summary_by_digest` . `SUM_TIMER_WAIT` AS `total_latency` , `performance_schema` . `events_statements_summary_by_digest` . `SUM_SORT_MERGE_PASSES` AS `sort_merge_passes` , `round` ( `ifnull` ( ( `performance_schema` . `events_statements_summary_by_digest` . `SUM_SORT_MERGE_PASSES` / `nullif` ( `performance_schema` . `events_statements_summary_by_digest` . `COUNT_STAR` , ? ) ) , ? ) , ? ) AS `avg_sort_merges` , `performance_schema` . `events_statements_summary_by_digest` . `SUM_SORT_SCAN` AS `sorts_using_scans` , `performance_schema` . `events_statements_summary_by_digest` . `SUM_SORT_RANGE` AS `sort_using_range` , `performance_schema` . 