基于 Oracle 函数的位图索引
Oracle Function based Bitmap Index
我正在使用 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
位图连接索引受 number of restrictions 约束。即:
You cannot create a function-based join index.
The dimension table columns must be either primary key columns or have unique constraints.
第一个排除索引中有 nvl ( col, 0 )
第二个解释了您遇到的错误。您需要在 table_2.col
上添加主要或唯一约束。这也意味着此列中不应有空值!
因此您将需要一种不同的方法来为此查询编制索引。
我正在使用 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
位图连接索引受 number of restrictions 约束。即:
You cannot create a function-based join index.
The dimension table columns must be either primary key columns or have unique constraints.
第一个排除索引中有 nvl ( col, 0 )
第二个解释了您遇到的错误。您需要在 table_2.col
上添加主要或唯一约束。这也意味着此列中不应有空值!
因此您将需要一种不同的方法来为此查询编制索引。