2. 16 MCPs for SQL
70-765 70-764 70-762
70-761 70-473 70-463
70-465 70-464 70-462
70-451 70-433 70-442
70-441 70-447 70-229
70-228
BI….???
Best tuning
5 mins query -> 0.02 sec.
3. What you will learn today
No details of SQL architecture
No details of index tuning
No details of SQLOS
How to think about everything from performance
point of view.
4. Take away (1/2)
All performance issue has reasons. Understand where
the issue comes from. (CPU, Memory, Disk)
All performance features are:
• solve the bottle neck somehow
• workaround the bottle neck
It may generate another issue
5. Take away (2/2)
New features may:
Improve performance
and/or
Decrease performance
6. Goal
Let you feel you learn something
Demystify performance turning myth
And confuse you all
16. GAM, SGAM and PFS
GAM
Record what extents have been allocated.
SGAM
Record which extents are used as mixed extents and have unused page.
Each GAM/SGAM covers 64,000 extents, or almost 4 GB of data.
PFS (Page Free Space)
Record the allocation status of each page.
Check if its empty, 1 to 50 percent full, 51 to 80 percent full, 81 to 95 percent full, or 96 to 100
percent full.
17. (IAM) Index Allocation Map
Maps the extents in a 4-gigabyte (GB) part of a database file used by an
allocation unit.
• IN_ROW_DATA
Holds a partition of a heap or index.
• LOB_DATA
Holds large object (LOB) data types, such as xml, varbinary(max), and
varchar(max).
• ROW_OVERFLOW_DATA
Holds variable length data stored in varchar, nvarchar, varbinary, or
sql_variant columns that exceed the 8,060 byte row size limit.
18. Data and Log
How they store data?
Data :
Random Access
RAID 10/5
Log:
Sequential and writes only for normal time
RAID 0
19. Fill factor
Avoid Page split but why?
May place pages into different extent => More IO
Split happens when data is inserted in the middle
Log?
Sequential Guid?
22. Partitioning and Stretch database
Want to reduce
Partitioning
Avoid query unnecessary partitions
Move old data to other table
Stretch
Remove data from local by move old data to Azure
Archive??
Cannot query
23. Question
What happens when data or log file out of space?
• SQL stops
• Auto grow the space
• Archive old data
24. File space management
Auto grow settings
Cause many issues, last resort
Instant File Initialization
Not for transaction log
TempDB?
28. Question
When SQL server rereleases a cached object from its memory?
• When no one uses the cached data anymore
• It won’t release no matter what
• Only when needed under memory pressure
30. How fast SSD vs. DDR4
SSD
• Sequential Read/Write 3,100/2,000MB/s
• Random Read/Write 540K/50K IOPs (2160/200MB/s)
DDR4
• Transfer rate 3200 Mb/s (25.6GB/s)
31. Max and min server memory
1. Start from less then min.
2. Keep acquiring memory until it exceeds min.
3. Not exceed max.
4. When releases memory, it still keeps min memory.
https://docs.microsoft.com/en-us/sql/relational-databases/memory-management-architecture-guide?view=sql-server-
2017
32. Buffer Management
1 buffer = 8KB page.
NUMA support
DISK/IO
SQL reads and writes to buffer, not disk.
=> Read ahead to improve performance
=> Lazy writer writes data to disk (or checkpoint)
https://docs.microsoft.com/en-us/sql/relational-databases/memory-management-architecture-guide?view=sql-server-
2017#buffer-management
33. Buffer Management Read Data
Read ahead
Read 64 pages (512 KB) (SQL2016)
Read up to with dynamic algorithm 4 MB data (SQL2017)
sequential read-ahead
random prefetching read-ahead
https://www.sqlshack.com/sql-server-read-ahead-mechanism-concept-performance-gains/
34. Buffer Management Write Data
https://docs.microsoft.com/en-us/sql/relational-databases/writing-pages?view=sql-server-2017
37. Question
Why optimizer can create plan before execute query?
• By gut
• By query records first
• By using stats
• It does optimize by last ran result
44. Question
Index boost query performance
• Of course!
• Only select
• Only select and update
• It depends…
45. Heap, Clustered Index, Non-clustered Index
Heap : Table
Ordered as inserted
Clustered Index : Table B-tree
Ordered by specified column(s) value
Non-clustered Index : Additional data
58. Performance related new features
Resumable online index rebuild
New adaptive queries
Auto tuning
256 GB initial tempdb file size
Computed columns, json functions, cross apply for in-memory
optimized tables
Read Scalability Group (wo/cluster)
New read ahead algorithm
Query Store enhancement (wait statistics)
https://www.youtube.com/watch?v=DK4xUzG4Zm0
59. Best Practices
Index, partition, statistics
Procedures and parameterized queries
Max server memory and mdop
Multiple files for tempdb Avoid auto grow
SnapshotLock pages IFI Power Settings
Location of data and log files In-memory table
Columnstore index Use persisted memory