@@ -735,6 +735,9 @@ func (e *Explain) prepareSchema() error {
735735 fieldNames = []string {"binary plan" }
736736 case format == types .ExplainFormatTiDBJSON :
737737 fieldNames = []string {"TiDB_JSON" }
738+ case format == types .ExplainFormatRU :
739+ // TODO: Populate RU-specific columns after per-operator RU attribution is available.
740+ fieldNames = []string {"id" , "task" , "actRows" , "selfRU" , "cumRU" , "cumRU%" , "detail" }
738741 case e .Explore :
739742 fieldNames = []string {"statement" , "binding_hint" , "plan" , "plan_digest" , "avg_latency" , "exec_times" , "avg_scan_rows" ,
740743 "avg_returned_rows" , "latency_per_returned_row" , "scan_rows_per_returned_row" , "recommend" , "reason" ,
@@ -932,6 +935,9 @@ func (e *Explain) RenderResult() error {
932935 return err
933936 }
934937 e .Rows = append (e .Rows , []string {str })
938+ case types .ExplainFormatRU :
939+ flat := FlattenPhysicalPlan (e .TargetPlan , true )
940+ e .Rows = ExplainFlatPlanInRUFormat (flat , e .RuntimeStatsColl )
935941 default :
936942 return errors .Errorf ("explain format '%s' is not supported now" , e .Format )
937943 }
@@ -1106,6 +1112,38 @@ func prepareOperatorInfo(flatOp *FlatOperator, format string, analyze bool,
11061112 return append (rows , row )
11071113}
11081114
1115+ // ExplainFlatPlanInRUFormat returns the explain analyze result with RU columns.
1116+ func ExplainFlatPlanInRUFormat (flat * FlatPhysicalPlan , runtimeStatsColl * execdetails.RuntimeStatsColl ) (rows [][]string ) {
1117+ if flat == nil || len (flat .Main ) == 0 || flat .InExplain {
1118+ return
1119+ }
1120+ for _ , flatOp := range flat .Main {
1121+ rows = prepareRUOperatorInfo (flatOp , runtimeStatsColl , rows )
1122+ }
1123+ for _ , cte := range flat .CTEs {
1124+ for _ , flatOp := range cte {
1125+ rows = prepareRUOperatorInfo (flatOp , runtimeStatsColl , rows )
1126+ }
1127+ }
1128+ for _ , subQ := range flat .ScalarSubQueries {
1129+ for _ , flatOp := range subQ {
1130+ rows = prepareRUOperatorInfo (flatOp , runtimeStatsColl , rows )
1131+ }
1132+ }
1133+ return
1134+ }
1135+
1136+ func prepareRUOperatorInfo (flatOp * FlatOperator , runtimeStatsColl * execdetails.RuntimeStatsColl , rows [][]string ) [][]string {
1137+ p := flatOp .Origin
1138+ if p .ExplainID ().String () == "_0" {
1139+ return rows
1140+ }
1141+ taskType , id := getExplainIDAndTaskTp (flatOp )
1142+ actRows , _ , _ , _ := getRuntimeInfoStr (p .SCtx (), p , runtimeStatsColl )
1143+ // TODO: Replace the empty RU columns with real selfRU, cumRU, cumRU%, and detail values.
1144+ return append (rows , []string {id , taskType , actRows , "" , "" , "" , "" })
1145+ }
1146+
11091147func (e * Explain ) prepareOperatorInfoForJSONFormat (p base.Plan , taskType , explainID string ) * ExplainInfoForEncode {
11101148 if p .ExplainID ().String () == "_0" {
11111149 return nil
0 commit comments