This project can be used to profile database queries, which can be useful when optimizing database queries.
The core functionality lies in the file profiler.sh, written in Bash.
The script performs the following tasks:
- Runs the SQL queries in
setup_database.csv. This can be used to prepare database and setup environmental variables before running queries for profiling. The first four lines insetup_database.csvcontains SQL queries for enabling data collection for performance schema profiling and clearing a couple of tables. - Runs queries specified in
queries.csvfor profiling. Queries can be run numerous times (configurable vian_repetitionsvariable in script). The script collects average execution time as well as a breakdown of atomic steps in executing a query. Average execution times of queries are stored insummary.csv, which is created when the script is run for the first time. Entries in this CSV file are tab-separated and each row includes a time stamp, query, and average execution time. Times for atomic steps are stored as*.logfiles inperformance_logsfolder. - Runs SQL queries in
revert_changes.csv. This can be used to teardown any changes done to the database as a part of setup. - Shows a progress bar that indicates the overall status of profiling.
- Configure your MariaDB user name and password in lines 23-24 in
profiler.sh:
mariadb_username=root
mariadb_password=password
- Set the number of repetitions (i.e., the number of times each query will be executed) by modifying the
n_repetitionsvariable inprofiler.sh. The default value is 10. - Run the script by typing the following command in Shell when in the project folder:
bash profiler.sh
Queries that need to be profiled are specified in queries.csv file. Each line contains a database name (if applicable) and the query, separated by a $ delimiter. You may leave the database name empty for queries that do not require a specific database to be loaded.