SQL パフォーマンス チューニング ~ プランガイドの利用~

  • Upload
    ismail

  • View
    342

  • Download
    31

Embed Size (px)

DESCRIPTION

SQL パフォーマンス チューニング ~ プランガイドの利用~. 中上級編 vol. 2 前編:クエリヒント. SQL パフォーマンス チューニング 中上級編 3 回シリーズ. 2010 年 9 月公開 中上級編 vol. 1 カバーリングインデックス / クエリヒントの利用 2010 年 10 月 公開 中上級編 vol. 2 プランガイドの利用 2010 年 11 月公開 予定 中上級編 vol. 3 PSSDIAG/SQLNEXUS ツールの利用. 概要. パフォーマンス に関する 悩み シナリオ シナリオ 1: クエリヒント - PowerPoint PPT Presentation

Citation preview

Title of Presentation

vol. 2

SQL 1Seminar NameSQL 3 20109 vol. 1/

201010 vol. 2

201011 vol. 3PSSDIAG/SQLNEXUS 2Seminar Name

1:

2:

3Seminar Name

()

SQL Server 2005

1: FORCESEEK

1: tab1a1inta2inta3nchar(2000)

select a1,a2,a3 from tab1where a1 > 18000FORCESEEK

EXEC sp_create_plan_guide @name = N'PLANGUIDE1', @stmt = N'select a1,a2,a3 from tab1 where a1 > 18000', @type = N'SQL', @module_or_batch = NULL, @params = NULL, @hints = N'OPTION (TABLE HINT (tab1,FORCESEEK))'-- create database Scenario_2goALTER DATABASE [Scenario_2] SET AUTO_UPDATE_STATISTICS OFF WITH NO_WAITgo

-- use Scenario_2gocreate table tab1 (a1 int, a2 int, a3 nchar(2000))Go

1:-- create index IX_tab1_a1 on tab1(a1)go--OFFEXEC sp_autostats tab1,'OFF'go-- declare @icnt int set @icnt=1 while @icnt < 20001begin insert into tab1 values(@icnt,@icnt,N'') set @icnt = @icnt + 1end 1: 1:-- Management Studio -- DBCC DROPCLEANBUFFERSDBCC FREEPROCCACHE

SET STATISTICS PROFILE ONSET STATISTICS IO ONSET STATISTICS TIME ON

select a1,a2,a3 from tab1 where a1 > 18000

SET STATISTICS TIME OFFSET STATISTICS IO OFFSET STATISTICS PROFILE OFF 1: 'tab1' 1 10000 80

SQL Server : CPU = 78 = 1061

1:-- -- "FORCESEEK"

EXEC sp_create_plan_guide @name = N'PLANGUIDE1', @stmt = Nselect a1,a2,a3 from tab1 where a1 > 18000, @type = N'SQL', @module_or_batch = NULL, @params = NULL, @hints = N'OPTION (TABLE HINT (tab1,FORCESEEK))';

@stmt @hints

1:-- select plan_guide_id, name,is_disabled,scope_type, query_text, hints from sys.plan_guides

-- (is_disabled 1exec sp_control_plan_guide @operation = N'ENABLE',@name = N'PLANGUIDE1'

1: 'tab1' 1 2017

SQL Server : CPU = 78 = 283

vol. 2

SQL 15Seminar Name 2:

2: tab1a1inta2inta3nchar(2000)

select a1,a2,a3 from tab1where a1 > 18000EXEC sp_create_plan_guide @name = N'PLANGuide2', @stmt = N'select a1,a2,a3 from tab1 where a1 > 18000', @type = N'SQL', @module_or_batch = NULL, @params = NULL, @hints = NOPTION (USE PLAN N'')' 'tab1' 1 10000 80

SQL Server : CPU = 78 = 1061 2:

2: XML-- XML

1) Microsoft SQL Server 20082005 - - SQL Server Profiler []-[]

2)

3) Standard

4) []

2: XML5) - PerformanceShowplan XML- TSQLSQL:StmtStartingSQL:StmtCompleted

- PerformanceShowplan XML- Stored ProcedureSP:StmtStartingSP:StmtCompleted 2: XML36)

7)

8)

SQL:StmtStarting, SQL:StmtCompletedShowplan XML

2: XML49) Showplan XML [ ]

2: -- XML

EXEC sp_create_plan_guide @name = N'PLANGUIDE2', @stmt = N'select a1,a2,a3 from tab1 where a1 > 18000', @module_or_batch = NULL, @params = NULL, @hints =NOPTION (USE PLAN N'''')'

@hintsXMLN 2'')'

: 'tab1' 1 2017 0

SQL Server : CPU = 62 = 226

:

SET SHOWPLAN_XMLSET STATISTICS XMLsys.dm_exec_query_plan query_plan SQL Server Profiler Showplan XML Showplan XML Statistics Profile Showplan XML For Query Compile [ ] XML

SQL Server Management Studio

1--

1) Microsoft SQL Server 20082005 - - SQL Server Profiler []-[]

2)

3) Standard

4) []

26Seminar Name5) - PerformanceShowplan XML- TSQLSQL:StmtStartingSQL:StmtCompleted

- PerformanceShowplan XML- Stored ProcedureSP:StmtStartingSP:StmtCompleted6)

7)

dbcc freeproccachegogo

dbcc freeproccache

48) Showplan XML [ ]

9) 8)

(SQL Server 2005/2008/2008R2)sp_create_plan_guide (Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms179880.aspxsys.plan_guides (Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms178010.aspxsp_control_plan_guide (Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms188733.aspx (Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms181714.aspx (Transact-SQL) : SQL Server 2005http://msdn.microsoft.com/ja-jp/library/ms181714(SQL.90).aspx

(Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms187373.aspx

(Transact-SQL) : SQL Server 2005http://msdn.microsoft.com/ja-jp/library/ms187373(SQL.90).aspxOPTION (Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms190322.aspxOPTION (Transact-SQL)http://msdn.microsoft.com/ja-jp/library/ms190322(SQL.90).aspx http://msdn.microsoft.com/ja-jp/library/ms187032.aspx : SQL Server 2005http://msdn.microsoft.com/ja-jp/library/ms187032(SQL.90).aspx

Ihr Potenzial. Unser Antrieb.

33Seminar Name