﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 07:57:35 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>I thought Fried Rice  :-D &amp; Egg Omlet  :-P</description><pubDate>Wed, 13 Mar 2013 01:07:28 GMT</pubDate><dc:creator>karthik M</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]Lynn Pettis (3/11/2013)[/b][hr][quote][b]Eugene Elutin (3/11/2013)[/b][hr]Curiosity is a great thing!Without it, elephants wouldn't have trunks...What does the Crocodile have for dinner?...:hehe:[/quote]Whatever it wants...[/quote]It prefers to start with curios, little elephants, actually... (as per Rudyard Kipling):hehe:</description><pubDate>Mon, 11 Mar 2013 06:12:59 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]Eugene Elutin (3/11/2013)[/b][hr]Curiosity is a great thing!Without it, elephants wouldn't have trunks...What does the Crocodile have for dinner?...:hehe:[/quote]Whatever it wants...</description><pubDate>Mon, 11 Mar 2013 06:04:09 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>Curiosity is a great thing!Without it, elephants wouldn't have trunks...What does the Crocodile have for dinner?...:hehe:</description><pubDate>Mon, 11 Mar 2013 05:05:00 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]Matt Miller (#4) (3/8/2013)[/b][hr]Besides - all of those sorts methods you mentioned presume a flat list structure.  The internals for how tables are structured are anything but flat.In short - I suspect the actual answer is "none of the above".[/quote]I'd tend to agree with Matt on this - my suspicion is that it will use a heavily optimised hash table in most circumstances but the only people that can give you a definitive answer would be Microsoft.You could try asking on MSDN.</description><pubDate>Mon, 11 Mar 2013 04:26:41 GMT</pubDate><dc:creator>crmitchell</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>Besides - all of those sorts methods you mentioned presume a flat list structure.  The internals for how tables are structured are anything but flat.In short - I suspect the actual answer is "none of the above".</description><pubDate>Fri, 08 Mar 2013 08:23:12 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>I would suspect that there's some sort of internal algorithm used to select the best sort algorithm for a given data set, based on the data type, data volumes etc</description><pubDate>Fri, 08 Mar 2013 05:13:07 GMT</pubDate><dc:creator>Jason-299789</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]karthik M (3/8/2013)[/b][hr][quote]Why does it matter which one SQL uses? [/quote]I am asking "Out of Curiosity" to know the algorithm used by the engine.[/quote]So download the public symbols, attach a debugger to SQL Server and walk through what runs when you order a query.</description><pubDate>Fri, 08 Mar 2013 04:48:57 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]karthik M (3/8/2013)[/b][hr]is this a secret maintened by microsoft ? :-)[/quote]In the sense that it's proprietary information that they've chosen not to share and SQL Server is a closed source product, yes.</description><pubDate>Fri, 08 Mar 2013 04:22:05 GMT</pubDate><dc:creator>HowardW</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]karthik M (3/8/2013)[/b][hr]is this a secret maintened by microsoft ? :-)[/quote]Short answer, yes.Longer answer, Microsoft publishes some of the internals because it helps people understand how or why things are occurring within the system. Also, some people figure out some of the internals through trial &amp; error, investigation, or even putting a debugger on the system. But all the internals are not published. There are lots and lots of proprietary information that Microsoft has inside the code that they just don't feel the need to share. The exact sorting process used by the query engine (not the optimizer) is not something I've seen documentation on, so I suspect it's protected.</description><pubDate>Fri, 08 Mar 2013 04:20:59 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>is this a secret maintened by microsoft ? :-)</description><pubDate>Fri, 08 Mar 2013 04:10:46 GMT</pubDate><dc:creator>karthik M</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote]Why does it matter which one SQL uses? [/quote]I am asking "Out of Curiosity" to know the algorithm used by the engine. </description><pubDate>Fri, 08 Mar 2013 04:09:06 GMT</pubDate><dc:creator>karthik M</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]karthik M (3/8/2013)[/b][hr]whereever the optimizer sort the data, it sould use some algorothim to do this operation? Right? My question is simple, is there any alogrithm used for ORDER BY clause or not by the optimizer?[/quote]As I said earlier, the optimiser won't use any algorithm. The optimiser optimises queries, it doesn't run them.Sure there will be algorithms used for order by (and for every single other operation given the definition of 'algorithm'). Why does it matter which one SQL uses?</description><pubDate>Fri, 08 Mar 2013 02:54:47 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>The optimiser is the wrong term for this, it's not the query optimiser that performs sorts. The Query Engine obviously uses algorithms to perform sorts. Those algorithms are proprietary and undocumented, but you'd imagine them to be based on some of the better performing sorting mechanisms above, tweaked and changed for SQL's internal storage characteristics, index usage, parallelism, statistics, etc.</description><pubDate>Fri, 08 Mar 2013 02:42:19 GMT</pubDate><dc:creator>HowardW</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>whereever the optimizer sort the data, it sould use some algorothim to do this operation? Right? My question is simple, is there any alogrithm used for ORDER BY clause or not by the optimizer?</description><pubDate>Fri, 08 Mar 2013 01:57:40 GMT</pubDate><dc:creator>karthik M</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]Grant Fritchey (3/7/2013)[/b][hr][quote][b]GilaMonster (3/7/2013)[/b][hr]Unless the data's small enough it can manage entirely within the memory grant. Not much chance of that except with trivial data.[/quote]Not arguing, just clarifying, won't it allocate some space on tempdb anyway?[/quote]Sorts I don't think so, not unless it actually spills. Until it spills, it's within the query execution's memory memory space.</description><pubDate>Thu, 07 Mar 2013 09:45:14 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]GilaMonster (3/7/2013)[/b][hr]Unless the data's small enough it can manage entirely within the memory grant. Not much chance of that except with trivial data.[/quote]Not arguing, just clarifying, won't it allocate some space on tempdb anyway?</description><pubDate>Thu, 07 Mar 2013 09:34:35 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]Grant Fritchey (3/7/2013)[/b][hr]The query engine will do what it does. That's in the internals. No way to know without a debugger or insider knowledge. It will use tempdb though.[/quote]Unless the data's small enough it can manage entirely within the memory grant. Not much chance of that except with trivial data.</description><pubDate>Thu, 07 Mar 2013 09:27:35 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>The query engine will do what it does. That's in the internals. No way to know without a debugger or insider knowledge. It will use tempdb though.</description><pubDate>Thu, 07 Mar 2013 05:55:43 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>[quote][b]karthik M (3/7/2013)[/b][hr]I have a table with 5 rows.100523253445323No index has been created.If I use ORDER BY , which alogirthm is used to do this sort operation?523100232534453[/quote]Again, why?  It does it and it does it quickly.</description><pubDate>Thu, 07 Mar 2013 05:54:14 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>I have a table with 5 rows.100523253445323No index has been created.If I use ORDER BY , which alogirthm is used to do this sort operation?523100232534453</description><pubDate>Thu, 07 Mar 2013 05:41:47 GMT</pubDate><dc:creator>karthik M</dc:creator></item><item><title>RE: ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>Well the optimiser won't use any algorithm. The optimiser optimises queries, it doesn't run them.Why does it matter?</description><pubDate>Thu, 07 Mar 2013 02:40:07 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>ORDER BY = Bubble Sort ? Quick Sort ? Insertion Sort ?</title><link>http://www.sqlservercentral.com/Forums/Topic1427851-392-1.aspx</link><description>Hi All,When We sort the data by using ORDER BY , which sorting algorithm method will be used by SQL optimizer?1) Bubble Sort2) Quick Sort3) Merge Sort4) Heap Sort5) Insertion SortInputs are welcome!</description><pubDate>Thu, 07 Mar 2013 02:37:17 GMT</pubDate><dc:creator>karthik M</dc:creator></item></channel></rss>