数据库中的数据存储在操作系统管理的文件

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

记录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
How to organize the records in a file: • Heap file(堆文件组织): 记录没有顺序,一条记录可以放 在文件中的任何地方。通常一文件一关系. • Sequential file(顺序文件组织): 记录根据检索码的值顺 序存储。 • Hashing file(散列文件组织): 散列函数的计算结果确定 记录应存储到文件的哪个块中。 • Clustering file(聚集文件组织): 几个不同关系的记录可 以存储在同一个文件中。不同关系中的相关记录存储在 相同的块中。
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

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)
聚集文件
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:
Organization of Records in Files(2)
• Many relational-database systems store each relation in a separate file to use OS file system • However, many large-scale database systems do not relay directly on the underlying OS file. Instead, one large OS file is allocated to database system. All relations are stored in this one file. Database systems manage the file.
Topic 6:Storage, File Organization and Indexing
File Organization(1)
♦ 数据库中的数据存储在操作系统管理的文件 中: 一个关系对应到一个文件 一个关系对应到多个文件 一个文件对应到多个关系 ♦ 操作系统分配给数据库系统一个大的操作系 统文件。所有关系都存储在这个文件中,这 个文件的管理由数据库系统进行。
– 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
– 记录类型允许一个或多个字段是变长的
• VARCHAR
– 记录类型允许可重复的字段
Record Storage(5)
• 变长记录文件(定长表示法) 使用一个或多个定长记录来代表一个变长 记录。
– 预留空间: 使用长度为最大记录长度的定长记 录。对较短记录未使用的空间用特殊的空值或 记录终结符号来填充。 – 使用指针: 变长记录用一系列通过指针链接起 来的定长记录来表示。
•不易重新使用被删除记录的空间 •分配给记录的空间不能随记录的改变而改变
Record Storage(10)
• 变长记录文件(变长表示法) slotted-page(分槽的页)结构 :每个块的开始处
有一个块头。
块头
记录条目个数 大小 空闲空间尾指针 位置
空闲空间
Organization of Records in Files(1)
Mianus Downtown Redwood Brighton
700 ⊥ ⊥ ⊥ ⊥ ⊥
记录2 记录3 记录4 记录5
500 A-110 600
account-info关系
Record Storage(7)
使用指针 的方法 记录0 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
• 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
Loan-schema = ( loan-number, branch-name,amount)
Depositor-schema = (customer-name,account-number) Borrower-schema = (customer-name,loan-number)
File Organization(3)
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
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
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
Record Storage(2)
• 定长记录文件 顺序存储法
严重缺点 删除一条记录十分困难 除非块的大小恰好是 。待删除记录所占据的 记录大小的倍数,否 空间必须由文件中的其 则一些记录会跨过块 它记录来填充,或者必 的边界,从而读写这 须用一种方法标记被删 样一条记录需要两次 除的记录使得它可以被 块访问。 忽略。
block
A-305 A-215 A-101 A-222 A-217 A-210 A-218 A-110
350 700 500 700 750 900 700 600
百度文库overflow
Record Storage(9)
• 变长记录文件(变长表示法)
Byte-String(字节流)表示 :把每个记录作为一个连续的字 节流存储,每个记录的末尾附加一个特殊的记录终止符号。 0 1 2 3 4
account关系
记录8 Perryridge A-218 700
Record Storage(4)
• 变长记录文件 以下情况下需要变长记录文件:
– 多种记录类型在一个文件中存储
• Account-list ( branch-name, account-info: (account-number, balance)* )
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)
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)
• 记录的物理存储 • 文件中记录的组织
Record Storage(1)
• Fixed-Length Records(定长记录文件) 文件中所有的记录都具有相同的长度,从 而一个块中所有的记录都是等长的。 • Variable-Length Records(变长记录文件) 文件中的记录可以有不同的长度,从而一 个块中的各个记录可以具有不同的长度。
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
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
相关文档
最新文档