SQL query optimizations

Optimizing queries and the data access layer of your enterprise application is key to avoiding bottlenecks and performance issues. We can use New Relic as an APM, and this will help us to detect bottlenecks and performance problems using database access graphics. With these graphics, we can find the SQL sentences used by your application, finding delay transactions or blocked tables if we continue to drilldown the information until we can also find the most SQL sentences used and the number of connections managed, as in the following screenshot:

Database metrics from New Relic

From the app, we can identify the queries most used and check for opportunities to optimize them. We would need indexes or to refactor our code to get better performance. On the other hand, without using an APM or a profiling tool, we can use a number of techniques to improve our SQL and data access layers, such as the following:

In the next section, we will look at how to simulate virtual users in order to create a load test for your applications.