db2 中的 Oracle rownum - Java 数据归档

发布于 2024-08-29 02:38:00 字数 586 浏览 10 评论 0原文

我有一个 Java 数据归档过程,可以在 db2 和 sybase 之间移动数据。仅供参考 - 这不是通过任何导入/导出过程完成的,因为每个表上有几个在运行时可用的条件,因此该过程是用 java 开发的。

现在,我为每个源和目标组合定义了单个 DatabaseReader 和 DatabaseWriter,以便数据在多个线程中移动。我想我想进一步扩展它,我可以为每个源和目标组合定义多个 DatabaseReaders 和多个 DatabaseWriter。

因此,例如,如果源数据约为 100 行,并且我定义了 10 个读取器和 10 个写入器,则每个读取器将读取 10 行并将其提供给写入器。我希望进程能够根据服务器上的可用资源 [CPU、内存等] 为我提供极高的性能。

但我猜问题是这些源表没有主键,并且在多个集合中获取行非常困难。

Oracle 提供了 rownum 概念,我想那里的生活要简单得多......但是 db2 怎么样?我如何使用 db2 实现这种行为?有没有办法说先获取前 10 条记录,然后获取接下来的 10 条记录,依此类推?

有什么建议/想法吗?

DB2 版本 - DB2 v8.1.0.144 修复包数量 - 16 Linux

I have a data archiving process in java that moves data between db2 and sybase. FYI - This is not done through any import/export process because there are several conditions on each table that are available on run-time and so this process is developed in java.

Right now I have single DatabaseReader and DatabaseWriter defined for each source and destination combination so that data is moved in multiple threads. I guess I wanted to expand this further where I can have Multiple DatabaseReaders and Multiple DatabaseWriters defined for each source and destination combination.

So, for example if the source data is about 100 rows and I defined 10 readers and 10 writer, each reader will read 10 rows and give them to the writer. I hope process will give me extreme performance depending on the resources available on the server [CPU, Memory etc].

But I guess the problem is these source tables do not have primary keys and it is extremely difficult to grab rows in multiple sets.

Oracle provides rownum concept and i guess the life is much simpler there....but how about db2? How can I achieve this behavior with db2? Is there a way to say fetch first 10 records and then fetch next 10 records and so on?

Any suggestions / ideas ?

Db2 Version - DB2 v8.1.0.144
Fix Pack Num - 16
Linux

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

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

发布评论

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

评论(2

一世旳自豪 2024-09-05 02:38:00

如果我理解正确的话,您只是尝试以 10 行为一组批量写入目标表。无需将读取分批分成 10 行。

只需触发 select 语句,然后继续读取,直到用完数据。
在每 10 行,您可以调用 writer。然而,大多数 jdbc 客户端都会在幕后执行这种优化,因此这可能并不比一次插入一行更好。

我怀疑 nieve 多线程实现是否会加快速度,因为目标数据库引擎无论如何都会完成大部分工作,并且它将受到日志写入和锁定的限制,而多线程没有帮助(或更糟!)。

据我所知,简单的单线程“选择”/“插入”过程将轻松胜过您的多线程程序。还有其他方法可以对此进行优化: -

  1. 调整数据库客户端,以便批量进行网络操作。
  2. 检查“COMMIT”处理,以便在每 100 次左右插入后提交一次。

If I understand correctly you are just trying to write to the target table in batches of 10 rows. There is no need to batch the reads into 10 rows.

Just fire of the select statement then keep reading until you run out of data.
On every 10th row you can invoke the writer. However most jdbc clients will perform this sort of optimisation under the covers so this will lprobably be no better than inserting rows one at a time.

I have my doubts that a nieve multithreaded implementation will speed things up as the target database engine is doing most of the work anyway and it will be constrained by log writes and locking which multithreading does not help (or makes worse!).

As far as I can see a simple single threaded "select"/"insert" process will easily outperform your multithreaded program. There are other ways to optimise this:-

  1. Tune you database clients so that network operations are batched up.
  2. Examine you "COMMIT" processing so that you commit after every 100 or so inserts.
追风人 2024-09-05 02:38:00

DB2 确实支持 rownum 概念。不知道您的数据库架构,这是一个示例:

SELECT *
FROM (
  SELECT rownumber() OVER (order by column1, column2) AS number, column1, column2
  FROM mytable
) temp
WHERE number BETWEEN 20 AND 30

这里的子查询获取表中的每一行,并根据指定的顺序分配 rownumber 函数。 “外部”查询可以使用行号来选择批处理中实际需要的行。

DB2 does indeed support a rownum concept. Not knowing your database schema, this is an example:

SELECT *
FROM (
  SELECT rownumber() OVER (order by column1, column2) AS number, column1, column2
  FROM mytable
) temp
WHERE number BETWEEN 20 AND 30

The subquery here obtains every row in your table, and the rownumber function is assigned based on the order specified. The "outside" query can use the rownumber to select the rows that you actually want for your batches.

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