page52
33
Physical Query Plan
Finally, the physical query plan is delivered for execution. This is the optimal or “best”
plan developed through application of all the prior steps.
The physical query plan is a directed acyclic graph (DAG) for which further
information can be found here:
https://en.wikipedia.org/wiki/Directed_
acyclic_graph
.
A DAG may be thought of as a flowchart with unidirectional links to branching logic
where a determination is made to proceed or finish. There are no cycles or loops within
the DAG, and it is not possible to follow a series of directed edges and return to the
same node.
DAGs provide a useful way to represent dependencies, workflows, and hierarchical
relationships between different elements in a system or problem.
Within the Snowflake physical query plan, the branching logic is one of the
following:
•
Operators that either process data or implement a feature such as
aggregation, filtering, or summary.
•
Links that are pipelines connecting operators or implementing
parallelization features.
You can help the query optimizer by delivering the minimally simplest code.
As it happens, the simplest code is most often the easiest to read and best laid out.
Remember: smallest table first.
Query Execution
Data stored in a hybrid, columnar, compressed format lends itself to parallel processing.
Snowflake processes queries using massively parallel processing (MPP) compute
clusters where each node in the cluster stores a portion of the entire data set locally in
columnar format.
In other words, if you can “chunk” data into discrete groups, each “chunk” can be
processed independently by a separate processing unit.
Storing data in an organized manner improves clustering too; I will discuss this
further in Chapter 4.
Chapter 2
the Query Optimizer