Вы находитесь на странице: 1из 57

:

SQL
Server 1,5

SQL Server


OS, SQL Server



2 2
SQL Server

3 3
,

3 :


.
.

. . -
,
.

.

4 4
,



.
CASE*Method - Entity Relationship Modelling by Richard Barker

5 5

.
.

View ()
, view ,
, .

.
.

6 6
SQL Server

SQL Server (
) (
SQL Server)

Paul Randal:
Wait statistics, or please tell me where it hurts (
) http://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-
it-hurts/

Pinal Dave:
http://blog.sqlauthority.com/2011/02/01/sql-server-wait-stats-wait-types-wait-queues-
day-0-of-28-2/

BOL: https://msdn.microsoft.com/ru-ru/library/ms179984.aspx

7 7

73% 16% -

8 8

CXPACKET:

, Max
Degree Parallelism =1

Max Degree Parallelism =0 CPU

Max Degree Parallelism =1 ,
hint MAXDOP=0

SQL Server,
Max Degree Parallelism =1 c DMV: DBCC SQLPERF
('sys.dm_os_wait_stats', CLEAR);

9 9

PAGEIOLATCH_SH PAGEIOLATCH_EX :

/,

(
/ )

Ian Stirk
: https://msdn.microsoft.com/ru-
ru/magazine/cc135978.aspx

10 10

( )
( )
CPU
Microsoft +10
+15

11
11
Data Compression: Strategy, Capacity Planning and
Best Practices

https://technet.microsoft.com/en-us/library/dd894051(v=sql.100).aspx
Percent of Update Operations on the Object
Percent of Scan Operations on the Object
High U -> ROW

12
12
-

13 13

, (Page) 3
:
None
Row
Page

14 14

15 15
DMV
(sys.dm_os_wait_stats , sys.dm_exec_query_stats .)

, TOP 4 ,

,, 9-12

Data
Collection

16 16
: Data Collection
Data Collection, Disk Usage

18 18
Data Collection, Server Activity History

19 19
Data Collection, Query Statistics History

20 20
Data Collection, Query Statistics History, Query #1

21 21
Data Collection, Query Statistics History, Query
#1,

22 22
SQL Server

23 23
SARG (Search argument) by Kalen Delaney
More Small Code Changes, Bigger SQL Server Performance
Improvements
http://sqlmag.com/database-performance-tuning/more-small-code-
changes-bigger-sql-server-performance-improvements

SARG: WHERE <column> <operator> <value>

24 24
SARG

WHERE name = Joe


WHERE 10 > price
WHERE Total BETWEEN 10 and 20

25 25
NOT SARG

WHERE substring(name, 1,2) = Mc


WHERE Total * 10 BETWEEN 100 and 200
WHERE Total * qty BETWEEN 100 and 200

- , , :
WHERE name LIKE Mc%
WHERE Total BETWEEN 10 and 20

Total *qty ,

26 26
- P
CPU, CPU
-,
-

TOP CPU TOP -


, .

27 27
When to Breakdown Complex Queries by SQLCAT
http://blogs.msdn.com/b/sqlcat/archive/2013/09/09/when-to-break-down-complex-queries.aspx
OR WHERE
UNION IN WHERE

Cumulative Update 1 for SQL Server 2012


SP2 , Cumulative Update 10 for SQL Server 2012 SP1 sql 2014
SQL Server 2014: TEMPDB Hidden Performance Gem
http://blogs.msd n.com/b/psssql/archive/2014/04/09/sql-server-2014-tempdb-hidden-
performance-gem.aspx

CASE WHERE ON (JOIN)


28 28

SARG
view
WHERE.
SQL ,
.

29 29
SQL Server

30 30

,

31 31

,

32 32

,

33 33
,
,

int, bigint

16 , 900

34 34
,
:


<
>
between

ORDER BY

35 35
:



:
WHERE
JOIN
GROUP BY

37 37
INCLUDE

INCLUDE
.

(Lookup)
RID Lookup -
Key Lookup

38 38
- P

,
,

( )

39 39
:



(Maintenance Task) SQL Server

41 41

Tips for DBA: Using sys.dm_db_index_physical_stats in a script to rebuild or


reorganize indexes (no partitions / SQL Server 2005)
http://blogs.msmvps.com/gladchenko/2008/03/30/tips-for-dba-using-sys-
dm_db_index_physical_stats-in-a-script-to-rebuild-or-reorganize-indexes-no-partitions-
sql-server-2005/

ONLINE , SORT_IN_TEMPDB,
MAXDOP=10
3- 2012
2014 SORT_IN_TEMPDB=ON SQL Server 2014: TEMPDB Hidden Performance Gem
http://blogs.msdn.com/b/psssql/archive/2014/04/09/sql-server-2014-tempdb-hidden-
performance-gem.aspx

42 42
-

43 43
SQL Server

44 44


RCSI
HINT NOLOCK , !!!
: Beware the NOLOCK Hint
Itzik Ben-Gan http://sqlmag.com/sql-server/beware-nolock-hint

45 45
Read-Committed Snapshot Isolation




ALTER DATABASE AdventureWorks2008R2
SET READ_COMMITTED_SNAPSHOT ON

SELECT is_read_committed_snapshot_on FROM


sys.databases WHERE name= 'AdventureWorks2008R2
0
1

46 46
:
Read-Committed Snapshot Isolation

Read-Committed Snapshot Isolation


- Snapshot Isolation
Snapshot Isolation
,


TEMPDB
TEMPDB

48 48
SQL Server


OS, SQL Server

49 49

NTFS 64
- fsutil fsinfo ntfsinfo D:


Windows Server 2008
- -
40%
Disk Partition Alignment Best Practices for SQL Server
https://technet.microsoft.com/en-us/library/dd758814(v=sql.100).aspx

50 50
TEMPDB
Storage Top 10 Best Practices
https://technet.microsoft.com/ru-ru/library/cc966534.aspx

#7 Consider configuration of TEMPDB database


Make sure to move TEMPDB to adequate storage and pre-size after installing SQL Server.
Performance may benefit if TEMPDB is placed on RAID 1+0 (dependent on TEMPDB usage).
For the TEMPDB database, create 1 data file per CPU, as described in #8 below

#8 Lining up the number of data files with CPUs has scalability advantages for allocation
intensive workloads.
It is recommended to have .25 to 1 data files (per filegroup) for each CPU on the host server.
This is especially true for TEMPDB where the recommendation is 1 data file per CPU.

2006 - - 8 ,
10

51 51
TEMPDB

Storage Top 10 Best Practices 2006 -


- 8 , 10


tempdb, ,

https://www.techdays.ru/videos/6565.html

52 52
max server memory -
1. 5% 2-4 ,
2. SQL Server ( *.exe, *.dll, *ocx . ),
SQL heap, CLR. 500 MB, CLR
.
3. "Worker thread",
(512+(NumCpu-4)*16)*2 MB
4. "max server memory" : OS Mem 1. 2(500 MB) - 3.7
= 471.2 GB. .. ( "max
server memory") 471 GB.
SQL 2012 "max server memory" SQL
heap CLR.

53 53

Dont Touch That Button! Four Dangerous Settings in SQL Server


http://www.brentozar.com/archive/2012/12/dont-touch-that-button-four-
dangerous-settings-in-sql-server-video/
Priority Boost
CPU Affinity Mask and I/O Affinity Mask
LightWeight Pooling, aka Fiber Mode

: HOW IT WORKS: IO Affinity Mask - Should I Use It?


http://blogs.msdn.com/b/psssql/archive/2010/11/19/how-it-works-io-affinity-
mask-should-i-use-it.aspx

54 54
SQL
Server. Microsoft.
SQL Server. (Memory Analysis)
http://blogs.technet.com/b/sqlruteam/archive/2014/02/10/sql-server-memory-
analysis.aspx

SQL Server. .
http://blogs.technet.com/b/sqlruteam/archive/2014/01/12/server.aspx

SQL Server. (Disk analysis)


http://blogs.technet.com/b/sqlruteam/archive/2014/03/12/sql_5f00_server_5f00_disk
_5f00_analysis_5f00_overview.aspx

55 55
?
!