Question

In: Computer Science

Queries written by developers are not always optimized for performance. It is crucial to ensure that...

Queries written by developers are not always optimized for performance. It is crucial to ensure that all queries are fully optimized in the database whenever possible so that they can execute optimally. There may be changes in code or the addition of indices to help with optimization.

Review six queries that require optimization (I am stuck on these 3).

1. SELECT Order.CustomerID, Product.ProductID, OrderDetail.OrderID

FROM Product, OrderDetail, Order

WHERE Order.OrderID = OrderDetail.OrderID AND OrderDetail.ProductID = Product.ProductID AND OrderDetail.Price = 50

a. Optimize query performance using appropriate strategies (that is, optimizer hints, additional indices, changing the query search arguments, or some combination thereof as appropriate).

b. Explain briefly why you chose the strategies that you employed.

2. SELECT Order.CustomerID, Product.ProductID, OrderDetail.OrderID

FROM Product, OrderDetail, Order

WHERE Order.OrderID = OrderDetail.OrderID AND OrderDetail.ProductID = Product.ProductID AND CustomerID < 100 AND Quantity = 1

a. Optimize query performance using appropriate strategies (that is, optimizer hints, additional indices, changing the query search arguments, or some combination thereof as appropriate).

b. Explain briefly why you chose the strategies that you employed.

3. SELECT Customer.FirstName, Customer.LastName, Product.ProductName, OrderDetail.Quantity, OrderDetail.Price

FROM Customer, Order, OrderDetail, Product

WHERE Customer.CustomerID = Order.CustomerID

AND Order.OrderID = OrderDetail.OrderID

AND OrderDetail.ProductID = Product.ProductID

AND ProductID NOT IN (1, 2, 3, 4, 5, 6, 7)

a. Optimize query performance using appropriate strategies (that is, optimizer hints, additional indices, changing the query search arguments, or some combination thereof as appropriate).

b. Explain briefly why you chose the strategies that you employed.

Solutions

Expert Solution

1. (a)

SELECT Order.CustomerID, Product.ProductID, OrderDetails.OrderID

FROM ( Order INNER JOIN OrderDetails ON Order.OrderID = OrderDetails.OrderID ) INNER JOIN Product ON OrderDetails.ProductID = Product.ProductID where OrderDetails.Price = 50;

2. (b)

SELECT Order.CustomerID, Product.ProductID, OrderDetail.OrderID

FROM ( Order INNER JOIN OrderDetails ON Order.OrderID = OrderDetails.OrderID ) INNER JOIN Product ON OrderDetails.ProductID = Product.ProductID

where OrderDetails.Price = 50 AND Order.CustomerID < 100 AND OrderDetails.Quantity = 1;

3.(a)

SELECT Customer.FirstName, Customer.LastName, Product.ProductName, OrderDetail.Quantity, OrderDetail.Price

FROM (Customer LEFT INNER JOIN Order ON Customer.CustomerID = Order.CustomerID )

INNER JOIN OrderDetails ON Order.OrderID = OrderDetails.OrderID ) INNER JOIN Product ON OrderDetails.ProductID = Product.ProductID

where Product.ProductID NOT IN (1, 2, 3, 4, 5, 6, 7);


Related Solutions

Using appropriate performance measures is crucial for the success of the performance evaluation and incentive schemes....
Using appropriate performance measures is crucial for the success of the performance evaluation and incentive schemes. However, using improper performance measures may result in goal conflict problems (e.g., between departments, between managers and shareholders, or between a superior and a subordinate). Describe two goal conflict situations caused by the use of inappropriate performance measures and also discuss potential solution(s) for each situation.
Waste water treatment is a crucial process to ensure that the waste water can be safely...
Waste water treatment is a crucial process to ensure that the waste water can be safely recycled back to the environment. However, there are certain challenges or issues related to this waste water treatment that can endanger the environment. In your opinion (supported by journal or academic references), what are those challenges and how can civil engineers prevent those happening>
Is it always possible to construct and carry out a crucial test to determine once and...
Is it always possible to construct and carry out a crucial test to determine once and for all which of two competing hypotheses is correct? Explain.
performance management(setting performance standards and expectations and how performance report are written?
performance management(setting performance standards and expectations and how performance report are written?
Conducting ethical research is crucial to ensure that participants are not harmed. Discuss five research ethics...
Conducting ethical research is crucial to ensure that participants are not harmed. Discuss five research ethics and give examples of how you would apply each to a research project.
Validation and verification of data is always important with any spreadsheet. It's crucial that the data,...
Validation and verification of data is always important with any spreadsheet. It's crucial that the data, functions and formulas are accurate. In this week's reading, various techniques are covered to help improve the accuracy of a spreadsheet. Choose two of those techniques, explain what they do and share an example of each.
Explain the concepts of liquidity and solvency. Why is performance on these two dimensions crucial to...
Explain the concepts of liquidity and solvency. Why is performance on these two dimensions crucial to company survival? How does coverage analysis differ from measures of liquidity and solvency?
The sequence of nitrogenous bases in an RNA and DNA strand is always written in the...
The sequence of nitrogenous bases in an RNA and DNA strand is always written in the 5? to 3? direction because __________. 1. each strand of RNA or DNA has an unlinked 3? carbon and an unlinked 5? carbon 2. DNA and RNA are synthesized in this direction in cells 3. DNA strands are antiparallel 4. nucleotides are added to the 5? end of the nucleic acid
In the book, the question is written as such: Are price and quantity demanded always inversely...
In the book, the question is written as such: Are price and quantity demanded always inversely related? Can you think of circumstances under which increasing the price of a good or service might cause the quantity demanded to increase? Can you think of circumstances under which decreasing the price might cause quantity demanded to decrease?
"To ensure investors are protected and the market integrity is always preserved, we will not hesitate...
"To ensure investors are protected and the market integrity is always preserved, we will not hesitate to take offenders to court." Justify the rationale of why shareholders interest must be safeguarded.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT