Skip to content

[release/7.0] Fix to #29638 - GroupBy generates invalid SQL when using custom database function - #31743

Merged
wtgodbe merged 1 commit into
release/7.0from
fix29638_70
Oct 4, 2023
Merged

[release/7.0] Fix to #29638 - GroupBy generates invalid SQL when using custom database function#31743
wtgodbe merged 1 commit into
release/7.0from
fix29638_70

Conversation

@maumar

@maumar maumar commented Sep 14, 2023

Copy link
Copy Markdown
Contributor

Port of #30617
Fixes #29638

Description

Problem is that CloningExpressionVisitor doesn't have proper handling for TableValuedFunctionExpression, and therefore goes through default expression visitor pattern (visit all children, check if there are any changes, if there are return new, if not return the same). Since there are no changes, the same instance is returned from cloning, and causes the problem. Fix is to add proper handling of TVFExpression in the CloningExpressionVisitor so that it produces a proper copy.

Customer impact

Incorrect sql generated for queries using group by with custom database function. We generate incorrect aliases so is some cases data corruption is possible, although unlikely.

How found

Customer report on 7.0

Regression

No. The scenario also fails on 6.0

Testing

Added regression tests for affected scenarios.

Risk

Small: Fix potentially affects all scenarios that use clone mechanism on a TVF. The previous cloning behavior for TVF was incorrect, never generating a close but returning the same instance instead. The fix is not only isolated to the group by, so slightly higher risk than other, super isolated cases EF query patch fixes, but the chance of breaking other scenarios is low. We would have to rely on incorrect cloning behavior to begin with. Also added quirk to revert to old behavior if necessary.

@maumar
maumar requested review from ajcvickers and roji September 14, 2023 20:30
@maumar

maumar commented Sep 14, 2023

Copy link
Copy Markdown
Contributor Author

@ajcvickers to decide if we should go ahead with this for patching

…ase function

Problem is that CloningExpressionVisitor doesn't have proper handling for TableValuedFunctionExpression, and therefore goes through default expression visitor pattern (visit all children, check if there are any changes, if there are return new, if not return the same). Since there are no changes, the same instance is returned from cloning, and causes the problem. Fix is to add proper handling of TVFExpression in the CloningExpressionVisitor so that it produces a proper copy.

Fixes #29638
@ajcvickers

Copy link
Copy Markdown
Contributor

@maumar Let's discuss next triage whether to service. If we decide to do this in 7, then we should also consider 6.

@maumar maumar changed the title Fix to #29638 - GroupBy generates invalid SQL when using custom database function [release/7.0]] Fix to #29638 - GroupBy generates invalid SQL when using custom database function Sep 15, 2023
@maumar maumar changed the title [release/7.0]] Fix to #29638 - GroupBy generates invalid SQL when using custom database function [release/7.0] Fix to #29638 - GroupBy generates invalid SQL when using custom database function Sep 15, 2023
@ajcvickers ajcvickers added this to the 7.0.x milestone Sep 22, 2023
@rbhanda rbhanda modified the milestones: 7.0.x, 7.0.13 Sep 26, 2023
@wtgodbe
wtgodbe merged commit 4be0967 into release/7.0 Oct 4, 2023
@wtgodbe
wtgodbe deleted the fix29638_70 branch October 4, 2023 16:17
@ajcvickers ajcvickers removed this from the 7.0.13 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants