我正在使用 Oracle 11g,我有三个表,即TABLE_1
, TABLE_2
, TABLE_3
。在选择语句中,我需要执行以下查询:
SELECT
-- // ommitted
FROM
TABLE_1,
TABLE_2,
TABLE_3
WHERE
-- // ommitted
AND NVL(TABLE_1.COL_1, 0) = NVL(TABLE_2.COL, 0)
AND (TABLE_1.COL_2 = TABLE_3.COL OR NVL(TABLE_1.COL_2, 0) = 0)
我想为以下内容创建基于函数的位图索引:
NVL(TABLE_1.COL_1, 0) = NVL(TABLE_2.COL, 0)
(TABLE_1.COL_2 = TABLE_3.COL OR NVL(TABLE_1.COL_2, 0) = 0)
可能吗?
因为NVL(TABLE_1.COL_1, 0) = NVL(TABLE_2.COL, 0)
我尝试过:
CREATE BITMAP INDEX TABLE_1_TABLE_2_NVL_COL_IDX
ON TABLE_1 (TABLE_2.COL)
FROM TABLE_1, TABLE_2
WHERE NVL(TABLE_1.COL_1, 0) = NVL(TABLE_2.COL, 0);
但它抛出了错误:
ORA-25954: missing primary key or unique constraint on dimension 25954. 00000 - "missing primary key or unique constraint on dimension\n" *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.
如果我能够创建索引,那么以下语法是否是在 select 语句中提供提示的正确方法?:
SELECT
/*+ INDEX (TABLE_1 TABLE_1_TABLE_2_NVL_COL_IDX) */
/*+ INDEX (TABLE_1 TABLE_1_TABLE_3_NVL_COL_IDX) */
-- // ommitted