Configuring collection without sorting does not have an effect

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.

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:


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:

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"}

Hi @Jimmi and welcome in our community :champagne: !

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 :wink:

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.

Hey @Jimmi,

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

1 Like