SQL Server 2000 Performance

66
Microsoft® SQL Server TM  2000 Performance Microsoft Corporation

Transcript of SQL Server 2000 Performance

Page 1: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 1/66

Microsoft® SQL Server TM 2000 Performance

Microsoft Corporation

Page 2: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 2/66

What We Will Cover

Locking

Query Processor

Query Tuning

System Configuration

Performance Monitoring

Page 3: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 3/66

Session Prerequisites

This session assumes that youunderstand the fundamentals of

Windows ®  2000 Server

SQL Server 2000 System Monitor

Level 200

Page 4: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 4/66

Agenda

Locking

Query Processor

Query Tuning

System Configuration

Performance Monitoring

Page 5: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 5/66

Lock ManagerWhat it does for you

Acquires and Releases Locks

Maintains compatibility BetweenLock Modes

Resolves Deadlocks

Escalates Locks

Uses 2 Locking Systems

Shared Data Locks

Internal latches for Internal data andindex concurrency

Page 6: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 6/66

LockingLocking Granularity for user data

Table

Page Page Page

Row Row Row

Page 7: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 7/66

Lock Isolation Levels

Supports all 4 ANSI and ISOisolation levels

Serializable

Repeatable Read Read Committed - default

Read Uncommitted

Page 8: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 8/66

LockingUser data lock types – Shared

Acquired automatically when data isread

Applies to Table, Page, Index Key or row.

Many processes can hold a shared lockon the same data.

Cannot be locked exclusively while inshared lock mode*

*Unless it is the same process that holds the shared lock

Page 9: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 9/66

LockingUser data lock types – Exclusive

Automatically acquired when data ismodified

Only one process can hold at a time on

any data. Held until the end of a Transaction

All other lock requests by other

processes will be refused. Can use Query hints to decide to read

locked data.

Page 10: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 10/66

LockingUser data lock types – Update

Hybrid of shared and exclusive

Acquired when a search is requiredbefore any data modification

Allow others to still read while lockapplied

Needs an exclusive lock to modify data

Data can have many shared but only oneupdate

Page 11: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 11/66

LockingUser data lock types – Intent

Not a real lock mode just a qualifiere.g.

Intent Update lock

Used by SQL as resource lockindicator

Page 12: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 12/66

LockingUser data lock types – Special

3 special modes

Schema Stabi l i ty   – used when queries aremodified, prevents scheme modification

locks. Scheme Modi f icat ion  – used when table

struc tures are being m odif ied

Bu lk update  – used when the BULK INSERT

or BCP command are used.

Page 13: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 13/66

LockingViewing lock information 

Use sp_lock stored procedure

Use sp_lock2 stored procedure

Shows current and waiting locks

Spid Dbid Objid IndId Type Resource Mode Status

54 pubs 19723 2 TAB IS GRANT

58 pubs 19755 1 PAG 1:88 IX GRANT

52 Pubs 0 0 DB S GRANT

Page 14: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 14/66

LockingViewing lock information - Type

Abbr Resource Internal

Code

Description / Example

DB Database 2

TAB Table 5 Table id 261775902EXT Extent 8 File/ page number 1:96

PAG Page 6 File/ page number 1:104

KEY Key 7 Hashed value ac0001a10a00

AC Row 9 File/page/slot number 1:151:4APP Application 10 Hash of the app name MYpr8dea

Page 15: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 15/66

LockingViewing lock information - Mode

Abbreviation Mode Internal code

S Shared 4

X Exclusive 6

U Update 5IS Intent shared 7

IU Intent update 8

IX Intent exclusive 9

SIX Shared with intent exclusive 11

Sch-S Schema stability 2

Sch-M Schema modification 3

BU Bulk update 13

Page 16: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 16/66

Lock Block

Lock resource block

Grant WaitConvert

Lock Block

Lock resource block

Grant WaitConvert

Lock

Owner

Block

Lock

Owner

Block 

Lock

Owner

Block 

Locking ArchitectureLock hash table

All owner blocks

From same transaction

Linked together

Page 17: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 17/66

LockingRow Versus Page Level

Lock Overhead

Each lock – 32 bytes

Each Process holding lock – 32 bytes Each Process waiting for lock – 32

bytes

Page Level – 8k

Row Level – dependent on Row size

Which to use depends onapplication

Page 18: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 18/66

Demonstration 1

Viewing SQL Server Locks

Page 19: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 19/66

Agenda

Locking Query Processor

Query Tuning

System Configuration

Performance Monitoring

Page 20: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 20/66

Query ProcessorStatement Compilation Process 

Parse the statement

Create a sequence tree

Normalise the tree

SQL DMLStatement?

Compile the TSQLStatement procedurally

Compile the TSQLStatement procedurally

Create Query Graph

Optimize and create Plan

Yes

 No

Page 21: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 21/66

Query Processoroptimizing a statement

Trivial plan optimizer

Simplification

Statistics loading

Cost-based optimizer

Phases 1 to n-1

Full optimization for

Serial execution

Output plan

Full optimization for

parallel execution

Found a cheap

Plan?

1

1

Found

Plan?

Cheapest cost

Is > than parallelism

Threshold?

No

No

No

 Yes

 Yes

 Yes

Page 22: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 22/66

Query ProcessorHow the Optimizer Works

Query Analysis Index Selection

Join Selection

Nested iteration

Hashing

Merging

Page 23: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 23/66

Query ProcessorCaching – costing a query plan

Allocate memory

From buffer cache

Set initial cost to

Creation cost

Ad-hoc &

Cheap to

Compile?

Type of

Plan?

Put plan in cache

Set initial cost

To Zero

Don’t Cache  Yes

No

Ad-hoc

Page 24: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 24/66

Query ProcessorCompilation and execution flow

Plan in

Cache?

Parse/normalize

Compile TSQL

Optimize statements

Put plan in cache

Retrieve plan from cache

Wait for memory grant scheduler

Open (active) plan

Run plan to completion

Plan need to

Be recompiled?

No

No

 Yes

 Yes

Page 25: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 25/66

Demonstration 2

Query AnalyzerObtain statistics about a query

Use the graphical showplanUse the estimated showplan

Page 26: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 26/66

Agenda

Locking Query Processor

Query Tuning

System Configuration

Performance Monitoring

Page 27: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 27/66

Query TuningTuning – When to Start

Start at the Beginning

Consider performance before youeven write your first line of code

Be sure that you've set up a gooddatabase structure

Create what appear to be usefulindexes

Make sure all analysis is done witha representative workload

Page 28: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 28/66

Query TuningApplication and Database Design

Provides Biggest PerformanceGains

Normalize

Evaluate Your Critical Transactions

Keep Table Row Lengths and KeyLengths Compact

Create Useful Indexes

Benchmark, Prototype and Test

Page 29: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 29/66

SQL Server

SQL ProfilerIndex Tuning

Wizard

Query tuningIndex Creation and Tuning

Page 30: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 30/66

Query TuningMonitoring Query Performance

STATISTICS – Input/Output

Logical Reads

Physical Reads

Read Ahead Reads

Scan Count 

STATISTICS - Time

 SHOWPLAN

Showplan_Text, Showplan_All,Graphical Showplan

Page 31: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 31/66

Query TuningQuery Hints

Query hints should be used forspecial cases—not as standardoperating procedure

Hint Types:

Join Hints

Index Hints

Lock Hints

Processing Hints

Page 32: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 32/66

Query TuningBlocking and Deadlocks – How to

Resolve Them Keep transactions as short as

possible

Never add a pause within atransaction for user input

When you process a result set,

process all rows as quickly aspossible

For browsing applications, considerusing cursors with optimistic

concurrency control

Page 33: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 33/66

Query TuningDeadlocks – How to Resolve Them

To prevent cycle deadlocks, makeall processes access resources in aconsistent order.

Reduce the transaction isolationlevel if it's suitable for theapplication.

To prevent conversion deadlocks,explicitly serialize access to aresource.

Q t i

Page 34: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 34/66

Gather information about the application’sbehavior Use SQL Profiler

Analyze the information Query Analyzer

Index Tuning Wizard

Apply Changes Index Tuning Wizard

Enterprise Manager

Query tuningPerformance Tuning

A step-by-step approach

Page 35: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 35/66

Demonstration 3

Load Simulator

Page 36: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 36/66

Demonstration 4

Index Tuning WizardAnalyze workload

View reports

Apply suggested indexes

Page 37: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 37/66

Agenda

Locking Query Processor

Query Tuning

System Configuration

Performance Monitoring

Page 38: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 38/66

System ConfigurationResource Allocation and System

File Location

Ensure that MaximizeData Throughput forNetwork Applicationsis selected for File andPrint Services

Do not locate SQLServer files on samedrive as PAGEFILE.sys

Page 39: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 39/66

System ConfigurationConfiguring SQL Resources

Sp_configure

EXE sp_configure

RE ONFIGURE

With override

Enterprise Manager

Page 40: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 40/66

System ConfigurationConfiguring SQL Resources

Min Server Memoryand Max ServerMemory

Set Working Set Size Minimum Query

Memory

Page 41: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 41/66

System ConfigurationConfiguring SQL Resources

Scheduling

Lightweight Pooling

Affinity mask Priority boost

Max Worker Threads

Disk I/O Options Recovery Interval

Page 42: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 42/66

System ConfigurationConfiguring SQL Resources  Query Processing Options

Min Memory Per Query

Index Create Memory

Query Wait

Query Governor Cost Limit

Max Degree of Parallelism

Page 43: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 43/66

System ConfigurationConfiguring SQL Resources 

Database Options

Read Only

Single User

Autoclose

Autoshrink

Auto Create Statistics

Auto Update Statistics

S C f

Page 44: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 44/66

System ConfigurationConfiguring SQL Resources 

Buffer Manager

―Pintable‖ Option 

Monitoring Performance SQLPERF(WAITSTATS)

SQLPERF(LRUSTATS)

Page 45: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 45/66

Demonstration 5

SQL System ConfigurationEnterprise Managersp_configure

A d

Page 46: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 46/66

Agenda

Locking Query Processor

Query Tuning

System Configuration

Performance Monitoring

P f M it i

Page 47: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 47/66

Performance MonitoringHow to Use SQL Profiler

Monitor server events

Capture SQL statements

Identify poorly-performing queries

Replicate problems for diagnosis

P f M it i

Page 48: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 48/66

Performance MonitoringWhen to Use SQL Profiler

Debug T-SQL or stored procedures

Monitor the performance of SQLServer to tune workloads

Capture deadlocking scenarios

Playback events captured

P f

Page 49: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 49/66

PerformanceMonitoringSQL Profiler   Event Categories

Data Columns Filters

Page 50: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 50/66

Demonstration 6

SQL ProfilerTrace queries on a database

Create Trace Wizard

P f M it i

Page 51: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 51/66

Performance MonitoringSystem Stored Procedures

SQL Trace

sp_trace_create

sp_trace_setevent

sp_trace_setf i l ter

sp_trace_setstatus

sp_trace_generateevent

SQLDIAG

Page 52: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 52/66

Demonstration 7

System Diagnostic Procedures 

P f M it i

Page 53: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 53/66

Performance MonitoringUsing System Monitor

Monitors Entire SystemPerformance

System Counters

SQL Counters

P f M it i

Page 54: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 54/66

Performance MonitoringSystem Monitor

Monitor multiple computerssimultaneously

View and change charts to reflect

current activityExport data to spreadsheet or

database applications

Add system alerts to notify you ofpossible problems

P f M it i

Page 55: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 55/66

Performance MonitoringSystem Monitor

Run an application when a countervalue exceeds a user-defined value

Create log files

Append log files to form a long-termarchive

View current-activity reports

Create reports from existing log files

Save chart, alert, log, or reportsettings

P f M it i

Page 56: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 56/66

Performance MonitoringSystem Monitor - System Counters

System:

Context Switches/sec

Processor: %Processor Time

%Privileged Time

%User Time

Processor Queue Length

P f M it i

Page 57: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 57/66

Performance MonitoringSystem Monitor - System Counters 

SQL Server: Memory Manager:

Total Server Memory(KB)

Process: Working Set Counter For SQL Server

Instance

SQL Server Buffer Manager: Buffer Cache Hit Ratio

Performance Monitoring

Page 58: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 58/66

Performance MonitoringSystem Monitor - System Counters

Memory:

Pages/sec SQLServer: Databases

Transactions/sec

PhysicalDisk: Disk Transfers/sec

Page 59: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 59/66

Demonstration 8

System Monitor

Set Up System Monitor

Session Summary

Page 60: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 60/66

Session Summary

SQL Server 2000 can use severaltechniques to enhance performanceof applications

Techniques include: Application and Database design

Query Tuning

System Configuration

Performance Monitoring

For More Information

Page 61: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 61/66

For More Information…  TechNet Web site at

www.microsoft.com/technet Microsoft Official Curricula (MOC)

Course # 2071 - Querying Microsoft SQL Server 2000 with Transact-SQL

Course # 2072 - Administering a Microsoft SQL Server 2000 Database 

Microsoft Press ―Inside SQL Server 2000‖, Microsoft Press, 2000., or: 

http://mspress.microsoft.com/books/4297.htm  

―Microsoft® SQL Server™ 2000 Resource Kit‖, http://www.mspress.microsoft.com/PROD/BOOKS/4939.HTM 

―Microsoft® SQL Server™ 2000 Reference Library ―, http://mspress.microsoft.com/prod/books/5001.htm  

―Microsoft® SQL Server™ 2000 Administrator's Companion‖, http://mspress.microsoft.com/books/4519.htm  

―Microsoft® BackOffice® 4.5 Resource Kit ‖, Microsoft Press, 1999, or: http://mspress.microsoft.com/prod/books/2483.htm  

Training

Page 62: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 62/66

TrainingTraining Resources for IT Professionals

Querying Microsoft SQL Server 2000 with Transact-SQL Course # 2071—Two days—Instructor-led or eLearning 

Available: through MS CTECs in your area

Administering a Microsoft SQL Server 2000 Database

Course # 2072—Five days—Instructor-led

Available: through MS CTECs in your area

To locate a training provider for this course, please access

mcspreferral.microsoft.com/default.asp Microsoft Certified Technical Education Centers (CTECs)

are Microsoft’s premier partners for training services 

Where Can I Get TechNet?

Page 63: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 63/66

Where Can I Get TechNet?

Visit TechNet Online atwww.microsoft.com/technet

Register for the TechNet Flashwww.microsoft.com/technet/register/flash.asp

Join the TechNet Online forum atwww.microsoft.com/technet/discuss

Become an TechNet Subscriber attechnetbuynow.one.microsoft.com

Attend More TechNet Events

Become A Microsoft

Page 64: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 64/66

Become A MicrosoftCertified Systems Engineer What Is MCSE?

Premier certification for professionals who analyzethe business requirements and design andimplement the infrastructure for business solutions

based on the Microsoft server software. How do I become a Windows 2000 MCSE?

Pass 4 Core Exams

Pass 1 Design Exam

Pass 2 Electives from a comprehensive list

Where Do I Get More Information? For more information about certification

requirements, exams, and training options,visit www.microsoft.com/mcp

Page 65: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 65/66

Session Credits

Page 66: SQL Server 2000 Performance

8/11/2019 SQL Server 2000 Performance

http://slidepdf.com/reader/full/sql-server-2000-performance 66/66

Session Credits

Authors: Dan Keables, Joel Ware IV Producer/Editor: Alan Le Marquand

Thanks to our Microsoft technical

specialists who reviewed this session: John Doe