Hustle and Bustle of SQL Pages Jacques Mostert SQLAdventurar Djl.Mostert@gmail.com
Proudly brought to you by Platinum Gold Silver Bronze
QUERY Overview Query -> magic -> results
Relational Engine Query Plan Parse Optimize Normalize Buffer Pool Task Query Plan Parse Task Task Optimize Normalize Buffer Pool Storage Engine Plan Cache Computer starts query Query is executed by user Goes into a task queue Gets a worker/scheduler (REMEMBER SQL IS LAZY) Does a HASH on the query and checks the plan cache Start language event Parse Normalize Optimize – Engine is MS Holy Grail and closely guarded secret It has 4 stages -pre optimization – trivial plan -transaction processing when cost is < 0.2 -Quick plan when cost is <1 -Full Optimization Execution plan Allocate Memory IO Subsystem
Relational Engine Parse Query Plan Optimize Normalize Query Executer Task Query Plan Task Task Optimize Normalize Query Executer Buffer Pool Storage Engine Plan Cache Query Executer Storage engine Access method manager Buffer manager BM checks the data cache and checks for the page it needs If page is there no need to go to disc if not then it needs to load the page to the buffer pool Then the request is passed to the IO Manager IO Manager goes to the disc gets the data and sends it all the way back. Why does the buffer pool matter? HDD 200MB/s, SDD300-600MB/s DDR6.4GB to 17GB/s Access Method Buffer Manager Data Cache IO Subsystem IO Manager
What we visualize a SQL page to look like
What it actually looks like Not going to discuss page structures SQL does not read parts of a page but the whole page If you set statistics on 128 pages = 1MB 128000 pages = 1GB
PAGE (8Kb)
EXTEND (64Kb) Mixed or Uniform
Sector Size
Select (Read) Insert (Write) Delete (Remove) Update
Memory / Buffer
TempDB / Workspace Tempdb is used by the SQL OS for operations, snapshot isolation, always on, index rebuild and so forth TempDB is SQL Server dumpster or public toilet. Everything or everyone uses it Sorting is not limited to your memory. Your query is not that important that SQL will give it all to you Memory is shared and used to cache data, cache execution plans and executing your query
Pile Of “HEAP” Data rows stored random Pages are everywhere HEAPS are not bad per-say there could be an advantage to having a HEAP when you insert “random” data and read large chunks without the need for sorting
Cluster Confusion Explain why it is bad to create a clustered index on a column that does not store sequential number like GUID If a table only has a clustered index it is going to be slow. Because there is then only one copy of the table same as the HEAP
Nonclustered Index Nonclustered index – create copies of columns Clusteres index included
This is effectively a covering index for the specific query This is effectively a covering index for the specific query. In the perfect world there would be an index like this for every query.
Table Lock
Page Locking
Row Locking
Sorting Group By Create work space Write down while sql reads
Compression
THANK YOU! Platinum Gold Silver Bronze