Jack Douglas
[Partition pruning](https://www.postgresql.org/docs/14/ddl-partitioning.html#DDL-PARTITION-PRUNING) is [working fine](https://dbfiddle.uk/XK3xBosY), but even though both queries use exactly the same index and the 'Index Cond' in the plan is identical, one is an Index Scan and the other an Index Only Scan:

``` 
create table foo(
  part_id integer
, id integer generated always as identity
, num integer
) partition by list (part_id);
```

``` 
create table foo_1 partition of foo for values in (1);
```

``` 
insert into foo(part_id,num) select 1, generate_series(1,1000);
```

``` 
create unique index ind on foo_1(id) include (num);
```

``` 
explain (verbose) select id,num from foo_1 where id=500;
```
| QUERY PLAN |
|:-----------|
| Index Only Scan using ind on public.foo\_1  (cost=0.28..8.29 rows=1 width=8) |
|   Output: id, num |
|   Index Cond: (foo\_1.id = 500) |

``` 
explain (verbose) select id,num from foo where part_id=1 and id=500;
```
| QUERY PLAN |
|:-----------|
| Index Scan using ind on public.foo\_1 foo  (cost=0.28..8.29 rows=1 width=8) |
|   Output: foo.id, foo.num |
|   Index Cond: (foo.id = 500) |
|   Filter: (foo.part\_id = 1) |

[fiddle](https://dbfiddle.uk/r2bzjhpJ)
Top Answer
Anonymous 3091
Well, you ask it to check `part_id`, don't you, and it's not a part of your index, so the row has to be accessed.

If you include `part_id` in the index, it'll become an [index-only scan](https://dbfiddle.uk/FDFqhsxr).

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.