SQLLens.AI Docs
Pillar

Slow Query Log Analyzer (QLA)

Aggregate slow-query workload from digest tables, slow logs, or uploaded files — rank fingerprints by impact, batch-analyze with Optimize All, apply index DDL with optional before/after validation, and jump into the single-query Query Optimizer.

Overview

The Slow Query Log Analyzer (MySQL/MariaDB) and Query Log Optimizer (PostgreSQL) share one panel. They:

Animated demo: Workload optimizer — slow query log, Optimize All, indexes, and benefit report.
End-to-end flow: load workload → review ranked fingerprints → Optimize All → Create Indexes + Validate → visual summary (rows saved, I/O weight, estimated response-time benefit).
Animated demo: Query Profiler session timings.
Session profiler — complement workload log analysis with live fingerprints.
Naming

MySQL/MariaDB connections show Slow Query Log Analyzer. PostgreSQL connections show Query Log Optimizer — same panel, engine-specific data sources.

How to open

The panel opens scoped to the tree node you picked. Confirm the sidebar Active database matches the workload you intend to tune.

Home screen — choose a data source

Before any grid appears, the home screen offers one or more load paths. Filters on each card control time window, row limit, and sort order.

MySQL / MariaDB sources

Card / controlWhat it does
Query Digest → Analyze Query DigestReads performance_schema.events_statements_summary_by_digest. No slow log setup required. Filters: Last Seen Within, Latest Rows Limit, Sort by (total time, avg time, call count).
mysql.slow_log → Analyze mysql.slow_logReads the slow-log table when slow_query_log=ON and log_output=TABLE. Same time/limit/sort filters as the table card. Disabled until the server reports the table is available.
Upload File / drop zoneParse a local slow log (.log, .txt, .csv). Drag-and-drop or click to browse.
Enable Slow Query LogAppears when auto-detect finds logging off. Opens a modal with SQL to enable logging (requires elevated privileges).
Load from MySQL Slow Query LogAfter auto-detect finds the server log path: loads the file directly (or last N lines when the file exceeds 100 MB).
Read last … linesTail input (default 10,000 lines) for very large on-server log files.

PostgreSQL sources

Card / controlWhat it does
pg_stat_statements → Analyze pg_stat_statementsRecommended. Cluster-wide stats since last reset. Requires extension + shared_preload_libraries. Badge shows Ready or Not installed.
Connect throughDatabase where CREATE EXTENSION pg_stat_statements was run (extension catalog location).
Load workload fromLimit initial load to one database, or All databases for cluster-wide view.
Min Avg Time (ms)Filter out fast statements (0 = include all).
Latest Rows Limit / Sort byCap rows returned; sort by total time, avg time, or call count.
Upload PG Log File / drop zoneParse server log output from log_min_duration_statement. Auto-detect for local servers when logging collector is on.
Enable PG Slow LoggingGuidance when statement logging is not configured.

Toolbar after load

Once a report is loaded, the top toolbar switches from load buttons to filtering plus reload shortcuts:

ControlMySQL / MariaDBPostgreSQL
Load From Query DigestReload from performance_schema digestLoad From pg_stat_statements
Load From mysql.slow_logReload from slow-log table—
Upload …Upload Slow Log FileUpload PG Server Log
FilterText filter across query text, database, table, fingerprint
Tune DB (PostgreSQL only)Dropdown to scope grid, Optimize All, and Create Indexes to one database

Summary stat cards

Six tiles above the tabs summarize the loaded report:

CardMeaning
Total QueriesRaw execution count in the loaded window
FingerprintsDistinct normalized query patterns
Total Response TimeSum of execution time across the workload
Avg Query ScoreMean optimization score (0–100) across fingerprints
IndexesCount of index recommendations after Optimize All (or placeholder before run)
Full Table Scan / ImprovementFull-scan query count and expected improvement summary after batch optimize

Main tabs

TabContents
Query FingerprintsPrimary tuning grid — ranked statements, row actions, recommended indexes. Bubble timeline chart above the table.
Table UsageDual pie charts (top tables & databases by usage %) plus a sortable Table Grid / Database Grid sub-tab.
Database UsageSame analytics as Table Usage with database-first breakdown.
User UsageBar charts and grid: calls, usage %, response time, rows examined per database user.

Click any column header in a grid to sort ascending/descending. On Query Fingerprints, the # rank column is fixed by impact priority (not affected by sort order).

Query Fingerprints — columns

ColumnDescription
#Impact rank among visible rows (1 = highest impact). Color-coded badge.
ImpactNumeric impact score — higher means more pain in this workload.
QueryRatingStar rating (1–5) plus grade chip (A–E) and optimization score /100.
Query FingerprintNormalized template; hover for sample SQL with literals.
ResponseTimeTotal time for this fingerprint in the window.
PCT(%)Share of total workload time — heat bar visualization.
CallsExecution count.
AvgResponseTimeMean time per call with sparkline vs. peers.
ActionsPer-row EXPLAIN, Optimize, Copy (see below).
MaxLongest single execution.
Database / TableSchemas and tables referenced.
QueryScoreComposite score: 40% response time + 25% usage + 25% rows examined + 10% rows-examined/sent ratio.
RowsExamined / RowsReturnAverage rows scanned vs. rows returned to client.
TypeQuality tag: OK, SLOW, BAD, or BAD+SLOW.
Recommended IndexesBefore Optimize All: prompt button. After: summary chip + copy DDL / copy rewrite tips.

Row action buttons

ButtonAction
📋 EXPLAINOpens Visual Explain / plan analysis for that fingerprint’s sample query in the Query Optimizer workbench.
⚡ OptimizeFull optimizer analysis (indexes, rewrites, plan issues) for one statement.
📋 CopyCopies sample SQL to the clipboard.
📋 Copy index DDL (Recommended Indexes)Copies all CREATE INDEX statements for that row.
📝 Copy rewrite tipsCopies textual rewrite guidance from recommendations.

Rows that cannot be optimized (e.g. missing sample SQL, unsupported statement type) show — with a tooltip explaining why. Optimizable types: SELECT, UPDATE, DELETE, WITH.

Action bar (batch operations)

Right of the main tabs:

ButtonWhat it does
⚡ Optimize all QueriesRuns the Query Optimizer across top fingerprints (scope set in Optimizer Settings). Fills Recommended Indexes column and updates summary tiles. Shows progress banner with cancel.
Create Indexes + Validate ▼Dropdown: Create Indexes + Validate (EXPLAIN before/after) or Create Indexes only. Opens full-screen Create Indexes overlay.
Export Index DDL ▼Export indexes script (save file) or Copy indexes script (clipboard). Requires Optimize All first.
🔍 SettingsOpens Optimizer Settings modal (sampling + Optimize All scope).

Bubble timeline (Query Fingerprints tab)

Above the fingerprint table, a scatter timeline plots slow executions over time:

Operation progress banner

During Optimize All, Create Indexes, or validation, a status banner appears below the action bar:

Create Indexes overlay

Full-screen flow opened from the action bar. Two phases: selection then results (after Create Indexes or Create Indexes + Validate).

Selection screen controls

ControlPurpose
Select all checkboxToggle all index recommendations.
Ignore Low impact indexesDeselects low-impact rows from the create list.
ThreadsParallel CREATE INDEX workers (1, 2, 4, 8, 16). Use 1 on busy production systems.
Summary stripN selected · Est. total: … — selected count and rough duration estimate.
Per-row checkboxInclude/exclude individual CREATE INDEX statements.
CancelClose overlay without creating anything.
Create IndexesApply selected DDL without before/after EXPLAIN validation.
Create Indexes + ValidateApply DDL, then run monitored before/after EXPLAIN and timing checks (5% improvement threshold for row counts).

Results screen — visual summary

After validation completes, charts summarize aggregate benefit (as shown in the demo GIF):

SectionWhat it shows
Outcome mix (donut)Improvement vs. no impact vs. regression vs. failed recommendations.
Cumulative I/O savings (line chart)Rows saved (blue, left Y-axis) and I/O weight saved (green, right Y-axis) — cumulative as each query is optimized. Hover points for per-query detail.
Estimated response-time benefitLarge Nx ratio from weighted EXPLAIN rows before ÷ after, plus absolute row savings (e.g. 5.7M → 753K rows).
Weighted totals (all queries)Before/after bar comparison and % reduction in weighted rows (count × EXPLAIN rows, summed).
Per-index details gridDDL, status, rows before/after, impact %, optimizer index usage, timings, errors. Scroll horizontally for all columns.

Results screen — drop actions

ButtonPurpose
Drop unused indexesRemoves indexes from this batch that validation showed the optimizer did not use.
Drop allRolls back every index created from this recommendation set (confirmation modal).
Cancel (during drop)Stops an in-progress drop operation.
CloseExit results view back to the analyzer grid.

Optimizer Settings modal

Gear icon in the action bar. Two tabs — settings persist in your VS Code profile.

Tab / optionDescription
Slow Query Optimizer → Collect query samplesWhen checked, fetches real literal values from history for better index recommendations. Uncheck to use normalized templates only.
Queries to optimize in "Optimize All"All queries · Top 5 · Top 10 · Top 25 — limits batch analysis to highest-impact fingerprints.
Skip tables with many indexesComing soon — skip recommendations when a table already exceeds N indexes.
Query Optimizer → Collect query samplesSame sampling toggle for single-query Optimize opened from a grid row.
Save / CancelPersist or discard changes.

Auto-detect & enable slow logging

QLA probes the server for log configuration:

Production caution

Enabling verbose statement logging adds overhead. Use conservative thresholds (long_query_time, log_min_duration_statement) and narrow time windows when loading digest stats.

Recommended tuning workflow

  1. Load the smallest window that captures the problem (digest is usually enough for MySQL; pg_stat_statements for PostgreSQL).
  2. Filter by database, table, or query text; on PostgreSQL use Tune DB to focus one schema.
  3. Review Query Fingerprints sorted by impact — inspect bubble chart spikes.
  4. Optimize All Queries (or top N via settings) to populate index recommendations.
  5. Export Index DDL for change review, or Create Indexes + Validate to measure EXPLAIN improvement on the server.
  6. For hard cases, use row ⚡ Optimize to open the full Query Optimizer (rewrites, visual explain, trace).
  7. Truncate or rotate logs after a tuning pass so the next analysis is not skewed by fixed queries.

Privileges & troubleshooting

Tips