273 | | * Push selection down: filter `ticket` by `account_id` and `date_purchased` before joins to reduce data early. |
274 | | * Compute `weight` in a projection step before aggregation for clarity and efficiency. |
275 | | * Replace correlated subquery for `AVG` with a window function or single aggregation to avoid repeated scans. |
276 | | * Indexing opportunities: |
| 273 | Push selection down: filter `ticket` by `account_id` and `date_purchased` before joins to reduce data early. |
| 274 | Compute `weight` in a projection step before aggregation for clarity and efficiency. |
| 275 | Replace correlated subquery for `AVG` with a window function or single aggregation to avoid repeated scans. |
| 276 | Indexing opportunities: |
379 | | * Push projections early: keep only `location_id`, `ticket_id`, `account_id`, `price`, and join keys before grouping. |
380 | | * Apply the date filter (`past year`) explicitly in the `WHERE` clause on `ticket.date_purchased` (missing in original). |
381 | | * Replace cross join with `stats` by using a window function (`AVG() OVER ()`) to avoid scanning `destinations` twice. |
382 | | * Indexing opportunities: |
| 379 | Push projections early: keep only `location_id`, `ticket_id`, `account_id`, `price`, and join keys before grouping. |
| 380 | Apply the date filter (`past year`) explicitly in the `WHERE` clause on `ticket.date_purchased` (missing in original). |
| 381 | Replace cross join with `stats` by using a window function (`AVG() OVER ()`) to avoid scanning `destinations` twice. |
| 382 | Indexing opportunities: |
472 | | * Push projections early to reduce carried attributes before aggregation. |
473 | | * Join order: start with fact tables (`ticket`, `payment`) then join dimension tables (`trip`, `route`, `location`, `transport_organizer`). |
474 | | * The `max_tickets` CTE is redundant unless we need to filter only top seller(s). |
475 | | * Indexing opportunities: |
| 472 | Push projections early to reduce carried attributes before aggregation. |
| 473 | Join order: start with fact tables (`ticket`, `payment`) then join dimension tables (`trip`, `route`, `location`, `transport_organizer`). |
| 474 | The `max_tickets` CTE is redundant unless we need to filter only top seller(s). |
| 475 | Indexing opportunities: |