Repository navigation
devtools: planner_fuzz, a metamorphic fuzz tester for missed reuse and sharing - #921
Merged
Merged
Conversation
…d sharing Generates small PromQL and SQL workloads (and samples seed workload files), checks marginal-cost relations against a witness plan priced by Stage 2 and Stage 3, plus monotonicity and invariance relations, shrinks each new violation and writes an issue draft per distinct shrunk case. Regression tests find the open issues #903, #902 and #891.
Sound estimate witnesses (root estimate only, merge capability, distinct states), a violation needs a cheaper witness, no nested window for rate or increase, per-check streamed worker results with the running check and stderr, one draft per class, more shrink steps, cached reference price, units in field names.
… before shrinking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #879
Why
Missed reuse and missed sharing in the planner (a query priced higher than a cheaper equivalent plan the rules never generate) are found today only by reading plans by hand. Each one shows up as a cost that should not go up, or should not go down by less, when the workload is changed in a known way. Those relations can be checked mechanically on generated workloads.
What
Adds
planner_fuzz, a metamorphic fuzz tester in theasap-devtoolscrate. For a generated or seeded workload it builds a related workload (looser accuracy, a filter on a group key, a coarser grouping, a nested shorter window, a duplicate query, an added query, a renamed or reordered workload, a disjoint copy, and so on), plans both with the same search, and checks the relation between their costs per second. A violation is shrunk to a small workload and written as a draft finding with the exactstage_pipelinecommand that reproduces it. No planner behavior changes.How
generate.rsdraws PromQL and SQL queries and workloads from a seed, or mutates a--seed-workloadfile.relations.rsdefines each relation:derivebuilds the related workload,evaluateplans both sides and returns holds, violated, or inconclusive. Marginal relations compare the extra cost of a query with its stand-alone cost; monotonic relations compare the two totals. Tolerance is max(relative x cost, absolute).shrink.rsremoves queries and simplifies each remaining query while the violation still holds.report.rsdeduplicates violations into classes, writes a per-seed summary and one draft per class.--worker) with a timeout, so a hang or crash in the planner becomes a counted outcome.sql_catalogmoves fromstage_pipelineintoplanning_stagesso both tools build SQL tables from--tablethe same way.Key code interfaces added / modified
crates/devtools/src/planner_fuzz/mod.rscrates/devtools/src/planner_fuzz/relations.rscrates/devtools/src/planning_stages.rsCLI,
crates/devtools/src/bin/planner_fuzz.rs(new):planner_fuzz --seed <u64> --cases <n> --time-budget-s <s> [--relations <name|letter>,...] [--search legacy|memo-brute-force|exhaustive] [--seed-workload <file>]... [--ignore-accuracy-guarantees] [--relative-tolerance <f64>] [--absolute-tolerance <f64>] [--max-shrink-attempts <n>] [--case-timeout-s <s>] --out <dir>Usage
Before this PR
Missed-reuse bugs were found by hand. There was no way to ask whether a planner change made some related workload cheaper than the one it was derived from.
After this PR
planner_fuzzruns the relations over seeded random workloads or the committed eval workloads, shrinks each violation, and writes reproducible drafts. The crate README (crates/devtools/src/planner_fuzz/README.md) holds the relation tables, how the derived cost is computed, and the coverage against the design doc. Three regression tests re-find known planner issues from committed fixtures.Verification
On the rebased head, with
asap-devtoolsbuilt where HiGHS builds:cargo nextest run -p asap-devtools: 84 of 84 passed, including the 9planner_fuzzintegration tests, the 9 library tests, and the 46stage_pipelinetests.cargo clippy -p asap-devtools --all-targets -- -D warningsandcargo fmt --check: clean.Limitation: relations are checked on cost per second only; findings are drafts for a person to review and are not filed automatically.