Oracle SQL Update 查询需要几天时间才能更新

发布于 2024-09-03 07:48:10 字数 252 浏览 2 评论 0原文

我正在尝试根据来自源的记录更新目标表中的记录。例如,如果传入记录存在于目标表中,我将在目标表中更新它们,否则我将简单地插入。我的源中有超过 100 万条记录,而我的目标有 4600 万条记录。目标表根据日历键进行分区。我使用 Informatica 实现了整个逻辑。我发现 Informatica 代码在查看 Informatica 会话日志时完全没问题,但更新需要很长时间(更新 100 万条记录需要 5 天以上)。

关于在该场景中可以采取哪些措施来提高性能有什么建议吗?

I am trying to update a record in the target table based on the record coming in from source. For instance, if the incoming record is present in the target table I would update them in the target else I would simply insert. I have over one million records in my source while my target has 46 million records. The target table is partitioned based on calendar key. I implement this whole logic using Informatica. I find that the Informatica code is perfectly fine looking at the Informatica session log but its in the update it takes long time (more than 5 days to update one million records).

Any suggestions as to what can be done on the scenario to improve the performance?

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

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

发布评论

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

评论(2

轻许诺言 2024-09-10 07:48:10

你可以试试这个

  1  MERGE
  2     INTO  target_table tgt
  3     USING source_table src
  4     ON  ( src.object_id = tgt.object_id )
  5  WHEN MATCHED
  6  THEN
  7     UPDATE
  8     SET   tgt.object_name = src.object_name
  9     ,     tgt.object_type = src.object_type
 10  WHEN NOT MATCHED
 11  THEN
 12     INSERT ( tgt.object_id
 13            , tgt.object_name
 14            , tgt.object_type )
 15     VALUES ( src.object_id
 16            , src.object_name
 17            , src.object_type );

语法,乍一看有点令人畏惧,但如果我们从上到下读一遍,它是相当直观的。请注意以下子句:

•MERGE(第 1 行):如前所述,这是 Oracle 中的第四条 DML 语句。我们可能希望直接添加的任何提示都遵循此关键字(即 MERGE /*+ HINT */);

•INTO(第2 行):这就是我们指定MERGE 目标的方式。目标必须是表或可更新视图(此处不能使用内联视图);

•USING(第3 行):USING 子句表示MERGE 的源数据集。这可以是单个表(如我们的示例)或内联视图;

•ON ()(第 4 行):ON 子句是我们提供源数据集和目标表之间的联接的地方。注意连接条件必须在括号内;

•WHEN MATCHED(第5行):这个子句是我们在目标表中已经有匹配记录(即源数据集和目标数据集之间存在连接)时指示Oracle做什么的地方。在这种情况下,我们显然需要更新。该子句的限制之一是我们无法更新 ON 子句中使用的任何列(当然我们不需要这样做,因为它们已经匹配)。任何包含连接列的尝试都会引发不直观的无效标识符异常; WHEN

NOT MATCHED(第10行):这个子句是我们插入当前没有匹配项的记录的地方。

You can try this

  1  MERGE
  2     INTO  target_table tgt
  3     USING source_table src
  4     ON  ( src.object_id = tgt.object_id )
  5  WHEN MATCHED
  6  THEN
  7     UPDATE
  8     SET   tgt.object_name = src.object_name
  9     ,     tgt.object_type = src.object_type
 10  WHEN NOT MATCHED
 11  THEN
 12     INSERT ( tgt.object_id
 13            , tgt.object_name
 14            , tgt.object_type )
 15     VALUES ( src.object_id
 16            , src.object_name
 17            , src.object_type );

The syntax at first looks a little daunting, but if we read through from top to bottom, it is quite intuitive. Note the following clauses:

•MERGE (line 1): as stated previously, this is now the 4th DML statement in Oracle. Any hints we might wish to add directly follow this keyword (i.e. MERGE /*+ HINT */);

•INTO (line 2): this is how we specify the target for the MERGE. The target must be either a table or an updateable view (an in-line view cannot be used here);

•USING (line 3): the USING clause represents the source dataset for the MERGE. This can be a single table (as in our example) or an in-line view;

•ON () (line 4): the ON clause is where we supply the join between the source dataset and target table. Note that the join conditions must be in parentheses;

•WHEN MATCHED (line 5): this clause is where we instruct Oracle on what to do when we already have a matching record in the target table (i.e. there is a join between the source and target datasets). We obviously want an UPDATE in this case. One of the restrictions of this clause is that we cannot update any of the columns used in the ON clause (though of course we don't need to as they already match). Any attempt to include a join column will raise an unintuitive invalid identifier exception; and

•WHEN NOT MATCHED (line 10): this clause is where we INSERT records for which there is no current match.

定格我的天空 2024-09-10 07:48:10

我不确定这如何适用于您的项目,因为您可能需要进行很多更改。由于您正在处理数百万条记录,因此我建议使用批处理作业。您可以使用 SQL Loader 实用程序。但这取决于源的格式。如果它是一个文件(例如csv文件),那么它是正确的选择。

I am not sure how this is applicable to your project since you may need to change a lot. Since you are dealing with millions on records, I would recommend a batch job. You can use SQL Loader utility. But it depends on the format of source. If it is a file(e.g. csv file), it is the right choice.

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