private void addPkFkInfoToAST(ASTNode ast, Join join, boolean swapSides) {
    List<RexNode> joinFilters = new ArrayList<>(RelOptUtil.conjunctions(join.getCondition()));
    RelMetadataQuery mq = join.getCluster().getMetadataQuery();
    HiveRelOptUtil.PKFKJoinInfo rightInputResult =
            HiveRelOptUtil.extractPKFKJoin(join, joinFilters, false, mq);
    HiveRelOptUtil.PKFKJoinInfo leftInputResult =
            HiveRelOptUtil.extractPKFKJoin(join, joinFilters, true, mq);
    // Add the fkJoinIndex (0=left, 1=right, if swapSides is false) to the AST
    // check if the nonFK side is filtered
    if (leftInputResult.isPkFkJoin && leftInputResult.additionalPredicates.isEmpty()) {
      RelNode nonFkInput = join.getRight();
      ast.addChild(pkFkHint(swapSides ? 1 : 0, HiveRelOptUtil.isRowFilteringPlan(mq, nonFkInput)));
    } else if (rightInputResult.isPkFkJoin && rightInputResult.additionalPredicates.isEmpty()) {
      RelNode nonFkInput = join.getLeft();
      ast.addChild(pkFkHint(swapSides ? 0 : 1, HiveRelOptUtil.isRowFilteringPlan(mq, nonFkInput)));
    }
  }
Add PK-FK join information to the AST as a query hint
@param ast
@param join
@param swapSides whether the left and right input of the join is swapped
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java