How are algorithms chosen for a SQL query?

The algorithms are chosen automatically by the DBMS. For a given SQL query there may be many possible execution plans. Amongst all equivalent plans choose the one with lowest cost. Cost is estimated using statistical information from the database catalog.
For More Information Please Refer:

You May Also Like to Read: