🤖 AI Summary
This study addresses the challenge of auditing cloud systems caused by the difficulty of statically extracting SQL templates from imperative Go ORM code. To overcome this, we propose an LLM agent-based approach leveraging code index graphs and hybrid context retrieval. By integrating graph traversal, pattern matching, and call chain tracing, our method effectively resolves context loss in dynamic SQL generation, enabling automated pre-deployment reconstruction of SQL templates. Evaluated across five large-scale Go repository benchmarks, the proposed approach achieves a recall rate of 68%–72%, significantly outperforming existing static analysis tools and baseline methods. These results demonstrate that our framework provides an efficient solution for performance auditing in cloud-native applications, bridging the gap between dynamic code behavior and static analysis requirements.
📝 Abstract
Suboptimal SQL queries can significantly degrade the performance of cloud systems, motivating the extraction and auditing of SQL statements before deployment. However, Go ORM frameworks construct SQL imperatively through scattered method-call sequences, making it difficult to statically recover the resulting SQL templates. We present AutoSQL, a system that reconstructs SQL templates from Go ORM code. AutoSQL constructs a Code Index, a directed graph that captures structural dependencies between functions, types, and global variables as navigable edges. It then traces upstream call chains from ORM invocation sites to identify database-interacting functions as entry points. For each entry point, an LLM agent traverses the Code Index to collect code slices that influence SQL generation, switching to pattern-based search when the graph cannot resolve a retrieval goal. We call this strategy Hybrid Context Retrieval. Once sufficient context is collected, the agent synthesizes SQL templates. Evaluation on a benchmark of 579 test-covered entry points and 1,186 runtime-traced SQL statements from five large-scale Go repositories shows that AutoSQL achieves 68.04% to 72.18% recall, exceeding the static reachability baseline by 11.80% to 15.94% and outperforming existing methods by 8.52% to 21.50%.