Eternal Story on Temporary Objects

Similar documents
Into into Locking and Blocking. Dmitri Korotkevitch ( 1

TempDB how it works? Dubi Lebel Dubi Or Not To Be

IT Best Practices Audit TCS offers a wide range of IT Best Practices Audit content covering 15 subjects and over 2200 topics, including:

SQL Server Internals: The Practical Angle Sneak Peek. Dmitri Korotkevitch Moderated by Roberto Fonseca

SQL Server DBA Course Content

Natural Born Killers, performance issues to avoid

Designing Database Solutions for Microsoft SQL Server (465)

Optimizing tempdb Performance

Common non-configured options on a Database Server

SQL Server: Practical Troubleshooting. Dmitri Korotkevitch (

Microsoft SQL Server Database Administration

New Features in SQL That Will Change the Way You Tune

Ms Sql Server 2008 R2 Check If Temp Table Exists

SQLSaturday Sioux Falls, SD Hosted by (605) SQL

PERFORMANCE TUNING SQL SERVER ON CRAPPY HARDWARE 3/1/2019 1

Performance Troubleshooting Made Easier

Get the Skinny on Minimally Logged Operations

SQL Server Myths and Misconceptions

Maintaining a Microsoft SQL Server 2005 Database Course 2780: Three days; Instructor-Led

Internals of Active Dataguard. Saibabu Devabhaktuni

<Insert Picture Here> Looking at Performance - What s new in MySQL Workbench 6.2

DESIGNING DATABASE SOLUTIONS FOR MICROSOFT SQL SERVER CERTIFICATION QUESTIONS AND STUDY GUIDE

IBM DB2 11 DBA for z/os Certification Review Guide Exam 312

Troubleshooting With Extended Events

Data Partitioning. For DB Architects and Mere Mortals. Dmitri Korotkevitch

Activant Solutions Inc. SQL Server 2005: Data Storage

The dangerous Beauty of Bookmark Lookups

SQL Coding Guidelines

TEN QUERY TUNING TECHNIQUES

MILOŠ RADIVOJEVIĆ, PRINCIPAL DATABASE CONSULTANT, BWIN GVC, VIENNA, AUSTRIA

<Insert Picture Here> DBA Best Practices: A Primer on Managing Oracle Databases

[MS10987A]: Performance Tuning and Optimizing SQL Databases

Foreword Preface Db2 Family And Db2 For Z/Os Environment Product Overview DB2 and the On-Demand Business DB2 Universal Database DB2 Middleware and

Jyotheswar Kuricheti

Course Outline. SQL Server Performance & Tuning For Developers. Course Description: Pre-requisites: Course Content: Performance & Tuning.

SQL Server 2016 Query Store

70-459: Transition Your MCITP: Database Administrator 2008 or MCITP: Database Developer 2008 to MCSE: Data Platform

6232B: Implementing a Microsoft SQL Server 2008 R2 Database

Monitoring & Tuning Azure SQL Database

Synergetics-Standard-SQL Server 2012-DBA-7 day Contents

Course 6231A: Maintaining a Microsoft SQL Server 2008 Database

Oracle Database 11g: Performance Tuning DBA Release 2

Performance Tuning & Optimizing SQL Databases Microsoft Official Curriculum (MOC 10987)

Course 6231A: Maintaining a Microsoft SQL Server 2008 Database

T-SQL Performance Issues What you should know to avoid, find and resolve them. Claire Mora

Querying Microsoft SQL Server (461)

DESIGNING FOR PERFORMANCE SERIES. Smokin Fast Queries Query Optimization

Index. B Batches comparing, bit or 64-bit architecture, 5 Blocking, 42 Buff er cache, 143 Bulk changed map (BCM), 85 87

EZY Intellect Pte. Ltd., #1 Changi North Street 1, Singapore

Oracle Database 11g: Performance Tuning DBA Release 2

Introduction to Statistics in SQL Server. Andy Warren

Triangle SQL Server User Group Adaptive Query Processing with Azure SQL DB and SQL Server 2017

CONFIGURING SQL SERVER FOR PERFORMANCE LIKE A MICROSOFT CERTIFIED MASTER

Tuesday, April 6, Inside SQL Server

Microsoft SQL Server" 2008 ADMINISTRATION. for ORACLE9 DBAs

Maintaining a Microsoft SQL Server 2008 Database (Course 6231A)

SQL Server Administration 10987: Performance Tuning and Optimizing SQL Databases. Upcoming Dates. Course Description.

Oracle Database 12c Performance Management and Tuning

Best Practices for Deployment of SQL Compliance Manager

Getting the most from your SAN File and Filegroup design patterns. Stephen Archbold

Index. Symbol function, 391

5/2/2015. Overview of SSIS performance Troubleshooting methods Performance tips

Will my workload run faster with In-Memory OLTP?

SQL Server 2014 Training. Prepared By: Qasim Nadeem

Course Outline. Performance Tuning and Optimizing SQL Databases Course 10987B: 4 days Instructor Led

Hardware Intel Core I5 and above 4 GB RAM LAN Connectivity 500 MB HDD (Free Space)

Oracle Database 11g : Performance Tuning DBA Release2

Background. Let s see what we prescribed.

Exam Questions

Scale out Read Only Workload by sharing data files of InnoDB. Zhai weixiang Alibaba Cloud

Query Store What s it all about?

MySQL 8.0: Atomic DDLs Implementation and Impact

Oracle Database 12c: Performance Management and Tuning

Seminar 3. Transactions. Concurrency Management in MS SQL Server

Oralogic Education Systems

Locking & Blocking Made Simple

Many-to-Many One-to-One Limiting Values Summary

Tables. Tables. Physical Organization: SQL Server Partitions

Physical Organization: SQL Server 2005

Learning Objectives : This chapter provides an introduction to performance tuning scenarios and its tools.

Build ETL efficiently (10x) with Minimal Logging

Exadata Implementation Strategy

MySQL Database Administrator Training NIIT, Gurgaon India 31 August-10 September 2015

exam.100q. Number: Passing Score: 800 Time Limit: 120 min Provisioning SQL Databases

Tuning SQL Server for SharePoint. Daniel Glenn InfoWorks, Inc.

How to Scale MongoDB. Apr

Build ETL efficiently (10x) with Minimal Logging

Database Management and Tuning

High Availability- Disaster Recovery 101

Module 9: Managing Schema Objects

OpenWorld 2018 SQL Tuning Tips for Cloud Administrators

DB2 Performance Essentials

Course Contents of ORACLE 9i

It Depends. Database administration for developers

Oracle Database 11g Data Guard

Where is Database Management System (DBMS) being Used?

SQL Server 2014: In-Memory OLTP for Database Administrators

Performance Tuning and Optimizing SQL Databases (10987)

InnoDB: Status, Architecture, and Latest Enhancements

CA Unified Infrastructure Management Snap

Transcription:

Eternal Story on Temporary Objects Dmitri V. Korotkevitch http://aboutsqlserver.com

About Me 14+ years of experience working with Microsoft SQL Server Microsoft SQL Server MVP Microsoft Certified Master SQL Server 2008 Email: dmitri@aboutsqlserver.com Blog: http://aboutsqlserver.com 2

Agenda 3

What is TempDB? 4

Mid-level DBA 5

Senior DBAs 6

Temporary Tables Temporary Tables == Regular Tables No Views No Triggers New Statistics Recompilation Threshold of 6 rows KEEP PLAN hint removes threshold 7 7

Temporary Tables Temp Table Creation: System Objects and Allocation Maps changes (Database and Log Files) Writing Log Records to tempdb log file Logical or Physical Reads from UserTbl Writing Data Pages to tempdb data file(s) Extents and Pages allocations for #StageTbl data Temp Table Deletion: System Objects and Allocation Maps changes (Database and Log Files) 8 8

Temporary Tables Staging large amount of data is expensive Good use-cases: Query Simplification Improving Cardinality Estimations (especially in case of UDF) Reducing Locking Time 9 9

Demo: Using Temporary Tables 10

Temporary Objects Caching SQL Server keeps IAM and one data page per index Requirements: Objects in SP and Triggers <8MB No Named Constraints No DDL changes after creation (DROP is OK) 11 11

Demo: Temporary Objects Caching 12

Table Variables Lightweight Temporary Tables Stored in TempDB No Indexes; however, Primary Key and Unique Constraints are supported No Statistics Statement-level rollback only 13 13

Demo: Using Table Variables 14

Table Variables vs. Temporary Tables Temporary Tables Table Variables 15 15

Table Variables vs. Temporary Tables Use Table Variables when missing statistics does not affect execution plans Small amount of data No joins with other tables Plans are: PK/UQ Singleton Lookup OR Full Scan Generally, Temporary Tables are the safer choice 16 16

Table Types and Table-Valued Parameters 17 17

Table Types and Table-Valued Parameters Scope / Visibility Temporary Tables: Call Stack Table Variables: Current Batch only Table Types: Passing Table Variable as parameter to T-SQL routine Table-Valued Parameters is one of the fastest ways to pass batch of rows from client to T-SQL module Performance is on-par with SqlBatchCopy Schema should strictly match.net DataTable No Sql_variant support (Bug in.net) 18 18

Demo: Table Types and TVP 19

Spools Internal Temporary Tables / Caches Used for Optimization and Consistency 20 20

Demo: Spools 21

TempDB Spills 22 22

TempDB Spills Sort or Hash operators do not have enough memory Often incorrect memory grant estimations Outdated Statistics Incorrect row-size estimation Monitor Hash and Sort warnings Extended Events (SQL Server 2012+) SQL Trace 23 23

Demo: Tempdb Spills 24

Row Versioning / Version Store READ COMMITTED SNAPSHOT / SNAPSHOT AFTER UPDATE/DELETE triggers ONLINE INDEX REBUILD MARS 25 25

Demo: Version Store 26

TempDB Best Practices Reduce TEMPDB load Put tempdb to fastest drive array Use redundant array if downtime is unacceptable Use T1118 Disabling Mixed Extents Allocation Create multiple files < 8 logical CPU: 1 file per CPU >= 8 logical CPU: 8 files and add files in groups of 4 if needed (PAGELATCH waits on tempdb) All files should be the same size with auto-growth in MB Utilize temporary objects caching 27 27

TempDB as Staging Area Good Logging is more efficient than with users databases DB does not need REDO support SIMPLE recovery mode Does not write to transaction log in users databases LOG Backups HA Strategies Bad Data could disappear in case of SQL Server restart or HA failover 28 28

We covered Temporary Objects Temporary Tables Table Variables Table Types and Table-Valued Parameters Spools Spills Version Store Temporary Objects Caching Best Practices 29 29

Q & A Thank you very much for attending! Slide Deck and Code Samples will be posted at: http://aboutsqlserver.com/presentations Email: dmitri@aboutsqlserver.com Blog: http://aboutsqlserver.com 30 30

Thank You for Attending