Home > Store

Guru's Guide to SQL Server Architecture and Internals, The

Register your product to gain access to bonus material or receive a coupon.

Guru's Guide to SQL Server Architecture and Internals, The

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

SQL Server guru and bestselling author Ken Henderson has written the consummate reference to Microsoft SQL Server!

° Contains the most depth and breadth of coverage of any book on SQL Server architecture, internals, and tuning

° Will be a key reference for anyone working with SQL Server, no matter what their skill level

° The latest of the highly-regarded, bestselling Guru's Guides from Ken Henderson

Description

  • Copyright 2004
  • Dimensions: 7" x 9-1/4"
  • Pages: 1072
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-70047-6
  • ISBN-13: 978-0-201-70047-3

"I can pretty much guarantee that anyone who uses SQL Server on a regular basis (even those located in Redmond working on SQL Server) can learn something new from reading this book."
--David Campbell, Product Unit Manager,
Relational Server Team, Microsoft Corporation

The latest book from the highly regarded and best-selling author Ken Henderson, The Guru's Guide to SQL Server Architecture and Internals is the consummate reference to Microsoft SQL Server. Picking up where documentation and white papers leave off, this book takes an all-inclusive approach to provide the most depth and breadth of coverage of any book on SQL Server architecture, internals, and tuning.

Blending in-depth discussion with practical application, the guide begins with several chapters on the fundamental Windows technologies behind SQL Server, including processes and threads, memory management, Windows I/O, and networking. The focus then moves on to the architectural details of SQL Server and how to practically apply them.

The entire SQL Server product is covered--not just the functionality that resides within the core executable or product features that have been in place for years. SQL Server has matured and broadened substantially with each release, and the author explores the "fringe" technologies that have yet to be covered elsewhere, including Notification Services, Full Text Search, SQLXML, replication, DTS, and a host of others.

Throughout the book, the author uses WinDbg, Microsoft's free downloadable symbolic debugger, to look under the hood of SQL Server. Armed with new debugging and coding skills, readers will be ready to master SQL Server on their own.

The accompanying CD-ROM is packed with additional material, including full source code for the book's 900+ examples, as well as three invaluable tools: DTSDIAG, the VBODSOLE Library, and DTS Package Guru. DTSDIAG allows developers and administrators to simultaneously collect Profiler traces, perform logs, blocking script output, system event logs, and SQLDIAG reports from a specified SQL Server. The VBODSOLE Library features more than twenty new COM-based functions for Transact-SQL, including T-SQL enhancements such as array-manipulation routines, financial functions, string-manipulation functions, and system functions. DTS Package Guru is a .NET-based package editor for SQL Server's Data Transformation Services that allows editing of any modifiable package and supports the automation of mass package changes.

The Guru's Guide to SQL Server Architecture and Internals is the essential guide for database developers and admin- istrators alike, regardless of skill level.



0201700476B10012003

Sample Content

Online Sample Chapter

Using SQL Server's XML Support

Downloadable Sample Chapter

Download the Sample Chapter related to this title.

Table of Contents



List of Exercises.


Foreword.


Historical Perspective.


Preface.


Acknowledgments.


Introduction.


About the Author.

I. FOUNDATIONS.

1. Overview.

Chapter Overview.

Chapter Pairs.

About the Code.

2. Windows Fundamentals.

The Win32 API.

User Mode vs. Kernel Mode.

Processes and Threads.

Virtual Memory vs. Physical Memory.

Subsystems.

Dynamic-Link Libraries.

Tools.

Recap.

Knowledge Measure.

3. Processes and Threads.

Processes.

Threads.

Thread Scheduling.

Thread Synchronization.

4. Memory Fundamentals.

Memory Basics.

Virtual Memory.

Heaps.

Shared Memory.

5. I/O Fundamentals.

I/O Basics.

Asynchronous and Nonbuffered I/O.

Scatter-Gather I/O.

I/O Completion Ports.

Memory-Mapped File I/O.

6. Networking Fundamentals.

Overview.

Named Pipes.

Windows Sockets.

Remote Procedure Call.

Recap.

Knowledge Measure.

7. COM.

Overview.

Before COM.

The Dawn of COM.

Basic Architecture.

COM at Work.

Threading Models.

COM and SQL Server.

Recap.

Knowledge Measure.

8. XML.

Overview.

Simplicity Comes at a Price.

A Brief History of XML.

XML vs. HTML: An Example.

Document Type Definitions.

XML Schemas.

Converting XML to HTML Using a Style Sheet.

The Document Object Model.

Processing XML with MSXML.

Resources.

Recap.

Knowledge Measure.

II. SUBSYSTEMS, COMPONENTS, AND TECHNOLOGIES.

9. SQL Server as a Server.

SQL Server and Networking.

The SQL Server Executable.

SQL Server's DLLs.

SQL Server I/O.

SQL Server Components.

Recap.

Knowledge Measure.

10. User Mode Scheduler.

UMS Design Goals.

User Mode vs. Kernel Mode Scheduling.

Preemptive vs. Cooperative Tasking.

How UMS Takes Over Scheduling.

The UMS Scheduler.

The UMS Scheduler Lists.

Going Preemptive.

Hidden Schedulers.

DBCC SQLPERF(umsstats).

Recap.

Knowledge Measure.

11. SQL Server Memory Management.

Memory Regions.

Sizing.

The BPool.

Primitive Allocations.

AWE.

The Lazywriter.

The Memory Managers.

Pulling It All Together.

Recap.

Knowledge Measure.

12. Query Processor.

Key Terms and Concepts.

Parsing.

Optimization Stages.

Optimization Limits.

Parameter Sniffing.

Auto-Parameterization.

Indexing.

Statistics.

Indexable Expressions.

Join Order and Type Selection.

Logical and Physical Operators.

Recap.

Knowledge Measure.

13. Transactions.

The ACID Test.

How SQL Server Transactions Work.

Types of Transactions.

Avoiding Transactions Altogether.

Automatic Transaction Management.

Transaction Isolation Levels.

Transaction Commands and Syntax.

Debugging Transactions.

Optimizing Transactional Code.

Recap.

Knowledge Measure.

14. Cursors.

Overview.

On Cursors and ISAM Databases.

Types of Cursors.

Appropriate Cursor Use.

Transact-SQL Cursor Syntax.

Configuring Cursors.

Updating Cursors.

Cursor Variables.

Cursor Stored Procedures.

Optimizing Cursor Performance.

Recap.

Knowledge Measure.

15. ODSOLE.

Overview.

The sp_OA Procedures.

Automating with ODSOLE.

Automating SQL-DMO by Using ODSOLE.

Using ODSOLE to Automate Custom Objects.

Recap.

Knowledge Measure.

16. Full-Text Search.

Overview.

Architectural Details.

Setting Up Full-Text Indexes.

Full-Text Predicates.

Rowset Functions.

Recap.

Knowledge Measure.

III. DATA SERVICES.

17. Server Federations.

Partitioned Views.

Recap.

Knowledge Measure.

18. SQLXML.

Overview.

MSXML.

FOR XML.

Using FOR XML.

OPENXML.

Using OPENXML.

Accessing SQL Server over HTTP.

URL Queries.

Using URL Queries.

Template Queries.

Mapping Schemas.

Updategrams.

XML Bulk Load.

Managed Classes.

SQLXML Web Service (SOAP) Support.

SQLXML Limitations.

Recap. Knowledge Measure.

19. Notification Services.

How It Works.

Building Your Own Notification Application.

Recap.

Knowledge Measure.

20. Data Transformation Services.

Overview.

Packages.

The Multiphase Data Pump.

The Bulk Insert Task.

The Data Driven Query Task.

ActiveX Transformations.

Other Types of Transformations.

Lookup Queries.

Workflow Properties.

DTS and Transactions.

Controlling Package Workflow through Scripting.

Parameterized DTS Packages.

The DSO Rowset Provider.

Using DTS to Transform Replication Subscriptions.

Custom Tasks.

Controlling DTS through Automation.

Recap.

Knowledge Measure.

21. Snapshot Replication.

Overview.

The Snapshot Agent.

Duties of the Snapshot and Distribution Agents.

Updatable Subscriptions.

Remote Agent Activation.

Replication Cleanup.

Recap.

Knowledge Measure.

22. Transactional Replication.

Overview.

The MSrepl_commands Table.

The sp_replcmds Procedure.

The sp_repldone Procedure.

Update Stored Procedures.

Concurrent Snapshot Processing.

Updatable Subscriptions.

Validating Replicated Data.

Skipping Errors.

Cleanup.

Recap.

Knowledge Measure.

23. Merge Replication.

Overview.

Conflict Resolution.

Generations.

Filtering.

Identity Range Management.

Recap.

Knowledge Measure.

IV. UNDOCUMENTED SQL SERVER.

24. Finding Undocumented Features.

The syscomments Gold Mine.

Goodies in sysobjects.

Scripting Undocumented and System Objects.

The Profiler Treasure Trove.

Snooping around in the Installation Scripts.

DLL Imports.

Recap.

Knowledge Measure.

25. DTSDIAG.

V. ESSAYS.

Why I Really, Really Don't Like Fish!
Pseudo-Techie Tactics 101.
Index. 0201700476T10012003

Foreword

Foreword

When I first started programming computers, I wrote many programs before taking the time to understand the instruction set of the system I was developing on. I got most of these programs working, but debugging complex issues was a painstaking process. As the sophistication of the programs evolved, I eventually hit a wall. When I stepped back and learned the instruction set and underlying architecture of the system, an amazing thing happened: I was able to break through the wall, and I became much more proficient. Frustration and complexity melted away, and, armed with a deep knowledge of the system, I was able to do things that were impossible before.

You've no doubt experienced something similar. Maybe it was while programming computers. Perhaps it was in learning to play a musical instrument--after a short time, you could play scales or simple melodies. However, to truly master an instrument to the point where you can improvise freely requires deep knowledge in both musical theory and proficiency in the instrument. This is the difference between surface knowledge (having the ability to use something) and deep knowledge (knowing how something really works so that you can master it and synthesize new knowledge based on your deep understanding).

Ken Henderson has invested tremendous effort in unlocking the secrets of Microsoft SQL Server, having recently written The Guru's Guide to Transact-SQL (Addison-Wesley, 2000) and The Guru's Guide to SQL Server Stored Procedures, XML, and HTML (Addison-Wesley, 2002). Ken is one of those people who seek deep knowledge. He isn't satisfied in knowing how to operate something--he needs to know how something operates. In his research for The Guru's Guide to SQL Server Architecture and Internals, Ken learned how SQL Server operates, from the ground up--and that is how he presents it.

Part I, Foundations, describes the fundamental substrate on which SQL Server is built. By discussing various Windows services and facilities, this section helps familiarize readers with how SQL Server (or any other high-performance Windows application) communicates with Windows.

Part II, Subsystems, Components, and Technologies, delves into the architecture of SQL Server's core relational engine. Ken discusses the User Mode Scheduler (UMS), a base component of SQL Server that allows it to efficiently scale to thousands of users and process tens of thousands of transactions per second. A highlight of this section is the chapter on the query processor. Ken offers an incredibly clear description of how a query is transformed from SQL text (supplied by an application or user) through parsing, normalization, optimization, and ultimate conversion into a series of physical operators that the execution engine runs to solve the query. Throughout this section Ken describes many of the optimizer's inputs, plan choices, and execution strategies. He also offers a number of "under the cover" tips for how you can peer into this complex portion of the product to determine why the optimizer may have chosen a particular plan to solve your complex query.

Part III, Data Services, discusses the various ways you can interact with SQL Server's core data engine. In this section Ken describes SQL Server's XML facilities and how Data Transformation Services (DTS) can be used to transform and move data into and out of SQL Server. The recently released Notification Services, which can be used to create highly scaled event- and subscription-based data services, is also covered. Finally, Ken describes the various replication technologies supported by SQL Server in great detail.

One obligation in writing a foreword for a book is to provide guidance about who should read it. In this instance, the recommendation is clear: This book is for anyone interested in furthering their existing knowledge of SQL Server into deep knowledge. Some people are naturally inclined to explore any new subject in a deep way. If you are someone who is not satisfied in knowing that something works, but rather you need to know how and why it works, Ken's book will quench your thirst. Perhaps you find that your knowledge of SQL Server, built over a period of time by using the product, no longer offers you explanations to complex issues and questions you face. Ken's book will take you beyond Books Online and into the inner workings of the product. Maybe you simply want to know how SQL Server, a complex and high-performance application, was designed and constructed. Again, The Guru's Guide to SQL Server Architecture and Internals will meet your needs.

I can pretty much guarantee that anyone who uses SQL Server on a regular basis (even those located in Redmond working on SQL Server) can learn something new by reading this book.

David Campbell
June 2003
David Campbell joined Microsoft in 1994 as a developer on the core storage engine of Microsoft SQL Server. He has been with the SQL Server team since then and is currently the Product Unit Manager of the Relational Server team.

Historical Perspective

It is hard to believe that it has been ten years since I was offered a job to work at Microsoft to support its new SQL Server Windows NT product. I never thought I would find myself or our product in the position we are today. My previous experience was as a C programmer and database developer on UNIX systems mainly working with Oracle and Ingres. My perception of Microsoft was purely as a desktop company. The only database I had even seen on a PC was dBase. As I contemplated the job offer, I was naturally skeptical. How could Microsoft even create a product that could compete with the biggest names in the database industry? Fortunately for me, Andrea Stoppani, the director of SQL Support for Microsoft in 1993, convinced me that not only would Microsoft and SQL Server be successful but also that I would find a rewarding career with Microsoft because I would have an opportunity like never before: to train, learn, debug, and dig into the internal "nuts and bolts" of a relational database engine.

Ten years later, that promise has held true. In my role as an escalation engineer at Microsoft, I've had to train, learn, debug, and dig into the internal mechanics of the engine that drives SQL Server. Because of that gained knowledge, I've been asked to advise and provide feedback and insight to the development team with each new release. Through these years, I've witnessed an evolution and revolution with this product, from the early years of supporting SQL Server 4.20 for OS/2 when customers on single processor machines were limited to 16MB of RAM to the enterprise-ready, TPC record-breaking SQL Server 2000 Enterprise Server running on a machine with 64CPUs and 512GB of RAM.

The engine itself has clearly evolved from its early origin. The storage engine and query processor for SQL Server 4.20 through SQL Server 6.5 were all based on the original architectural design that came from the port of the Sybase engine on OS/2. During these years, remarkable changes and additions were performed to make the engine run faster and become a reliable, affordable platform for many users looking to deploy database systems. However, these efforts ultimately reached their limits. This is why SQL Server 7.0 was so significant. Microsoft attracted some of the leading developers in the database industry to design and implement a new architecture for the engine, a foundation to build on for years to come.

The changes and evolution have not just been with the SQL Server engine. In fact, in my early years of supporting SQL Server, the engine was the primary focus of the job because the product was pretty much the engine, sqlservr.exe. The development community back then focused its efforts on Visual Basic or C applications using DB-Library communicating over named pipes or IPX/SPX. ODBC was just an idea on Kyle Geiger's computer. Today, it is more common for Microsoft support engineers to deal with multitiered Web-based applications supporting online business retail applications with thousands of users all communicating over TCP/IP. The mind-set of supporting "just the engine" no longer applies. The SQL Server product has expanded to include a rich framework of data services including Multi-Server Job Scheduling, Data Replication, XML, Data Transformation Services, and Notification Services.

As I reflect on the changes to the engine and the core additions that have made it such a popular product, I think about the common questions I get from customers and other Microsoft employees: "How can I learn more about what makes SQL Server so powerful? How can I gain expert knowledge of some of the internals of the SQL Server engine in order to maximize the usage of the product?" My answer is always, "Think like a programmer." To be more specific, "Think like a Windows programmer."

I have learned the importance of gaining a solid understanding of the foundation of technology that the engine uses to perform its work. This includes a range of Windows programming topics such as processes, threads, synchronization, asynchronous I/O, dynamic linked libraries, virtual memory, networking, and COM. Regardless of the various SQL Server releases over the years, learning these topics has been essential to my understanding of the internals of the product. Learning these topics takes much more than just reading about them. You must apply the knowledge and truly understand the meaning behind the concepts. Don't just read about what structure exception handling is--understand why it has become an important feature for the SQL Server engine to use. Part I of this book can help guide you toward that goal. It provides concise, comprehensible coverage of Windows programming fundamentals. But don't just read those chapters. Go through the examples and be sure you understand the answers to the questions in each chapter. Once you master a solid knowledge of these concepts, you will have the right foundation and frame of mind to understand Part II of this book, which covers the internals of the core components that make up the SQL Server engine. Armed with this information, you will be able to broaden and round your skills by understanding the technologies covered in Part III that complement the engine and provide the complete database services product that SQL Server has become.

SQL Server has grown as a technology and as a force in the database industry. The number of high-quality books on this product alone is a leading indicator. When I started at Microsoft in 1993, there were no books on Microsoft SQL Server (and only one was produced within the next year). Today you can search the Web or go to your local bookstore and find dozens of books dedicated to this product ranging from topics on performance tuning to database administration to XML. The development of this book is a testament to the product's success. The book seeks to expand the knowledge of important topics about SQL Server in order to broaden the level of expertise worldwide. With knowledge there is power, and this book is about empowering SQL Server users, developers, and administrators to get the most out of the product.

Bob Ward
June 2003
Bob Ward joined Microsoft in 1993 as a support engineer for Microsoft SQL Server. He is currently an escalation engineer in SQL Server Support.

Index

Download the Index file related to this title.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020