Performance Tips for MySQL

Software Code
20-08-2017 18:52:42

MySQL is a very powerful open source Relational Database Management System (RDMS). It uses the Structured Query Language (SQL) and is thus the most popular choice for managing content within a database.

Lots of web applications page through information. Here are 5 tips which will help to improve the performance of MySQL database and will thus help give better results.

1. Indexing

In MySQL, there are several types of indexes like Hash Indexes (MEMORY and NDB), Tree Indexes etc. The use of indexes to find groups of adjacent rows instead of a single row speeds up most of the queries.  As the data is presorted, indexing can be used to avoid the sorting operations which are quite time-consuming. Sequential search technique is used while searching for the data in tables which leads to wastage of time. Indexing thus helps in improving the response time and proves to be one of the best performance tips for MySQL.

2. Use of InnoDB as a storage engine

Switch from MyISAM to InnoDB for better results in terms of the performance. The change buffering feature of InnoDB delays building secondary indexes. MyISAM uses a single lock to protect the key buffer when loading the data to/from a disk resulting in contention. InnoDB prevents such type of contention and boosts the insert performance.

3. Profile the workload

Profiling the workload exposes the most expensive queries for further tuning. Workload- profiling tools group the similar type of queries together allowing us to see which queries are fast and which are slow. The slow queries can then be rewritten and the physical database design can then be tuned to make it well suited for the specific queries it needs to serve.

4. Avoid using MySQL as a queue

Queues are sly and slip into the design without our realization. Queue Systems have many work processes checking for something to do which creates a problem in heavily loaded applications. Serialization of workload takes place because of the queues which prevent tasks from being done in parallel. Creation of a single huge table like huge emails table. New emails go into the table and even if there might be only a few messages to send, the size of the table makes all the queries really slow. Data growth speeds up and it thus paves the way for a disaster. Creation of separate tables and avoiding storing queues in the same table as the other data will help improve the performance drastically.

5. Handling the pagination queries

Paging Queries can be slow with MySQL as they contain the OFFSET keyword which instructs the server that only a subset is required. By linking the pages, these applications group a lot of pages in such a way that they cannot be indexed. This causes the server to do a lot of work and it ends up discarding rows. By using a Deferred Join or by maintaining a place or position column one can avoid this. Paging by ID or USERNAME without discarding records will help you save big as the server probably won’t fetch these records, speeding up the database drastically.


Coding Community (New Delhi, India)