Chapter 1 - User-defined types and typed tables Flashcards
What are the basic OO features that must be supported in an ORDBMS?
Object identity classes or types inheritance encapsulation overriding + late binding complex objects completeness (for method implementation) extensibility
What are the key features and benefits of USER-defined types?
- extend DBS functionality + flexibility
- strong typing
- information hiding (no impl. details)
Benefits: - Reuse: overloading + inheritance
- change: isolation + low impact
In which sense do UDTs support strong typing?
- type checking can be enhanced with semantics -> not based just on primitive types.
Shoe size different of room area -> but both integers
How does the cast mechanism of distinct types work?
DT: Renamed type with different semantics (share interval representation)
Cast: allows comparison/ordering based os source type/ create DT values from literals, etc..
* cast functions automatically created (CAST (SOURCE AS DISCTINCT) WITH F)
How can we ensure the compatibility between source and distinct type without explicit casting?
Relaxed strong typing for assignments USING CAST FUNCTIONS:
CAST (SRC AS DST) WITH F AS ASSIGNMENT
* comparison requires explicit casts *
How to distinct types compare to domains in the relational model?
in rel. model -> domain = type
in SQL -> domain = type + constraint + default + collation (CREATE DOMAIN)
What are the intensional and extensional aspects of Structured Types?
- Intention = description = type/class -> UDTs
- > concerns interface and substitution inheritance (operations) - Extension = actual things = set of objects -> typed tables
- > Concerns instantiated objects and inclusion inheritance (structure/state)
what are the different ways in which objects (i.e. instances of structured types) may exist?
Object as values: Values of a ST (columns, attr. of other ST, domains, variables, expressions)
-> no identity, no state modifications
Objects as rows: in typed tables (oid column = identity, update statement = modification
What are two possible instantiation mechanism of structured types
- System-supplied constructor function type-name ->returns obj with default values
- NEW operator -> calls user-defined constructor
How can we access the attributes of an object in the query language?
- dot notation for objects as value (a.b.c.d)
- SELECT or UPDATE of columns for typed tables
- ”->” for referenced stored in tables = DEREF followed by dot
How are subtyping and inheritance realized with structured UDTs?
Just like OO languages
CREATE TYPE … UNDER … -> inherits attributes and methods
**substitutability implied
What are the equivalent of abstract and final classes in an ORDBMS?
- Abstract= NOT INSTATIABLE (no system-supplied constructor)
* final = not supported -> all DTs are final, all STs are not final.
What is the meaning of subtype substitutability and how is it realized in an ORDBMBS?
B < A -> B supports at least the operations defined in A and B can be used everywhere an A is expected.
**obs: invariant return , argument and attribute types
How can we test for the type of an object in SQL?
- Determination of dynamic type. IS OF (boolean = instance of)
- subtypes out: ONLY(type) (type == getClass( ))
What are typed tables and what characteristics do they provide to objects?
tables whose columns are attributes of an ST and rows are objects with an identity
-> provide identity + persistence + update capability
How can we modify the state of objects in typed tables?
modify obj attributes by updating column values
How do table hierarchies relate to type hierarchies?
(Table inherits constraints, triggers, etc)
- typed table can be declared under another typed table of a super type
- *but columns only of the super-type table
- > to exclude subtypes-> FROM ONLY table
How is the concept of object identity supported in ORDBSs?
(identity->existence != values) (sharing, updates, references….)
Primary keys not enough: modifiable, not uniform across tables, require join to navigate into obj
*Solution: oid column (pk) maintained by system + reference types.
What are the variation criteria for object identity in ORDBMSs?
- externall/internal *system/user generated (define identity upon creation)
- Scope of uniquenes (maximal type in table hierarchy)
- reusability (reusing id of deleted obj)
What are reference types and different approaches for their representation?
Used to reference instances of STs stored in typed tables
- > user generated (REF USING )
- > System generated (REF is system gen.)
- > Derived from other attrs (REF FROM (…))
Give an overview over the general use of reference types in the query language
- Insertion
- > User gen.: Like any other, with costs provided
- > System gen.: retrieved from destination table on a subquery
- Strong typing
- > Comparison/assignment requires some REF type
- > Substitutability supported: REF(sub) compatible with REF(super)
What is the requirement on a reference type in order to allow dereferencing it?
- Must be scoped (limited to single table)
why?:
-> Dynamic checks (delete, authorization …)
->Updates
What are path expressions and how do they work when scoped references are used?
Scoped references: When creating table, specify precisely the table in which referenced objects are stored (ref-attribute-name) WITH OPTIONS SCOPE [references are checked]
path expressions:
ref-of-attributte
acesses: a->b.c
What is the functionality of the DEREF operator?
Retrieve object (structured type value) from reference
What is the relation between reference types and referential constraints?
- > Ref. constraints specify inclusion dependencies (no dereferencing)
- > no strong typing
How do the operators ONLY and IS OF work when applied to typed tables?
- > DEREF (obj) IS OF (type)
- > SELECT … FROM ONLY (super)
What are the different forms of equality and how are they used in SQL?
- > Shallow-equality of objects = reference attributes compared by identity
- > deep-equality = derefs nested objects, comparing atomic values by deep equality
What is the goal of UDT ordering and the different types of comparison supported?
Goal: allow comparison (equality) of objects
types: EQUALS ONLY (=, !=), ORDER FULL (all)
What are different approaches for defining ordering fnctions and in which scenarios are they allowed?
STATE: Function automatically created, comparing attributes pair wise (equals) **2 param
RELATIVE: Specify function to compare two objects of the same type and return integer (compare to) **2 parameters
MAP: Map object to predefined type and compare them normally (hash code) **1 param
Explain the concept of comparison type.
Nearest supertype for which comparison was defined
comparison = ordering of comparison type
What is the goal of USER-defined Casts?
Allow values to be cast to other types -> from/to UDTs and reference type CREATE CAST (T1 AS T2) WITH FUNCTION F(T1) [AS ASSIGNMENT]