-
Notifications
You must be signed in to change notification settings - Fork 28.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
[SPARK-16174][SQL] Improve OptimizeIn
optimizer to remove literal repetitions
#13876
Changes from 9 commits
74d107d
779ade8
e99fa4a
4f54c64
6628c7b
314bc74
23d6e30
125036a
63a4a79
ccf972d
f068e4b
eead3db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -820,16 +820,24 @@ object ConstantFolding extends Rule[LogicalPlan] { | |
} | ||
|
||
/** | ||
* Replaces [[In (value, seq[Literal])]] with optimized version[[InSet (value, HashSet[Literal])]] | ||
* which is much faster | ||
* Optimize IN predicates: | ||
* 1. Removes literal repetitions. | ||
* 2. Replaces [[In (value, seq[Literal])]] with optimized version | ||
* [[InSet (value, HashSet[Literal])]] which is much faster. | ||
*/ | ||
case class OptimizeIn(conf: CatalystConf) extends Rule[LogicalPlan] { | ||
def apply(plan: LogicalPlan): LogicalPlan = plan transform { | ||
case q: LogicalPlan => q transformExpressionsDown { | ||
case In(v, list) if !list.exists(!_.isInstanceOf[Literal]) && | ||
list.size > conf.optimizerInSetConversionThreshold => | ||
val hSet = list.map(e => e.eval(EmptyRow)) | ||
InSet(v, HashSet() ++ hSet) | ||
case expr @ In(v, list) if expr.inSetConvertible => | ||
val newList = ExpressionSet(list).toSeq | ||
if (newList.size > conf.optimizerInSetConversionThreshold) { | ||
val hSet = newList.map(e => e.eval(EmptyRow)) | ||
InSet(v, HashSet() ++ hSet) | ||
} else if (newList.size < list.size) { | ||
expr.copy(value = v, list = newList) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to copy value here, do you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, it's a whole value. We had better create the expression There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry what i meant was ... we only need to do
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. My bad! |
||
} else { // newList.length == list.length | ||
expr | ||
} | ||
} | ||
} | ||
} | ||
|
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.
Oh, here is regression. Originally,
v
could be non-deterministic.