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