{"id":433,"date":"2024-06-28T11:36:57","date_gmt":"2024-06-28T11:36:57","guid":{"rendered":"https:\/\/datadandies.nl\/?p=433"},"modified":"2024-06-28T11:36:57","modified_gmt":"2024-06-28T11:36:57","slug":"clustering-depth-of-tables-in-snowflake-a-potential-indicator-of-clustering-health-of-a-table","status":"publish","type":"post","link":"https:\/\/datadandies.nl\/index.php\/2024\/06\/28\/clustering-depth-of-tables-in-snowflake-a-potential-indicator-of-clustering-health-of-a-table\/","title":{"rendered":"Clustering depth of tables in Snowflake: a potential indicator of clustering health of a table"},"content":{"rendered":"\n<p>Clustering depth indicates if micro-partitions are overlapping with one another. Ideally, micro-partitions are not overlapping and are contiguous. Being contiguous means that one micro-partition seamlessly connects with another micro-partition.<\/p>\n\n\n\n<p>Sometimes however, micro-partitions are overlapping. A reason for this could be a less than optimal clustering key. Whatever the reason, this is not ideal, because now you run the risk of unnecessarily scanning the same data twice when scanning two micro-partitions. A possible solution for a high clustering depth is choosing a clustering key that is better suited for the job.<\/p>\n\n\n\n<p>Below are some numbers to give you an idea of how clustering depth is defined in Snowflake.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;When you have a table with no micro-partitions (a table with no data), the clustering depth is 0.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;When you have a table that contains data and the micro-partitions are not overlapping and contiguous, the clustering depth is 1.<\/p>\n\n\n\n<p>You can find out the clustering depth of a table by using the system function below.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT SYSTEM$CLUSTERING_DEPTH(\u2018DATABASE.SCHEMA.TABLE\u2019)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">SELECT<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">SYSTEM<\/span><span style=\"color: #D8DEE9FF\">$CLUSTERING_DEPTH(\u2018DATABASE.SCHEMA.<\/span><span style=\"color: #81A1C1\">TABLE<\/span><span style=\"color: #D8DEE9FF\">\u2019)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>For the record, having a clustering depth of higher than 1 does not mean that you have to burn the entire database down, drop every table in existence and live a life as a potato farmer devoid of any computers from this moment on. Query performance is a better performance indicator.<\/p>\n\n\n\n<p>The Snowflake documentation has a great picture that assists in visualizing clustering depth. See the link below.<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/docs.snowflake.com\/en\/user-guide\/tables-clustering-micropartitions#clustering-depth-illustrated\n<\/div><\/figure>\n\n\n\n<p>Another link with some additional interesting info:<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.linkedin.com\/pulse\/demystifying-clustering-snowflake-guide-optimize-your-roshan-patil\/\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Clustering depth indicates if micro-partitions are overlapping with one another. Ideally, micro-partitions are not overlapping and are contiguous. Being contiguous means that one micro-partition seamlessly connects with another micro-partition. Sometimes however, micro-partitions are overlapping. A reason for this could be a less than optimal clustering key. Whatever the reason, this is not ideal, because now&hellip;<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/datadandies.nl\/index.php\/2024\/06\/28\/clustering-depth-of-tables-in-snowflake-a-potential-indicator-of-clustering-health-of-a-table\/\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[40,4],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-blog","tag-snowflake","tag-sql"],"_links":{"self":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":1,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":434,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts\/433\/revisions\/434"}],"wp:attachment":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}