How to know when Snowflake queries are spilling to storage #1550
bennieregenold7
announced in
Archive
Replies: 1 comment
-
Thank you for this discussion. Regarding #3, CTEs are perfectly fine to achieve optimal performance as long as you design them correctly. CTEs should select as little as needed, filter as early as possible and have that help filter larger datasets later. To get the best performance, CTEs should be written as an inverted funnel. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One of the biggest killers of performance in Snowflake is queries spilling to either local or remote storage. This happens when your query processes more data than your virtual warehouse can hold in memory, and is directly related to the size of your warehouse.
Find the problem
So, how do you know if you have spillage? The easiest way is to go into the query profile and look for the stats there. To do that, go to the
History
tab in the IDE and find the query that is performing poorly. Then, click on theQuery ID
field and clickProfile
. If your query has multiple steps you may need to click throughStep 1
,Step ...
, until you find the one that's spilling.In the example below you can see that 45.64 GB of data spilled to local storage. This spillage has a significant impact on performance because you incur the time it takes to move that data to storage, and then anytime that Snowflake needs to retrieve it, it is using less performant resources to pull it. For more specifics on this, checkout Snowflake documentation.
Fix the problem
There are a few things you can do to fix this problem:
Beta Was this translation helpful? Give feedback.
All reactions