Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 14, 2024
1 parent 72af654 commit dae1384
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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 || !calculator.checkNdvValidation(scan)) && 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 @@ -404,11 +406,11 @@ private double getOlapTableRowCount(OlapScan olapScan) {
}

// check validation of ndv.
private boolean checkNdvValidation(OlapScan olapScan) {
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.count != cache.numNulls) {
if (!cache.isUnKnown && cache.ndv == 0 && rowCount != cache.numNulls) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,12 @@ void test16() {
Assertions.assertEquals("(a = 1)",
rewritten.toSql());
}

@Test
void test17() {
String expr = "(a=1 and b=2) or (a in (2, 3) and ((a=2 and c=3) or (a=3 or d=4)))";
Expression expression = PARSER.parseExpression(expr);
Expression rewritten = OrToIn.INSTANCE.rewriteTree(expression, context);
System.out.println(rewritten);
}
}

0 comments on commit dae1384

Please sign in to comment.