Operation 225362

SELECT users.*, COUNT(DISTINCT posts.id) as post_count, COUNT(DISTINCT comments.id) as comment_count, SUM(posts.view_count) as total_views, AVG(posts.view_count) as avg_views, MIN(posts.created_at) as first_post, MAX(posts.created_at) as latest_post FROM users LEFT JOIN posts ON users.id = posts.user_id LEFT JOIN comments ON users.id = comments.user_id GROUP BY users.id
Operation Type
sql
Duration
19.0 ms
Request Impact
6.6% of total request time
Occurred At
Sep 13, 2026 11:20 PM
SQL Analysis
Normal query (<100 ms)
Performance Comparison
Average: 17.9ms
95th Percentile: 34.0ms
Based on 1000 recent operations
Related Operations
5 similar operations in this request
Potential N+1 query pattern detected
Optimization Tips
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 single_column index: add_index :comments, :user_id - Fast JOIN execution
Add single_column index: add_index :posts, :user_id - Fast JOIN execution
Add WHERE clause to filter results - Avoid full table scans and reduce data transfer
Consider breaking complex query (complexity: 12) into smaller parts - Easier maintenance and potentially better performance
Index Optimization - Review indexes on the 'users' table. Consider composite indexes for WHERE clauses.