CS 342 Lecture -*- Outline -*- they learned about RDBs in 361... remark: they should read the other examples too (sets, eval) * relational data base example ad: good example of list processing relations another kind of larger values more examples of typical recursive LISP functions effect: understand language design of RDB operations understand paradigm of list processing, levels of abstraction another example of data abstraction ** relational data bases (page 40) *** tables are n-ary relations mathematically, relation is a set of records (labelled tuples) order of the tuples doesn't matter labels called attributes type of a relation = number and names of columns (record type) *** symbols in tables represent entities in real world e.g., drebber... *** operations all make new relations (don't change or mutate old ones) for each discuss type and kinds of questions it can be used to answer **** selection restricts relation to satisfy a simple predicate like {e | e.crime = murder} answers: what elements have attribute x? returns relation of same type as argument **** projection trims fields off all records like {[victim: e.victim, criminal: e.criminal] | e in LONDON-MURDER-CRIMES} answers: ignoring these attributes, what's the relation between? returns relation with only the given fields **** join matches attributes in different relations like {[victim: v, weapon: m.weapon, motive: m.motive, criminal: m.criminal] | lmv in LONDON-MURDER-VITCIMS, m in MURDERS, (v = lmv.victim) <==> (v = m.victim)} answers: what other relations exist between the common parts of these relations? returns relation with all fields in argument relations **** set operations combine query answers union answers "or" intersection answers "and" diff answers "except" all return relation of same type as argument ** design of the RDB operations (as a language) context: think of RBD operations as a miniature language what kinds of automation do these operations give? are there irregularities in the design? We know operations are "enough", because of "relational completeness" theorem ** implemenation of rdb in LISP *** data structure list of lists. first list gives attribute names (labels) other lists are relationships (tuples, records) see page 42. *** operations select (page 43) derive code for select and each of the following: col-num converts an attribute name into a column number (index) nth gives nth element of a list (car is 0th) include-rows includes all rows for which nth column = v project (page 44) col-num* gives list of column numbers where attributes found is it in ascending or descending order? (descending) include-cols selects given columns from a row, making new row what order does it put them elements in? (reverse from list of column numbers) include-cols* includes all the new rows made by include-cols join exercise for students another exercise, hand execute the query at bottom of page 44. do it equationally