Skip to content

Commit 03d5c52

Browse files
committed
materialize the query only once
1 parent c176c21 commit 03d5c52

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/CteMaterializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public void materializeCTE(Analysis analysis, MPPQueryContext context) {
8282
(tableRef, query) -> {
8383
Table table = tableRef.getNode();
8484
if (query.isMaterialized()) {
85-
if (!query.isDone()) {
85+
if (!query.isExecuted()) {
8686
CteDataStore dataStore =
8787
fetchCteQueryResult(context, table, query, analysis.getWith());
88+
query.setExecuted(true);
8889
if (dataStore == null) {
8990
// CTE query execution failed. Use inline instead of materialization
9091
// in the outer query

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/Query.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class Query extends Statement {
4444
private final Optional<Node> limit;
4545
// whether this query needs materialization
4646
private boolean materialized = false;
47+
// whether this query has ever been executed
48+
private boolean isExecuted = false;
49+
// materialization has been executed successfully if cteDataStore is not null
4750
private CteDataStore cteDataStore = null;
4851

4952
public Query(
@@ -115,6 +118,14 @@ public void setMaterialized(boolean materialized) {
115118
this.materialized = materialized;
116119
}
117120

121+
public boolean isExecuted() {
122+
return isExecuted;
123+
}
124+
125+
public void setExecuted(boolean executed) {
126+
isExecuted = executed;
127+
}
128+
118129
public boolean isDone() {
119130
return cteDataStore != null;
120131
}

0 commit comments

Comments
 (0)