diff --git a/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java b/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java index dcf3b05774746..75def9fdd36aa 100644 --- a/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java @@ -1333,6 +1333,8 @@ private void normalizeConjunctsNonLeft(FragmentNormalizer normalizer, TNormalPla @Override public void normalizeConjuncts(FragmentNormalizer normalizer, TNormalPlanNode planNode, List conjuncts) { if (!normalizer.isProcessingLeftNode()) { + // take column names of HashJoin RHS into cache digest computation + associateSlotIdsWithColumns(normalizer, planNode, Optional.empty()); normalizeConjunctsNonLeft(normalizer, planNode); return; } diff --git a/fe/fe-core/src/test/java/com/starrocks/planner/QueryCacheTest.java b/fe/fe-core/src/test/java/com/starrocks/planner/QueryCacheTest.java index 5eb19734bd447..b7e9250a85147 100644 --- a/fe/fe-core/src/test/java/com/starrocks/planner/QueryCacheTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/planner/QueryCacheTest.java @@ -27,7 +27,9 @@ import com.starrocks.common.FeConstants; import com.starrocks.qe.ConnectContext; import com.starrocks.sql.plan.ExecPlan; +import com.starrocks.sql.util.Util; import com.starrocks.statistic.StatsConstants; +import com.starrocks.thrift.TCacheParam; import com.starrocks.utframe.StarRocksAssert; import com.starrocks.utframe.UtFrameUtils; import kotlin.text.Charsets; @@ -46,6 +48,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.starrocks.sql.optimizer.statistics.CachedStatisticStorageTest.DEFAULT_CREATE_TABLE_TEMPLATE; @@ -1530,4 +1533,28 @@ public void testGroupByDifferentColumnsOnUnpartitionedTable() { Assert.assertTrue(frag0.isPresent() && frag1.isPresent()); Assert.assertNotEquals(frag0.get().getCacheParam().digest, frag1.get().getCacheParam().digest); } + + @Test + public void testDigestsVaryAsDifferentColumnNames() { + String sqlFmt = "select %s, count(distinct lo_custkey) \n" + + "from lineorder left outer join[broadcast] \n" + + " part on lo_custkey = p_partkey group by %s"; + + String[] columnNames = new String[] + {"p_mfgr", "p_color", "p_category", "p_brand", "p_type", "p_container"}; + + List> planFragments = Stream.of(columnNames) + .map(col -> String.format(sqlFmt, col, col)) + .map(this::getCachedFragment) + .collect(Collectors.toList()); + Assert.assertTrue(planFragments.stream().allMatch(Optional::isPresent)); + Set digests = planFragments.stream().map(optFrag -> optFrag + .map(PlanFragment::getCacheParam) + .map(TCacheParam::getDigest) + .map(Util::toHexString)) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(Collectors.toSet()); + Assert.assertEquals(digests.size(), columnNames.length); + } }