-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(mssql/query-generation): fix duplicate columns in ORDER BY statement #9173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mssql/query-generation): fix duplicate columns in ORDER BY statement #9173
Conversation
b8c241f to
2c67400
Compare
…ent for limit/offset queries
2c67400 to
f4d97a3
Compare
|
This should fix #6706 as well |
|
@sushantdhiman , @hisorange what do you think, how can I improve this? |
sushantdhiman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link me the issue which this PR is trying to fix?
Fix LGTM, but this will need a integration test
|
i had test,This pull request fix #9008 as well |
|
@sushantdhiman can you please review this pull request,i test this in my project and all work fine,and this pull will not change coverage,anything else we should do to improve this? thanks! |
|
I have reviewed this PR, it needs a test to prevent regression |
|
@sushantdhiman sorry for bothering you too frequently, and thanks for maintaining this awesome tool. 👍 |
Exactly, this will prevent future regressions
|
|
@balazsnemeth Thanks for your fix and @lerit thanks for your SSCCE, I have used both to fix this issue #9307 , this will be released in next v5 beta release |
Pull Request check-list
npm run testornpm run test-DIALECTpass with this change (including linting)?The
DIALECT=mssql npm run test-docker-integrationpass with this change (including linting).Description of change
Query:
Wrong generated mssql sql:
SELECT [PullDetail].[Id], [PullDetail].[PullId], [PullDetail].[SkuId], [PullDetail].[MoldsPulled], [PullDetail].[UnitWasteCollected], [PullDetail].[JumboBoxesFromSheet], [PullDetail].[BigBoxesFromSheet], [PullDetail].[SmallBoxesFromSheet], [PullDetail].[EachFromSheet], [PullDetail].[JumboBoxes], [PullDetail].[BigBoxes], [PullDetail].[SmallBoxes], [PullDetail].[Each], [PullDetail].[QtyBoxJumbo], [PullDetail].[QtyBoxBig], [PullDetail].[QtyBoxSmall], [PullDetail].[Variance], [PullDetail].[RowVersion], [PullDetail].[TimeZoneId], [PullDetail].[CreatedById], [PullDetail].[CreatedOn], [PullDetail].[CreatedOnServer], [PullDetail].[ModifiedById], [PullDetail].[ModifiedOn], [PullDetail].[ModifiedOnServer], [PullDetail].[OwnerId], [Pull].[Id] AS [Pull.Id], [Pull].[Name] AS [Pull.Name], [Pull].[Day] AS [Pull.Day], [Pull].[Shift] AS [Pull.Shift], [Pull].[StatusId] AS [Pull.StatusId], [Pull].[FileId] AS [Pull.FileId], [Pull].[FileWebUrl] AS [Pull.FileWebUrl], [Pull].[RowVersion] AS [Pull.RowVersion], [Pull].[TimeZoneId] AS [Pull.TimeZoneId], [Pull].[CreatedById] AS [Pull.CreatedById], [Pull].[CreatedOn] AS [Pull.CreatedOn], [Pull].[CreatedOnServer] AS [Pull.CreatedOnServer], [Pull].[ModifiedById] AS [Pull.ModifiedById], [Pull].[ModifiedOn] AS [Pull.ModifiedOn], [Pull].[ModifiedOnServer] AS [Pull.ModifiedOnServer], [Pull].[OwnerId] AS [Pull.OwnerId], [Pull->Status].[Id] AS [Pull.Status.Id], [Pull->Status].[Code] AS [Pull.Status.Code], [Pull->Status].[Name] AS [Pull.Status.Name], [Pull->Status].[TimeZoneId] AS [Pull.Status.TimeZoneId], [Pull->Status].[CreatedById] AS [Pull.Status.CreatedById], [Pull->Status].[CreatedOn] AS [Pull.Status.CreatedOn], [Pull->Status].[CreatedOnServer] AS [Pull.Status.CreatedOnServer], [Pull->Status].[ModifiedById] AS [Pull.Status.ModifiedById], [Pull->Status].[ModifiedOn] AS [Pull.Status.ModifiedOn], [Pull->Status].[ModifiedOnServer] AS [Pull.Status.ModifiedOnServer], [Pull->Status].[OwnerId] AS [Pull.Status.OwnerId], [TimeZone].[Id] AS [TimeZone.Id], [TimeZone].[Name] AS [TimeZone.Name], [TimeZone].[UTCOffset] AS [TimeZone.UTCOffset], [CreatedBy].[Id] AS [CreatedBy.Id], [CreatedBy].[UserName] AS [CreatedBy.UserName], [CreatedBy].[Salary_Value] AS [CreatedBy.Salary_Value], [CreatedBy].[Salary_Base] AS [CreatedBy.Salary_Base], [CreatedBy].[Password] AS [CreatedBy.Password], [CreatedBy].[CurrencyId] AS [CreatedBy.CurrencyId], [CreatedBy].[ExchangeRate] AS [CreatedBy.ExchangeRate], [CreatedBy].[DeletedOn] AS [CreatedBy.DeletedOn], [CreatedBy].[FirstName] AS [CreatedBy.FirstName], [CreatedBy].[LastName] AS [CreatedBy.LastName], [CreatedBy].[RowVersion] AS [CreatedBy.RowVersion], [CreatedBy].[TimeZoneId] AS [CreatedBy.TimeZoneId], [CreatedBy].[CreatedById] AS [CreatedBy.CreatedById], [CreatedBy].[CreatedOn] AS [CreatedBy.CreatedOn], [CreatedBy].[CreatedOnServer] AS [CreatedBy.CreatedOnServer], [CreatedBy].[ModifiedById] AS [CreatedBy.ModifiedById], [CreatedBy].[ModifiedOn] AS [CreatedBy.ModifiedOn], [CreatedBy].[ModifiedOnServer] AS [CreatedBy.ModifiedOnServer], [CreatedBy].[OwnerId] AS [CreatedBy.OwnerId], [ModifiedBy].[Id] AS [ModifiedBy.Id], [ModifiedBy].[UserName] AS [ModifiedBy.UserName], [ModifiedBy].[Salary_Value] AS [ModifiedBy.Salary_Value], [ModifiedBy].[Salary_Base] AS [ModifiedBy.Salary_Base], [ModifiedBy].[Password] AS [ModifiedBy.Password], [ModifiedBy].[CurrencyId] AS [ModifiedBy.CurrencyId], [ModifiedBy].[ExchangeRate] AS [ModifiedBy.ExchangeRate], [ModifiedBy].[DeletedOn] AS [ModifiedBy.DeletedOn], [ModifiedBy].[FirstName] AS [ModifiedBy.FirstName], [ModifiedBy].[LastName] AS [ModifiedBy.LastName], [ModifiedBy].[RowVersion] AS [ModifiedBy.RowVersion], [ModifiedBy].[TimeZoneId] AS [ModifiedBy.TimeZoneId], [ModifiedBy].[CreatedById] AS [ModifiedBy.CreatedById], [ModifiedBy].[CreatedOn] AS [ModifiedBy.CreatedOn], [ModifiedBy].[CreatedOnServer] AS [ModifiedBy.CreatedOnServer], [ModifiedBy].[ModifiedById] AS [ModifiedBy.ModifiedById], [ModifiedBy].[ModifiedOn] AS [ModifiedBy.ModifiedOn], [ModifiedBy].[ModifiedOnServer] AS [ModifiedBy.ModifiedOnServer], [ModifiedBy].[OwnerId] AS [ModifiedBy.OwnerId], [Owner].[Id] AS [Owner.Id], [Owner].[UserName] AS [Owner.UserName], [Owner].[Salary_Value] AS [Owner.Salary_Value], [Owner].[Salary_Base] AS [Owner.Salary_Base], [Owner].[Password] AS [Owner.Password], [Owner].[CurrencyId] AS [Owner.CurrencyId], [Owner].[ExchangeRate] AS [Owner.ExchangeRate], [Owner].[DeletedOn] AS [Owner.DeletedOn], [Owner].[FirstName] AS [Owner.FirstName], [Owner].[LastName] AS [Owner.LastName], [Owner].[RowVersion] AS [Owner.RowVersion], [Owner].[TimeZoneId] AS [Owner.TimeZoneId], [Owner].[CreatedById] AS [Owner.CreatedById], [Owner].[CreatedOn] AS [Owner.CreatedOn], [Owner].[CreatedOnServer] AS [Owner.CreatedOnServer], [Owner].[ModifiedById] AS [Owner.ModifiedById], [Owner].[ModifiedOn] AS [Owner.ModifiedOn], [Owner].[ModifiedOnServer] AS [Owner.ModifiedOnServer], [Owner].[OwnerId] AS [Owner.OwnerId] FROM [CreativeMines].[PullDetail] AS [PullDetail] LEFT OUTER JOIN ( [CreativeMines].[Pull] AS [Pull] INNER JOIN [CreativeMines].[PullStatus] AS [Pull->Status] ON [Pull].[StatusId] = [Pull->Status].[Id] AND [Pull->Status].[Name] = N'New' ) ON [PullDetail].[PullId] = [Pull].[Id] LEFT OUTER JOIN [MetaBase].[TimeZone] AS [TimeZone] ON [PullDetail].[TimeZoneId] = [TimeZone].[Id] LEFT OUTER JOIN [MetaBase].[User] AS [CreatedBy] ON [PullDetail].[CreatedById] = [CreatedBy].[Id] LEFT OUTER JOIN [MetaBase].[User] AS [ModifiedBy] ON [PullDetail].[ModifiedById] = [ModifiedBy].[Id] LEFT OUTER JOIN [MetaBase].[User] AS [Owner] ON [PullDetail].[OwnerId] = [Owner].[Id] WHERE [PullDetail].[RowVersion] >= 2 ORDER BY [Pull->Status].[Name] DESC ORDER BY [PullDetail].[Id] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;
(Observe the two OrderBy clause at the end).
After the fix, the produces SQL:
SELECT [PullDetail].[Id], [PullDetail].[PullId], [PullDetail].[SkuId], [PullDetail].[MoldsPulled], [PullDetail].[UnitWasteCollected], [PullDetail].[JumboBoxesFromSheet], [PullDetail].[BigBoxesFromSheet], [PullDetail].[SmallBoxesFromSheet], [PullDetail].[EachFromSheet], [PullDetail].[JumboBoxes], [PullDetail].[BigBoxes], [PullDetail].[SmallBoxes], [PullDetail].[Each], [PullDetail].[QtyBoxJumbo], [PullDetail].[QtyBoxBig], [PullDetail].[QtyBoxSmall], [PullDetail].[Variance], [PullDetail].[RowVersion], [PullDetail].[TimeZoneId], [PullDetail].[CreatedById], [PullDetail].[CreatedOn], [PullDetail].[CreatedOnServer], [PullDetail].[ModifiedById], [PullDetail].[ModifiedOn], [PullDetail].[ModifiedOnServer], [PullDetail].[OwnerId], [Pull].[Id] AS [Pull.Id], [Pull].[Name] AS [Pull.Name], [Pull].[Day] AS [Pull.Day], [Pull].[Shift] AS [Pull.Shift], [Pull].[StatusId] AS [Pull.StatusId], [Pull].[FileId] AS [Pull.FileId], [Pull].[FileWebUrl] AS [Pull.FileWebUrl], [Pull].[RowVersion] AS [Pull.RowVersion], [Pull].[TimeZoneId] AS [Pull.TimeZoneId], [Pull].[CreatedById] AS [Pull.CreatedById], [Pull].[CreatedOn] AS [Pull.CreatedOn], [Pull].[CreatedOnServer] AS [Pull.CreatedOnServer], [Pull].[ModifiedById] AS [Pull.ModifiedById], [Pull].[ModifiedOn] AS [Pull.ModifiedOn], [Pull].[ModifiedOnServer] AS [Pull.ModifiedOnServer], [Pull].[OwnerId] AS [Pull.OwnerId], [Pull->Status].[Id] AS [Pull.Status.Id], [Pull->Status].[Code] AS [Pull.Status.Code], [Pull->Status].[Name] AS [Pull.Status.Name], [Pull->Status].[TimeZoneId] AS [Pull.Status.TimeZoneId], [Pull->Status].[CreatedById] AS [Pull.Status.CreatedById], [Pull->Status].[CreatedOn] AS [Pull.Status.CreatedOn], [Pull->Status].[CreatedOnServer] AS [Pull.Status.CreatedOnServer], [Pull->Status].[ModifiedById] AS [Pull.Status.ModifiedById], [Pull->Status].[ModifiedOn] AS [Pull.Status.ModifiedOn], [Pull->Status].[ModifiedOnServer] AS [Pull.Status.ModifiedOnServer], [Pull->Status].[OwnerId] AS [Pull.Status.OwnerId], [TimeZone].[Id] AS [TimeZone.Id], [TimeZone].[Name] AS [TimeZone.Name], [TimeZone].[UTCOffset] AS [TimeZone.UTCOffset], [CreatedBy].[Id] AS [CreatedBy.Id], [CreatedBy].[UserName] AS [CreatedBy.UserName], [CreatedBy].[Salary_Value] AS [CreatedBy.Salary_Value], [CreatedBy].[Salary_Base] AS [CreatedBy.Salary_Base], [CreatedBy].[Password] AS [CreatedBy.Password], [CreatedBy].[CurrencyId] AS [CreatedBy.CurrencyId], [CreatedBy].[ExchangeRate] AS [CreatedBy.ExchangeRate], [CreatedBy].[DeletedOn] AS [CreatedBy.DeletedOn], [CreatedBy].[FirstName] AS [CreatedBy.FirstName], [CreatedBy].[LastName] AS [CreatedBy.LastName], [CreatedBy].[RowVersion] AS [CreatedBy.RowVersion], [CreatedBy].[TimeZoneId] AS [CreatedBy.TimeZoneId], [CreatedBy].[CreatedById] AS [CreatedBy.CreatedById], [CreatedBy].[CreatedOn] AS [CreatedBy.CreatedOn], [CreatedBy].[CreatedOnServer] AS [CreatedBy.CreatedOnServer], [CreatedBy].[ModifiedById] AS [CreatedBy.ModifiedById], [CreatedBy].[ModifiedOn] AS [CreatedBy.ModifiedOn], [CreatedBy].[ModifiedOnServer] AS [CreatedBy.ModifiedOnServer], [CreatedBy].[OwnerId] AS [CreatedBy.OwnerId], [ModifiedBy].[Id] AS [ModifiedBy.Id], [ModifiedBy].[UserName] AS [ModifiedBy.UserName], [ModifiedBy].[Salary_Value] AS [ModifiedBy.Salary_Value], [ModifiedBy].[Salary_Base] AS [ModifiedBy.Salary_Base], [ModifiedBy].[Password] AS [ModifiedBy.Password], [ModifiedBy].[CurrencyId] AS [ModifiedBy.CurrencyId], [ModifiedBy].[ExchangeRate] AS [ModifiedBy.ExchangeRate], [ModifiedBy].[DeletedOn] AS [ModifiedBy.DeletedOn], [ModifiedBy].[FirstName] AS [ModifiedBy.FirstName], [ModifiedBy].[LastName] AS [ModifiedBy.LastName], [ModifiedBy].[RowVersion] AS [ModifiedBy.RowVersion], [ModifiedBy].[TimeZoneId] AS [ModifiedBy.TimeZoneId], [ModifiedBy].[CreatedById] AS [ModifiedBy.CreatedById], [ModifiedBy].[CreatedOn] AS [ModifiedBy.CreatedOn], [ModifiedBy].[CreatedOnServer] AS [ModifiedBy.CreatedOnServer], [ModifiedBy].[ModifiedById] AS [ModifiedBy.ModifiedById], [ModifiedBy].[ModifiedOn] AS [ModifiedBy.ModifiedOn], [ModifiedBy].[ModifiedOnServer] AS [ModifiedBy.ModifiedOnServer], [ModifiedBy].[OwnerId] AS [ModifiedBy.OwnerId], [Owner].[Id] AS [Owner.Id], [Owner].[UserName] AS [Owner.UserName], [Owner].[Salary_Value] AS [Owner.Salary_Value], [Owner].[Salary_Base] AS [Owner.Salary_Base], [Owner].[Password] AS [Owner.Password], [Owner].[CurrencyId] AS [Owner.CurrencyId], [Owner].[ExchangeRate] AS [Owner.ExchangeRate], [Owner].[DeletedOn] AS [Owner.DeletedOn], [Owner].[FirstName] AS [Owner.FirstName], [Owner].[LastName] AS [Owner.LastName], [Owner].[RowVersion] AS [Owner.RowVersion], [Owner].[TimeZoneId] AS [Owner.TimeZoneId], [Owner].[CreatedById] AS [Owner.CreatedById], [Owner].[CreatedOn] AS [Owner.CreatedOn], [Owner].[CreatedOnServer] AS [Owner.CreatedOnServer], [Owner].[ModifiedById] AS [Owner.ModifiedById], [Owner].[ModifiedOn] AS [Owner.ModifiedOn], [Owner].[ModifiedOnServer] AS [Owner.ModifiedOnServer], [Owner].[OwnerId] AS [Owner.OwnerId] FROM [CreativeMines].[PullDetail] AS [PullDetail] LEFT OUTER JOIN ( [CreativeMines].[Pull] AS [Pull] INNER JOIN [CreativeMines].[PullStatus] AS [Pull->Status] ON [Pull].[StatusId] = [Pull->Status].[Id] AND [Pull->Status].[Name] = N'New' ) ON [PullDetail].[PullId] = [Pull].[Id] LEFT OUTER JOIN [MetaBase].[TimeZone] AS [TimeZone] ON [PullDetail].[TimeZoneId] = [TimeZone].[Id] LEFT OUTER JOIN [MetaBase].[User] AS [CreatedBy] ON [PullDetail].[CreatedById] = [CreatedBy].[Id] LEFT OUTER JOIN [MetaBase].[User] AS [ModifiedBy] ON [PullDetail].[ModifiedById] = [ModifiedBy].[Id] LEFT OUTER JOIN [MetaBase].[User] AS [Owner] ON [PullDetail].[OwnerId] = [Owner].[Id] WHERE [PullDetail].[RowVersion] >= 2 ORDER BY [Pull->Status].[Name] DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;