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.
Figures & tables
Cust
Segment
Token
c1
Retail
t1
c2
Retail
t2
Figure 1: Database instance for the running example.
Status
Why
Lineage
Open
{{t1,t3},{t2,t4}}
{t1,t2,t3,t4}
Shipped
{{t1,t5}}
{t1,t5}
Figure 2: Result of Q1 with Why-provenance and Lineage.
Classifier
Metric
PSD
Lineage
Atomic Why
Token TF
Witness TF
Blocked Why
1-NN
Acc
0.9928
0.9968
0.9672
0.9272
0.8796
0.9958
F1
0.9928
0.9968
0.9671
0.9175
0.8623
0.9958
Mean test time (ms/execution)
0.0853
283.6
192.6
7.238
5.031
4315.7
5-NN
Acc
0.9836
0.9972
0.9452
0.8908
0.8000
0.9968
F1
0.9836
0.9972
0.9462
0.8706
0.7686
0.9968
Mean test time (ms/execution)
0.0969
283.2
192.6
7.123
5.008
5949.4
Table 1: Classification effectiveness and mean test-processing time with 10,000 training and 2,500 test executions.