Every data team has a query nobody wants to touch. It started as an ad-hoc report, grew a new LEFT JOIN with every urgent request, and now it's 2,000+ lines long and the person who wrote it left two years ago. AI assistants make this worse, not better. Adding one more column to that query is one prompt away, and the result is usually correct, except when the model didn't know about the edge case nobody put in the prompt.
In this presentation Lasha will share how he approaches breaking these queries into manageable models. We'll look at why splitting a query by its CTEs doesn't really solve anything, how to read the execution graph before deciding where to cut (including a case where fixing one reused CTE took a query from 55 minutes to 10), and the six questions he uses to find real model boundaries: grain, entity, metric, risk, validation, and product. We'll also talk briefly about naming, and about a paper from 1971 that reached the same conclusion first, about programs rather than SQL. Examples use BigQuery and dbt with a small lending dataset, but the ideas apply to any SQL engine. All the SQL from the talk is shared and runnable.
Agenda
- 5:30PM Pizza and Networking
- 6:00PM Presentation
Speaker Bio
Lasha Dolenjashvili is an analytics engineer working in lending portfolio analytics, with 7 years in data engineering and analytics. He specializes in decomposing legacy SQL, BigQuery execution and cost, and dbt modeling.