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

Fix query failure due to unused dynamic filters #18385

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}