Assignment # 2Preliminaries
Important Points
· Evidence of academic misconduct (e.g., plagiarism, collaboration/collusion among students) will be taken seriously and University regulations strictly followed.
· You are expected to produce a word-processed answer to this assignment. Please use Arial font and a font size of 12. For SQL code and output, you can use courier new, which preserves SQL format and layout.
· You are required to use the Harvard Style of referencing and citation. The “Cite them right” guide is recommended for referencing and citation (Pears and Shields, 2008) which should be followed throughout your answer especially Part 3.
· Late submissions will be given zero marks unless prior permission is gained from the school office/programme leader.
Module Learning Outcomes (MLOs) assessed:
Knowledge & Understanding:
2. Key concepts of data warehousing.
Intellectual / Professional skills & abilities:
3. Conceptual data modelling, relational database design and implementation in SQL & PL/SQL, and object-based databases.
4. Design and Implementation of a data warehouse using Oracle database system.
Tasks of the Assignment
Part 1 (50 marks) Scenario: Mechanical Production Factories (MPF) Database System
MPF is a company that produces customised mechanical products within Europe. The company produces a rang of mechanical products at several factories. Information about which work force are assigned to which production orders and kept in the force usage register.
In order to access information quickly and to ensure that all past records are available for audit purposes, the company developed a database. Figure 1 shows a UML class diagram, which provides a conceptual model of the database. Relational Design for MPF Database System
A conceptual model of a database may be implemented using any database system (e.g. relational, object-relational, object-oriented). However, to start with, we have mapped the MPF’s conceptual model onto a relational logical model. Figure 2 details the relations for an implementation of the database using a relational database system. Note that Figure 2 uses shorthand / abbreviated notation for data types / domains for describing various attributes of the relations involved in the database.
Figure 1: UML Class Diagram for the MPF Database
Domains/Data Types: ID = Number(6) LTXT = Varchar(50)
STXT = Varchar(30) DEC = Number(8, 2) INT = Number(6)
Factory (FactoryId: ID, Location: LTXT, Country: LTXT)
Product (ProdId: ID, Description: LTXT, CostPerItem: DEC, LabCostPerItem: DEC)
FactoryProduct (FactoryId: ID *: ID, ProdId*: ID)
Workforce (wfId: ID, wfName: STXT, yearlyIncome: DEC, yearlyTax: DEC, taxCode: INT, factoryId*: ID)
Production (prodOrderId: ID, quantity: INT, itemPrice: DEC,orderDate: Date, promiseDate: Date, completionDate: Date, shipmentDate: Date, status: CHAR, prodID*: ID)
ForceUsage (wfId*:ID, prodOrderId*:I.
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Assignment # 2PreliminariesImportant Points· Evidence of acad.docx
1. Assignment # 2Preliminaries
Important Points
· Evidence of academic misconduct (e.g., plagiarism,
collaboration/collusion among students) will be taken seriously
and University regulations strictly followed.
· You are expected to produce a word-processed answer to this
assignment. Please use Arial font and a font size of 12. For SQL
code and output, you can use courier new, which preserves SQL
format and layout.
· You are required to use the Harvard Style of referencing and
citation. The “Cite them right” guide is recommended for
referencing and citation (Pears and Shields, 2008) which should
be followed throughout your answer especially Part 3.
· Late submissions will be given zero marks unless prior
permission is gained from the school office/programme leader.
Module Learning Outcomes (MLOs) assessed:
Knowledge & Understanding:
2. Key concepts of data warehousing.
Intellectual / Professional skills & abilities:
3. Conceptual data modelling, relational database design and
implementation in SQL & PL/SQL, and object-based databases.
4. Design and Implementation of a data warehouse using Oracle
database system.
2. Tasks of the Assignment
Part 1 (50 marks) Scenario: Mechanical Production
Factories (MPF) Database System
MPF is a company that produces customised mechanical
products within Europe. The company produces a rang of
mechanical products at several factories. Information about
which work force are assigned to which production orders and
kept in the force usage register.
In order to access information quickly and to ensure that all past
records are available for audit purposes, the company developed
a database. Figure 1 shows a UML class diagram, which
provides a conceptual model of the database. Relational Design
for MPF Database System
A conceptual model of a database may be implemented using
any database system (e.g. relational, object-relational, object-
oriented). However, to start with, we have mapped the MPF’s
conceptual model onto a relational logical model. Figure 2
details the relations for an implementation of the database using
a relational database system. Note that Figure 2 uses shorthand /
abbreviated notation for data types / domains for describing
various attributes of the relations involved in the database.
Figure 1: UML Class Diagram for the MPF Database
Domains/Data Types: ID = Number(6) LTXT =
Varchar(50)
STXT = Varchar(30) DEC = Number(8,
2) INT = Number(6)
Factory (FactoryId: ID, Location: LTXT, Country: LTXT)
Product (ProdId: ID, Description: LTXT, CostPerItem: DEC,
LabCostPerItem: DEC)
3. FactoryProduct (FactoryId: ID *: ID, ProdId*: ID)
Workforce (wfId: ID, wfName: STXT, yearlyIncome: DEC,
yearlyTax: DEC, taxCode: INT, factoryId*: ID)
Production (prodOrderId: ID, quantity: INT, itemPrice:
DEC,orderDate: Date, promiseDate: Date, completionDate:
Date, shipmentDate: Date, status: CHAR, prodID*: ID)
ForceUsage (wfId*:ID, prodOrderId*:ID, jobDate:Date,
jobHours:INT, jobHourlyRate:DEC, jobPosted: CHAR)
Figure 2: Relational logical Schema for the MPF Database
TASKS3.1 Implementing Object-Relational version of the MPF
Database (25 MARKS)
Implement the MPF Database using object-relational (O-R)
features of Oracle 10g//11g. You need to discuss your approach
to the implementation (2 marks) and provide complete code (23
marks).
The discussion of your approach should highlight the choices
you have made during implementation of your O-R version of
the database. You need to justify your approach/choices (e.g.,
why object types / tables you created are appropriate for the
database).
Note that all relationships (e.g. one-to-one, one-to-many, many-
to-many) must be bi-directional. Moreover, each to-many side
of a relationship (e.g., in case of many-to-one and many-to-
many) should be implemented using nested tables. In addition,
your implementation should allow all objects to be shareable
(i.e. all relationships should be REF based).
Oracle (2013) provides more detailed documentation on Oracle
object-relational features.
3.2 Populating the O-R version of the MPF Database
(12 MARKS)
Using PL/SQL and/or SQL, populate your O-R version of the
4. MPF Database with some sample data. This part can be seen to
contain the following sub-tasks:
(a) Creating / inserting objects in your object tables.
(b) Establishing one-to-many, many-to-one, and many-to-many
relationships (see the UML class diagram) among the objects
created in sub-task (a).
3.3 Querying the O-R version of the MPF Database (8 MARKS)
For this part, you must use PL/SQL procedures (2 procedures,
each worth 4 marks). Answer the following questions after
populating the object-relational database (i.e., after completing
part 3.2):
Q a) For each of the production order, display production
details, dates and hours of their workforce usage and names and
ids of the associated workforce staff.
Q b) For each of the product, display product details,
details of the associated production orders and details of the
factories where the products are produced.
NOTE the following important points for Parts 3.1 to 3.3:
· You must submit all the SQL and PL/SQL code used for
creating, populating and querying the O-R database.
· You must submit the output of running your code (e.g., spool
files).
3.4 Contrasting your O-R version with the relational version of
the MPF Database (5 MARKS)
Compare and contrast the relational version of the MPF
Database with your object-relational version from part 3.1. You
should highlight the advantages and disadvantages of both
5. versions. Comment on which version will best suit the MPF
Database.
Part 2 (50 marks)
1. The Sales History (SH) Data Warehouse
SH is a sample database schema provided by Oracle, which has
been extensively used in the Oracle’s Data Warehousing Guide
(Lane, 2013) The SH schema, as shown in Figure 3, consists of
a big fact table, SALES, and five relatively small dimension
tables: TIMES, PROMOTIONS, CHANNELS, PRODUCTS and
CUSTOMERS. The additional COUNTRIES table linked to
CUSTOMERS creates a simple snowflake. The model and the
attributes are aimed at demonstrating data warehousing
functionality like star transformation and query rewrite. They
do not necessarily represent the optimal approach for this kind
of data warehouse in real productive environments; and such a
design would be driven more by business requirements than by
the star itself. Table 1 shows the cardinalities of the tables in
the SH schema.
Table
Number of Rows
Customers
55,500
Countries
23
Products
72
6. Sales
9,18,843
Times
1826
Promotions
503
Channels
5
Table 1: Cardinalities of SH tables.
Figure 3: SH Star Schema.
Usually, a star schema includes a single fact table and few
dimensional tables, however, the SH schema designer identified
another useful fact table called COSTS, which is linked to the
TIMES and PRODUCTS dimensional tables. Figure 3 shows two
fact tables: SALES and COSTS.
1. Implementation of SH schema
Table 2 shows the files that constitute the implementation of the
SH schema using Oracle 10g/11g/12c.
FileDescription
sh_cre.sql
Script for creating the base tables of the SH data warehouse.
sh_cons.sql
Script for enabling constraints.
sh_drop.sql
Script for dropping the SH schema objects.
sh_idx.sql
Script for creating indexes.
7. sh_pop1.sql
Script for loading data into COUNTRIES and CHANNELS
tables.
sh_pop2.sql
Script for populating the TIMES dimensional table.
sh_schema_objects.sql
Script for calling other scripts e.g. sh_cre.sql for creating base
tables and populating the small dimensional tables.
sh_cremv.sql
Script for creating materialized views.
sh_ext_table.sql
Script for creating an external table.
sh_main.sql
Script that calls several other scripts including e.g.
sh_cremv.sql, sh_idx.sql etc.
sh_costs.sql
Script for populating the COSTS fact table.
sh_hiera.sql
Script for creating dimensional hierarchies, which are called
DIMENSION in Oracle.
Table 2: Files used to implement the SH schema.
3. Two versions of SH schema/database
1) The default and optimized version of the SH database is
created under the SH2 user. You have read-only access to query
any of the tables of SH database by prefixing any table or view
name by “SH2.”, e.g., to query the contents of CHANNELS
table, use:
SELECT * FROM SH2.CHANNELS;
8. 2) An un-optimized version of the SH database has been created
under your own username DWn. You will be given a special
username and password for doing this part of the assignment
(i.e. an Oracle account starting with DW and followed by a
number e.g. DW1, DW2, etc). Throughout this part, you MUST
use this special username. However, it is assumed that you will
not create any indexes on any of the tables in your own personal
version of the SH until asked to do specifically. Moreover,
neither materialized views (see sh_cremv.sql) nor dimensional
hierarchies (see sh_hiera.sql) should be created in your version
of the SH database.
4. Important Note
Whenever, you need to assess the performance of existing
database structures (e.g., materialized view, index, dimensional
hierarchies) you must refer to SH2 as above (using the “SH2.”
prefix). Any new database structures that you need to create
should be created under your username. Likewise, when you
need to assess the performance of any new database structures
that you create under your DWn username, you need to prefix
all tables/views/materialised views accordingly, e.g., to query
the contents of your CHANNELS table, use:
SELECT * FROM DWn.CHANNELS;
5. Tasks of the Assignment
Note: You must submit all the SQL queries and any other code
that you wrote in answering any of the parts / questions (e.g.,
9. the use of Explain Plan statements for the queries and their
output).
(i) Study the index definitions in sh_idx.sql. Discuss in detail
(using cost based analysis) why these indexes (at least two of
them) are useful for answering queries over the SH2 and DWn
versions of the database. You do not need to run the sh_idx.sql
script at all.
(10 Marks)
(ii) Identify two new indexes and justify why they could be
useful. Write the SQL code for creating these indexes under
your DWn user. Give example queries with cost-based analysis
for both DWn (which will have the new indexes) and SH2 users
(which will not have any of your new indexes). (10 Marks)
(iii) Given the materialized views (MVs) defined in
sh_cremv.sql, discuss in detail why these MVs are useful for
users of the SH database. You should provide detailed examples
(cost based analysis, e.g., using Explain Plan for running
sample queries on both SH2 and DWn) to illustrate your answer.
You do not need to run the sh_idx.sql script at all.
(10 Marks)
(iv) Identify two other MVs based on the base tables in the SH
schema under your DWn user and justify why they would be
useful. Write the SQL code for creating these MVs.
(10 Marks)
(v) Prior to the introduction of the aggregation function
ROLLUP, there was no possibility to express an aggregation
over different levels within one SQL statement without using
the set operation UNION ALL. Every different aggregation
level needed its own SQL aggregation expression, operating on
the exact same data set n times, once for each of the n different
10. aggregation levels. With the introduction of ROLLUP in the
recent editions, Oracle provided a single SQL command for
handling the aggregation over different levels within one single
SQL statement, not only improving the runtime of this operation
but also reducing the number of internal operations necessary
and reducing the workload on the system.
a. Using ROLLUP, write an SQL query over the SH schema
under your DWn user involving one fact table (SALES or
COSTS) and at least two dimension tables. Provide reasons why
your query may be useful for users of the SH data warehouse.
(3 Marks)
b. Using set operation UNION ALL (and not ROLLUP), write
an SQL query that produces the same result as the query in (a)
above.
(3 Marks)
c. Using EXPLAIN PLAN, provide a detailed discussion
analysing costs of evaluating the above queries (i.e. with and
without ROLLUP).
(4 Marks)
Hand-in procedure
You should hand in your answer for this assignment as a single
word processed document electronically on the ELP. A sample
assignment template file will be uploaded on the ELP near the
submission deadline.
References
11. Lane, P. (2013) Oracle Database Data Warehousing Guide, 11g
Release 2 (11.2). Part Number E25554-02. Available at:
https://docs.oracle.com/cd/E11882_01/server.112/e25554/toc.ht
m (Accessed: 17 February 2017).
Pears, R. and Shields, G. (2008) Cite them right: the essential
referencing guide.
Newcastle upon Tyne: Pear Tree Books.
Oracle (2005a) Application Developer's Guide - Object-
Relational Features 10g Release 2 (10.2). Part Number B14260-
01. Available at:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14
260/toc.htm (Accessed: 9 November 2016).
Oracle (2005b) Oracle Database PL/SQL User's Guide and
Reference 10g Release 2 (10.2). Available at:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/toc.ht
m (Accessed: 16 March 2017).
Write in C language ( will not accept any others than C and will
consider ZERO
We discussed both the pthreads library and the dining
philosophers problem in class. We also implemented, and
discussed, an “arbitrator solution”. You will find with this
homework a pthreads implementation of a bad dining
philosophers solution that will deadlock. This bad solution is in
the file bad_philosophers.c. You will also find with this
homework a pthread implementation of a working dining
philosophers problem that uses an arbitrator to prevent
deadlocks. This solution is in the file good_philosophers1.c.
You may modify either of these programs to address any of the
12. questions in this homework. You may also start from scratch if
you so choose.
First 1: By yourself, code a version of the “resource hierarchy
solution” for dining philosophers. You MAY turn in a
fixed/modified version of the bad_philosophers.c code of you
can start from scratch. Note that the resource hierarchy solution
is discussed in the book and in hundreds of online tutorials. The
solution is:
Each philosopher runs in an independent thread and each thread
is defined as follows:
While (1)
{ think for some period of time;
when the fork next to me with the smallest number is available,
pick it up; when the fork next to me with the largest number is
available, pick it up; eat for some period of time;
put one fork down;
put the other fork down; }
Note that the “high” numbered and the “low” numbered fork
many NOT always have the same “right fork/left fork” mapping
for all the philosopher. The key here is NOT doing left first and
then right first or right first and then left first. Rather, it is
doing LOWEST NUMBER first and HIGHEST NUMBER
second.
Note, there are versions of this program online. It would be best
if you do not refer to them and cheat yourself of a chance to
figure it out. In any case, you may NOT copy online solutions.
Your solution should be your own and it should be
THROROUGLY commented to explain exactly what the code is
doing. Uncommented code will be scored zero for this question.
Your turn in for this question is a C program in a file called
good_philosophers2.c. Again, it should be lavishly commented.
Seconds 2: For this question, we’ll define “fair” as meaning that
all the philosophers eat about as often as all of the rest of them.
How would you determine if a particular algorithm is fair?
Using this method, experiment with the arbiter solution and the
resource hierarchy solution that you have in
13. good_philosophers1.c and good_philosophers2.c
good_philosophers1.c and good_philosophers1.c respectively.
Are they both fair? If one is not, provide
your reasoning about WHY it is not fair. Your answer to this
question, including any pictures of figures you may want to use,
should be in a PDF file called question_2.pdf
3. Third 3: In real programs, it is more likely that any resource
could need to grab any resource (chopstick) instead of just some
smaller set (chopsticks “close-by”). Consider the program
bad_jerk_philosophers.c that implements a new version of the
dining philosophers problem. In this case, all the philosophers
are jerks and each will, when hungry, make a random choice
about which two chopsticks to take from ANYWHERE on the
table. The provided code deadlocks fairly quickly. Write two
NEW versions of the “jerk dining philosopher problem” that do
NOT deadlock. One version should use an arbiter solution and
should be called good_jerk_philosophers1.c. The second version
should use a resource hierarchy solution and should be called
good_jerk_philosophers2.c. As before, both pieces of code
should be lavishly commented. Uncommented code will not be
graded. Each of the two programs is worth 20 points each.
4. Forth 4: Consider a version of the dining philosophers
problem in which any of the N philosophers may grab between 2
and N chopsticks before eating. This means each philosopher
may grab ANY number between two and all the chopsticks on
the table and those chopsticks need not be anywhere near him
(though they could be). Would a resource hierarchy solution for
this problem prevent deadlocks? Could such a solution livelock?
Could such a solution fail to prevent starvation? Explain your
answers for each. You answer, including any diagrams you may
wish to include, should be in a single pdf file with the name
Four_a.pdf.
5. 5) Fifth 5: Write code that solves the problem in number 4
(A), that prevents both deadlocks and starvation. Call this
program Five_b.c You should lavishly comment your code.
14. Explain, in comments, how you designed the program to prevent
deadlocks and starvation.
When you are done, create a single zip archive file with ALL
your answer files in it. The name of the file should be
<your_last_name>_hw2.zip. The zip archive should contain the
following files:
good_philosophers2.c - Your resource hierarchy
modifications to bad_philosophers.c
question2.pdf - Your answers to problem 2
good_jerk_philosophers1.c -
Yourarbitermodificationstobad_jerk_philosophers.c
good_jerk_philosophers2.c -
Yourresourcehierarchymodificationstobad_jerk_philosophers.c
Four_a.pdf - written answers for problem 4
Four_b.c - code for problem 5
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
// Change the constant below to change the number of
philosophers
// coming to lunch...
// This is a known GOOD solution based on the Arbitrator
// solution
#define PHILOSOPHER_COUNT 20
// Each philosopher is represented by one thread. Each thread
independenly
// runs the same "think/start eating/finish eating" program.
pthread_t philosopher[PHILOSOPHER_COUNT];
15. // Each chopstick gets one mutex. If there are N philosophers,
there are
// N chopsticks. That's the whole problem. There's not enough
chopsticks
// for all of them to be eating at the same time. If they all
cooperate,
// everyone can eat. If they don't... or don't know how....
well....
// philosophers are going to starve.
pthread_mutex_t chopstick[PHILOSOPHER_COUNT];
// The arbitrator solution adds a "waiter" that ensures that only
pairs of
// chopsticks are grabbed. Here is the mutex for the waiter ;)
pthread_mutex_t waiter;
void *philosopher_program(int philosopher_number)
{ // In this version of the "philosopher program", the
philosopher
// will think and eat forever.
while (1)
{ // Philosophers always think before they eat. They need
to
// build up a bit of hunger....
//printf ("Philosopher %d is thinkingn",
philosopher_number);
usleep(1);
// That was a lot of thinking.... now hungry... this
// philosopher (who knows his own number) grabs the
16. chopsticks
// to her/his right and left. The chopstick to the left of
// philosopher N is chopstick N. The chopstick to the
right
// of philosopher N is chopstick N+1
//printf ("Philosopher %d wants
chopsticksn",philosopher_number);
pthread_mutex_lock(&waiter);
pthread_mutex_lock(&chopstick[philosopher_number]);
pthread_mutex_lock(&chopstick[(philosopher_number+1)%PHI
LOSOPHER_COUNT]);
pthread_mutex_unlock(&waiter);
// Hurray, if I got this far I'm eating
printf ("Philosopher %d is
eatingn",philosopher_number);
//usleep(1); // I spend twice as much time eating as
thinking...
// typical....
// I'm done eating. Now put the chopsticks back on the
table
//printf ("Philosopher %d finished
eatingn",philosopher_number);
pthread_mutex_unlock(&chopstick[philosopher_number]);
pthread_mutex_unlock(&chopstick[(philosopher_number+1)%P
HILOSOPHER_COUNT]);
//printf("Philosopher %d has placed chopsticks on the
18. #include <pthread.h>
#include <time.h>
#include <unistd.h>
// Change the constant below to change the number of
philosophers
// coming to lunch...
#define PHILOSOPHER_COUNT 4
// Each philosopher is represented by one thread. Each thread
independenly
// runs the same "think/start eating/finish eating" program.
pthread_t philosopher[PHILOSOPHER_COUNT];
// Each chopstick gets one mutex. If there are N philosophers,
there are
// N chopsticks. That's the whole problem. There's not enough
chopsticks
// for all of them to be eating at the same time. If they all
cooperate,
// everyone can eat. If they don't... or don't know how....
well....
// philosophers are going to starve.
pthread_mutex_t chopstick[PHILOSOPHER_COUNT];
void *philosopher_program(int philosopher_number)
{ // In this version of the "philosopher program", the
philosopher
// will think and eat forever.
while (1)
{ // Philosophers always think before they eat. They need
19. to
// build up a bit of hunger....
//printf ("Philosopher %d is thinkingn",
philosopher_number);
usleep(1);
// That was a lot of thinking.... now hungry... this
// philosopher (who knows his own number) grabs the
chopsticks
// to her/his right and left. The chopstick to the left of
// philosopher N is chopstick N. The chopstick to the
right
// of philosopher N is chopstick N+1
//printf ("Philosopher %d wants
chopsticksn",philosopher_number);
pthread_mutex_lock(&chopstick[philosopher_number]);
pthread_mutex_lock(&chopstick[(philosopher_number+1)%PHI
LOSOPHER_COUNT]);
// Hurray, if I got this far I'm eating
printf ("Philosopher %d is
eatingn",philosopher_number);
//usleep(1); // I spend twice as much time eating as
thinking...
// typical....
// I'm done eating. Now put the chopsticks back on the
table
//printf ("Philosopher %d finished
eatingn",philosopher_number);
21. #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
// Change the constant below to change the number of
philosophers
// coming to lunch...
#define PHILOSOPHER_COUNT 5
// Each philosopher is represented by one thread. Each thread
independenly
// runs the same "think/start eating/finish eating" program.
pthread_t philosopher[PHILOSOPHER_COUNT];
// Each chopstick gets one mutex. If there are N philosophers,
there are
// N chopsticks. That's the whole problem. There's not enough
chopsticks
// for all of them to be eating at the same time. If they all
cooperate,
// everyone can eat. If they don't... or don't know how....
well....
// philosophers are going to starve.
pthread_mutex_t chopstick[PHILOSOPHER_COUNT];
int Random_Int(int max)
{ return((rand() % (max+1)));
}
22. void *philosopher_program(int philosopher_number)
{ // In this version of the "philosopher program", the
philosopher
// will think and eat forever.
int i_want_this;
int i_want_this_too;
while (1)
{ // Philosophers always think before they eat. They need
to
// build up a bit of hunger....
usleep(1);
// That was a lot of thinking.... now hungry... this
// philosopher is a jerk. He may not grap the chopsticks
// closest to him. In fact, he may grab any two
chopsticks at
// the table.... because he is a jerk.
i_want_this = Random_Int(PHILOSOPHER_COUNT);
while ((i_want_this_too =
Random_Int(PHILOSOPHER_COUNT)) == i_want_this);
printf ("Jerk Philosopher %d wants chopsticks %d and
%dn",
philosopher_number,
i_want_this,
i_want_this_too);
pthread_mutex_lock(&chopstick[i_want_this]);
pthread_mutex_lock(&chopstick[i_want_this_too]);
// Hurray, if I got this far I'm eating
printf ("Jerk Philosopher %d is eating with chopsticks
23. %d and %dn",
philosopher_number,
i_want_this,
i_want_this_too);
// I'm done eating. Now put the chopsticks back on the
table
pthread_mutex_unlock(&chopstick[i_want_this]);
pthread_mutex_unlock(&chopstick[i_want_this_too]);
}
return(NULL);
}
int main()
{ int i;
srand(time(NULL));
for(i=0;i<PHILOSOPHER_COUNT;i++)
pthread_mutex_init(&chopstick[i],NULL);
for(i=0;i<PHILOSOPHER_COUNT;i++)
pthread_create(&philosopher[i],NULL,(void
*)philosopher_program,(void *)i);
for(i=0;i<PHILOSOPHER_COUNT;i++)
pthread_join(philosopher[i],NULL);
for(i=0;i<PHILOSOPHER_COUNT;i++)
pthread_mutex_destroy(&chopstick[i]);
return 0;
}
24. Rem
Rem $Header: sh_idx.sql 01-feb-2001.15:13:21 ahunold Exp $
Rem
Rem sh_idx.sql
Rem
Rem Copyright (c) Oracle Corporation 2001. All Rights
Reserved.
Rem
Rem NAME
Rem sh_idx.sql - Create database objects
Rem
Rem DESCRIPTION
Rem SH is the Sales History schema of the Oracle 9i Sample
Rem Schemas
Rem
Rem NOTES
Rem
Rem
25. Rem MODIFIED (MM/DD/YY)
Rem hbaer 01/29/01 - Created
Rem ahunold 03/05/01 - no DROPs needed, part of creation
suite
REM some indexes on fact table SALES
CREATE BITMAP INDEX sales_prod_bix
ON sales (prod_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
CREATE BITMAP INDEX sales_cust_bix
ON sales (cust_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
CREATE BITMAP INDEX sales_time_bix
ON sales (time_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
26. CREATE BITMAP INDEX sales_channel_bix
ON sales (channel_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
CREATE BITMAP INDEX sales_promo_bix
ON sales (promo_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
REM some indexes on fact table COSTS
CREATE BITMAP INDEX costs_prod_bix
ON costs (prod_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
CREATE BITMAP INDEX costs_time_bix
ON costs (time_id)
LOCAL NOLOGGING COMPUTE STATISTICS ;
27. REM some indexes on dimension tables
CREATE BITMAP INDEX products_prod_status_bix
ON products(prod_status)
NOLOGGING COMPUTE STATISTICS ;
CREATE INDEX products_prod_subcat_ix
ON products(prod_subcategory)
NOLOGGING COMPUTE STATISTICS ;
CREATE INDEX products_prod_cat_ix
ON products(prod_category)
NOLOGGING COMPUTE STATISTICS ;
CREATE BITMAP INDEX customers_gender_bix
ON customers(cust_gender)
NOLOGGING COMPUTE STATISTICS ;
28. CREATE BITMAP INDEX customers_marital_bix
ON customers(cust_marital_status)
NOLOGGING COMPUTE STATISTICS ;
CREATE BITMAP INDEX customers_yob_bix
ON customers(cust_year_of_birth)
NOLOGGING COMPUTE STATISTICS ;
COMMIT;
DWUsersWindows UsernameData Warehouse UserNameData
Warehouse
Passwordw17019901DW1DWpasswordw18039998DW2DWpass
wordw18041462DW3DWpasswordw18032109DW4DWpassword
w18043097DW5DWpasswordw18042503DW6DWpasswordw160
36822DW7DWpasswordw18026804DW8DWpasswordw1803710
0DW9DWpasswordw18044330DW10DWpasswordu017449DW1
1DWpasswordw18034092DW12DWpasswordw18043814DW13D
Wpasswordw18040906DW14DWpasswordw18045694DW15DW
passwordw13003649DW16DWpasswordw18032171DW17DWpa
sswordw17033928DW18DWpasswordt025133DW19DWpasswor
dw18042396DW20DWpasswordw18022972DW21DWpasswordw
18014415DW22DWpasswordw18016339DW23DWpasswordw18
032007DW24DWpasswordw18040829DW25DWpasswordw1804
31. Rem
Rem
Rem MODIFIED (MM/DD/YY)
Rem hbaer 01/29/01 - Created
Rem ahunold 03/05/01 - no DROPs needed, part of creation
script
REM AKHTAR 16/03/05 - updated
Rem first materialized view; simple aggregate join MV
Rem equivalent to example 1 in MV chapter DWG, page 8-11
CREATE MATERIALIZED VIEW cal_month_sales_mv
PCTFREE 5
BUILD IMMEDIATE
REFRESH FORCE
ENABLE QUERY REWRITE
AS
SELECT t.calendar_month_desc
32. , sum(s.amount_sold) AS Money
FROM sales s
, times t
WHERE s.time_id = t.time_id
GROUP BY t.calendar_month_desc;
Rem more complex mv with additional key columns to join to
other dimensions;
CREATE MATERIALIZED VIEW fweek_pscat_sales_mv
PCTFREE 5
BUILD IMMEDIATE
REFRESH COMPLETE
ENABLE QUERY REWRITE
AS
SELECT t.week_ending_day
, p.prod_subcategory
33. , sum(s.amount_sold) AS Money
, s.channel_id
, s.promo_id
FROM sales s
, times t
, products p
WHERE s.time_id = t.time_id
AND s.prod_id = p.prod_id
GROUP BY t.week_ending_day
, p.prod_subcategory
, s.channel_id
, s.promo_id;
CREATE BITMAP INDEX FW_PSC_S_MV_SUBCAT_BIX
ON fweek_pscat_sales_mv(prod_subcategory);
CREATE BITMAP INDEX FW_PSC_S_MV_CHAN_BIX
ON fweek_pscat_sales_mv(channel_id);
34. CREATE BITMAP INDEX FW_PSC_S_MV_PROMO_BIX
ON fweek_pscat_sales_mv(promo_id);
CREATE BITMAP INDEX FW_PSC_S_MV_WD_BIX
ON fweek_pscat_sales_mv(week_ending_day);
TASKS Part 1
3.1 Implementing Object-Relational version of the MPF
Database (25 MARKS)
Provide a logical approach to implementation / conceptual view
of nested or object relational structure (2 marks):
Provide SQL Code for creating object types and object-tables
(23 marks):
Provide spool file output or other forms of output from Running
the above SQL code:
3.2 Populating the O-R version of the MPF Database
(12 MARKS)
Provide SQL code for populating your Object-Relational
Database with some sample data. This part can be seen to
contain the following sub-tasks:
(a) Creating / inserting objects in your object tables.
(b) Establishing one-to-many, many-to-one, and many-to-many
relationships (see the UML class diagram) among the objects
35. created in sub-task (a).
Provide spool file output or other forms of output from Running
the above SQL code for populating the database:
3.3 Querying the O-R version of the MPF Database (8 MARKS)
Q a) For each of the production order, display production
details, dates and hours of their workforce usage and names and
ids of the associated workforce staff.
Provide the PL/SQL code for creating the above procedure (4
marks):
Provide spool file output or other forms of output from
Executing the above PL/SQL procedure:
Q b) For each of the product, display product details,
details of the associated production orders and details of the
factories where the products are produced.
Provide the PL/SQL code for creating the above procedure (4
marks):
36. Provide spool file output or other forms of output from
Executing the above PL/SQL procedure
3.4 Contrasting your O-R version with the relational version of
the MPF Database (5 MARKS)
Provide your answer here:
37. Part 2 (50 marks)
(i) Study the index definitions in sh_idx.sql. Discuss in detail
(using cost based analysis) why these indexes (at least two of
them) are useful for answering queries over the SH2 and DWn
versions of the database. You do not need to run the sh_idx.sql
script at all.
(10 Marks)
Answer Part 2 (2.i)
Provide the details of the 2 indexes you are going to compare
their performance impact on SH2 (i.e., name the indexes and on
which tables those indexes were created in SH2, these indexes
must not exist in your DWn version) 1 Mark:
Provide the 2 SQL queries you are going to run to compare the
performance impact of the above 2 Indexes on SH2 and the
version of the same queries on DWn (2 marks):
Provide Explain Plan statements & outputs for the above 2 SQL
queries you have run to compare the performance impact of
those 2 Indexes on SH2 and their version of the same queries on
DWn (4 marks):
38. Provide Discussion of the cost-based comparison of the above 2
sets of queries and their explain plan cost figures (3 marks):
(ii) Identify two new indexes and justify why they could be
useful. Write the SQL code for creating these indexes under
your DWn user. Give example queries with cost-based analysis
for both DWn (which will have the new indexes) and SH2 users
(which will not have any of your new indexes). (10 Marks)
Answer Part 2 (2.ii)
Provide the SQL Code for the 2 indexes you have created on
your DWn database for comparing their performance impact on
DWn (i.e., these indexes must not exist in SH2)
2 Marks:
Provide the 2 SQL queries you are going to run to compare the
performance impact of your own 2 Indexes on DWn and the
version of the same queries on SH2 (2 marks):
Provide Explain Plan statements & outputs for the above 2 SQL
queries you have run to compare the performance impact of
your 2 Indexes on DWn and their version of the same queries on
SH2 (3 marks):
39. Provide Discussion of the cost-based comparison of the above 2
sets of queries and their explain plan cost figures (3 marks):
(iii) Given the materialized views (MVs) defined in
sh_cremv.sql, discuss in detail why these MVs are useful for
users of the SH database. You should provide detailed examples
(cost based analysis, e.g., using Explain Plan for running
sample queries on both SH2 and DWn) to illustrate your answer.
You do not need to run the sh_idx.sql script at all.
(10 Marks)
Answer Part 2 (2.iii)
Provide 2 SQL queries you are going to run to compare the
performance impact of the 2 MVs in SH2 and the version of the
same queries on DWn (4 marks):
Provide Explain Plan statements & outputs for the above 2 SQL
queries you have run to compare the performance impact of
those 2 MVs in SH2 and their version of the same queries on
DWn (3 marks):
Provide Discussion of the cost-based comparison of the above 2
40. sets of queries and their explain plan cost figures (3 marks):
(iv) Identify two other MVs based on the base tables in the SH
schema under your DWn user and justify why they would be
useful. Write the SQL code for creating these MVs.
(10 Marks)
Answer Part 2 (2.iv)
Provide SQL code you used to create the 2 MVs you created in
your own DWn database (i.e., these MVs must not exist in SH2)
(4 marks):
Provide the 2 SQL queries you are going to run to compare the
performance impact of your own 2 MVs on DWn and the
version of the same queries on SH2 (2 marks):
41. Provide Explain Plan statements & outputs for the above 2 SQL
queries you have run to compare the performance impact of
your 2 MVs on DWn and their version of the same queries on
SH2 (2 marks):
Provide Discussion of the cost-based comparison of the above 2
sets of queries and their explain plan cost figures (2 marks):
(v) Prior to the introduction of the aggregation function
ROLLUP, there was no possibility to express an aggregation
over different levels within one SQL statement without using
the set operation UNION ALL. Every different aggregation
level needed its own SQL aggregation expression, operating on
the exact same data set n times, once for each of the n different
aggregation levels. With the introduction of ROLLUP in the
recent editions, Oracle provided a single SQL command for
handling the aggregation over different levels within one single
SQL statement, not only improving the runtime of this operation
but also reducing the number of internal operations necessary
and reducing the workload on the system.
a. Using ROLLUP, write an SQL query over the SH schema
under your DWn user involving one fact table (SALES or
COSTS) and at least two dimension tables. Provide reasons why
your query may be useful for users of the SH data warehouse.
(3 Marks)
Provide the SQL Query here (using ROLLUP):
b. Using set operation UNION ALL (and not ROLLUP), write
42. an SQL query that produces the same result as the query in (a)
above.
(3 Marks)
Provide the SQL Query here (WITHOUT using ROLLUP, i.e.,
using UNION ALL):
c. Using EXPLAIN PLAN, provide a detailed discussion
analysing costs of evaluating the above queries (i.e. with and
without ROLLUP).
(4 Marks)
Provide your answer here: