Filtering on Join Nodes

Objective

After completing this lesson, you will be able to specify how a filter applies to a join

Adding a Filter to a Join Node

When you define a filter (a filter expression) in a join node, you have a possibility to optimize the runtime execution of the calculation view by mapping this filter between two (or more) sources of the join node. With filter mapping, when a filter is defined on a column from one source, you can ask the SQL optimizer to also apply this filter to a column of another other source.

Note

From SAP HANA Cloud QRC 4/2023, it is also possible to define filter mapping in non-equi joins.
Screen capture of the filter mapping for a join definition. First, select Filter in a drop-down element to activate the filter mapping. Second, drag and drop column names to create a mapping, for example, map product to product_name. Third, define the direction of the filter mapping. (For the benefit, refer to the text above.)

Defining the filter mapping can be done graphically, in a similar way as defining joins. For this reason, the Join Definition tab offers two modes, to create either a Join or a Filter mapping when dragging a column from a source to a column of another source to create a connector.

Note

You can also choose to display Join connectors only, Filter mapping connectors only, or both.

A Direction must also be specified, so that the optimizer knows from which side (left or right) an existing filter must be mapped to the other side. The default direction is Left ↔ Right, that is, bi-directional. A filter mapping connector has a dedicated color (orange) and a filter icon. One or two arrows show the mapping direction(s).

The improved performance results from the early execution of filters on both sources, before the join is executed. Therefore, filter mapping can be seen as a help to the optimizer in case the optimizer does not filter before executing the join - although it would make sense in your context. In the example shown in the figure, Filtering on Join, the optimizer does not know that product in the left table is the same thing as product_name in the right table. By mapping the filter on product to the column product_name, you can reduce the result set of Projection_2 to reduce the join execution time.

In some cases, filter mapping also helps ensuring that consistent data is returned.

Log in to track your progress & complete quizzes