Closed letarak closed 7 months ago
Hello @letarak,
I did investigation on this problem.
First of all, each RDBMS has its own parameter limit per batch (some of them has no limit, to be fair). In this case I assume you work with MS SQL Server, which has max parameter limit - 2100 parameters per batch. Exceeding this limit throws an exception. For example, your test in DO 5.0 ends up with such exception, because maximum number of parameters in your case is 25 * 101 = 2525. Way too much. DO 5.0 batching has only batch size as incoming parameter this is why it builds batch of 25 inserts no matter what.
On certain point we decided to make batching algorithm a bit smarter to prevent sever side exception because it is waste of time, especially when number of parameters is detectable. So starting from certain versions of 6.0, DataObjects.Net has maximum number of parameters for each provider and batching mechanism can lower number of SQL requests in batch to prevent parameters overflow. In extreme cases, it can execute batches with 1 SQL request, or throw an exception if it failed to configure even 1 SQL request batch.
You can clearly see that 20 items (or 2020 parameters) were persisted despite the fact that BatchSize is 25.
Apparently, new batching has an issue. I confirm this. It will be fixed in 6.0 and merged up to master.
During investigation I tackled the problem (it seems that, need to be tested) so PR with fix will appear soon. Merging will take a while because it has new code and needs to be tested as merged, but it will appear in newer versions.
It took more time to fix new batching. This is serious issue and it's my number one priority so it will be fixed for sure.
I finally fixed this issue and some more problems with batching in PR #348
@letarak, the issue must be fixed now in 6.0, 7.0 and 7.1 branches, patched versions are released. I will close the issue after your confirmation, just to be sure. I thank you for finding this serious problem.
Confirm, on 7.1.1 it works as expected Thank you
DO 7.1.0
If insert batch query exceeded parameters limit (MSSQL ~2000) and persisted implicitly by query, elements missing in db Sample to reproduce