From 10c1e3f5e1931b51a15ebf277f7aee5e8c539224 Mon Sep 17 00:00:00 2001 From: kaijianding Date: Thu, 17 Oct 2024 14:05:25 +0800 Subject: [PATCH 1/2] [BugFix] Fix incorrect materialized view row count (#51944) Signed-off-by: kaijian.ding (cherry picked from commit 1df36e49d4657570ffa8b9ed7b7a595ea994dd56) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java --- .../java/com/starrocks/catalog/TabletStatMgr.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java b/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java index ea40b3f4bc962..9c570d92a34ae 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java @@ -39,6 +39,7 @@ import com.google.common.collect.Maps; import com.starrocks.catalog.MaterializedIndex.IndexExtState; import com.starrocks.common.Config; +import com.starrocks.common.Pair; import com.starrocks.common.util.FrontendDaemon; import com.starrocks.common.util.concurrent.lock.LockType; import com.starrocks.common.util.concurrent.lock.Locker; @@ -115,8 +116,13 @@ protected void runAfterCatalogReady() { } // NOTE: calculate the row first with read lock, then update the stats with write lock +<<<<<<< HEAD locker.lockTableWithIntensiveDbLock(db, table.getId(), LockType.READ); Map indexRowCountMap = Maps.newHashMap(); +======= + locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); + Map, Long> indexRowCountMap = Maps.newHashMap(); +>>>>>>> 1df36e49d4 ([BugFix] Fix incorrect materialized view row count (#51944)) try { OlapTable olapTable = (OlapTable) table; for (Partition partition : olapTable.getAllPartitions()) { @@ -129,7 +135,8 @@ protected void runAfterCatalogReady() { for (Tablet tablet : index.getTablets()) { indexRowCount += tablet.getRowCount(version); } // end for tablets - indexRowCountMap.put(index.getId(), indexRowCount); + indexRowCountMap.put(Pair.create(physicalPartition.getId(), index.getId()), + indexRowCount); if (!olapTable.isTempPartition(partition.getId())) { totalRowCount += indexRowCount; } @@ -150,7 +157,8 @@ protected void runAfterCatalogReady() { for (PhysicalPartition physicalPartition : partition.getSubPartitions()) { for (MaterializedIndex index : physicalPartition.getMaterializedIndices(IndexExtState.VISIBLE)) { - Long indexRowCount = indexRowCountMap.get(index.getId()); + Long indexRowCount = + indexRowCountMap.get(Pair.create(physicalPartition.getId(), index.getId())); if (indexRowCount != null) { index.setRowCount(indexRowCount); } From ce8e726561bc1ed267063ee9f8700fd82c5a8771 Mon Sep 17 00:00:00 2001 From: "shuming.li" Date: Fri, 18 Oct 2024 17:07:20 +0800 Subject: [PATCH 2/2] Fix bugs Signed-off-by: shuming.li --- .../src/main/java/com/starrocks/catalog/TabletStatMgr.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java b/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java index 9c570d92a34ae..129bcf0c64abc 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/TabletStatMgr.java @@ -116,13 +116,7 @@ protected void runAfterCatalogReady() { } // NOTE: calculate the row first with read lock, then update the stats with write lock -<<<<<<< HEAD - locker.lockTableWithIntensiveDbLock(db, table.getId(), LockType.READ); - Map indexRowCountMap = Maps.newHashMap(); -======= - locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); Map, Long> indexRowCountMap = Maps.newHashMap(); ->>>>>>> 1df36e49d4 ([BugFix] Fix incorrect materialized view row count (#51944)) try { OlapTable olapTable = (OlapTable) table; for (Partition partition : olapTable.getAllPartitions()) {