Changes between Version 16 and Version 17 of AnalyticalStatisticalQuerying
- Timestamp:
- 09/30/25 21:44:46 (13 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AnalyticalStatisticalQuerying
v16 v17 275 275 Replace correlated subquery for `AVG` with a window function or single aggregation to avoid repeated scans. 276 276 Indexing opportunities: 277 -`ticket(account_id, date_purchased)` for fast filtering.278 -Foreign key indexes on `ticket.trip_id`, `trip.route_id`, and `route.{from_location_id, to_location_id, transport_organizer_id}`.277 `ticket(account_id, date_purchased)` for fast filtering. 278 Foreign key indexes on `ticket.trip_id`, `trip.route_id`, and `route.{from_location_id, to_location_id, transport_organizer_id}`. 279 279 280 280 === Conclusion (Rewritten SQL) === … … 381 381 Replace cross join with `stats` by using a window function (`AVG() OVER ()`) to avoid scanning `destinations` twice. 382 382 Indexing opportunities: 383 -`ticket(gets_off_location_id, date_purchased)`384 -`student_ticket.ticket_id`, `child_ticket.ticket_id`385 -Foreign keys on `trip.route_id`, `trip.transport_organizer_id`.383 `ticket(gets_off_location_id, date_purchased)` 384 `student_ticket.ticket_id`, `child_ticket.ticket_id` 385 Foreign keys on `trip.route_id`, `trip.transport_organizer_id`. 386 386 387 387 === Conclusion (Rewritten SQL) === … … 474 474 The `max_tickets` CTE is redundant unless we need to filter only top seller(s). 475 475 Indexing opportunities: 476 -`ticket.trip_id`, `trip.route_id`, `ticket.payment_id`477 -Foreign keys: `route.from_location_id`, `route.to_location_id`, `route.transport_organizer_id`476 `ticket.trip_id`, `trip.route_id`, `ticket.payment_id` 477 Foreign keys: `route.from_location_id`, `route.to_location_id`, `route.transport_organizer_id` 478 478 479 479 === Conclusion (Rewritten SQL) ===