I'd like to argue that this performance test is senseless and any conclusions drawn from it are incorrect as:
Sorting in ABAP and sorting on the database only yields the same results if the whole table is selected. If the number of results is limited (e.g. get the last 100 invoices) then sorting on the database yields the correct result while sorting in ABAP (after the limit) does not. As one rarely selects a whole table the test case is completely unrealistic.
Sorting by the primary key (pgmid, object, obj_name) does not make any sense. In which scenario would that be useful? You might want to search for a certain object, then sorting by obj_name might be useful, or you might want to see recent transported objects and sort by the correction (korrnum)
Just to demonstrate run the following example:
REPORT Z_SORT_PERF.
DATA:
start TYPE timestampl,
end TYPE timestampl.
DATA(limit) = 10000.
* ------------- HANA UNCOMMON SORT ----------------------------------------
GET TIME STAMP FIELD start.
SELECT * FROM tadir ORDER BY PRIMARY KEY INTO TABLE @DATA(hana_uncommon) UP TO @limit ROWS.
GET TIME STAMP FIELD end.
WRITE |HANA uncommon sort: { cl_abap_tstmp=>subtract( tstmp1 = end tstmp2 = start ) }s|.
NEW-LINE.
* ------------- HANA COMMON SORT ----------------------------------------
GET TIME STAMP FIELD start.
SELECT * FROM tadir ORDER BY KORRNUM INTO TABLE @DATA(hana_common) UP TO @limit ROWS.
GET TIME STAMP FIELD end.
WRITE |HANA common sort: { cl_abap_tstmp=>subtract( tstmp1 = end tstmp2 = start ) }s|.
NEW-LINE.
On my test system this runs in 1.034s (the uncommon one) vs 0.08s (the common one). That's 10 times faster (though that comparison also makes little sense). Why is that? Because there is a secondary index defined for the KORRNUM field for exactly that purpose (sorting) while the primary key index is supposed for enforcing uniqueness constraints and retrieving single records.
In general a database is not meant to optimize for one single query, but is optimized for overall system performance (under memory constraints). This is usually achieved by sacrificing the performance of uncommon queries for the optimization of common ones.
For performance reasons, a sort should only take place in the database if supported by an index. This guaranteed only when ORDER BY PRIMARY KEY is specified
That's a slightly misleading formulation. There are indices that are not optimal for sorting, and although there is no guarantee that a database creates a secondary index and uses it while sorting, it is very likely that it does so in common cases.