Print SQL execution and time
Purpose
Pain point: When we test the business, we need to view the actual SQL execution and time consumption. Many upper-level drivers have multiple ways to enable printing, and many of them require code modification or configuration modification for printing.
DebugTools to print SQL and time consumption at runtime by modifying the database driver bytecode
at the jdbc layer, thereby avoiding the impact of different upper-level database connection pools on SQL printing.
Theoretically supports all database drivers connected through Jdbc:
Use
Idea
Configure to open or close in setting -> Other Settings -> DebugTools
Pretty
: Print SQL statements in formatted formCompress
: Print SQL statements in compressed formNo
: Do not print SQL statementsAuto save sql to file
: Save SQL statements to a fileSQL Retention Days
: Retain SQL statements for a certain number of days
The SQL file is in the .idea/DebugTools/sql
folder. You can also open the latest SQL file by clicking the ToolsWindow
.
Success will output Print xxx(mysql/oracle/...) log bytecode enhancement in the log successful
The printing effect is as follows:
Execute consume Time: 3 ms; Execute SQL:Execute consume Time: 3 ms; Execute SQL:
SELECT
id,
name,
age,
version
FROM
dp_user
WHERE
id=1
TIP
Since DebugTools prints SQL in bytecode, you need to restart the application to take effect after modifying the configuration.
Agent
Start the application by using java -javaagent:/path/to/your/debug-tools-agent-{version}.jar -jar your-app.jar
agent download address
Warning
It is best not to use it in a production environment
Because DebugTools implements SQL printing by modifying the database driver bytecode, there may be incompatibility or other unconsidered situations, and there may be risks in the production environment.