Skip to content

Commit

Permalink
Remove eliminating sort optimization
Browse files Browse the repository at this point in the history
This bit of code is making the assumption that it's safe to remove the Sort because there are no exchanges yet. However, it's forgetting the fact that the data needs to be sorted, so later when the exchange is added this expectation is broken.
  • Loading branch information
takezoe committed Oct 19, 2023
1 parent 17005ae commit 6e927b0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,18 +608,6 @@ public PlanWithProperties visitSort(SortNode node, PreferredProperties preferred
{
PlanWithProperties child = planChild(node, PreferredProperties.undistributed());

if (child.getProperties().isSingleNode()) {
// current plan so far is single node, so local properties are effectively global properties
// skip the SortNode if the local properties guarantee ordering on Sort keys
// TODO: This should be extracted as a separate optimizer once the planner is able to reason about the ordering of each operator
List<LocalProperty<Symbol>> desiredProperties = node.getOrderingScheme().toLocalProperties();

if (LocalProperties.match(child.getProperties().getLocalProperties(), desiredProperties).stream()
.noneMatch(Optional::isPresent)) {
return child;
}
}

if (isDistributedSortEnabled(session)) {
child = planChild(node, PreferredProperties.any());
// insert round robin exchange to eliminate skewness issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import static io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer;
import static io.trino.sql.planner.assertions.PlanMatchPattern.anyTree;
import static io.trino.sql.planner.assertions.PlanMatchPattern.functionCall;
import static io.trino.sql.planner.assertions.PlanMatchPattern.output;
import static io.trino.sql.planner.assertions.PlanMatchPattern.sort;
import static io.trino.sql.planner.assertions.PlanMatchPattern.specification;
import static io.trino.sql.planner.assertions.PlanMatchPattern.tableScan;
Expand All @@ -56,21 +55,6 @@ public class TestEliminateSorts
"lineitem",
ImmutableMap.of(QUANTITY_ALIAS, "quantity"));

@Test
public void testEliminateSorts()
{
@Language("SQL") String sql = "SELECT quantity, row_number() OVER (ORDER BY quantity) FROM lineitem ORDER BY quantity";

PlanMatchPattern pattern =
output(
window(windowMatcherBuilder -> windowMatcherBuilder
.specification(windowSpec)
.addFunction(functionCall("row_number", Optional.empty(), ImmutableList.of())),
anyTree(LINEITEM_TABLESCAN_Q)));

assertUnitPlan(sql, pattern);
}

@Test
public void testNotEliminateSorts()
{
Expand Down

0 comments on commit 6e927b0

Please sign in to comment.