-
Notifications
You must be signed in to change notification settings - Fork 63
Fix LIMIT
clause execution order
#300
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #300 +/- ##
=========================================
Coverage 82.49% 82.50%
- Complexity 1218 1219 +1
=========================================
Files 157 157
Lines 9264 9263 -1
Branches 1513 1512 -1
=========================================
Hits 7642 7642
+ Misses 1170 1169 -1
Partials 452 452
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
// wrap the ExprValue to use ExprValue.equals as the equality | ||
SetQuantifier.DISTINCT -> projectedRows.filter(createUniqueExprValueFilter()) | ||
SetQuantifier.ALL -> projectedRows | ||
} | ||
|
||
if (limit != null) { | ||
quantifiedRows = quantifiedRows.take(compileLimit(limit, env)) |
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.
Since this is inside a closure that's passed to thunkFactory.thunkEnv
(line 968), the call to compileLimit
is being invoked at evaluation-time, which means the limit clause is being re-compiled once for every row--I think. At least this is being recompiled every time the query is executed. Either is a problem. Compilation should always happen once and only once.
To fix this move the compileLimit
call outside of the closure, i.e. to 967 or even higher.
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 is an important aspect of how EvaluatingCompiler
works: a significant portion of the the code in it executes at evaluation-time and not-compile time because it resides in closures (thunks) such as this one. It is important to avoid re-compiling parts of expressions within the body of a thunk.
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 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.
Need to avoid re-compiling the LIMIT clause by moving it's thunk creations outside of the body of all of its thunks.
// wrap the ExprValue to use ExprValue.equals as the equality | ||
SetQuantifier.DISTINCT -> projectedRows.filter(createUniqueExprValueFilter()) | ||
SetQuantifier.ALL -> projectedRows | ||
} | ||
|
||
if (limit != null) { | ||
quantifiedRows = quantifiedRows.take(compileLimit(limit, env)) |
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 is an important aspect of how EvaluatingCompiler
works: a significant portion of the the code in it executes at evaluation-time and not-compile time because it resides in closures (thunks) such as this one. It is important to avoid re-compiling parts of expressions within the body of a thunk.
val registers = createRegisterBank() | ||
|
||
// note: the group key can be anything here because we only ever have a single | ||
// group when aggregates are used without GROUP BY expression | ||
val syntheticGroup = Group(valueFactory.nullValue, registers) | ||
|
||
if (limit != null) { | ||
fromProductions = fromProductions.take(compileLimit(limit, env)) |
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.
Move compileLimit
outside of thunk body.
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.
Codecov Report
@@ Coverage Diff @@
## master #300 +/- ##
=========================================
Coverage ? 82.39%
Complexity ? 1228
=========================================
Files ? 157
Lines ? 9359
Branches ? 1524
=========================================
Hits ? 7711
Misses ? 1190
Partials ? 458
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Fixes #281
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.