Skip to content
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

opt: eliminate unnecessary IndexJoins that wrap partial index scans #54588

Open
mgartner opened this issue Sep 18, 2020 · 1 comment
Open

opt: eliminate unnecessary IndexJoins that wrap partial index scans #54588

mgartner opened this issue Sep 18, 2020 · 1 comment
Labels
C-performance Perf of queries or internals. Solution not expected to change functional behavior. T-sql-queries SQL Queries Team
Projects

Comments

@mgartner
Copy link
Collaborator

mgartner commented Sep 18, 2020

There are numerous cases where an unnecessary IndexJoin wraps a partial index scan. This happens when proving filter/predicate implication reduces the remaining filters such that a column that is not stored in the partial index is no longer referenced after the scan.

#53586 fixed this when the unnecessary IndexJoin was wrapped in a Project. However, there are other cases that this fix does not cover. Here is one example:

root@127.0.0.1:58553/defaultdb> create table t (a int, s string, index (a) where s = 'foo');

root@127.0.0.1:58553/defaultdb> explain (opt, verbose) select distinct(a) from t where s = 'foo';
                                            text
--------------------------------------------------------------------------------------------
  distinct-on
   ├── columns: a:1
   ├── grouping columns: a:1
   ├── internal-ordering: +1 opt(2)
   ├── stats: [rows=9.5617925, distinct(1)=9.5617925, null(1)=0.1]
   ├── cost: 56.1356179
   ├── key: (1)
   └── index-join t
        ├── columns: a:1 s:2
        ├── stats: [rows=10, distinct(1)=9.5617925, null(1)=0.1, distinct(2)=1, null(2)=0]
        ├── cost: 55.92
        ├── fd: ()-->(2)
        ├── ordering: +1 opt(2) [actual: +1]
        ├── prune: (1)
        ├── interesting orderings: (+1)
        └── scan t@t_a_idx,partial
             ├── columns: a:1 rowid:3
             ├── stats: [rows=10, distinct(2)=1, null(2)=0]
             ├── cost: 14.81
             ├── key: (3)
             ├── fd: (3)-->(1)
             ├── ordering: +1
             └── interesting orderings: (+3) (+1,+3)

Ideally, normalization rules could be run that would prune the unnecessary s column from the IndexJoin, and ultimately remove the IndexJoin altogether.

Jira issue: CRDB-3736

@mgartner mgartner added the C-performance Perf of queries or internals. Solution not expected to change functional behavior. label Sep 18, 2020
@mgartner mgartner added this to To Do in Partial Indexes via automation Sep 18, 2020
@mgartner mgartner added this to Triage in BACKLOG, NO NEW ISSUES: SQL Optimizer via automation Sep 18, 2020
@mgartner mgartner changed the title opt: eliminate unnecessary IndexJoins after partial index scans opt: eliminate unnecessary IndexJoins that wrap partial index scans Sep 18, 2020
@RaduBerinde RaduBerinde moved this from Triage to Plan enhancements (higher priority) in BACKLOG, NO NEW ISSUES: SQL Optimizer Jan 11, 2021
@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@mgartner mgartner removed this from To Do in Partial Indexes Feb 16, 2023
@mgartner mgartner added this to Triage in SQL Queries via automation Feb 16, 2023
@mgartner mgartner removed this from Plan enhancements (higher priority) in BACKLOG, NO NEW ISSUES: SQL Optimizer Feb 16, 2023
@mgartner mgartner moved this from Triage to Backlog in SQL Queries Feb 16, 2023
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-performance Perf of queries or internals. Solution not expected to change functional behavior. T-sql-queries SQL Queries Team
Projects
Status: Backlog
SQL Queries
Backlog (DO NOT ADD NEW ISSUES)
Development

No branches or pull requests

2 participants