# Sorting applies pagination before @cascade

**URL:** <https://discuss.dgraph.io/t/sorting-applies-pagination-before-cascade/15554>\
**Category:** Dgraph\
**Tags:** kind:bug\
**Created:** [September 14, 2021, 12:25am UTC](https://discuss.dgraph.io/t/sorting-applies-pagination-before-cascade/15554 "2021-09-14T00:25:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iluminae](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iluminae/32/7367_2.png) [@iluminae](https://discuss.dgraph.io/u/iluminae)\
**Post date:** [September 14, 2021, 12:25am UTC](https://discuss.dgraph.io/t/sorting-applies-pagination-before-cascade/15554/1 "2021-09-14T00:25:13Z")

</div>

### What version of Dgraph are you using?

> **Dgraph Version**
>
> ```auto
> 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

### What is the hardware spec (RAM, OS)?

12 alpha @ 16c 32GiB ram on k8s.

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

(EG: contrived schema and query to demonstrate issue, I dont actually want to do this specifically)

Imagine database state with 100,000 `Person`s. Simple query to retrieve those that live in Toronto can use @cascade to remove results that do not have an edge to the city node named `Toronto`.

Imagine 99,000 people of the 100,000 live somewhere else. So, this should grab the first 100 people that live in Toronto, sorted by name:

```auto
{ 
  a(func: type("Person"), first: 100, orderasc: name) @cascade(city) {
    name, xid
    city @filter(eq(city.name,"Toronto"))
  }
}

```

But, @cascade removes the pagination from `first:` until after the graph has been formed. That would be fine in this case, but `orderasc, orderdesc` put on their own pagination of 1000 _if no other pagination is found_.

Since cascade removes pagination, `applyOrderAndPagination()` in query.go sees a `first: 0` and applies its own `first: 1000` in `ProcessGraph()`, well before the final pagination from cascade is applied in `ProcessQuery()`

### Expected behaviour and actual result.

Pagination should be consistent even if using sort and cascade, but it is not.

---

<div class="post-metadata">

**Author:** ![iluminae](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iluminae/32/7367_2.png) [@iluminae](https://discuss.dgraph.io/u/iluminae)\
**Post date:** [September 17, 2021, 3:13pm UTC](https://discuss.dgraph.io/t/sorting-applies-pagination-before-cascade/15554/2 "2021-09-17T15:13:17Z")

</div>

Any acknowledgement of this bug please?

---

<div class="post-metadata">

**Author:** ![ahsan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ahsan/32/3517_2.png) [@ahsan](https://discuss.dgraph.io/u/ahsan)\
**Post date:** [September 19, 2021, 7:46pm UTC](https://discuss.dgraph.io/t/sorting-applies-pagination-before-cascade/15554/3 "2021-09-19T19:46:32Z")

</div>

Thanks @iluminae for reporting the bug. We’ll let you know once this is fixed.

---

<div class="post-metadata">

**Author:** ![Daniel](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/daniel/32/8499_2.png) [@Daniel](https://discuss.dgraph.io/u/Daniel)\
**Post date:** [September 19, 2021, 7:49pm UTC](https://discuss.dgraph.io/t/sorting-applies-pagination-before-cascade/15554/4 "2021-09-19T19:49:07Z")

</div>

Thank you @ahsan, I’m also tracking this as it prevents some key sorting operations on our cloud. Would a fix become directly available on Dgraph cloud or what do those release cycles look like? Thank you!
