FuncEvalGMN: Evaluating Functional Correctness of SQL via Graph Matching Network

Yi Zhan, Yang Sun, Han Weng, Longjie Cui, Guifeng Wang, Jiajun Xie, Yu Tian, Xiaoming Yin, Boyi Liu, Dongchi HuangarXiv 2024 · DOI

Evaluating the quality of AI-generated SQL code presents a significant challenge. Traditional metrics often fall into two traps: Execution Accuracy (EA) can yield "false positives" where logically flawed queries happen to work on specific sample data, while Text Matching metrics (like BLEU or ROUGE) produce "false negatives" by penalizing valid SQL that simply uses different syntax than the reference.

To bridge this gap, researchers from ByteDance have introduced FuncEvalGMN, a graph-based evaluation framework. FuncEvalGMN assesses the "functional correctness" of SQL by analyzing its underlying logical structure rather than its surface-level syntax or output.

The FuncEvalGMN Pipeline

FuncEvalGMN treats SQL evaluation as a graph matching problem. The process involves transforming SQL queries into rich logical representations and using a specialized neural network to compare them.

Overview of the FuncEvalGMN pipeline, illustrating the stages from dataset construction to final evaluation score.

The pipeline consists of four main stages:

  1. Dataset Construction: Pairs of reference and generated SQL are collected.
  2. Graph Construction: SQL is parsed into a logical execution plan rather than a simple syntax tree.
  3. Graph Matching: A Graph Matching Network (GMN) computes a similarity score between the reference and generated graphs.
  4. Evaluation: The final score determines the functional equivalence of the generated code.

Structural Representation: RelNode vs. AST

A core innovation of FuncEvalGMN is the use of the Relational Operator Tree (RelNode). While a standard Abstract Syntax Tree (AST) merely mirrors the grammar of the code, the RelNode (generated via Apache Calcite) represents the logical execution plan.

Comparison between a standard AST and the proposed RelNode graph, highlighting how RelNodes capture logical operations and data flows.

By abstracting away syntactic variations—such as using MAX() versus ORDER BY ... LIMIT 1—the RelNode focuses on the operations that actually define the query's behavior. This representation is further augmented with "logic flows" and "data flows," creating a comprehensive program graph.

Graph Matching with Cross-Attention

To compare these graphs, the framework employs a Graph Matching Network (GMN). Unlike standard Graph Neural Networks that process graphs in isolation, the GMN uses cross-graph attention to align nodes between the generated and reference queries.

A critical component is the Global Positional Embedding (PE). By identifying "seed nodes" (nodes that are clearly identical across both graphs) and performing random walks, the model learns the relative hierarchy of nodes. This allows it to recognize that a specific column reference in one query serves the same functional purpose as a differently placed reference in another.

Experimental Results

The authors evaluated FuncEvalGMN on the Spider and BIRD benchmarks, as well as a custom Spider-Pair dataset designed to test robustness against syntactically diverse but functionally identical queries.

Key findings include:

  • Superior Accuracy: On the challenging test-aug dataset, FuncEvalGMN achieved an 84.8% AUC, significantly outperforming GPT-4 (75.6%) and traditional metrics like CodeBLEU (57.9%).
  • Impact of RelNode: Ablation studies showed that switching from a standard AST to the optimized RelNode representation improved performance by 39% on augmented test sets.
  • Efficiency: FuncEvalGMN provides a scalable evaluation metric that does not require a live database environment, making it ideal for integration into large-scale training loops.

Conclusion and Future Directions

FuncEvalGMN demonstrates that logical intent is a more reliable signal for SQL evaluation than raw syntax or brittle execution results. While the model shows some performance degradation on highly complex schemas (like those in the BIRD dataset), it sets a new state-of-the-art for functional correctness metrics. Future work aims to expand support for vendor-specific SQL keywords and explore the application of this graph-matching approach to general-purpose programming languages like Python.

Summary updated

BibTeX
@misc{zhan2024funcevalgmn,
  author = {Yi Zhan and Yang Sun and Han Weng and Longjie Cui and Guifeng Wang and Jiajun Xie and Yu Tian and Xiaoming Yin and Boyi Liu and Dongchi Huang},
  title = {{FuncEvalGMN: Evaluating Functional Correctness of SQL via Graph Matching Network}},
  year = {2024},
  eprint = {2407.14530},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.14530},
}
Figure