Papers
Topics
Authors
Recent
Search
2000 character limit reached

Multiset semantics in SPARQL, Relational Algebra and Datalog

Published 1 May 2026 in cs.DB and cs.LO | (2605.00417v1)

Abstract: The paper analyzes and characterizes the algebraic and logical structure of the multiset semantics for SPARQL patterns involving AND, UNION, FILTER, EXCEPT, and SELECT. To do this, we align SPARQL with two well-established query languages: Datalog and Relational Algebra. Specifically, we study (i) a version of non-recursive Datalog with safe negation extended to support multisets, and (ii) a multiset relational algebra comprising projection, selection, natural join, arithmetic union, and except. We prove that these three formalisms are expressively equivalent under multiset semantics.

Summary

  • The paper demonstrates the formal expressive equivalence across core SPARQL, Multiset Relational Algebra, and Non-Recursive Datalog with safe negation.
  • It formalizes translation mechanisms that preserve multiset semantics, including operators like AND, UNION, and EXCEPT, across the languages.
  • The results provide a theoretical basis for query optimization and system design by ensuring robust algebraic-logical correspondence in multiset query processing.

Multiset Semantics in SPARQL, Relational Algebra, and Datalog

Introduction

This work provides a comprehensive algebraic and logical analysis of multiset (bag) semantics as implemented in the core fragment of SPARQL, Relational Algebra, and Datalog. The study targets the core SPARQL operators (AND, UNION, FILTER, EXCEPT, SELECT) and investigates their expressive power over multisets, establishing formal equivalence with corresponding fragments of Multiset Relational Algebra (MRA) and Non-Recursive Datalog with Safe Negation (NRMD¬). The main contribution is a rigorous demonstration that these formalisms are expressively equivalent for multiset queries, supplying precise translations for queries, databases, and results between them.

Background and Motivations

Multisets—collections in which element multiplicity matters—arise in database systems primarily due to practical performance and application-driven requirements, such as aggregation and the prohibitive cost of duplicate elimination. Despite being well-studied in sets, extending classical query languages (including relational algebra, Datalog, and SPARQL) to support multisets introduces considerable complexity. The design space is broad because set-theoretic operations (union, intersection, difference) admit multiple inequivalent multiset extensions, as reflected in SQL and SPARQL variants. This leads to ambiguity and complexity in expressiveness and containment questions.

Prior work has addressed algebraic structures for bags (e.g., BALG [90190], BQL [90191]), expressive power, tractability, and query translation and containment under bag semantics in relational and logic-based languages (e.g., [91030], [91368], [90820], [91353]). For SPARQL, the challenge has been to formalize and relate its multiset semantics to those of classical query frameworks; previous studies have often neglected multiplicity or lacked an encompassing algebraic-logical correspondence.

Formalizations: Multiset SPARQL, MRA, and NRMD¬

Multiset SPARQL

The paper isolates a “relational core” fragment of SPARQL, which includes graph pattern queries built using AND, UNION, FILTER, EXCEPT, and SELECT, while restricting attention to queries and subqueries expressible without OPTIONAL and MINUS. The semantics assigns a multiset of solution mappings to each query—each mapping assigning variables to RDF terms, with cardinality tracking the number of derivations.

The semantics of the core pattern operators under multisets are as follows:

  • AND: Compatible mappings are joined, multiplicities multiply;
  • UNION: Multiset addition of mapping counts;
  • EXCEPT: Mappings present only in the left operand are retained with their original count;
  • FILTER: Mapping preserved iff the filter is satisfied (three-valued logic);
  • SELECT: Projection with multiplicities summed over mappings yielding the same projected tuple.

Normalization ensures that all unions and differences are between multisets with the same schema, easing translation to relational algebra and Datalog.

Non-Recursive Multiset Datalog with Safe Negation (NRMD¬)

Multiset Datalog is extended to allow for multisets in the extensional database and the number of derivations of a fact determines multiplicity. Only non-recursive programs (acyclic dependency graph) with safe rules and safe negation are considered, matching the expressiveness of the SPARQL fragment.

Proof-theoretic semantics is adopted: answers are counted by the number of distinct derivation trees. To facilitate translation, NRMD¬ programs are normalized to a restricted form: rules correspond either to projection, join, or safe negation.

Multiset Relational Algebra (MRA)

MRA is defined via the following operators:

  • Projection (π\pi): Sums multiplicities of tuples mapped to the same projection;
  • Selection (σ\sigma): Filters with multiplicity preserved;
  • Join (\Join): Cartesian product with compatible tuples, multiplicities multiply;
  • Arithmetic Union (\cup): Adds multiplicities;
  • Except (\setminus): Keeps multiplicity from minuend for tuples not in subtrahend.

All relational analogs use arithmetic (bag) semantics, and normalization ensures unions/differences operate over the same schema.

Main Results

Expressive Equivalence

The principal theorems establish that the multiset semantics of the core SPARQL, MRA, and NRMD¬ are mutually expressible. Translation functions are formally constructed in both directions for each pair, mapping databases, queries, and answers such that semantics (including multiplicity) is preserved.

Key Translation Mechanisms

  • SPARQL \leftrightarrow NRMD¬: SPARQL patterns are recursively mapped to Datalog rules; AND becomes join, UNION becomes Datalog union, EXCEPT becomes safe negation. Mapping multiplicity is preserved via correspondence with the number of derivation trees.
  • SPARQL \leftrightarrow MRA: SPARQL patterns translate to normalized RA expressions, using explicit handling of unbound variables as special nulls. The challenge of expressing compatibility joins and multiset projections is addressed using additional relations for nulls and compatibility.
  • NRMD¬ \leftrightarrow MRA: Safe, non-recursive Datalog rules correspond to queries over MRA with the same set of operators, using constructed translation tables for atomic, join, projection, and negation rules.

A simulation diagram (triangle) is established, closing all translation links, thereby proving that all three languages express exactly the same class of multiset queries.

Strong and Notable Claims

  • Full Equivalence: The multiset semantics of the specified SPARQL core is neither strictly more nor less expressive than MRA with aforementioned operators or non-recursive safe Datalog with negation and bags.
  • Sufficiency of Core Operators: No further multiset operator is needed for full expressiveness within these fragments; particularly, optional and set-based operators do not add expressive power in this fragment.
  • Algebraic Simplicity: There exists a canonical MRA fragment that precisely matches the logical expressiveness of NRMD¬ and the core SPARQL, facilitating theoretical analysis and system implementation.

Implications

The clear algebraic-logical characterization of multiset semantics across SPARQL, RA, and Datalog has several significant implications:

  1. Theory Transfer: Classical results on complexity, optimization, and normal forms for bag semantics in relational algebra/datalog directly inform analysis and implementation in SPARQL engines.
  2. Query Optimization: The structural insights enable principled query rewriting and optimization under multiset semantics, including bag-aware containment, minimization, and translation to SQL.
  3. Design Guidance: The correspondence highlights that SPARQL’s design in the core is algebraically clean and does not yield anomalous behavior seen in some SQL bag operations; it cautions against ad hoc multiset operator proliferation in future SPARQL extensions.
  4. Foundation for Extensions: The work serves as a rigorous basis for future theoretical developments concerning aggregation, recursion, or additional operators in multiset query processing in both SPARQL and Datalog.

Directions for Future Research

Future lines of inquiry may include:

  • Extending the equivalence to fragments beyond the relational core (i.e., including OPTIONAL, MINUS, aggregates) and determining whether bag semantics can be tightly characterized in those cases.
  • Systematic comparison with combined or hybrid bag-set semantics present in real-world SQL engines and SPARQL systems.
  • Investigating the complexity and tractability of containment, minimization, and other forms of analysis in richer versions of SPARQL and its logical counterparts under multiset semantics.
  • Exploring formal foundations for bag semantics with incomplete or uncertain information, building on the logical toolkit developed here.

Conclusion

This work delivers a formally complete alignment of multiset/bag semantics in the core of SPARQL, MRA, and Datalog, with explicit translation frameworks showing expressive equivalence. This result enables rigorous theoretical transfer, principled system design, and lays a foundation for deeper investigation into multiset query languages and their practical applications in modern data systems.

Reference:

"Multiset semantics in SPARQL, Relational Algebra and Datalog" (2605.00417)

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.