HW02 (Cop6731)
HW02 (Cop6731)
Zno_FirstName_LastName_HW02.pdf
Zno_FirstName_LastName_HW02_spool.txt
Example)
Z00000001_KwangSoo_Yang_HW02.pdf
Z00000001_KwangSoo_Yang_HW02_spool.txt
The pdf file should contain all answers for both Question and Lab Parts.
Please do not use the zip file to upload the files. Upload two separate files.
After submitting the homework, please download it and see if the submission is correct.
Late submissions are not accepted after two days (i.e., Nov. 9 (Saturday)).
Late penalty
a) (4 points) Show the B+ tree that would result from inserting a data entry with key 26.
b) (4 points) Given the result of (a), show the B+ tree that would result from deleting a data
entry with key 56.
a) (3 points) Show the index that would result from inserting a data entry with key 16.
b) (3 points) Given the result of (a), show the index that would result from inserting a data entry
with key 21.
Use the “spool” command to create a log file for the output of SQL (e.g., SPOOL filename and SPOOL
OFF)
Note: Submit both answers and SPOOL files (i.e., an explanation and a SPOOL file).
Consider the following relational schema.
Query Evaluation
Use the Spool command to log the output of SQL (e.g., SPOOL filename and SPOOL OFF)
There are two files you should submit: 1) explanation for query execution plans and 2) recorded spool file.
1. (5 points) Execute the following two SQLs and explain which access method is used in each query. Explain
why one outperforms another.
SELECT /*+ GATHER_PLAN_STATISTICS */ count(G.id)
FROM guest G
WHERE G.id BETWEEN 1 AND 10;
2. (5 points) Execute the following two SQLs and explain which access method is used in each query. Explain
why one outperforms another.
SELECT /*+ GATHER_PLAN_STATISTICS */ count(H.id)
FROM hotel H
WHERE H.name LIKE '%pton Inn'
3. (5 points) Execute the following SQL. How many tables were accessed to produce the outcome, and how
many indexes were utilized in the process?
SELECT /*+ GATHER_PLAN_STATISTICS */ G.fname
FROM guest G, reserve R, hotel H
WHERE G.id = R.gid AND R.hid = H.id
AND G.id = 1047;
4. (10 points) Execute the following SQL and draw the query tree for the SQL. Describe what kinds of access
methods are used for each table. Explain which join method is used in each join operation.
SELECT /*+ GATHER_PLAN_STATISTICS */ H.name
FROM guest G, reserve R, hotel H, city C
WHERE G.id = R.gid AND R.hid = H.id AND H.cid = C.id
AND C.name ='Blowing Rock' AND G.fname ='Darryl' AND G.lname ='Getty';
5. (10 points) Execute the following SQL and draw the query tree for the SQL. Describe what kinds of access
methods are used for each table. Explain which join method is used in each join operation.
SELECT /*+ GATHER_PLAN_STATISTICS */ G.fname
FROM guest G, reserve R, room RM, hotel H, bill B
WHERE G.id = R.gid AND R.hid = RM.hid AND R.rno = RM.no AND RM.hid = H.id AND R.id = B.rid
AND H.name = 'Michiana Motel' AND B.payment_date='09-JUN-23' AND RM.no = 3;
Assume that each terminal represents each user (i.e., User1 and User2).
Create the student table using the following query.
CREATE TABLE customer ( id integer,
age integer,
primary key (id) );
Execute SET AUTOCOMMIT OFF. This command suppresses automatic committing so that you
must commit changes manually (Note that # represents the order of the SQL execution).
# User 1 User 2 User3
1 SET AUTOCOMMIT OFF
2 SET AUTOCOMMIT OFF
3 SET AUTOCOMMIT OFF
Save the spool files and submit both answers and spool files.
# User 1 User 2 User 3
1 SPOOL OFF
2 SPOOL OFF
3 SPOOL OFF
Transaction Processing and Recovery
1. (5 points) What is the result after STEP 8 and STEP10? Explain why this result makes sense or why it does
not make sense?
# User 1 User 2 User 3
1 DELETE FROM customer;
2 COMMIT;
INSERT INTO customer (id, age)
3
VALUES (1, 20);
UPDATE customer
4
SET age = age +10;
5 COMMIT;
UPDATE customer
6
SET age = age +10;
7 COMMIT;
SELECT id, age
8
FROM customer;
9 COMMIT;
SELECT id, age
10
FROM customer;
2. (5 points) What is the result of STEP 7? Explain why this result makes sense or why it does not make sense?
# User 1 User 2 User 3
DELETE FROM customer;
COMMIT;
INSERT INTO customer (id, age)
1
VALUES (1, 20);
INSERT INTO customer (id, age)
2
VALUES (2, 20);
3 COMMIT;
DELETE FROM customer
4
WHERE id = 1 OR id =2;
5 COMMIT;
6 COMMIT;
SELECT id, age
7
FROM customer;
3. (5 points) What happens after STEP 7 and STEP 8? What is the result of Step 9? Explain why this result
makes sense or why it does not make sense?
# User 1 User 2 User 3
1 DELETE FROM customer;
2 COMMIT;
INSERT INTO customer (id, age)
3
VALUES (1, 20);
UPDATE customer
4 SET age =30
WHERE id = 1;
INSERT INTO customer (id,age)
5
VALUES (2, 20);
INSERT INTO customer (id,age)
6
VALUES (1, 30);
INSERT INTO customer (id, age)
7
VALUES (2, 30);
INSERT INTO customer (id, age)
8
VALUES (2, 40);
9 COMMIT;
10 COMMIT;
11 COMMIT;