-
Notifications
You must be signed in to change notification settings - Fork 176
Skipping codegen and compile for Scan only plan #3853
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
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
import org.apache.calcite.linq4j.Enumerable; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public interface Scannable { |
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.
Nit: Add javadoc to explain
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.
done
} | ||
|
||
@Override | ||
protected Function0<CalcitePrepare> createPrepareFactory() { |
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.
Nit: Looks like this method is marked as @Deprecated
. Use withPrepareFactory() in OpenSearchDriver instead?
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.
Actually we cannot use withPrepareFactory
since withPrepareFactory
will return a Driver
instead of OpenSearchDriver
. We need the added connect()
method of OpenSearchDriver
.
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.
Em, maybe we could with casting.
try {
OpenSearchDriver driver = (OpenSearchDriver) new OpenSearchDriver().withPrepareFactory(OpenSearchPrepareImpl::new);
return driver.connect("jdbc:calcite:", info, null, typeFactory);
} catch (SQLException e) {
throw new RuntimeException(e);
}
Anyway, let' keep current createPrepareFactory()
unless it is removed in future.
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
final JavaTypeFactory typeFactory = context.getTypeFactory(); | ||
final EnumerableRel.Prefer prefer; | ||
if (elementType == Object[].class) { | ||
prefer = EnumerableRel.Prefer.ARRAY; | ||
} else { | ||
prefer = EnumerableRel.Prefer.CUSTOM; | ||
} | ||
final Convention resultConvention = | ||
enableBindable ? BindableConvention.INSTANCE : EnumerableConvention.INSTANCE; |
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 comments if copy from calcite? e.g.
// START FROM CALCITE
// END FROM CALCITE
} | ||
|
||
@Override | ||
protected PreparedResult implement(RelRoot root) { |
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.
Can we leverage BindableConvention.INSTANCE and regsiter a rule for convertion?
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.
No, Bindable and Enumerable conventions cannot work together. The resultConvention
of physical plan can only be one of them.
* Skipping codegen and compile for Scan only plan Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix explain IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix explain IT without pushdown Signed-off-by: Lantao Jin <ltjin@amazon.com> * add javadoc Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit a3cd42e) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…3866) * Skipping codegen and compile for Scan only plan (#3853) * Skipping codegen and compile for Scan only plan Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix explain IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix explain IT without pushdown Signed-off-by: Lantao Jin <ltjin@amazon.com> * add javadoc Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit a3cd42e) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Fix compile error in JDK11 Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Lantao Jin <ltjin@amazon.com>
Description
Currently, when the Calcite engine is enabled, all query plans -- regardless of their structure -- are converted to
EnumerableRel
. This means the plan is transformed into aLinq4j
Expression, generates Java code, and undergoes just-in-time (JIT) compilation before execution.For simple or fully pushdown-compatible queries (e.g.,
source=t
,source=t | where a=1
,source=t | sort a
, orsource=t | where a=1 | sort b | head 10
), the optimized plans only contain nodeEnumerableTableScan
. Despite their simplicity, these plans unnecessarily undergo code generation and dynamic compilation, introducing overhead.To reduce codegen and compilation time, we propose converting such plans to
BindableRel
instead ofEnumerableRel
. This bypasses code generation and compilation entirely, improving plan execution time by ~30% (By benchmarking the simple queries by #3822)Related Issues
Resolves #3852
Check List
--signoff
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.