New
Pages
296
Published
2008
Refactoring SQL Applications
How experienced practitioners redesign queries, schemas, and SQL code for real-world performance
Stop writing SQL that works and start writing SQL that performs — learn how senior practitioners diagnose, redesign, and tune queries that matter.
Most SQL books teach you to write queries that return correct results. This one teaches you to write queries that survive production. Stéphane Faroult and Pascal L'Hermite draw on decades of database consulting to show you how to identify performance bottlenecks, rethink schema decisions, and rewrite SQL with the execution engine in mind. If your queries work but your database is slow, this book is the practical answer.
About this book
Correct SQL and fast SQL are not the same thing. Most developers learn enough SQL to retrieve the data they need, then spend years wondering why their application slows to a crawl under real load. Refactoring SQL Applications closes that gap.
Stéphane Faroult and Pascal L'Hermite bring decades of database consulting experience to bear on the problems that actually appear in production systems: queries that scan too many rows, indexes that go unused, schemas that seemed logical at design time but punish you at scale, and application code that talks to the database in all the wrong ways. This is not a book about SQL syntax. It is a book about how experienced practitioners think.
The book walks you through a disciplined approach to SQL refactoring: how to read an execution plan, how to identify the real bottleneck rather than the obvious one, and how to redesign a query without breaking the application that depends on it. You will learn to distinguish problems that require query rewrites from problems that require schema changes, and to make that call with confidence rather than guesswork.
Along the way, Faroult and L'Hermite cover the patterns that repeatedly cause trouble across databases and codebases:
- Correlated subqueries that execute row-by-row when a join would execute once
- Implicit type conversions that silently defeat indexes
- Aggregation pushed to the wrong layer of the stack
- Application-level loops driving individual SQL statements that belong in a single set-based query
- Schema denormalization applied without measuring its actual cost
Every technique is grounded in the authors' real consulting engagements. The examples are the kind of SQL you will recognise from your own codebase, not toy examples built to illustrate a single point. By the time you finish, you will have a repeatable process for approaching any slow query — and the vocabulary to explain your decisions to colleagues, architects, and managers who need to understand why the rewrite was worth doing.
If you are an intermediate SQL user who suspects there is a lot you are still missing, or an experienced developer who has hit the wall on a specific performance problem, this book gives you the mental model that makes the difference.
🎯 What you'll learn
- Read and interpret execution plans to locate the actual source of a performance problem
- Distinguish query-level bottlenecks from schema-level bottlenecks and choose the right fix for each
- Rewrite correlated subqueries, nested selects, and application-side loops as efficient set-based SQL
- Identify the indexing mistakes that silently prevent the optimizer from using your indexes
- Refactor aggregation and filtering logic to push work to the most efficient layer of the stack
- Apply a repeatable diagnostic process to any slow query rather than guessing at fixes
- Communicate performance trade-offs clearly to teammates and stakeholders who did not write the SQL
👤 Who is this book for?
- Backend developers who write SQL regularly but have never been taught to read or interpret an execution plan
- Application engineers whose queries return correct results but whose databases are struggling under production load
- DBAs and data engineers tasked with auditing or tuning SQL written by others
- Architects evaluating schema and query design trade-offs before a system ships or scales
- Technical leads who need a shared vocabulary for SQL performance review conversations with their teams
Table of contents
-
01
The Refactoring Mindset
Establishes why SQL refactoring is a distinct discipline from writing SQL from scratch. You learn the mental shift required to diagnose existing code rather than replace it wholesale.
-
02
Reading Execution Plans
Walks you through the structure of execution plans across major database engines. You practise identifying the operations that signal trouble before you touch a single line of SQL.
-
03
Finding the Real Bottleneck
Introduces a systematic diagnostic process for isolating the actual cause of poor query performance. You learn to separate I/O problems, lock contention, and poor query logic from one another.
-
04
Rewriting Queries
Covers the most common and costly query anti-patterns, including correlated subqueries and implicit type conversions. You rewrite each pattern into its more efficient equivalent and verify the improvement.
-
05
Set-Based Thinking
Explains why row-by-row processing embedded in application code or cursors is a recurring root cause of SQL performance problems. You learn to translate iterative logic into single set-based statements.
-
06
Index Strategy
Examines how the optimizer selects and uses indexes and why well-intentioned indexes are often ignored. You learn to design and audit indexes that the engine will actually use.
-
07
Schema Refactoring
Addresses the structural schema decisions that query rewrites alone cannot fix. You work through normalization and denormalization trade-offs with a focus on measurable impact rather than theory.
-
08
Application and Database Interaction
Looks at the boundary between application code and the database as a source of avoidable performance problems. You learn to reduce round-trips, batch statements, and move logic to the right layer.
-
09
Putting It All Together
Applies the full diagnostic and refactoring process to realistic end-to-end case studies drawn from consulting practice. You leave with a repeatable workflow you can carry directly into your own codebase.
Frequently asked questions
Do I need to be an expert in a specific database engine to benefit from this book?
No. The principles and patterns the authors cover apply across major relational databases. Where behaviour differs between engines, the book notes it, but the core diagnostic and refactoring approach is engine-agnostic.
Is this book suitable for someone who is still learning SQL?
It is best suited to developers who already write SQL regularly and have hit real performance problems. Complete beginners will find the material assumes familiarity with joins, subqueries, and basic schema design.
Does the book cover NoSQL or newer distributed databases?
No. The book focuses entirely on relational SQL databases. It was published in 2008, so technologies that emerged after that date are not covered.
Is this book still relevant given it was published in 2008?
The core reasoning about execution plans, set-based logic, indexing, and schema design is as relevant today as it was at publication. Specific syntax examples reflect the database versions available at the time, but the mental models have not aged.
Does the book include downloadable code or companion files?
Check the publisher's page for any companion materials. The book's examples are presented inline and are short enough to follow and reproduce without a separate download.
Who are the authors and what is their background?
Stéphane Faroult and Pascal L'Hermite are database consultants with extensive practical experience tuning SQL applications across industries. Their previous collaboration includes the well-regarded book The Art of SQL.
You might also like
New
New
T-SQL Fundamentals
A complete foundation in Transact-SQL for SQL Server and Azure SQL development
New
SQL Cookbook
Problem-Solution Recipes for SQL Across Multiple Database Platforms
by Anthony Molinaro, Robert de Graaf