arXiv(opens in a new tab)cs.DBOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.08089

When Plans Change Answers: Formalizing Cost-Accuracy Optimization for Semantic Queries

Kyoungmin Kim

Abstract

In semantic query engines, predicates are evaluated by machine-learned models, and the choice of a query plan affects not only the cost of a query but also its result. Existing systems either apply a fixed threshold to each semantic operator or tune accuracy per operator, without accounting for how errors propagate through joins. We give a formal problem definition for cost-accuracy optimization of such queries. Our starting point is the calibrated confidence that decision models such as Jev attach to each decision. It yields an expected error for every decision; weighting these errors by each decision's contribution to the output (in the simplest case, its fan-out) gives the expected output quality of a plan without any labeled data, and the same computation in reverse turns an output-level accuracy target into a price on each base or intermediate tuple. Building on this, we define an oracle semantics for relational algebra with semantic operators, physical plans as pairs of a logical plan and a decision policy, declarative output-level targets, and a hierarchy of plan equivalence. We show that accuracy is plan-invariant under pointwise-deterministic policies, and that selection pushdown is not quality-sound when escalation bands are calibrated on the plan's own candidates. Expected quality can be computed in polynomial time under bag semantics; under set semantics it follows the dichotomy of tuple-independent probabilistic databases when every relation carries a semantic predicate. Choosing which tuples to drop is NP-hard, while the optimization problem decomposes into per-tuple decisions through two Lagrange multipliers. Simulations on a synthetic workload illustrate these effects; an evaluation on real engines is left for future work.

1 Introduction

A classical query optimizer can treat all plans in its search space as interchangeable with respect to the result and compare them by cost alone. Semantic query engines break this assumption. Once a predicate is evaluated by a model, thresholds, cascades, candidate pruning, and sample-based calibration all affect which tuples are returned, and two plans for the same query may return different answers. In this paper we ask three questions. When should two such plans be considered equivalent? How can we predict the accuracy of a plan without comparing its output to ground truth? And how do we find the cheapest plan whose accuracy is good enough?

Running example. Consider a retailer that wants to contact every customer who bought a product for which some review reports a battery fire:

SELECT o.* FROM Reviews r JOIN Orders o ON r.product = o.product

WHERE SEM(r.text, 'reports a battery fire')

We assume that the semantic predicate is evaluated by an inexpensive decision model, such as Jev in JEVDB [Wang et al., 2026], which returns a confidence prp_{r} that review r satisfies the predicate.

Table 1: Running example: five reviews, their decision-model confidence pp, and fan-out ff (orders of the reviewed product). A plan that accepts the reviews with p≥0.5p\ge 0.5 makes the expected errors on the right: per review (operator level) and per output row (output level).

ReviewppffActionExpected error per reviewExpected error in output rows
r1r_{1}0.980.9822ACCEPTFP: 1−p=0.021-p=0.02FP: 0.02⋅2=0.040.02\cdot2=0.04
r2r_{2}0.900.904040ACCEPTFP: 0.100.10FP: 0.10⋅40=4.000.10\cdot40=4.00
r3r_{3}0.600.6055ACCEPTFP: 0.400.40FP: 0.40⋅5=2.000.40\cdot5=2.00
r4r_{4}0.300.30100100REJECTFN: p=0.30p=0.30FN: 0.30⋅100=30.000.30\cdot100=30.00
r5r_{5}0.050.0533REJECTFN: 0.050.05FN: 0.05⋅3=0.150.05\cdot3=0.15
Expected recall / precision0.88/0.830.88/0.830.58/0.870.58/0.87

Uncertain reviews can additionally be sent to a more expensive LLM judge. A review that passes the filter contributes one output row per order of its product; we call this number its fan-out frf_{r}. Table 1 lists five reviews.

From confidence to expected error. Suppose the confidences are calibrated. Then a review accepted with confidence pp is a false positive with probability 1−p1-p, and a rejected review is a false negative with probability pp. Let confi\mathrm{conf}_{i} denote the confidence in the action that was taken, i.e., pip_{i} if the review is accepted and 1−pi1-p_{i} if it is rejected. By linearity of expectation,

E[#wrong decisions]=∑i(1−confi),\mathbb{E}[\#\mathrm{wrong\ decisions}]=\sum_{i}\left(1-\mathrm{conf}_{i}\right),

where accepted instances account for the false positives and rejected instances for the false negatives. For the plan in Table 1, the filter makes 0.52 false positives and 0.35 false negatives in expectation, for an expected recall of 2.48/(2.48+0.35)=0.882.48/(2.48+0.35)=0.88. The query result, however, consists of orders and not of reviews. An error on rir_{i} affects fif_{i} output rows, so the expected number of wrong output rows is the same sum weighted by each decision's contribution to the output, here ∑ifi(1−confi)\sum_{i} f_{i}(1-\mathrm{conf}_{i}). On output rows the expected recall drops to 0.58, and 30 of the 30.15 expected missing rows are due to a single review, r4r_{4}, which is both uncertain and has a large fan-out.

From expected error back to decisions. The same reasoning can be applied in the opposite direction to make decisions. Escalating r4r_{4} to the judge costs one LLM call and removes 30 expected missing rows, which raises the expected output recall from 0.58 to 0.998. Escalating r3r_{3} also costs one call, but removes only 2 expected wrong rows. In general, an output-level target can be pushed down to a price per unit of expected output error. Each base or intermediate tuple then compares the cost of resolving its uncertainty with the reduction in output error that this buys. Figure 1 illustrates both directions.

Why calibrated confidence matters. Without confidences, the accuracy of a plan can only be measured against labeled ground truth, and an optimizer has nothing but cost to compare plans by. Boolean decisions from a fixed model and threshold do not help either, since then all classically equivalent plans return the same answer (Theorem 5.3). Calibrated confidences allow us to predict the output quality of a plan before executing it (Sections 4 and 7), to compare plans by their predicted quality and thereby decide which rewrites are safe (Section 5), and to optimize by assigning a price to output error at the level of individual tuples (Sections 6 and 8).

Figure

target (ρ,γ)(\rho, \gamma) pushed down as a price per unit of output error, weighed per tuple against the cost of an escalation, a drop, or a reorder

Figure 1: The role of calibrated confidence. Forward (solid): each decision has an expected error, which lineage weights by the decision's contribution cic_i to the output (in the running example, its fan-out); the sum gives the expected output quality of a plan. Backward (dashed): an output-level target induces a cost-accuracy trade-off for each tuple.

Motivating gaps. JEVDB [Wang et al., 2026] evaluates predicates with Jev either at a fixed threshold (its Flash mode) or with a per-predicate escalation band [ℓ,h)[\ell, h). The band is fit on a sample of about 200 candidates labeled by an LLM judge, such that the expected recall and precision loss relative to the judge stay below user-given tolerances (0.05 in the experiments). JEVDB pushes semantic filters down by default, arguing that Jev calls are cheap, and leaves semantic-aware query optimization to future work. Like other current systems, it states accuracy targets per operator.

Per-operator targets can differ substantially from the quality of the query result. In Table 1, the filter has an expected recall of 0.88, whereas the query result has an expected recall of 0.58. To our knowledge, no current system lets the user specify a single accuracy target for the query and distributes it across operators and tuples.

References (33)