首页 文章

使用几何体在物化视图上启用快速刷新

提问于
浏览
3

我有一个看似简单的问题,物化视图似乎是理想的解决方案,但我不能让它高效工作,也许答案很简单:“Oracle根本不允许它”,但我希望我我忽视了一些愚蠢的事情 .

问题:由于一些历史性的决定,我有一个表格,其中包含来自两个国家的几何图形,存储在一个国家的坐标系中 . 我现在想要使用共享坐标系创建物化视图 . 所以实际上,实现这一目标的最简单的查询是:

select thr_ident, thr_status, geom from 
  ((
     select thr_ident, thr_status, sdo_cs.transform(sdo_cs.transform(thr_geometry, 327680), 8307) as geom
     from th_threat 
     where thr_origin in (6,61, 11, 9) 
   ) 
   union all 
   (
     select thr_ident, thr_status, sdo_cs.transform(thr_geometry, 8307) as geom
     from th_threat 
     where thr_origin not in (6,61,11,9) 
  ))

几何体只创建一次,但我希望状态保持同步(出于可视化目的) . 所以我在 thr_identthr_status 上添加了一个物化视图日志:

create materialized view log on th_threat 
with sequence, rowid (thr_ident, thr_status)
including new values;

并创建了物化视图,并希望每当原始源数据发生变化时('on commit')它将自动保持同步 .

但显然 refresh on commit 在使用对象时是不可能的,但如果它足够有效/足够快,那么 fast refresh 就足够了 .

我假设假设 union all 并没有真正帮助,我将其重写为单个查询,如下所示:

create materialized view th_threat_mv 
--  refresh fast on demand
as  
select 
  rowid rid, thr_ident, thr_status, 
  case 
    when thr_origin in (6,61, 11, 9) then 
      sdo_cs.transform(sdo_cs.transform(thr_geometry, 327680), 8307)
    else   
      sdo_cs.transform(thr_geometry, 8307)
  end as geom    
from th_threat;

但仍未启用快速刷新 .

explain_mview 的结果显示只有完全刷新是可能的,其他都被禁用(对我来说有点难以阅读/推断,我可以在请求时转储它,但它会重复三次 object data types are not supported in this context ) .

mtune_view 给了我以下错误:

QSM-03113: Cannot tune the MATERIALIZED VIEW statement

QSM-02083: mv references PL/SQL function that maintains state

所以现在我猜这是由 SDO_CS.TRANSFORM 引起的?

从理论上讲,我认为快速刷新是可能的/简单的:

  • 在插入上创建行(使用适当的转换)

  • 更新 thr_status 时的状态(或完整计算单行)

但要么我没有正确实现它,要么Oracle无法推断它实际上是一个简单的1-1物化视图(因为它包含几何?一个case语句?) .

我总是可以使用触发器来酿造我自己的解决方案,但是想知道我是否忽略了一些显而易见的东西以使材料视图有效工作(因为它看起来非常合适) . 非常感谢任何帮助/见解/评论 .

1 回答

  • 0

    你是对的 . Oracle认为它是一个复杂的查询,因为几何函数和复杂查询无法快速刷新 . 您需要进行全面刷新 . 谢谢

    萨比哈

相关问题