Академический Документы
Профессиональный Документы
Культура Документы
An Introduction to Databases
Outline: Databases
Lecture 6 -- Page 1
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
What is a Database
organizing data
company
compname sales assets netincome empls indcode yr
...
42 pharmaceuticals
44 computers
...
4
Lecture 6 -- Page 2
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
Information is in tables
Also called (base) relations
Lecture 6 -- Page 3
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
SELECT *
FROM company;
Lecture 6 -- Page 4
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
Choose Columns
allied -279000 85
boeing 292000 82
...
Choose Rows
FROM company
10
Lecture 6 -- Page 5
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
Compute Columns
(netincome/assets) AS roa
FROM company;
11
Sorting
FROM company
WHERE yr = 84
12
Lecture 6 -- Page 6
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
Aggregates
Sum(sales) AS totalsales
FROM company
14
Lecture 6 -- Page 7
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
More examples
FROM company
GROUP BY yr;
15
Joins
Combine rows from one table with rows
from another
Usually join on some common column
Don't combine rows unless their value in the
common column is the same
Where clause says the common column must be
same in each table
16
Lecture 6 -- Page 8
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
company
compname sales assets netincome empls indcode yr
...
42 pharmaceuticals
44 computers
...
17
Database Representations
Requirements:
Minimize disk space taken by database
Enable fast retrieval of records with desired properties
Main ideas:
Store tables as sequential files
- within each table records can be stored in any order
Augment those tables with indexes to accelerate
retrieval
18
Lecture 6 -- Page 9
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
Indexes
Like a book index, it says where to find things
Indexes can make queries run faster
To understand indexes we have to break the
abstraction barrier
How are tables stored?
- Assume they are stored sequentially, one row after the other
- Each row takes a fixed number of bytes of storage
How are queries processed?
19
Example
SELECT *
FROM company
Lecture 6 -- Page 10
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
Index on indcode
37-41 42 43-45
22
Lecture 6 -- Page 11
Chrysanthos Dellarocas.
Lecture notes for 15.564: Information Technology I
More on Trees
That was a trinary tree
Each node had three children
Three is called the breadth
DBMS
representation
- Creates/Modifies tables
- Inserts/Deletes data
- Runs queries
- ...
24
Lecture 6 -- Page 12
Chrysanthos Dellarocas.