Professional Documents
Culture Documents
Database Performance Tuning and Query Optimization: Discussion Focus
Database Performance Tuning and Query Optimization: Discussion Focus
Database Performance Tuning and Query Optimization: Discussion Focus
Chapter 11
Discussion Focus
This chapter focuses on the factors that directly affect database performance. Because performance-
tuning techniques can be DBMS-specific, the material in this chapter may not be applicable under all
circumstances, nor will it necessarily pertain to all DBMS types.
This chapter is designed to build a foundation for the general understanding of database performance-
tuning issues and to help you choose appropriate performance-tuning strategies.
Start by reading about the basic database performance-tuning concepts (11.1). You are
encouraged to use the web to search for information about the internal architecture (internal
process and database storage formats) of various database systems. Focus on the similarities to
lay a common foundation.
Be familiar with how a DBMS processes SQL queries in general terms and stress the importance
of indexes in query processing.
Step through the query processing example in section 11.4, Optimizer Choices.
There are common practices used to write more efficient SQL code. Note that some practices are
DBMS-specific. As technology advances, the query optimization logic becomes increasingly
sophisticated and effective. Therefore, some of the SQL practices illustrated in this chapter may
not improve query performance as dramatically as it does in older systems.
Step though the chapter material using the query optimization example in section 11.8.
Problem Solutions
Because this column has only two possible values (“M” and “F”), the EMP_SEX column has low
sparsity.
2. What indexes should you create? Write the required SQL commands.
Ch11 Database Performance Tuning-and Query Optimization
3. Using Table 11.4 on page 499 as an example, create two alternative access plans (Plan A & Plan
B). Use the following assumptions:
a. There are 8,000 employees.
b. There are 4,150 female employees.
c. There are 370 employees in area code 615.
d. There are 190 female employees in area code 615.
Because the EMP_DOB column stores employee’s birthdays, this column is very likely to have high
data sparsity.
Ch11 Database Performance Tuning-and Query Optimization
I don’t think it is necessary to create an index in the EMP_DOB column because it would not help
this query, due to the query uses the YEAR function. However, if the same column is used for other
queries, then I might re-consider creating an index.
Ch11 Database Performance Tuning-and Query Optimization
Problems 7-10 are based on the ER model shown in Figure P11.7 and on the query shown after the
figure.
7. Assuming that there are no table statistics, what type of optimization will the DBMS use?
8. What type of database I/O operations will likely be used by the query? (See Table 11.3.)
The DBMS will likely use a full table scan to compute the average price in the inner subquery. The
DBMS is also very likely to use another full table scan of PRODUCT to execute the outer query.
Ch11 Database Performance Tuning-and Query Optimization
Because each product is likely to have a different price, the P_PRICE column is likely to have high
sparsity.
Yes, I should create an index because the column P_PRICE has high sparsity and the column is very
likely to be used in many different SQL queries as part of a conditional expression.
The LINE_UNITS column in the LINE table represents the quantity purchased of a given product in
a given invoice. This column is likely to have many different values and therefore, the column is
very likely to have high sparsity.
12. Should you create an index? If so, what would the index column(s) be, and why would you
create that index? If not, explain your reasoning.
Yes, you should create an index on LINE_UNITS. This index is likely to help in the execution of the
inner query that computes the maximum value of LINE_UNITS.
Ch11 Database Performance Tuning-and Query Optimization
13. Should you create an index on P_CODE? If so, write the SQL command to create that index. If
not, explain your reasoning.
Yes, creating an index on P_CODE will help in query execution. The SQL command would be: