Sort Algritham Used SNOWFLAKE database

I am trying to understand the kind of sorting algorithm used by ORDER BY Clause in SNOWFLAKE SQl.

When we put order by on columns . It sort data based ASC or DESC with NULL AS FIRST OR LAST.

Is it Merge Sort ? or any other hybrid sort technique

Upvotes: 0

Views: 1514

Answers (1)

Rajib Deb
Rajib Deb

Reputation: 1774

This is mentioned in the documentation @ https://docs.snowflake.com/en/sql-reference/constructs/order-by.html

All data is sorted according to the numeric byte value of each character in the ASCII table. UTF-8 encoding is supported.

For numeric values, leading zeros before the decimal point and trailing zeros (0) after the decimal point have no effect on sort order.

Unless specified otherwise, NULL values are considered to be higher than any non-NULL values. As a result, the ordering for NULLS depends on the sort order:

If the sort order is ASC, NULLS are returned last; to force NULLS to be first, use NULLS FIRST.

If the sort order is DESC, NULLS are returned first; to force NULLS to be last, use NULLS LAST.

An ORDER BY can be used at different levels in a query, for example in a subquery or inside an OVER() subclause. An ORDER BY inside a subquery or subclause applies only within that subquery or subclause. For example, the ORDER BY in the following query orders results only within the subquery, not the outermost level of the query:

Upvotes: 3

Related Questions