Repository navigation
Fix completeness: a second key no longer turns a provable pair unprovable - #12
Open
zvonimir-dd wants to merge 2 commits into
Open
zvonimir-dd wants to merge 2 commits into
zvonimir-dd wants to merge 2 commits into
Conversation
With two keys on a table, each key's columns are functions of the other's, and min_subst eliminated whichever variable came first. An equivalent pair could then sum over the first key on one side and the second on the other (e.g. a JOIN on the item id against an EXISTS), which unification, matching summation variables only up to a permutation, cannot relate: adding a key turned a provable pair unprovable. Give the functions of every key after the first their own prefix (rpu!) and make min_subst try expressions through them only in a second pass, for the variables the first pass kept. Secondary keys still eliminate variables the first key cannot (SELECT DISTINCT over a unique column), but no longer decide which key a sum ranges over. Any choice min_subst makes is justified by an implied equality, so this cannot make a non-equivalent pair provable. Without rpu! expressions the second pass eliminates nothing: a candidate the first pass rejected has the variable itself among its root dependencies, and still does. Single-key inputs are therefore decided exactly as before. Fixes qed-solver#11. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every key made every other column a function of its columns, so a second key on a table of n columns added up to n more equations per scan, all handed to the implied-equalities call in stablize. On wide tables that call hit its timeout, nothing was substituted, and pairs provable with one key came back unprovable. The first key already determines every column. A later key only has to determine the first key's columns not in it: then two rows equal on the later key agree on the first key, and so are the same row, and any instance satisfying all keys has such functions. Its predicate is implied too, so it is dropped. A superkey of the first key now adds nothing. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Fixes #11: a second key on a table can turn a provable pair unprovable. Adding a key only narrows the instances, so that should never happen. There are two causes, one per commit.
1.
min_substpicks the summation variable by column orderWith keys
{id}and{grp}onitems(id, owner, grp), theScanencoding makes each key's columns functions of the other key's:id = rpn!0-0-1(grp)andgrp = rpn!0-1-0(id).min_substthen eliminates whichever of the two it reaches first. On the issue's pair, theRUST_LOG=infotrace of upstreammainshows the result:id := item_id, and the sum ranges over the item id (rpk!0-0($2)).id := rpn!0-0-1(grp), and the sum ranges overgrp(rpk!0-1($2)).Unify<Term>matches summation variables only up to a permutation. At the samev, one summand is "the row whose id is v" and the other "the row whose grp is v", so the check fails.Fix: the functions of every key after the first get their own prefix,
rpu!.min_substtries expressions through them only in a second pass, and only for the variables the first pass kept. Secondary keys still eliminate what the first key cannot:SELECT grpvsSELECT DISTINCT grpstill proves. But they no longer decide which key a sum ranges over.2. Every key made every column a function of it
A second key on an n-column table added up to n more equations per scan. All of them go to the
get_implied_equalitiescall instablize. On wide tables that call hitsQED_SMT_TIMEOUT, nothing gets substituted, and the pair comes back unprovable withequiv_class_timed_outset. This is how the timeouts the issue mentions arise.Fix: a key after the first now only determines the first key's columns that it lacks, and its predicate is dropped.
Why neither change can create a false proof
min_substpicks is justified by an implied equality under the summand's own condition:Σ_v [L(v)]·f(v) = [L(e)]·f(e)whenL ⟹ v = e. Changing which justified substitution is picked cannot make a non-equivalent pair provable.rpu!. So they agree on the whole first key, and are the same row.rpu!functions always exist.Single-key inputs are unaffected. Pass 2 accepts nothing without
rpu!terms. Any candidate pass 1 rejected had the variable itself among its root dependencies, and still does. Commit 2 changes only keys after the first.Testing
Issue repro:
two_keys.jsongoes fromfalsetotrue;one_key.jsonstaystrue.42 hand-written controls. They run over three key settings: one key, two keys, and two keys in reverse order. They cover:
grp;SELECT DISTINCTover a column that is unique only through the second key;DISTINCT ownerand a self-join onowner.Upstream
mainmisses 5 equivalent pairs, all second-key cases. With both commits, all 42 come out as expected, with no false proofs and no missed proofs.tests/(1731 cases), upstreammainvs this branch:min_substdecisions ([dep]/[key], as a sorted multiset per case) are byte-identical on all 1705 cases where no table has two keys.testExpandProjectInsometimes segfaults on both builds, with Z3 interrupted during the equivalence-class step; run alone it reproduces on upstreammaintoo.Real-world pairs: on the pairs behind the issue's "about a dozen proofs lost", most proofs come back with both commits, on the solver versions pinned here. With commit 1 alone only the non-timeout cases come back. A few cases over very wide tables still run past a 60 s budget.
Builds:
nix buildwarnings are unchanged. I also measured both commits on Z3 5.1.0 / cvc5 1.4.1. The direction is the same there, but more of the wide-table cases stay at the time budget, because that Z3'sget_implied_equalitiesis slower.🤖 Generated with Claude Code