Referential Join Decision Calculator for SAP HANA Calculation Views
Determine if it’s safe and optimal to use a referential join in your specific calculation view scenario.
Decision Tool
Enter the properties of your join to see if a referential join is appropriate. The answer to “can we use referential join in calculation view” depends on these factors.
Join Decision Logic Chart
This chart visualizes the logic used by the calculator to determine the best join type for your SAP HANA Calculation View.
| Scenario | Cardinality | Integrity Guaranteed | Recommendation |
|---|---|---|---|
| Ideal Case | N..1 or 1..1 | Yes | Referential Join (Optimal Performance) |
| Integrity Unsure | N..1 or 1..1 | No | Inner Join (Safe but Slower) |
| Invalid Cardinality | 1..N or N..M | – | Inner or Left Outer Join (Referential is Unsafe) |
What is “can we use referential join in calculation view”?
The question “can we use referential join in calculation view” is a common one for SAP HANA developers aiming for maximum performance. A referential join is a highly optimized join type that acts semantically like an inner join but with a critical assumption: that referential integrity is guaranteed by the application or source system. This means for every row in the “many” side of the join (the left/fact table), a corresponding entry exists on the “one” side (the right/dimension table).
If this condition is met, the HANA engine can make powerful optimizations, most notably “join pruning”. This means if a query does not request any columns from the right table, the entire join operation can be skipped, leading to significant performance gains. However, if integrity is not guaranteed, using a referential join can lead to incorrect data and aggregations. This calculator helps you decide based on your specific modeling scenario.
Referential Join Formula and Explanation
There isn’t a mathematical formula, but a logical one. The decision is based on a set of rules. The primary question you must answer is: Does every foreign key in the fact table have a matching primary key in the dimension table?
| Variable | Meaning | Unit | Typical range |
|---|---|---|---|
| Join Cardinality | The relationship between the left (fact) and right (dimension) tables. | Ratio | N..1, 1..1, 1..N, N..M |
| Referential Integrity | The guarantee that a matching record exists in the right table for every record in the left. | Boolean (Yes/No) | True or False |
| Join Pruning Goal | The desire for the HANA engine to skip the join if no fields from the right table are needed. | Boolean (Yes/No) | True or False |
For more details on performance, see our article on SAP HANA Calculation View Performance Tips.
Practical Examples
Example 1: The Ideal Scenario
You are joining a Sales Fact table (left) to a Product Dimension table (right) on `ProductID`. You know that every sale record has a valid, existing `ProductID`.
- Inputs: Cardinality = N..1, Integrity Guaranteed = Yes.
- Results: YES. This is the perfect use case. Queries that don’t need product details (e.g., total sales amount) will be extremely fast due to join pruning. Queries that do need product details (e.g., sales by product category) will execute correctly, behaving like an inner join.
Example 2: The Unsafe Scenario
You are joining a user activity log (left) to a user profile table (right). Some activities might be from guest users who don’t have a profile, or from users who were later deleted.
- Inputs: Cardinality = N..1, Integrity Guaranteed = No.
- Results: NO. Using a referential join here is dangerous. If you query for an aggregate measure from the activity log, HANA might assume matches exist and produce an incorrect total. You should use a Left Outer Join to ensure all activity log records are preserved, or an Inner Join if you only want to analyze activities from known users. Explore the differences in our guide on referential join vs inner join sap hana.
How to Use This can we use referencial join in calculation view Calculator
Follow these steps to determine the correct join strategy:
- Select Cardinality: Choose the cardinality that represents your join from the dropdown. For classic star schemas, this is almost always N..1.
- Confirm Integrity: Honestly assess if your data’s referential integrity is perfect. If there’s any doubt, uncheck the box. This is the most critical step.
- Consider Pruning: Check the “Join Pruning” box if you have queries that only select measures from the fact table, as this is the primary benefit of a referential join.
- Review the Result: The tool will instantly tell you if a referential join is recommended, cautioned, or unsafe, and provide the best alternative.
Key Factors That Affect Join Behavior
- Data Cleansing: The quality of your ETL process directly impacts whether you can guarantee referential integrity.
- Query Patterns: The performance benefit is only realized when queries don’t select columns from the right table. Analyze your typical query patterns. Read about hana join pruning.
- Cardinality Setting: The optimizer relies on the cardinality you set in the calculation view to make its decisions. An incorrect setting can mislead the engine.
- Source System Guarantees: Some systems, by design, ensure integrity (e.g., preventing deletion of master data that has associated transactions).
- Join Type in View: Since SAP HANA 1.0 SP11, referential joins can be combined with other join types like Left Outer, adding another layer of behavior.
- Calculated Columns: Introducing calculated columns on join fields can sometimes prevent optimizations. It’s best to join on raw table columns. See our deep dive on joining on calculated columns.
FAQ about Referential Joins
- 1. What happens if I use a referential join and integrity is broken?
- You may get incorrect results. For example, an aggregate measure (like SUM of sales) could be wrong because HANA might not execute the join, thus not filtering out rows that should have been excluded by an inner join.
- 2. Is a referential join faster than an inner join?
- It can be, specifically when join pruning occurs. If the join is executed, the performance is very similar to an inner join. The main benefit is avoiding the join execution entirely.
- 3. What’s the difference between a referential join and a left outer join?
- A referential join assumes a match exists and may behave like an inner join. A left outer join makes no such assumption and will always return all rows from the left table, filling in NULLs for non-matching rows from the right table.
- 4. Can I always use a Referential Join for N..1 cardinality?
- No. The cardinality is a prerequisite, but the guarantee of referential integrity is the deciding factor. If integrity is not 100% certain, use an inner or left outer join.
- 5. When does join pruning actually happen?
- It happens when you set the join type to Referential (or Left Outer in some cases) and your query does NOT request any columns (not for select, filter, or aggregation) from the right-hand table.
- 6. My referential join is slow. Why?
- If your queries always require columns from both tables, the join will always be executed, and you won’t see the pruning benefit. Check your query design or use tools for performance optimization of calculation views.
- 7. Does the “Dynamic Join” feature relate to this?
- Yes, dynamic joins are another optimization feature where the engine can prune joins based on the columns requested by the query. They can be used in conjunction with referential joins.
- 8. Where is the setting for referential join?
- In the graphical calculation view editor, when you define a join between two nodes, you select the ‘Join Type’ property in the join’s details panel and set it to ‘Referential’.
Related Tools and Internal Resources
Explore these related topics for a deeper understanding of SAP HANA modeling and performance:
- SAP HANA Calculation View Performance Tips: General best practices for optimizing your views.
- Referential Join vs. Inner Join: A detailed comparison of these two common join types.
- Understanding Join Pruning: An in-depth look at how HANA avoids expensive join operations.