public void addSortItem(SortItem sortItem) {
    this.sortItemList.add(sortItem);
    switch (sortItem.getSortKey()) {
      case OrderByKey.TIME:
        orderByTime = true;
        timeOrderPriority = sortItemList.size() - 1;
        break;
      case OrderByKey.TIMESERIES:
        orderByTimeseries = true;
        timeseriesOrderPriority = sortItemList.size() - 1;
        break;
      case OrderByKey.DEVICE:
        orderByDevice = true;
        deviceOrderPriority = sortItemList.size() - 1;
        break;
      default:
        throw new IllegalArgumentException(
            String.format("Unknown sort key %s", sortItem.getSortKey()));
    }
  }
The order of query result set
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/component/OrderByComponent.java