Physical Database Design
Materialized Views
CREATE VIEW <name> [AS] (<query>)
MATERIALIZED [AS <data_structure>]
Example: PNUM/(pnum, lname, dept)
- Btree primary index on
pnum
calledPROF-PRIMARY
create view PROF-PRIMARY as (select * from PROF)
materialized as BTREE with search key (pnum)
- Btree secondary index
lname
calledPROF-SECONDARY
create view PROF-SECONDARY
as (select lname, rid from PROF-PRIMARY)
materialized as BTREE with search key (lname)
Data Structure
<data_structure>
- ISAM or VSAM file
- Unsorted heap file
- Hash file
- R trees
- Array
Workloads exist and are common that favour any of these
- Navigational applications and R trees
- OLAP workloads, main memory arrays, and heap files
Records encoding tuples in an index can also be co-clustered with records encoding tuples for another index
Co-Clustering Indices
Beyond Standard Physical Design
Query Optimizations
see also Query Optimization for Relational Algebra
View Based Query Rewriting Problem
Given a query
Theorem: View based query rewriting is undecidable
- Even when
and each is a conjunctive query and any plan equivalent to is acceptable
Query Plan Tools
Tool to enable one to investigate what plan is chose for a query and what the estimated cost is
- DB2
db2expln
anddynexpln
Example: Invoking tools on bibliography query
select name from author, wrote where aid = author
Index Advising Tools
Tool to advise on a standard physical design given a workload description
- DB2
db2advis
Guidelines
- Don’t index unless the performance increase outweighs the update overhead
- Attributes mentioned in WHERE clauses are candidates for each index search keys
- Multi-attribute search keys should be considered when
- A WHERE clause contains several conditions
- It enables index-only plans
- Choose indexes that benefit as many queries as possible
- Each relation can have at most one primary index so it should be chosen wisely
- Target important queries that would benefit the most
- Range queries benefit the most from clustering
- Join queries benefit the most from co-clustering
- multi-attribute index that enabled an index-only plan does not benefit from being clustered
- Target important queries that would benefit the most