This topic describes how to optimize SQL statements.

Create indexes

After you check the execution plan, you may find that some SQL queries do not use indexes and the query efficiency is low. You can create indexes to improve query performance. The following examples show the difference of query performance before and after you create the index:

  • Before creation of the indexCreate indexes - Figure 1
  • After creation of the indexCreate indexes - Figure 2

Use an optimal execution plan

After you check the execution plan, you may find that the execution plan is not optimal and SQL statements are not executed at an expected speed. In this case, you can create an appropriate index to optimize your execution plan. The following examples show the difference of query performance before and after you optimize your execution plan:

  • Before optimization of the execution planUse an optimal execution plan - Figure 1
  • After optimization of the execution planUse an optimal execution plan - Figure 2

Modify SQL statements

If you cannot improve the efficiency of SQL queries by creating indexes, you need to modify SQL statements for specific optimizations. The following examples show the difference of query performance before and after you modify the SQL statements:

  • Before modification of the SQL statementsModify SQL statements - Figure 1
  • After modification of the SQL statementsModify SQL statements - Figure 2