Performance Part 10: Indexes, Selectivity and WHERE Conditions
Preview · a free account unlocks the full lesson
Understand how indexes serve WHERE conditions: primary key and secondary indexes (SE11), field order and leading fields, selectivity, conditions that prevent index use (NOT, < , leading wildcards, functions), client field, checking the execution plan in ST05, HANA specifics, and when (not) to create a new index.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Parts 1 through 9 of this series reduced the number of database calls and the volume of data moved; the last piece is making sure each remaining SELECT finds its rows efficiently, which comes down to indexes, selectivity, and how a WHERE condition is written.
Every table has a primary index built from its key fields in table order — for VBAP, that's MANDT, VBELN, POSNR — and may also have secondary indexes, visible in SE11 via the Indexes button (for example, an index on BSEG, or VBAK~A on ERDAT, depending on release); check what already exists before designing a WHERE clause.
An index only helps if the WHERE condition specifies its leading fields, in order, with selective values. For an index on (MANDT, KUNNR, ERDAT), a condition like WHERE kunnr = … AND erdat IN … uses the index well, but WHERE erdat IN … alone cannot use the leading KUNNR field efficiently, since it skips over it. Open SQL adds MANDT automatically as part of client handling, so you never need to write it yourself.
Selectivity itself matters a great deal: a condition that matches around 1% of a table's rows benefits strongly from an index, while one matching 50% of the rows usually doesn't, because scanning everything ends up being just as fast. Certain conditions actively hurt index usage: NOT, <>, and NOT IN on indexed fields; LIKE '%abc' with a leading wildcard; very broad ranges or IN lists with many values; and selecting through non-key text fields, such as names, with no index behind them at all.
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
Interview questions on this topic
Related SAP topics
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.