Too aggressive query optimization
See original GitHub issueQuery like that:
db.Table1
.Where(_ =>
db.Table2
.Where(r => r.Table1Id == _.Id)
.OrderByDescending(r => r.SomeField)
.Select(r => r.AssociationProperty.TextField)
.First()
.Contains(filterText))
Generates invalid subquery SQL without logic added by Select and Contains:
SELECT *
FROM Table1
WHERE
(
SELECT TOP (1)
*
FROM
Table2
WHERE
Table2.fk_id = table1.id
ORDER BY
Table2.SomeField DESC
)
Such query rejected by database engine (MSSQ) and miss join on association, text field selection and LIKE predicate
If you will need exact test-case to reproduce issue, I could provide it a bit later.
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Query: SubQueryMemberPushDown optimization is too ...
Query : SubQueryMemberPushDown optimization is too aggressive, which may lead to invalid sql or data corruption #8505.
Read more >Optimizer being overly aggressive
Optimizer being overly aggressive. Posted by: Adrian Cornish Date: July 06, 2012 08:18PM. I've reduced my issue down to this simple SP.
Read more >SQL Server 2012 Aggressive Over-Indexing when i run ...
In my post How to Fix sp_BlitzIndex Aggressive Indexes Warnings, I note that ... Over-indexing means your table likely has too many indexes....
Read more >How to Fix sp_BlitzIndex Aggressive Indexes Warnings
sp_BlitzIndex may report “Aggressive Indexes”, and point to the clustered index as being involved. However, that doesn't mean you need to DROP ...
Read more >An overly aggressive optimization in BLASTN and ...
It appears the bug fix in BLAST+ 2.8.1 to remove the overly aggressive optimisation in BLASTN and MegaBLAST alone fixed 9 of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Of course.
Test query
Generated SQL (invalid). Similar to one in defect but a bit different. Maybe because of different relations schema but I assume it is due to changes made to linq2db for last two years.
Also commenting
First
call produce interesting results. Contains converted to comparison instead of LIKE: