Skip to content

Commit

Permalink
if ndv is invalid, disable join reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 15, 2024
1 parent bc9b87d commit 1fb4249
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ public static void disableJoinReorderIfTableRowCountNotAvailable(
StatsCalculator calculator = new StatsCalculator(context);
for (LogicalOlapScan scan : scans) {
double rowCount = calculator.getOlapTableRowCount(scan);
if (rowCount == -1 && ConnectContext.get() != null) {
// analyzed rowCount may be zero, but BE-reported rowCount could be positive.
// check ndv validation when reported rowCount > 0
if ((rowCount == -1 || !calculator.checkNdvValidation(scan, rowCount)) && ConnectContext.get() != null) {
try {
ConnectContext.get().getSessionVariable().disableNereidsJoinReorderOnce();
LOG.info("disable join reorder since row count not available: "
Expand Down Expand Up @@ -403,6 +405,21 @@ private double getOlapTableRowCount(OlapScan olapScan) {
return rowCount;
}

// check validation of ndv.
private boolean checkNdvValidation(OlapScan olapScan, double rowCount) {
for (Slot slot : ((Plan) olapScan).getOutput()) {
if (isVisibleSlotReference(slot)) {
ColumnStatistic cache = getColumnStatsFromTableCache((CatalogRelation) olapScan, (SlotReference) slot);
if (!cache.isUnKnown
&& cache.ndv == 0
&& (cache.minExpr != null || cache.maxExpr != null)) {
return false;
}
}
}
return true;
}

private Statistics computeOlapScan(OlapScan olapScan) {
OlapTable olapTable = olapScan.getTable();
double tableRowCount = getOlapTableRowCount(olapScan);
Expand Down

0 comments on commit 1fb4249

Please sign in to comment.