100% found this document useful (1 vote)
143 views

Adams - Hash Clusters Oracle

The document discusses hash clusters in Oracle databases. It describes how hash clusters partition rows across blocks using a hash function applied to a cluster key. Rows are stored in either fixed blocks based on their hash value, or chained blocks if there is not enough space in the fixed blocks. It provides examples of creating and querying single-table hash clusters to optimize for high data density storage.

Uploaded by

rockerabc123
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
143 views

Adams - Hash Clusters Oracle

The document discusses hash clusters in Oracle databases. It describes how hash clusters partition rows across blocks using a hash function applied to a cluster key. Rows are stored in either fixed blocks based on their hash value, or chained blocks if there is not enough space in the fixed blocks. It provides examples of creating and querying single-table hash clusters to optimize for high data density storage.

Uploaded by

rockerabc123
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Using Hash Clusters

Unix + Oracle =
Steve Adams
Ixora [email protected]
Cluster Blocks
Table Directory Row Directory
0
1
0
1
2
3
4

• Table directory 0
1
2

• partitions the row directory


• row numbers are relative to their table
• cluster keys are stored as table 0

Unix + Oracle =
Steve Adams
Ixora [email protected]
Cluster Key Changes
• Performed by recursive/service transactions
• commit independent of parent/user transaction
• improves concurrency
• Single threaded
• to prevent incompatible key changes
• always use ITL slot 1
• slot 1 is reserved - user transactions never use it
• wait in shared mode for TX lock if slot is busy

Unix + Oracle =
Steve Adams
Ixora [email protected]
Index Cluster Inserts
• Key can be inserted to block if
• number of keys < (data area size - 14) / SIZE
• available space > SIZE - 27
• key and data row pieces fit below PCTFREE
• Row inserts
• lookup key in cluster index
• insert to (last) data block if space permits
• try up to 3 previous blocks in the key chain
• link a freelist block into the key chain & insert
Unix + Oracle =
Steve Adams
Ixora [email protected]
Index Cluster Deletes
• Data row piece headers have a key index
• Keys have current & pending row counts
• both incremented on insert
• pending decremented on delete
• current decremented on stub cleanout
• Flushable keys
• current count was, or pending count is zero
• when inserting a new key, try to clean out all
committed stubs and flush keys if possible
Unix + Oracle =
Steve Adams
Ixora [email protected]
Demonstration
• Flushable keys
• Key insert restrictions

Unix + Oracle =
Steve Adams
Ixora [email protected]
Demonstration
• Index clusters row inserts

Unix + Oracle =
Steve Adams
Ixora [email protected]
Cluster Key Scans
• Purpose
• to fetch all rows for a clustered table
with a known cluster key value

• Buffer gets
• visit all blocks in the key chain (reverse order)
• scan row directory entries for the table
and check cluster key index for all rows

Unix + Oracle =
Steve Adams
Ixora [email protected]
Assessing Cluster Key Chaining
• Detection
• compare cluster key scan block gets
to the cluster key scans statistic
• maybe DBA_CLUSTERS .
AVG_BLOCKS_PER_KEY
• Fix
• rename existing tables and create new cluster
• use PL/SQL iterate over the cluster keys
and copy all rows for each key in turn
Unix + Oracle =
Steve Adams
Ixora [email protected]
Hash Theory
• TBD

Unix + Oracle =
Steve Adams
Ixora [email protected]
Hash Clusters
• Fixed blocks
• formatted during cluster creation
• hash key value implied by location
• keys never flushed; blocks never freed
• no data row counts, or previous key rowid needed
• Chained blocks
• just like index cluster blocks
• key data is hash key value

Unix + Oracle =
Steve Adams
Ixora [email protected]
Demonstration
• Hash cluster

Unix + Oracle =
Steve Adams
Ixora [email protected]
Single Table Hash Clusters
• Better “single row per hash key”
• Reserved slots
• one row slot per key
• cluster key scans only inspect that slot
iff no keys have more than one row
• otherwise scan all row slots for table
• “A” flag in data layer flag byte
• no more than one row per key

Unix + Oracle =
Steve Adams
Ixora [email protected]
Demonstration
• Single table hash cluster

Unix + Oracle =
Steve Adams
Ixora [email protected]
Hash Functions
• Internal hash function
• returns 31-bit positive integer
• good distribution, but not perfect
• mod(hash value, HASHKEYS)
• HASH IS column_name
• must be integer column
• saves hash computation
• no false collisions

Unix + Oracle =
Steve Adams
Ixora [email protected]
Demonstration
• Single table hash cluster without HASH IS

Unix + Oracle =
Steve Adams
Ixora [email protected]
Hash Cluster Data Density
• Use SINGLE TABLE syntax if possible
• Otherwise
• 2K tablespace block size
• no SIZE parameter
• HASHKEYS is number of fixed blocks needed
• primary key columns first in row
• Benefits
• minimize CPU cost of cluster key scans
• maximize data density - only one key per block
Unix + Oracle =
Steve Adams
Ixora [email protected]

You might also like