Download presentation
Presentation is loading. Please wait.
1
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus University of California, Berkeley School of Information Management and Systems SIMS 257: Database Management
2
10/3/2000SIMS 257: Database Management -- Ray Larson Review Physical Database Design RAID Data Integrity
3
10/3/2000SIMS 257: Database Management -- Ray Larson Physical Design Decisions There are several critical decisions that will affect the integrity and performance of the system. –Storage Format –Physical record composition –Data arrangement –Indexes –Query optimization and performance tuning
4
10/3/2000SIMS 257: Database Management -- Ray Larson When to Index Tradeoff between time and space: –Indexes permit faster processing for searching –But they take up space for the index –They also slow processing for insertions, deletions, and updates, because both the table and the index must be modified Thus they SHOULD be used for databases where search is the main mode of interaction The might be skipped if high rates of updating and insertions are expected
5
10/3/2000SIMS 257: Database Management -- Ray Larson When to Use Indexes Rules of thumb –Indexes are most useful on larger tables –Specify a unique index for the primary key of each table –Indexes are most useful for attributes used as search criteria or for joining tables –Indexes are useful if sorting is often done on the attribute –Most useful when there are many different values for an attribute –Some DBMS limit the number of indexes and the size of the index key values –Some indexed will not retrieve NULL values
6
10/3/2000SIMS 257: Database Management -- Ray Larson RAID Technology Parallel Writes Disk 2Disk 3Disk 4Disk 1 1 2 3 4 5 6 7 8 9 10 11 12 * * Parallel Reads Stripe One logical disk drive
7
10/3/2000SIMS 257: Database Management -- Ray Larson Raid 0 Parallel Writes Disk 2Disk 3Disk 4Disk 1 1 2 3 4 5 6 7 8 9 10 11 12 * * Parallel Reads Stripe One logical disk drive
8
10/3/2000SIMS 257: Database Management -- Ray Larson RAID-1 Parallel Writes Disk 2Disk 3Disk 4Disk 1 1 1 2 2 3 3 4 4 5 5 6 6 * * Parallel Reads Stripe
9
10/3/2000SIMS 257: Database Management -- Ray Larson RAID-2 Writes span all drives Disk 2Disk 3Disk 4Disk 1 1a 1b ecc ecc 2a 2b ecc ecc 3a 3b ecc ecc * * Reads span all drives Stripe
10
10/3/2000SIMS 257: Database Management -- Ray Larson RAID-3 Writes span all drives Disk 2Disk 3Disk 4Disk 1 1a 1b 1c ecc 2a 2b 2c ecc 3a 3b 3c ecc * * Reads span all drives Stripe
11
10/3/2000SIMS 257: Database Management -- Ray Larson Raid-4 Disk 2Disk 3Disk 4Disk 1 1 2 3 ecc 4 5 6 ecc 7 8 9 ecc * * Stripe Parallel Writes Parallel Reads
12
10/3/2000SIMS 257: Database Management -- Ray Larson RAID-5 Parallel Writes Disk 2Disk 3Disk 4Disk 1 1 2 3 4 5 6 7 8 9 10 11 12 ecc ecc * * Parallel Reads Stripe
13
10/3/2000SIMS 257: Database Management -- Ray Larson Integrity Constraints The constraints we wish to impose in order to protect the database from becoming inconsistent. Five types –Required data –attribute domain constraints –entity integrity –referential integrity –enterprise constraints
14
10/3/2000SIMS 257: Database Management -- Ray Larson
15
10/3/2000SIMS 257: Database Management -- Ray Larson Required Data Some attributes must always contain a value -- they cannot have a null For example: – Every employee must have a job title. –Every diveshop diveitem must have an order number and an item number.
16
10/3/2000SIMS 257: Database Management -- Ray Larson Attribute Domain Constraints Every attribute has a domain, that is a set of values that are legal for it to use. For example: –The domain of sex in the employee relation is “M” or “F” Domain ranges can be used to validate input to the database.
17
10/3/2000SIMS 257: Database Management -- Ray Larson Entity Integrity The primary key of any entity cannot be NULL.
18
10/3/2000SIMS 257: Database Management -- Ray Larson Referential Integrity A “foreign key” links each occurrence in a relation representing a child entity to the occurrence of the parent entity containing the matching candidate key. Referential Integrity means that if the foreign key contains a value, that value must refer to an existing occurrence in the parent entity. For example: –Since the Order ID in the diveitem relation refers to a particular diveords item, that item must exist for referential integrity to be satisfied.
19
10/3/2000SIMS 257: Database Management -- Ray Larson Referential Integrity Referential integrity options are declared when tables are defined (in most systems) There are many issues having to do with how particular referential integrity constraints are to be implemented to deal with insertions and deletions of data from the parent and child tables.
20
10/3/2000SIMS 257: Database Management -- Ray Larson Insertion rules A row should not be inserted in the referencing (child) table unless there already exists a matching entry in the referenced table. Inserting into the parent table should not cause referential integrity problems. Sometimes a special NULL value may be used to create child entries without a parent or with a “dummy” parent.
21
10/3/2000SIMS 257: Database Management -- Ray Larson Deletion rules A row should not be deleted from the referenced table (parent) if there are matching rows in the referencing table (child). Three ways to handle this –Restrict -- disallow the delete –Nullify -- reset the foreign keys in the child to some NULL or dummy value –Cascade -- Delete all rows in the child where there is a foreign key matching the key in the parent row being deleted
22
10/3/2000SIMS 257: Database Management -- Ray Larson Referential Integrity This can be implemented using external programs that access the database newer databases implement executable rules or built-in integrity constraints (e.g. Access)
23
10/3/2000SIMS 257: Database Management -- Ray Larson Enterprise Constraints These are business rule that may affect the database and the data in it –for example, if a manager is only permitted to manage 10 employees then it would violate an enterprise constraint to manage more
24
10/3/2000SIMS 257: Database Management -- Ray Larson Today Relational Operations Relational Algebra Relational Calculus Introduction to SQL via Access
25
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra Operations Select Project Product Union Intersect Difference Join Divide
26
10/3/2000SIMS 257: Database Management -- Ray Larson Select Extracts specified tuples (rows) from a specified relation (table).
27
10/3/2000SIMS 257: Database Management -- Ray Larson Project Extracts specified attributes(columns) from a specified relation.
28
10/3/2000SIMS 257: Database Management -- Ray Larson Product Builds a relation from two specified relations consisting of all possible concatenated pairs of tuples, one from each of the two relations. abcabc xyxy xyxyxyxyxyxy aabbccaabbcc Product
29
10/3/2000SIMS 257: Database Management -- Ray Larson Union Builds a relation consisting of all tuples appearing in either or both of two specified relations.
30
10/3/2000SIMS 257: Database Management -- Ray Larson Intersect Builds a relation consisting of all tuples appearing in both of two specified relations
31
10/3/2000SIMS 257: Database Management -- Ray Larson Difference Builds a relation consisting of all tuples appearing in first relation but not the second.
32
10/3/2000SIMS 257: Database Management -- Ray Larson Join Builds a relation from two specified relations consisting of all possible concatenated pairs of, one from each of the two relations, such that in each pair the two tuples satisfy some condition. A1 B1 A2 B1 A3 B2 B1 C1 B2 C2 B3 C3 A1 B1 C1 A2 B1 C1 A3 B2 C2 (Natural or Inner) Join
33
10/3/2000SIMS 257: Database Management -- Ray Larson Outer Join Outer Joins are similar to PRODUCT -- but will leave NULLs for any row in the first table with no corresponding rows in the second. A1 B1 A2 B1 A3 B2 A4 B7 B1 C1 B2 C2 B3 C3 A1 B1 C1 A2 B1 C1 A3 B2 C2 A4 * * Outer Join
34
10/3/2000SIMS 257: Database Management -- Ray Larson Divide Takes two relations, one binary and one unary, and builds a relation consisting of all values of one attribute of the binary relation that match (in the other attribute) all values in the unary relation. a xyxy xyzxyxyzxy aaabcaaabc Divide
35
10/3/2000SIMS 257: Database Management -- Ray Larson ER Diagram: Acme Widget Co. Contains Part Part#Count Price Customer Quantity Orders Cust# Invoice Writes Sales-Rep Invoice# Sales Rep# Line-Item Contains Part# Invoice# Cust# Hourly Employee ISA Emp# Wage
36
10/3/2000SIMS 257: Database Management -- Ray Larson Employee
37
10/3/2000SIMS 257: Database Management -- Ray Larson Part
38
10/3/2000SIMS 257: Database Management -- Ray Larson Sales-Rep Hourly
39
10/3/2000SIMS 257: Database Management -- Ray Larson Customer
40
10/3/2000SIMS 257: Database Management -- Ray Larson Invoice
41
10/3/2000SIMS 257: Database Management -- Ray Larson Line-Item
42
10/3/2000SIMS 257: Database Management -- Ray Larson Join Items
43
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra What is the name of the customer who ordered Large Red Widgets? –Select “large Red Widgets” from Part as temp1 –Join temp1 with Line-item on Part # as temp2 –Join temp2 with Invoice on Invoice # as temp3 –Join temp3 with customer on cust # as temp4 –Project Name from temp4
44
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Calculus Relational Algebra provides a set of explicit operations (select, project, join, etc) that can be used to build some desired relation from the database. Relational Calculus provides a notation for formulating the definition of that desired relation in terms of the relations in the database without explicitly stating the operations to be performed SQL is based on the relational calculus.
45
10/3/2000SIMS 257: Database Management -- Ray Larson SQL Structured Query Language Database Definition and Querying Basic language is standardized across relational DBMSs. Each system may have proprietary extensions to standard. Relational Calculus combines Select, Project and Join operations in a single command. SELECT.
46
10/3/2000SIMS 257: Database Management -- Ray Larson SELECT Syntax: –SELECT attr1, attr2,…, attr3 FROM rel1 r1, rel2 r2,… rel3 r3 WHERE condition1 {AND | OR} condition2 ORDER BY attr1, attr3 Examples in Access...
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.