物化视图的增量刷新如何工作?

How incremental refresh on Materialized view works?

假设我有一个正在构建物化视图(MV)的查询 select * from employee, department where employee.id = department.id and name like '%Andy%'

关于 MV 的增量更新如何在内部工作,我有两个相关问题

1) 假设我在员工或部门 table 中插入或更新任何条目,我能否将 MV 上的 increment refresh 配置为与 insert/update 事务异步 或者必须是同步过程?

2)插入或更新时,oracle 是否评估(通过事务日志)每个 updated/inserted 行并应用 MV 查询条件,看看是否满足它。如果是,更新或插入 MV 中的行?

1) Say I insert or update any entry either in employee or department table, can I configure increment refresh on MV to be asynchronous of insert/update transaction or it is mandatory to be synchronous process ?

如果您希望在基础 table 上提交更改后立即在实体化视图上提供数据,那么您可以使用 ON COMMIT 刷新方法。

或者,如果您想通过增量应用对实体化视图的更改来刷新,那么您可以使用 FAST 刷新方法。您可以异步执行此操作。

2)While insert or update , Does oracle evaluate(through transactionl logas) each updated/inserted row and apply the MV query criteria , see if satisfies it . If yes, update or insert the row in MV ?

这取决于您使用的是哪种刷新方法。如果您正在使用 FAST 或 ON COMMIT 刷新方法,那么是的,它仅将更改应用到 MV,这些更改满足用于创建 MV 的查询中定义的条件。

对于 FAST REFRESH,您必须在 table 基础上为 MV 创建 MATERIALIZED VIEW LOG,您 select。在这些物化视图日志中,Oracle 存储了 updated/inserted/deleted 行信息。即 Oracle 不会像您假设的那样使用 REDO 日志。

一旦基于您的 table 的所有 MView 都被刷新(通过 ON COMMIT 或手动刷新),相应的物化视图日志的内容将被截断。