page39
19
DISTINCT Clause
Where only unique rows are required to be returned, a
DISTINCT
clause may be used.
this optional clause is used to return unique rows only.
DISTINCT
forces an aggregation operation visible within the query profile. I discuss
this later, but for now it is sufficient to know there is an impact for using a
DISTINCT
clause. I find
SELECT DISTINCT
acceptable when sampling data as a pre-cursor to assist
the development process.
The use of
DISTINCT
in production code often indicates a missing join condition
within a query, an incomplete/incorrect database design, or an expedient solution being
used to resolve a data quality issue. Regardless of the root cause, I recommend always
investigating such occurrences.
ORDER BY Clause
For a variety of reasons you may need to order returned data sets in either ascending or
descending order. For example, in a graphical user interface, you may want to display
search results in alphabetical order.
this optional clause is used to sort returned data sets.
Ordering returned data sets forces a sort operation visible within the Query Profile. I
discuss this later, but for now it is sufficient to know there is an impact for using an
ORDER
BY
clause.
LIMIT/OFFSET
Sometimes you will need to sample data, and
LIMIT
provides the operator to restrict
the returned data set to a known sample size. Likewise, you might want to start your
sample from a nominal position within the returned data set, and
OFFSET
provides this
capability.
ChaptEr 1
tuning thE SnowFlakE Data ClouD