为什么在 H2 数据库上通过 getBytes(long pos, int length) 查看 BLOB 如此慢?

发布于 2024-10-16 02:59:55 字数 253 浏览 3 评论 0 原文

我有一个应用程序需要查看 blob 并获取少量字节(通过 getBytes(long pos, int length))。这些 blob 约为 30MB。当我请求靠近 blob 开头的字节时,性能是合理的。当我请求靠近 blob 末尾的字节时,性能会更差。查看源代码(JdbcBlob.java),似乎 blob 是按顺序读取的,而不是随机读取的(通过输入流)。

有人知道任何解决方法吗?我是 H2 的忠实粉丝,这个问题不会影响交易,但我认为它可以改进。

谢谢

I have an application that needs to peek into blobs get out small numbers of bytes (via getBytes(long pos, int length)). The blobs are ~30MB. When I ask for bytes near the beginning of the blob, the performance is reasonable. When I ask for bytes near the end of the blob, the performance is much worse. Looking at the source code (JdbcBlob.java) it appears that the blob is read sequentially instead of randomly (via an input stream).

Does anybody know of any workarounds? I'm a huge H2 fan and this issue isn't a deal breaker but I think it could be improved.

Thanks

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

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

发布评论

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

评论(2

放手` 2024-10-23 02:59:55

它很慢,因为H2使用InputStream并且不进行随机访问(所以你已经自己回答了这个问题)。不支持随机访问的原因是:到目前为止没有人请求此功能:-)

我认为没有简单的解决方法。需要更改H2以支持随机访问。对于 BLOB 数据,这应该相对容易;对于CLOB数据来说会更困难(因为数据以UTF-8形式存储,并且不太容易找到正确的点)。

我现在已经在路线图中添加了一个功能请求,但是如果您在不久的将来确实需要这个功能,那么恐怕您将不得不自己实现它。 H2 是开源的,欢迎提供补丁:-)

It's slow, because H2 uses an InputStream and doesn't do random access (so you have already answered the question yourself). The reason why random access it is not supported is: so far nobody requested this feature :-)

I don't think there is a simple workaround. H2 needs to be changed to support random access. For BLOB data, this should be relatively easy; for CLOB data it will be harder (because data is stored in UTF-8 form, and it's not so easy to seek to the right point).

I have now added a feature request in the roadmap, but if you really need this feature in the near future, then I'm afraid you will have to implement it yourself. H2 is open source, and patches are always welcome :-)

绝對不後悔。 2024-10-23 02:59:55

我刚刚升级到版本 1.3.166,很高兴发现这个问题已得到纠正。在我的例子中,查看斑点末端附近大约需要 500 毫秒。

现在需要 4 毫秒。

I just upgraded to version 1.3.166 and was happy to find that this issue has been corrected. Peeking near the end of the blob in my case took about 500ms.

It now takes 4ms.

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