Compare commits
3
Commits
b011a30ab6
...
659352e992
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
659352e992 | ||
|
|
fde465354e | ||
|
|
5bd0da5970 |
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
import sys
|
||||
|
||||
# Use this file to write your queries. Submit this file in Gradescope after finishing your homework.
|
||||
|
||||
#TODO: Write your username and answer to each query as a string in the return statements in the functions below.
|
||||
# Do not change the function names.
|
||||
|
||||
#Make sure to test that python prints out the strings (your username and SQL queries) correctly.
|
||||
|
||||
#usage:python3 hw1.py
|
||||
# make sure the program prints out your SQL statements correctly. That means the autograder will read you SQL correctly.
|
||||
# Running the Python3 file will not execute your SQL statements (just prints them).
|
||||
|
||||
def username():
|
||||
return "srettig" # Write your username here
|
||||
|
||||
|
||||
def query1():
|
||||
return """
|
||||
|
||||
"""
|
||||
|
||||
def query2():
|
||||
return """
|
||||
|
||||
"""
|
||||
|
||||
def query3():
|
||||
return """
|
||||
|
||||
"""
|
||||
|
||||
def query4():
|
||||
return """
|
||||
|
||||
"""
|
||||
|
||||
#Do not edit below
|
||||
|
||||
def main():
|
||||
query_options = {1: query1(), 2: query2(), 3: query3(), 4: query4()}
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
if username() == "username":
|
||||
print("Make sure to change the username function to return your username.")
|
||||
return
|
||||
else:
|
||||
print(username())
|
||||
for query in query_options.values():
|
||||
print(query)
|
||||
elif len(sys.argv) == 2:
|
||||
if sys.argv[1] == "username":
|
||||
print(username())
|
||||
else:
|
||||
print(query_options[int(sys.argv[1])])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,4 +0,0 @@
|
||||
Claude Shannon? came up with theory of information. You are looking for information and knowledge
|
||||
|
||||
You want to integrate all the data. Some centralized warehouse. Utilities to access the data. Queries to let you get the data you care about.
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
# 1/9/24
|
||||
Claude Shannon? came up with theory of information. You are looking for information and knowledge
|
||||
|
||||
You want to integrate all the data. Some centralized warehouse. Utilities to access the data. Queries to let you get the data you care about.
|
||||
|
||||
# 1/11/24
|
||||
Additional DBMS functionality
|
||||
- Temporal database as well
|
||||
|
||||
@@ -109,7 +109,41 @@ public class BufMgr {
|
||||
*/
|
||||
public void pinPage(PageId pageno, Page page, boolean emptyPage)
|
||||
throws BufferPoolExceededException, DiskMgrException {
|
||||
// YOUR CODE HERE
|
||||
//Check if page already in memory
|
||||
if (pageMap.containsKey(pageno.pid)) {
|
||||
// page is already in memory
|
||||
Integer frameno = pageMap.get(pageno.pid);
|
||||
frmDescr[frameno].pinCount++;
|
||||
|
||||
if (frmDescr[frameno].pinCount == 1) {
|
||||
//the frame was marked previously removal, we need to undo that.
|
||||
fifo.remove(frameno);
|
||||
}
|
||||
page.setPage(bufPool[frameno]);
|
||||
} else {
|
||||
if (fifo.size() > 0) {
|
||||
// there is a page that can be removed
|
||||
Integer frameno = fifo.remove();
|
||||
if (frmDescr[frameno].pageno != -1) {
|
||||
// the frame is not empty
|
||||
PageId oldPage = new PageId(frmDescr[frameno].pageno);
|
||||
pageMap.remove(oldPage.pid);
|
||||
if (frmDescr[frameno].dirtyBit) {
|
||||
// the page has been written to, and needs to be written to disk
|
||||
Minibase.DiskManager.write_page(oldPage, bufPool[frameno]);
|
||||
}
|
||||
}
|
||||
// we now have an empty frame in frameno
|
||||
// we can grab the new page
|
||||
Minibase.DiskManager.read_page(pageno, bufPool[frameno]);
|
||||
page.setPage(bufPool[frameno]);
|
||||
pageMap.put(pageno.pid, frameno);
|
||||
resetFrameDescriptor(frameno, pageno.pid);
|
||||
frmDescr[frameno].pinCount++;
|
||||
} else {
|
||||
throw new BufferPoolExceededException("All pages in the buffer pool are pinned.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +163,24 @@ public class BufMgr {
|
||||
*/
|
||||
public void unpinPage(PageId pageno, boolean dirty)
|
||||
throws PageNotFoundException, PageUnpinnedException {
|
||||
// YOUR CODE HERE
|
||||
if (!pageMap.containsKey(pageno.pid)) {
|
||||
throw new PageNotFoundException("the page is not in memory");
|
||||
}
|
||||
Integer frameno = pageMap.get(pageno.pid);
|
||||
|
||||
if (frmDescr[frameno].pinCount > 0) {
|
||||
frmDescr[frameno].pinCount--;
|
||||
if (frmDescr[frameno].pinCount == 0) {
|
||||
//add to fifo
|
||||
fifo.add(frameno);
|
||||
}
|
||||
} else {
|
||||
throw new PageUnpinnedException("the page is already unpinned");
|
||||
}
|
||||
|
||||
if (dirty) {
|
||||
frmDescr[frameno].dirtyBit = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,8 +200,26 @@ public class BufMgr {
|
||||
* @throws BufferPoolExceededException if the new page cannot be pinned after the run is allocated due to the buffer being full. If this exception is thrown, the newly allocated pages should be deallocated
|
||||
*/
|
||||
public PageId newPage(Page firstpage, int howmany) throws DiskMgrException, BufferPoolExceededException {
|
||||
// YOUR CODE HERE
|
||||
return new PageId();
|
||||
PageId nPage = null;
|
||||
|
||||
try {
|
||||
nPage = Minibase.DiskManager.allocate_page(howmany);
|
||||
|
||||
pinPage(nPage, firstpage, false);
|
||||
return nPage;
|
||||
|
||||
} catch (BufferPoolExceededException bee) {
|
||||
try {
|
||||
if (nPage != null){
|
||||
Minibase.DiskManager.deallocate_page(nPage, howmany);
|
||||
}
|
||||
} catch (BufMgrException be) {
|
||||
throw new DiskMgrException("Exception in deallocating page.");
|
||||
}
|
||||
throw bee;
|
||||
} catch (BufMgrException be) {
|
||||
throw new DiskMgrException("Exception in allocating page.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +232,16 @@ public class BufMgr {
|
||||
* @throws DiskMgrException if there is an error in the DiskMgr layer. This is likely caused by incorrect implementations in other methods of the Buffer Manager
|
||||
*/
|
||||
public void freePage(PageId pageno) throws PagePinnedException, DiskMgrException {
|
||||
// YOUR CODE HERE
|
||||
if (pageMap.containsKey(pageno.pid)) {
|
||||
Integer frameno = pageMap.get(pageno.pid);
|
||||
if (frmDescr[frameno].pinCount > 0) {
|
||||
throw new PagePinnedException("The page is still pinned!");
|
||||
} else {
|
||||
pageMap.remove(pageno.pid);
|
||||
resetFrameDescriptor(frameno);
|
||||
// bufPool[frameno] = new Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,102 @@
|
||||
## Week 1
|
||||
#### Readings
|
||||
Chapters 1-3
|
||||
|
||||
#### Main Ideas
|
||||
Various types of data model, schema/subschema, data independence
|
||||
- Benefits of using a DBMS
|
||||
- Disk parameters
|
||||
|
||||
---
|
||||
## Week 2
|
||||
#### Readings
|
||||
Chapters 1-3
|
||||
Chapter 16
|
||||
|
||||
#### Main Ideas
|
||||
- Think about user, database, schema/catalog, DBMS software/utilities
|
||||
- Implementing query processing, recovery, privacy, concurrency software
|
||||
- Performance evaluation, how to implement ideas that can improve performance (Query optimization, I/O optimization, reducing I/Os by getting more data in one I/O operation for later use)
|
||||
- Relationship among data, hierarchical and network model vs relational model that deal with set of records
|
||||
- Types of queries for different models
|
||||
- Hierarchical model needs, commands such as *get next, get next within parent*
|
||||
- Network model goes from one entity to another via links and uses the command *find next*
|
||||
|
||||
---
|
||||
## Week 3
|
||||
#### Readings
|
||||
Chapter 16
|
||||
Some of Chapter 17
|
||||
|
||||
#### Main Ideas
|
||||
- Different types of storage and devices and their characteristics
|
||||
Fig 16.1, 16.2, Table 16.2 (pages 549-550)
|
||||
- Making data access more efficient on disk
|
||||
( 16.2.2)
|
||||
- Buffering of blocks, buffer management, buffer replacement policies
|
||||
- How to deal with fixed length and variable length records
|
||||
(16.4.2) figure 16.5
|
||||
- Spanned records, blocking factor, allocating file blocks on disk
|
||||
( 16.4.3)
|
||||
- File of ordered records
|
||||
(16.7)
|
||||
- How to deal with overflows
|
||||
( second paragraph on page 571, modifying values ( paragraph 3 on page 571)
|
||||
- Primary index
|
||||
Table 16.3
|
||||
- Hashing figure, Folding, Collisions, open addressing and chaining
|
||||
16.8 and page 574
|
||||
- Buckets and external hashing
|
||||
( 16.8.2)
|
||||
- Extendible hashing
|
||||
Figure 16.11 and Figure 16.12
|
||||
- Parallism, RAID, Stripping the data on multiple disks
|
||||
|
||||
Review Questions on page 593-595
|
||||
|
||||
---
|
||||
## Week 4
|
||||
#### Readings
|
||||
|
||||
---
|
||||
|
||||
## Week 5
|
||||
|
||||
---
|
||||
|
||||
## Week 6
|
||||
#### Readings
|
||||
Chapter 16
|
||||
- Page 552, 553, Section 16.2.2
|
||||
- Section 16.3
|
||||
- Pages 556, 557, 558, 559
|
||||
- Figure 16.5, 16.6, 16.7, 16.8, 16.9, 16.10, 16.11, 16.12 and related pages
|
||||
- RAID Tech in 16.10
|
||||
More on Chapter 17 later
|
||||
|
||||
---
|
||||
|
||||
## Midterm
|
||||
Chapters and Topics you must read and understand for midterm and will also be included in preparing for final exam.
|
||||
|
||||
Chapter 1 all topics pages 3-28
|
||||
|
||||
Chapter 2 all topics pages 31-55. You must know DBMS component modules on page 43, database system utilities on page 45, classification of database management systems in section 2.6. Section 2.5 is too general but hard to make any questions but please read to learn about various architectures and how DBMS, OS, and hardware and communication are layered.
|
||||
|
||||
Chapter 3 pages 59-68. main phases of database design, different types of attributes for an entity. You do not need to worry about ER diagram and on page 64.
|
||||
|
||||
Chapter 5 all topics pages 149-170
|
||||
|
||||
Chapter 6 all topics pages 177-201, how to covert English to SQL query and vice versa
|
||||
|
||||
Chapter 7 all topics pages 207-221. There exist and for all semantics. Aggregate functions and grouping. Queries in exam will not be very complicated but a good understanding of SQL features is needed.
|
||||
|
||||
Chapter 8 all topics about relational algebra on pages 239-259, query trees and optimization by rearranging operators (move join at higher level in tree to do them at the end). Outer joins, left outer join, right outer join. Some familiarity with relational calculus. s in section 8.6.1, page 269. Converting a relational algebra to SQL or relational calculus as section 8.6.4 ( briefly). Safe expression 8.6.8 on page 276. What is domain calculus and its advantages.
|
||||
|
||||
Chapter 16 all topics pages 541-588. Disk storage and parameters ( also see appendix B on page 1167-1169, buffer management and replacement, fixed length, variable length records, hashing on pages 572-581, Parallel disks RAID (briefly), questions such as 16.34-16.37 and in assignment
|
||||
|
||||
Chapter 17 various types of indexes, example 1 and 2 on page 605-606, multi-level indexes in section 17.2 on page 613, example 4 on page 614, general knowledge of B-Trees and B+ Trees, partitioned hashing and grid files ( pages 632-633) and bitmap indexes on page 634-635, tuning indexes page 640, section 17.7 physical database design and factors that influence it on page 643-646 ( easy to read but very useful
|
||||
|
||||
|
||||
Maybe soon if he can cover it
|
||||
Chapter 14 pages 459-461, informal design guidelines section 14.1 on page 461, insertion, deletion, modification anomalies, section 14.1.5 and functional dependencies and eventually normalization (first, second, third normal form of relations). Plan to cover them soon up to page 487
|
||||
Reference in New Issue
Block a user