Crossref DOIMemberCiteFactoropen accessissn
SJIF Impact Factor 8.659 | ISSN: 2582-3930
IJSREM Logo

International Journal of Scientific Research in Engineering and Management

(Gateway to Global Scholars - An International, Scholarly, Multi-Disciplinary, Open Access Journal)

Peer-Reviewed Journal Designed to Meet UGC's Quality Parameters

HomeCurrent IssuePast IssuesPay OnlineConferencesEditorial BoardAbout UsContact Us
IJSREM

Loading article...

Follow Us

  • Google Scholar
  • ResearchGate
  • Academia.edu
  • Mendeley
  • LinkedIn
  • Facebook
  • Instagram

Journal Policies

  • Peer Review Policy
  • Publication Ethics
  • Copyright Infringement
  • Refund & Cancellation Policy
  • Terms and Conditions
  • Privacy Policy

Journal Identifiers & Licenses

  • ISSN Verified: 2582-3930ISSN Verified: 2582-3930
  • Crossref DOI: 10.55041Crossref DOI: 10.55041
  • SJIF Ranking: 08.659SJIF Ranking: 08.659
  • Licensed under CC BY 4.0Licensed under CC BY 4.0
  • ISO Certification: 9001:2015ISO Certification: 9001:2015
  • Indexed & Cited In: Google ScholarIndexed & Cited In: Google Scholar

Contact Us

International Journal of Scientific Research in Engineering and Management (IJSREM)

#62/1, New No 7, 1st Cross, 2nd Main, Ganganagar, R T Nagar, Bangalore North, Bangalore, Karnataka, India – 560032
[email protected]+91 93911 67991
logos
logos
Working Hours

Mon – Sat: 9:00 AM – 6:00 PM

Sunday: 10:00 AM – 4:00 PM

+91 93911 67991

© 2026 IJSREM – International Journal of Scientific Research in Engineering and Management. This is an open-access journal. Articles are published under the Creative Commons Attribution (CC BY 4.0) License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

DisclaimerPrivacy PolicyTerms and Conditions
ArticlePeer ReviewedOpen AccessPlagiarism Passed
Paper ID:IJSREM68834

An AI Agent-Based Approach for Automated SQL Query Generation and Optimization Using Python

Stream/Area:

-

Subject:

-

Paper ID:

IJSREM68834

Volume:

10 |

11 |

Nov 2026

Pages:

1-6

Publication Frequency:

Monthly (12 issues per year)

DOI
Digital Object Identifier
10.55041/IJSREM68834

License:International Journal of Scientific Research in Engineering and Management follows the Creative Commons Attribution 4.0 (CC BY 4.0) License, allowing free use and distribution with proper attribution.

Share this article:

Authors

Mahesh Prabhakar Lendave

Mahesh Prabhakar Lendave

Department of Master of Computer Application

JCEI’s Jaihind Institute of Management and Research, Vadgaon Sahani

Download Author Certificate
AMP

Asmita Mohan Phatangare

Department of Master of Computer Application

JCEI’s Jaihind Institute of Management and Research, Vadgaon Sahani

Download Co-Author Certificate

Author Services & Downloads

Full ArticlesAcceptance Certificate

Abstract

Writing correct and efficient SQL queries requires the knowledge of the database schema and of the query engine’s behavior. Therefore, direct data access is usually limited to the database experts. Most current natural language to SQL approaches focus on the result correctness of the generated SQL queries and neglect the efficiency of the queries. In this paper, we propose a Python-based multi-agent system which combines query generation and query optimization. Our system consists of five cooperating agents: a schema linking agent, a planning agent, a generation agent, a validation agent, and an optimization agent. These agents communicate with each other using explicit intermediate artifacts and use the database’s feedback, such as the output of EXPLAIN statements and the measured execution time of the generated queries, in order to verify their work. The optimization agent uses sargability-restoring rewrite rules as well as an execution-validated index advisor. It only accepts a change if the result set of the query is unchanged and if, in case of index advice, the latency of the query is decreased. We evaluated our system on SQLite using a synthetic four-table e-commerce database with three scales (10,000 to 200,000 orders) and a benchmark of 56 in-scope questions with independently written gold SQL queries. For all 56 in-scope questions, the generated SQL queries were correct. For eight out-of-scope questions, the system refused six of them and silently mis-answered two. The optimized queries returned identical results to the unoptimized queries in all cases. For 50,000 orders, the full optimizer achieved a geometric mean speedup of 1.79x (95% bootstrap CI 1.44–2.26) and 1.89x for 200,000 orders. The mean latency of the largest scale was decreased from 184.6 ms to 153.6 ms. An ablation study shows that most of the gain is achieved by query rewriting (1.43x alone) and that index advice alone is unreliable (1.13x, with 18% of queries slowed down by more than 10%). Since the planner is rule-based and the data are synthetic, our results demonstrate the value of the generate-validate-optimize loop rather than the open-domain translation accuracy.

KEYWORDS

text-to-SQL AI agents query optimization index selection query rewriting SQLite Python.

Cite This Article

Mahesh Prabhakar Lendave, Asmita Mohan Phatangare, "An AI Agent-Based Approach for Automated SQL Query Generation and Optimization Using Python," International Journal of Scientific Research in Engineering and Management, vol. 10, no. 11, pp. 1-6, Nov 2026. https://doi.org/10.55041/IJSREM68834

Full Article/Conclusion

In this paper, we presented a Python multi-agent pipeline to generate SQL from natural language questions and then optimize it with verified rewrites and measured index advice. We correctly answered all 56 in-scope questions on a synthetic e-commerce workload, with no change to query result, and achieved a geometric mean speedup of 1.79 to 2.07 (depending on scale). Most of the speedup was from rewrite, and index advice was mainly useful in combination with it. We also showed the limitations: modest absolute latency improvement, worse performance on some families, and silent errors on out-of-scope questions.   Future work includes the replacement of rule-based planner and generator with LLM-backed component and testing on public benchmarks with realistic databases. Extending the pipeline to other engines, e.g., PostgreSQL, MySQL. Using hypothetical indexes, cost estimates instead of repeated timing. Measurement of index storage and write overhead. Formal verification of rewrite rules. Abstention mechanism for detecting uncovered parts of question.

References

1. Agrawal, S., Chaudhuri, S., Kollár, L., Marathe, A., Narasayya, V., & Syamala, M. (2004). Database tuning advisor for Microsoft SQL Server 2005. Proceedings of the 30th International Conference on Very Large Data Bases (VLDB), 1110–1121.   2. Chaudhuri, S., & Narasayya, V. R. (1997). An efficient, cost-driven index selection tool for Microsoft SQL Server. Proceedings of the 23rd International Conference on Very Large Data Bases (VLDB), 146–155.   3. Chaudhuri, S. (1998). An overview of query optimization in relational systems. Proceedings of the 17th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS), 34–43.   4. Efron, B., & Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman & Hall.   5. Fleming, P. J., & Wallace, J. J. (1986). How not to lie with statistics: The correct way to summarize benchmark results. Communications of the ACM, 29(3), 218–221.   6. Gao, D., Wang, H., Li, Y., Sun, X., Qian, Y., Ding, B., & Zhou, J. (2024). Text-to-SQL empowered by large language models: A benchmark evaluation. Proceedings of the VLDB Endowment, 17(5), 1132–1145.   7. Katsogiannis-Meimarakis, G., & Koutrika, G. (2023). A survey on deep learning approaches for text-to-SQL. The VLDB Journal, 32. https://doi.org/10.1007/s00778-022-00776-8   8. Kossmann, J., Halfpap, S., Jankrift, M., & Plattner, H. (2020). Magic mirror in my hand, which is the best in the land? An experimental evaluation of index selection algorithms. Proceedings of the VLDB Endowment, 13(12), 2382–2395.   9. Kraska, T., Beutel, A., Chi, E. H., Dean, J., & Polyzotis, N. (2018). The case for learned index structures. Proceedings of the ACM SIGMOD International Conference on Management of Data, 489–504.   10. Li, J., Hui, B., Qu, G., et al. (2023). Can LLM already serve as a database interface? A big bench for large-scale database grounded text-to-SQLs. Advances in Neural Information Processing Systems (NeurIPS), 36, Datasets and Benchmarks Track.

Editorial & Review Transparency

Publication Date

11/9/2026

Peer Review Type

Double-Blind Peer Review

Review Rounds: 2

Documents

Review Report (Confidential)
Copyright Form (Office)

Article Metrics & Impact

Article Views

0

Total views since publication

PDF Downloads

2

Total downloads since publication

Geographic Reach

5

Indexing, Archiving & Preservation

Google Scholar
Academia
ResearchGate
Crossref
SSRN
Semantic Scholar
Thomson Reuters
WorldCat
Mendeley
OpenAlex
EBSCO
Zenodo

Digital Preservation: This article is permanently archived on Zenodo and complies with all data preservation standards across major indexing platforms.

Ethics, Compliance & Transparency

Plagiarism Screening

This manuscript has been checked for plagiarism using TurnitinPlagiarismChecker software.

Conflict of Interest

The authors declare no conflict of interest related to this research work.

Funding Information

No funding information available for this research.

Similar & Recommended Articles

Similar Articles by Topic

Related research in the same subject area

Loading similar articles...