Analyze and optimize the following SQL query:
```sql
[[SELECTED_TEXT]]
```
**Database:** [[DB_TYPE]] (PostgreSQL / MySQL / SQLite / ...)
**Table sizes:** [[SIZES]]
Check:
1. Missing or unnecessary indexes
2. Inefficient JOINs or subqueries
3. Avoid SELECT *
4. Query plan analysis (EXPLAIN)
5. Possible alternatives (CTEs, Window Functions, Materialized Views)
Show optimized version with justification.