dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mysql/#31
Script #31
mysql
Performanceread-onlyMin Version: 5.7

MySQL Queries Doing Full Table Scans

Ranks queries that scan whole tables without an index by total latency. The fastest way to find missing indexes.

#full-table-scan#sys-schema#missing-index
mysql · sql
SELECT db, LEFT(query, 150) AS query, exec_count,
       sys.format_time(total_latency) AS total_latency,
       no_index_used_count, rows_examined_avg
FROM sys.x$statements_with_full_table_scans
ORDER BY total_latency DESC
LIMIT 20;
Operational Notes & Remediation Guidance

Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 5.7).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.