@@ -99,9 +99,10 @@ public enum ExplainType {
9999
100100 private final Set <SchemaLockType > acquiredLocks = new HashSet <>();
101101
102- // Previously, the boolean value 'isExplainAnalyze' was needed to determine whether query
103- // statistics should be recorded during the query process. Now 'explainType' is used to
104- // determine whether query statistics or query plan should be recorded during the query process.
102+ // Determines the explanation mode for the query:
103+ // - NONE: Normal query execution without explanation
104+ // - EXPLAIN: Show the logical and physical query plan without execution
105+ // - EXPLAIN_ANALYZE: Execute the query and collect detailed execution statistics
105106 private ExplainType explainType = ExplainType .NONE ;
106107 private boolean isVerbose = false ;
107108
@@ -124,14 +125,19 @@ public enum ExplainType {
124125
125126 private boolean userQuery = false ;
126127
127- private final Map <NodeRef <Table >, Long > cteMaterializationCosts = new HashMap <>();
128128 private Map <NodeRef <Table >, Query > cteQueries = new HashMap <>();
129- // table -> (maxLineLength, 'explain' or 'explain analyze' result)
130- // Max line length of each CTE should be remembered because we need to standardize
131- // the output format of main query and CTE query.
129+
130+ // Stores the EXPLAIN/EXPLAIN ANALYZE results for Common Table Expressions (CTEs)
131+ // Key: CTE table reference
132+ // Value: Pair containing (max line length of the explain output, list of formatted explain lines)
133+ // This ensures consistent formatting between the main query and its CTE sub-queries
132134 private final Map <NodeRef <Table >, Pair <Integer , List <String >>> cteExplainResults =
133135 new LinkedHashMap <>();
134- // Do not release CTE query result if it is a subquery.
136+ // Tracks the materialization time cost (in nanoseconds) for each CTE to help optimize query
137+ // planning
138+ private final Map <NodeRef <Table >, Long > cteMaterializationCosts = new HashMap <>();
139+
140+ // Never materialize CTE in a subquery.
135141 private boolean subquery = false ;
136142
137143 // Tables in the subquery
0 commit comments