Table Clusters

Table Clusters 

       A table cluster is a group of tables that share common columns and store related data in the same blocks. When tables are clustered, a single data block can contain rows from multiple tables. For example, a block can store rows from both the employees and departments tables rather than from only a single table.

      The cluster key is the column or columns that the clustered tables have in common.

      You can consider clustering tables when they are primarily queried (but not modified) and records from the tables are frequently queried together or joined. Because table clusters store related rows of different tables in the same data blocks, properly used table clusters offer the following benefits over nonclustered tables:

      ■Disk I/O is reduced for joins of clustered tables.
      ■Access time improves for joins of clustered tables.
      ■Less storage is required to store related table and index data because the cluster key value is not stored repeatedly for each row.

      Typically, clustering tables is not appropriate in the following situations:

      ■The tables are frequently updated.
      ■The tables frequently require a full table scan.
      ■The tables require truncating.

Indexed Clusters

     An indexed cluster is a table cluster that uses an index to locate data. The cluster index is a B-tree index on the cluster key.A cluster index must be created before any rows can be inserted into clustered tables.

     Assume that you create the cluster employees_departments_cluster with the cluster key department_id, as shown in Example 2–8. Because the HASHKEYS clause is not specified, this cluster is an indexed cluster. Afterward, you create an index named idx_emp_dept_cluster on this cluster key.

CREATE CLUSTER employees_departments_cluster
(department_id NUMBER(4))
SIZE 512;
CREATE INDEX idx_emp_dept_cluster ON CLUSTER employees_departments_cluster;

     You then create the employees and departments tables in the cluster, specifying the department_id column as the cluster key, as follows (the ellipses mark the place where the column specification goes):

CREATE TABLE employees ( ... )
CLUSTER employees_departments_cluster (department_id);
CREATE TABLE departments ( ... )
CLUSTER employees_departments_cluster (department_id);

       Finally, you add rows to the employees and departments tables. The database physically stores all rows for each department from the employees and departments tables in the same data blocks. The database stores the rows in a heap and locates them with the index.



Hash Clusters

      A hash cluster is like an indexed cluster, except the index key is replaced with a hash function. No separate cluster index exists. In a hash cluster, the data is the index.

      With an indexed table or indexed cluster, Oracle Database locates table rows using key values stored in a separate index. To find or store a row in an indexed table or table cluster, the database must perform at least two I/Os:

      ■One or more I/Os to find or store the key value in the index
      ■Another I/O to read or write the row in the table or table cluster

      To find or store a row in a hash cluster, Oracle Database applies the hash function to the cluster key value of the row. The resulting hash value corresponds to a data block in the cluster, which the database reads or writes on behalf of the issued statement.
      Hashing is an optional way of storing table data to improve the performance of data retrieval. Hash clusters may be beneficial when the following conditions are met:

      ■A table is queried much more often than modified.
      ■The hash key column is queried frequently with equality conditions, for example, WHERE department_id=20. For such queries, the cluster key value is hashed. The hash key value points directly to the disk area that stores the rows.
      ■You can reasonably guess the number of hash keys and the size of the data stored with each key value.


摘自--- Oracle Concepts


相關資料


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章