-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Materialize tables during planning #23426
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
Changes from all commits
237dbc0
b684002
7aecc32
b2fef75
c1f579a
7ffc4eb
35f5d2d
27f3691
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.sql.planner; | ||
|
|
||
| import com.google.inject.BindingAnnotation; | ||
|
|
||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.FIELD; | ||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.PARAMETER; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| @Retention(RUNTIME) | ||
| @Target({FIELD, PARAMETER, METHOD}) | ||
| @BindingAnnotation | ||
| public @interface ForPlanner {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import io.trino.cost.StatsCalculator; | ||
| import io.trino.cost.TaskCountEstimator; | ||
| import io.trino.execution.TaskManagerConfig; | ||
| import io.trino.metadata.InternalNodeManager; | ||
| import io.trino.metadata.Metadata; | ||
| import io.trino.split.PageSourceManager; | ||
| import io.trino.split.SplitManager; | ||
|
|
@@ -255,6 +256,8 @@ | |
| import io.trino.sql.planner.optimizations.HashGenerationOptimizer; | ||
| import io.trino.sql.planner.optimizations.IndexJoinOptimizer; | ||
| import io.trino.sql.planner.optimizations.LimitPushDown; | ||
| import io.trino.sql.planner.optimizations.MaterializeFilteredTableScan; | ||
| import io.trino.sql.planner.optimizations.MaterializeTableScan; | ||
| import io.trino.sql.planner.optimizations.MetadataQueryOptimizer; | ||
| import io.trino.sql.planner.optimizations.OptimizerStats; | ||
| import io.trino.sql.planner.optimizations.PlanOptimizer; | ||
|
|
@@ -267,6 +270,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ExecutorService; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
|
|
@@ -281,9 +285,11 @@ public class PlanOptimizers | |
| @Inject | ||
| public PlanOptimizers( | ||
| PlannerContext plannerContext, | ||
| @ForPlanner ExecutorService executor, | ||
| TaskManagerConfig taskManagerConfig, | ||
| SplitManager splitManager, | ||
| PageSourceManager pageSourceManager, | ||
| InternalNodeManager nodeManager, | ||
| StatsCalculator statsCalculator, | ||
| ScalarStatsCalculator scalarStatsCalculator, | ||
| CostCalculator costCalculatorWithoutEstimatedExchanges, | ||
|
|
@@ -294,10 +300,12 @@ public PlanOptimizers( | |
| RuleStatsRecorder ruleStats) | ||
| { | ||
| this(plannerContext, | ||
| executor, | ||
| taskManagerConfig, | ||
| false, | ||
| splitManager, | ||
| pageSourceManager, | ||
| nodeManager, | ||
| statsCalculator, | ||
| scalarStatsCalculator, | ||
| costCalculatorWithoutEstimatedExchanges, | ||
|
|
@@ -310,10 +318,12 @@ public PlanOptimizers( | |
|
|
||
| public PlanOptimizers( | ||
| PlannerContext plannerContext, | ||
| ExecutorService executor, | ||
| TaskManagerConfig taskManagerConfig, | ||
| boolean forceSingleNode, | ||
| SplitManager splitManager, | ||
| PageSourceManager pageSourceManager, | ||
| InternalNodeManager nodeManager, | ||
| StatsCalculator statsCalculator, | ||
| ScalarStatsCalculator scalarStatsCalculator, | ||
| CostCalculator costCalculatorWithoutEstimatedExchanges, | ||
|
|
@@ -644,6 +654,10 @@ public PlanOptimizers( | |
| .add(new PushDistinctLimitIntoTableScan(plannerContext)) | ||
| .add(new PushTopNIntoTableScan(metadata)) | ||
| .add(new RewriteTableFunctionToTableScan(plannerContext)) // must run after ImplementTableFunctionSource | ||
| .add(new MaterializeFilteredTableScan(plannerContext, splitManager, pageSourceManager, nodeManager, executor)) | ||
| .add(new MaterializeTableScan(plannerContext, splitManager, pageSourceManager, nodeManager, executor)) | ||
|
Comment on lines
+657
to
+658
Member
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. This might be too early in the planning process for this optimization. Ideally, we want to delay this until after as much predicate and projection pushdown as possible has happened.
Member
Author
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. I have NO IDEA where to put this optimization. I just looked around and guessed. If you can tell me exactly where to put it, that would be great. Or if you want to take over this PR, I'm happy for that too.. |
||
| .add(new PushFilterIntoValues(plannerContext)) | ||
| .add(new ReplaceJoinOverConstantWithProject()) | ||
| .build(); | ||
| IterativeOptimizer pushIntoTableScanOptimizer = new IterativeOptimizer( | ||
| plannerContext, | ||
|
|
||
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.
5 seconds is quite long as a default, 1-2 seconds seems more reasonable