Add planner support to prevent mixed CPP/Java execution#25384
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds planner support to prevent mixed CPP/Java execution by ensuring that system table scans (which run on the coordinator) are separated by an exchange from non-Java (CPP) functions that must run on workers. Key changes include updating test expectations in the native sidecar plugin, adding utility methods in RowExpressionUtils, and modifying multiple iterative rule sets (RemoveRedundantExchangeRuleSet, ExtractSystemTableFilterRuleSet, and PickTableLayout) to properly handle function eligibility and exchange boundaries.
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java | Updated test for information_schema tables to reflect new behavior |
| presto-main-base/src/main/java/com/facebook/presto/sql/relational/RowExpressionUtils.java | Added method to detect non-coordinator-eligible call expressions |
| presto-main-base/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RemoveRedundantExchangeRuleSet.java | Added rules to remove unnecessary exchanges for system table scans |
| presto-main-base/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PickTableLayout.java | Updated predicate handling to avoid partition pruning on ineligible expressions |
| presto-main-base/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ExtractSystemTableFilterRuleSet.java | Added extraction rules for system table filters |
| presto-main-base/src/main/java/com/facebook/presto/sql/planner/PlanOptimizers.java | Registered the new rules into the plan optimizer pipeline |
Comments suppressed due to low confidence (2)
presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java:199
- The test was modified from expecting a failure to asserting a successful query. Please verify that this change is intended and that the expected query result is asserted appropriately in accompanying test validations.
{
presto-main-base/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PickTableLayout.java:277
- [nitpick] It would be helpful to add an inline comment explaining the purpose of assigning TRUE_CONSTANT to ineligiblePredicate and how it interacts with the subsequent filtering logic to separate ineligible expressions.
RowExpression ineligiblePredicate = TRUE_CONSTANT;
|
Why doesn't this if-block trigger during AddExchanges and pre-add the Exchange above the System table scan - if (nativeExecution && containsSystemTableScan(plan)) {
plan = gatheringExchange(idAllocator.getNextId(), REMOTE_STREAMING, plan);
} |
|
@aaneja good feedback, it should. I designed this to ignore the nativeExecution flag, as even with nativeExecution disabled this should kick in. But it made the scope of the changes larger, so in the interest of making this PR smaller I'm working on presuming that the above rule will always kick in. |
ba5ab4f to
2a40f08
Compare
|
@aaneja I removed |
|
@tdcmeehan With So how does Are there rules after |
|
I'm wondering if it would instead make sense to set |
|
@aaneja I initially went with this approach, but found that there were rules that further pushed down projections such as |
There was a problem hiding this comment.
I'm fine with the current approach. Can you also add a plan checker, similar to (or inside of) CheckUnsupportedPrestissimoTypes to ensure that there are no nodes 'under' a coordinator-only exchange other than a TableScanNode when nativeExecution is turned on ?
In the long term, we should move the point we set the COORDINATOR_DISTRIBUTION on the Exchange partitioning handle to AddExchanges. This way we can reason about if a Project/Filter/Aggregate can be pushed through the Exchange more clearly
| ruleStats, | ||
| statsCalculator, | ||
| costCalculator, | ||
| new ExtractSystemTableFilterRuleSet(metadata.getFunctionAndTypeManager()).rules())); |
There was a problem hiding this comment.
Should we move this to L992 above the // DO NOT add optimizers that change the plan shape (computations) after this point comment
364b161 to
283327b
Compare
|
@aaneja I added the plan checker, and addressed your other feedback. Would you please take another look? |
Description
System table scans must execute on the coordinator, but CPP (native/non-Java) functions cannot run on the coordinator - they must execute on workers. When a query contains both system table scans and non-Java functions, the planner needs to ensure that there's an exchange boundary between the scan and filter/projection, and undo any filter pushdown that may have occured.
Motivation and Context
This problem was discovered during testing support of only CPP function validation, without supporting constant folding. This is an inevitable problem, as with the Presto sidecar built-in functions are now being reported as being C++, which are ineligible for execution on the coordinator.
Impact
Fix the above issue.
Test Plan
Tests have been added in this PR.
Contributor checklist