P95 Query Time

P95 Query Time

The 95th percentile database query duration — 95% of queries complete faster than this. Weighted by execution frequency across all queries. Slow queries are often caused by missing indexes or N+1 patterns.

33 ms

5.6%

Compared to previous 7 days

Execution Rate

Query Execution Rate

Total database queries executed over the last 14 days, expressed as an average rate. Spikes may indicate N+1 queries or inefficient data access patterns.

2.62 / hour

13.0%

Compared to previous 7 days

Query Responses

Query Responses

This panel shows all executions of this query, including performance metrics, duration distribution, and query execution details.

Click marker to copy SHA
Time Period ▼ Executions Avg Duration Min Duration Max Duration
Sep 23, 2026 15 19.07 ms 1.0 ms 35.0 ms
Sep 22, 2026 65 18.22 ms 1.0 ms 35.0 ms
Sep 21, 2026 67 16.51 ms 1.0 ms 35.0 ms
Sep 20, 2026 48 19.0 ms 2.0 ms 33.0 ms
Sep 19, 2026 47 17.83 ms 3.0 ms 35.0 ms
Sep 18, 2026 50 18.96 ms 1.0 ms 34.0 ms
Sep 17, 2026 54 15.74 ms 1.0 ms 32.0 ms
Sep 16, 2026 64 16.56 ms 1.0 ms 35.0 ms
Sep 15, 2026 69 19.91 ms 1.0 ms 49.0 ms
Sep 14, 2026 59 18.61 ms 1.0 ms 47.0 ms
Total of 15 record(s).

Normalized Query

SELECT * FROM comments WHERE post_id = ? ORDER BY created_at DESC LIMIT ?

Diagnostics

Query Diagnostics

Automatically generated analysis for this query. Includes N+1 detection (from live request data), query characteristics, detected issues, optimization suggestions, and a database EXPLAIN plan. Click Re-analyze to regenerate.


Query Characteristics
Query Type
SELECT
Tables
1
Joins
0
Complexity Score
3
Has LIMIT
Yes
Has ORDER BY
Yes
Has GROUP BY
No
Has Subqueries
No

Issues Detected
  • Using SELECT * may retrieve unnecessary columns

Optimization Suggestions
  • Use includes() or preload() to load associated records — Eliminate N+1 queries and reduce database load
  • Use includes() to eager load associations — Eliminate N+1 queries and reduce database load
  • Use joins() when you only need to filter, not access associated data — Eliminate N+1 queries and reduce database load
  • Use preload() when you don't need to query on associations — Eliminate N+1 queries and reduce database load
  • Add composite index: add_index :comments, ["post_id", "created_at"] — Single index for filtering and sorting
    add_index :comments, ["post_id", "created_at"]
  • Add single_column index: add_index :comments, :post_id — Fast lookups for post_id = value queries
    add_index :comments, :post_id

Execution Plan
7 | 0 | 61 | SEARCH comments USING INDEX index_comments_on_post_id (post_id=?)
28 | 0 | 0 | USE TEMP B-TREE FOR ORDER BY

Query Locations

Query Locations

Shows where in your codebase this query originates, based on the last 30 days of executions. P95 duration and row count highlight the worst-case performance at each call site.

Location P95 Duration (ms) P95 Row Count Count
app/models/application_record.rb:12 33.0 496
app/jobs/import_job.rb:45 49.0 1
app/jobs/image_processing_job.rb:47 41.0 1
app/jobs/notification_job.rb:63 44.0 1
app/jobs/webhook_delivery_job.rb:56 45.0 1

Raw Data

{
  "query": {
    "id": 97,
    "normalized_sql": "SELECT * FROM comments WHERE post_id = ? ORDER BY created_at DESC LIMIT ?",
    "analyzed_at": "2026-09-23 07:02:22 UTC"
  },
  "performance": {
    "total_executions": 500,
    "p95_duration_ms": "34.0",
    "avg_duration_ms": 17.908,
    "p95_row_count": null,
    "avg_row_count": null
  },
  "characteristics": {
    "query_type": "SELECT",
    "table_count": 1,
    "join_count": 0,
    "where_clause_complexity": 1,
    "has_subqueries": false,
    "has_limit": true,
    "has_order_by": true,
    "has_group_by": false,
    "has_having": false,
    "has_distinct": false,
    "has_aggregations": false,
    "estimated_complexity": 3
  },
  "call_locations": [
    {
      "location": "app/models/application_record.rb:12",
      "count": 496,
      "p95_duration_ms": "33.0",
      "p95_row_count": null
    },
    {
      "location": "app/jobs/import_job.rb:45",
      "count": 1,
      "p95_duration_ms": "49.0",
      "p95_row_count": null
    },
    {
      "location": "app/jobs/image_processing_job.rb:47",
      "count": 1,
      "p95_duration_ms": "41.0",
      "p95_row_count": null
    },
    {
      "location": "app/jobs/notification_job.rb:63",
      "count": 1,
      "p95_duration_ms": "44.0",
      "p95_row_count": null
    },
    {
      "location": "app/jobs/webhook_delivery_job.rb:56",
      "count": 1,
      "p95_duration_ms": "45.0",
      "p95_row_count": null
    }
  ],
  "n_plus_one": {
    "detected": false
  },
  "index_recommendations": [
    "add_index :comments, :post_id",
    "add_index :comments, [\"post_id\", \"created_at\"]",
    "add_index :comments, :created_at"
  ],
  "issues": [
    "Using SELECT * may retrieve unnecessary columns"
  ],
  "explain_plan": "7 | 0 | 61 | SEARCH comments USING INDEX index_comments_on_post_id (post_id=?)\n28 | 0 | 0 | USE TEMP B-TREE FOR ORDER BY"
}