Optimizing multi-criteria sort query
If I divide the time for query planning and execution by the number of rows returned, I find that the &quot;big&quot; query took 0.00054 milliseconds per result row, while the &quot;small&quot; one took 0.00234 milliseconds, more than four times as long.
If you add to that the (unknown) time it took to get the shape_ids in the first place, I cannot see how splitting up the query can lead to a performance advantage.
Besides, you later have to combine all the small result sets and sort them by shape_pt_sequence, which will also take some time.
The &quot;big&quot; query doesn't sort at all, it uses an index scan, and that is probably the most efficient way to go about it.