Chapter 3 - User-defined Routines and Object Behavior Flashcards

1
Q

What is the general idea and the different kinds of User-defined Routines?

A
  • Named persisted code to be invoked in SQL (PSM/external)
  • Integrated in schema, CREATE/ALTER/DROP, privileges
  • Procedure (CALL statement), function (expression), method (type function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the general structure of a routine definition in SQL?

A
  • > Head: Name + list of parameters (IN/OUT/INOUT) + returns* type
    • procedures
  • **functions/methods
  • > Body: SQL (PSM); or host programming language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the alternatives for providing implementation for routines?

A

SQL(PSM)**, external

** Procedural language extensions (statements)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the differences between procedures and functions in SQL?

A
  • > Procedure -> Statement context
    • OUT/INOUT parameters: modified by procedure and mode available to caller afterwords
    • Dynamic Result Sets: Declare and return cursors
  • > Function -> Expression context
    • returns (mandatory) (no result sets)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which additional functionality is provided by table functions?

A

Transform non-relational data on relational table dynamically
Returns a table (multiset of rows)
-> RETURNS TABLE (name type, name type, …)
-> RETURNS TABLE (SELECT… FROM…)
Used in FROM clause
-> SELECT … FROM TABLE (f(a,b) AS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Compare table functions and views as mechanisms for virtual tables?

A

TFs support dynamic parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are privileges applied to UDRs?

A

Execute privilege
Roles: (DEFINER**, INVOKER) when executing queries inside routine def
** With GRANT option
** Routine droped if lost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are implications of cross-schema overloading?

A
  • Overloading routines with the same signature

* Need to define schema path for overload resolution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the general idea and the algorithm for subject routine determination in SQL?

A
  • > Decide which routine to invoke based on: Static types of args, type precedence list (subtype relation for STs) schema path, EXECUTE privilege
  • > Algorithm: 1. set of candidates (name+ num of args) from all PATH if not fully qualified. 2. Eliminate unprivileged and incompatible arg types (not in prec. list). 3. Select best match from left to right. 4. Select first on PATH.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is the overloading of procedures supported in SQL?

A

Only based on param numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are methods in SQL and how do they differ from functions?

A

-> SQL functions belonging to a structured type.
diffs:
-> Implicit SELF parameter (subject parameter)
-> Separate body and signature def (same schema as ST)
-> Invoked with dot notation: UDT-value.method()
CREATE TYPE T AS (…)
METHOD in RETURNS type;
CREATE METHOD m FOR T
BEGIN … END;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the different types of methods supported in SQL?

A

-> Instance (original vs overriding), constructor, static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does SQL support overriding methods?

A

Signature must match, except for implict SELF, which is of subtype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does subject routine determination work for instance methods?

A
  • > Just like for functions, but setting PATH to list of supertype schemas
  • > Dynamic dispatch: decide between overriding methods based on dynamic type of SELF.
  • Schema evolution affects actual invoked method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does method invocation work for typed tables and object references?

A

Typed tables: DEREF(oid).method( ) -> Transform ROW into value of ST
references: “->” notation -> Requires SELECT privilege on scoped table: table-specific INVOKE privileges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the goal of observer and mutator methods?

A

Access and modification of attributes is made through them
-> Implicity associated to attributes
Mutators return modified copy of object

17
Q

Give an overview of how the modification of object state works in SQL.

A
  • > Values of STs can’t be modified, just copied through mutators (no side-effects)
  • > Rows of typed tables are modified with UPDATE statement
18
Q

How does attributes access work for SQL objects and assignments?

A

DOT notation: Att access = invoke observer
Systantic sugar for assignments.
SET obj.att = value -> obj.att(value)

19
Q

How does SQL support object encapsulation?

A
  • > State is only accessible through methods (separate iface/impl.)
  • > Public interface definition not supported
  • > Implemented through privileges
20
Q

Give an overview over static methods in SQL?

A

No subject parameter (SELF), no overriding, static binding

Invocation ‘::’ “STATIC METHOD…”

21
Q

What are the different alternatives for constructing objects in SQL?

A
System defined (default values) + Mutator invocations
User-defined: "CONSTRUCTOR METHOD type RETURNS type"+ "CREATE ... FOR type" + NEW
22
Q

How does SQL deal with type substitutability of method return values?

A
  • Return type must be the ST, method returns copy of self
  • inherited methods return sypertype: static type error (for columns types e.g.)
  • Type-preserving functions/methods: SELF AS RESULT: type of self argument is type of return value
23
Q

Give an overview over the additional routine characteristics.

A
  • DETERMINISTIC vs NOT DETERMINISTIC
  • RETURNS NULL ON NULL INPUT vs CALLED ON NULL INPUT
  • CONTAINS SQL, READS SQL DATA, MODIFIES SQL DATA
24
Q

What is the goal of external routines and how are they supported in SQL?

A

Better performance, existing libraries

No body on CREATE: LANGUAGE + NAME (path)

25
Q

How does SQL deal with parameters of external routines?

A
  • no names, type depends on host language, CAST FROM to convert from host types
  • > parameter style
    • > SQL: additional pointer parameters: name, return value, error msg, SQLSTATE, null idicators…
    • > GENERAL: no additional params -> same signature, but with pointers (null not supp)
26
Q

Give an overview of the functionality provided by SQLJ part. 1

A

Implement SQL routines using java (LANGUAGE JAVA PARAMETER STYLE JAVA)

  • > JAR file as a database object
  • > SQL/JRT(2003)
  • > arguments must be SQL data type
27
Q

What is the functionality provided by SQLJ part 2?

A
  • > Define SQL types using java (Java class -> SQL UDT)
  • > based on install_jar
  • > mapping state + behavior
  • > Automatic mapping to java object on fetch/method invocation (Java serializ., JDBS SQL data interface)
28
Q

How does SQLJ handle instance update methods?

A
  • Identify method with SELF AS RESULT

* SQL system invokes java method on a copy, returning it with the modifications

29
Q

What are the different serialization mechanism of SQLJ?

A

(CREATE TYPE… LANGUAGE JAVA USING x)

  • Serializable: persistent obj state defined by java serialization
    • > SQL attributes must correspond to java public fields
  • SQLDATA: persistent state defined by SQL attributes
    • > readsql + write SQL methods (fields != attrs possible)
  • Implement both interfaces and dont specify on CREATE type -> portability
    • > complete state in public fields