db2 database design - db2no database_design_-_from_logical_to_physical… · db2 database design:...

58
is rented under reports to completes rents / is in employed by receives makes rents under is made on is rented as CUSTOMER CustomerNum Name Address Phone CreditCardNum CreditCardExDate StatusCode MOVIE MovieNum Name Director Description Star Rating Genre Rental Rate STORE StoreNum Manager Address Phone EMPLOYEE EmployeeNum Name Address Phone SocialSecNum HireDate Salary Supervisor (FK) PAYMENT Payment Transaction Num Type Amount PaymentDate Status MOVIE RENTAL RECORD Rental Record Date Rental Date Due Date Rental Status Rental Rate Overdue Charge Amt MOVIE COPY Movie Copy Num General Condition JoinDate DB2 Database Design: From Logical to Physical Mullins Consulting, Inc. http://www.CraigSMullins.com

Upload: trandung

Post on 07-Feb-2018

254 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

is

rented

under

reports to

completes

rents /is in

employed by

receives

makes

rents under

is made on

is rented as

CUSTOMERCustomerNum

NameAddressPhone

CreditCardNumCreditCardExDateStatusCode

MOVIEMovieNum

NameDirectorDescriptionStarRatingGenreRental Rate

STOREStoreNum

ManagerAddressPhone

EMPLOYEEEmployeeNum

NameAddressPhoneSocialSecNumHireDateSalarySupervisor (FK)

PAYMENT

Payment Transaction NumTypeAmountPaymentDateStatus

MOVIE RENTAL RECORDRental Record Date

Rental DateDue DateRental StatusRental RateOverdue Charge Amt

MOVIE COPYMovie Copy Num

General Condition

JoinDate

DB2 Database Design: From Logical to Physical

Mullins Consulting, Inc.http://www.CraigSMullins.com

Page 2: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

2

Author

This presentation was prepared by:

Craig S. MullinsPresident & Principal Consultant

Mullins Consulting, Inc.15 Coventry Ct.Sugar Land, TX 77479Tel: 281-494-6153E-mail: [email protected]

This document is protected under the copyright laws of the United States and other countries as an unpublished work. This document contains information that is proprietary and confidential to Mullins Consulting, Inc., which shall not be disclosed outside or duplicated, used, or disclosed in whole or in part for any purpose other than as approved by Mullins Consulting, Inc. Any use or disclosure in whole or in part of this information without the express written permission of Mullins Consulting, Inc. is prohibited.

© 2011 Craig S. Mullins and Mullins Consulting, Inc. (Unpublished). All rights reserved.

Page 3: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Capital - Chart of Accounts

Facilities - blueprints

Human Resources - org chart

Materials - Bill of Materials

Why Model Data?

Data?

3

Page 4: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Data Modeling Objectives

• Document and communicate the business information

requirements

• Enable databases with:– Minimum redundancy

– Maximum integrity

– Sharability

– Stability

– Flexibility

– Consistency

– Timely access

– Usability

• Increase value of data resource

achieves

e.g., Data modeling

Database

Characteristic

Database

has

ObjectiveFunction

4

Page 5: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

• Don’t think “how”; think “what”

• Don’t think physical; think conceptual

• Don’t think process; think structure

• Don’t think navigation; think relationship

Data Thinking

5

Page 6: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Data Modeling Concepts

Concepts to be covered will include:

� Entities

� Entity Types

� Entity Occurrences

� Relationships

� Attributes

� Attribute Roles

� Keys

� Diagramming Techniques

6

Page 7: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Entities

Student

Instructor

Course

• Something that exists and is capable of being described.

• A person, place, thing, concept or event about which an organization maintains facts.

Employee

Order

Item 7

Page 8: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Entity Examples

• Person: Roles people play

• Employee • Customer• Supplier • Agent

• Thing: Physical object type

• Item • Part• Product • Building• Material • Equipment

• Concept: Intangible ideas

• Warranty • Route• Account

Entity

Person Place Thing Event Concept

� Place: Areas or geographic locations

• Office • Warehouse• City • Region

� Event: Things that "happen"

• Sale • Order• Transfer • Shipment• Project • Agreement• Reservation • Flight

8

Page 9: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Entity Occurrence

Entity Type

Entity Occurrences

•Customer: Moore

City: Pittsburgh

State: PA

Phone: 555

Credit:: Go

AMEX:

VISA:

Contact:

Customer: Jackson

City: An

State: MI

Phone: 5

Credit:: Ex

AMEX:

VISA:

Contact:

Customer: Mullins

City: Houston

State: TX

Phone: 555-1234

Credit:: Fair

AMEX: xxxxxxxxxxxxxxxxxxx

VISA: xxxxxxxxxxxxxxxxxxxx

Contact: Mike

9

Page 10: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Entity Naming Guidelines

• Noun, or Adjective-Noun format

–Contract

–Lease Agreement

• Minimize use of adjectives

–Contractor vs Contract Employee

–Training vs Employee Course

• Do not pluralize; use singular instead: Employee vs

Employees

–The entity type is a model or pattern rather than the set of all

employees

• Use business terms and be consistent

–Vendor or Supplier?

–User or Client?

• Remove process specific artifacts from the entity name

–State not Residence State

–Agent not Selling Agent10

Page 11: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Relationships

• How the different entities are associated with

each other

Customer Order

Places

Is Placed By

Places

Is Placed By

11

Page 12: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

One-to-One One-to-Many Many-to-Many

CUSTOMER ACCOUNT STUDENT COURSE

1 1 1 M M M

STUDENT

STUDENT

STUDENT

STUDENT

1

2

3

4

5

COURSE

COURSE

COURSE

COURSE

CUSTOMER

CUSTOMER

CUSTOMER

CUSTOMER

ACCOUNT

ACCOUNT

ACCOUNT

ACCOUNT

EMPLOYEE

EMPLOYEE

EMPLOYEE

EMPLOYEE

EMPLOYEE

TEMP_EMP

TEMP_EMP

TEMP_EMP

TEMP_EMP

TEMP_EMP

Diagramming Conventions

12

Page 13: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Data Model Guidelines

Order Customer

Order Customer

Order

Customer Customer

Order

Reads left-to-right Is placed by

Read right-to-left

Places

Read top-to-bottomRead bottom-to-top

Is placed byPlaces

� The relationship is read clockwise over the line

13

Page 14: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Types of Entities

• Examining relationships can help to

determine the type of entity:

– Fundamental Entities - represent fundamental, or

basic, business objects

– Characteristic Entities - contain multiple attributes

or facts describing a basic entity

– Associative Entities - describe a relationship

between two other entities

14

Page 15: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

STUDENT

StudentID

LastNameFirstName

MiddleInitMajorID

ENROLLMENT

StudentID

CourseNum

CourseCompDate

Grade

COURSE

CourseNum

CourseNameCredits

STUDENT

StudentID

LastNameFirstName

MiddleInitMajorID

COURSE

CourseNum

CourseNameCredits

Creating an Associative Entity

15

Page 16: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Attributes

Customer: Smith

Customer #: 0001

City: New York

State: New York

Phone: 555-1938

Credit: Good

Customer Cust Number Cust NameStreet AddressCityStateZip CodePhone NumCredit Limit Amt

ENTITY = NounsATTR = Adjectives 16

Page 17: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Attributes

� An attribute is a fact about an entity. It is a data element that is an inherent property of an entity.

� An attribute will fulfill one (and only one) of these objectives:

� Describe

� Identify

� Relate

17

Page 18: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Attribute Naming Guidelines

CLASS ABBREVIATION DESCRIPTION

ADDRESS ADDR Address or location

AMOUNT AMT Monetary amount

CODE CODE Classifications, codes, types

DATE DATE Calendar dates

DESCRIPTION DESC Descriptive text

IDENTIFIER ID Alphanumeric unique identifier

IMAGE IMG Encoded digital image

NAME NAME Alphabetic name, identification

NUMBER NUM Numeric count

PERCENT PCT Relationships as %

QUANTITY QTY Counts and units

TEXT TXT Free form document text

TIME TIME Time; temporal data

18

Page 19: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Keys

� A key is an attribute, or group of attributed, that are used to identify.

� There are three types of keys:

� Candidate Keys

� Primary Keys

� Foreign Keys

19

Page 20: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Primary Keys

• The attribute or attributes that uniquely identify an entity type

• A primary key value uniquely identifies a single occurrence

of an entityOrder

Order #: 0001 Line #: 1

ProdID: 1234Qty: 5

CustomerNumber

Order Number +Line Number Product

ID

0001 / 1

20

Page 21: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Foreign Keys

• An attribute (or attributes) in one entity that relates an

occurrence of that entity to an occurrence of another entity

• The relating attribute(s) contains the same value(s) as the

primary key of the related entity occurrence

Employee Org Unitworks inemploys

Emp NumEmp NameOrg Unit Num (F)

Org Unit NumOrg Name

Employee Org Unitmanages

managed by

Emp NumEmp Name

Org Unit NumOrg Name

(Relationship Attributes)

21

Page 22: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Normalization

• First Normal Form

A row is in first normal form if and only if all underlying

domains contain atomic values only.

• Second Normal FormA row is in second normal form if and only if it is in first

normal form and every non-key attribute is fully dependent

on the key.

• Third Normal FormA row is in third normal form if and only if it is in second

normal form and every non-key attribute is is non-

transitively dependent on the primary key.

The process of identifying the one

best place a fact belongs.

22

Page 23: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Derived and Base Data

Student IDStudent NameStudent Date of BirthStudent Age(D)

Course

Course NumCourse Offering DateCourse NameCourse Fee

Student IDCourse NumCourse Offering DateCourse Completion DateCourse Charge Back Amt(DT)

Enrollment

Student

23

Page 24: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Data Model of Modeling Terms

Relationship

Entity

Attribute

Occurrence

Domain

Primary

Key

Attribute

Value

24

Page 25: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Terminology Summary

Occur-rence

Object-Oriented Term

Type,ADT, Class

Instance, Object

Property

ObjectIdentifier

CommonTerm

GraphicTerm

DPTerm

DesignTerm

Rela-tionalTerm

FileCabinet

Table File EntityRelation,

Table

FileFolder

or Record

Row Record Tuple,Row

Fact Column

FieldData Item

DataElement

Attribute Column(Domain)

Index IdentifierRecord

KeyPrimary

KeyPrimary

Key

25

Page 26: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

• Translation of Logical Model to Physical Database

• Create DDL

• Entities to Tables, Attributes to Columns, Relationships and Keys to

DB2 RI and Indexes, etc.

• Tbut differences CAN and WILL occur

• Create Storage Structures for Database

• Files for data and indexes

• Partitioning

• Clustering

• Optimization

• Etc.

Transforming Logical to

Physical

26

Page 27: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

TABLESPACE

TABLEX

TABLEY

TABLESPACE

TABLEA

TABLEB

TABLEC

TABLEB

TABLEA

INDEX SPACE

INDEX on

TABLEY

DB2 Object Overview

STOGROUP

DATABASE

VOLC01 VOLC02

TABLESPACE

TABLEZ(Partition 1)

(Partition 2)

(Partition 3)

INDEX SPACE

INDEX on

TABLEZ(Partition 1)

(Partition 2)

(Partition 3)DB2

CATALOG

MVS

ICF

CATALOG

LINEAR

VSAM

Background

DB2 Files

D

B

2

V

S

A

M

27

Page 28: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

DB2 Object Hierarchy

28

Page 29: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

DB2 Data Types

• CHAR

• VARCHAR

• CLOB

• DBCLOB

• GRAPHIC

• VARGRAPHIC

• BLOB

• DATE

• TIME

• TIMESTAMP

• TIMESTAMP w/TIMEZONE

• XML

• BIGINT

• INTEGER

• SMALLINT

• DECIMAL

– NUMERIC

• FLOAT

– REAL

– DOUBLE

• DECFLOAT

• BINARY

• VARBINARY

29

Page 30: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

30

Page 31: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Decimal: Precision and Scale

• The precision of a decimal number is

the total number of digits in the number

(do not count the decimal point).

– For example, the number 983.201

has a precision of 6.

• The scale of a decimal number is equal

to the number of digits to the right of

the decimal point.

– In the previous example,

the scale is 3.

31

Page 32: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

32

Page 33: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

33

Page 34: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Storing Large Objects:

BLOBs, CLOBs and DBCLOBs

Base Table Space

Base TableISBN Text ROWID

Index

LOB Table Space

Auxiliary Table

Database34

Page 35: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

35

Page 36: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

36

Page 37: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

37

Page 38: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Column Ordering

• Sequence columns based on logging

– Infrequently updated non-variable columns first

– Static (infrequently updated) variable columns

– Frequently updated columns last

– Frequently modified together, place next to each other

FIRST

NAME

Frequently updated at

the same time (marriage)

Tbut infrequently updated.

CUST

ID

LAST

NAME

ACCT

BAL

Frequently

updated

Static,

infrequently

updated38

Page 39: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Reordered Row Format

• RRF automatically puts variable columns at

the end of the row

– Does not impact the DCLGEN or how you interact with the

table in your programs; just changes physical storage on

disk.

– So RRF stores fixed-length columns first and the variable

columns at the end.

• Pointers within the row will point to the beginning of the variable

columns.

– The previous format is now called Basic Row Format, or

BRF.

– Over time, your table spaces will migrate to RRFT

39

Page 40: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

40

Page 41: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Row Size(to determine page size, free space)

41

Page 42: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Constraints

• Referential

– PRIMARY KEY

– FOREIGN KEY

• UNIQUE

• CHECK

– (CHECK SALARY > 50000.00)

• Triggers

42

Page 43: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

43

Page 44: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

RI: System or User-Managed?

� Standard declarative implementation.

� Less coding required.

� Easier to modify later. (DDL and CHECK)

� More efficient.

� Ad hoc and planned updates.

� Requires program code to be written.

� Hard to modify later.

� Sometimes there is the possibility for better insert performance.

� Works only for planned updates.

Referential constraints & Triggers

Program logic

44

Page 45: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

45

Page 46: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Denormalization

• Prejoined Tables - when the cost of joining is prohibitive

• Report Tables - for specialized critical reports (e.g. CEO)

• Mirror Tables - when two types of environments require

concurrent access to the same data (OLTP vs DSS)

• Split Tables - when distinct groups/apps use different parts of

the same table

– Splitting columns across two tables for long variable character columns.

• Combined Tables - to eliminate one-to-one relationships

• Redundant Data - to reduce the number of joins for a single

column (e.g. definitional, CA to California)

• Repeating Groups - to reduce overall I/O (& possibly DASD)

• Derivable Data - to eliminate calculations & aggregations

• Speed Tables - to support hierarchies

• Page Size - to reduce page size 46

Page 47: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

47

Page 48: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

48

Page 49: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

49

Page 50: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Universal Table Spaces

• The future (and present) of DB2 table spaces

• Combine many of the best features of partitioned and

segmented

– Only one table per table space

• Partition by Growth

– DB2 creates a new partition, as needed, as more data gets

added to the table space

• MAXPARTITIONS controls how many partitions

can be created

• Range-Partitioned

– More like a traditional partitioned table space

– Control over partitions and which ranges of data go into

which partition 50

Page 51: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

51

Page 52: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

3390 Storage Group 3380 Storage Group

3390

3380

52

Page 53: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

DB2 IndexesIndex AdvantagesOptimize data access:

• DB2 decides whether or not to use an index at BIND time

• DB2 maintains all indexes

• Tablespace scans can be avoided through index usage

• Recommended on foreign key columns to speed referential integrity

access

• Indexes can minimize sorting

• There can be multiple indexes per table to suit the way data is processed

Guarantee uniqueness:

• Only means of ensuring uniqueness of column values

• Required on primary key column as part of referential integrity

implementation

Implement clustering:

in the index

• DB2 will attempt to maintain rows in the sequence of the column values

in the index 53

Page 54: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

• A proper indexing strategy can be the #1 factor to ensure optimal performance– First take care of unique & PK constraints

– Then for foreign keys (usually)

– Heavily used queries - predicates

– Overloading of columns for IXO

– Index to avoid sorting

• ORDER BY, GROUP BY, DISTINCT

– Choose first column wisely (high cardinality)

– Choose clustering index wisely

– Indexing variable columns?

– Consider the cost of indexes

Indexing Strategy

54

Page 55: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Index Organization

55

Page 56: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

56

Page 57: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

View Usage Rules

• Valid reasons to implement views:

– Security - row and column level

– Access - efficient access paths

– Data Derivation - put the calculations in the view

– Mask Complexity - hide complex SQL from users

– Rename a Table

– Column Renaming - table with better column names

(easier to use than AS)

• Synchronize all views with base tables...

DO NOT USE ONE VIEW PER BASE TABLE!57

Page 58: DB2 Database Design - DB2No Database_Design_-_From_Logical_to_Physical… · DB2 Database Design: From Logical to Physical ... • DB2 decides whether or not to use an index at BIND

Database Design for DB2

http://www.craigsmullins.com

Craig S. MullinsMullins Consulting, Inc.

58