Inconsistent response of sort as a result of indexing of a predicate

I am currently digging the code to find out what exactly is being done by dgraph. I guess that Total order is considered by dgraph but on a filtered set because for this query on the same data:

{
  data(func: has(name), orderasc: class){
    name
    class
  }
}

We get a response:

 {
        "name": "bob",
        "class": "2"
      },
      {
        "name": "alice",
        "class": "5"
      },
      {
        "name": "cat"
      },
      {
        "name": "deg"
      }
    ]

But somehow, the filtered out elements are not put back in case of indexed class predicate:

and the response is:

"data": [
      {
        "name": "bob",
        "class": "2"
      },
      {
        "name": "alice",
        "class": "5"
      }
    ]