Reading the Tea Leaves: Query Optimization with Postgres and AI

Data Engineering Intermediate

A practical tour of cost-based query optimizers, how to read EXPLAIN plans, and how LLMs can help diagnose and fix slow queries, demonstrated on Postgres.

Speeding up slow processes in Postgres and Spark leads straight into the world of query optimizers. This talk covers a short history of cost-based query optimizers, the basics of how they work, and how to use AI tools to interpret the query plans produced by EXPLAIN. The focus is Postgres, with a demonstration of how the query plan changes with indexing, sort orders, and joins. LLMs turn out to be very good, as many have found, not only at interpreting query plans but also at diagnosing problems. The goal is a repeatable process for analyzing and optimizing queries, and a look at how that process can be packaged into skills and agents.