imay closed pull request #256: Improve cardinality, avgRowSize, numNodes stat
info in OlapScanNode
URL: https://github.com/apache/incubator-doris/pull/256
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/fe/src/main/java/org/apache/doris/planner/OlapScanNode.java
b/fe/src/main/java/org/apache/doris/planner/OlapScanNode.java
index 578c3fc6..8c4b71a5 100644
--- a/fe/src/main/java/org/apache/doris/planner/OlapScanNode.java
+++ b/fe/src/main/java/org/apache/doris/planner/OlapScanNode.java
@@ -93,9 +93,12 @@
private long totalTabletsNum = 0;
private long selectedIndexId = -1;
private int selectedPartitionNum = 0;
+ private long totalBytes = 0;
boolean isFinalized = false;
+ private HashSet<Long> scanBackendIds = new HashSet<>();
+
/**
* Constructs node to scan given data files of table 'tbl'.
*/
@@ -143,9 +146,22 @@ public void finalize(Analyzer analyzer) throws
UserException {
throw new UserException(e.getMessage());
}
+ computeStats(analyzer);
isFinalized = true;
}
+ @Override
+ public void computeStats(Analyzer analyzer) {
+ if (cardinality > 0) {
+ avgRowSize = totalBytes / (float) cardinality;
+ if (hasLimit()) {
+ cardinality = Math.min(cardinality, limit);
+ }
+ numNodes = scanBackendIds.size();
+ }
+ }
+
+
// private void analyzeVectorizedConjuncts(Analyzer analyzer) throws
InternalException {
// for (SlotDescriptor slot : desc.getSlots()) {
// for (Expr conjunct : conjuncts) {
@@ -434,6 +450,7 @@ private void addScanRangeLocations(Partition partition,
Collections.shuffle(replicas);
boolean tabletIsNull = true;
+ boolean collectedStat = false;
for (Replica replica : replicas) {
Backend backend =
Catalog.getCurrentSystemInfo().getBackend(replica.getBackendId());
if (backend == null) {
@@ -447,6 +464,14 @@ private void addScanRangeLocations(Partition partition,
scanRangeLocations.addToLocations(scanRangeLocation);
paloRange.addToHosts(new TNetworkAddress(ip, port));
tabletIsNull = false;
+
+ //for CBO
+ if (!collectedStat && replica.getRowCount() != -1) {
+ cardinality += replica.getRowCount();
+ totalBytes += replica.getDataSize();
+ collectedStat = true;
+ }
+ scanBackendIds.add(backend.getId());
}
if (tabletIsNull) {
throw new UserException(tabletId + "have no alive replicas");
@@ -599,6 +624,18 @@ protected String getNodeExplainString(String prefix,
TExplainLevel detailLevel)
"buckets=%s/%s", selectedTabletsNum, totalTabletsNum));
output.append("\n");
+ output.append(prefix).append(String.format(
+ "cardinality=%s", cardinality));
+ output.append("\n");
+
+ output.append(prefix).append(String.format(
+ "avgRowSize=%s", avgRowSize));
+ output.append("\n");
+
+ output.append(prefix).append(String.format(
+ "numNodes=%s", numNodes));
+ output.append("\n");
+
return output.toString();
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]