• No results found

VIEWS virtual relation data duplication consistency problems

N/A
N/A
Protected

Academic year: 2021

Share "VIEWS virtual relation data duplication consistency problems"

Copied!
14
0
0

Loading.... (view fulltext now)

Full text

(1)

VIEWS

• A virtual relation that is defined from other

pre-existing relations Called the “defining

relations” of the view

• A view supports multiple user perspectives on

the database corresponding to different

information organizations, avoiding the need for

data duplication or information consistency

problems

• Additional motivation: security (privacy concerns,

users need only access/modify selected

attributes in the data

without being able to

access the other attributes

)

(2)

Differences between a Conceptual

Database and a View

• Employee

• Salary

• Age

• Employee

• Department

• Salary

• Birth date

VIEW CONCEPTUAL DATABASE

Constructable, but not actually present in the database

(3)

EXAMPLE: Airline Databases

External/USER Conceptual Physical

Reservation Department Dispatcher Personnel Dept. • Passengers • Flights • Aircraft • Crews Files, Records Bits

Low level of Abstraction High level of Abstraction

(4)

DATA INDEPENDENCE

Logical Data Independence

– Many modifications of

conceptual scheme can be made without affecting views – No Changes in application

programs necessary

Physical Data Independence – Physical schema can be

changed without alerting the conceptual level

– Allows for tuning Physical Database View1 View2 Viewn Conceptual Database

(5)

Analogy from the programming

language world

View level Function f(i) f(i)=∑m j=1A(i,j) Concept Level Integer Array A[1..n,1..m] Physical Level 9 3 2 3 2 2 5 1 6 1 2 .. n 1 2 .. m 1 2 .. m 1 2 .. m

(6)

VIEW DEFINITIONS

Views are defined by a query that generates

the desired virtual relation from existing

relations:

In Relational Algebra:

Create view DEPHEADS As

DNAME,DNUMBERS,FNAME,LNAME

(EMPLOYEE MGRSSN=SSN DEPARTMENT)

Views typically include selected projections with optional selects and joins

DEPHEADS DNAME DNO FNAME LNAME

Pebody 5 Robin Wang Admin 4 Jenifer Veallau CS 1 James Borg

(7)

VIEWS IN SQL

CREATE VIEW DEPHEADS AS

SELECT DNAME,DNUMBER,FNAME,LNAME FROM DEPARTMENT,EMPLOYEE

WHERE DEPARTMENT.MGRSSN=EMPLOYEE.SSN

The SQL statement defining view are typically executed at query time, thus additions/changes in the defining/base relations are reflected in the virtual relation (view)

transparently.

Allow Query a views:

SELECT FNAME,LNAME FROM DEPHEADS

WHERE DNUMBER=5

The information is a virtual relation is always “up to date” (automatically reflect database update) Defining SQL Query Attribute in view relation Defining relation

(8)

Complex Views

•Views may include complex calculations

CREATE VIEW EMP_AGE(LNAME,AGE) AS

SELECT LNAME,MONTHS-BETWEEN(SYSDATE,BDATE)/12 FROM EMPLOYEE LNAME AGE SMITH WANG ZELAYA 40.86 50.91 38.12

•Views creation/definition may contain aggregate operation

CREATE VIEW DEPT-INFO(DEPT_NAME,NUM_EMPS,TOTAL_SAL) AS

SELECT DNAME,COUNT(*),SUM(SALARY) FROM DEPARTMENT, EMPLOYEE

WHERE DNUMBER=DNO GROUP BY DNAME; DEPT_NAME NUM EMPLOYER TOTAL SALARY RESEACHER ADMIN HEADQUATER 4 3 1 135,000 93,000 35,000 Remaining attributes Built op. See Chapter 7

(9)

Syntax:

UPDATE <VIEW-NAME>

SET <LIST OF CHAGES TO VIEW ATTRIBUTES> WHERE <condition based on view attributes>

mapped to necessary updates in the defining relation

OK if simple name change

Changes to the database via views

UPDATE DEPHEAD

SET DNAME = ‘research’

WHERE LNAME = ‘Wallace’ OR LNAME = ‘SMITH’

Rename all departments manager by

(10)

…… 6 SALES 201 98316738 4 ADMIN 401 33344455 5 RESEARCH MGRSSN DNO DNAME

PROBLEMS WITH VIEWS

Fields null result. Join fail because null join attribute

SELECT EMPLOYEE.LNAME FROM DEPARTMENT,EMPLOYEE WHERE MGRSSN=SSN AND DNAME=‘SALES’ ANOMOLY SELECT LNAME FROM DEPHEADS WHERE DNAME=‘SALES’

Null values in the fields projected out of the defining relations by the view.

Insert into DEPHEADS

Values(‘SALES”,6,’John’,’Wilson’)

Insert into a view based on a join

…… LOC

DEPARTMENT EMPLOYEE

FNAME LNAME SSN BDATE ADDRES SAL

John James John Smith Bary Wilson 419324 123123 --- 11,July 10 Nov --- 223333 111222 ---- 30000 55000 ----

(11)

Additional Problem with views

UPDATE DEPT_INFO

SET TOTAL_SAL = 100000 WHERE DNAME = ‘RESEARCH’

Problem when view attribute is defined as an aggregate quantity

how can the constraint

sum(salary)=100000

be realized as an update on the individual salary attributes for dept with > 1 employee

(12)

In general, updates are only allows when there is only one

possible update in the base relation to accomplish the view

update.

1). A view with a single defining table is updatable, if

a) The view attribute contain the primary key and all other “not null” attributes.

(still problem of nulls in the defining relations)

2). Views defines using

--- joins

--- grouping

---aggregate functions

generally not updatable

⇒ But generally no restrictions on read-only views

RESTRICTIONS ON VIEWS

(13)

Strategy #1: QUERY MAPPING

Convert query on view to query on base relation Problem: may be inefficient if the view involves

complex calculation like aggregate function.

Strategy #2: VIEW MATERIALIZATION

Create temporary table to reflect the view structure --- efficient if many queries to few updates Temporary table must be updated (recomputed) if updates to the defining relations

--- full recomputation costly

--- minimal update difficult to determine --- goal of avoiding data duplication

View Implementation Issue

(14)

Strategy #1: QUERY MAPPING

Convert query on view to query on base relation Problem: may be inefficient if the view involves

complex calculation like aggregate function.

Strategy #2: VIEW MATERIALIZATION

Create temporary table to reflect the view structure --- efficient if many queries to few updates Temporary table must be updated (recomputed) if updates to the defining relations

--- full recomputation costly

--- minimal update difficult to determine

--- fail to avoid relational count of eliminating data duplication

View Implementation Issue

Oracle approach

(Runtime macro)

References

Related documents

The Holocene records for the prairie vole are from a scattering of sites in the north, east, southwest, and east-central parts of the state, but that leaves large

Key developments in value-added agricultural production and marketing (differentiation based on locality, authenticity and protection of geographical origin; food tourism

To assess the effects of nonlinearity on the evolution of optimal disturbances, their streamwise evolution in linear ( ǫ = 0. 1}, set of param- eters were used as inlet condition

IMPORTANT NOTE - Following the OTC submission to the OPA A Connection Cost Estimate (CCE) document will be sent by email from the Generation Planning Section, once a positive offer

The first stage is a literature review investigation of current practices and previous research in the areas of the global construction industry and UK construction;

The BSN Visa Debit Card/-i is the first multi-privilege Visa payWave debit card issued in Malaysia and is linked to your BSN savings account. The card offers a host of benefits

In fact, BG prevalence varies widely across markets, and recent research shows that group affiliation remains common even in some highly-developed economies

As well as predicting that employment is insensitive to relative wages, the technological theory presented here is also consistent with a range of stylized facts about the labour