Skip to content

Commit

Permalink
fix(interactive): Fix Bugs of Count Estimation When Feasible Plan Is …
Browse files Browse the repository at this point in the history
…Unavailable in Equivalent Set (alibaba#4181)

Committed-by: xiaolei.zl from Dev container
  • Loading branch information
shirly121 authored and zhanglei1949 committed Sep 5, 2024
1 parent 127d875 commit 518df7f
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,19 @@ public Double getRowCount(RelNode node, RelMetadataQuery mq) {
}
}
}
throw new UnsupportedOperationException(
"estimate count for pattern " + pattern + " is unsupported yet");
double totalRowCount = 1.0d;
for (PatternEdge edge : pattern.getEdgeSet()) {
totalRowCount *= countEstimator.estimate(edge);
}
for (PatternVertex vertex : pattern.getVertexSet()) {
int degree = pattern.getEdgesOf(vertex).size();
if (degree > 0) {
double vertexCount = countEstimator.estimate(vertex);
vertexCount = Double.compare(vertexCount, 0.0d) == 0 ? 1.0d : vertexCount;
totalRowCount /= Math.pow(vertexCount, degree - 1);
}
}
return totalRowCount;
} else if (node instanceof TableScan) {
return getRowCount((TableScan) node, mq);
} else if (node instanceof Filter) {
Expand All @@ -131,6 +142,12 @@ public Double getRowCount(RelNode node, RelMetadataQuery mq) {
return mq.getRowCount(subset);
}
}
Pattern original =
(node instanceof GraphExtendIntersect)
? ((GraphExtendIntersect) node).getGlogueEdge().getDstPattern()
: ((GraphJoinDecomposition) node).getParentPatten();
return mq.getRowCount(
new GraphPattern(node.getCluster(), node.getTraitSet(), original));
} else if (node instanceof Join) {
return mdRowCount.getRowCount((Join) node, mq);
} else if (node instanceof Union) {
Expand Down

0 comments on commit 518df7f

Please sign in to comment.