我有一个包含大约7M行的表和一个SSIS包,它使用如下语句更新该表中的5.6M行。
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="https://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<main role="main" class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</main>
然后我启动几个大型select语句,它们对MERGE INTO Target t
USING
(
select ID,
Type
from SomeTable
) s
ON (t.ID = s.ID)
WHEN MATCHED THEN UPDATE SET t.Type = s.Type
进行内连接。我从那些select语句中得到了ORA-01555(快照太旧:回滚段号字符串,名称“字符串”太小)。这看起来像MERGE语句在提交完成之前返回。我最初的想法是增加回滚段的大小(这无疑会引入完整性问题),但我们的DBA并不热衷于这个想法。他们建议我在开始选择语句之前等待1分钟。 (对我来说,与人工等待同步是一个危险信号。)
我的问题是,有没有办法确保在MERGE语句返回之前MERGE提交已经完成?对我来说,这将解决问题。
答案 0 :(得分:0)
我会避免合并整个表格(如果可能的话):
MERGE INTO Target t
USING( select ID, Type
from SomeTable
where some_kind_of_timestamp_column > date_of_last_incremental_load
) s
ON (t.ID = s.ID)
WHEN MATCHED THEN UPDATE SET t.Type = s.Type
WHERE (t.Type != s.Type)
OR (t.Type IS NULL AND s.TYPE IS NOT NULL)
OR (t.Type IS NOT NULL AND s.TYPE IS NULL)
-- there is no need for updating A -> A
COMMIT;
-- some select