@Override
    protected IrRowPattern visitIrAlternation(IrAlternation node, Void context) {
      List<IrRowPattern> children =
          node.getPatterns().stream().map(this::process).collect(toImmutableList());

      int emptyChildIndex = -1;
      for (int i = 0; i < children.size(); i++) {
        if (children.get(i) instanceof IrEmpty) {
          checkState(
              emptyChildIndex < 0,
              "run IrRowPatternFlattener first to remove redundant empty pattern");
          emptyChildIndex = i;
        }
      }

      if (emptyChildIndex < 0) {
        return new IrAlternation(children);
      }

      // remove the empty child:
      // (() | A) -> A??
      // (() | A | B) -> (A?? | B)
      if (emptyChildIndex == 0) {
        IrRowPattern child = new IrQuantified(children.get(1), zeroOrOne(false));
        if (children.size() == 2) {
          return child;
        }
        ImmutableList.Builder<IrRowPattern> builder =
            ImmutableList.<IrRowPattern>builder()
                .add(child)
                .addAll(children.subList(2, children.size()));
        return new IrAlternation(builder.build());
      }
      // (A | ()) -> A?
      // (A | B | () | C) -> (A | B? | C)
      children =
          ImmutableList.<IrRowPattern>builder()
              .addAll(children.subList(0, emptyChildIndex - 1))
              .add(new IrQuantified(children.get(emptyChildIndex - 1), zeroOrOne(true)))
              .addAll(children.subList(emptyChildIndex + 1, children.size()))
              .build();

      if (children.size() == 1) {
        return children.get(0);
      }
      return new IrAlternation(children);
    }
Remove empty pattern from pattern alternation and replace it with quantification of a
neighbouring term.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/rowpattern/IrPatternAlternationOptimizer.java