CDS Views Part 3: Performance — Joins, Associations, Filters and Aggregation
Preview · a free account unlocks the full lesson
Make CDS views fast: understand how associations and path expressions turn into joins, why to-many paths multiply rows, how to push filters and aggregation to the database, and how to analyze a slow view.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 2 built ZI_SalesOrderItem. Now comes the question every project hits after go-live: why is this CDS-based list slow, and how do you design views that stay fast with millions of rows?
The core idea is that a CDS view is executed as SQL on SAP HANA, so performance depends on how much data the database has to read, join and send back. Good design means filtering early, joining only what's needed, aggregating in the database, and returning only the columns and rows the consumer actually needs.
The distinction between a join and an association matters a great deal. A JOIN in the data source — "as select from zso_head inner join zso_item on ..." — always executes, even if the consumer never reads a joined field.
An ASSOCIATION, by contrast, is only a declared relationship, and it becomes a join only when a consumer actually uses it, whether through a path expression in a SELECT, in another view, or via OData $expand.
So it pays to model relationships as associations and let consumers decide — a list report that shows only the order number and date never pays for the customer join.
Path expressions are what turn an association into an actual join. "_Customer.CustomerName" in a view's element list, or "\_Customer-CustomerName" in ABAP SQL, generates a LEFT OUTER JOIN by default to the associated view. To-one associations ([0..1], [1..1]) are safe to use in a select list, since one row stays one row.
To-many associations ([0..*], [1..*]), though, multiply rows when used in a select list or in a WHERE clause — an order with 5 items suddenly appears 5 times, producing wrong counts and slow queries.
A to-many path can be turned into a to-one path with a filter, such as "_Item[ ItemNumber = '000010' ].Material", or with a "1:" cardinality hint when the filter guarantees a single row. Cardinality should always be declared correctly, since getting it wrong lets the optimizer choose bad plans and hides duplicates.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
More lessons in this topic
Interview questions on this topic
Referenced SAP objects
Reviewed reference pages for the objects this page mentions.
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.