seawinde commented on code in PR #30258:
URL: https://github.com/apache/doris/pull/30258#discussion_r1465779427
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java:
##########
@@ -279,11 +282,46 @@ private static List<Slot> applyNullable(List<Slot> slots,
boolean nullable) {
.collect(ImmutableList.toImmutableList());
}
+ private static Map<Slot, Slot> mapPrimaryToForeign(ImmutableEqualSet<Slot>
equivalenceSet,
+ Set<Slot> foreignKeys) {
+ ImmutableMap.Builder<Slot, Slot> builder = new
ImmutableMap.Builder<>();
+ for (Slot foreignSlot : foreignKeys) {
+ Set<Slot> primarySlots = equivalenceSet.calEqualSet(foreignSlot);
+ if (primarySlots.size() != 1) {
+ return ImmutableMap.of();
+ }
+ builder.put(primarySlots.iterator().next(), foreignSlot);
+ }
+ return builder.build();
+ }
+
+ /**
+ * Check whether the given join can be eliminated by pk-fk
+ */
+ public static boolean canEliminateByFk(LogicalJoin<?, ?> join, Plan
primaryPlan, Plan foreignPlan) {
+ if (!join.getJoinType().isInnerJoin() ||
!join.getOtherJoinConjuncts().isEmpty() || join.isMarkJoin()) {
+ return false;
+ }
+
+ ForeignKeyContext context = new ForeignKeyContext();
+ context.collectForeignKeyConstraint(primaryPlan);
+ context.collectForeignKeyConstraint(foreignPlan);
+
+ ImmutableEqualSet<Slot> equalSet = join.getEqualSlots();
+ Set<Slot> primaryKey = Sets.intersection(equalSet.getAllItemSet(),
primaryPlan.getOutputSet());
+ Set<Slot> foreignKey = Sets.intersection(equalSet.getAllItemSet(),
foreignPlan.getOutputSet());
+ if (!context.isForeignKey(foreignKey) &&
!context.isPrimaryKey(primaryKey)) {
Review Comment:
maybe this should be ||(or)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]