Databases
AuraScore 83/100

Query Performance Audit and Safe Indexing Script

Generate a query log parsing and zero-downtime indexing script to remediate sluggish analytical workloads.

Deploy this template when productivity bottlenecks require automated slow-query log analysis and concurrent index generation. It yields clean, idempotent scripts tailored to your database engine.

Template

Role: Staff Performance DBA specializing in low-overhead query optimization and non-blocking database tuning.

Context

  • Database system: {{rdbms_type}}
  • Query latency cutoff: {{slow_query_threshold_ms}} ms
  • Operating environment: {{workload_environment}}
  • Source telemetry feed: {{audit_log_format}}
  • Maximum lock wait threshold: {{lock_timeout_seconds}} seconds
  • Orchestration medium: {{output_script_language}}

Task

Construct an end-to-end audit and safe index generation script that extracts slow query metrics, identifies missing indexes, and builds non-blocking indexing DDL.

Method

  1. Connect to telemetry outputs formatted as {{audit_log_format}} within {{rdbms_type}}.
  2. Filter query signatures exceeding the latency cutoff of {{slow_query_threshold_ms}} ms.
  3. Aggregate queries by query fingerprint and extract sequential scan access paths.
  4. Map scanned filter predicates and join keys to target table definitions.
  5. Generate non-blocking index creation commands tailored for {{workload_environment}}.
  6. Inject session-level lock timeouts using {{lock_timeout_seconds}} before each DDL statement.
  7. Add pre-execution index existence checks to make index creation strictly idempotent.
  8. Include health verification queries measuring index usage and storage footprint.

Constraints

  • Index creation MUST use online/concurrent building modes to prevent blocking live writes.
  • The script MUST NOT create duplicate or redundant composite indexes with identical leading columns.
  • All DDL statements must set lock timeout limits matching {{lock_timeout_seconds}}.
  • Syntax and command parameters must be fully valid for {{output_script_language}} and {{rdbms_type}}.

Output format

Return the deliverable organized into the following exact sections:

  1. Audit & Extraction Script: Formatted code block in {{output_script_language}} to parse logs.
  2. Idempotent Migration DDL: SQL code block containing concurrent index creation statements.
  3. Operational Rollback Block: SQL statements to drop newly added indexes cleanly if needed.

Self-review

  • Confirm that online indexing clauses (e.g., CONCURRENTLY / ONLINE = ON) are present.
  • Validate that lock wait limits enforce {{lock_timeout_seconds}} prior to every DDL attempt.
  • Verify query filtering matches {{slow_query_threshold_ms}} ms without dropping top offenders.
AuraScore breakdown
83/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency7/10 · Adequate

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-databases
research-productivity-operations
performance
dba
indexing