on rules, procedures, caching and views in data base system by m. stonebraker, a. jhingran, j. goh,...

17
ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Upload: stephanie-collins

Post on 27-Mar-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

ON RULES, PROCEDURES, CACHING AND VIEWS IN

DATA BASE SYSTEMby M. Stonebraker, A. Jhingran, J.

Goh, and S. Potamianos

UC Berkley

Presented by Zhou Ji

Page 2: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

• Main idea of the paper: A rule system is a fundamental concept in a next generation DBMS, and it subsumes both views and procedures as special cases.

• Background: POSTGRES system

the second POSTGRES rule system (PRS2)

Page 3: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

1. What is view and procedure data type?

• What is view?

View is a virtual relation that is defined on other relations, all queries and updates to which can be mapped to commands on the underlying base relation.

Example:define view TOY_EMP as retrieve (EMP name, EMP age, EMP salary) where EMP dept = “toy”

Page 4: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

• What is the procedure data type?Data type of a column in a relation, each of

which is an unrestricted collection of query language commands.

Example: EMP(name, hobbies)Hobby relations: SOFTBALL(name, position, average)

JOGGING(name, mile, best-time)

Page 5: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Define procedure foobar for employee Joe:retrieve (SOFTBALL all)where SOFTBALL name=“Joe”retrieve (JOGGING all)where JOGGING name =“Joe”

Insert a record of Joe to EMP:append to EMP (name=“Joe”, hobbies=foobar)

Page 6: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

2. The form of PRS2

DEFINE RULE rule-name [AS EXCEPTION rule-name] ON event TO object [[FROM clause] WHERE clause] THEN DO [instead] action

NEW and CURRENT can appear instead of a tuple variable whenever a tuple is permissible.

Page 7: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Example 1

• define rule example_1 on replace to EMP salary where EMP name = “Joe” then replace EMP (salary = NEW salary) where EMP name = “Sam”

Whenever Joe’s salary is changed, Sam gets the same salary.

• define rule example_2 on retrieve to EMP salary where EMP name = “Joe” then replace EMP (salary = CURRENT salary) where EMP name = “Bill”

Page 8: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Example 3

• define rule example_3 on retrieve to EMP salary where EMP dept = “shoe” and user() = Joe then do instead retrieve (salary = null)

Joe is not allowed to see the salary of employees in the shoe department.

define rule example_4 on retrieve to EMP salary where EMP dept = “shoe” and user() = Joe then do replace CURRENT (salary = null)

Page 9: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Example 8

• define rule example_8 on retrieve to TOY_EMP then do instead retrieve (EMP-OID = EMP-OID, EMP name, EMP age, EMP salary) where (EMP dept = “toy”)

This specifies a view - retrieving from the view TOY_EMP is mapped to the underlying base relation EMP.

Page 10: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

3. How does the rule system simulate view and procedure?

• Procedure definition in POSTGRESdefine [updated] procedure proc-name (type-1, , type-2) as postquel-commands

• Without parameters, it is a view definitiondefine [updated] view view-name as postquel-commands

Page 11: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Example

define [updated] view TOP_EMP as retrieve (EMP name, EMP age, EMP salary) where EMP dept = “toy”

The system construct the following rules in addition to example_8 to simulate the view

define rule TOP_EMP_d on delete to TOY_EMP then do instead delete EMP where EMP OID=CURRENT EMP_OID

define rule TOP_EMP_a on append to TOY_EMP then do instead append EMP (name=NEW name, age=NEW age, salary=NEW salary, dept=“toy”)

define rule TOP_EMP_r on replace to TOY_EMP then do instead replace EMP (name=NEW name, age=NEW age, salary=NEW salary, dept=“toy”) where EMP OID=CURRENT EMP_OID

Page 12: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Rule to support procedure data type

• on retrieve to rel-name column-name where rel-name OID=value then do instead execute proc-name(parameter-list)

Exampleappend to EMP (name=“Sam”, hobbies=foolbar(param-1, ,param-n))

Simulated byappend to EMP (name=“Sam”)define rule example_17 on retrieve to EMP hobbies where EMP OID=value then do instead execute foobar(param-1,,param-n)

Page 13: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

One general purpose rules system supports all the following concepts.

• Views

• special semantics for updating views

• materialized views

• partial views

• procedures

• special procedures

• caching of procedures

Page 14: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

4. Implementation and caching

• Implementation– tuple level

– query rewrite

• cachingthree cases

– (1) object: relation, event: no where clause

– (2) object: “relation-name field”, event : no where clause

– (3) there is a where clause

Page 15: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

Examples

• Consider example_8 and incoming queryretrieve (TOY_EMP salary) where TOY_EMP name=“Sam”

Rewrite the query toretrieve (EMP salary) where EMP name=“Sam” and EMP dept=“toy”

Page 16: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

5. Conclusions

• It is recommend that implementers concentrate on a single powerful rules system and then simulate all of the various concepts using the rules system.

• Semantics of CURRENT and NEW attributes is enforced by tuple level implementation, or removed by query rewriting.

Page 17: ON RULES, PROCEDURES, CACHING AND VIEWS IN DATA BASE SYSTEM by M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos UC Berkley Presented by Zhou Ji

conclusions

• Non-standard update semantics can be specified as additional updating rule, thereby substantially enhancing the power of views.

• POSTGRES procedures are merely an additional application of the rule system. Caching of rules naturally supports materialized views and cached procedures, thereby no extra mechanism are required to obtain this functionality.