Oops, a bug again
In continued working on the sortby. Unfortunately, I discovered a bug with another optimisation that I had done earlier (an optimisation that removes useless let and record selection operators, and that is used in conjunction with the SQL optimisations). I haven't fixed this one yet.