private GbyKeyType getGbyKeyType(GroupByOperator gbyOp) {
      GroupByDesc gbyDesc = gbyOp.getConf();
      int numCols = gbyDesc.getOutputColumnNames().size();
      int aggCols = gbyDesc.getAggregators().size();
      // If the Group by operator has null key
      if (numCols == aggCols) {
        return GbyKeyType.NULL;
      }
      // If the Gby key is a constant
      List<String> dpCols = gbyOp.getSchema().getColumnNames().subList(0, numCols - aggCols);
      for(String dpCol : dpCols) {
        ExprNodeDesc end = ExprNodeDescUtils.findConstantExprOrigin(dpCol, gbyOp);
        if (!(end instanceof ExprNodeConstantDesc)) {
          return GbyKeyType.OTHER;
        }
      }
      return GbyKeyType.CONSTANT;
    }
There is a set of queries which can be answered entirely from statistics stored in metastore.
Examples of such queries are count(*), count(a), max(a), min(b) etc. Hive already collects
these basic statistics for query planning purposes. These same statistics can be used to
answer queries also.

Optimizer looks at query plan to determine if it can answer query using statistics
and than change the plan to answer query entirely using statistics stored in metastore.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/StatsOptimizer.java