Synthesizing Document Database Queries using Collection Abstractions

Qikang Liu, Yang He, Yanwen Cai, Byeongguk Kwak, Yuepeng Wang

Abstract

Document databases are increasingly popular in various applications, but their queries are challenging to write due to the flexible and complex data model underlying document databases. This paper presents a synthesis technique that aims to generate document database queries from input-output examples automatically. A new domain-specific language is designed to express a representative set of document database queries in an algebraic style. Furthermore, the synthesis technique leverages a novel abstraction of collections for deduction to efficiently prune the search space and quickly generate the target query. An evaluation of 110 benchmarks from various sources shows that the proposed technique can synthesize 108 benchmarks successfully. On average, the synthesizer can generate document database queries from a small number of input-output examples within tens of seconds.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Total: 110 benchmarks from StackOverflow, MongoDB Document, Twitter API, and KaggleNosdaqbenchmarks solved108 benchmarkstime-limit=5 minutes · benchmark-count=110
Source quote
L630: \multirow{4}{=}{Total} │ \multirow{4}{*}{110} │ \multirow{4}{*}{108} │ avg │ 14.2 │ 175 │ 57 │ 13
Total: 110 benchmarks from StackOverflow, MongoDB Document, Twitter API, and KaggleNosdaqaverage synthesis time14.2 stime-limit=5 minutes · benchmark-count=110
Source quote
L630: \multirow{4}{=}{Total} │ \multirow{4}{*}{110} │ \multirow{4}{*}{108} │ avg │ 14.2 │ 175 │ 57 │ 13
Synthesized queries from the 110-benchmark evaluationNosdaqqueries equivalent to the desired ones107 queriesinspection=manual · benchmark-count=110
Source quote
L647: To understand if Nosdaq\xspace can synthesize desired queries, we have manually inspected all 108 synthesized queries and found 107 of them are equivalent to the desired ones. There is only one benchmark (from StackOverflow) where Nosdaq\xspace synthesized a plausible query in terms of the example but the query is not desired.
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
110 document database query benchmarksEUSolver baselinebenchmarks solved25 benchmarkstime-limit=5 minutes · benchmark-count=110
Source quote
L669: As shown in Figure~\ref{fig:baseline}, as opposed to 108 benchmarks solved by Nosdaq\xspace, EUSolver\xspace can only solve {25} benchmarks within the 5-minute time limit due to the large search space of document database queries in general.
110 document database query benchmarksChatGPT (gpt-4o-2024-08-06) baselinebenchmarks for which the generated query was desired53 benchmarksinput=input-output examples and constants; no natural-language description · model=gpt-4o-2024-08-06 · benchmark-count=110
Source quote
L674: To compare Nosdaq\xspace with the LLM-based approach, we have used ChatGPT (version gpt-4o-2024-08-06) to synthesize all of our 110 benchmarks. Specifically, we have used the same set of input-output examples and constants in each benchmark and asked ChatGPT to generate MongoDB queries. To make fair comparisons, we did not provide additional natural language descriptions about what the query should do. The evaluation shows that GPT can only generate the desired query for 53 out of 110 benchmarks. For 24 benchmarks, the generated query is plausible but undesired, i.e., it is consistent with the examples but not equivalent to the desired one. For the remaining 33 benchmarks, the generated query is inconsistent with the input-output examples. The errors made by GPT include misunderstanding the semantics of operators, missing predicates, etc. Recall that Nosdaq\xspace can synthesize desired queries for 107 benchmarks and plausible but undesired query for 1 benchmark. We believe our synthesis technique is more effective and generalizable than GPT to synthesize document database queries from examples.
BibTeX
@misc{liu2024synthesizing,
  author = {Qikang Liu and Yang He and Yanwen Cai and Byeongguk Kwak and Yuepeng Wang},
  title = {{Synthesizing Document Database Queries using Collection Abstractions}},
  year = {2024},
  eprint = {2412.06102},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.06102},
}

Loading related content...

Figure