docs: public void optimizeCriteria( List<QueryCriteria> criteriaList ) {
  
          // we don't expect subqueries with task variable criteria
          Set<QueryCriteria> optimizedCriteria = Collections.newSetFromMap(new IdentityHashMap<QueryCriteria, Boolean>(1));
  
          boolean endOfListNotYetReached = true;
          while( endOfListNotYetReached ) {
              Set<QueryCriteria> taskVarCriteria = Collections.newSetFromMap(new IdentityHashMap<QueryCriteria, Boolean>(2));
  
              boolean endOfListReached = true;
              for( QueryCriteria criteria : criteriaList ) {
  
                  if( ! criteria.isFirst() && criteria.isUnion() ) {
                      if( taskVarCriteria.size() > 1 ) {
                          endOfListReached = false;
                          break;
                      }
                      taskVarCriteria.clear();
                  }
  
                  // if group, recurse
                  if( criteria.isGroupCriteria() ) {
                      if( optimizedCriteria.add(criteria) ) {
                          optimizeCriteria(criteria.getCriteria());
                      }
                      continue;
                  }
  
                  String listId = criteria.getListId();
                  if( listId.equals(TASK_VARIABLE_NAME_ID_LIST)
                          || listId.equals(TASK_VARIABLE_VALUE_ID_LIST) ) {
                      taskVarCriteria.add(criteria);
                  }
              }
  
              if( endOfListReached ) {
                  endOfListNotYetReached = false;
              }
  
              if( taskVarCriteria.size() > 1 ) {
                  Iterator<QueryCriteria> criteriaIter = criteriaList.iterator();
                  QueryCriteria combinedTaskVarCriteria = null;
                  while( criteriaIter.hasNext() ) {
                      QueryCriteria criteria = criteriaIter.next();
                      if( taskVarCriteria.contains(criteria) ) {
                          if( combinedTaskVarCriteria == null ) {
                              combinedTaskVarCriteria = criteria;
                              criteria = new QueryCriteria(criteria);
  
                              // combined criteria replaces the original, and thus:
                              // 1. KEEPS the original union flag!
                              // 2. KEEPS the original first flag!
                              combinedTaskVarCriteria.setListId(TASK_VARIABLE_COMBINED_ID);
                              combinedTaskVarCriteria.setType(QueryCriteriaType.NORMAL);
                              combinedTaskVarCriteria.getValues().clear();
                              combinedTaskVarCriteria.getDateValues().clear();
                              // processed as a normal, even though it's group
                              combinedTaskVarCriteria.addCriteria(criteria);
                          } else {
                              combinedTaskVarCriteria.addCriteria(criteria);
                              criteriaIter.remove();
                          }
                      }
                      if( combinedTaskVarCriteria != null && criteria.isUnion() ) {
                          break;
                      }
                  }
              }
          }
  
      }