diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java index 7e6d81db7935112..b3638f3b75bf564 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java @@ -948,9 +948,11 @@ public void computeSampleTabletIds() { } for (Long partitionId : selectedPartitionIds) { final Partition partition = olapTable.getPartition(partitionId); - final MaterializedIndex selectedTable = partition.getIndex(selectedIndexId); - selectedRows += selectedTable.getRowCount(); - selectedPartitionList.add(partitionId); + final MaterializedIndex selectedIndex = partition.getIndex(selectedIndexId); + if (selectedIndex != null) { + selectedRows += selectedIndex.getRowCount(); + selectedPartitionList.add(partitionId); + } } selectedPartitionList.sort(Comparator.naturalOrder()); @@ -970,7 +972,7 @@ public void computeSampleTabletIds() { // 3. Sampling partition. If Seek is specified, the partition will be the same for each sampling. long hitRows = 0; // The number of rows hit by the tablet long partitionSeek = tableSample.getSeek() != -1 - ? tableSample.getSeek() : (long) (new SecureRandom().nextDouble() * selectedPartitionIds.size()); + ? tableSample.getSeek() : (long) (new SecureRandom().nextDouble() * selectedPartitionList.size()); for (int i = 0; i < selectedPartitionList.size(); i++) { int seekPid = (int) ((i + partitionSeek) % selectedPartitionList.size()); final Partition partition = olapTable.getPartition(selectedPartitionList.get(seekPid));