# Configuring collection without sorting does not have an effect

**URL:** <https://community.forestadmin.com/t/configuring-collection-without-sorting-does-not-have-an-effect/4293>\
**Category:** Help me!\
**Created:** [March 2, 2022, 7:46pm UTC](https://community.forestadmin.com/t/configuring-collection-without-sorting-does-not-have-an-effect/4293 "2022-03-02T19:46:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jimmi/32/304_2.png) [@Jimmi](https://community.forestadmin.com/u/Jimmi)\
**Post date:** [March 2, 2022, 7:46pm UTC](https://community.forestadmin.com/t/configuring-collection-without-sorting-does-not-have-an-effect/4293/1 "2022-03-02T19:46:53Z")

</div>

## Feature(s) impacted

Default sorting

## Observed behavior

Setting the sorting of a collection to “no sorting”, still adds an `order by` in the database query.

## Expected behavior

Setting the sorting of a collection to “no sorting”, makes database queries without `order by`

## Context

- Project name: `Back Office`
- Team name: Any team
- Environment name: Production
- Agent type & version: Forest liana Rails, v7.4.5, with Postgres database
- Recent changes made on your end if any: No

It seems that the following method in the Rails agent adds an implicit sorting when I don’t want any.

> <https://github.com/ForestAdmin/forest-rails/blob/f9312e50896c6c526e9c95395b8047fc53e8d666/app/services/forest_liana/search_query_builder.rb#L160-L188>

Sorting in big database tables has negative performance impact and I want to avoid it completely. The Forest configuration in the collection settings gives the wrong impression that leaving the field and order empty:

 ![Screenshot 2022-03-02 at 19.34.59](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/f/fa487ef99b523bfd6fc4ae7db9fe57f208bf7331.png)  
would achieve no ordering, but it still orders records.

Please see the logs below that clearly show params without sorting, but the database query still using `order by`:

```javascript
Rack -- Started -- {:method=>"GET", :path=>"/forest/Order?timezone=Europe%2FLondon&fields%5BOrder%5D=id%2Ccreated_at%2Cupdated_at%2Cstate&filters=%7B%22field%22%3A%22state%22%2C%22operator%22%3A%22equal%22%2C%22value%22%3A%22placed%22%7D&page%5Bnumber%5D=1&page%5Bsize%5D=10"}
ForestLiana::UserSpace::OrderController -- Processing #index
(0.289ms) ActiveRecord -- Order Load -- {:sql=>"SELECT \"orders\".* FROM \"orders\" WHERE (\"orders\".\"state\" = 'placed') ORDER BY \"orders\".\"created_at\" DESC LIMIT $1 OFFSET $2", :binds=>{:limit=>10, :offset=>0}, :allocations=>168, :cached=>nil}
(3.716ms) ForestLiana::UserSpace::OrderController -- Completed #index -- {:controller=>"ForestLiana::UserSpace::OrderController", :action=>"index", :params=>{"timezone"=>"Europe/London", "fields"=>{"Order"=>"id,created_at,updated_at,state"}, "filters"=>"{\"field\":\"state\",\"operator\":\"equal\",\"value\":\"placed\"}", "page"=>{"number"=>"1", "size"=>"10"}, "collection"=>"Order"}, :format=>"JSON", :method=>"GET", :path=>"/forest/Order", :status=>200, :view_runtime=>0.16, :allocations=>2244, :status_message=>"OK"}

```

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [March 3, 2022, 2:48pm UTC](https://community.forestadmin.com/t/configuring-collection-without-sorting-does-not-have-an-effect/4293/2 "2022-03-03T14:48:48Z")

</div>

Hi @Jimmi and welcome in our community 🍾 !

Not having a sort would mean no possibility to have a pagination which is not what we want. So the sort IS necessary.  
In your case, if you don’t want a loss of performance you could order by your primary key or by `created_at` and adding an index on the `created_at` field 😉

---

<div class="post-metadata">

**Author:** ![Jimmi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jimmi/32/304_2.png) [@Jimmi](https://community.forestadmin.com/u/Jimmi)\
**Post date:** [March 3, 2022, 5:42pm UTC](https://community.forestadmin.com/t/configuring-collection-without-sorting-does-not-have-an-effect/4293/3 "2022-03-03T17:42:45Z")

</div>

If Forest Liana will apply sorting, no matter what, then why does the Forest UI allows me to set it to empty, without any warning? That seems confusing to me.

Additionally, I have tested with Postgres and it does not require an `order by` for the pagination to work. The returned rows might not be stable in the long term, but I think that should be left to the discretion of the Forest editor.

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [March 4, 2022, 2:49pm UTC](https://community.forestadmin.com/t/configuring-collection-without-sorting-does-not-have-an-effect/4293/4 "2022-03-04T14:49:20Z")

</div>

Hey @Jimmi,

Actually you are correct it’s not the case on other agent (`forest-express-sequelize` for instance). Let me report the issue.

> **[ClickUp](https://sharing.clickup.com/t/h/227p51j/YNRHRGDUY7O27H1)**
