|
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;
|
|
73 | 75 | import io.trino.sql.planner.SplitSourceFactory;
|
74 | 76 | import io.trino.sql.planner.SubPlan;
|
75 | 77 | import io.trino.sql.planner.optimizations.AdaptivePlanOptimizer;
|
| 78 | +import io.trino.sql.planner.optimizations.ctereuse.CteReuse; |
76 | 79 | import io.trino.sql.planner.optimizations.PlanOptimizer;
|
77 | 80 | import io.trino.sql.planner.plan.OutputNode;
|
78 | 81 | import io.trino.sql.tree.ExplainAnalyze;
|
@@ -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,8 @@ 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 | + |
506 | 514 | // fragment the plan
|
507 | 515 | SubPlan fragmentedPlan;
|
508 | 516 | try (var _ = scopedSpan(tracer, "fragment-plan")) {
|
@@ -809,6 +817,7 @@ public static class SqlQueryExecutionFactory
|
809 | 817 | private final ExchangeManagerRegistry exchangeManagerRegistry;
|
810 | 818 | private final EventDrivenTaskSourceFactory eventDrivenTaskSourceFactory;
|
811 | 819 | private final TaskDescriptorStorage taskDescriptorStorage;
|
| 820 | + private final FormatOptions formatOptions; |
812 | 821 |
|
813 | 822 | @Inject
|
814 | 823 | SqlQueryExecutionFactory(
|
@@ -841,7 +850,8 @@ public static class SqlQueryExecutionFactory
|
841 | 850 | SqlTaskManager coordinatorTaskManager,
|
842 | 851 | ExchangeManagerRegistry exchangeManagerRegistry,
|
843 | 852 | EventDrivenTaskSourceFactory eventDrivenTaskSourceFactory,
|
844 |
| - TaskDescriptorStorage taskDescriptorStorage) |
| 853 | + TaskDescriptorStorage taskDescriptorStorage, |
| 854 | + FormatOptions formatOptions) |
845 | 855 | {
|
846 | 856 | this.tracer = requireNonNull(tracer, "tracer is null");
|
847 | 857 | this.schedulerStats = requireNonNull(schedulerStats, "schedulerStats is null");
|
@@ -875,6 +885,7 @@ public static class SqlQueryExecutionFactory
|
875 | 885 | this.exchangeManagerRegistry = requireNonNull(exchangeManagerRegistry, "exchangeManagerRegistry is null");
|
876 | 886 | this.eventDrivenTaskSourceFactory = requireNonNull(eventDrivenTaskSourceFactory, "eventDrivenTaskSourceFactory is null");
|
877 | 887 | this.taskDescriptorStorage = requireNonNull(taskDescriptorStorage, "taskDescriptorStorage is null");
|
| 888 | + this.formatOptions = requireNonNull(formatOptions, "formatOptions is null"); |
878 | 889 | }
|
879 | 890 |
|
880 | 891 | @Override
|
@@ -925,7 +936,8 @@ public QueryExecution createQueryExecution(
|
925 | 936 | coordinatorTaskManager,
|
926 | 937 | exchangeManagerRegistry,
|
927 | 938 | eventDrivenTaskSourceFactory,
|
928 |
| - taskDescriptorStorage); |
| 939 | + taskDescriptorStorage, |
| 940 | + formatOptions); |
929 | 941 | }
|
930 | 942 | }
|
931 | 943 | }
|
0 commit comments