Oracle - Materialized View alter structure so slow

浪尽此生 提交于 2019-12-01 19:26:04

You can't alter the definition of the query for a materialized view - you have to drop and recreate it. That said, you can try this approach, it could be faster than recreating the entire MV:

  1. Drop the materialized view, using PRESERVE TABLE.
  2. Update the data in the table that used to be the MV to reflect the new column definitions.
  3. Recreate the materialized view using the ON PREBUILT TABLE clause.

If you have indexes on the view, it may be helpful to disable and rebuild them.

5+ days to build a 2-3 million row MV? Thats waaaaay out of whack, too much to be just poor SQL. My guess is that you may be blocked by some other process(?). Not sure, but check this from a different session after you launch your MV rebuild:

select s1.username || '@' || s1.machine
  || ' ( SID=' || s1.sid || ' )  is blocking '
  || s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
  from v$lock l1, v$session s1, v$lock l2, v$session s2
  where s1.sid=l1.sid and s2.sid=l2.sid
  and l1.BLOCK=1 and l2.request > 0
  and l1.id1 = l2.id1
  and l2.id2 = l2.id2 ;

Just a guess. If you use Toad you can get this info as well (via Database->monitor->session browser). This will also show you Long Ops progress (table scans, etc).

Edit: Oh, btw, build the MV using nologging, should help a bit overall once you determine that you don't have issues stated above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!