boolean alterPrefixPathInternal(
      List<String> prefix, List<String> path, List<String> current, List<List<String>> results) {
    if (prefix.isEmpty()) {
      current.addAll(path);
      results.add(current);
      return !path.isEmpty() && MULTI_LEVEL_PATH_WILDCARD.equals(path.get(0));
    }
    if (path.isEmpty()) {
      return false;
    }

    if (MULTI_LEVEL_PATH_WILDCARD.equals(path.get(0))) {
      // Wildcard matches part of or the whole the prefix.
      for (int j = 1; j <= prefix.size(); j++) {
        List<String> copy = new ArrayList<>(current);
        copy.addAll(prefix.subList(0, j));
        if (alterPrefixPathInternal(
            prefix.subList(j, prefix.size()), path.subList(1, path.size()), copy, results)) {
          return true;
        }
      }
      // Wildcard matches the prefix and some more levels.
      List<String> copy = new ArrayList<>(current);
      copy.addAll(prefix);
      return alterPrefixPathInternal(
          Collections.emptyList(), path.subList(0, path.size()), copy, results);
    } else if (ONE_LEVEL_PATH_WILDCARD.equals(path.get(0)) || prefix.get(0).equals(path.get(0))) {
      // No need to make a copy.
      current.add(prefix.get(0));
      return alterPrefixPathInternal(
          prefix.subList(1, prefix.size()), path.subList(1, path.size()), current, results);
    }

    return false;
  }
Let PRE stands for the remaining prefix nodes, PATH for the remaining path nodes, and C for the
path being processed. And assume the size of the prefix is i and that of this path is j.

<p>If the first node of the path is not '**' and it matches the first node of the path. The
optimality equation is,

<p>O(PRE(0, i), PATH(0, j), C) = O(PRE(1, i), PATH(1, j), [PRE(0)])

<p>If the first node of the path is '**', it may match the first 1, 2, ... i nodes of the
prefix. '**' may match the all the remaining nodes of the prefix, as well as some additional
levels. Thus, the optimality equation is,

<p>O(PRE(0, i), PATH(0, j), C) = { O(PRE(1, i), PATH(1, j), [PRE(0)]), ... , O([], PATH(1, j),
C + PRE(0) + ... + PRE(i-1)), O([], PATH(0, j), C + PRE(0) + ... + PRE(i-1))}

<p>And when all the prefix nodes are matched,

<p>O([], PATH, C) = C + PATH

<p>The algorithm above takes all the possible matches of a multi-level wildcard into account.
Thus, it produces the correct result.

<p>To prevent overlapping among the final results, this algorithm stops when the prefix has no
remaining node and the first remaining node of the path is '**'. This strategy works because
this algorithm will always find the path with the least levels in the search space.

@param prefix The remaining nodes of the prefix.
@param path The remaining nodes of the path.
@param current The path being processed.
@param results The final results.
@return True if the search should be stopped, else false.
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java