This is an automated email from the ASF dual-hosted git repository.
cambyzju pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 8f5688f8a5e [fix](plan) wrong result for random distributed agg table
with all keys not null (#36270)
8f5688f8a5e is described below
commit 8f5688f8a5e743eb06d224e49be93bb8d9c69633
Author: camby <[email protected]>
AuthorDate: Mon Jun 17 09:25:22 2024 +0800
[fix](plan) wrong result for random distributed agg table with all keys not
null (#36270)
---
.../java/org/apache/doris/catalog/OlapTable.java | 4 +++
.../plans/logical/LogicalCatalogRelation.java | 23 +++++++++--------
.../aggregate/select_random_distributed_tbl.out | 12 +++++++++
.../aggregate/select_random_distributed_tbl.groovy | 29 +++++++++++++++++++++-
4 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index 75a2fcd96c8..406c6d61793 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -936,6 +936,10 @@ public class OlapTable extends Table implements
MTMVRelatedTableIf {
return distributionColumnNames;
}
+ public boolean isRandomDistribution() {
+ return defaultDistributionInfo instanceof RandomDistributionInfo;
+ }
+
public void renamePartition(String partitionName, String newPartitionName)
{
if (partitionInfo.getType() == PartitionType.UNPARTITIONED) {
// bug fix
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java
index 3711ce31f98..49d0ed29688 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java
@@ -128,18 +128,21 @@ public abstract class LogicalCatalogRelation extends
LogicalRelation implements
@Override
public void computeUnique(DataTrait.Builder builder) {
Set<Slot> outputSet = Utils.fastToImmutableSet(getOutputSet());
- if (table instanceof OlapTable && ((OlapTable)
table).getKeysType().isAggregationFamily()) {
- ImmutableSet.Builder<Slot> uniqSlots =
ImmutableSet.builderWithExpectedSize(outputSet.size());
- for (Slot slot : outputSet) {
- if (!(slot instanceof SlotReference)) {
- continue;
- }
- SlotReference slotRef = (SlotReference) slot;
- if (slotRef.getColumn().isPresent() &&
slotRef.getColumn().get().isKey()) {
- uniqSlots.add(slot);
+ if (table instanceof OlapTable) {
+ OlapTable olapTable = (OlapTable) table;
+ if (olapTable.getKeysType().isAggregationFamily() &&
!olapTable.isRandomDistribution()) {
+ ImmutableSet.Builder<Slot> uniqSlots =
ImmutableSet.builderWithExpectedSize(outputSet.size());
+ for (Slot slot : outputSet) {
+ if (!(slot instanceof SlotReference)) {
+ continue;
+ }
+ SlotReference slotRef = (SlotReference) slot;
+ if (slotRef.getColumn().isPresent() &&
slotRef.getColumn().get().isKey()) {
+ uniqSlots.add(slot);
+ }
}
+ builder.addUniqueSlot(uniqSlots.build());
}
- builder.addUniqueSlot(uniqSlots.build());
}
for (PrimaryKeyConstraint c : table.getPrimaryKeyConstraints()) {
diff --git
a/regression-test/data/query_p0/aggregate/select_random_distributed_tbl.out
b/regression-test/data/query_p0/aggregate/select_random_distributed_tbl.out
index 1afb2a06762..c03e72c8f9e 100644
--- a/regression-test/data/query_p0/aggregate/select_random_distributed_tbl.out
+++ b/regression-test/data/query_p0/aggregate/select_random_distributed_tbl.out
@@ -215,3 +215,15 @@
-- !sql_16 --
2
+-- !sql_17 --
+1
+
+-- !sql_18 --
+1
+
+-- !sql_19 --
+1
+
+-- !sql_20 --
+1
+
diff --git
a/regression-test/suites/query_p0/aggregate/select_random_distributed_tbl.groovy
b/regression-test/suites/query_p0/aggregate/select_random_distributed_tbl.groovy
index ff0df74589a..439559aa5e0 100644
---
a/regression-test/suites/query_p0/aggregate/select_random_distributed_tbl.groovy
+++
b/regression-test/suites/query_p0/aggregate/select_random_distributed_tbl.groovy
@@ -131,4 +131,31 @@ suite("select_random_distributed_tbl") {
}
sql "drop table ${tableName};"
-}
\ No newline at end of file
+
+ // test all keys are NOT NULL for AGG table
+ sql "drop table if exists random_distributed_tbl_test_2;"
+ sql """ CREATE TABLE random_distributed_tbl_test_2 (
+ `k1` LARGEINT NOT NULL
+ ) ENGINE=OLAP
+ AGGREGATE KEY(`k1`)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY RANDOM BUCKETS 10
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+ """
+
+ sql """ insert into random_distributed_tbl_test_2 values(1); """
+ sql """ insert into random_distributed_tbl_test_2 values(1); """
+ sql """ insert into random_distributed_tbl_test_2 values(1); """
+
+ sql "set enable_nereids_planner = false;"
+ qt_sql_17 "select k1 from random_distributed_tbl_test_2;"
+ qt_sql_18 "select distinct k1 from random_distributed_tbl_test_2;"
+
+ sql "set enable_nereids_planner = true;"
+ qt_sql_19 "select k1 from random_distributed_tbl_test_2;"
+ qt_sql_20 "select distinct k1 from random_distributed_tbl_test_2;"
+
+ sql "drop table random_distributed_tbl_test_2;"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]