diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/PruneShuffleDistributionNodeRule.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/PruneShuffleDistributionNodeRule.java index a7d9cbe2c49965..e5a161a8aa8ee3 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/PruneShuffleDistributionNodeRule.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/PruneShuffleDistributionNodeRule.java @@ -46,6 +46,9 @@ public OptExpression rewrite(OptExpression root, TaskContext taskContext) { !GlobalStateMgr.getCurrentState().getNodeMgr().getClusterInfo().isSingleBackendAndComputeNode()) { return root; } + if (sv.isEnableQueryCache()) { + return root; + } return root.getOp().accept(VISITOR, root, null); } diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/task/EnforceAndCostTask.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/task/EnforceAndCostTask.java index 93e0f087642cbd..800e5e522031c7 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/task/EnforceAndCostTask.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/task/EnforceAndCostTask.java @@ -419,7 +419,7 @@ private boolean canGenerateOneStageAgg(GroupExpression childBestExpr) { return false; } - if (sv.isEnableLocalShuffleAgg() && + if (sv.isEnableLocalShuffleAgg() && !sv.isEnableQueryCache() && GlobalStateMgr.getCurrentState().getNodeMgr().getClusterInfo().isSingleBackendAndComputeNode()) { return true; } diff --git a/test/sql/test_query_cache/R/test_query_cache_with_localshuffle_agg b/test/sql/test_query_cache/R/test_query_cache_with_localshuffle_agg new file mode 100644 index 00000000000000..b3cfac83d7061c --- /dev/null +++ b/test/sql/test_query_cache/R/test_query_cache_with_localshuffle_agg @@ -0,0 +1,35 @@ +-- name: test_query_cache_with_localshuffle_agg +CREATE TABLE t1 ( + id int(11) NOT NULL, + category varchar(192) NULL +) ENGINE=OLAP +PRIMARY KEY(id) +DISTRIBUTED BY HASH(id) BUCKETS 10 +PROPERTIES ( + "compression" = "LZ4", + "enable_persistent_index" = "true", + "fast_schema_evolution" = "true", + "replicated_storage" = "true", + "replication_num" = "1" +); +-- result: +-- !result +INSERT INTO t1 (id, category) +SELECT generate_series, + CONCAT('cat-', CAST(generate_series % 10 AS STRING)) +FROM TABLE(generate_series(1, 1000)); +-- result: +-- !result +SELECT category, COUNT(*) FROM t1 GROUP BY category ORDER BY category limit 10; +-- result: +cat-0 100 +cat-1 100 +cat-2 100 +cat-3 100 +cat-4 100 +cat-5 100 +cat-6 100 +cat-7 100 +cat-8 100 +cat-9 100 +-- !result \ No newline at end of file diff --git a/test/sql/test_query_cache/T/test_query_cache_with_localshuffle_agg b/test/sql/test_query_cache/T/test_query_cache_with_localshuffle_agg new file mode 100644 index 00000000000000..07e685d1261970 --- /dev/null +++ b/test/sql/test_query_cache/T/test_query_cache_with_localshuffle_agg @@ -0,0 +1,22 @@ +-- name: test_query_cache_with_localshuffle_agg + +CREATE TABLE t1 ( + id int(11) NOT NULL, + category varchar(192) NULL +) ENGINE=OLAP +PRIMARY KEY(id) +DISTRIBUTED BY HASH(id) BUCKETS 10 +PROPERTIES ( + "compression" = "LZ4", + "enable_persistent_index" = "true", + "fast_schema_evolution" = "true", + "replicated_storage" = "true", + "replication_num" = "1" +); + +INSERT INTO t1 (id, category) +SELECT generate_series, + CONCAT('cat-', CAST(generate_series % 10 AS STRING)) +FROM TABLE(generate_series(1, 1000)); + +SELECT category, COUNT(*) FROM t1 GROUP BY category ORDER BY category limit 10; \ No newline at end of file