Snowflakes and why not to use them (1/4): The Basics

Snowflakes and why not to use them (1/4): The Basics

Stars and snowflakes

There are two basic ways how to model data for reporting and analytics. These are star schema and snowflake schema. The only difference is that snowflake schema can contain links between dimensions, while in star schema dimensions can be linked only directly to the fact table. The diagrams below illustrate the differences:

Fig 1.: Snowflake schema (source: Wikipedia, Snowflake.)

Fig 2.: Star schema (source: Wikipedia, Star.)

Slowly changing dimension

Most of the datawarehouses will keep history of changing data. This means that you want to track how dimensional data change. For example, if customer changes address you want to keep both records – before the change and after the change. Although I worked on some datawarehouses where this was not implemented and dimensions were always completely reloaded, most of the implementations I was involved in did contain slowly changing dimensions (SCD) and most often it was SCD2. I will shortly explain SCD2 but will not elaborate on the other types, there is plenty of stuff out there:

  • SCD2 versions data using two timestamp columns (ValidFrom and ValidTo)
  • Current records has ValidTo = NULL
  • Once a record is updated or deleted ValidTo is updated to the time of deletion or update; if this time is not supplied by the source system it is the time of the ETL load (just simple GETDATE()).
  • If you load round the clock the precision of this timestamp might need to be up seconds
  • I would strongly suggest to implement hash to identify the changes. Hash would be calculated over all the columns except business key (but that can be included as well but it is of no use). The whole data flow can be described using the following diagram:

Fig 3.: Data flow of SCD2 with hashes

Few last words...

In this text I have explained the basic terms I will be using in the next articles. These are star and snowflake schemas and slowly changing dimension type 2. In the next text I will implement those in MS SQL 2012. What about you? Do you use snowflakes or stars? Do you use SCDs?

Sources:

My previous technical articles:


Ron van der Poel

BI Engineer Azure Cloud / Power BI at Rabobank Netherlands

8 年

Hai Petr, how do you implement hash in a DB2 environment?

回复
Roger Jackson

Retiree at University of Life

8 年

Nowflake brings the worst features of both Star and Relational... it guarantees the integrity of data structures at the cost of high performance big queries. No one solution is ever perfect in every way?

The problem of the snowflake schema is performance: the more joins, the less performance. This is why we try to avoid them if we can. There is no shame in denormalizing a datawarehouse, quite the contrary. The shame is on slow reports! Also, I like your diagram. I have used this technique not for SCD2 but for Change Data Capture (differential load of big tables). Same principles. But you explain it neatly.

I prefer Star schema overall. Not sure the last time I used a Snowflake schema. I say about 50% of my projects I have used SCD2, depends on project requirements. Hash approach has always been the best way for me to change data.

回复
Pugazendhi A.

Sudar.io - Extreme Automation of AI data foundation and data products A first in many ways! - Enterprise Data Warehouse (DV2.0) Design Deploy & Load complete no-code automation - SQL only Business Vault

8 年

Nice article. I agree this is would be a great SCD2 load strategy for many use cases. Most cases I have seen have source as more than one table for the SCD2 dimension. In this case different columns of the dimension come from different source tables. I guess this strategy would count on a staging table with columns matching the target data. The overhead with managing the staging table this way needs to be weighed against the efficiency by this process. Also, when we get delta feeds of the source(s), the 'Delete record' step will need a different route.

回复

要查看或添加评论,请登录

Petr Podrouzek的更多文章

  • Innovating with Emplifi Unified Analytics ??

    Innovating with Emplifi Unified Analytics ??

    Last week marked a significant milestone for Emplifi with the launch of Unified Analytics ??. This feature symbolizes…

    3 条评论
  • My goals for 2022

    My goals for 2022

    My goal for January was to come up with what I would like to achieve in 2022 professionally. I asked myself how can I…

    2 条评论
  • Top 3 things I did in 2021

    Top 3 things I did in 2021

    I truly believe it is important to reflect on past experiences and learnings. Sometimes we are so preoccupied with the…

    3 条评论
  • Data warehouse release nightmares (2/2)

    Data warehouse release nightmares (2/2)

    In the previous text, I have discussed the issues I have encountered when releasing DWH based on my 10 years of…

  • Data warehouse release nightmares (1/2)

    Data warehouse release nightmares (1/2)

    I have been a BI/DWH developer for nearly 10 years now and most of the projects I have worked on had one particular…

    1 条评论
  • What value can MDM bring to organisations and at what cost? (3/3)

    What value can MDM bring to organisations and at what cost? (3/3)

    In the previous articles, I have discussed the benefits of implementing MDM but also the costs it can bring. Now let's…

  • What value can MDM bring to organisations and at what cost? (2/3)

    What value can MDM bring to organisations and at what cost? (2/3)

    In the previous article, I discussed the benefits of implementing MDM. As with any technology, it does come with a cost…

  • What value can MDM bring to organisations and at what cost? (1/3)

    What value can MDM bring to organisations and at what cost? (1/3)

    There are many applications supporting various processes in organizations - there is not a single process that would…

    3 条评论
  • Snowflakes and why not to use them (4/4): Conclusion

    Snowflakes and why not to use them (4/4): Conclusion

    In the previous articles, I have introduced simple snowflake utilizing SCD2 model. I have also build a simple star…

    1 条评论
  • Snowflakes and why not to use them (3/4): The problem

    Snowflakes and why not to use them (3/4): The problem

    As stated in the previous article, snowflakes can be more efficient in using storage compared to stars. And believe me,…

    2 条评论

社区洞察

其他会员也浏览了