Changes between Version 16 and Version 17 of AnalyticalStatisticalQuerying


Ignore:
Timestamp:
09/30/25 21:44:46 (13 days ago)
Author:
222077
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AnalyticalStatisticalQuerying

    v16 v17  
    275275Replace correlated subquery for `AVG` with a window function or single aggregation to avoid repeated scans.
    276276Indexing 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.
     278Foreign key indexes on `ticket.trip_id`, `trip.route_id`, and `route.{from_location_id, to_location_id, transport_organizer_id}`.
    279279
    280280=== Conclusion (Rewritten SQL) ===
     
    381381Replace cross join with `stats` by using a window function (`AVG() OVER ()`) to avoid scanning `destinations` twice.
    382382Indexing 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`.
    386386
    387387=== Conclusion (Rewritten SQL) ===
     
    474474The `max_tickets` CTE is redundant unless we need to filter only top seller(s).
    475475Indexing 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`
    478478
    479479=== Conclusion (Rewritten SQL) ===