When Plans Change Answers: Formalizing Cost-Accuracy Optimization for Semantic Queries
Organizations: KAIST
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, and, with what we call confidence-centric skipping, tuples that can no longer affect the target are skipped without being scored. Simulations on a synthetic workload illustrate these effects; an evaluation on real engines is left for future work.
Figures & tables
| Review | Action | Expected error per review | Expected error in output rows | ||
| 0.98 | 2 | Accept | FP: | FP: | |
| 0.90 | 40 | Accept | FP: | FP: | |
| 0.60 | 5 | Accept | FP: | FP: | |
| 0.30 | 100 | Reject | FN: | FN: | |
| 0.05 | 3 | Reject | FN: | FN: | |
| Expected recall / precision | / | / | |||
| Class | Action depends on | Example |
|---|---|---|
| Pointwise-deterministic (PD) | only, fixed function | Jev with fixed ; JEVDB-Flash; “accept iff ” |
| Population-calibrated (PC) | and a statistic of | escalation band fit on a sample of current candidates; JEVDB’s quality-controlled mode |
| Context-aware (CA) | , fan-out, downstream cost/selectivity | escalate because |
| Sound pruning | necessary condition, sound extractor | lossless SBF; relational Bloom semijoin |
| Level | and are related iff | In Fig. 3 | Checkable without labels? |
|---|---|---|---|
| Oracle ( ) | same answer under oracle predicates | all points | yes (classical rules) |
| Implementation | same answer under the implemented predicates | two ends of a black segment (PD policy) | yes, for PD policies |
| Confidence-relative ( ) | same predicted output recall and precision | points at the same height | yes, from confidences |
| Admissibility ( ) | both meet the output target | points in the shaded band | predicted form ( ) only |
| Result | Statement | Status |
|---|---|---|
| Quality evaluation | Bag: PTIME. Set: PTIME for hierarchical, #P-hard for non-hierarchical with all atoms probabilistic | Theorem 7.3 |
| Plan invariance | Under PD policies, CASQO separates into classical cost-based QO plus a plan-independent policy choice | Proposition 5.3 |
| PC unsoundness | Selection pushdown is not quality-sound for population-calibrated policies | Proposition 5.11 |
| Per-tuple decomposition | Two prices push an output target down to independent per-tuple decisions | Proposition 8.2 |
| Instance-level drop | NP-hard, even with one filter, one join, and | Proposition 8.6 |
| Confidence-centric skipping | Unprocessed instances can be skipped unscored once a bound on their contribution meets the target | Proposition 8.4 |
| Plan | Output recall | Output precision | F1 | Cost | Admissible |
|---|---|---|---|---|---|
| PD, pushdown | 0.997 0.001 | 0.983 0.011 | 0.990 0.006 | 1.00 | 100% |
| PD, pull-up | 0.997 0.001 | 0.983 0.011 | 0.990 0.006 | 88.22 | 100% |
| PC, pushdown | 0.992 0.020 | 0.924 0.064 | 0.956 0.037 | 0.86 | 62% |
| PC, pull-up | 0.950 0.020 | 0.977 0.021 | 0.963 0.016 | 71.40 | 96% |
| Policy | Cost | Escalations | Output recall | Output precision |
|---|---|---|---|---|
| Operator-level band | 37,256 | 688 | 0.917 0.027 | 0.911 0.033 |
| Instance-level (priced) | 7,164 | 87 | 0.921 0.022 | 0.910 0.021 |
| Decision model | Pred. recall | True recall | Pred. precision | True precision | Error (precision) |
|---|---|---|---|---|---|
| Calibrated | 0.997 | 0.997 | 0.983 | 0.982 | 0.008 0.006 |
| Overconfident | 1.000 | 0.994 | 0.981 | 0.872 | 0.109 0.027 |
| Overconfident + PPI | 0.995 | 0.994 | 0.874 | 0.872 | 0.028 0.020 |
| Model cost | Policy | Reviews scored | Escalations | Cost | Output recall | Output precision |
|---|---|---|---|---|---|---|
| 1 | score all | 2,000 | 145 | 18,389 | 0.924 0.021 | 0.918 0.016 |
| 1 | staged + skip | 806 | 144 | 17,063 | 0.915 0.019 | 0.916 0.016 |
| 10 | score all | 2,000 | 145 | 36,389 | 0.924 0.021 | 0.918 0.016 |
| 10 | staged + skip | 712 | 157 | 24,149 | 0.925 0.022 | 0.913 0.014 |
| Order and summary | Unscored | Cost saving | Output recall | Output precision |
|---|---|---|---|---|
| Decreasing fan-out | 58% / 67% | 7.0% / 9.3% | 0.912 0.017 | 0.913 0.016 |
| Storage (random) order | 1% / 2% | 0.7% / 1.7% | 0.914 0.021 | 0.916 0.016 |
| Increasing fan-out | 0% / 0% | 0.7% / 1.7% | 0.911 0.015 | 0.916 0.016 |
| Fan-out noisy prior | 24% / 29% | 2.6% / 3.3% | 0.920 0.018 | 0.917 0.016 |
| Zone map, random layout | 58% / 67% | 7.1% / 9.3% | 0.912 0.017 | 0.914 0.016 |
| Zone map, clustered | 82% / 87% | 11.8% / 13.8% | 0.896 0.015 | 0.912 0.016 |