使用 groupby 和 where 子句在提交时快速刷新

Refresh fast on commit with groupby and where clause

我能够成功创建如下所示的实体化视图,但是当我查看 MV_CAPABILITIES_TABLE 时,它告诉我 REFRESH_FAST_AFTER_ONETAB_DML 和 REFRESH_FAST_ANY_DML 是不可能的。

CREATE MATERIALIZED VIEW MV_contacts_table
BUILD IMMEDIATE
REFRESH FAST ON COMMIT AS
SELECT t.ID AS ID,
MAX(DECODE(t.FieldName, 'FirstName', t.FieldValue)) FirstName, 
MAX(DECODE(t.FieldName, 'LastName', t.FieldValue)) LastName,
COUNT(*) AS NUM_FIELDS FROM Contacts_Table t
WHERE t.FieldName = 'FirstName' OR t.FieldName = 'LastName'
GROUP BY t.ID

这里是MV_CAPABILITIES_TABLE

PCT                             N               
REFRESH_COMPLETE                Y               
REFRESH_FAST                    Y               
REWRITE                         N               
PCT_TABLE                       N   CONTACTS_TABLE  675 2068    relation is not a partitioned table
REFRESH_FAST_AFTER_INSERT       Y               
REFRESH_FAST_AFTER_ONETAB_DML   N                       2086    mv uses the MIN or MAX aggregate functions
REFRESH_FAST_AFTER_ANY_DML      N                       2161    see the reason why REFRESH_FAST_AFTER_ONETAB_DML is disabled
REFRESH_FAST_PCT                N                       2157    PCT is not possible on any of the detail tables in the materialized view
REWRITE_FULL_TEXT_MATCH         N                       2159    query rewrite is disabled on the materialized view
REWRITE_PARTIAL_TEXT_MATCH      N                       2159    query rewrite is disabled on the materialized view
REWRITE_GENERAL                 N                       2159    query rewrite is disabled on the materialized view
REWRITE_PCT                     N                       2158    general rewrite is not possible or PCT is not possible on any of the detail tables
PCT_TABLE_REWRITE               N   CONTACTS_TABLE  675 2068    relation is not a partitioned table

如果我删除 where 子句,则 REFRESH_FAST_AFTER_ANY_DML 是可能的。是否有可能调整此 SQL 查询,以便我的物化视图设置为 REFRESH_FAST_AFTER_ANY_DML 并包含 Where 子句?

这是一个restriction of materialized views:

A materialized view with MAX or MIN is fast refreshable after delete or mixed DML statements if it does not have a WHERE clause.

The max/min fast refresh after delete or mixed DML does not have the same behavior as the insert-only case. It deletes and recomputes the max/min values for the affected groups. You need to be aware of its performance impact.

(强调我的)。

所以你需要找到一些其他的方法来实现你的目标。