ch9_disks_06_2
TRANSCRIPT
-
8/10/2019 Ch9_Disks_06_2
1/33
1
The Bare Basics
Storing Data on Disks and Files
Chapter 9
-
8/10/2019 Ch9_Disks_06_2
2/33
2
Disks and Files
DBMS stores information on (hard) disks.
This has major impliations for DBMS desi!n"
#$%D& transfer data from disk to main memor'(#%M).
#T$& transfer data from #%M to disk.
Both are hi!h*ost operations+ relati,e to in*memor'operations+ so m-st e planned aref-ll'"
-
8/10/2019 Ch9_Disks_06_2
3/33
/
Why Not Store Everything in MainMemory?
Costs too much. Same amo-nt of mone' 0ill -' 'o- sa' either 12MB of
#%M or 23B of disk.
Main memory is volatile. e 0ant data to e sa,ed et0een r-ns. (4,io-sl'")
T'pial stora!e hierarhies& Main memor' (#%M) for -rrentl' -sed data (primar'stora!e) .
Disk for the main dataase (seondar' stora!e). Tapes for arhi,in! older ,ersions of data (tertiar' stora!e
-
8/10/2019 Ch9_Disks_06_2
4/33
5
Disks Seondar' stora!e de,ie of hoie. Main ad,anta!e o,er tapes&
random access ,s. sequential.
Data is stored and retrie,ed in -nits & alled disk locks or!ages.
6nlike #%M+ time to retrie,e a disk pa!e,aries dependin! -pon loation on disk. Therefore+ relati,e plaement of pa!es on
disk has major impat on DBMS
performane"
-
8/10/2019 Ch9_Disks_06_2
5/33
-
8/10/2019 Ch9_Disks_06_2
6/33
;
$ccessing a Disk %age
Time to aess (read80rite) a disk lok& seek time (mo,in! arms to position disk head on trak) rotational delay (0aitin! for lok to rotate -nder head)
trans"er time (at-all' mo,in! data to8from disk s-rfae) Seek time and rotational dela' dominate.
Seek time ,aries from ao-t 1 to 2mse #otational dela' ,aries from to 1mse
Transfer rate is ao-t 1mse per 5
-
8/10/2019 Ch9_Disks_06_2
7/33>
$rranging %ages on Disk
?Ne&t@ lok onept& loks on same trak+ follo0ed ' loks on same 'linder+ follo0ed ' loks on adjaent 'linder
Bloks in a le sho-ld e arran!ed seA-entiall'on disk (' ?ne:t@)+to minimie seek androtational dela'.
or a seA-ential san+!re'"etchingse,eralpa!es at a time is a i! 0in"
-
8/10/2019 Ch9_Disks_06_2
8/33
($)D *(edundant $rray o")nde!endent Disks+
Disk %rra'& %rran!ement of se,eral disks that !i,esastration of a sin!le lar!e disk.
3oals& nrease performane and reliailit'.
T0o main tehniA-es& Data stripin!&
Data is partitionedSie of a partition is alled the stripin! -nit.Eartitions are distri-ted o,er se,eral disks.
#ed-ndan'&More disks FG more reliale.#ed-ndant information allo0s reonstr-tion of data if a disk
fails.
-
8/10/2019 Ch9_Disks_06_2
9/339
($)D ,evels
=e,el & Ho red-ndan' Best 0rite performane
Hot est in readin!. (h'I)
=e,el 1& Mirrored (t0o idential opies) $ah disk has a mirror ima!e (hek disk) Earallel reads+ a 0rite in,ol,es t0o disks. Ma:im-m transfer rate F transfer rate of
one disk
-
8/10/2019 Ch9_Disks_06_2
10/331/
Disk S!ace Management
=o0est la'er of DBMS soft0are mana!esspae on disk.
Ji!her le,els all -pon this la'er to& alloate8de*alloate a pa!e read80rite a pa!e
Ji!her le,els don@t need to kno0 ho0 thisis done+ or ho0 free spae is mana!ed.
-
8/10/2019 Ch9_Disks_06_2
11/3315
Bu-er Management in a
DBMS
Data must e in ($M "or DBMS to o!erate on it. Tale o" /"rame01 !ageid2 !airs is maintained3
DB
MAIN MEMORY
DISK
disk pa!e
free frame
Ea!e #eA-ests from Ji!her =e,els
B6$# E44=
hoie of frame ditated' replacement policy
-
8/10/2019 Ch9_Disks_06_2
12/3317
When a %age is (equested 333
f reA-ested pa!e is not in -Ker pool& Choose a frame for re!lacement f frame is dirt'+ 0rite it to disk #ead reA-ested pa!e into hosen frame
%in the pa!e and ret-rn its address.
)" requests can e !redicted *e3g31 sequenti
!ages can e!re'"etched *several !ages at
-
8/10/2019 Ch9_Disks_06_2
13/331;
More on Bu-er Management
#eA-estor of pa!e m-st -npinit+ and indiate0hether pa!e has een modied& dirtyit is -sed for this.
Ea!e in pool ma' e reA-ested man' times+ a!in count is -sed. % pa!e is a andidate for replaement iK!in count
F .
CC L reo,er' ma' entail additional 84 0hena frame is hosen for replaement. (Write'
$head ,og protool more later.)
-
8/10/2019 Ch9_Disks_06_2
14/331>
Bu-er (e!lacement %olicy
rame is hosen for replaement ' are!lacement !olicy4 =east*reentl'*-sed (=#6)+ Clok+ M#6 et.
Eoli' an ha,e i! impat on of 84@sdepends on access !attern.
Sequential 5ooding& Hast' sit-ationa-sed ' =#6 N repeated seA-ential
sans. -Ker frames O pa!es in le means eah
pa!e reA-est a-ses an 84. M#6m-h etter in this sit-ation (-t not in all
sit-ations+ of o-rse).
-
8/10/2019 Ch9_Disks_06_2
15/33
1
DBMS vs3 6S File System
4S does disk spae L -Ker m!mt alread'"
So 0h' not let 4S mana!e these tasksI
DiKerenes in 4S s-pport& Eortailit' iss-es Some limitations+ e.!.+ les don@t span m-ltiple disk
de,ies. B-Ker mana!ement in DBMS reA-ires ailit' to&
pin a pa!e in -Ker pool+ fore a pa!e to disk (important for implementin! CC L
reo,er')+ adj-st re!lacement !olicy1 and pre*feth pa!es ased
on aess patterns in t'pial DB operations.
-
8/10/2019 Ch9_Disks_06_2
16/33
19
Structure o" a DBMS
% t'pial DBMS has a la'eredarhitet-re.
Disk Stora!e hierarh'+ #%D
Disk Spae Mana!ement#oles+ ree loks
B-Ker Mana!ement
B-Ker Eool+ #eplaement poli'
iles and %ess Methods
ile or!aniation(heap les+ sortedle+ inde:es)
ile and pa!e le,el stora!e(olletion
of pa!es or reords)
Query Optimization
and Execution
Relational Operators
iles and Access !ethods
"u##er !ana$ement
Disk Space !ana$ement
D"
These layers
must consider
concurrency
control andrecovery
Index FilesSystem Catalog
Data Files
-
8/10/2019 Ch9_Disks_06_2
17/33
2
Files o" (ecords
Ea!e or lokis the !ran-larit' for doin! 84 Ji!her le,els of DBMSoperate on &
records+ and
7les omposed of reords. =$& % olletion of pa!es+ eah ontainin!
a olletion of reords. ile m-st s-pport&
insert8delete8modif'reord reada parti-lar reord (speied -sin! record
id) sanall reords (possil' 0ith some onditions
on the reords to e retrie,ed)
-
8/10/2019 Ch9_Disks_06_2
18/33
21
8nordered Files *9ea! Files+
Simplest le str-t-reontains reords in noparti-lar order.
%s le !ro0s and shrinks+ disk pa!es arealloated and de*alloated.
To s-pport reord le,el operations+ 0e m-st& keep trak of the!agesin a le keep trak of "ree s!aceon pa!es keep trak of the recordson a pa!e
There are man' alternati,es for keepin! trak
of this.
-
8/10/2019 Ch9_Disks_06_2
19/33
22
$lternative :4
9ea! File )m!lemented as,ist
Maintain a tale ontainin! pairs of&OheapPlePname+ headPpa!ePaddressG
$ah pa!e ontains 2 ?pointers@ (rid) pl-s data.
JeaderEa!e
DataEa!e
DataEa!e
DataEa!e
DataEa!e
DataEa!e
DataEa!e
Ea!es 0ithree Spae
-ll Ea!es
-
8/10/2019 Ch9_Disks_06_2
20/33
2/
9ea! File )m!lemented as a
,ist nsert a ne0 pa!e into heap le Disk mana!er adds a ne0 free spae pa!einto link
Delete a pa!e from heap le #emo,edfrom the list
Disk mana!er dealloatesit
Disad,anta!es& f reords are of ,ariale len!th+ all pa!es 0ill e in
free list.
#etrie,e and e:amine se,eral pa!esfor eno-!hspae.
-
8/10/2019 Ch9_Disks_06_2
21/33
25
$lternative ;4 9ea! File 8sing %ageDirectory
n diretor'+ eah entr' for a pa!e inl-desn-mer of free 'teson pa!e.
The diretor' is a olletion of pa!es(linked list implementation is j-st one alternati,e). Much smaller than linked list o" all 9F !ages"
Data
Ea!e 1
DataEa!e 2
DataEa!e H
HeaderPage
DIRECTORY
-
8/10/2019 Ch9_Disks_06_2
22/33
27
$lternative ;4
9ea! File 8sing a %ageDirectory
%d,anta!e of Ea!e Diretor'&
The sie of diretor' is ,er' small(m-hsmaller than heap le.)
Searhin! spae is ,er' eQient+ ea-send free spae 0itho-t lookin! at at-al
heap data pa!es.
-
8/10/2019 Ch9_Disks_06_2
23/33
2;
%age Formats
Ea!e & astration is -sed for 84 #eord & data !ran-larit' for hi!her le,el of
DBMS
Jo0 to arran!e reords in pa!esI dentif' a reord&
R Opa!ePid+ slotPn-merG+ 0here slotPn-mer F rid
R Most ases+ -se Opa!ePid+ slotPn-merG as rid.
%lternati,e approahes to mana!e slotson apa!e
Jo0 to s-pport insert8deletin!8searhin!I
-
8/10/2019 Ch9_Disks_06_2
24/33
2>
(ecords Formats4 Fi&ed ,ength(ecord
nformation ao-t eld t'pes same for allreords in a le
Stored reord format in systemcatalogs3
N indin! i
-
8/10/2019 Ch9_Disks_06_2
25/33
2
%age Formats4 Fi&ed ,ength(ecords
(ecord id = /!age id1 slot 023
Note4 )n 7rst alternative1 moving records "or "ree s!acemanagement changes rid> may not e acce!talei"e&isting e&ternal re"erences to the record that is moved3
Slot 1
Slot 2
Slot H
. . . . . .
H M1. . .
M ... / 2 1
E%C
-
8/10/2019 Ch9_Disks_06_2
26/33
29
(ecord Formats4 ariale
,engthT0o alternati,e formats ( elds is :ed)&
N SeondoKers diret aess to i@th eld
N eQient stora!e of nulls* small diretor' o,erhead.
5
ieldCo-nt
ields Delimited ' Speial S'mols
1 2 / 5
1 2 / 5
%rra' of ield 4Ksets
-
8/10/2019 Ch9_Disks_06_2
27/33
/
%age Formats4 ariale ,ength(ecords
Slot diretor' F OreordPoKset+reordPlen!thGU
Ea!e i#id F (i+H)
#id F (i+2)
#id F (i+1)
Eointer
to startof freespae
S=4T D#$CT4#V
H . . . 2 1
2 1; 25 H
slots
4Kset ofreordfrom startof dataarea
Length = 24
Length = 16
Length = 20
-
8/10/2019 Ch9_Disks_06_2
28/33
/1
%age Formats4 ariale ,ength(ecords
Slot diretor' F OreordPoKset+ reordPlen!thGU Dis8%d,anta!es&
N Mo,in!& rid is not han!ed
N Deletion& oKset F *1 (rid han!edI
Can 0e delete slotI h'I)
N nsertion& #e-se deleted slot.
4nl' insert if none a,ailale.
ree spaeI ree spae pointerI #e'le afterdeletionI
-
8/10/2019 Ch9_Disks_06_2
29/33
/2
System Catalogs
Meta information stored in s'stem atalo!s.
or eah inde:& str-t-re (e.!.+ BN tree) and searh ke' elds
or eah relation& name+ le name+ le str-t-re (e.!.+ Jeap le) attri-te name and t'pe+ for eah attri-te inde: name+ for eah inde: inte!rit' onstraints
or eah ,ie0& ,ie0 name and denition
El-s statistis+ a-thoriation+ -Ker pool sie+ et.
Catalogs are themselves stored as relation
-
8/10/2019 Ch9_Disks_06_2
30/33
//
$ttr@Cat*attr@name1 rel@name1 ty!e1!osition+
attrPname relPname t'pe positionattrPname %ttri-tePCat strin! 1relPname %ttri-tePCat strin! 2t'pe %ttri-tePCat strin! /
position %ttri-tePCat inte!er 5sid St-dents strin! 1name St-dents strin! 2lo!in St-dents strin! /a!e St-dents inte!er 5!pa St-dents real 7d a-lt' strin! 1fname a-lt' strin! 2sal a-lt' real /
-
8/10/2019 Ch9_Disks_06_2
31/33
/5
Summary
Disks pro,ide heap+ non*,olatile stora!e. #andom aess+ -t ost depends on loation
of pa!e on disk mportant to arran!e data seA-entiall'to
minimie seekand rotation dela's.
B-Ker mana!er rin!s pa!es into #%M. Ea!e sta's in #%M -ntil released ' reA-estor.
ritten to disk 0hen frame hosen forreplaement. rame to replae ased on replaement poli'3 Tries to pre*feth se,eral pa!es at a time.
-
8/10/2019 Ch9_Disks_06_2
32/33
/7
More Summary
DBMS ,s. 4S ile S-pport DBMS needs feat-res not fo-nd in man' 4Ss.R forin! a pa!e to diskR ontrollin! the order of pa!e 0rites to diskR les spannin! disks
R ailit' to ontrol pre*fethin! and pa!e replaementpoli' ased on preditale aess patterns
ormats for #eords and Ea!es & Slotted pa!e format& s-pports ,ariale len!th
reords and allo0s reords to mo,e on pa!e.
Wariale len!th reord format& eld oKsetdiretor' oKers s-pport for diret aess to i@theld and n-ll ,al-es.
-
8/10/2019 Ch9_Disks_06_2
33/33
Even More Summary
ile la'erkeeps trak of pa!es in a le+ ands-pports astration of a olletion ofreords. Ea!es 0ith free spae identied -sin! linked list
or diretor' str-t-re
nde:ess-pport eQient retrie,al ofreords ased on the ,al-es in some elds.
Catalo! relationsstore information ao-trelations+ inde:es and ,ie0s.
nformation ommon to all reords in olletion