Skip to main content
QUICK REVIEW

[Paper Review] Queries with Guarded Negation (full version)

Vince Bárány, Balder ten Cate|arXiv (Cornell University)|Mar 1, 2012
Advanced Database Systems and QueriesComputer Science36 references6 citations
TL;DR

This paper introduces GN-SQL and GN-Datalog, query languages that restrict negation to guarded form—ensuring negative conditions apply only to tuples sharing a common context—thereby enabling decidable and efficient query processing. The key contribution is proving that fundamental problems like query containment, evaluation, and boundedness are decidable and have tractable complexity for these languages, subsuming major existing languages and covering most practical SQL negation patterns.

ABSTRACT

A well-established and fundamental insight in database theory is that negation (also known as complementation) tends to make queries difficult to process and difficult to reason about. Many basic problems are decidable and admit practical algorithms in the case of unions of conjunctive queries, but become difficult or even undecidable when queries are allowed to contain negation. Inspired by recent results in finite model theory, we consider a restricted form of negation, guarded negation. We introduce a fragment of SQL, called GN-SQL, as well as a fragment of Datalog with stratified negation, called GN-Datalog, that allow only guarded negation, and we show that these query languages are computationally well behaved, in terms of testing query containment, query evaluation, open-world query answering, and boundedness. GN-SQL and GN-Datalog subsume a number of well known query languages and constraint languages, such as unions of conjunctive queries, monadic Datalog, and frontier-guarded tgds. In addition, an analysis of standard benchmark workloads shows that most usage of negation in SQL in practice is guarded negation.

Motivation & Objective

  • To address the computational intractability of negation in standard query languages by restricting it to guarded form.
  • To define GN-SQL and GN-Datalog as practical, well-behaved query languages that support useful forms of negation.
  • To show that core database problems—like query containment and open-world query answering—are decidable and efficiently solvable under guarded negation.
  • To demonstrate that guarded negation captures most real-world SQL usage patterns, making it both theoretically sound and practically relevant.
  • To extend known decidability results from logic to database query languages, generalizing prior work on monadic Datalog and unions of conjunctive queries.

Proposed method

  • Define GNFO (guarded-negation first-order logic) and GNFP (guarded-negation fixed-point logic) as foundational formalisms for guarded negation.
  • Introduce GN-SQL as a syntactic fragment of SQL where negation is restricted to guarded conditions, ensuring translation into GNFO.
  • Define GN-Datalog as a Datalog variant with stratified negation, where negated atoms must be guarded by EDB atoms in the same tuple.
  • Prove that GN-SQL and GN-Datalog are expressively complete for GNFO and GNFP, respectively, via logical and algebraic characterizations.
  • Analyze real-world SQL benchmark workloads to show that most practical negation is guarded, justifying the restriction.
  • Establish complexity bounds using reductions and translations into GNFO/GNFP, leveraging known results from finite model theory.

Experimental results

Research questions

  • RQ1Can negation in SQL and Datalog be restricted in a way that preserves decidability of core query problems while remaining expressive?
  • RQ2Is guarded negation sufficient to capture most practical uses of negation in real-world SQL workloads?
  • RQ3What is the combined and data complexity of query evaluation, containment, and open-world query answering for guarded-negation languages?
  • RQ4Is the boundedness problem decidable for Datalog with guarded negation, and how does it compare to known results for monadic Datalog?
  • RQ5Can GN-SQL and GN-Datalog be extended with constants, comparisons, or aggregation while preserving decidability and tractability?

Key findings

  • Query containment for GN-SQL and GN-Datalog is 2ExpTime-complete, which is decidable and within a well-understood complexity class.
  • Query evaluation for GN-SQL has combined complexity in P^NP[log²], and for GN-Datalog in P^NP, indicating efficient tractability under reasonable assumptions.
  • Open-world query answering for GN-SQL is coNP-complete in data complexity, and solvable in PTime for a significant fragment.
  • The boundedness problem for GN-Datalog is decidable, generalizing the known decidability for monadic Datalog.
  • GN-SQL and GN-Datalog subsume unions of conjunctive queries, monadic Datalog, and frontier-guarded tgds, showing broad expressive power.
  • Most negation in standard SQL benchmark workloads is guarded, validating the practical relevance of the restriction.

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.