The invention discloses a MyBatis framework-oriented
SQL (Structured
Query Language) automatic analysis and optimization method and
system, and the method comprises the steps: calling a GenericTokenParser, an XNodeParser and a SqlSourceBuilder tool class officially provided by Apache MyBatis, completing the grammar analysis of a dynamic
SQL statement, the recognition and replacement of a parameter placeholder, generating a BoundSql object, and obtaining complete
execution plan information; inputting the static
SQL text and the
execution plan into a configurable
artificial intelligence large model interface, and deeply analyzing the performance
bottleneck by the
large model; and automatically diagnosing the problem severity through a
rule engine based on a quantitative index of an
execution plan field, dividing the problem severity into three levels of emergency optimization, important optimization and suggested optimization, and generating a structured diagnosis report containing
problem description, reason analysis and an
executable optimization scheme. According to the method, the MyBatis framework characteristics and the AI
large model capacity are deeply fused, the problems that dynamic SQL analysis is inaccurate, diagnosis lacks quantitative grading, an optimized
closed loop is incomplete, and rules are statically solidified are solved, and the efficiency and the intelligent level of
database performance management are remarkably improved.