当前位置:
文档之家› 数据库中的数据存储在操作系统管理的文件
数据库中的数据存储在操作系统管理的文件
Loan-schema = ( loan-number, branch-name,amount)
Depositor-schema = (customer-name,account-number) Borrower-schema = (customer-name,loan-number)
File Organization(3)
account-info关系
400 350 700 500 700 900 750 600 700
Record Storage(8)
使用指针的方法(anchor block and overflow block) anchor Perryridge A-102 400 block
Round Hill Mianus Downtown Redwood Brighton
聚集文件
Customer-name Hayes Turner Customer关系
Customer-city Brooklyn Stanford
Organization of Records in Files(5)
• Clustering enhances the processing of join (depositor, customer), but slowing processing of other types of query. • For example:
•不易重新使用被删除记录的空间 •分配给记录的空间不能随记录的改变而改变
Record Storage(10)
• 变长记录文件(变长表示法) slotted-page(分槽的页)结构 :每个块的开始处
有一个块头。
块头
记录条目个数 大小 空闲空间尾指针 位置
空闲空间
Organization of Records in Files(1)
– 记录类型允许一个或多个字段是变长的
• VARCHAR
– 记录类型允许可重复的字段
Record Storage(5)
• 变长记录文件(定长表示法) 使用一个或多个定长记录来代表一个变长 记录。
– 预留空间: 使用长度为最大记录长度的定长记 录。对较短记录未使用的空间用特殊的空值或 记录终结符号来填充。 – 使用指针: 变长记录用一系列通过指针链接起 来的定长记录来表示。
– Select * from customer; – The query requires more block accesses than it did in one-relation-in-one-file – It can be improved by chaining together all the records of the relation using pointers
account关系
记录8 Perryridge A-218 700
Record Storage(4)
• 变长记录文件 以下情况下需要变长记录文件:
– 多种记录类型在一个文件中存储
• Account-list ( branch-name, account-info: (account-number, balance)* )
Large Objects Storage(1)
• Large objects are called binary large objects (blobs) • In relational systems, use long field to store large objects • Most relational databases restrict the size of a record to be no larger than the size of a page, to simplify the buffer manager and free-space manager • Large objects or long fields are often stored in a special file (or collection of files)
Topic 6:Storage, File Organization and Indexing
File Organization(1)
♦ 数据库中的数据存储在操作系统管理的文件 中: 一个关系对应到一个文件 一个关系对应到多个文件 一个文件对应到多个关系 ♦ 操作系统分配给数据库系统一个大的操作系 统文件。所有关系都存储在这个文件中,这 个文件的管理由数据库系统进行。
Organization of Records in Files(3)
• To see the advantage of method, consider the following SQL for bank database:
– Select account-number, customer-name, customer-street, customer-city from depositor, customer where depositor.customer-name = customer.customer-name
记录0 记录1 记录2 记录3 记录4 记录5 记录6 记录7 记录8
Perryridge Rouond Hill Mianus Downtown Redwood Perryridge Brighton Downtown Perryridge
A-102 A-305 A-215 A-101 A-222 A-201 A-217 A-110 A-218
• The determination of when clustering is to be used depends on the types of query that database designer believes to be most frequent • Careful use of clustering can produce significant performance gains in query processing
Organization of Records in Files(4)
聚集文件组织
Hayes Hayes Hayes Hayes Turner Turner Main Brooklyn A-102 A-220 A-503 Putnam Stanford A-305
Customer-name Account-number Hayes A-102 Hayes A-220 Hayes A-503 Turner A-305 depositor关系 Customer-street Main Putnam
File Organization(2)
样例数据库:
Branch-schema = (branch-name,branch-city,assets) Customer-schema = (customer-name,customer-street, customer-city) Account-schema = ( account-number, branch-name, balance)
400 350 700 500 700 900 750 600 700
Record Storage(3)
定长记录文件 空闲指针链法
文件头 记录0 Perryridge A-102 400 记录1 记录2 记录3 记录4 记录5 记录6 记录7 Mianus A-215 700 Downtown A-101 500 Perryridge A-201 900 Downtown A-110 600
•
Organization of Records in Files(6)
聚集文件组织(带指针链)
Hayes Hayes Hayes Hayes Turner Turner Main A-102 A-220 A-503 Putnam A-305 Brooklyn
Stanford
Organization of Records in Files(7)
Record Storage(6)
预留空间的方法
A-102 A-305 A-215 A-101 A-222 A-217 400 A-201 900 A-218 350 700 700 750 ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥
记录0 Perryridge 记录1 Round Hill
Mianus Downtown Redwood Brighton
700 ⊥ ⊥ ⊥ ⊥ ⊥
记录2 记录3 记录4 记录5
500 A-110 600
account-info关系
Re0 Perryridge
A-102 记录1 Rouond Hill A-305 记录2 Mianus A-215 记录3 Downtown A-101 记录4 Redwood A-222 记录5 A-201 记录6 Brighton A-217 记录7 A-110 记录8 A-218
Perryridge Round Hill Mianus Downtown Redwood A-102 A-305 A-215 A-101 A-222 A-217 400 350 700 500 700 750 A-201 ⊥ ⊥ A-110 ⊥ ⊥ 600 ⊥ 900 A-218 700 ⊥
5 Brighton
How to organize the records in a file: • Heap file(堆文件组织): 记录没有顺序,一条记录可以放 在文件中的任何地方。通常一文件一关系. • Sequential file(顺序文件组织): 记录根据检索码的值顺 序存储。 • Hashing file(散列文件组织): 散列函数的计算结果确定 记录应存储到文件的哪个块中。 • Clustering file(聚集文件组织): 几个不同关系的记录可 以存储在同一个文件中。不同关系中的相关记录存储在 相同的块中。