[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Shahrzad Shirazi :
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
Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962
Reviewed-by: Ali Alsuliman
Tested-by: Ali Alsuliman
---
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
Gerrit-Reviewer: Ali Alsuliman
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Hongyu Shi
Gerrit-Reviewer: Jenkins
Gerrit-Reviewer: Rithwik Koul
Gerrit-Reviewer: Shahrzad Shirazi
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Shahrzad Shirazi : Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul. Shahrzad Shirazi has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 5: (1 comment) File asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962/comment/8940f08b_518383da?usp=email : PS5, Line 1233: op = op.getInputs().get(0).getValue(); > Did you think about the case where the pipeline is not linear? Will have another patch for that. -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 5 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 17:26:34 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: Ali Alsuliman
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Ali Alsuliman : Attention is currently required from: Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Ali Alsuliman has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 5: (1 comment) File asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962/comment/70c4458c_b668305c?usp=email : PS5, Line 1233: op = op.getInputs().get(0).getValue(); Did you think about the case where the pipeline is not linear? -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 5 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 17:09:15 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Ali Alsuliman : Attention is currently required from: Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Ali Alsuliman has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 5: Code-Review+2 Verified+1 -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 5 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 17:07:39 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Anon. E. Moose #1000171 has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 5: Analytics Compatibility Compilation Successful https://cbjenkins.page.link/DMbu3yyxJGzVqQmM6 : SUCCESS -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 5 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 16:32:37 + Gerrit-HasComments: No Gerrit-Has-Labels: No
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Anon. E. Moose #1000171 has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 4: Contrib-2 Analytics Compatibility Tests Failed https://cbjenkins.page.link/aBKhsBwdkMKVviih8 : UNSTABLE -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 4 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 11:10:59 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Anon. E. Moose #1000171 has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 4: Analytics Compatibility Compilation Successful https://cbjenkins.page.link/5gjZyQgF9SDj3g7S6 : SUCCESS -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 4 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 09:23:49 + Gerrit-HasComments: No Gerrit-Has-Labels: No
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Jenkins : Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Jenkins has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 3: Integration-Tests-1 Integration Tests Failed https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-trigger/8039/ : UNSTABLE -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 3 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 01:21:21 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Jenkins : Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul, Shahrzad Shirazi. Jenkins has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 2: Integration-Tests+1 Integration Tests Successful https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-trigger/8038/ : SUCCESS -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 2 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Shahrzad Shirazi Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 01:01:46 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Jenkins : Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul. Jenkins has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 1: Integration-Tests+1 Integration Tests Successful https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-trigger/8037/ : SUCCESS -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 1 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Rithwik Koul Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Fri, 02 Oct 2026 00:11:32 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul. Anon. E. Moose #1000171 has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 3: Contrib+1 Analytics Compatibility Tests Successful https://cbjenkins.page.link/yin4ikNBgz8141Gj8 : SUCCESS -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 3 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Rithwik Koul Gerrit-CC: Jenkins Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Thu, 01 Oct 2026 23:40:10 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul. Anon. E. Moose #1000171 has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 3: Analytics Compatibility Compilation Successful https://cbjenkins.page.link/tkd9dFWPzyWb97xA9 : SUCCESS -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 3 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Rithwik Koul Gerrit-CC: Anon. E. Moose #1000171 Gerrit-CC: Jenkins Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Thu, 01 Oct 2026 20:44:44 + Gerrit-HasComments: No Gerrit-Has-Labels: No
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Shahrzad Shirazi : Attention is currently required from: Ali Alsuliman, Hongyu Shi, Rithwik Koul. Shahrzad Shirazi has posted comments on this change by Shahrzad Shirazi. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21962?usp=email ) Change subject: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY .. Patch Set 3: (1 comment) Patchset: PS3: Please find the examples in the child patch. -- 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: comment Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I39702d2fadb5087910831cf61f19d0bc43505644 Gerrit-Change-Number: 21962 Gerrit-PatchSet: 3 Gerrit-Owner: Shahrzad Shirazi Gerrit-Reviewer: Ali Alsuliman Gerrit-Reviewer: Hongyu Shi Gerrit-Reviewer: Rithwik Koul Gerrit-CC: Jenkins Gerrit-Attention: Ali Alsuliman Gerrit-Attention: Rithwik Koul Gerrit-Attention: Hongyu Shi Gerrit-Comment-Date: Thu, 01 Oct 2026 20:39:44 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No
[S] Change in asterixdb[master]: [ASTERIXDB-3934][COMP] Skip distinct-count sampling over CLUSTER BY
>From Shahrzad Shirazi :
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
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 @@
]>
- &ObjectsQueries;
- &AsyncDeferredQueries;
- &GeoQueries;
- &TemporalQueries;
- &SqlppQueries;
- &CBOJoinQueries;
- &VectorQueries;
&ClusterByQueries;
--
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
