# Sorting doesn't work on queries with cascade

**URL:** <https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584>\
**Category:** Dgraph\
**Tags:** kind:bug\
**Created:** [July 28, 2022, 12:41am UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584 "2022-07-28T00:41:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielhr](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@danielhr](https://discuss.dgraph.io/u/danielhr)\
**Post date:** [July 28, 2022, 12:41am UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/1 "2022-07-28T00:41:40Z")

</div>

Using DGraph Cloud.

When adding sorting to a query that’s using the @cascade directive, results are omitted showing only a small percentage of all the nodes.

All these three queries are identical except for the fact that one doesn’t sort, the other one sorts in ascending order and the last one in descending order, and the number of nodes returned is different for each query. I had already raised this issue last year and it seems to me that this is a very critical bug since it basically impedes users from sorting if we want to filter on a nested node (since we have to use cascade). Are there any plans on fixing this?

 ![Screen Shot 2022-07-27 at 8.32.54 PM](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/6/69f50e10e74ac3e6c932d7d0aba2d7686836a934.png)  
 ![Screen Shot 2022-07-27 at 8.32.14 PM](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/b/ba45a919a0105409eba9f2bbf27cc2fbde83d887.png)  
 ![Screen Shot 2022-07-27 at 8.32.39 PM](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2cbe6690fb9ed8ac104f270618506dca6138cccd.png)

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [July 28, 2022, 8:22pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/2 "2022-07-28T20:22:07Z")

</div>

Hey @danielhr I’m not able to reproduce your issue on 21.03 (dgraph cloud). Let’s see if we can track down this issue.

Can you have a look at this sandbox repo: [https://github.com/matthewmcneely/dgraph-v23.01-sandbox/tree/issue/sorting-doesnt-work-on-queries-with-cascade-17584](https://github.com/matthewmcneely/dgraph-v23.01-sandbox/tree/issue/sorting-doesnt-work-on-queries-with-cascade-17584)

It’d be great if you could spin this up and verify the results that I get (count is correct regardless of sorting). Maybe compare my schema to yours, what’s different? Maybe there’s something in your data that’s different from mine.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [July 29, 2022, 1:19am UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/3 "2022-07-29T01:19:40Z")

</div>

Maybe read this thread

> [@V21.03: After pagination+cascade change, queries are too slow to finish](http://discuss.hypermode.com/t/v21-03-after-pagination-cascade-change-queries-are-too-slow-to-finish/14184/25):
>
> @matthewmcneely no, I have not - but the issue is a fundamental design decision (to remove all pagination for any query that includes any level of cascade until the end of processing, introduced by [this pr](https://github.com/dgraph-io/dgraph/pull/7440)) as opposed to a unknown bug.

Or

> [@Sorting with @cascade returns empty results](http://discuss.hypermode.com/t/sorting-with-cascade-returns-empty-results/14841/8):
>
> It’s ok, we just upgraded to v21.03.1 (from v21.03.0) and it is now working

---

<div class="post-metadata">

**Author:** ![danielhr](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@danielhr](https://discuss.dgraph.io/u/danielhr)\
**Post date:** [July 29, 2022, 4:15am UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/4 "2022-07-29T04:15:52Z")

</div>

Hey, thanks for reaching out.

My schema has the following differences:

```auto
  currentPrice: Float @search # on Product
  name: String! @id @search(by: [hash]) # on Category

```

I guess the data might also be what’s causing the issue, I PMed you my endpoint so you can repro.

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [July 29, 2022, 8:49pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/5 "2022-07-29T20:49:34Z")

</div>

The @search directive on the `currentPrice` edge seems to be the/an issue. I’m not seeing the exact result you experienced: dgraph reports an error (the container exits and restarts) and I get back empty results, not just inaccurate results like you’re seeing.

If I use the 21.03.01 version image (instead of the 21.03.0 version), no issues exist. I _believe_ the cloud is on 21.03.0 – but I can’t confirm that because I’m unable to log into [cloud.dgraph.io](http://cloud.dgraph.io) at the moment 😕

---

<div class="post-metadata">

**Author:** ![danielhr](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@danielhr](https://discuss.dgraph.io/u/danielhr)\
**Post date:** [July 29, 2022, 11:39pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/6 "2022-07-29T23:39:53Z")

</div>

Okay. Please get back to me once you confirm. In either case, can you reproduce on my endpoint or is there a way for me to debug this? Like looking at my endpoint’s logs.

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [July 31, 2022, 3:42pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/7 "2022-07-31T15:42:03Z")

</div>

I can confirm that cloud is running 21.03.0 I’m not a dgraph employee so I cannot access your endpoint.

If you can live without the @search directive on the `currentPrice` edge, I’d say that’s your closest path to joy.

---

<div class="post-metadata">

**Author:** ![danielhr](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@danielhr](https://discuss.dgraph.io/u/danielhr)\
**Post date:** [August 2, 2022, 9:53pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/8 "2022-08-02T21:53:16Z")

</div>

Okay, thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![danielhr](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@danielhr](https://discuss.dgraph.io/u/danielhr)\
**Post date:** [August 2, 2022, 9:57pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/9 "2022-08-02T21:57:09Z")

</div>

@fulsmita is there any ETA on when this will be addressed?

---

<div class="post-metadata">

**Author:** ![yongxing\_Liang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/yongxing_liang/32/11633_2.png) [@yongxing\_Liang](https://discuss.dgraph.io/u/yongxing_Liang)\
**Post date:** [June 20, 2024, 10:56am UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/10 "2024-06-20T10:56:17Z")

</div>

@danielhr is the issue solved? I encounter the same issue on dgraph v22.02

---

<div class="post-metadata">

**Author:** ![himanshu-msphere](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/himanshu-msphere/32/11744_2.png) [@himanshu-msphere](https://discuss.dgraph.io/u/himanshu-msphere)\
**Post date:** [May 27, 2025, 6:48am UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/11 "2025-05-27T06:48:47Z")

</div>

Same issue in v24.1.2  
Below DQL query return no results

```auto
{
      queryModel(func: type(Model),first: 100, orderasc: Model.name) @cascade(Model.brand) {
            id: uid
            name: Model.name
            brand: Model.brand @filter(eq(Brand.name,"iphone")) {
                  id: uid
                  name: Brand.name
            }
      }
}

```

When removed orderasc than it’s shown results

```auto
{
      queryModel(func: type(Model),first: 100) @cascade(Model.brand) {
            id: uid
            name: Model.name
            brand: Model.brand @filter(eq(Brand.name,"iphone")) {
                  id: uid
                  name: Brand.name
            }
      }
}

```

---

<div class="post-metadata">

**Author:** ![Juri](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/juri/32/8872_2.png) [@Juri](https://discuss.dgraph.io/u/Juri)\
**Post date:** [August 1, 2025, 11:06pm UTC](https://discuss.dgraph.io/t/sorting-doesnt-work-on-queries-with-cascade/17584/12 "2025-08-01T23:06:46Z")

</div>

Hi just dropping my 2 cents here

for fulltext search ive used typesense. i remember dgraph had that feature that you can trigger functions after inserting new nodes. so after submitting new data into your DB, you can fire a short JS function that throws the entry into the typesense DB
