Find slow queries in MariaDB
Rank statement summaries by total execution time to find queries with the greatest combined cost.
SELECT DIGEST_TEXT AS query_text, COUNT_STAR AS calls, SUM_TIMER_WAIT / 1000000000000 AS total_seconds, AVG_TIMER_WAIT / 1000000000000 AS mean_seconds, SUM_ROWS_EXAMINED AS rows_examinedFROM performance_schema.events_statements_summary_by_digestWHERE SCHEMA_NAME = DATABASE()ORDER BY SUM_TIMER_WAIT DESCLIMIT 100;Each row groups statements by their query pattern. The timer conversion gives seconds. Compare total time for cumulative cost and mean time for the cost of one call.
Find slow queries in MariaDB
Section titled “Find slow queries in MariaDB”- Connect to the database you want to inspect.
- Click Admin in the toolbar.
- Select Slow Queries.
- Compare execution times and call counts.
The view requests up to 100 statement groups for the current database, ordered by total execution time. These are server statistics, including work from other clients. You can also run the SQL above in the SQL editor.
Required statistics and access
Section titled “Required statistics and access”Performance Schema must be enabled and collecting statement statistics.
Your account needs read access to performance_schema.events_statements_summary_by_digest.
Check whether Performance Schema is enabled with:
SELECT @@performance_schema AS enabled;An enabled server can still have no collected statements. This view reads statement summaries rather than the slow query log file. For missing data or permission errors, follow admin data unavailable.
Inspect a query plan
Section titled “Inspect a query plan”MariaDB uses EXPLAIN FORMAT=JSON for an estimated plan and ANALYZE FORMAT=JSON for execution measurements.
Review the statement before choosing execution analysis: ANALYZE runs it.
Follow Explain with AI for plan interpretation.
Related
Section titled “Related”- MariaDB overview
- View locks when queries wait for other transactions
- Diagnose performance
- Slow or timed out