O'Reilly logo

SQL Performance Tuning by Trudy Pelzer, Peter Gulutzan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. ORDER BY

The ORDER BY clause causes sorts. Sorts take time. In this chapter, we'll look at how much time, and what you can do about it.

Some of this chapter is also relevant to other situations that cause sorts. It is a simple matter to see that DBMSs may choose to sort a list when they need to discover duplicates, so GROUP BY, DISTINCT, CREATE [UNIQUE] INDEX, and UNION might use the same algorithms that are used by ORDER BY. Less commonly, DBMSs may choose to sort any two lists and merge them when they need to perform either inner or outer joins. In all those cases, though, the sorting is a side effect, so we'll focus on ORDER BY—with the admonishment that what we're saying may be applicable more broadly.

General Sort Considerations ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required