Download presentation
Presentation is loading. Please wait.
1
An illustrative DBMS and database
The INGRES relational database system for a retail enterprise 5/6/2019 CS319 Theory of Databases
2
The Ingres Relational Database 1
A sample INGRES relational DB for a retail enterprise Database = System Catalogue and User Relations System Catalogue (5 standard relations) relation attribute indexes integrities protect 5/6/2019 CS319 Theory of Databases
3
The Ingres Relational Database 2
A sample INGRES relational DB for a retail enterprise User Relations (8 relations) item parts store supply supplier dept employee sale 5/6/2019 CS319 Theory of Databases
4
The Ingres Relational Database 3
A sample INGRES relational DB for a retail enterprise The user relations record enterprise activity, viz. sale of items made up of component parts ordered from suppliers. The system catalogue records the meta-information about the user relations: their attributes, constraints, protection, relevant physical organisation 5/6/2019 CS319 Theory of Databases
5
The Retail Database 1 Significance of user relations
parts what parts do suppliers supply? supply what has been supplied / is pending? supplier who are the suppliers? item what items do we sell / are in stock? store what outlets do we have for sales? dept who are dept sales managers? employee who are our sales employees? sale when, where & by whom are sales made? 5/6/2019 CS319 Theory of Databases
6
The Retail Database 2 Attributes for these relations are as follows:
item: number, name, dept, price, qoh parts: pnum, pname, colour, weight, qoh, supplier store: number, city, state supply: snum, pnum, jnum, shipdate, quantity supplier: number, name, city, state dept: number, name, store, floor, manager employee: number, name, salary, manager, DOB, startdate sale: number, date, store, dept, item, quantity, employee, credit 5/6/2019 CS319 Theory of Databases
7
The Retail Database 3 Interpretation of relations ...
Each tuple can be interpreted as an assertion e.g. a tuple in the sale relation: “ on <date> salesperson <employee> sold <quantity> of the item <item> in <dept> of <store> for <credit> and this was sale number <number> ” sale: number, date, store, dept, item, quantity, employee, credit 5/6/2019 CS319 Theory of Databases
8
The Retail Database 4 The system catalogue is the Data Dictionary. Has info about all the relations in the database. For instance: relation: relid, relowner, reltups, relwid, relatts .... attribute: attrelid, attowner, attname, attfrmt, .... .... content of the relation relation: relid name of the relation relowner who owns relation reltups how many tuples the relation has relwid how wide each tuple is relatts details of attributes of relation .... 5/6/2019 CS319 Theory of Databases
9
The Retail Database 5 User access to data dictionary info about relations ... data dictionary info re relation presented via header: Relation: ... Owner: ... Tuple width: ... Number of Tuples: ... Storage structure: ... Relation type: ... + relation table characterising attributes of the relation. 5/6/2019 CS319 Theory of Databases
10
The Retail Database 6 Sample content of data dictionary ….
… suppose that current content of store relation is: 5/6/2019 CS319 Theory of Databases
11
The Retail Database 7 Header for the data dictionary information on store: Relation: store Owner: ingres Tuple width: 23 Number of Tuples: 3 Storage structure: paged heap Relation type: user relation 5/6/2019 CS319 Theory of Databases
12
The Retail Database 8 … relation table characterising the attributes of store: Attribute name type length number i 2 city c 15 state c 12 This means number field is up to 2 digit number, city field is up to 15 characters etc. 5/6/2019 CS319 Theory of Databases
13
Issues raised by relational databases 1
How do we conceive the relation scheme? Conceptual aspect: does relation scheme match enterprise? how do we do the real-world modelling? Use E-R modelling to assist here Technical aspect: is the scheme free of redundancy? are there anomalies on update / deletion? ... use a theory of database design: normal forms etc 5/6/2019 CS319 Theory of Databases
14
Issues raised by relational databases 2
What is a suitable theoretical framework for a query language? - relational theory What mathematical model should we use to interpret information retrieval formally? … have logical and algebraic frameworks - relational calculus and relational algebra By what criterion is a query language sufficiently expressive? … introduce a notion of completeness 5/6/2019 CS319 Theory of Databases
15
Issues raised by relational databases 3
How do we make access to information efficient without disclosing physical model? principles for storing relations: B-trees, hashing, indexes optimisation techniques for query processing How do we make query languages that are precise but easy to use? commercial query language designs SQL, QBE etc 5/6/2019 CS319 Theory of Databases
16
Relational query languages 1
Archetypal query in Quel constructs new relation from relations R1, R2, ..., Rk. range of t1 is R1 range of t2 is R2 .... range of tk is Rk retrieve (ti(1).Aj(1), ...., ti(r).Aj(r)) where Y(t1, t2, ..., tk) Y(t1, t2, ..., tk) is a (quantifier-free) logical constraint on the tuples selected by the range variables t1, t2, ..., tk in the construction process 5/6/2019 CS319 Theory of Databases
17
Relational query languages 2
Illustrative example of use of QUEL: parts pnum, pname, colour, weight, qoh supply snum, pnum, jnum, shipdate, quantity Display supplier, partname , shipdate for all parts shipped since 1994 range of p is parts range of s is supply retrieve (s.snum, p.pname, s.shipdate) where (s.pnum = p.pnum) and (s.shipdate >= 1994) 5/6/2019 CS319 Theory of Databases
18
Relational query languages 3
Linking example to the abstract formalism: k= two relations used in construction Index the relations by integers, so that R1 is parts, R2 is supply, t1 is p, t2 is s Index the attributes of parts and supply by integers: e.g. t1.A3 is p.colour, t2.A3 is s.jnum etc 5/6/2019 CS319 Theory of Databases
19
Relational query languages 4
… linking example to abstract formalism … i() and j() functions with domain set {1,2,3} constructing a relation with 3-tuples i maps onto the set {1,2} … from which relation are new fields derived? j maps onto the set {1, 2, ..., 5} … from which fields are new fields derived? Y(t1, t2) =Y(p, s) is a logical constraint on the tuples selected from parts and supply viz. "s and p must designate tuples with the same part number, and the shipdate for the supply tuple must be 1994 or later" 5/6/2019 CS319 Theory of Databases
20
Relational query languages 5
In general, can translate this into a logical specification for a new relation constructed from a set of source relations R1, R2, ..., Rk - express this in the form: [The required relation is] the set of tuples of the form u(r) = (u[1], u[2], ..., u[r]) where ti is a tuple in the relation Ri, u is made up of particular components of the ti's, and the ti's used to construct u satisfy some additional constraint. 5/6/2019 CS319 Theory of Databases
21
Relational query languages 6
A suitable logical expression for the required relation is { u(r) | ( t1) ... ( tk) ( R1(t1) R2(t2) ... Rk(tk) u[1] = ti(1) [ j(1) ] u[2] = ti(2) [j(2)] ... u[r] = ti(r) [j(r)], Y(t1, t2, ..., tk) ) } 5/6/2019 CS319 Theory of Databases
22
Relational query languages 7
This uses a Relational Calculus formalism to define the set of tuples that make up the new relation by a predicate. Here Rj(tj) is a basic predicate asserting that tj is a tuple in the relation Rj. Need a "predicate calculus over relations" to do this. There are two variants of this: tuple relational calculus domain relational calculus. QUEL is tuple relational calculus based. 5/6/2019 CS319 Theory of Databases
23
The QUEL query language 1
Sample QUEL queries referring to HVFC database MEMBERS(NAME, ADDRESS, BALANCE) ORDERS(ORDER_NO, NAME, ITEM, QUANTITY) SUPPLIERS(SNAME, SADDRESS, ITEM, PRICE) Print names of members with balances < 0: range of t is MEMBERS retrieve (t.NAME) where t.BALANCE<0 5/6/2019 CS319 Theory of Databases
24
The QUEL query language 2
Sample QUEL queries referring to HVFC database MEMBERS(NAME, ADDRESS, BALANCE) ORDERS(ORDER_NO, NAME, ITEM, QUANTITY) SUPPLIERS(SNAME, SADDRESS, ITEM, PRICE) Print supplier names, items & prices of all suppliers supplying at least one item ordered by Brooks. range of r is ORDERS range of s is SUPPLIERS retrieve (s.SNAME, s.ITEM, s.PRICE) where r.NAME = "Brooks, B" and r.ITEM = s.ITEM 5/6/2019 CS319 Theory of Databases
25
The QUEL query language 3
Sample QUEL queries referring to HVFC database MEMBERS(NAME, ADDRESS, BALANCE) ORDERS(ORDER_NO, NAME, ITEM, QUANTITY) SUPPLIERS(SNAME, SADDRESS, ITEM, PRICE) Print suppliers supplying every item Brooks orders. range of s is SUPPLIERS range of i is SUPPLIERS retrieve into SUPITEM (S = s.SNAME, I = i.ITEM) Step 1: SUPITEM now contains all (supplier, item) pairs - howsoever supplier and item related. 5/6/2019 CS319 Theory of Databases
26
The QUEL query language 4
Sample QUEL queries referring to HVFC database MEMBERS(NAME, ADDRESS, BALANCE) ORDERS(ORDER_NO, NAME, ITEM, QUANTITY) SUPPLIERS(SNAME, SADDRESS, ITEM, PRICE) Print suppliers supplying every item Brooks orders. range of s is SUPPLIERS range of t is SUPITEM delete t where t.S = s.SNAME and t.I = s.ITEM Step 2: Find all tuples (S, I) where S does not supply I. 5/6/2019 CS319 Theory of Databases
27
The QUEL query language 5
Sample QUEL queries referring to HVFC database MEMBERS(NAME, ADDRESS, BALANCE) ORDERS(ORDER_NO, NAME, ITEM, QUANTITY) SUPPLIERS(SNAME, SADDRESS, ITEM, PRICE) Print suppliers supplying every item Brooks orders. range of r is ORDERS range of t is SUPITEM retrieve into SUPFAIL (S = t.S, I = t.I) where r.NAME = "Brooks, B" and r.ITEM = t.I Step 3: Construct list of suppliers who don't supply some item ordered by Brooks. 5/6/2019 CS319 Theory of Databases
28
The QUEL query language 6
Sample QUEL queries referring to HVFC database MEMBERS(NAME, ADDRESS, BALANCE) ORDERS(ORDER_NO, NAME, ITEM, QUANTITY) SUPPLIERS(SNAME, SADDRESS, ITEM, PRICE) Print suppliers supplying every item Brooks orders. range of s is SUPPLIERS retrieve into SNAMES (S = s.SNAME) constructs list of supplier names. Finally range of n is SNAMES range of f is SUPFAIL delete n where n.S = f.S Step 4: SNAMES is the now required relation 5/6/2019 CS319 Theory of Databases
29
The QUEL query language 7
Print suppliers supplying every item Brooks orders: range of s is SUPPLIERS range of i is SUPPLIERS retrieve into SUPITEM (S = s.SNAME, I = i.ITEM) range of t is SUPITEM delete t where t.S = s.SNAME and t.I = s.ITEM range of r is ORDERS retrieve into SUPFAIL (S = t.S, I = t.I) where r.NAME = "Brooks, B" and r.ITEM = t.I retrieve into SNAMES (S = s.SNAME) range of n is SNAMES range of f is SUPFAIL delete n where n.S = f.S 5/6/2019 CS319 Theory of Databases
30
The QUEL query language 7
Completeness of QUEL Must represent 5 primitive relational algebra operations: 1. Union T(n) = R(n) È S(n) range of r is R append to T(C1 = r.A1, ..., Cn = r.An) range of s is S append to T(C1 = s.B1, ..., Cn = s.Bn) 5/6/2019 CS319 Theory of Databases
31
The QUEL query language 8
Completeness of QUEL (cont.) 2. Set Difference T(n) = R(n) - S(n) range of r is R append to T (C1 = r.A1, ..., Cn = r.An) range of t is T range of s is S delete t where t.C1 = s.B1 and ... and t.Cn = s.Bn) 5/6/2019 CS319 Theory of Databases
32
The QUEL query language 9
Completeness of QUEL 3. Cartesian Product T(m+n) = R(m) ´ S(n) range of r is R range of s is S append to T(C1 = r.A1, ..., Cm = r.Am, Cm+1 = s.B1, ..., Cm+n = s.Bn) 5/6/2019 CS319 Theory of Databases
33
The QUEL query language 10
Completeness of QUEL 4. Projection T = Õ i(1), i(2), ..., i(k) (R) range of r is R append to T(C1 = r.Ai(1), ..., Ck = r.Ai(k) ) 5. Selection sF(R), where F condition on tuples in R append to T(C1 = r.A1, ..., Cn = r.An) where F' [ F' º condition F transformed to QUEL syntax ] 5/6/2019 CS319 Theory of Databases
34
To follow … Review of Relational Database Systems
5/6/2019 CS319 Theory of Databases
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.