Pagination/Sort issues with @cascade on 21.03.1


Report a Dgraph Bug

What version of Dgraph are you using?

Dgraph Version
$ dgraph version
 
Dgraph version   : v21.03.1
Dgraph codename  : rocket-1
Dgraph SHA-256   : a00b73d583a720aa787171e43b4cb4dbbf75b38e522f66c9943ab2f0263007fe
Commit SHA-1     : ea1cb5f35
Commit timestamp : 2021-06-17 20:38:11 +0530
Branch           : HEAD
Go version       : go1.16.2
jemalloc enabled : true

Have you tried reproducing the issue with the latest release?

Yes, I’m running dgraph/standalone:latest

What is the hardware spec (RAM, OS)?

Macbook Pro Core i9
32GB ram, 12 allocated to Docker Desktop

Steps to reproduce the issue (command/config used to run Dgraph).

Newbie here :sweat_smile: so I’m following the tour, I loaded into my local dgraph the data set at this step:
https://dgraph.io/tour/moredata/1/#user

I’m running Dgraph with:

docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 \
  -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph \
  dgraph/standalone:latest

Expected behaviour and actual result.

I was playing with queries before moving to the next step in the tutorial, and I noticed a strange behaviour when using @cascade together with pagination/sorting.

More specifically I’m running this:

{
  tom_hanks_movies(func: type(Movie), first: 5) @cascade  {
    name@.
    initial_release_date
    ~director.film {
        name@.
    }
    starring {
        performance.character {
            name@.
        }
        performance.actor @filter(eq(name@., "Tom Hanks")) {
            name@.
        }
    }
  }
}

and it returns correctly 5 results, but if I do:

{
  tom_hanks_movies(func: type(Movie), first: 5, orderasc: name@.) @cascade  {
    name@.
    initial_release_date
    ~director.film {
        name@.
    }
    starring {
        performance.character {
            name@.
        }
        performance.actor @filter(eq(name@., "Tom Hanks")) {
            name@.
        }
    }
  }
}

It returns 0 results, btw also if I order by initial_release_date it returns 0 results.
Then I noticed this:

{
  tom_hanks_movies(func: type(Movie), first: 5) {
    count(uid)
  }
}
=>
{
"data": {
        "tom_hanks_movies": [
            {
                "count": 5
            }
        ]
    }
}
{
  tom_hanks_movies(func: type(Movie), first: 5, orderasc: name@.) @cascade {
    count(uid)
  }
}
=>
{
"data": {
        "tom_hanks_movies": [
            {
                "count": 5
            }
        ]
    }
}
{
  tom_hanks_movies(func: type(Movie), first: 5) @cascade {
    count(uid)
  }
}
=>
{
"data": {
        "tom_hanks_movies": [
            {
                "count": 125614
            }
        ]
    }
}
{
  tom_hanks_movies(func: type(Movie), first: 5, orderasc: name@en) @cascade {
    count(uid)
  }
}
=>
{
"data": {
        "tom_hanks_movies": [
            {
                "count": 1000
            }
        ]
    }
}

I understand that ordering on a count() and @cascade without filters don’t really make sense, but I would still expect the same count of 5 given the first: 5, no? :face_with_monocle:

Just as a side note, if I run the same query with orderasc and cascade on version 21.03.0, the dgraph alpha process panics and exits… this was fixed in 21.03.1