01intro · 3 Computer Architecture OS DBMS App App App App Computer Architecture: a set of...

Post on 16-Aug-2020

1 views 0 download

transcript

7/2/18

1

1

2

IBM 350 hard disk getting loaded into a PanAm airplane in 1956.(3.75 Mbytes, available for rent @ $3,200/month)

3

Modern Interesting Stuff About Databases

§ It used to be about (kind of boring stuff): em ployee records, bank records, etc.

§ Today, the fie ld covers a ll the largest sources of data, w ith m any new ideas.o Web search.o Data mining.o Scientific and medical databases.o Integrating information.

7/2/18

2

4

More Interesting Stuff

§ Database program m ing centers around lim ited program m ing languages.o Only area where non-Turing-complete

languages make sense.o Leads to very succinct programming, but

also to unique query optimization problems.

5

Still More …

§ You m ay not notice it, but databases are behind alm ost everyth ing you do on the W eb.o Google searches.o Amazon, eBay, etc.

6

And More…

§ Databases often have unique concurrency contro l prob lem so Many activities (transactions) at the

database at all times.o Must not confuse actions, e.g., two

withdrawals from the same account must each debit the account.

§ Recovery?

7/2/18

3

Computer Architecture

OS

DBMS

App App

App

App

Computer Architecture:◆ a set of disciplines

that describes a computer system by specifying its parts and their relations.

M ainm em oryI/O

bridgeBus in terface

ALU

R egister file

C PU

System bus M em ory bus

D isk contro ller

G raphicsadapter

U SBcontro ller

M ouse Keyboard D isp lay

D isk

I/O bus Expansion slo ts forother devices such

as netw ork adapters

hello executable stored on d isk

PC

Computer Architecture

OS

DBMS

App App

App

App

OS is a software that:◆manages computer

hardware and software resources;

◆ provides common services for computer programs.

7/2/18

4

Computer Architecture

OS

DBMS

App App

App

AppWhat DBMS offers:◆ Data Independences◗ Physical and Logical

◆ Integrity & Security◆ Concurrency and

Transaction◆ Recovery◆ Easy query and

programming with SQL

DBMS System Architecture –A collective efforts of the DB community for over 30 years!

7/2/18

5

What Is a DBMS?§ A very large, integrated co llection of

data.§ Models real-world enterprise.

o Entities (e.g., students, courses)o Relationships (e.g., Madonna is taking

CS564)§ A Database Managem ent System

(DBMS) is a software package designed to store and m anage databases.

Why Use a DBMS?

§ Data independence and effic ient access.§ Reduced application developm ent tim e.

§ Data integrity and security.§ Uniform data adm in istration.§ Concurrent access, recovery from

crashes.

15

What is a Data Model?

1. Mathem atical representation of data.o Examples: relational model = tables;

semistructured model = trees/graphs.

2. Operations on data.3. Constra ints.

7/2/18

6

16

A Relation is a Table

nam e m anf

W interbrew Pete ’sBud Lite Anheuser-Busch

Beers

Attributes(columnheaders)

Tuples(rows)

Relationname

Edgar F. Codd’s Definition

17

E.F. Codd. A Relational Model of Data for Large Shared Data Banks. Communications of the ACM. 13(6), 377-387, June 1970

Relational Model§ Data Collectors:

o SETo LISTo BAG (Multi-Set)

§ Attribute: ATOMIC value.§ Tuple: a LIST of attribute values.§ Relation: a SET of tup les.

18

7/2/18

7

19

Schemas

§ Relation schem a = re lation nam e and attribute list.o Optionally: types of attributes.o Example: Beers(name, manf) or

Beers(name: string, manf: string)§ Database = collection of re lations.§ Database schem a = set of a ll re lation

schem as in the database.

20

Why Relations?

§ Very sim ple m odel.§ Often m atches how we th ink about

data.§ Abstract m odel that underlies SQL, the

m ost im portant database language today.

21

Our Running Example

Beers(name, manf)Bars(name, addr, license)Drinkers(name, addr, phone)Likes(drinker, beer)Sells(bar, beer, price)Frequents(drinker, bar)

§ Underline = key (tup les cannot have the sam e value in a ll key attributes).o Excellent example of a constraint.

7/2/18

8

22

Database Schemas in SQL

§ SQL is prim arily a query language, for getting inform ation from a database.

§ But SQL also includes a data-defin itioncom ponent for describ ing database schem as.

23

Creating (Declaring) a Relation

§ Sim plest form is:CREATE TABLE <nam e> (

< list of e lem ents>);

§ To delete a re lation:DROP TABLE <nam e>;

24

Elements of Table Declarations

§ Most basic e lem ent: an attribute and its type.

§ The m ost com m on types are:

o INT or INTEGER (synonyms).o REAL or FLOAT (synonyms).

o CHAR(n ) = fixed-length string of ncharacters.

o VARCHAR(n ) = variable-length string of up to n characters.

7/2/18

9

25

Example: Create Table

CREATE TABLE Sells (

bar CHAR(20),beer VARCHAR(20),

price REAL

);

26

SQL Values

§ Integers and reals are represented as you would expect.

§ Strings are too, except they require sing le quotes.o Two single quotes = real quote, e.g., ’Joe’’s Bar’.

§ Any value can be NULL.

27

Dates and Times

§ DATE and TIME are types in SQL.§ The form of a date value is:

DATE ’yyyy-m m -dd’o Example: DATE ’2007-09-30’ for Sept.

30, 2007.

7/2/18

10

28

Times as Values

§ The form of a tim e value is:

TIME ’hh:m m :ss’w ith an optional decim al point and

fractions of a second fo llow ing.o Example: TIME ’15:30:02.5’ = two

and a half seconds after 3:30PM.

29

Declaring Keys

§ An attribute or list of attributes m ay be declared PRIMARY KEY or UNIQUE.

§ Either says that no two tup les of the re lation m ay agree in a ll the attribute(s) on the list.

§ There are a few d istinctions to be m entioned later.

30

Declaring Single-Attribute Keys

§ Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute.

§ Exam ple:CREATE TABLE Beers (

name CHAR(20) UNIQUE,

manf CHAR(20)

);

7/2/18

11

31

Declaring Multiattribute Keys

§ A key declaration can also be another e lem ent in the list of e lem ents of a CREATE TABLE statem ent.

§ This form is essentia l if the key consists of m ore than one attribute.o May be used even for one-attribute keys.

32

Example: Multiattribute Key

§ The bar and beer together are the key for Sells:CREATE TABLE Sells (

bar CHAR(20),beer VARCHAR(20),

price REAL,PRIMARY KEY (bar, beer)

);

33

PRIMARY KEY vs. UNIQUE

1. There can be on ly one PRIMARY KEY for a re lation, but several UNIQUE attributes.

2. No attribute of a PRIMARY KEY can ever be NULL in any tup le. But attributes declared UNIQUE m ay have NULL’s, and there m ay be several tup les w ith NULL.

7/2/18

12

34

Semistructured Data

§ Another data m odel, based on trees.§ Motivation: flexib le representation of

data.§ Motivation: sharing of docum ents

am ong system s and databases.

35

Graphs of Semistructured Data

§ Nodes = objects.§ Labels on arcs (like attribute nam es).

§ Atom ic values at leaf nodes (nodes w ith no arcs out).

§ Flexib ility: no restriction on:o Labels out of a node.o Number of successors with a given label.

36

Example: Data Graph

BudA.B.

Gold1995

MapleJoe’s

M’lob

beer beerbarmanfmanf

servedAt

name

name name

addr

prize

year award

root

The bar objectfor Joe’s Bar

The beer objectfor Bud

Notice anew kindof data.

7/2/18

13

Summary§ DBMS used to m aintain, query large datasets.§ Benefits include recovery from system crashes,

concurrent access, qu ick application developm ent, data integrity and security.

§ Levels of abstraction g ive data independence.§ A DBMS typ ically has a layered arch itecture.§ DBAs hold responsib le jobs

and are well-paid!§ DBMS R&D is one of the broadest,

m ost exciting areas in CS.