Mysql Query Optimization

0
524
MySQLQueryOptimizer
MySQL Query Optimizer

Query optimization is a feature of many relational database management systems such as MySQL, Oracle, SQL Server. The query optimizer attempts to determine the most efficient way to execute a given query by considering the possible optimizer query plan.

Generally, Developers write SQL Queries, but all of them should review by Database Architect or DB Performance experts for getting the best performance. They can give recommendations for the best performance. Also, they check how efficiently execute the given queries with EXPLAIN plain. Then, they can provide query rewrite recommendations and optimal indexes.

How to optimizer MySQL Queries?

In case, if it is not happening in your organization or  DB architects are not available (not DBA team) don’t worry. There are some tools available in the market which can help to do it.  My Favorite tool is SmartWorkbench.  the SmartWorkbench is an advance MySQL GUI tool having may features. Query Optimization is one of them.

It can detect bad queries while writing them, it can optimize the given query and provide Query rewrite recommendations and Optimal indexes which can help to speed up queries. Most importantly, it can give statistical reports of the query performance growth report as evidence.

MySQL Query Optimizer
MySQL Query Optimizer

Bulk MySQL Queries Optimization:

In case, If you are developing your project with Java Hibernate or any ORM framework then it doesn’t need to write SQL queries. The Framework can generate SQL queries. In such cases, SmartWorkbnech can do you just need to enable MySQL Slow queries to log files using the following commands.

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 0.1;
SET GLOBAL log_queries_not_using_indexes=1; 

After one day, the slow query log file has all queries which need query optimization. MySQL creates the slow query log file in the data directory folder. Using the following command you get the exact location of the slow query log file.

show VARIABLES like '%slow_query_log_file%'

MySQL Slow Query Log Analyzer :

The SmartWorkbench has many advanced features and one of them is the Slow query log analyzer(1). It is a MySQL GUI tool that can connect to MySQL and pull a slow query log file(4) directly from OS if OS credits saved with the tool. Also, It allows you to drag and drop(2) or upload slow query log files(3).

It shows a consolidated report after submitting slow query log files with all keen observations including high frequency executed Queries, slow response queries, Queries execution time, lock time, total scanned records, total returned records, and Query ratting. It helps you to easily identify problematic queries that are not optimized by DB performance experts.

Most Importantly, It can do Query optimization for all slow queries and provide optimal indexes for all of them at once. There is an option to download the report in excel format. You can observe significant overall DB performance after adding them. It results to improve your application response time. It doesn’t need any special skills


MySQL DB benchmarking

It is always best practice to do a benchmark with high traffic. Better to put load 4 times more traffic what you expect at pick traffic time. You can identify bottlenecks and improve performance. Also, SmartWorkbnech helps to fix MySQL bottlenecks and DB issues.  SmartWorkbnech slow query log analyzer and query analyzer modules can optimizer all queries.

slow query log analyser

Moreover, SmartWorkbench Debugger can identify and fix MySQL regular issues as DEADLOCKS, QUERY LOCKS, LONG-RUNNING QUERIES, HIGH CPU/RAM/DISK IO issues, REPLICATION LAGGING, LONG RUNNING TRANSACTIONS, TOO-MANY CONNECTIONS and so on.

Also, it can recommend MySQL configuration using the MySQL Config manager based on your application workload.

LEAVE A REPLY