Data Vault Techniques on Snowflake: Querying Really Big Satellite Tables
The central design choice is to stop treating a massive satellite as a table to be brute-force scanned and instead introduce a narrow companion structure that pinpoints the current row per parent key. The editorial point is not that one query shape is universally faster, but that Snowflakeโs storage layout and execution engine reward designs that separate history retention from current-state retrieval. That distinction matters because most reporting wants present values, while the satellite preserves full lineage.
The evidence is operational, not theoretical: a LEAD-and-QUALIFY approach scanned every micro-partition and returned 1.9 million current rows from 61 million records in about 50 seconds on an XSMALL warehouse, while a larger warehouse improved raw runtime only after spin-up and higher credit burn. Materialized views and search optimization did not fit the pattern, and streams solve a different problem. The proposed companion table enables dynamic pruning through a join filter, keeping the base satellite INSERT-ONLY.
The tradeoff is added moving parts. A current-state companion table must be loaded and maintained, even if transient, and the gain depends on disciplined idempotent loading with hash diffs. The cautionary note is that warehouse upsizing can mask poor data access patterns while increasing orchestration latency and cost. For practitioners, the significance is architectural: optimize around the common current-record lookup, but preserve the immutable history table and avoid designs that rely on constant physical reorganization.
Query Analysis
| Virtual Warehouse T-Shirt Size | Number of Nodes = Credits Charged Per Hourย | Credits Charged Per Second |
|---|---|---|
| XSMALL | 1 | 0.0003 |
| SMALL | 2 | 0.0006 |
| โฆ | โฆ | โฆ |
| X4LARGE | 128 | 0.0356 |
What could we do differently?
Storage in the cloud is cheap, and by using Snowflakeโs encrypted, compressed proprietary columnar and row-optimized tables, it is even cheaper. In 2021 Snowflakeย announcedย improvements to its data storage compression algorithms that reduced Snowflakeโs table storage footprint even further. The cost of storage on disk is a cost Snowflake incurs that is passed on to its customers. This means Snowflake achieves a smaller storage footprint than an equivalent table in another blob store and does not charge you for those savings, but instead passes those savings on to you Letโs look at data model and object options: 1.ย Materialized Viewย is a pre-computed data set derived from a query specification and stored for later use. Essentially, underneath a materialized view (MV) is the persistence of micro-partitions clustered in a way to better suit the type of queries that will be executed on that data itself. Weโd love to have the current records clustered together so that the query plan references the least number of micro-partitions to answer that query. The problem with a currentย limitationย of MVs is that it does not allow for window functions such as LEAD(), and therefore itโs not possible to infer the current record for a satellite table. Snowflake MVs also do not allow for join conditions and therefore cannot be used with a PIT table. 2.ย Search Optimization Serviceย (SOS) aims to significantly improve the performance ofย selective point lookupย queries on tables. A point lookup query returns only one or a small number of distinct rows. SOS is like a secondary index when clustering is not a feasible option, but for a small number of records this does not fall into the scope of retrieving millions of current records from a satellite table. In fact, after testing and allowing SOS to build its search access paths, attempting a query to find the current record for a parent entity does not use SOS at all. It is absent from the query profile and therefore SOS is not effective for this type of query. 3.ย Streamsย is a change data capture mechanism that places a point-in-time reference (called anย offset) as the current transactional version of the object. Although an excellent way of tracking new records in a table, streams have no concept of the table content itself. Once a stream is consumed, the offset moves to the end of the table indicating that all the records since it was last processed are now consumed. (We do have a use for streams in Data Vault as seen in blog post #2, and as we will also see in post #5.)Part 2 of 2 on query optimization: understanding JoinFilter
For the eagle-eyed reader, in the previous blog post we indeed did see something in the query plan that deserves an explanation: JoinFilter[6]:- Populatedย in parallelย from theย same sourceย using theย same mechanismย to detect changesย idempotently, the record-hash (aka HashDiff).
- A C-PIT exists for each satellite table needing an efficient querying mechanism, typicallyย high-churnย andย largeย satellite tables.
- C-PIT will contain theย business keyย if it is supporting aย hub-satellite table, or theย relationship keysย if it is supportingย a link-satellite table.
- C-PIT will contain the satelliteโs hash key, load date, and record hash and nothing else; the satellite table has the same Data Vault metadata tags but also (of course) the attributes of the parent entity. These could range from one attribute to hundreds.
- Unlike the satellite table, a C-PIT is disposable and therefore does not need the same protection as its related satellite table. Therefore, the table is defined asย transientย and does not have Fail-Safe or Time Travel beyond 1 day. It can deal with data loaded at any cadence becauseย high churnย is not a concern. The satellite table remains INSERT-ONLY.
- C-PIT is used in an equi-join to locate the current record from its accompanying satellite table.
- C-PIT is updated using aย MERGEย statement and keeps no history, it is only concerned with theย currentย record and therefore keeps theย active/currentย load date per parent key and that entityโs HashDiff. Remember a satelliteโs HashDiff is defined in staging as illustrated aboveโit can be sent to two destinations, the satellite table, and the C-PIT table respectively.
Lab report
This blog post is not intended to apply to your own experiments and doesnโt assume the solutions presented above will resolve all situations. The intention here is to give you various options to consider as you look to understand the possibilities of performance of the Data Cloud. It is important that you establish a repeatable pattern that has as few โswitchesโ as possible, and by switches I mean donโt design an architecture that follows a different automation path depending on minor factors that adds unnecessary complexity to your data flow. This will inevitably lead to technical debt. In the next blog post we will look at an architecture approach that exclusively uses Snowflake proprietary technology to achieve near real-time data pipelines.Reference:
- Working with Materialized Views โย https://docs.snowflake.com/en/user-guide/views-materialized.html
- Using the Search Optimization Service โย https://docs.snowflake.com/en/user-guide/search-optimization-service.html
- Understanding Snowflake Virtual Warehouse, Storage, and Cloud Services Usage โย https://docs.snowflake.com/en/user-guide/credits.html
- Introduction to Streams โย https://docs.snowflake.com/en/user-guide/streams-intro.html
- Caching in Snowflake โย Original Post
Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.
