Operation 139725
SELECT * FROM users LEFT JOIN posts ON users.id = posts.user_id LEFT JOIN comments ON posts.id = comments.post_id LEFT JOIN tags ON posts.id = tags.post_id LEFT JOIN categories ON posts.category_id = categories.id WHERE users.active = ? AND posts.published = ? AND comments.approved = ? AND tags.name LIKE ? AND categories.visible = ? AND users.email LIKE ? AND posts.title LIKE ? OR comments.content LIKE ? AND users.created_at BETWEEN ? AND ? AND posts.updated_at > ? ORDER BY users.created_at, posts.created_at, comments.created_at
- Operation Type
sql
- Duration
- 10.0 ms
- Request Impact
- 8.3% of total request time
- Occurred At
- Sep 22, 2026 8:07 PM
- SQL Analysis
- Normal query (<100 ms)
- Performance Comparison
-
Average: 18.2ms
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() or preload() to load associated records - Eliminate N+1 queries and reduce database loadUse includes() to eager load associations - Eliminate N+1 queries and reduce database loadUse joins() when you only need to filter, not access associated data - Eliminate N+1 queries and reduce database loadUse preload() when you don't need to query on associations - Eliminate N+1 queries and reduce database loadAdd composite index: add_index :users, ["active", "published", "approved", "visible", "created_at", "updated_at", "name", "email", "title", "content", "created_at", "created_at", "created_at"] - Single index for filtering and sortingAdd composite index: add_index :users, ["active", "published", "approved", "visible", "created_at", "updated_at", "name", "email", "title", "content"] - Efficient multi-column filteringAdd single_column index: add_index :comments, :post_id - Fast JOIN executionAdd single_column index: add_index :posts, :category_id - Fast JOIN executionAdd single_column index: add_index :posts, :user_id - Fast JOIN executionAdd single_column index: add_index :tags, :post_id - Fast JOIN executionAdd single_column index: add_index :users, :active - Fast lookups for active = value queriesAdd single_column index: add_index :users, :approved - Fast lookups for approved = value queriesAdd single_column index: add_index :users, :published - Fast lookups for published = value queriesAdd single_column index: add_index :users, :visible - Fast lookups for visible = value queriesAdd composite index: add_index :users, ["created_at", "created_at", "created_at"] - Avoid sorting for complex ORDER BYAdd single_column index: add_index :users, :created_at - Efficient range scans for created_atAdd single_column index: add_index :users, :updated_at - Efficient range scans for updated_atReview if all 4 JOINs are necessary - Simplified query execution and better performanceSpecify only needed columns instead of SELECT * - Reduced memory usage and faster data transferConsider breaking complex query (complexity: 33) into smaller parts - Easier maintenance and potentially better performanceSimplify WHERE clause by breaking into multiple queries or using views - Easier maintenance and potentially better performanceIndex Optimization - Review indexes on the 'users' table. Consider composite indexes for WHERE clauses.