>From Shahrzad Shirazi <[email protected]>: Shahrzad Shirazi has uploaded this change for review. ( 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 --- M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml 2 files changed, 16 insertions(+), 7 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/62/21962/1 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; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 80b8ae2..b2bc904 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -27,12 +27,5 @@ <!ENTITY ClusterByQueries SYSTEM "queries_sqlpp/cluster-by/ClusterByQueries.xml"> ]> <test-suite xmlns="urn:xml.testframework.asterix.apache.org" ResultOffsetPath="results" QueryOffsetPath="queries_sqlpp" QueryFileExtension=".sqlpp" SourceLocation="true"> - &ObjectsQueries; - &AsyncDeferredQueries; - &GeoQueries; - &TemporalQueries; - &SqlppQueries; - &CBOJoinQueries; - &VectorQueries; &ClusterByQueries; </test-suite> -- 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: newchange Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 1 Gerrit-Owner: Shahrzad Shirazi <[email protected]>
