How do I add a cluster on a composite key?

只谈情不闲聊 提交于 2020-05-30 08:00:47

问题


I have created a cluster

create cluster abc_clus
(abc_key int)
;

and then created an index based on that cluster

create index abc_clus_idx
on cluster abc_clus;

I tried adding this cluster on these 4 tables for a complex join

 create table number1
(
    dateofbirth date,  
    Time timestamp(0), 
    IDnumber int not null,
    class varchar(7) not null, 
primary key (dateofbirth, Time, class))
cluster abc_clus(class);

and

  create table number2(
    tutornumber int not null,
    forename varchar2(20) not null,
 constraint number2 primary key (tutornumber))
       cluster abc_clus(tutornumber);

and

create table number3
(
constraint number3 primary key (Roomnumber),
Roomnumber int not null, 
xyz varchar(20))
cluster abc_clus(Roomnumber3);

and

create table number4
(
constraint class_pk primary key (classnumber),
classnumber int not null)
 cluster abc_clus(classnumber);

However, when I try this, I get this error:

ORA-01753: column definition incompatible with clustered column definition

I'm wondering how the correct way would be to add the cluster on the composite key: firstname, lastname, address.

I am using SQL plus.

Thanks


回答1:


The table column needs to be the same datatype as the cluster column. In your example, this works fine:

create table test1 (
  id int
) cluster abc_clus(id);
Table TEST1 created.

Even a composite key works, if the datatype matches:

create table test2 (
  a int,
  b int,
  primary key(a, b)
) cluster abc_clus(a);
Table TEST2 created.

However, if the datatype is different, you get your error message:

create table test3 (
  vc varchar2(7)
) cluster abc_clus(vc);
ORA-01753: column definition incompatible with clustered column definition

And the datatype has to be exactly the same, even int and number are not compatible:

create table test4 (
  n NUMBER
) cluster abc_clus(n);
ORA-01753: column definition incompatible with clustered column definition

EDIT:

You can even have composite clusters:

create cluster idc_clus ( i int, d date );

create index idc_clus_idx on cluster idc_clus;

create table test5 ( i int, d date, primary key (i,d) ) cluster idc_clus(i, d);



来源:https://stackoverflow.com/questions/61570454/how-do-i-add-a-cluster-on-a-composite-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!