4

I wanted to ask how you guys in general use batch-size within the mappings. Do you in general set a certain number on any mapped collection? Of course, I do know about the other fetching strategies like join fetch, but sometimes I have to filter during post processing, which might trigger lot's of lazy loading. I figured out if I set the batch-size e.g. to 100, I have much better performance in such cases.

Do you set this property in general on any mapped collection? If not, why not? Could there be any disadvantage?

4

1 回答 1

4

在集合或父实体上设置batch-size几乎可以做同样的事情。

batch-size真正在做的是将问题SELECT N+1转化为SELECT N/batch-size + 1条件。

有一个缺点,那就是您需要平衡设置正确数字之间的差异。如果batch-size 太大,会加载太多数据,如果太小,仍然会有太多查询。你如何平衡这一点是有争议的,如果不设置测试是不可能衡量的。

我认为这是一个微优化,很重要,因为它可以真正减少 select/n+1 问题。然而,它确实不如为每个场景独立选择正确的获取策略重要,这使得整体策略更好。

我也认为这是一个生产问题,应该针对真实用户针对真实数据进行测试。

附带说明一下,我总是将 my 设置batch-size为等于我的分页大小,不要问我为什么感觉很好!

于 2012-04-26T11:28:00.920 回答