2. Simon Cho
Chapter leader of SQLAngeles.com
SQL Community Speaker in SQLPass.org
Visa Inc Database Engineer
Blog : Simonsql.com
Email : Simon@SimonSQL.com
Like to DIY wood working!
3.
4. What is the Physical DB objects?
A. Table
B. View
C. Stored Procedure
D. Trigger
E. Synonyms
5. How much you knows about Index?
No Idea….
Cluster Index vs Non-Cluster Index
Unique Index vs Non-Unique Index
Index Scan vs Index Seek
Covering Index
What type of data is in index Leaf node
Index Compression…
9. Note: No data order
Double Linked List Double Linked List
File Seq1 File Seq2 File Seq3
Once data size grows, it can’t fit in Memory.
Create multiple files.
Page 1 Page 2 Page 3
Page(Data Blocks) : MSSQL = 8KB, MySQL(InnoDB) = 4KB - 64KB(Default 16KB), Oracle = 2KB – 32 KB(Default 8KB)
10. Getting bigger and bigger
Page 1
Page 2
Page 3
Page N
Page …
New Decision. Let’s order data and create a control page.
Note: Data order by Key
Page 0
12. Then, what is the NonClustered Index?
I only need a part of data for search, “Name”
13. Page 1
Sort By “Name” along with “Seq” key. After that, create new file list like Clustered Index
Page ….
Page N
Leaf Nodes
Root Node
Intermediate
Nodes
17. Search By Ordered value(=Index Key)
SELECT * FROM tbl
WHERE Seq = 12001 or Seq = 12100
Page 2
@Seq1 = 12001
@Seq2 = 12100
Page 0
Page 2
Cost = 4 Pages
(Logical IO)
4 Pages * 8KB = 32 KB
Index Seek(=Bookmark Look up = Key Look up)
Note: Possibly read same page multiple times.
18. Search By Non-Ordered value
SELECT * FROM tbl
WHERE Tel = ‘123-123-1234’ or Tel = ‘456-465-4567’
Cost = N Pages
(Logical IO)
N Pages * 8KB ≈ Index Size(Heap Size)
Index Scan(=Table Scan)
wish to call “heap scan”
19. Index Overhead(CL + NC) vs Heap
Search :
Insert :
Delete :
Update :
Space :
2 inserts CL and NC(IO is not X2)
2 deletes CL and NC(IO is not X2)
2 updates in case of NC data updated.
Extra Space required.
Has benefit.
20. Drop/Change Clustered key
All NonClustered Indexes Rebuild!!!
- All NC leaf data point to Heap key(Rowid) -> Change to new CL key