首页 > 数据库 > Oracle > [ORACLE]表簇、索引化表簇、哈希簇
表簇(table cluster):
一组共享公共的列的表,其中,共有的列成为簇键。比如将employees表和departments表聚簇,簇键为department_id。
簇键值是被聚簇的表的一组特定行的簇键列的值,存储时只会储存一次,不会在在所有行重复存储。 表簇会将被聚簇的表的相关列物理存储在一起(比如放到同一个数据块中)。
比如 departments和employees表中department_id=30的所有行会放在一起,其中department_id=30这个信息只会存储一次,不会在每行都存储。
索引化表簇(indexed cluster):
是使用索引来查询数据的表簇。在簇键上建B树索引称为簇索引,下面是建立索引化表簇的例子:
## 建立表簇 CREATE CLUSTER employees_departments_cluster (department_id NUMBER(4)) SIZE 512; ## 建立簇索引 CREATE INDEX idx_emp_dept_cluster ON CLUSTER employees_departments_cluster; ## 在簇中创建表 CREATE TABLE employees ( ... ) CLUSTER employees_departments_cluster (department_id); CREATE TABLE departments ( ... ) CLUSTER employees_departments_cluster (department_id);
哈希簇(hash cluster):
是将簇键的值用hash函数进行计算表簇。在访问表中数据时,直接对簇键值进行hash,就可以得到对应的数据块的地址,例如 hash(department_id)。下面是建哈希簇的例子:
## 建立表簇,指定为哈希簇 CREATE CLUSTER employees_departments_cluster (department_id NUMBER(4)) SIZE 8192 HASHKEYS 100; ## 在簇中创建表 CREATE TABLE employees ( ... ) CLUSTER employees_departments_cluster (department_id); CREATE TABLE departments ( ... ) CLUSTER employees_departments_cluster (department_id);
相比非聚簇表的优点:
对被聚簇表的联接,可以减少磁盘I/O,提高访问速度
因为簇键值只存储一次,可以节省空间
参考:
《oracle 11g concepts》
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69996961/viewspace-2764758/ ,如需转载,请注明出处,否则将追究法律责任。