[Fix](nereids)Disable getting partition related table and column when self join (#30650)
* add left anti join ut * forbidden the self join partition column get * [Fix](nereids) Disable getting partition related table and column when self join * fix code style
This commit is contained in:
@ -43,6 +43,9 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalWindow;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -72,9 +75,6 @@ public class MaterializedViewUtils {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (columnExpr == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!(columnExpr instanceof SlotReference)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@ -85,13 +85,14 @@ public class MaterializedViewUtils {
|
||||
// check sql pattern
|
||||
IncrementCheckerContext context = new IncrementCheckerContext(columnSlot);
|
||||
materializedViewPlan.accept(MaterializedViewIncrementChecker.INSTANCE, context);
|
||||
if (context.getTableColumnList().isEmpty() || !context.isPctPossible()) {
|
||||
if (context.getPartitionRelatedTableAndColumnList().isEmpty() || !context.isPctPossible()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
// TODO support to return only one related table info, support multi later
|
||||
return Optional.of(new RelatedTableInfo(new BaseTableInfo(context.getTableColumnList().get(0).key()),
|
||||
Pair<TableIf, Column> tableIfColumnPair = context.getPartitionRelatedTableAndColumnList().get(0);
|
||||
return Optional.of(new RelatedTableInfo(new BaseTableInfo(tableIfColumnPair.key()),
|
||||
context.isPctPossible(),
|
||||
context.getTableColumnList().get(0).value().getName()));
|
||||
tableIfColumnPair.value().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,19 +227,29 @@ public class MaterializedViewUtils {
|
||||
|
||||
@Override
|
||||
public Void visitLogicalRelation(LogicalRelation relation, IncrementCheckerContext context) {
|
||||
if (!(relation instanceof LogicalCatalogRelation) || !context.getTableColumnList().isEmpty()) {
|
||||
return visit(relation, context);
|
||||
if (!(relation instanceof LogicalCatalogRelation)) {
|
||||
return null;
|
||||
}
|
||||
LogicalCatalogRelation logicalCatalogRelation = (LogicalCatalogRelation) relation;
|
||||
TableIf table = logicalCatalogRelation.getTable();
|
||||
// if self join, can't infer partition column
|
||||
if (!context.getTableIdAndRelationMapping().get(table.getId()).isEmpty()) {
|
||||
context.setPctPossible(false);
|
||||
return null;
|
||||
}
|
||||
// record tableId and relation, to check the self join
|
||||
context.addTableIdAndRelation(((LogicalCatalogRelation) relation).getTable().getId(), relation);
|
||||
// TODO: 2024/1/31 support only one partition referenced column, support multi later
|
||||
if (!context.getPartitionRelatedTableAndColumnList().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (!(table instanceof MTMVRelatedTableIf)) {
|
||||
return visit(relation, context);
|
||||
return null;
|
||||
}
|
||||
MTMVRelatedTableIf relatedTable = (MTMVRelatedTableIf) table;
|
||||
PartitionType type = relatedTable.getPartitionType();
|
||||
|
||||
if (PartitionType.UNPARTITIONED.equals(type)) {
|
||||
return visit(relation, context);
|
||||
return null;
|
||||
}
|
||||
Set<Column> partitionColumnSet = new HashSet<>(relatedTable.getPartitionColumns());
|
||||
Column mvReferenceColumn = context.getMvPartitionColumn().getColumn().get();
|
||||
@ -254,7 +265,8 @@ public class MaterializedViewUtils {
|
||||
IncrementCheckerContext context) {
|
||||
Set<Expression> groupByExprSet = new HashSet<>(aggregate.getGroupByExpressions());
|
||||
if (groupByExprSet.isEmpty()) {
|
||||
return visit(aggregate, context);
|
||||
context.setPctPossible(false);
|
||||
return null;
|
||||
}
|
||||
Set<Column> originalGroupbyExprSet = new HashSet<>();
|
||||
groupByExprSet.forEach(groupExpr -> {
|
||||
@ -264,6 +276,7 @@ public class MaterializedViewUtils {
|
||||
});
|
||||
if (!originalGroupbyExprSet.contains(context.getMvPartitionColumn().getColumn().get())) {
|
||||
context.setPctPossible(false);
|
||||
return null;
|
||||
}
|
||||
return visit(aggregate, context);
|
||||
}
|
||||
@ -317,8 +330,9 @@ public class MaterializedViewUtils {
|
||||
private static final class IncrementCheckerContext {
|
||||
private final SlotReference mvPartitionColumn;
|
||||
private boolean pctPossible = true;
|
||||
private final List<Pair<TableIf, Column>> tableColumnList = new ArrayList<>();
|
||||
private boolean joinNullGenerateSide;
|
||||
private final List<Pair<TableIf, Column>> partitionRelatedTableAndColumnList = new ArrayList<>();
|
||||
// This record the table id and relation mapping, because a table maybe used repeatedly.
|
||||
private final Multimap<Long, LogicalRelation> tableIdAndRelationMapping = HashMultimap.create();
|
||||
|
||||
public IncrementCheckerContext(SlotReference mvPartitionColumn) {
|
||||
this.mvPartitionColumn = mvPartitionColumn;
|
||||
@ -337,19 +351,19 @@ public class MaterializedViewUtils {
|
||||
}
|
||||
|
||||
public void addTableColumn(TableIf relatedTable, Column partitionColumn) {
|
||||
tableColumnList.add(Pair.of(relatedTable, partitionColumn));
|
||||
partitionRelatedTableAndColumnList.add(Pair.of(relatedTable, partitionColumn));
|
||||
}
|
||||
|
||||
public List<Pair<TableIf, Column>> getTableColumnList() {
|
||||
return tableColumnList;
|
||||
public List<Pair<TableIf, Column>> getPartitionRelatedTableAndColumnList() {
|
||||
return partitionRelatedTableAndColumnList;
|
||||
}
|
||||
|
||||
public boolean isJoinNullGenerateSide() {
|
||||
return joinNullGenerateSide;
|
||||
public Multimap<Long, LogicalRelation> getTableIdAndRelationMapping() {
|
||||
return tableIdAndRelationMapping;
|
||||
}
|
||||
|
||||
public void setJoinNullGenerateSide(boolean joinNullGenerateSide) {
|
||||
this.joinNullGenerateSide = joinNullGenerateSide;
|
||||
public void addTableIdAndRelation(Long tableId, LogicalRelation relation) {
|
||||
tableIdAndRelationMapping.put(tableId, relation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user