Professional Documents
Culture Documents
1 Data Storage Structures-Ch13
1 Data Storage Structures-Ch13
so
Chapter 13: Data Storage Structures
I 81 41 im W.tl F
fixedlength
V lab I gth
T
File Organization يتم تخزين قاعدة البيانات
كل.كمجموعة من امللفات
▪ One approach
• Assume record size is fixed
Database System Concepts - 7th Edition 13.2 ©Silberschatz, Korth and Sudarshan
IT dit al s
b i Fixed-Length Records m size is a 4
:نهج بسيط
▪ Simple approach: gal d i • تخزين السجل
to
• Store record i starting from byteyn (i – 1), where n is the size of
n بد ًءا من البايت
each record.
e هوn حيث، (i - 1)
حجم
• Record access is simple but records may cross blocks 3
isaiah
4 I am
▪ Modification: do not allow records to cross block boundaries was
o Wii memory
it u A
j A 1
41 m m is
I cantstonge a2e
it is ai pi i s
i it
Database System Concepts - 7th Edition 13.3 ©Silberschatz, Korth and Sudarshan
size
or fields
real is Kim
wi
f
att
AH semi g's
105 am It is
0 d sit Jot El
40 o 1
o w
W 911 w I 21
12 11 40
yo
4041 is Yo n
Yo 3 1 80
Fixed-Length Records
3 cross block wa y't j t
▪ Deletion of record i: alternatives:
• move records i + 1, . . ., n to i, . . . , n – 1 to sat onin sp I
• move record n to i
• do not move records, but link all free records on a free list
Record 3 deleted
3 a m
Y
at I s
80 as 80
Database System Concepts - 7th Edition 13.4 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records
o 411 It
Database System Concepts - 7th Edition 13.5 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records
46 im
ID wi't 3 It I do
Ii z Je 4 freespace of
6.66a86 N pm
a 6064,151
66 0 4 4356
116s.mil 5
visit gW
record
WE
wi ios out record12 4356
too ms a
Database System Concepts - 7th Edition 13.6 ©Silberschatz, Korth and Sudarshan
تنشأ السجالت ذات الطول
ti i size Variable-Length Records املتغير في أنظمة قواعد
length
:البيانات بعدة طرق
s
Variable length
attributes(offset, length),
Database System Concepts - 7th Edition 13.7 ©Silberschatz, Korth and Sudarshan
ex for variable length
array JI Si is 0 518 03 151 p at 6,1 6
É W
M
m e at IU in 1 I on
9 fixed variable lenghth I I m
b
i i m
a 9581
w si mi y www.t a it it a
U ok a I di et i saw a en mi si
i am a low
Variable-Length Records: Slotted Page Structure
▪ يحتوي رأس الصفحة
:املشقوقة على
• عدد إدخاالت السجل
• نهاية املساحة الخالية
4,11 Gum w
▪1 Slotted page ya
Header a
header contains:
• number of record entries W D B ET a
• end of free space in the block It'swww.a.us
• location and size of each record Go e si owl owl 413 is
Headers I I 211Datapiled 6
it
▪ Records can be moved around within a page to keep them contiguous
with no empty space between them; entry in the header must be
updated.
▪ Pointers should not point directly to record — instead they should point
to the entry for the record in header.
aww it 8
sit to
ah M FB Header
Database System Concepts - 7th Edition 13.8 ©Silberschatz, Korth and Sudarshan
video
Storing Large Objects
picha
re
▪ PostgreSQL TOAST Ei la ma
Examples:
create table pictures(name varchar(32) not null primary key, pic blob(16M));
bdf a
CREATE TABLE documents (id INT, text CLOB)
Database System Concepts - 7th Edition 13.9 ©Silberschatz, Korth and Sudarshan
I D B 20 01 b mi 911 É i d
I ok Organization يمكن- ▪ كومة
of Records in Files وضع سجل في أي
مكان في امللف
• For example, a value of 7 indicates that at least 7∕8th of the space in the
block is free.
Can have second-level free-space map
• In example below, each entry stores maximum from 4 entries of first-level
free-space map
▪ Free space map written to disk periodically, OK to have wrong (old) values
for some entries (will be detected and fixed)
Database System Concepts - 7th Edition 13.11 ©Silberschatz, Korth and Sudarshan
Sequential File Organization
▪ مناسب للتطبيقات التي
▪ Suitable for applications that require sequential processing of تتطلب معالجة متسلسلة لـ
the entire file
امللف بأكمله ▪ يتم ترتيب
▪ The records in the file are ordered by a search-key السجالت املوجودة في امللف
Database System Concepts - 7th Edition 13.12 ©Silberschatz, Korth and Sudarshan
iw.sk i
Sequential File Organization (Cont.)
skins it onis i ni استخدم- ▪ الحذف
wi g i sat in e is z si
▪ Deletion – use pointer chains
▪ Insertion –locate the position where the record is to be inserted
g wht • if there is free space insert there
an alsees go ok
insent • if no free space, insert the record in an overflow block
• In either case, pointer chain must be updated
▪ Need to reorganize the file
from time to time to restore
sequential order
i am sit in I 28
Database System Concepts - 7th Edition 13.13 ©Silberschatz, Korth and Sudarshan
WE Eat is up Il Il N
Multitable Clustering File Organization
قم بتخزين عدة عالقات في ملف واحد باستخدام منظمة ملف تجميع متعددة
Store several relations in one file using a multitable clustering
file organization
department
instructor
C
multitable clustering create cluster command
of department and cluster key is dept name.
instructor
Database System Concepts - 7th Edition 13.14 ©Silberschatz, Korth and Sudarshan
Multitable Clustering File Organization (cont.)
as a s
▪ good for queries involving department ⨝ instructor, and for queries
involving one single department and its instructors
▪ bad for queries involving only department
▪ results in variable size records
▪ Can add pointer chains to link records of a particular relation
- ▪ مناسب لالستفسارات املتعلقة بمدرس القسم ولالستفسارات إشراك قسم واحد ومعلميه
- قسما فقط
ً سيئ لالستعالمات التي تتضمن
- ينتج عنه سجالت متغيرة الحجم
يمكن إضافة سالسل مؤشرات لربط سجالت عالقة معينة
Database System Concepts - 7th Edition 13.15 ©Silberschatz, Korth and Sudarshan
يمكن تقسيم السجالت:تجزئة الجدول
Partitioning ذات العالقة إلى أصغر
an 851 I im sitI t l
▪ Table partitioning: Records in a relation can be partitioned into smaller
relations that are stored separately
It
transaction_2018, transaction_2019, etc.
▪ E.g., transaction partition for current year on SSD, for older years
on magnetic disk
solidstatedrive d
in Ms Wi axe
Database System Concepts - 7th Edition 13.16 ©Silberschatz, Korth and Sudarshan
oket km data
ma am in s.iqData Dictionary Storage يقوم قاموس البيانات
Data
t t w wt w Data st.ms so
The Data dictionary (also called system catalog) stores metadata; that is,
data about data, such as
Database System Concepts - 7th Edition 13.17 ©Silberschatz, Korth and Sudarshan
Relational Representation of System Metadata
44 w 81 if a 1 4 93 l d
▪ Relational
representation on my
disk
s
▪ Specialized data s
structures designed s
for efficient access,
in memory
iii i am i mis É
ownie ti s inou
it
me
admin
analyst
wife pata si b
most
▪ Blocks are units of both storage allocation and data transfer.
▪ Obiang's
Buffer – portion of
metastasis
main memory
soya ma oil se
available to store copies of disk blocks.
im
orgies mainmemory is Mihaly Buffer 13 um
g ▪ Buffer manager – subsystem responsible for allocating buffer space in main
memory. ran d
rimsie ewmdai
e eHands
wiersma
processing
am
Database System Concepts - 7th Edition 13.19 ©Silberschatz, Korth and Sudarshan
▪ تستدعي
Buffer Manager البرامج مدير املخزن
▪ Programs call on the buffer manager when they need a block from disk.
• If the block is already in the buffer, buffer manager returns the address of
1am IT
WE1 Data the block in main memory disk
18 I s i w w's is
I
• If the block is not in the buffer, the buffer manager
Bufferto so did as l
▪ Allocates space in the buffer for the block
a a web 41 Buffer is pal oh Is it
• Replacing (throwing out) some other block, if required, to make
space for the new block.
Buffer b so bi
a mix at I a e
• Replaced block written back to disk only if it was modified since
the most recent time that it was written to/fetched from the disk.
▪ Reads the block from the disk to the buffer, and returns the address of
Database System Concepts - 7th Edition 13.20 ©Silberschatz, Korth and Sudarshan
Buffer Manager -Buffer replacement strategy
too disk t.LI 1,512
▪ Pinned block: memory block that is not allowed to be written back to disk
• Pin done before reading/writing datadfrom a block :▪ كتلة مثبتة
كتلة ذاكرة ال
• Unpin done when read /write is complete wait t.is
a basin• Multiple concurrent pin/unpin operations possible
I Wide ▪ Keep a pin count, buffer block can be evicted only if pin count = 0
nasty
▪ Shared and exclusive locks on buffer tags looks's s i list
pinlunpinsiksbxo.ws.is
• Needed to prevent concurrent operations from reading page contents
twists she as they are moved/reorganized, and to ensure only one
move/reorganize at a time
was listen
E ist 4051 40 mn.gs iv girls
• Readers get shared lock, updates to a block require exclusive lock cow
Block
m.nw.wi• Locking rules: g us.ie
▪ Only one process can get exclusive lock at a time jam
a rites s buffer
i sie
▪ Shared lock cannot be concurrently with exclusive lock
▪ Multiple processes may be given shared lock concurrently
s www.wsis
i e.skobwsharedlock
Database System Concepts - 7th Edition 13.21 ©Silberschatz, Korth and Sudarshan
Buffer w Jw I I l 431 051 2 it s t I تستبدل معظم أنظمة
Buffer-Replacement Policies التشغيل الكتلة األقل
▪ Most operating systems replace the block least recently used (LRU strategy)
• i te
Idea behind LRU – use pastipattern
sa vie in ya i am
of block references as a predictor of
future references
• t.I.tk
LRU can be bad for some queries
▪ Example of bad access pattern for LRU: when computing the join of 2 relations r
and s by a nested loops
tuple m e
for each tuple tr of r do
for each tuple ts of s do
if the tuples tr and ts match … iw.is
join
تحرر املساحة التي يشغلها الكتل بأسرع ما- ▪ إستراتيجية القذف الفوري
يمكن
(MRU) نظرا ألنه تمت معالجة املجموعة النهائية لتلك الكتلة ▪ إستراتيجيةً
يجب على النظام تثبيت الكتلة- مؤخرا
ً املستخدمة
بعد أن تم إجراء املجموعة النهائية لتلك الكتلة.قيد املعالجة حاليا
وتصبح أحدث استخدامات، يتم إلغاء تثبيت الكتلة، تمت معالجته
.الكتلة
Database System Concepts - 7th Edition 13.23 ©Silberschatz, Korth and Sudarshan
9 im g s1st w w j
Optimization of Disk Block Access
يدعم مديرو املخزن
املخرجات القسرية للكتل
s p.jo qt II é mi I six o pas system w yo t o g p ie
bi ti ▪ Buffer managers support forced output of blocks for the purpose of recovery
5 is w son i
ask aswrite
Nonvolatile buffers speed up disk writes by writing blocks to a non-
volatile RAM or flash buffer immediately I E a w
rmmo so of wi u o Eso wi a t.si as an Buffywww.wl
• Writes can be reordered to minimize disk arm movement di
▪ Log disk – a disk devoted to writing a sequential log of block updates
• Used exactly like nonvolatile RAM
www.t.am al 0418 I o to e
▪ Write to log disk is very fast since no seeks are required
f
▪ Journaling file systems write data in-order to NV-RAM or log disk
• Reordering without journaling: risk of corruption of file system data
risk if u É 561 43 o ul s t
431 T I I b in WI Is 65 at
Database System Concepts - 7th Edition 13.24 ©Silberschatz, Korth and Sudarshan
16 M at A
Column-Oriented Storage
ً ▪ يُعرف
أيضا باسم التمثيل العمودي
▪ Also known as columnar representation ▪ تخزين كل سمة من سمات العالقة
▪ Store each attribute of a relation separately بشكل منفصل مثال
▪ Example new II 138
Database System Concepts - 7th Edition 13.25 ©Silberschatz, Korth and Sudarshan
Columnar Representation :▪ الفوائد
اإلخراج/ • تقليل اإلدخال
في حالة الوصول إلى بعض
▪ Benefits:
He a aim I a lady
• Reduced IO if only some attributes are accessed
• Improved CPU cache performance si si i m
Into
• Improved compression imJiya
• Vector processing on modern CPU architectures
▪ Drawbacks
• Cost of tuple reconstruction from columnar representation
• Cost of tuple deletion and update
tax am
• Cost of decompression
www.t▪ Columnar representation found to be more efficient for decision support than
noisy row-oriented representation
▪ Traditional row-oriented representation preferable for transaction processing
▪ Some databases support both representations
• Called hybrid row/column stores
rowrepresentation it d
and
columnpresentation
Database System Concepts - 7th Edition 13.26 ©Silberschatz, Korth and Sudarshan
ORC :والباركيه
Columnar File Representation ملف
Parquet is a column-oriented
binary file format
data www
Database System Concepts - 7th Edition 13.27 ©Silberschatz, Korth and Sudarshan
Storage Organization in Main-Memory Databases
▪ يمكن تخزين
السجالت مباشرة
▪ Can store records directly in
memory without a buffer manager
byuse
▪ Column-oriented storage can be 2
used in-memory for decision
support applications
• Compression reduces
wi I I1,51 memory requirement
Wity asm
Ii sway
Database System Concepts - 7th Edition 13.28 ©Silberschatz, Korth and Sudarshan
End of Chapter 13
Database System Concepts - 7th Edition 13.29 ©Silberschatz, Korth and Sudarshan