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

Remove redundant ORDER BY from WITH and views #18159

Merged
merged 3 commits into from Aug 4, 2023

Conversation

martint
Copy link
Member

@martint martint commented Jul 7, 2023

ORDER BY without LIMIT / OFFSET is irrelevant unless it's in the top-level query.

Alternative to #18153

Release notes

(x) Release notes are required, with the following suggested text:

# General
* Improve performance of queries containing redundant `ORDER BY` clauses in views or WITH clauses. 
   This may affect the semantics of queries that incorrectly rely on implementation-specific behavior. 
   The old behavior can be restored via the `skip_redundant_sort` session property or the 
  `optimizer.skip-redundant-sort` configuration property

Copy link
Contributor

@radek-kondziolka radek-kondziolka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

@martint martint force-pushed the redundant-order-by branch 2 times, most recently from 379b963 to 7d1d87f Compare July 8, 2023 05:41
Be intentional about whether the analyzer is being called for a top-level
statement, which does not require or expect an outer scope to exist.
The merge componenents were being planned with the scope passed
in to the method, which is empty due to merge being a top-level
statement. Technically, this is incorrect, as those components
cannot exist without an outer scope.
@@ -457,23 +457,28 @@ class StatementAnalyzer

public Scope analyze(Node node)
{
return analyze(node, Optional.empty());
return analyze(node, Optional.empty(), true);
}

public Scope analyze(Node node, Scope outerQueryScope)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider getting rid of this method and making the caller explicitly say top level or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this method implies it's not top-level (since there's an outer query scope). It's the method below that is not necessary. I'll update its usages and remove it.

Track whether the query being analyzed is at the top level
to decide whether the ORDER BY is ineffective.
@martint martint merged commit a71f59c into trinodb:master Aug 4, 2023
85 checks passed
@martint martint deleted the redundant-order-by branch August 4, 2023 15:57
@github-actions github-actions bot added this to the 423 milestone Aug 4, 2023
@mosabua
Copy link
Member

mosabua commented Aug 4, 2023

Any suggestion for release note entry @martint ? Also .. does this need doc update?

@martint
Copy link
Member Author

martint commented Aug 4, 2023

@mosabua, added it to the PR description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants