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: prune columns that are guaranteed not to be needed for partial index mutations #51623

Closed
mgartner opened this issue Jul 20, 2020 · 0 comments · Fixed by #58358
Closed

opt: prune columns that are guaranteed not to be needed for partial index mutations #51623

mgartner opened this issue Jul 20, 2020 · 0 comments · Fixed by #58358
Assignees
Labels
A-partial-indexes Relating to partial indexes. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@mgartner
Copy link
Collaborator

In the example below, a does not need to be fetched because the secondary partial index is guaranteed not to change during this mutation—none of its indexed or referenced columns are changing.

Also, the partial index put and del columns can be pruned.

root@127.0.0.1:54758/defaultdb> create table t (k int primary key, a int, b int, c int, index (a) where b > 1, family (a), family (b), family (c));
CREATE TABLE

Time: 3.244ms

root@127.0.0.1:54758/defaultdb> explain (opt, verbose) update t set c = c + 1 where true;
                                       text
----------------------------------------------------------------------------------
  update t
   ├── columns: <none>
   ├── fetch columns: k:5 a:6 c:8
   ├── update-mapping:
   │    └── c_new:10 => c:4
   ├── partial index put columns: partial_index_del1:9
   ├── partial index del columns: partial_index_del1:9
   ├── cardinality: [0 - 0]
   ├── volatile, mutations
   ├── stats: [rows=0]
   ├── cost: 1190.04
   └── project
        ├── columns: c_new:10 partial_index_del1:9 k:5 a:6 c:8
        ├── immutable
        ├── stats: [rows=1000]
        ├── cost: 1190.03
        ├── key: (5)
        ├── fd: (5)-->(6,8-10), (8)-->(10)
        ├── prune: (5,6,8-10)
        ├── scan t
        │    ├── columns: k:5 a:6 b:7 c:8
        │    ├── partial index predicates
        │    │    └── t_a_idx: filters
        │    │         └── b:7 > 1 [outer=(7), constraints=(/7: [/2 - ]; tight)]
        │    ├── stats: [rows=1000]
        │    ├── cost: 1160.02
        │    ├── key: (5)
        │    ├── fd: (5)-->(6-8)
        │    └── prune: (5-8)
        └── projections
             ├── c:8 + 1 [as=c_new:10, outer=(8), immutable]
             └── b:7 > 1 [as=partial_index_del1:9, outer=(7)]
@mgartner mgartner added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-partial-indexes Relating to partial indexes. labels Jul 20, 2020
@mgartner mgartner self-assigned this Dec 29, 2020
@craig craig bot closed this as completed in d8b5cb0 Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-partial-indexes Relating to partial indexes. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
1 participant