33
33
import com .apple .foundationdb .record .query .plan .QueryPlanInfoKeys ;
34
34
import com .apple .foundationdb .record .query .plan .QueryPlanResult ;
35
35
import com .apple .foundationdb .record .query .plan .cascades .CascadesPlanner ;
36
+ import com .apple .foundationdb .record .query .plan .cascades .PlannerPhase ;
36
37
import com .apple .foundationdb .record .query .plan .cascades .Reference ;
37
38
import com .apple .foundationdb .record .query .plan .cascades .debug .Debugger ;
38
39
import com .apple .foundationdb .record .query .plan .cascades .debug .Stats ;
88
89
import java .sql .Struct ;
89
90
import java .util .ArrayList ;
90
91
import java .util .Collections ;
92
+
91
93
import java .util .List ;
92
94
import java .util .Map ;
93
95
import java .util .Objects ;
@@ -296,7 +298,11 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
296
298
DataType .StructType .Field .from ("TRANSFORM_YIELD_COUNT" , DataType .Primitives .LONG .type (), 4 ),
297
299
DataType .StructType .Field .from ("INSERT_TIME_NS" , DataType .Primitives .LONG .type (), 5 ),
298
300
DataType .StructType .Field .from ("INSERT_NEW_COUNT" , DataType .Primitives .LONG .type (), 6 ),
299
- DataType .StructType .Field .from ("INSERT_REUSED_COUNT" , DataType .Primitives .LONG .type (), 7 )),
301
+ DataType .StructType .Field .from ("INSERT_REUSED_COUNT" , DataType .Primitives .LONG .type (), 7 ),
302
+ DataType .StructType .Field .from ("REWRITING_PHASE_TASK_COUNT" , DataType .Primitives .LONG .type (), 8 ),
303
+ DataType .StructType .Field .from ("PLANNING_PHASE_TASK_COUNT" , DataType .Primitives .LONG .type (), 9 ),
304
+ DataType .StructType .Field .from ("REWRITING_PHASE_TASKS_TOTAL_TIME_NS" , DataType .Primitives .LONG .type (), 10 ),
305
+ DataType .StructType .Field .from ("PLANNING_PHASE_TASKS_TOTAL_TIME_NS" , DataType .Primitives .LONG .type (), 11 )),
300
306
true );
301
307
final var explainStructType = DataType .StructType .from (
302
308
"EXPLAIN" , List .of (
@@ -320,25 +326,35 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
320
326
plannerMetrics = null ;
321
327
} else {
322
328
final var plannerEventClassStatsMap = plannerStatsMaps .getEventClassStatsMap ();
323
- final var executingTasksStats =
329
+
330
+ final var aggregateExecutingTasksStats =
324
331
Optional .ofNullable (plannerEventClassStatsMap .get (Debugger .ExecutingTaskEvent .class ));
325
- final var transformRuleCallStats =
332
+ final var aggregateTransformRuleCallStats =
326
333
Optional .ofNullable (plannerEventClassStatsMap .get (Debugger .TransformRuleCallEvent .class ));
327
- final var insertIntoMemoStats =
334
+ final var aggregateInsertIntoMemoStats =
328
335
Optional .ofNullable (plannerEventClassStatsMap .get (Debugger .InsertIntoMemoEvent .class ));
329
336
337
+ final var executingTasksStatsForRewritingPhase =
338
+ plannerStatsMaps .getEventWithStateClassStatsMapByPlannerPhase (PlannerPhase .REWRITING )
339
+ .map (m -> m .get (Debugger .ExecutingTaskEvent .class ));
340
+ final var executingTasksStatsForPlanningPhase =
341
+ plannerStatsMaps .getEventWithStateClassStatsMapByPlannerPhase (PlannerPhase .PLANNING )
342
+ .map (m -> m .get (Debugger .ExecutingTaskEvent .class ));
343
+
330
344
plannerMetrics =
331
345
new ImmutableRowStruct (new ArrayRow (
332
- executingTasksStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
333
- executingTasksStats .map (Stats ::getTotalTimeInNs ).orElse (0L ),
334
- transformRuleCallStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
335
- transformRuleCallStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
336
- transformRuleCallStats .map (s -> s .getCount (Debugger .Location .YIELD )).orElse (0L ),
337
- insertIntoMemoStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
338
- insertIntoMemoStats .map (s -> s .getCount (Debugger .Location .NEW )).orElse (0L ),
339
- insertIntoMemoStats .map (s -> s .getCount (Debugger .Location .REUSED )).orElse (0L ),
340
- parsedContinuation .getVersion (),
341
- parsedContinuation .getCompiledStatement () == null ? null : parsedContinuation .getCompiledStatement ().getPlanSerializationMode ()
346
+ aggregateExecutingTasksStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
347
+ aggregateExecutingTasksStats .map (Stats ::getTotalTimeInNs ).orElse (0L ),
348
+ aggregateTransformRuleCallStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
349
+ aggregateTransformRuleCallStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
350
+ aggregateTransformRuleCallStats .map (s -> s .getCount (Debugger .Location .YIELD )).orElse (0L ),
351
+ aggregateInsertIntoMemoStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
352
+ aggregateInsertIntoMemoStats .map (s -> s .getCount (Debugger .Location .NEW )).orElse (0L ),
353
+ aggregateInsertIntoMemoStats .map (s -> s .getCount (Debugger .Location .REUSED )).orElse (0L ),
354
+ executingTasksStatsForRewritingPhase .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
355
+ executingTasksStatsForPlanningPhase .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
356
+ executingTasksStatsForRewritingPhase .map (Stats ::getTotalTimeInNs ).orElse (0L ),
357
+ executingTasksStatsForPlanningPhase .map (Stats ::getTotalTimeInNs ).orElse (0L )
342
358
), RelationalStructMetaData .of (plannerMetricsStructType ));
343
359
}
344
360
0 commit comments