-
Notifications
You must be signed in to change notification settings - Fork 676
index planning: implement branch and bound #13568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dimitar/index-planning/add-virtual-predicates
Are you sure you want to change the base?
index planning: implement branch and bound #13568
Conversation
958ba9d to
9c471e6
Compare
9a9da0c to
142f2ad
Compare
0c02b81 to
fccd6f3
Compare
This will help us test the branch and bound planner with more complex queries. Signed-off-by: Dimitar Dimitrov <[email protected]>
Signed-off-by: Dimitar Dimitrov <[email protected]>
…d-bound Remove the partialPlan struct and its duplicated cost calculation methods. Instead, use the plan struct directly with its virtualPredicate() method and numDecidedPredicates field to compute lower bound costs. Changes: - Removed partialPlan struct - Removed all cost methods from partialPlan (now inherited from plan) - Changed partialPlans heap type to plans - Updated pools to use plan instead of partialPlan - Branch-and-bound now uses plan directly with numDecidedPredicates tracking - TotalCost() automatically computes lower bound when numDecidedPredicates < len(predicates) This simplifies the code by eliminating duplication while maintaining the same behavior. Signed-off-by: Dimitar Dimitrov <[email protected]>
fccd6f3 to
17d3132
Compare
Signed-off-by: Dimitar Dimitrov <[email protected]>
| heap.Push(prospectPlans, newPlanWithCost(current.plan, current.numDecidedPredicates+1)) | ||
| } | ||
|
|
||
| // Fall back to index-only plan to ensure that our code doesn't choose a more expensive plan than the naive plan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use the cost of the indexOnlyPlan as the starting bestCompleteCost to further narrow the possible number of generated plans/branches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it would 👍 let me do that now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 42ec853 ; this also changed the tests. but I checked and the costs of the old and the new plans is the same - 11.5, 0, 0. So adding the index-only plan at the start just influences which equivalent plan with the same cost we choose, but they're all in theory equally cheap
Signed-off-by: Dimitar Dimitrov <[email protected]>
What this PR does
The exhaustive planner generates all 2^N possible plans for N matchers, which becomes prohibitively expensive for queries with many matchers.
This change implements a branch-and-bound algorithm that:
For undecided predicates, the lower bound calculation:
Benchmarks
The tradeoff is that for smaller plans the new exploration is more expensive
Details
Which issue(s) this PR fixes or relates to
closes #11921
based on the changes from #13572
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]. If changelog entry is not needed, please add thechangelog-not-neededlabel to the PR.about-versioning.mdupdated with experimental features.Note
Replaces exhaustive 2^N plan generation with a branch-and-bound priority-queue explorer, refactors planner to stream plans, and updates tracing, pooling, and tests (incl. large-matcher cases).
generatePlansBranchAndBoundwith a min-heap over plan lower-bound costs; prunes branches and merges remaining candidates (branch_and_bound.go).iter.Seq[plan]); selects first plan containing index matchers.newIndexOnlyPlan(),hasAnyIndexPredicate(), and virtual predicate tweaks for non-zero minimal costs; addsGetPlans()slab-backed PQ; removes "too many matchers" early abort.planningDisabled(ctx)and context helper; returns input plan unchanged when disabled.TestCostBasedPlannerWithManyMatchers(1000 matchers); adds preservation and preference tests.planner_test_cases.csvwith high-cardinality 20-matcher scenarios and sharded variants.Written by Cursor Bugbot for commit 42ec853. This will update automatically on new commits. Configure here.