-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Join context hints #17541
Join context hints #17541
Conversation
...i-stage-query/src/test/quidem/org.apache.druid.msq.quidem.MSQQuidemTest/msqNestedJoinHint.iq
Outdated
Show resolved
Hide resolved
...i-stage-query/src/test/quidem/org.apache.druid.msq.quidem.MSQQuidemTest/msqNestedJoinHint.iq
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryUtils.java
Outdated
Show resolved
Hide resolved
|
||
import java.util.Arrays; | ||
|
||
public enum JoinHint |
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 it would be better to not have this as an enum - and you could probably use as(JoinAlgorithm.class)
or asJoinAlgorithm()
to obtain the current value
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.
There's an issue with that, Calcite only seems to accept certain keywords as hints, and this is sort_merge
. Trying to replace the hint name with sortMerge
seems to make it not read by calcite.
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.
doesn't really mattter - I was just thinking something like:
public abstract class DruidHint {
abstract T as(Class<T> clazz);
public static DruidHint fromRelHint(RelHint rh) {
// factory method
}
static abstrat class DruidJoinHint extends DruidHint {}
static class SortMerge extends DruidJoinHint {
String name() { "sort_merge"; }
as() ... { return
}
}
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.
Made some changes to make it more in line with this, please take a look
@JsonCreator | ||
public static JoinHint fromString(final String id) | ||
{ |
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 don't think this should be serializable by jackson; if it gets on the wire it should be a JoinAlgorithm
already
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 it might have been to deserializer it for the planner context at some point
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 don't think this JoinHint
should be serialized
if its not in use I think it would be better to remove it
sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java
Outdated
Show resolved
Hide resolved
processing/src/main/java/org/apache/druid/query/JoinDataSource.java
Outdated
Show resolved
Hide resolved
processing/src/main/java/org/apache/druid/query/planning/PreJoinableClause.java
Outdated
Show resolved
Hide resolved
processing/src/main/java/org/apache/druid/query/JoinDataSource.java
Outdated
Show resolved
Hide resolved
...sions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/DataSourcePlan.java
Outdated
Show resolved
Hide resolved
|
||
import java.util.Arrays; | ||
|
||
public enum JoinHint |
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.
doesn't really mattter - I was just thinking something like:
public abstract class DruidHint {
abstract T as(Class<T> clazz);
public static DruidHint fromRelHint(RelHint rh) {
// factory method
}
static abstrat class DruidJoinHint extends DruidHint {}
static class SortMerge extends DruidJoinHint {
String name() { "sort_merge"; }
as() ... { return
}
}
@JsonCreator | ||
public static JoinHint fromString(final String id) | ||
{ |
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 don't think this JoinHint
should be serialized
if its not in use I think it would be better to remove it
private static HintStrategyTable createHintStrategies() | ||
{ | ||
return HintStrategyTable.builder() | ||
.hintStrategy(JoinHint.BROADCAST.name(), HintPredicates.JOIN) |
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.
is the usage of name()
intended here?
because I think that will return BROADCAST
the "name" of the enum key and not the id
!
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.
note: this method returning HintStrategyTable
could live inside DruidHint
if that's created
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.
Moved to DruidHint
|
||
public static JoinAlgorithm getJoinAlgorithm(Join join, PlannerContext plannerContext) | ||
{ | ||
RelHint closestHint = null; |
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.
note: I was thinking to use DruidJoinHint
here.. so that you can't even set closesHint to a non-join hint...but its not really important
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.
Keeping the RelHint allows keeping track the closestHint's path length, to compare in the for loop. We do have a check to see if it's a join hint in the loop so this should be fine
Rebased and addressed some issues of #17406
Currently, using the query context, all joins in a query can be hinted to either broadcast or sort merge join. However, this does not allow this to be set at a join level.
Add support for hints to queries, which can dictate the join type.
Syntax
Note
Calcite does not expose if the hint is at a particular join level, and allows inheritance of hints from parent nodes. This causes join hints to to affect inner queries. Additional join hints can be added to inner queries as a workaround.
This PR has: