SQL Server Indexing: Using a Low-Selectivity BIT Column First Can Be the Best Strategy
Total Page:16
File Type:pdf, Size:1020Kb
SQLCAT’s Guide to: Relational Engine Microsoft SQLCAT Team Summary: This ebook is a collection of the most popular technical notes, tools and blogs authored by the SQLCAT team and posted to their blog over the course of several years. It covers SQL technology from 2005 to 2012. Category: Guide & Reference Applies to: SQL Server 2005 to 2012 Source: SQLCAT Blog E-book publication date: September 2013 Copyright © 2012 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN- US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly o Contents Section 1: Administration ............................................................................................................................. 5 DBCC Checks and Terabyte-Scale Databases ............................................................................................ 6 Scheduling Sub-Minute Log Shipping in SQL Server 2008 ...................................................................... 12 Tuning Backup Compression Part 2 ........................................................................................................ 15 Restart SQL Audit Policy and Job ............................................................................................................ 25 SQL DMVStats Toolkit ............................................................................................................................. 26 Section 2: Database Design ......................................................................................................................... 27 SQL Server Partition Management Tool ................................................................................................. 47 Character data types versus number data types: are there any performance benefits? ...................... 28 The Many Benefits of Money…Data Type! ............................................................................................. 38 How many files should a database have? - Part 1: OLAP workloads ...................................................... 43 Section 3: Fast-track .................................................................................................................................... 47 Lessons Learned and Findings from a Large Fast-Track POC .................................................................. 49 Section 4: Performance ............................................................................................................................... 70 Top Tips for Maximizing the Performance & Scalability of Dynamics AX 2009 systems on SQL Server 2008 ........................................................................................................................................................ 71 Introduction: ......................................................................................................................................... 102 Conclusions: .......................................................................................................................................... 111 Top SQL Server 2005 Performance Issues for OLTP Applications ......................................................... 112 Table-Valued Functions and tempdb Contention ................................................................................. 114 Resolving PAGELATCH Contention on Highly Concurrent INSERT Workloads ...................................... 130 SQL Server Indexing: Using a Low-Selectivity BIT Column First Can Be the Best Strategy ..................... 85 Tuning the Performance of Backup Compression in SQL Server 2008 ................................................... 71 Maximizing Throughput with TVPs ....................................................................................................... 130 Bulk Loading Data into a Table with Concurrent Queries ..................................................................... 140 Section 5: Real World Scenarios ............................................................................................................... 146 Lessons Learned from Benchmarking a Tier 1 Core Banking ISV Solution - Temenos T24 ................... 147 Section 6: Replication ............................................................................................................................... 155 Initializing a Transactional Replication Subscriber from an Array-Based Snapshot ............................. 156 Upgrading Replication from SQL Server 2000 32-Bit to SQL Server 2008 64-Bit without re-initialization .............................................................................................................................................................. 167 Section 7: Service Broker .......................................................................................................................... 168 SQL Server Service Broker: Maintaining Identity Uniqueness Across Database Copies ....................... 169 Section 8: Troubleshooting ....................................................................................................................... 172 Diagnosing Transaction Log Performance Issues and Limits of the Log Manager ................................ 173 Eliminating Deadlocks Caused By Foreign Keys with Large Transactions ............................................. 180 Resolving scheduler contention for concurrent BULK INSERT .............................................................. 187 Response Time Analysis using Extended Events ................................................................................... 191 Memory Error Recovery in SQL Server 2012 ........................................................................................ 192 Section 9: SQL Top 10 ............................................................................................................................... 195 Top 10 Hidden Gems in SQL 2008 R2 .................................................................................................... 196 Top 10 SQL Server 2008 Features for the Database Administrator (DBA) ........................................... 209 Top 10 SQL Server 2008 Features for ISV Applications ......................................................................... 221 Top 10 Hidden Gems in SQL Server 2005 ............................................................................................. 196 Top 10 Best Practices for Building a Large Scale Relational Data Warehouse ..................................... 230 Storage Top 10 Best Practices ............................................................................................................... 196 Top 10 Best Practices for SQL Server Maintenance for SAP ................................................................. 234 Section 1: Administration DBCC Checks and Terabyte-Scale Databases 1. Overview: Historically, the SQL Server product team and the support organization have recommended that all maintenance plans for Microsoft® SQL Server® include running DBCC CHECKDB on a regular basis to detect and correct potential corruption in the database. In the case of mission-critical applications such as trading systems, medical records, and banking operations, many customers have interpreted this recommendation as requiring even a daily DBCC check to ensure that no errors are present before performing a backup operation. However, since the SQL Server 6.5 days, in which a daily DBCC CHECKDB may have been a best practice, there have been several trends - both challenges and opportunities -- that make it worth reconsidering the way that DBCC should fit into SQL Server database maintenance plans, especially for large databases. Challenges: Many mission-critical databases have grown to massive size. It is not unusual to find databases in the 5-20 terabyte range on SQL Server, in which a DBCC operation requires many hours to complete. This is usually incompatible with a daily maintenance window, if feasible at all on a 24x7 system. Every new version of SQL Server has expanded the range of logical checks performed by DBCC so that it has become more time-consuming to execute. For example, SQL Server 2005 introduced data purity checks to validate that data present in columns adheres to valid ranges for the data type. SQL Server 2005 also introduced checks that verify the integrity of indexed views. Opportunities: Enterprise-class storage subsystems and the widespread use of RAID, especially in mission-critical settings, have made the storage tier much less prone to physical corruption. SQL Server has introduced new mechanisms to detect the