我使用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
型
1条答案
按热度按时间lkaoscv71#
位图连接索引受到许多限制。即:
第一种方法排除了索引中有nvl(col,0)的情况
第二个解释了你得到的错误。你需要在
table_2.col
上添加一个主约束或唯一约束。这也意味着在这个列中不应该有空值!因此,您将需要一种不同的方法来为这个查询建立索引。