HANA Code Remediation Navneet July 8, 2015 HANA Code Remediation Guidelines HANA developments guidelines are an outcome of HANA migration projects as well as continuous code improvements. How-to-Guide address statements creating a high workload on HANA DB and therefore should be avoided during development phase. Each solution/product architect and developer are responsible to apply these guides in order to keep HANA DB performance stable over the time. Analysis of WHERE Condition for SELECT Changing database access in loops Database Hints Native SQL Search problematic SELECT statements Search SELECT .. FOR ALL ENTRIES-clauses How to Search SELECT for Pool- or Cluster-Tables without ORDER BY How to Table Attributes Check © 2015 SAP SE or an SAP affiliate company. All rights reserved. 2 HANA Code Remediation Guidelines Analysis of WHERE Condition For SELECT Problem A SELECT statement without a WHERE condition reads the entire table. Solution Check whether the data selection can be limited through use of a suitable WHERE condition. False-Positive can be suppressed using the pseudo comment "#EC CI_NOWHERE © 2015 SAP SE or an SAP affiliate company. All rights reserved. 3 HANA Code Remediation Guidelines Changing database access in loops Problem Changing database statements like INSERT, UPDATE, MODIFY, DELETE in loops lead to multiple database accesses. Loops could be: • SELECT ... ENDSELECT. • LOOP ... ENDLOOP. • DO ... ENDDO. • WHILE ... ENDWHILE. • PROVIDE ... ENDPROVIDE. Solution Check whether an array change is possible. False-Positive can be hidden by using the pseudo comment "#EC CI_IMUD_NESTED. © 2015 SAP SE or an SAP affiliate company. All rights reserved. 4 HANA Code Remediation Guidelines Database Hints Problem • Hints can only be evaluated at runtime and they cannot be checked with ABAP syntax analysis. Incorrect entries can cause a runtime error. Invalid hints may also be ignored, depending on the database. • hints are specific for one system configuration and its quantity structure. • A hint does not have any functional effects in this case. This means that although it influences the process duration, it does not influence the resulting set of a statement. For this reason you cannot usually check in the program if a hint was ever evaluated. Solution Do not use hints for databases that are not listed in SAP note 129385 "Database hints in Open SQL". © 2015 SAP SE or an SAP affiliate company. All rights reserved. 5 HANA Code Remediation Guidelines Native SQL Problem • Programs with Native SQL statements are generally dependent on the database system used, so that they cannot be executed in all AS ABAP systems. • Native SQL statements are not checked completely by the syntax check Solution Do not use Native SQL. It is recommended to use the Open SQL subset in SAP standard. © 2015 SAP SE or an SAP affiliate company. All rights reserved. 6 HANA Code Remediation Guidelines Search Problematic SELECT * Statements Problem In general a SELECT * statement lead to performance & memory issues. due to the HANA column based storage of tables the select * is not recommended. If not all table fields are used the select should be limited to the fields which are required. Solution • Do not select more fields than required! However, it has to be ensured that all required fields are read. • If the SELECT is only used for existence check use addition UPTO 1 ROWS or SELECT SINGLE NOTE - A correction for existing code is only recommended for tables with more than 50 fields by standard development. For less than 50 fields an adaption is only recommended if more than 1000 records are read. © 2015 SAP SE or an SAP affiliate company. All rights reserved. 7 HANA Code Remediation Guidelines SELECT… FOR ALL ENTRIES clause Problem In case the internal table is empty the content of the database table would be read completely. The addition FOR ALL ENTRIES ignores SAP buffering for: • Tables with single record buffering, • Tables with generic buffering if the condition after FOR ALL ENTRIES prevents precisely one generic area from being specified exactly Solution It is always a good idea to perform some performance tests comparing FOR ALL ENTRIES and INNER JOIN ... to identify the best and fastest solution. It is best practice to check SELECT ... FOR ALL ENTRIES with an explicit test for content. For e.g. by using an IF statement. © 2015 SAP SE or an SAP affiliate company. All rights reserved. 8 HANA Code Remediation Guidelines SELECT for POOL or CLUSTER tables without ORDER BY Problem Cluster Tables and pool tables has been migrated to transparent tables (Few Pool Tables still exist). But the data selection is not sorted automatically by using the normal Select statement. Solution Select without an ORDER BY clause on pool or cluster tables must be checked if an explicit ORDER BY clause is necessary: • If the order of records is relevant add an ORDER BY clause. • If the order of records does not matter suppress the message via the pseudo comment "#EC CI_NOORDER Notes • SELECT SINGLE statements are not analyzed since they retrieve only one line and sorting is therefore not relevant. • If the result of the SELECT statement is moved into a sorted internal table, a special message is raised. © 2015 SAP SE or an SAP affiliate company. All rights reserved. 9 HANA Code Remediation Guidelines TABLE Attribute Check Problem The HANA database does not use classical table buffering methods. Each read goes to the live data. Therefore Non-buffered tables need to be checked if buffering needs to be enabled on application server side. Solution The solution depends on the table content. The technical settings (transport attributes, buffering) and the secondary indices of the database table have to be checked and if necessary to be maintained. In general tables can be buffered if: • They can be buffered 'logically'. • They are not too big. • Most of the accesses are reads, low amount of writes. • Way how they are accessed fits to the buffering technique © 2015 SAP SE or an SAP affiliate company. All rights reserved. 10 Code Inspector Checks – Part I For HANA Code remediation activity, Code inspector variants “FUNCTIONAL_DB” and “FUNCTIONAL_DB_ADDITION”. © 2015 SAP SE or an SAP affiliate company. All rights reserved. 11 Code Inspector Checks – Part II © 2015 SAP SE or an SAP affiliate company. All rights reserved. 12 Code Inspector Checks – Part III © 2015 SAP SE or an SAP affiliate company. All rights reserved. 13 Code Inspector Checks – Part IV © 2015 SAP SE or an SAP affiliate company. All rights reserved. 14 Thank you Navneet Chaubey © 2015 SAP SE or an SAP affiliate company. All rights reserved.