Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private void adjustColStats(CatalogRelation catalogRelation, SlotReference slot,
private ColumnStatistic getColumnStatsFromTableCache(CatalogRelation catalogRelation, SlotReference slot) {
long idxId = -1;
if (catalogRelation instanceof OlapScan) {
idxId = ((OlapScan) catalogRelation).getSelectedIndexIdForMV();
idxId = ((OlapScan) catalogRelation).getSelectedIndexId();
}
return getColumnStatistic(catalogRelation.getTable(), slot.getName(), idxId);
}
Expand All @@ -359,7 +359,7 @@ private ColumnStatistic getColumnStatsFromPartitionCache(CatalogRelation catalog
List<String> partitionNames) {
long idxId = -1;
if (catalogRelation instanceof OlapScan) {
idxId = ((OlapScan) catalogRelation).getSelectedIndexIdForMV();
idxId = ((OlapScan) catalogRelation).getSelectedIndexId();
}
return getColumnStatistic(catalogRelation.getTable(), slot.getName(), idxId, partitionNames);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ private Statistics computeOlapScan(LogicalOlapScan olapScan) {
for (Slot slot : olapScan.getOutput()) {
if (isVisibleSlotReference(slot)) {
ColumnStatistic cache = getColumnStatistic(olapTable, slot.getName(),
olapScan.getSelectedIndexIdForMV());
olapScan.getSelectedIndexId());
rowCount = Math.max(rowCount, cache.count);
}
builder.putColumnStatistics(slot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public interface OlapScan {

long getSelectedIndexId();

/**
* if this is mv, return selectedIndexId, o.w -1
* @return -1 or selectedIndexId
*/
long getSelectedIndexIdForMV();

List<Long> getSelectedPartitionIds();

List<Long> getSelectedTabletIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ public long getSelectedIndexId() {
return logicalOlapScan.getSelectedIndexId();
}

@Override
public long getSelectedIndexIdForMV() {
return logicalOlapScan.getSelectedIndexIdForMV();
}

@Override
public List<Long> getSelectedPartitionIds() {
return logicalOlapScan.getSelectedPartitionIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,6 @@ public long getSelectedIndexId() {
return selectedIndexId;
}

@Override
public long getSelectedIndexIdForMV() {
if (getTable().getBaseIndexId() != selectedIndexId) {
return selectedIndexId;
}
return -1;
}

public boolean isIndexSelected() {
return indexSelected;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public long getSelectedIndexId() {
return physicalOlapScan.getSelectedIndexId();
}

@Override
public long getSelectedIndexIdForMV() {
return physicalOlapScan.getSelectedIndexIdForMV();
}

@Override
public List<Long> getSelectedPartitionIds() {
return physicalOlapScan.getSelectedPartitionIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ public long getSelectedIndexId() {
return selectedIndexId;
}

@Override
public long getSelectedIndexIdForMV() {
if (getTable().getBaseIndexId() != selectedIndexId) {
return selectedIndexId;
}
return -1;
}

@Override
public List<Long> getSelectedTabletIds() {
return selectedTabletIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.doris.statistics;

import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.ClientPool;
import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
Expand Down Expand Up @@ -91,6 +93,12 @@ public ColumnStatistic getColumnStatistics(long catalogId, long dbId, long tblId
if (ctx != null && ctx.getSessionVariable().internalSession) {
return ColumnStatistic.UNKNOWN;
}
// Need to change base index id to -1 for OlapTable.
try {
idxId = changeBaseIndexId(catalogId, dbId, tblId, idxId);
} catch (Exception e) {
return ColumnStatistic.UNKNOWN;
}
StatisticsCacheKey k = new StatisticsCacheKey(catalogId, dbId, tblId, idxId, colName);
try {
CompletableFuture<Optional<ColumnStatistic>> f = columnStatisticsCache.get(k);
Expand All @@ -109,6 +117,12 @@ public PartitionColumnStatistic getPartitionColumnStatistics(long catalogId, lon
if (ctx != null && ctx.getSessionVariable().internalSession) {
return PartitionColumnStatistic.UNKNOWN;
}
// Need to change base index id to -1 for OlapTable.
try {
idxId = changeBaseIndexId(catalogId, dbId, tblId, idxId);
} catch (Exception e) {
return PartitionColumnStatistic.UNKNOWN;
}
PartitionColumnStatisticCacheKey k = new PartitionColumnStatisticCacheKey(
catalogId, dbId, tblId, idxId, partName, colName);
try {
Expand All @@ -122,6 +136,21 @@ public PartitionColumnStatistic getPartitionColumnStatistics(long catalogId, lon
return PartitionColumnStatistic.UNKNOWN;
}

// Base index id should be set to -1 for OlapTable. Because statistics tables use -1 for base index.
// TODO: Need to use the real index id in statistics table in later version.
private long changeBaseIndexId(long catalogId, long dbId, long tblId, long idxId) {
if (idxId != -1) {
TableIf table = StatisticsUtil.findTable(catalogId, dbId, tblId);
if (table instanceof OlapTable) {
OlapTable olapTable = (OlapTable) table;
if (idxId == olapTable.getBaseIndexId()) {
idxId = -1;
}
}
}
return idxId;
}

public Histogram getHistogram(long ctlId, long dbId, long tblId, String colName) {
return getHistogram(ctlId, dbId, tblId, -1, colName).orElse(null);
}
Expand Down