MEM-SQL: Memory-Empowered Text-to-SQL

Xiaoqi Wang, Wenqi Pei, Shizheng Hou, Yilai Liu, Han Chen, Boyan Li, Yuyu Luo, Hongyang Du

arXiv:2611.18338 · 2026-11-16 공개 · arXiv · PDF

natural-language-processing text-to-sql sql-generation schema-linking query-reuse benchmark-hare on-demand-schema-linking verified-queries

Abstract

Text-to-SQL systems translate natural language questions into SQL queries over increasingly complex databases. However, widely used benchmarks evaluate questions independently, overlooking settings where earlier queries over the same database can supply joins or calculations for a new question. We introduce HARE (History-AwaRe Text-to-SQL BEnchmark) to measure the accuracy and cost of adapting historical SQL. HARE comprises 1,600 requests derived from a fixed pool of 823 verified queries across four datasets. Annotations record which components each request preserves and which edits it requires, distinguishing whole-query adaptation from partial reuse. Our method, MEM-SQL (Memory-EMpowered Text-to-SQL), stores whole-query templates, reusable SQL blocks, and mappings from domain concepts to schema elements. MEM-SQL uses a layer only if every requirement assigned to it has a match above that layer's threshold. With On-demand Schema Linking (OSL), MEM-SQL consults the schema only when no layer qualifies or the generator judges retrieved evidence insufficient. Across six language models on HARE, mean execution accuracy rises from 37.1% for Direct Generation without history to 50.0% for MEM-SQL, with 76.6% fewer input tokens and 68.8% lower latency on average. Further analysis shows that requests reusing several verified queries remain a bottleneck, with accuracy falling from 56.7% to 29.7%, most sharply when reused components must be placed in a new query structure or combined with a shared join. Applying OSL to three other memory designs consistently reduces generation cost, while its accuracy benefit depends on the memory design. Verified history can thus make generation both more accurate and cheaper, but its value depends on the evidence retained and when the system consults the schema.

한국어 요약

한 줄 요약

MEM-SQL은 기존 SQL 쿼리 히스토리를 활용해 Text-to-SQL 생성 정확도와 효율성을 동시에 향상시키는 시스템이다.

핵심 기여도

핵심 아이디어

기존 Text-to-SQL 시스템은 독립적인 질문을 기준으로 평가되며, 동일 데이터베이스 내 이전 쿼리의 재사용을 고려하지 않았다. MEM-SQL은 이전에 검증된 SQL 쿼리(Verified Queries)를 메모리에 저장하고, 새로운 질문이 이를 부분적으로 또는 전체적으로 재사용할 수 있도록 한다. 이는 전체 쿼리 템플릿, 재사용 가능한 SELECT 블록, 도메인 개념과 스키마 요소 간 매핑을 3단계 메모리 계층으로 구분하여 관리한다. MEM-SQL은 각 계층의 요구사항이 해당 계층의 임계값 이상으로 매칭될 때만 해당 계층을 사용하며, 이는 불완전한 정보가 결과에 영향을 주는 것을 방지한다. OSL 알고리즘은 스키마를 참조하는 시점을 지연시켜, 불필요한 스키마 링킹을 줄인다.

기술적 접근법

주요 결과

의의 및 한계

MEM-SQL은 기존 Text-to-SQL 시스템이 독립적인 질문만 처리하는 한계를 극복하고, 동일 데이터베이스 내 쿼리 히스토리를 활용해 정확도와 효율성을 동시에 향상시킨다. 특히, OSL을 통해 스키마 참조를 최소화함으로써 대규모 데이터베이스에서도 성능을 개선할 수 있다. 그러나 HARE는 스키마 드리프트(정의 변경)를 고려하지 않으며, MEM-SQL은 정적 메모리 기반으로 동적 환경에서의 성능 변화를 평가하지 못한다는 한계가 있다. 또한, 실행 정확도는 형식 차이(예: 반올림)나 논리 오류를 감지하지 못한다.

실용적 활용

MEM-SQL은 기업 데이터베이스에서 반복적인 쿼리 요청이 많은 상황(예: BI 분석, 고객 지원)에 유용하게 적용될 수 있다. 특히, 기존 쿼리 히스토리를 활용해 비용을 절감하고, 사용자 질문에 대한 응답 정확도를 높이는 데 기여할 수 있다.