-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Allow predicate pushdown after aggregation pushdown #6007
Allow predicate pushdown after aggregation pushdown #6007
Conversation
89582f3
to
7208a55
Compare
// handle's aggregations are applied after constraint, so we cannot apply filter if aggregates is already set | ||
// TODO (https://github.com/prestosql/presto/issues/4112) allow filter pushdown after aggregation pushdown | ||
return Optional.empty(); | ||
if (constraint.getSummary().getDomains().isEmpty()) { |
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.
if (constraint.getSummary().getDomains().isEmpty()) { | |
if (constraint.getSummary().isNone()) { |
return Optional.empty(); | ||
} | ||
|
||
Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().get(); |
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.
Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().get(); | |
Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().orElseThrow(); |
boolean canPushDown = domains.keySet().stream().allMatch(predicateColumn -> | ||
groupingSets.stream().allMatch(group -> group.contains(predicateColumn))); |
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.
i think we can pushdown if all the constraint columns are fully contained by every grouping set.
it's not testable right now, since the SPI supoports grouping set pushdown, but the engine actually does not yet
i propose
Set<ColumnHandle> constraintColumns = constraint.getSummary().getDomains().orElseThrow().keySet();
List<List<JdbcColumnHandle>> groupingSets = handle.getGroupingSets().get();
verify(!groupingSets.isEmpty());
boolean canPushDown = groupingSets.stream()
.allMatch(groupingSet -> isContainedBy(constraintColumns, groupingSet));
private static boolean isContainedBy(Set<ColumnHandle> searchedFor, List<JdbcColumnHandle> container)
{
if (searchedFor.size() < 3) {
return container.containsAll(searchedFor);
}
return ImmutableSet.copyOf(container).containsAll(searchedFor);
}
(we can also consider the method overkill and just do the defensive version inline)
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.
If I'm reading this correctly the conditions are the same. Right? Every constraint column must be in every group set.
What's the motivation for the defensive version, with the copy?
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.
What's the motivation for the defensive version, with the copy?
avoid O(m*n) when long group by (m) and many predicated column (n)
If I'm reading this correctly the conditions are the same.
correct. i read the initial code incorrectly though
Comments addressed |
ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers")); | ||
ConnectorTableHandle aggregatedTable = applyCountAggregation(session, baseTableHandle, groupByColumn); | ||
|
||
Domain domain = Domain.singleValue(BIGINT, 123L); |
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.
Add a case with two grouping sets (a, b) and (a) and predicate on column (b) only. No predicate pushdown should occur
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.
I had to set supportsGroupingSets
to true in TestingH2JdbcClient
to add that case, might break some other tests?
Edit: Seems fine
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.
Edit: Seems fine
surprising to me, will take a look
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.
i think i was adding the flag because h2 did not support GROUPING SETS; OTOH tests currently cannot exploit this fact, as engine doesn't push grouping sets yet.
Yet, h2 version did not change, so it may be h2 still doesn't support this.
Maybe instead of changing the return type of supportsGroupingSets
, just use a "mock" jdbc client in the TestJdbcMetadata
test?
By "mock" i mean a ForwardingJdbcClient
delegating to database.getJdbcClient()
, but overriding supportsGroupingSets
?
This way you'd avoid making a false statement in the io.prestosql.plugin.jdbc.TestingH2JdbcClient#supportsGroupingSets
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.
Sounds good. Updated.
5f7760c
to
5e6777b
Compare
@@ -37,7 +37,7 @@ public TestingH2JdbcClient(BaseJdbcConfig config, ConnectionFactory connectionFa | |||
@Override | |||
public boolean supportsGroupingSets() | |||
{ | |||
return false; | |||
return 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.
remove the overrride, as the default is (and will be) 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.
see however #6007 (comment)
ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers")); | ||
ConnectorTableHandle aggregatedTable = applyCountAggregation(session, baseTableHandle, groupByColumn); | ||
|
||
Domain domain = Domain.singleValue(BIGINT, 123L); |
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.
Edit: Seems fine
surprising to me, will take a look
5e6777b
to
32bf131
Compare
32bf131
to
c9ff336
Compare
Predicates pushed down after aggregations must be on group by keys
c9ff336
to
fce761c
Compare
Merged, thanks! |
Predicates pushed down after aggregations must be on group by keys.
#4112