Also, sometimes you just have bad luck. I know.
There’s a hack called OPTION(RECOMPILE) that you add to OrderBy. It made this BAQ literally 100x faster:
The way this works (says the novice) is that OrderBy can be specified with a numeral representing the field to sort by.
So if you already sort by column 1, then 1 OPTION(RECOMPILE)
doesn’t change anything. But if you sort by column 5 then 3 then 4, and you still use 1 OPTION(RECOMPILE)
you will find that your precious sorting is lost. You’d have to recreate the logic with numbers. (I think it’s comma separated?)
But first, ignore all that and just give it a whirl and see if it runs faster.