>From Shahrzad Shirazi <[email protected]>:

Shahrzad Shirazi has submitted this change. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email )

Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over 
CLUSTER BY
......................................................................

[ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY

CBO estimates a GROUP BY's output by running count-distinct per key
over a sample of its input. When that input holds a CLUSTER BY, the
sample query carries one copy of the clustering per key, so k-means
runs once per key over the sample, and a clustering of a sample is
not the clustering of the dataset.

Report no estimate instead, as an unsampled dataset does.

Ext-ref: MB-73589
Generated-by: Claude Fable 5.1 <[email protected]>
Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962
Reviewed-by: Ali Alsuliman <[email protected]>
Tested-by: Ali Alsuliman <[email protected]>
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
1 file changed, 16 insertions(+), 0 deletions(-)

Approvals:
  Ali Alsuliman: Looks good to me, approved; Verified




diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
index 2340c23..d8ca841 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
@@ -1183,6 +1183,11 @@

         // distinct cardinality supported only for GroupByOp and DistinctOp
         if (tag == LogicalOperatorTag.DISTINCT || tag == 
LogicalOperatorTag.GROUP) {
+            if (hasClusterByBelow(grpByDistinctOp)) {
+                // Not estimated: the sample query would run the whole 
clustering once per key over the sample,
+                // and a clustering of a sample is not the clustering of the 
dataset.
+                return distinctCard;
+            }
             ILogicalOperator parent = 
OperatorUtils.findDataSourceScanOperatorParent(grpByDistinctOp);
             DataSourceScanOperator scanOp = (DataSourceScanOperator) 
parent.getInputs().get(0).getValue();
             if (scanOp == null) {
@@ -1219,6 +1224,17 @@
         return distinctCard;
     }

+    /** Whether a CLUSTER BY sits on the path from {@code op} down to its data 
source. */
+    private static boolean hasClusterByBelow(ILogicalOperator op) {
+        while (op != null && !op.getInputs().isEmpty()) {
+            if (op.getOperatorTag() == LogicalOperatorTag.CLUSTER_BY) {
+                return true;
+            }
+            op = op.getInputs().get(0).getValue();
+        }
+        return false;
+    }
+
     private long findSampleSizeWithPredicates(SelectOperator selOp, 
SampleDataSource sampleDataSource)
             throws AlgebricksException {
         long sampleSize = Long.MAX_VALUE;

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644
Gerrit-Change-Number: 21962
Gerrit-PatchSet: 6
Gerrit-Owner: Shahrzad Shirazi <[email protected]>
Gerrit-Reviewer: Ali Alsuliman <[email protected]>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Hongyu Shi <[email protected]>
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Rithwik Koul <[email protected]>
Gerrit-Reviewer: Shahrzad Shirazi <[email protected]>

Reply via email to