Course: Data Science and Database Technologies
Source: Physical Design, local path 16-PhysicalDesign.pdf, 41 PDF pages. The source displays the Data Base and Data Mining Group (DBMG) mark; no individual lecturer name is printed on the slides. Lecture number 16 follows the supplied filename identifier.
Lecture summary
Physical design is the third database design phase, following conceptual design (ER or UML) and logical design (relational tables). Its goal is to deliver good application performance while preserving data independence—meaning changes to storage layout or indexes do not require modifying application SQL. Unlike logical design, physical design depends on the chosen DBMS product because each system provides different storage structures and access techniques.
Because no universal algorithmic formula produces an optimal physical schema, design proceeds iteratively from the workload (frequent queries, modification operations, predicate selectivity, and required performance) combined with general criteria, heuristics, and post-deployment database tuning. Designers decide each table’s physical file organization (heap, clustered/ordered, hashed, or multi-table clustering), choose between B⁺-Tree and hash indexes, assign at most one clustered (primary) index alongside zero or more unclustered (secondary) indexes, and check whether new indexes hurt update throughput or disk space. When queries remain slow, the first step is to update database statistics and tune indexes rather than inserting DBMS-specific hints (such as Oracle hints) that break data independence.
For analytical queries joining large tables before aggregating, group-by push down reduces intermediate row counts by performing partial GROUP BY aggregations earlier (lower in the query tree) before joins. Finally, ten concrete SQL examples on an EMP/DEPT schema illustrate why expressions on indexed columns, skewed distributions, low cardinality relative to block factor, nested-loop outer/inner table roles, covering indexes, and composite index key order determine whether an index helps or hurts.
Learning route
- Review prerequisites: Physical Access Structures and Access Methods, Clustered and Unclustered Indexes, Query Optimization Pipeline and Relational Algebra, Query Cost Estimation and Access Selection, and Join Algorithms and Execution Plan Selection.
- Read Physical Design Workload and Index Selection Heuristics for inputs/outputs, file organizations, indexing rules, nested-loop outer/inner choice, statistics, and hints.
- Read Group-By Push Down for query-tree direction, the
SALES/SHOP/PRODUCTrewrite trace, and automatic vs. SQL-level push down. - Read Covering Indexes and Composite Index Design for index-only access (Examples 7–9) and composite index column ordering (Example 10).
Source map
| PDF pages | Material |
|---|---|
| 1–5 | Database design phases, physical design goals, data independence, inputs and outputs |
| 6–10 | Selection dimensions: physical file organizations, clustered vs. unclustered indices, B⁺-Tree vs. hash, and logical-schema adjustments |
| 11–18 | Physical design strategies, primary-key and predicate criteria, heuristics for small tables, low cardinality, WHERE, joins, and GROUP BY |
| 19–22 | Group-by push down worked example (PRODUCT, SHOP, SALES query and query-tree rewrites) |
| 23 | Troubleshooting slow queries: updating database statistics, tuning, and avoiding optimizer hints |
| 24–41 | Physical design examples 1–10 on EMP and DEPT |
Worked examples from the source
1. Group-by push down trace (Slides 19–22)
Schema:
PRODUCT(Prod#,PName,PType,PCategory)SHOP(Shop#,City,Province,Region,State)SALES(Prod#,Shop#,Date,Qty)
Query:
SELECT PType, Province, SUM(Qty)
FROM Sales S, Shop SH, Product P
WHERE S.Shop# = SH.Shop#
AND S.Prod# = P.Prod#
AND Region = 'Piemonte'
GROUP BY PType, Province;Instead of joining every daily SALES row with SHOP and PRODUCT before aggregating at the top, the rewritten tree pushes partial aggregations downward (earlier):
- Push
GROUP BY Prod#, Provincebelow thePRODUCTjoin (retainingProd#as join key becauseProd#determinesPType). - Push
GROUP BY Prod#, Shop#directly ontoSALESbelow theSHOPjoin (collapsing dailyDaterows before joiningSHOP).
Because not every DBMS automatically applies group-by push down (Slide 18), inspect the execution plan and, when necessary, rewrite the SQL with a pre-aggregated subquery. See Group-By Push Down.
2. The ten EMP and DEPT physical design examples (Slides 24–41)
Base schema (Slide 25):
EMP(Emp#,EName,Dept#,Salary,Age,Hobby), withDept#referencingDEPT.Dept#DEPT(Dept#,DName,Mgr), withMgrreferencingEMP.Emp#
| Ex. (Slides) | SQL / Scenario | Physical Design Decision & Explanation |
|---|---|---|
| 1 (26) | SELECT * FROM EMP WHERE Salary/12 = 1500; | A B⁺-Tree on Salary may be ignored because Salary is wrapped in arithmetic (Salary/12). Rewrite as Salary = 18000. |
| 2 (27) | SELECT * FROM EMP WHERE Salary = 18000; | Index is usable, but gives no benefit if 18000 occurs very frequently (skewed data distribution / low selectivity). |
| 3 (28–29) | EMP block factor = 30 tuples/block; index EMP.Dept#? | Case A (Card(DEPT) = 50): No — almost every page holds nearly all departments, so a sequential scan is better.Case B ( Card(DEPT) = 2000): Yes — each page holds few departments, so a secondary index skips most blocks. |
| 4 (30) | SELECT EName, Mgr FROM EMP E, DEPT D WHERE E.Dept# = D.Dept# AND DName = 'Toys'; | Hash index on DEPT.DName (equality filter makes DEPT the outer table) + Hash index on EMP.Dept# for nested-loop probing with EMP as the inner table. |
| 5 (31) | Example 4 + AND Age = 25; | Consider an index on Age only if selective (few rows match Age = 25). |
| 6 (32–34) | SELECT EName, Mgr FROM EMP E, DEPT D WHERE E.Dept# = D.Dept# AND Salary BETWEEN 10000 AND 12000 AND Hobby = 'Tennis'; | Selection on EMP: Hash on Hobby (equality usually more selective) or B⁺-Tree on Salary (range); smart optimizers intersect RIDs from both.Join: Hash join or nested loop with EMP outer, DEPT inner + index on DEPT.Dept# (unless DEPT is very small). |
| 7 (35–36) | SELECT Dept#, COUNT(*) FROM EMP WHERE Age > 20 GROUP BY Dept#; | No B⁺-Tree on Age (unselective). Clustered index on Dept# avoids sorting and reads grouped pages cleanly; an unclustered secondary index on Dept# alone risks too many table reads for Age > 20. |
| 8 (37–38) | SELECT Dept#, COUNT(*) FROM EMP GROUP BY Dept#; | Unclustered (secondary) index on Dept# acts as a covering index: it answers the query without reading EMP table data. |
| 9 (39) | SELECT Mgr FROM DEPT, EMP WHERE DEPT.Dept# = EMP.Dept#; | Unclustered index on EMP.Dept# covers EMP completely (Mgr comes from DEPT), avoiding reading table EMP. |
| 10 (40–41) | SELECT AVG(Salary) FROM EMP WHERE Age = 25 AND Salary BETWEEN 3000 AND 5000; | Composite B⁺-Tree index on <Age, Salary> is fastest (equality/more selective key first, range key second, and covers AVG(Salary)). Field order limits reuse and composite indexes increase update overhead. |
Added study clarifications in the linked concept notes (such as the receipt-counting and phonebook analogies, manual SQL push-down rewrite, and the CUSTOMER/ORDER exercise) are explicitly labeled as added study explanations outside the PDF.
Revision prompts
- Explain why physical design must preserve data independence and why Oracle-style optimizer hints violate it.
- Given a block factor and table cardinality (as in Example 3), explain when a secondary index helps versus when a sequential scan wins.
- Redraw the
PRODUCT/SHOP/SALESgroup-by push down query tree from scratch and explain whyProd#andShop#stay in the pushed-downGROUP BYclauses. - Distinguish nested-loop outer vs. inner table selection across Examples 4 and 6.
- Explain why an unclustered index on
EMP.Dept#covers Example 8 and Example 9, why it fails to cover Example 7, and how a composite index changes Example 7 and Example 10.
Source and scope
Data Base and Data Mining Group (DBMG), Physical Design, local path 16-PhysicalDesign.pdf, 41 PDF pages. This note paraphrases and structures the source examples; added analogies and extra exercises live in the linked concept notes with explicit labels.