Skip to content
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

SqlServer: Split query involving Skip without OrderBy does not work #21202

Closed
smitpatel opened this issue Jun 10, 2020 · 4 comments · Fixed by #28056
Closed

SqlServer: Split query involving Skip without OrderBy does not work #21202

smitpatel opened this issue Jun 10, 2020 · 4 comments · Fixed by #28056
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-5.0 punted-for-6.0 type-bug
Milestone

Comments

@smitpatel
Copy link
Member

smitpatel commented Jun 10, 2020

exec sp_executesql N'SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region]
FROM (
    SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
    FROM [Customers] AS [c]
    ORDER BY (SELECT 1)
    OFFSET @__p_0 ROWS
) AS [t]
ORDER BY [t].[CustomerID]',N'@__p_0 int',@__p_0=10;

exec sp_executesql N'SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [t].[CustomerID]
FROM (
    SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
    FROM [Customers] AS [c]
    ORDER BY (SELECT 1)
    OFFSET @__p_0 ROWS
) AS [t]
INNER JOIN [Orders] AS [o] ON [t].[CustomerID] = [o].[CustomerID]
ORDER BY [t].[CustomerID]',N'@__p_0 int',@__p_0=10

Generates following results
image
The first customer does not match. If instead of ORDER BY (SELECT 1) proper order is specified, it returns correct results.

This works fine in Sqlite.

@ajcvickers
Copy link
Member

/cc @roji

@lauxjpn
Copy link
Contributor

lauxjpn commented Oct 30, 2020

Doesn't work with Pomelo/MySQL as well.

@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0 Nov 5, 2020
@maumar
Copy link
Contributor

maumar commented Sep 4, 2021

@smitpatel add deterministic orderby when we can and/or disable this scenario for split otherwise?

@smitpatel
Copy link
Member Author

Since this gives incorrect results, we should throw an error in this case rather than letting query run. It is not test issue of non-deterministic ordering.

@maumar maumar assigned smitpatel and unassigned maumar Sep 10, 2021
@smitpatel smitpatel removed this from the 6.0.0 milestone Sep 10, 2021
@AndriySvyryd AndriySvyryd added this to the MQ milestone Sep 14, 2021
@AndriySvyryd AndriySvyryd modified the milestones: MQ, Backlog Sep 15, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Nov 10, 2021
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 18, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-5.0 punted-for-6.0 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants