|
61 | 61 | import io.trino.sql.analyzer.Analysis;
|
62 | 62 | import io.trino.sql.analyzer.Analyzer;
|
63 | 63 | import io.trino.sql.analyzer.AnalyzerFactory;
|
| 64 | +import io.trino.sql.newir.FormatOptions; |
| 65 | +import io.trino.sql.newir.Program; |
64 | 66 | import io.trino.sql.planner.AdaptivePlanner;
|
65 | 67 | import io.trino.sql.planner.InputExtractor;
|
66 | 68 | import io.trino.sql.planner.LogicalPlanner;
|
|
74 | 76 | import io.trino.sql.planner.SubPlan;
|
75 | 77 | import io.trino.sql.planner.optimizations.AdaptivePlanOptimizer;
|
76 | 78 | import io.trino.sql.planner.optimizations.PlanOptimizer;
|
| 79 | +import io.trino.sql.planner.optimizations.ctereuse.CteReuse; |
77 | 80 | import io.trino.sql.planner.plan.OutputNode;
|
78 | 81 | import io.trino.sql.tree.ExplainAnalyze;
|
79 | 82 | import io.trino.sql.tree.Query;
|
@@ -148,6 +151,7 @@ public class SqlQueryExecution
|
148 | 151 | private final EventDrivenTaskSourceFactory eventDrivenTaskSourceFactory;
|
149 | 152 | private final TaskDescriptorStorage taskDescriptorStorage;
|
150 | 153 | private final PlanOptimizersStatsCollector planOptimizersStatsCollector;
|
| 154 | + private final FormatOptions formatOptions; |
151 | 155 |
|
152 | 156 | private SqlQueryExecution(
|
153 | 157 | PreparedQuery preparedQuery,
|
@@ -185,7 +189,8 @@ private SqlQueryExecution(
|
185 | 189 | SqlTaskManager coordinatorTaskManager,
|
186 | 190 | ExchangeManagerRegistry exchangeManagerRegistry,
|
187 | 191 | EventDrivenTaskSourceFactory eventDrivenTaskSourceFactory,
|
188 |
| - TaskDescriptorStorage taskDescriptorStorage) |
| 192 | + TaskDescriptorStorage taskDescriptorStorage, |
| 193 | + FormatOptions formatOptions) |
189 | 194 | {
|
190 | 195 | try (SetThreadName _ = new SetThreadName("Query-" + stateMachine.getQueryId())) {
|
191 | 196 | this.slug = requireNonNull(slug, "slug is null");
|
@@ -240,6 +245,7 @@ private SqlQueryExecution(
|
240 | 245 | this.eventDrivenTaskSourceFactory = requireNonNull(eventDrivenTaskSourceFactory, "taskSourceFactory is null");
|
241 | 246 | this.taskDescriptorStorage = requireNonNull(taskDescriptorStorage, "taskDescriptorStorage is null");
|
242 | 247 | this.planOptimizersStatsCollector = requireNonNull(planOptimizersStatsCollector, "planOptimizersStatsCollector is null");
|
| 248 | + this.formatOptions = requireNonNull(formatOptions, "formatOptions is null"); |
243 | 249 | }
|
244 | 250 | }
|
245 | 251 |
|
@@ -503,6 +509,9 @@ private PlanRoot doPlanQuery(CachingTableStatsProvider tableStatsProvider)
|
503 | 509 | Plan plan = logicalPlanner.plan(analysis);
|
504 | 510 | queryPlan.set(plan);
|
505 | 511 |
|
| 512 | + Optional<Program> optimizedProgram = CteReuse.reuseCommonSubqueries(plan, plannerContext, getSession(), formatOptions); |
| 513 | + checkState(optimizedProgram.isEmpty()); |
| 514 | + |
506 | 515 | // fragment the plan
|
507 | 516 | SubPlan fragmentedPlan;
|
508 | 517 | try (var _ = scopedSpan(tracer, "fragment-plan")) {
|
@@ -809,6 +818,7 @@ public static class SqlQueryExecutionFactory
|
809 | 818 | private final ExchangeManagerRegistry exchangeManagerRegistry;
|
810 | 819 | private final EventDrivenTaskSourceFactory eventDrivenTaskSourceFactory;
|
811 | 820 | private final TaskDescriptorStorage taskDescriptorStorage;
|
| 821 | + private final FormatOptions formatOptions; |
812 | 822 |
|
813 | 823 | @Inject
|
814 | 824 | SqlQueryExecutionFactory(
|
@@ -841,7 +851,8 @@ public static class SqlQueryExecutionFactory
|
841 | 851 | SqlTaskManager coordinatorTaskManager,
|
842 | 852 | ExchangeManagerRegistry exchangeManagerRegistry,
|
843 | 853 | EventDrivenTaskSourceFactory eventDrivenTaskSourceFactory,
|
844 |
| - TaskDescriptorStorage taskDescriptorStorage) |
| 854 | + TaskDescriptorStorage taskDescriptorStorage, |
| 855 | + FormatOptions formatOptions) |
845 | 856 | {
|
846 | 857 | this.tracer = requireNonNull(tracer, "tracer is null");
|
847 | 858 | this.schedulerStats = requireNonNull(schedulerStats, "schedulerStats is null");
|
@@ -875,6 +886,7 @@ public static class SqlQueryExecutionFactory
|
875 | 886 | this.exchangeManagerRegistry = requireNonNull(exchangeManagerRegistry, "exchangeManagerRegistry is null");
|
876 | 887 | this.eventDrivenTaskSourceFactory = requireNonNull(eventDrivenTaskSourceFactory, "eventDrivenTaskSourceFactory is null");
|
877 | 888 | this.taskDescriptorStorage = requireNonNull(taskDescriptorStorage, "taskDescriptorStorage is null");
|
| 889 | + this.formatOptions = requireNonNull(formatOptions, "formatOptions is null"); |
878 | 890 | }
|
879 | 891 |
|
880 | 892 | @Override
|
@@ -925,7 +937,8 @@ public QueryExecution createQueryExecution(
|
925 | 937 | coordinatorTaskManager,
|
926 | 938 | exchangeManagerRegistry,
|
927 | 939 | eventDrivenTaskSourceFactory,
|
928 |
| - taskDescriptorStorage); |
| 940 | + taskDescriptorStorage, |
| 941 | + formatOptions); |
929 | 942 | }
|
930 | 943 | }
|
931 | 944 | }
|
0 commit comments