Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The database is stored as a collection of les. Each le is a sequence of records. A record is a sequence of elds. First approach:
assume record size is xed each le has records of one particular type only different les are used for different relations
26
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Fixed-Length Records
Simple approach: Store record i starting from byte n ! (i 1), where n is the size of each record. Calculate the block based on that. Record access is simple. But records may cross blocks!
Deletion of record i: alternatives: move records i + 1, . . ., n to i, . . . , n 1 move record n to i do not move records, but mark deleted records and link all free records on a free list
27
Free Lists
Store the address of the rst deleted record in the le header. Use this rst record to store the address of the second deleted record, and so on One can think of these stored addresses as pointers since they point to the location of a record. More space efcient representation: reuse space for normal attributes of free records to store pointers. (No pointers stored in in-use records.)
28
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Variable-Length Records
Variable-length records arise in database systems in several ways: Storage of multiple record types in a le. Record types that allow variable lengths for one or more elds. E.g varchars
Store several records, with variable length, in blocks (slotted page) A record cannot be bigger than a slotted page This limits the size of records in a database, which is usually the (default) case There are special types for big records, that are treated differently (remember the clobs and blobs in Oracle?)
29
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Slotted pages are usually the size of a block Header contains: number of record entries end of free space in the block location and size of each record
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. (Other) pointers should not point directly to record instead they should point to the entry for the record in header.
30
The choice of a proper organisation of records in a le is important for the efciency of real databases!
31
32
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
33
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
34
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
good for queries involving depositor customer, and for queries involving one single customer and her accounts bad for queries involving only customer but one can add pointer chains to link records of a particular relation results in variable size records
35
File System
In sequential le organisation, each relation is stored in a le One may rely in the le system of the underlying operating system Multitable clustering may have signicant gains in efciency But this may not be compatible with the le system of the operating system
Several large scale database management systems do not rely directly on the underlying operating system The relations are all stored in a single (multitable) le The database management system manages the le by itself This requires the implementation of an own le system inside the DBMS
36
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Information about relations names of relations names and types of attributes of each relation names and denitions of views
integrity constraints User and accounting information, including passwords Statistical and descriptive data number of tuples in each relation Physical le organisation information How relation is stored (sequential/hash/) Physical location of relation Information about indices (in the sequel)
37
Relation_metadata = (relation_name, number_of_attributes, storage_organization, location) Attribute_metadata = (attribute_name, relation_name, domain_type, ! position, length) User_metadata = (user_name, encrypted_password, group) Index_metadata = (index_name, relation_name, index_type, ! index_attributes) View_metadata = (view_name, denition)
38
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Segments are divided into extents, each extent being a set of contiguous database blocks. A database block need not be the same size of an operating system block, but is always a multiple
39
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Hash le organisation (to be studied next week) is also possible for fetching the appropriate cluster A database can be tuned by an appropriate choice for the organisation of data: Choosing partitions Appropriate choice of clusters Hash or sequential
42
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Basic Concepts
Indexing mechanisms are used to speed up access to desired data. Search Key - attribute or set of attributes used to look up records in a le. An index le consists of records (called index entries) of the form search-key pointer
Index les are typically much smaller than the original le Two basic kinds of indices: Ordered indices: search keys are stored in sorted order Hash indices: search keys are distributed uniformly across buckets using a hash function.
43
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
44
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Ordered Indices
In an ordered index, index entries are stored sorted on the search key value. E.g. as an authors catalog in a library. Primary index: in a sequentially ordered le, the index whose search key species the sequential order of the le. Also called clustering index The search key of a primary index is usually but not necessarily the primary key.
Secondary index: an index whose search key species an order different from the sequential order of the le. Also called non-clustering index. Index-sequential le: ordered sequential le with a primary index.
45
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
46
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
47
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Multilevel Index
If the primary index does not t in memory, access becomes expensive. Solution: treat primary index kept on disk as a sequential le and construct a sparse index on it. outer index a sparse index of primary index inner index the primary index le
If the outer index is still too large to t in main memory, yet another level of index can be created, and so on. Indices at all levels must be updated on insertion or deletion from the le.
48
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
49
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
if an entry for the search key exists in the index, it is deleted by replacing the entry in the index with the next search-key value in the le (in search-key order). If the next search-key value already has an index entry, the entry is deleted instead of being replaced.
50
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
If a new block is created, the rst search-key value appearing in the new block is inserted into the index.
Multilevel insertion (as well as deletion) algorithms are simple extensions of the single-level algorithms the outer indices are sparse, whereas the inner one is dense
51
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Secondary Indices
Frequently, one wants to nd all the records whose values in a certain eld (which is not the search-key of the primary index) satisfy some condition. Example 1: In the account relation stored sequentially by account number, we may want to nd all accounts in a particular branch Example 2: as above, but where we want to nd all accounts with a specied balance or range of balances
We can have a secondary index with an index record for each search-key value
52
Jos Alferes - Adaptado de Database System Concepts - 5th Edition
Index record points to a bucket that contains pointers to all the actual records with that particular search-key value. Secondary indices have to be dense, since the le is not sorted by the search key.
53
54
Jos Alferes - Adaptado de Database System Concepts - 5th Edition