Documente Academic
Documente Profesional
Documente Cultură
After completing this module, you will be able to: Choose columns as candidate Secondary Indexes. Describe Composite Secondary Indexes. Analyze Change Rating and Value Access.
Accessing Rows
SELECT {expression} FROM tablename
Returns the value(s) from the table(s) for display or processing. The row(s) must be physically read first.
UPDATE tablename SET columns = {expression}
Changes one or more column values to new values. The rows(s) must be physically located (read) first.
DELETE FROM tablename
Removes rows from a table. The row(s) must be physically located (read) first.
Any of the above SQL statements can contain a WHERE clause.
Values in the WHERE cause tell the RDBMS what set of rows to act on. Without a WHERE clause, all rows participate in the operation. Limiting the number of rows the RDBMS must handle improves throughput.
Row Selection
WHERE clause conditions that may use indexing if available*:
colname = value colname IS NULL colname IN (subquery) * colname IN (explicit list of values) t1.col_x = t1.col_y t1.col_x = t2.col_x condition1 AND condition2 condition1 OR condition2 colname = ANY, SOME or ALL
Access methods for the above depend on whether the column(s) are indexed, type of index, and selectivity of the index.
The following functions effect output only, not base row selection. Poor relational models severely limit physical design choices and generally force more Full Table Scans.
Composite Indexes are used only if ALL columns have explicit values.
Composite USIs may be used for PK enforcement. Avoid composite NUSIs other than for covering indexes. Multiple single column NUSIs support bit mapping combinations. COLLECT STATISTICS on all NUSIs to allow the Optimizer to use them.
<
Example: Assume the typical rows per value is 2000 and the table has 100,000 rows. If typical row size is 480 bytes and typical block size is 48,000 bytes, then
Is 2000 100,000 < 480 48,000 ? Is .02 < .01 ? No, therefore this column is not a NUSI candidate.
If typical row size is 4800 bytes and typical block size is 48,000 bytes, then
Is 2000 100,000 < 4800 48,000 ? Is .02 < .10 ? Yes, therefore this column is a NUSI candidate.
Exercise 3 Sample
On the following pages, there are sample tables with typical rows per value demographics. Indicate ALL possible Secondary Index candidates (USI and NUSI). Later exercises will guide your final choices. EXAMPLE 6,000,000 Rows PK/FK A PK,SA B C FK,NN D NN,ND Secondary Index Candidate Guidelines: All PI candidates are secondary Index candidates. Assume 48K blocks and rows are < 480 bytes. Column(s) are a NUSI candidate if
typical rows per value rows in table typical row size
<
F
Value Access Join Access Join Rows Distinct Values Max Rows/Value Max Rows/NULL Typical Rows/Value Change Rating PI/SI
0 0 0 8 800K 0 700K 0
Value Access Join Access Join Rows Distinct Values Max Rows/Value Max Rows/NULL Typical Rows/Value Change Rating PI/SI
Value Access Join Access Join Rows Distinct Values Max Rows/Value Max Rows/NULL Typical Rows/Value Change Rating
12 0 0 90K 2 4K 1 9 NUSI
12 0 0 12 10K 0 8K 1
4 0 0 5 24K 0 20K 2
PI/SI
NUSI?
NUSI?
PI/SI
NUPI
USI NUSI
NUPI
NUSI NUSI
NUPI
NUSI
PI/SI
NUPI
USI NUSI
NUPI
NUSI
NUPI
NUSI NUSI
PI/SI
NUPI
USI NUSI NUSI
Change Rating
Change Rating indicates how often values in a column are UPDATEd:
0 = column values never change. 10 = column changes with every write operation.
PK columns are always 0. Historical data columns are always 0. Data that does not normally change = 1. Update tracking columns = 10. All other columns are rated 2 - 9. Base Primary Index choices on columns with very stable data values:
Value Access
Value Access:
How often annually all known transactions access rows from the table
through this column. The above demographics result from Activity Modeling. Index choices determine if the rows will be accessed via index or FTS. Secondary indexes can be created at any time.
Secondary Index overhead may cost more than doing the FTS.
Exercise 4 Sample
On the following pages, there are sample tables with change row and value access demographics. Eliminate Index candidates based on change rating and value access. Later exercises will guide your final choices. EXAMPLE 6,000,000 Rows PK/FK A PK,SA B C FK,NN D NN,ND E F G H Change Rating Guidelines: PI change rating 0 - 2. SI change rating 0 - 5. Value Access Guideline: NUSI Value Access > 0
Value Access Join Access Join Rows Distinct Values Max Rows/Value Max Rows/NULL Typical Rows/Value Change Rating PI/SI
0 0 0 8 800K 0 700K 0
Value Access Join Access Join Rows Distinct Values Max Rows/Value Max Rows/NULL Typical Rows/Value Change Rating PI/SI
Value Access Join Access Join Rows Distinct Values Max Rows/Value Max Rows/NULL Typical Rows/Value Change Rating
12 0 0 90K 2 4K 1 9
12 0 0 12 10K 0 8K 1
4 0 0 5 24K 0 20K 2
PI/SI
NUSI
UPI
NUPI
PI/SI
NUPI
USI NUSI
NUPI
NUSI NUSI?
NUPI
NUSI
PI/SI
NUPI
USI NUSI
NUPI
NUSI
NUPI
NUSI NUSI
PI/SI
NUPI
USI NUSI NUSI
Review Questions
1. In the case of a NUPI, the best way to avoid a duplicate row check is to ________. a. b. c. d. use set tables compare data values byte-by-byte within a Row Hash in order to ensure uniqueness. assign a USI on the PK to enforce uniqueness on a NUPI table. use the NOT NULL constraint on the column
2. Why should you avoid creating composite NUSIs? What is a better method? ______________________________________________________ ______________________________________________________ 3. Which SQL statement does not require the row to be physically read first? ____ a. b. c. d. INSERT SELECT UPDATE DELETE
2. Why should you avoid creating composite NUSIs? What is a better method?
Composite indexes are utilized only if explicit values are supplied for each and every column in the index. It is better to define several single-column NUSIs in order to possibly utilize NUSI bit mapping.
3. Which SQL statement does not require the row to be physically read first? ____ a. b. c. d. INSERT SELECT UPDATE DELETE