145. SQL Indexing: Why Is Your Query So Slow?
145. SQL Indexing: Why Is Your Query So Slow?
How do SQL indexes actually work, and why does SQL Server sometimes ignore the index you created? Christian explains SQL indexing from the ground up, with Jelle asking the questions.
“SQL Server will notice when it’s easy or non-beneficial to use an index and will actually not use it, but you still have to maintain it.”
Christian starts with how SQL Server stores data in 8 KB pages, and how a balanced tree on top of those pages makes searching a million rows take only a few steps.
We cover:
The difference between a clustered and a non-clustered index
Why an auto-increment ID usually makes a better clustered key than a GUID
What you get for free when you set a primary key
Demo in the AdventureWorks database: execution plans, key lookups and index statistics
Why this still matters when you use Entity Framework
The main point: whether an index helps depends on your data. Searching for white products uses the color index, but searching for black products scans the whole table, because the statistics show there are far more black products. And every index costs you on every insert, update and delete, and in storage.
Want a follow-up on included columns, filtered indexes, columnstore or vector indexes? Let us know in the comments on YouTube.
More videos
-
144. Human in the Loop: When Should AI Ask Permission?
When should an AI agent ask for permission? Learn about human-in-the-loop and how to build approval into agent workflows with Microsoft Agent Framework.Content typeVideo
-
143. Harness Engineering: How to Build Better AI Coding Agents
What is harness engineering? Learn how tools, context and automated checks help AI coding agents like GitHub Copilot deliver consistent, maintainable code.Content typeVideo
-
142. Quantum Computing: Let's Write Some Actual Code! (Q# & Azure Quantum)
Get started with quantum computing in Q#: Christian and Jelle work with qubits, superposition and entanglement, and run code on Azure Quantum.Content typeVideo
Stay up to date with our Betatalks and tech updates!
Sign up and receive a biweekly update with the latest knowledge and developments.