Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a DBMS implement their own sorting algorithm? Or do they?

When a SQL is translated to C by parser such as YACC or BISON, does that piece of translated C code contains the the sorting algorithm mathematics? I do not understand how the sorting is implemented in a DBMS (such as MySQL or Microsoft SQL Server) - is the algorithm part of the grammar parser? Or, does the algorithm applies to a resulted group of data only after it get fetched from an SQL query, but not directly apply to the computer memory? Or is the sorting algorithm an ISO standard and that all DBMS are required to use the same algorithm?

I did my researched and googling but find no clear answer. Without unneedingly reading a book on database internal, could someone explain the concept clearly?

like image 890
KMC Avatar asked Mar 14 '23 14:03

KMC


1 Answers

The SQL standard does not include any specifications on how sorting should be done. When you issue a query with order by, it's the database's responsibility to return a result in the specified order, but each database is free to implement this however it sees fit.

like image 115
Mureinik Avatar answered Apr 08 '23 04:04

Mureinik