Invalid binary aggregation optimization regression
See original GitHub issueAfter upgrading from 2.6(.4) to 2.7(.2), a predicate interpretation/optimization problem occours when condition is in conjunctive normal form, and extra condition added in nested reverse form.
We use boolean constants to control how the predicate would behave under certain data driven scenarios. Constants are translated into SQL “1 = 1” or “1 = 0” accordingly, which is fine. The problem occours for example in cases like:
var isEmptyX = true, isEmptyY = false;
var includeZ = true, includeW = true;
(isEmptyX || x.Prop1 == [...]) && (isEmptyY || x.Prop2 == [...]) && ((includeZ && x.Field == EnumVal1) || (includeW && x.Field == EnumVal2))
The last nested past of this expression in 2.7.2 will translate into ...AND (1 == 1 AND 1 == 0 OR 1 == 1 AND Field == EnumVal2)
.
If I switch the EnumVal1
equality check with the part EnumVal2
to be the last in the predicate, then it will generate ... AND Field == Enumval1
accordingly.
Inspecting the Expression on query object it seems that parentheses dropped internally as well. This seems to be some kind of too optimistic optimization that replaces the other field access expression with constant boolean for no reason.
Setting used: Configuration.Linq.UseBinaryAggregateExpression = true
(this setting is a must for use, because some sub-system generates huge (1000+) parameter-based predicates that would cause stack overflow otherwise)
Thanks in advance.
Environment details
linq2db version: 2.7.2 Database Server: SQL Server 2017 Database Provider: SqlClient Operating system: Window 10 1804 .NET Framework: 4.7.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
@detoxhby, thanks. Wait for quick fix and bug-fix release.
It generates LinqService pair tests, this could be excluded (but generates good query though…).