Optimizing Query Performance

Using the @Aggregate_Aware Function

Objective

After completing this lesson, you will be able to explain how aggregate awareness improves query performance in SAP BusinessObjects Information Design Tool using pre-aggregated tables.

@Aggregate_Aware Function

Watch the video to understand the concept of aggregate awareness and see a business case for using the @Aggregate_Aware function to improve performance.

Insert the Aggregate Table

To meet the reporting requirement, you add the aggregate table to the data foundation. Create joins from the aggregate table to the existing tables:

  • ANNUAL_FIGURES.SHOWROOM_ID=SHOWROOM.SHOWROOM_ID
  • ANNUAL_FIGURES.MAKER_ID=MAKER.MAKER_ID

Insert a Table

To insert a table, first open the data foundation in the editor by double-clicking the data foundation name in the Local projects view.

Once the data foundation is open, navigate to the Connection tab.

Select the table you want to insert and move it into the data foundation view.

A dashed line connects the ANNUAL_FIGURES table in the left panel to its corresponding entity in the relational diagram on the right.

Contexts

The data foundation currently contains two contexts: Sales and Rentals. These contexts resolve loops and ensure that the universe correctly interprets queries for detailed sales or rental transactions.

When you create these joins, SAP BusinessObjects Information Design Tool detects a structural problem. You have created a loop.

Nine connected database tables outline relationships for clients, sales, rentals, models, showrooms, makers, and annual figures in a car dealership schema.

To resolve the loop, you need to create a new context named Aggregate. This context isolates the new query path and tells the universe when to use it.

Next, decide which joins to include in this new context. To keep your aggregate data accurate, include only joins that do not change the level of detail of the aggregate table.

The rule is simple. A join is compatible with the aggregate context if its cardinality is one-to-one (1,1).

A 1,1 cardinality means that for each row in your aggregate table, there is one and only one matching row in the dimension table you join to.

Here are the joins compatible with the new context:

  • ANNUAL_FIGURES.SHOWROOM_ID = SHOWROOM.SHOWROOM_ID
    • Cardinality: 1,1
    • Business Meaning: Each row in ANNUAL_FIGURES matches one and only one row in the SHOWROOM table.
    • Conclusion: This join is compatible. We will include it in the Aggregate context.
  • SHOWROOM.COUNTRY_ID = COUNTRY_SHOWROOM.COUNTRY_ID
    • Cardinality: 1,1
    • Business Meaning: Each row in the SHOWROOM table matches one and only one row in the COUNTRY_SHOWROOM table.
    • Conclusion: This join is compatible. We will include it in the Aggregate context.
  • ANNUAL_FIGURES.MAKER_ID = MAKER.MAKER_ID
    • Cardinality: 1,1
    • Business Meaning: Each row in ANNUAL_FIGURES matches one and only one row in the MAKER table.
    • Conclusion: This join is compatible. We will include it in the Aggregate context.

Configure the following joins for the Aggregate context:

Four highlighted tables—COUNTRY_SHOWROOM, SHOWROOM, ANNUAL_FIGURES, and MAKER—are connected by green relationship lines in a database schema diagram.

Modifying the following joins for the Sales context:

Entity-relationship diagram connects tables for client, sale, showroom, model, maker, region, and country, illustrating their relationships with primary and foreign keys.

Modifying the following joins for the Rentals context:

Database schema diagram connects tables for client, region, showroom, rental, model, maker, and country with primary and foreign key relationships highlighted.

By creating the Aggregate context and adding these specific 1,1 joins, we have successfully resolved the loop and defined a clean, isolated query path for our aggregated data.

Insert Context

To begin, open the data foundation in the editor by double-clicking its name in the Local projects view.

Once the data foundation is open, navigate to the Aliases and contexts tab.

Select the Insert Context icon; this action displays the context’s properties in the Context properties pane.

You can then edit the context name in the Name field.

To manage joins within the context, click the Joins tab. Double-clicking a join toggles its state between included, excluded, or ignored; alternatively, you can double-click the join line directly in the data foundation view to achieve the same result.

Context AGGREGATE is selected, displaying table relationships and join expressions with several join errors indicated by red icons.

Apply Aggregate Awareness to Objects

Aggregate aware objects are items in the business layer for which you want queries to use the aggregate tables when possible instead of performing aggregation using non-aggregate tables.

In our scenario it is possible to read the sales amount from the ANNUAL_FIGURES table or the combination of the SALE, SALE_MODEL, MODEL tables.

In the SQL expression for the object, define the SELECT statement to use the @Aggregate_Aware function:

  • @Aggregate_Aware(sum(<Aggregate table 1>), ... sum(<Aggregate table n>))
  • In the @Aggregate_Aware function, <Aggregate table 1> is the aggregate table with the highest level of aggregation, and <Aggregate table n> is the aggregate table with the lowest level (the detailed fact table).

Configure the Sales revenue object:

SQL Expression Editor contains an Aggregate_Aware function with annotated brackets indicating the highest and lowest levels of aggregation in the formula.

Define Incompatible Objects Using Aggregate Navigation

You need to specify which objects the system can use with the ANNUAL_FIGURES aggregate table.

Why is this so important?

Imagine a user runs a query asking for sales revenue by client. Our ANNUAL_FIGURES table does not contain information about individual clients; it is aggregated by maker and showroom. In this case, the universe must not use the aggregate table and must instead return to the detailed data path.

How does the universe know if an object is compatible with an aggregate table?

The rule for determining this compatibility is simple and direct, and it follows from the work we just did with contexts: An object is compatible with the aggregate table if it points to a table that is part of the Aggregate context.

Set Aggregate Navigation

To set aggregate navigation, first open the business layer in the editor by double-clicking the business layer name in the Local projects view.

Once the business layer is open, from the main menu, select Actions→Set aggregate navigation.

Actions menu highlights Set Aggregate Navigation, and the Set Aggregate Navigation window lists data foundation tables with associated incompatible objects for selection.

In the Set aggregate navigation dialog box, you specify which tables contain objects that are not compatible with aggregate tables containing objects optimized for aggregate awareness.

For the ANNUAL_FIGURES table, disable:

  • Showroom
  • Showroom Address
  • Showroom Country
  • Maker
  • Sales revenue
Database schema diagram highlights relationships between showroom, showroom address, showroom country, sales revenue, and maker tables, with corresponding color-coded legend and arrows.

Let's Summarize What You've Learned

  • Aggregate awareness enables the universe to use pre-aggregated tables, improving query performance and reducing response times.
  • The @Aggregate_Aware function directs queries to the most appropriate table based on the query’s level of detail.
  • Creating a dedicated Aggregate context with only 1-to-1 joins ensures accurate and efficient use of aggregate tables.
  • Aggregate navigation defines which objects are compatible with aggregate tables, preventing incorrect query results.