[fix](planner) Fix select table tablet not effective (#25378)

Fix select table tablet not effective, table distributed by random.
If tabletID specified in query does not exist in this partition, skip scan partition.
This commit is contained in:
Xinyi Zou
2023-10-25 18:02:27 +08:00
committed by GitHub
parent 4bda1650e1
commit a919ef618d
2 changed files with 150 additions and 8 deletions

View File

@ -970,6 +970,8 @@ public class OlapScanNode extends ScanNode {
continue;
}
// It is assumed here that all tablets row count is uniformly distributed
// TODO Use `p.getBaseIndex().getTablet(n).getRowCount()` to get each tablet row count to compute sample.
long avgRowsPerTablet = Math.max(p.getBaseIndex().getRowCount() / ids.size(), 1);
long tabletCounts = Math.max(
avgRowsPerPartition / avgRowsPerTablet + (avgRowsPerPartition % avgRowsPerTablet != 0 ? 1 : 0), 1);
@ -1026,19 +1028,28 @@ public class OlapScanNode extends ScanNode {
final Partition partition = olapTable.getPartition(partitionId);
final MaterializedIndex selectedTable = partition.getIndex(selectedIndexId);
final List<Tablet> tablets = Lists.newArrayList();
final Collection<Long> tabletIds = distributionPrune(selectedTable, partition.getDistributionInfo());
Collection<Long> tabletIds = distributionPrune(selectedTable, partition.getDistributionInfo());
LOG.debug("distribution prune tablets: {}", tabletIds);
if (tabletIds != null && sampleTabletIds.size() != 0) {
tabletIds.retainAll(sampleTabletIds);
if (sampleTabletIds.size() != 0) {
if (tabletIds != null) {
tabletIds.retainAll(sampleTabletIds);
} else {
tabletIds = sampleTabletIds;
}
LOG.debug("after sample tablets: {}", tabletIds);
}
List<Long> allTabletIds = selectedTable.getTabletIdsInOrder();
if (tabletIds != null) {
for (Long id : tabletIds) {
tablets.add(selectedTable.getTablet(id));
if (selectedTable.getTablet(id) != null) {
tablets.add(selectedTable.getTablet(id));
scanTabletIds.add(id);
} else {
// The tabletID specified in query does not exist in this partition, skip scan partition.
Preconditions.checkState(sampleTabletIds.size() != 0);
}
}
scanTabletIds.addAll(tabletIds);
} else {
tablets.addAll(selectedTable.getTablets());
scanTabletIds.addAll(allTabletIds);