【发布时间】:2019-08-26 03:53:45
【问题描述】:
我正在使用 select 进行更新查询以避免多个 JVM 重复处理,并且我在 int-jdbc:inbound-channel-adapter 中有 max-row=10。
假设该表有 50,000 条记录。
spring/integration/jdbc会只锁10行还是50000行?
另外,根据文档:https://docs.spring.io/spring-integration/docs/5.2.0.M3/reference/html/jdbc.html
“建议通过供应商特定的查询选项使用结果集限制,例如 MySQL LIMIT 或 SQL Server TOP 或 Oracle 的 ROWNUM。有关详细信息,请参阅特定供应商文档。”
这意味着服务器将选择查询获取的所有记录。
<int-jdbc:inbound-channel-adapter
id="initial.poller"
query="select id from transaction where status='created'"
max-rows="10"
update="update transaction set status='processed' where ID in (:id)"
row-mapper="pollerRowMapper"
data-source="dataSource" channel="transactionChannel">
<int:poller fixed-rate="200" time-unit="MILLISECONDS">
<int:transactional />
</int:poller>
</int-jdbc:inbound-channel-adapter>
我在调试模式下检查了只有 10 行被 jvm 锁定,其他 JVM 正在获取并处理其他记录。
1) spring/hibernate 如何与 oracle 通信以仅锁定它正在挑选的 10 条记录?
2) 如果查询中必须使用 ROWNUM,max-rows 的用途是什么?
编辑 1:我们无法同时选择 update 和 rownum。 oracle 上都不允许这些:
select * from (select id from transaction where status='created' order by id) WHERE rownum <= 10 FOR UPDATE SKIP LOCKED ;
select * from (select id from transaction where status='created' order by id FOR UPDATE SKIP LOCKED) WHERE rownum <= 10 ;
如何获得性能优化?表有数百万条记录。
【问题讨论】:
标签: oracle spring-integration spring-jdbc