Problem
System analysts at a large company spend much of their time writing and tuning SQL against a corporate data warehouse. Query mistakes and weak knowledge of the schema waste time and make the analytics less accurate. A general-purpose LLM does not know how a given warehouse's tables are joined. The author tests whether a small model adapted to the warehouse's own queries can suggest tables, JOIN conditions and query fragments.
Example from the article: a training query is split into an input, SELECT s.date, c.category_name, p.supplier_id FROM sales s, and an output with the JOINs and the date filter.
Solution in brief
Take a code-oriented LLM (DeepSeek Coder 1.3B) and fine-tune it with LoRA on SQL queries, each cut into a "question" (the beginning) and an "answer" (the continuation). Score the output with a token-level ROUGE-L adapted to SQL and with an AST-plus-Levenshtein similarity. The experiment used synthetic logs from a toy schema, so it shows the pipeline, not production accuracy.
Questions this case answers
- How to adapt a code-generation model to one database schema from its query history when full fine-tuning is too expensive
- How to measure the structural similarity of generated SQL queries to reference queries without executing them
- How to help warehouse analysts find the right tables and JOIN conditions when writing SQL?
- How to fine-tune a small code LLM on a warehouse's own query history without full retraining?
Tools and methods
- DeepSeek Coder 1.3B instruct — base code model from Hugging Face.
- LoRA — trains small low-rank matrices instead of all weights.
- Synthetic SQL log generator — builds queries from an Excel schema description.
- ROUGE-L-SQL — longest-common-subsequence score over SQL tokens.
- AST similarity with Levenshtein distance — structural match that ignores aliases and literals.
Google or a one-time email code. No password.