Skip to content

Supporting filters in the left base table for join datasources - #10697

Merged
clintropolis merged 9 commits into
apache:masterfrom
abhishekagarwal87:correlated-subquery
Mar 4, 2021
Merged

clintropolis merged 9 commits into
apache:masterfrom
abhishekagarwal87:correlated-subquery

Conversation

@abhishekagarwal87

@abhishekagarwal87 abhishekagarwal87 commented Dec 21, 2020 •

Copy link
Copy Markdown
Contributor

As of now, if the left query in the JOIN has a filter present, we plan it as the join between two query data sources even if the left source is a base table. This is of course not efficient. We had even introduced some custom calcite rules so that filters on join query are not pushed into the children tables. This issue is more significant for correlated queries since the generated physical plan is a left join with a filter on the left base table. Hence, the execution of correlation queries is not efficient.
This PR adds the support for pushing filters into the left child. We would add the support for the right child in a different PR and also get rid of the custom calcite rules once that happens.
What does not work

  • Partitioning pruning based on left filter of join table

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

Key changed/added classes in this PR

@abhishekagarwal87 abhishekagarwal87 changed the title [WIP] Supporting filters in the left base table Supporting filters in the left base table for join datasources Mar 4, 2021

@clintropolis clintropolis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

public static DataSourceAnalysis forDataSource(final DataSource dataSource)
{
// Strip outer queries, retaining querySegmentSpecs as we go down (lowest will become the 'baseQuerySegmentSpec').
// Strip outer queries, retaining querySegmentSpecs as we go down (lowest will become the 'baseQuerySegmentSpec'o).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was probably an accident?

return Pair.of(dataSource, toFiltration(filter, virtualColumnRegistry));
}
//TODO: We should avoid promoting the time filter as interval for right outer and full outer joins. This is not
// donw now as we apply the intervals to left base table today irrespective of the join type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo donw -> done?

@clintropolis
clintropolis merged commit 1a15987 into apache:master Mar 4, 2021

if (left.getPartialDruidQuery().stage() == PartialDruidQuery.Stage.SELECT_PROJECT
&& left.getPartialDruidQuery().getWhereFilter() == null) {
if (left.getPartialDruidQuery().stage() == PartialDruidQuery.Stage.SELECT_PROJECT) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not work right if left is a DruidJoinQueryRel or DruidOuterQueryRel instead of a DruidQueryRel (since leftFilter is only supported for regular tables).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. good catch. will fix this.

Comment thread processing/src/main/java/org/apache/druid/query/JoinDataSource.java
@clintropolis clintropolis added this to the 0.22.0 milestone Aug 12, 2021
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
…e#10697)

* where filter left first draft

* Revert changes in calcite test

* Refactor a bit

* Fixing the Tests

* Changes

* Adding tests

* Add tests for correlated queries

* Add comment

* Fix typos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants