1

我正在使用 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
4

1 回答 1

3

位图连接索引受到许多限制。即:

  • 您不能创建基于函数的连接索引。

  • 维度表列必须是主键列或具有唯一约束。

第一个排除在索引中有 nvl ( col, 0 )

第二个解释了您遇到的错误。您需要在table_2.col. 这也意味着此列中不应有空值!

因此,您将需要一种不同的方法来为此查询建立索引。

于 2019-01-10T16:25:56.663 回答