我正在使用Oracle 11g,我有三个表,即TABLE_1
,TABLE_2
,TABLE_3
。在select语句中,我需要执行以下查询:
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
答案 0 :(得分:2)
位图连接索引受number of restrictions的约束。即:
您无法创建基于函数的联接索引。
维度表列必须是主键列或具有唯一约束。
第一个排除索引中包含nvl(col,0)
第二个解释您得到的错误。您需要在table_2.col
上添加主要约束或唯一约束。这也意味着此列中不应包含空值!
因此,您将需要一种不同的方法来为此查询建立索引。