CDS Table Functions Part 4: Performance with HANA Plan Analysis
Preview · a free account unlocks the full lesson
Make table functions fast: why consumer filters may not be pushed down, how to design parameters and set-based SQLScript, how to measure with ST05, SQL trace and HANA PlanViz / explain plan, and how to compare against a CDS alternative.
In this lessonShow sectionsHide sections
Visual overview
Explanation
"Runs on HANA" doesn't mean "runs fast" — performance needs to be measured with the real consumer query. Selective filters belong in parameters rather than relying on the consumer's WHERE clause being pushed down automatically. SQLScript should stay set-based: one SELECT, no cursors or row-by-row loops. The tools worth knowing are ST05 for the statement and its timing, the explain plan, and HANA PlanViz for operator-level analysis.
Parts 1 through 3 built a correct table function; this part is about making it fast.
Table functions can end up slow for a few recurring reasons. The function computes its full result first, and only then does the consumer's WHERE, ORDER BY and paging get applied — unless the optimizer can push those conditions directly into the SQLScript body. Window functions like ROW_NUMBER running over all rows of a large table are expensive. Imperative SQLScript — cursors, loops, scalar calls per row — prevents parallel, set-based execution. And joining the function's result with large views can create huge intermediate results.
A few design rules help avoid this. Use parameters for selective filters — company code, date range, supplier — applied as early as possible inside the SQLScript. Filter before ranking or aggregating: WHERE first, then ROW_NUMBER over the already-reduced set. Select only the columns actually needed.
Avoid reaching for SELECT DISTINCT as a fix for duplicate rows — find the join actually causing them instead. And prefer a single declarative statement; where steps are genuinely needed, table variables work well, as in lt_open = SELECT …; RETURN SELECT … FROM :lt_open, which HANA can still optimize as a whole.
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
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.