Render scalar date day-split unions as a single inline UNION ALL CTE#5639
Closed
mikaelweave wants to merge 1 commit into
Closed
Render scalar date day-split unions as a single inline UNION ALL CTE#5639mikaelweave wants to merge 1 commit into
mikaelweave wants to merge 1 commit into
Conversation
Mark day-split unions produced by ScalarTemporalEqualityRewriter so SQL expression splitting keeps them as a single union expression. Add unit coverage for union marker behavior and split decisions, and port DOB/chaining E2E scenarios from the temporal rewriter union-handling branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5639 +/- ##
=======================================
Coverage ? 76.96%
=======================================
Files ? 999
Lines ? 36706
Branches ? 5554
=======================================
Hits ? 28249
Misses ? 7104
Partials ? 1353 🚀 New features to boost your workflow:
|
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.
Summary
For allow-listed scalar date searches (e.g.
birthdate=1980-01-01),ScalarTemporalEqualityRewriteremits a day-splitUnionExpressionflagged withDoNotSplitIntoSeparateCtes. Previously this either fanned out into multiple CTEs (one per branch plus an aggregating CTE) or, as a bare union, produced broken SQL. This PR renders such unions as a single CTE whose branches are combined with inlineUNION ALL.Changes
SearchParamTableExpressionExtensions):HasUnionAllExpression/SplitExpressionsnow also recognize a bareUnionExpressionpredicate (the actual runtime shape), not justAnd(union).SqlQueryGenerator):AppendNewSetOfUnionAllTableExpressionsdispatches onDoNotSplitIntoSeparateCtes; flagged unions go to a newAppendInlinedUnionAllTableExpression(single CTE, inlineUNION ALL) reusing the extractedAppendUnionAllBranchSelectbody. The non-flagged path is unchanged.SortRewriter): a union over the sort parameter is treated as a filter match (SortWithFilter), fixing a 500 forbirthdate=...&_sort=birthdate.SqlQueryGenerator): a date-overlapConcatenationnow restricts against the same predecessor as its sibling CTE, fixing a reverse-chain case (_has:...&birthdate=...) that returned 0 rows.ExpressionRewriter.VisitUnion.Tests
DateSearchTests/ChainingSearchTestsscenarios; fixed a generic-Taskcompile error inDateSearchTests.Microsoft.Health.Fhir.SqlServer.UnitTestspass on net8.0 and net9.0.