You are on page 1of 36

SPICA Join Path problems


A join path is a series of joins that a query can use to
access data in the tables linked by the joins.
Join path problems can arise from the limited way that
dimension and fact tables are related in a relational
The three major join path problems that you encounter
when designing a schema –
• loops
• chasm traps
• fan traps

SPICA Loops Explained

• In a relational database schema, a common type of join
path that returns too few rows is called a loop.

• Loops create additional conditions in the generated SQL
statement. Additional statements are added to the where
clause, producing in most cases an incorrect final result
set of a Business Objects query (too few rows).

• A loop is a set of joins that defines a closed path through
a set of tables in a schema. Loops occur when joins form
multiple paths between lookup tables.


SPICA Loop returns incorrect results DATA SYSTEMS .

SPICA Run following Query DATA SYSTEMS For each resort country. . give me the number of guests from each country that stay at each resort.

SPICA Expected Result DATA SYSTEMS .


city_id ) AND ( Region.country_id ) AND ( Resort.service_id=Invoice_Line.cust_id=Sales.service_id ) AND ( Sales.resort_id ) AND ( Service_Line.cust_id ) AND ( City.sl_id=Service.resort_id=Service_Line.region_id ) AND ( Country.region_id=City.inv_id ) AND ( Customer.sl_id ) AND ( Service.service_line = 'Accommodation' ) .inv_id=Invoice_Line.country_id=Resort.city_id=Customer.country_id ) AND ( Service_Line.SPICA Reason DATA SYSTEMS The Where clause created by the loop is shown below: WHERE ( Country.country_id=Region.

country_id=Resort.SPICA Joins causing the problem DATA SYSTEMS The following two joins are both applying a restriction to the Country table: • Country.country_id=Region.country_id .country_id • Country.

• Create Contexts for join paths.SPICA Solutions DATA SYSTEMS • Create alias of affecting dimensions. .

.SPICA Aliases Defined DATA SYSTEMS • An alias is an alternate name for a database table. • It is in some way similar to database view.

SPICA Create Alias for the Country DATA SYSTEMS .

sl_id ) AND ( Service_Line.cust_id ) AND ( Invoice_Line.country_id=Resort.sl_id=Service_Line.resort_id=Service_Line.SPICA Where clause after alias DATA SYSTEMS WHERE ( City.service_line = 'Accommodation' ) .inv_id ) AND ( Invoice_Line.resort_id ) AND ( Service.country_id ) AND ( Customer.service_id=Service.service_id ) AND ( Resort.city_id=Customer.cust_id=Sales.region_id ) AND ( Country_Region.region_id=Region.city_id ) AND ( City.country_id=Region.country_id ) AND (Country.inv_id=Sales.

SPICA Disadvantage of Aliases DATA SYSTEMS • Multiple copies of Similar Objects .

. You often use contexts in schemas that contain multiple fact tables (“multiple stars”) that share lookup tables and query requires data from only one fact table at a time.SPICA Context Defined DATA SYSTEMS A context resolves a loop by defining a set of joins that specify one specific path through tables in a loop. It ensures that joins are not included from different paths within the same SQL query.

Consider Following schema SPICA with Loop DATA SYSTEMS .

you break the loop. but if you want to add a City table to the schema. you end up with a loop again as shown below: .SPICA Alias doesn’t solve the problem DATA SYSTEMS If you created an alias for the Customer so that you had a Customer to Reservation join and a Customer_Sales to Sales join.

SPICA No end to Aliasing DATA SYSTEMS You must continue creating aliases for each new table you add to the schema. . and also ends up proliferating the number of similar objects using each table in the universe. This is difficult to maintain.

This ensures that queries answer questions for one transaction or the other. and create a context that specifies one or the other path around the schema.SPICA Create Context DATA SYSTEMS The only way to resolve this loop is to leave the loop in place. such as: Is the customer information needed from the perspective of sales or reservations? .

you can follow two different paths from the Customer table to the Service table: .SPICA Designer Detects two contexts DATA SYSTEMS • In the example.

SPICA Reservation Line Context DATA SYSTEMS .

SPICA Sales Line Context DATA SYSTEMS .

Cardinalities must be set before detecting loops . Automatically Identifying and SPICA Resolving Loops DATA SYSTEMS You can use Designer to automatically detect loops and propose candidate aliases and contexts that you can insert in your schema to resolve the loops.

SPICA Chasm Trap DATA SYSTEMS A chasm trap is a type of join path between three tables when two "many-to-one“ joins converge on a single table. and there is no context in place that separates the converging join paths (The three tables have been separated from the rest of the schema to illustrate the chasm trap). Contd… . of rows in the query. Chasm Trap inflates no.

Incorrect results only when all the following conditions exist SPICA DATA SYSTEMS .

Results of two SPICA separate Queries DATA SYSTEMS .

SPICA Result of combined Query DATA SYSTEMS .

A Cartesian product has been returned and the results are incorrect. .SPICA Reason DATA SYSTEMS The number of guests that have used. and future guests who have reserved to use the Sports service has increased considerably.

context is the only way to resolve Chasm Trap. Resolving a Chasm Trap SPICA DATA SYSTEMS The second option works when fact table has only numerical columns. in this way contexts can be avoided. . Junk dimension should be designed for descriptive elements of fact table. If the fact table has descriptive columns.

The fanning out effect of “one-to-many” joins can cause incorrect results to be returned when a query includes objects based on both tables. .SPICA Fan Traps DATA SYSTEMS A fan trap is a type of join path between three tables when a “one-to many” join links a table which is in turn linked by another “one-to-many” join.

w/o Model Id DATA SYSTEMS .SPICA Correct Result.

Incorrect result after SPICA adding Model Id DATA SYSTEMS .

SPICA Reason DATA SYSTEMS Sales is not available at Model Id Level .


SPICA Correct Results DATA SYSTEMS .

Insert product_promotion_facts & promotion_lookup tables into the existing universe. 4. Contexts . Manually create Aliases.SPICA Exercise # 2 DATA SYSTEMS 1. Connect shop_facts & product_promotion_facts using shortcut join. 5. Insert joins & cardinalities. Create required Classes & Objects for these tables. Check integrity & solve Loops if any. Detect Loops and Contexts 7. 2. 6. 3.