Currently if you click "sort ascending" and then "sort descending" in the cog menu you get SQL something like this:
select * from (
select * from (
select id, slug, link_url, link_title, via_url, via_title, commentary, created, metadata, search_document, import_ref, card_image from blog_blogmark
) as results order by "link_title"
) as results order by "link_url" desc
Each sort wraps the previous sorted query in another nested query.
We can do better than this! Sorting really complex queries with with (...) in them and suchlike is hard, but we can at least notice if the query we are re-sorting ends with order by X already and replace that clause rather than wrapping the whole thing.
Currently if you click "sort ascending" and then "sort descending" in the cog menu you get SQL something like this:
Each sort wraps the previous sorted query in another nested query.
We can do better than this! Sorting really complex queries with
with (...)in them and suchlike is hard, but we can at least notice if the query we are re-sorting ends withorder by Xalready and replace that clause rather than wrapping the whole thing.