Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
3
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Online Table Move
• Online Table Reorganization Improvements
• Sparse MDC Tables
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
4
Index Compression : Overview
• Three different compression techniques applies to index pages
1. Slot directory compression
2. “RIDlist” compression
3. Prefix key compression
5
Index Compression : Existing Page Format
Page Header
COLE, F, KIRA 3011, 3025, 3026, 3027, 3029, 3033, 3035, 3036, 3037
An index key RIDlist (the IDs of the records in the table with this key)
6
Index Compression : Variable Slot Directory
Page Header
COLE, F, KIRA 3011, 3025, 3026, 3027, 3029, 3033, 3035, 3036, 3037
An index key RIDlist (the IDs of the records in the table with this key)
7
Index Compression : RIDlist Compression
Page Header
DALY, M, AL 3009, 3, 1, 2, 1, 1, 92
8
Index Compression : Prefix Compression
Page Header
DALY, M, AL 3009, 3, 1, 2, 1, 1, 92
9
Index Compression : Prefix Compression
Page Header
M 1055, 1
RA 3011, 14, 1, 1, 2, 4, 2, 1, 1
L 3009, 3, 1, 2, 1, 1, 92
NTHONY 6008, 1, 1, 1
Compressed Compressed
Key RIDlist
10
Index Compression : Sample Data
11
Index Compression : Monitoring
12
Index Compression : Monitoring
Actual savings
13
Index Compression : Performance Attributes
• Tradeoff 60
• Some additional CPU cycles needed for compress / 40
decompress
• 0-10% in early measurements 20
• Typically outweighed by reduction in I/O resulting in higher 0 INSERTS QUERY 1 QUERY 2
overall throughput
Uncompressed
Compressed 14
Temp Compression : Overview
15
Temp Compression : Details
16
Temp Compression : Details
1) CREATE
2) INSERT..
100 56%
185
reduction
5% better
Not Compressed
180
50 Compessed
175
0 170
18
LOB Compression
CREATE TABLE (NAME CHAR(20), AGE INT, PICTURE BLOB(10MB), SERVICE INT)
• Compression
• Inlined LOBs are in the base data row, and therefore can be compressed with
DB2’s row compression
• Performance
• Inlined LOBs require do not require an extra I/O to be accessed
• Usage Recommendations
• Consider inlining LOBs that have one or more of the following characteristics:
• Frequently accessed
• Often small enough to fit entirely on a data page
• Compressible (i.e. not random data, not already compressed)
• Keep in mind:
• Potential growth in table size
20
LOB Inlining : Details
• Specify maximum INLINE LENGTH on CREATE or ALTER TABLE
• CREATE TABLE … PICTURE BLOB(10MB) INLINE LENGTH 10000
• ALTER TABLE … ALTER COLUMN PICTURE SET INLINE LENGTH 10000
• LOBs <= than inline length will be stored directly in the row in the data page
• DB2 will search for a page with sufficient space
• There can be a mixture of inlined and non-inlined LOBs within a single page and within a
single row
• INLINE LENGTH limits
Page size Row size limit INLINE LENGTH limit
4k 4005 4001
8k 8101 8097
16k 16293 16289
32k 32677 32673
• Implicit Inlining
• LOBs can be inlined even if there is no INLINE LENGTH set !
• Occurs when a LOB’s actual length is <= it’s maximum descriptor size based on the declared
maximum length of the LOB (see speaker notes)
• Otherwise space would be consumed both in data page (for descriptor) and LOB object (actual LOB)
21
Implicit Inlining
LOB
Descriptor
LOB
22
LOB Inlining : Example Savings
Total physical storage (KBs)
70000
60000
50000
40000
30000
20000
10000
0
No Compression Data Compression LOBs Inlined LOBs Inlined plus Data
Compression
23
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Sparse MDC Tables
• Online Table Move
• Online Table Reorganization Improvements
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
24
Automatic Storage Rebalance : Motivation
• Let’s review what occurs when paths are added to your automatic
storage pool,…
Two storage paths New storage paths p1 and p2 become full DB2 automatically
and a table space has not used by the creates a new stripe
a container on each table space set on p3 and p4
immediately
p1 p2 p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3 p4
C0 C1 C0 C1
ALTER DB TS TS
ADD p3, p4 grows C0 C1 grows C0 C1
C2 C3
25
Automatic Storage Rebalance : REBALANCE
Two storage paths New storage paths REBALANCE causes DB2 If table space is not growing
and a table space has not used by the to create equal-sized rapidly, consider REDUCing
a container on each table space containers in new paths, and it to make space available
immediately redistribute extents to them for other table spaces
p1 p2 p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3 p4
C0 C1 C2 C3
C0 C1 C0 C1 C0 C1 C2 C3
26
Dropping Storage Paths
• Requires REBALANCE 27
Dropping Storage Paths : Example
p1 p2 p3 p1 p2 p3 p1 p3
C1 C2 C3 C1 C2 C3
C1 C3
Drop Pending
28
Monitoring
New database snapshot field
Automatic storage path = /storagePath1
Node number = 0
State = In Use | Not In Use | Drop Pending
File system ID = 64768
Storage path free space (bytes) = 66725142528
File system used space (bytes) = 50100731904
File system total space (bytes) = 317068410880
29
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Sparse MDC Tables
• Online Table Move
• Online Table Reorganization Improvements
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
30
Adopting Automatic Storage : Motivation
• DB2 automatic storage …
• Collapses storage management tasks for any number of tablespaces down to
a single point of management
• Significantly reduces human costs
• Is IBM’s strategic direction going forward for DB2 LUW
31
Adopting Automatic Storage : Made Simpler
32
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Sparse MDC Tables
• Online Table Move
• Online Table Reorganization Improvements
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
33
Reclaimable Storage : Motivation
• CREATE DATABASE … ON /p1, /p2 /p1 /p2
• CREATE TABLESPACE ts1
• DROP TABLE t1
Trapped Free
• LOAD t3 …
Space
34
Reclaimable Storage : Overview
ALTER TABLESPACE <tsname> REDUCE --+-----------------------------+---
'-- <size> --+-------------+--+--'
| +----- K -----+ |
| +----- M -----+ |
| +----- G -----+ |
| '-- PERCENT --' |
'--- MAX ---------------------'
'--- STOP --------------------'
• Works by:
• Moving used extents from higher addresses in the tablespace to unused lower addresses
• Lowering high water mark accordingly
• Shrinking/removing containers to return space back to the Automatic Storage paths
ALTER
DROP TABLE 2 TABLESPACE …
DROP TABLE 3 REDUCE MAX
37
Reclaimable Storage : Examples
ALTER
DROP TABLE 2 TABLESPACE …
DROP TABLE 3 REDUCE nn
38
Reclaimable Storage : Monitoring
• Tablespace snapshot
Tablespace Type = Database managed space
Using automatic storage = Yes
Using reclaimable storage = Yes
...
Tablespace State = 0x'00000010‘
Detailed explanation: Extent movement in progress
• New MON_GET_EXTENT_MOVEMENT_STATUS()
TBSP_NAME TBSP_ID .... NUM_EXTENTS_MOVED NUM_EXTENTS_LEFT TOTAL_MOVE_TIME
--------- ------- ----------------- ---------------- ---------------
USERSPACE1 2 -1 -1 -1
TS1 3 4000 2000 60000
Year Year
Table Object
• These pages and storage are still assigned to the MDC table
• How can this storage be reused elsewhere in the table space?
• If you have a maintenance window : Classic REORG
• If not,…. ?
41
Sparse MDC Tables
REORG TABLE Sales
RECLAIM EXTENTS ONLY
Region Region
Extent is freed
Year Year back to table
space & can be
Table Object used by other
tables !
42
Sparse MDC Tables
• Very fast !
• Not really a reorg
• No copy of the table created, no copy phase, etc
43
Sparse MDC Tables
44
Online Table Move : Motivation
• Initial definition
CONNECT to mydb
• Now what ?
• If you have a large enough maintenance window
• UNLOAD, re CREATE, re LOAD
• But what if you have no maintenance windows ?
45
Online Table Move : Data Flow
Online table move control table
1 INIT PHASE SYSTOOLS.ADMIN_MOVE_TABLE
Create triggers,target, tabschema tabname key value
staging tables
SOURCE TARGET
TABLE 2 TABLE
COPY PHASE
c1 c2 … cn c1 c2 … cn
3
REPLAY PHASE
INSERT INSERT
c1 c2 … cn
Rows with
DELETE DELETE keys present
UPDATE UPDATE in staging
table are
re-copied
Online Keys of
from source
Workload row changed
table
by online
workoad 4 SWAP PHASE
captured via
triggers STAGING Rename Target -> Source
TABLE
46
Online Table Move : Example Use Cases
48
Online Table Reorg Concurrency : Motivation
No new write
Time period dependent on … accesses
- Duration of existing write transactions during this
- Time taken for final row movement phase and truncate phase
period
49
Online Table Reorg Concurrency :
Improvements
• Usage recommendations:
• If you find the S lock is holding up your workload, use REORG… PAUSE to
reclaim currently available space, and resume full table access
• At a later time, check current table size via ADMIN_GET_TAB_INFO()
• If satisfied with space reclaimed:
• REORG … STOP
• Else
• REORG … RESUME
50
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Sparse MDC Tables
• Online Table Move
• Online Table Reorganization Improvements
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
51
Table Partitioning Improvements : Motivation
SQL
Automatic SET INTEGRITY
Asynchronous
Index Cleanup COMMIT
Global Index (order_id)
CREATE
TABLE
JUNE
i1 i1
53
Partitioned Indexes : Benefits
• Storage
• Partitioned indexes do not store partition identifier in each key
• 2 byte savings per RID
• Each partitioned index will be a fraction of the size of an alternative non-partitiioned index
• In some cases, may be able to use REGULAR (small RID) tablespaces for indexes
• Another 2 byte savings per RID
• Performance
• Storage savings typically leads to performance savings
• Less I/O bandwidth and memory consumption
• However, be aware that partitioned indexes will (in general) not provide ‘order’, eg:
SELECT * … ORDER BY partitioned_index_key // can’t use partitioned index for order; may need sort
// (unless of course part. index key is prefixed by table part key)
54
Partitioned Indexes : Utilities / DDL
• Partition-level index REORG
REORG INDEXES ALL FOR TABLE xyz … ON DATA PARTITION jan … ALLOW WRITE ACCESS
• Statistics
• New SYSINDEXPARTITIONS catalog table added to contain per-index-partition statistics
• Also, new statistics added to SYSDATAPARTITIONS to help determine when/if partitioning level
table reorg would be useful
• RUNSTATS continues to operate on table level
55
Partitioned Indexes : Utilities / DDL (cont’d)
• ATTACH
• If required partitioned indexes have already been created on the table about to be attached
• They are just quickly “linked in” as the index partition for this new data partition
• SET INTEGRITY will not perform index maintenance operations for such indexes (eliminates
associated logging) !
• Otherwise, they will be created automatically
• Hint: use the REQUIRE MATCHING INDEXES to ensure automatic creation does not occur
ALTER TABLE … ATTACH PARTITION…. REQUIRE MATCHING INDEXES
• DETACH
• Partitioned indexes for the detached partition quickly “unlinked” from the range partitioned
table, and become regular indexes on the detached partition (now just a regular table)
• No Async Index Cleanup necessary for Partitioned indexes
56
Partitioned Indexes : Streamlined Roll-in
CREATE TABLE
JUNE
CREATE INDEX
ALTER TABLE
LOAD
ATTACH
JUNE
No Global Index to Maintain SET INTEGRITY
ALTER TABLE
DETACH
PARTITION
JAN
58 © 2009 IBM Corporation
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Sparse MDC Tables
• Online Table Move
• Online Table Reorganization Improvements
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
59
Currently Committed Isolation : Motivation
Uncommitted insert
Uncommitted update
Uncommitted delete
60
Currently Committed Isolation : Output
Uncommitted insert
Uncommitted update
Uncommitted delete
61
Currently Committed Isolation : How it Works
INS:Emp,1,6354,Smith,A1/21, 43
INS:Emp,4,1325,Tata,X1/03,33
For uncommitted DELETEs and UPDATEs, when encountering a lock which would
otherwise conflict, DB2 uses new information in the lock manager to reconstruct and
return the previously committed data from the log buffer or log file.
62
Currently Committed : Internals & Usage Notes
• Log-based implementation : simple & fast
• No need for rollback segments !
• Currently committed data typically reconstructed from memory (log buffer)
• Exception: updates/deletes from mass update transactions that spill log buffer
• Active logs read from storage in this case
63
Currently Committed Isolation : Externals
CUR_COMMIT database configuration parameter
ON : cursor stability scans return currently committed data (default for new dbs)
AVAILABLE : cursor stability scans return currently committed data if explicitly requested
DISABLED : disabled (default for upgraded databases)
BIND option
>--+-------------------------------------------------------------+-->
'--CONCURRENTACCESSRESOLUTION--+--USE CURRENTLY COMMITTED--+--'
'--WAIT FOR OUTCOME---------‘
CLI, JCC
SQL_ATTR_CONCURRENT_ACCESS_RESOLOUTION = 1
concurrentAccessResolution property
Notes
• CC does not apply to target table of write, catalogs, RCT, “integrity scans”
• DB2 needs to hold the right to update the row in this case
• Target table of write still exhibit “skip uncommitted inserts” aspect of CC
• CC extends “skip uncommitted inserts” to Read Stability isolation as well
64
Currently Committed Isolation : Example
APPLICATION A APPLICATION B
UPDATE T1 SET COL1=? WHERE COL2=? UPDATE T2 SET COL1=? WHERE COL2=?
65
Currently Committed Isolation : Semantics
Cursor Stability N Y Y
with CC N Y Y
Read Stability N N Y
with CC N N Y
Repeatable Read N N N
66
Agenda
• Compression Advancements
• Indexes
• Temp Data
• LOBs
• Storage Management
• Automatic Storage : Rebalance Improvements
• Automatic Storage : Easier Adoption
• Reclaimable Storage
• Table Maintenance
• Sparse MDC Tables
• Online Table Move
• Online Table Reorganization Improvements
• Table Partitioning
• Partitioned Indexes
• Currently Committed Isolation
• High Availability Disaster Recovery
• Active Standby
67
HADR Reads on Standby : Motivation
Read enabled Standby in
OLTP Clients perpetual Rollforward
HADR Communication
Clients
Reporting/DSS/BI
workloads
Resource Utilization
• Standby provides High Availability, Disaster Recovery & allows read-only workloads
• Improve resource utilization
• Decrease total cost of ownership
68
HADR Reads on Standby : Overview
• Writers blocked
• Error SQL1773N
69
Matt Huras
IBM
huras@ca.ibm.com
dwsnow@us.ibm.com
paulz@ca.ibm.com
bminor@ca.ibm.com