Why are relational set-based queries better than cursors?

The main reason that I’m aware of is that set-based operations can be optimised by the engine by running them across multiple threads. For example, think of a quicksort – you can separate the list you’re sorting into multiple “chunks” and sort each separately in their own thread. SQL engines can do similar things with huge amounts of data in one set-based query.

When you perform cursor-based operations, the engine can only run sequentially and the operation has to be single threaded.

Leave a Comment