March 8, 2013 at 4:48 am
karthik M (3/8/2013)
Why does it matter which one SQL uses?
I am asking "Out of Curiosity" to know the algorithm used by the engine.
So download the public symbols, attach a debugger to SQL Server and walk through what runs when you order a query.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 8, 2013 at 5:13 am
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
_________________________________________________________________________
SSC Guide to Posting and Best Practices
March 8, 2013 at 8:23 am
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".
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
March 11, 2013 at 4:26 am
Matt Miller (#4) (3/8/2013)
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".
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.
March 11, 2013 at 5:05 am
Curiosity is a great thing!
Without it, elephants wouldn't have trunks...
What does the Crocodile have for dinner?...
:hehe:
March 11, 2013 at 6:04 am
Eugene Elutin (3/11/2013)
Curiosity is a great thing!Without it, elephants wouldn't have trunks...
What does the Crocodile have for dinner?...
:hehe:
Whatever it wants...
March 11, 2013 at 6:13 am
Lynn Pettis (3/11/2013)
Eugene Elutin (3/11/2013)
Curiosity is a great thing!Without it, elephants wouldn't have trunks...
What does the Crocodile have for dinner?...
:hehe:
Whatever it wants...
It prefers to start with curios, little elephants, actually... (as per Rudyard Kipling)
:hehe:
March 13, 2013 at 1:07 am
I thought Fried Rice 😀 & Egg Omlet 😛
karthik
July 1, 2015 at 9:59 pm
There are two different sort logics used by SQL Server to handle sorting! First one is the quick sort and another one is Merge sort. It begins sort in memory using Quick Sort algorithm but note that the memory requirement for this is at least 200% of its input rows size. Now if the memory grant is exceeded(even by a single byte), it spills entire immediate sort and remaining sort to disk. Then it will complete the sort on disk using Merge Sort algorithm.
Pawan Kumar Khowal
MSBISkills.com
Regards,
Pawan Kumar Khowal
MSBISkills.com
July 2, 2015 at 9:07 am
Pawan Kumar Khowal (7/1/2015)
There are two different sort logics used by SQL Server to handle sorting! First one is the quick sort and another one is Merge sort. It begins sort in memory using Quick Sort algorithm but note that the memory requirement for this is at least 200% of its input rows size. Now if the memory grant is exceeded(even by a single byte), it spills entire immediate sort and remaining sort to disk. Then it will complete the sort on disk using Merge Sort algorithm.Pawan Kumar Khowal
MSBISkills.com
Rather than us just taking your word for it, please tell us how you came to these findings. Thanks.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 2, 2015 at 9:19 am
I know it's an old thread, but since it's been revived today, Paul White discusses the internals of the various sorts used by SQL Server in these two fairly recent articles:
http://sqlperformance.com/2015/04/sql-plan/internals-of-the-seven-sql-server-sorts-part-1
and
http://sqlperformance.com/2015/05/sql-plan/internals-of-the-seven-sql-server-sorts-part-2
Cheers!
July 7, 2015 at 7:23 am
crmitchell (3/11/2013)
Matt Miller (#4) (3/8/2013)
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".
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.
Ok I'll bite. How do you sort with a hash table? Isn't that the sort of index that you use when you DON'T want sorted / ISAM like access?
edit: missed the post dates LOL
July 7, 2015 at 7:49 am
patrickmcginnis59 10839 (7/7/2015)
crmitchell (3/11/2013)
Matt Miller (#4) (3/8/2013)
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".
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.
Ok I'll bite. How do you sort with a hash table? Isn't that the sort of index that you use when you DON'T want sorted / ISAM like access?
edit: missed the post dates LOL
You sort the index which holds the hashes to the original table.
July 7, 2015 at 8:16 am
crmitchell (7/7/2015)
patrickmcginnis59 10839 (7/7/2015)
crmitchell (3/11/2013)
Matt Miller (#4) (3/8/2013)
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".
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.
Ok I'll bite. How do you sort with a hash table? Isn't that the sort of index that you use when you DON'T want sorted / ISAM like access?
edit: missed the post dates LOL
You sort the index which holds the hashes to the original table.
It might return the hashes in sorted order, but you want the original rows in sorted order.
July 7, 2015 at 8:32 am
patrickmcginnis59 10839 (7/7/2015)
crmitchell (7/7/2015)
patrickmcginnis59 10839 (7/7/2015)
crmitchell (3/11/2013)
Matt Miller (#4) (3/8/2013)
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".
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.
Ok I'll bite. How do you sort with a hash table? Isn't that the sort of index that you use when you DON'T want sorted / ISAM like access?
edit: missed the post dates LOL
You sort the index which holds the hashes to the original table.
It might return the hashes in sorted order, but you want the original rows in sorted order.
No, the point of a hash table is that you don't need to change the location of the data on the filesystem. You sort on the key in the hashtable not the hash. The hash is a pointer to the location of the original row
The result of the query would be the original rows ordered according to the key on the hashtable.
Its the same principle as a nonclustered index which isn't a covering index but implemented at a lower level
Viewing 15 posts - 16 through 30 (of 30 total)
You must be logged in to reply to this topic. Login to reply