Track-SQL: Enhancing Generative Language Models with Dual-Extractive Modules for Schema and Context Tracking in Multi-turn Text-to-SQL
Organizations: School of Computer Science, Guangdong University of Technology · Guangdong Laboratory of Artificial Intelligence and Digital Economy (SZ) · Peng Cheng Laboratory · College of Science, Shantou University
Abstract
Generative language models have shown significant potential in single-turn Text-to-SQL. However, their performance does not extend equivalently to multi-turn Text-to-SQL. This is primarily due to generative language models' inadequacy in handling the complexities of context information and dynamic schema linking in multi-turn interactions. In this paper, we propose a framework named Track-SQL, which enhances generative language models with dual-extractive modules designed to track schema and contextual changes in multi-turn Text-to-SQL. Specifically, Track-SQL incorporates a Semantic-enhanced Schema Extractor and a Schema-aware Context Extractor. Experimental results demonstrate that Track-SQL achieves state-of-the-art performance on the SparC and CoSQL datasets. Furthermore, detailed ablation studies reveal that Track-SQL significantly improves execution accuracy in multi-turn interactions by 7.1% and 9.55% on these datasets, respectively. Our implementation will be open-sourced at https://github.com/DMIRLAB-Group/Track-SQL.
Figures & tables
| Model | SparC | CoSQL | ||||||||||
| QM | IM | QM | IM | |||||||||
| EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | |
| In-Context Learning Approach | ||||||||||||
| ACT-SQL Zhang et al. (2023) | 51.0 | 63.8 | 56.9 | 24.4 | 38.9 | 29.6 | 46.0 | 63.7 | 55.2 | 13.3 | 30.7 | 21.5 |
| CoE-SQL Zhang et al. (2024a) | 56.0 | 70.3 | 63.3 | 36.5 | 50.5 | 41.9 | 52.4 | 69.6 | 60.6 | 23.9 | 39.6 | 30.4 |
| Fine-tuned Model | ||||||||||||
| QM | IM | |||
| EX | TS | EX | TS | |
| Track-SQL | 75.39 | 69.16 | 57.81 | 50.71 |
| w/o SESE | 68.57( ) | 62.42( ) | 51.42( ) | 45.26( ) |
| w/o ACID | 74.56( ) | 67.91( ) | 56.39( ) | 48.57( ) |
| w/o SACE | 72.73( ) | 67.16( ) | 51.89( ) | 44.78( ) |
| w/o SACE & SESE | 71.40( ) | 65.08( ) | 50.71( ) | 43.36( ) |
| QM | IM | |||
| EX | TS | EX | TS | |
| Track-SQL | 70.60 | 62.26 | 43.67 | 32.76 |
| w/o SESE | 64.94( ) | 58.98( ) | 36.86( ) | 31.74( ) |
| w/o ACID | 68.22( ) | 61.37( ) | 39.24( ) | 32.42( ) |
| w/o SACE | 68.81( ) | 61.46( ) | 37.88( ) | 29.01( ) |
| w/o SACE & SESE | 66.03( ) | 58.88( ) | 34.12( ) | 26.96( ) |
| SparC | CoSQL | |||
| Track-SQL | 8.50 | 21.46 | 12.74 | 25.90 |
| w/o com-enh | 9.57 | 21.05 | 13.62 | 29.93 |
| w/o com&col-enh | 9.44 | 28.18 | 13.38 | 27.42 |
| SESE | SQL Generator | |||
| Train | Inference | Train | Inference | |
| SparC | 30.9±2.8(h) | 0.20(s) | 1.5±0.2(h) | 1.15(s) |
| CoSQL | 27.5±2.4(h) | 0.21(s) | 1.6±0.3(h) | 1.15(s) |
Appendix figures & tables14 assets
Supplementary material from the paper’s appendix.
Appendix
| Easy (483) | Medium (441) | Hard (145) | Extra (134) | |||||||||
| EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | |
| Track-SQL | 81.8 | 84.9 | 83.0 | 64.6 | 72.8 | 66.4 | 44.8 | 64.8 | 53.8 | 35.1 | 54.5 | 38.8 |
| w/o SESE | 77.6 | 78.7 | 77.6 | 56.5 | 68.0 | 59.4 | 42.8 | 59.3 | 46.2 | 30.6 | 44.0 | 35.1 |
| w/o ACID | 79.3 | 85.5 | 82.8 | 62.8 | 72.8 | 65.8 | 44.8 | 63.4 | 49.7 | 39.6 | 53.0 | 41.0 |
| w/o SACE | 79.5 | 84.1 | 81.8 | 63.9 | 71.9 | 66.4 | 39.3 | 60.0 | 48.3 | 32.8 | 48.5 | 37.3 |
| w/o SACE & SESE | 79.1 | 80.7 | 78.5 | 63.3 | 71.7 | 64.2 | 43.4 | 59.3 | 46.9 | 37.3 | 50.0 | 39.6 |
| Easy (417) | Medium (320) | Hard (163) | Extra (107) | |||||||||
| EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | |
| Track-SQL | 80.6 | 85.4 | 82.5 | 51.6 | 67.5 | 55.6 | 36.2 | 59.5 | 46.0 | 24.3 | 39.3 | 28.0 |
| w/o SESE | 75.1 | 79.4 | 76.7 | 50.0 | 60.9 | 51.6 | 36.2 | 53.4 | 46.0 | 25.2 | 38.3 | 31.8 |
| w/o ACID | 78.2 | 83.5 | 81.1 | 52.8 | 65.0 | 56.2 | 31.3 | 55.8 | 44.2 | 22.4 | 37.4 | 26.2 |
| w/o SACE | 78.2 | 83.5 | 80.3 | 50.0 | 61.6 | 51.9 | 35.6 | 62.0 | 48.5 | 29.0 | 43.9 | 36.4 |
| w/o SACE & SESE | 75.8 | 77.7 | 75.8 | 48.4 | 60.9 | 51.6 | 38.0 | 66.3 | 52.8 | 16.8 | 35.5 | 24.3 |
| Turn 1 (422) | Turn 2 (422) | Turn 3 (270) | Turn 4 (88) | Turn > 4 (1) | |||||||||||
| EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | |
| Track-SQL | 74.2 | 79.6 | 76.5 | 65.9 | 75.6 | 67.8 | 57.8 | 67.4 | 59.6 | 51.1 | 68.2 | 60.2 | 0 | 100 | 100 |
| w/o SESE | 70.1 | 75.6 | 71.8 | 60.9 | 69.2 | 61.4 | 51.1 | 60.4 | 53.0 | 40.9 | 58.0 | 52.3 | 0 | 0 | 0 |
| w/o ACID | 72.5 | 80.6 | 77.3 | 64.2 | 75.1 | 66.6 | 56.7 | 67.8 | 59.3 | 54.5 | 64.8 | 56.8 | 0 | 0 | 0 |
| w/o SACE | 72.3 | 79.1 | 75.8 | 63.0 | 72.3 | 64.9 | 55.9 | 65.9 | 59.6 | 51.1 | 65.9 | 60.2 | 0 | 0 | 0 |
| w/o SACE & SESE | 71.3 | 77.0 | 72.7 | 63.7 | 70.9 | 64.0 | 58.9 | 67.0 | 58.5 | 51.1 | 61.4 | 54.5 | 0 | 0 | 0 |
| Turn 1(293) | Turn 2 (285) | Turn 3 (244) | Turn 4 (114) | Turn > 4 (71) | |||||||||||
| EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | EM | EX | TS | |
| Track-SQL | 64.8 | 76.5 | 70.3 | 58.2 | 72.3 | 63.9 | 56.6 | 68.0 | 58.2 | 55.3 | 64.9 | 55.3 | 40.8 | 57.7 | 47.9 |
| w/o SESE | 61.4 | 70.0 | 64.5 | 57.9 | 67.4 | 62.8 | 50.8 | 64.3 | 54.5 | 52.6 | 56.1 | 51.8 | 42.3 | 50.7 | 47.9 |
| w/o ACID | 65.2 | 73.4 | 68.6 | 55.1 | 69.1 | 62.8 | 54.5 | 66.8 | 58.6 | 51.8 | 62.3 | 53.5 | 42.3 | 57.7 | 47.9 |
| w/o SACE | 66.2 | 75.8 | 69.3 | 52.6 | 66.7 | 59.6 | 57.8 | 69.3 | 59.4 | 52.6 | 64.0 | 58.8 | 42.3 | 54.9 | 47.9 |
| w/o SACE & SESE | 62.8 | 71.0 | 65.2 | 55.1 | 68.1 | 62.5 | 52.5 | 65.2 | 55.7 | 50.0 | 58.8 | 50.0 | 35.2 | 52.1 | 43.7 |
| Table-Weighted Avg | Table-Macro Avg | Column-Weighted Avg | Column-Macro Avg | |||||||||
| Precision | Recall | F1 | Precision | Recall | F1 | Precision | Recall | F1 | Precision | Recall | F1 | |
| SESE | 96.48 | 96.43 | 96.45 | 95.74 | 96.42 | 96.07 | 97.09 | 96.93 | 96.99 | 90.95 | 94.34 | 92.55 |
| w/o com-enh | 96.18 | 96.11 | 96.12 | 95.32 | 96.16 | 95.72 | 96.91 | 96.68 | 96.76 | 90.11 | 94.24 | 92.03 |
| w/o com-enh & col-enh | 96.58 | 96.57 | 96.57 | 96.09 | 96.31 | 96.20 | 96.70 | 96.67 | 96.69 | 91.31 | 92.05 | 91.68 |
| Table-Weighted Avg | Table-Macro Avg | Column-Weighted Avg | Column-Macro Avg | |||||||||
| Precision | Recall | F1 | Precision | Recall | F1 | Precision | Recall | F1 | Precision | Recall | F1 | |
| SESE | 95.33 | 95.28 | 95.30 | 94.29 | 94.87 | 94.57 | 96.85 | 96.71 | 96.77 | 89.70 | 92.65 | 91.11 |
| w/o com-enh | 95.32 | 95.30 | 95.31 | 94.47 | 94.66 | 94.57 | 96.81 | 96.79 | 96.80 | 90.90 | 91.24 | 91.07 |
| w/o com-enh & col-enh | 94.65 | 94.39 | 94.45 | 92.83 | 94.64 | 93.64 | 96.40 | 95.98 | 96.13 | 86.97 | 92.78 | 89.59 |
| Case#1 | Question#1 Question#2 Question#3 | What is every student’s id? Of those ids, which correspond to those who own cats as pets? List all the other ids. |
| Gold | SELECT stuid FROM student EXCEPT SELECT T1.stuid FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid = T2.stuid JOIN pets AS T3 ON T3.petid = T2.petid WHERE T3.pettype = ’cat’ | |
| w/o SACE | SELECT stuid FROM has_pet except SELECT stuid FROM has_pet JOIN pets ON has_pet.petid = pets.petid WHERE pettype = ’cat’ | |
| Track-SQL | SELECT stuid FROM student except SELECT student.stuid FROM student JOIN has_pet ON student.stuid = has_pet.stuid JOIN pets ON has_pet.petid = pets.petid WHERE pets.pettype = ’cat’ | |
| SELECT student.stuid FROM student JOIN has_pet ON student.stuid = has_pet.stuid JOIN pets ON has_pet.petid = pets.petid WHERE pets.pettype = ’cat’ | ||
| Case#2 | Question#1 Question#2 Question#3 | How many car models are produced in total? How many in Germany? How about in Japan? |
| Gold | SELECT count(*) FROM MODEL_LIST AS T1 JOIN CAR_MAKERS AS T2 ON T1.Maker = T2.Id JOIN COUNTRIES AS T3 ON T2.Country = T3.CountryId WHERE T3.CountryName = ’japan’ |
| SESE(Inference) | SQL Generator(Inference) | SESE(Train) | SQL Generator(Train) | |||||
| Total time(s) | Avg Time(s) | Total time(s) | Avg Time(s) | Total time(h) | Avg Time(s) | Total time(h) | Avg Time(s) | |
| SparC | 240.348±1.45 | 0.20±0.00013 | 1386.98±2.13 | 1.152±0.025 | 30.93h±2.78 | 3.88±0.43 | 1.45±0.21 | 11.23±2.31 |
| CoSQL | 214.456±2.56 | 0.21±0.0012 | 1170.41±1.56 | 1.15±0.012 | 27.49h±2.43 | 3.92±0.29 | 1.61±0.33 | 11.43±2.51 |
| SESE(Inference) | SQL Generator(Inference) | SESE(Train) | SQL Generator(Train) | |
| Graphics Memory(GB) | 2.235 | 16.477 | 20.997 | 62.194 |
| Input for generating annotated descriptions of database columns |
| You are a database schema designer who specializes in generating concise descriptions for table columns based on the provided column names, types, and sample values. The descriptions should be brief, adjective-noun phrases that reflect the nature of the data in the column. |
| Table Name: {table_name} |
| Column: {column_name} |
| Type: {column_type} |
| Sample Values: {values} |
| Format for fine-tuning SQL generation |
| Input : |
| You are a SQL query generator that converts multi-turn questions along with associated database schema information into corresponding SQL statements. The multi-turn questions will be concatenated using the ‘ ’ symbol, and you should generate the SQL statement that answers the current turn of the question based on the provided database schema. |
| Each database schema is provided in the following format: |
| Table name : Column name1, Column name2 Different tables are separated by the ‘|’ symbol, and the order of table names and column names is relevant to the current question; those appearing earlier are more closely related. |
| Base SQL: { } |
Text-to-SQL
Text-to-SQL translates natural-language questions into executable database queries, linking user intent to schemas, values, and SQL logic.
See all 173 papers