cockroachdb / cockroachdb/cockroach

opt: normalize and optimize PlanGrams

Open
#172,180 0 comments 0 reactions 0 assignees View on GitHub
A-plan-management A-statement-hint C-enhancement T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

(Breaking this out from https://github.com/cockroachdb/cockroach/issues/152053.)

The optimizer uses a simple top-down interpretive walk to match optimizer expressions against PlanGrams. This means that two PlanGrams that describe the same set of plans could have very different matching performance, depending on the construction of the PlanGrams themselves.

There are some simple optimizations we could do to a PlanGram to make it cheaper to match against (which mostly have to do with reducing the number of distinct productions). We should consider doing some or all of these when loading a PlanGram from disk.

1. remove chain rules by computing the transitive closure
2. remove useless or unreachable nonterminals
3. remove / combine duplicate nonterminals
4. inline nonterminals called from one place

(And there are many more ideas from [Tree Automata Techniques and Applications](https://jacquema.gitlabpages.inria.fr/files/tata.pdf) that we could consider.)

Jira issue: CRDB-65338

Contributor guide

Open the contributing guide

Research direction

Start by reading the parent issue 152053 and the PlanGram loading and matching design described here, then review the referenced Tree Automata Techniques and Applications paper. Define which normalization steps to pursue and compare matching performance before and after loading PlanGrams from disk; done means the selected optimizations are implemented and validated without changing the represented plans.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.