arXiv:2610.22705cs.DBOct 2026

Manuscript Offprint

arXiv:2610.22705

Data Provenance Aggregation and Structural Descriptors for Query-Template Identification

Paulo Pintor, Rogério Costa, José Moreira

Abstract

Runtime query similarity identification supports several activities, including workload analysis, identifying recurring behaviour, auditing, debugging, and anomaly detection. Existing methods for evaluating query similarity mostly rely on SQL text, execution plans, or result values but do not account for input data or how results are derived during query execution.

This paper proposes a novel approach using data provenance for query-template identification. We construct query-level profiles that capture explicit data dependencies, occurrence frequencies, and structural properties by aggregating tuple-level Lineage and Why-provenance across entire query results. We also derive Provenance Structural Descriptors (PSD), which summarise these profiles using a small set of numerical features.

We evaluate our proposals using these profiles to identify query templates over 12,500 distinct query instances generated from parametrised TPC-DS query templates. The experimental evaluation shows that query templates can be identified solely from their provenance footprints, and that accuracy improves as more historical data becomes available. It also shows that PSD achieve high classification accuracy with limited training history and low test-processing cost.

Keywords: Data provenance, Query similarity, Query-level provenance, Lineage, Why-provenance

1 Introduction

Modern data systems execute large numbers of queries, many of which are generated from a smaller set of parametrised templates representing routine tasks or user intents [1–3]. Given this templated structure, characterising queries and measuring their similarity is important to cluster and summarise workloads [1, 3], identify recurring execution patterns [2, 4], or relate new queries to historical workloads [5], as well as for downstream applications such as auditing, debugging, user profiling, and anomaly detection [6, 7].

Existing approaches to characterising queries and measuring their similarity obtain their features from the query text or its abstract syntax tree [8, 9], from execution plans and runtime statistics [10], or from the results the queries return [11, 12], including the most recent AI-based methods [10, 13]. While effective at capturing how a query is written, executed, or what it returns, these features provide limited insight into how its results derive from the underlying data: queries with different text may produce the same results through different derivations, whereas queries with similar text or results may access and combine data in very different ways.

Data provenance formally describes the relationship between a query’s output and the underlying source data. Rather than recording only the result, provenance models capture information about how each output tuple is derived. Depending on the model, this information may identify contributing input tuples, explain why an output tuple appears, or describe how alternative derivations combine [14–18]. This offers a way to characterise queries based on their underlying data dependencies, complementing the features used by existing approaches and providing a basis for measuring query similarity and classifying queries according to how their results are derived.

In this work, we investigate query-template identification using data provenance. The task is to predict the parametrised query template that generated a given query instance. A template is a parametrized query where constants are replaced by variables. Our hypothesis is that there are template-specific characteristics that remain consistent across parameter instantiations and discriminative across different templates. To make it usable for query-template identification, we aggregate tuple-level provenance across each query result into query-level representations, without requiring correspondences between individual output tuples. The resulting representations make contributing tuples and derivational structure available as features for query-template identification, allowing the task to be addressed through observed data dependencies rather than SQL text, execution plans, or result values.

We consider two established provenance abstractions: Lineage, which records the input tuples contributing to an output tuple, and Why-provenance, which additionally captures alternative derivations and their conjunctive structure through witnesses. We formalize set-based aggregations, which record the presence of contributing tuples or witnesses, and bag-based aggregations, which capture their occurrence frequencies across the query result. Building on these abstractions, we investigate two complementary approaches to comparing query executions. The first examines structural representations that preserve varying degrees of derivational detail, ranging from flat contributing tuples to atomic or blocked witness compositions, using specialized similarity measures. The second encodes provenance characteristics as numerical feature vectors, including both fine-grained identity-based representations and a novel set of compact, fixed-dimension metrics termed Provenance Structural Descriptors (PSD), enabling query-template classification via standard nearest-neighbor and supervised machine learning methods. The main contributions are:

• We formalise set-based and bag-based aggregations of tuple-level Lineage and Why-provenance for characterising and classifying complete query executions.

  • We define and evaluate provenance representations that preserve different information, including contributing tuple identities, complete witness identities, occurrence frequencies, and compact structural descriptors.

  • We introduce a candidate-restricted comparison procedure for Why-provenance that recognises partial witness overlap while limiting the query- and witness-level comparisons performed.

• We analyse classification effectiveness and test-processing cost across classifiers and training-history sizes, and assess PSD feature contributions through model attributions, descriptor-group comparisons, and single-descriptor experiments.

The results show that query-level provenance provides an effective basis for query-template identification, offering a complementary perspective based on how database tuples contribute to the derivation of query results. This perspective makes explicit relationships that are not disclosed in previous work, such as queries producing identical results from different contributing tuples. The proposed framework can be deployed independently to classify queries according to their actual data usage or integrated with syntax-, plan-, and result-based techniques. This integration enables workload characterization from multiple perspectives and can improve the identification of recurring query patterns for anomaly detection, user profiling and other analysis tasks.

The remainder of this paper is organised as follows. Section 2 introduces the relevant provenance concepts, reviews related work, and presents motivating examples. Section 3 formalises the query-level aggregations and defines the resulting representations and comparison procedures. Section 4 describes the experimental setup and implementation, presents the results, and discusses their implications. Finally, Section 5 summarises the contributions and outlines directions for future work.

References (32)