Skip to main content
QUICK REVIEW

[Paper Review] CodexDB: Generating Code for Processing SQL Queries using GPT-3 Codex

Immanuel Trummer|arXiv (Cornell University)|Apr 19, 2022
Mathematics, Computing, and Information ProcessingComputer Science5 citations
TL;DR

CodexDB is a novel SQL processing engine that generates query execution code from natural language instructions using OpenAI's GPT-3 Codex model. By decomposing complex SQL queries into natural language processing steps, enriching them with user-provided customization instructions and schema metadata, and prompting Codex to generate code, the system achieves correct code generation for 81% of WikiSQL benchmark queries, demonstrating the feasibility of natural language-driven database customization without low-level coding expertise.

ABSTRACT

CodexDB is an SQL processing engine whose internals can be customized via natural language instructions. CodexDB is based on OpenAI's GPT-3 Codex model which translates text into code. It is a framework on top of GPT-3 Codex that decomposes complex SQL queries into a series of simple processing steps, described in natural language. Processing steps are enriched with user-provided instructions and descriptions of database properties. Codex translates the resulting text into query processing code. An early prototype of CodexDB is able to generate correct code for a majority of queries of the WikiSQL benchmark and can be customized in various ways.

Motivation & Objective

  • To enable non-expert users to customize database query processing without writing code.
  • To address the high barrier to modifying traditional DBMSs, which require deep expertise and millions of lines of code.
  • To explore whether large language models can generate correct, customizable query execution code from natural language specifications.
  • To prototype a system that integrates natural language instructions into the query processing pipeline via code generation.
  • To evaluate the feasibility and limitations of using LLMs for end-to-end database query customization.

Proposed method

  • Decomposing complex SQL queries into a sequence of simple, natural language processing steps using text templates.
  • Enhancing each processing step with user-provided natural language instructions and database schema/physical layout information.
  • Constructing a prompt for GPT-3 Codex that combines the enriched processing steps and metadata to generate executable code.
  • Using few-shot prompting with example programs to improve code generation reliability and success rate.
  • Integrating generated code samples into runtime prompts to increase consistency and correctness.
  • Validating generated code on the WikiSQL benchmark and measuring execution performance under different instruction sets.

Experimental results

Research questions

  • RQ1Can natural language instructions be effectively used to customize query processing code generation in a database system?
  • RQ2To what extent can GPT-3 Codex generate correct and efficient code for complex SQL queries when guided by natural language descriptions and schema metadata?
  • RQ3How does the integration of user-provided instructions affect the correctness and behavior of generated code?
  • RQ4What are the limitations of current LLM-based code generation in the context of database query processing?
  • RQ5Can a prototype system achieve high code generation accuracy while supporting diverse customization goals like logging, library usage, and performance tuning?

Key findings

  • CodexDB achieved correct code generation for up to 81% of queries in the WikiSQL benchmark, depending on the scenario and model variant.
  • The system successfully generated code that used specific libraries (e.g., pandas, vaex) as instructed, though some generated programs included redundant imports.
  • Performance measurements showed that instruction-based code generation led to measurable differences in execution time, indicating that generated code reflects the intended behavior.
  • 100% of programs generated under logging instructions contained print statements, with 13% including variable outputs, confirming that instructions were interpreted and implemented as intended.
  • The inclusion of example programs in prompts significantly improved code generation reliability, suggesting that few-shot prompting is effective for this task.
  • Manual inspection revealed that while most generated code followed the intended logic, some cases showed suboptimal patterns, such as importing libraries without full utilization.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.