Skip to content

Commit

Permalink
Fix query failure due to unused dynamic filters
Browse files Browse the repository at this point in the history
  • Loading branch information
raunaqmorarka committed Jul 25, 2023
1 parent c43020a commit a22015d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ public PlanOptimizers(
// pushdown into the connectors. Invoke PredicatePushdown and PushPredicateIntoTableScan after this
// to leverage predicate pushdown on projected columns and to pushdown dynamic filters.
builder.add(new StatsRecordingPlanOptimizer(optimizerStats, new PredicatePushDown(plannerContext, typeAnalyzer, true, true)));
builder.add(new RemoveUnsupportedDynamicFilters(plannerContext)); // Remove unsupported dynamic filters introduced by PredicatePushdown
builder.add(new IterativeOptimizer(
plannerContext,
ruleStats,
Expand All @@ -908,6 +907,9 @@ public PlanOptimizers(
.add(new PushPredicateIntoTableScan(plannerContext, typeAnalyzer, false))
.add(new RemoveRedundantPredicateAboveTableScan(plannerContext, typeAnalyzer))
.build()));
// Remove unsupported dynamic filters introduced by PredicatePushdown. Also, cleanup dynamic filters removed by
// PushPredicateIntoTableScan and RemoveRedundantPredicateAboveTableScan due to those rules replacing table scans with empty ValuesNode
builder.add(new RemoveUnsupportedDynamicFilters(plannerContext));
builder.add(inlineProjections);
builder.add(new UnaliasSymbolReferences(metadata)); // Run unalias after merging projections to simplify projections more efficiently
builder.add(columnPruningOptimizer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.testng.annotations.Test;

import static io.airlift.testing.Closeables.closeAllSuppress;
import static io.trino.testing.TestingNames.randomNameSuffix;

public class TestDistributedFaultTolerantEngineOnlyQueries
extends AbstractDistributedEngineOnlyQueries
Expand Down Expand Up @@ -73,4 +74,27 @@ public void testSelectiveLimit()
{
// FTE mode does not terminate query when limit is reached
}

@Test
public void testIssue18383()
{
String tableName = "test_issue_18383_" + randomNameSuffix();
assertUpdate("CREATE TABLE " + tableName + " (id VARCHAR)");

assertQueryReturnsEmptyResult(
"""
WITH
t1 AS (
SELECT NULL AS address_id FROM %s i1
INNER JOIN %s i2 ON i1.id = i2.id),
t2 AS (
SELECT id AS address_id FROM %s
UNION
SELECT * FROM t1)
SELECT * FROM t2
INNER JOIN %s i ON i.id = t2.address_id
""".formatted(tableName, tableName, tableName, tableName));

assertUpdate("DROP TABLE " + tableName);
}
}

0 comments on commit a22015d

Please sign in to comment.