-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Use boolean or aggregation in correlated exists #21422
Conversation
9d083d0
to
2c2461c
Compare
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
@@ -143,7 +141,7 @@ private Optional<PlanNode> rewriteToNonDefaultAggregation(ApplyNode applyNode, C | |||
Symbol exists = getOnlyElement(applyNode.getSubqueryAssignments().keySet()); | |||
Assignments.Builder assignments = Assignments.builder() | |||
.putIdentities(applyNode.getInput().getOutputSymbols()) | |||
.put(exists, new Coalesce(ImmutableList.of(subqueryTrue.toSymbolReference(), Booleans.FALSE))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: static import -> separate commit
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Show resolved
Hide resolved
...trino/sql/planner/iterative/rule/TestTransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
@kasiafi do you want to take a look? |
b89dc45
to
d6ec139
Compare
d893121
to
7d64ca0
Compare
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
c31662c
to
0fbec15
Compare
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
2ff67c7
to
4a37220
Compare
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
4a37220
to
3c06e31
Compare
f25f754
to
916f0c0
Compare
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
@@ -200,7 +212,7 @@ public Result apply(CorrelatedJoinNode correlatedJoinNode, Captures captures, Co | |||
ImmutableList.of(), | |||
inputWithUniqueId.getOutputSymbols(), | |||
source.getOutputSymbols(), | |||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without setting this flag it directly, it is not set for left join.
Could you check why? The rule is OptimizeDuplicateInsensitiveJoins
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/sql/query/TestCorrelatedAggregation.java
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
caf353c
to
9aea658
Compare
9aea658
to
e61be97
Compare
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Outdated
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Show resolved
Hide resolved
...in/src/main/java/io/trino/sql/planner/iterative/rule/PushFilterThroughBoolOrAggregation.java
Show resolved
Hide resolved
.../io/trino/sql/planner/iterative/rule/TransformCorrelatedGlobalAggregationWithProjection.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/sql/planner/TestLogicalPlanner.java
Outdated
Show resolved
Hide resolved
Optional.empty(), | ||
SINGLE, | ||
join(INNER, builder -> builder | ||
.maySkipOutputDuplicates(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could used the new syntax in TestOptimizeDuplicateInsensitiveJoins
@@ -287,4 +289,39 @@ public void testWithPreexistingMask() | |||
.right(project(ImmutableMap.of("non_null", expression(TRUE)), | |||
values(ImmutableMap.of("a", 0, "mask", 1))))))))); | |||
} | |||
|
|||
@Test | |||
public void rewritesOnSubqueryWithBoolOr() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: testRewrites...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make naming convention inconsistent. I will make refactor
PR outside this one.
core/trino-main/src/test/java/io/trino/sql/query/TestCorrelatedAggregation.java
Outdated
Show resolved
Hide resolved
if (aggregation.getFilter().isPresent() || aggregation.getMask().isPresent()) { | ||
return Optional.empty(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably could generalize it a bit more, e.g: count
with arguments
3878135
to
e7701be
Compare
Improve performance of correlated exists by replacing count aggregation with bool_or, which reduced the need to use additional symbol with mask. As a result, aggregation can be marked as streaming and join can be marked as may skip duplicates.
Description
Improve performance of correlated exists by replacing count aggregation with bool_or,
which reduced the need to use additional symbol with mask. As a result, aggregation can be
marked as streaming and join can be marked as may skip duplicates.
after_q21.txt
before_q21.txt
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(X) Release notes are required, with the following suggested text: