Sie sind auf Seite 1von 12

Implementation of Database Exercise 1

Tanmaya Mahapatra Matriculation Number : 340959 tanmaya.mahapatra@rwth-aachen.de Bharath Rangaraj Matriculation Number : 340909 bharath.rangaraj@rwth-aachen.de Manasi Jayapal Matriculation Number : 340892 manasi.jayapal@rwth-aachen.de October 28, 2013

1
1.1

Exercise 1.1 : Database Architecture


Name each of the ve layers in the database architecture specied in the lecture, explain the concepts handled in each layer, and the interfaces between layers.

The ve layers in the Database Architecture are : Logical Data Structures Logical Access Paths/Structures Storage Structures Propagation Control/Page Assignment File Services/Memory Assignment Structures The important concepts handled in each layer together with the interfaces between each layer is shown in the Table 1

1.1 Name each of the ve layers in the database architecture specied in the lecture, explain the concepts handled in each layer, and the interfaces between layers.

Table 1: Concepts & Interfaces in Different Layers of Database. Layer Name Logical Data Structure Concepts Handled Roles Played Prepares Query Execution Plan : Translates & Optimize Queries. Addressing Units Tables Views Tuples Auxiliary Structures External Schema Description Addressing Units External Records Sets Keys Access Paths Continued on next page Interface Between Layers Interface Users interact using a Set-oriented Interface (SQL)

EXERCISE 1.1 : DATABASE ARCHITECTURE 2

1.1 Name each of the ve layers in the database architecture specied in the lecture, explain the concepts handled in each layer, and the interfaces between layers.

Layer Name Logical Access Paths/Structures

Table 1 continued from previous page Concepts Handled Interface Between Layers Roles Played Interface Manage Cursor Sort Components Manages Dictionary The Higher Layer interacts using a Record Oriented DB Interface

EXERCISE 1.1 : DATABASE ARCHITECTURE

Storage Structures

Roles Played Manage Records & Index Consists of Auxiliary structures like Page Indexes. Consists of Addressing Units like Pages & Segments

Interface Internal Record Interface (Stores Records in B* Trees)

Continued on next page

1.1 Name each of the ve layers in the database architecture specied in the lecture, explain the concepts handled in each layer, and the interfaces between layers.

Layer Name Propagation Control/Page Assignment

Table 1 continued from previous page Concepts Handled Interface Between Layers Roles Played Interface Manages Buer & Segments Consists of Auxiliary structures like Page Tables, Block Tables etc. Consists of Addressing Units like Blocks & Files. Continued on next page DB Buer Interface

EXERCISE 1.1 : DATABASE ARCHITECTURE 4

1.1 Name each of the ve layers in the database architecture specied in the lecture, explain the concepts handled in each layer, and the interfaces between layers.

Layer Name File Services/Memory Assignment Structures

Table 1 continued from previous page Concepts Handled Interface Between Layers Roles Played Interface Manages Files & External Memory. Consists of Addressing Units like tracks, cylinders & channels. Consists of Auxiliary structures like File Catalogues, Free-Placement etc. Memory Assignment Structures File Interface (Manages read/write Block)

EXERCISE 1.1 : DATABASE ARCHITECTURE 5

EXERCISE 1.1 : DATABASE ARCHITECTURE

1.2
.

The following tasks belong to dierent layers, sort them so that they match the architecture top-down

1. Buering 2. Logical Relation and Cursor Management 3. Media Access 4. Access Path Management 5. View Formulation and Management Solution 1. Buering = Propagation Control/Page Assignment 2. Logical Relation and Cursor Management = Logical Access Paths/Structures 3. Media Access = File Services/Memory Assignment Structures 4. Access Path Management = Storage Structures 5. View Formulation and Management = Logical Data Structures Tasks sorted so that they match the architecture (top-down) 1. View Formulation and Management 2. Logical Relation and Cursor Management 3. Access Path Management 4. Buering 5. Media Access

1.3

What does data independence mean ? Why is it an important feature of database systems ? Give examples for how data independence is achieved in the ve-layered architecture!

Data Independence Data Independence means application programs are insulated from changes in the way the data is structured and stored. Data independence is achieved through use of the three levels of data abstraction; in particular, the conceptual schema and the external schema provide distinct benets in this area. There are 2 types of Data Independence : 1.2 The following tasks belong to dierent layers, sort them so that they match the architecture top-down

EXERCISE 1.1 : DATABASE ARCHITECTURE

Logical Data Independence The ability to change the logical schema without changing the external schema is called as Logical Data Independence. Physical Data Independence The ability to change the physical schema without changing the logical schema is called as Physical Data Independence. Important Feature Data Independence is regarded as an important feature of Database Systems because : It facilitates improvement of various layers and changes to various layers without aecting/impacting other layers. Applications are insulated from how data are structured and stored. It provides protection from changes in logical structure of Data. It provides protection from changes in physical structure of Data. Examples 1. Data independence is achieved by abstracting each higher level to its lower lever that is layer i+1 is the abstraction of layer i and data representation is unique to each layer and the data of each layer is hidden from the other layers. 2. The layers communicate by invoking the abstract methods and while communication the data must be converted to the layer specic form since each layer consists of unique data representation and data representation of each layer is hidden from other layers. Layers Logical Data Structures Logical access path Abstraction Provided Position indicator and explicit relations in the table. Number and kind of physical access paths and internal representation of tables. Management of Buers and Logging. File Maping and Indirect Page Assignment. Technical features and technical details of external media.

Storage Structures Page Assignment Structures Memory Assignment Structures

1.3 What does data independence mean ? Why is it an important feature of database systems ? Give examples for how data independence is achieved in the ve-layered architecture!

EXERCISE 1.1 : DATABASE ARCHITECTURE

Scenario To understand how Data Independence is achieved in the 5 layer model we consider a scenario in which a user/program wants some specic information about a particular Book and Author. 1. The User interacts with the top most layer of the DB (L5) with the help of a SQL. The user has no idea of where the data or how the data is actually stored. SELECT B.Title A.Author from Books B, Author A where B.aid = A.aid; 2. It prepares a Query Execution plan and the operations of it are directly invoked at L4 Interface. 3. The L4 layer plans a sort/merge join for the query evaluation. Sorted objects have to be created explicitly in L4, before the join can be processed. 4. The Index-scans, which deliver the records to be sorted, fetch them via physical access paths and storage structures managed by L3. 5. L3 oers a variety of storage structures which physically embody the indexes or other types of access paths. 6. The functionality provided by L3 needs to refer to the physical Data of DB. The DB Buer acts as an interface to the DB on external devices and provides access to pages based on logical page references. 7. L1 encapsulates number, type and location of external devices. It together with the OS le Management process actually fetches the Data stored somewhere on the storage Disk. The dierent levels perform dierent operations without actually knowing what other layers are actually doing. The user submitting the query does not know that the simple SQL is broken into QEP and other complicated stu nally leading to very low level data access mechanism. This demonstrates Data Independence in the 5 layered Database Model. The addition or removal of new entities, attributes or relationships to the conceptual schema should be possible without having to change existing external schemas or having to rewrite existing application programs. A change to the internal schema such as using a dierent le organizations or storage structures, storage devices or indexing strategy should be possible without having to change the conceptual or external schema

1.3 What does data independence mean ? Why is it an important feature of database systems ? Give examples for how data independence is achieved in the ve-layered architecture!

EXERCISE 1.2 : QUERY LANGUAGES

Exercise 1.2 : Query Languages


lives(pname,city,street) which contains for every person the location(s) he lives, works(pname,cname,salary) which contains for every person the name of the company that the person works for, as well as his salary, located(cname,city) which contains the locations for every company (i.e. a company can be located in more than one city), boss(pname,mname), which contains the persons that are supervised by a manager.

The following relations are given:

Formulate the following queries as expressions in relational algebra, tuple relational calculus,domain relational calculus and SQL:

2.1

Find the names of all persons who are working in the same company as their boss and get in this company a higher salary than their boss.
Relational Algebra

2.1.1

2.1.2

Tuple Relational Calculus

{w.pname | works(w) (b) (boss(b) b.pname = w.pname w.salary < {w.salary | work (w) (b) (boss(b) b.mname = w.pname} w.cname = {w.cname | works(w) (b) (boss(b)) b.mname = w.pname}} 2.1.3 Domain Relational Calculus

{pname|(cname)(salary )(name1)(name2)(< pname, cname, salary > works < name1, name2 > boss pname = name1 salary < {salary |(cname)(pname)(name1)(name2)(< pname, cname, salary > works < name1, name2 > boss name2 = pname)} cname = {cname |(pname)(salary )(name1)(name2)(< pname, cname, salary > works < name1, name2 > boss name2 = pname)})}

EXERCISE 1.2 : QUERY LANGUAGES SQL

10

2.1.4

1 SELECT PNAME F R O M (BOSS N A T U R A L JOIN WORKS J ) W H E R E 3 SALARY > (SELECT M A X(SALARY) F R O M WORKS W W H E R E PNAME = MNAME and J .CNAME = W.CNAME) A N D 5 CNAME IN (SELECT CNAME F R O M WORKS W H E R E PNAME = MNAME) ; 7 / ANOTHER METHOD / 9 SELECT EPNAME F R O M WORKS W INNER JOIN 11 (SELECT PNAME AS EPNAME, CNAME AS ECNAME, SALARY AS ESALARY, MNAME as EMNAME F R O M WORKS N A T U R A L JOIN BOSS) ON W.PNAME = EMNAME A N D W.CNAME = ECNAME A N D W.SALARY <ESALARY;

Listing 1: SQL Query for nding the names of persons who are working in the same company as their Boss & earn more salary than Boss

2.2
2.2.1

Find the names of all persons, who work for at least two dierent companies (2)
Relational Algebra

1. Taking the Cartesian Product of works table and storing the result into a table called Companies and renaming the elds to avoid duplication : (companies(1 pname1,2 cname1,3 salary1,4 pname2,5 cname2,6 salary2),works works)) 2. Persons working for at least 2 dierent companies: pname1((pname1=pname2)(cname1=cname2) (companies))

2.2.2

Tuple Relational Calculus

{w.pname | works(w) {COU N T (x.pname) | works(x)} 2} 2.2.3 Domain Relational Calculus

{< pname > |( cname)( salary )(< pname, cname, salary > works {COU N T (pname) | ( cname)( salary )(< pname, cname, salary > works)} 2)} 2.2.4 SQL

2.2 Find the names of all persons, who work for at least two dierent companies (2)

EXERCISE 1.2 : QUERY LANGUAGES

11

SELECT T .PNAME F R O M WORKS T G R O U P BY T .PNAME HAVING C O U N T(T .PNAME) >=2;

Listing 2: SQL Query for nding names of all person working for at least 2 companies

2.3

Find the names of the persons with the highest salary (Note: There might be several persons with the same salary).
Relational Algebra

2.3.1

1. Find all the salaries less than the others : ( (worksd (works)) )
works.salary
works.salary<d.salary

2. Find the largest salary: salary(works)works.salary (works.salary<d.salary (works)d (works))

2.3.2

Tuple Relational Calculus

{w.pname | works(w) w.salary = {M AX (x.salary ) | works(x)}} 2.3.3 Domain Relational Calculus

{pname | ( cname)( salary )(< pname, cname, salary > works salary {M AX (salary ) | ( pname) ( cname) ( < pname, cname, salary > works)})} 2.3.4
1 3

SQL

SELECT PNAME F R O M WORKS W W H E R E (W.SALARY IN (SELECT M A X(SALARY) F R O M WORKS) ) ;

Listing 3: SQL Query for nding the names of the persons with the highest salary.

2.3 Find the names of the persons with the highest salary (Note: There might be several persons with the same salary).

EXERCISE 1.2 : QUERY LANGUAGES

12

2.4
2.4.1

Find the names of all companies that are located in cities in which IBM is not located.
Relational Algebra

1. Choose the city corresponding to the city in which IBM is located : cname= IBM (located) 2. Select the companies located in cities where IBM is not located: cname(cname,city cname= IBM (located))

2.4.2

Tuple Relational Calculus

{l.name | located(l) l.city = {l.city | located(l) l.cname = IBM }} 2.4.3 Domain Relational Calculus

{cname |( city )( < cname, city > located city = {city | ( cname) ( < cname, city > located cname = IBM ) })} 2.4.4 SQL

1 SELECT CNAME F R O M LOCATED L W H E R E L . CITY NOT IN (SELECT CITY F R O M LOCATED W H E R E CNAME = IBM ) ; 3 / The Below Query i s Case I n s e n s i t i v e / 5 SELECT CNAME F R O M LOCATED L 7 W H E R E (L O W E R(TRIM(L . CITY) ) NOT IN 9 (SELECT L O W E R(TRIM(CITY) ) F R O M LOCATED W H E R EL O W E R(TRIM( CNAME) ) = L O W E R(TRIM( IBM ) ) ) ) ;

Listing 4: SQL Query for nding the names of all companies that are located in cities in which IBM is not located.

2.4 Find the names of all companies that are located in cities in which IBM is not located.

Das könnte Ihnen auch gefallen