Repository navigation
fix: EmptyCollectionRewriter visits each SQL node once - #263
Merged
Merged
Conversation
The rewriter visited the children of every non-SELECT node twice, once to test the result and once to return it, so its pass over the final SQL tree took 2^depth visits. It runs on every query, ExecuteUpdate and ExecuteDelete through ValueRangesParameterBasedSqlProcessorFactory, whether or not a range or set is involved: 22 OR'd terms took 1.4 s to translate against 1 ms without the plugin. The other visitors under Query/ visit once. SqlProcessingCostTests counts visits through a counting extension node (12 levels: 12 visits, 8190 with the double visit) and translates a 40-term OR filter within a 20 s bound, which it does not finish with the double visit restored. Closes #249 Found-By: CA Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #249
Problem
EmptyCollectionRewriter(#137) visited the children of every non-SELECTnode twice:if (base.VisitExtension(node) is not SelectExpression select) return base.VisitExtension(node);. So its pass over the final SQL tree took time exponential in the tree's depth. It runs on every query,ExecuteUpdateandExecuteDelete, throughValueRangesParameterBasedSqlProcessorFactory, whether or not the query touches a range or set. A filter of 22 OR'd terms took 1.4 s against 1 ms without the plugin, and 30 or more terms effectively never compiled.Change
ExpressionVisitorunderQuery/for the same pattern.UnionNamerand the interceptor's rewriters visit once,ChildCollectorcollects direct children only, andColumnCollectorruns only once aSELECTholds an emptyVALUES.Tests
SqlProcessingCostTests(EF Core translation tests, no database):EmptyCollectionRewriter_VisitsEachNodeOncefeeds the rewriter a chain of 12 counting extension nodes and expects 12 visits. This count doesn't depend on timing.AFilterOfFortyOredTerms_Translates_InAboutAMillisecondPerTermtranslates 40 OR'd non-foldable predicates throughToQueryStringwithin a 20 s bound. The wait is bounded, so with the bug the test fails instead of hanging.8190and the 40-term translation had not finished after 20 s.The EF Core translation suite (287) passes.
🤖 Generated with Claude Code