code: private void calculatePropertyRestrictions() {
          if (restrictedProperties == null) {
              return;
          }
          // we use aliases for ordering, so we need the property in the select clause
          for (org.javatuples.Pair<Traversal.Admin<?, ?>, Comparator<?>> comparator : this.getDbComparators()) {
  
              if (comparator.getValue1() instanceof ElementValueComparator) {
                  restrictedProperties.add(((ElementValueComparator<?>) comparator.getValue1()).getPropertyKey());
  
              } else if ((comparator.getValue0() instanceof ElementValueTraversal<?> || comparator.getValue0() instanceof TokenTraversal<?, ?>)
                      && comparator.getValue1() instanceof Order) {
                  Traversal.Admin<?, ?> t = comparator.getValue0();
                  String key;
                  if (t instanceof ElementValueTraversal) {
                      ElementValueTraversal<?> elementValueTraversal = (ElementValueTraversal<?>) t;
                      key = elementValueTraversal.getPropertyKey();
                  } else {
                      TokenTraversal<?, ?> tokenTraversal = (TokenTraversal<?, ?>) t;
                      // see calculateLabeledAliasId
                      if (tokenTraversal.getToken().equals(T.id)) {
                          key = Topology.ID;
                      } else {
                          key = tokenTraversal.getToken().getAccessor();
                      }
                  }
                  if (key != null) {
                      restrictedProperties.add(key);
                  }
              }
          }
      }
docs: calculate property restrictions from explicit restrictions and required properties