1.问题现象:
在创建位图连接索引时,报以下错误:
SQL> CREATE BITMAP INDEX bjx ON sales(c.cust_city,c.cust_state_province)
2 FROM sales s, customers c
3 WHERE s.cust_id = c.cust_id;
FROM sales s, customers c
*
ERROR at line 2:
ORA-25954: missing primary key or unique constraint on dimension
2.错误原因
检查错误帮助 : ORA-25954: missing primary key or unique constraint on dimension Cause: An attempt to create a join index was made, which failed because one or more dimensions did not have an appropriate constraint matching the join conditions.
Action: Ensure that the where clause is correct (contains all of the constraint columns) and that an enforced constraint is on each dimension table.
提示原因是 维度表上没有建立主键或唯一键。
3.问题分析
SQL> select OWNER,CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,DEFERRABLE,DEFERRED,VALIDATED from user_constraints where table_name='CUSTOMERS' and constraint_type in ('P','U');
OWNER CONSTRAINT_NAME C STATUS DEFERRABLE DEFERRED VALIDATED
------------------------------ ------------------------------ - -------- -------------- --------- -------------
SH CUSTOMERS_PK P ENABLED NOT DEFERRABLE IMMEDIATE NOT VALIDATED
检查发现,这个customer表的主键是存在的,而且是可用的,但validated为 NOT VALIDATED
分析是否可以变为 validated
SQL> select count(*),count(distinct cust_id) from customers;
COUNT(*) COUNT(DISTINCTCUST_ID)
---------- ----------------------
55500 55500
数据都唯一
4.问题解决
启用validate
SQL> alter table customers enable validate constraint CUSTOMERS_PK ;
Table altered.
SQL> select OWNER,CONSTRAINT_NAME,STATUS,DEFERRABLE,DEFERRED,VALIDATED from user_constraints where table_name='CUSTOMERS' and constraint_type in ('P','U');
OWNER CONSTRAINT_NAME STATUS DEFERRABLE DEFERRED VALIDATED
------------------------------ ------------------------------ -------- -------------- --------- -------------
SH CUSTOMERS_PK ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED
再次去创建 Bitmap Join Index , 问题解决。
SQL> CREATE BITMAP INDEX bjx ON sales(c.cust_city,c.cust_state_province)
2 FROM sales s, customers c
3 WHERE s.cust_id = c.cust_id local;
Index created.
|