sap hana_join types
TRANSCRIPT
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 1/24
©SAP AG HA300 2-2
© 2012 SAP AG. All rights reserved. 2
At the end of this Lesson you will be able to:
Objectives
Connecting Tables
Explain differences between Inner Join, Left Outer Join,
Right Outer Join, Full Outer Join, Text Join and
referential Join when connecting tables.
Explain how using Standard Union and Union with
constant values.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 2/24
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 3/24
©SAP AG HA300 2-4
© 2012 SAP AG. All rights reserved. 4
This module covers the following topics:
Overview
Connecting Tables
How to connect tables using
Inner Join
Left Outer Join
Right Outer Join
Full Outer Join
Text Join
Referential Join
Union
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 4/24
©SAP AG HA300 2-5
© 2012 SAP AG. All rights reserved. 5
Join Types – Definitions and Referential Integrity
Join Type Use when you need to
report on…
Be aware that…
INNER facts with matching dimensions
only
facts without any dimension will be excluded
dimensions without any fact will be excluded
JOIN is always performed
LEFT OUTER all posted facts whether there is
a matching dimension or not
dimensions without any fact will be excluded
best for performance because JOIN is omissible
RIGHT OUTER all dimensions whether there
are matching facts or not
facts without any dimension will be excluded
JOIN is always performed
REFERENTIAL facts for the requested
dimensions AND referential integrity is
ensured
it is the default join type
acts as an INNER for Attributes Views join on attribute views is “optional”, which facts are
returned will depend on which attributes are queried for
TEXT an SAP dimension table joined
to a text table for translation
purpose
only available for Attribute Views with SAP ERP tables
(SPRAS field) or equivalent design
acts as an INNER
Referential Joins
Is semantically a inner join that assume that referential integrity is given which means that theleft table always have an corresponding entry on the right table. It could be used in e.g. data
foundation for header-item relations where it can be assumed that for each item a header
exists. It can be seen as an optimized or faster inner join where the right table is not checked if
no field from the right table is requested. That means that the Referential Joins will be only
executed, when fields from both tables are requested. Therefore, if a field is selected from the
right table it will act similar to inner join, and if no fields from the right table is selected it will
act similar to a left outer join. From performance perspective, the Left Outer Join are almost
equally fast as Referential Join, while the Inner Join is usually slower due to the fact, that the
join is always executed.
Referential joins should be used with caution since it assumes that referential integrity is
ensured. The only valid scenario for the Referential Join is that (a) it is 100% guaranteed that
for each row in one table, there is at least one join partner in the other table, and (b) that holds
true in both directions (c) at all times. If that is not the case then referential joins have the
possibility to give incorrect calculations if the referential integrity is not met – meaning if a
delivery header is created but the items is not processed until a later stage then any
calculations that use referential joins will be incorrect.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 5/24
©SAP AG HA300 2-6
© 2012 SAP AG. All rights reserved. 6
Attribute View
Inner Join – Attribute View
Connecting Tables
Customer (3 & 4) is not
returned due to nocorresponding entry (TX) in
the state table.
Inner Join returns rows when there is at least one match in both sides of the join.
Inner is used even if it’s not added.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 6/24
©SAP AG HA300 2-7
© 2012 SAP AG. All rights reserved. 7
Inner Join – Analytical View
Connecting Tables
Analytical
View
Be aware that Inner Joinslose facts with fragmented
dimensions. Order (4 & 77)
lost due to no
corresponding customer
and state record
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 7/24
©SAP AG HA300 2-8
© 2012 SAP AG. All rights reserved. 8
Inner Join and Design Time Filters
Connecting Tables
Design time filter applied ( AGE < 13)
of left/central table
Design time filter applied to (STATE = MI)
on right table
Both design time filters are applied first
before the join is executed
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 8/24
©SAP AG HA300 2-9
© 2012 SAP AG. All rights reserved. 9
Attribute View
Left Outer Join – Attribute View
Connecting Tables
No matches for TX in the right table.
Left Outer Join returns all rows from the left
table even if there are no matches in the
right table.
This join is popular in Analytical Views
whereby the Attribute view is joined to the
fact table.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 9/24
©SAP AG HA300 2-10
© 2012 SAP AG. All rights reserved. 10
Left Outer Join – Analytical View
Connecting Tables
Analytical
View
Customer (TOM) is
not returned due to no
corresponding sale
item record in sales
order table.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 10/24
©SAP AG HA300 2-11
© 2012 SAP AG. All rights reserved. 11
Left Outer Join and Design Time Filters
Connecting Tables
Design time filter applied ( AGE < 13)
of left/central table
Design time filter applied to (STATE = MI)
on right table
Filters are applied to both tables and then
afterwards the join is executed.
Due to the left outer join TOM will be included in
the result set even though he resides in TX
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 11/24
©SAP AG HA300 2-12
© 2012 SAP AG. All rights reserved. 12
Right Outer Join – Attribute View
Connecting Tables
Alabama is included in the result set,
though there is no match in the left
table.
Attribute View Right Outer Join returns all the rows from
the right table, even if there are no
matches in the left table.
Right outer join is rarely used, be aware, that the number of records in the result set is
determined by the number of records in the right table. This means that if there is a 1:nrelationship the number of records can be greater that the number of records in the left table.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 12/24
©SAP AG HA300 2-13
© 2012 SAP AG. All rights reserved. 13
Right Outer Join – Analytical View
Connecting Tables
Right Outer Join
results in NULL
measure.
Analytical
View
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 13/24
©SAP AG HA300 2-14
© 2012 SAP AG. All rights reserved. 14
Full Outer Join
Connecting Tables
STATE SNAME
? ? ? ? AL ALABAMA
1 WERNER 10 MI MI MICHIGAN
2 MARK 11 MI MI MICHIGAN
3 TOM 12 TX ? ?
4 BOB 13 TX ? ?
C_ID CNAME AGE STATE
Full Outer Join is neither left nor
right - it's both. It includes all therows from both of the tables or result
sets participating in the Join.
When no matching rows exist for
rows on the left side or right side of
the Join, you see NULL values.
Be aware that Full Outer Joins make up facts for unused dimension entries (ALABAMA)
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 14/24
©SAP AG HA300 2-15
© 2012 SAP AG. All rights reserved. 15
Text Join
Connecting Tables
Text Join are used to join a text
table to a master data table.
Text Joins acts as a Left Outer join
and can be used with SAP tables
where the language column
(SPRAS) is present.
For each attribute it is possible to
define a description mapping that
will be specific to the end users
language.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 15/24
©SAP AG HA300 2-16
© 2012 SAP AG. All rights reserved. 16
Join Types – Text Join for multilingual reporting
Text Join is used whentranslation for a dimension is
available
Designed for ERP table (and
typically SPRAS field)
User language is used as a filter
at runtime to find the right
translation for that attribute
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 16/24
©SAP AG HA300 2-17
© 2012 SAP AG. All rights reserved. 17
Referential Join
Connecting Tables
Relies on Referential Integrity Each entry in the left table MUST havea corresponding entry in the right table
Optimized for performance Join is only performed if at least one
field from the right table is requested.
Like an Inner Join when join is
executed
When field from both tables are
requested an inner Join is performed.
Only available in OLAP engine Referential join is a feature availableonly in OLAP engine, when testing
Attribute Views outside the context of a
Analytical view then the Join Engine
will perform a Inner Join.
Is semantically a inner join that assume that referential integrity is given which means that the
left table always have an corresponding entry on the right table. It could be used in e.g. datafoundation for header-item relations where it can be assumed that for each item a header
exists.
It can be seen as an optimized or faster inner join where the right table is not checked if no
field from the right table is requested.
That means that the Referential Joins will be only executed, when fields from both tables are
requested. Therefore, if a field is selected from the right table it will act similar to inner join,
and if no fields from the right table is selected it will act similar to a left outer join.
From performance perspective, the Left Outer Join are almost equally fast as Referential Join,
while the Inner Join is usually slower due to the fact, that the join is always executed.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 17/24
©SAP AG HA300 2-18
© 2012 SAP AG. All rights reserved. 18
Referential Join – Attribute View
Connecting Tables
*** Referential join is a feature available only in OLAP engine, when testing
Attribute Views outside the context of a Analytical view then the Join Engine will
perform a Inner Join. As a result TOM and BOB will not be returned.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 18/24
©SAP AG HA300 2-19
© 2012 SAP AG. All rights reserved. 19
Referential Join – Analytical View
Connecting Tables
*** TOM is not returned due to no
corresponding facts in the sales table
*** The Amount includes all facts including Customer 77 and BOBs
order even through master records do not exist reason is when
only non-key fields are selected from the left table, all joins to
other tables will be omitted
*** Customer 77, TOM and BOB are not returned since C_ID is a Joined key field
resulting in an Inner Join. BOB has no corresponding Texas description and TOM has no
corresponding facts.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 19/24
©SAP AG HA300 2-20
© 2012 SAP AG. All rights reserved. 20
Referential Join – Using MDX
Connecting Tables
No referential integrity
of data in both tables
No Join processed
Like Inner Join
Referential joins should be used with caution since it assumes that referential integrity
is ensured.The only valid scenario for the Referential Join is that (a) it is 110% guaranteed that for each
row in one table, there is at least one join partner in the other table, and (b) that holds true in
both directions (c) at all times.
If that is not the case then referential joins have the possibility to give incorrect calculations if
the referential integrity is not met – meaning if a delivery header is created but the items is not
processed until a later stage then any calculations that use referential joins will be incorrect.
Referential Join cannot be used if a filter is set on a field in the right table.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 20/24
©SAP AG HA300 2-21
© 2012 SAP AG. All rights reserved. 21
Calculation View- Join vs. Union
Connecting Tables
Caution!! Do not JOIN Analytical Views, this could lead to performance
implications. Instead use Union with constant values when working withmultiple fact tables
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 21/24
©SAP AG HA300 2-22
© 2012 SAP AG. All rights reserved. 22
Unions
Connecting Tables
Unions are used to combine the result-set of two or more SELECT statements.
The Union operation is popular for combining plan and actual values in CO-PA.
Note that Unions are not supported in modeled artifacts (Attribute Views or Analytical
Views) and can only be realized in Calculation Views.
Refrain from Joining Analytical views; rather use Unions with Constant values.
Unions with Constant values are supported within Graphical Calculation Views and
the UNION operator can accept 1..N input sources.
Whereas a Script Based calculation view’s comparable CE_UNION_ALL function can
only accept 2 input sources at a given time.
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 22/24
©SAP AG HA300 2-23
© 2012 SAP AG. All rights reserved. 23
Standard Union
Connecting Tables
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 23/24
©SAP AG HA300 2-24
© 2012 SAP AG. All rights reserved. 24
Union with Constant Values
Connecting Tables
8/18/2019 SAP HANA_Join Types
http://slidepdf.com/reader/full/sap-hanajoin-types 24/24
© 2012 SAP AG. All rights reserved. 25
You should now be able to:
Summary
Connecting Tables
Explain differences between Inner Join, Left Outer Join,
Right Outer Join, Full Outer Join, Text Join and
Referential Join when connecting tables.
Explain how using Standard Union and Union with
constant values.