db-08: a day in the life of a type ii record richard banville progress fellow
TRANSCRIPT
DB-08: A Day in the Life of a Type II Record
Richard BanvilleProgress Fellow
2 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Agenda
Update a record Details Details Details
3 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Major Shared-Memory Structures
Buffer pool (-B)
Lock Table (-L)
BI Buffers (-bibufs)
AI Buffers (-aibufs)
Transaction Table (-n)
Usrctl (-n)
Srvctl (-Mn)
Object Cache (-omcache)
4 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
DO TRANSACTION: FIND customer WHERE
cust.name = “Dopey”. cust.name = “Smarty” cust.city = “Orlando” cust.state = “FL”.END.
A Simple Program
Begin Transaction.
Find Index Entry via chosen index
Lock & Retrieve record
5 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
DO TRANSACTION: FIND customer WHERE
cust.name = “Dopey”. cust.name = “Smarty” cust.city = “Orlando” cust.state = “FL”.END.
A Simple Program
Update record buffer w/changed fields
Make any index changes
Save record changes
6 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
DO TRANSACTION: FIND customer WHERE
cust.name = “Dopey”. cust.name = “Smarty” cust.city = “Orlando” cust.state = “FL”.END.
A Simple Program
Commit the updates
Release or downgrade locks
7 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Details Part I
Getting the Record
Begin Transaction.
Find Index Entry via chosen index
Lock & Retrieve record
8 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Start Transaction
Acquire a transaction entry Begin note deferred
Transaction Table (-n)Usrctl (-n)
User Id 9Trans Id 2433405
9 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Finding the Record
Lookup record by area/rowid Rowid stored in index
– Associates known value with rowid
– Know values are ordered within index Language picks index
– Choice based on statement For fast access
– have index that matches predicate
10 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Index Entry
An index entry consists of two parts:–key (one or more components)
– rowid of the record containing the key
Key Component(s)
Name Rec-Id
Bashful 256
Doc 3341
Dopey 9794
Grumpy 9806
Happy 9876
Sleepy 7776
Sneezy 512
Key Component(s)
Cust-Num Rec-Id
100 512
101 7776
102 3341
103 9876
104 9794
105 9806
106 256
11 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
B-tree LayoutBlock’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
root
internal
leaf
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
records
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Need Area & Root Block to start traversal
(Name Index)
12 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Disk Storage Files
Storage Areas
Schema Area Area 7 Area 8
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ta
ble
A
Ta
ble
B
Cu
st
Tb
l
Ta
ble
D
Ind
ex
A-1
Ind
ex
B-1
Na
me
Id
x
Cu
st#
Id
x
SR
ep
Id
x
Ind
ex
D-1
Ind
ex
D-2
Logical
Physical
Lan
gu
ages
Sto
rage E
ng
ine
13 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Disk Storage Files
Storage Areas and Object Mapping
Schema Area Area 7 Area 8
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ext
ent
Ta
ble
A
Ta
ble
B
Cu
st
Tb
l
Ta
ble
D
Ind
ex
A-1
Ind
ex
B-1
Na
me
Id
x
Cu
st#
Id
x
SR
ep
Id
x
Ind
ex
D-1
Ind
ex
D-2
Logical
Physical
Mapping
Lan
gu
ages
Sto
rage E
ng
ine
14 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Object Mapping Cache
replacing
Has
h T
able
LRU Chain “oldest”“newest”
aging
Area 6 Area 7 Area 8 Area 9
T1 I1 T3 I3 T2 I2 T4 I4
Array of cache entries (unordered)
Each entry contains area info & root block
15 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Performance (omlru simplified)
replacing
Has
h T
able
LRU Chain “oldest”“newest”
aging
Omlru avoidance when –omsize proper
Area 6 Area 7 Area 8 Area 9
T1 I1 T3 I3 T2 I2 T4 I4
Find I2/T2Find I1/T1
Find I3/T3Find I2 …Find I1/T1
16 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
We know the Index’s area
We know the rowid of the index root block
Let’s find it so we can traverse the index
17 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Find Buffer in Buffer Pool
replacing
Has
h T
able
(-h
ash
)
LRU Chain “oldest”“newest”
aging
M M M M
M MM M
Checkpoint Queue M MM M
Page Writer Queue
database
Array of (–B) buffer pool entries (unordered)
May need to flush data on page-in (if APW not @ peak performance)
18 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Effect of -Bp
replacing
Has
h T
able
(-h
ash
)
LRU Chain “oldest”“newest”
aging
M M M M
User 1 –Bp LRU Chain
User 2 –Bp LRU Chain
19 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Find the “Dopey” EntryBlock’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
root
internal
leaf
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
records
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Top Reserved
Free Space
o o o
. . . Compressed Index Entries . . .
Bot Index No.
Num Entries
Bytes Used
. . . Compressed Index Entries . . .
Dummy Entry . . .
Compression effects number of blocks traversed
20 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Free List
Active & Queued (Waiting) Lock Entries
HashTable
(-lkhash)
The Lock Table (-L)
XX SQSQ SQSQ SQSQ SQSQ
Row-id
Table-id
Owner
Lock State
Next Pointer
Lock Table Entry
SS
XX
Need to share lock the record (even though the record wasn’t located yet!)
(9794)
(1)
(Shared)
(User Id 9)
21 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
We know the Record’s rowid
In the interest of time, assume we’ve done the object mapping and attempted the
lookup in the buffer pool
Let’s go get the record
22 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Reading a Record from Disk
* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
Block numbers1 to 8,388,608
Row numbers0 to 255
ROWID
prostrct list <dbname>: d “Customer":8,64 x_7.d1 f 384d “Customer":8,64 x_7.d2 f 3200d “Customer":8,64 x_7.d3
Looking for ROWID 9794, Table 1, Area 8
Find _Area where _Area-number = 8.
Display _Area-recbits _Area-Blocksize. 6 8192
23 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Reading a Record from Disk
Find _Area where _Area-number = 8.
Display _Area-recbits _Area-Blocksize.
prostrct list <dbname>: d “Customer":8,64 x_7.d1 f 384d “Customer":8,64 x_7.d2 f 3200d “Customer":8,64 x_7.d3
Looking for ROWID 9794, Table 1, Area 8
6 8192
* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
Block numbers1 to 33,554,432
Row numbers0 to 63
ROWID 9794
* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0
Block: 153 Row: 2
24 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Get the Record
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Language Record Buffer
Find the record and assemble all the pieces.Rowid 9794
Rowid 2828
Row 2 in Block 153 of area 8
25 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Details Part II
Perform Updates
Update record buffer w/changed fields
Make any index changes
Save record changes
26 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Update Fields in Record Buffer
New row is larger than original– Field values stored variable size
Need more space– We can handle it
new
original
Language Record Buffer
State Name
27 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Free List (-L)
Active & Queued (Waiting) Lock Entries
HashTable
(-lkhash)
Upgrade the Lock to EX
XX SQSQ SQSQ SQSQ SQSQ
Row-id
Table-id
Owner
Lock State
Next Pointer
LockTableEntry
SS
XX
(9794)
(1)SS
28 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Free List (-L)
Active & Queued (Waiting) Lock Entries
HashTable
(-lkhash)
Lock Conflict!
XX SQSQ SQSQ SQSQ SQSQ
SS
XX
XQXQ
Queued entry - We must wait(Watch out for deadlock!)
(-lkwtmo)
29 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Free List (-L)
Active & Queued (Waiting) Lock Entries
HashTable
(-lkhash)
Now We Got It
XX SQSQ SQSQ SQSQ SQSQ
SS
XX
XQXQXX
30 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Key Component(s)
Name Rec-Id
Bashful 256
Doc 3341
Dopey 9794
Grumpy 9806
Happy 9876
Sleepy 7776
Sneezy 512
Non-unique Key
Updating an Index Entry
Key Component(s)
Name Rec-Id
Bashful 256
Doc 3341
Dopey 9794
Grumpy 9806
Happy 9876
Sleepy 7776
Smarty 9794
Sneezy 512
Non-unique Key
“Dopey” goes “Smarty”
Key Component(s)
Name Rec-Id
Bashful 256
Doc 3341
Dopey -2433405
Grumpy 9806
Happy 9876
Sleepy 7776
Smarty 9794
Sneezy 512
Unique Key
31 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Update the Record Blocks
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Language Record Buffer
All buffer pool actions replayedRowid 9794
Rowid 2828
Reallocate space fragment by fragment
OOPs, out of space!
32 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Need Space?
200200 300300 400400 200200
Record block free chain for Customer table
CustObjectBlock
CustObjectBlock
4K4K 2K2K 8K8K 8K8K
Record block free chain for Order table
OrderObjectBlock
OrderObjectBlock
Objects are selfish with their space allocation chains
33 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Need Space?
200200 300300 400400 200200
Record block free chain for Customer table
CustObjectBlock
CustObjectBlock
Blocks on RM free chain governed by Record Packing Factor
Records/Block, Create Limit (75/150), Toss Limit (150/300)
Blocks checked, recycled or tossed is limited (internal boundaries)
Example: Need 200 bytes
Toss
Recycle Take/ Toss
34 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Need Space?
200200 300300 400400 200200
Record block free chain for Customer table
CustObjectBlock
CustObjectBlock
Blocks on RM free chain governed by Record Packing Factor
Records/Block, Create Limit (75/150), Toss Limit (150/300)
Blocks checked, recycled or tossed is limited (internal boundaries)
Example: Need 300 bytes
Toss Toss
Recycle
35 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Cluster Size Matters
200200 300300 400400 200200
Record block free chain for Customer Table
CustObjectBlock
CustObjectBlock 8K8K 8K8K 8K8K 8K8K 8K8K 8K8K 8K8K
AreaControlObject
AreaControlObject
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
Area Cluster Free Chain
36 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Cluster Size Matters
200200 300300 400400 200200
Record block free chain for Customer Table
CustObjectBlock
CustObjectBlock 8K8K 8K8K 8K8K 8K8K 8K8K 8K8K 8K8K
AreaControlObject
AreaControlObject
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K8K
Area Cluster Free ChainCluster free chain empty? Raise area HWM or extend area.
37 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Connect All Fragments
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Language Record Buffer
Rowid 9794
Rowid 2828
Block’s DBKEY Type Chain Backup Ctr
Next DBKEY in Chain Block Update Counter
Free SpaceFreeDirs. Rec 0 Offset Rec 1 Offset
Rec 2 Offset Rec n Offset
NumDirs.
Free Space
Used Data Space
Record 0
Record 1
Record 1
Rowid 10240
38 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Details Part III
Make it real
Commit the updates
Release or downgrade locks
39 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
End Transaction
Transaction Table (-n)Usrctl (-n)
User Id 9Trans Id 2433405
Release Transaction Entry
Write Commit Note/do commit processing
40 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
SSSS EQEQ
Free List
Active & Queued (Waiting) Lock Entries
HashTable
(-lkhash)
Release/Downgrade Locks
XX SQSQ SQSQ SQSQ
XX
SQSQ
Awaken users waiting on lock
Release exclusive lock
SQSQSQSQ EQEQSQSQXX SQSQ EQEQ
41 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
In Summary
YOU: Simple Update WE: Lots of work You can Enhance the
Process
42 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Questions?
43 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation
Thank you for your time!
44 DB-08: A Day in the Life of a Type II Record© 2005 Progress Software Corporation