mindplay-dk / sql

Database framework and query builder
Other
17 stars 6 forks source link

Feature: performance analysis decorator #29

Open mindplay-dk opened 7 years ago

mindplay-dk commented 7 years ago

Add a Connection decorator to proxy the fetch() and execute() methods, and use Postgres/MySQL EXPLAIN queries to log query performance information to a PSR LoggerInterface instance.

https://www.postgresql.org/docs/9.4/static/sql-explain.html

http://dev.mysql.com/doc/refman/5.7/en/explain.html

First version can simply log this information - an improved future version could perform some analysis/filtering on the performance data, for example highlighting log-entries that indicate sequential table scans and other potential issues.

It should avoid logging redundant queries - e.g. avoid doing multiple analysis queries when the same SQL query template is executed multiple times. (Consider using debug_backtrace() to group queries by call site.)

It should report the number of times the same SQL query template was executed.

It should measure and report the total and average time (in milliseconds) for each SQL query template.

Add documentation.