Benjamin Nevarez Rotating Header Image

My Book, “Inside the Query Optimizer”, available at the PASS Summit

My book, “Inside the SQL Server Query Optimizer”, is almost finished and we will have a conference edition of it available at the PASS Summit. The final version of the book, published by Red Gate books, will be available on Amazon by Christmas.

For more details on the contents, I am including the Preface of the book next.

clip_image002

Preface

The Query Optimizer has always been one of my favorite SQL Server topics, which is why I started blogging about it and submitting related presentations to PASS. And so it would have continued, except that, after several blog posts discussing the Query Optimizer, Red Gate invited me to write a book about it. This is that book.

I started learning about the Query Optimizer by reading the very few SQL Server books which discussed the topic, and most of them covered it only very briefly. Yet I pressed on, and later, while trying to learn more about the topic, I found an extremely rich source of information in the form of the many available research papers. It was hard to fully grasp them at the beginning, as academic papers can be difficult to read and understand, but soon I got used to them, and was all the more knowledgeable for it.

Having said that, I feel that I’m in a bit of a minority, and that many people still see the Query Optimizer just as a black box where a query is submitted and an amazing execution plan is returned. It is also seen as a very complex component, and rightly so. It definitely is a very complex component, perhaps the most complex in database management software, but there is still a lot of great information about the Query Optimizer that SQL Server professionals can benefit from.  

The Query Optimizer is the SQL Server component that tries to give you an optimal execution plan for your queries and, just as importantly, tries to find that execution plan as quickly as possible. A better understanding of what the Query Optimizer does behind the scenes can help you to improve the performance of your databases and applications, and this book explains the core concepts behind how the SQL Server Query Optimizer works. With this knowledge, you’ll be able to write better queries, provide the Query Optimizer with the information it needs to produce efficient execution plans, and troubleshoot the cases when the Query Optimizer is not giving you a good plan.

With that in mind, and in case it’s not obvious, the content of this book is intended for SQL Server professionals: database developers and administrators, data architects, and basically anybody who submits more than just trivial queries to SQL Server. Here’s a quick overview of what the book covers:

The first chapter, Introduction to Query Optimization, starts with an overview on how the SQL Server Query Optimizer works and introduces the concepts that will be covered in more detail in the rest of the book. A look into some of the challenges query optimizers still face today is covered next, along with a section on how to read and understand execution plans. The Chapter closes with a discussion of join ordering, traditionally one of the most complex problems in query optimization.

The second chapter talks about the Execution Engine, and describes it as a collection of physical operators that perform the functions of the query processor. It emphasizes how these operations, implemented by the Execution Engine, define the choices available to the Query Optimizer when building execution plans. This Chapter includes sections on data access operations, the concepts of sorting and hashing, aggregations, and joins, to conclude with a brief introduction to parallelism.

Chapter 3, Statistics and Cost Estimation, shows how the quality of the execution plans generated by the Query Optimizer is directly related to the accuracy of its cardinality and cost estimations. The Chapter describes Statistics objects in detail, and includes some sections on how statistics are created and maintained, as well as how they are used by the Query Optimizer. We’ll also take a look at how to detect cardinality estimation errors, which may cause the Query Optimizer to choose inefficient plans, together with some recommendations on how to avoid and fix these problems. Just to round off the subject, the chapter ends with and introduction to cost estimation.

Chapter 4, Index selection, shows how SQL Server can speed up your queries and dramatically improve the performance of your applications just by using the right indexes. The Chapter shows how SQL Server selects indexes, how you can provide better indexes, and how you can verify your execution plans to make sure these indexes are correctly used. We’ll talk about the Database Engine Tuning Advisor and the Missing Indexes feature, which will show how the Query Optimizer itself can provide you with index tuning recommendations.

Chapter 5, The Optimization Process, is the Chapter that goes right into the internals of the Query Optimizer and introduces the steps that it performs without you ever knowing. This covers everything from the moment a query is submitted to SQL Server until an execution plan is generated and is ready to be executed, including steps like parsing, binding, simplification, trivial plan and full optimization. Important components which are part of the Query Optimizer architecture, such as transformation rules and the memo structure, are also introduced.

Chapter 6, Additional Topics, includes a variety of subjects, starting with the basics of update operations and how they also need to be optimized just like any other query, so that they can be performed as quickly as possible. We’ll have an introduction to Data Warehousing and how SQL Server optimizes star queries, before launching into a detailed explanation of Parameter sniffing, along with some recommendations on how to avoid some problems presented by this behavior. Continuing with the topic of parameters, the Chapter concludes by discussing auto-parameterization and forced parameterization.

Chapter 7 describes Hints, and warns that, although hints are a powerful tool which allows you to take explicit control over the execution plan of a query, they need to be used with caution and only as a last resort when no other option is available. The chapter covers the most-used hints, and ends with a couple of sections on plan guides and the USE PLAN query hint.

Before we get started, please bear in mind that this book contains many undocumented SQL Server statements. These statements are provided only as a way to explore and understand the Query Optimizer and, as such, should not be used on a production environment. Use them wisely, and I hope you enjoy learning about this topic as much as I do.

Benjamin Nevarez

About the author

Benjamin Nevarez Benjamin Nevarez is a SQL Server MVP and independent consultant based in Los Angeles, California who specializes in SQL Server query tuning and optimization. He is the author of "SQL Server 2014 Query Tuning & Optimization" and "Inside the SQL Server Query Optimizer" and co-author of "SQL Server 2012 Internals". With more than 20 years of experience in relational databases, Benjamin has also been a speaker at many SQL Server conferences, including the PASS Summit, SQL Server Connections and SQLBits. Benjamin’s blog can be found at http://www.benjaminnevarez.com and he can also be reached by e-mail at admin at benjaminnevarez dot com and on twitter at @BenjaminNevarez.

12 Comments

  1. [...] Nevarez (blog) has been working really hard on a book on the Query Optimizer. It just got finished in time so that there will be copies available at the PASS Summit. I strongly [...]

  2. bk says:

    When will your book be available to the general public?

  3. Benjamin Nevarez says:

    Hi bk,

    We are planning to have the final version of the book available on Amazon this December.

    Thanks,

    Ben

  4. Justin says:

    Hey Ben, any updates on the book? It’s not on amazon yet, and I’m excited to get it in my hands.

  5. Alejandro Mesa says:

    Benjamin,

    Feliz año nuevo!!!

    Le pedi tu libro a Santa, pero no me lo trajo porque aún no esta en el mercado. Por favor, pidele a la editora que tenga una version para Kindle tambien.

    Saludos,
    Alejandro

  6. Benjamin Nevarez says:

    Hi Justin and Alejandro,

    Thanks for your interest in the book and sorry for the delay in answering your questions. The information I have from Red Gate is that the book will be released by early February.

    I will update this blog if I have additional information or when the book is finally released.

    Thanks,

    Ben

  7. luis says:

    Hola Benjamin, ayer estuve en el evento pass de madrid oyendo lo de “param sniffing”. Eso lo conocía pero quiero profundizar mucho más porque me gusta bastante el tema de la optimización de consultas.
    ¿Donde y cuando puedo comprar tu libro? ¿Lo vas a poner en español? (es broma)

    Un saludo.

  8. Benjamin Nevarez says:

    Hi Luis,

    Let me answer your question in both English and Spanish. The latest information I have from Red Gate is that the book will be available on Amazon this month. I will post an update both on this blog and on my twitter account @BenjaminNevarez as soon as the book is available.

    La ultima informacion que recibi de Red Gate indica que el libro estara disponible en Amazon este mes. Voy a poner un aviso tanto en mi blog como en mi cuenta de twitter @BenjaminNevarez en cuanto tenga mas informacion.

    Thanks,

    Benjamin

  9. Benjamin Nevarez says:

    Hello,

    In case anybody is still reading this post, my book is now available on Amazon at http://amzn.to/hOaKCb.

    Thanks,

    Ben

  10. [...] Now it is available on Amazon and some other book-stores. You also can find more detail description chapter y chapter using this link. [...]

  11. Luis says:

    hola benjamin, muy interesante libro, lo estoy leyendo, no vas a sacar una version en español, seria bueno para nosotros los latinos.

  12. Benjamin Nevarez says:

    Que tal Luis, como estas?

    Gracias por leer mi libro! Por el momento no hay planes de traducirlo al Español. Lo que si quisiera hacer pronto es escribir la segunda edición con contenido adicional y actualizado para SQL Server 2012.

    Saludos,

    Benjamin

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>