Skip to content

Commit

Permalink
enable_stats for external table
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Aug 8, 2024
1 parent 547ff3c commit 75c4c8e
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ private ColumnStatistic getColumnStatistic(TableIf table, String colName, long i
*/
private Statistics computeCatalogRelation(CatalogRelation catalogRelation) {
StatisticsBuilder builder = new StatisticsBuilder();
double tableRowCount = catalogRelation.getTable().getRowCount();
// for FeUt, use ColumnStatistic.UNKNOWN
if (!FeConstants.enableInternalSchemaDb
|| ConnectContext.get() == null
Expand All @@ -1049,20 +1050,26 @@ private Statistics computeCatalogRelation(CatalogRelation catalogRelation) {
}
}
Set<SlotReference> slotSet = slotSetBuilder.build();

double rowCount = catalogRelation.getTable().getRowCountForNereids();
if (tableRowCount <= 0) {
// try to get row count from col stats
for (SlotReference slot : slotSet) {
ColumnStatistic cache = getColumnStatsFromTableCache(catalogRelation, slot);
tableRowCount = Math.max(cache.count, tableRowCount);
}
}
for (SlotReference slot : slotSet) {
ColumnStatistic cache = getColumnStatsFromTableCache(catalogRelation, slot);
ColumnStatisticBuilder colStatsBuilder = new ColumnStatisticBuilder(cache);
if (cache.isUnKnown) {
colStatsBuilder.setCount(rowCount);
ColumnStatistic cache;
if (ConnectContext.get() != null && ! ConnectContext.get().getSessionVariable().enableStats) {
cache = ColumnStatistic.UNKNOWN;
} else {
cache = getColumnStatsFromTableCache(catalogRelation, slot);
}
adjustColStats(catalogRelation, slot, colStatsBuilder);
rowCount = Math.max(rowCount, colStatsBuilder.getCount());
ColumnStatisticBuilder colStatsBuilder = new ColumnStatisticBuilder(cache);
colStatsBuilder.setCount(tableRowCount);
builder.putColumnStatistics(slot, colStatsBuilder.build());
}
checkIfUnknownStatsUsedAsKey(builder);
return builder.setRowCount(rowCount).build();
return builder.setRowCount(tableRowCount).build();
}

private Statistics computeTopN(TopN topN) {
Expand Down

0 comments on commit 75c4c8e

Please sign in to comment.