🎡 BigQuery Optimization learnings. No Self-Joins – use window functions instead.

You always learn stuff about your data warehouses. I never really used self joins a lot before (never really resonated with me). In a project I worked together with someone else and they solved the problem by using 2-3 self-joins (basically to figure out previous invoice values).

The query execution time was way off (8-10m on a small data size). Rewriting the query to use window functions decreased execution time to 4s.