Oracle - 物化视图改变结构太慢

发布于 2024-11-08 20:43:48 字数 444 浏览 0 评论 0原文

我有一个巨大的物质化观点,我必须调整。这是一个简单的调整,因为我只是将 NVL 函数添加到 select 语句中。

即原始...

Select this,
       that.....

即修改

Select NVL(this, orThat) as this,
       NVL(That, orThis) as that

该查询需要 26 秒才能运行,但由于检索的行数(230 万),速度非常慢。它连续运行了将近 5 天,然后我就停止了。

这是一个问题,特别是因为我需要将其交付给客户,而他们无法运行 5 天以上的脚本来创建 MV。

问:有什么办法可以加快MV的修改/重新制作速度?如果我修改MV会更快还是会和删除并重新创建一样?

Oracle 版本 = 10g

I have a huge materailized view that I have to adjust. It's a simple adjustment as I'm just adding an NVL function to the select statement.

I.e. Original...

Select this,
       that.....

I.e. Modified

Select NVL(this, orThat) as this,
       NVL(That, orThis) as that

The query takes 26 seconds to run, but due to the amount of rows retrieved (2.3 million) it is dead slow. It ran for almost 5 days straight and then I stopped it.

This is a problem, especially since I need to deliver this to a client, and they can't run a script for 5+ days to create a MV.

Question: Is there any way to speed up the altering/recreation of a MV? Would it be faster if I altered the MV or would it be around the same as dropping and recreating?

Oracle version = 10g

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我很坚强 2024-11-15 20:43:48

您无法更改物化视图的查询定义 - 您必须删除并重新创建它。也就是说,您可以尝试这种方法,它可能比重新创建整个 MV 更快:

  1. 使用 PRESERVE TABLE 删除物化视图。
  2. 更新表中曾经是 MV 的数据以反映新的列定义。
  3. 使用 ON PREBUILT TABLE 子句重新创建物化视图。

如果视图上有索引,禁用并重建它们可能会有所帮助。

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.

半葬歌 2024-11-15 20:43:48

5 天以上构建 2-300 万行 MV?这太不正常了,不仅仅是糟糕的 SQL。我的猜测是您可能被其他进程阻止(?)。不确定,但在启动 MV 重建后从另一个会话中检查这一点:

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 ;

只是猜测。如果您使用 Toad,您也可以获得此信息(通过数据库 -> 监视器 -> 会话浏览器)。这还将向您显示长时间操作的进度(表扫描等)。

编辑:哦,顺便说一句,使用 nologging 构建 MV,一旦您确定没有上述问题,总体上应该会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文